[BACK]Return to init_main.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / kern

Annotation of src/sys/kern/init_main.c, Revision 1.482.2.3

1.482.2.3! pgoyette    1: /*     $NetBSD: init_main.c,v 1.489 2017/01/05 03:22:20 pgoyette Exp $ */
1.347     ad          2:
                      3: /*-
1.384     ad          4:  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
1.347     ad          5:  * All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  *
                     16:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     17:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     18:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     19:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     20:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     21:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     22:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     23:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     24:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     25:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     26:  * POSSIBILITY OF SUCH DAMAGE.
                     27:  */
1.61      mycroft    28:
                     29: /*
                     30:  * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993
                     31:  *     The Regents of the University of California.  All rights reserved.
                     32:  * (c) UNIX System Laboratories, Inc.
                     33:  * All or some portions of this file are derived from material licensed
                     34:  * to the University of California by American Telephone and Telegraph
                     35:  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
                     36:  * the permission of UNIX System Laboratories, Inc.
                     37:  *
                     38:  * Redistribution and use in source and binary forms, with or without
                     39:  * modification, are permitted provided that the following conditions
                     40:  * are met:
                     41:  * 1. Redistributions of source code must retain the above copyright
                     42:  *    notice, this list of conditions and the following disclaimer.
                     43:  * 2. Redistributions in binary form must reproduce the above copyright
                     44:  *    notice, this list of conditions and the following disclaimer in the
                     45:  *    documentation and/or other materials provided with the distribution.
1.224     agc        46:  * 3. Neither the name of the University nor the names of its contributors
                     47:  *    may be used to endorse or promote products derived from this software
                     48:  *    without specific prior written permission.
                     49:  *
                     50:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     51:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     52:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     53:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     54:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     55:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     56:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     57:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     58:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     59:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     60:  * SUCH DAMAGE.
                     61:  *
                     62:  *     @(#)init_main.c 8.16 (Berkeley) 5/14/95
                     63:  */
                     64:
                     65: /*
                     66:  * Copyright (c) 1995 Christopher G. Demetriou.  All rights reserved.
                     67:  *
                     68:  * Redistribution and use in source and binary forms, with or without
                     69:  * modification, are permitted provided that the following conditions
                     70:  * are met:
                     71:  * 1. Redistributions of source code must retain the above copyright
                     72:  *    notice, this list of conditions and the following disclaimer.
                     73:  * 2. Redistributions in binary form must reproduce the above copyright
                     74:  *    notice, this list of conditions and the following disclaimer in the
                     75:  *    documentation and/or other materials provided with the distribution.
1.61      mycroft    76:  * 3. All advertising materials mentioning features or use of this software
                     77:  *    must display the following acknowledgement:
                     78:  *     This product includes software developed by the University of
                     79:  *     California, Berkeley and its contributors.
                     80:  * 4. Neither the name of the University nor the names of its contributors
                     81:  *    may be used to endorse or promote products derived from this software
                     82:  *    without specific prior written permission.
                     83:  *
                     84:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     85:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     86:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     87:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     88:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     89:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     90:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     91:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     92:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     93:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     94:  * SUCH DAMAGE.
                     95:  *
1.118     fvdl       96:  *     @(#)init_main.c 8.16 (Berkeley) 5/14/95
1.61      mycroft    97:  */
1.196     lukem      98:
                     99: #include <sys/cdefs.h>
1.482.2.3! pgoyette  100: __KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.489 2017/01/05 03:22:20 pgoyette Exp $");
1.115     mrg       101:
1.370     tsutsui   102: #include "opt_ddb.h"
1.475     ozaki-r   103: #include "opt_inet.h"
1.223     jonathan  104: #include "opt_ipsec.h"
1.382     apb       105: #include "opt_modular.h"
1.267     kardel    106: #include "opt_ntp.h"
1.198     jdolecek  107: #include "opt_pipe.h"
1.172     soren     108: #include "opt_syscall_debug.h"
1.267     kardel    109: #include "opt_sysv.h"
1.292     ad        110: #include "opt_fileassoc.h"
                    111: #include "opt_ktrace.h"
1.281     elad      112: #include "opt_pax.h"
1.380     christos  113: #include "opt_compat_netbsd.h"
1.361     simonb    114: #include "opt_wapbl.h"
1.404     elad      115: #include "opt_ptrace.h"
1.458     tls       116: #include "opt_rnd_printf.h"
1.465     nat       117: #include "opt_splash.h"
1.482.2.3! pgoyette  118: #include "opt_kernhist.h"
1.465     nat       119:
1.470     uebayasi  120: #if defined(SPLASHSCREEN) && defined(makeoptions_SPLASHSCREEN_IMAGE)
1.465     nat       121: extern void *_binary_splash_image_start;
                    122: extern void *_binary_splash_image_end;
                    123: #endif
1.61      mycroft   124:
1.377     he        125: #include "ksyms.h"
1.441     tls       126:
1.276     dogcow    127: #include "veriexec.h"
1.106     explorer  128:
1.61      mycroft   129: #include <sys/param.h>
1.164     enami     130: #include <sys/acct.h>
1.61      mycroft   131: #include <sys/filedesc.h>
1.131     thorpej   132: #include <sys/file.h>
1.61      mycroft   133: #include <sys/errno.h>
1.162     thorpej   134: #include <sys/callout.h>
1.302     yamt      135: #include <sys/cpu.h>
1.436     jruoho    136: #include <sys/cpufreq.h>
1.408     dyoung    137: #include <sys/spldebug.h>
1.61      mycroft   138: #include <sys/kernel.h>
                    139: #include <sys/mount.h>
                    140: #include <sys/proc.h>
1.136     thorpej   141: #include <sys/kthread.h>
1.61      mycroft   142: #include <sys/resourcevar.h>
                    143: #include <sys/signalvar.h>
                    144: #include <sys/systm.h>
                    145: #include <sys/vnode.h>
1.288     hannken   146: #include <sys/fstrans.h>
1.87      thorpej   147: #include <sys/tty.h>
1.61      mycroft   148: #include <sys/conf.h>
1.95      thorpej   149: #include <sys/disklabel.h>
1.61      mycroft   150: #include <sys/buf.h>
                    151: #include <sys/device.h>
1.186     jdolecek  152: #include <sys/exec.h>
1.128     thorpej   153: #include <sys/socketvar.h>
1.61      mycroft   154: #include <sys/protosw.h>
1.338     yamt      155: #include <sys/percpu.h>
1.434     christos  156: #include <sys/pserialize.h>
1.342     rmind     157: #include <sys/pset.h>
1.338     yamt      158: #include <sys/sysctl.h>
1.61      mycroft   159: #include <sys/reboot.h>
1.209     jdolecek  160: #include <sys/event.h>
1.227     jonathan  161: #include <sys/mbuf.h>
1.302     yamt      162: #include <sys/sched.h>
1.292     ad        163: #include <sys/sleepq.h>
1.455     rmind     164: #include <sys/ipi.h>
1.284     ad        165: #include <sys/iostat.h>
1.304     yamt      166: #include <sys/vmem.h>
1.307     ad        167: #include <sys/uuid.h>
                    168: #include <sys/extent.h>
1.309     ad        169: #include <sys/disk.h>
1.325     ad        170: #include <sys/msgbuf.h>
1.340     ad        171: #include <sys/module.h>
1.343     ad        172: #include <sys/event.h>
1.357     ad        173: #include <sys/lockf.h>
1.364     pooka     174: #include <sys/once.h>
1.435     rmind     175: #include <sys/kcpuset.h>
1.367     ad        176: #include <sys/ksyms.h>
1.365     pooka     177: #include <sys/uidinfo.h>
1.379     pooka     178: #include <sys/kprintf.h>
1.482.2.3! pgoyette  179: #include <sys/bufq.h>
1.449     christos  180: #ifdef IPSEC
1.223     jonathan  181: #include <netipsec/ipsec.h>
                    182: #endif
1.82      christos  183: #include <sys/domain.h>
1.94      mouse     184: #include <sys/namei.h>
1.103     explorer  185: #include <sys/rnd.h>
1.192     jdolecek  186: #include <sys/pipe.h>
1.273     elad      187: #if NVERIEXEC > 0
1.245     blymn     188: #include <sys/verified_exec.h>
1.273     elad      189: #endif /* NVERIEXEC > 0 */
1.292     ad        190: #ifdef KTRACE
                    191: #include <sys/ktrace.h>
                    192: #endif
1.266     elad      193: #include <sys/kauth.h>
1.252     skrll     194: #include <net80211/ieee80211_netbsd.h>
1.437     tls       195: #include <sys/cprng.h>
1.61      mycroft   196:
1.77      christos  197: #include <sys/syscall.h>
1.68      cgd       198: #include <sys/syscallargs.h>
                    199:
1.281     elad      200: #include <sys/pax.h>
1.334     elad      201:
1.438     jym       202: #include <secmodel/secmodel.h>
                    203:
1.61      mycroft   204: #include <ufs/ufs/quota.h>
                    205:
1.159     fvdl      206: #include <miscfs/genfs/genfs.h>
1.410     elad      207: #include <miscfs/specfs/specdev.h>
1.159     fvdl      208:
1.323     ad        209: #include <sys/cpu.h>
1.61      mycroft   210:
1.425     uebayasi  211: #include <uvm/uvm.h>   /* extern struct uvm uvm */
1.114     mrg       212:
1.202     lukem     213: #include <dev/cons.h>
1.465     nat       214: #include <dev/splash/splash.h>
1.310     xtraeme   215:
1.414     pooka     216: #include <net/bpf.h>
1.81      christos  217: #include <net/if.h>
                    218: #include <net/raw_cb.h>
1.468     ozaki-r   219: #include <net/if_llatbl.h>
1.61      mycroft   220:
1.399     pooka     221: #include <prop/proplib.h>
                    222:
1.398     pooka     223: #include <sys/userconf.h>
                    224:
1.251     junyoung  225: extern struct lwp lwp0;
1.311     pooka     226: extern time_t rootfstime;
1.251     junyoung  227:
1.216     thorpej   228: #ifndef curlwp
                    229: struct lwp *curlwp = &lwp0;
1.133     pk        230: #endif
1.105     mycroft   231: struct proc *initproc;
1.61      mycroft   232:
                    233: struct vnode *rootvp, *swapdev_vp;
                    234: int    boothowto;
1.156     thorpej   235: int    cold = 1;                       /* still working on startup */
1.380     christos  236: struct timespec boottime;              /* time at system startup - will only follow settime deltas */
1.61      mycroft   237:
1.356     ad        238: int    start_init_exec;                /* semaphore for start_init() */
1.163     thorpej   239:
1.437     tls       240: cprng_strong_t *kern_cprng;
                    241:
1.260     christos  242: static void check_console(struct lwp *l);
1.176     thorpej   243: static void start_init(void *);
1.398     pooka     244: static void configure(void);
                    245: static void configure2(void);
1.421     tsutsui   246: static void configure3(void);
1.176     thorpej   247: void main(void);
1.280     christos  248:
1.61      mycroft   249: /*
                    250:  * System startup; initialize the world, create process 0, mount root
                    251:  * filesystem, and fork to create init and pagedaemon.  Most of the
                    252:  * hard work is done in the lower-level initialization routines including
                    253:  * startup(), which does memory initialization and autoconfiguration.
                    254:  */
1.81      christos  255: void
1.176     thorpej   256: main(void)
1.61      mycroft   257: {
1.380     christos  258:        struct timespec time;
1.216     thorpej   259:        struct lwp *l;
1.144     thorpej   260:        struct proc *p;
1.204     thorpej   261:        int s, error;
1.175     jdolecek  262: #ifdef NVNODE_IMPLICIT
                    263:        int usevnodes;
                    264: #endif
1.312     ad        265:        CPU_INFO_ITERATOR cii;
                    266:        struct cpu_info *ci;
1.61      mycroft   267:
1.216     thorpej   268:        l = &lwp0;
1.327     matt      269: #ifndef LWP0_CPU_INFO
1.216     thorpej   270:        l->l_cpu = curcpu();
1.327     matt      271: #endif
1.394     yamt      272:        l->l_pflag |= LP_RUNNING;
1.233     junyoung  273:
1.317     ad        274:        /*
1.61      mycroft   275:         * Attempt to find console and initialize
                    276:         * in case of early panic or other messages.
                    277:         */
                    278:        consinit();
                    279:
1.321     ad        280:        kernel_lock_init();
1.364     pooka     281:        once_init();
1.434     christos  282:
1.440     rmind     283:        mi_cpu_init();
1.423     pgoyette  284:        kernconfig_lock_init();
1.429     rmind     285:        kthread_sysinit();
1.179     thorpej   286:
1.397     pooka     287:        /* Initialize the device switch tables. */
                    288:        devsw_init();
                    289:
1.432     rmind     290:        /* Initialize event counters. */
                    291:        evcnt_init();
                    292:
1.114     mrg       293:        uvm_init();
1.457     riastrad  294:        ubchist_init();
1.435     rmind     295:        kcpuset_sysinit();
1.127     thorpej   296:
1.399     pooka     297:        prop_kern_init();
                    298:
1.377     he        299: #if ((NKSYMS > 0) || (NDDB > 0) || (NMODULAR > 0))
1.376     martin    300:        ksyms_init();
1.377     he        301: #endif
1.379     pooka     302:        kprintf_init();
1.376     martin    303:
1.338     yamt      304:        percpu_init();
                    305:
1.347     ad        306:        /* Initialize lock caches. */
                    307:        mutex_obj_init();
1.389     ad        308:        rw_obj_init();
1.347     ad        309:
1.434     christos  310:        /* Passive serialization. */
                    311:        pserialize_init();
                    312:
1.482.2.1  pgoyette  313:        /* Init the detach capability in devsw */
                    314:        devsw_detach_init();
                    315:
1.307     ad        316:        /* Initialize the extent manager. */
                    317:        extent_init();
                    318:
1.145     thorpej   319:        /* Do machine-dependent initialization. */
                    320:        cpu_startup();
1.162     thorpej   321:
1.378     pooka     322:        /* Initialize the sysctl subsystem. */
                    323:        sysctl_init();
                    324:
1.307     ad        325:        /* Initialize callouts, part 1. */
1.166     enami     326:        callout_startup();
1.145     thorpej   327:
1.409     elad      328:        /* Initialize the kernel authorization subsystem. */
                    329:        kauth_init();
                    330:
1.438     jym       331:        secmodel_init();
                    332:
1.409     elad      333:        spec_init();
                    334:
1.414     pooka     335:        /*
                    336:         * Set BPF op vector.  Can't do this in bpf attach, since
                    337:         * network drivers attach before bpf.
                    338:         */
                    339:        bpf_setops();
                    340:
1.403     elad      341:        /* Start module system. */
1.417     pooka     342:        module_init();
1.403     elad      343:
1.291     elad      344:        /*
                    345:         * Initialize the kernel authorization subsystem and start the
                    346:         * default security model, if any. We need to do this early
                    347:         * enough so that subsystems relying on any of the aforementioned
                    348:         * can work properly. Since the security model may dictate the
                    349:         * credential inheritance policy, it is needed at least before
                    350:         * any process is created, specifically proc0.
                    351:         */
1.403     elad      352:        module_init_class(MODULE_CLASS_SECMODEL);
1.290     elad      353:
1.228     pk        354:        /* Initialize the buffer cache */
                    355:        bufinit();
1.482.2.3! pgoyette  356:        biohist_init();
        !           357:
        !           358: #ifdef KERNHIST
        !           359:        sysctl_kernhist_init();
        !           360: #endif
1.228     pk        361:
1.465     nat       362:
                    363: #if defined(SPLASHSCREEN) && defined(SPLASHSCREEN_IMAGE)
                    364:        size_t splash_size = (&_binary_splash_image_end -
                    365:            &_binary_splash_image_start) * sizeof(void *);
                    366:        splash_setimage(&_binary_splash_image_start, splash_size);
                    367: #endif
                    368:
1.128     thorpej   369:        /* Initialize sockets. */
                    370:        soinit();
1.127     thorpej   371:
1.156     thorpej   372:        /*
1.212     thorpej   373:         * The following things must be done before autoconfiguration.
1.156     thorpej   374:         */
1.437     tls       375:        rnd_init();             /* initialize entropy pool */
                    376:
                    377:        cprng_init();           /* initialize cryptographic PRNG */
1.176     thorpej   378:
1.236     simonb    379:        /* Initialize process and pgrp structures. */
1.63      mycroft   380:        procinit();
1.279     thorpej   381:        lwpinit();
1.210     thorpej   382:
1.251     junyoung  383:        /* Initialize signal-related data structures. */
                    384:        signal_init();
1.61      mycroft   385:
1.333     ad        386:        /* Initialize resource management. */
                    387:        resource_init();
                    388:
1.407     rmind     389:        /* Create process 0. */
1.251     junyoung  390:        proc0_init();
1.420     pooka     391:        lwp0_init();
1.61      mycroft   392:
1.383     yamt      393:        /* Disable preemption during boot. */
                    394:        kpreempt_disable();
                    395:
1.307     ad        396:        /* Initialize the UID hash table. */
                    397:        uid_init();
                    398:
                    399:        /* Charge root for one process. */
1.61      mycroft   400:        (void)chgproccnt(0, 1);
                    401:
1.330     ad        402:        /* Initialize timekeeping. */
                    403:        time_init();
                    404:
1.292     ad        405:        /* Initialize the run queues, turnstiles and sleep queues. */
1.302     yamt      406:        sched_rqinit();
1.292     ad        407:        turnstile_init();
                    408:        sleeptab_init(&sleeptab);
                    409:
1.405     elad      410:        sched_init();
                    411:
1.339     rmind     412:        /* Initialize processor-sets */
                    413:        psets_init();
                    414:
1.436     jruoho    415:        /* Initialize cpufreq(9) */
                    416:        cpufreq_init();
                    417:
1.302     yamt      418:        /* MI initialization of the boot cpu */
                    419:        error = mi_cpu_attach(curcpu());
                    420:        KASSERT(error == 0);
                    421:
1.350     ad        422:        /* Initialize timekeeping, part 2. */
                    423:        time_init2();
                    424:
1.338     yamt      425:        /*
                    426:         * Initialize mbuf's.  Do this now because we might attempt to
                    427:         * allocate mbufs or mbuf clusters during autoconfiguration.
                    428:         */
                    429:        mbinit();
                    430:
1.284     ad        431:        /* Initialize I/O statistics. */
                    432:        iostat_init();
                    433:
1.325     ad        434:        /* Initialize the log device. */
                    435:        loginit();
                    436:
1.403     elad      437:        /* Second part of module system initialization. */
1.422     pgoyette  438:        module_start_unload_thread();
1.355     ad        439:
1.61      mycroft   440:        /* Initialize the file systems. */
1.194     matt      441: #ifdef NVNODE_IMPLICIT
                    442:        /*
                    443:         * If maximum number of vnodes in namei vnode cache is not explicitly
                    444:         * defined in kernel config, adjust the number such as we use roughly
1.359     ad        445:         * 10% of memory for vnodes and associated data structures in the
                    446:         * assumed worst case.  Do not provide fewer than NVNODE vnodes.
1.194     matt      447:         */
1.448     para      448:        usevnodes = calc_cache_size(vmem_size(kmem_arena, VMEM_FREE|VMEM_ALLOC),
                    449:            10, VNODE_KMEM_MAXPCT) / VNODE_COST;
1.205     sommerfe  450:        if (usevnodes > desiredvnodes)
1.194     matt      451:                desiredvnodes = usevnodes;
                    452: #endif
1.61      mycroft   453:        vfsinit();
1.357     ad        454:        lf_init();
1.61      mycroft   455:
1.288     hannken   456:        /* Initialize fstrans. */
                    457:        fstrans_init();
1.267     kardel    458:
1.319     ad        459:        /* Initialize the file descriptor system. */
1.343     ad        460:        fd_sys_init();
1.319     ad        461:
1.375     pooka     462:        /* Initialize cwd structures */
                    463:        cwd_sys_init();
                    464:
1.344     ad        465:        /* Initialize kqueue. */
1.343     ad        466:        kqueue_init();
1.307     ad        467:
1.268     kardel    468:        inittimecounter();
1.267     kardel    469:        ntp_init();
                    470:
1.326     ad        471:        /* Initialize tty subsystem. */
                    472:        tty_init();
                    473:        ttyldisc_init();
                    474:
1.336     ad        475:        /* Initialize the buffer cache, part 2. */
                    476:        bufinit2();
                    477:
1.309     ad        478:        /* Initialize the disk wedge subsystem. */
                    479:        dkwedge_init();
                    480:
1.437     tls       481:        /* Initialize the kernel strong PRNG. */
                    482:        kern_cprng = cprng_strong_create("kernel", IPL_VM,
                    483:                                         CPRNG_INIT_ANY|CPRNG_REKEY_ANY);
1.458     tls       484:
1.360     yamt      485:        /* Initialize interfaces. */
                    486:        ifinit1();
                    487:
1.408     dyoung    488:        spldebug_start();
                    489:
1.433     bouyer    490:        /* Initialize sockets thread(s) */
                    491:        soinit1();
                    492:
1.482.2.3! pgoyette  493:        /*
        !           494:         * Initialize the bufq strategy sub-system and any built-in
        !           495:         * strategy modules - they may be needed by some devices during
        !           496:         * auto-configuration
        !           497:         */
        !           498:        bufq_init();
        !           499:        module_init_class(MODULE_CLASS_BUFQ);
        !           500:
1.156     thorpej   501:        /* Configure the system hardware.  This will enable interrupts. */
                    502:        configure();
1.61      mycroft   503:
1.459     riastrad  504:        /* Once all CPUs are detected, initialize the per-CPU cprng_fast.  */
                    505:        cprng_fast_init();
                    506:
1.381     christos  507:        ssp_init();
                    508:
1.424     eeh       509:        ubc_init();             /* must be after autoconfig */
                    510:
1.432     rmind     511:        mm_init();
                    512:
1.381     christos  513:        configure2();
1.456     rmind     514:
                    515:        ipi_sysinit();
                    516:
1.383     yamt      517:        /* Now timer is working.  Enable preemption. */
                    518:        kpreempt_enable();
                    519:
1.461     uebayasi  520:        /* Get the threads going and into any sleeps before continuing. */
                    521:        yield();
                    522:
1.453     riastrad  523:        /* Enable deferred processing of RNG samples */
                    524:        rnd_init_softint();
                    525:
1.458     tls       526: #ifdef RND_PRINTF
                    527:        /* Enable periodic injection of console output into entropy pool */
                    528:        kprintf_init_callout();
                    529: #endif
                    530:
1.418     cegger    531:        vmem_rehash_start();    /* must be before exec_init */
                    532:
                    533:        /* Initialize exec structures */
                    534:        exec_init(1);           /* seminit calls exithook_establish() */
                    535:
1.273     elad      536: #if NVERIEXEC > 0
1.283     elad      537:        /*
                    538:         * Initialise the Veriexec subsystem.
                    539:         */
                    540:        veriexec_init();
1.273     elad      541: #endif /* NVERIEXEC > 0 */
1.251     junyoung  542:
1.281     elad      543:        pax_init();
                    544:
1.449     christos  545: #ifdef IPSEC
1.223     jonathan  546:        /* Attach network crypto subsystem */
                    547:        ipsec_attach();
                    548: #endif
1.61      mycroft   549:
                    550:        /*
                    551:         * Initialize protocols.  Block reception of incoming packets
                    552:         * until everything is ready.
                    553:         */
1.190     thorpej   554:        s = splnet();
1.61      mycroft   555:        ifinit();
1.475     ozaki-r   556: #if defined(INET) || defined(INET6)
1.468     ozaki-r   557:        lltableinit();
1.469     ozaki-r   558: #endif
1.390     pooka     559:        domaininit(true);
1.200     itojun    560:        if_attachdomain();
1.61      mycroft   561:        splx(s);
                    562:
                    563: #ifdef GPROF
                    564:        /* Initialize kernel profiling. */
                    565:        kmstartup();
                    566: #endif
1.164     enami     567:
1.351     sborrill  568:        /* Initialize system accounting. */
1.164     enami     569:        acct_init();
1.61      mycroft   570:
1.301     ad        571: #ifndef PIPE_SOCKETPAIR
1.300     ad        572:        /* Initialize pipes. */
                    573:        pipe_init();
1.301     ad        574: #endif
1.300     ad        575:
1.292     ad        576: #ifdef KTRACE
                    577:        /* Initialize ktrace. */
                    578:        ktrinit();
                    579: #endif
                    580:
1.406     elad      581:        machdep_init();
                    582:
1.427     pooka     583:        procinit_sysctl();
                    584:
1.472     mrg       585:        scdebug_init();
                    586:
1.163     thorpej   587:        /*
                    588:         * Create process 1 (init(8)).  We do this now, as Unix has
                    589:         * historically had init be process 1, and changing this would
                    590:         * probably upset a lot of people.
                    591:         *
                    592:         * Note that process 1 won't immediately exec init(8), but will
                    593:         * wait for us to inform it that the root file system has been
                    594:         * mounted.
                    595:         */
1.216     thorpej   596:        if (fork1(l, 0, SIGCHLD, NULL, 0, start_init, NULL, NULL, &initproc))
1.163     thorpej   597:                panic("fork init");
                    598:
                    599:        /*
1.340     ad        600:         * Load any remaining builtin modules, and hand back temporary
1.422     pgoyette  601:         * storage to the VM system.  Then require force when loading any
                    602:         * remaining un-init'ed built-in modules to avoid later surprises.
1.340     ad        603:         */
                    604:        module_init_class(MODULE_CLASS_ANY);
1.422     pgoyette  605:        module_builtin_require_force();
1.340     ad        606:
                    607:        /*
1.208     thorpej   608:         * Finalize configuration now that all real devices have been
                    609:         * found.  This needs to be done before the root device is
                    610:         * selected, since finalization may create the root device.
                    611:         */
                    612:        config_finalize();
1.163     thorpej   613:
1.400     pooka     614:        sysctl_finalize();
                    615:
1.163     thorpej   616:        /*
                    617:         * Now that autoconfiguration has completed, we can determine
                    618:         * the root and dump devices.
                    619:         */
1.445     mlelstv   620:        cpu_rootconf();
1.101     thorpej   621:        cpu_dumpconf();
1.61      mycroft   622:
                    623:        /* Mount the root file system. */
1.95      thorpej   624:        do {
1.416     pooka     625:                domountroothook(root_device);
1.95      thorpej   626:                if ((error = vfs_mountroot())) {
1.97      thorpej   627:                        printf("cannot mount root, error = %d\n", error);
1.95      thorpej   628:                        boothowto |= RB_ASKNAME;
                    629:                        setroot(root_device,
1.152     thorpej   630:                            (rootdev != NODEV) ? DISKPART(rootdev) : 0);
1.95      thorpej   631:                }
                    632:        } while (error != 0);
                    633:        mountroothook_destroy();
                    634:
1.421     tsutsui   635:        configure3();
                    636:
1.239     pk        637:        /*
                    638:         * Initialise the time-of-day clock, passing the time recorded
                    639:         * in the root filesystem (if any) for use by systems that
                    640:         * don't have a non-volatile time-of-day device.
                    641:         */
                    642:        inittodr(rootfstime);
                    643:
1.61      mycroft   644:        /*
                    645:         * Now can look at time, having had a chance to verify the time
1.292     ad        646:         * from the file system.  Reset l->l_rtime as it may have been
1.61      mycroft   647:         * munched in mi_switch() after the time got set.
                    648:         */
1.380     christos  649:        getnanotime(&time);
1.267     kardel    650:        boottime = time;
1.447     pgoyette  651:
1.352     ad        652:        mutex_enter(proc_lock);
1.225     jdolecek  653:        LIST_FOREACH(p, &allproc, p_list) {
1.295     pavel     654:                KASSERT((p->p_flag & PK_MARKER) == 0);
1.353     ad        655:                mutex_enter(p->p_lock);
1.380     christos  656:                TIMESPEC_TO_TIMEVAL(&p->p_stats->p_start, &time);
1.225     jdolecek  657:                LIST_FOREACH(l, &p->p_lwps, l_sibling) {
1.292     ad        658:                        lwp_lock(l);
1.332     yamt      659:                        memset(&l->l_rtime, 0, sizeof(l->l_rtime));
1.292     ad        660:                        lwp_unlock(l);
1.225     jdolecek  661:                }
1.353     ad        662:                mutex_exit(p->p_lock);
1.163     thorpej   663:        }
1.352     ad        664:        mutex_exit(proc_lock);
1.332     yamt      665:        binuptime(&curlwp->l_stime);
1.61      mycroft   666:
1.312     ad        667:        for (CPU_INFO_FOREACH(cii, ci)) {
                    668:                ci->ci_schedstate.spc_lastmod = time_second;
                    669:        }
                    670:
1.163     thorpej   671:        /* Create the pageout daemon kernel thread. */
                    672:        uvm_swap_init();
1.336     ad        673:        if (kthread_create(PRI_PGDAEMON, KTHREAD_MPSAFE, NULL, uvm_pageout,
1.307     ad        674:            NULL, NULL, "pgdaemon"))
1.135     thorpej   675:                panic("fork pagedaemon");
1.61      mycroft   676:
1.163     thorpej   677:        /* Create the filesystem syncer kernel thread. */
1.336     ad        678:        if (kthread_create(PRI_IOFLUSH, KTHREAD_MPSAFE, NULL, sched_sync,
                    679:            NULL, NULL, "ioflush"))
1.159     fvdl      680:                panic("fork syncer");
1.185     chs       681:
                    682:        /* Create the aiodone daemon kernel thread. */
1.286     yamt      683:        if (workqueue_create(&uvm.aiodone_queue, "aiodoned",
1.336     ad        684:            uvm_aiodone_worker, NULL, PRI_VM, IPL_NONE, WQ_MPSAFE))
1.185     chs       685:                panic("fork aiodoned");
1.137     thorpej   686:
1.462     mrg       687:        /* Wait for final configure threads to complete. */
                    688:        config_finalize_mountroot();
                    689:
1.163     thorpej   690:        /*
                    691:         * Okay, now we can let init(8) exec!  It's off to userland!
                    692:         */
1.356     ad        693:        mutex_enter(proc_lock);
1.163     thorpej   694:        start_init_exec = 1;
1.356     ad        695:        cv_broadcast(&lbolt);
                    696:        mutex_exit(proc_lock);
1.163     thorpej   697:
1.61      mycroft   698:        /* The scheduler is an infinite loop. */
1.114     mrg       699:        uvm_scheduler();
1.61      mycroft   700:        /* NOTREACHED */
                    701: }
                    702:
1.398     pooka     703: /*
                    704:  * Configure the system's hardware.
                    705:  */
                    706: static void
                    707: configure(void)
                    708: {
                    709:
                    710:        /* Initialize autoconf data structures. */
1.401     pooka     711:        config_init_mi();
1.398     pooka     712:        /*
                    713:         * XXX
                    714:         * callout_setfunc() requires mutex(9) so it can't be in config_init()
                    715:         * on amiga and atari which use config_init() and autoconf(9) fucntions
                    716:         * to initialize console devices.
                    717:         */
                    718:        config_twiddle_init();
                    719:
                    720:        pmf_init();
                    721:
1.471     jmcneill  722:        /* Initialize driver modules */
                    723:        module_init_class(MODULE_CLASS_DRIVER);
                    724:
1.430     uebayasi  725:        userconf_init();
1.398     pooka     726:        if (boothowto & RB_USERCONF)
1.430     uebayasi  727:                userconf_prompt();
1.398     pooka     728:
                    729:        if ((boothowto & (AB_SILENT|AB_VERBOSE)) == AB_SILENT) {
                    730:                printf_nolog("Detecting hardware...");
                    731:        }
                    732:
                    733:        /*
                    734:         * Do the machine-dependent portion of autoconfiguration.  This
                    735:         * sets the configuration machinery here in motion by "finding"
                    736:         * the root bus.  When this function returns, we expect interrupts
                    737:         * to be enabled.
                    738:         */
                    739:        cpu_configure();
                    740: }
                    741:
                    742: static void
                    743: configure2(void)
                    744: {
                    745:        CPU_INFO_ITERATOR cii;
                    746:        struct cpu_info *ci;
                    747:        int s;
                    748:
                    749:        /*
                    750:         * Now that we've found all the hardware, start the real time
                    751:         * and statistics clocks.
                    752:         */
                    753:        initclocks();
                    754:
                    755:        cold = 0;       /* clocks are running, we're warm now! */
                    756:        s = splsched();
                    757:        curcpu()->ci_schedstate.spc_flags |= SPCF_RUNNING;
                    758:        splx(s);
                    759:
                    760:        /* Boot the secondary processors. */
                    761:        for (CPU_INFO_FOREACH(cii, ci)) {
                    762:                uvm_cpu_attach(ci);
                    763:        }
                    764:        mp_online = true;
                    765: #if defined(MULTIPROCESSOR)
                    766:        cpu_boot_secondary_processors();
                    767: #endif
                    768:
                    769:        /* Setup the runqueues and scheduler. */
                    770:        runq_init();
1.405     elad      771:        synch_init();
1.398     pooka     772:
                    773:        /*
                    774:         * Bus scans can make it appear as if the system has paused, so
                    775:         * twiddle constantly while config_interrupts() jobs are running.
                    776:         */
                    777:        config_twiddle_fn(NULL);
                    778:
                    779:        /*
                    780:         * Create threads to call back and finish configuration for
                    781:         * devices that want interrupts enabled.
                    782:         */
                    783:        config_create_interruptthreads();
                    784: }
                    785:
1.93      mouse     786: static void
1.421     tsutsui   787: configure3(void)
                    788: {
                    789:
                    790:        /*
                    791:         * Create threads to call back and finish configuration for
                    792:         * devices that want the mounted root file system.
                    793:         */
                    794:        config_create_mountrootthreads();
                    795:
                    796:        /* Get the threads going and into any sleeps before continuing. */
                    797:        yield();
                    798: }
                    799:
                    800: static void
1.443     mlelstv   801: rootconf_handle_wedges(void)
                    802: {
1.477     christos  803:        struct disklabel label;
1.443     mlelstv   804:        struct partition *p;
                    805:        struct vnode *vp;
                    806:        daddr_t startblk;
                    807:        uint64_t nblks;
1.482     msaitoh   808:        device_t dev;
1.443     mlelstv   809:        int error;
                    810:
                    811:        if (booted_nblks) {
                    812:                /*
                    813:                 * bootloader passed geometry
                    814:                 */
                    815:                dev      = booted_device;
                    816:                startblk = booted_startblk;
                    817:                nblks    = booted_nblks;
                    818:
                    819:                /*
                    820:                 * keep booted_device and booted_partition
                    821:                 * in case the kernel doesn't identify a wedge
                    822:                 */
                    823:        } else {
                    824:                /*
                    825:                 * bootloader passed partition number
                    826:                 *
                    827:                 * We cannot ask the partition device directly when it is
                    828:                 * covered by a wedge. Instead we look up the geometry in
                    829:                 * the disklabel.
                    830:                 */
                    831:                vp = opendisk(booted_device);
1.444     martin    832:
                    833:                if (vp == NULL)
                    834:                        return;
                    835:
1.477     christos  836:                error = VOP_IOCTL(vp, DIOCGDINFO, &label, FREAD, NOCRED);
1.443     mlelstv   837:                VOP_CLOSE(vp, FREAD, NOCRED);
                    838:                vput(vp);
                    839:                if (error)
                    840:                        return;
                    841:
                    842:                KASSERT(booted_partition >= 0
                    843:                        && booted_partition < MAXPARTITIONS);
                    844:
1.477     christos  845:                p = &label.d_partitions[booted_partition];
1.443     mlelstv   846:
                    847:                dev      = booted_device;
                    848:                startblk = p->p_offset;
                    849:                nblks    = p->p_size;
                    850:        }
                    851:
                    852:        dev = dkwedge_find_partition(dev, startblk, nblks);
                    853:        if (dev != NULL) {
                    854:                booted_device = dev;
                    855:                booted_partition = 0;
                    856:        }
                    857: }
                    858:
1.445     mlelstv   859: void
1.443     mlelstv   860: rootconf(void)
                    861: {
1.445     mlelstv   862:        if (booted_device != NULL)
                    863:                rootconf_handle_wedges();
1.443     mlelstv   864:
                    865:        setroot(booted_device, booted_partition);
                    866: }
                    867:
                    868: static void
1.260     christos  869: check_console(struct lwp *l)
1.93      mouse     870: {
1.391     dholland  871:        struct vnode *vp;
1.93      mouse     872:        int error;
                    873:
1.391     dholland  874:        error = namei_simple_kernel("/dev/console",
                    875:                                NSM_FOLLOW_NOEMULROOT, &vp);
1.96      cgd       876:        if (error == 0)
1.391     dholland  877:                vrele(vp);
1.96      cgd       878:        else if (error == ENOENT)
                    879:                printf("warning: no /dev/console\n");
1.93      mouse     880:        else
1.96      cgd       881:                printf("warning: lookup /dev/console: error %d\n", error);
1.93      mouse     882: }
                    883:
1.61      mycroft   884: /*
                    885:  * List of paths to try when searching for "init".
                    886:  */
1.327     matt      887: static const char * const initpaths[] = {
1.61      mycroft   888:        "/sbin/init",
                    889:        "/sbin/oinit",
                    890:        "/sbin/init.bak",
1.454     apb       891:        "/rescue/init",
1.61      mycroft   892:        NULL,
                    893: };
                    894:
                    895: /*
                    896:  * Start the initial user process; try exec'ing each pathname in "initpaths".
                    897:  * The program is invoked with one argument containing the boot flags.
                    898:  */
                    899: static void
1.176     thorpej   900: start_init(void *arg)
1.61      mycroft   901: {
1.216     thorpej   902:        struct lwp *l = arg;
                    903:        struct proc *p = l->l_proc;
1.130     eeh       904:        vaddr_t addr;
1.78      mycroft   905:        struct sys_execve_args /* {
1.108     mycroft   906:                syscallarg(const char *) path;
1.92      cgd       907:                syscallarg(char * const *) argp;
                    908:                syscallarg(char * const *) envp;
1.68      cgd       909:        } */ args;
                    910:        int options, i, error;
                    911:        register_t retval[2];
1.66      mycroft   912:        char flags[4], *flagsp;
1.202     lukem     913:        const char *path, *slash;
1.474     christos  914:        char *ucp, **uap, *arg0, *arg1, *argv[3];
1.202     lukem     915:        char ipath[129];
                    916:        int ipx, len;
1.61      mycroft   917:
1.76      cgd       918:        /*
                    919:         * Now in process 1.
                    920:         */
1.146     gwr       921:        strncpy(p->p_comm, "init", MAXCOMLEN);
1.163     thorpej   922:
                    923:        /*
                    924:         * Wait for main() to tell us that it's safe to exec.
                    925:         */
1.356     ad        926:        mutex_enter(proc_lock);
1.163     thorpej   927:        while (start_init_exec == 0)
1.356     ad        928:                cv_wait(&lbolt, proc_lock);
                    929:        mutex_exit(proc_lock);
1.93      mouse     930:
                    931:        /*
                    932:         * This is not the right way to do this.  We really should
                    933:         * hand-craft a descriptor onto /dev/console to hand to init,
                    934:         * but that's a _lot_ more work, and the benefit from this easy
                    935:         * hack makes up for the "good is the enemy of the best" effect.
                    936:         */
1.260     christos  937:        check_console(l);
1.61      mycroft   938:
                    939:        /*
                    940:         * Need just enough stack to hold the faked-up "execve()" arguments.
                    941:         */
1.211     chs       942:        addr = (vaddr_t)STACK_ALLOC(USRSTACK, PAGE_SIZE);
1.205     sommerfe  943:        if (uvm_map(&p->p_vmspace->vm_map, &addr, PAGE_SIZE,
1.482.2.2  pgoyette  944:            NULL, UVM_UNKNOWN_OFFSET, 0,
                    945:            UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_RW, UVM_INH_COPY,
                    946:            UVM_ADV_NORMAL,
                    947:            UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW)) != 0)
1.114     mrg       948:                panic("init: couldn't allocate argument space");
1.297     christos  949:        p->p_vmspace->vm_maxsaddr = (void *)STACK_MAX(addr, PAGE_SIZE);
1.61      mycroft   950:
1.202     lukem     951:        ipx = 0;
                    952:        while (1) {
                    953:                if (boothowto & RB_ASKNAME) {
                    954:                        printf("init path");
                    955:                        if (initpaths[ipx])
                    956:                                printf(" (default %s)", initpaths[ipx]);
                    957:                        printf(": ");
                    958:                        len = cngetsn(ipath, sizeof(ipath)-1);
1.371     tsutsui   959:                        if (len == 4 && strcmp(ipath, "halt") == 0) {
1.370     tsutsui   960:                                cpu_reboot(RB_HALT, NULL);
                    961:                        } else if (len == 6 && strcmp(ipath, "reboot") == 0) {
                    962:                                cpu_reboot(0, NULL);
                    963: #if defined(DDB)
                    964:                        } else if (len == 3 && strcmp(ipath, "ddb") == 0) {
                    965:                                console_debugger();
                    966:                                continue;
                    967: #endif
1.371     tsutsui   968:                        } else if (len > 0 && ipath[0] == '/') {
1.202     lukem     969:                                ipath[len] = '\0';
                    970:                                path = ipath;
1.371     tsutsui   971:                        } else if (len == 0 && initpaths[ipx] != NULL) {
                    972:                                path = initpaths[ipx++];
                    973:                        } else {
                    974:                                printf("use absolute path, ");
                    975: #if defined(DDB)
                    976:                                printf("\"ddb\", ");
                    977: #endif
                    978:                                printf("\"halt\", or \"reboot\"\n");
                    979:                                continue;
1.202     lukem     980:                        }
                    981:                } else {
1.370     tsutsui   982:                        if ((path = initpaths[ipx++]) == NULL) {
                    983:                                ipx = 0;
                    984:                                boothowto |= RB_ASKNAME;
                    985:                                continue;
                    986:                        }
1.202     lukem     987:                }
                    988:
1.211     chs       989:                ucp = (char *)USRSTACK;
1.64      mycroft   990:
1.61      mycroft   991:                /*
1.64      mycroft   992:                 * Construct the boot flag argument.
1.61      mycroft   993:                 */
1.66      mycroft   994:                flagsp = flags;
                    995:                *flagsp++ = '-';
1.61      mycroft   996:                options = 0;
1.66      mycroft   997:
1.61      mycroft   998:                if (boothowto & RB_SINGLE) {
1.64      mycroft   999:                        *flagsp++ = 's';
1.61      mycroft  1000:                        options = 1;
                   1001:                }
                   1002: #ifdef notyet
                   1003:                if (boothowto & RB_FASTBOOT) {
1.64      mycroft  1004:                        *flagsp++ = 'f';
1.61      mycroft  1005:                        options = 1;
                   1006:                }
                   1007: #endif
1.64      mycroft  1008:
                   1009:                /*
                   1010:                 * Move out the flags (arg 1), if necessary.
                   1011:                 */
                   1012:                if (options != 0) {
                   1013:                        *flagsp++ = '\0';
                   1014:                        i = flagsp - flags;
                   1015: #ifdef DEBUG
1.415     hubertf  1016:                        aprint_normal("init: copying out flags `%s' %d\n", flags, i);
1.64      mycroft  1017: #endif
1.211     chs      1018:                        arg1 = STACK_ALLOC(ucp, i);
                   1019:                        ucp = STACK_MAX(arg1, i);
1.474     christos 1020:                        if ((error = copyout((void *)flags, arg1, i)) != 0)
                   1021:                                goto copyerr;
                   1022:                } else
                   1023:                        arg1 = NULL;
1.61      mycroft  1024:
                   1025:                /*
                   1026:                 * Move out the file name (also arg 0).
                   1027:                 */
1.64      mycroft  1028:                i = strlen(path) + 1;
                   1029: #ifdef DEBUG
1.415     hubertf  1030:                aprint_normal("init: copying out path `%s' %d\n", path, i);
1.202     lukem    1031: #else
1.203     lukem    1032:                if (boothowto & RB_ASKNAME || path != initpaths[0])
1.202     lukem    1033:                        printf("init: trying %s\n", path);
1.64      mycroft  1034: #endif
1.211     chs      1035:                arg0 = STACK_ALLOC(ucp, i);
                   1036:                ucp = STACK_MAX(arg0, i);
1.474     christos 1037:                if ((error = copyout(path, arg0, i)) != 0)
                   1038:                        goto copyerr;
1.61      mycroft  1039:
                   1040:                /*
                   1041:                 * Move out the arg pointers.
                   1042:                 */
1.439     christos 1043:                ucp = (void *)STACK_ALIGN(ucp, STACK_ALIGNBYTES);
1.479     macallan 1044:                uap = (char **)STACK_ALLOC(ucp, sizeof(argv));
1.211     chs      1045:                SCARG(&args, path) = arg0;
                   1046:                SCARG(&args, argp) = uap;
                   1047:                SCARG(&args, envp) = NULL;
1.142     mycroft  1048:                slash = strrchr(path, '/');
1.474     christos 1049:
                   1050:                argv[0] = slash ? arg0 + (slash + 1 - path) : arg0;
                   1051:                argv[1] = arg1;
                   1052:                argv[2] = NULL;
1.479     macallan 1053:                if ((error = copyout(argv, uap, sizeof(argv))) != 0)
1.474     christos 1054:                        goto copyerr;
1.61      mycroft  1055:
                   1056:                /*
1.481     palle    1057:                 * Now try to exec the program.  If it can't for any reason
1.61      mycroft  1058:                 * other than it doesn't exist, complain.
                   1059:                 */
1.260     christos 1060:                error = sys_execve(l, &args, retval);
1.179     thorpej  1061:                if (error == 0 || error == EJUSTRETURN) {
1.292     ad       1062:                        KERNEL_UNLOCK_LAST(l);
1.61      mycroft  1063:                        return;
1.179     thorpej  1064:                }
1.202     lukem    1065:                printf("exec %s: error %d\n", path, error);
1.61      mycroft  1066:        }
1.90      christos 1067:        printf("init: not found\n");
1.61      mycroft  1068:        panic("no init");
1.474     christos 1069: copyerr:
                   1070:        panic("copyout %d", error);
1.61      mycroft  1071: }
1.345     yamt     1072:
                   1073: /*
1.448     para     1074:  * calculate cache size (in bytes) from physmem and vsize.
1.345     yamt     1075:  */
                   1076: vaddr_t
1.448     para     1077: calc_cache_size(vsize_t vsize, int pct, int va_pct)
1.345     yamt     1078: {
                   1079:        paddr_t t;
                   1080:
                   1081:        /* XXX should consider competing cache if any */
                   1082:        /* XXX should consider submaps */
1.346     yamt     1083:        t = (uintmax_t)physmem * pct / 100 * PAGE_SIZE;
1.448     para     1084:        if (vsize != 0) {
1.346     yamt     1085:                vsize = (uintmax_t)vsize * va_pct / 100;
                   1086:                if (t > vsize) {
                   1087:                        t = vsize;
                   1088:                }
1.345     yamt     1089:        }
                   1090:        return t;
                   1091: }
1.385     ad       1092:
                   1093: /*
                   1094:  * Print the system start up banner.
                   1095:  *
                   1096:  * - Print a limited banner if AB_SILENT.
                   1097:  * - Always send normal banner to the log.
                   1098:  */
1.388     tsutsui  1099: #define MEM_PBUFSIZE   sizeof("99999 MB")
                   1100:
1.385     ad       1101: void
                   1102: banner(void)
                   1103: {
                   1104:        static char notice[] = " Notice: this software is "
                   1105:            "protected by copyright";
1.386     ad       1106:        char pbuf[81];
1.446     christos 1107:        void (*pr)(const char *, ...) __printflike(1, 2);
1.385     ad       1108:        int i;
                   1109:
                   1110:        if ((boothowto & AB_SILENT) != 0) {
                   1111:                snprintf(pbuf, sizeof(pbuf), "%s %s (%s)",
                   1112:                    ostype, osrelease, kernel_ident);
1.392     ad       1113:                printf_nolog("%s", pbuf);
1.387     ad       1114:                for (i = 80 - strlen(pbuf) - sizeof(notice); i > 0; i--)
1.385     ad       1115:                        printf(" ");
1.392     ad       1116:                printf_nolog("%s\n", notice);
1.385     ad       1117:                pr = aprint_normal;
                   1118:        } else {
                   1119:                pr = printf;
                   1120:        }
                   1121:
                   1122:        memset(pbuf, 0, sizeof(pbuf));
                   1123:        (*pr)("%s%s", copyright, version);
1.388     tsutsui  1124:        format_bytes(pbuf, MEM_PBUFSIZE, ctob((uint64_t)physmem));
1.385     ad       1125:        (*pr)("total memory = %s\n", pbuf);
1.388     tsutsui  1126:        format_bytes(pbuf, MEM_PBUFSIZE, ctob((uint64_t)uvmexp.free));
1.385     ad       1127:        (*pr)("avail memory = %s\n", pbuf);
                   1128: }

CVSweb <webmaster@jp.NetBSD.org>