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