]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/startup.c
54596deed7aa408dbe39184b0d86069bdce27927
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_kern.h>
90 #include <vm/vm_init.h>
91 #include <vm/vm_map.h>
92 #include <vm/vm_object.h>
93 #include <vm/vm_page.h>
94 #include <vm/vm_pageout.h>
95 #include <machine/pmap.h>
96 #include <machine/commpage.h>
97 #include <sys/version.h>
100 #include <ppc/Firmware.h>
101 #include <ppc/mappings.h>
105 extern void rtclock_reset(void);
108 void cpu_launch_first_thread(
110 void start_kernel_threads(void);
111 void swapin_thread();
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.
162 * Initialize the Event Trace Analysis Package.
163 * Dynamic Phase: 2 of 2
168 * Create a kernel thread to start the other kernel
171 startup_thread
= kernel_thread_with_priority(
172 kernel_task
, MAXPRI_KERNEL
,
173 start_kernel_threads
, TRUE
, FALSE
);
175 * Pretend it is already running.
177 * We can do this without locking, because nothing
178 * else is running yet.
180 startup_thread
->state
= TH_RUN
;
181 hw_atomic_add(&startup_thread
->processor_set
->run_count
, 1);
186 cpu_launch_first_thread(startup_thread
);
188 panic("cpu_launch_first_thread returns!");
192 * Now running in a thread. Create the rest of the kernel threads
193 * and the bootstrap task.
196 start_kernel_threads(void)
200 thread_bind(current_thread(), cpu_to_processor(cpu_number()));
203 * Create the idle threads and the other
206 for (i
= 0; i
< NCPUS
; i
++) {
207 processor_t processor
= cpu_to_processor(i
);
211 thread
= kernel_thread_with_priority(
212 kernel_task
, MAXPRI_KERNEL
,
213 idle_thread
, TRUE
, FALSE
);
216 thread_bind_locked(thread
, processor
);
217 processor
->idle_thread
= thread
;
219 thread
->state
|= TH_IDLE
;
220 thread_go_locked(thread
, THREAD_AWAKENED
);
221 thread_unlock(thread
);
226 * Initialize the thread reaper mechanism.
228 thread_reaper_init();
231 * Initialize the stack swapin mechanism.
236 * Initialize the periodic scheduler mechanism.
241 * Initialize the thread callout mechanism.
243 thread_call_initialize();
246 * Invoke some black magic.
253 * Create the clock service.
255 clock_service_create();
258 * Create the device service.
260 device_service_create();
262 shared_file_boot_time_init();
270 (void) spllo(); /* Allow interruptions */
273 * Fill in the comm area (mapped into every task address space.)
278 * Start the user bootstrap.
283 extern void bsd_init(void);
288 thread_bind(current_thread(), PROCESSOR_NULL
);
291 * Become the pageout daemon.
301 processor_t myprocessor
= current_processor();
304 myprocessor
->cpu_data
= get_cpu_data();
305 thread
= myprocessor
->next_thread
;
306 myprocessor
->next_thread
= THREAD_NULL
;
307 if (thread
== THREAD_NULL
) {
308 thread
= machine_wake_thread
;
309 machine_wake_thread
= THREAD_NULL
;
311 thread_machine_set_current(thread
);
312 if (thread
== machine_wake_thread
)
313 thread_bind(thread
, myprocessor
);
315 cpu_launch_first_thread(thread
);
321 * Now running in a thread context
324 start_cpu_thread(void)
326 processor_t processor
;
328 processor
= cpu_to_processor(cpu_number());
330 slave_machine_init();
332 if (processor
->processor_self
== IP_NULL
) {
333 ipc_processor_init(processor
);
334 ipc_processor_enable(processor
);
337 (void) thread_terminate(current_act());
341 * Start up the first thread on a CPU.
344 cpu_launch_first_thread(
347 register int mycpu
= cpu_number();
348 processor_t processor
= cpu_to_processor(mycpu
);
350 processor
->cpu_data
->preemption_level
= 0;
353 start_timer(&kernel_timer
[mycpu
]);
354 clock_get_uptime(&processor
->last_dispatch
);
356 if (thread
== THREAD_NULL
|| thread
== processor
->idle_thread
)
357 panic("cpu_launch_first_thread");
359 rtclock_reset(); /* start realtime clock ticking */
360 PMAP_ACTIVATE_KERNEL(mycpu
);
362 thread_machine_set_current(thread
);
364 thread
->state
&= ~TH_UNINT
;
365 thread
->last_processor
= processor
;
366 processor
->current_pri
= thread
->sched_pri
;
367 _mk_sp_thread_begin(thread
, processor
);
368 thread_unlock(thread
);
369 timer_switch(&thread
->system_timer
);
371 PMAP_ACTIVATE_USER(thread
->top_act
, mycpu
);
373 /* preemption enabled by load_context */
374 load_context(thread
);