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