portdat.h 23 KB

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