1 typedef struct BIOS32si BIOS32si; 2 typedef struct BIOS32ci BIOS32ci; 3 typedef struct Conf Conf; 4 typedef struct Confmem Confmem; 5 typedef struct FPsave FPsave; 6 typedef struct ISAConf ISAConf; 7 typedef struct Label Label; 8 typedef struct Lock Lock; 9 typedef struct MMU MMU; 10 typedef struct Mach Mach; 11 typedef struct Notsave Notsave; 12 typedef struct PCArch PCArch; 13 typedef struct Pcidev Pcidev; 14 typedef struct PCMmap PCMmap; 15 typedef struct PCMslot PCMslot; 16 typedef struct Page Page; 17 typedef struct PMMU PMMU; 18 typedef struct Proc Proc; 19 typedef struct Segdesc Segdesc; 20 typedef vlong Tval; 21 typedef struct Ureg Ureg; 22 typedef struct Vctl Vctl; 23 24 #pragma incomplete BIOS32si 25 #pragma incomplete Pcidev 26 #pragma incomplete Ureg 27 28 #define MAXSYSARG 5 /* for mount(fd, afd, mpt, flag, arg) */ 29 30 /* 31 * Where configuration info is left for the loaded programme. 32 * There are 3584 bytes available at CONFADDR. 33 */ 34 #define BOOTLINE ((char*)CONFADDR) 35 #define BOOTLINELEN 64 36 #define BOOTARGS ((char*)(CONFADDR+BOOTLINELEN)) 37 #define BOOTARGSLEN (3584-0x200-BOOTLINELEN) 38 #define MAXCONF 100 39 40 enum { 41 Promptsecs = 60, 42 }; 43 44 char *confname[MAXCONF]; 45 char *confval[MAXCONF]; 46 int nconf; 47 48 #define KMESGSIZE 64 49 #define PCICONSSIZE 64 50 #define STAGESIZE 64 51 52 #define NAMELEN 28 53 54 #define GSHORT(p) (((p)[1]<<8)|(p)[0]) 55 #define GLSHORT(p) (((p)[0]<<8)|(p)[1]) 56 57 #define GLONG(p) ((GSHORT(p+2)<<16)|GSHORT(p)) 58 #define GLLONG(p) (((ulong)GLSHORT(p)<<16)|GLSHORT(p+2)) 59 #define PLLONG(p,v) (p)[3]=(v);(p)[2]=(v)>>8;(p)[1]=(v)>>16;(p)[0]=(v)>>24 60 61 #define PLVLONG(p,v) (p)[7]=(v);(p)[6]=(v)>>8;(p)[5]=(v)>>16;(p)[4]=(v)>>24;\ 62 (p)[3]=(v)>>32; (p)[2]=(v)>>40;\ 63 (p)[1]=(v)>>48; (p)[0]=(v)>>56; 64 65 enum { 66 Stkpat = 0, 67 }; 68 69 /* 70 * parameters for sysproc.c 71 */ 72 #define AOUT_MAGIC (I_MAGIC) 73 74 struct Lock 75 { 76 ulong magic; 77 ulong key; 78 ulong sr; 79 ulong pc; 80 Proc *p; 81 Mach *m; 82 ushort isilock; 83 long lockcycles; 84 }; 85 86 struct Label 87 { 88 ulong sp; 89 ulong pc; 90 }; 91 92 93 /* 94 * FPsave.status 95 */ 96 enum 97 { 98 /* this is a state */ 99 FPinit= 0, 100 FPactive= 1, 101 FPinactive= 2, 102 103 /* the following is a bit that can be or'd into the state */ 104 FPillegal= 0x100, 105 }; 106 107 struct FPsave 108 { 109 ushort control; 110 ushort r1; 111 ushort status; 112 ushort r2; 113 ushort tag; 114 ushort r3; 115 ulong pc; 116 ushort selector; 117 ushort r4; 118 ulong operand; 119 ushort oselector; 120 ushort r5; 121 uchar regs[80]; /* floating point registers */ 122 }; 123 124 struct Confmem 125 { 126 ulong base; 127 ulong npage; 128 ulong kbase; 129 ulong klimit; 130 }; 131 132 struct Conf 133 { 134 ulong nmach; /* processors */ 135 ulong nproc; /* processes */ 136 ulong monitor; /* has monitor? */ 137 Confmem mem[4]; /* physical memory */ 138 ulong npage; /* total physical pages of memory */ 139 ulong upages; /* user page pool */ 140 ulong nimage; /* number of page cache image headers */ 141 ulong nswap; /* number of swap pages */ 142 int nswppo; /* max # of pageouts per segment pass */ 143 ulong base0; /* base of bank 0 */ 144 ulong base1; /* base of bank 1 */ 145 ulong copymode; /* 0 is copy on write, 1 is copy on reference */ 146 ulong ialloc; /* max interrupt time allocation in bytes */ 147 ulong pipeqsize; /* size in bytes of pipe queues */ 148 int nuart; /* number of uart devices */ 149 }; 150 151 /* 152 * MMU stuff in proc 153 */ 154 #define NCOLOR 1 155 struct PMMU 156 { 157 Page* mmupdb; /* page directory base */ 158 Page* mmufree; /* unused page table pages */ 159 Page* mmuused; /* used page table pages */ 160 Page* kmaptable; /* page table used by kmap */ 161 uint lastkmap; /* last entry used by kmap */ 162 int nkmap; /* number of current kmaps */ 163 }; 164 165 /* 166 * things saved in the Proc structure during a notify 167 */ 168 struct Notsave 169 { 170 ulong svflags; 171 ulong svcs; 172 ulong svss; 173 }; 174 175 #include "../port/portdat.h" 176 177 typedef struct { 178 ulong link; /* link (old TSS selector) */ 179 ulong esp0; /* privilege level 0 stack pointer */ 180 ulong ss0; /* privilege level 0 stack selector */ 181 ulong esp1; /* privilege level 1 stack pointer */ 182 ulong ss1; /* privilege level 1 stack selector */ 183 ulong esp2; /* privilege level 2 stack pointer */ 184 ulong ss2; /* privilege level 2 stack selector */ 185 ulong xcr3; /* page directory base register - not used because we don't use trap gates */ 186 ulong eip; /* instruction pointer */ 187 ulong eflags; /* flags register */ 188 ulong eax; /* general registers */ 189 ulong ecx; 190 ulong edx; 191 ulong ebx; 192 ulong esp; 193 ulong ebp; 194 ulong esi; 195 ulong edi; 196 ulong es; /* segment selectors */ 197 ulong cs; 198 ulong ss; 199 ulong ds; 200 ulong fs; 201 ulong gs; 202 ulong ldt; /* selector for task's LDT */ 203 ulong iomap; /* I/O map base address + T-bit */ 204 } Tss; 205 206 struct Segdesc 207 { 208 ulong d0; 209 ulong d1; 210 }; 211 212 struct Mach 213 { 214 int machno; /* physical id of processor (KNOWN TO ASSEMBLY) */ 215 ulong splpc; /* pc of last caller to splhi */ 216 217 ulong* pdb; /* page directory base for this processor (va) */ 218 Tss* tss; /* tss for this processor */ 219 Segdesc *gdt; /* gdt for this processor */ 220 221 Proc* proc; /* current process on this processor */ 222 Proc* externup; /* extern register Proc *up */ 223 224 Page* pdbpool; 225 int pdbcnt; 226 227 ulong ticks; /* of the clock since boot time */ 228 Label sched; /* scheduler wakeup */ 229 Lock alarmlock; /* access to alarm list */ 230 void* alarm; /* alarms bound to this clock */ 231 int inclockintr; 232 233 Proc* readied; /* for runproc */ 234 ulong schedticks; /* next forced context switch */ 235 236 int tlbfault; 237 int tlbpurge; 238 int pfault; 239 int cs; 240 int syscall; 241 int load; 242 int intr; 243 int flushmmu; /* make current proc flush it's mmu state */ 244 int ilockdepth; 245 Perf perf; /* performance counters */ 246 247 ulong spuriousintr; 248 int lastintr; 249 250 int loopconst; 251 252 Lock apictimerlock; 253 int cpumhz; 254 uvlong cyclefreq; /* Frequency of user readable cycle counter */ 255 uvlong cpuhz; 256 int cpuidax; 257 int cpuiddx; 258 char cpuidid[16]; 259 char* cpuidtype; 260 int havetsc; 261 int havepge; 262 uvlong tscticks; 263 int pdballoc; 264 int pdbfree; 265 266 vlong mtrrcap; 267 vlong mtrrdef; 268 vlong mtrrfix[11]; 269 vlong mtrrvar[32]; /* 256 max. */ 270 271 int stack[1]; 272 }; 273 274 /* 275 * KMap the structure doesn't exist, but the functions do. 276 */ 277 typedef struct KMap KMap; 278 #define VA(k) ((void*)(k)) 279 KMap* kmap(Page*); 280 void kunmap(KMap*); 281 282 struct 283 { 284 Lock; 285 int machs; /* bitmap of active CPUs */ 286 int exiting; /* shutdown */ 287 int ispanic; /* shutdown in response to a panic */ 288 int thunderbirdsarego; /* lets the added processors continue to schedinit */ 289 int rebooting; /* just idle cpus > 0 */ 290 }active; 291 292 /* 293 * routines for things outside the PC model, like power management 294 */ 295 struct PCArch 296 { 297 char* id; 298 int (*ident)(void); /* this should be in the model */ 299 void (*reset)(void); /* this should be in the model */ 300 int (*serialpower)(int); /* 1 == on, 0 == off */ 301 int (*modempower)(int); /* 1 == on, 0 == off */ 302 303 void (*intrinit)(void); 304 int (*intrenable)(Vctl*); 305 int (*intrvecno)(int); 306 int (*intrdisable)(int); 307 void (*introff)(void); 308 void (*intron)(void); 309 310 void (*clockenable)(void); 311 uvlong (*fastclock)(uvlong*); 312 void (*timerset)(uvlong); 313 314 void (*resetothers)(void); /* put other cpus into reset */ 315 }; 316 317 /* cpuid instruction result register bits */ 318 enum { 319 /* dx */ 320 Fpuonchip = 1<<0, 321 Pse = 1<<3, /* page size extensions */ 322 Tsc = 1<<4, /* time-stamp counter */ 323 Cpumsr = 1<<5, /* model-specific registers, rdmsr/wrmsr */ 324 Pae = 1<<6, /* physical-addr extensions */ 325 Mce = 1<<7, /* machine-check exception */ 326 Cmpxchg8b = 1<<8, 327 Cpuapic = 1<<9, 328 Mtrr = 1<<12, /* memory-type range regs. */ 329 Pge = 1<<13, /* page global extension */ 330 Pse2 = 1<<17, /* more page size extensions */ 331 Clflush = 1<<19, 332 Mmx = 1<<23, 333 Fxsr = 1<<24, /* have SSE FXSAVE/FXRSTOR */ 334 Sse = 1<<25, /* thus sfence instr. */ 335 Sse2 = 1<<26, /* thus mfence & lfence instr.s */ 336 }; 337 338 /* 339 * a parsed plan9.ini line 340 */ 341 #define NISAOPT 8 342 343 struct ISAConf { 344 char *type; 345 ulong port; 346 int irq; 347 ulong dma; 348 ulong mem; 349 ulong size; 350 ulong freq; 351 352 int nopt; 353 char *opt[NISAOPT]; 354 }; 355 356 extern PCArch *arch; /* PC architecture */ 357 358 /* 359 * Each processor sees its own Mach structure at address MACHADDR. 360 * However, the Mach structures must also be available via the per-processor 361 * MMU information array machp, mainly for disambiguation and access to 362 * the clock which is only maintained by the bootstrap processor (0). 363 */ 364 Mach* machp[MAXMACH]; 365 366 #define MACHP(n) (machp[n]) 367 368 extern Mach *m; 369 #define up (((Mach*)MACHADDR)->externup) 370 371 /* 372 * hardware info about a device 373 */ 374 typedef struct { 375 ulong port; 376 int size; 377 } Devport; 378 379 struct DevConf 380 { 381 ulong intnum; /* interrupt number */ 382 char *type; /* card type, malloced */ 383 int nports; /* Number of ports */ 384 Devport *ports; /* The ports themselves */ 385 }; 386 387 typedef struct BIOS32ci { /* BIOS32 Calling Interface */ 388 u32int eax; 389 u32int ebx; 390 u32int ecx; 391 u32int edx; 392 u32int esi; 393 u32int edi; 394 } BIOS32ci; 395 396 /* misc. */ 397 extern int v_flag; 398 399 /* APM goo */ 400 typedef struct Apminfo { 401 int haveinfo; 402 int ax; 403 int cx; 404 int dx; 405 int di; 406 int ebx; 407 int esi; 408 } Apminfo; 409 extern Apminfo apm; 410 411 /* 412 * Multiboot grot. 413 */ 414 typedef struct Mbi Mbi; 415 struct Mbi { 416 u32int flags; 417 u32int memlower; 418 u32int memupper; 419 u32int bootdevice; 420 u32int cmdline; 421 u32int modscount; 422 u32int modsaddr; 423 u32int syms[4]; 424 u32int mmaplength; 425 u32int mmapaddr; 426 u32int driveslength; 427 u32int drivesaddr; 428 u32int configtable; 429 u32int bootloadername; 430 u32int apmtable; 431 u32int vbe[6]; 432 }; 433 434 enum { /* flags */ 435 Fmem = 0x00000001, /* mem* valid */ 436 Fbootdevice = 0x00000002, /* bootdevice valid */ 437 Fcmdline = 0x00000004, /* cmdline valid */ 438 Fmods = 0x00000008, /* mod* valid */ 439 Fsyms = 0x00000010, /* syms[] has a.out info */ 440 Felf = 0x00000020, /* syms[] has ELF info */ 441 Fmmap = 0x00000040, /* mmap* valid */ 442 Fdrives = 0x00000080, /* drives* valid */ 443 Fconfigtable = 0x00000100, /* configtable* valid */ 444 Fbootloadername = 0x00000200, /* bootloadername* valid */ 445 Fapmtable = 0x00000400, /* apmtable* valid */ 446 Fvbe = 0x00000800, /* vbe[] valid */ 447 }; 448 449 typedef struct Mod Mod; 450 struct Mod { 451 u32int modstart; 452 u32int modend; 453 u32int string; 454 u32int reserved; 455 }; 456 457 typedef struct MMap MMap; 458 struct MMap { 459 u32int size; 460 u32int base[2]; 461 u32int length[2]; 462 u32int type; 463 }; 464 465 MMap mmap[32+1]; 466 int nmmap; 467 468 Mbi *multibootheader; 469 470 enum { 471 Maxfile = 4096, 472 }; 473 474 /* from 9load */ 475 476 enum { /* returned by bootpass */ 477 MORE, ENOUGH, FAIL 478 }; 479 enum { 480 INITKERNEL, 481 READEXEC, 482 READ9TEXT, 483 READ9DATA, 484 READGZIP, 485 READEHDR, /* elf states ... */ 486 READPHDR, 487 READEPAD, 488 READEDATA, /* through here */ 489 READE64HDR, /* elf64 states ... */ 490 READ64PHDR, 491 READE64PAD, 492 READE64DATA, /* through here */ 493 TRYBOOT, 494 TRYEBOOT, /* another elf state */ 495 TRYE64BOOT, /* another elf state */ 496 INIT9LOAD, 497 READ9LOAD, 498 FAILED 499 }; 500 501 typedef struct Execbytes Execbytes; 502 struct Execbytes 503 { 504 uchar magic[4]; /* magic number */ 505 uchar text[4]; /* size of text segment */ 506 uchar data[4]; /* size of initialized data */ 507 uchar bss[4]; /* size of uninitialized data */ 508 uchar syms[4]; /* size of symbol table */ 509 uchar entry[4]; /* entry point */ 510 uchar spsz[4]; /* size of sp/pc offset table */ 511 uchar pcsz[4]; /* size of pc/line number table */ 512 }; 513 514 typedef struct { 515 Execbytes; 516 uvlong uvl[1]; 517 } Exechdr; 518 519 typedef struct Boot Boot; 520 struct Boot { 521 int state; 522 523 Exechdr hdr; 524 uvlong entry; 525 526 char *bp; /* base ptr */ 527 char *wp; /* write ptr */ 528 char *ep; /* end ptr */ 529 }; 530 531 extern int debugload; 532 extern Apminfo apm; 533 extern Chan *conschan; 534 extern char *defaultpartition; 535 extern int iniread; 536 extern u32int memstart; 537 extern u32int memend; 538 extern int noclock; 539 extern int pxe; 540 extern int vga; 541 542 extern int biosinited; 543 544 extern void _KTZERO(void); 545 #define KTZERO ((uintptr)_KTZERO) 546