portdat.h 22 KB

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