Tue Jan 28 16:35:39 2020 UTC ()
Call radix_tree_init() earlier, so more stuff can make use of radixtree.


(ad)
diff -r1.518 -r1.519 src/sys/kern/init_main.c

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

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