]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
c0fea474 | 2 | * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. |
1c79356b A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
37839358 A |
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. | |
1c79356b | 11 | * |
37839358 A |
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 | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
37839358 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * @OSF_COPYRIGHT@ | |
24 | */ | |
25 | /* | |
26 | * Mach Operating System | |
27 | * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University | |
28 | * All Rights Reserved. | |
29 | * | |
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. | |
35 | * | |
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. | |
39 | * | |
40 | * Carnegie Mellon requests users of this software to return to | |
41 | * | |
42 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
43 | * School of Computer Science | |
44 | * Carnegie Mellon University | |
45 | * Pittsburgh PA 15213-3890 | |
46 | * | |
47 | * any improvements or extensions that they make and grant Carnegie Mellon | |
48 | * the rights to redistribute these changes. | |
49 | */ | |
50 | /* | |
51 | */ | |
52 | ||
53 | /* | |
54 | * Mach kernel startup. | |
55 | */ | |
56 | ||
57 | #include <debug.h> | |
58 | #include <xpr_debug.h> | |
59 | #include <mach_kdp.h> | |
1c79356b A |
60 | #include <mach_host.h> |
61 | #include <norma_vm.h> | |
1c79356b A |
62 | |
63 | #include <mach/boolean.h> | |
64 | #include <mach/machine.h> | |
91447636 | 65 | #include <mach/thread_act.h> |
1c79356b A |
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> | |
91447636 | 73 | #include <kern/ledger.h> |
1c79356b A |
74 | #include <kern/machine.h> |
75 | #include <kern/processor.h> | |
76 | #include <kern/sched_prim.h> | |
1c79356b A |
77 | #include <kern/startup.h> |
78 | #include <kern/task.h> | |
79 | #include <kern/thread.h> | |
80 | #include <kern/timer.h> | |
1c79356b A |
81 | #include <kern/xpr.h> |
82 | #include <kern/zalloc.h> | |
91447636 | 83 | #include <kern/locks.h> |
c0fea474 | 84 | #include <console/serial_protos.h> |
55e303ae | 85 | #include <vm/vm_shared_memory_server.h> |
1c79356b A |
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> | |
43866e37 | 93 | #include <machine/commpage.h> |
91447636 | 94 | #include <libkern/version.h> |
1c79356b A |
95 | |
96 | #ifdef __ppc__ | |
97 | #include <ppc/Firmware.h> | |
98 | #include <ppc/mappings.h> | |
99 | #endif | |
100 | ||
91447636 | 101 | static void kernel_bootstrap_thread(void); |
1c79356b | 102 | |
91447636 A |
103 | static void load_context( |
104 | thread_t thread); | |
1c79356b | 105 | |
c0fea474 A |
106 | #ifdef i386 |
107 | extern void cpu_window_init(int); | |
108 | #endif | |
109 | ||
110 | ||
1c79356b A |
111 | /* |
112 | * Running in virtual memory, on the interrupt stack. | |
1c79356b | 113 | */ |
c0fea474 | 114 | |
1c79356b | 115 | void |
91447636 | 116 | kernel_bootstrap(void) |
1c79356b | 117 | { |
91447636 A |
118 | kern_return_t result; |
119 | thread_t thread; | |
1c79356b | 120 | |
91447636 | 121 | lck_mod_init(); |
1c79356b A |
122 | sched_init(); |
123 | vm_mem_bootstrap(); | |
124 | ipc_bootstrap(); | |
125 | vm_mem_init(); | |
126 | ipc_init(); | |
1c79356b A |
127 | |
128 | /* | |
129 | * As soon as the virtual memory system is up, we record | |
130 | * that this CPU is using the kernel pmap. | |
131 | */ | |
132 | PMAP_ACTIVATE_KERNEL(master_cpu); | |
133 | ||
1c79356b | 134 | mapping_free_prime(); /* Load up with temporary mapping blocks */ |
1c79356b A |
135 | |
136 | machine_init(); | |
137 | kmod_init(); | |
138 | clock_init(); | |
139 | ||
1c79356b | 140 | machine_info.memory_size = mem_size; |
91447636 A |
141 | machine_info.max_mem = max_mem; |
142 | machine_info.major_version = version_major; | |
143 | machine_info.minor_version = version_minor; | |
1c79356b A |
144 | |
145 | /* | |
146 | * Initialize the IPC, task, and thread subsystems. | |
147 | */ | |
148 | ledger_init(); | |
1c79356b | 149 | task_init(); |
1c79356b | 150 | thread_init(); |
1c79356b A |
151 | |
152 | /* | |
91447636 | 153 | * Create a kernel thread to execute the kernel bootstrap. |
1c79356b | 154 | */ |
91447636 | 155 | result = kernel_thread_create((thread_continue_t)kernel_bootstrap_thread, NULL, MAXPRI_KERNEL, &thread); |
c0fea474 A |
156 | |
157 | if (result != KERN_SUCCESS) panic("kernel_bootstrap: result = %08X\n", result); | |
9bccf70c | 158 | |
91447636 A |
159 | thread->state = TH_RUN; |
160 | thread_deallocate(thread); | |
55e303ae | 161 | |
91447636 | 162 | load_context(thread); |
1c79356b | 163 | /*NOTREACHED*/ |
1c79356b A |
164 | } |
165 | ||
166 | /* | |
91447636 A |
167 | * Now running in a thread. Kick off other services, |
168 | * invoke user bootstrap, enter pageout loop. | |
1c79356b | 169 | */ |
91447636 A |
170 | static void |
171 | kernel_bootstrap_thread(void) | |
1c79356b | 172 | { |
91447636 A |
173 | processor_t processor = current_processor(); |
174 | thread_t self = current_thread(); | |
1c79356b A |
175 | |
176 | /* | |
91447636 | 177 | * Create the idle processor thread. |
1c79356b | 178 | */ |
91447636 | 179 | idle_thread_create(processor); |
0b4e3aa0 A |
180 | |
181 | /* | |
91447636 A |
182 | * N.B. Do not stick anything else |
183 | * before this point. | |
184 | * | |
185 | * Start up the scheduler services. | |
0b4e3aa0 | 186 | */ |
91447636 | 187 | sched_startup(); |
0b4e3aa0 | 188 | |
1c79356b | 189 | /* |
91447636 A |
190 | * Remain on current processor as |
191 | * additional processors come online. | |
1c79356b | 192 | */ |
91447636 | 193 | thread_bind(self, processor); |
1c79356b A |
194 | |
195 | /* | |
91447636 | 196 | * Kick off memory mapping adjustments. |
1c79356b | 197 | */ |
1c79356b | 198 | mapping_adjust(); |
1c79356b | 199 | |
1c79356b A |
200 | /* |
201 | * Create the clock service. | |
202 | */ | |
203 | clock_service_create(); | |
204 | ||
205 | /* | |
206 | * Create the device service. | |
207 | */ | |
208 | device_service_create(); | |
209 | ||
91447636 | 210 | shared_file_boot_time_init(ENV_DEFAULT_ROOT, cpu_type()); |
1c79356b A |
211 | |
212 | #ifdef IOKIT | |
213 | { | |
214 | PE_init_iokit(); | |
215 | } | |
216 | #endif | |
43866e37 A |
217 | |
218 | (void) spllo(); /* Allow interruptions */ | |
219 | ||
c0fea474 A |
220 | /* |
221 | * Fill in the comm area (mapped into every task address space.) | |
222 | */ | |
223 | commpage_populate(); | |
224 | ||
225 | #ifdef i386 | |
226 | /* | |
227 | * create and initialize a copy window | |
228 | * for processor 0 | |
229 | */ | |
230 | cpu_window_init(0); | |
231 | #endif | |
1c79356b A |
232 | |
233 | /* | |
234 | * Start the user bootstrap. | |
235 | */ | |
1c79356b A |
236 | #ifdef MACH_BSD |
237 | { | |
1c79356b A |
238 | bsd_init(); |
239 | } | |
240 | #endif | |
241 | ||
55e303ae | 242 | serial_keyboard_init(); /* Start serial keyboard if wanted */ |
55e303ae | 243 | |
91447636 | 244 | thread_bind(self, PROCESSOR_NULL); |
1c79356b A |
245 | |
246 | /* | |
247 | * Become the pageout daemon. | |
248 | */ | |
1c79356b A |
249 | vm_pageout(); |
250 | /*NOTREACHED*/ | |
251 | } | |
252 | ||
91447636 A |
253 | /* |
254 | * slave_main: | |
255 | * | |
256 | * Load the first thread to start a processor. | |
257 | */ | |
1c79356b A |
258 | void |
259 | slave_main(void) | |
260 | { | |
91447636 | 261 | processor_t processor = current_processor(); |
1c79356b A |
262 | thread_t thread; |
263 | ||
91447636 A |
264 | /* |
265 | * Use the idle processor thread if there | |
266 | * is no dedicated start up thread. | |
267 | */ | |
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; | |
272 | } | |
273 | else { | |
274 | thread = processor->next_thread; | |
275 | processor->next_thread = THREAD_NULL; | |
1c79356b | 276 | } |
9bccf70c | 277 | |
91447636 | 278 | load_context(thread); |
1c79356b | 279 | /*NOTREACHED*/ |
1c79356b A |
280 | } |
281 | ||
282 | /* | |
91447636 A |
283 | * processor_start_thread: |
284 | * | |
285 | * First thread to execute on a started processor. | |
286 | * | |
287 | * Called at splsched. | |
1c79356b A |
288 | */ |
289 | void | |
91447636 | 290 | processor_start_thread(void) |
1c79356b | 291 | { |
91447636 A |
292 | processor_t processor = current_processor(); |
293 | thread_t self = current_thread(); | |
294 | ||
1c79356b A |
295 | slave_machine_init(); |
296 | ||
91447636 A |
297 | /* |
298 | * If running the idle processor thread, | |
299 | * reenter the idle loop, else terminate. | |
300 | */ | |
301 | if (self == processor->idle_thread) | |
302 | thread_block((thread_continue_t)idle_thread); | |
303 | ||
304 | thread_terminate(self); | |
305 | /*NOTREACHED*/ | |
1c79356b A |
306 | } |
307 | ||
308 | /* | |
91447636 A |
309 | * load_context: |
310 | * | |
311 | * Start the first thread on a processor. | |
1c79356b | 312 | */ |
91447636 A |
313 | static void |
314 | load_context( | |
1c79356b A |
315 | thread_t thread) |
316 | { | |
91447636 | 317 | processor_t processor = current_processor(); |
1c79356b | 318 | |
91447636 A |
319 | machine_set_current_thread(thread); |
320 | processor_up(processor); | |
1c79356b | 321 | |
91447636 A |
322 | PMAP_ACTIVATE_KERNEL(PROCESSOR_DATA(processor, slot_num)); |
323 | ||
324 | /* | |
325 | * Acquire a stack if none attached. The panic | |
326 | * should never occur since the thread is expected | |
327 | * to have reserved stack. | |
328 | */ | |
329 | if (!thread->kernel_stack) { | |
330 | if (!stack_alloc_try(thread)) | |
331 | panic("load_context"); | |
332 | } | |
333 | ||
334 | /* | |
335 | * The idle processor threads are not counted as | |
336 | * running for load calculations. | |
337 | */ | |
338 | if (!(thread->state & TH_IDLE)) | |
339 | pset_run_incr(thread->processor_set); | |
1c79356b | 340 | |
55e303ae | 341 | processor->active_thread = thread; |
9bccf70c | 342 | processor->current_pri = thread->sched_pri; |
91447636 A |
343 | processor->deadline = UINT64_MAX; |
344 | thread->last_processor = processor; | |
345 | ||
346 | processor->last_dispatch = mach_absolute_time(); | |
347 | timer_switch((uint32_t)processor->last_dispatch, | |
348 | &PROCESSOR_DATA(processor, offline_timer)); | |
1c79356b | 349 | |
91447636 | 350 | PMAP_ACTIVATE_USER(thread, PROCESSOR_DATA(processor, slot_num)); |
1c79356b | 351 | |
55e303ae | 352 | machine_load_context(thread); |
1c79356b A |
353 | /*NOTREACHED*/ |
354 | } |