init_main.c (77183) | init_main.c (78161) |
---|---|
1/* 2 * Copyright (c) 1995 Terrence R. Lambert 3 * All rights reserved. 4 * 5 * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993 6 * The Regents of the University of California. All rights reserved. 7 * (c) UNIX System Laboratories, Inc. 8 * All or some portions of this file are derived from material licensed --- 25 unchanged lines hidden (view full) --- 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 * SUCH DAMAGE. 40 * 41 * @(#)init_main.c 8.9 (Berkeley) 1/21/94 | 1/* 2 * Copyright (c) 1995 Terrence R. Lambert 3 * All rights reserved. 4 * 5 * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993 6 * The Regents of the University of California. All rights reserved. 7 * (c) UNIX System Laboratories, Inc. 8 * All or some portions of this file are derived from material licensed --- 25 unchanged lines hidden (view full) --- 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 * SUCH DAMAGE. 40 * 41 * @(#)init_main.c 8.9 (Berkeley) 1/21/94 |
42 * $FreeBSD: head/sys/kern/init_main.c 77183 2001-05-25 16:59:11Z rwatson $ | 42 * $FreeBSD: head/sys/kern/init_main.c 78161 2001-06-13 10:58:39Z peter $ |
43 */ 44 45#include "opt_init_path.h" 46 47#include <sys/param.h> 48#include <sys/file.h> 49#include <sys/filedesc.h> 50#include <sys/kernel.h> --- 21 unchanged lines hidden (view full) --- 72 73#include <vm/vm.h> 74#include <vm/vm_param.h> 75#include <vm/pmap.h> 76#include <vm/vm_map.h> 77#include <sys/user.h> 78#include <sys/copyright.h> 79 | 43 */ 44 45#include "opt_init_path.h" 46 47#include <sys/param.h> 48#include <sys/file.h> 49#include <sys/filedesc.h> 50#include <sys/kernel.h> --- 21 unchanged lines hidden (view full) --- 72 73#include <vm/vm.h> 74#include <vm/vm_param.h> 75#include <vm/pmap.h> 76#include <vm/vm_map.h> 77#include <sys/user.h> 78#include <sys/copyright.h> 79 |
80extern struct linker_set sysinit_set; /* XXX */ 81 | |
82void mi_startup(void); /* Should be elsewhere */ 83 84/* Components of the first process -- never freed. */ 85static struct session session0; 86static struct pgrp pgrp0; 87struct proc proc0; 88static struct procsig procsig0; 89static struct filedesc0 filedesc0; --- 17 unchanged lines hidden (view full) --- 107 * executed. 108 */ 109SYSINIT(placeholder, SI_SUB_DUMMY, SI_ORDER_ANY, NULL, NULL) 110 111/* 112 * The sysinit table itself. Items are checked off as the are run. 113 * If we want to register new sysinit types, add them to newsysinit. 114 */ | 80void mi_startup(void); /* Should be elsewhere */ 81 82/* Components of the first process -- never freed. */ 83static struct session session0; 84static struct pgrp pgrp0; 85struct proc proc0; 86static struct procsig procsig0; 87static struct filedesc0 filedesc0; --- 17 unchanged lines hidden (view full) --- 105 * executed. 106 */ 107SYSINIT(placeholder, SI_SUB_DUMMY, SI_ORDER_ANY, NULL, NULL) 108 109/* 110 * The sysinit table itself. Items are checked off as the are run. 111 * If we want to register new sysinit types, add them to newsysinit. 112 */ |
115struct sysinit **sysinit = (struct sysinit **)sysinit_set.ls_items; 116struct sysinit **newsysinit; | 113SET_DECLARE(sysinit_set, struct sysinit); 114struct sysinit **sysinit, **sysinit_end; 115struct sysinit **newsysinit, **newsysinit_end; |
117 118/* 119 * Merge a new sysinit set into the current set, reallocating it if 120 * necessary. This can only be called after malloc is running. 121 */ 122void | 116 117/* 118 * Merge a new sysinit set into the current set, reallocating it if 119 * necessary. This can only be called after malloc is running. 120 */ 121void |
123sysinit_add(struct sysinit **set) | 122sysinit_add(struct sysinit **set, struct sysinit **set_end) |
124{ 125 struct sysinit **newset; 126 struct sysinit **sipp; 127 struct sysinit **xipp; | 123{ 124 struct sysinit **newset; 125 struct sysinit **sipp; 126 struct sysinit **xipp; |
128 int count = 0; | 127 int count; |
129 | 128 |
129 count = set_end - set; |
|
130 if (newsysinit) | 130 if (newsysinit) |
131 for (sipp = newsysinit; *sipp; sipp++) 132 count++; | 131 count += newsysinit_end - newsysinit; |
133 else | 132 else |
134 for (sipp = sysinit; *sipp; sipp++) 135 count++; 136 for (sipp = set; *sipp; sipp++) 137 count++; 138 count++; /* Trailing NULL */ | 133 count += sysinit_end - sysinit; |
139 newset = malloc(count * sizeof(*sipp), M_TEMP, M_NOWAIT); 140 if (newset == NULL) 141 panic("cannot malloc for sysinit"); 142 xipp = newset; 143 if (newsysinit) | 134 newset = malloc(count * sizeof(*sipp), M_TEMP, M_NOWAIT); 135 if (newset == NULL) 136 panic("cannot malloc for sysinit"); 137 xipp = newset; 138 if (newsysinit) |
144 for (sipp = newsysinit; *sipp; sipp++) | 139 for (sipp = newsysinit; sipp < newsysinit_end; sipp++) |
145 *xipp++ = *sipp; 146 else | 140 *xipp++ = *sipp; 141 else |
147 for (sipp = sysinit; *sipp; sipp++) | 142 for (sipp = sysinit; sipp < sysinit_end; sipp++) |
148 *xipp++ = *sipp; | 143 *xipp++ = *sipp; |
149 for (sipp = set; *sipp; sipp++) | 144 for (sipp = set; sipp < set_end; sipp++) |
150 *xipp++ = *sipp; | 145 *xipp++ = *sipp; |
151 *xipp = NULL; | |
152 if (newsysinit) 153 free(newsysinit, M_TEMP); 154 newsysinit = newset; | 146 if (newsysinit) 147 free(newsysinit, M_TEMP); 148 newsysinit = newset; |
149 newsysinit_end = newset + count; |
|
155} 156 157/* 158 * System startup; initialize the world, create process 0, mount root 159 * filesystem, and fork to create init and pagedaemon. Most of the 160 * hard work is done in the lower-level initialization routines including 161 * startup(), which does memory initialization and autoconfiguration. 162 * --- 5 unchanged lines hidden (view full) --- 168void 169mi_startup(void) 170{ 171 172 register struct sysinit **sipp; /* system initialization*/ 173 register struct sysinit **xipp; /* interior loop of sort*/ 174 register struct sysinit *save; /* bubble*/ 175 | 150} 151 152/* 153 * System startup; initialize the world, create process 0, mount root 154 * filesystem, and fork to create init and pagedaemon. Most of the 155 * hard work is done in the lower-level initialization routines including 156 * startup(), which does memory initialization and autoconfiguration. 157 * --- 5 unchanged lines hidden (view full) --- 163void 164mi_startup(void) 165{ 166 167 register struct sysinit **sipp; /* system initialization*/ 168 register struct sysinit **xipp; /* interior loop of sort*/ 169 register struct sysinit *save; /* bubble*/ 170 |
171 if (sysinit == NULL) { 172 sysinit = SET_BEGIN(sysinit_set); 173 sysinit_end = SET_LIMIT(sysinit_set); 174 } 175 |
|
176restart: 177 /* 178 * Perform a bubble sort of the system initialization objects by 179 * their subsystem (primary key) and order (secondary key). 180 */ | 176restart: 177 /* 178 * Perform a bubble sort of the system initialization objects by 179 * their subsystem (primary key) and order (secondary key). 180 */ |
181 for (sipp = sysinit; *sipp; sipp++) { 182 for (xipp = sipp + 1; *xipp; xipp++) { | 181 for (sipp = sysinit; sipp < sysinit_end; sipp++) { 182 for (xipp = sipp + 1; xipp < sysinit_end; xipp++) { |
183 if ((*sipp)->subsystem < (*xipp)->subsystem || 184 ((*sipp)->subsystem == (*xipp)->subsystem && 185 (*sipp)->order <= (*xipp)->order)) 186 continue; /* skip*/ 187 save = *sipp; 188 *sipp = *xipp; 189 *xipp = save; 190 } 191 } 192 193 /* 194 * Traverse the (now) ordered list of system initialization tasks. 195 * Perform each task, and continue on to the next task. 196 * 197 * The last item on the list is expected to be the scheduler, 198 * which will not return. 199 */ | 183 if ((*sipp)->subsystem < (*xipp)->subsystem || 184 ((*sipp)->subsystem == (*xipp)->subsystem && 185 (*sipp)->order <= (*xipp)->order)) 186 continue; /* skip*/ 187 save = *sipp; 188 *sipp = *xipp; 189 *xipp = save; 190 } 191 } 192 193 /* 194 * Traverse the (now) ordered list of system initialization tasks. 195 * Perform each task, and continue on to the next task. 196 * 197 * The last item on the list is expected to be the scheduler, 198 * which will not return. 199 */ |
200 for (sipp = sysinit; *sipp; sipp++) { | 200 for (sipp = sysinit; sipp < sysinit_end; sipp++) { |
201 202 if ((*sipp)->subsystem == SI_SUB_DUMMY) 203 continue; /* skip dummy task(s)*/ 204 205 if ((*sipp)->subsystem == SI_SUB_DONE) 206 continue; 207 208 /* Call function */ 209 (*((*sipp)->func))((*sipp)->udata); 210 211 /* Check off the one we're just done */ 212 (*sipp)->subsystem = SI_SUB_DONE; 213 214 /* Check if we've installed more sysinit items via KLD */ 215 if (newsysinit != NULL) { | 201 202 if ((*sipp)->subsystem == SI_SUB_DUMMY) 203 continue; /* skip dummy task(s)*/ 204 205 if ((*sipp)->subsystem == SI_SUB_DONE) 206 continue; 207 208 /* Call function */ 209 (*((*sipp)->func))((*sipp)->udata); 210 211 /* Check off the one we're just done */ 212 (*sipp)->subsystem = SI_SUB_DONE; 213 214 /* Check if we've installed more sysinit items via KLD */ 215 if (newsysinit != NULL) { |
216 if (sysinit != (struct sysinit **)sysinit_set.ls_items) | 216 if (sysinit != SET_BEGIN(sysinit_set)) |
217 free(sysinit, M_TEMP); 218 sysinit = newsysinit; | 217 free(sysinit, M_TEMP); 218 sysinit = newsysinit; |
219 sysinit_end = newsysinit_end; |
|
219 newsysinit = NULL; | 220 newsysinit = NULL; |
221 newsysinit_end = NULL; |
|
220 goto restart; 221 } 222 } 223 224 panic("Shouldn't get here!"); 225 /* NOTREACHED*/ 226} 227 --- 396 unchanged lines hidden --- | 222 goto restart; 223 } 224 } 225 226 panic("Shouldn't get here!"); 227 /* NOTREACHED*/ 228} 229 --- 396 unchanged lines hidden --- |