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

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

CVSweb <webmaster@jp.NetBSD.org>