portdat.h 22 KB

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