]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/i386_init.c
xnu-792.21.3.tar.gz
[apple/xnu.git] / osfmk / i386 / i386_init.c
1 /*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * @OSF_COPYRIGHT@
30 */
31 /*
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989, 1988 Carnegie Mellon University
34 * All Rights Reserved.
35 *
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
41 *
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45 *
46 * Carnegie Mellon requests users of this software to return to
47 *
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
52 *
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
55 */
56
57 #include <platforms.h>
58 #include <mach_kdb.h>
59 #include <himem.h>
60
61 #include <mach/i386/vm_param.h>
62
63 #include <string.h>
64 #include <mach/vm_param.h>
65 #include <mach/vm_prot.h>
66 #include <mach/machine.h>
67 #include <mach/time_value.h>
68 #include <kern/spl.h>
69 #include <kern/assert.h>
70 #include <kern/debug.h>
71 #include <kern/misc_protos.h>
72 #include <kern/startup.h>
73 #include <kern/clock.h>
74 #include <kern/xpr.h>
75 #include <kern/cpu_data.h>
76 #include <kern/processor.h>
77 #include <vm/vm_page.h>
78 #include <vm/pmap.h>
79 #include <vm/vm_kern.h>
80 #include <i386/fpu.h>
81 #include <i386/pmap.h>
82 #include <i386/ipl.h>
83 #include <i386/pio.h>
84 #include <i386/misc_protos.h>
85 #include <i386/cpuid.h>
86 #include <i386/mp.h>
87 #include <i386/machine_routines.h>
88 #include <i386/postcode.h>
89 #if MACH_KDB
90 #include <ddb/db_aout.h>
91 #endif /* MACH_KDB */
92 #include <ddb/tr.h>
93 #ifdef __MACHO__
94 #include <mach/thread_status.h>
95
96 static KernelBootArgs_t *kernelBootArgs;
97 #endif
98
99 vm_offset_t boot_args_start = 0; /* pointer to kernel arguments, set in start.s */
100
101 #ifdef __MACHO__
102 #include <mach-o/loader.h>
103 vm_offset_t edata, etext, end;
104
105 /* operations only against currently loaded 32 bit mach kernel */
106 extern struct segment_command *getsegbyname(const char *);
107 extern struct section *firstsect(struct segment_command *);
108 extern struct section *nextsect(struct segment_command *, struct section *);
109
110 /*
111 * Called first for a mach-o kernel before paging is set up.
112 * Returns the first available physical address in memory.
113 */
114
115 void
116 i386_preinit(void)
117 {
118 struct segment_command *sgp;
119 struct section *sp;
120 struct KernelBootArgs *pp;
121 int i;
122
123 sgp = getsegbyname("__DATA");
124 if (sgp) {
125 sp = firstsect(sgp);
126 if (sp) {
127 do {
128 if ((sp->flags & S_ZEROFILL))
129 bzero((char *) sp->addr, sp->size);
130 } while ((sp = nextsect(sgp, sp)));
131 }
132 }
133
134 kernelBootArgs = (KernelBootArgs_t *)
135 ml_static_ptovirt(boot_args_start);
136 pp = (struct KernelBootArgs *) kernelBootArgs;
137 pp->configEnd = (char *)
138 ml_static_ptovirt((vm_offset_t) pp->configEnd);
139 for (i = 0; i < pp->numBootDrivers; i++) {
140 pp->driverConfig[i].address = (unsigned)
141 ml_static_ptovirt(pp->driverConfig[i].address);
142 }
143 return;
144 }
145 #endif
146
147 extern const char version[];
148 extern const char version_variant[];
149
150 /*
151 * Cpu initialization. Running virtual, but without MACH VM
152 * set up. First C routine called, unless i386_preinit() was called first.
153 */
154 void
155 i386_init(void)
156 {
157 unsigned int maxmem;
158 unsigned int cpus;
159
160 postcode(I386_INIT_ENTRY);
161
162 master_cpu = 0;
163 cpu_data_alloc(TRUE);
164 cpu_init();
165 postcode(CPU_INIT_D);
166
167 /*
168 * Setup some processor related structures to satisfy funnels.
169 * Must be done before using unparallelized device drivers.
170 */
171 processor_bootstrap();
172
173 PE_init_platform(FALSE, kernelBootArgs);
174 postcode(PE_INIT_PLATFORM_D);
175
176 /*
177 * Set up initial thread so current_thread() works early on
178 */
179 thread_bootstrap();
180 postcode(THREAD_BOOTSTRAP_D);
181
182 printf_init(); /* Init this in case we need debugger */
183 panic_init(); /* Init this in case we need debugger */
184
185 /* setup debugging output if one has been chosen */
186 PE_init_kprintf(FALSE);
187
188 /* setup console output */
189 PE_init_printf(FALSE);
190
191 kprintf("version_variant = %s\n", version_variant);
192 kprintf("version = %s\n", version);
193
194 /*
195 * VM initialization, after this we're using page tables...
196 * The maximum number of cpus must be set beforehand.
197 */
198 if (!PE_parse_boot_arg("maxmem", &maxmem))
199 maxmem=0;
200 else
201 maxmem = maxmem * (1024 * 1024);
202
203 if (PE_parse_boot_arg("cpus", &cpus)) {
204 if ((0 < cpus) && (cpus < max_ncpus))
205 max_ncpus = cpus;
206 }
207
208 i386_vm_init(maxmem, kernelBootArgs);
209
210 PE_init_platform(TRUE, kernelBootArgs);
211
212 /* create the console for verbose or pretty mode */
213 PE_create_console();
214
215 machine_startup();
216
217 }