portdat.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  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. ulong id;
  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 Segment
  357. {
  358. Ref;
  359. QLock lk;
  360. ushort steal; /* Page stealer lock */
  361. ushort type; /* segment type */
  362. ulong base; /* virtual base */
  363. ulong top; /* virtual top */
  364. ulong size; /* size in pages */
  365. ulong fstart; /* start address in file for demand load */
  366. ulong flen; /* length of segment in file */
  367. int flushme; /* maintain icache for this segment */
  368. Image *image; /* text in file attached to this segment */
  369. Physseg *pseg;
  370. ulong* profile; /* Tick profile area */
  371. Pte **map;
  372. int mapsize;
  373. Pte *ssegmap[SSEGMAPSIZE];
  374. ulong mark; /* portcountrefs */
  375. };
  376. enum
  377. {
  378. RENDLOG = 5,
  379. RENDHASH = 1<<RENDLOG, /* Hash to lookup rendezvous tags */
  380. MNTLOG = 5,
  381. MNTHASH = 1<<MNTLOG, /* Hash to walk mount table */
  382. NFD = 100, /* per process file descriptors */
  383. PGHLOG = 9,
  384. PGHSIZE = 1<<PGHLOG, /* Page hash for image lookup */
  385. };
  386. #define REND(p,s) ((p)->rendhash[(s)&((1<<RENDLOG)-1)])
  387. #define MOUNTH(p,qid) ((p)->mnthash[(qid).path&((1<<MNTLOG)-1)])
  388. struct Pgrp
  389. {
  390. Ref; /* also used as a lock when mounting */
  391. int noattach;
  392. ulong pgrpid;
  393. QLock debug; /* single access via devproc.c */
  394. RWlock ns; /* Namespace n read/one write lock */
  395. Mhead *mnthash[MNTHASH];
  396. };
  397. struct Rgrp
  398. {
  399. Ref; /* the Ref's lock is also the Rgrp's lock */
  400. Proc *rendhash[RENDHASH]; /* Rendezvous tag hash */
  401. };
  402. struct Egrp
  403. {
  404. Ref;
  405. RWlock;
  406. Evalue **ent;
  407. int nent;
  408. int ment;
  409. ulong path; /* qid.path of next Evalue to be allocated */
  410. ulong vers; /* of Egrp */
  411. };
  412. struct Evalue
  413. {
  414. char *name;
  415. char *value;
  416. int len;
  417. Evalue *link;
  418. Qid qid;
  419. };
  420. struct Fgrp
  421. {
  422. Ref;
  423. Chan **fd;
  424. int nfd; /* number allocated */
  425. int maxfd; /* highest fd in use */
  426. int exceed; /* debugging */
  427. };
  428. enum
  429. {
  430. DELTAFD = 20 /* incremental increase in Fgrp.fd's */
  431. };
  432. struct Pallocmem
  433. {
  434. ulong base;
  435. ulong npage;
  436. };
  437. struct Palloc
  438. {
  439. Lock;
  440. Pallocmem mem[4];
  441. Page *head; /* most recently used */
  442. Page *tail; /* least recently used */
  443. ulong freecount; /* how many pages on free list now */
  444. Page *pages; /* array of all pages */
  445. ulong user; /* how many user pages */
  446. Page *hash[PGHSIZE];
  447. Lock hashlock;
  448. Rendez r; /* Sleep for free mem */
  449. QLock pwait; /* Queue of procs waiting for memory */
  450. };
  451. struct Waitq
  452. {
  453. Waitmsg w;
  454. Waitq *next;
  455. };
  456. /*
  457. * fasttick timer interrupts
  458. */
  459. enum {
  460. /* Mode */
  461. Trelative, /* timer programmed in ns from now */
  462. Tabsolute, /* timer programmed in ns since epoch */
  463. Tperiodic, /* periodic timer, period in ns */
  464. };
  465. struct Timer
  466. {
  467. /* Public interface */
  468. int tmode; /* See above */
  469. vlong tns; /* meaning defined by mode */
  470. void (*tf)(Ureg*, Timer*);
  471. void *ta;
  472. /* Internal */
  473. Lock;
  474. Timers *tt; /* Timers queue this timer runs on */
  475. vlong twhen; /* ns represented in fastticks */
  476. Timer *tnext;
  477. };
  478. enum
  479. {
  480. RFNAMEG = (1<<0),
  481. RFENVG = (1<<1),
  482. RFFDG = (1<<2),
  483. RFNOTEG = (1<<3),
  484. RFPROC = (1<<4),
  485. RFMEM = (1<<5),
  486. RFNOWAIT = (1<<6),
  487. RFCNAMEG = (1<<10),
  488. RFCENVG = (1<<11),
  489. RFCFDG = (1<<12),
  490. RFREND = (1<<13),
  491. RFNOMNT = (1<<14),
  492. };
  493. /*
  494. * process memory segments - NSEG always last !
  495. */
  496. enum
  497. {
  498. SSEG, TSEG, DSEG, BSEG, ESEG, LSEG, SEG1, SEG2, SEG3, SEG4, NSEG
  499. };
  500. enum
  501. {
  502. Dead = 0, /* Process states */
  503. Moribund,
  504. Ready,
  505. Scheding,
  506. Running,
  507. Queueing,
  508. QueueingR,
  509. QueueingW,
  510. Wakeme,
  511. Broken,
  512. Stopped,
  513. Rendezvous,
  514. Waitrelease,
  515. Proc_stopme = 1, /* devproc requests */
  516. Proc_exitme,
  517. Proc_traceme,
  518. Proc_exitbig,
  519. Proc_tracesyscall,
  520. TUser = 0, /* Proc.time */
  521. TSys,
  522. TReal,
  523. TCUser,
  524. TCSys,
  525. TCReal,
  526. NERR = 64,
  527. NNOTE = 5,
  528. Npriq = 20, /* number of scheduler priority levels */
  529. Nrq = Npriq+2, /* number of priority levels including real time */
  530. PriRelease = Npriq, /* released edf processes */
  531. PriEdf = Npriq+1, /* active edf processes */
  532. PriExtra = 0, /* edf processes we don't care about */
  533. PriNormal = 10, /* base priority for normal processes */
  534. PriKproc = 13, /* base priority for kernel processes */
  535. PriRoot = 13, /* base priority for root processes */
  536. };
  537. struct Schedq
  538. {
  539. Lock;
  540. Proc* head;
  541. Proc* tail;
  542. int n;
  543. };
  544. struct Proc
  545. {
  546. Label sched; /* known to l.s */
  547. char *kstack; /* known to l.s */
  548. Mach *mach; /* machine running this proc */
  549. char *text;
  550. char *user;
  551. char *args;
  552. int nargs; /* number of bytes of args */
  553. Proc *rnext; /* next process in run queue */
  554. Proc *qnext; /* next process on queue for a QLock */
  555. QLock *qlock; /* addr of qlock being queued for DEBUG */
  556. int state;
  557. char *psstate; /* What /proc/#/status reports */
  558. Segment *seg[NSEG];
  559. QLock seglock; /* locked whenever seg[] changes */
  560. ulong pid;
  561. ulong noteid; /* Equivalent of note group */
  562. Proc *pidhash; /* next proc in pid hash */
  563. Lock exl; /* Lock count and waitq */
  564. Waitq *waitq; /* Exited processes wait children */
  565. int nchild; /* Number of living children */
  566. int nwait; /* Number of uncollected wait records */
  567. QLock qwaitr;
  568. Rendez waitr; /* Place to hang out in wait */
  569. Proc *parent;
  570. Pgrp *pgrp; /* Process group for namespace */
  571. Egrp *egrp; /* Environment group */
  572. Fgrp *fgrp; /* File descriptor group */
  573. Rgrp *rgrp; /* Rendez group */
  574. ulong parentpid;
  575. ulong time[6]; /* User, Sys, Real; child U, S, R */
  576. uvlong kentry; /* Kernel entry time stamp (for profiling) */
  577. /*
  578. * pcycles: cycles spent in this process (updated on procsave/restore)
  579. * when this is the current proc and we're in the kernel
  580. * (procrestores outnumber procsaves by one)
  581. * the number of cycles spent in the proc is pcycles + cycles()
  582. * when this is not the current process or we're in user mode
  583. * (procrestores and procsaves balance), it is pcycles.
  584. */
  585. vlong pcycles;
  586. int insyscall;
  587. int fpstate;
  588. QLock debug; /* to access debugging elements of User */
  589. Proc *pdbg; /* the debugging process */
  590. ulong procmode; /* proc device file mode */
  591. ulong privatemem; /* proc does not let anyone read mem */
  592. int hang; /* hang at next exec for debug */
  593. int procctl; /* Control for /proc debugging */
  594. ulong pc; /* DEBUG only */
  595. Lock rlock; /* sync sleep/wakeup with postnote */
  596. Rendez *r; /* rendezvous point slept on */
  597. Rendez sleep; /* place for syssleep/debug */
  598. int notepending; /* note issued but not acted on */
  599. int kp; /* true if a kernel process */
  600. Proc *palarm; /* Next alarm time */
  601. ulong alarm; /* Time of call */
  602. int newtlb; /* Pager has changed my pte's, I must flush */
  603. int noswap; /* process is not swappable */
  604. uintptr rendtag; /* Tag for rendezvous */
  605. uintptr rendval; /* Value for rendezvous */
  606. Proc *rendhash; /* Hash list for tag values */
  607. Timer; /* For tsleep and real-time */
  608. Rendez *trend;
  609. int (*tfn)(void*);
  610. void (*kpfun)(void*);
  611. void *kparg;
  612. FPsave fpsave; /* address of this is known by db */
  613. int scallnr; /* sys call number - known by db */
  614. Sargs s; /* address of this is known by db */
  615. int nerrlab;
  616. Label errlab[NERR];
  617. char *syserrstr; /* last error from a system call, errbuf0 or 1 */
  618. char *errstr; /* reason we're unwinding the error stack, errbuf1 or 0 */
  619. char errbuf0[ERRMAX];
  620. char errbuf1[ERRMAX];
  621. char genbuf[128]; /* buffer used e.g. for last name element from namec */
  622. Chan *slash;
  623. Chan *dot;
  624. Note note[NNOTE];
  625. short nnote;
  626. short notified; /* sysnoted is due */
  627. Note lastnote;
  628. int (*notify)(void*, char*);
  629. Lock *lockwait;
  630. Lock *lastlock; /* debugging */
  631. Lock *lastilock; /* debugging */
  632. Mach *wired;
  633. Mach *mp; /* machine this process last ran on */
  634. Ref nlocks; /* number of locks held by proc */
  635. ulong delaysched;
  636. ulong priority; /* priority level */
  637. ulong basepri; /* base priority level */
  638. uchar fixedpri; /* priority level deson't change */
  639. ulong cpu; /* cpu average */
  640. ulong lastupdate;
  641. uchar yield; /* non-zero if the process just did a sleep(0) */
  642. ulong readytime; /* time process came ready */
  643. ulong movetime; /* last time process switched processors */
  644. int preempted; /* true if this process hasn't finished the interrupt
  645. * that last preempted it
  646. */
  647. Edf *edf; /* if non-null, real-time proc, edf contains scheduling params */
  648. int trace; /* process being traced? */
  649. ulong qpc; /* pc calling last blocking qlock */
  650. int setargs;
  651. void *ureg; /* User registers for notes */
  652. void *dbgreg; /* User registers for devproc */
  653. Notsave;
  654. /*
  655. * machine specific MMU
  656. */
  657. PMMU;
  658. };
  659. enum
  660. {
  661. PRINTSIZE = 256,
  662. MAXCRYPT = 127,
  663. NUMSIZE = 12, /* size of formatted number */
  664. MB = (1024*1024),
  665. READSTR = 1000, /* temporary buffer size for device reads */
  666. };
  667. extern Conf conf;
  668. extern char* conffile;
  669. extern int cpuserver;
  670. extern Dev* devtab[];
  671. extern char* eve;
  672. extern char hostdomain[];
  673. extern uchar initcode[];
  674. extern int kbdbuttons;
  675. extern Queue* kbdq;
  676. extern Queue* kprintoq;
  677. extern Ref noteidalloc;
  678. extern int nsyscall;
  679. extern Palloc palloc;
  680. extern Queue* serialoq;
  681. extern char* statename[];
  682. extern Image swapimage;
  683. extern char* sysname;
  684. extern uint qiomaxatomic;
  685. enum
  686. {
  687. LRESPROF = 3,
  688. };
  689. /*
  690. * action log
  691. */
  692. struct Log {
  693. Lock;
  694. int opens;
  695. char* buf;
  696. char *end;
  697. char *rptr;
  698. int len;
  699. int nlog;
  700. int minread;
  701. int logmask; /* mask of things to debug */
  702. QLock readq;
  703. Rendez readr;
  704. };
  705. struct Logflag {
  706. char* name;
  707. int mask;
  708. };
  709. enum
  710. {
  711. NCMDFIELD = 128
  712. };
  713. struct Cmdbuf
  714. {
  715. char *buf;
  716. char **f;
  717. int nf;
  718. };
  719. struct Cmdtab
  720. {
  721. int index; /* used by client to switch on result */
  722. char *cmd; /* command name */
  723. int narg; /* expected #args; 0 ==> variadic */
  724. };
  725. /*
  726. * routines to access UART hardware
  727. */
  728. struct PhysUart
  729. {
  730. char* name;
  731. Uart* (*pnp)(void);
  732. void (*enable)(Uart*, int);
  733. void (*disable)(Uart*);
  734. void (*kick)(Uart*);
  735. void (*dobreak)(Uart*, int);
  736. int (*baud)(Uart*, int);
  737. int (*bits)(Uart*, int);
  738. int (*stop)(Uart*, int);
  739. int (*parity)(Uart*, int);
  740. void (*modemctl)(Uart*, int);
  741. void (*rts)(Uart*, int);
  742. void (*dtr)(Uart*, int);
  743. long (*status)(Uart*, void*, long, long);
  744. void (*fifo)(Uart*, int);
  745. void (*power)(Uart*, int);
  746. int (*getc)(Uart*); /* polling versions, for iprint, rdb */
  747. void (*putc)(Uart*, int);
  748. };
  749. enum {
  750. Stagesize= 2048
  751. };
  752. /*
  753. * software UART
  754. */
  755. struct Uart
  756. {
  757. void* regs; /* hardware stuff */
  758. void* saveregs; /* place to put registers on power down */
  759. char* name; /* internal name */
  760. ulong freq; /* clock frequency */
  761. int bits; /* bits per character */
  762. int stop; /* stop bits */
  763. int parity; /* even, odd or no parity */
  764. int baud; /* baud rate */
  765. PhysUart*phys;
  766. int console; /* used as a serial console */
  767. int special; /* internal kernel device */
  768. Uart* next; /* list of allocated uarts */
  769. QLock;
  770. int type; /* ?? */
  771. int dev;
  772. int opens;
  773. int enabled;
  774. Uart *elist; /* next enabled interface */
  775. int perr; /* parity errors */
  776. int ferr; /* framing errors */
  777. int oerr; /* rcvr overruns */
  778. int berr; /* no input buffers */
  779. int serr; /* input queue overflow */
  780. /* buffers */
  781. int (*putc)(Queue*, int);
  782. Queue *iq;
  783. Queue *oq;
  784. Lock rlock;
  785. uchar istage[Stagesize];
  786. uchar *iw;
  787. uchar *ir;
  788. uchar *ie;
  789. Lock tlock; /* transmit */
  790. uchar ostage[Stagesize];
  791. uchar *op;
  792. uchar *oe;
  793. int drain;
  794. int modem; /* hardware flow control on */
  795. int xonoff; /* software flow control on */
  796. int blocked;
  797. int cts, dsr, dcd, dcdts; /* keep track of modem status */
  798. int ctsbackoff;
  799. int hup_dsr, hup_dcd; /* send hangup upstream? */
  800. int dohup;
  801. Rendez r;
  802. };
  803. extern Uart* consuart;
  804. /*
  805. * performance timers, all units in perfticks
  806. */
  807. struct Perf
  808. {
  809. ulong intrts; /* time of last interrupt */
  810. ulong inintr; /* time since last clock tick in interrupt handlers */
  811. ulong avg_inintr; /* avg time per clock tick in interrupt handlers */
  812. ulong inidle; /* time since last clock tick in idle loop */
  813. ulong avg_inidle; /* avg time per clock tick in idle loop */
  814. ulong last; /* value of perfticks() at last clock tick */
  815. ulong period; /* perfticks() per clock tick */
  816. };
  817. struct Watchdog
  818. {
  819. void (*enable)(void); /* watchdog enable */
  820. void (*disable)(void); /* watchdog disable */
  821. void (*restart)(void); /* watchdog restart */
  822. void (*stat)(char*, char*); /* watchdog statistics */
  823. };
  824. /* queue state bits, Qmsg, Qcoalesce, and Qkick can be set in qopen */
  825. enum
  826. {
  827. /* Queue.state */
  828. Qstarve = (1<<0), /* consumer starved */
  829. Qmsg = (1<<1), /* message stream */
  830. Qclosed = (1<<2), /* queue has been closed/hungup */
  831. Qflow = (1<<3), /* producer flow controlled */
  832. Qcoalesce = (1<<4), /* coallesce packets on read */
  833. Qkick = (1<<5), /* always call the kick routine after qwrite */
  834. };
  835. #define DEVDOTDOT -1
  836. #pragma varargck argpos print 1
  837. #pragma varargck argpos snprint 3
  838. #pragma varargck argpos sprint 2
  839. #pragma varargck argpos fprint 2
  840. #pragma varargck argpos panic 1
  841. #pragma varargck type "lld" vlong
  842. #pragma varargck type "llx" vlong
  843. #pragma varargck type "lld" uvlong
  844. #pragma varargck type "llx" uvlong
  845. #pragma varargck type "lx" void*
  846. #pragma varargck type "ld" long
  847. #pragma varargck type "lx" long
  848. #pragma varargck type "ld" ulong
  849. #pragma varargck type "lx" ulong
  850. #pragma varargck type "d" int
  851. #pragma varargck type "x" int
  852. #pragma varargck type "c" int
  853. #pragma varargck type "C" int
  854. #pragma varargck type "d" uint
  855. #pragma varargck type "x" uint
  856. #pragma varargck type "c" uint
  857. #pragma varargck type "C" uint
  858. #pragma varargck type "s" char*
  859. #pragma varargck type "S" Rune*
  860. #pragma varargck type "r" void
  861. #pragma varargck type "%" void
  862. #pragma varargck type "I" uchar*
  863. #pragma varargck type "V" uchar*
  864. #pragma varargck type "E" uchar*
  865. #pragma varargck type "M" uchar*
  866. #pragma varargck type "p" void*
  867. #pragma varargck type "q" char*
  868. #pragma varargck flag ','