2 * Copyright (c) 2003-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989, 1988 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
59 #include <platforms.h>
62 #include <mach/i386/vm_param.h>
65 #include <mach/vm_param.h>
66 #include <mach/vm_prot.h>
67 #include <mach/machine.h>
68 #include <mach/time_value.h>
70 #include <kern/assert.h>
71 #include <kern/debug.h>
72 #include <kern/misc_protos.h>
73 #include <kern/startup.h>
74 #include <kern/clock.h>
77 #include <kern/cpu_data.h>
78 #include <kern/processor.h>
79 #include <console/serial_protos.h>
80 #include <vm/vm_page.h>
82 #include <vm/vm_kern.h>
84 #include <i386/pmap.h>
86 #include <i386/misc_protos.h>
87 #include <i386/cpuid.h>
89 #include <i386/mp_desc.h>
90 #include <i386/machine_routines.h>
91 #include <i386/postcode.h>
92 #include <i386/Diagnostics.h>
93 #include <i386/pmCPU.h>
95 #include <i386/hpet.h>
97 #include <ddb/db_aout.h>
101 static boot_args
*kernelBootArgs
;
103 extern int disableConsoleOutput
;
104 extern const char version
[];
105 extern const char version_variant
[];
106 extern int nx_enabled
;
108 extern int noVMX
; /* if set, rosetta should not emulate altivec */
110 void cpu_stack_set(void);
114 * Cpu initialization. Running virtual, but without MACH VM
115 * set up. First C routine called.
118 i386_init(vm_offset_t boot_args_start
)
121 uint64_t maxmemtouse
;
123 boolean_t legacy_mode
;
125 postcode(I386_INIT_ENTRY
);
127 i386_macho_zerofill();
130 * Setup boot args given the physical start address.
132 kernelBootArgs
= (boot_args
*)
133 ml_static_ptovirt(boot_args_start
);
134 kernelBootArgs
->MemoryMap
= (uint32_t)
135 ml_static_ptovirt((vm_offset_t
)kernelBootArgs
->MemoryMap
);
136 kernelBootArgs
->deviceTreeP
= (uint32_t)
137 ml_static_ptovirt((vm_offset_t
)kernelBootArgs
->deviceTreeP
);
140 (void) cpu_data_alloc(TRUE
);
142 postcode(CPU_INIT_D
);
144 /* init processor performance control */
147 PE_init_platform(FALSE
, kernelBootArgs
);
148 postcode(PE_INIT_PLATFORM_D
);
150 printf_init(); /* Init this in case we need debugger */
151 panic_init(); /* Init this in case we need debugger */
153 /* setup debugging output if one has been chosen */
154 PE_init_kprintf(FALSE
);
156 if (!PE_parse_boot_arg("diag", &dgWork
.dgFlags
))
160 if(PE_parse_boot_arg("serial", &serialmode
)) {
161 /* We want a serial keyboard and/or console */
162 kprintf("Serial mode specified: %08X\n", serialmode
);
165 (void)switch_to_serial_console();
166 disableConsoleOutput
= FALSE
; /* Allow printfs to happen */
169 /* setup console output */
170 PE_init_printf(FALSE
);
172 kprintf("version_variant = %s\n", version_variant
);
173 kprintf("version = %s\n", version
);
176 * VM initialization, after this we're using page tables...
177 * The maximum number of cpus must be set beforehand.
179 if (!PE_parse_boot_arg("maxmem", &maxmem
))
182 maxmemtouse
= ((uint64_t)maxmem
) * (uint64_t)(1024 * 1024);
184 if (PE_parse_boot_arg("cpus", &cpus
)) {
185 if ((0 < cpus
) && (cpus
< max_ncpus
))
190 * debug support for > 4G systems
192 if (!PE_parse_boot_arg("himemory_mode", &vm_himemory_mode
))
193 vm_himemory_mode
= 0;
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_arg("-legacy", &legacy_mode
)) {
203 kprintf(" but legacy mode forced\n");
206 kprintf(" and will be enabled\n");
209 if (!(cpuid_extfeatures() & CPUID_EXTFEATURE_XD
))
212 i386_vm_init(maxmemtouse
, IA32e
, kernelBootArgs
);
214 if ( ! PE_parse_boot_arg("novmx", &noVMX
))
215 noVMX
= 0; /* OK to support Altivec in rosetta? */
219 power_management_init();
221 PE_init_platform(TRUE
, kernelBootArgs
);
223 /* create the console for verbose or pretty mode */
226 processor_bootstrap();