]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/startup.c
dc9a6a92a28afc24d8e9cc2766264020d8915631
2 * Copyright (c) 2000-2005 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.
54 * Mach kernel startup.
58 #include <xpr_debug.h>
60 #include <mach_host.h>
63 #include <mach/boolean.h>
64 #include <mach/machine.h>
65 #include <mach/thread_act.h>
66 #include <mach/task_special_ports.h>
67 #include <mach/vm_param.h>
68 #include <ipc/ipc_init.h>
69 #include <kern/assert.h>
70 #include <kern/misc_protos.h>
71 #include <kern/clock.h>
72 #include <kern/cpu_number.h>
73 #include <kern/ledger.h>
74 #include <kern/machine.h>
75 #include <kern/processor.h>
76 #include <kern/sched_prim.h>
77 #include <kern/startup.h>
78 #include <kern/task.h>
79 #include <kern/thread.h>
80 #include <kern/timer.h>
82 #include <kern/zalloc.h>
83 #include <kern/locks.h>
84 #include <console/serial_protos.h>
85 #include <vm/vm_shared_memory_server.h>
86 #include <vm/vm_kern.h>
87 #include <vm/vm_init.h>
88 #include <vm/vm_map.h>
89 #include <vm/vm_object.h>
90 #include <vm/vm_page.h>
91 #include <vm/vm_pageout.h>
92 #include <machine/pmap.h>
93 #include <machine/commpage.h>
94 #include <libkern/version.h>
97 #include <ppc/Firmware.h>
98 #include <ppc/mappings.h>
101 static void kernel_bootstrap_thread(void);
103 static void load_context(
107 extern void cpu_window_init(int);
112 * 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
);
157 if (result
!= KERN_SUCCESS
) panic("kernel_bootstrap: result = %08X\n", result
);
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.)
227 * create and initialize a copy window
234 * Start the user bootstrap.
242 serial_keyboard_init(); /* Start serial keyboard if wanted */
244 thread_bind(self
, PROCESSOR_NULL
);
247 * Become the pageout daemon.
256 * Load the first thread to start a processor.
261 processor_t processor
= current_processor();
265 * Use the idle processor thread if there
266 * is no dedicated start up thread.
268 if (processor
->next_thread
== THREAD_NULL
) {
269 thread
= processor
->idle_thread
;
270 thread
->continuation
= (thread_continue_t
)processor_start_thread
;
271 thread
->parameter
= NULL
;
274 thread
= processor
->next_thread
;
275 processor
->next_thread
= THREAD_NULL
;
278 load_context(thread
);
283 * processor_start_thread:
285 * First thread to execute on a started processor.
287 * Called at splsched.
290 processor_start_thread(void)
292 processor_t processor
= current_processor();
293 thread_t self
= current_thread();
295 slave_machine_init();
298 * If running the idle processor thread,
299 * reenter the idle loop, else terminate.
301 if (self
== processor
->idle_thread
)
302 thread_block((thread_continue_t
)idle_thread
);
304 thread_terminate(self
);
311 * Start the first thread on a processor.
317 processor_t processor
= current_processor();
319 machine_set_current_thread(thread
);
320 processor_up(processor
);
322 PMAP_ACTIVATE_KERNEL(PROCESSOR_DATA(processor
, slot_num
));
325 * Acquire a stack if none attached. The panic
326 * should never occur since the thread is expected
327 * to have reserved stack.
329 if (!thread
->kernel_stack
) {
330 if (!stack_alloc_try(thread
))
331 panic("load_context");
335 * The idle processor threads are not counted as
336 * running for load calculations.
338 if (!(thread
->state
& TH_IDLE
))
339 pset_run_incr(thread
->processor_set
);
341 processor
->active_thread
= thread
;
342 processor
->current_pri
= thread
->sched_pri
;
343 processor
->deadline
= UINT64_MAX
;
344 thread
->last_processor
= processor
;
346 processor
->last_dispatch
= mach_absolute_time();
347 timer_switch((uint32_t)processor
->last_dispatch
,
348 &PROCESSOR_DATA(processor
, offline_timer
));
350 PMAP_ACTIVATE_USER(thread
, PROCESSOR_DATA(processor
, slot_num
));
352 machine_load_context(thread
);