xref: /plan9-contrib/sys/src/9/pcboot/dat.h (revision 77dd0a987f922b1125641a8757e16b54f2cf323f)
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 PCArch	PCArch;
12 typedef struct Pcidev	Pcidev;
13 typedef struct PCMmap	PCMmap;
14 typedef struct PCMslot	PCMslot;
15 typedef struct Page	Page;
16 typedef struct PMMU	PMMU;
17 typedef struct Proc	Proc;
18 typedef struct Segdesc	Segdesc;
19 typedef vlong		Tval;
20 typedef struct Ureg	Ureg;
21 typedef struct Vctl	Vctl;
22 
23 #pragma incomplete BIOS32si
24 #pragma incomplete Pcidev
25 #pragma incomplete Ureg
26 
27 #define MAXSYSARG	5	/* for mount(fd, afd, mpt, flag, arg) */
28 
29 /*
30  * Where configuration info is left for the loaded programme.
31  * There are 3584 bytes available at CONFADDR.
32  */
33 #define BOOTLINE	((char*)CONFADDR)
34 #define BOOTLINELEN	64
35 #define BOOTARGS	((char*)(CONFADDR+BOOTLINELEN))
36 #define	BOOTARGSLEN	(3584-0x200-BOOTLINELEN)
37 #define	MAXCONF		100
38 
39 enum {
40 	Promptsecs	= 60,
41 };
42 
43 char *confname[MAXCONF];
44 char *confval[MAXCONF];
45 int nconf;
46 
47 #define KMESGSIZE 64
48 #define PCICONSSIZE 64
49 #define STAGESIZE 64
50 
51 #define NAMELEN 28
52 
53 #define	GSHORT(p)	(((p)[1]<<8)|(p)[0])
54 #define	GLSHORT(p)	(((p)[0]<<8)|(p)[1])
55 
56 #define	GLONG(p)	((GSHORT(p+2)<<16)|GSHORT(p))
57 #define	GLLONG(p)	(((ulong)GLSHORT(p)<<16)|GLSHORT(p+2))
58 #define	PLLONG(p,v)	(p)[3]=(v);(p)[2]=(v)>>8;(p)[1]=(v)>>16;(p)[0]=(v)>>24
59 
60 #define	PLVLONG(p,v)	(p)[7]=(v);(p)[6]=(v)>>8;(p)[5]=(v)>>16;(p)[4]=(v)>>24;\
61 			(p)[3]=(v)>>32; (p)[2]=(v)>>40;\
62 			(p)[1]=(v)>>48; (p)[0]=(v)>>56;
63 
64 enum {
65 	Stkpat =	0,
66 };
67 
68 /*
69  *  parameters for sysproc.c
70  */
71 #define AOUT_MAGIC	(I_MAGIC)
72 
73 struct Lock
74 {
75 	ulong	magic;
76 	ulong	key;
77 	ulong	sr;
78 	ulong	pc;
79 	Proc	*p;
80 	Mach	*m;
81 	ushort	isilock;
82 	long	lockcycles;
83 };
84 
85 struct Label
86 {
87 	ulong	sp;
88 	ulong	pc;
89 };
90 
91 
92 /*
93  * FPsave.status
94  */
95 enum
96 {
97 	/* this is a state */
98 	FPinit=		0,
99 	FPactive=	1,
100 	FPinactive=	2,
101 
102 	/* the following is a bit that can be or'd into the state */
103 	FPillegal=	0x100,
104 };
105 
106 struct	FPsave
107 {
108 	ushort	control;
109 	ushort	r1;
110 	ushort	status;
111 	ushort	r2;
112 	ushort	tag;
113 	ushort	r3;
114 	ulong	pc;
115 	ushort	selector;
116 	ushort	r4;
117 	ulong	operand;
118 	ushort	oselector;
119 	ushort	r5;
120 	uchar	regs[80];	/* floating point registers */
121 };
122 
123 struct Confmem
124 {
125 	ulong	base;
126 	ulong	npage;
127 	ulong	kbase;
128 	ulong	klimit;
129 };
130 
131 struct Conf
132 {
133 	ulong	nmach;		/* processors */
134 	ulong	nproc;		/* processes */
135 	ulong	monitor;	/* has monitor? */
136 	Confmem	mem[4];		/* physical memory */
137 	ulong	npage;		/* total physical pages of memory */
138 	ulong	upages;		/* user page pool */
139 	ulong	nimage;		/* number of page cache image headers */
140 	ulong	nswap;		/* number of swap pages */
141 	int	nswppo;		/* max # of pageouts per segment pass */
142 	ulong	base0;		/* base of bank 0 */
143 	ulong	base1;		/* base of bank 1 */
144 	ulong	copymode;	/* 0 is copy on write, 1 is copy on reference */
145 	ulong	ialloc;		/* max interrupt time allocation in bytes */
146 	ulong	pipeqsize;	/* size in bytes of pipe queues */
147 	int	nuart;		/* number of uart devices */
148 };
149 
150 /*
151  *  MMU stuff in proc
152  */
153 #define NCOLOR 1
154 struct PMMU
155 {
156 	Page*	mmupdb;			/* page directory base */
157 	Page*	mmufree;		/* unused page table pages */
158 	Page*	mmuused;		/* used page table pages */
159 	Page*	kmaptable;		/* page table used by kmap */
160 	uint	lastkmap;		/* last entry used by kmap */
161 	int	nkmap;			/* number of current kmaps */
162 };
163 
164 #include "../port/portdat.h"
165 
166 typedef struct {
167 	ulong	link;			/* link (old TSS selector) */
168 	ulong	esp0;			/* privilege level 0 stack pointer */
169 	ulong	ss0;			/* privilege level 0 stack selector */
170 	ulong	esp1;			/* privilege level 1 stack pointer */
171 	ulong	ss1;			/* privilege level 1 stack selector */
172 	ulong	esp2;			/* privilege level 2 stack pointer */
173 	ulong	ss2;			/* privilege level 2 stack selector */
174 	ulong	xcr3;			/* page directory base register - not used because we don't use trap gates */
175 	ulong	eip;			/* instruction pointer */
176 	ulong	eflags;			/* flags register */
177 	ulong	eax;			/* general registers */
178 	ulong 	ecx;
179 	ulong	edx;
180 	ulong	ebx;
181 	ulong	esp;
182 	ulong	ebp;
183 	ulong	esi;
184 	ulong	edi;
185 	ulong	es;			/* segment selectors */
186 	ulong	cs;
187 	ulong	ss;
188 	ulong	ds;
189 	ulong	fs;
190 	ulong	gs;
191 	ulong	ldt;			/* selector for task's LDT */
192 	ulong	iomap;			/* I/O map base address + T-bit */
193 } Tss;
194 
195 struct Segdesc
196 {
197 	ulong	d0;
198 	ulong	d1;
199 };
200 
201 struct Mach
202 {
203 	int	machno;			/* physical id of processor (KNOWN TO ASSEMBLY) */
204 	ulong	splpc;			/* pc of last caller to splhi */
205 
206 	ulong*	pdb;			/* page directory base for this processor (va) */
207 	Tss*	tss;			/* tss for this processor */
208 	Segdesc	*gdt;			/* gdt for this processor */
209 
210 	Proc*	proc;			/* current process on this processor */
211 	Proc*	externup;		/* extern register Proc *up */
212 
213 	Page*	pdbpool;
214 	int	pdbcnt;
215 
216 	ulong	ticks;			/* of the clock since boot time */
217 	Label	sched;			/* scheduler wakeup */
218 	Lock	alarmlock;		/* access to alarm list */
219 	void*	alarm;			/* alarms bound to this clock */
220 	int	inclockintr;
221 
222 	Proc*	readied;		/* for runproc */
223 	ulong	schedticks;		/* next forced context switch */
224 
225 	int	tlbfault;
226 	int	tlbpurge;
227 	int	pfault;
228 	int	cs;
229 	int	syscall;
230 	int	load;
231 	int	intr;
232 	int	flushmmu;		/* make current proc flush it's mmu state */
233 	int	ilockdepth;
234 	Perf	perf;			/* performance counters */
235 
236 	ulong	spuriousintr;
237 	int	lastintr;
238 
239 	int	loopconst;
240 
241 	Lock	apictimerlock;
242 	int	cpumhz;
243 	uvlong	cyclefreq;		/* Frequency of user readable cycle counter */
244 	uvlong	cpuhz;
245 	int	cpuidax;
246 	int	cpuiddx;
247 	char	cpuidid[16];
248 	char*	cpuidtype;
249 	int	havetsc;
250 	int	havepge;
251 	uvlong	tscticks;
252 	int	pdballoc;
253 	int	pdbfree;
254 
255 	vlong	mtrrcap;
256 	vlong	mtrrdef;
257 	vlong	mtrrfix[11];
258 	vlong	mtrrvar[32];		/* 256 max. */
259 
260 	int	stack[1];
261 };
262 
263 /*
264  * KMap the structure doesn't exist, but the functions do.
265  */
266 typedef struct KMap		KMap;
267 #define	VA(k)		((void*)(k))
268 KMap*	kmap(Page*);
269 void	kunmap(KMap*);
270 
271 struct
272 {
273 	Lock;
274 	int	machs;			/* bitmap of active CPUs */
275 	int	exiting;		/* shutdown */
276 	int	ispanic;		/* shutdown in response to a panic */
277 	int	thunderbirdsarego;	/* lets the added processors continue to schedinit */
278 	int	rebooting;		/* just idle cpus > 0 */
279 }active;
280 
281 /*
282  *  routines for things outside the PC model, like power management
283  */
284 struct PCArch
285 {
286 	char*	id;
287 	int	(*ident)(void);		/* this should be in the model */
288 	void	(*reset)(void);		/* this should be in the model */
289 	int	(*serialpower)(int);	/* 1 == on, 0 == off */
290 	int	(*modempower)(int);	/* 1 == on, 0 == off */
291 
292 	void	(*intrinit)(void);
293 	int	(*intrenable)(Vctl*);
294 	int	(*intrvecno)(int);
295 	int	(*intrdisable)(int);
296 	void	(*introff)(void);
297 	void	(*intron)(void);
298 
299 	void	(*clockenable)(void);
300 	uvlong	(*fastclock)(uvlong*);
301 	void	(*timerset)(uvlong);
302 
303 	void	(*resetothers)(void);	/* put other cpus into reset */
304 };
305 
306 /* cpuid instruction result register bits */
307 enum {
308 	/* dx */
309 	Fpuonchip = 1<<0,
310 	Pse	= 1<<3,		/* page size extensions */
311 	Tsc	= 1<<4,		/* time-stamp counter */
312 	Cpumsr	= 1<<5,		/* model-specific registers, rdmsr/wrmsr */
313 	Pae	= 1<<6,		/* physical-addr extensions */
314 	Mce	= 1<<7,		/* machine-check exception */
315 	Cmpxchg8b = 1<<8,
316 	Cpuapic	= 1<<9,
317 	Mtrr	= 1<<12,	/* memory-type range regs.  */
318 	Pge	= 1<<13,	/* page global extension */
319 	Pse2	= 1<<17,	/* more page size extensions */
320 	Clflush = 1<<19,
321 	Acpif	= 1<<22,
322 	Mmx	= 1<<23,
323 	Fxsr	= 1<<24,	/* have SSE FXSAVE/FXRSTOR */
324 	Sse	= 1<<25,	/* thus sfence instr. */
325 	Sse2	= 1<<26,	/* thus mfence & lfence instr.s */
326 };
327 
328 /*
329  *  a parsed plan9.ini line
330  */
331 #define NISAOPT		8
332 
333 struct ISAConf {
334 	char	*type;
335 	ulong	port;
336 	int	irq;
337 	ulong	dma;
338 	ulong	mem;
339 	ulong	size;
340 	ulong	freq;
341 
342 	int	nopt;
343 	char	*opt[NISAOPT];
344 };
345 
346 extern PCArch	*arch;			/* PC architecture */
347 
348 /*
349  * Each processor sees its own Mach structure at address MACHADDR.
350  * However, the Mach structures must also be available via the per-processor
351  * MMU information array machp, mainly for disambiguation and access to
352  * the clock which is only maintained by the bootstrap processor (0).
353  */
354 Mach* machp[MAXMACH];
355 
356 #define	MACHP(n)	(machp[n])
357 
358 extern Mach	*m;
359 #define up	(((Mach*)MACHADDR)->externup)
360 
361 /*
362  *  hardware info about a device
363  */
364 typedef struct {
365 	ulong	port;
366 	int	size;
367 } Devport;
368 
369 struct DevConf
370 {
371 	ulong	intnum;			/* interrupt number */
372 	char	*type;			/* card type, malloced */
373 	int	nports;			/* Number of ports */
374 	Devport	*ports;			/* The ports themselves */
375 };
376 
377 typedef struct BIOS32ci {		/* BIOS32 Calling Interface */
378 	u32int	eax;
379 	u32int	ebx;
380 	u32int	ecx;
381 	u32int	edx;
382 	u32int	esi;
383 	u32int	edi;
384 } BIOS32ci;
385 
386 /* misc. */
387 extern int	v_flag;
388 
389 /* APM goo */
390 typedef struct Apminfo {
391 	int haveinfo;
392 	int ax;
393 	int cx;
394 	int dx;
395 	int di;
396 	int ebx;
397 	int esi;
398 } Apminfo;
399 extern Apminfo	apm;
400 
401 /*
402  * Multiboot grot.
403  */
404 typedef struct Mbi Mbi;
405 struct Mbi {
406 	u32int	flags;
407 	u32int	memlower;
408 	u32int	memupper;
409 	u32int	bootdevice;
410 	u32int	cmdline;
411 	u32int	modscount;
412 	u32int	modsaddr;
413 	u32int	syms[4];
414 	u32int	mmaplength;
415 	u32int	mmapaddr;
416 	u32int	driveslength;
417 	u32int	drivesaddr;
418 	u32int	configtable;
419 	u32int	bootloadername;
420 	u32int	apmtable;
421 	u32int	vbe[6];
422 };
423 
424 enum {						/* flags */
425 	Fmem		= 0x00000001,		/* mem* valid */
426 	Fbootdevice	= 0x00000002,		/* bootdevice valid */
427 	Fcmdline	= 0x00000004,		/* cmdline valid */
428 	Fmods		= 0x00000008,		/* mod* valid */
429 	Fsyms		= 0x00000010,		/* syms[] has a.out info */
430 	Felf		= 0x00000020,		/* syms[] has ELF info */
431 	Fmmap		= 0x00000040,		/* mmap* valid */
432 	Fdrives		= 0x00000080,		/* drives* valid */
433 	Fconfigtable	= 0x00000100,		/* configtable* valid */
434 	Fbootloadername	= 0x00000200,		/* bootloadername* valid */
435 	Fapmtable	= 0x00000400,		/* apmtable* valid */
436 	Fvbe		= 0x00000800,		/* vbe[] valid */
437 };
438 
439 typedef struct Mod Mod;
440 struct Mod {
441 	u32int	modstart;
442 	u32int	modend;
443 	u32int	string;
444 	u32int	reserved;
445 };
446 
447 typedef struct MMap MMap;
448 struct MMap {
449 	u32int	size;
450 	u32int	base[2];
451 	u32int	length[2];
452 	u32int	type;
453 };
454 
455 MMap mmap[32+1];
456 int nmmap;
457 
458 Mbi *multibootheader;
459 
460 enum {
461 	Maxfile = 4096,
462 };
463 
464 /* from 9load */
465 
466 enum {	/* returned by bootpass */
467 	MORE, ENOUGH, FAIL
468 };
469 enum {
470 	INITKERNEL,
471 	READEXEC,
472 	READ9TEXT,
473 	READ9DATA,
474 	READGZIP,
475 	READEHDR,		/* elf states ... */
476 	READPHDR,
477 	READEPAD,
478 	READEDATA,		/* through here */
479 	READE64HDR,		/* elf64 states ... */
480 	READ64PHDR,
481 	READE64PAD,
482 	READE64DATA,		/* through here */
483 	TRYBOOT,
484 	TRYEBOOT,		/* another elf state */
485 	TRYE64BOOT,		/* another elf state */
486 	INIT9LOAD,
487 	READ9LOAD,
488 	FAILED
489 };
490 
491 typedef struct Execbytes Execbytes;
492 struct	Execbytes
493 {
494 	uchar	magic[4];		/* magic number */
495 	uchar	text[4];	 	/* size of text segment */
496 	uchar	data[4];	 	/* size of initialized data */
497 	uchar	bss[4];	  		/* size of uninitialized data */
498 	uchar	syms[4];	 	/* size of symbol table */
499 	uchar	entry[4];	 	/* entry point */
500 	uchar	spsz[4];		/* size of sp/pc offset table */
501 	uchar	pcsz[4];		/* size of pc/line number table */
502 };
503 
504 typedef struct {
505 	Execbytes;
506 	uvlong uvl[1];
507 } Exechdr;
508 
509 typedef struct Boot Boot;
510 struct Boot {
511 	int state;
512 
513 	Exechdr hdr;
514 	uvlong	entry;
515 
516 	char *bp;	/* base ptr */
517 	char *wp;	/* write ptr */
518 	char *ep;	/* end ptr */
519 };
520 
521 extern int	debugload;
522 extern Apminfo	apm;
523 extern Chan	*conschan;
524 extern char	*defaultpartition;
525 extern int	iniread;
526 extern u32int	memstart;
527 extern u32int	memend;
528 extern int	noclock;
529 extern int	pxe;
530 extern int	vga;
531 
532 extern int	biosinited;
533 
534 extern void _KTZERO(void);
535 #define KTZERO ((uintptr)_KTZERO)
536