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