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