dat.h 8.0 KB

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