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.
52 #include <platforms.h>
55 #include <fast_idle.h>
57 #include <mach/i386/vm_param.h>
60 #include <mach/vm_param.h>
61 #include <mach/vm_prot.h>
62 #include <mach/machine.h>
63 #include <mach/time_value.h>
64 #include <kern/etap_macros.h>
66 #include <kern/assert.h>
67 #include <kern/debug.h>
68 #include <kern/misc_protos.h>
69 #include <kern/startup.h>
70 #include <kern/clock.h>
71 #include <kern/time_out.h>
73 #include <kern/cpu_data.h>
74 #include <kern/processor.h>
75 #include <vm/vm_page.h>
77 #include <vm/vm_kern.h>
79 #include <i386/pmap.h>
82 #include <i386/misc_protos.h>
83 #include <i386/cpuid.h>
84 #include <i386/rtclock_entries.h>
87 #include <ddb/db_aout.h>
91 #include <mach/boot_info.h>
92 #include <mach/thread_status.h>
94 static KernelBootArgs_t
*kernelBootArgs
;
97 vm_offset_t boot_args_start
= 0; /* pointer to kernel arguments, set in start.s */
100 #include <mach-o/loader.h>
101 vm_offset_t edata
, etext
, end
;
104 * Called first for a mach-o kernel before paging is set up.
105 * Returns the first available physical address in memory.
111 struct segment_command
*sgp
;
114 sgp
= (struct segment_command
*) getsegbyname("__DATA");
116 sp
= (struct section
*) firstsect(sgp
);
119 if (sp
->flags
& S_ZEROFILL
)
120 bzero((char *) sp
->addr
, sp
->size
);
121 } while (sp
= (struct section
*)nextsect(sgp
, sp
));
125 kernelBootArgs
= (KernelBootArgs_t
*) boot_args_start
;
126 end
= round_page( kernelBootArgs
->kaddr
+ kernelBootArgs
->ksize
);
132 extern const char version
[];
133 extern const char version_variant
[];
136 * Cpu initialization. Running virtual, but without MACH VM
137 * set up. First C routine called, unless i386_preinit() was called first.
147 * Setup some processor related structures to satisfy funnels.
148 * Must be done before using unparallelized device drivers.
150 processor_ptr
[0] = &processor_array
[0];
152 master_processor
= cpu_to_processor(master_cpu
);
154 PE_init_platform(FALSE
, kernelBootArgs
);
157 * Set up initial thread so current_thread() works early on
161 printf_init(); /* Init this in case we need debugger */
162 panic_init(); /* Init this in case we need debugger */
164 /* setup debugging output if one has been chosen */
165 PE_init_kprintf(FALSE
);
166 kprintf("kprintf initialized\n");
168 /* setup console output */
169 PE_init_printf(FALSE
);
171 kprintf("version_variant = %s\n", version_variant
);
172 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 maxmem
= maxmem
* (1024 * 1024);
184 if (PE_parse_boot_arg("cpus", &wncpu
)) {
185 if (!((wncpu
> 0) && (wncpu
< NCPUS
)))
190 i386_vm_init(maxmem
, kernelBootArgs
);
192 PE_init_platform(TRUE
, kernelBootArgs
);
194 /* create the console for verbose or pretty mode */