2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989, 1988 Carnegie Mellon University
28 * All Rights Reserved.
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.
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.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
51 #include <platforms.h>
55 #include <mach/i386/vm_param.h>
58 #include <mach/vm_param.h>
59 #include <mach/vm_prot.h>
60 #include <mach/machine.h>
61 #include <mach/time_value.h>
63 #include <kern/assert.h>
64 #include <kern/debug.h>
65 #include <kern/misc_protos.h>
66 #include <kern/startup.h>
67 #include <kern/clock.h>
69 #include <kern/cpu_data.h>
70 #include <kern/processor.h>
71 #include <vm/vm_page.h>
73 #include <vm/vm_kern.h>
75 #include <i386/pmap.h>
78 #include <i386/misc_protos.h>
79 #include <i386/cpuid.h>
81 #include <i386/machine_routines.h>
82 #include <i386/postcode.h>
84 #include <ddb/db_aout.h>
88 #include <mach/thread_status.h>
90 static KernelBootArgs_t
*kernelBootArgs
;
93 vm_offset_t boot_args_start
= 0; /* pointer to kernel arguments, set in start.s */
96 #include <mach-o/loader.h>
97 vm_offset_t edata
, etext
, end
;
99 /* operations only against currently loaded 32 bit mach kernel */
100 extern struct segment_command
*getsegbyname(const char *);
101 extern struct section
*firstsect(struct segment_command
*);
102 extern struct section
*nextsect(struct segment_command
*, struct section
*);
105 * Called first for a mach-o kernel before paging is set up.
106 * Returns the first available physical address in memory.
112 struct segment_command
*sgp
;
114 struct KernelBootArgs
*pp
;
117 sgp
= getsegbyname("__DATA");
122 if ((sp
->flags
& S_ZEROFILL
))
123 bzero((char *) sp
->addr
, sp
->size
);
124 } while ((sp
= nextsect(sgp
, sp
)));
128 kernelBootArgs
= (KernelBootArgs_t
*)
129 ml_static_ptovirt(boot_args_start
);
130 pp
= (struct KernelBootArgs
*) kernelBootArgs
;
131 pp
->configEnd
= (char *)
132 ml_static_ptovirt((vm_offset_t
) pp
->configEnd
);
133 for (i
= 0; i
< pp
->numBootDrivers
; i
++) {
134 pp
->driverConfig
[i
].address
= (unsigned)
135 ml_static_ptovirt(pp
->driverConfig
[i
].address
);
141 extern const char version
[];
142 extern const char version_variant
[];
145 * Cpu initialization. Running virtual, but without MACH VM
146 * set up. First C routine called, unless i386_preinit() was called first.
154 postcode(I386_INIT_ENTRY
);
157 cpu_data_alloc(TRUE
);
159 postcode(CPU_INIT_D
);
162 * Setup some processor related structures to satisfy funnels.
163 * Must be done before using unparallelized device drivers.
165 processor_bootstrap();
167 PE_init_platform(FALSE
, kernelBootArgs
);
168 postcode(PE_INIT_PLATFORM_D
);
171 * Set up initial thread so current_thread() works early on
174 postcode(THREAD_BOOTSTRAP_D
);
176 printf_init(); /* Init this in case we need debugger */
177 panic_init(); /* Init this in case we need debugger */
179 /* setup debugging output if one has been chosen */
180 PE_init_kprintf(FALSE
);
182 /* setup console output */
183 PE_init_printf(FALSE
);
185 kprintf("version_variant = %s\n", version_variant
);
186 kprintf("version = %s\n", version
);
189 * VM initialization, after this we're using page tables...
190 * The maximum number of cpus must be set beforehand.
192 if (!PE_parse_boot_arg("maxmem", &maxmem
))
195 maxmem
= maxmem
* (1024 * 1024);
197 if (PE_parse_boot_arg("cpus", &cpus
)) {
198 if ((0 < cpus
) && (cpus
< max_ncpus
))
202 i386_vm_init(maxmem
, kernelBootArgs
);
204 PE_init_platform(TRUE
, kernelBootArgs
);
206 /* create the console for verbose or pretty mode */