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