]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/pc/dat.h
pc, pc64: increase confmem slots to 64
[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         ulong   npage;          /* total physical pages of memory */
124         ulong   upages;         /* user page pool */
125         ulong   nimage;         /* number of page cache image headers */
126         ulong   nswap;          /* number of swap pages */
127         int     nswppo;         /* max # of pageouts per segment pass */
128         ulong   copymode;       /* 0 is copy on write, 1 is copy on reference */
129         ulong   ialloc;         /* max interrupt time allocation in bytes */
130         ulong   pipeqsize;      /* size in bytes of pipe queues */
131         int     nuart;          /* number of uart devices */
132         Confmem mem[64];        /* physical memory */
133 };
134
135 struct Segdesc
136 {
137         ulong   d0;
138         ulong   d1;
139 };
140
141 /*
142  *  MMU stuff in proc
143  */
144 #define NCOLOR 1
145 struct PMMU
146 {
147         Page*   mmupdb;                 /* page directory base */
148         Page*   mmufree;                /* unused page table pages */
149         Page*   mmuused;                /* used page table pages */
150         Page*   kmaptable;              /* page table used by kmap */
151         uint    lastkmap;               /* last entry used by kmap */
152         int     nkmap;                  /* number of current kmaps */
153
154         Segdesc gdt[NPROCSEG];  /* per process descriptors */
155         Segdesc *ldt;   /* local descriptor table */
156         int     nldt;   /* number of ldt descriptors allocated */
157         
158         u32int  dr[8];                  /* debug registers */
159         void    *vmx;
160 };
161
162 #include "../port/portdat.h"
163
164 typedef struct {
165         ulong   link;                   /* link (old TSS selector) */
166         ulong   esp0;                   /* privilege level 0 stack pointer */
167         ulong   ss0;                    /* privilege level 0 stack selector */
168         ulong   esp1;                   /* privilege level 1 stack pointer */
169         ulong   ss1;                    /* privilege level 1 stack selector */
170         ulong   esp2;                   /* privilege level 2 stack pointer */
171         ulong   ss2;                    /* privilege level 2 stack selector */
172         ulong   xcr3;                   /* page directory base register - not used because we don't use trap gates */
173         ulong   eip;                    /* instruction pointer */
174         ulong   eflags;                 /* flags register */
175         ulong   eax;                    /* general registers */
176         ulong   ecx;
177         ulong   edx;
178         ulong   ebx;
179         ulong   esp;
180         ulong   ebp;
181         ulong   esi;
182         ulong   edi;
183         ulong   es;                     /* segment selectors */
184         ulong   cs;
185         ulong   ss;
186         ulong   ds;
187         ulong   fs;
188         ulong   gs;
189         ulong   ldt;                    /* selector for task's LDT */
190         ulong   iomap;                  /* I/O map base address + T-bit */
191 } Tss;
192
193
194 struct Mach
195 {
196         int     machno;                 /* physical id of processor */
197         uintptr splpc;                  /* pc of last caller to splhi */
198         Proc*   proc;                   /* current process on this processor */
199         Proc*   externup;               /* extern register Proc *up */
200
201         PMach;
202
203         uvlong  tscticks;
204         ulong   spuriousintr;
205         int     lastintr;
206
207         int     loopconst;
208         int     aalcycles;
209         int     cpumhz;
210         uvlong  cpuhz;
211
212         int     cpuidax;
213         int     cpuidcx;
214         int     cpuiddx;
215         char    cpuidid[16];
216         char*   cpuidtype;
217         uchar   cpuidfamily;
218         uchar   cpuidmodel;
219         uchar   cpuidstepping;
220
221         char    havetsc;
222         char    havepge;
223         char    havewatchpt8;
224         char    havenx;
225
226         ulong*  pdb;                    /* page directory base for this processor (va) */
227         Tss*    tss;                    /* tss for this processor */
228         Segdesc*gdt;                    /* gdt for this processor */
229         
230         u32int  dr7;                    /* shadow copy of dr7 */
231         u32int  xcr0;
232         void*   vmx;
233
234         Page*   pdbpool;
235         int     pdbcnt;
236         int     pdballoc;
237         int     pdbfree;
238
239         uintptr stack[1];
240 };
241
242 /*
243  * KMap the structure doesn't exist, but the functions do.
244  */
245 typedef struct KMap             KMap;
246 #define VA(k)           ((void*)(k))
247 KMap*   kmap(Page*);
248 void    kunmap(KMap*);
249
250 extern u32int MemMin;
251
252 struct
253 {
254         char    machs[MAXMACH];         /* active CPUs */
255         int     exiting;                /* shutdown */
256 }active;
257
258 /*
259  *  routines for things outside the PC model, like power management
260  */
261 struct PCArch
262 {
263         char*   id;
264         int     (*ident)(void);         /* this should be in the model */
265         void    (*reset)(void);         /* this should be in the model */
266
267         void    (*intrinit)(void);
268         int     (*intrassign)(Vctl*);
269         int     (*intrirqno)(int, int);
270         int     (*intrspurious)(int);
271         int     (*intrvecno)(int);
272         void    (*introff)(void);
273         void    (*intron)(void);
274
275         void    (*clockinit)(void);
276         void    (*clockenable)(void);
277         uvlong  (*fastclock)(uvlong*);
278         void    (*timerset)(uvlong);
279 };
280
281 /* cpuid instruction result register bits */
282 enum {
283         /* cx */
284         Monitor = 1<<3,
285
286         /* dx */
287         Fpuonchip = 1<<0,
288         Vmex    = 1<<1,         /* virtual-mode extensions */
289         Pse     = 1<<3,         /* page size extensions */
290         Tsc     = 1<<4,         /* time-stamp counter */
291         Cpumsr  = 1<<5,         /* model-specific registers, rdmsr/wrmsr */
292         Pae     = 1<<6,         /* physical-addr extensions */
293         Mce     = 1<<7,         /* machine-check exception */
294         Cmpxchg8b = 1<<8,
295         Cpuapic = 1<<9,
296         Mtrr    = 1<<12,        /* memory-type range regs.  */
297         Pge     = 1<<13,        /* page global extension */
298         Mca     = 1<<14,        /* machine-check architecture */
299         Pat     = 1<<16,        /* page attribute table */
300         Pse2    = 1<<17,        /* more page size extensions */
301         Clflush = 1<<19,
302         Acpif   = 1<<22,        /* therm control msr */
303         Mmx     = 1<<23,
304         Fxsr    = 1<<24,        /* have SSE FXSAVE/FXRSTOR */
305         Sse     = 1<<25,        /* thus sfence instr. */
306         Sse2    = 1<<26,        /* thus mfence & lfence instr.s */
307         Rdrnd   = 1<<30,        /* RDRAND support bit */
308 };
309
310 /* model-specific registers, for compatibility with pc64 code */
311 enum {
312         Efer            = 0xc0000080,           /* Extended Feature Enable */
313         Star            = 0xc0000081,           /* Legacy Target IP and [CS]S */
314         Lstar           = 0xc0000082,           /* Long Mode Target IP */
315         Cstar           = 0xc0000083,           /* Compatibility Target IP */
316         Sfmask          = 0xc0000084,           /* SYSCALL Flags Mask */
317         FSbase          = 0xc0000100,           /* 64-bit FS Base Address */
318         GSbase          = 0xc0000101,           /* 64-bit GS Base Address */
319         KernelGSbase    = 0xc0000102,           /* SWAPGS instruction */
320 };
321
322 /*
323  *  a parsed plan9.ini line
324  */
325 #define NISAOPT         8
326
327 struct ISAConf {
328         char    *type;
329         uvlong  port;
330         int     irq;
331         ulong   dma;
332         ulong   mem;
333         ulong   size;
334         ulong   freq;
335
336         int     nopt;
337         char    *opt[NISAOPT];
338 };
339
340 extern PCArch   *arch;                  /* PC architecture */
341
342 /*
343  * Each processor sees its own Mach structure at address MACHADDR.
344  * However, the Mach structures must also be available via the per-processor
345  * MMU information array machp, mainly for disambiguation and access to
346  * the clock which is only maintained by the bootstrap processor (0).
347  */
348 Mach* machp[MAXMACH];
349         
350 #define MACHP(n)        (machp[n])
351
352 extern Mach     *m;
353 #define up      (((Mach*)MACHADDR)->externup)
354
355 /*
356  *  hardware info about a device
357  */
358 typedef struct {
359         ulong   port;   
360         int     size;
361 } Devport;
362
363 struct DevConf
364 {
365         ulong   intnum;                 /* interrupt number */
366         char    *type;                  /* card type, malloced */
367         int     nports;                 /* Number of ports */
368         Devport *ports;                 /* The ports themselves */
369 };
370
371 typedef struct BIOS32ci {               /* BIOS32 Calling Interface */
372         u32int  eax;
373         u32int  ebx;
374         u32int  ecx;
375         u32int  edx;
376         u32int  esi;
377         u32int  edi;
378 } BIOS32ci;