Home | History | Annotate | Line # | Download | only in boot
init_main.c revision 1.11
      1 /*	$NetBSD: init_main.c,v 1.11 2014/01/11 14:09:13 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 /* for command parser */
     98 
     99 #define BUFFSIZE 100
    100 #define MAXARGS  30
    101 
    102 char buffer[BUFFSIZE];
    103 
    104 int   argc;
    105 char *argv[MAXARGS];
    106 
    107 #define BOOT_TIMEOUT 10
    108 int boot_timeout = BOOT_TIMEOUT;
    109 
    110 static const char prompt[] = "boot> ";
    111 
    112 /*
    113  * PROM monitor's boot device info
    114  */
    115 
    116 /* LUNA-I monitor's bootinfo structure */
    117 /* This bootinfo data address is investigated on ROM Ver4.22 and Ver4.25 */
    118 #define	LUNA1_BOOTINFOADDR	0x000008c0
    119 struct luna1_bootinfo {
    120 	uint8_t	bi_xxx1[3];	/* 0x08c0: ??? */
    121 	uint8_t	bi_device;	/* 0x08c3: boot device */
    122 #define	LUNA1_BTDEV_DK	0		/* Hard-Disk */
    123 #define	LUNA1_BTDEV_FB	1		/* Floppy-Disk */
    124 #define	LUNA1_BTDEV_SD	2		/* Streamer-Tape */
    125 #define	LUNA1_BTDEV_P0	3		/* RS232c */
    126 #define	LUNA1_BTDEV_ET	4		/* Ether-net */
    127 #define	LUNA1_NBTDEV	5
    128 
    129 	struct {
    130 		uint8_t	bd_xxx1;	/*  0: ??? */
    131 		uint8_t	bd_boot;	/*  1: 1 == booted */
    132 		char	bd_name[2];	/*  2: device name (dk, fb, sd ... ) */
    133 		uint8_t	bd_drv;		/*  4: drive number (not ID) */
    134 		uint8_t	bd_xxx2;	/*  5: ??? */
    135 		uint8_t	bd_xxx3;	/*  6: ??? */
    136 		uint8_t	bd_part;	/*  7: dk partition / st record # */
    137 		uint8_t	bd_xxx4[4];	/*  8: ??? */
    138 		uint8_t	bd_xxx5[4];	/* 12: ??? */
    139 	} bi_devinfo[LUNA1_NBTDEV];
    140 } __packed;
    141 
    142 /* LUNA-II monitor's bootinfo structure */
    143 /* This bootinfo data address is investigated on ROM Version 1.11 */
    144 #define	LUNA2_BOOTINFOADDR	0x00001d80
    145 struct luna2_bootinfo {
    146 	uint8_t	bi_xxx1[13];	/* 0x1d80: ??? */
    147 	uint8_t	bi_device;	/* 0x1d8d: boot device */
    148 #define	LUNA2_BTDEV_DK	0		/* Hard-Disk */
    149 #define	LUNA2_BTDEV_FT	1		/* Floppy-Disk */
    150 #define	LUNA2_BTDEV_SD	2		/* Streamer-Tape */
    151 #define	LUNA2_BTDEV_P0	3		/* RS232c */
    152 #define	LUNA2_NBTDEV	4
    153 
    154 	struct {
    155 		uint8_t	bd_xxx1;	/*  0: ??? */
    156 		uint8_t	bd_boot;	/*  1: 1 == booted */
    157 		char	bd_name[4];	/*  2: device name (dk, ft, sd ... ) */
    158 		uint8_t	bd_xxx2;	/*  6: ??? */
    159 		uint8_t	bd_ctlr;	/*  7: SCSI controller number */
    160 		uint8_t	bd_id;		/*  8: SCSI ID number */
    161 		uint8_t	bd_xxx3;	/*  9: device number index? */
    162 		uint8_t	bd_xxx4;	/* 10: ??? */
    163 		uint8_t	bd_part;	/* 11: dk partition / st record # */
    164 		uint8_t	bd_xxx5[4];	/* 12: ??? */
    165 		uint8_t	bd_xxx6[4];	/* 16: ??? */
    166 	} bi_devinfo[LUNA2_NBTDEV];
    167 } __packed;
    168 
    169 /* #define BTINFO_DEBUG */
    170 
    171 void
    172 main(void)
    173 {
    174 	int i, status = 0;
    175 	const char *machstr;
    176 	const char *bootdev;
    177 	uint32_t howto;
    178 	int unit, part;
    179 	int bdev, ctlr, id;
    180 
    181 	/*
    182 	 * Initialize the console before we print anything out.
    183 	 */
    184 	if (cputype == CPU_68030) {
    185 		machtype = LUNA_I;
    186 		machstr  = "LUNA-I";
    187 		cpuspeed = MHZ_25;
    188 		hz = 60;
    189 	} else {
    190 		machtype = LUNA_II;
    191 		machstr  = "LUNA-II";
    192 		cpuspeed = MHZ_25 * 2;	/* XXX */
    193 		hz = 100;
    194 	}
    195 
    196 	nplane   = get_plane_numbers();
    197 
    198 	cninit();
    199 
    200 	printf("\n");
    201 	printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
    202 	printf(">> (based on Stinger ver 0.0 [%s])\n", VERS_LOCAL);
    203 	printf("\n");
    204 
    205 	i = ROM_memsize;
    206 	printf("Machine model   = %s\n", machstr);
    207 	printf("Physical Memory = 0x%x  ", i);
    208 	i >>= 20;
    209 	printf("(%d MB)\n", i);
    210 	printf("\n");
    211 
    212 	/*
    213 	 * IO configuration
    214 	 */
    215 
    216 #ifdef SUPPORT_ETHERNET
    217 	try_bootp = 1;
    218 #endif
    219 
    220 	find_devs();
    221 	printf("\n");
    222 
    223 	/* use sd(0,0) for the default boot device */
    224 	bootdev = "sd";
    225 	unit = 0;
    226 	part = 0;
    227 
    228 	if (machtype == LUNA_I) {
    229 		const struct luna1_bootinfo *bi1 = (void *)LUNA1_BOOTINFOADDR;
    230 
    231 		bdev = bi1->bi_device;
    232 		switch (bdev) {
    233 		case LUNA1_BTDEV_DK:
    234 			/* note: bd_drv is not SCSI ID */
    235 			ctlr = 0;
    236 			id   = 6 - bi1->bi_devinfo[bdev].bd_drv;
    237 			unit = UNIT(ctlr, id);
    238 			break;
    239 		case LUNA1_BTDEV_ET:
    240 			bootdev = "le";
    241 			unit = 0;
    242 			break;
    243 		default:
    244 			/* not supported */
    245 			break;
    246 		}
    247 #ifdef BTINFO_DEBUG
    248 		printf("bi1->bi_device = 0x%02x\n", bi1->bi_device);
    249 		printf("bi1->bi_devinfo[bdev].bd_boot = 0x%02x\n",
    250 		    bi1->bi_devinfo[bdev].bd_boot);
    251 		printf("bi1->bi_devinfo[bdev].bd_name = %c%c\n",
    252 		    bi1->bi_devinfo[bdev].bd_name[0],
    253 		    bi1->bi_devinfo[bdev].bd_name[1]);
    254 		printf("bi1->bi_devinfo[bdev].bd_drv = 0x%02x\n",
    255 		    bi1->bi_devinfo[bdev].bd_drv);
    256 		printf("bi1->bi_devinfo[bdev].bd_part = 0x%02x\n",
    257 		    bi1->bi_devinfo[bdev].bd_part);
    258 #endif
    259 	} else {
    260 		const struct luna2_bootinfo *bi2 = (void *)LUNA2_BOOTINFOADDR;
    261 
    262 		bdev = bi2->bi_device;
    263 		switch (bdev) {
    264 		case LUNA2_BTDEV_DK:
    265 			ctlr = bi2->bi_devinfo[bdev].bd_ctlr;
    266 			id   = bi2->bi_devinfo[bdev].bd_id;
    267 			unit = UNIT(ctlr, id);
    268 			break;
    269 		default:
    270 			/* not supported */
    271 			break;
    272 		}
    273 #ifdef BTINFO_DEBUG
    274 		printf("bi2->bi_device = 0x%02x\n", bi2->bi_device);
    275 		printf("bi2->bi_devinfo[bdev].bd_boot = 0x%02x\n",
    276 		    bi2->bi_devinfo[bdev].bd_boot);
    277 		printf("bi2->bi_devinfo[bdev].bd_name = %s\n",
    278 		    bi2->bi_devinfo[bdev].bd_name);
    279 		printf("bi2->bi_devinfo[bdev].bd_ctlr = 0x%02x\n",
    280 		    bi2->bi_devinfo[bdev].bd_ctlr);
    281 		printf("bi2->bi_devinfo[bdev].bd_id = 0x%02x\n",
    282 		    bi2->bi_devinfo[bdev].bd_id);
    283 		printf("bi2->bi_devinfo[bdev].bd_part = 0x%02x\n",
    284 		    bi2->bi_devinfo[bdev].bd_part);
    285 #endif
    286 	}
    287 
    288 	snprintf(default_file, sizeof(default_file),
    289 	    "%s(%d,%d)%s", bootdev, unit, part, "netbsd");
    290 
    291 	howto = reorder_dipsw(dipsw2);
    292 
    293 	if ((howto & 0xFE) == 0) {
    294 		char c;
    295 
    296 		printf("Press return to boot now,"
    297 		    " any other key for boot menu\n");
    298 		printf("booting %s - starting in ", default_file);
    299 		c = awaitkey("%d seconds. ", boot_timeout, true);
    300 		if (c == '\r' || c == '\n' || c == 0) {
    301 			printf("auto-boot %s\n", default_file);
    302 			bootnetbsd(default_file, 0);
    303 		}
    304 	}
    305 
    306 	/*
    307 	 * Main Loop
    308 	 */
    309 
    310 	printf("type \"help\" for help.\n");
    311 
    312 	do {
    313 		memset(buffer, 0, BUFFSIZE);
    314 		if (getline(prompt, buffer) > 0) {
    315 			argc = getargs(buffer, argv, sizeof(argv)/sizeof(char *));
    316 
    317 			status = parse(argc, argv);
    318 			if (status == ST_NOTFOUND)
    319 				printf("Command \"%s\" is not found !!\n", argv[0]);
    320 		}
    321 	} while(status != ST_EXIT);
    322 
    323 	exit(0);
    324 }
    325 
    326 int
    327 get_plane_numbers(void)
    328 {
    329 	int r = ROM_plane;
    330 	int n = 0;
    331 
    332 	for (; r ; r >>= 1)
    333 		if (r & 0x1)
    334 			n++;
    335 
    336 	return(n);
    337 }
    338 
    339 int
    340 reorder_dipsw(int dipsw)
    341 {
    342 	int i, sw = 0;
    343 
    344 	for (i = 0; i < 8; i++) {
    345 		if ((dipsw & 0x01) == 0)
    346 			sw += 1;
    347 
    348 		if (i == 7)
    349 			break;
    350 
    351 		sw <<= 1;
    352 		dipsw >>= 1;
    353 	}
    354 
    355 	return(sw);
    356 }
    357