Home | History | Annotate | Line # | Download | only in alpha
autoconf.c revision 1.16
      1  1.16       cgd /*	$NetBSD: autoconf.c,v 1.16 1996/11/13 21:13:04 cgd Exp $	*/
      2   1.1       cgd 
      3   1.1       cgd /*
      4   1.4       cgd  * Copyright (c) 1992, 1993
      5   1.4       cgd  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.4       cgd  * This software was developed by the Computer Systems Engineering group
      8   1.4       cgd  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9   1.4       cgd  * contributed to Berkeley.
     10   1.1       cgd  *
     11   1.4       cgd  * All advertising materials mentioning features or use of this software
     12   1.4       cgd  * must display the following acknowledgement:
     13   1.4       cgd  *	This product includes software developed by the University of
     14   1.4       cgd  *	California, Lawrence Berkeley Laboratory.
     15   1.4       cgd  *
     16   1.4       cgd  * Redistribution and use in source and binary forms, with or without
     17   1.4       cgd  * modification, are permitted provided that the following conditions
     18   1.4       cgd  * are met:
     19   1.4       cgd  * 1. Redistributions of source code must retain the above copyright
     20   1.4       cgd  *    notice, this list of conditions and the following disclaimer.
     21   1.4       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     22   1.4       cgd  *    notice, this list of conditions and the following disclaimer in the
     23   1.4       cgd  *    documentation and/or other materials provided with the distribution.
     24   1.4       cgd  * 3. All advertising materials mentioning features or use of this software
     25   1.4       cgd  *    must display the following acknowledgement:
     26   1.4       cgd  *	This product includes software developed by the University of
     27   1.4       cgd  *	California, Berkeley and its contributors.
     28   1.4       cgd  * 4. Neither the name of the University nor the names of its contributors
     29   1.4       cgd  *    may be used to endorse or promote products derived from this software
     30   1.4       cgd  *    without specific prior written permission.
     31   1.4       cgd  *
     32   1.4       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33   1.4       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34   1.4       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35   1.4       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36   1.4       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37   1.4       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38   1.4       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39   1.4       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40   1.4       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41   1.4       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42   1.4       cgd  * SUCH DAMAGE.
     43   1.4       cgd  *
     44   1.4       cgd  *	@(#)autoconf.c	8.4 (Berkeley) 10/1/93
     45   1.1       cgd  */
     46   1.1       cgd 
     47   1.1       cgd #include <sys/param.h>
     48   1.1       cgd #include <sys/systm.h>
     49   1.1       cgd #include <sys/buf.h>
     50   1.1       cgd #include <sys/disklabel.h>
     51   1.1       cgd #include <sys/conf.h>
     52   1.1       cgd #include <sys/reboot.h>
     53   1.1       cgd #include <sys/device.h>
     54  1.16       cgd #include <dev/cons.h>
     55   1.1       cgd 
     56   1.1       cgd #include <machine/autoconf.h>
     57   1.5       cgd #include <machine/prom.h>
     58  1.15       cgd #include <machine/cpuconf.h>
     59   1.5       cgd 
     60   1.7       cgd extern char		root_device[17];		/* XXX */
     61   1.7       cgd 
     62   1.5       cgd struct device		*booted_device;
     63   1.5       cgd int			booted_partition;
     64   1.5       cgd struct bootdev_data	*bootdev_data;
     65   1.5       cgd char			boot_dev[128];
     66   1.5       cgd 
     67   1.5       cgd void	parse_prom_bootdev __P((void));
     68   1.5       cgd int	atoi __P((char *));
     69   1.1       cgd 
     70  1.11       cgd static struct device *parsedisk __P((char *str, int len, int defpart,
     71  1.11       cgd 				     dev_t *devp));
     72   1.4       cgd static struct device *getdisk __P((char *str, int len, int defpart,
     73   1.4       cgd 				   dev_t *devp));
     74   1.4       cgd static int findblkmajor __P((struct device *dv));
     75   1.7       cgd static char *findblkname __P((int));
     76   1.4       cgd static int getstr __P((char *cp, int size));
     77   1.4       cgd 
     78  1.16       cgd void	setroot __P((void));
     79  1.16       cgd void	swapconf __P((void));
     80  1.16       cgd 
     81   1.1       cgd /*
     82   1.1       cgd  * configure:
     83   1.1       cgd  * called at boot time, configure all devices on system
     84   1.1       cgd  */
     85   1.1       cgd void
     86   1.1       cgd configure()
     87   1.1       cgd {
     88   1.1       cgd 
     89   1.5       cgd 	parse_prom_bootdev();
     90   1.5       cgd 
     91   1.1       cgd 	(void)splhigh();
     92   1.2       cgd 	if (config_rootfound("mainbus", "mainbus") == NULL)
     93   1.1       cgd 		panic("no mainbus found");
     94   1.1       cgd 	(void)spl0();
     95   1.1       cgd 
     96   1.5       cgd 	if (booted_device == NULL)
     97  1.14  christos 		printf("WARNING: can't figure what device matches \"%s\"\n",
     98   1.5       cgd 		    boot_dev);
     99   1.1       cgd 	setroot();
    100   1.1       cgd 	swapconf();
    101   1.1       cgd 	cold = 0;
    102   1.1       cgd }
    103   1.1       cgd 
    104   1.1       cgd /*
    105   1.1       cgd  * Configure swap space and related parameters.
    106   1.1       cgd  */
    107  1.16       cgd void
    108   1.1       cgd swapconf()
    109   1.1       cgd {
    110   1.4       cgd 	struct swdevt *swp;
    111   1.4       cgd 	int nblks, maj;
    112   1.1       cgd 
    113   1.1       cgd 	for (swp = swdevt; swp->sw_dev != NODEV; swp++) {
    114   1.4       cgd 		maj = major(swp->sw_dev);
    115   1.1       cgd 		if (maj > nblkdev)
    116   1.1       cgd 			break;
    117   1.1       cgd 		if (bdevsw[maj].d_psize) {
    118   1.1       cgd 			nblks = (*bdevsw[maj].d_psize)(swp->sw_dev);
    119   1.1       cgd 			if (nblks != -1 &&
    120   1.1       cgd 			    (swp->sw_nblks == 0 || swp->sw_nblks > nblks))
    121   1.1       cgd 				swp->sw_nblks = nblks;
    122   1.1       cgd 			swp->sw_nblks = ctod(dtoc(swp->sw_nblks));
    123   1.1       cgd 		}
    124   1.1       cgd 	}
    125   1.4       cgd 	dumpconf();
    126   1.1       cgd }
    127   1.1       cgd 
    128   1.4       cgd struct nam2blk {
    129   1.4       cgd 	char *name;
    130   1.4       cgd 	int maj;
    131   1.4       cgd } nam2blk[] = {
    132   1.4       cgd 	{ "st",		2 },
    133   1.4       cgd 	{ "cd",		3 },
    134  1.11       cgd 	{ "rd",		6 },
    135   1.4       cgd 	{ "sd",		8 },
    136   1.4       cgd #if 0
    137   1.4       cgd 	{ "fd",		XXX },
    138   1.4       cgd #endif
    139   1.4       cgd };
    140   1.4       cgd 
    141  1.12       cgd #ifdef RAMDISK_HOOKS
    142  1.12       cgd static struct device fakerdrootdev = { DV_DISK, {}, NULL, 0, "rd0", NULL };
    143  1.12       cgd #endif
    144  1.12       cgd 
    145   1.4       cgd static int
    146   1.4       cgd findblkmajor(dv)
    147   1.4       cgd 	struct device *dv;
    148   1.4       cgd {
    149   1.4       cgd 	char *name = dv->dv_xname;
    150   1.4       cgd 	register int i;
    151   1.4       cgd 
    152   1.4       cgd 	for (i = 0; i < sizeof(nam2blk)/sizeof(nam2blk[0]); ++i)
    153   1.4       cgd 		if (strncmp(name, nam2blk[i].name, strlen(nam2blk[0].name))
    154   1.4       cgd 		    == 0)
    155   1.4       cgd 			return (nam2blk[i].maj);
    156   1.4       cgd 	return (-1);
    157   1.4       cgd }
    158   1.4       cgd 
    159   1.7       cgd static char *
    160   1.7       cgd findblkname(maj)
    161   1.7       cgd 	int maj;
    162   1.7       cgd {
    163   1.7       cgd 	register int i;
    164   1.7       cgd 
    165   1.7       cgd 	for (i = 0; i < sizeof(nam2blk)/sizeof(nam2blk[0]); ++i)
    166   1.7       cgd 		if (maj == nam2blk[i].maj)
    167   1.7       cgd 			return (nam2blk[i].name);
    168   1.7       cgd 	return (NULL);
    169   1.7       cgd }
    170   1.7       cgd 
    171   1.4       cgd static struct device *
    172   1.4       cgd getdisk(str, len, defpart, devp)
    173   1.4       cgd 	char *str;
    174   1.4       cgd 	int len, defpart;
    175   1.4       cgd 	dev_t *devp;
    176   1.4       cgd {
    177   1.4       cgd 	register struct device *dv;
    178   1.1       cgd 
    179   1.4       cgd 	if ((dv = parsedisk(str, len, defpart, devp)) == NULL) {
    180  1.14  christos 		printf("use one of:");
    181  1.12       cgd #ifdef RAMDISK_HOOKS
    182  1.14  christos 		printf(" %s[a-h]", fakerdrootdev.dv_xname);
    183  1.12       cgd #endif
    184   1.4       cgd 		for (dv = alldevs.tqh_first; dv != NULL;
    185   1.4       cgd 		    dv = dv->dv_list.tqe_next) {
    186   1.4       cgd 			if (dv->dv_class == DV_DISK)
    187  1.14  christos 				printf(" %s[a-h]", dv->dv_xname);
    188   1.4       cgd #ifdef NFSCLIENT
    189   1.4       cgd 			if (dv->dv_class == DV_IFNET)
    190  1.14  christos 				printf(" %s", dv->dv_xname);
    191   1.4       cgd #endif
    192   1.4       cgd 		}
    193  1.14  christos 		printf(" halt\n");
    194   1.4       cgd 	}
    195   1.4       cgd 	return (dv);
    196   1.4       cgd }
    197   1.4       cgd 
    198  1.11       cgd static struct device *
    199   1.4       cgd parsedisk(str, len, defpart, devp)
    200   1.4       cgd 	char *str;
    201   1.4       cgd 	int len, defpart;
    202   1.4       cgd 	dev_t *devp;
    203   1.4       cgd {
    204   1.4       cgd 	register struct device *dv;
    205   1.4       cgd 	register char *cp, c;
    206   1.4       cgd 	int majdev, part;
    207   1.4       cgd 
    208   1.4       cgd 	if (len == 0)
    209   1.4       cgd 		return (NULL);
    210  1.11       cgd 
    211  1.11       cgd 	if (len == 4 && !strcmp(str, "halt"))
    212  1.11       cgd 		boot(RB_HALT, NULL);
    213  1.11       cgd 
    214   1.4       cgd 	cp = str + len - 1;
    215   1.4       cgd 	c = *cp;
    216   1.4       cgd 	if (c >= 'a' && c <= ('a' + MAXPARTITIONS - 1)) {
    217   1.4       cgd 		part = c - 'a';
    218   1.4       cgd 		*cp = '\0';
    219   1.4       cgd 	} else
    220   1.4       cgd 		part = defpart;
    221   1.4       cgd 
    222  1.12       cgd #ifdef RAMDISK_HOOKS
    223  1.12       cgd 	if (strcmp(str, fakerdrootdev.dv_xname) == 0) {
    224  1.12       cgd 		dv = &fakerdrootdev;
    225  1.12       cgd 		goto gotdisk;
    226  1.12       cgd 	}
    227  1.12       cgd #endif
    228   1.4       cgd 	for (dv = alldevs.tqh_first; dv != NULL; dv = dv->dv_list.tqe_next) {
    229   1.4       cgd 		if (dv->dv_class == DV_DISK &&
    230   1.4       cgd 		    strcmp(str, dv->dv_xname) == 0) {
    231  1.12       cgd #ifdef RAMDISK_HOOKS
    232  1.12       cgd gotdisk:
    233  1.12       cgd #endif
    234   1.4       cgd 			majdev = findblkmajor(dv);
    235   1.4       cgd 			if (majdev < 0)
    236   1.4       cgd 				panic("parsedisk");
    237   1.4       cgd 			*devp = MAKEDISKDEV(majdev, dv->dv_unit, part);
    238   1.4       cgd 			break;
    239   1.4       cgd 		}
    240   1.4       cgd #ifdef NFSCLIENT
    241   1.4       cgd 		if (dv->dv_class == DV_IFNET &&
    242   1.4       cgd 		    strcmp(str, dv->dv_xname) == 0) {
    243   1.4       cgd 			*devp = NODEV;
    244   1.4       cgd 			break;
    245   1.4       cgd 		}
    246   1.4       cgd #endif
    247   1.4       cgd 	}
    248   1.4       cgd 
    249   1.4       cgd 	*cp = c;
    250   1.4       cgd 	return (dv);
    251   1.4       cgd }
    252   1.1       cgd 
    253   1.1       cgd /*
    254   1.1       cgd  * Attempt to find the device from which we were booted.
    255   1.1       cgd  * If we can do so, and not instructed not to do so,
    256   1.1       cgd  * change rootdev to correspond to the load device.
    257   1.4       cgd  *
    258   1.4       cgd  * XXX Actually, swap and root must be on the same type of device,
    259   1.4       cgd  * (ie. DV_DISK or DV_IFNET) because of how (*mountroot) is written.
    260   1.4       cgd  * That should be fixed.
    261   1.1       cgd  */
    262  1.16       cgd void
    263   1.1       cgd setroot()
    264   1.1       cgd {
    265   1.1       cgd 	struct swdevt *swp;
    266   1.4       cgd 	struct device *dv;
    267   1.4       cgd         register int len;
    268   1.4       cgd 	dev_t nrootdev, nswapdev = NODEV;
    269   1.7       cgd 	char buf[128], *rootdevname;
    270   1.4       cgd 	extern int (*mountroot) __P((void *));
    271   1.4       cgd 	dev_t temp;
    272   1.4       cgd 	struct device *bootdv, *rootdv, *swapdv;
    273   1.5       cgd 	int bootpartition;
    274   1.4       cgd #if defined(NFSCLIENT)
    275   1.4       cgd 	extern char *nfsbootdevname;
    276   1.4       cgd 	extern int nfs_mountroot __P((void *));
    277   1.4       cgd #endif
    278   1.4       cgd #if defined(FFS)
    279   1.4       cgd 	extern int ffs_mountroot __P((void *));
    280   1.4       cgd #endif
    281   1.4       cgd 
    282  1.12       cgd #ifdef RAMDISK_HOOKS
    283  1.12       cgd 	bootdv = &fakerdrootdev;
    284  1.12       cgd 	bootpartition = 0;
    285  1.12       cgd #else
    286   1.5       cgd 	bootdv = booted_device;
    287   1.5       cgd 	bootpartition = booted_partition;
    288  1.12       cgd #endif
    289   1.4       cgd 
    290   1.4       cgd 	/*
    291   1.4       cgd 	 * If 'swap generic' and we couldn't determine root device,
    292   1.4       cgd 	 * ask the user.
    293   1.4       cgd 	 */
    294   1.4       cgd 	if (mountroot == NULL && bootdv == NULL)
    295   1.4       cgd 		boothowto |= RB_ASKNAME;
    296   1.4       cgd 
    297   1.4       cgd 	if (boothowto & RB_ASKNAME) {
    298   1.4       cgd 		for (;;) {
    299  1.14  christos 			printf("root device");
    300   1.9       cgd 			if (bootdv != NULL) {
    301  1.14  christos 				printf(" (default %s", bootdv->dv_xname);
    302   1.9       cgd 				if (bootdv->dv_class == DV_DISK)
    303  1.14  christos 					printf("%c", bootpartition + 'a');
    304  1.14  christos 				printf(")");
    305   1.9       cgd 			}
    306  1.14  christos 			printf(": ");
    307   1.4       cgd 			len = getstr(buf, sizeof(buf));
    308   1.4       cgd 			if (len == 0 && bootdv != NULL) {
    309   1.4       cgd 				strcpy(buf, bootdv->dv_xname);
    310   1.4       cgd 				len = strlen(buf);
    311   1.4       cgd 			}
    312   1.4       cgd 			if (len > 0 && buf[len - 1] == '*') {
    313   1.4       cgd 				buf[--len] = '\0';
    314   1.4       cgd 				dv = getdisk(buf, len, 1, &nrootdev);
    315   1.4       cgd 				if (dv != NULL) {
    316  1.16       cgd 					rootdv = swapdv = dv;
    317   1.4       cgd 					nswapdev = nrootdev;
    318   1.4       cgd 					goto gotswap;
    319   1.4       cgd 				}
    320   1.4       cgd 			}
    321   1.4       cgd 			dv = getdisk(buf, len, bootpartition, &nrootdev);
    322   1.4       cgd 			if (dv != NULL) {
    323   1.4       cgd 				rootdv = dv;
    324   1.4       cgd 				break;
    325   1.4       cgd 			}
    326   1.4       cgd 		}
    327   1.4       cgd 
    328   1.4       cgd 		/*
    329   1.4       cgd 		 * because swap must be on same device type as root, for
    330   1.4       cgd 		 * network devices this is easy.
    331   1.4       cgd 		 */
    332   1.4       cgd 		if (rootdv->dv_class == DV_IFNET) {
    333   1.4       cgd 			swapdv = NULL;
    334   1.4       cgd 			goto gotswap;
    335   1.4       cgd 		}
    336   1.4       cgd 		for (;;) {
    337  1.14  christos 			printf("swap device");
    338  1.14  christos 			printf(" (default %s", rootdv->dv_xname);
    339  1.11       cgd 			if (rootdv->dv_class == DV_DISK)
    340  1.14  christos 				printf("b");
    341  1.14  christos 			printf(")");
    342  1.14  christos 			printf(": ");
    343   1.4       cgd 			len = getstr(buf, sizeof(buf));
    344   1.4       cgd 			if (len == 0) {
    345   1.4       cgd 				switch (rootdv->dv_class) {
    346   1.4       cgd 				case DV_IFNET:
    347   1.4       cgd 					nswapdev = NODEV;
    348   1.4       cgd 					break;
    349   1.4       cgd 				case DV_DISK:
    350   1.4       cgd 					nswapdev = MAKEDISKDEV(major(nrootdev),
    351   1.4       cgd 					    DISKUNIT(nrootdev), 1);
    352   1.4       cgd 					break;
    353   1.4       cgd 				case DV_TAPE:
    354   1.4       cgd 				case DV_TTY:
    355   1.4       cgd 				case DV_DULL:
    356   1.4       cgd 				case DV_CPU:
    357   1.4       cgd 					break;
    358   1.4       cgd 				}
    359   1.4       cgd 				swapdv = rootdv;
    360   1.4       cgd 				break;
    361   1.4       cgd 			}
    362   1.4       cgd 			dv = getdisk(buf, len, 1, &nswapdev);
    363   1.4       cgd 			if (dv) {
    364   1.4       cgd 				if (dv->dv_class == DV_IFNET)
    365   1.4       cgd 					nswapdev = NODEV;
    366   1.4       cgd 				swapdv = dv;
    367   1.4       cgd 				break;
    368   1.4       cgd 			}
    369   1.4       cgd 		}
    370   1.4       cgd gotswap:
    371   1.4       cgd 		rootdev = nrootdev;
    372   1.4       cgd 		dumpdev = nswapdev;
    373   1.4       cgd 		swdevt[0].sw_dev = nswapdev;
    374   1.4       cgd 		swdevt[1].sw_dev = NODEV;
    375   1.4       cgd 	} else if (mountroot == NULL) {
    376   1.4       cgd 		int majdev;
    377   1.4       cgd 
    378   1.4       cgd 		/*
    379   1.4       cgd 		 * "swap generic"
    380   1.4       cgd 		 */
    381   1.4       cgd 		majdev = findblkmajor(bootdv);
    382   1.4       cgd 		if (majdev >= 0) {
    383   1.4       cgd 			/*
    384   1.4       cgd 			 * Root and swap are on a disk.
    385   1.4       cgd 			 */
    386   1.4       cgd 			rootdv = swapdv = bootdv;
    387   1.4       cgd 			rootdev = MAKEDISKDEV(majdev, bootdv->dv_unit,
    388   1.4       cgd 			    bootpartition);
    389   1.4       cgd 			nswapdev = dumpdev =
    390   1.4       cgd 			    MAKEDISKDEV(majdev, bootdv->dv_unit, 1);
    391   1.4       cgd 		} else {
    392   1.4       cgd 			/*
    393   1.4       cgd 			 * Root and swap are on a net.
    394   1.4       cgd 			 */
    395   1.6       cgd 			rootdv = swapdv = bootdv;
    396   1.4       cgd 			nswapdev = dumpdev = NODEV;
    397   1.4       cgd 		}
    398   1.4       cgd 		swdevt[0].sw_dev = nswapdev;
    399   1.4       cgd 		swdevt[1].sw_dev = NODEV;
    400   1.4       cgd         } else {
    401   1.4       cgd 		/*
    402  1.12       cgd 		 * `root DEV swap DEV': honor rootdev/swdevt.
    403   1.4       cgd 		 * rootdev/swdevt/mountroot already properly set.
    404   1.4       cgd 		 */
    405   1.7       cgd 
    406   1.7       cgd 		rootdevname = findblkname(major(rootdev));
    407   1.7       cgd 		if (rootdevname == NULL) {
    408   1.7       cgd 			/* Root on NFS or unknown device. */
    409   1.7       cgd 			strcpy(root_device, "??");
    410   1.7       cgd 		} else {
    411   1.7       cgd 			/* Root on known block device. */
    412  1.14  christos 			sprintf(root_device, "%s%d%c", rootdevname,
    413   1.7       cgd 			    DISKUNIT(rootdev), DISKPART(rootdev) + 'a');
    414   1.7       cgd 		}
    415   1.7       cgd 
    416   1.4       cgd 		return;
    417   1.4       cgd 	}
    418   1.1       cgd 
    419   1.4       cgd 	switch (rootdv->dv_class) {
    420   1.4       cgd #if defined(NFSCLIENT)
    421   1.4       cgd 	case DV_IFNET:
    422   1.7       cgd 		strcpy(root_device, "??");
    423   1.4       cgd 		mountroot = nfs_mountroot;
    424   1.4       cgd 		nfsbootdevname = rootdv->dv_xname;
    425   1.1       cgd 		return;
    426   1.4       cgd #endif
    427   1.4       cgd #if defined(FFS)
    428   1.4       cgd 	case DV_DISK:
    429   1.4       cgd 		mountroot = ffs_mountroot;
    430  1.14  christos 		sprintf(root_device, "%s%c", rootdv->dv_xname,
    431   1.4       cgd 		    DISKPART(rootdev) + 'a');
    432  1.14  christos 		printf("root on %s", root_device);
    433   1.4       cgd 		if (nswapdev != NODEV)
    434  1.14  christos 			printf(" swap on %s%c", swapdv->dv_xname,
    435   1.4       cgd 			    DISKPART(nswapdev) + 'a');
    436  1.14  christos 		printf("\n");
    437   1.4       cgd 		break;
    438   1.4       cgd #endif
    439   1.4       cgd 	default:
    440  1.14  christos 		printf("can't figure root, hope your kernel is right\n");
    441   1.1       cgd 		return;
    442   1.4       cgd 	}
    443   1.4       cgd 
    444   1.1       cgd 	/*
    445   1.4       cgd 	 * Make the swap partition on the root drive the primary swap.
    446   1.1       cgd 	 */
    447   1.4       cgd 	temp = NODEV;
    448   1.1       cgd 	for (swp = swdevt; swp->sw_dev != NODEV; swp++) {
    449   1.4       cgd 		if (major(rootdev) == major(swp->sw_dev) &&
    450   1.4       cgd 		    DISKUNIT(rootdev) == DISKUNIT(swp->sw_dev)) {
    451   1.1       cgd 			temp = swdevt[0].sw_dev;
    452   1.1       cgd 			swdevt[0].sw_dev = swp->sw_dev;
    453   1.1       cgd 			swp->sw_dev = temp;
    454   1.1       cgd 			break;
    455   1.1       cgd 		}
    456   1.1       cgd 	}
    457   1.1       cgd 	if (swp->sw_dev == NODEV)
    458   1.1       cgd 		return;
    459   1.1       cgd 
    460   1.1       cgd 	/*
    461   1.1       cgd 	 * If dumpdev was the same as the old primary swap device, move
    462   1.1       cgd 	 * it to the new primary swap device.
    463   1.1       cgd 	 */
    464   1.1       cgd 	if (temp == dumpdev)
    465   1.1       cgd 		dumpdev = swdevt[0].sw_dev;
    466   1.4       cgd }
    467   1.4       cgd 
    468   1.4       cgd static int
    469   1.4       cgd getstr(cp, size)
    470   1.4       cgd 	register char *cp;
    471   1.4       cgd 	register int size;
    472   1.4       cgd {
    473   1.4       cgd 	register char *lp;
    474   1.4       cgd 	register int c;
    475   1.4       cgd 	register int len;
    476   1.4       cgd 
    477   1.4       cgd 	lp = cp;
    478   1.4       cgd 	len = 0;
    479   1.4       cgd 	for (;;) {
    480   1.4       cgd 		c = cngetc();
    481   1.4       cgd 		switch (c) {
    482   1.4       cgd 		case '\n':
    483   1.4       cgd 		case '\r':
    484  1.14  christos 			printf("\n");
    485   1.4       cgd 			*lp++ = '\0';
    486   1.4       cgd 			return (len);
    487   1.4       cgd 		case '\b':
    488   1.4       cgd 		case '\177':
    489   1.4       cgd 		case '#':
    490   1.4       cgd 			if (len) {
    491   1.4       cgd 				--len;
    492   1.4       cgd 				--lp;
    493  1.14  christos 				printf("\b \b");
    494   1.4       cgd 			}
    495   1.4       cgd 			continue;
    496   1.4       cgd 		case '@':
    497   1.4       cgd 		case 'u'&037:
    498   1.4       cgd 			len = 0;
    499   1.4       cgd 			lp = cp;
    500  1.14  christos 			printf("\n");
    501   1.4       cgd 			continue;
    502   1.4       cgd 		default:
    503   1.4       cgd 			if (len + 1 >= size || c < ' ') {
    504  1.14  christos 				printf("\007");
    505   1.4       cgd 				continue;
    506   1.4       cgd 			}
    507  1.14  christos 			printf("%c", c);
    508   1.4       cgd 			++len;
    509   1.4       cgd 			*lp++ = c;
    510   1.4       cgd 		}
    511   1.4       cgd 	}
    512   1.5       cgd }
    513   1.5       cgd 
    514   1.5       cgd void
    515   1.5       cgd parse_prom_bootdev()
    516   1.5       cgd {
    517   1.5       cgd 	static char hacked_boot_dev[128];
    518   1.5       cgd 	static struct bootdev_data bd;
    519   1.5       cgd 	char *cp, *scp, *boot_fields[8];
    520   1.5       cgd 	int i, done;
    521   1.5       cgd 
    522   1.5       cgd 	booted_device = NULL;
    523   1.5       cgd 	booted_partition = 0;
    524   1.5       cgd 	bootdev_data = NULL;
    525   1.5       cgd 
    526   1.5       cgd         prom_getenv(PROM_E_BOOTED_DEV, boot_dev, sizeof(boot_dev));
    527   1.5       cgd 	bcopy(boot_dev, hacked_boot_dev, sizeof hacked_boot_dev);
    528   1.5       cgd #if 0
    529  1.14  christos 	printf("parse_prom_bootdev: boot dev = \"%s\"\n", boot_dev);
    530   1.5       cgd #endif
    531   1.5       cgd 
    532   1.5       cgd 	i = 0;
    533   1.5       cgd 	scp = cp = hacked_boot_dev;
    534   1.5       cgd 	for (done = 0; !done; cp++) {
    535   1.5       cgd 		if (*cp != ' ' && *cp != '\0')
    536   1.5       cgd 			continue;
    537   1.5       cgd 		if (*cp == '\0')
    538   1.5       cgd 			done = 1;
    539   1.5       cgd 
    540   1.5       cgd 		*cp = '\0';
    541   1.5       cgd 		boot_fields[i++] = scp;
    542   1.5       cgd 		scp = cp + 1;
    543   1.5       cgd 		if (i == 8)
    544   1.5       cgd 			done = 1;
    545   1.5       cgd 	}
    546   1.5       cgd 	if (i != 8)
    547   1.5       cgd 		return;		/* doesn't look like anything we know! */
    548   1.5       cgd 
    549   1.5       cgd #if 0
    550  1.14  christos 	printf("i = %d, done = %d\n", i, done);
    551   1.5       cgd 	for (i--; i >= 0; i--)
    552  1.14  christos 		printf("%d = %s\n", i, boot_fields[i]);
    553   1.5       cgd #endif
    554   1.5       cgd 
    555   1.5       cgd 	bd.protocol = boot_fields[0];
    556   1.5       cgd 	bd.bus = atoi(boot_fields[1]);
    557   1.5       cgd 	bd.slot = atoi(boot_fields[2]);
    558   1.5       cgd 	bd.channel = atoi(boot_fields[3]);
    559   1.5       cgd 	bd.remote_address = boot_fields[4];
    560   1.5       cgd 	bd.unit = atoi(boot_fields[5]);
    561   1.5       cgd 	bd.boot_dev_type = atoi(boot_fields[6]);
    562   1.5       cgd 	bd.ctrl_dev_type = boot_fields[7];
    563   1.5       cgd 
    564   1.5       cgd #if 0
    565  1.14  christos 	printf("parsed: proto = %s, bus = %d, slot = %d, channel = %d,\n",
    566   1.5       cgd 	    bd.protocol, bd.bus, bd.slot, bd.channel);
    567  1.14  christos 	printf("\tremote = %s, unit = %d, dev_type = %d, ctrl_type = %s\n",
    568   1.5       cgd 	    bd.remote_address, bd.unit, bd.boot_dev_type, bd.ctrl_dev_type);
    569   1.5       cgd #endif
    570   1.5       cgd 
    571   1.5       cgd 	bootdev_data = &bd;
    572   1.5       cgd }
    573   1.5       cgd 
    574   1.5       cgd int
    575   1.5       cgd atoi(s)
    576   1.5       cgd 	char *s;
    577   1.5       cgd {
    578   1.5       cgd 	int n, neg;
    579   1.5       cgd 
    580   1.5       cgd 	n = 0;
    581   1.5       cgd 	neg = 0;
    582   1.5       cgd 
    583   1.5       cgd 	while (*s == '-') {
    584   1.5       cgd 		s++;
    585   1.5       cgd 		neg = !neg;
    586   1.5       cgd 	}
    587   1.5       cgd 
    588   1.5       cgd 	while (*s != '\0') {
    589   1.5       cgd 		if (*s < '0' && *s > '9')
    590   1.5       cgd 			break;
    591   1.5       cgd 
    592   1.5       cgd 		n = (10 * n) + (*s - '0');
    593   1.5       cgd 		s++;
    594   1.5       cgd 	}
    595   1.5       cgd 
    596   1.5       cgd 	return (neg ? -n : n);
    597   1.5       cgd }
    598   1.5       cgd 
    599   1.5       cgd void
    600   1.5       cgd device_register(dev, aux)
    601   1.5       cgd 	struct device *dev;
    602   1.5       cgd 	void *aux;
    603   1.5       cgd {
    604  1.15       cgd 	extern const struct cpusw *cpu_fn_switch;
    605   1.5       cgd 
    606   1.5       cgd 	if (bootdev_data == NULL) {
    607   1.5       cgd 		/*
    608   1.5       cgd 		 * There is no hope.
    609   1.5       cgd 		 */
    610   1.5       cgd 
    611   1.5       cgd 		return;
    612   1.5       cgd 	}
    613   1.5       cgd 
    614  1.15       cgd 	(*cpu_fn_switch->device_register)(dev, aux);
    615   1.1       cgd }
    616