[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.437.2.2

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

CVSweb <webmaster@jp.NetBSD.org>