Home | History | Annotate | Line # | Download | only in boot
init_main.c revision 1.9
      1 /*	$NetBSD: init_main.c,v 1.9 2014/01/10 11:12:03 tsutsui Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1992 OMRON Corporation.
      5  *
      6  * This code is derived from software contributed to Berkeley by
      7  * OMRON Corporation.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed by the University of
     20  *	California, Berkeley and its contributors.
     21  * 4. Neither the name of the University nor the names of its contributors
     22  *    may be used to endorse or promote products derived from this software
     23  *    without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  * SUCH DAMAGE.
     36  *
     37  *	@(#)init_main.c	8.2 (Berkeley) 8/15/93
     38  */
     39 /*
     40  * Copyright (c) 1992, 1993
     41  *	The Regents of the University of California.  All rights reserved.
     42  *
     43  * This code is derived from software contributed to Berkeley by
     44  * OMRON Corporation.
     45  *
     46  * Redistribution and use in source and binary forms, with or without
     47  * modification, are permitted provided that the following conditions
     48  * are met:
     49  * 1. Redistributions of source code must retain the above copyright
     50  *    notice, this list of conditions and the following disclaimer.
     51  * 2. Redistributions in binary form must reproduce the above copyright
     52  *    notice, this list of conditions and the following disclaimer in the
     53  *    documentation and/or other materials provided with the distribution.
     54  * 3. Neither the name of the University nor the names of its contributors
     55  *    may be used to endorse or promote products derived from this software
     56  *    without specific prior written permission.
     57  *
     58  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68  * SUCH DAMAGE.
     69  *
     70  *	@(#)init_main.c	8.2 (Berkeley) 8/15/93
     71  */
     72 
     73 #include <sys/param.h>
     74 #include <sys/boot_flag.h>
     75 #include <machine/cpu.h>
     76 #include <luna68k/stand/boot/samachdep.h>
     77 #include <luna68k/stand/boot/stinger.h>
     78 #include <luna68k/stand/boot/romvec.h>
     79 #include <luna68k/stand/boot/status.h>
     80 #include <lib/libsa/loadfile.h>
     81 #ifdef SUPPORT_ETHERNET
     82 #include <lib/libsa/dev_net.h>
     83 #endif
     84 
     85 static int get_plane_numbers(void);
     86 static int reorder_dipsw(int);
     87 
     88 int cpuspeed;	/* for DELAY() macro */
     89 int hz = 60;
     90 int machtype;
     91 char default_file[64];
     92 
     93 #define	VERS_LOCAL	"Phase-31"
     94 
     95 int nplane;
     96 
     97 /* KIFF */
     98 
     99 struct KernInter  KIFF;
    100 struct KernInter *kiff = &KIFF;
    101 
    102 /* for command parser */
    103 
    104 #define BUFFSIZE 100
    105 #define MAXARGS  30
    106 
    107 char buffer[BUFFSIZE];
    108 
    109 int   argc;
    110 char *argv[MAXARGS];
    111 
    112 #define BOOT_TIMEOUT 10
    113 int boot_timeout = BOOT_TIMEOUT;
    114 
    115 static const char prompt[] = "boot> ";
    116 
    117 /*
    118  * PROM monitor's boot device info
    119  */
    120 
    121 /* LUNA-I monitor's bootinfo structure */
    122 /* This bootinfo data address is investigated on ROM Ver4.22 and Ver4.25 */
    123 #define	LUNA1_BOOTINFOADDR	0x000008c0
    124 struct luna1_bootinfo {
    125 	uint8_t	bi_xxx1[3];	/* 0x08c0: ??? */
    126 	uint8_t	bi_device;	/* 0x08c3: boot device */
    127 #define	LUNA1_BTDEV_DK	0		/* Hard-Disk */
    128 #define	LUNA1_BTDEV_FB	1		/* Floppy-Disk */
    129 #define	LUNA1_BTDEV_SD	2		/* Streamer-Tape */
    130 #define	LUNA1_BTDEV_P0	3		/* RS232c */
    131 #define	LUNA1_BTDEV_ET	4		/* Ether-net */
    132 #define	LUNA1_NBTDEV	5
    133 
    134 	struct {
    135 		uint8_t	bd_xxx1;	/*  0: ??? */
    136 		uint8_t	bd_boot;	/*  1: 1 == booted */
    137 		char	bd_name[2];	/*  2: device name (dk, fb, sd ... ) */
    138 		uint8_t	bd_drv;		/*  4: drive number (not ID) */
    139 		uint8_t	bd_xxx2;	/*  5: ??? */
    140 		uint8_t	bd_xxx3;	/*  6: ??? */
    141 		uint8_t	bd_part;	/*  7: dk partition / st record # */
    142 		uint8_t	bd_xxx4[4];	/*  8: ??? */
    143 		uint8_t	bd_xxx5[4];	/* 12: ??? */
    144 	} bi_devinfo[LUNA1_NBTDEV];
    145 } __packed;
    146 
    147 /* LUNA-II monitor's bootinfo structure */
    148 /* This bootinfo data address is investigated on ROM Version 1.11 */
    149 #define	LUNA2_BOOTINFOADDR	0x00001d80
    150 struct luna2_bootinfo {
    151 	uint8_t	bi_xxx1[13];	/* 0x1d80: ??? */
    152 	uint8_t	bi_device;	/* 0x1d8d: boot device */
    153 #define	LUNA2_BTDEV_DK	0		/* Hard-Disk */
    154 #define	LUNA2_BTDEV_FT	1		/* Floppy-Disk */
    155 #define	LUNA2_BTDEV_SD	2		/* Streamer-Tape */
    156 #define	LUNA2_BTDEV_P0	3		/* RS232c */
    157 #define	LUNA2_NBTDEV	4
    158 
    159 	struct {
    160 		uint8_t	bd_xxx1;	/*  0: ??? */
    161 		uint8_t	bd_boot;	/*  1: 1 == booted */
    162 		char	bd_name[4];	/*  2: device name (dk, ft, sd ... ) */
    163 		uint8_t	bd_xxx2;	/*  6: ??? */
    164 		uint8_t	bd_ctlr;	/*  7: SCSI controller number */
    165 		uint8_t	bd_id;		/*  8: SCSI ID number */
    166 		uint8_t	bd_xxx3;	/*  9: device number index? */
    167 		uint8_t	bd_xxx4;	/* 10: ??? */
    168 		uint8_t	bd_part;	/* 11: dk partition / st record # */
    169 		uint8_t	bd_xxx5[4];	/* 12: ??? */
    170 		uint8_t	bd_xxx6[4];	/* 16: ??? */
    171 	} bi_devinfo[LUNA2_NBTDEV];
    172 } __packed;
    173 
    174 /* #define BTINFO_DEBUG */
    175 
    176 void
    177 main(void)
    178 {
    179 	int i, status = 0;
    180 	const char *machstr;
    181 	const char *bootdev;
    182 	int unit, part;
    183 	int bdev, ctlr, id;
    184 
    185 	/*
    186 	 * Initialize the console before we print anything out.
    187 	 */
    188 	if (cputype == CPU_68030) {
    189 		machtype = LUNA_I;
    190 		machstr  = "LUNA-I";
    191 		cpuspeed = MHZ_25;
    192 		hz = 60;
    193 	} else {
    194 		machtype = LUNA_II;
    195 		machstr  = "LUNA-II";
    196 		cpuspeed = MHZ_25 * 2;	/* XXX */
    197 		hz = 100;
    198 	}
    199 
    200 	nplane   = get_plane_numbers();
    201 
    202 	cninit();
    203 
    204 	printf("\n");
    205 	printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
    206 	printf(">> (based on Stinger ver 0.0 [%s])\n", VERS_LOCAL);
    207 	printf("\n");
    208 
    209 	kiff->maxaddr = (void *) (ROM_memsize -1);
    210 	kiff->dipsw   = ~((dipsw2 << 8) | dipsw1) & 0xFFFF;
    211 	kiff->plane   = nplane;
    212 
    213 	i = (int) kiff->maxaddr + 1;
    214 	printf("Machine model   = %s\n", machstr);
    215 	printf("Physical Memory = 0x%x  ", i);
    216 	i >>= 20;
    217 	printf("(%d MB)\n", i);
    218 	printf("\n");
    219 
    220 	/*
    221 	 * IO configuration
    222 	 */
    223 
    224 #ifdef SUPPORT_ETHERNET
    225 	try_bootp = 1;
    226 #endif
    227 
    228 	find_devs();
    229 	printf("\n");
    230 
    231 	/* use sd(0,0) for the default boot device */
    232 	bootdev = "sd";
    233 	unit = 0;
    234 	part = 0;
    235 
    236 	if (machtype == LUNA_I) {
    237 		const struct luna1_bootinfo *bi1 = (void *)LUNA1_BOOTINFOADDR;
    238 
    239 		bdev = bi1->bi_device;
    240 		switch (bdev) {
    241 		case LUNA1_BTDEV_DK:
    242 			/* note: bd_drv is not SCSI ID */
    243 			ctlr = 0;
    244 			id   = 6 - bi1->bi_devinfo[bdev].bd_drv;
    245 			unit = UNIT(ctlr, id);
    246 			break;
    247 		case LUNA1_BTDEV_ET:
    248 			bootdev = "le";
    249 			unit = 0;
    250 			break;
    251 		default:
    252 			/* not supported */
    253 			break;
    254 		}
    255 #ifdef BTINFO_DEBUG
    256 		printf("bi1->bi_device = 0x%02x\n", bi1->bi_device);
    257 		printf("bi1->bi_devinfo[bdev].bd_boot = 0x%02x\n",
    258 		    bi1->bi_devinfo[bdev].bd_boot);
    259 		printf("bi1->bi_devinfo[bdev].bd_name = %c%c\n",
    260 		    bi1->bi_devinfo[bdev].bd_name[0],
    261 		    bi1->bi_devinfo[bdev].bd_name[1]);
    262 		printf("bi1->bi_devinfo[bdev].bd_drv = 0x%02x\n",
    263 		    bi1->bi_devinfo[bdev].bd_drv);
    264 		printf("bi1->bi_devinfo[bdev].bd_part = 0x%02x\n",
    265 		    bi1->bi_devinfo[bdev].bd_part);
    266 #endif
    267 	} else {
    268 		const struct luna2_bootinfo *bi2 = (void *)LUNA2_BOOTINFOADDR;
    269 
    270 		bdev = bi2->bi_device;
    271 		switch (bdev) {
    272 		case LUNA2_BTDEV_DK:
    273 			ctlr = bi2->bi_devinfo[bdev].bd_ctlr;
    274 			id   = bi2->bi_devinfo[bdev].bd_id;
    275 			unit = UNIT(ctlr, id);
    276 			break;
    277 		default:
    278 			/* not supported */
    279 			break;
    280 		}
    281 #ifdef BTINFO_DEBUG
    282 		printf("bi2->bi_device = 0x%02x\n", bi2->bi_device);
    283 		printf("bi2->bi_devinfo[bdev].bd_boot = 0x%02x\n",
    284 		    bi2->bi_devinfo[bdev].bd_boot);
    285 		printf("bi2->bi_devinfo[bdev].bd_name = %s\n",
    286 		    bi2->bi_devinfo[bdev].bd_name);
    287 		printf("bi2->bi_devinfo[bdev].bd_ctlr = 0x%02x\n",
    288 		    bi2->bi_devinfo[bdev].bd_ctlr);
    289 		printf("bi2->bi_devinfo[bdev].bd_id = 0x%02x\n",
    290 		    bi2->bi_devinfo[bdev].bd_id);
    291 		printf("bi2->bi_devinfo[bdev].bd_part = 0x%02x\n",
    292 		    bi2->bi_devinfo[bdev].bd_part);
    293 #endif
    294 	}
    295 
    296 	snprintf(default_file, sizeof(default_file),
    297 	    "%s(%d,%d)%s", bootdev, unit, part, "netbsd");
    298 
    299 	howto = reorder_dipsw(dipsw2);
    300 
    301 	if ((howto & 0xFE) == 0) {
    302 		char c;
    303 
    304 		printf("Press return to boot now,"
    305 		    " any other key for boot menu\n");
    306 		printf("booting %s - starting in ", default_file);
    307 		c = awaitkey("%d seconds. ", boot_timeout, true);
    308 		if (c == '\r' || c == '\n' || c == 0) {
    309 			printf("auto-boot %s\n", default_file);
    310 			bootnetbsd(default_file);
    311 		}
    312 	}
    313 
    314 	/*
    315 	 * Main Loop
    316 	 */
    317 
    318 	printf("type \"help\" for help.\n");
    319 
    320 	do {
    321 		memset(buffer, 0, BUFFSIZE);
    322 		if (getline(prompt, buffer) > 0) {
    323 			argc = getargs(buffer, argv, sizeof(argv)/sizeof(char *));
    324 
    325 			status = parse(argc, argv);
    326 			if (status == ST_NOTFOUND)
    327 				printf("Command \"%s\" is not found !!\n", argv[0]);
    328 		}
    329 	} while(status != ST_EXIT);
    330 
    331 	exit(0);
    332 }
    333 
    334 int
    335 get_plane_numbers(void)
    336 {
    337 	int r = ROM_plane;
    338 	int n = 0;
    339 
    340 	for (; r ; r >>= 1)
    341 		if (r & 0x1)
    342 			n++;
    343 
    344 	return(n);
    345 }
    346 
    347 int
    348 reorder_dipsw(int dipsw)
    349 {
    350 	int i, sw = 0;
    351 
    352 	for (i = 0; i < 8; i++) {
    353 		if ((dipsw & 0x01) == 0)
    354 			sw += 1;
    355 
    356 		if (i == 7)
    357 			break;
    358 
    359 		sw <<= 1;
    360 		dipsw >>= 1;
    361 	}
    362 
    363 	return(sw);
    364 }
    365