portdat.h 22 KB

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