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