dat.h 7.9 KB

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