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 Sema Sema;
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*);
52 #pragma incomplete DevConf
53 #pragma incomplete Edf
54 #pragma incomplete Mntcache
55 #pragma incomplete Mntrpc
56 #pragma incomplete Queue
57 #pragma incomplete Timers
75 Lock use; /* to access Qlock structure */
76 Proc *head; /* next process waiting for object */
77 Proc *tail; /* last process waiting for object */
78 int locked; /* flag */
84 Proc *head; /* list of waiting processes */
86 ulong wpc; /* pc of writer */
87 Proc *wproc; /* writing proc */
88 int readers; /* number of readers */
89 int writer; /* number of writers */
100 ulong args[MAXSYSARG];
104 * Access types in namec & channel flags
108 Aaccess, /* as in stat, wstat */
109 Abind, /* for left-hand-side of bind */
110 Atodir, /* as in chdir */
112 Amount, /* to be mounted or mounted upon */
113 Acreate, /* is to be created */
114 Aremove, /* will be removed by caller */
116 COPEN = 0x0001, /* for i/o */
117 CMSG = 0x0002, /* the message channel for a mount */
118 /*rsc CCREATE = 0x0004, /* permits creation if c->mnt */
119 CCEXEC = 0x0008, /* close on exec */
120 CFREE = 0x0010, /* not in use */
121 CRCLOSE = 0x0020, /* remove on close */
122 CCACHE = 0x0080, /* client cache */
130 Bipck = (1<<2), /* ip checksum */
131 Budpck = (1<<3), /* udp checksum */
132 Btcpck = (1<<4), /* tcp checksum */
133 Bpktck = (1<<5), /* packet checksum */
141 uchar* rp; /* first unconsumed byte */
142 uchar* wp; /* first empty byte */
143 uchar* lim; /* 1 past the end of the buffer */
144 uchar* base; /* start of the buffer */
145 void (*free)(Block*);
147 ushort checksum; /* IP checksum of complete packet (minus media header) */
150 #define BLEN(s) ((s)->wp - (s)->rp)
151 #define BALLOC(s) ((s)->lim - (s)->base)
155 Ref; /* the Lock in this Ref is also Chan's lock */
156 Chan* next; /* allocation */
158 vlong offset; /* in fd */
159 vlong devoffset; /* in underlying device; see read */
162 ushort mode; /* read/write */
165 int fid; /* for devmnt */
166 ulong iounit; /* chunk size for i/o; 0==default */
167 Mhead* umh; /* mount point that derived Chan; used in unionread */
168 Chan* umc; /* channel in union; held for union read */
169 QLock umqlock; /* serialize unionreads */
170 int uri; /* union read index */
171 int dri; /* devdirread index */
172 uchar* dirrock; /* directory entry rock for translations */
177 Mntcache*mcp; /* Mount cache pointer */
178 Mnt* mux; /* Mnt for clients using me for messages */
181 Qid pgrpid; /* for #p/notepg */
182 ulong mid; /* for ns in devproc */
184 Chan* mchan; /* channel to mounted server */
185 Qid mqid; /* qid of root of mount point */
193 Chan **mtpt; /* mtpt history */
194 int len; /* strlen(s) */
195 int alen; /* allocated length of s */
196 int mlen; /* number of path elements */
197 int malen; /* allocated length of mtpt */
207 void (*shutdown)(void);
208 Chan* (*attach)(char*);
209 Walkqid*(*walk)(Chan*, Chan*, char**, int);
210 int (*stat)(Chan*, uchar*, int);
211 Chan* (*open)(Chan*, int);
212 Chan* (*create)(Chan*, char*, int, ulong);
213 void (*close)(Chan*);
214 long (*read)(Chan*, void*, long, vlong);
215 Block* (*bread)(Chan*, long, ulong);
216 long (*write)(Chan*, void*, long, vlong);
217 long (*bwrite)(Chan*, Block*, ulong);
218 void (*remove)(Chan*);
219 int (*wstat)(Chan*, uchar*, int);
220 void (*power)(int); /* power mgt: power(1) => on, power (0) => off */
221 int (*config)(int, char*, DevConf*); /* returns nil on error */
243 NSCACHE = (1<<NSLOG),
246 struct Mntwalk /* state for /proc/#/ns */
260 Chan* to; /* channel replacing channel */
269 Chan* from; /* channel mounted upon */
270 Mount* mount; /* what's mounted upon it */
271 Mhead* hash; /* Hash chain */
277 /* references are counted using c->ref; channels on this mount point incref(c->mchan) == Mnt.c */
278 Chan *c; /* Channel to file service */
279 Proc *rip; /* Reader in progress */
280 Mntrpc *queue; /* Queue of pending requests on this channel */
281 ulong id; /* Multiplexer id for channel check */
282 Mnt *list; /* Free list */
283 int flags; /* cache */
284 int msize; /* data + IOHDRSZ */
285 char *version; /* 9P version */
286 Queue *q; /* input queue */
291 NUser, /* note provided externally */
292 NExit, /* deliver note quietly */
293 NDebug, /* print debug message */
299 int flag; /* whether system posted it */
305 PG_TXTFLUSH = 1, /* flush dcache and invalidate icache */
306 PG_DATFLUSH = 2, /* flush both i & d caches (UNUSED) */
307 PG_NEWCOL = 3, /* page has been recolored */
309 PG_MOD = 0x01, /* software modified bit */
310 PG_REF = 0x02, /* software referenced bit */
316 ulong pa; /* Physical address in memory */
317 ulong va; /* Virtual address for user */
318 ulong daddr; /* Disc address on swap */
319 ulong gen; /* Generation counter for swap */
320 ushort ref; /* Reference count */
321 char modref; /* Simulated modify/reference bits */
322 char color; /* Cache coloring */
323 char cachectl[MAXMACH]; /* Cache flushing control for putmmu */
324 Image *image; /* Associated text or swap image */
325 Page *next; /* Lru free list */
327 Page *hash; /* Image hash chains */
332 Lock; /* Free map lock */
333 int free; /* currently free swap pages */
334 uchar* swmap; /* Base of swap map in memory */
335 uchar* alloc; /* Round robin allocator */
336 uchar* last; /* Speed swap allocation */
337 uchar* top; /* Top of swap map */
338 Rendez r; /* Pager kproc idle sleep */
339 ulong highwater; /* Pager start threshold */
340 ulong headroom; /* Space pager frees under highwater */
341 ulong xref; /* Ref count for all map refs >= 255 */
347 Chan *c; /* channel to text file */
348 Qid qid; /* Qid for page cache coherence */
351 ushort type; /* Device type of owning channel */
352 Segment *s; /* TEXT segment for image if running */
353 Image *hash; /* Qid hash chains */
354 Image *next; /* Free list */
355 int notext; /* no file associated */
360 Page *pages[PTEPERTAB]; /* Page map for this chunk of pte */
361 Page **first; /* First used entry */
362 Page **last; /* Last used entry */
368 SG_TYPE = 07, /* Mask type of segment */
376 SG_RONLY = 0040, /* Segment is read only */
377 SG_CEXEC = 0100, /* Detach at exec */
381 #define onswap(s) (((ulong)s)&PG_ONSWAP)
382 #define pagedout(s) (((ulong)s)==0 || onswap(s))
383 #define swapaddr(s) (((ulong)s)&~PG_ONSWAP)
385 #define SEGMAXSIZE (SEGMAPSIZE*PTEMAPMEM)
389 ulong attr; /* Segment attributes */
390 char *name; /* Attach name */
391 ulong pa; /* Physical address */
392 ulong size; /* Maximum segment size in pages */
393 Page *(*pgalloc)(Segment*, ulong); /* Allocation if we need it */
394 void (*pgfree)(Page*);
410 ushort steal; /* Page stealer lock */
411 ushort type; /* segment type */
412 ulong base; /* virtual base */
413 ulong top; /* virtual top */
414 ulong size; /* size in pages */
415 ulong fstart; /* start address in file for demand load */
416 ulong flen; /* length of segment in file */
417 int flushme; /* maintain icache for this segment */
418 Image *image; /* text in file attached to this segment */
420 ulong* profile; /* Tick profile area */
423 Pte *ssegmap[SSEGMAPSIZE];
426 ulong mark; /* portcountrefs */
432 RENDHASH = 1<<RENDLOG, /* Hash to lookup rendezvous tags */
434 MNTHASH = 1<<MNTLOG, /* Hash to walk mount table */
435 NFD = 100, /* per process file descriptors */
437 PGHSIZE = 1<<PGHLOG, /* Page hash for image lookup */
439 #define REND(p,s) ((p)->rendhash[(s)&((1<<RENDLOG)-1)])
440 #define MOUNTH(p,qid) ((p)->mnthash[(qid).path&((1<<MNTLOG)-1)])
444 Ref; /* also used as a lock when mounting */
447 QLock debug; /* single access via devproc.c */
448 RWlock ns; /* Namespace n read/one write lock */
449 Mhead *mnthash[MNTHASH];
454 Ref; /* the Ref's lock is also the Rgrp's lock */
455 Proc *rendhash[RENDHASH]; /* Rendezvous tag hash */
465 ulong path; /* qid.path of next Evalue to be allocated */
466 ulong vers; /* of Egrp */
482 int nfd; /* number allocated */
483 int maxfd; /* highest fd in use */
484 int exceed; /* debugging */
489 DELTAFD = 20 /* incremental increase in Fgrp.fd's */
502 Page *head; /* most recently used */
503 Page *tail; /* least recently used */
504 ulong freecount; /* how many pages on free list now */
505 Page *pages; /* array of all pages */
506 ulong user; /* how many user pages */
509 Rendez r; /* Sleep for free mem */
510 QLock pwait; /* Queue of procs waiting for memory */
520 * fasttick timer interrupts
524 Trelative, /* timer programmed in ns from now */
525 Tperiodic, /* periodic timer, period in ns */
530 /* Public interface */
531 int tmode; /* See above */
532 vlong tns; /* meaning defined by mode */
533 void (*tf)(Ureg*, Timer*);
537 Timers *tt; /* Timers queue this timer runs on */
538 Tval tticks; /* tns converted to ticks */
539 Tval twhen; /* ns represented in fastticks */
560 * process memory segments - NSEG always last !
564 SSEG, TSEG, DSEG, BSEG, ESEG, LSEG, SEG1, SEG2, SEG3, SEG4, NSEG
569 Dead = 0, /* Process states */
583 Proc_stopme = 1, /* devproc requests */
589 TUser = 0, /* Proc.time */
599 Npriq = 20, /* number of scheduler priority levels */
600 Nrq = Npriq+2, /* number of priority levels including real time */
601 PriRelease = Npriq, /* released edf processes */
602 PriEdf = Npriq+1, /* active edf processes */
603 PriNormal = 10, /* base priority for normal processes */
604 PriExtra = Npriq-1, /* edf processes at high best-effort pri */
605 PriKproc = 13, /* base priority for kernel processes */
606 PriRoot = 13, /* base priority for root processes */
619 Label sched; /* known to l.s */
620 char *kstack; /* known to l.s */
621 Mach *mach; /* machine running this proc */
625 int nargs; /* number of bytes of args */
626 Proc *rnext; /* next process in run queue */
627 Proc *qnext; /* next process on queue for a QLock */
628 QLock *qlock; /* addr of qlock being queued for DEBUG */
630 char *psstate; /* What /proc/#/status reports */
632 QLock seglock; /* locked whenever seg[] changes */
634 ulong noteid; /* Equivalent of note group */
635 Proc *pidhash; /* next proc in pid hash */
637 Lock exl; /* Lock count and waitq */
638 Waitq *waitq; /* Exited processes wait children */
639 int nchild; /* Number of living children */
640 int nwait; /* Number of uncollected wait records */
642 Rendez waitr; /* Place to hang out in wait */
645 Pgrp *pgrp; /* Process group for namespace */
646 Egrp *egrp; /* Environment group */
647 Fgrp *fgrp; /* File descriptor group */
648 Rgrp *rgrp; /* Rendez group */
650 Fgrp *closingfgrp; /* used during teardown */
653 ulong time[6]; /* User, Sys, Real; child U, S, R */
655 uvlong kentry; /* Kernel entry time stamp (for profiling) */
657 * pcycles: cycles spent in this process (updated on procsave/restore)
658 * when this is the current proc and we're in the kernel
659 * (procrestores outnumber procsaves by one)
660 * the number of cycles spent in the proc is pcycles + cycles()
661 * when this is not the current process or we're in user mode
662 * (procrestores and procsaves balance), it is pcycles.
669 QLock debug; /* to access debugging elements of User */
670 Proc *pdbg; /* the debugging process */
671 ulong procmode; /* proc device default file mode */
672 ulong privatemem; /* proc does not let anyone read mem */
673 int hang; /* hang at next exec for debug */
674 int procctl; /* Control for /proc debugging */
675 ulong pc; /* DEBUG only */
677 Lock rlock; /* sync sleep/wakeup with postnote */
678 Rendez *r; /* rendezvous point slept on */
679 Rendez sleep; /* place for syssleep/debug */
680 int notepending; /* note issued but not acted on */
681 int kp; /* true if a kernel process */
682 Proc *palarm; /* Next alarm time */
683 ulong alarm; /* Time of call */
684 int newtlb; /* Pager has changed my pte's, I must flush */
685 int noswap; /* process is not swappable */
687 uintptr rendtag; /* Tag for rendezvous */
688 uintptr rendval; /* Value for rendezvous */
689 Proc *rendhash; /* Hash list for tag values */
691 Timer; /* For tsleep and real-time */
694 void (*kpfun)(void*);
697 FPsave fpsave; /* address of this is known by db */
698 int scallnr; /* sys call number - known by db */
699 Sargs s; /* address of this is known by db */
702 char *syserrstr; /* last error from a system call, errbuf0 or 1 */
703 char *errstr; /* reason we're unwinding the error stack, errbuf1 or 0 */
704 char errbuf0[ERRMAX];
705 char errbuf1[ERRMAX];
706 char genbuf[128]; /* buffer used e.g. for last name element from namec */
712 short notified; /* sysnoted is due */
714 int (*notify)(void*, char*);
717 Lock *lastlock; /* debugging */
718 Lock *lastilock; /* debugging */
721 Mach *mp; /* machine this process last ran on */
722 Ref nlocks; /* number of locks held by proc */
724 ulong priority; /* priority level */
725 ulong basepri; /* base priority level */
726 uchar fixedpri; /* priority level deson't change */
727 ulong cpu; /* cpu average */
729 uchar yield; /* non-zero if the process just did a sleep(0) */
730 ulong readytime; /* time process came ready */
731 ulong movetime; /* last time process switched processors */
732 int preempted; /* true if this process hasn't finished the interrupt
733 * that last preempted it
735 Edf *edf; /* if non-null, real-time proc, edf contains scheduling params */
736 int trace; /* process being traced? */
738 ulong qpc; /* pc calling last blocking qlock */
739 QLock *eql; /* interruptable eqlock */
743 void *ureg; /* User registers for notes */
744 void *dbgreg; /* User registers for devproc */
748 * machine specific MMU
751 char *syscalltrace; /* syscall trace */
758 NUMSIZE = 12, /* size of formatted number */
760 /* READSTR was 1000, which is way too small for usb's ctl file */
761 READSTR = 4000, /* temporary buffer size for device reads */
765 extern char* conffile;
766 extern int cpuserver;
767 extern Dev* devtab[];
769 extern char hostdomain[];
770 extern uchar initcode[];
771 extern Queue* kprintoq;
773 extern Palloc palloc;
774 extern Queue* serialoq;
775 extern char* statename[];
776 extern Image swapimage;
777 extern char* sysname;
778 extern uint qiomaxatomic;
779 extern char* sysctab[];
799 int logmask; /* mask of things to debug */
824 int index; /* used by client to switch on result */
825 char *cmd; /* command name */
826 int narg; /* expected #args; 0 ==> variadic */
830 * routines to access UART hardware
836 void (*enable)(Uart*, int);
837 void (*disable)(Uart*);
839 void (*dobreak)(Uart*, int);
840 int (*baud)(Uart*, int);
841 int (*bits)(Uart*, int);
842 int (*stop)(Uart*, int);
843 int (*parity)(Uart*, int);
844 void (*modemctl)(Uart*, int);
845 void (*rts)(Uart*, int);
846 void (*dtr)(Uart*, int);
847 long (*status)(Uart*, void*, long, long);
848 void (*fifo)(Uart*, int);
849 void (*power)(Uart*, int);
850 int (*getc)(Uart*); /* polling versions, for iprint, rdb */
851 void (*putc)(Uart*, int);
863 void* regs; /* hardware stuff */
864 void* saveregs; /* place to put registers on power down */
865 char* name; /* internal name */
866 ulong freq; /* clock frequency */
867 int bits; /* bits per character */
868 int stop; /* stop bits */
869 int parity; /* even, odd or no parity */
870 int baud; /* baud rate */
872 int console; /* used as a serial console */
873 int special; /* internal kernel device */
874 Uart* next; /* list of allocated uarts */
882 Uart *elist; /* next enabled interface */
884 int perr; /* parity errors */
885 int ferr; /* framing errors */
886 int oerr; /* rcvr overruns */
887 int berr; /* no input buffers */
888 int serr; /* input queue overflow */
891 int (*putc)(Queue*, int);
896 uchar istage[Stagesize];
901 Lock tlock; /* transmit */
902 uchar ostage[Stagesize];
907 int modem; /* hardware flow control on */
908 int xonoff; /* software flow control on */
910 int cts, dsr, dcd; /* keep track of modem status */
912 int hup_dsr, hup_dcd; /* send hangup upstream? */
918 extern Uart* consuart;
921 * performance timers, all units in perfticks
925 ulong intrts; /* time of last interrupt */
926 ulong inintr; /* time since last clock tick in interrupt handlers */
927 ulong avg_inintr; /* avg time per clock tick in interrupt handlers */
928 ulong inidle; /* time since last clock tick in idle loop */
929 ulong avg_inidle; /* avg time per clock tick in idle loop */
930 ulong last; /* value of perfticks() at last clock tick */
931 ulong period; /* perfticks() per clock tick */
936 void (*enable)(void); /* watchdog enable */
937 void (*disable)(void); /* watchdog disable */
938 void (*restart)(void); /* watchdog restart */
939 void (*stat)(char*, char*); /* watchdog statistics */
943 /* queue state bits, Qmsg, Qcoalesce, and Qkick can be set in qopen */
947 Qstarve = (1<<0), /* consumer starved */
948 Qmsg = (1<<1), /* message stream */
949 Qclosed = (1<<2), /* queue has been closed/hungup */
950 Qflow = (1<<3), /* producer flow controlled */
951 Qcoalesce = (1<<4), /* coallesce packets on read */
952 Qkick = (1<<5), /* always call the kick routine after qwrite */
957 #pragma varargck type "I" uchar*
958 #pragma varargck type "V" uchar*
959 #pragma varargck type "E" uchar*
960 #pragma varargck type "M" uchar*