1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51#include <platforms.h>
52#include <mach_kdb.h>
53#include <himem.h>
54
55#include <mach/i386/vm_param.h>
56
57#include <string.h>
58#include <mach/vm_param.h>
59#include <mach/vm_prot.h>
60#include <mach/machine.h>
61#include <mach/time_value.h>
62#include <kern/spl.h>
63#include <kern/assert.h>
64#include <kern/debug.h>
65#include <kern/misc_protos.h>
66#include <kern/startup.h>
67#include <kern/clock.h>
68#include <kern/xpr.h>
69#include <kern/cpu_data.h>
70#include <kern/processor.h>
71#include <vm/vm_page.h>
72#include <vm/pmap.h>
73#include <vm/vm_kern.h>
74#include <i386/fpu.h>
75#include <i386/pmap.h>
76#include <i386/ipl.h>
77#include <i386/pio.h>
78#include <i386/misc_protos.h>
79#include <i386/cpuid.h>
80#include <i386/mp.h>
81#include <i386/machine_routines.h>
82#include <i386/postcode.h>
83#if MACH_KDB
84#include <ddb/db_aout.h>
85#endif
86#include <ddb/tr.h>
87#ifdef __MACHO__
88#include <mach/thread_status.h>
89
90static KernelBootArgs_t *kernelBootArgs;
91#endif
92
93vm_offset_t boot_args_start = 0;
94
95#ifdef __MACHO__
96#include <mach-o/loader.h>
97vm_offset_t edata, etext, end;
98
99
100extern struct segment_command *getsegbyname(const char *);
101extern struct section *firstsect(struct segment_command *);
102extern struct section *nextsect(struct segment_command *, struct section *);
103
104
105
106
107
108
109void
110i386_preinit(void)
111{
112 struct segment_command *sgp;
113 struct section *sp;
114 struct KernelBootArgs *pp;
115 int i;
116
117 sgp = getsegbyname("__DATA");
118 if (sgp) {
119 sp = firstsect(sgp);
120 if (sp) {
121 do {
122 if ((sp->flags & S_ZEROFILL))
123 bzero((char *) sp->addr, sp->size);
124 } while ((sp = nextsect(sgp, sp)));
125 }
126 }
127
128 kernelBootArgs = (KernelBootArgs_t *)
129 ml_static_ptovirt(boot_args_start);
130 pp = (struct KernelBootArgs *) kernelBootArgs;
131 pp->configEnd = (char *)
132 ml_static_ptovirt((vm_offset_t) pp->configEnd);
133 for (i = 0; i < pp->numBootDrivers; i++) {
134 pp->driverConfig[i].address = (unsigned)
135 ml_static_ptovirt(pp->driverConfig[i].address);
136 }
137 return;
138}
139#endif
140
141extern const char version[];
142extern const char version_variant[];
143
144
145
146
147
148void
149i386_init(void)
150{
151 unsigned int maxmem;
152 unsigned int cpus;
153
154 postcode(I386_INIT_ENTRY);
155
156 master_cpu = 0;
157 cpu_data_alloc(TRUE);
158 cpu_init();
159 postcode(CPU_INIT_D);
160
161
162
163
164
165 processor_bootstrap();
166
167 PE_init_platform(FALSE, kernelBootArgs);
168 postcode(PE_INIT_PLATFORM_D);
169
170
171
172
173 thread_bootstrap();
174 postcode(THREAD_BOOTSTRAP_D);
175
176 printf_init();
177 panic_init();
178
179
180 PE_init_kprintf(FALSE);
181
182
183 PE_init_printf(FALSE);
184
185 kprintf("version_variant = %s\n", version_variant);
186 kprintf("version = %s\n", version);
187
188
189
190
191
192 if (!PE_parse_boot_arg("maxmem", &maxmem))
193 maxmem=0;
194 else
195 maxmem = maxmem * (1024 * 1024);
196
197 if (PE_parse_boot_arg("cpus", &cpus)) {
198 if ((0 < cpus) && (cpus < max_ncpus))
199 max_ncpus = cpus;
200 }
201
202 i386_vm_init(maxmem, kernelBootArgs);
203
204 PE_init_platform(TRUE, kernelBootArgs);
205
206
207 PE_create_console();
208
209 machine_startup();
210
211}
212