]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/i386_init.c
xnu-792.18.15.tar.gz
[apple/xnu.git] / osfmk / i386 / i386_init.c
CommitLineData
55e303ae 1/*
89b3af67 2 * Copyright (c) 2003-2005 Apple Computer, Inc. All rights reserved.
55e303ae 3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55e303ae 5 *
8f6c56a5
A
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
8ad349bb 24 * limitations under the License.
8f6c56a5
A
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
55e303ae
A
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
55e303ae
A
57#include <platforms.h>
58#include <mach_kdb.h>
55e303ae
A
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>
55e303ae
A
67#include <kern/spl.h>
68#include <kern/assert.h>
69#include <kern/debug.h>
70#include <kern/misc_protos.h>
71#include <kern/startup.h>
72#include <kern/clock.h>
89b3af67 73#include <kern/pms.h>
55e303ae
A
74#include <kern/xpr.h>
75#include <kern/cpu_data.h>
76#include <kern/processor.h>
89b3af67 77#include <console/serial_protos.h>
55e303ae
A
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>
55e303ae
A
84#include <i386/misc_protos.h>
85#include <i386/cpuid.h>
55e303ae 86#include <i386/mp.h>
89b3af67 87#include <i386/mp_desc.h>
91447636
A
88#include <i386/machine_routines.h>
89#include <i386/postcode.h>
89b3af67
A
90#include <i386/Diagnostics.h>
91#include <i386/pmCPU.h>
92#include <i386/tsc.h>
93#include <i386/hpet.h>
55e303ae
A
94#if MACH_KDB
95#include <ddb/db_aout.h>
96#endif /* MACH_KDB */
97#include <ddb/tr.h>
55e303ae 98
89b3af67 99static boot_args *kernelBootArgs;
55e303ae 100
89b3af67
A
101extern int disableConsoleOutput;
102extern const char version[];
103extern const char version_variant[];
104extern int nx_enabled;
8f6c56a5 105
89b3af67 106extern int noVMX; /* if set, rosetta should not emulate altivec */
8f6c56a5 107
89b3af67 108void cpu_stack_set(void);
8ad349bb 109
55e303ae
A
110
111/*
112 * Cpu initialization. Running virtual, but without MACH VM
89b3af67 113 * set up. First C routine called.
55e303ae
A
114 */
115void
89b3af67 116i386_init(vm_offset_t boot_args_start)
55e303ae
A
117{
118 unsigned int maxmem;
89b3af67 119 uint64_t maxmemtouse;
91447636 120 unsigned int cpus;
89b3af67 121 boolean_t legacy_mode;
91447636
A
122
123 postcode(I386_INIT_ENTRY);
55e303ae 124
89b3af67 125 i386_macho_zerofill();
8ad349bb 126
8f6c56a5 127 /*
89b3af67 128 * Setup boot args given the physical start address.
8f6c56a5 129 */
89b3af67
A
130 kernelBootArgs = (boot_args *)
131 ml_static_ptovirt(boot_args_start);
132 kernelBootArgs->MemoryMap = (uint32_t)
133 ml_static_ptovirt((vm_offset_t)kernelBootArgs->MemoryMap);
134 kernelBootArgs->deviceTreeP = (uint32_t)
135 ml_static_ptovirt((vm_offset_t)kernelBootArgs->deviceTreeP);
136
137 master_cpu = 0;
138 (void) cpu_data_alloc(TRUE);
139 cpu_init();
140 postcode(CPU_INIT_D);
8f6c56a5 141
89b3af67
A
142 /* init processor performance control */
143 pmsInit();
144
55e303ae 145 PE_init_platform(FALSE, kernelBootArgs);
91447636 146 postcode(PE_INIT_PLATFORM_D);
55e303ae 147
55e303ae
A
148 printf_init(); /* Init this in case we need debugger */
149 panic_init(); /* Init this in case we need debugger */
150
151 /* setup debugging output if one has been chosen */
152 PE_init_kprintf(FALSE);
55e303ae 153
89b3af67
A
154 if (!PE_parse_boot_arg("diag", &dgWork.dgFlags))
155 dgWork.dgFlags = 0;
156
157 serialmode = 0;
158 if(PE_parse_boot_arg("serial", &serialmode)) {
159 /* We want a serial keyboard and/or console */
160 kprintf("Serial mode specified: %08X\n", serialmode);
161 }
162 if(serialmode & 1) {
163 (void)switch_to_serial_console();
164 disableConsoleOutput = FALSE; /* Allow printfs to happen */
165 }
166
55e303ae
A
167 /* setup console output */
168 PE_init_printf(FALSE);
169
170 kprintf("version_variant = %s\n", version_variant);
171 kprintf("version = %s\n", version);
172
55e303ae
A
173 /*
174 * VM initialization, after this we're using page tables...
175 * The maximum number of cpus must be set beforehand.
176 */
177 if (!PE_parse_boot_arg("maxmem", &maxmem))
89b3af67 178 maxmemtouse=0;
55e303ae 179 else
89b3af67 180 maxmemtouse = ((uint64_t)maxmem) * (uint64_t)(1024 * 1024);
55e303ae 181
91447636
A
182 if (PE_parse_boot_arg("cpus", &cpus)) {
183 if ((0 < cpus) && (cpus < max_ncpus))
184 max_ncpus = cpus;
185 }
55e303ae 186
89b3af67
A
187 /*
188 * debug support for > 4G systems
189 */
190 if (!PE_parse_boot_arg("himemory_mode", &vm_himemory_mode))
191 vm_himemory_mode = 0;
192
193 /*
194 * At this point we check whether we are a 64-bit processor
195 * and that we're not restricted to legacy mode, 32-bit operation.
196 */
197 boolean_t IA32e = FALSE;
198 if (cpuid_extfeatures() & CPUID_EXTFEATURE_EM64T) {
199 kprintf("EM64T supported");
200 if (PE_parse_boot_arg("-legacy", &legacy_mode)) {
201 kprintf(" but legacy mode forced\n");
202 } else {
203 IA32e = TRUE;
204 kprintf(" and will be enabled\n");
205 }
206 }
207 if (!(cpuid_extfeatures() & CPUID_EXTFEATURE_XD))
208 nx_enabled = 0;
209
210 i386_vm_init(maxmemtouse, IA32e, kernelBootArgs);
211
212 if ( ! PE_parse_boot_arg("novmx", &noVMX))
213 noVMX = 0; /* OK to support Altivec in rosetta? */
214
215 tsc_init();
216 hpet_init();
217 power_management_init();
55e303ae
A
218
219 PE_init_platform(TRUE, kernelBootArgs);
220
221 /* create the console for verbose or pretty mode */
222 PE_create_console();
91447636 223
89b3af67
A
224 processor_bootstrap();
225 thread_bootstrap();
226
55e303ae
A
227 machine_startup();
228
229}