portdat.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  1. typedef struct Alarms Alarms;
  2. typedef struct Block Block;
  3. typedef struct Chan Chan;
  4. typedef struct Cmdbuf Cmdbuf;
  5. typedef struct Cmdtab Cmdtab;
  6. typedef struct Confmem Confmem;
  7. typedef struct Dev Dev;
  8. typedef struct Dirtab Dirtab;
  9. typedef struct Edf Edf;
  10. typedef struct Egrp Egrp;
  11. typedef struct Evalue Evalue;
  12. typedef struct Fgrp Fgrp;
  13. typedef struct DevConf DevConf;
  14. typedef struct Image Image;
  15. typedef struct Log Log;
  16. typedef struct Logflag Logflag;
  17. typedef struct Mntcache Mntcache;
  18. typedef struct Mount Mount;
  19. typedef struct Mntrpc Mntrpc;
  20. typedef struct Mntwalk Mntwalk;
  21. typedef struct Mnt Mnt;
  22. typedef struct Mhead Mhead;
  23. typedef struct Note Note;
  24. typedef struct Page Page;
  25. typedef struct Path Path;
  26. typedef struct Palloc Palloc;
  27. typedef struct Pallocmem Pallocmem;
  28. typedef struct Perf Perf;
  29. typedef struct PhysUart PhysUart;
  30. typedef struct Pgrp Pgrp;
  31. typedef struct Physseg Physseg;
  32. typedef struct Proc Proc;
  33. typedef struct Pte Pte;
  34. typedef struct QLock QLock;
  35. typedef struct Queue Queue;
  36. typedef struct Ref Ref;
  37. typedef struct Rendez Rendez;
  38. typedef struct Rgrp Rgrp;
  39. typedef struct RWlock RWlock;
  40. typedef struct Sargs Sargs;
  41. typedef struct Schedq Schedq;
  42. typedef struct Segment Segment;
  43. typedef struct Sema Sema;
  44. typedef struct Timer Timer;
  45. typedef struct Timers Timers;
  46. typedef struct Uart Uart;
  47. typedef struct Waitq Waitq;
  48. typedef struct Walkqid Walkqid;
  49. typedef struct Watchdog Watchdog;
  50. typedef int Devgen(Chan*, char*, Dirtab*, int, int, Dir*);
  51. #pragma incomplete DevConf
  52. #pragma incomplete Edf
  53. #pragma incomplete Mntcache
  54. #pragma incomplete Mntrpc
  55. #pragma incomplete Queue
  56. #pragma incomplete Timers
  57. #include <fcall.h>
  58. struct Ref
  59. {
  60. Lock;
  61. long ref;
  62. };
  63. struct Rendez
  64. {
  65. Lock;
  66. Proc *p;
  67. };
  68. struct QLock
  69. {
  70. Lock use; /* to access Qlock structure */
  71. Proc *head; /* next process waiting for object */
  72. Proc *tail; /* last process waiting for object */
  73. int locked; /* flag */
  74. };
  75. struct RWlock
  76. {
  77. Lock use;
  78. Proc *head; /* list of waiting processes */
  79. Proc *tail;
  80. ulong wpc; /* pc of writer */
  81. Proc *wproc; /* writing proc */
  82. int readers; /* number of readers */
  83. int writer; /* number of writers */
  84. };
  85. struct Alarms
  86. {
  87. QLock;
  88. Proc *head;
  89. };
  90. struct Sargs
  91. {
  92. ulong args[MAXSYSARG];
  93. };
  94. /*
  95. * Access types in namec & channel flags
  96. */
  97. enum
  98. {
  99. Aaccess, /* as in stat, wstat */
  100. Abind, /* for left-hand-side of bind */
  101. Atodir, /* as in chdir */
  102. Aopen, /* for i/o */
  103. Amount, /* to be mounted or mounted upon */
  104. Acreate, /* is to be created */
  105. Aremove, /* will be removed by caller */
  106. COPEN = 0x0001, /* for i/o */
  107. CMSG = 0x0002, /* the message channel for a mount */
  108. /*rsc CCREATE = 0x0004, /* permits creation if c->mnt */
  109. CCEXEC = 0x0008, /* close on exec */
  110. CFREE = 0x0010, /* not in use */
  111. CRCLOSE = 0x0020, /* remove on close */
  112. CCACHE = 0x0080, /* client cache */
  113. };
  114. /* flag values */
  115. enum
  116. {
  117. BINTR = (1<<0),
  118. BFREE = (1<<1),
  119. Bipck = (1<<2), /* ip checksum */
  120. Budpck = (1<<3), /* udp checksum */
  121. Btcpck = (1<<4), /* tcp checksum */
  122. Bpktck = (1<<5), /* packet checksum */
  123. };
  124. struct Block
  125. {
  126. long ref;
  127. Block* next;
  128. Block* list;
  129. uchar* rp; /* first unconsumed byte */
  130. uchar* wp; /* first empty byte */
  131. uchar* lim; /* 1 past the end of the buffer */
  132. uchar* base; /* start of the buffer */
  133. void (*free)(Block*);
  134. ushort flag;
  135. ushort checksum; /* IP checksum of complete packet (minus media header) */
  136. };
  137. #define BLEN(s) ((s)->wp - (s)->rp)
  138. #define BALLOC(s) ((s)->lim - (s)->base)
  139. struct Chan
  140. {
  141. Ref; /* the Lock in this Ref is also Chan's lock */
  142. Chan* next; /* allocation */
  143. Chan* link;
  144. vlong offset; /* in fd */
  145. vlong devoffset; /* in underlying device; see read */
  146. ushort type;
  147. ulong dev;
  148. ushort mode; /* read/write */
  149. ushort flag;
  150. Qid qid;
  151. int fid; /* for devmnt */
  152. ulong iounit; /* chunk size for i/o; 0==default */
  153. Mhead* umh; /* mount point that derived Chan; used in unionread */
  154. Chan* umc; /* channel in union; held for union read */
  155. QLock umqlock; /* serialize unionreads */
  156. int uri; /* union read index */
  157. int dri; /* devdirread index */
  158. uchar* dirrock; /* directory entry rock for translations */
  159. int nrock;
  160. int mrock;
  161. QLock rockqlock;
  162. int ismtpt;
  163. Mntcache*mcp; /* Mount cache pointer */
  164. Mnt* mux; /* Mnt for clients using me for messages */
  165. union {
  166. void* aux;
  167. Qid pgrpid; /* for #p/notepg */
  168. ulong mid; /* for ns in devproc */
  169. };
  170. Chan* mchan; /* channel to mounted server */
  171. Qid mqid; /* qid of root of mount point */
  172. Path* path;
  173. };
  174. struct Path
  175. {
  176. Ref;
  177. char *s;
  178. Chan **mtpt; /* mtpt history */
  179. int len; /* strlen(s) */
  180. int alen; /* allocated length of s */
  181. int mlen; /* number of path elements */
  182. int malen; /* allocated length of mtpt */
  183. };
  184. struct Dev
  185. {
  186. int dc;
  187. char* name;
  188. void (*reset)(void);
  189. void (*init)(void);
  190. void (*shutdown)(void);
  191. Chan* (*attach)(char*);
  192. Walkqid*(*walk)(Chan*, Chan*, char**, int);
  193. int (*stat)(Chan*, uchar*, int);
  194. Chan* (*open)(Chan*, int);
  195. void (*create)(Chan*, char*, int, ulong);
  196. void (*close)(Chan*);
  197. long (*read)(Chan*, void*, long, vlong);
  198. Block* (*bread)(Chan*, long, ulong);
  199. long (*write)(Chan*, void*, long, vlong);
  200. long (*bwrite)(Chan*, Block*, ulong);
  201. void (*remove)(Chan*);
  202. int (*wstat)(Chan*, uchar*, int);
  203. void (*power)(int); /* power mgt: power(1) => on, power (0) => off */
  204. int (*config)(int, char*, DevConf*); /* returns nil on error */
  205. };
  206. struct Dirtab
  207. {
  208. char name[KNAMELEN];
  209. Qid qid;
  210. vlong length;
  211. long perm;
  212. };
  213. struct Walkqid
  214. {
  215. Chan *clone;
  216. int nqid;
  217. Qid qid[1];
  218. };
  219. enum
  220. {
  221. NSMAX = 1000,
  222. NSLOG = 7,
  223. NSCACHE = (1<<NSLOG),
  224. };
  225. struct Mntwalk /* state for /proc/#/ns */
  226. {
  227. int cddone;
  228. Mhead* mh;
  229. Mount* cm;
  230. };
  231. struct Mount
  232. {
  233. ulong mountid;
  234. Mount* next;
  235. Mhead* head;
  236. Mount* copy;
  237. Mount* order;
  238. Chan* to; /* channel replacing channel */
  239. int mflag;
  240. char *spec;
  241. };
  242. struct Mhead
  243. {
  244. Ref;
  245. RWlock lock;
  246. Chan* from; /* channel mounted upon */
  247. Mount* mount; /* what's mounted upon it */
  248. Mhead* hash; /* Hash chain */
  249. };
  250. struct Mnt
  251. {
  252. Lock;
  253. /* references are counted using c->ref; channels on this mount point incref(c->mchan) == Mnt.c */
  254. Chan *c; /* Channel to file service */
  255. Proc *rip; /* Reader in progress */
  256. Mntrpc *queue; /* Queue of pending requests on this channel */
  257. ulong id; /* Multiplexer id for channel check */
  258. Mnt *list; /* Free list */
  259. int flags; /* cache */
  260. int msize; /* data + IOHDRSZ */
  261. char *version; /* 9P version */
  262. Queue *q; /* input queue */
  263. };
  264. enum
  265. {
  266. NUser, /* note provided externally */
  267. NExit, /* deliver note quietly */
  268. NDebug, /* print debug message */
  269. };
  270. struct Note
  271. {
  272. char msg[ERRMAX];
  273. int flag; /* whether system posted it */
  274. };
  275. enum
  276. {
  277. PG_NOFLUSH = 0,
  278. PG_TXTFLUSH = 1, /* flush dcache and invalidate icache */
  279. PG_DATFLUSH = 2, /* flush both i & d caches (UNUSED) */
  280. PG_NEWCOL = 3, /* page has been recolored */
  281. PG_MOD = 0x01, /* software modified bit */
  282. PG_REF = 0x02, /* software referenced bit */
  283. };
  284. struct Page
  285. {
  286. Lock;
  287. ulong pa; /* Physical address in memory */
  288. ulong va; /* Virtual address for user */
  289. ulong daddr; /* Disc address on swap */
  290. ushort ref; /* Reference count */
  291. char modref; /* Simulated modify/reference bits */
  292. char color; /* Cache coloring */
  293. char cachectl[MAXMACH]; /* Cache flushing control for putmmu */
  294. Image *image; /* Associated text or swap image */
  295. Page *next; /* Lru free list */
  296. Page *prev;
  297. Page *hash; /* Image hash chains */
  298. };
  299. struct Swapalloc
  300. {
  301. Lock; /* Free map lock */
  302. int free; /* currently free swap pages */
  303. uchar* swmap; /* Base of swap map in memory */
  304. uchar* alloc; /* Round robin allocator */
  305. uchar* last; /* Speed swap allocation */
  306. uchar* top; /* Top of swap map */
  307. Rendez r; /* Pager kproc idle sleep */
  308. ulong highwater; /* Pager start threshold */
  309. ulong headroom; /* Space pager frees under highwater */
  310. }swapalloc;
  311. struct Image
  312. {
  313. Ref;
  314. Chan *c; /* channel to text file */
  315. Qid qid; /* Qid for page cache coherence */
  316. Qid mqid;
  317. Chan *mchan;
  318. ushort type; /* Device type of owning channel */
  319. Segment *s; /* TEXT segment for image if running */
  320. Image *hash; /* Qid hash chains */
  321. Image *next; /* Free list */
  322. int notext; /* no file associated */
  323. };
  324. struct Pte
  325. {
  326. Page *pages[PTEPERTAB]; /* Page map for this chunk of pte */
  327. Page **first; /* First used entry */
  328. Page **last; /* Last used entry */
  329. };
  330. /* Segment types */
  331. enum
  332. {
  333. SG_TYPE = 07, /* Mask type of segment */
  334. SG_TEXT = 00,
  335. SG_DATA = 01,
  336. SG_BSS = 02,
  337. SG_STACK = 03,
  338. SG_SHARED = 04,
  339. SG_PHYSICAL = 05,
  340. SG_RONLY = 0040, /* Segment is read only */
  341. SG_CEXEC = 0100, /* Detach at exec */
  342. };
  343. #define PG_ONSWAP 1
  344. #define onswap(s) (((ulong)s)&PG_ONSWAP)
  345. #define pagedout(s) (((ulong)s)==0 || onswap(s))
  346. #define swapaddr(s) (((ulong)s)&~PG_ONSWAP)
  347. #define SEGMAXSIZE (SEGMAPSIZE*PTEMAPMEM)
  348. struct Physseg
  349. {
  350. ulong attr; /* Segment attributes */
  351. char *name; /* Attach name */
  352. ulong pa; /* Physical address */
  353. ulong size; /* Maximum segment size in pages */
  354. Page *(*pgalloc)(Segment*, ulong); /* Allocation if we need it */
  355. void (*pgfree)(Page*);
  356. };
  357. struct Sema
  358. {
  359. Rendez;
  360. long *addr;
  361. int waiting;
  362. Sema *next;
  363. Sema *prev;
  364. };
  365. struct Segment
  366. {
  367. Ref;
  368. QLock lk;
  369. ushort steal; /* Page stealer lock */
  370. ushort type; /* segment type */
  371. ulong base; /* virtual base */
  372. ulong top; /* virtual top */
  373. ulong size; /* size in pages */
  374. ulong fstart; /* start address in file for demand load */
  375. ulong flen; /* length of segment in file */
  376. int flushme; /* maintain icache for this segment */
  377. Image *image; /* text in file attached to this segment */
  378. Physseg *pseg;
  379. ulong* profile; /* Tick profile area */
  380. Pte **map;
  381. int mapsize;
  382. Pte *ssegmap[SSEGMAPSIZE];
  383. Lock semalock;
  384. Sema sema;
  385. ulong mark; /* portcountrefs */
  386. };
  387. enum
  388. {
  389. RENDLOG = 5,
  390. RENDHASH = 1<<RENDLOG, /* Hash to lookup rendezvous tags */
  391. MNTLOG = 5,
  392. MNTHASH = 1<<MNTLOG, /* Hash to walk mount table */
  393. NFD = 100, /* per process file descriptors */
  394. PGHLOG = 9,
  395. PGHSIZE = 1<<PGHLOG, /* Page hash for image lookup */
  396. };
  397. #define REND(p,s) ((p)->rendhash[(s)&((1<<RENDLOG)-1)])
  398. #define MOUNTH(p,qid) ((p)->mnthash[(qid).path&((1<<MNTLOG)-1)])
  399. struct Pgrp
  400. {
  401. Ref; /* also used as a lock when mounting */
  402. int noattach;
  403. ulong pgrpid;
  404. QLock debug; /* single access via devproc.c */
  405. RWlock ns; /* Namespace n read/one write lock */
  406. Mhead *mnthash[MNTHASH];
  407. };
  408. struct Rgrp
  409. {
  410. Ref; /* the Ref's lock is also the Rgrp's lock */
  411. Proc *rendhash[RENDHASH]; /* Rendezvous tag hash */
  412. };
  413. struct Egrp
  414. {
  415. Ref;
  416. RWlock;
  417. Evalue **ent;
  418. int nent;
  419. int ment;
  420. ulong path; /* qid.path of next Evalue to be allocated */
  421. ulong vers; /* of Egrp */
  422. };
  423. struct Evalue
  424. {
  425. char *name;
  426. char *value;
  427. int len;
  428. Evalue *link;
  429. Qid qid;
  430. };
  431. struct Fgrp
  432. {
  433. Ref;
  434. Chan **fd;
  435. int nfd; /* number allocated */
  436. int maxfd; /* highest fd in use */
  437. int exceed; /* debugging */
  438. };
  439. enum
  440. {
  441. DELTAFD = 20 /* incremental increase in Fgrp.fd's */
  442. };
  443. struct Pallocmem
  444. {
  445. ulong base;
  446. ulong npage;
  447. };
  448. struct Palloc
  449. {
  450. Lock;
  451. Pallocmem mem[4];
  452. Page *head; /* most recently used */
  453. Page *tail; /* least recently used */
  454. ulong freecount; /* how many pages on free list now */
  455. Page *pages; /* array of all pages */
  456. ulong user; /* how many user pages */
  457. Page *hash[PGHSIZE];
  458. Lock hashlock;
  459. Rendez r; /* Sleep for free mem */
  460. QLock pwait; /* Queue of procs waiting for memory */
  461. };
  462. struct Waitq
  463. {
  464. Waitmsg w;
  465. Waitq *next;
  466. };
  467. /*
  468. * fasttick timer interrupts
  469. */
  470. enum {
  471. /* Mode */
  472. Trelative, /* timer programmed in ns from now */
  473. Tperiodic, /* periodic timer, period in ns */
  474. };
  475. struct Timer
  476. {
  477. /* Public interface */
  478. int tmode; /* See above */
  479. vlong tns; /* meaning defined by mode */
  480. void (*tf)(Ureg*, Timer*);
  481. void *ta;
  482. /* Internal */
  483. Lock;
  484. Timers *tt; /* Timers queue this timer runs on */
  485. Tval tticks; /* tns converted to ticks */
  486. Tval twhen; /* ns represented in fastticks */
  487. Timer *tnext;
  488. };
  489. enum
  490. {
  491. RFNAMEG = (1<<0),
  492. RFENVG = (1<<1),
  493. RFFDG = (1<<2),
  494. RFNOTEG = (1<<3),
  495. RFPROC = (1<<4),
  496. RFMEM = (1<<5),
  497. RFNOWAIT = (1<<6),
  498. RFCNAMEG = (1<<10),
  499. RFCENVG = (1<<11),
  500. RFCFDG = (1<<12),
  501. RFREND = (1<<13),
  502. RFNOMNT = (1<<14),
  503. };
  504. /*
  505. * process memory segments - NSEG always last !
  506. */
  507. enum
  508. {
  509. SSEG, TSEG, DSEG, BSEG, ESEG, LSEG, SEG1, SEG2, SEG3, SEG4, NSEG
  510. };
  511. enum
  512. {
  513. Dead = 0, /* Process states */
  514. Moribund,
  515. Ready,
  516. Scheding,
  517. Running,
  518. Queueing,
  519. QueueingR,
  520. QueueingW,
  521. Wakeme,
  522. Broken,
  523. Stopped,
  524. Rendezvous,
  525. Waitrelease,
  526. Proc_stopme = 1, /* devproc requests */
  527. Proc_exitme,
  528. Proc_traceme,
  529. Proc_exitbig,
  530. Proc_tracesyscall,
  531. TUser = 0, /* Proc.time */
  532. TSys,
  533. TReal,
  534. TCUser,
  535. TCSys,
  536. TCReal,
  537. NERR = 64,
  538. NNOTE = 5,
  539. Npriq = 20, /* number of scheduler priority levels */
  540. Nrq = Npriq+2, /* number of priority levels including real time */
  541. PriRelease = Npriq, /* released edf processes */
  542. PriEdf = Npriq+1, /* active edf processes */
  543. PriNormal = 10, /* base priority for normal processes */
  544. PriExtra = Npriq-1, /* edf processes at high best-effort pri */
  545. PriKproc = 13, /* base priority for kernel processes */
  546. PriRoot = 13, /* base priority for root processes */
  547. };
  548. struct Schedq
  549. {
  550. Lock;
  551. Proc* head;
  552. Proc* tail;
  553. int n;
  554. };
  555. struct Proc
  556. {
  557. Label sched; /* known to l.s */
  558. char *kstack; /* known to l.s */
  559. Mach *mach; /* machine running this proc */
  560. char *text;
  561. char *user;
  562. char *args;
  563. int nargs; /* number of bytes of args */
  564. Proc *rnext; /* next process in run queue */
  565. Proc *qnext; /* next process on queue for a QLock */
  566. QLock *qlock; /* addr of qlock being queued for DEBUG */
  567. int state;
  568. char *psstate; /* What /proc/#/status reports */
  569. Segment *seg[NSEG];
  570. QLock seglock; /* locked whenever seg[] changes */
  571. ulong pid;
  572. ulong noteid; /* Equivalent of note group */
  573. Proc *pidhash; /* next proc in pid hash */
  574. Lock exl; /* Lock count and waitq */
  575. Waitq *waitq; /* Exited processes wait children */
  576. int nchild; /* Number of living children */
  577. int nwait; /* Number of uncollected wait records */
  578. QLock qwaitr;
  579. Rendez waitr; /* Place to hang out in wait */
  580. Proc *parent;
  581. Pgrp *pgrp; /* Process group for namespace */
  582. Egrp *egrp; /* Environment group */
  583. Fgrp *fgrp; /* File descriptor group */
  584. Rgrp *rgrp; /* Rendez group */
  585. Fgrp *closingfgrp; /* used during teardown */
  586. ulong parentpid;
  587. ulong time[6]; /* User, Sys, Real; child U, S, R */
  588. uvlong kentry; /* Kernel entry time stamp (for profiling) */
  589. /*
  590. * pcycles: cycles spent in this process (updated on procsave/restore)
  591. * when this is the current proc and we're in the kernel
  592. * (procrestores outnumber procsaves by one)
  593. * the number of cycles spent in the proc is pcycles + cycles()
  594. * when this is not the current process or we're in user mode
  595. * (procrestores and procsaves balance), it is pcycles.
  596. */
  597. vlong pcycles;
  598. int insyscall;
  599. int fpstate;
  600. QLock debug; /* to access debugging elements of User */
  601. Proc *pdbg; /* the debugging process */
  602. ulong procmode; /* proc device file mode */
  603. ulong privatemem; /* proc does not let anyone read mem */
  604. int hang; /* hang at next exec for debug */
  605. int procctl; /* Control for /proc debugging */
  606. ulong pc; /* DEBUG only */
  607. Lock rlock; /* sync sleep/wakeup with postnote */
  608. Rendez *r; /* rendezvous point slept on */
  609. Rendez sleep; /* place for syssleep/debug */
  610. int notepending; /* note issued but not acted on */
  611. int kp; /* true if a kernel process */
  612. Proc *palarm; /* Next alarm time */
  613. ulong alarm; /* Time of call */
  614. int newtlb; /* Pager has changed my pte's, I must flush */
  615. int noswap; /* process is not swappable */
  616. uintptr rendtag; /* Tag for rendezvous */
  617. uintptr rendval; /* Value for rendezvous */
  618. Proc *rendhash; /* Hash list for tag values */
  619. Timer; /* For tsleep and real-time */
  620. Rendez *trend;
  621. int (*tfn)(void*);
  622. void (*kpfun)(void*);
  623. void *kparg;
  624. FPsave fpsave; /* address of this is known by db */
  625. int scallnr; /* sys call number - known by db */
  626. Sargs s; /* address of this is known by db */
  627. int nerrlab;
  628. Label errlab[NERR];
  629. char *syserrstr; /* last error from a system call, errbuf0 or 1 */
  630. char *errstr; /* reason we're unwinding the error stack, errbuf1 or 0 */
  631. char errbuf0[ERRMAX];
  632. char errbuf1[ERRMAX];
  633. char genbuf[128]; /* buffer used e.g. for last name element from namec */
  634. Chan *slash;
  635. Chan *dot;
  636. Note note[NNOTE];
  637. short nnote;
  638. short notified; /* sysnoted is due */
  639. Note lastnote;
  640. int (*notify)(void*, char*);
  641. Lock *lockwait;
  642. Lock *lastlock; /* debugging */
  643. Lock *lastilock; /* debugging */
  644. Mach *wired;
  645. Mach *mp; /* machine this process last ran on */
  646. Ref nlocks; /* number of locks held by proc */
  647. ulong delaysched;
  648. ulong priority; /* priority level */
  649. ulong basepri; /* base priority level */
  650. uchar fixedpri; /* priority level deson't change */
  651. ulong cpu; /* cpu average */
  652. ulong lastupdate;
  653. uchar yield; /* non-zero if the process just did a sleep(0) */
  654. ulong readytime; /* time process came ready */
  655. ulong movetime; /* last time process switched processors */
  656. int preempted; /* true if this process hasn't finished the interrupt
  657. * that last preempted it
  658. */
  659. Edf *edf; /* if non-null, real-time proc, edf contains scheduling params */
  660. int trace; /* process being traced? */
  661. ulong qpc; /* pc calling last blocking qlock */
  662. int setargs;
  663. void *ureg; /* User registers for notes */
  664. void *dbgreg; /* User registers for devproc */
  665. Notsave;
  666. /*
  667. * machine specific MMU
  668. */
  669. PMMU;
  670. };
  671. enum
  672. {
  673. PRINTSIZE = 256,
  674. MAXCRYPT = 127,
  675. NUMSIZE = 12, /* size of formatted number */
  676. MB = (1024*1024),
  677. READSTR = 1000, /* temporary buffer size for device reads */
  678. };
  679. extern Conf conf;
  680. extern char* conffile;
  681. extern int cpuserver;
  682. extern Dev* devtab[];
  683. extern char* eve;
  684. extern char hostdomain[];
  685. extern uchar initcode[];
  686. extern int kbdbuttons;
  687. extern Queue* kbdq;
  688. extern Queue* kprintoq;
  689. extern Ref noteidalloc;
  690. extern int nsyscall;
  691. extern Palloc palloc;
  692. extern Queue* serialoq;
  693. extern char* statename[];
  694. extern Image swapimage;
  695. extern char* sysname;
  696. extern uint qiomaxatomic;
  697. enum
  698. {
  699. LRESPROF = 3,
  700. };
  701. /*
  702. * action log
  703. */
  704. struct Log {
  705. Lock;
  706. int opens;
  707. char* buf;
  708. char *end;
  709. char *rptr;
  710. int len;
  711. int nlog;
  712. int minread;
  713. int logmask; /* mask of things to debug */
  714. QLock readq;
  715. Rendez readr;
  716. };
  717. struct Logflag {
  718. char* name;
  719. int mask;
  720. };
  721. enum
  722. {
  723. NCMDFIELD = 128
  724. };
  725. struct Cmdbuf
  726. {
  727. char *buf;
  728. char **f;
  729. int nf;
  730. };
  731. struct Cmdtab
  732. {
  733. int index; /* used by client to switch on result */
  734. char *cmd; /* command name */
  735. int narg; /* expected #args; 0 ==> variadic */
  736. };
  737. /*
  738. * routines to access UART hardware
  739. */
  740. struct PhysUart
  741. {
  742. char* name;
  743. Uart* (*pnp)(void);
  744. void (*enable)(Uart*, int);
  745. void (*disable)(Uart*);
  746. void (*kick)(Uart*);
  747. void (*dobreak)(Uart*, int);
  748. int (*baud)(Uart*, int);
  749. int (*bits)(Uart*, int);
  750. int (*stop)(Uart*, int);
  751. int (*parity)(Uart*, int);
  752. void (*modemctl)(Uart*, int);
  753. void (*rts)(Uart*, int);
  754. void (*dtr)(Uart*, int);
  755. long (*status)(Uart*, void*, long, long);
  756. void (*fifo)(Uart*, int);
  757. void (*power)(Uart*, int);
  758. int (*getc)(Uart*); /* polling versions, for iprint, rdb */
  759. void (*putc)(Uart*, int);
  760. };
  761. enum {
  762. Stagesize= 2048
  763. };
  764. /*
  765. * software UART
  766. */
  767. struct Uart
  768. {
  769. void* regs; /* hardware stuff */
  770. void* saveregs; /* place to put registers on power down */
  771. char* name; /* internal name */
  772. ulong freq; /* clock frequency */
  773. int bits; /* bits per character */
  774. int stop; /* stop bits */
  775. int parity; /* even, odd or no parity */
  776. int baud; /* baud rate */
  777. PhysUart*phys;
  778. int console; /* used as a serial console */
  779. int special; /* internal kernel device */
  780. Uart* next; /* list of allocated uarts */
  781. QLock;
  782. int type; /* ?? */
  783. int dev;
  784. int opens;
  785. int enabled;
  786. Uart *elist; /* next enabled interface */
  787. int perr; /* parity errors */
  788. int ferr; /* framing errors */
  789. int oerr; /* rcvr overruns */
  790. int berr; /* no input buffers */
  791. int serr; /* input queue overflow */
  792. /* buffers */
  793. int (*putc)(Queue*, int);
  794. Queue *iq;
  795. Queue *oq;
  796. Lock rlock;
  797. uchar istage[Stagesize];
  798. uchar *iw;
  799. uchar *ir;
  800. uchar *ie;
  801. Lock tlock; /* transmit */
  802. uchar ostage[Stagesize];
  803. uchar *op;
  804. uchar *oe;
  805. int drain;
  806. int modem; /* hardware flow control on */
  807. int xonoff; /* software flow control on */
  808. int blocked;
  809. int cts, dsr, dcd; /* keep track of modem status */
  810. int ctsbackoff;
  811. int hup_dsr, hup_dcd; /* send hangup upstream? */
  812. int dohup;
  813. Rendez r;
  814. };
  815. extern Uart* consuart;
  816. /*
  817. * performance timers, all units in perfticks
  818. */
  819. struct Perf
  820. {
  821. ulong intrts; /* time of last interrupt */
  822. ulong inintr; /* time since last clock tick in interrupt handlers */
  823. ulong avg_inintr; /* avg time per clock tick in interrupt handlers */
  824. ulong inidle; /* time since last clock tick in idle loop */
  825. ulong avg_inidle; /* avg time per clock tick in idle loop */
  826. ulong last; /* value of perfticks() at last clock tick */
  827. ulong period; /* perfticks() per clock tick */
  828. };
  829. struct Watchdog
  830. {
  831. void (*enable)(void); /* watchdog enable */
  832. void (*disable)(void); /* watchdog disable */
  833. void (*restart)(void); /* watchdog restart */
  834. void (*stat)(char*, char*); /* watchdog statistics */
  835. };
  836. /* queue state bits, Qmsg, Qcoalesce, and Qkick can be set in qopen */
  837. enum
  838. {
  839. /* Queue.state */
  840. Qstarve = (1<<0), /* consumer starved */
  841. Qmsg = (1<<1), /* message stream */
  842. Qclosed = (1<<2), /* queue has been closed/hungup */
  843. Qflow = (1<<3), /* producer flow controlled */
  844. Qcoalesce = (1<<4), /* coallesce packets on read */
  845. Qkick = (1<<5), /* always call the kick routine after qwrite */
  846. };
  847. #define DEVDOTDOT -1
  848. #pragma varargck type "I" uchar*
  849. #pragma varargck type "V" uchar*
  850. #pragma varargck type "E" uchar*
  851. #pragma varargck type "M" uchar*