]>
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 * 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>
61 #include <mach_host.h>
65 #include <mach/boolean.h>
66 #include <mach/machine.h>
67 #include <mach/task_special_ports.h>
68 #include <mach/vm_param.h>
69 #include <ipc/ipc_init.h>
70 #include <kern/assert.h>
71 #include <kern/misc_protos.h>
72 #include <kern/clock.h>
73 #include <kern/cpu_number.h>
74 #include <kern/etap_macros.h>
75 #include <kern/machine.h>
76 #include <kern/processor.h>
77 #include <kern/sched_prim.h>
78 #include <kern/mk_sp.h>
79 #include <kern/startup.h>
80 #include <kern/task.h>
81 #include <kern/thread.h>
82 #include <kern/timer.h>
83 #include <kern/timer_call.h>
85 #include <kern/zalloc.h>
86 #include <vm/vm_shared_memory_server.h>
87 #include <vm/vm_kern.h>
88 #include <vm/vm_init.h>
89 #include <vm/vm_map.h>
90 #include <vm/vm_object.h>
91 #include <vm/vm_page.h>
92 #include <vm/vm_pageout.h>
93 #include <machine/pmap.h>
94 #include <machine/commpage.h>
95 #include <sys/version.h>
98 #include <ppc/Firmware.h>
99 #include <ppc/mappings.h>
103 extern void rtclock_reset(void);
106 void cpu_launch_first_thread(
108 void start_kernel_threads(void);
111 * Running in virtual memory, on the interrupt stack.
112 * Does not return. Dispatches initial thread.
114 * Assumes that master_cpu is set.
119 thread_t startup_thread
;
128 * As soon as the virtual memory system is up, we record
129 * that this CPU is using the kernel pmap.
131 PMAP_ACTIVATE_KERNEL(master_cpu
);
134 mapping_free_prime(); /* Load up with temporary mapping blocks */
142 timer_call_initialize();
144 machine_info
.max_cpus
= NCPUS
;
145 machine_info
.memory_size
= mem_size
;
146 machine_info
.avail_cpus
= 0;
147 machine_info
.major_version
= KERNEL_MAJOR_VERSION
;
148 machine_info
.minor_version
= KERNEL_MINOR_VERSION
;
151 * Initialize the IPC, task, and thread subsystems.
158 * Initialize the Event Trace Analysis Package.
159 * Dynamic Phase: 2 of 2
164 * Create a kernel thread to start the other kernel
167 startup_thread
= kernel_thread_create(start_kernel_threads
, MAXPRI_KERNEL
);
172 startup_thread
->state
= TH_RUN
;
173 pset_run_incr(startup_thread
->processor_set
);
175 cpu_launch_first_thread(startup_thread
);
177 panic("cpu_launch_first_thread returns!");
181 * Now running in a thread. Create the rest of the kernel threads
182 * and the bootstrap task.
185 start_kernel_threads(void)
189 thread_bind(current_thread(), cpu_to_processor(cpu_number()));
192 * Create the idle threads and the other
195 for (i
= 0; i
< NCPUS
; i
++) {
196 processor_t processor
= cpu_to_processor(i
);
200 thread
= kernel_thread_create(idle_thread
, MAXPRI_KERNEL
);
204 thread
->bound_processor
= processor
;
205 processor
->idle_thread
= thread
;
207 thread
->sched_pri
= thread
->priority
= IDLEPRI
;
208 thread
->state
= (TH_RUN
| TH_IDLE
);
209 thread_unlock(thread
);
214 * Initialize the thread reaper mechanism.
216 thread_reaper_init();
219 * Initialize the stack swapin mechanism.
224 * Initialize the periodic scheduler mechanism.
229 * Initialize the thread callout mechanism.
231 thread_call_initialize();
234 * Invoke some black magic.
241 * Create the clock service.
243 clock_service_create();
246 * Create the device service.
248 device_service_create();
250 shared_file_boot_time_init(ENV_DEFAULT_ROOT
, machine_slot
[cpu_number()].cpu_type
);
258 (void) spllo(); /* Allow interruptions */
261 * Fill in the comm area (mapped into every task address space.)
266 * Start the user bootstrap.
271 extern void bsd_init(void);
277 serial_keyboard_init(); /* Start serial keyboard if wanted */
280 thread_bind(current_thread(), PROCESSOR_NULL
);
283 * Become the pageout daemon.
293 processor_t myprocessor
= current_processor();
296 thread
= myprocessor
->next_thread
;
297 myprocessor
->next_thread
= THREAD_NULL
;
298 if (thread
== THREAD_NULL
) {
299 thread
= machine_wake_thread
;
300 machine_wake_thread
= THREAD_NULL
;
303 cpu_launch_first_thread(thread
);
309 * Now running in a thread context
312 start_cpu_thread(void)
314 slave_machine_init();
316 (void) thread_terminate(current_act());
320 * Start up the first thread on a CPU.
323 cpu_launch_first_thread(
326 register int mycpu
= cpu_number();
327 processor_t processor
= cpu_to_processor(mycpu
);
329 clock_get_uptime(&processor
->last_dispatch
);
330 start_timer(&kernel_timer
[mycpu
]);
331 machine_thread_set_current(thread
);
334 rtclock_reset(); /* start realtime clock ticking */
335 PMAP_ACTIVATE_KERNEL(mycpu
);
338 thread
->state
&= ~TH_UNINT
;
339 thread
->last_processor
= processor
;
340 processor
->active_thread
= thread
;
341 processor
->current_pri
= thread
->sched_pri
;
342 _mk_sp_thread_begin(thread
, processor
);
343 thread_unlock(thread
);
344 timer_switch(&thread
->system_timer
);
346 PMAP_ACTIVATE_USER(thread
->top_act
, mycpu
);
348 /* preemption enabled by load_context */
349 machine_load_context(thread
);