portdat.h 21 KB

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