Sat Oct 17 13:52:52 2015 UTC ()
initialize MODULE_CLASS_DRIVER modules before the drivers themselves are loaded during autoconfiguration


(jmcneill)
diff -r1.470 -r1.471 src/sys/kern/init_main.c

cvs diff -r1.470 -r1.471 src/sys/kern/init_main.c (switch to unified diff)

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