dat.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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 Conf Conf;
  10. typedef struct Confmem Confmem;
  11. typedef struct Fxsave Fxsave;
  12. typedef struct ICC ICC;
  13. typedef struct ICCparms ICCparms;
  14. typedef struct ISAConf ISAConf;
  15. typedef struct Label Label;
  16. typedef struct Lock Lock;
  17. typedef struct MCPU MCPU;
  18. typedef struct MFPU MFPU;
  19. typedef struct MMMU MMMU;
  20. typedef struct NIX NIX;
  21. typedef struct Mach Mach;
  22. typedef uint64_t Mpl;
  23. typedef struct Page Page;
  24. typedef struct PFPU PFPU;
  25. typedef struct PmcCtr PmcCtr;
  26. typedef struct PmcCtl PmcCtl;
  27. typedef struct PmcWait PmcWait;
  28. typedef struct PMMU PMMU;
  29. typedef struct PNOTIFY PNOTIFY;
  30. typedef uint64_t PTE;
  31. typedef struct Proc Proc;
  32. typedef struct Sys Sys;
  33. typedef struct Stackframe Stackframe;
  34. typedef uint64_t uintmem; /* Physical address (hideous) */
  35. typedef struct Ureg Ureg;
  36. typedef struct Vctl Vctl;
  37. /*
  38. * Conversion for Ureg to gdb reg. This avoids a lot of nonsense
  39. * in the outside world. TODO.
  40. */
  41. enum regnames {
  42. GDB_IP,
  43. };
  44. #define DBG_MAX_REG_NUM (0)
  45. #define GDB_NUMREGBYTES (0)
  46. #define MAXSYSARG 6 /* for mount(fd, afd, mpt, flag, arg, mntname) */
  47. /*
  48. * parameters for sysproc.c
  49. */
  50. #define ELF_MAGIC (ELF_MAG)
  51. /*
  52. * machine dependent definitions used by ../port/portdat.h
  53. */
  54. /* Crap. */
  55. struct ISAConf {
  56. int _;
  57. };
  58. /* End Crap. */
  59. struct Lock
  60. {
  61. uint32_t key;
  62. int isilock;
  63. Mpl pl;
  64. uintptr_t _pc;
  65. Proc* p;
  66. Mach* m;
  67. uint64_t lockcycles;
  68. };
  69. struct Label
  70. {
  71. uintptr_t sp;
  72. uintptr_t pc;
  73. // TODO: how many?
  74. uintptr_t regs[64];
  75. };
  76. struct Fxsave {
  77. int _;
  78. };
  79. /*
  80. * FPU stuff in Proc
  81. */
  82. struct PFPU {
  83. int fpustate;
  84. unsigned char fxsave[sizeof(Fxsave)+15];
  85. void* fpusave;
  86. };
  87. /*
  88. * MMU stuff in Proc
  89. */
  90. #define NCOLOR 1
  91. struct PMMU
  92. {
  93. Page* mmuptp[4]; /* page table pages for each level */
  94. };
  95. /*
  96. * things saved in the Proc structure during a notify
  97. */
  98. struct PNOTIFY
  99. {
  100. // void emptiness;
  101. char emptiness;
  102. };
  103. struct Confmem
  104. {
  105. uintptr_t base;
  106. usize npage;
  107. uintptr_t kbase;
  108. uintptr_t klimit;
  109. };
  110. struct Conf
  111. {
  112. uint32_t nproc; /* processes */
  113. Confmem mem[4]; /* physical memory */
  114. uint64_t npage; /* total physical pages of memory */
  115. usize upages; /* user page pool */
  116. uint32_t copymode; /* 0 is copy on write, 1 is copy on reference */
  117. uint32_t ialloc; /* max interrupt time allocation in bytes */
  118. uint32_t nimage; /* number of page cache image headers */
  119. };
  120. enum
  121. {
  122. NPGSZ = 4 /* # of supported pages sizes in Mach */
  123. };
  124. #include "../port/portdat.h"
  125. /*
  126. * CPU stuff in Mach.
  127. */
  128. struct MCPU
  129. {
  130. int _;
  131. };
  132. /*
  133. * FPU stuff in Mach.
  134. */
  135. struct MFPU
  136. {
  137. int _;
  138. };
  139. struct NIX
  140. {
  141. ICC* icc; /* inter-core call */
  142. int nixtype;
  143. };
  144. /*
  145. * MMU stuff in Mach.
  146. */
  147. struct MMMU
  148. {
  149. uintptr_t FaultingAddress;
  150. Page* pml4; /* root for this processor */
  151. PTE* pmap; /* unused as of yet */
  152. Page pml4kludge; /* NIX KLUDGE: we need a page */
  153. };
  154. /*
  155. * Inter core calls
  156. */
  157. enum
  158. {
  159. ICCLNSZ = 128, /* Cache line size for inter core calls */
  160. ICCOK = 0, /* Return codes: Ok; trap; syscall */
  161. ICCTRAP,
  162. ICCSYSCALL
  163. };
  164. struct ICC
  165. {
  166. /* fn is kept in its own cache line */
  167. union{
  168. void (*fn)(void);
  169. unsigned char _ln1_[ICCLNSZ];
  170. };
  171. int flushtlb; /* on the AC, before running fn */
  172. int rc; /* return code from AC to TC */
  173. char* note; /* to be posted in the TC after returning */
  174. unsigned char data[ICCLNSZ]; /* sent to the AC */
  175. };
  176. /*
  177. * hw perf counters
  178. */
  179. struct PmcCtl {
  180. Ref r;
  181. uint32_t _coreno;
  182. int enab;
  183. int user;
  184. int os;
  185. int nodesc;
  186. char descstr[KNAMELEN];
  187. int reset;
  188. };
  189. struct PmcWait{
  190. Ref r;
  191. Rendez rend;
  192. PmcWait* next;
  193. };
  194. struct PmcCtr{
  195. int stale;
  196. PmcWait *wq;
  197. uint64_t ctr;
  198. int ctrset;
  199. PmcCtl PmcCtl;
  200. int ctlset;
  201. };
  202. enum {
  203. PmcMaxCtrs = 4,
  204. PmcIgn = 0,
  205. PmcGet = 1,
  206. PmcSet = 2,
  207. };
  208. /*
  209. * Per processor information.
  210. *
  211. * The offsets of the first few elements may be known
  212. * to low-level assembly code, so do not re-order:
  213. * self - machp()
  214. * splpc - splhi, spllo, splx
  215. * proc - syscallentry
  216. * stack - acsyscall
  217. * externup - externup()
  218. */
  219. struct Mach
  220. {
  221. /* WARNING! Known to assembly! */
  222. uintptr_t self; /* %gs:0 still gives us a Mach* */
  223. uint64_t splpc; /* pc of last caller to splhi */
  224. Proc* proc; /* current process on this processor */
  225. uintptr_t stack; /* mach stack, kstack is in proc->kstack */
  226. uintptr_t rathole; /* to save a reg in syscallentry */
  227. Proc* externup; /* Forsyth recommends we replace the global up with this. */
  228. /* end warning, I think */
  229. int machno; /* physical id of processor */
  230. int online;
  231. MMMU MMU;
  232. uint64_t ticks; /* of the clock since boot time */
  233. Label sched; /* scheduler wakeup */
  234. Lock alarmlock; /* access to alarm list */
  235. void* alarm; /* alarms bound to this clock */
  236. int inclockintr;
  237. Proc* readied; /* old runproc, only relevant if kernel booted with nosmp (-n append) */
  238. uint64_t schedticks; /* next forced context switch, same as above */
  239. uint64_t qstart; /* time when up started running */
  240. int qexpired; /* quantum expired */
  241. int tlbfault;
  242. int tlbpurge;
  243. int pfault;
  244. int cs;
  245. int syscall;
  246. int intr;
  247. int mmuflush; /* make current proc flush it's mmu state */
  248. int ilockdepth;
  249. Perf perf; /* performance counters */
  250. int inidle; /* profiling */
  251. int lastintr;
  252. uint64_t cyclefreq; /* Frequency of user readable cycle counter */
  253. int64_t cpuhz;
  254. int cpumhz;
  255. uint64_t rdtsc;
  256. Lock pmclock;
  257. PmcCtr pmc[PmcMaxCtrs];
  258. MFPU FPU;
  259. MCPU CPU;
  260. NIX NIX;
  261. /* for restoring pre-AMP scheduler */
  262. Sched *sch;
  263. int load;
  264. };
  265. struct Stackframe
  266. {
  267. Stackframe *next;
  268. uintptr_t pc;
  269. };
  270. /*
  271. * firmware sets up the virtual memory of the kernel. What to do after that? I don't know.
  272. */
  273. struct Sys {
  274. unsigned char machstk[MACHSTKSZ];
  275. union {
  276. Mach mach;
  277. unsigned char machpage[MACHSZ];
  278. };
  279. union {
  280. struct {
  281. uint64_t pmstart; /* physical memory */
  282. uint64_t pmoccupied; /* how much is occupied */
  283. uint64_t pmend; /* total span */
  284. uintptr_t vmstart; /* base address for malloc */
  285. uintptr_t vmunused; /* 1st unused va */
  286. uintptr_t vmunmapped; /* 1st unmapped va */
  287. uintptr_t vmend; /* 1st unusable va */
  288. uint64_t epoch; /* crude time synchronisation */
  289. int nc[NIXROLES]; /* number of online processors */
  290. int nmach;
  291. int load;
  292. uint64_t ticks; /* of the clock since boot time */
  293. };
  294. unsigned char syspage[4*KiB];
  295. };
  296. union {
  297. Mach* machptr[MACHMAX];
  298. unsigned char ptrpage[4*KiB];
  299. };
  300. uint64_t cyclefreq; /* Frequency of user readable cycle counter (mach 0) */
  301. uint pgszlg2[NPGSZ]; /* per Mach or per Sys? */
  302. uint pgszmask[NPGSZ]; /* Per sys -aki */
  303. uint pgsz[NPGSZ];
  304. int npgsz;
  305. unsigned char _57344_[2][4*KiB]; /* unused */
  306. };
  307. extern Sys *sys;
  308. #define MACHP(x) (sys->machptr[(x)])
  309. /*
  310. * KMap
  311. */
  312. typedef void KMap;
  313. extern KMap* kmap(Page*);
  314. #define kunmap(k)
  315. #define VA(k) PTR2UINT(k)
  316. struct
  317. {
  318. Lock l;
  319. int nonline; /* # of active CPUs */
  320. int nbooting; /* # of CPUs waiting for the bTC to go */
  321. int exiting; /* shutdown */
  322. int ispanic; /* shutdown in response to a panic */
  323. int thunderbirdsarego; /* lets the added processors continue */
  324. }active;
  325. /*
  326. * The Mach structures must be available via the per-processor
  327. * MMU information array machptr, mainly for disambiguation and access to
  328. * the clock which is only maintained by the bootstrap processor (0).
  329. */
  330. extern uintptr_t kseg0;
  331. extern char*rolename[];
  332. /*
  333. * Horrid.
  334. */
  335. // HARVEY: TODO: bring this back, it's actually nice. Or do something better.
  336. // Talk to Ron before you condemn it.
  337. #ifdef _DBGC_
  338. #define DBGFLG (dbgflg[_DBGC_])
  339. #else
  340. #define DBGFLG (0)
  341. #endif /* _DBGC_ */
  342. #define DBG(...) if(!DBGFLG){}else dbgprint(__VA_ARGS__)
  343. extern char dbgflg[256];
  344. #define dbgprint print /* for now */