xref: /inferno-os/os/boot/pc/mem.h (revision 8a8c2d742b51525f66c2210e3c8a251de10022ff)
174a4d8c2SCharles.Forsyth /*
274a4d8c2SCharles.Forsyth  * Memory and machine-specific definitions.  Used in C and assembler.
374a4d8c2SCharles.Forsyth  */
474a4d8c2SCharles.Forsyth 
574a4d8c2SCharles.Forsyth /*
674a4d8c2SCharles.Forsyth  * Sizes
774a4d8c2SCharles.Forsyth  */
874a4d8c2SCharles.Forsyth #define	BI2BY		8			/* bits per byte */
974a4d8c2SCharles.Forsyth #define	BI2WD		32			/* bits per word */
1074a4d8c2SCharles.Forsyth #define	BY2WD		4			/* bytes per word */
1174a4d8c2SCharles.Forsyth #define	BY2PG		4096			/* bytes per page */
1274a4d8c2SCharles.Forsyth #define	WD2PG		(BY2PG/BY2WD)		/* words per page */
1374a4d8c2SCharles.Forsyth #define	PGSHIFT		12			/* log(BY2PG) */
1474a4d8c2SCharles.Forsyth #define	PGROUND(s)	(((s)+(BY2PG-1))&~(BY2PG-1))
1574a4d8c2SCharles.Forsyth 
1674a4d8c2SCharles.Forsyth #define	MAXMACH		1			/* max # cpus system can run */
1774a4d8c2SCharles.Forsyth 
1874a4d8c2SCharles.Forsyth /*
1974a4d8c2SCharles.Forsyth  * Time
2074a4d8c2SCharles.Forsyth  */
2174a4d8c2SCharles.Forsyth #define	HZ		(100)				/* clock frequency */
2274a4d8c2SCharles.Forsyth #define	MS2HZ		(1000/HZ)			/* millisec per clock tick */
2374a4d8c2SCharles.Forsyth #define	TK2SEC(t)	((t)/HZ)			/* ticks to seconds */
2474a4d8c2SCharles.Forsyth #define	TK2MS(x)	((x)*(1000/HZ))
2574a4d8c2SCharles.Forsyth #define	MS2TK(t)	((((ulong)(t))*HZ)/1000)	/* milliseconds to ticks */
2674a4d8c2SCharles.Forsyth 
2774a4d8c2SCharles.Forsyth /*
2874a4d8c2SCharles.Forsyth  * Fundamental addresses
2974a4d8c2SCharles.Forsyth  */
3074a4d8c2SCharles.Forsyth #define IDTADDR		0x80000800		/* idt */
3174a4d8c2SCharles.Forsyth #define APBOOTSTRAP	0x80001000		/* AP bootstrap code */
3274a4d8c2SCharles.Forsyth #define CONFADDR	0x80001200		/* info passed from boot loader */
3374a4d8c2SCharles.Forsyth #define CPU0PDB		0x80002000		/* bootstrap processor PDB */
3474a4d8c2SCharles.Forsyth #define CPU0PTE		0x80003000		/* bootstrap processor PTE's for 0-4MB */
3574a4d8c2SCharles.Forsyth #define MACHADDR	0x80004000		/* as seen by current processor */
3674a4d8c2SCharles.Forsyth #define CPU0MACH	0x80005000		/* Mach for bootstrap processor */
37*8a8c2d74SCharles.Forsyth #define BIOSXCHG	0x80006000		/* To exchange data with the BIOS */
3874a4d8c2SCharles.Forsyth #define	MACHSIZE	(BY2PG*8)		/* stack size */
3974a4d8c2SCharles.Forsyth 
4074a4d8c2SCharles.Forsyth /*
4174a4d8c2SCharles.Forsyth  *  Address spaces
4274a4d8c2SCharles.Forsyth  *
4374a4d8c2SCharles.Forsyth  *  Kernel is at 2GB-4GB
4474a4d8c2SCharles.Forsyth  */
4574a4d8c2SCharles.Forsyth #define	KZERO		0x80000000		/* base of kernel address space */
4674a4d8c2SCharles.Forsyth #define	KTZERO		KZERO			/* first address in kernel text */
4774a4d8c2SCharles.Forsyth #define ROMBIOS		(KZERO|0xF0000)
4874a4d8c2SCharles.Forsyth 
4974a4d8c2SCharles.Forsyth /*
5074a4d8c2SCharles.Forsyth  *  known 80386 segments (in GDT) and their selectors
5174a4d8c2SCharles.Forsyth  */
5274a4d8c2SCharles.Forsyth #define	NULLSEG	0	/* null segment */
5374a4d8c2SCharles.Forsyth #define	KDSEG	1	/* kernel data/stack */
5474a4d8c2SCharles.Forsyth #define	KESEG	2	/* kernel executable */
5574a4d8c2SCharles.Forsyth #define	UDSEG	3	/* user data/stack */
5674a4d8c2SCharles.Forsyth #define	UESEG	4	/* user executable */
5774a4d8c2SCharles.Forsyth #define	SYSGATE	5	/* system call gate */
5874a4d8c2SCharles.Forsyth #define TSSSEG	6	/* task segment */
5974a4d8c2SCharles.Forsyth 
6074a4d8c2SCharles.Forsyth #define SELGDT	(0<<3)	/* selector is in gdt */
6174a4d8c2SCharles.Forsyth #define	SELLDT	(1<<3)	/* selector is in ldt */
6274a4d8c2SCharles.Forsyth 
6374a4d8c2SCharles.Forsyth #define SELECTOR(i, t, p)	(((i)<<3) | (t) | (p))
6474a4d8c2SCharles.Forsyth 
6574a4d8c2SCharles.Forsyth #define NULLSEL	SELECTOR(NULLSEG, SELGDT, 0)
6674a4d8c2SCharles.Forsyth #define KESEL	SELECTOR(KESEG, SELGDT, 0)
6774a4d8c2SCharles.Forsyth #define KDSEL	SELECTOR(KDSEG, SELGDT, 0)
6874a4d8c2SCharles.Forsyth #define UESEL	SELECTOR(UESEG, SELGDT, 3)
6974a4d8c2SCharles.Forsyth #define UDSEL	SELECTOR(UDSEG, SELGDT, 3)
7074a4d8c2SCharles.Forsyth #define TSSSEL	SELECTOR(TSSSEG, SELGDT, 0)
7174a4d8c2SCharles.Forsyth 
7274a4d8c2SCharles.Forsyth /*
7374a4d8c2SCharles.Forsyth  *  fields in segment descriptors
7474a4d8c2SCharles.Forsyth  */
7574a4d8c2SCharles.Forsyth #define SEGDATA	(0x10<<8)	/* data/stack segment */
7674a4d8c2SCharles.Forsyth #define SEGEXEC	(0x18<<8)	/* executable segment */
7774a4d8c2SCharles.Forsyth #define	SEGTSS	(0x9<<8)	/* TSS segment */
7874a4d8c2SCharles.Forsyth #define SEGCG	(0x0C<<8)	/* call gate */
7974a4d8c2SCharles.Forsyth #define	SEGIG	(0x0E<<8)	/* interrupt gate */
8074a4d8c2SCharles.Forsyth #define SEGTG	(0x0F<<8)	/* task gate */
8174a4d8c2SCharles.Forsyth #define SEGTYPE	(0x1F<<8)
8274a4d8c2SCharles.Forsyth 
8374a4d8c2SCharles.Forsyth #define SEGP	(1<<15)		/* segment present */
8474a4d8c2SCharles.Forsyth #define SEGPL(x) ((x)<<13)	/* priority level */
8574a4d8c2SCharles.Forsyth #define SEGB	(1<<22)		/* granularity 1==4k (for expand-down) */
8674a4d8c2SCharles.Forsyth #define SEGG	(1<<23)		/* granularity 1==4k (for other) */
8774a4d8c2SCharles.Forsyth #define SEGE	(1<<10)		/* expand down */
8874a4d8c2SCharles.Forsyth #define SEGW	(1<<9)		/* writable (for data/stack) */
8974a4d8c2SCharles.Forsyth #define	SEGR	(1<<9)		/* readable (for code) */
9074a4d8c2SCharles.Forsyth #define SEGD	(1<<22)		/* default 1==32bit (for code) */
9174a4d8c2SCharles.Forsyth 
9274a4d8c2SCharles.Forsyth /*
9374a4d8c2SCharles.Forsyth  *  virtual MMU
9474a4d8c2SCharles.Forsyth  */
9574a4d8c2SCharles.Forsyth #define PTEMAPMEM	(1024*1024)	/* ??? */
9674a4d8c2SCharles.Forsyth #define SEGMAPSIZE	16		/* ??? */
9774a4d8c2SCharles.Forsyth #define	PTEPERTAB	(PTEMAPMEM/BY2PG)	/* ??? */
9874a4d8c2SCharles.Forsyth #define PPN(x)		((x)&~(BY2PG-1))
9974a4d8c2SCharles.Forsyth 
10074a4d8c2SCharles.Forsyth /*
10174a4d8c2SCharles.Forsyth  *  physical MMU
10274a4d8c2SCharles.Forsyth  */
10374a4d8c2SCharles.Forsyth #define	PTEVALID	(1<<0)
10474a4d8c2SCharles.Forsyth #define	PTEUNCACHED	0		/* everything is uncached */
10574a4d8c2SCharles.Forsyth #define	PTEWRITE	(1<<1)
10674a4d8c2SCharles.Forsyth #define	PTERONLY	(0<<1)
10774a4d8c2SCharles.Forsyth #define	PTEKERNEL	(0<<2)
10874a4d8c2SCharles.Forsyth #define	PTEUSER		(1<<2)
10974a4d8c2SCharles.Forsyth #define	PTESIZE		(1<<7)
11074a4d8c2SCharles.Forsyth 
11174a4d8c2SCharles.Forsyth /*
11274a4d8c2SCharles.Forsyth  *  flag register bits that we care about
11374a4d8c2SCharles.Forsyth  */
11474a4d8c2SCharles.Forsyth #define IFLAG	0x200
115