]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/startup.c
2 * Copyright (c) 2000-2004 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.
62 * Mach kernel startup.
66 #include <xpr_debug.h>
68 #include <mach_host.h>
71 #include <mach/boolean.h>
72 #include <mach/machine.h>
73 #include <mach/thread_act.h>
74 #include <mach/task_special_ports.h>
75 #include <mach/vm_param.h>
76 #include <ipc/ipc_init.h>
77 #include <kern/assert.h>
78 #include <kern/misc_protos.h>
79 #include <kern/clock.h>
80 #include <kern/cpu_number.h>
81 #include <kern/ledger.h>
82 #include <kern/machine.h>
83 #include <kern/processor.h>
84 #include <kern/sched_prim.h>
85 #include <kern/startup.h>
86 #include <kern/task.h>
87 #include <kern/thread.h>
88 #include <kern/timer.h>
90 #include <kern/zalloc.h>
91 #include <kern/locks.h>
92 #include <vm/vm_shared_memory_server.h>
93 #include <vm/vm_kern.h>
94 #include <vm/vm_init.h>
95 #include <vm/vm_map.h>
96 #include <vm/vm_object.h>
97 #include <vm/vm_page.h>
98 #include <vm/vm_pageout.h>
99 #include <machine/pmap.h>
100 #include <machine/commpage.h>
101 #include <libkern/version.h>
104 #include <ppc/Firmware.h>
105 #include <ppc/mappings.h>
106 #include <ppc/serial_io.h>
109 static void kernel_bootstrap_thread(void);
111 static void load_context(
115 * Running in virtual memory, on the interrupt stack.
118 kernel_bootstrap(void)
120 kern_return_t result
;
131 * As soon as the virtual memory system is up, we record
132 * that this CPU is using the kernel pmap.
134 PMAP_ACTIVATE_KERNEL(master_cpu
);
136 mapping_free_prime(); /* Load up with temporary mapping blocks */
142 machine_info
.memory_size
= mem_size
;
143 machine_info
.max_mem
= max_mem
;
144 machine_info
.major_version
= version_major
;
145 machine_info
.minor_version
= version_minor
;
148 * Initialize the IPC, task, and thread subsystems.
155 * Create a kernel thread to execute the kernel bootstrap.
157 result
= kernel_thread_create((thread_continue_t
)kernel_bootstrap_thread
, NULL
, MAXPRI_KERNEL
, &thread
);
158 if (result
!= KERN_SUCCESS
)
159 panic("kernel_bootstrap");
161 thread
->state
= TH_RUN
;
162 thread_deallocate(thread
);
164 load_context(thread
);
169 * Now running in a thread. Kick off other services,
170 * invoke user bootstrap, enter pageout loop.
173 kernel_bootstrap_thread(void)
175 processor_t processor
= current_processor();
176 thread_t self
= current_thread();
179 * Create the idle processor thread.
181 idle_thread_create(processor
);
184 * N.B. Do not stick anything else
187 * Start up the scheduler services.
192 * Remain on current processor as
193 * additional processors come online.
195 thread_bind(self
, processor
);
198 * Kick off memory mapping adjustments.
203 * Create the clock service.
205 clock_service_create();
208 * Create the device service.
210 device_service_create();
212 shared_file_boot_time_init(ENV_DEFAULT_ROOT
, cpu_type());
220 (void) spllo(); /* Allow interruptions */
223 * Fill in the comm area (mapped into every task address space.)
228 * Start the user bootstrap.
237 serial_keyboard_init(); /* Start serial keyboard if wanted */
240 thread_bind(self
, PROCESSOR_NULL
);
243 * Become the pageout daemon.
252 * Load the first thread to start a processor.
257 processor_t processor
= current_processor();
261 * Use the idle processor thread if there
262 * is no dedicated start up thread.
264 if (processor
->next_thread
== THREAD_NULL
) {
265 thread
= processor
->idle_thread
;
266 thread
->continuation
= (thread_continue_t
)processor_start_thread
;
267 thread
->parameter
= NULL
;
270 thread
= processor
->next_thread
;
271 processor
->next_thread
= THREAD_NULL
;
274 load_context(thread
);
279 * processor_start_thread:
281 * First thread to execute on a started processor.
283 * Called at splsched.
286 processor_start_thread(void)
288 processor_t processor
= current_processor();
289 thread_t self
= current_thread();
291 slave_machine_init();
294 * If running the idle processor thread,
295 * reenter the idle loop, else terminate.
297 if (self
== processor
->idle_thread
)
298 thread_block((thread_continue_t
)idle_thread
);
300 thread_terminate(self
);
307 * Start the first thread on a processor.
313 processor_t processor
= current_processor();
315 machine_set_current_thread(thread
);
316 processor_up(processor
);
318 PMAP_ACTIVATE_KERNEL(PROCESSOR_DATA(processor
, slot_num
));
321 * Acquire a stack if none attached. The panic
322 * should never occur since the thread is expected
323 * to have reserved stack.
325 if (!thread
->kernel_stack
) {
326 if (!stack_alloc_try(thread
))
327 panic("load_context");
331 * The idle processor threads are not counted as
332 * running for load calculations.
334 if (!(thread
->state
& TH_IDLE
))
335 pset_run_incr(thread
->processor_set
);
337 processor
->active_thread
= thread
;
338 processor
->current_pri
= thread
->sched_pri
;
339 processor
->deadline
= UINT64_MAX
;
340 thread
->last_processor
= processor
;
342 processor
->last_dispatch
= mach_absolute_time();
343 timer_switch((uint32_t)processor
->last_dispatch
,
344 &PROCESSOR_DATA(processor
, offline_timer
));
346 PMAP_ACTIVATE_USER(thread
, PROCESSOR_DATA(processor
, slot_num
));
348 machine_load_context(thread
);