]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
11 | * | |
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 | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993 | |
24 | * The Regents of the University of California. All rights reserved. | |
25 | * (c) UNIX System Laboratories, Inc. | |
26 | * All or some portions of this file are derived from material licensed | |
27 | * to the University of California by American Telephone and Telegraph | |
28 | * Co. or Unix System Laboratories, Inc. and are reproduced herein with | |
29 | * the permission of UNIX System Laboratories, Inc. | |
30 | * | |
31 | * Redistribution and use in source and binary forms, with or without | |
32 | * modification, are permitted provided that the following conditions | |
33 | * are met: | |
34 | * 1. Redistributions of source code must retain the above copyright | |
35 | * notice, this list of conditions and the following disclaimer. | |
36 | * 2. Redistributions in binary form must reproduce the above copyright | |
37 | * notice, this list of conditions and the following disclaimer in the | |
38 | * documentation and/or other materials provided with the distribution. | |
39 | * 3. All advertising materials mentioning features or use of this software | |
40 | * must display the following acknowledgement: | |
41 | * This product includes software developed by the University of | |
42 | * California, Berkeley and its contributors. | |
43 | * 4. Neither the name of the University nor the names of its contributors | |
44 | * may be used to endorse or promote products derived from this software | |
45 | * without specific prior written permission. | |
46 | * | |
47 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
48 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
50 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
53 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
54 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
55 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
56 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
57 | * SUCH DAMAGE. | |
58 | * | |
59 | * @(#)init_main.c 8.16 (Berkeley) 5/14/95 | |
60 | */ | |
61 | ||
62 | /* | |
63 | * | |
64 | * Mach Operating System | |
65 | * Copyright (c) 1987 Carnegie-Mellon University | |
66 | * All rights reserved. The CMU software License Agreement specifies | |
67 | * the terms and conditions for use and redistribution. | |
68 | */ | |
69 | /* | |
70 | * HISTORY | |
71 | * 16-Apr-98 A. Ramesh at Apple | |
72 | * Created for Apple Core from DR2 init_main.c. | |
73 | */ | |
74 | ||
75 | #include <quota.h> | |
76 | ||
77 | #include <sys/param.h> | |
78 | #include <sys/filedesc.h> | |
79 | #include <sys/kernel.h> | |
80 | #include <sys/mount.h> | |
81 | #include <sys/proc.h> | |
82 | #include <sys/systm.h> | |
83 | #include <sys/vnode.h> | |
84 | #include <sys/conf.h> | |
85 | #include <sys/buf.h> | |
86 | #include <sys/clist.h> | |
87 | #include <sys/user.h> | |
88 | #include <ufs/ufs/quota.h> | |
89 | ||
90 | #include <sys/malloc.h> | |
91 | #include <sys/dkstat.h> | |
92 | ||
93 | #include <machine/spl.h> | |
94 | #include <kern/thread.h> | |
95 | #include <kern/task.h> | |
96 | #include <kern/ast.h> | |
97 | ||
98 | #include <mach/vm_param.h> | |
99 | ||
100 | #include <vm/vm_map.h> | |
101 | #include <vm/vm_kern.h> | |
102 | ||
103 | #include <sys/ux_exception.h> | |
104 | ||
105 | #include <sys/reboot.h> | |
106 | #include <mach/exception_types.h> | |
107 | #include <dev/busvar.h> | |
108 | #include <sys/kdebug.h> | |
109 | ||
110 | extern shared_region_mapping_t system_shared_region; | |
111 | ||
112 | char copyright[] = | |
113 | "Copyright (c) 1982, 1986, 1989, 1991, 1993\n\tThe Regents of the University of California. All rights reserved.\n\n"; | |
114 | ||
115 | extern void ux_handler(); | |
116 | ||
117 | /* Components of the first process -- never freed. */ | |
118 | struct proc proc0; | |
119 | struct session session0; | |
120 | struct pgrp pgrp0; | |
121 | struct pcred cred0; | |
122 | struct filedesc filedesc0; | |
123 | struct plimit limit0; | |
124 | struct pstats pstats0; | |
125 | struct sigacts sigacts0; | |
126 | struct proc *kernproc, *initproc; | |
127 | ||
128 | ||
129 | long cp_time[CPUSTATES]; | |
130 | long dk_seek[DK_NDRIVE]; | |
131 | long dk_time[DK_NDRIVE]; | |
132 | long dk_wds[DK_NDRIVE]; | |
133 | long dk_wpms[DK_NDRIVE]; | |
134 | long dk_xfer[DK_NDRIVE]; | |
135 | long dk_bps[DK_NDRIVE]; | |
136 | ||
137 | int dk_busy; | |
138 | int dk_ndrive; | |
139 | ||
140 | long tk_cancc; | |
141 | long tk_nin; | |
142 | long tk_nout; | |
143 | long tk_rawcc; | |
144 | ||
145 | /* Global variables to make pstat happy. We do swapping differently */ | |
146 | int nswdev, nswap; | |
147 | int nswapmap; | |
148 | void *swapmap; | |
149 | struct swdevt swdevt[1]; | |
150 | ||
151 | dev_t rootdev; /* device of the root */ | |
152 | dev_t dumpdev; /* device to take dumps on */ | |
153 | long dumplo; /* offset into dumpdev */ | |
154 | long hostid; | |
155 | char hostname[MAXHOSTNAMELEN]; | |
156 | int hostnamelen; | |
157 | char domainname[MAXDOMNAMELEN]; | |
158 | int domainnamelen; | |
159 | ||
160 | char rootdevice[16]; /* hfs device names have at least 9 chars */ | |
161 | struct timeval boottime; /* GRODY! This has to go... */ | |
162 | #if FIXME /* [ */ | |
163 | struct timeval time; | |
164 | #endif /* FIXME ] */ | |
165 | ||
166 | #ifdef KMEMSTATS | |
167 | struct kmemstats kmemstats[M_LAST]; | |
168 | #endif | |
169 | ||
170 | int lbolt; /* awoken once a second */ | |
171 | struct vnode *rootvp; | |
172 | int boothowto = RB_DEBUG; | |
173 | ||
174 | vm_map_t bsd_pageable_map; | |
175 | vm_map_t mb_map; | |
176 | ||
177 | int cmask = CMASK; | |
178 | ||
179 | int parse_bsd_args(void); | |
180 | extern int bsd_hardclockinit; | |
181 | extern vm_address_t bsd_init_task; | |
182 | extern char init_task_failure_data[]; | |
183 | ||
184 | funnel_t * kernel_flock; | |
185 | funnel_t * network_flock; | |
186 | int disable_funnel = 0; /* disables split funnel */ | |
187 | int enable_funnel = 0; /* disables split funnel */ | |
188 | ||
189 | /* | |
190 | * Initialization code. | |
191 | * Called from cold start routine as | |
192 | * soon as a stack and segmentation | |
193 | * have been established. | |
194 | * Functions: | |
195 | * clear and free user core | |
196 | * turn on clock | |
197 | * hand craft 0th process | |
198 | * call all initialization routines | |
199 | * fork - process 0 to schedule | |
200 | * - process 1 execute bootstrap | |
201 | * - process 2 to page out | |
202 | */ | |
203 | ||
204 | /* | |
205 | * Sets the name for the given task. | |
206 | */ | |
207 | void proc_name(s, p) | |
208 | char *s; | |
209 | struct proc *p; | |
210 | { | |
211 | int length = strlen(s); | |
212 | ||
213 | bcopy(s, p->p_comm, | |
214 | length >= sizeof(p->p_comm) ? sizeof(p->p_comm) : | |
215 | length + 1); | |
216 | } | |
217 | ||
218 | ||
219 | /* To allow these values to be patched, they're globals here */ | |
220 | #include <machine/vmparam.h> | |
221 | struct rlimit vm_initial_limit_stack = { DFLSSIZ, MAXSSIZ }; | |
222 | struct rlimit vm_initial_limit_data = { DFLDSIZ, MAXDSIZ }; | |
223 | struct rlimit vm_initial_limit_core = { DFLCSIZ, MAXCSIZ }; | |
224 | ||
225 | extern thread_t first_thread; | |
226 | ||
227 | #define SPL_DEBUG 0 | |
228 | #if SPL_DEBUG | |
229 | #define dprintf(x) printf x | |
230 | #else SPL_DEBUG | |
231 | #define dprintf(x) | |
232 | #endif /* SPL_DEBUG */ | |
233 | ||
234 | extern thread_t cloneproc(struct proc *, int); | |
235 | ||
236 | void | |
237 | bsd_init() | |
238 | { | |
239 | register struct proc *p; | |
240 | extern struct ucred *rootcred; | |
241 | register int i; | |
242 | int s; | |
243 | thread_t th; | |
244 | extern void bsdinit_task(); | |
245 | void lightning_bolt(void ); | |
246 | kern_return_t ret; | |
247 | boolean_t funnel_state; | |
248 | extern void uthread_zone_init(); | |
249 | ||
250 | extern int (*mountroot) __P((void)); | |
251 | ||
252 | ||
253 | #if 1 | |
254 | /* split funnel is enabled by default */ | |
255 | PE_parse_boot_arg("dfnl", &disable_funnel); | |
256 | #else | |
257 | /* split funnel is disabled befault */ | |
258 | disable_funnel = 1; | |
259 | PE_parse_boot_arg("efnl", &enable_funnel); | |
260 | if (enable_funnel) { | |
261 | /* enable only if efnl is set in bootarg */ | |
262 | disable_funnel = 0; | |
263 | } | |
264 | #endif | |
265 | ||
266 | kernel_flock = funnel_alloc(KERNEL_FUNNEL); | |
267 | if (kernel_flock == (funnel_t *)0 ) { | |
268 | panic("fail to allocate kernel mutex lock\n"); | |
269 | } | |
270 | ||
271 | ||
272 | funnel_state = thread_funnel_set(kernel_flock, TRUE); | |
273 | ||
274 | if (!disable_funnel) { | |
275 | network_flock = funnel_alloc(NETWORK_FUNNEL); | |
276 | if (network_flock == (funnel_t *)0 ) { | |
277 | panic("fail to allocate network mutex lock\n"); | |
278 | } | |
279 | } else { | |
280 | network_flock = kernel_flock; | |
281 | } | |
282 | ||
283 | ||
284 | printf(copyright); | |
285 | ||
286 | kmeminit(); | |
287 | ||
288 | parse_bsd_args(); | |
289 | ||
290 | bsd_bufferinit(); | |
291 | ||
292 | /* Initialize the uthread zone */ | |
293 | uthread_zone_init(); | |
294 | ||
295 | /* | |
296 | * Initialize process and pgrp structures. | |
297 | */ | |
298 | procinit(); | |
299 | ||
300 | kernproc = &proc0; | |
301 | ||
302 | p = kernproc; | |
303 | ||
304 | /* kernel_task->proc = kernproc; */ | |
305 | set_bsdtask_info(kernel_task,(void *)kernproc); | |
306 | p->p_pid = 0; | |
307 | ||
308 | /* give kernproc a name */ | |
309 | proc_name("kernel_task", p); | |
310 | ||
311 | if (current_task() != kernel_task) | |
312 | printf("We are in for problem, current task in not kernel task\n"); | |
313 | ||
314 | /* | |
315 | * Create process 0. | |
316 | */ | |
317 | LIST_INSERT_HEAD(&allproc, p, p_list); | |
318 | p->p_pgrp = &pgrp0; | |
319 | LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash); | |
320 | LIST_INIT(&pgrp0.pg_members); | |
321 | LIST_INSERT_HEAD(&pgrp0.pg_members, p, p_pglist); | |
322 | ||
323 | pgrp0.pg_session = &session0; | |
324 | session0.s_count = 1; | |
325 | session0.s_leader = p; | |
326 | ||
327 | p->task = kernel_task; | |
328 | ||
329 | p->p_stat = SRUN; | |
330 | p->p_flag = P_INMEM|P_SYSTEM; | |
331 | p->p_nice = NZERO; | |
332 | p->p_pptr = p; | |
333 | lockinit(&p->signal_lock, PVM, "signal", 0, 0); | |
334 | p->sigwait = FALSE; | |
335 | p->sigwait_thread = THREAD_NULL; | |
336 | p->exit_thread = THREAD_NULL; | |
337 | ||
338 | /* Create credentials. */ | |
339 | lockinit(&cred0.pc_lock, PLOCK, "proc0 cred", 0, 0); | |
340 | cred0.p_refcnt = 1; | |
341 | p->p_cred = &cred0; | |
342 | p->p_ucred = crget(); | |
343 | p->p_ucred->cr_ngroups = 1; /* group 0 */ | |
344 | ||
345 | /* Create the file descriptor table. */ | |
346 | filedesc0.fd_refcnt = 1+1; /* +1 so shutdown will not _FREE_ZONE */ | |
347 | p->p_fd = &filedesc0; | |
348 | filedesc0.fd_cmask = cmask; | |
349 | ||
350 | /* Create the limits structures. */ | |
351 | p->p_limit = &limit0; | |
352 | for (i = 0; i < sizeof(p->p_rlimit)/sizeof(p->p_rlimit[0]); i++) | |
353 | limit0.pl_rlimit[i].rlim_cur = | |
354 | limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY; | |
355 | limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur = NOFILE; | |
356 | limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur = MAXUPRC; | |
357 | limit0.pl_rlimit[RLIMIT_STACK] = vm_initial_limit_stack; | |
358 | limit0.pl_rlimit[RLIMIT_DATA] = vm_initial_limit_data; | |
359 | limit0.pl_rlimit[RLIMIT_CORE] = vm_initial_limit_core; | |
360 | limit0.p_refcnt = 1; | |
361 | ||
362 | p->p_stats = &pstats0; | |
363 | p->p_sigacts = &sigacts0; | |
364 | ||
365 | /* | |
366 | * Charge root for one process. | |
367 | */ | |
368 | (void)chgproccnt(0, 1); | |
369 | ||
370 | ||
371 | /* | |
372 | * Allocate a kernel submap for pageable memory | |
373 | * for temporary copying (table(), execve()). | |
374 | */ | |
375 | { | |
376 | vm_offset_t min; | |
377 | ||
378 | ret = kmem_suballoc(kernel_map, | |
379 | &min, | |
380 | (vm_size_t)512*1024, | |
381 | TRUE, | |
382 | TRUE, | |
383 | &bsd_pageable_map); | |
384 | if (ret != KERN_SUCCESS) | |
385 | panic("Failed to allocare bsd pageable map\n"); | |
386 | } | |
387 | ||
388 | /* | |
389 | * Initialize the calendar by | |
390 | * reading the BBC, if not already set. | |
391 | */ | |
392 | IOKitResetTime(); | |
393 | ||
394 | ubc_init(); | |
395 | ||
396 | /* Initialize the file systems. */ | |
397 | vfsinit(); | |
398 | ||
399 | /* Initialize mbuf's. */ | |
400 | mbinit(); | |
401 | ||
402 | /* Initialize syslog */ | |
403 | log_init(); | |
404 | ||
405 | /* Initialize SysV shm */ | |
406 | shminit(); | |
407 | ||
408 | /* POSIX Shm and Sem */ | |
409 | pshm_cache_init(); | |
410 | psem_cache_init(); | |
411 | ||
412 | /* | |
413 | * Initialize protocols. Block reception of incoming packets | |
414 | * until everything is ready. | |
415 | */ | |
416 | s = splimp(); | |
417 | sysctl_register_fixed(); | |
418 | dlil_init(); | |
419 | socketinit(); | |
420 | domaininit(); | |
421 | splx(s); | |
422 | ||
423 | /* | |
424 | * Create kernel idle cpu processes. This must be done | |
425 | * before a context switch can occur (and hence I/O can | |
426 | * happen in the binit() call). | |
427 | */ | |
428 | p->p_fd->fd_cdir = NULL; | |
429 | p->p_fd->fd_rdir = NULL; | |
430 | ||
431 | ||
432 | #ifdef GPROF | |
433 | /* Initialize kernel profiling. */ | |
434 | kmstartup(); | |
435 | #endif | |
436 | ||
437 | /* kick off timeout driven events by calling first time */ | |
438 | thread_wakeup(&lbolt); | |
439 | timeout(lightning_bolt,0,hz); | |
440 | ||
441 | bsd_autoconf(); | |
442 | ||
443 | /* | |
444 | * We attach the loopback interface *way* down here to ensure | |
445 | * it happens after autoconf(), otherwise it becomes the | |
446 | * "primary" interface. | |
447 | */ | |
448 | #include <loop.h> | |
449 | #if NLOOP > 0 | |
450 | loopattach(); /* XXX */ | |
451 | #endif | |
452 | ||
453 | vnode_pager_bootstrap(); | |
454 | ||
455 | /* Mount the root file system. */ | |
456 | while( TRUE) { | |
457 | int err; | |
458 | ||
459 | setconf(); | |
460 | /* | |
461 | * read the time after clock_initialize_calendar() | |
462 | * and before nfs mount | |
463 | */ | |
464 | microtime(&time); | |
465 | ||
466 | if (0 == (err = vfs_mountroot())) | |
467 | break; | |
468 | printf("cannot mount root, errno = %d\n", err); | |
469 | boothowto |= RB_ASKNAME; | |
470 | } | |
471 | ||
472 | mountlist.cqh_first->mnt_flag |= MNT_ROOTFS; | |
473 | ||
474 | /* Get the vnode for '/'. Set fdp->fd_fd.fd_cdir to reference it. */ | |
475 | if (VFS_ROOT(mountlist.cqh_first, &rootvnode)) | |
476 | panic("cannot find root vnode"); | |
477 | filedesc0.fd_cdir = rootvnode; | |
478 | VREF(rootvnode); | |
479 | VOP_UNLOCK(rootvnode, 0, p); | |
480 | ||
481 | ||
482 | /* | |
483 | * Now can look at time, having had a chance to verify the time | |
484 | * from the file system. Reset p->p_rtime as it may have been | |
485 | * munched in mi_switch() after the time got set. | |
486 | */ | |
487 | p->p_stats->p_start = boottime = time; | |
488 | p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0; | |
489 | ||
490 | #ifdef DEVFS | |
491 | { | |
492 | extern void devfs_kernel_mount(char * str); | |
493 | ||
494 | devfs_kernel_mount("/dev"); | |
495 | } | |
496 | #endif DEVFS | |
497 | ||
498 | /* Initialize signal state for process 0. */ | |
499 | siginit(p); | |
500 | ||
501 | /* printf("Launching user process\n"); */ | |
502 | ||
503 | bsd_utaskbootstrap(); | |
504 | ||
505 | (void) thread_funnel_set(kernel_flock, FALSE); | |
506 | } | |
507 | ||
508 | void | |
509 | bsdinit_task() | |
510 | { | |
511 | struct proc *p = current_proc(); | |
512 | struct uthread *ut; | |
513 | kern_return_t kr; | |
514 | thread_act_t th_act; | |
515 | boolean_t funnel_state; | |
516 | ||
517 | funnel_state = thread_funnel_set(kernel_flock, TRUE); | |
518 | ||
519 | #if FIXME /* [ */ | |
520 | ||
521 | ipc_port_t master_bootstrap_port; | |
522 | task_t bootstrap_task; | |
523 | thread_act_t bootstrap_thr_act; | |
524 | ipc_port_t root_device_port; | |
525 | ||
526 | master_bootstrap_port = ipc_port_alloc_kernel(); | |
527 | if (master_bootstrap_port == IP_NULL) | |
528 | panic("can't allocate master bootstrap port"); | |
529 | printf("setting bootstrap port \n"); | |
530 | task_set_special_port(bootstrap_task, | |
531 | TASK_BOOTSTRAP_PORT, | |
532 | ipc_port_make_send(master_bootstrap_port)); | |
533 | ||
534 | printf("Setting exception port for the init task\n"); | |
535 | (void) task_set_exception_ports(get_threadtask(th), | |
536 | EXC_MASK_ALL & | |
537 | ~(EXC_MASK_SYSCALL | | |
538 | EXC_MASK_MACH_SYSCALL | EXC_MASK_RPC_ALERT), | |
539 | ux_exception_port, | |
540 | EXCEPTION_DEFAULT, 0); | |
541 | ||
542 | #endif /* FIXME ] */ | |
543 | proc_name("init", p); | |
544 | ||
545 | ux_handler_init(); | |
546 | /* port_reference(ux_exception_port);*/ | |
547 | ||
548 | th_act = current_act(); | |
549 | (void) host_set_exception_ports(host_priv_self(), | |
550 | EXC_MASK_ALL & ~(EXC_MASK_SYSCALL | | |
551 | EXC_MASK_MACH_SYSCALL | | |
552 | EXC_MASK_RPC_ALERT), | |
553 | ux_exception_port, | |
554 | EXCEPTION_DEFAULT, 0); | |
555 | ||
556 | (void) task_set_exception_ports(get_threadtask(th_act), | |
557 | EXC_MASK_ALL & ~(EXC_MASK_SYSCALL | | |
558 | EXC_MASK_MACH_SYSCALL | | |
559 | EXC_MASK_RPC_ALERT), | |
560 | ux_exception_port, | |
561 | EXCEPTION_DEFAULT, 0); | |
562 | ||
563 | ||
564 | ||
565 | ||
566 | ut = (uthread_t)get_bsdthread_info(th_act); | |
567 | ut->uu_ar0 = (void *)get_user_regs(th_act); | |
568 | ||
569 | bsd_hardclockinit = 1; /* Start bsd hardclock */ | |
570 | bsd_init_task = get_threadtask(th_act); | |
571 | init_task_failure_data[0] = 0; | |
572 | vm_set_shared_region(get_threadtask(th_act), system_shared_region); | |
573 | load_init_program(p); | |
574 | ||
575 | (void) thread_funnel_set(kernel_flock, FALSE); | |
576 | ||
577 | } | |
578 | ||
579 | void | |
580 | lightning_bolt() | |
581 | { | |
582 | boolean_t funnel_state; | |
583 | extern void klogwakeup(void); | |
584 | ||
585 | funnel_state = thread_funnel_set(kernel_flock, TRUE); | |
586 | ||
587 | thread_wakeup(&lbolt); | |
588 | timeout(lightning_bolt,0,hz); | |
589 | klogwakeup(); | |
590 | ||
591 | (void) thread_funnel_set(kernel_flock, FALSE); | |
592 | } | |
593 | ||
594 | bsd_autoconf(){ | |
595 | extern kern_return_t IOKitBSDInit( void ); | |
596 | ||
597 | kminit(); | |
598 | ||
599 | /* | |
600 | * Early startup for bsd pseudodevices. | |
601 | */ | |
602 | { | |
603 | struct pseudo_init *pi; | |
604 | ||
605 | for (pi = pseudo_inits; pi->ps_func; pi++) | |
606 | (*pi->ps_func) (pi->ps_count); | |
607 | } | |
608 | ||
609 | return( IOKitBSDInit()); | |
610 | } | |
611 | ||
612 | ||
613 | #include <sys/disklabel.h> // for MAXPARTITIONS | |
614 | ||
615 | setconf() | |
616 | { | |
617 | extern kern_return_t IOFindBSDRoot( char * rootName, | |
618 | dev_t * root, u_int32_t * flags ); | |
619 | ||
620 | extern int (*mountroot) __P((void)); | |
621 | extern int nfs_mountroot(); /* nfs_vfsops.c */ | |
622 | ||
623 | u_int32_t flags; | |
624 | kern_return_t err; | |
625 | ||
626 | /* | |
627 | * calls into IOKit can generate networking registrations | |
628 | * which needs to be under network funnel. Right thing to do | |
629 | * here is to drop the funnel alltogether and regrab it afterwards | |
630 | */ | |
631 | thread_funnel_set(kernel_flock, FALSE); | |
632 | err = IOFindBSDRoot( rootdevice, &rootdev, &flags ); | |
633 | thread_funnel_set(kernel_flock, TRUE); | |
634 | if( err) { | |
635 | printf("setconf: IOFindBSDRoot returned an error (%d);" | |
636 | "setting rootdevice to 'sd0a'.\n", err); /* XXX DEBUG TEMP */ | |
637 | rootdev = makedev( 6, 0 ); | |
638 | strcpy( rootdevice, "sd0a" ); | |
639 | flags = 0; | |
640 | } | |
641 | ||
642 | /* if network device then force nfs root */ | |
643 | if( flags & 1 ) { | |
644 | printf("mounting nfs root\n"); | |
645 | mountroot = nfs_mountroot; | |
646 | } else { | |
647 | /* otherwise have vfs determine root filesystem */ | |
648 | mountroot = NULL; | |
649 | } | |
650 | ||
651 | } | |
652 | ||
653 | bsd_utaskbootstrap() | |
654 | { | |
655 | thread_act_t th_act; | |
656 | ||
657 | th_act = (thread_act_t)cloneproc(kernproc, 0); | |
658 | initproc = pfind(1); | |
659 | thread_hold(th_act); | |
660 | (void) thread_stop_wait(getshuttle_thread(th_act)); | |
661 | thread_ast_set(th_act,AST_BSD_INIT); | |
662 | thread_release(th_act); | |
663 | thread_unstop(getshuttle_thread(th_act)); | |
664 | (void) thread_resume(th_act); | |
665 | } | |
666 | ||
667 | parse_bsd_args() | |
668 | { | |
669 | extern char init_args[]; | |
670 | char namep[16]; | |
671 | extern int boothowto; | |
672 | extern int srv; | |
673 | extern int ncl; | |
674 | ||
675 | int len; | |
676 | ||
677 | if (PE_parse_boot_arg("-s", namep)) { | |
678 | boothowto |= RB_SINGLE; | |
679 | len = strlen(init_args); | |
680 | if(len != 0) | |
681 | strcat(init_args," -s"); | |
682 | else | |
683 | strcat(init_args,"-s"); | |
684 | } | |
685 | if (PE_parse_boot_arg("-b", namep)) { | |
686 | boothowto |= RB_NOBOOTRC; | |
687 | len = strlen(init_args); | |
688 | if(len != 0) | |
689 | strcat(init_args," -b"); | |
690 | else | |
691 | strcat(init_args,"-b"); | |
692 | } | |
693 | ||
694 | if (PE_parse_boot_arg("-F", namep)) { | |
695 | len = strlen(init_args); | |
696 | if(len != 0) | |
697 | strcat(init_args," -F"); | |
698 | else | |
699 | strcat(init_args,"-F"); | |
700 | } | |
701 | ||
702 | if (PE_parse_boot_arg("-v", namep)) { | |
703 | len = strlen(init_args); | |
704 | if(len != 0) | |
705 | strcat(init_args," -v"); | |
706 | else | |
707 | strcat(init_args,"-v"); | |
708 | } | |
709 | ||
710 | if (PE_parse_boot_arg("-x", namep)) { /* safe boot */ | |
711 | len = strlen(init_args); | |
712 | if(len != 0) | |
713 | strcat(init_args," -x"); | |
714 | else | |
715 | strcat(init_args,"-x"); | |
716 | } | |
717 | ||
718 | PE_parse_boot_arg("srv", &srv); | |
719 | PE_parse_boot_arg("ncl", &ncl); | |
720 | PE_parse_boot_arg("nbuf", &nbuf); | |
721 | ||
722 | return 0; | |
723 | } | |
724 | ||
725 | boolean_t | |
726 | thread_funnel_switch( | |
727 | int oldfnl, | |
728 | int newfnl) | |
729 | { | |
730 | thread_t cur_thread; | |
731 | boolean_t funnel_state_prev; | |
732 | int curfnl; | |
733 | funnel_t * curflock; | |
734 | funnel_t * oldflock; | |
735 | funnel_t * newflock; | |
736 | funnel_t * exist_funnel; | |
737 | extern int disable_funnel; | |
738 | ||
739 | ||
740 | if (disable_funnel) | |
741 | return(TRUE); | |
742 | ||
743 | if(oldfnl == newfnl) { | |
744 | panic("thread_funnel_switch: can't switch to same funnel"); | |
745 | } | |
746 | ||
747 | if ((oldfnl != NETWORK_FUNNEL) && (oldfnl != KERNEL_FUNNEL)) | |
748 | { | |
749 | panic("thread_funnel_switch: invalid oldfunnel"); | |
750 | } | |
751 | if ((newfnl != NETWORK_FUNNEL) && (newfnl != KERNEL_FUNNEL)) | |
752 | { | |
753 | panic("thread_funnel_switch: invalid oldfunnel"); | |
754 | } | |
755 | ||
756 | if((curflock = thread_funnel_get()) == THR_FUNNEL_NULL) { | |
757 | panic("thread_funnel_switch: no funnel held"); | |
758 | } | |
759 | ||
760 | cur_thread = current_thread(); | |
761 | ||
762 | if ((oldfnl == NETWORK_FUNNEL) && (curflock != network_flock)) | |
763 | panic("thread_funnel_switch: network funnel not held"); | |
764 | ||
765 | if ((oldfnl == KERNEL_FUNNEL) && (curflock != kernel_flock)) | |
766 | panic("thread_funnel_switch: network funnel not held"); | |
767 | ||
768 | if(oldfnl == NETWORK_FUNNEL) { | |
769 | oldflock = network_flock; | |
770 | newflock = kernel_flock; | |
771 | } else { | |
772 | oldflock = kernel_flock; | |
773 | newflock = network_flock; | |
774 | } | |
775 | KERNEL_DEBUG(0x603242c | DBG_FUNC_NONE, oldflock, 1, 0, 0, 0); | |
776 | thread_funnel_set(oldflock, FALSE); | |
777 | KERNEL_DEBUG(0x6032428 | DBG_FUNC_NONE, newflock, 1, 0, 0, 0); | |
778 | thread_funnel_set(newflock, TRUE); | |
779 | KERNEL_DEBUG(0x6032434 | DBG_FUNC_NONE, newflock, 1, 0, 0, 0); | |
780 | ||
781 | return(TRUE); | |
782 | } |