Deleted Added
full compact
autoconf.c (52121) autoconf.c (52778)
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * William Jolitz.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * from: @(#)autoconf.c 7.1 (Berkeley) 5/9/91
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * William Jolitz.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * from: @(#)autoconf.c 7.1 (Berkeley) 5/9/91
37 * $FreeBSD: head/sys/i386/i386/autoconf.c 52121 1999-10-11 14:50:03Z peter $
37 * $FreeBSD: head/sys/i386/i386/autoconf.c 52778 1999-11-01 23:51:00Z msmith $
38 */
39
40/*
41 * Setup the system to run on the current machine.
42 *
43 * Configure() is called at boot time and initializes the vba
44 * device tables and the memory controller monitoring. Available
45 * devices are determined (from possibilities mentioned in ioconf.c),

--- 32 unchanged lines hidden (view full) ---

78device_t isa_bus_device = 0;
79
80static void configure_first __P((void *));
81static void configure __P((void *));
82static void configure_final __P((void *));
83
84static void configure_finish __P((void));
85static void configure_start __P((void));
38 */
39
40/*
41 * Setup the system to run on the current machine.
42 *
43 * Configure() is called at boot time and initializes the vba
44 * device tables and the memory controller monitoring. Available
45 * devices are determined (from possibilities mentioned in ioconf.c),

--- 32 unchanged lines hidden (view full) ---

78device_t isa_bus_device = 0;
79
80static void configure_first __P((void *));
81static void configure __P((void *));
82static void configure_final __P((void *));
83
84static void configure_finish __P((void));
85static void configure_start __P((void));
86#if defined(FFS) || defined(FFS_ROOT)
86
87#if defined(FFS) && defined(FFS_ROOT)
87static void setroot __P((void));
88#endif
88static void setroot __P((void));
89#endif
89static int setrootbyname __P((char *name));
90static void gets __P((char *));
91
92SYSINIT(configure1, SI_SUB_CONFIGURE, SI_ORDER_FIRST, configure_first, NULL);
93/* SI_ORDER_SECOND is hookable */
94SYSINIT(configure2, SI_SUB_CONFIGURE, SI_ORDER_THIRD, configure, NULL);
95/* SI_ORDER_MIDDLE is hookable */
96SYSINIT(configure3, SI_SUB_CONFIGURE, SI_ORDER_ANY, configure_final, NULL);
97
98dev_t rootdev = NODEV;
99dev_t dumpdev = NODEV;
100
90
91SYSINIT(configure1, SI_SUB_CONFIGURE, SI_ORDER_FIRST, configure_first, NULL);
92/* SI_ORDER_SECOND is hookable */
93SYSINIT(configure2, SI_SUB_CONFIGURE, SI_ORDER_THIRD, configure, NULL);
94/* SI_ORDER_MIDDLE is hookable */
95SYSINIT(configure3, SI_SUB_CONFIGURE, SI_ORDER_ANY, configure_final, NULL);
96
97dev_t rootdev = NODEV;
98dev_t dumpdev = NODEV;
99
101#if defined(CD9660) || defined(CD9660_ROOT)
102
103#include <sys/fcntl.h>
104#include <sys/proc.h>
105#include <sys/stat.h>
106#include <machine/clock.h>
107
108/*
109 * XXX All this CD-ROM root stuff is fairly messy. Ick.
110 *
111 * We need to try out all our potential CDROM drives, so we need a table.
112 */
113static struct {
114 char *name;
115 int major;
116} try_cdrom[] = {
117 { "cd", 6 },
118 { "mcd", 7 },
119 { "scd", 16 },
120 { "matcd", 17 },
121 { "wcd", 19 },
122 { 0, 0}
123};
124
125static int find_cdrom_root __P((void));
126
127static int
128find_cdrom_root()
129{
130 int i, j, error;
131 struct cdevsw *bd;
132 dev_t orootdev;
133
134#if CD9660_ROOTDELAY > 0
135 DELAY(CD9660_ROOTDELAY * 1000000);
136#endif
137 orootdev = rootdev;
138 for (i = 0 ; i < 2; i++)
139 for (j = 0 ; try_cdrom[j].name ; j++) {
140 if (try_cdrom[j].major >= NUMCDEVSW)
141 continue;
142 rootdev = makebdev(try_cdrom[j].major, i * 8);
143 bd = devsw(rootdev);
144 if (bd == NULL || bd->d_open == NULL)
145 continue;
146 if (bootverbose)
147 printf("trying %s%d as rootdev (%p)\n",
148 try_cdrom[j].name, i, (void *)rootdev);
149 error = (bd->d_open)(rootdev, FREAD, S_IFBLK, curproc);
150 if (error == 0) {
151 if (bd->d_close != NULL)
152 (bd->d_close)(rootdev, FREAD, S_IFBLK,
153 curproc);
154 return 0;
155 }
156 }
157
158 rootdev = orootdev;
159 return EINVAL;
160}
161#endif /* CD9660 || CD9660_ROOT */
162
163static void
164configure_start()
165{
166}
167
168static void
169configure_finish()
170{
171}
172
173device_t nexus_dev;
174
175/*
176 * Determine i/o configuration for a machine.
177 */
178static void
179configure_first(dummy)
180 void *dummy;
181{
100device_t nexus_dev;
101
102/*
103 * Determine i/o configuration for a machine.
104 */
105static void
106configure_first(dummy)
107 void *dummy;
108{
182
183 configure_start(); /* DDB hook? */
184}
185
186static void
187configure(dummy)
188 void *dummy;
189{
190
191 /*

--- 51 unchanged lines hidden (view full) ---

243}
244
245static void
246configure_final(dummy)
247 void *dummy;
248{
249 int i;
250
109}
110
111static void
112configure(dummy)
113 void *dummy;
114{
115
116 /*

--- 51 unchanged lines hidden (view full) ---

168}
169
170static void
171configure_final(dummy)
172 void *dummy;
173{
174 int i;
175
251 configure_finish(); /* DDB hook? */
252
253 cninit_finish();
254
255 if (bootverbose) {
256
257#ifdef APIC_IO
258 imen_dump();
259#endif /* APIC_IO */
260

--- 27 unchanged lines hidden (view full) ---

288 }
289 printf(" %d accounted for\n", bootinfo.bi_n_bios_used);
290
291 printf("Device configuration finished.\n");
292 }
293 cold = 0;
294}
295
176 cninit_finish();
177
178 if (bootverbose) {
179
180#ifdef APIC_IO
181 imen_dump();
182#endif /* APIC_IO */
183

--- 27 unchanged lines hidden (view full) ---

211 }
212 printf(" %d accounted for\n", bootinfo.bi_n_bios_used);
213
214 printf("Device configuration finished.\n");
215 }
216 cold = 0;
217}
218
296
219/*
220 * Do legacy root filesystem discovery.
221 */
297void
298cpu_rootconf()
299{
222void
223cpu_rootconf()
224{
300 /*
301 * XXX NetBSD has a much cleaner approach to finding root.
302 * XXX We should adopt their code.
303 */
304#if defined(CD9660) || defined(CD9660_ROOT)
305 if ((boothowto & RB_CDROM)) {
306 if (bootverbose)
307 printf("Considering CD-ROM root f/s.\n");
308 /* NB: find_cdrom_root() sets rootdev if successful. */
309 if (find_cdrom_root() == 0)
310 mountrootfsname = "cd9660";
311 else if (bootverbose)
312 printf("No CD-ROM available as root f/s.\n");
313 }
225#if defined(NFS) && defined(NFS_ROOT)
226#if !defined(BOOTP_NFSROOT)
227 if (nfs_diskless_valid)
314#endif
228#endif
315
316#ifdef BOOTP_NFSROOT
317 if (!mountrootfsname && !nfs_diskless_valid) {
318 if (bootverbose)
319 printf("Considering BOOTP NFS root f/s.\n");
320 mountrootfsname = "nfs";
321 }
322#endif /* BOOTP_NFSROOT */
323#if defined(NFS) || defined(NFS_ROOT)
324 if (!mountrootfsname && nfs_diskless_valid) {
325 if (bootverbose)
326 printf("Considering NFS root f/s.\n");
327 mountrootfsname = "nfs";
328 }
329#endif /* NFS */
330
331#if defined(FFS) || defined(FFS_ROOT)
332 if (!mountrootfsname) {
333 mountrootfsname = "ufs";
334 if (bootverbose)
335 printf("Considering FFS root f/s.\n");
336 if (boothowto & RB_ASKNAME)
337 setconf();
338 else
339 setroot();
340 }
229 rootdevnames[0] = "nfs:";
341#endif
230#endif
342
343 if (!mountrootfsname) {
344 panic("Nobody wants to mount my root for me");
345 }
231#if defined(FFS) && defined(FFS_ROOT)
232 setroot();
233#endif
346}
234}
235SYSINIT(cpu_rootconf, SI_SUB_ROOT_CONF, SI_ORDER_FIRST, cpu_rootconf, NULL)
347
348u_long bootdev = 0; /* not a dev_t - encoding is different */
349
236
237u_long bootdev = 0; /* not a dev_t - encoding is different */
238
350#define FDMAJOR 2
239#if defined(FFS) && defined(FFS_ROOT)
240#define FDMAJOR 2
351#define FDUNITSHIFT 6
352
241#define FDUNITSHIFT 6
242
353#if defined(FFS) || defined(FFS_ROOT)
354/*
355 * Attempt to find the device from which we were booted.
356 * If we can do so, and not instructed not to do so,
357 * set rootdevs[] and rootdevnames[] to correspond to the
358 * boot device(s).
243/*
244 * Attempt to find the device from which we were booted.
245 * If we can do so, and not instructed not to do so,
246 * set rootdevs[] and rootdevnames[] to correspond to the
247 * boot device(s).
248 *
249 * This code survives in order to allow the system to be
250 * booted from legacy environments that do not correctly
251 * populate the kernel environment. There are significant
252 * restrictions on the bootability of the system in this
253 * situation; it can only be mounting root from a 'da'
254 * 'wd' or 'fd' device, and the root filesystem must be ufs.
359 */
360static void
361setroot()
362{
363 int majdev, mindev, unit, slice, part;
364 dev_t newrootdev, dev;
365 char partname[2];
366 char *sname;
367
255 */
256static void
257setroot()
258{
259 int majdev, mindev, unit, slice, part;
260 dev_t newrootdev, dev;
261 char partname[2];
262 char *sname;
263
368 if (boothowto & RB_DFLTROOT) {
369#ifdef ROOTDEVNAME
370 setrootbyname(ROOTDEVNAME);
371#else
372 setconf();
373#endif
374 return;
375 }
376 if ((bootdev & B_MAGICMASK) != B_DEVMAGIC) {
377 printf("no B_DEVMAGIC (bootdev=%#lx)\n", bootdev);
264 if ((bootdev & B_MAGICMASK) != B_DEVMAGIC) {
265 printf("no B_DEVMAGIC (bootdev=%#lx)\n", bootdev);
378 setconf();
379 return;
380 }
381 majdev = B_TYPE(bootdev);
382 dev = makebdev(majdev, 0);
383 if (devsw(dev) == NULL) {
384 printf("no devsw (majdev=%d bootdev=%#lx)\n", majdev, bootdev);
266 return;
267 }
268 majdev = B_TYPE(bootdev);
269 dev = makebdev(majdev, 0);
270 if (devsw(dev) == NULL) {
271 printf("no devsw (majdev=%d bootdev=%#lx)\n", majdev, bootdev);
385 setconf();
386 return;
387 }
388 unit = B_UNIT(bootdev);
389 slice = B_SLICE(bootdev);
390 if (slice == WHOLE_DISK_SLICE)
391 slice = COMPATIBILITY_SLICE;
392 if (slice < 0 || slice >= MAX_SLICES) {
393 printf("bad slice\n");
272 return;
273 }
274 unit = B_UNIT(bootdev);
275 slice = B_SLICE(bootdev);
276 if (slice == WHOLE_DISK_SLICE)
277 slice = COMPATIBILITY_SLICE;
278 if (slice < 0 || slice >= MAX_SLICES) {
279 printf("bad slice\n");
394 setconf();
395 return;
396 }
397
398 /*
399 * XXX kludge for inconsistent unit numbering and lack of slice
400 * support for floppies.
401 */
402 if (majdev == FDMAJOR) {
403 slice = COMPATIBILITY_SLICE;
404 part = RAW_PART;
405 mindev = unit << FDUNITSHIFT;
406 } else {
407 part = B_PARTITION(bootdev);
408 mindev = dkmakeminor(unit, slice, part);
409 }
410
411 newrootdev = makebdev(majdev, mindev);
280 return;
281 }
282
283 /*
284 * XXX kludge for inconsistent unit numbering and lack of slice
285 * support for floppies.
286 */
287 if (majdev == FDMAJOR) {
288 slice = COMPATIBILITY_SLICE;
289 part = RAW_PART;
290 mindev = unit << FDUNITSHIFT;
291 } else {
292 part = B_PARTITION(bootdev);
293 mindev = dkmakeminor(unit, slice, part);
294 }
295
296 newrootdev = makebdev(majdev, mindev);
412 rootdevs[0] = newrootdev;
413 sname = dsname(newrootdev, unit, slice, part, partname);
297 sname = dsname(newrootdev, unit, slice, part, partname);
414 rootdevnames[0] = malloc(strlen(sname) + 2, M_DEVBUF, M_NOWAIT);
415 sprintf(rootdevnames[0], "%s%s", sname, partname);
298 rootdevnames[0] = malloc(strlen(sname) + 6, M_DEVBUF, M_NOWAIT);
299 sprintf(rootdevnames[0], "ufs:%s%s", sname, partname);
416
417 /*
418 * For properly dangerously dedicated disks (ones with a historical
419 * bogus partition table), the boot blocks will give slice = 4, but
420 * the kernel will only provide the compatibility slice since it
421 * knows that slice 4 is not a real slice. Arrange to try mounting
422 * the compatibility slice as root if mounting the slice passed by
423 * the boot blocks fails. This handles the dangerously dedicated
424 * case and perhaps others.
425 */
426 if (slice == COMPATIBILITY_SLICE)
427 return;
428 slice = COMPATIBILITY_SLICE;
300
301 /*
302 * For properly dangerously dedicated disks (ones with a historical
303 * bogus partition table), the boot blocks will give slice = 4, but
304 * the kernel will only provide the compatibility slice since it
305 * knows that slice 4 is not a real slice. Arrange to try mounting
306 * the compatibility slice as root if mounting the slice passed by
307 * the boot blocks fails. This handles the dangerously dedicated
308 * case and perhaps others.
309 */
310 if (slice == COMPATIBILITY_SLICE)
311 return;
312 slice = COMPATIBILITY_SLICE;
429 rootdevs[1] = dkmodslice(newrootdev, slice);
430 sname = dsname(newrootdev, unit, slice, part, partname);
313 sname = dsname(newrootdev, unit, slice, part, partname);
431 rootdevnames[1] = malloc(strlen(sname) + 2, M_DEVBUF, M_NOWAIT);
432 sprintf(rootdevnames[1], "%s%s", sname, partname);
314 rootdevnames[1] = malloc(strlen(sname) + 6, M_DEVBUF, M_NOWAIT);
315 sprintf(rootdevnames[1], "ufs:%s%s", sname, partname);
433}
434#endif
316}
317#endif
435
436
437
438static int
439setrootbyname(char *name)
440{
441 char *cp;
442 int bd, unit, slice, part;
443 dev_t dev;
444
445 printf("setrootbyname(\"%s\")\n", name);
446 slice = 0;
447 part = 0;
448 cp = name;
449 while (cp != '\0' && (*cp < '0' || *cp > '9'))
450 cp++;
451 if (cp == name) {
452 printf("missing device name\n");
453 return(1);
454 }
455 if (*cp == '\0') {
456 printf("missing unit number\n");
457 return(1);
458 }
459 unit = *cp - '0';
460 *cp++ = '\0';
461 for (bd = 0; bd < NUMCDEVSW; bd++) {
462 dev = makebdev(bd, 0);
463 if (devsw(dev) != NULL &&
464 strcmp(devsw(dev)->d_name, name) == 0)
465 goto gotit;
466 }
467 return (2);
468gotit:
469 while (*cp >= '0' && *cp <= '9')
470 unit += 10 * unit + *cp++ - '0';
471 if (*cp == 's' && cp[1] >= '0' && cp[1] <= '9') {
472 slice = cp[1] - '0' + 1;
473 cp += 2;
474 }
475 if (*cp >= 'a' && *cp <= 'h') {
476 part = *cp - 'a';
477 cp++;
478 }
479 if (*cp != '\0') {
480 printf("junk after name\n");
481 return (1);
482 }
483 rootdev = makebdev(bd, dkmakeminor(unit, slice, part));
484 printf("driver=%s, unit=%d, slice=%d, part=%d -> rootdev=%p\n",
485 name, unit, slice, part, (void *)rootdev);
486 return 0;
487}
488
489void
490setconf()
491{
492 char name[128];
493 int i;
494 dev_t dev;
495
496 for(;;) {
497 printf("root device? ");
498 gets(name);
499 i = setrootbyname(name);
500 if (!i)
501 return;
502
503 printf("use one of:\n");
504 for (i = 0; i < NUMCDEVSW; i++) {
505 dev = makebdev(i, 0);
506 if (devsw(dev) != NULL)
507 printf(" \"%s\"", devsw(dev)->d_name);
508 }
509 printf("\nfollowed by a unit number...\n");
510 }
511}
512
513static void
514gets(cp)
515 char *cp;
516{
517 register char *lp;
518 register int c;
519
520 lp = cp;
521 for (;;) {
522 printf("%c", c = cngetc() & 0177);
523 switch (c) {
524 case -1:
525 case '\n':
526 case '\r':
527 *lp++ = '\0';
528 return;
529 case '\b':
530 case '\177':
531 if (lp > cp) {
532 printf(" \b");
533 lp--;
534 }
535 continue;
536 case '#':
537 lp--;
538 if (lp < cp)
539 lp = cp;
540 continue;
541 case '@':
542 case 'u' & 037:
543 lp = cp;
544 printf("%c", '\n');
545 continue;
546 default:
547 *lp++ = c;
548 }
549 }
550}