2 * Copyright (c) 2003 Apple Computer, 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>
61 #include <mach/i386/vm_param.h>
64 #include <mach/vm_param.h>
65 #include <mach/vm_prot.h>
66 #include <mach/machine.h>
67 #include <mach/time_value.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>
75 #include <kern/cpu_data.h>
76 #include <kern/processor.h>
77 #include <vm/vm_page.h>
79 #include <vm/vm_kern.h>
81 #include <i386/pmap.h>
84 #include <i386/misc_protos.h>
85 #include <i386/cpuid.h>
87 #include <i386/machine_routines.h>
88 #include <i386/postcode.h>
90 #include <ddb/db_aout.h>
94 #include <mach/thread_status.h>
96 static KernelBootArgs_t
*kernelBootArgs
;
99 vm_offset_t boot_args_start
= 0; /* pointer to kernel arguments, set in start.s */
102 #include <mach-o/loader.h>
103 vm_offset_t edata
, etext
, end
;
105 /* operations only against currently loaded 32 bit mach kernel */
106 extern struct segment_command
*getsegbyname(const char *);
107 extern struct section
*firstsect(struct segment_command
*);
108 extern struct section
*nextsect(struct segment_command
*, struct section
*);
111 * Called first for a mach-o kernel before paging is set up.
112 * Returns the first available physical address in memory.
118 struct segment_command
*sgp
;
120 struct KernelBootArgs
*pp
;
123 sgp
= getsegbyname("__DATA");
128 if ((sp
->flags
& S_ZEROFILL
))
129 bzero((char *) sp
->addr
, sp
->size
);
130 } while ((sp
= nextsect(sgp
, sp
)));
134 kernelBootArgs
= (KernelBootArgs_t
*)
135 ml_static_ptovirt(boot_args_start
);
136 pp
= (struct KernelBootArgs
*) kernelBootArgs
;
137 pp
->configEnd
= (char *)
138 ml_static_ptovirt((vm_offset_t
) pp
->configEnd
);
139 for (i
= 0; i
< pp
->numBootDrivers
; i
++) {
140 pp
->driverConfig
[i
].address
= (unsigned)
141 ml_static_ptovirt(pp
->driverConfig
[i
].address
);
147 extern const char version
[];
148 extern const char version_variant
[];
151 * Cpu initialization. Running virtual, but without MACH VM
152 * set up. First C routine called, unless i386_preinit() was called first.
160 postcode(I386_INIT_ENTRY
);
163 cpu_data_alloc(TRUE
);
165 postcode(CPU_INIT_D
);
168 * Setup some processor related structures to satisfy funnels.
169 * Must be done before using unparallelized device drivers.
171 processor_bootstrap();
173 PE_init_platform(FALSE
, kernelBootArgs
);
174 postcode(PE_INIT_PLATFORM_D
);
177 * Set up initial thread so current_thread() works early on
180 postcode(THREAD_BOOTSTRAP_D
);
182 printf_init(); /* Init this in case we need debugger */
183 panic_init(); /* Init this in case we need debugger */
185 /* setup debugging output if one has been chosen */
186 PE_init_kprintf(FALSE
);
188 /* setup console output */
189 PE_init_printf(FALSE
);
191 kprintf("version_variant = %s\n", version_variant
);
192 kprintf("version = %s\n", version
);
195 * VM initialization, after this we're using page tables...
196 * The maximum number of cpus must be set beforehand.
198 if (!PE_parse_boot_arg("maxmem", &maxmem
))
201 maxmem
= maxmem
* (1024 * 1024);
203 if (PE_parse_boot_arg("cpus", &cpus
)) {
204 if ((0 < cpus
) && (cpus
< max_ncpus
))
208 i386_vm_init(maxmem
, kernelBootArgs
);
210 PE_init_platform(TRUE
, kernelBootArgs
);
212 /* create the console for verbose or pretty mode */