dat.h 8.4 KB

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