dat.h 10 KB

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