]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/pc64/dat.h
games/galaxy: simplify zoom loop
[plan9front.git] / sys / src / 9 / pc64 / 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 Fxsave   Fxsave;
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      (S_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         uintptr sp;
51         uintptr pc;
52 };
53
54 /*
55  * FPsave.status
56  */
57 enum
58 {
59         /* this is a state */
60         FPinit=         0,
61         FPactive=       1,
62         FPinactive=     2,
63
64         /* the following is a bit that can be or'd into the state */
65         FPillegal=      0x100,
66 };
67
68 /*
69  * the FP regs must be stored here, not somewhere pointed to from here.
70  * port code assumes this.
71  */
72 struct Fxsave {
73         u16int  fcw;                    /* x87 control word */
74         u16int  fsw;                    /* x87 status word */
75         u8int   ftw;                    /* x87 tag word */
76         u8int   zero;                   /* 0 */
77         u16int  fop;                    /* last x87 opcode */
78         u64int  rip;                    /* last x87 instruction pointer */
79         u64int  rdp;                    /* last x87 data pointer */
80         u32int  mxcsr;                  /* MMX control and status */
81         u32int  mxcsrmask;              /* supported MMX feature bits */
82         uchar   st[128];                /* shared 64-bit media and x87 regs */
83         uchar   xmm[256];               /* 128-bit media regs */
84         uchar   ign[96];                /* reserved, ignored */
85 };
86
87 union FPsave {
88         uchar align[512+15];
89         Fxsave;
90 };
91
92 struct Confmem
93 {
94         uintptr base;
95         ulong   npage;
96         uintptr kbase;
97         uintptr klimit;
98 };
99
100 struct Conf
101 {
102         ulong   nmach;          /* processors */
103         ulong   nproc;          /* processes */
104         ulong   monitor;        /* has monitor? */
105         Confmem mem[16];        /* physical memory */
106         ulong   npage;          /* total physical pages of memory */
107         ulong   upages;         /* user page pool */
108         ulong   nimage;         /* number of page cache image headers */
109         ulong   nswap;          /* number of swap pages */
110         int     nswppo;         /* max # of pageouts per segment pass */
111         ulong   copymode;       /* 0 is copy on write, 1 is copy on reference */
112         ulong   ialloc;         /* max interrupt time allocation in bytes */
113         ulong   pipeqsize;      /* size in bytes of pipe queues */
114         int     nuart;          /* number of uart devices */
115 };
116
117 struct Segdesc
118 {
119         u32int  d0;
120         u32int  d1;
121 };
122
123 /*
124  *  MMU structure for PDP, PD, PT pages.
125  */
126 struct MMU
127 {
128         MMU     *next;
129         uintptr *page;
130         int     index;
131         int     level;
132 };
133
134 /*
135  *  MMU stuff in proc
136  */
137 #define NCOLOR 1
138 struct PMMU
139 {
140         MMU*    mmuhead;
141         MMU*    mmutail;
142         MMU*    kmaphead;
143         MMU*    kmaptail;
144         ulong   kmapcount;
145         ulong   kmapindex;
146         ulong   mmucount;
147 };
148
149 /*
150  *  things saved in the Proc structure during a notify
151  */
152 struct Notsave
153 {
154         ulong   svflags;
155         ulong   svcs;
156         ulong   svss;
157 };
158
159 #include "../port/portdat.h"
160
161 typedef struct {
162         u32int  _0_;
163         u32int  rsp0[2];
164         u32int  rsp1[2];
165         u32int  rsp2[2];
166         u32int  _28_[2];
167         u32int  ist[14];
168         u16int  _92_[5];
169         u16int  iomap;
170 } Tss;
171
172 struct Mach
173 {
174         int     machno;                 /* physical id of processor (KNOWN TO ASSEMBLY) */
175         uintptr splpc;                  /* pc of last caller to splhi (KNOWN TO ASSEMBLY) */
176
177         Proc*   proc;                   /* current process on this processor (KNOWN TO ASSEMBLY) */
178
179         u64int* pml4;                   /* pml4 base for this processor (va) */
180         Tss*    tss;                    /* tss for this processor */
181         Segdesc *gdt;                   /* gdt for this processor */
182
183         u64int  mmumap[4];              /* bitmap of pml4 entries for zapping */
184         MMU*    mmufree;                /* freelist for MMU structures */
185         ulong   mmucount;               /* number of MMU structures in freelist */
186
187         ulong   ticks;                  /* of the clock since boot time */
188         Label   sched;                  /* scheduler wakeup */
189         Lock    alarmlock;              /* access to alarm list */
190         void*   alarm;                  /* alarms bound to this clock */
191         int     inclockintr;
192
193         Proc*   readied;                /* for runproc */
194         ulong   schedticks;             /* next forced context switch */
195
196         int     tlbfault;
197         int     tlbpurge;
198         int     pfault;
199         int     cs;
200         int     syscall;
201         int     load;
202         int     intr;
203         int     flushmmu;               /* make current proc flush it's mmu state */
204         int     ilockdepth;
205         Perf    perf;                   /* performance counters */
206
207         ulong   spuriousintr;
208         int     lastintr;
209
210         int     loopconst;
211
212         int     cpumhz;
213         uvlong  cyclefreq;              /* Frequency of user readable cycle counter */
214         uvlong  cpuhz;
215         int     cpuidax;
216         int     cpuidcx;
217         int     cpuiddx;
218         char    cpuidid[16];
219         char*   cpuidtype;
220         int     havetsc;
221         int     havepge;
222         uvlong  tscticks;
223
224         uintptr stack[1];
225 };
226
227 /*
228  * KMap the structure
229  */
230 typedef void KMap;
231 #define VA(k)           ((void*)k)
232
233 struct
234 {
235         Lock;
236         char    machs[MAXMACH];         /* bitmap of active CPUs */
237         int     exiting;                /* shutdown */
238         int     thunderbirdsarego;      /* lets the added processors continue to schedinit */
239 }active;
240
241 /*
242  *  routines for things outside the PC model, like power management
243  */
244 struct PCArch
245 {
246         char*   id;
247         int     (*ident)(void);         /* this should be in the model */
248         void    (*reset)(void);         /* this should be in the model */
249         int     (*serialpower)(int);    /* 1 == on, 0 == off */
250         int     (*modempower)(int);     /* 1 == on, 0 == off */
251
252         void    (*intrinit)(void);
253         int     (*intrenable)(Vctl*);
254         int     (*intrvecno)(int);
255         int     (*intrdisable)(int);
256         void    (*introff)(void);
257         void    (*intron)(void);
258
259         void    (*clockenable)(void);
260         uvlong  (*fastclock)(uvlong*);
261         void    (*timerset)(uvlong);
262 };
263
264 /* cpuid instruction result register bits */
265 enum {
266         /* cx */
267         Monitor = 1<<3,
268
269         /* dx */
270         Fpuonchip = 1<<0,
271         Vmex    = 1<<1,         /* virtual-mode extensions */
272         Pse     = 1<<3,         /* page size extensions */
273         Tsc     = 1<<4,         /* time-stamp counter */
274         Cpumsr  = 1<<5,         /* model-specific registers, rdmsr/wrmsr */
275         Pae     = 1<<6,         /* physical-addr extensions */
276         Mce     = 1<<7,         /* machine-check exception */
277         Cmpxchg8b = 1<<8,
278         Cpuapic = 1<<9,
279         Mtrr    = 1<<12,        /* memory-type range regs.  */
280         Pge     = 1<<13,        /* page global extension */
281         Mca     = 1<<14,        /* machine-check architecture */
282         Pat     = 1<<16,        /* page attribute table */
283         Pse2    = 1<<17,        /* more page size extensions */
284         Clflush = 1<<19,
285         Acpif   = 1<<22,        /* therm control msr */
286         Mmx     = 1<<23,
287         Fxsr    = 1<<24,        /* have SSE FXSAVE/FXRSTOR */
288         Sse     = 1<<25,        /* thus sfence instr. */
289         Sse2    = 1<<26,        /* thus mfence & lfence instr.s */
290         Rdrnd   = 1<<30,        /* RDRAND support bit */
291 };
292
293 enum {                                          /* MSRs */
294         PerfEvtbase     = 0xc0010000,           /* Performance Event Select */
295         PerfCtrbase     = 0xc0010004,           /* Performance Counters */
296
297         Efer            = 0xc0000080,           /* Extended Feature Enable */
298         Star            = 0xc0000081,           /* Legacy Target IP and [CS]S */
299         Lstar           = 0xc0000082,           /* Long Mode Target IP */
300         Cstar           = 0xc0000083,           /* Compatibility Target IP */
301         Sfmask          = 0xc0000084,           /* SYSCALL Flags Mask */
302         FSbase          = 0xc0000100,           /* 64-bit FS Base Address */
303         GSbase          = 0xc0000101,           /* 64-bit GS Base Address */
304         KernelGSbase    = 0xc0000102,           /* SWAPGS instruction */
305 };
306
307 /*
308  *  a parsed plan9.ini line
309  */
310 #define NISAOPT         8
311
312 struct ISAConf {
313         char    *type;
314         ulong   port;
315         int     irq;
316         ulong   dma;
317         ulong   mem;
318         ulong   size;
319         ulong   freq;
320
321         int     nopt;
322         char    *opt[NISAOPT];
323 };
324
325 extern PCArch   *arch;                  /* PC architecture */
326
327 Mach* machp[MAXMACH];
328         
329 #define MACHP(n)        (machp[n])
330
331 extern register Mach* m;                        /* R15 */
332 extern register Proc* up;                       /* R14 */
333
334 /*
335  *  hardware info about a device
336  */
337 typedef struct {
338         ulong   port;   
339         int     size;
340 } Devport;
341
342 struct DevConf
343 {
344         ulong   intnum;                 /* interrupt number */
345         char    *type;                  /* card type, malloced */
346         int     nports;                 /* Number of ports */
347         Devport *ports;                 /* The ports themselves */
348 };
349
350 typedef struct BIOS32ci {               /* BIOS32 Calling Interface */
351         u32int  eax;
352         u32int  ebx;
353         u32int  ecx;
354         u32int  edx;
355         u32int  esi;
356         u32int  edi;
357 } BIOS32ci;