dat.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. typedef struct ACVctl ACVctl;
  10. typedef struct Conf Conf;
  11. typedef struct Confmem Confmem;
  12. typedef struct Fxsave Fxsave;
  13. typedef struct ICC ICC;
  14. typedef struct ICCparms ICCparms;
  15. typedef struct ISAConf ISAConf;
  16. typedef struct Label Label;
  17. typedef struct Lock Lock;
  18. typedef struct MCPU MCPU;
  19. typedef struct MFPU MFPU;
  20. typedef struct MMMU MMMU;
  21. typedef struct NIX NIX;
  22. typedef struct Mach Mach;
  23. typedef uint64_t Mpl;
  24. typedef struct Page Page;
  25. typedef struct Pcidev Pcidev;
  26. typedef struct PFPU PFPU;
  27. typedef struct PmcCtr PmcCtr;
  28. typedef struct PmcCtl PmcCtl;
  29. typedef struct PmcWait PmcWait;
  30. typedef struct PMMU PMMU;
  31. typedef struct PNOTIFY PNOTIFY;
  32. typedef uint64_t PTE;
  33. typedef struct Proc Proc;
  34. typedef struct Sys Sys;
  35. typedef struct Stackframe Stackframe;
  36. typedef uint64_t uintmem; /* Physical address (hideous) */
  37. typedef struct Ureg Ureg;
  38. typedef struct Vctl Vctl;
  39. /*
  40. * Conversion for Ureg to gdb reg. This avoids a lot of nonsense
  41. * in the outside world.
  42. */
  43. enum regnames {
  44. GDB_AX, /* 0 */
  45. GDB_BX, /* 1 */
  46. GDB_CX, /* 2 */
  47. GDB_DX, /* 3 */
  48. GDB_SI, /* 4 */
  49. GDB_DI, /* 5 */
  50. GDB_BP, /* 6 */
  51. GDB_SP, /* 7 */
  52. GDB_R8, /* 8 */
  53. GDB_R9, /* 9 */
  54. GDB_R10, /* 10 */
  55. GDB_R11, /* 11 */
  56. GDB_R12, /* 12 */
  57. GDB_R13, /* 13 */
  58. GDB_R14, /* 14 */
  59. GDB_R15, /* 15 */
  60. GDB_PC, /* 16 */
  61. GDB_PS, /* 17 */
  62. GDB_CS, /* 18 */
  63. GDB_SS, /* 19 */
  64. GDB_DS, /* 20 */
  65. GDB_ES, /* 21 */
  66. GDB_FS, /* 22 */
  67. GDB_GS, /* 23 */
  68. };
  69. #define GDB_ORIG_AX 57
  70. #define DBG_MAX_REG_NUM 24
  71. /* 17 64 bit regs and 5 32 bit regs */
  72. #define GDB_NUMREGBYTES ((17 * 8) + (5 * 4))
  73. #define MAXSYSARG 5 /* for mount(fd, afd, mpt, flag, arg) */
  74. /*
  75. * parameters for sysproc.c
  76. */
  77. #define AOUT_MAGIC (S_MAGIC)
  78. #define ELF_MAGIC (ELF_MAG)
  79. /*
  80. * machine dependent definitions used by ../port/portdat.h
  81. */
  82. struct Lock
  83. {
  84. uint32_t key;
  85. int isilock;
  86. Mpl pl;
  87. uintptr_t _pc;
  88. Proc* p;
  89. Mach* m;
  90. uint64_t lockcycles;
  91. };
  92. struct Label
  93. {
  94. uintptr_t sp;
  95. uintptr_t pc;
  96. uintptr_t regs[14];
  97. };
  98. struct Fxsave {
  99. uint16_t fcw; /* x87 control word */
  100. uint16_t fsw; /* x87 status word */
  101. uint8_t ftw; /* x87 tag word */
  102. uint8_t zero; /* 0 */
  103. uint16_t fop; /* last x87 opcode */
  104. uint64_t rip; /* last x87 instruction pointer */
  105. uint64_t rdp; /* last x87 data pointer */
  106. uint32_t mxcsr; /* MMX control and status */
  107. uint32_t mxcsrmask; /* supported MMX feature bits */
  108. unsigned char st[128]; /* shared 64-bit media and x87 regs */
  109. unsigned char xmm[256]; /* 128-bit media regs */
  110. unsigned char ign[96]; /* reserved, ignored */
  111. };
  112. /*
  113. * FPU stuff in Proc
  114. */
  115. struct PFPU {
  116. int fpustate;
  117. unsigned char fxsave[sizeof(Fxsave)+15];
  118. void* fpusave;
  119. };
  120. /*
  121. * MMU stuff in Proc
  122. */
  123. #define NCOLOR 1
  124. struct PMMU
  125. {
  126. Page* mmuptp[4]; /* page table pages for each level */
  127. };
  128. /*
  129. * things saved in the Proc structure during a notify
  130. */
  131. struct PNOTIFY
  132. {
  133. // void emptiness;
  134. char emptiness;
  135. };
  136. struct Confmem
  137. {
  138. uintptr_t base;
  139. usize npage;
  140. uintptr_t kbase;
  141. uintptr_t klimit;
  142. };
  143. struct Conf
  144. {
  145. uint32_t nproc; /* processes */
  146. Confmem mem[4]; /* physical memory */
  147. uint64_t npage; /* total physical pages of memory */
  148. usize upages; /* user page pool */
  149. uint32_t copymode; /* 0 is copy on write, 1 is copy on reference */
  150. uint32_t ialloc; /* max interrupt time allocation in bytes */
  151. uint32_t nimage; /* number of page cache image headers */
  152. };
  153. enum
  154. {
  155. NPGSZ = 4 /* # of supported pages sizes in Mach */
  156. };
  157. #include "../port/portdat.h"
  158. /*
  159. * CPU stuff in Mach.
  160. */
  161. struct MCPU
  162. {
  163. uint32_t cpuinfo[3][4]; /* CPUID Functions 0, 1, and 5 (n.b.: 2-4 are invalid) */
  164. int ncpuinfos; /* number of standard entries */
  165. int ncpuinfoe; /* number of extended entries */
  166. int isintelcpu; /* */
  167. };
  168. /*
  169. * FPU stuff in Mach.
  170. */
  171. struct MFPU
  172. {
  173. uint16_t fcw; /* x87 control word */
  174. uint32_t mxcsr; /* MMX control and status */
  175. uint32_t mxcsrmask; /* supported MMX feature bits */
  176. };
  177. struct NIX
  178. {
  179. ICC* icc; /* inter-core call */
  180. int nixtype;
  181. };
  182. /*
  183. * MMU stuff in Mach.
  184. */
  185. struct MMMU
  186. {
  187. uintptr_t cr2;
  188. Page* pml4; /* pml4 for this processor */
  189. PTE* pmap; /* unused as of yet */
  190. Page pml4kludge; /* NIX KLUDGE: we need a page */
  191. };
  192. /*
  193. * Inter core calls
  194. */
  195. enum
  196. {
  197. ICCLNSZ = 128, /* Cache line size for inter core calls */
  198. ICCOK = 0, /* Return codes: Ok; trap; syscall */
  199. ICCTRAP,
  200. ICCSYSCALL
  201. };
  202. struct ICC
  203. {
  204. /* fn is kept in its own cache line */
  205. union{
  206. void (*fn)(void);
  207. unsigned char _ln1_[ICCLNSZ];
  208. };
  209. int flushtlb; /* on the AC, before running fn */
  210. int rc; /* return code from AC to TC */
  211. char* note; /* to be posted in the TC after returning */
  212. unsigned char data[ICCLNSZ]; /* sent to the AC */
  213. };
  214. /*
  215. * hw perf counters
  216. */
  217. struct PmcCtl {
  218. Ref r;
  219. uint32_t _coreno;
  220. int enab;
  221. int user;
  222. int os;
  223. int nodesc;
  224. char descstr[KNAMELEN];
  225. int reset;
  226. };
  227. struct PmcWait{
  228. Ref r;
  229. Rendez rend;
  230. PmcWait* next;
  231. };
  232. struct PmcCtr{
  233. int stale;
  234. PmcWait *wq;
  235. uint64_t ctr;
  236. int ctrset;
  237. PmcCtl PmcCtl;
  238. int ctlset;
  239. };
  240. enum {
  241. PmcMaxCtrs = 4,
  242. PmcIgn = 0,
  243. PmcGet = 1,
  244. PmcSet = 2,
  245. };
  246. /*
  247. * Per processor information.
  248. *
  249. * The offsets of the first few elements may be known
  250. * to low-level assembly code, so do not re-order:
  251. * self - machp()
  252. * splpc - splhi, spllo, splx
  253. * proc - syscallentry
  254. * stack - acsyscall
  255. * externup - externup()
  256. */
  257. struct Mach
  258. {
  259. /* WARNING! Known to assembly! */
  260. uintptr_t self; /* %gs:0 still gives us a Mach* */
  261. uint64_t splpc; /* pc of last caller to splhi */
  262. Proc* proc; /* current process on this processor */
  263. uintptr_t stack; /* mach stack, kstack is in proc->kstack */
  264. uintptr_t rathole; /* to save a reg in syscallentry */
  265. Proc* externup; /* Forsyth recommends we replace the global up with this. */
  266. /* end warning, I think */
  267. int machno; /* physical id of processor */
  268. int apicno;
  269. int online;
  270. MMMU MMU;
  271. unsigned char* vsvm;
  272. void* gdt;
  273. void* tss;
  274. uint32_t ticks; /* of the clock since boot time */
  275. Label sched; /* scheduler wakeup */
  276. Lock alarmlock; /* access to alarm list */
  277. void* alarm; /* alarms bound to this clock */
  278. int inclockintr;
  279. Proc* readied; /* old runproc, only relevant if kernel booted with nosmp (-n append) */
  280. uint32_t schedticks; /* next forced context switch, same as above */
  281. uint32_t qstart; /* time when up started running */
  282. int qexpired; /* quantum expired */
  283. int tlbfault;
  284. int tlbpurge;
  285. int pfault;
  286. int cs;
  287. int syscall;
  288. int intr;
  289. int mmuflush; /* make current proc flush it's mmu state */
  290. int ilockdepth;
  291. Perf perf; /* performance counters */
  292. int inidle; /* profiling */
  293. int lastintr;
  294. Lock apictimerlock;
  295. uint64_t cyclefreq; /* Frequency of user readable cycle counter */
  296. int64_t cpuhz;
  297. int cpumhz;
  298. uint64_t rdtsc;
  299. Lock pmclock;
  300. PmcCtr pmc[PmcMaxCtrs];
  301. MFPU FPU;
  302. MCPU CPU;
  303. NIX NIX;
  304. /* for restoring pre-AMP scheduler */
  305. Sched *sch;
  306. int load;
  307. };
  308. struct Stackframe
  309. {
  310. Stackframe *next;
  311. uintptr_t pc;
  312. };
  313. /*
  314. * This is the low memory map, between 0x100000 and 0x110000.
  315. * It is located there to allow fundamental datastructures to be
  316. * created and used before knowing where free memory begins
  317. * (e.g. there may be modules located after the kernel BSS end).
  318. * The layout is known in the bootstrap code in l32p.s.
  319. * It is logically two parts: the per processor data structures
  320. * for the bootstrap processor (stack, Mach, vsvm, and page tables),
  321. * and the global information about the system (syspage, ptrpage).
  322. * Some of the elements must be aligned on page boundaries, hence
  323. * the unions.
  324. */
  325. struct Sys {
  326. unsigned char machstk[MACHSTKSZ];
  327. PTE pml4[PTSZ/sizeof(PTE)]; /* */
  328. PTE pdp[PTSZ/sizeof(PTE)];
  329. PTE pd[PTSZ/sizeof(PTE)];
  330. PTE pt[PTSZ/sizeof(PTE)];
  331. unsigned char vsvmpage[4*KiB];
  332. union {
  333. Mach mach;
  334. unsigned char machpage[MACHSZ];
  335. };
  336. union {
  337. struct {
  338. uint64_t pmstart; /* physical memory */
  339. uint64_t pmoccupied; /* how much is occupied */
  340. uint64_t pmend; /* total span */
  341. uintptr_t vmstart; /* base address for malloc */
  342. uintptr_t vmunused; /* 1st unused va */
  343. uintptr_t vmunmapped; /* 1st unmapped va */
  344. uintptr_t vmend; /* 1st unusable va */
  345. uint64_t epoch; /* crude time synchronisation */
  346. int nc[NIXROLES]; /* number of online processors */
  347. int nmach;
  348. int load;
  349. uint32_t ticks; /* of the clock since boot time */
  350. };
  351. unsigned char syspage[4*KiB];
  352. };
  353. union {
  354. Mach* machptr[MACHMAX];
  355. unsigned char ptrpage[4*KiB];
  356. };
  357. uint64_t cyclefreq; /* Frequency of user readable cycle counter (mach 0) */
  358. uint pgszlg2[NPGSZ]; /* per Mach or per Sys? */
  359. uint pgszmask[NPGSZ]; /* Per sys -aki */
  360. uint pgsz[NPGSZ];
  361. int npgsz;
  362. unsigned char _57344_[2][4*KiB]; /* unused */
  363. };
  364. extern Sys *sys;
  365. #define MACHP(x) (sys->machptr[(x)])
  366. /*
  367. * KMap
  368. */
  369. typedef void KMap;
  370. extern KMap* kmap(Page*);
  371. #define kunmap(k)
  372. #define VA(k) PTR2UINT(k)
  373. struct
  374. {
  375. Lock l;
  376. int nonline; /* # of active CPUs */
  377. int nbooting; /* # of CPUs waiting for the bTC to go */
  378. int exiting; /* shutdown */
  379. int ispanic; /* shutdown in response to a panic */
  380. int thunderbirdsarego; /* lets the added processors continue */
  381. }active;
  382. /*
  383. * a parsed plan9.ini line
  384. */
  385. #define NISAOPT 8
  386. struct ISAConf {
  387. char *type;
  388. uintptr_t port;
  389. int irq;
  390. uint32_t dma;
  391. uintptr_t mem;
  392. usize size;
  393. uint32_t freq;
  394. int nopt;
  395. char *opt[NISAOPT];
  396. };
  397. /*
  398. * The Mach structures must be available via the per-processor
  399. * MMU information array machptr, mainly for disambiguation and access to
  400. * the clock which is only maintained by the bootstrap processor (0).
  401. */
  402. extern uintptr_t kseg0;
  403. extern char*rolename[];
  404. /*
  405. * Horrid.
  406. */
  407. // HARVEY: TODO: bring this back, it's actually nice. Or do something better.
  408. // Talk to Ron before you condemn it.
  409. #ifdef _DBGC_
  410. #define DBGFLG (dbgflg[_DBGC_])
  411. #else
  412. #define DBGFLG (0)
  413. #endif /* _DBGC_ */
  414. #define DBG(...) do{if(DBGFLG)dbgprint(__VA_ARGS__);}while(0)
  415. extern char dbgflg[256];
  416. #define dbgprint print /* for now */