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