]> git.saurik.com Git - apple/xnu.git/blob - bsd/kern/bsd_init.c
xnu-792.25.20.tar.gz
[apple/xnu.git] / bsd / kern / bsd_init.c
1 /*
2 * Copyright (c) 2000-2004 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 #include <sys/param.h>
71 #include <sys/filedesc.h>
72 #include <sys/kernel.h>
73 #include <sys/mount_internal.h>
74 #include <sys/proc_internal.h>
75 #include <sys/kauth.h>
76 #include <sys/systm.h>
77 #include <sys/vnode_internal.h>
78 #include <sys/conf.h>
79 #include <sys/buf_internal.h>
80 #include <sys/clist.h>
81 #include <sys/user.h>
82 #include <sys/time.h>
83 #include <sys/systm.h>
84 #include <sys/mman.h>
85
86 #include <bsm/audit_kernel.h>
87
88 #include <sys/malloc.h>
89 #include <sys/dkstat.h>
90
91 #include <kern/startup.h>
92 #include <kern/thread.h>
93 #include <kern/task.h>
94 #include <kern/ast.h>
95
96 #include <mach/vm_param.h>
97
98 #include <vm/vm_map.h>
99 #include <vm/vm_kern.h>
100
101 #include <sys/ux_exception.h> /* for ux_exception_port */
102
103 #include <sys/reboot.h>
104 #include <mach/exception_types.h>
105 #include <dev/busvar.h> /* for pseudo_inits */
106 #include <sys/kdebug.h>
107
108 #include <mach/mach_types.h>
109 #include <mach/vm_prot.h>
110 #include <mach/semaphore.h>
111 #include <mach/sync_policy.h>
112 #include <kern/clock.h>
113 #include <mach/kern_return.h>
114
115 #include <mach/shared_memory_server.h>
116 #include <vm/vm_shared_memory_server.h>
117
118 #include <net/init.h>
119
120 #include <machine/exec.h>
121
122 extern int app_profile; /* on/off switch for pre-heat cache */
123
124 char copyright[] =
125 "Copyright (c) 1982, 1986, 1989, 1991, 1993\n\t"
126 "The Regents of the University of California. "
127 "All rights reserved.\n\n";
128
129 extern void ux_handler();
130
131 /* Components of the first process -- never freed. */
132 struct proc proc0;
133 struct session session0;
134 struct pgrp pgrp0;
135 struct filedesc filedesc0;
136 struct plimit limit0;
137 struct pstats pstats0;
138 struct sigacts sigacts0;
139 struct proc *kernproc, *initproc;
140
141 long tk_cancc;
142 long tk_nin;
143 long tk_nout;
144 long tk_rawcc;
145
146 int lock_trace = 0;
147 /* Global variables to make pstat happy. We do swapping differently */
148 int nswdev, nswap;
149 int nswapmap;
150 void *swapmap;
151 struct swdevt swdevt[1];
152
153 dev_t rootdev; /* device of the root */
154 dev_t dumpdev; /* device to take dumps on */
155 long dumplo; /* offset into dumpdev */
156 long hostid;
157 char hostname[MAXHOSTNAMELEN];
158 int hostnamelen;
159 char domainname[MAXDOMNAMELEN];
160 int domainnamelen;
161 #if __i386__
162 struct exec_archhandler exec_archhandler_ppc = {
163 .path = "/usr/libexec/oah/translate",
164 };
165 #else /* __i386__ */
166 struct exec_archhandler exec_archhandler_ppc;
167 #endif /* __i386__ */
168
169 char rootdevice[16]; /* hfs device names have at least 9 chars */
170
171 #ifdef KMEMSTATS
172 struct kmemstats kmemstats[M_LAST];
173 #endif
174
175 int lbolt; /* awoken once a second */
176 struct vnode *rootvp;
177 int boothowto = RB_DEBUG;
178
179 #define BSD_PAGABLE_MAP_SIZE (16 * 512 * 1024)
180 vm_map_t bsd_pageable_map;
181 vm_map_t mb_map;
182 semaphore_t execve_semaphore;
183
184 int cmask = CMASK;
185 extern int customnbuf;
186
187 int parse_bsd_args(void);
188 extern int bsd_hardclockinit;
189 extern task_t bsd_init_task;
190 extern char init_task_failure_data[];
191 extern void time_zone_slock_init(void);
192 static void process_name(char *, struct proc *);
193
194 static void setconf(void);
195
196 funnel_t *kernel_flock;
197
198 extern void sysv_shm_lock_init(void);
199 extern void sysv_sem_lock_init(void);
200 extern void sysv_msg_lock_init(void);
201 extern void pshm_lock_init();
202 extern void psem_lock_init();
203 extern int maxprocperuid;
204
205 /* kmem access not enabled by default; can be changed with boot-args */
206 int setup_kmem = 0;
207
208 extern void stackshot_lock_init();
209
210 /*
211 * Initialization code.
212 * Called from cold start routine as
213 * soon as a stack and segmentation
214 * have been established.
215 * Functions:
216 * turn on clock
217 * hand craft 0th process
218 * call all initialization routines
219 * hand craft 1st user process
220 */
221
222 /*
223 * Sets the name for the given task.
224 */
225 static void
226 process_name(s, p)
227 char *s;
228 struct proc *p;
229 {
230 int length = strlen(s);
231
232 bcopy(s, p->p_comm,
233 length >= sizeof(p->p_comm) ? sizeof(p->p_comm) :
234 length + 1);
235 }
236
237 /* To allow these values to be patched, they're globals here */
238 #include <machine/vmparam.h>
239 struct rlimit vm_initial_limit_stack = { DFLSSIZ, MAXSSIZ };
240 struct rlimit vm_initial_limit_data = { DFLDSIZ, MAXDSIZ };
241 struct rlimit vm_initial_limit_core = { DFLCSIZ, MAXCSIZ };
242
243 extern thread_t cloneproc(struct proc *, int);
244 extern int (*mountroot)(void);
245 extern int netboot_mountroot(); /* netboot.c */
246 extern int netboot_setup(struct proc * p);
247
248 lck_grp_t * proc_lck_grp;
249 lck_grp_attr_t * proc_lck_grp_attr;
250 lck_attr_t * proc_lck_attr;
251
252 /* hook called after root is mounted XXX temporary hack */
253 void (*mountroot_post_hook)(void);
254
255 /*
256 * This function is called very early on in the Mach startup, from the
257 * function start_kernel_threads() in osfmk/kern/startup.c. It's called
258 * in the context of the current (startup) task using a call to the
259 * function kernel_thread_create() to jump into start_kernel_threads().
260 * Internally, kernel_thread_create() calls thread_create_internal(),
261 * which calls uthread_alloc(). The function of uthread_alloc() is
262 * normally to allocate a uthread structure, and fill out the uu_sigmask,
263 * uu_act, and uu_ucred fields. It skips filling these out in the case
264 * of the "task" being "kernel_task", because the order of operation is
265 * inverted. To account for that, we need to manually fill in at least
266 * the uu_cred field so that the uthread structure can be used like any
267 * other.
268 */
269 void
270 bsd_init()
271 {
272 register struct proc *p;
273 struct uthread *ut;
274 extern kauth_cred_t rootcred;
275 register int i;
276 int s;
277 int error;
278 thread_t th;
279 struct vfs_context context;
280 void lightning_bolt(void );
281 kern_return_t ret;
282 boolean_t funnel_state;
283 struct ucred temp_cred;
284 extern void file_lock_init(void);
285
286 kernel_flock = funnel_alloc(KERNEL_FUNNEL);
287 if (kernel_flock == (funnel_t *)0 ) {
288 panic("bsd_init: Failed to allocate kernel funnel");
289 }
290
291 funnel_state = thread_funnel_set(kernel_flock, TRUE);
292
293 printf(copyright);
294
295 kmeminit();
296
297 parse_bsd_args();
298
299 /* Initialize the uthread zone */
300 //uthread_zone_init(); /* XXX redundant: previous uthread_alloc() */
301
302 /* Initialize kauth subsystem before instancing the first credential */
303 kauth_init();
304
305 /* Initialize process and pgrp structures. */
306 procinit();
307
308 kernproc = &proc0;
309
310 p = kernproc;
311
312 /* kernel_task->proc = kernproc; */
313 set_bsdtask_info(kernel_task,(void *)p);
314 p->p_pid = 0;
315
316 /* give kernproc a name */
317 process_name("kernel_task", p);
318
319 /* allocate proc lock group attribute and group */
320 proc_lck_grp_attr= lck_grp_attr_alloc_init();
321
322 proc_lck_grp = lck_grp_alloc_init("proc", proc_lck_grp_attr);
323
324 /* Allocate proc lock attribute */
325 proc_lck_attr = lck_attr_alloc_init();
326
327 lck_mtx_init(&p->p_mlock, proc_lck_grp, proc_lck_attr);
328 lck_mtx_init(&p->p_fdmlock, proc_lck_grp, proc_lck_attr);
329
330 if (current_task() != kernel_task)
331 printf("bsd_init: We have a problem, "
332 "current task is not kernel task\n");
333
334 ut = (uthread_t)get_bsdthread_info(current_thread());
335
336 /*
337 * Create process 0.
338 */
339 LIST_INSERT_HEAD(&allproc, p, p_list);
340 p->p_pgrp = &pgrp0;
341 LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
342 LIST_INIT(&pgrp0.pg_members);
343 LIST_INSERT_HEAD(&pgrp0.pg_members, p, p_pglist);
344
345 pgrp0.pg_session = &session0;
346 session0.s_count = 1;
347 session0.s_leader = p;
348
349 p->task = kernel_task;
350
351 p->p_stat = SRUN;
352 p->p_flag = P_SYSTEM;
353 p->p_nice = NZERO;
354 p->p_pptr = p;
355 lockinit(&p->signal_lock, PVM, "signal", 0, 0);
356 TAILQ_INIT(&p->p_uthlist);
357 p->sigwait = FALSE;
358 p->sigwait_thread = THREAD_NULL;
359 p->exit_thread = THREAD_NULL;
360
361 /*
362 * Create credential. This also Initializes the audit information.
363 * XXX It is not clear what the initial values should be for audit ID,
364 * XXX session ID, etc..
365 */
366 bzero(&temp_cred, sizeof(temp_cred));
367 temp_cred.cr_ngroups = 1;
368
369 p->p_ucred = kauth_cred_create(&temp_cred);
370
371 /* give the (already exisiting) initial thread a reference on it */
372 kauth_cred_ref(p->p_ucred);
373 ut->uu_ucred = p->p_ucred;
374
375 TAILQ_INIT(&p->aio_activeq);
376 TAILQ_INIT(&p->aio_doneq);
377 p->aio_active_count = 0;
378 p->aio_done_count = 0;
379
380 file_lock_init();
381
382 /* Create the file descriptor table. */
383 filedesc0.fd_refcnt = 1+1; /* +1 so shutdown will not _FREE_ZONE */
384 p->p_fd = &filedesc0;
385 filedesc0.fd_cmask = cmask;
386 filedesc0.fd_knlistsize = -1;
387 filedesc0.fd_knlist = NULL;
388 filedesc0.fd_knhash = NULL;
389 filedesc0.fd_knhashmask = 0;
390
391 /* Create the limits structures. */
392 p->p_limit = &limit0;
393 for (i = 0; i < sizeof(p->p_rlimit)/sizeof(p->p_rlimit[0]); i++)
394 limit0.pl_rlimit[i].rlim_cur =
395 limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
396 limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur = NOFILE;
397 limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur = maxprocperuid;
398 limit0.pl_rlimit[RLIMIT_NPROC].rlim_max = maxproc;
399 limit0.pl_rlimit[RLIMIT_STACK] = vm_initial_limit_stack;
400 limit0.pl_rlimit[RLIMIT_DATA] = vm_initial_limit_data;
401 limit0.pl_rlimit[RLIMIT_CORE] = vm_initial_limit_core;
402 limit0.p_refcnt = 1;
403
404 p->p_stats = &pstats0;
405 p->p_sigacts = &sigacts0;
406
407 /*
408 * Charge root for two processes: init and mach_init.
409 */
410 (void)chgproccnt(0, 1);
411
412 /*
413 * Allocate a kernel submap for pageable memory
414 * for temporary copying (execve()).
415 */
416 {
417 vm_offset_t min;
418
419 ret = kmem_suballoc(kernel_map,
420 &min,
421 (vm_size_t)BSD_PAGABLE_MAP_SIZE,
422 TRUE,
423 VM_FLAGS_ANYWHERE,
424 &bsd_pageable_map);
425 if (ret != KERN_SUCCESS)
426 panic("bsd_init: Failed to allocate bsd pageable map");
427 }
428
429 /*
430 * Initialize buffers and hash links for buffers
431 *
432 * SIDE EFFECT: Starts a thread for bcleanbuf_thread(), so must
433 * happen after a credential has been associated with
434 * the kernel task.
435 */
436 bsd_bufferinit();
437
438 /* Initialize the execve() semaphore */
439 ret = semaphore_create(kernel_task, &execve_semaphore,
440 SYNC_POLICY_FIFO, (BSD_PAGABLE_MAP_SIZE / NCARGS));
441 if (ret != KERN_SUCCESS)
442 panic("bsd_init: Failed to create execve semaphore");
443
444 /*
445 * Initialize the calendar.
446 */
447 IOKitResetTime();
448
449 ubc_init();
450
451 /* Initialize the file systems. */
452 vfsinit();
453
454 /* Initialize mbuf's. */
455 mbinit();
456
457 /*
458 * Initializes security event auditing.
459 * XXX: Should/could this occur later?
460 */
461 audit_init();
462
463 /* Initialize kqueues */
464 knote_init();
465
466 /* Initialize for async IO */
467 aio_init();
468
469 /* Initialize pipes */
470 pipeinit();
471
472 /* Initialize SysV shm subsystem locks; the subsystem proper is
473 * initialized through a sysctl.
474 */
475 sysv_shm_lock_init();
476 sysv_sem_lock_init();
477 sysv_msg_lock_init();
478 pshm_lock_init();
479 psem_lock_init();
480
481 /* POSIX Shm and Sem */
482 pshm_cache_init();
483 psem_cache_init();
484 time_zone_slock_init();
485
486 /* Stack snapshot facility lock */
487 stackshot_lock_init();
488 /*
489 * Initialize protocols. Block reception of incoming packets
490 * until everything is ready.
491 */
492 sysctl_register_fixed();
493 sysctl_mib_init();
494 dlil_init();
495 proto_kpi_init();
496 socketinit();
497 domaininit();
498
499 p->p_fd->fd_cdir = NULL;
500 p->p_fd->fd_rdir = NULL;
501
502 #ifdef GPROF
503 /* Initialize kernel profiling. */
504 kmstartup();
505 #endif
506
507 /* kick off timeout driven events by calling first time */
508 thread_wakeup(&lbolt);
509 timeout((void (*)(void *))lightning_bolt, 0, hz);
510
511 bsd_autoconf();
512
513 /*
514 * We attach the loopback interface *way* down here to ensure
515 * it happens after autoconf(), otherwise it becomes the
516 * "primary" interface.
517 */
518 #include <loop.h>
519 #if NLOOP > 0
520 loopattach(); /* XXX */
521 #endif
522
523 /* Register the built-in dlil ethernet interface family */
524 ether_family_init();
525
526 /* Call any kext code that wants to run just after network init */
527 net_init_run();
528
529 vnode_pager_bootstrap();
530 #if 0
531 /* XXX Hack for early debug stop */
532 printf("\nabout to sleep for 10 seconds\n");
533 IOSleep( 10 * 1000 );
534 /* Debugger("hello"); */
535 #endif
536
537 inittodr(0);
538
539 /* Mount the root file system. */
540 while( TRUE) {
541 int err;
542
543 setconf();
544 bsd_hardclockinit = -1; /* start ticking */
545
546 if (0 == (err = vfs_mountroot()))
547 break;
548 #if NFSCLIENT
549 if (mountroot == netboot_mountroot) {
550 printf("cannot mount network root, errno = %d\n", err);
551 mountroot = NULL;
552 if (0 == (err = vfs_mountroot()))
553 break;
554 }
555 #endif
556 printf("cannot mount root, errno = %d\n", err);
557 boothowto |= RB_ASKNAME;
558 }
559
560 context.vc_proc = p;
561 context.vc_ucred = p->p_ucred;
562 mountlist.tqh_first->mnt_flag |= MNT_ROOTFS;
563
564 /* Get the vnode for '/'. Set fdp->fd_fd.fd_cdir to reference it. */
565 if (VFS_ROOT(mountlist.tqh_first, &rootvnode, &context))
566 panic("bsd_init: cannot find root vnode");
567 rootvnode->v_flag |= VROOT;
568 (void)vnode_ref(rootvnode);
569 (void)vnode_put(rootvnode);
570 filedesc0.fd_cdir = rootvnode;
571
572 #if NFSCLIENT
573 if (mountroot == netboot_mountroot) {
574 int err;
575 /* post mount setup */
576 if (err = netboot_setup(p)) {
577 panic("bsd_init: NetBoot could not find root, %d", err);
578 }
579 }
580 #endif
581
582
583 microtime(&p->p_stats->p_start);
584 p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
585
586 #if DEVFS
587 {
588 extern void devfs_kernel_mount(char * str);
589
590 devfs_kernel_mount("/dev");
591 }
592 #endif /* DEVFS */
593
594 /* Initialize signal state for process 0. */
595 siginit(p);
596
597 bsd_utaskbootstrap();
598
599 #if __i386__
600 // this should be done after the root filesystem is mounted
601 error = set_archhandler(p, CPU_TYPE_POWERPC);
602 if (error)
603 exec_archhandler_ppc.path[0] = 0;
604 #endif
605
606 /* invoke post-root-mount hook */
607 if (mountroot_post_hook != NULL)
608 mountroot_post_hook();
609
610 (void) thread_funnel_set(kernel_flock, funnel_state);
611 }
612
613 /* Called with kernel funnel held */
614 void
615 bsdinit_task(void)
616 {
617 struct proc *p = current_proc();
618 struct uthread *ut;
619 kern_return_t kr;
620 thread_t th_act;
621 shared_region_mapping_t system_region;
622
623 process_name("init", p);
624
625 ux_handler_init();
626
627 th_act = current_thread();
628 (void) host_set_exception_ports(host_priv_self(),
629 EXC_MASK_ALL & ~(EXC_MASK_SYSCALL |
630 EXC_MASK_MACH_SYSCALL |
631 EXC_MASK_RPC_ALERT),
632 ux_exception_port,
633 EXCEPTION_DEFAULT, 0);
634
635 (void) task_set_exception_ports(get_threadtask(th_act),
636 EXC_MASK_ALL & ~(EXC_MASK_SYSCALL |
637 EXC_MASK_MACH_SYSCALL |
638 EXC_MASK_RPC_ALERT),
639 ux_exception_port,
640 EXCEPTION_DEFAULT, 0);
641
642
643
644
645 ut = (uthread_t)get_bsdthread_info(th_act);
646
647 bsd_hardclockinit = 1; /* Start bsd hardclock */
648 bsd_init_task = get_threadtask(th_act);
649 init_task_failure_data[0] = 0;
650 system_region = lookup_default_shared_region(ENV_DEFAULT_ROOT, cpu_type());
651 if (system_region == NULL) {
652 shared_file_boot_time_init(ENV_DEFAULT_ROOT, cpu_type());
653 } else {
654 vm_set_shared_region(get_threadtask(th_act), system_region);
655 }
656 load_init_program(p);
657 /* turn on app-profiling i.e. pre-heating */
658 app_profile = 1;
659 lock_trace = 1;
660 }
661
662 void
663 lightning_bolt()
664 {
665 boolean_t funnel_state;
666 extern void klogwakeup(void);
667
668 funnel_state = thread_funnel_set(kernel_flock, TRUE);
669
670 thread_wakeup(&lbolt);
671 timeout(lightning_bolt,0,hz);
672 klogwakeup();
673
674 (void) thread_funnel_set(kernel_flock, FALSE);
675 }
676
677 bsd_autoconf()
678 {
679 extern kern_return_t IOKitBSDInit( void );
680
681 kminit();
682
683 /*
684 * Early startup for bsd pseudodevices.
685 */
686 {
687 struct pseudo_init *pi;
688
689 for (pi = pseudo_inits; pi->ps_func; pi++)
690 (*pi->ps_func) (pi->ps_count);
691 }
692
693 return( IOKitBSDInit());
694 }
695
696
697 #include <sys/disklabel.h> /* for MAXPARTITIONS */
698
699 static void
700 setconf(void)
701 {
702 extern kern_return_t IOFindBSDRoot( char * rootName,
703 dev_t * root, u_int32_t * flags );
704 u_int32_t flags;
705 kern_return_t err;
706
707 /*
708 * calls into IOKit can generate networking registrations
709 * which needs to be under network funnel. Right thing to do
710 * here is to drop the funnel alltogether and regrab it afterwards
711 */
712 thread_funnel_set(kernel_flock, FALSE);
713 err = IOFindBSDRoot( rootdevice, &rootdev, &flags );
714 thread_funnel_set(kernel_flock, TRUE);
715 if( err) {
716 printf("setconf: IOFindBSDRoot returned an error (%d);"
717 "setting rootdevice to 'sd0a'.\n", err); /* XXX DEBUG TEMP */
718 rootdev = makedev( 6, 0 );
719 strcpy( rootdevice, "sd0a" );
720 flags = 0;
721 }
722
723 #if NFSCLIENT
724 if( flags & 1 ) {
725 /* network device */
726 mountroot = netboot_mountroot;
727 } else {
728 #endif
729 /* otherwise have vfs determine root filesystem */
730 mountroot = NULL;
731 #if NFSCLIENT
732 }
733 #endif
734
735 }
736
737 bsd_utaskbootstrap()
738 {
739 thread_t th_act;
740 struct uthread *ut;
741
742 th_act = cloneproc(kernproc, 0);
743 initproc = pfind(1);
744 /* Set the launch time for init */
745 microtime(&initproc->p_stats->p_start);
746
747 ut = (struct uthread *)get_bsdthread_info(th_act);
748 ut->uu_sigmask = 0;
749 act_set_astbsd(th_act);
750 (void) thread_resume(th_act);
751 }
752
753 parse_bsd_args()
754 {
755 extern char init_args[];
756 char namep[16];
757 extern int boothowto;
758 extern int srv;
759 extern int ncl;
760
761 int len;
762
763 if (PE_parse_boot_arg("-s", namep)) {
764 boothowto |= RB_SINGLE;
765 len = strlen(init_args);
766 if(len != 0)
767 strcat(init_args," -s");
768 else
769 strcat(init_args,"-s");
770 }
771
772 if (PE_parse_boot_arg("-b", namep)) {
773 boothowto |= RB_NOBOOTRC;
774 len = strlen(init_args);
775 if(len != 0)
776 strcat(init_args," -b");
777 else
778 strcat(init_args,"-b");
779 }
780
781 if (PE_parse_boot_arg("-F", namep)) {
782 len = strlen(init_args);
783 if(len != 0)
784 strcat(init_args," -F");
785 else
786 strcat(init_args,"-F");
787 }
788
789 if (PE_parse_boot_arg("-v", namep)) {
790 len = strlen(init_args);
791 if(len != 0)
792 strcat(init_args," -v");
793 else
794 strcat(init_args,"-v");
795 }
796
797 if (PE_parse_boot_arg("-x", namep)) { /* safe boot */
798 len = strlen(init_args);
799 if(len != 0)
800 strcat(init_args," -x");
801 else
802 strcat(init_args,"-x");
803 }
804
805 if (PE_parse_boot_arg("-d", namep)) {
806 len = strlen(init_args);
807 if(len != 0)
808 strcat(init_args," -d");
809 else
810 strcat(init_args,"-d");
811 }
812
813 PE_parse_boot_arg("srv", &srv);
814 PE_parse_boot_arg("ncl", &ncl);
815 if (PE_parse_boot_arg("nbuf", &max_nbuf_headers))
816 customnbuf = 1;
817 PE_parse_boot_arg("kmem", &setup_kmem);
818
819 return 0;
820 }
821
822 #if !NFSCLIENT
823 int
824 netboot_root(void)
825 {
826 return(0);
827 }
828 #endif