2 * Copyright (c) 2003-2008 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989, 1988 Carnegie Mellon University
34 * All Rights Reserved.
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.
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.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
57 #include <platforms.h>
60 #include <mach/i386/vm_param.h>
63 #include <mach/vm_param.h>
64 #include <mach/vm_prot.h>
65 #include <mach/machine.h>
66 #include <mach/time_value.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>
75 #include <kern/cpu_data.h>
76 #include <kern/processor.h>
77 #include <console/serial_protos.h>
78 #include <vm/vm_page.h>
80 #include <vm/vm_kern.h>
82 #include <i386/pmap.h>
84 #include <i386/misc_protos.h>
85 #include <i386/cpuid.h>
87 #include <i386/mp_desc.h>
88 #include <i386/machine_routines.h>
89 #include <i386/machine_check.h>
90 #include <i386/postcode.h>
91 #include <i386/Diagnostics.h>
92 #include <i386/pmCPU.h>
94 #include <i386/locks.h> /* LcksOpts */
96 #include <ddb/db_aout.h>
100 static boot_args
*kernelBootArgs
;
104 extern int disableConsoleOutput
;
105 extern const char version
[];
106 extern const char version_variant
[];
107 extern int nx_enabled
;
109 extern int noVMX
; /* if set, rosetta should not emulate altivec */
112 * Cpu initialization. Running virtual, but without MACH VM
113 * set up. First C routine called.
116 i386_init(vm_offset_t boot_args_start
)
119 uint64_t maxmemtouse
;
121 boolean_t legacy_mode
;
124 postcode(I386_INIT_ENTRY
);
126 i386_macho_zerofill();
128 /* Initialize machine-check handling */
132 * Setup boot args given the physical start address.
134 kernelBootArgs
= (boot_args
*)
135 ml_static_ptovirt(boot_args_start
);
136 kernelBootArgs
->MemoryMap
= (uint32_t)
137 ml_static_ptovirt((vm_offset_t
)kernelBootArgs
->MemoryMap
);
138 kernelBootArgs
->deviceTreeP
= (uint32_t)
139 ml_static_ptovirt((vm_offset_t
)kernelBootArgs
->deviceTreeP
);
142 (void) cpu_data_alloc(TRUE
);
144 postcode(CPU_INIT_D
);
146 PE_init_platform(FALSE
, kernelBootArgs
);
147 postcode(PE_INIT_PLATFORM_D
);
149 printf_init(); /* Init this in case we need debugger */
150 panic_init(); /* Init this in case we need debugger */
152 /* setup debugging output if one has been chosen */
153 PE_init_kprintf(FALSE
);
155 if (!PE_parse_boot_argn("diag", &dgWork
.dgFlags
, sizeof (dgWork
.dgFlags
)))
159 if(PE_parse_boot_argn("serial", &serialmode
, sizeof (serialmode
))) {
160 /* We want a serial keyboard and/or console */
161 kprintf("Serial mode specified: %08X\n", serialmode
);
164 (void)switch_to_serial_console();
165 disableConsoleOutput
= FALSE
; /* Allow printfs to happen */
168 /* setup console output */
169 PE_init_printf(FALSE
);
171 kprintf("version_variant = %s\n", version_variant
);
172 kprintf("version = %s\n", version
);
174 if (!PE_parse_boot_argn("maxmem", &maxmem
, sizeof (maxmem
)))
177 maxmemtouse
= ((uint64_t)maxmem
) * (uint64_t)(1024 * 1024);
179 if (PE_parse_boot_argn("cpus", &cpus
, sizeof (cpus
))) {
180 if ((0 < cpus
) && (cpus
< max_ncpus
))
185 * debug support for > 4G systems
187 if (!PE_parse_boot_argn("himemory_mode", &vm_himemory_mode
, sizeof (vm_himemory_mode
)))
188 vm_himemory_mode
= 0;
190 if (!PE_parse_boot_argn("immediate_NMI", &fidn
, sizeof (fidn
)))
191 force_immediate_debugger_NMI
= FALSE
;
193 force_immediate_debugger_NMI
= fidn
;
196 * At this point we check whether we are a 64-bit processor
197 * and that we're not restricted to legacy mode, 32-bit operation.
199 boolean_t IA32e
= FALSE
;
200 if (cpuid_extfeatures() & CPUID_EXTFEATURE_EM64T
) {
201 kprintf("EM64T supported");
202 if (PE_parse_boot_argn("-legacy", &legacy_mode
, sizeof (legacy_mode
))) {
203 kprintf(" but legacy mode forced\n");
206 kprintf(" and will be enabled\n");
210 if (!(cpuid_extfeatures() & CPUID_EXTFEATURE_XD
))
213 /* Obtain "lcks" options:this currently controls lock statistics */
214 if (!PE_parse_boot_argn("lcks", &LcksOpts
, sizeof (LcksOpts
)))
218 * VM initialization, after this we're using page tables...
219 * The maximum number of cpus must be set beforehand.
221 i386_vm_init(maxmemtouse
, IA32e
, kernelBootArgs
);
223 if ( ! PE_parse_boot_argn("novmx", &noVMX
, sizeof (noVMX
)))
224 noVMX
= 0; /* OK to support Altivec in rosetta? */
227 power_management_init();
229 PE_init_platform(TRUE
, kernelBootArgs
);
231 /* create the console for verbose or pretty mode */
234 processor_bootstrap();