]>
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_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.
60 * Mach kernel startup.
64 #include <xpr_debug.h>
66 #include <mach_host.h>
69 #include <mach/boolean.h>
70 #include <mach/machine.h>
71 #include <mach/thread_act.h>
72 #include <mach/task_special_ports.h>
73 #include <mach/vm_param.h>
74 #include <ipc/ipc_init.h>
75 #include <kern/assert.h>
76 #include <kern/misc_protos.h>
77 #include <kern/clock.h>
78 #include <kern/cpu_number.h>
79 #include <kern/ledger.h>
80 #include <kern/machine.h>
81 #include <kern/processor.h>
82 #include <kern/sched_prim.h>
83 #include <kern/startup.h>
84 #include <kern/task.h>
85 #include <kern/thread.h>
86 #include <kern/timer.h>
88 #include <kern/zalloc.h>
89 #include <kern/locks.h>
90 #include <vm/vm_shared_memory_server.h>
91 #include <vm/vm_kern.h>
92 #include <vm/vm_init.h>
93 #include <vm/vm_map.h>
94 #include <vm/vm_object.h>
95 #include <vm/vm_page.h>
96 #include <vm/vm_pageout.h>
97 #include <machine/pmap.h>
98 #include <machine/commpage.h>
99 #include <libkern/version.h>
102 #include <ppc/Firmware.h>
103 #include <ppc/mappings.h>
104 #include <ppc/serial_io.h>
107 static void kernel_bootstrap_thread(void);
109 static void load_context(
113 * Running in virtual memory, on the interrupt stack.
116 kernel_bootstrap(void)
118 kern_return_t result
;
129 * As soon as the virtual memory system is up, we record
130 * that this CPU is using the kernel pmap.
132 PMAP_ACTIVATE_KERNEL(master_cpu
);
134 mapping_free_prime(); /* Load up with temporary mapping blocks */
140 machine_info
.memory_size
= mem_size
;
141 machine_info
.max_mem
= max_mem
;
142 machine_info
.major_version
= version_major
;
143 machine_info
.minor_version
= version_minor
;
146 * Initialize the IPC, task, and thread subsystems.
153 * Create a kernel thread to execute the kernel bootstrap.
155 result
= kernel_thread_create((thread_continue_t
)kernel_bootstrap_thread
, NULL
, MAXPRI_KERNEL
, &thread
);
156 if (result
!= KERN_SUCCESS
)
157 panic("kernel_bootstrap");
159 thread
->state
= TH_RUN
;
160 thread_deallocate(thread
);
162 load_context(thread
);
167 * Now running in a thread. Kick off other services,
168 * invoke user bootstrap, enter pageout loop.
171 kernel_bootstrap_thread(void)
173 processor_t processor
= current_processor();
174 thread_t self
= current_thread();
177 * Create the idle processor thread.
179 idle_thread_create(processor
);
182 * N.B. Do not stick anything else
185 * Start up the scheduler services.
190 * Remain on current processor as
191 * additional processors come online.
193 thread_bind(self
, processor
);
196 * Kick off memory mapping adjustments.
201 * Create the clock service.
203 clock_service_create();
206 * Create the device service.
208 device_service_create();
210 shared_file_boot_time_init(ENV_DEFAULT_ROOT
, cpu_type());
218 (void) spllo(); /* Allow interruptions */
221 * Fill in the comm area (mapped into every task address space.)
226 * Start the user bootstrap.
235 serial_keyboard_init(); /* Start serial keyboard if wanted */
238 thread_bind(self
, PROCESSOR_NULL
);
241 * Become the pageout daemon.
250 * Load the first thread to start a processor.
255 processor_t processor
= current_processor();
259 * Use the idle processor thread if there
260 * is no dedicated start up thread.
262 if (processor
->next_thread
== THREAD_NULL
) {
263 thread
= processor
->idle_thread
;
264 thread
->continuation
= (thread_continue_t
)processor_start_thread
;
265 thread
->parameter
= NULL
;
268 thread
= processor
->next_thread
;
269 processor
->next_thread
= THREAD_NULL
;
272 load_context(thread
);
277 * processor_start_thread:
279 * First thread to execute on a started processor.
281 * Called at splsched.
284 processor_start_thread(void)
286 processor_t processor
= current_processor();
287 thread_t self
= current_thread();
289 slave_machine_init();
292 * If running the idle processor thread,
293 * reenter the idle loop, else terminate.
295 if (self
== processor
->idle_thread
)
296 thread_block((thread_continue_t
)idle_thread
);
298 thread_terminate(self
);
305 * Start the first thread on a processor.
311 processor_t processor
= current_processor();
313 machine_set_current_thread(thread
);
314 processor_up(processor
);
316 PMAP_ACTIVATE_KERNEL(PROCESSOR_DATA(processor
, slot_num
));
319 * Acquire a stack if none attached. The panic
320 * should never occur since the thread is expected
321 * to have reserved stack.
323 if (!thread
->kernel_stack
) {
324 if (!stack_alloc_try(thread
))
325 panic("load_context");
329 * The idle processor threads are not counted as
330 * running for load calculations.
332 if (!(thread
->state
& TH_IDLE
))
333 pset_run_incr(thread
->processor_set
);
335 processor
->active_thread
= thread
;
336 processor
->current_pri
= thread
->sched_pri
;
337 processor
->deadline
= UINT64_MAX
;
338 thread
->last_processor
= processor
;
340 processor
->last_dispatch
= mach_absolute_time();
341 timer_switch((uint32_t)processor
->last_dispatch
,
342 &PROCESSOR_DATA(processor
, offline_timer
));
344 PMAP_ACTIVATE_USER(thread
, PROCESSOR_DATA(processor
, slot_num
));
346 machine_load_context(thread
);