2 |
- |
1 |
/*
|
|
|
2 |
* Memory and machine-specific definitions. Used in C and assembler.
|
|
|
3 |
*/
|
|
|
4 |
|
|
|
5 |
/*
|
|
|
6 |
* Sizes
|
|
|
7 |
*/
|
|
|
8 |
#define BI2BY 8 /* bits per byte */
|
|
|
9 |
#define BI2WD 32 /* bits per word */
|
|
|
10 |
#define BY2WD 4 /* bytes per word */
|
|
|
11 |
#define BY2V 8 /* bytes per double word */
|
|
|
12 |
#define BY2PG 4096 /* bytes per page */
|
|
|
13 |
#define WD2PG (BY2PG/BY2WD) /* words per page */
|
|
|
14 |
#define BY2XPG (4096*1024) /* bytes per big page */
|
|
|
15 |
#define PGSHIFT 12 /* log(BY2PG) */
|
|
|
16 |
#define CACHELINESZ 32 /* pentium & later */
|
|
|
17 |
#define BLOCKALIGN 8
|
|
|
18 |
|
|
|
19 |
#define MAXMACH 1 /* max # cpus system can run */
|
|
|
20 |
/*
|
|
|
21 |
* we use a larger-than-normal kernel stack in the bootstraps as we have
|
|
|
22 |
* significant arrays (buffers) on the stack. we typically consume about
|
|
|
23 |
* 4.5K of stack.
|
|
|
24 |
*/
|
|
|
25 |
#define KSTACK (4*BY2PG) /* Size of kernel stack */
|
|
|
26 |
#define MACHSIZE BY2PG
|
|
|
27 |
|
|
|
28 |
/*
|
|
|
29 |
* Time
|
|
|
30 |
*/
|
|
|
31 |
#define HZ (100) /* clock frequency */
|
|
|
32 |
#define MS2HZ (1000/HZ) /* millisec per clock tick */
|
|
|
33 |
#define TK2SEC(t) ((t)/HZ) /* ticks to seconds */
|
|
|
34 |
|
|
|
35 |
/*
|
|
|
36 |
* Address spaces
|
|
|
37 |
*
|
|
|
38 |
* Kernel is at 2GB-4GB
|
|
|
39 |
*/
|
|
|
40 |
#define KZERO 0x80000000 /* base of kernel address space */
|
|
|
41 |
#define KSEGM 0xF0000000
|
|
|
42 |
#define VPT (KZERO-VPTSIZE)
|
|
|
43 |
#define VPTSIZE BY2XPG
|
|
|
44 |
#define NVPT (VPTSIZE/BY2WD)
|
|
|
45 |
#define KMAP (VPT-KMAPSIZE)
|
|
|
46 |
#define KMAPSIZE BY2XPG
|
|
|
47 |
#define VMAP (KMAP-VMAPSIZE)
|
|
|
48 |
#define VMAPSIZE (0x10000000-VPTSIZE-KMAPSIZE)
|
|
|
49 |
#define UZERO 0 /* base of user address space */
|
|
|
50 |
#define UTZERO (UZERO+BY2PG) /* first address in user text */
|
|
|
51 |
#define UTROUND(t) ROUNDUP((t), BY2PG)
|
|
|
52 |
#define USTKTOP (VMAP-BY2PG) /* byte just beyond user stack */
|
|
|
53 |
#define USTKSIZE (16*1024*1024) /* size of user stack */
|
|
|
54 |
#define TSTKTOP (USTKTOP-USTKSIZE) /* end of new stack in sysexec */
|
|
|
55 |
#define TSTKSIZ 100 /* pages in new stack; limits exec args */
|
|
|
56 |
|
|
|
57 |
/*
|
|
|
58 |
* Fundamental addresses - bottom 64kB saved for return to real mode
|
|
|
59 |
*
|
|
|
60 |
* we need some fixed address space for things that normally fit below the
|
|
|
61 |
* kernel and some of it needs to be addressible from real mode, thus under 1MB.
|
|
|
62 |
*
|
|
|
63 |
* pxe loading starts us at 0x7c00 and non-pxe loading starts us at 0x10000.
|
|
|
64 |
*
|
|
|
65 |
* this assertion must hold: PDX(TMPADDR) == PDX(MACHADDR).
|
|
|
66 |
* see realmode0.s for a description of the Chinese puzzle.
|
|
|
67 |
*/
|
|
|
68 |
/* first 1K is real-mode IVT (vectors) */
|
|
|
69 |
/* next 256 bytes are bios data area (bda) */
|
|
|
70 |
/* 0x500 to 0x800 unused [768] */
|
|
|
71 |
/*
|
|
|
72 |
* RMCODE should be the lowest address used in real mode.
|
|
|
73 |
* all real-mode buffers, etc. should follow it.
|
|
|
74 |
*/
|
|
|
75 |
#define RMCODE (KZERO+0x800) /* copy of initial KTZERO [2K, magic] */
|
|
|
76 |
#define REBOOTADDR (RMCODE-KZERO) /* reboot code - physical address [128] */
|
|
|
77 |
#define RMSIZE 2048
|
|
|
78 |
/* 0x1000 to 0x1200 unused [512] */
|
|
|
79 |
/* CONFADDR must match def'n in kernel being loaded */
|
|
|
80 |
#define CONFADDR (KZERO+0x1200) /* cfg passed to kernel [3.5K, fixed] */
|
|
|
81 |
#define BIOSXCHG (KZERO+0x2000) /* BIOS data exchange [2K+32] */
|
|
|
82 |
/* 0x2820 to 0x2900 unused [224] */
|
|
|
83 |
#define RMUADDR (KZERO+0x2900) /* real mode Ureg [128 (76 actual)] */
|
|
|
84 |
/* 0x2980 to 0x3000 unused [1664] */
|
|
|
85 |
#define IDTADDR (KZERO+0x3000) /* protected-mode idt [2K] */
|
|
|
86 |
/* 0x3800 to 0x4000 unused [2K] */
|
|
|
87 |
|
|
|
88 |
/* we only use one processor for bootstrapping, so merge MACHADDR & CPU0MACH */
|
|
|
89 |
#define MACHADDR (KZERO+0x4000) /* as seen by current processor */
|
|
|
90 |
#define CPU0MACH MACHADDR /* Mach for bootstrap processor */
|
|
|
91 |
#define CPU0GDT (KZERO+0x5000) /* bootstrap processor GDT after Mach */
|
|
|
92 |
#define TMPADDR (KZERO+0x6000) /* used for temporary mappings */
|
|
|
93 |
/* 0x7000—0x7800 unused [2K], could be extra real-mode stack */
|
|
|
94 |
#define PXEBASE 0x7c00 /* pxe loads us here */
|
|
|
95 |
#define RMSTACK PXEBASE /* real phys. stack base [1K below] */
|
|
|
96 |
#define PBSBASE 0x10000 /* pbs loads us here (at 64K) */
|
|
|
97 |
|
|
|
98 |
/*
|
|
|
99 |
* we used to use 9boot's `end', rounded up, but that was when the boot loader
|
|
|
100 |
* was in the first 640K; now end is up around 10MB (at least for 9boot).
|
|
|
101 |
* various machines nibble away at the top of the lowest 640K.
|
|
|
102 |
*/
|
|
|
103 |
#define BIOSTABLES (512*1024)
|
|
|
104 |
// #define BIOSTABLES (600*1024) /* fails on amd64 */
|
|
|
105 |
// #define BIOSTABLES 0x3800 /* 2K: fails on amd64 */
|
|
|
106 |
|
|
|
107 |
#define Bootkernaddr (9*MB) /* where to put decompressed boot kernel */
|
|
|
108 |
#define Bootkernmax (4*MB) /* max size */
|
|
|
109 |
#define Unzipbuf (13*MB)
|
|
|
110 |
#define Mallocbase (16*MB)
|
|
|
111 |
/*
|
|
|
112 |
* MemMin is what the bootstrap code in l*.s has already mapped;
|
|
|
113 |
* MemMax is the limit of physical memory to scan.
|
|
|
114 |
*/
|
|
|
115 |
#define MemMin (20*MB) /* don't have PTEs for more allocated yet */
|
|
|
116 |
#define MemMax (512*MB) /* allow for huge 10gbe buffers */
|
|
|
117 |
|
|
|
118 |
#define Lowmemsz (640*KB)
|
|
|
119 |
|
|
|
120 |
#define LOWPTEPAGES (MemMin / (4*MB))
|
|
|
121 |
|
|
|
122 |
#define Kernelmax (8*MB) /* max size of real kernel, not an address */
|
|
|
123 |
|
|
|
124 |
/*
|
|
|
125 |
* known x86 segments (in GDT) and their selectors
|
|
|
126 |
*/
|
|
|
127 |
#define NULLSEG 0 /* null segment */
|
|
|
128 |
#define KDSEG 1 /* kernel data/stack */
|
|
|
129 |
#define KESEG 2 /* kernel executable */
|
|
|
130 |
#define UDSEG 3 /* user data/stack */
|
|
|
131 |
#define UESEG 4 /* user executable */
|
|
|
132 |
#define TSSSEG 5 /* task segment */
|
|
|
133 |
#define APMCSEG 6 /* APM code segment */
|
|
|
134 |
#define APMCSEG16 7 /* APM 16-bit code segment */
|
|
|
135 |
#define APMDSEG 8 /* APM data segment */
|
|
|
136 |
#define KESEG16 9 /* kernel executable 16-bit */
|
|
|
137 |
#define NGDT 10 /* number of GDT entries required */
|
|
|
138 |
/* #define APM40SEG 8 /* APM segment 0x40 */
|
|
|
139 |
|
|
|
140 |
#define SELGDT (0<<2) /* selector is in gdt */
|
|
|
141 |
#define SELLDT (1<<2) /* selector is in ldt */
|
|
|
142 |
|
|
|
143 |
#define SELECTOR(i, t, p) (((i)<<3) | (t) | (p))
|
|
|
144 |
|
|
|
145 |
#define NULLSEL SELECTOR(NULLSEG, SELGDT, 0)
|
|
|
146 |
#define KDSEL SELECTOR(KDSEG, SELGDT, 0)
|
|
|
147 |
#define KESEL SELECTOR(KESEG, SELGDT, 0)
|
|
|
148 |
#define UESEL SELECTOR(UESEG, SELGDT, 3)
|
|
|
149 |
#define UDSEL SELECTOR(UDSEG, SELGDT, 3)
|
|
|
150 |
#define TSSSEL SELECTOR(TSSSEG, SELGDT, 0)
|
|
|
151 |
#define APMCSEL SELECTOR(APMCSEG, SELGDT, 0)
|
|
|
152 |
#define APMCSEL16 SELECTOR(APMCSEG16, SELGDT, 0)
|
|
|
153 |
#define APMDSEL SELECTOR(APMDSEG, SELGDT, 0)
|
|
|
154 |
/* #define APM40SEL SELECTOR(APM40SEG, SELGDT, 0) */
|
|
|
155 |
|
|
|
156 |
/*
|
|
|
157 |
* fields in segment descriptors
|
|
|
158 |
*/
|
|
|
159 |
#define SEGDATA (0x10<<8) /* data/stack segment */
|
|
|
160 |
#define SEGEXEC (0x18<<8) /* executable segment */
|
|
|
161 |
#define SEGTSS (0x9<<8) /* TSS segment */
|
|
|
162 |
#define SEGCG (0x0C<<8) /* call gate */
|
|
|
163 |
#define SEGIG (0x0E<<8) /* interrupt gate */
|
|
|
164 |
#define SEGTG (0x0F<<8) /* trap gate */
|
|
|
165 |
#define SEGTYPE (0x1F<<8)
|
|
|
166 |
|
|
|
167 |
#define SEGP (1<<15) /* segment present */
|
|
|
168 |
#define SEGPL(x) ((x)<<13) /* priority level */
|
|
|
169 |
#define SEGB (1<<22) /* granularity 1==4k (for expand-down) */
|
|
|
170 |
#define SEGG (1<<23) /* granularity 1==4k (for other) */
|
|
|
171 |
#define SEGE (1<<10) /* expand down */
|
|
|
172 |
#define SEGW (1<<9) /* writable (for data/stack) */
|
|
|
173 |
#define SEGR (1<<9) /* readable (for code) */
|
|
|
174 |
#define SEGD (1<<22) /* default 1==32bit (for code) */
|
|
|
175 |
|
|
|
176 |
/*
|
|
|
177 |
* virtual MMU
|
|
|
178 |
*/
|
|
|
179 |
#define PTEMAPMEM (1024*1024)
|
|
|
180 |
#define PTEPERTAB (PTEMAPMEM/BY2PG)
|
|
|
181 |
#define SEGMAPSIZE 1984
|
|
|
182 |
#define SSEGMAPSIZE 16
|
|
|
183 |
#define PPN(x) ((x)&~(BY2PG-1))
|
|
|
184 |
|
|
|
185 |
/*
|
|
|
186 |
* physical MMU
|
|
|
187 |
*/
|
|
|
188 |
#define PTEVALID (1<<0)
|
|
|
189 |
#define PTEWT (1<<3)
|
|
|
190 |
#define PTEUNCACHED (1<<4)
|
|
|
191 |
#define PTEWRITE (1<<1)
|
|
|
192 |
#define PTERONLY (0<<1)
|
|
|
193 |
#define PTEKERNEL (0<<2)
|
|
|
194 |
#define PTEUSER (1<<2)
|
|
|
195 |
#define PTESIZE (1<<7)
|
|
|
196 |
#define PTEGLOBAL (1<<8)
|
|
|
197 |
|
|
|
198 |
/* CR0 */
|
|
|
199 |
#define PG 0x80000000
|
|
|
200 |
|
|
|
201 |
/*
|
|
|
202 |
* Macros for calculating offsets within the page directory base
|
|
|
203 |
* and page tables.
|
|
|
204 |
*/
|
|
|
205 |
#define PDX(va) ((((ulong)(va))>>22) & 0x03FF)
|
|
|
206 |
#define PTX(va) ((((ulong)(va))>>12) & 0x03FF)
|
|
|
207 |
|
|
|
208 |
#define getpgcolor(a) 0
|
|
|
209 |
|