portdat.h 22 KB

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