1 typedef struct Alarms Alarms;
2 typedef struct Audio Audio;
3 typedef struct Block Block;
4 typedef struct Chan Chan;
5 typedef struct Cmdbuf Cmdbuf;
6 typedef struct Cmdtab Cmdtab;
7 typedef struct Confmem Confmem;
8 typedef struct Dev Dev;
9 typedef struct Dirtab Dirtab;
10 typedef struct Edf Edf;
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 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*);
53 #pragma incomplete DevConf
54 #pragma incomplete Edf
55 #pragma incomplete Mntcache
56 #pragma incomplete Mntrpc
57 #pragma incomplete Queue
58 #pragma incomplete Timers
76 Lock use; /* to access Qlock structure */
77 Proc *head; /* next process waiting for object */
78 Proc *tail; /* last process waiting for object */
79 int locked; /* flag */
85 Proc *head; /* list of waiting processes */
87 ulong wpc; /* pc of writer */
88 Proc *wproc; /* writing proc */
89 int readers; /* number of readers */
90 int writer; /* number of writers */
101 ulong args[MAXSYSARG];
105 * Access types in namec & channel flags
109 Aaccess, /* as in stat, wstat */
110 Abind, /* for left-hand-side of bind */
111 Atodir, /* as in chdir */
113 Amount, /* to be mounted or mounted upon */
114 Acreate, /* is to be created */
115 Aremove, /* will be removed by caller */
117 COPEN = 0x0001, /* for i/o */
118 CMSG = 0x0002, /* the message channel for a mount */
119 /*rsc CCREATE = 0x0004, /* permits creation if c->mnt */
120 CCEXEC = 0x0008, /* close on exec */
121 CFREE = 0x0010, /* not in use */
122 CRCLOSE = 0x0020, /* remove on close */
123 CCACHE = 0x0080, /* client cache */
131 Bipck = (1<<2), /* ip checksum */
132 Budpck = (1<<3), /* udp checksum */
133 Btcpck = (1<<4), /* tcp checksum */
134 Bpktck = (1<<5), /* packet checksum */
142 uchar* rp; /* first unconsumed byte */
143 uchar* wp; /* first empty byte */
144 uchar* lim; /* 1 past the end of the buffer */
145 uchar* base; /* start of the buffer */
146 void (*free)(Block*);
148 ushort checksum; /* IP checksum of complete packet (minus media header) */
151 #define BLEN(s) ((s)->wp - (s)->rp)
152 #define BALLOC(s) ((s)->lim - (s)->base)
156 Ref; /* the Lock in this Ref is also Chan's lock */
157 Chan* next; /* allocation */
159 vlong offset; /* in fd */
160 vlong devoffset; /* in underlying device; see read */
163 ushort mode; /* read/write */
166 int fid; /* for devmnt */
167 ulong iounit; /* chunk size for i/o; 0==default */
168 Mhead* umh; /* mount point that derived Chan; used in unionread */
169 Chan* umc; /* channel in union; held for union read */
170 QLock umqlock; /* serialize unionreads */
171 int uri; /* union read index */
172 int dri; /* devdirread index */
173 uchar* dirrock; /* directory entry rock for translations */
178 Mntcache*mcp; /* Mount cache pointer */
179 Mnt* mux; /* Mnt for clients using me for messages */
182 Qid pgrpid; /* for #p/notepg */
183 ulong mid; /* for ns in devproc */
185 Chan* mchan; /* channel to mounted server */
186 Qid mqid; /* qid of root of mount point */
194 Chan **mtpt; /* mtpt history */
195 int len; /* strlen(s) */
196 int alen; /* allocated length of s */
197 int mlen; /* number of path elements */
198 int malen; /* allocated length of mtpt */
208 void (*shutdown)(void);
209 Chan* (*attach)(char*);
210 Walkqid*(*walk)(Chan*, Chan*, char**, int);
211 int (*stat)(Chan*, uchar*, int);
212 Chan* (*open)(Chan*, int);
213 void (*create)(Chan*, char*, int, ulong);
214 void (*close)(Chan*);
215 long (*read)(Chan*, void*, long, vlong);
216 Block* (*bread)(Chan*, long, ulong);
217 long (*write)(Chan*, void*, long, vlong);
218 long (*bwrite)(Chan*, Block*, ulong);
219 void (*remove)(Chan*);
220 int (*wstat)(Chan*, uchar*, int);
221 void (*power)(int); /* power mgt: power(1) => on, power (0) => off */
222 int (*config)(int, char*, DevConf*); /* returns nil on error */
244 NSCACHE = (1<<NSLOG),
247 struct Mntwalk /* state for /proc/#/ns */
261 Chan* to; /* channel replacing channel */
270 Chan* from; /* channel mounted upon */
271 Mount* mount; /* what's mounted upon it */
272 Mhead* hash; /* Hash chain */
278 /* references are counted using c->ref; channels on this mount point incref(c->mchan) == Mnt.c */
279 Chan *c; /* Channel to file service */
280 Proc *rip; /* Reader in progress */
281 Mntrpc *queue; /* Queue of pending requests on this channel */
282 ulong id; /* Multiplexer id for channel check */
283 Mnt *list; /* Free list */
284 int flags; /* cache */
285 int msize; /* data + IOHDRSZ */
286 char *version; /* 9P version */
287 Queue *q; /* input queue */
292 NUser, /* note provided externally */
293 NExit, /* deliver note quietly */
294 NDebug, /* print debug message */
300 int flag; /* whether system posted it */
306 PG_TXTFLUSH = 1, /* flush dcache and invalidate icache */
307 PG_DATFLUSH = 2, /* flush both i & d caches (UNUSED) */
308 PG_NEWCOL = 3, /* page has been recolored */
310 PG_MOD = 0x01, /* software modified bit */
311 PG_REF = 0x02, /* software referenced bit */
317 ulong pa; /* Physical address in memory */
318 ulong va; /* Virtual address for user */
319 ulong daddr; /* Disc address on swap */
320 ulong gen; /* Generation counter for swap */
321 ushort ref; /* Reference count */
322 char modref; /* Simulated modify/reference bits */
323 char color; /* Cache coloring */
324 char cachectl[MAXMACH]; /* Cache flushing control for putmmu */
325 Image *image; /* Associated text or swap image */
326 Page *next; /* Lru free list */
328 Page *hash; /* Image hash chains */
333 Lock; /* Free map lock */
334 int free; /* currently free swap pages */
335 uchar* swmap; /* Base of swap map in memory */
336 uchar* alloc; /* Round robin allocator */
337 uchar* last; /* Speed swap allocation */
338 uchar* top; /* Top of swap map */
339 Rendez r; /* Pager kproc idle sleep */
340 ulong highwater; /* Pager start threshold */
341 ulong headroom; /* Space pager frees under highwater */
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 */
742 void *ureg; /* User registers for notes */
743 void *dbgreg; /* User registers for devproc */
747 * machine specific MMU
750 char *syscalltrace; /* syscall trace */
757 NUMSIZE = 12, /* size of formatted number */
759 /* READSTR was 1000, which is way too small for usb's ctl file */
760 READSTR = 4000, /* temporary buffer size for device reads */
764 extern char* conffile;
765 extern int cpuserver;
766 extern Dev* devtab[];
768 extern char hostdomain[];
769 extern uchar initcode[];
770 extern int kbdbuttons;
772 extern Queue* kprintoq;
773 extern Ref noteidalloc;
775 extern Palloc palloc;
776 extern Queue* serialoq;
777 extern char* statename[];
778 extern Image swapimage;
779 extern char* sysname;
780 extern uint qiomaxatomic;
781 extern char* sysctab[];
801 int logmask; /* mask of things to debug */
826 int index; /* used by client to switch on result */
827 char *cmd; /* command name */
828 int narg; /* expected #args; 0 ==> variadic */
832 * routines to access UART hardware
838 void (*enable)(Uart*, int);
839 void (*disable)(Uart*);
841 void (*dobreak)(Uart*, int);
842 int (*baud)(Uart*, int);
843 int (*bits)(Uart*, int);
844 int (*stop)(Uart*, int);
845 int (*parity)(Uart*, int);
846 void (*modemctl)(Uart*, int);
847 void (*rts)(Uart*, int);
848 void (*dtr)(Uart*, int);
849 long (*status)(Uart*, void*, long, long);
850 void (*fifo)(Uart*, int);
851 void (*power)(Uart*, int);
852 int (*getc)(Uart*); /* polling versions, for iprint, rdb */
853 void (*putc)(Uart*, int);
865 void* regs; /* hardware stuff */
866 void* saveregs; /* place to put registers on power down */
867 char* name; /* internal name */
868 ulong freq; /* clock frequency */
869 int bits; /* bits per character */
870 int stop; /* stop bits */
871 int parity; /* even, odd or no parity */
872 int baud; /* baud rate */
874 int console; /* used as a serial console */
875 int special; /* internal kernel device */
876 Uart* next; /* list of allocated uarts */
884 Uart *elist; /* next enabled interface */
886 int perr; /* parity errors */
887 int ferr; /* framing errors */
888 int oerr; /* rcvr overruns */
889 int berr; /* no input buffers */
890 int serr; /* input queue overflow */
893 int (*putc)(Queue*, int);
898 uchar istage[Stagesize];
903 Lock tlock; /* transmit */
904 uchar ostage[Stagesize];
909 int modem; /* hardware flow control on */
910 int xonoff; /* software flow control on */
912 int cts, dsr, dcd; /* keep track of modem status */
914 int hup_dsr, hup_dcd; /* send hangup upstream? */
920 extern Uart* consuart;
927 void (*attach)(Audio *);
928 long (*read)(Audio *, void *, long, vlong);
929 long (*write)(Audio *, void *, long, vlong);
930 long (*volread)(Audio *, void *, long, vlong);
931 long (*volwrite)(Audio *, void *, long, vlong);
932 void (*close)(Audio *);
933 long (*ctl)(Audio *, void *, long, vlong);
934 long (*status)(Audio *, void *, long, vlong);
935 long (*buffered)(Audio *);
940 * performance timers, all units in perfticks
944 ulong intrts; /* time of last interrupt */
945 ulong inintr; /* time since last clock tick in interrupt handlers */
946 ulong avg_inintr; /* avg time per clock tick in interrupt handlers */
947 ulong inidle; /* time since last clock tick in idle loop */
948 ulong avg_inidle; /* avg time per clock tick in idle loop */
949 ulong last; /* value of perfticks() at last clock tick */
950 ulong period; /* perfticks() per clock tick */
955 void (*enable)(void); /* watchdog enable */
956 void (*disable)(void); /* watchdog disable */
957 void (*restart)(void); /* watchdog restart */
958 void (*stat)(char*, char*); /* watchdog statistics */
962 /* queue state bits, Qmsg, Qcoalesce, and Qkick can be set in qopen */
966 Qstarve = (1<<0), /* consumer starved */
967 Qmsg = (1<<1), /* message stream */
968 Qclosed = (1<<2), /* queue has been closed/hungup */
969 Qflow = (1<<3), /* producer flow controlled */
970 Qcoalesce = (1<<4), /* coallesce packets on read */
971 Qkick = (1<<5), /* always call the kick routine after qwrite */
976 #pragma varargck type "I" uchar*
977 #pragma varargck type "V" uchar*
978 #pragma varargck type "E" uchar*
979 #pragma varargck type "M" uchar*