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