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