Home | History | Annotate | Line # | Download | only in alpha
autoconf.c revision 1.9
      1  1.9  cgd /*	$NetBSD: autoconf.c,v 1.9 1996/09/17 19:41:52 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.1  cgd 
     55  1.1  cgd #include <machine/autoconf.h>
     56  1.5  cgd #include <machine/prom.h>
     57  1.5  cgd 
     58  1.7  cgd extern char		root_device[17];		/* XXX */
     59  1.7  cgd 
     60  1.5  cgd struct device		*booted_device;
     61  1.5  cgd int			booted_partition;
     62  1.5  cgd struct bootdev_data	*bootdev_data;
     63  1.5  cgd char			boot_dev[128];
     64  1.5  cgd 
     65  1.5  cgd void	parse_prom_bootdev __P((void));
     66  1.5  cgd int	atoi __P((char *));
     67  1.1  cgd 
     68  1.4  cgd struct device *parsedisk __P((char *str, int len, int defpart, dev_t *devp));
     69  1.4  cgd static struct device *getdisk __P((char *str, int len, int defpart,
     70  1.4  cgd 				   dev_t *devp));
     71  1.4  cgd static int findblkmajor __P((struct device *dv));
     72  1.7  cgd static char *findblkname __P((int));
     73  1.4  cgd static int getstr __P((char *cp, int size));
     74  1.4  cgd 
     75  1.1  cgd /*
     76  1.1  cgd  * configure:
     77  1.1  cgd  * called at boot time, configure all devices on system
     78  1.1  cgd  */
     79  1.1  cgd void
     80  1.1  cgd configure()
     81  1.1  cgd {
     82  1.1  cgd 	extern int cold;
     83  1.1  cgd 
     84  1.5  cgd 	parse_prom_bootdev();
     85  1.5  cgd 
     86  1.1  cgd 	(void)splhigh();
     87  1.2  cgd 	if (config_rootfound("mainbus", "mainbus") == NULL)
     88  1.1  cgd 		panic("no mainbus found");
     89  1.1  cgd 	(void)spl0();
     90  1.1  cgd 
     91  1.5  cgd 	if (booted_device == NULL)
     92  1.5  cgd 		printf("WARNING: can't figure what device matches \"%s\"\n",
     93  1.5  cgd 		    boot_dev);
     94  1.1  cgd 	setroot();
     95  1.1  cgd 	swapconf();
     96  1.1  cgd 	cold = 0;
     97  1.1  cgd }
     98  1.1  cgd 
     99  1.1  cgd /*
    100  1.1  cgd  * Configure swap space and related parameters.
    101  1.1  cgd  */
    102  1.1  cgd swapconf()
    103  1.1  cgd {
    104  1.4  cgd 	struct swdevt *swp;
    105  1.4  cgd 	int nblks, maj;
    106  1.1  cgd 
    107  1.1  cgd 	for (swp = swdevt; swp->sw_dev != NODEV; swp++) {
    108  1.4  cgd 		maj = major(swp->sw_dev);
    109  1.1  cgd 		if (maj > nblkdev)
    110  1.1  cgd 			break;
    111  1.1  cgd 		if (bdevsw[maj].d_psize) {
    112  1.1  cgd 			nblks = (*bdevsw[maj].d_psize)(swp->sw_dev);
    113  1.1  cgd 			if (nblks != -1 &&
    114  1.1  cgd 			    (swp->sw_nblks == 0 || swp->sw_nblks > nblks))
    115  1.1  cgd 				swp->sw_nblks = nblks;
    116  1.1  cgd 			swp->sw_nblks = ctod(dtoc(swp->sw_nblks));
    117  1.1  cgd 		}
    118  1.1  cgd 	}
    119  1.4  cgd 	dumpconf();
    120  1.1  cgd }
    121  1.1  cgd 
    122  1.4  cgd struct nam2blk {
    123  1.4  cgd 	char *name;
    124  1.4  cgd 	int maj;
    125  1.4  cgd } nam2blk[] = {
    126  1.4  cgd 	{ "st",		2 },
    127  1.4  cgd 	{ "cd",		3 },
    128  1.4  cgd 	{ "sd",		8 },
    129  1.4  cgd #if 0
    130  1.4  cgd 	{ "fd",		XXX },
    131  1.4  cgd #endif
    132  1.4  cgd };
    133  1.4  cgd 
    134  1.4  cgd static int
    135  1.4  cgd findblkmajor(dv)
    136  1.4  cgd 	struct device *dv;
    137  1.4  cgd {
    138  1.4  cgd 	char *name = dv->dv_xname;
    139  1.4  cgd 	register int i;
    140  1.4  cgd 
    141  1.4  cgd 	for (i = 0; i < sizeof(nam2blk)/sizeof(nam2blk[0]); ++i)
    142  1.4  cgd 		if (strncmp(name, nam2blk[i].name, strlen(nam2blk[0].name))
    143  1.4  cgd 		    == 0)
    144  1.4  cgd 			return (nam2blk[i].maj);
    145  1.4  cgd 	return (-1);
    146  1.4  cgd }
    147  1.4  cgd 
    148  1.7  cgd static char *
    149  1.7  cgd findblkname(maj)
    150  1.7  cgd 	int maj;
    151  1.7  cgd {
    152  1.7  cgd 	register int i;
    153  1.7  cgd 
    154  1.7  cgd 	for (i = 0; i < sizeof(nam2blk)/sizeof(nam2blk[0]); ++i)
    155  1.7  cgd 		if (maj == nam2blk[i].maj)
    156  1.7  cgd 			return (nam2blk[i].name);
    157  1.7  cgd 	return (NULL);
    158  1.7  cgd }
    159  1.7  cgd 
    160  1.4  cgd static struct device *
    161  1.4  cgd getdisk(str, len, defpart, devp)
    162  1.4  cgd 	char *str;
    163  1.4  cgd 	int len, defpart;
    164  1.4  cgd 	dev_t *devp;
    165  1.4  cgd {
    166  1.4  cgd 	register struct device *dv;
    167  1.1  cgd 
    168  1.4  cgd 	if ((dv = parsedisk(str, len, defpart, devp)) == NULL) {
    169  1.4  cgd 		printf("use one of:");
    170  1.4  cgd 		for (dv = alldevs.tqh_first; dv != NULL;
    171  1.4  cgd 		    dv = dv->dv_list.tqe_next) {
    172  1.4  cgd 			if (dv->dv_class == DV_DISK)
    173  1.4  cgd 				printf(" %s[a-h]", dv->dv_xname);
    174  1.4  cgd #ifdef NFSCLIENT
    175  1.4  cgd 			if (dv->dv_class == DV_IFNET)
    176  1.4  cgd 				printf(" %s", dv->dv_xname);
    177  1.4  cgd #endif
    178  1.4  cgd 		}
    179  1.4  cgd 		printf("\n");
    180  1.4  cgd 	}
    181  1.4  cgd 	return (dv);
    182  1.4  cgd }
    183  1.4  cgd 
    184  1.4  cgd struct device *
    185  1.4  cgd parsedisk(str, len, defpart, devp)
    186  1.4  cgd 	char *str;
    187  1.4  cgd 	int len, defpart;
    188  1.4  cgd 	dev_t *devp;
    189  1.4  cgd {
    190  1.4  cgd 	register struct device *dv;
    191  1.4  cgd 	register char *cp, c;
    192  1.4  cgd 	int majdev, part;
    193  1.4  cgd 
    194  1.4  cgd 	if (len == 0)
    195  1.4  cgd 		return (NULL);
    196  1.4  cgd 	cp = str + len - 1;
    197  1.4  cgd 	c = *cp;
    198  1.4  cgd 	if (c >= 'a' && c <= ('a' + MAXPARTITIONS - 1)) {
    199  1.4  cgd 		part = c - 'a';
    200  1.4  cgd 		*cp = '\0';
    201  1.4  cgd 	} else
    202  1.4  cgd 		part = defpart;
    203  1.4  cgd 
    204  1.4  cgd 	for (dv = alldevs.tqh_first; dv != NULL; dv = dv->dv_list.tqe_next) {
    205  1.4  cgd 		if (dv->dv_class == DV_DISK &&
    206  1.4  cgd 		    strcmp(str, dv->dv_xname) == 0) {
    207  1.4  cgd 			majdev = findblkmajor(dv);
    208  1.4  cgd 			if (majdev < 0)
    209  1.4  cgd 				panic("parsedisk");
    210  1.4  cgd 			*devp = MAKEDISKDEV(majdev, dv->dv_unit, part);
    211  1.4  cgd 			break;
    212  1.4  cgd 		}
    213  1.4  cgd #ifdef NFSCLIENT
    214  1.4  cgd 		if (dv->dv_class == DV_IFNET &&
    215  1.4  cgd 		    strcmp(str, dv->dv_xname) == 0) {
    216  1.4  cgd 			*devp = NODEV;
    217  1.4  cgd 			break;
    218  1.4  cgd 		}
    219  1.4  cgd #endif
    220  1.4  cgd 	}
    221  1.4  cgd 
    222  1.4  cgd 	*cp = c;
    223  1.4  cgd 	return (dv);
    224  1.4  cgd }
    225  1.1  cgd 
    226  1.1  cgd /*
    227  1.1  cgd  * Attempt to find the device from which we were booted.
    228  1.1  cgd  * If we can do so, and not instructed not to do so,
    229  1.1  cgd  * change rootdev to correspond to the load device.
    230  1.4  cgd  *
    231  1.4  cgd  * XXX Actually, swap and root must be on the same type of device,
    232  1.4  cgd  * (ie. DV_DISK or DV_IFNET) because of how (*mountroot) is written.
    233  1.4  cgd  * That should be fixed.
    234  1.1  cgd  */
    235  1.1  cgd setroot()
    236  1.1  cgd {
    237  1.1  cgd 	struct swdevt *swp;
    238  1.4  cgd 	struct device *dv;
    239  1.4  cgd         register int len;
    240  1.4  cgd 	dev_t nrootdev, nswapdev = NODEV;
    241  1.7  cgd 	char buf[128], *rootdevname;
    242  1.4  cgd 	extern int (*mountroot) __P((void *));
    243  1.4  cgd 	dev_t temp;
    244  1.4  cgd 	struct device *bootdv, *rootdv, *swapdv;
    245  1.5  cgd 	int bootpartition;
    246  1.4  cgd #if defined(NFSCLIENT)
    247  1.4  cgd 	extern char *nfsbootdevname;
    248  1.4  cgd 	extern int nfs_mountroot __P((void *));
    249  1.4  cgd #endif
    250  1.4  cgd #if defined(FFS)
    251  1.4  cgd 	extern int ffs_mountroot __P((void *));
    252  1.4  cgd #endif
    253  1.4  cgd 
    254  1.5  cgd 	bootdv = booted_device;
    255  1.5  cgd 	bootpartition = booted_partition;
    256  1.4  cgd 
    257  1.4  cgd 	/*
    258  1.4  cgd 	 * If 'swap generic' and we couldn't determine root device,
    259  1.4  cgd 	 * ask the user.
    260  1.4  cgd 	 */
    261  1.4  cgd 	if (mountroot == NULL && bootdv == NULL)
    262  1.4  cgd 		boothowto |= RB_ASKNAME;
    263  1.4  cgd 
    264  1.4  cgd 	if (boothowto & RB_ASKNAME) {
    265  1.4  cgd 		for (;;) {
    266  1.4  cgd 			printf("root device");
    267  1.9  cgd 			if (bootdv != NULL) {
    268  1.9  cgd 				printf(" (default %s", bootdv->dv_xname);
    269  1.9  cgd 				if (bootdv->dv_class == DV_DISK)
    270  1.9  cgd 					printf("%c", bootpartition + 'a');
    271  1.9  cgd 				printf(")");
    272  1.9  cgd 			}
    273  1.4  cgd 			printf(": ");
    274  1.4  cgd 			len = getstr(buf, sizeof(buf));
    275  1.4  cgd 			if (len == 0 && bootdv != NULL) {
    276  1.4  cgd 				strcpy(buf, bootdv->dv_xname);
    277  1.4  cgd 				len = strlen(buf);
    278  1.4  cgd 			}
    279  1.4  cgd 			if (len == 4 && !strcmp(buf, "halt"))
    280  1.8  mrg 				boot(RB_HALT, NULL);
    281  1.4  cgd 			if (len > 0 && buf[len - 1] == '*') {
    282  1.4  cgd 				buf[--len] = '\0';
    283  1.4  cgd 				dv = getdisk(buf, len, 1, &nrootdev);
    284  1.4  cgd 				if (dv != NULL) {
    285  1.4  cgd 					rootdv = dv;
    286  1.4  cgd 					nswapdev = nrootdev;
    287  1.4  cgd 					goto gotswap;
    288  1.4  cgd 				}
    289  1.4  cgd 			}
    290  1.4  cgd 			dv = getdisk(buf, len, bootpartition, &nrootdev);
    291  1.4  cgd 			if (dv != NULL) {
    292  1.4  cgd 				rootdv = dv;
    293  1.4  cgd 				break;
    294  1.4  cgd 			}
    295  1.4  cgd 		}
    296  1.4  cgd 
    297  1.4  cgd 		/*
    298  1.4  cgd 		 * because swap must be on same device type as root, for
    299  1.4  cgd 		 * network devices this is easy.
    300  1.4  cgd 		 */
    301  1.4  cgd 		if (rootdv->dv_class == DV_IFNET) {
    302  1.4  cgd 			swapdv = NULL;
    303  1.4  cgd 			goto gotswap;
    304  1.4  cgd 		}
    305  1.4  cgd 		for (;;) {
    306  1.4  cgd 			printf("swap device");
    307  1.9  cgd 			printf(" (default %s", rootdv->dv_xname);
    308  1.9  cgd 			if (->dv_class == DV_DISK)
    309  1.9  cgd 				printf("b");
    310  1.9  cgd 			printf(")");
    311  1.4  cgd 			printf(": ");
    312  1.4  cgd 			len = getstr(buf, sizeof(buf));
    313  1.4  cgd 			if (len == 0) {
    314  1.4  cgd 				switch (rootdv->dv_class) {
    315  1.4  cgd 				case DV_IFNET:
    316  1.4  cgd 					nswapdev = NODEV;
    317  1.4  cgd 					break;
    318  1.4  cgd 				case DV_DISK:
    319  1.4  cgd 					nswapdev = MAKEDISKDEV(major(nrootdev),
    320  1.4  cgd 					    DISKUNIT(nrootdev), 1);
    321  1.4  cgd 					break;
    322  1.4  cgd 				case DV_TAPE:
    323  1.4  cgd 				case DV_TTY:
    324  1.4  cgd 				case DV_DULL:
    325  1.4  cgd 				case DV_CPU:
    326  1.4  cgd 					break;
    327  1.4  cgd 				}
    328  1.4  cgd 				swapdv = rootdv;
    329  1.4  cgd 				break;
    330  1.4  cgd 			}
    331  1.4  cgd 			if (len == 4 && !strcmp(buf, "halt"))
    332  1.8  mrg 				boot(RB_HALT, NULL);
    333  1.4  cgd 			dv = getdisk(buf, len, 1, &nswapdev);
    334  1.4  cgd 			if (dv) {
    335  1.4  cgd 				if (dv->dv_class == DV_IFNET)
    336  1.4  cgd 					nswapdev = NODEV;
    337  1.4  cgd 				swapdv = dv;
    338  1.4  cgd 				break;
    339  1.4  cgd 			}
    340  1.4  cgd 		}
    341  1.4  cgd gotswap:
    342  1.4  cgd 		rootdev = nrootdev;
    343  1.4  cgd 		dumpdev = nswapdev;
    344  1.4  cgd 		swdevt[0].sw_dev = nswapdev;
    345  1.4  cgd 		swdevt[1].sw_dev = NODEV;
    346  1.4  cgd 	} else if (mountroot == NULL) {
    347  1.4  cgd 		int majdev;
    348  1.4  cgd 
    349  1.4  cgd 		/*
    350  1.4  cgd 		 * "swap generic"
    351  1.4  cgd 		 */
    352  1.4  cgd 		majdev = findblkmajor(bootdv);
    353  1.4  cgd 		if (majdev >= 0) {
    354  1.4  cgd 			/*
    355  1.4  cgd 			 * Root and swap are on a disk.
    356  1.4  cgd 			 */
    357  1.4  cgd 			rootdv = swapdv = bootdv;
    358  1.4  cgd 			rootdev = MAKEDISKDEV(majdev, bootdv->dv_unit,
    359  1.4  cgd 			    bootpartition);
    360  1.4  cgd 			nswapdev = dumpdev =
    361  1.4  cgd 			    MAKEDISKDEV(majdev, bootdv->dv_unit, 1);
    362  1.4  cgd 		} else {
    363  1.4  cgd 			/*
    364  1.4  cgd 			 * Root and swap are on a net.
    365  1.4  cgd 			 */
    366  1.6  cgd 			rootdv = swapdv = bootdv;
    367  1.4  cgd 			nswapdev = dumpdev = NODEV;
    368  1.4  cgd 		}
    369  1.4  cgd 		swdevt[0].sw_dev = nswapdev;
    370  1.4  cgd 		swdevt[1].sw_dev = NODEV;
    371  1.4  cgd         } else {
    372  1.4  cgd 		/*
    373  1.4  cgd 		 * `root DEV swap DEV': honour rootdev/swdevt.
    374  1.4  cgd 		 * rootdev/swdevt/mountroot already properly set.
    375  1.4  cgd 		 */
    376  1.7  cgd 
    377  1.7  cgd 		rootdevname = findblkname(major(rootdev));
    378  1.7  cgd 		if (rootdevname == NULL) {
    379  1.7  cgd 			/* Root on NFS or unknown device. */
    380  1.7  cgd 			strcpy(root_device, "??");
    381  1.7  cgd 		} else {
    382  1.7  cgd 			/* Root on known block device. */
    383  1.7  cgd 			sprintf(root_device, "%s%d%c", rootdevname,
    384  1.7  cgd 			    DISKUNIT(rootdev), DISKPART(rootdev) + 'a');
    385  1.7  cgd 		}
    386  1.7  cgd 
    387  1.4  cgd 		return;
    388  1.4  cgd 	}
    389  1.1  cgd 
    390  1.4  cgd 	switch (rootdv->dv_class) {
    391  1.4  cgd #if defined(NFSCLIENT)
    392  1.4  cgd 	case DV_IFNET:
    393  1.7  cgd 		strcpy(root_device, "??");
    394  1.4  cgd 		mountroot = nfs_mountroot;
    395  1.4  cgd 		nfsbootdevname = rootdv->dv_xname;
    396  1.1  cgd 		return;
    397  1.4  cgd #endif
    398  1.4  cgd #if defined(FFS)
    399  1.4  cgd 	case DV_DISK:
    400  1.4  cgd 		mountroot = ffs_mountroot;
    401  1.7  cgd 		sprintf(root_device, "%s%c", rootdv->dv_xname,
    402  1.4  cgd 		    DISKPART(rootdev) + 'a');
    403  1.7  cgd 		printf("root on %s", root_device);
    404  1.4  cgd 		if (nswapdev != NODEV)
    405  1.4  cgd 			printf(" swap on %s%c", swapdv->dv_xname,
    406  1.4  cgd 			    DISKPART(nswapdev) + 'a');
    407  1.4  cgd 		printf("\n");
    408  1.4  cgd 		break;
    409  1.4  cgd #endif
    410  1.4  cgd 	default:
    411  1.4  cgd 		printf("can't figure root, hope your kernel is right\n");
    412  1.1  cgd 		return;
    413  1.4  cgd 	}
    414  1.4  cgd 
    415  1.1  cgd 	/*
    416  1.4  cgd 	 * Make the swap partition on the root drive the primary swap.
    417  1.1  cgd 	 */
    418  1.4  cgd 	temp = NODEV;
    419  1.1  cgd 	for (swp = swdevt; swp->sw_dev != NODEV; swp++) {
    420  1.4  cgd 		if (major(rootdev) == major(swp->sw_dev) &&
    421  1.4  cgd 		    DISKUNIT(rootdev) == DISKUNIT(swp->sw_dev)) {
    422  1.1  cgd 			temp = swdevt[0].sw_dev;
    423  1.1  cgd 			swdevt[0].sw_dev = swp->sw_dev;
    424  1.1  cgd 			swp->sw_dev = temp;
    425  1.1  cgd 			break;
    426  1.1  cgd 		}
    427  1.1  cgd 	}
    428  1.1  cgd 	if (swp->sw_dev == NODEV)
    429  1.1  cgd 		return;
    430  1.1  cgd 
    431  1.1  cgd 	/*
    432  1.1  cgd 	 * If dumpdev was the same as the old primary swap device, move
    433  1.1  cgd 	 * it to the new primary swap device.
    434  1.1  cgd 	 */
    435  1.1  cgd 	if (temp == dumpdev)
    436  1.1  cgd 		dumpdev = swdevt[0].sw_dev;
    437  1.4  cgd }
    438  1.4  cgd 
    439  1.4  cgd static int
    440  1.4  cgd getstr(cp, size)
    441  1.4  cgd 	register char *cp;
    442  1.4  cgd 	register int size;
    443  1.4  cgd {
    444  1.4  cgd 	register char *lp;
    445  1.4  cgd 	register int c;
    446  1.4  cgd 	register int len;
    447  1.4  cgd 
    448  1.4  cgd 	lp = cp;
    449  1.4  cgd 	len = 0;
    450  1.4  cgd 	for (;;) {
    451  1.4  cgd 		c = cngetc();
    452  1.4  cgd 		switch (c) {
    453  1.4  cgd 		case '\n':
    454  1.4  cgd 		case '\r':
    455  1.4  cgd 			printf("\n");
    456  1.4  cgd 			*lp++ = '\0';
    457  1.4  cgd 			return (len);
    458  1.4  cgd 		case '\b':
    459  1.4  cgd 		case '\177':
    460  1.4  cgd 		case '#':
    461  1.4  cgd 			if (len) {
    462  1.4  cgd 				--len;
    463  1.4  cgd 				--lp;
    464  1.4  cgd 				printf("\b \b");
    465  1.4  cgd 			}
    466  1.4  cgd 			continue;
    467  1.4  cgd 		case '@':
    468  1.4  cgd 		case 'u'&037:
    469  1.4  cgd 			len = 0;
    470  1.4  cgd 			lp = cp;
    471  1.4  cgd 			printf("\n");
    472  1.4  cgd 			continue;
    473  1.4  cgd 		default:
    474  1.4  cgd 			if (len + 1 >= size || c < ' ') {
    475  1.4  cgd 				printf("\007");
    476  1.4  cgd 				continue;
    477  1.4  cgd 			}
    478  1.4  cgd 			printf("%c", c);
    479  1.4  cgd 			++len;
    480  1.4  cgd 			*lp++ = c;
    481  1.4  cgd 		}
    482  1.4  cgd 	}
    483  1.5  cgd }
    484  1.5  cgd 
    485  1.5  cgd void
    486  1.5  cgd parse_prom_bootdev()
    487  1.5  cgd {
    488  1.5  cgd 	static char hacked_boot_dev[128];
    489  1.5  cgd 	static struct bootdev_data bd;
    490  1.5  cgd 	char *cp, *scp, *boot_fields[8];
    491  1.5  cgd 	int i, done;
    492  1.5  cgd 
    493  1.5  cgd 	booted_device = NULL;
    494  1.5  cgd 	booted_partition = 0;
    495  1.5  cgd 	bootdev_data = NULL;
    496  1.5  cgd 
    497  1.5  cgd         prom_getenv(PROM_E_BOOTED_DEV, boot_dev, sizeof(boot_dev));
    498  1.5  cgd 	bcopy(boot_dev, hacked_boot_dev, sizeof hacked_boot_dev);
    499  1.5  cgd #if 0
    500  1.5  cgd 	printf("parse_prom_bootdev: boot dev = \"%s\"\n", boot_dev);
    501  1.5  cgd #endif
    502  1.5  cgd 
    503  1.5  cgd 	i = 0;
    504  1.5  cgd 	scp = cp = hacked_boot_dev;
    505  1.5  cgd 	for (done = 0; !done; cp++) {
    506  1.5  cgd 		if (*cp != ' ' && *cp != '\0')
    507  1.5  cgd 			continue;
    508  1.5  cgd 		if (*cp == '\0')
    509  1.5  cgd 			done = 1;
    510  1.5  cgd 
    511  1.5  cgd 		*cp = '\0';
    512  1.5  cgd 		boot_fields[i++] = scp;
    513  1.5  cgd 		scp = cp + 1;
    514  1.5  cgd 		if (i == 8)
    515  1.5  cgd 			done = 1;
    516  1.5  cgd 	}
    517  1.5  cgd 	if (i != 8)
    518  1.5  cgd 		return;		/* doesn't look like anything we know! */
    519  1.5  cgd 
    520  1.5  cgd #if 0
    521  1.5  cgd 	printf("i = %d, done = %d\n", i, done);
    522  1.5  cgd 	for (i--; i >= 0; i--)
    523  1.5  cgd 		printf("%d = %s\n", i, boot_fields[i]);
    524  1.5  cgd #endif
    525  1.5  cgd 
    526  1.5  cgd 	bd.protocol = boot_fields[0];
    527  1.5  cgd 	bd.bus = atoi(boot_fields[1]);
    528  1.5  cgd 	bd.slot = atoi(boot_fields[2]);
    529  1.5  cgd 	bd.channel = atoi(boot_fields[3]);
    530  1.5  cgd 	bd.remote_address = boot_fields[4];
    531  1.5  cgd 	bd.unit = atoi(boot_fields[5]);
    532  1.5  cgd 	bd.boot_dev_type = atoi(boot_fields[6]);
    533  1.5  cgd 	bd.ctrl_dev_type = boot_fields[7];
    534  1.5  cgd 
    535  1.5  cgd #if 0
    536  1.5  cgd 	printf("parsed: proto = %s, bus = %d, slot = %d, channel = %d,\n",
    537  1.5  cgd 	    bd.protocol, bd.bus, bd.slot, bd.channel);
    538  1.5  cgd 	printf("\tremote = %s, unit = %d, dev_type = %d, ctrl_type = %s\n",
    539  1.5  cgd 	    bd.remote_address, bd.unit, bd.boot_dev_type, bd.ctrl_dev_type);
    540  1.5  cgd #endif
    541  1.5  cgd 
    542  1.5  cgd 	bootdev_data = &bd;
    543  1.5  cgd }
    544  1.5  cgd 
    545  1.5  cgd int
    546  1.5  cgd atoi(s)
    547  1.5  cgd 	char *s;
    548  1.5  cgd {
    549  1.5  cgd 	int n, neg;
    550  1.5  cgd 	char c;
    551  1.5  cgd 
    552  1.5  cgd 	n = 0;
    553  1.5  cgd 	neg = 0;
    554  1.5  cgd 
    555  1.5  cgd 	while (*s == '-') {
    556  1.5  cgd 		s++;
    557  1.5  cgd 		neg = !neg;
    558  1.5  cgd 	}
    559  1.5  cgd 
    560  1.5  cgd 	while (*s != '\0') {
    561  1.5  cgd 		if (*s < '0' && *s > '9')
    562  1.5  cgd 			break;
    563  1.5  cgd 
    564  1.5  cgd 		n = (10 * n) + (*s - '0');
    565  1.5  cgd 		s++;
    566  1.5  cgd 	}
    567  1.5  cgd 
    568  1.5  cgd 	return (neg ? -n : n);
    569  1.5  cgd }
    570  1.5  cgd 
    571  1.5  cgd void
    572  1.5  cgd device_register(dev, aux)
    573  1.5  cgd 	struct device *dev;
    574  1.5  cgd 	void *aux;
    575  1.5  cgd {
    576  1.5  cgd 	extern void (*cpu_device_register) __P((struct device *dev, void *aux));
    577  1.5  cgd 
    578  1.5  cgd 	if (bootdev_data == NULL) {
    579  1.5  cgd 		/*
    580  1.5  cgd 		 * There is no hope.
    581  1.5  cgd 		 */
    582  1.5  cgd 
    583  1.5  cgd 		return;
    584  1.5  cgd 	}
    585  1.5  cgd 
    586  1.5  cgd 	(*cpu_device_register)(dev, aux);
    587  1.1  cgd }
    588