]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/startup.c
f5ca35a41f6e165116bd14b044475280c9d03f57
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);
112 void swapin_thread();
115 * Running in virtual memory, on the interrupt stack.
116 * Does not return. Dispatches initial thread.
118 * Assumes that master_cpu is set.
123 thread_t startup_thread
;
132 * As soon as the virtual memory system is up, we record
133 * that this CPU is using the kernel pmap.
135 PMAP_ACTIVATE_KERNEL(master_cpu
);
138 mapping_free_prime(); /* Load up with temporary mapping blocks */
146 timer_call_initialize();
148 machine_info
.max_cpus
= NCPUS
;
149 machine_info
.memory_size
= mem_size
;
150 machine_info
.avail_cpus
= 0;
151 machine_info
.major_version
= KERNEL_MAJOR_VERSION
;
152 machine_info
.minor_version
= KERNEL_MINOR_VERSION
;
155 * Initialize the IPC, task, and thread subsystems.
163 * Initialize the Event Trace Analysis Package.
164 * Dynamic Phase: 2 of 2
169 * Create a kernel thread to start the other kernel
172 startup_thread
= kernel_thread_with_priority(
173 kernel_task
, MAXPRI_KERNEL
,
174 start_kernel_threads
, TRUE
, FALSE
);
176 * Pretend it is already running.
178 * We can do this without locking, because nothing
179 * else is running yet.
181 startup_thread
->state
= TH_RUN
;
182 hw_atomic_add(&startup_thread
->processor_set
->run_count
, 1);
187 cpu_launch_first_thread(startup_thread
);
189 panic("cpu_launch_first_thread returns!");
193 * Now running in a thread. Create the rest of the kernel threads
194 * and the bootstrap task.
197 start_kernel_threads(void)
201 thread_bind(current_thread(), cpu_to_processor(cpu_number()));
204 * Create the idle threads and the other
207 for (i
= 0; i
< NCPUS
; i
++) {
208 processor_t processor
= cpu_to_processor(i
);
212 thread
= kernel_thread_with_priority(
213 kernel_task
, MAXPRI_KERNEL
,
214 idle_thread
, TRUE
, FALSE
);
217 thread_bind_locked(thread
, processor
);
218 processor
->idle_thread
= thread
;
220 thread
->state
|= TH_IDLE
;
221 thread_go_locked(thread
, THREAD_AWAKENED
);
222 thread_unlock(thread
);
227 * Initialize the thread reaper mechanism.
229 thread_reaper_init();
232 * Initialize the stack swapin mechanism.
237 * Initialize the periodic scheduler mechanism.
242 * Initialize the thread callout mechanism.
244 thread_call_initialize();
247 * Invoke some black magic.
254 * Create the clock service.
256 clock_service_create();
259 * Create the device service.
261 device_service_create();
263 shared_file_boot_time_init(ENV_DEFAULT_SYSTEM
, ENV_DEFAULT_ROOT
);
271 (void) spllo(); /* Allow interruptions */
274 * Fill in the comm area (mapped into every task address space.)
279 * Start the user bootstrap.
284 extern void bsd_init(void);
290 serial_keyboard_init(); /* Start serial keyboard if wanted */
293 thread_bind(current_thread(), PROCESSOR_NULL
);
296 * Become the pageout daemon.
306 processor_t myprocessor
= current_processor();
309 myprocessor
->cpu_data
= get_cpu_data();
310 thread
= myprocessor
->next_thread
;
311 myprocessor
->next_thread
= THREAD_NULL
;
312 if (thread
== THREAD_NULL
) {
313 thread
= machine_wake_thread
;
314 machine_wake_thread
= THREAD_NULL
;
316 thread_machine_set_current(thread
);
317 if (thread
== machine_wake_thread
)
318 thread_bind(thread
, myprocessor
);
320 cpu_launch_first_thread(thread
);
326 * Now running in a thread context
329 start_cpu_thread(void)
331 processor_t processor
;
333 processor
= cpu_to_processor(cpu_number());
335 slave_machine_init();
337 if (processor
->processor_self
== IP_NULL
) {
338 ipc_processor_init(processor
);
339 ipc_processor_enable(processor
);
342 (void) thread_terminate(current_act());
346 * Start up the first thread on a CPU.
349 cpu_launch_first_thread(
352 register int mycpu
= cpu_number();
353 processor_t processor
= cpu_to_processor(mycpu
);
355 processor
->cpu_data
->preemption_level
= 0;
358 start_timer(&kernel_timer
[mycpu
]);
359 clock_get_uptime(&processor
->last_dispatch
);
361 if (thread
== THREAD_NULL
|| thread
== processor
->idle_thread
)
362 panic("cpu_launch_first_thread");
364 rtclock_reset(); /* start realtime clock ticking */
365 PMAP_ACTIVATE_KERNEL(mycpu
);
367 thread_machine_set_current(thread
);
369 thread
->state
&= ~TH_UNINT
;
370 thread
->last_processor
= processor
;
371 processor
->current_pri
= thread
->sched_pri
;
372 _mk_sp_thread_begin(thread
, processor
);
373 thread_unlock(thread
);
374 timer_switch(&thread
->system_timer
);
376 PMAP_ACTIVATE_USER(thread
->top_act
, mycpu
);
378 /* preemption enabled by load_context */
379 load_context(thread
);