]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/pc/dat.h
kernel: cleanup the software mouse cursor mess
[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   copymode;       /* 0 is copy on write, 1 is copy on reference */
130         ulong   ialloc;         /* max interrupt time allocation in bytes */
131         ulong   pipeqsize;      /* size in bytes of pipe queues */
132         int     nuart;          /* number of uart devices */
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 struct Mach
194 {
195         int     machno;                 /* physical id of processor (KNOWN TO ASSEMBLY) */
196         ulong   splpc;                  /* pc of last caller to splhi */
197
198         ulong*  pdb;                    /* page directory base for this processor (va) */
199         Tss*    tss;                    /* tss for this processor */
200         Segdesc *gdt;                   /* gdt for this processor */
201
202         Proc*   proc;                   /* current process on this processor */
203         Proc*   externup;               /* extern register Proc *up */
204
205         Page*   pdbpool;
206         int     pdbcnt;
207
208         ulong   ticks;                  /* of the clock since boot time */
209         Label   sched;                  /* scheduler wakeup */
210         Lock    alarmlock;              /* access to alarm list */
211         void*   alarm;                  /* alarms bound to this clock */
212         int     inclockintr;
213
214         Proc*   readied;                /* for runproc */
215         ulong   schedticks;             /* next forced context switch */
216
217         int     tlbfault;
218         int     tlbpurge;
219         int     pfault;
220         int     cs;
221         int     syscall;
222         int     load;
223         int     intr;
224         int     flushmmu;               /* make current proc flush it's mmu state */
225         int     ilockdepth;
226         Perf    perf;                   /* performance counters */
227
228         ulong   spuriousintr;
229         int     lastintr;
230
231         int     loopconst;
232
233         int     cpumhz;
234         uvlong  cyclefreq;              /* Frequency of user readable cycle counter */
235         uvlong  cpuhz;
236         int     cpuidax;
237         int     cpuidcx;
238         int     cpuiddx;
239         char    cpuidid[16];
240         char*   cpuidtype;
241         uchar   cpuidfamily;
242         uchar   cpuidmodel;
243         uchar   cpuidstepping;
244         int     havetsc;
245         int     havepge;
246         int     havewatchpt8;
247         int     havenx;
248         uvlong  tscticks;
249         int     pdballoc;
250         int     pdbfree;
251         
252         u32int  dr7;                    /* shadow copy of dr7 */
253         
254         void*   vmx;
255
256         int     stack[1];
257 };
258
259 /*
260  * KMap the structure doesn't exist, but the functions do.
261  */
262 typedef struct KMap             KMap;
263 #define VA(k)           ((void*)(k))
264 KMap*   kmap(Page*);
265 void    kunmap(KMap*);
266
267 extern u32int MemMin;
268
269 struct
270 {
271         char    machs[MAXMACH];         /* active CPUs */
272         int     exiting;                /* shutdown */
273 }active;
274
275 /*
276  *  routines for things outside the PC model, like power management
277  */
278 struct PCArch
279 {
280         char*   id;
281         int     (*ident)(void);         /* this should be in the model */
282         void    (*reset)(void);         /* this should be in the model */
283         int     (*serialpower)(int);    /* 1 == on, 0 == off */
284         int     (*modempower)(int);     /* 1 == on, 0 == off */
285
286         void    (*intrinit)(void);
287         int     (*intrenable)(Vctl*);
288         int     (*intrvecno)(int);
289         int     (*intrdisable)(int);
290         void    (*introff)(void);
291         void    (*intron)(void);
292
293         void    (*clockenable)(void);
294         uvlong  (*fastclock)(uvlong*);
295         void    (*timerset)(uvlong);
296 };
297
298 /* cpuid instruction result register bits */
299 enum {
300         /* cx */
301         Monitor = 1<<3,
302
303         /* dx */
304         Fpuonchip = 1<<0,
305         Vmex    = 1<<1,         /* virtual-mode extensions */
306         Pse     = 1<<3,         /* page size extensions */
307         Tsc     = 1<<4,         /* time-stamp counter */
308         Cpumsr  = 1<<5,         /* model-specific registers, rdmsr/wrmsr */
309         Pae     = 1<<6,         /* physical-addr extensions */
310         Mce     = 1<<7,         /* machine-check exception */
311         Cmpxchg8b = 1<<8,
312         Cpuapic = 1<<9,
313         Mtrr    = 1<<12,        /* memory-type range regs.  */
314         Pge     = 1<<13,        /* page global extension */
315         Mca     = 1<<14,        /* machine-check architecture */
316         Pat     = 1<<16,        /* page attribute table */
317         Pse2    = 1<<17,        /* more page size extensions */
318         Clflush = 1<<19,
319         Acpif   = 1<<22,        /* therm control msr */
320         Mmx     = 1<<23,
321         Fxsr    = 1<<24,        /* have SSE FXSAVE/FXRSTOR */
322         Sse     = 1<<25,        /* thus sfence instr. */
323         Sse2    = 1<<26,        /* thus mfence & lfence instr.s */
324         Rdrnd   = 1<<30,        /* RDRAND support bit */
325 };
326
327 /* model-specific registers, for compatibility with pc64 code */
328 enum {
329         Efer            = 0xc0000080,           /* Extended Feature Enable */
330         Star            = 0xc0000081,           /* Legacy Target IP and [CS]S */
331         Lstar           = 0xc0000082,           /* Long Mode Target IP */
332         Cstar           = 0xc0000083,           /* Compatibility Target IP */
333         Sfmask          = 0xc0000084,           /* SYSCALL Flags Mask */
334         FSbase          = 0xc0000100,           /* 64-bit FS Base Address */
335         GSbase          = 0xc0000101,           /* 64-bit GS Base Address */
336         KernelGSbase    = 0xc0000102,           /* SWAPGS instruction */
337 };
338
339 /*
340  *  a parsed plan9.ini line
341  */
342 #define NISAOPT         8
343
344 struct ISAConf {
345         char    *type;
346         ulong   port;
347         int     irq;
348         ulong   dma;
349         ulong   mem;
350         ulong   size;
351         ulong   freq;
352
353         int     nopt;
354         char    *opt[NISAOPT];
355 };
356
357 extern PCArch   *arch;                  /* PC architecture */
358
359 /*
360  * Each processor sees its own Mach structure at address MACHADDR.
361  * However, the Mach structures must also be available via the per-processor
362  * MMU information array machp, mainly for disambiguation and access to
363  * the clock which is only maintained by the bootstrap processor (0).
364  */
365 Mach* machp[MAXMACH];
366         
367 #define MACHP(n)        (machp[n])
368
369 extern Mach     *m;
370 #define up      (((Mach*)MACHADDR)->externup)
371
372 /*
373  *  hardware info about a device
374  */
375 typedef struct {
376         ulong   port;   
377         int     size;
378 } Devport;
379
380 struct DevConf
381 {
382         ulong   intnum;                 /* interrupt number */
383         char    *type;                  /* card type, malloced */
384         int     nports;                 /* Number of ports */
385         Devport *ports;                 /* The ports themselves */
386 };
387
388 typedef struct BIOS32ci {               /* BIOS32 Calling Interface */
389         u32int  eax;
390         u32int  ebx;
391         u32int  ecx;
392         u32int  edx;
393         u32int  esi;
394         u32int  edi;
395 } BIOS32ci;