]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/pc/dat.h
devip: cleanup rudp.c
[plan9front.git] / sys / src / 9 / pc / dat.h
1 typedef struct BIOS32si BIOS32si;
2 typedef struct BIOS32ci BIOS32ci;
3 typedef struct Conf     Conf;
4 typedef struct Confmem  Confmem;
5 typedef union FPsave    FPsave;
6 typedef struct FPx87state FPx87state;
7 typedef struct FPssestate FPssestate;
8 typedef struct PFPU     PFPU;
9 typedef struct ISAConf  ISAConf;
10 typedef struct Label    Label;
11 typedef struct Lock     Lock;
12 typedef struct MMU      MMU;
13 typedef struct Mach     Mach;
14 typedef struct PCArch   PCArch;
15 typedef struct Pcidev   Pcidev;
16 typedef struct PCMmap   PCMmap;
17 typedef struct PCMslot  PCMslot;
18 typedef struct Page     Page;
19 typedef struct PMMU     PMMU;
20 typedef struct Proc     Proc;
21 typedef struct Segdesc  Segdesc;
22 typedef vlong           Tval;
23 typedef struct Ureg     Ureg;
24 typedef struct Vctl     Vctl;
25
26 #pragma incomplete BIOS32si
27 #pragma incomplete Pcidev
28 #pragma incomplete Ureg
29
30 #define MAXSYSARG       5       /* for mount(fd, afd, mpt, flag, arg) */
31
32 /*
33  *  parameters for sysproc.c
34  */
35 #define AOUT_MAGIC      (I_MAGIC)
36
37 struct Lock
38 {
39         ulong   key;
40         ulong   sr;
41         uintptr pc;
42         Proc    *p;
43         Mach    *m;
44         ushort  isilock;
45         long    lockcycles;
46 };
47
48 struct Label
49 {
50         ulong   sp;
51         ulong   pc;
52 };
53
54 struct  FPx87state              /* x87 fp state */
55 {
56         ushort  control;
57         ushort  r1;
58         ushort  status;
59         ushort  r2;
60         ushort  tag;
61         ushort  r3;
62         ulong   pc;
63         ushort  selector;
64         ushort  opcode;
65         ulong   operand;
66         ushort  oselector;
67         ushort  r4;
68         uchar   regs[80];       /* floating point registers */
69 };
70
71 struct  FPssestate              /* SSE fp state */
72 {
73         ushort  fcw;            /* control */
74         ushort  fsw;            /* status */
75         ushort  ftw;            /* tag */
76         ushort  fop;            /* opcode */
77         ulong   fpuip;          /* pc */
78         ushort  cs;             /* pc segment */
79         ushort  rsrvd1;         /* reserved */
80         ulong   fpudp;          /* data pointer */
81         ushort  ds;             /* data pointer segment */
82         ushort  rsrvd2;
83         ulong   mxcsr;          /* MXCSR register state */
84         ulong   mxcsr_mask;     /* MXCSR mask register */
85         uchar   xregs[480];     /* extended registers */
86 };
87
88 union FPsave {
89         FPx87state;
90         FPssestate;
91 };
92
93 struct PFPU
94 {
95         int     fpstate;
96         FPsave  *fpsave;
97 };
98
99 enum
100 {
101         /* this is a state */
102         FPinit=         0,
103         FPactive=       1,
104         FPinactive=     2,
105
106         /* the following is a bit that can be or'd into the state */
107         FPillegal=      0x100,
108 };
109
110 struct Confmem
111 {
112         ulong   base;
113         ulong   npage;
114         ulong   kbase;
115         ulong   klimit;
116 };
117
118 struct Conf
119 {
120         ulong   nmach;          /* processors */
121         ulong   nproc;          /* processes */
122         ulong   monitor;        /* has monitor? */
123         Confmem mem[4];         /* physical memory */
124         ulong   npage;          /* total physical pages of memory */
125         ulong   upages;         /* user page pool */
126         ulong   nimage;         /* number of page cache image headers */
127         ulong   nswap;          /* number of swap pages */
128         int     nswppo;         /* max # of pageouts per segment pass */
129         ulong   base0;          /* base of bank 0 */
130         ulong   base1;          /* base of bank 1 */
131         ulong   copymode;       /* 0 is copy on write, 1 is copy on reference */
132         ulong   ialloc;         /* max interrupt time allocation in bytes */
133         ulong   pipeqsize;      /* size in bytes of pipe queues */
134         int     nuart;          /* number of uart devices */
135 };
136
137 struct Segdesc
138 {
139         ulong   d0;
140         ulong   d1;
141 };
142
143 /*
144  *  MMU stuff in proc
145  */
146 #define NCOLOR 1
147 struct PMMU
148 {
149         Page*   mmupdb;                 /* page directory base */
150         Page*   mmufree;                /* unused page table pages */
151         Page*   mmuused;                /* used page table pages */
152         Page*   kmaptable;              /* page table used by kmap */
153         uint    lastkmap;               /* last entry used by kmap */
154         int     nkmap;                  /* number of current kmaps */
155
156         Segdesc gdt[NPROCSEG];  /* per process descriptors */
157         Segdesc *ldt;   /* local descriptor table */
158         int     nldt;   /* number of ldt descriptors allocated */
159         
160         u32int  dr[8];                  /* debug registers */
161         void    *vmx;
162 };
163
164 #include "../port/portdat.h"
165
166 typedef struct {
167         ulong   link;                   /* link (old TSS selector) */
168         ulong   esp0;                   /* privilege level 0 stack pointer */
169         ulong   ss0;                    /* privilege level 0 stack selector */
170         ulong   esp1;                   /* privilege level 1 stack pointer */
171         ulong   ss1;                    /* privilege level 1 stack selector */
172         ulong   esp2;                   /* privilege level 2 stack pointer */
173         ulong   ss2;                    /* privilege level 2 stack selector */
174         ulong   xcr3;                   /* page directory base register - not used because we don't use trap gates */
175         ulong   eip;                    /* instruction pointer */
176         ulong   eflags;                 /* flags register */
177         ulong   eax;                    /* general registers */
178         ulong   ecx;
179         ulong   edx;
180         ulong   ebx;
181         ulong   esp;
182         ulong   ebp;
183         ulong   esi;
184         ulong   edi;
185         ulong   es;                     /* segment selectors */
186         ulong   cs;
187         ulong   ss;
188         ulong   ds;
189         ulong   fs;
190         ulong   gs;
191         ulong   ldt;                    /* selector for task's LDT */
192         ulong   iomap;                  /* I/O map base address + T-bit */
193 } Tss;
194
195 struct Mach
196 {
197         int     machno;                 /* physical id of processor (KNOWN TO ASSEMBLY) */
198         ulong   splpc;                  /* pc of last caller to splhi */
199
200         ulong*  pdb;                    /* page directory base for this processor (va) */
201         Tss*    tss;                    /* tss for this processor */
202         Segdesc *gdt;                   /* gdt for this processor */
203
204         Proc*   proc;                   /* current process on this processor */
205         Proc*   externup;               /* extern register Proc *up */
206
207         Page*   pdbpool;
208         int     pdbcnt;
209
210         ulong   ticks;                  /* of the clock since boot time */
211         Label   sched;                  /* scheduler wakeup */
212         Lock    alarmlock;              /* access to alarm list */
213         void*   alarm;                  /* alarms bound to this clock */
214         int     inclockintr;
215
216         Proc*   readied;                /* for runproc */
217         ulong   schedticks;             /* next forced context switch */
218
219         int     tlbfault;
220         int     tlbpurge;
221         int     pfault;
222         int     cs;
223         int     syscall;
224         int     load;
225         int     intr;
226         int     flushmmu;               /* make current proc flush it's mmu state */
227         int     ilockdepth;
228         Perf    perf;                   /* performance counters */
229
230         ulong   spuriousintr;
231         int     lastintr;
232
233         int     loopconst;
234
235         int     cpumhz;
236         uvlong  cyclefreq;              /* Frequency of user readable cycle counter */
237         uvlong  cpuhz;
238         int     cpuidax;
239         int     cpuidcx;
240         int     cpuiddx;
241         char    cpuidid[16];
242         char*   cpuidtype;
243         int     havetsc;
244         int     havepge;
245         int     havewatchpt8;
246         uvlong  tscticks;
247         int     pdballoc;
248         int     pdbfree;
249         
250         u32int  dr7;                    /* shadow copy of dr7 */
251         
252         void*   vmx;
253
254         int     stack[1];
255 };
256
257 /*
258  * KMap the structure doesn't exist, but the functions do.
259  */
260 typedef struct KMap             KMap;
261 #define VA(k)           ((void*)(k))
262 KMap*   kmap(Page*);
263 void    kunmap(KMap*);
264
265 extern u32int MemMin;
266
267 struct
268 {
269         char    machs[MAXMACH];         /* active CPUs */
270         int     exiting;                /* shutdown */
271 }active;
272
273 /*
274  *  routines for things outside the PC model, like power management
275  */
276 struct PCArch
277 {
278         char*   id;
279         int     (*ident)(void);         /* this should be in the model */
280         void    (*reset)(void);         /* this should be in the model */
281         int     (*serialpower)(int);    /* 1 == on, 0 == off */
282         int     (*modempower)(int);     /* 1 == on, 0 == off */
283
284         void    (*intrinit)(void);
285         int     (*intrenable)(Vctl*);
286         int     (*intrvecno)(int);
287         int     (*intrdisable)(int);
288         void    (*introff)(void);
289         void    (*intron)(void);
290
291         void    (*clockenable)(void);
292         uvlong  (*fastclock)(uvlong*);
293         void    (*timerset)(uvlong);
294 };
295
296 /* cpuid instruction result register bits */
297 enum {
298         /* cx */
299         Monitor = 1<<3,
300
301         /* dx */
302         Fpuonchip = 1<<0,
303         Vmex    = 1<<1,         /* virtual-mode extensions */
304         Pse     = 1<<3,         /* page size extensions */
305         Tsc     = 1<<4,         /* time-stamp counter */
306         Cpumsr  = 1<<5,         /* model-specific registers, rdmsr/wrmsr */
307         Pae     = 1<<6,         /* physical-addr extensions */
308         Mce     = 1<<7,         /* machine-check exception */
309         Cmpxchg8b = 1<<8,
310         Cpuapic = 1<<9,
311         Mtrr    = 1<<12,        /* memory-type range regs.  */
312         Pge     = 1<<13,        /* page global extension */
313         Mca     = 1<<14,        /* machine-check architecture */
314         Pat     = 1<<16,        /* page attribute table */
315         Pse2    = 1<<17,        /* more page size extensions */
316         Clflush = 1<<19,
317         Acpif   = 1<<22,        /* therm control msr */
318         Mmx     = 1<<23,
319         Fxsr    = 1<<24,        /* have SSE FXSAVE/FXRSTOR */
320         Sse     = 1<<25,        /* thus sfence instr. */
321         Sse2    = 1<<26,        /* thus mfence & lfence instr.s */
322         Rdrnd   = 1<<30,        /* RDRAND support bit */
323 };
324
325 /* model-specific registers, for compatibility with pc64 code */
326 enum {
327         Efer            = 0xc0000080,           /* Extended Feature Enable */
328         Star            = 0xc0000081,           /* Legacy Target IP and [CS]S */
329         Lstar           = 0xc0000082,           /* Long Mode Target IP */
330         Cstar           = 0xc0000083,           /* Compatibility Target IP */
331         Sfmask          = 0xc0000084,           /* SYSCALL Flags Mask */
332         FSbase          = 0xc0000100,           /* 64-bit FS Base Address */
333         GSbase          = 0xc0000101,           /* 64-bit GS Base Address */
334         KernelGSbase    = 0xc0000102,           /* SWAPGS instruction */
335 };
336
337 /*
338  *  a parsed plan9.ini line
339  */
340 #define NISAOPT         8
341
342 struct ISAConf {
343         char    *type;
344         ulong   port;
345         int     irq;
346         ulong   dma;
347         ulong   mem;
348         ulong   size;
349         ulong   freq;
350
351         int     nopt;
352         char    *opt[NISAOPT];
353 };
354
355 extern PCArch   *arch;                  /* PC architecture */
356
357 /*
358  * Each processor sees its own Mach structure at address MACHADDR.
359  * However, the Mach structures must also be available via the per-processor
360  * MMU information array machp, mainly for disambiguation and access to
361  * the clock which is only maintained by the bootstrap processor (0).
362  */
363 Mach* machp[MAXMACH];
364         
365 #define MACHP(n)        (machp[n])
366
367 extern Mach     *m;
368 #define up      (((Mach*)MACHADDR)->externup)
369
370 /*
371  *  hardware info about a device
372  */
373 typedef struct {
374         ulong   port;   
375         int     size;
376 } Devport;
377
378 struct DevConf
379 {
380         ulong   intnum;                 /* interrupt number */
381         char    *type;                  /* card type, malloced */
382         int     nports;                 /* Number of ports */
383         Devport *ports;                 /* The ports themselves */
384 };
385
386 typedef struct BIOS32ci {               /* BIOS32 Calling Interface */
387         u32int  eax;
388         u32int  ebx;
389         u32int  ecx;
390         u32int  edx;
391         u32int  esi;
392         u32int  edi;
393 } BIOS32ci;