]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
21362eb3 | 2 | * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
8f6c56a5 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
8f6c56a5 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
8ad349bb | 24 | * limitations under the License. |
8f6c56a5 A |
25 | * |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
32 | * Mach Operating System | |
33 | * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
35 | * | |
36 | * Permission to use, copy, modify and distribute this software and its | |
37 | * documentation is hereby granted, provided that both the copyright | |
38 | * notice and this permission notice appear in all copies of the | |
39 | * software, derivative works or modified versions, and any portions | |
40 | * thereof, and that both notices appear in supporting documentation. | |
41 | * | |
42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
45 | * | |
46 | * Carnegie Mellon requests users of this software to return to | |
47 | * | |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
52 | * | |
53 | * any improvements or extensions that they make and grant Carnegie Mellon | |
54 | * the rights to redistribute these changes. | |
55 | */ | |
56 | /* | |
57 | */ | |
58 | ||
59 | /* | |
60 | * Mach kernel startup. | |
61 | */ | |
62 | ||
63 | #include <debug.h> | |
64 | #include <xpr_debug.h> | |
65 | #include <mach_kdp.h> | |
1c79356b A |
66 | #include <mach_host.h> |
67 | #include <norma_vm.h> | |
1c79356b A |
68 | |
69 | #include <mach/boolean.h> | |
70 | #include <mach/machine.h> | |
91447636 | 71 | #include <mach/thread_act.h> |
1c79356b A |
72 | #include <mach/task_special_ports.h> |
73 | #include <mach/vm_param.h> | |
74 | #include <ipc/ipc_init.h> | |
75 | #include <kern/assert.h> | |
76 | #include <kern/misc_protos.h> | |
77 | #include <kern/clock.h> | |
78 | #include <kern/cpu_number.h> | |
91447636 | 79 | #include <kern/ledger.h> |
1c79356b A |
80 | #include <kern/machine.h> |
81 | #include <kern/processor.h> | |
82 | #include <kern/sched_prim.h> | |
1c79356b A |
83 | #include <kern/startup.h> |
84 | #include <kern/task.h> | |
85 | #include <kern/thread.h> | |
86 | #include <kern/timer.h> | |
1c79356b A |
87 | #include <kern/xpr.h> |
88 | #include <kern/zalloc.h> | |
91447636 | 89 | #include <kern/locks.h> |
55e303ae | 90 | #include <vm/vm_shared_memory_server.h> |
1c79356b A |
91 | #include <vm/vm_kern.h> |
92 | #include <vm/vm_init.h> | |
93 | #include <vm/vm_map.h> | |
94 | #include <vm/vm_object.h> | |
95 | #include <vm/vm_page.h> | |
96 | #include <vm/vm_pageout.h> | |
97 | #include <machine/pmap.h> | |
43866e37 | 98 | #include <machine/commpage.h> |
91447636 | 99 | #include <libkern/version.h> |
1c79356b A |
100 | |
101 | #ifdef __ppc__ | |
102 | #include <ppc/Firmware.h> | |
103 | #include <ppc/mappings.h> | |
21362eb3 | 104 | #include <ppc/serial_io.h> |
1c79356b A |
105 | #endif |
106 | ||
91447636 | 107 | static void kernel_bootstrap_thread(void); |
1c79356b | 108 | |
91447636 A |
109 | static void load_context( |
110 | thread_t thread); | |
1c79356b A |
111 | |
112 | /* | |
113 | * Running in virtual memory, on the interrupt stack. | |
1c79356b A |
114 | */ |
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); |
21362eb3 A |
156 | if (result != KERN_SUCCESS) |
157 | panic("kernel_bootstrap"); | |
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 | ||
21362eb3 A |
220 | /* |
221 | * Fill in the comm area (mapped into every task address space.) | |
222 | */ | |
223 | commpage_populate(); | |
1c79356b A |
224 | |
225 | /* | |
226 | * Start the user bootstrap. | |
227 | */ | |
1c79356b A |
228 | #ifdef MACH_BSD |
229 | { | |
1c79356b A |
230 | bsd_init(); |
231 | } | |
232 | #endif | |
233 | ||
21362eb3 | 234 | #if __ppc__ |
55e303ae | 235 | serial_keyboard_init(); /* Start serial keyboard if wanted */ |
21362eb3 | 236 | #endif |
55e303ae | 237 | |
91447636 | 238 | thread_bind(self, PROCESSOR_NULL); |
1c79356b A |
239 | |
240 | /* | |
241 | * Become the pageout daemon. | |
242 | */ | |
1c79356b A |
243 | vm_pageout(); |
244 | /*NOTREACHED*/ | |
245 | } | |
246 | ||
91447636 A |
247 | /* |
248 | * slave_main: | |
249 | * | |
250 | * Load the first thread to start a processor. | |
251 | */ | |
1c79356b A |
252 | void |
253 | slave_main(void) | |
254 | { | |
91447636 | 255 | processor_t processor = current_processor(); |
1c79356b A |
256 | thread_t thread; |
257 | ||
91447636 A |
258 | /* |
259 | * Use the idle processor thread if there | |
260 | * is no dedicated start up thread. | |
261 | */ | |
262 | if (processor->next_thread == THREAD_NULL) { | |
263 | thread = processor->idle_thread; | |
264 | thread->continuation = (thread_continue_t)processor_start_thread; | |
265 | thread->parameter = NULL; | |
266 | } | |
267 | else { | |
268 | thread = processor->next_thread; | |
269 | processor->next_thread = THREAD_NULL; | |
1c79356b | 270 | } |
9bccf70c | 271 | |
91447636 | 272 | load_context(thread); |
1c79356b | 273 | /*NOTREACHED*/ |
1c79356b A |
274 | } |
275 | ||
276 | /* | |
91447636 A |
277 | * processor_start_thread: |
278 | * | |
279 | * First thread to execute on a started processor. | |
280 | * | |
281 | * Called at splsched. | |
1c79356b A |
282 | */ |
283 | void | |
91447636 | 284 | processor_start_thread(void) |
1c79356b | 285 | { |
91447636 A |
286 | processor_t processor = current_processor(); |
287 | thread_t self = current_thread(); | |
288 | ||
1c79356b A |
289 | slave_machine_init(); |
290 | ||
91447636 A |
291 | /* |
292 | * If running the idle processor thread, | |
293 | * reenter the idle loop, else terminate. | |
294 | */ | |
295 | if (self == processor->idle_thread) | |
296 | thread_block((thread_continue_t)idle_thread); | |
297 | ||
298 | thread_terminate(self); | |
299 | /*NOTREACHED*/ | |
1c79356b A |
300 | } |
301 | ||
302 | /* | |
91447636 A |
303 | * load_context: |
304 | * | |
305 | * Start the first thread on a processor. | |
1c79356b | 306 | */ |
91447636 A |
307 | static void |
308 | load_context( | |
1c79356b A |
309 | thread_t thread) |
310 | { | |
91447636 | 311 | processor_t processor = current_processor(); |
1c79356b | 312 | |
91447636 A |
313 | machine_set_current_thread(thread); |
314 | processor_up(processor); | |
1c79356b | 315 | |
91447636 A |
316 | PMAP_ACTIVATE_KERNEL(PROCESSOR_DATA(processor, slot_num)); |
317 | ||
318 | /* | |
319 | * Acquire a stack if none attached. The panic | |
320 | * should never occur since the thread is expected | |
321 | * to have reserved stack. | |
322 | */ | |
323 | if (!thread->kernel_stack) { | |
324 | if (!stack_alloc_try(thread)) | |
325 | panic("load_context"); | |
326 | } | |
327 | ||
328 | /* | |
329 | * The idle processor threads are not counted as | |
330 | * running for load calculations. | |
331 | */ | |
332 | if (!(thread->state & TH_IDLE)) | |
333 | pset_run_incr(thread->processor_set); | |
1c79356b | 334 | |
55e303ae | 335 | processor->active_thread = thread; |
9bccf70c | 336 | processor->current_pri = thread->sched_pri; |
91447636 A |
337 | processor->deadline = UINT64_MAX; |
338 | thread->last_processor = processor; | |
339 | ||
340 | processor->last_dispatch = mach_absolute_time(); | |
341 | timer_switch((uint32_t)processor->last_dispatch, | |
342 | &PROCESSOR_DATA(processor, offline_timer)); | |
1c79356b | 343 | |
91447636 | 344 | PMAP_ACTIVATE_USER(thread, PROCESSOR_DATA(processor, slot_num)); |
1c79356b | 345 | |
55e303ae | 346 | machine_load_context(thread); |
1c79356b A |
347 | /*NOTREACHED*/ |
348 | } |