]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/startup.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
31 * All Rights Reserved.
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
57 * Mach kernel startup.
61 #include <xpr_debug.h>
64 #include <mach_host.h>
68 #include <mach/boolean.h>
69 #include <mach/machine.h>
70 #include <mach/task_special_ports.h>
71 #include <mach/vm_param.h>
72 #include <ipc/ipc_init.h>
73 #include <kern/assert.h>
74 #include <kern/misc_protos.h>
75 #include <kern/clock.h>
76 #include <kern/cpu_number.h>
77 #include <kern/etap_macros.h>
78 #include <kern/machine.h>
79 #include <kern/processor.h>
80 #include <kern/sched_prim.h>
81 #include <kern/mk_sp.h>
82 #include <kern/startup.h>
83 #include <kern/task.h>
84 #include <kern/thread.h>
85 #include <kern/timer.h>
86 #include <kern/timer_call.h>
88 #include <kern/zalloc.h>
89 #include <vm/vm_shared_memory_server.h>
90 #include <vm/vm_kern.h>
91 #include <vm/vm_init.h>
92 #include <vm/vm_map.h>
93 #include <vm/vm_object.h>
94 #include <vm/vm_page.h>
95 #include <vm/vm_pageout.h>
96 #include <machine/pmap.h>
97 #include <machine/commpage.h>
98 #include <sys/version.h>
101 #include <ppc/Firmware.h>
102 #include <ppc/mappings.h>
106 extern void rtclock_reset(void);
109 void cpu_launch_first_thread(
111 void start_kernel_threads(void);
114 * Running in virtual memory, on the interrupt stack.
115 * Does not return. Dispatches initial thread.
117 * Assumes that master_cpu is set.
122 thread_t startup_thread
;
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
);
137 mapping_free_prime(); /* Load up with temporary mapping blocks */
145 timer_call_initialize();
147 machine_info
.max_cpus
= NCPUS
;
148 machine_info
.memory_size
= mem_size
;
149 machine_info
.avail_cpus
= 0;
150 machine_info
.major_version
= KERNEL_MAJOR_VERSION
;
151 machine_info
.minor_version
= KERNEL_MINOR_VERSION
;
154 * Initialize the IPC, task, and thread subsystems.
161 * Initialize the Event Trace Analysis Package.
162 * Dynamic Phase: 2 of 2
167 * Create a kernel thread to start the other kernel
170 startup_thread
= kernel_thread_create(start_kernel_threads
, MAXPRI_KERNEL
);
175 startup_thread
->state
= TH_RUN
;
176 pset_run_incr(startup_thread
->processor_set
);
178 cpu_launch_first_thread(startup_thread
);
180 panic("cpu_launch_first_thread returns!");
184 * Now running in a thread. Create the rest of the kernel threads
185 * and the bootstrap task.
188 start_kernel_threads(void)
192 thread_bind(current_thread(), cpu_to_processor(cpu_number()));
195 * Create the idle threads and the other
198 for (i
= 0; i
< NCPUS
; i
++) {
199 processor_t processor
= cpu_to_processor(i
);
203 thread
= kernel_thread_create(idle_thread
, MAXPRI_KERNEL
);
207 thread
->bound_processor
= processor
;
208 processor
->idle_thread
= thread
;
210 thread
->sched_pri
= thread
->priority
= IDLEPRI
;
211 thread
->state
= (TH_RUN
| TH_IDLE
);
212 thread_unlock(thread
);
217 * Initialize the thread reaper mechanism.
219 thread_reaper_init();
222 * Initialize the stack swapin mechanism.
227 * Initialize the periodic scheduler mechanism.
232 * Initialize the thread callout mechanism.
234 thread_call_initialize();
237 * Invoke some black magic.
244 * Create the clock service.
246 clock_service_create();
249 * Create the device service.
251 device_service_create();
253 shared_file_boot_time_init(ENV_DEFAULT_ROOT
, machine_slot
[cpu_number()].cpu_type
);
261 (void) spllo(); /* Allow interruptions */
264 * Fill in the comm area (mapped into every task address space.)
269 * Start the user bootstrap.
274 extern void bsd_init(void);
280 serial_keyboard_init(); /* Start serial keyboard if wanted */
283 thread_bind(current_thread(), PROCESSOR_NULL
);
286 * Become the pageout daemon.
296 processor_t myprocessor
= current_processor();
299 thread
= myprocessor
->next_thread
;
300 myprocessor
->next_thread
= THREAD_NULL
;
301 if (thread
== THREAD_NULL
) {
302 thread
= machine_wake_thread
;
303 machine_wake_thread
= THREAD_NULL
;
306 cpu_launch_first_thread(thread
);
312 * Now running in a thread context
315 start_cpu_thread(void)
317 slave_machine_init();
319 (void) thread_terminate(current_act());
323 * Start up the first thread on a CPU.
326 cpu_launch_first_thread(
329 register int mycpu
= cpu_number();
330 processor_t processor
= cpu_to_processor(mycpu
);
332 clock_get_uptime(&processor
->last_dispatch
);
333 start_timer(&kernel_timer
[mycpu
]);
334 machine_thread_set_current(thread
);
337 rtclock_reset(); /* start realtime clock ticking */
338 PMAP_ACTIVATE_KERNEL(mycpu
);
341 thread
->state
&= ~TH_UNINT
;
342 thread
->last_processor
= processor
;
343 processor
->active_thread
= thread
;
344 processor
->current_pri
= thread
->sched_pri
;
345 _mk_sp_thread_begin(thread
, processor
);
346 thread_unlock(thread
);
347 timer_switch(&thread
->system_timer
);
349 PMAP_ACTIVATE_USER(thread
->top_act
, mycpu
);
351 /* preemption enabled by load_context */
352 machine_load_context(thread
);