portdat.h 22 KB

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