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