]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
43866e37 A |
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 | |
13 | * file. | |
14 | * | |
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 | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
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. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | * @OSF_COPYRIGHT@ | |
27 | */ | |
28 | /* | |
29 | * Mach Operating System | |
30 | * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University | |
31 | * All Rights Reserved. | |
32 | * | |
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. | |
38 | * | |
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. | |
42 | * | |
43 | * Carnegie Mellon requests users of this software to return to | |
44 | * | |
45 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
46 | * School of Computer Science | |
47 | * Carnegie Mellon University | |
48 | * Pittsburgh PA 15213-3890 | |
49 | * | |
50 | * any improvements or extensions that they make and grant Carnegie Mellon | |
51 | * the rights to redistribute these changes. | |
52 | */ | |
53 | /* | |
54 | */ | |
55 | ||
56 | /* | |
57 | * Mach kernel startup. | |
58 | */ | |
59 | ||
60 | #include <debug.h> | |
61 | #include <xpr_debug.h> | |
62 | #include <mach_kdp.h> | |
63 | #include <cpus.h> | |
64 | #include <mach_host.h> | |
65 | #include <norma_vm.h> | |
66 | #include <etap.h> | |
67 | ||
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> | |
0b4e3aa0 | 81 | #include <kern/mk_sp.h> |
1c79356b A |
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> | |
87 | #include <kern/xpr.h> | |
88 | #include <kern/zalloc.h> | |
55e303ae | 89 | #include <vm/vm_shared_memory_server.h> |
1c79356b A |
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> | |
43866e37 | 97 | #include <machine/commpage.h> |
1c79356b A |
98 | #include <sys/version.h> |
99 | ||
100 | #ifdef __ppc__ | |
101 | #include <ppc/Firmware.h> | |
102 | #include <ppc/mappings.h> | |
103 | #endif | |
104 | ||
105 | /* Externs XXX */ | |
106 | extern void rtclock_reset(void); | |
107 | ||
108 | /* Forwards */ | |
109 | void cpu_launch_first_thread( | |
55e303ae | 110 | thread_t thread); |
1c79356b | 111 | void start_kernel_threads(void); |
1c79356b A |
112 | |
113 | /* | |
114 | * Running in virtual memory, on the interrupt stack. | |
115 | * Does not return. Dispatches initial thread. | |
116 | * | |
117 | * Assumes that master_cpu is set. | |
118 | */ | |
119 | void | |
120 | setup_main(void) | |
121 | { | |
122 | thread_t startup_thread; | |
123 | ||
124 | sched_init(); | |
125 | vm_mem_bootstrap(); | |
126 | ipc_bootstrap(); | |
127 | vm_mem_init(); | |
128 | ipc_init(); | |
1c79356b A |
129 | |
130 | /* | |
131 | * As soon as the virtual memory system is up, we record | |
132 | * that this CPU is using the kernel pmap. | |
133 | */ | |
134 | PMAP_ACTIVATE_KERNEL(master_cpu); | |
135 | ||
136 | #ifdef __ppc__ | |
137 | mapping_free_prime(); /* Load up with temporary mapping blocks */ | |
138 | #endif | |
139 | ||
140 | machine_init(); | |
141 | kmod_init(); | |
142 | clock_init(); | |
143 | ||
144 | init_timers(); | |
145 | timer_call_initialize(); | |
146 | ||
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; | |
152 | ||
153 | /* | |
154 | * Initialize the IPC, task, and thread subsystems. | |
155 | */ | |
156 | ledger_init(); | |
1c79356b | 157 | task_init(); |
1c79356b | 158 | thread_init(); |
1c79356b A |
159 | |
160 | /* | |
161 | * Initialize the Event Trace Analysis Package. | |
162 | * Dynamic Phase: 2 of 2 | |
163 | */ | |
164 | etap_init_phase2(); | |
165 | ||
166 | /* | |
167 | * Create a kernel thread to start the other kernel | |
9bccf70c | 168 | * threads. |
1c79356b | 169 | */ |
55e303ae | 170 | startup_thread = kernel_thread_create(start_kernel_threads, MAXPRI_KERNEL); |
9bccf70c | 171 | |
1c79356b A |
172 | /* |
173 | * Start the thread. | |
174 | */ | |
55e303ae A |
175 | startup_thread->state = TH_RUN; |
176 | pset_run_incr(startup_thread->processor_set); | |
177 | ||
1c79356b A |
178 | cpu_launch_first_thread(startup_thread); |
179 | /*NOTREACHED*/ | |
180 | panic("cpu_launch_first_thread returns!"); | |
181 | } | |
182 | ||
183 | /* | |
184 | * Now running in a thread. Create the rest of the kernel threads | |
185 | * and the bootstrap task. | |
186 | */ | |
187 | void | |
188 | start_kernel_threads(void) | |
189 | { | |
190 | register int i; | |
191 | ||
192 | thread_bind(current_thread(), cpu_to_processor(cpu_number())); | |
193 | ||
194 | /* | |
195 | * Create the idle threads and the other | |
196 | * service threads. | |
197 | */ | |
198 | for (i = 0; i < NCPUS; i++) { | |
0b4e3aa0 A |
199 | processor_t processor = cpu_to_processor(i); |
200 | thread_t thread; | |
201 | spl_t s; | |
202 | ||
55e303ae A |
203 | thread = kernel_thread_create(idle_thread, MAXPRI_KERNEL); |
204 | ||
0b4e3aa0 A |
205 | s = splsched(); |
206 | thread_lock(thread); | |
55e303ae | 207 | thread->bound_processor = processor; |
0b4e3aa0 A |
208 | processor->idle_thread = thread; |
209 | thread->ref_count++; | |
55e303ae A |
210 | thread->sched_pri = thread->priority = IDLEPRI; |
211 | thread->state = (TH_RUN | TH_IDLE); | |
0b4e3aa0 A |
212 | thread_unlock(thread); |
213 | splx(s); | |
1c79356b A |
214 | } |
215 | ||
9bccf70c A |
216 | /* |
217 | * Initialize the thread reaper mechanism. | |
218 | */ | |
219 | thread_reaper_init(); | |
220 | ||
0b4e3aa0 A |
221 | /* |
222 | * Initialize the stack swapin mechanism. | |
223 | */ | |
224 | swapin_init(); | |
225 | ||
226 | /* | |
227 | * Initialize the periodic scheduler mechanism. | |
228 | */ | |
229 | sched_tick_init(); | |
230 | ||
1c79356b A |
231 | /* |
232 | * Initialize the thread callout mechanism. | |
233 | */ | |
234 | thread_call_initialize(); | |
235 | ||
236 | /* | |
237 | * Invoke some black magic. | |
238 | */ | |
239 | #if __ppc__ | |
240 | mapping_adjust(); | |
241 | #endif | |
242 | ||
1c79356b A |
243 | /* |
244 | * Create the clock service. | |
245 | */ | |
246 | clock_service_create(); | |
247 | ||
248 | /* | |
249 | * Create the device service. | |
250 | */ | |
251 | device_service_create(); | |
252 | ||
55e303ae | 253 | shared_file_boot_time_init(ENV_DEFAULT_ROOT, machine_slot[cpu_number()].cpu_type); |
1c79356b A |
254 | |
255 | #ifdef IOKIT | |
256 | { | |
257 | PE_init_iokit(); | |
258 | } | |
259 | #endif | |
43866e37 A |
260 | |
261 | (void) spllo(); /* Allow interruptions */ | |
262 | ||
263 | /* | |
264 | * Fill in the comm area (mapped into every task address space.) | |
265 | */ | |
266 | commpage_populate(); | |
1c79356b A |
267 | |
268 | /* | |
269 | * Start the user bootstrap. | |
270 | */ | |
271 | ||
1c79356b A |
272 | #ifdef MACH_BSD |
273 | { | |
274 | extern void bsd_init(void); | |
275 | bsd_init(); | |
276 | } | |
277 | #endif | |
278 | ||
55e303ae A |
279 | #if __ppc__ |
280 | serial_keyboard_init(); /* Start serial keyboard if wanted */ | |
281 | #endif | |
282 | ||
1c79356b A |
283 | thread_bind(current_thread(), PROCESSOR_NULL); |
284 | ||
285 | /* | |
286 | * Become the pageout daemon. | |
287 | */ | |
288 | ||
289 | vm_pageout(); | |
290 | /*NOTREACHED*/ | |
291 | } | |
292 | ||
293 | void | |
294 | slave_main(void) | |
295 | { | |
296 | processor_t myprocessor = current_processor(); | |
297 | thread_t thread; | |
298 | ||
299 | thread = myprocessor->next_thread; | |
300 | myprocessor->next_thread = THREAD_NULL; | |
301 | if (thread == THREAD_NULL) { | |
302 | thread = machine_wake_thread; | |
303 | machine_wake_thread = THREAD_NULL; | |
304 | } | |
9bccf70c | 305 | |
1c79356b A |
306 | cpu_launch_first_thread(thread); |
307 | /*NOTREACHED*/ | |
308 | panic("slave_main"); | |
309 | } | |
310 | ||
311 | /* | |
312 | * Now running in a thread context | |
313 | */ | |
314 | void | |
315 | start_cpu_thread(void) | |
316 | { | |
1c79356b A |
317 | slave_machine_init(); |
318 | ||
1c79356b A |
319 | (void) thread_terminate(current_act()); |
320 | } | |
321 | ||
322 | /* | |
323 | * Start up the first thread on a CPU. | |
324 | */ | |
325 | void | |
326 | cpu_launch_first_thread( | |
327 | thread_t thread) | |
328 | { | |
329 | register int mycpu = cpu_number(); | |
9bccf70c | 330 | processor_t processor = cpu_to_processor(mycpu); |
1c79356b | 331 | |
9bccf70c | 332 | clock_get_uptime(&processor->last_dispatch); |
55e303ae A |
333 | start_timer(&kernel_timer[mycpu]); |
334 | machine_thread_set_current(thread); | |
335 | cpu_up(mycpu); | |
1c79356b A |
336 | |
337 | rtclock_reset(); /* start realtime clock ticking */ | |
338 | PMAP_ACTIVATE_KERNEL(mycpu); | |
339 | ||
1c79356b A |
340 | thread_lock(thread); |
341 | thread->state &= ~TH_UNINT; | |
9bccf70c | 342 | thread->last_processor = processor; |
55e303ae | 343 | processor->active_thread = thread; |
9bccf70c A |
344 | processor->current_pri = thread->sched_pri; |
345 | _mk_sp_thread_begin(thread, processor); | |
1c79356b A |
346 | thread_unlock(thread); |
347 | timer_switch(&thread->system_timer); | |
348 | ||
349 | PMAP_ACTIVATE_USER(thread->top_act, mycpu); | |
350 | ||
351 | /* preemption enabled by load_context */ | |
55e303ae | 352 | machine_load_context(thread); |
1c79356b A |
353 | /*NOTREACHED*/ |
354 | } |