dat.h 9.0 KB

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