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 Cname Cname;
  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 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. Cname* name;
  176. };
  177. struct Cname
  178. {
  179. Ref;
  180. int alen; /* allocated length */
  181. int len; /* strlen(s) */
  182. char *s;
  183. };
  184. struct Dev
  185. {
  186. int dc;
  187. char* name;
  188. void (*reset)(void);
  189. void (*init)(void);
  190. void (*shutdown)(void);
  191. Chan* (*attach)(char*);
  192. Walkqid*(*walk)(Chan*, Chan*, char**, int);
  193. int (*stat)(Chan*, uchar*, int);
  194. Chan* (*open)(Chan*, int);
  195. void (*create)(Chan*, char*, int, ulong);
  196. void (*close)(Chan*);
  197. long (*read)(Chan*, void*, long, vlong);
  198. Block* (*bread)(Chan*, long, ulong);
  199. long (*write)(Chan*, void*, long, vlong);
  200. long (*bwrite)(Chan*, Block*, ulong);
  201. void (*remove)(Chan*);
  202. int (*wstat)(Chan*, uchar*, int);
  203. void (*power)(int); /* power mgt: power(1) => on, power (0) => off */
  204. int (*config)(int, char*, DevConf*); // returns nil on error
  205. };
  206. struct Dirtab
  207. {
  208. char name[KNAMELEN];
  209. Qid qid;
  210. vlong length;
  211. long perm;
  212. };
  213. struct Walkqid
  214. {
  215. Chan *clone;
  216. int nqid;
  217. Qid qid[1];
  218. };
  219. enum
  220. {
  221. NSMAX = 1000,
  222. NSLOG = 7,
  223. NSCACHE = (1<<NSLOG),
  224. };
  225. struct Mntwalk /* state for /proc/#/ns */
  226. {
  227. int cddone;
  228. ulong id;
  229. Mhead* mh;
  230. Mount* cm;
  231. };
  232. struct Mount
  233. {
  234. ulong mountid;
  235. Mount* next;
  236. Mhead* head;
  237. Mount* copy;
  238. Mount* order;
  239. Chan* to; /* channel replacing channel */
  240. int mflag;
  241. char *spec;
  242. };
  243. struct Mhead
  244. {
  245. Ref;
  246. RWlock lock;
  247. Chan* from; /* channel mounted upon */
  248. Mount* mount; /* what's mounted upon it */
  249. Mhead* hash; /* Hash chain */
  250. };
  251. struct Mnt
  252. {
  253. Lock;
  254. /* references are counted using c->ref; channels on this mount point incref(c->mchan) == Mnt.c */
  255. Chan *c; /* Channel to file service */
  256. Proc *rip; /* Reader in progress */
  257. Mntrpc *queue; /* Queue of pending requests on this channel */
  258. ulong id; /* Multiplexer id for channel check */
  259. Mnt *list; /* Free list */
  260. int flags; /* cache */
  261. int msize; /* data + IOHDRSZ */
  262. char *version; /* 9P version */
  263. Queue *q; /* input queue */
  264. };
  265. enum
  266. {
  267. NUser, /* note provided externally */
  268. NExit, /* deliver note quietly */
  269. NDebug, /* print debug message */
  270. };
  271. struct Note
  272. {
  273. char msg[ERRMAX];
  274. int flag; /* whether system posted it */
  275. };
  276. enum
  277. {
  278. PG_NOFLUSH = 0,
  279. PG_TXTFLUSH = 1, /* flush dcache and invalidate icache */
  280. PG_DATFLUSH = 2, /* flush both i & d caches (UNUSED) */
  281. PG_NEWCOL = 3, /* page has been recolored */
  282. PG_MOD = 0x01, /* software modified bit */
  283. PG_REF = 0x02, /* software referenced bit */
  284. };
  285. struct Page
  286. {
  287. Lock;
  288. ulong pa; /* Physical address in memory */
  289. ulong va; /* Virtual address for user */
  290. ulong daddr; /* Disc address on swap */
  291. ushort ref; /* Reference count */
  292. char modref; /* Simulated modify/reference bits */
  293. char color; /* Cache coloring */
  294. char cachectl[MAXMACH]; /* Cache flushing control for putmmu */
  295. Image *image; /* Associated text or swap image */
  296. Page *next; /* Lru free list */
  297. Page *prev;
  298. Page *hash; /* Image hash chains */
  299. };
  300. struct Swapalloc
  301. {
  302. Lock; /* Free map lock */
  303. int free; /* currently free swap pages */
  304. uchar* swmap; /* Base of swap map in memory */
  305. uchar* alloc; /* Round robin allocator */
  306. uchar* last; /* Speed swap allocation */
  307. uchar* top; /* Top of swap map */
  308. Rendez r; /* Pager kproc idle sleep */
  309. ulong highwater; /* Pager start threshold */
  310. ulong headroom; /* Space pager frees under highwater */
  311. }swapalloc;
  312. struct Image
  313. {
  314. Ref;
  315. Chan *c; /* channel to text file */
  316. Qid qid; /* Qid for page cache coherence */
  317. Qid mqid;
  318. Chan *mchan;
  319. ushort type; /* Device type of owning channel */
  320. Segment *s; /* TEXT segment for image if running */
  321. Image *hash; /* Qid hash chains */
  322. Image *next; /* Free list */
  323. int notext; /* no file associated */
  324. };
  325. struct Pte
  326. {
  327. Page *pages[PTEPERTAB]; /* Page map for this chunk of pte */
  328. Page **first; /* First used entry */
  329. Page **last; /* Last used entry */
  330. Pte *next; /* Free list */
  331. };
  332. /* Segment types */
  333. enum
  334. {
  335. SG_TYPE = 07, /* Mask type of segment */
  336. SG_TEXT = 00,
  337. SG_DATA = 01,
  338. SG_BSS = 02,
  339. SG_STACK = 03,
  340. SG_SHARED = 04,
  341. SG_PHYSICAL = 05,
  342. SG_RONLY = 0040, /* Segment is read only */
  343. SG_CEXEC = 0100, /* Detach at exec */
  344. };
  345. #define PG_ONSWAP 1
  346. #define onswap(s) (((ulong)s)&PG_ONSWAP)
  347. #define pagedout(s) (((ulong)s)==0 || onswap(s))
  348. #define swapaddr(s) (((ulong)s)&~PG_ONSWAP)
  349. #define SEGMAXSIZE (SEGMAPSIZE*PTEMAPMEM)
  350. struct Physseg
  351. {
  352. ulong attr; /* Segment attributes */
  353. char *name; /* Attach name */
  354. ulong pa; /* Physical address */
  355. ulong size; /* Maximum segment size in pages */
  356. Page *(*pgalloc)(Segment*, ulong); /* Allocation if we need it */
  357. void (*pgfree)(Page*);
  358. };
  359. struct Segment
  360. {
  361. Ref;
  362. QLock lk;
  363. ushort steal; /* Page stealer lock */
  364. ushort type; /* segment type */
  365. ulong base; /* virtual base */
  366. ulong top; /* virtual top */
  367. ulong size; /* size in pages */
  368. ulong fstart; /* start address in file for demand load */
  369. ulong flen; /* length of segment in file */
  370. int flushme; /* maintain icache for this segment */
  371. Image *image; /* text in file attached to this segment */
  372. Physseg *pseg;
  373. ulong* profile; /* Tick profile area */
  374. Pte **map;
  375. int mapsize;
  376. Pte *ssegmap[SSEGMAPSIZE];
  377. };
  378. enum
  379. {
  380. RENDLOG = 5,
  381. RENDHASH = 1<<RENDLOG, /* Hash to lookup rendezvous tags */
  382. MNTLOG = 5,
  383. MNTHASH = 1<<MNTLOG, /* Hash to walk mount table */
  384. NFD = 100, /* per process file descriptors */
  385. PGHLOG = 9,
  386. PGHSIZE = 1<<PGHLOG, /* Page hash for image lookup */
  387. };
  388. #define REND(p,s) ((p)->rendhash[(s)&((1<<RENDLOG)-1)])
  389. #define MOUNTH(p,qid) ((p)->mnthash[(qid).path&((1<<MNTLOG)-1)])
  390. struct Pgrp
  391. {
  392. Ref; /* also used as a lock when mounting */
  393. int noattach;
  394. ulong pgrpid;
  395. QLock debug; /* single access via devproc.c */
  396. RWlock ns; /* Namespace n read/one write lock */
  397. Mhead *mnthash[MNTHASH];
  398. };
  399. struct Rgrp
  400. {
  401. Ref; /* the Ref's lock is also the Rgrp's lock */
  402. Proc *rendhash[RENDHASH]; /* Rendezvous tag hash */
  403. };
  404. struct Egrp
  405. {
  406. Ref;
  407. RWlock;
  408. Evalue **ent;
  409. int nent;
  410. int ment;
  411. ulong path; /* qid.path of next Evalue to be allocated */
  412. ulong vers; /* of Egrp */
  413. };
  414. struct Evalue
  415. {
  416. char *name;
  417. char *value;
  418. int len;
  419. Evalue *link;
  420. Qid qid;
  421. };
  422. struct Fgrp
  423. {
  424. Ref;
  425. Chan **fd;
  426. int nfd; /* number allocated */
  427. int maxfd; /* highest fd in use */
  428. int exceed; /* debugging */
  429. };
  430. enum
  431. {
  432. DELTAFD = 20 /* incremental increase in Fgrp.fd's */
  433. };
  434. struct Palloc
  435. {
  436. Lock;
  437. ulong p0, p1; /* base of pages in bank 0/1 */
  438. ulong np0, np1; /* number of pages in bank 0/1 */
  439. Page *head; /* most recently used */
  440. Page *tail; /* least recently used */
  441. ulong freecount; /* how many pages on free list now */
  442. ulong user; /* how many user pages */
  443. Page *hash[PGHSIZE];
  444. Lock hashlock;
  445. Rendez r; /* Sleep for free mem */
  446. QLock pwait; /* Queue of procs waiting for memory */
  447. };
  448. struct Waitq
  449. {
  450. Waitmsg w;
  451. Waitq *next;
  452. };
  453. /*
  454. * fasttick timer interrupts
  455. */
  456. enum {
  457. /* Mode */
  458. Trelative, /* timer programmed in ns from now */
  459. Tabsolute, /* timer programmed in ns since epoch */
  460. Tperiodic, /* periodic timer, period in ns */
  461. };
  462. struct Timer
  463. {
  464. /* Public interface */
  465. int tmode; /* See above */
  466. vlong tns; /* meaning defined by mode */
  467. void (*tf)(Ureg*, Timer*);
  468. void *ta;
  469. /* Internal */
  470. Lock;
  471. Timers *tt; /* Timers queue this timer runs on */
  472. vlong twhen; /* ns represented in fastticks */
  473. Timer *tnext;
  474. };
  475. enum
  476. {
  477. RFNAMEG = (1<<0),
  478. RFENVG = (1<<1),
  479. RFFDG = (1<<2),
  480. RFNOTEG = (1<<3),
  481. RFPROC = (1<<4),
  482. RFMEM = (1<<5),
  483. RFNOWAIT = (1<<6),
  484. RFCNAMEG = (1<<10),
  485. RFCENVG = (1<<11),
  486. RFCFDG = (1<<12),
  487. RFREND = (1<<13),
  488. RFNOMNT = (1<<14),
  489. };
  490. /*
  491. * process memory segments - NSEG always last !
  492. */
  493. enum
  494. {
  495. SSEG, TSEG, DSEG, BSEG, ESEG, LSEG, SEG1, SEG2, SEG3, SEG4, NSEG
  496. };
  497. enum
  498. {
  499. Dead = 0, /* Process states */
  500. Moribund,
  501. Ready,
  502. Scheding,
  503. Running,
  504. Queueing,
  505. QueueingR,
  506. QueueingW,
  507. Wakeme,
  508. Broken,
  509. Stopped,
  510. Rendezvous,
  511. Waitrelease,
  512. Proc_stopme = 1, /* devproc requests */
  513. Proc_exitme,
  514. Proc_traceme,
  515. Proc_exitbig,
  516. Proc_tracesyscall,
  517. TUser = 0, /* Proc.time */
  518. TSys,
  519. TReal,
  520. TCUser,
  521. TCSys,
  522. TCReal,
  523. NERR = 64,
  524. NNOTE = 5,
  525. Npriq = 20, /* number of scheduler priority levels */
  526. Nrq = Npriq+2, /* number of priority levels including real time */
  527. PriRelease = Npriq, /* released edf processes */
  528. PriEdf = Npriq+1, /* active edf processes */
  529. PriExtra = 0, /* edf processes we don't care about */
  530. PriNormal = 10, /* base priority for normal processes */
  531. PriKproc = 13, /* base priority for kernel processes */
  532. PriRoot = 13, /* base priority for root processes */
  533. };
  534. typedef uvlong Ticks;
  535. struct Schedq
  536. {
  537. Lock;
  538. Proc* head;
  539. Proc* tail;
  540. int n;
  541. };
  542. struct Proc
  543. {
  544. Label sched; /* known to l.s */
  545. char *kstack; /* known to l.s */
  546. Mach *mach; /* machine running this proc */
  547. char *text;
  548. char *user;
  549. char *args;
  550. int nargs; /* number of bytes of args */
  551. Proc *rnext; /* next process in run queue */
  552. Proc *qnext; /* next process on queue for a QLock */
  553. QLock *qlock; /* addr of qlock being queued for DEBUG */
  554. int state;
  555. char *psstate; /* What /proc/#/status reports */
  556. Segment *seg[NSEG];
  557. QLock seglock; /* locked whenever seg[] changes */
  558. ulong pid;
  559. ulong noteid; /* Equivalent of note group */
  560. Proc *pidhash; /* next proc in pid hash */
  561. Lock exl; /* Lock count and waitq */
  562. Waitq *waitq; /* Exited processes wait children */
  563. int nchild; /* Number of living children */
  564. int nwait; /* Number of uncollected wait records */
  565. QLock qwaitr;
  566. Rendez waitr; /* Place to hang out in wait */
  567. Proc *parent;
  568. Pgrp *pgrp; /* Process group for namespace */
  569. Egrp *egrp; /* Environment group */
  570. Fgrp *fgrp; /* File descriptor group */
  571. Rgrp *rgrp; /* Rendez group */
  572. ulong parentpid;
  573. ulong time[6]; /* User, Sys, Real; child U, S, R */
  574. uvlong kentry; /* Kernel entry time stamp (for profiling) */
  575. /*
  576. * pcycles: cycles spent in this process (updated on procsave/restore)
  577. * when this is the current proc and we're in the kernel
  578. * (procrestores outnumber procsaves by one)
  579. * the number of cycles spent in the proc is pcycles + cycles()
  580. * when this is not the current process or we're in user mode
  581. * (procrestores and procsaves balance), it is pcycles.
  582. */
  583. vlong pcycles;
  584. int insyscall;
  585. int fpstate;
  586. QLock debug; /* to access debugging elements of User */
  587. Proc *pdbg; /* the debugging process */
  588. ulong procmode; /* proc device file mode */
  589. ulong privatemem; /* proc does not let anyone read mem */
  590. int hang; /* hang at next exec for debug */
  591. int procctl; /* Control for /proc debugging */
  592. ulong pc; /* DEBUG only */
  593. Lock rlock; /* sync sleep/wakeup with postnote */
  594. Rendez *r; /* rendezvous point slept on */
  595. Rendez sleep; /* place for syssleep/debug */
  596. int notepending;/* note issued but not acted on */
  597. int kp; /* true if a kernel process */
  598. Proc *palarm; /* Next alarm time */
  599. ulong alarm; /* Time of call */
  600. int newtlb; /* Pager has changed my pte's, I must flush */
  601. int noswap; /* process is not swappable */
  602. ulong rendtag; /* Tag for rendezvous */
  603. ulong rendval; /* Value for rendezvous */
  604. Proc *rendhash; /* Hash list for tag values */
  605. Timer; /* For tsleep and real-time */
  606. Rendez *trend;
  607. int (*tfn)(void*);
  608. void (*kpfun)(void*);
  609. void *kparg;
  610. FPsave fpsave; /* address of this is known by db */
  611. int scallnr; /* sys call number - known by db */
  612. Sargs s; /* address of this is known by db */
  613. int nerrlab;
  614. Label errlab[NERR];
  615. char *syserrstr; /* last error from a system call, errbuf0 or 1 */
  616. char *errstr; /* reason we're unwinding the error stack, errbuf1 or 0 */
  617. char errbuf0[ERRMAX];
  618. char errbuf1[ERRMAX];
  619. char genbuf[128]; /* buffer used e.g. for last name element from namec */
  620. Chan *slash;
  621. Chan *dot;
  622. Note note[NNOTE];
  623. short nnote;
  624. short notified; /* sysnoted is due */
  625. Note lastnote;
  626. int (*notify)(void*, char*);
  627. Lock *lockwait;
  628. Lock *lastlock; /* debugging */
  629. Lock *lastilock; /* debugging */
  630. Mach *wired;
  631. Mach *mp; /* machine this process last ran on */
  632. Ref nlocks; /* number of locks held by proc */
  633. ulong delaysched;
  634. ulong priority; /* priority level */
  635. ulong basepri; /* base priority level */
  636. uchar fixedpri; /* priority level deson't change */
  637. ulong cpu; /* cpu average */
  638. ulong lastupdate;
  639. uchar yield; /* non-zero if the process just did a sleep(0) */
  640. ulong readytime; /* time process came ready */
  641. ulong movetime; /* last time process switched processors */
  642. int preempted; /* true if this process hasn't finished the interrupt
  643. * that last preempted it
  644. */
  645. Edf *edf; /* if non-null, real-time proc, edf contains scheduling params */
  646. int trace; /* process being traced? */
  647. ulong qpc; /* pc calling last blocking qlock */
  648. int setargs;
  649. void *ureg; /* User registers for notes */
  650. void *dbgreg; /* User registers for devproc */
  651. Notsave;
  652. /*
  653. * machine specific MMU
  654. */
  655. PMMU;
  656. };
  657. enum
  658. {
  659. PRINTSIZE = 256,
  660. MAXCRYPT = 127,
  661. NUMSIZE = 12, /* size of formatted number */
  662. MB = (1024*1024),
  663. READSTR = 1000, /* temporary buffer size for device reads */
  664. };
  665. extern Conf conf;
  666. extern char* conffile;
  667. extern int cpuserver;
  668. extern Dev* devtab[];
  669. extern char *eve;
  670. extern char hostdomain[];
  671. extern uchar initcode[];
  672. extern FPsave initfp;
  673. extern Queue* kbdq;
  674. extern Queue* kprintoq;
  675. extern Ref noteidalloc;
  676. extern Palloc palloc;
  677. extern Queue *serialoq;
  678. extern char* statename[];
  679. extern Image swapimage;
  680. extern int nsyscall;
  681. extern char *sysname;
  682. extern Talarm talarm;
  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 ','