2 * Memory and machine-specific definitions. Used in C and assembler.
5 #define MIN(a, b) ((a) < (b)? (a): (b))
6 #define MAX(a, b) ((a) > (b)? (a): (b))
11 #define BI2BY 8 /* bits per byte */
12 #define BI2WD 32 /* bits per word */
13 #define BY2WD 4 /* bytes per word */
14 #define BY2V 8 /* bytes per double word */
15 #define BY2PG 4096 /* bytes per page */
16 #define WD2PG (BY2PG/BY2WD) /* words per page */
17 #define BY2XPG (4096*1024) /* bytes per big page */
18 #define PGSHIFT 12 /* log(BY2PG) */
19 #define ROUND(s, sz) (((s)+((sz)-1))&~((sz)-1))
20 #define PGROUND(s) ROUND(s, BY2PG)
24 * In 32-bit mode, the MAXMACH limit is 32 without
25 * changing the way active.machs is defined and used
26 * (unfortunately, it is also used in the port code).
28 #define MAXMACH 32 /* max # cpus system can run */
29 #define KSTACK 4096 /* Size of kernel stack */
34 #define HZ (100) /* clock frequency */
35 #define MS2HZ (1000/HZ) /* millisec per clock tick */
36 #define TK2SEC(t) ((t)/HZ) /* ticks to seconds */
41 #define KZERO 0xF0000000 /* base of kernel address space */
42 #define KTZERO (KZERO+0x100000) /* first address in kernel text - 9load sits below */
43 #define VPT (KZERO-VPTSIZE)
44 #define VPTSIZE BY2XPG
45 #define NVPT (VPTSIZE/BY2WD)
46 #define KMAP (VPT-KMAPSIZE)
47 #define KMAPSIZE BY2XPG
48 #define VMAP (KMAP-VMAPSIZE)
49 #define VMAPSIZE (0x10000000-VPTSIZE-KMAPSIZE)
50 #define UZERO 0 /* base of user address space */
51 #define UTZERO (UZERO+BY2PG) /* first address in user text */
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 */
58 * Fundamental addresses - bottom 64kB saved for return to real mode
60 #define CONFADDR (KZERO+0x1200) /* info passed from boot loader */
61 #define TMPADDR (KZERO+0x2000) /* used for temporary mappings */
62 #define APBOOTSTRAP (KZERO+0x3000) /* AP bootstrap code */
63 #define RMUADDR (KZERO+0x7C00) /* real mode Ureg */
64 #define RMCODE (KZERO+0x8000) /* copy of first page of KTEXT */
65 #define RMBUF (KZERO+0x9000) /* buffer for user space - known to vga */
66 #define IDTADDR (KZERO+0x10800) /* idt */
67 #define REBOOTADDR (0x11000) /* reboot code - physical address */
68 #define CPU0PDB (KZERO+0x12000) /* bootstrap processor PDB */
69 #define CPU0PTE (KZERO+0x13000) /* bootstrap processor PTE's for 0-4MB */
70 #define CPU0GDT (KZERO+0x14000) /* bootstrap processor GDT */
71 #define MACHADDR (KZERO+0x15000) /* as seen by current processor */
72 #define CPU0MACH (KZERO+0x16000) /* Mach for bootstrap processor */
73 #define MACHSIZE BY2PG
74 #define CPU0PTE1 (KZERO+0x17000) /* bootstrap processor PTE's for 4MB-8MB */
75 #define CPU0END (CPU0PTE1+BY2PG)
77 * N.B. ramscan knows that CPU0END is the end of reserved data
78 * N.B. _startPADDR knows that CPU0PDB is the first reserved page
79 * and that there are 6 of them.
83 * known x86 segments (in GDT) and their selectors
85 #define NULLSEG 0 /* null segment */
86 #define KDSEG 1 /* kernel data/stack */
87 #define KESEG 2 /* kernel executable */
88 #define UDSEG 3 /* user data/stack */
89 #define UESEG 4 /* user executable */
90 #define TSSSEG 5 /* task segment */
91 #define APMCSEG 6 /* APM code segment */
92 #define APMCSEG16 7 /* APM 16-bit code segment */
93 #define APMDSEG 8 /* APM data segment */
94 #define KESEG16 9 /* kernel executable 16-bit */
95 #define LDTSEG 10 /* local descriptor table */
96 #define PROCSEG0 11 /* per process descriptor0 */
97 #define NPROCSEG 3 /* number of per process descriptors */
98 #define NGDT 14 /* number of GDT entries required */
100 #define SELGDT (0<<2) /* selector is in gdt */
101 #define SELLDT (1<<2) /* selector is in ldt */
103 #define SELECTOR(i, t, p) (((i)<<3) | (t) | (p))
105 #define NULLSEL SELECTOR(NULLSEG, SELGDT, 0)
106 #define KDSEL SELECTOR(KDSEG, SELGDT, 0)
107 #define KESEL SELECTOR(KESEG, SELGDT, 0)
108 #define UESEL SELECTOR(UESEG, SELGDT, 3)
109 #define UDSEL SELECTOR(UDSEG, SELGDT, 3)
110 #define TSSSEL SELECTOR(TSSSEG, SELGDT, 0)
111 #define APMCSEL SELECTOR(APMCSEG, SELGDT, 0)
112 #define APMCSEL16 SELECTOR(APMCSEG16, SELGDT, 0)
113 #define APMDSEL SELECTOR(APMDSEG, SELGDT, 0)
114 #define LDTSEL SELECTOR(LDTSEG, SELGDT, 0)
117 * fields in segment descriptors
119 #define SEGDATA (0x10<<8) /* data/stack segment */
120 #define SEGEXEC (0x18<<8) /* executable segment */
121 #define SEGTSS (0x9<<8) /* TSS segment */
122 #define SEGCG (0x0C<<8) /* call gate */
123 #define SEGIG (0x0E<<8) /* interrupt gate */
124 #define SEGTG (0x0F<<8) /* trap gate */
125 #define SEGLDT (0x02<<8) /* local descriptor table */
126 #define SEGTYPE (0x1F<<8)
128 #define SEGP (1<<15) /* segment present */
129 #define SEGPL(x) ((x)<<13) /* priority level */
130 #define SEGB (1<<22) /* granularity 1==4k (for expand-down) */
131 #define SEGG (1<<23) /* granularity 1==4k (for other) */
132 #define SEGE (1<<10) /* expand down */
133 #define SEGW (1<<9) /* writable (for data/stack) */
134 #define SEGR (1<<9) /* readable (for code) */
135 #define SEGD (1<<22) /* default 1==32bit (for code) */
140 #define PTEMAPMEM (1024*1024)
141 #define PTEPERTAB (PTEMAPMEM/BY2PG)
142 #define SEGMAPSIZE 1984
143 #define SSEGMAPSIZE 16
144 #define PPN(x) ((x)&~(BY2PG-1))
149 #define PTEVALID (1<<0)
151 #define PTEUNCACHED (1<<4)
152 #define PTEWRITE (1<<1)
153 #define PTERONLY (0<<1)
154 #define PTEKERNEL (0<<2)
155 #define PTEUSER (1<<2)
156 #define PTESIZE (1<<7)
157 #define PTEGLOBAL (1<<8)
160 * Macros for calculating offsets within the page directory base
163 #define PDX(va) ((((ulong)(va))>>22) & 0x03FF)
164 #define PTX(va) ((((ulong)(va))>>12) & 0x03FF)
166 #define getpgcolor(a) 0