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