Home | History | Annotate | Line # | Download | only in xxboot
bootmain.c revision 1.6
      1  1.6    isaki /*	$NetBSD: bootmain.c,v 1.6 2020/08/14 03:34:22 isaki Exp $	*/
      2  1.1  minoura 
      3  1.1  minoura /*-
      4  1.1  minoura  * Copyright (c) 1993, 1994 Takumi Nakamura.
      5  1.1  minoura  * Copyright (c) 1999, 2000 Itoh Yasufumi.
      6  1.1  minoura  * Copyright (c) 2001 Minoura Makoto.
      7  1.1  minoura  *
      8  1.1  minoura  * Redistribution and use in source and binary forms, with or without
      9  1.1  minoura  * modification, are permitted provided that the following conditions
     10  1.1  minoura  * are met:
     11  1.1  minoura  * 1. Redistributions of source code must retain the above copyright
     12  1.1  minoura  *    notice, this list of conditions and the following disclaimer.
     13  1.1  minoura  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  minoura  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  minoura  *    documentation and/or other materials provided with the distribution.
     16  1.1  minoura  * 3. All advertising materials mentioning features or use of this software
     17  1.1  minoura  *    must display the following acknowledgement:
     18  1.1  minoura  *	This product includes software developed by Takumi Nakamura.
     19  1.1  minoura  * 4. Neither the name of the University nor the names of its contributors
     20  1.1  minoura  *    may be used to endorse or promote products derived from this software
     21  1.1  minoura  *    without specific prior written permission.
     22  1.1  minoura  *
     23  1.1  minoura  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.1  minoura  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.1  minoura  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.1  minoura  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.1  minoura  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.1  minoura  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.1  minoura  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.1  minoura  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.1  minoura  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.1  minoura  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.1  minoura  * SUCH DAMAGE.
     34  1.1  minoura  */
     35  1.1  minoura 
     36  1.1  minoura #include <sys/param.h>
     37  1.1  minoura #include <sys/types.h>
     38  1.1  minoura #include <machine/bootinfo.h>
     39  1.1  minoura #include <lib/libsa/stand.h>
     40  1.1  minoura #include <lib/libsa/loadfile.h>
     41  1.1  minoura 
     42  1.6    isaki #include "xxboot.h"
     43  1.1  minoura #include "libx68k.h"
     44  1.1  minoura #include "iocs.h"
     45  1.1  minoura #include "exec_image.h"
     46  1.1  minoura 
     47  1.2  tsutsui #define EXSCSI_BDID	((void *)0x00ea0001)
     48  1.1  minoura 
     49  1.1  minoura /* for debug */
     50  1.1  minoura unsigned int startregs[16];
     51  1.1  minoura 
     52  1.2  tsutsui static int get_scsi_host_adapter(char *);
     53  1.2  tsutsui void bootmain(void) __attribute__ ((__noreturn__));
     54  1.1  minoura 
     55  1.1  minoura /*
     56  1.1  minoura  * Check the type of SCSI interface
     57  1.1  minoura  */
     58  1.1  minoura static int
     59  1.2  tsutsui get_scsi_host_adapter(char *devstr)
     60  1.1  minoura {
     61  1.2  tsutsui 	uint8_t *bootrom;
     62  1.1  minoura 	int ha;
     63  1.1  minoura 
     64  1.4  tsutsui #ifdef XXBOOT_DEBUG
     65  1.2  tsutsui 	*(uint32_t *)(devstr +  0) = '/' << 24 | 's' << 16 | 'p' << 8 | 'c';
     66  1.4  tsutsui #if defined(CDBOOT)
     67  1.2  tsutsui 	*(uint32_t *)(devstr +  4) = '@' << 24 | '0' << 16 | '/' << 8 | 'c';
     68  1.4  tsutsui #else
     69  1.4  tsutsui 	*(uint32_t *)(devstr +  4) = '@' << 24 | '0' << 16 | '/' << 8 | 's';
     70  1.4  tsutsui #endif
     71  1.2  tsutsui 	*(uint32_t *)(devstr +  8) = 'd' << 24 | '@' << 16 | '0' << 8 | ',';
     72  1.2  tsutsui 	*(uint32_t *)(devstr + 12) = '0' << 24 | ':' << 16 | 'a' << 8 | '\0';
     73  1.4  tsutsui #endif
     74  1.1  minoura 
     75  1.2  tsutsui 	bootrom = (uint8_t *)(BOOT_INFO & 0x00ffffe0);
     76  1.1  minoura 	/*
     77  1.1  minoura 	 * bootrom+0x24	"SCSIIN" ... Internal SCSI (spc@0)
     78  1.1  minoura 	 *		"SCSIEX" ... External SCSI (spc@1 or mha@0)
     79  1.1  minoura 	 */
     80  1.2  tsutsui 	if (*(uint16_t *)(bootrom + 0x24 + 4) == 0x494e) {	/* "IN" */
     81  1.1  minoura 		ha = (X68K_BOOT_SCSIIF_SPC << 4) | 0;
     82  1.1  minoura 	} else if (badbaddr(EXSCSI_BDID)) {
     83  1.1  minoura 		ha = (X68K_BOOT_SCSIIF_MHA << 4) | 0;
     84  1.4  tsutsui #ifdef XXBOOT_DEBUG
     85  1.2  tsutsui 		*(uint32_t *)devstr = '/' << 24 | 'm' << 16 | 'h' << 8 | 'a';
     86  1.4  tsutsui #endif
     87  1.1  minoura 	} else {
     88  1.1  minoura 		ha = (X68K_BOOT_SCSIIF_SPC << 4) | 1;
     89  1.4  tsutsui #ifdef XXBOOT_DEBUG
     90  1.1  minoura 		devstr[5] = '1';
     91  1.4  tsutsui #endif
     92  1.1  minoura 	}
     93  1.1  minoura 
     94  1.1  minoura 	return ha;
     95  1.1  minoura }
     96  1.1  minoura 
     97  1.1  minoura void
     98  1.1  minoura bootmain(void)
     99  1.1  minoura {
    100  1.1  minoura 	int bootdev, ha, fd;
    101  1.1  minoura 	char bootdevstr[16];
    102  1.1  minoura 	u_long marks[MARK_MAX];
    103  1.1  minoura 
    104  1.4  tsutsui 	IOCS_B_PRINT(bootprog_name);
    105  1.4  tsutsui 	IOCS_B_PRINT(" rev.");
    106  1.4  tsutsui 	IOCS_B_PRINT(bootprog_rev);
    107  1.4  tsutsui 	IOCS_B_PRINT("\r\n");
    108  1.1  minoura 
    109  1.1  minoura 	ha = get_scsi_host_adapter(bootdevstr);
    110  1.4  tsutsui #ifdef XXBOOT_DEBUG
    111  1.1  minoura 	bootdevstr[10] = '0' + (ID & 7);
    112  1.1  minoura 	bootdevstr[14] = 'a';
    113  1.4  tsutsui #endif
    114  1.4  tsutsui 
    115  1.4  tsutsui #if defined(CDBOOT)
    116  1.1  minoura 	bootdev = X68K_MAKESCSIBOOTDEV(X68K_MAJOR_CD, ha >> 4, ha & 15,
    117  1.1  minoura 				       ID & 7, 0, 0);
    118  1.4  tsutsui #elif defined(FDBOOT) || defined(SDBOOT)
    119  1.4  tsutsui 	if (BINF_ISFD(&BOOT_INFO)) {
    120  1.4  tsutsui 		/* floppy */
    121  1.4  tsutsui #ifdef XXBOOT_DEBUG
    122  1.4  tsutsui 		*(uint32_t *)bootdevstr =
    123  1.5    isaki 		    ('f' << 24) | ('d' << 16) | ('@' << 8) |
    124  1.5    isaki 		    ('0' + (BOOT_INFO & 3));
    125  1.4  tsutsui 		bootdevstr[4] = '\0';
    126  1.4  tsutsui #endif
    127  1.4  tsutsui 		/* fdNa for 1024 bytes/sector, fdNc for 512 bytes/sector */
    128  1.4  tsutsui 		bootdev = X68K_MAKEBOOTDEV(X68K_MAJOR_FD, BOOT_INFO & 3,
    129  1.4  tsutsui 		    (FDSECMINMAX.minsec.N == 3) ? 0 : 2);
    130  1.4  tsutsui 	} else {
    131  1.4  tsutsui 		/* SCSI */
    132  1.4  tsutsui 		bootdev = X68K_MAKESCSIBOOTDEV(X68K_MAJOR_SD, ha >> 4, ha & 15,
    133  1.4  tsutsui 		    ID & 7, 0, 0 /* XXX: assume partition a */);
    134  1.4  tsutsui 	}
    135  1.4  tsutsui #else
    136  1.4  tsutsui 	bootdev = 0;
    137  1.4  tsutsui #endif
    138  1.4  tsutsui 
    139  1.4  tsutsui #ifdef XXBOOT_DEBUG
    140  1.4  tsutsui 	IOCS_B_PRINT("boot device: ");
    141  1.4  tsutsui 	IOCS_B_PRINT(bootdevstr);
    142  1.1  minoura #endif
    143  1.4  tsutsui 	IOCS_B_PRINT("\r\n");
    144  1.1  minoura 
    145  1.1  minoura 	marks[MARK_START] = BOOT_TEXTADDR;
    146  1.1  minoura 	fd = loadfile("x68k/boot", marks, LOAD_TEXT|LOAD_DATA|LOAD_BSS);
    147  1.1  minoura 	if (fd < 0)
    148  1.1  minoura 		fd = loadfile("boot", marks, LOAD_TEXT|LOAD_DATA|LOAD_BSS);
    149  1.1  minoura 	if (fd >= 0) {
    150  1.1  minoura 		close(fd);
    151  1.1  minoura 		exec_image(BOOT_TEXTADDR, /* image loaded at */
    152  1.1  minoura 			   BOOT_TEXTADDR, /* image executed at */
    153  1.1  minoura 			   BOOT_TEXTADDR, /* XXX: entry point */
    154  1.1  minoura 			   0, 		  /* XXX: image size */
    155  1.1  minoura 			   bootdev, 0);	  /* arguments */
    156  1.1  minoura 	}
    157  1.1  minoura 	IOCS_B_PRINT("can't load the secondary bootstrap.");
    158  1.1  minoura 	exit(0);
    159  1.1  minoura }
    160  1.1  minoura 
    161  1.1  minoura int
    162  1.1  minoura devopen(struct open_file *f, const char *fname, char **file)
    163  1.1  minoura {
    164  1.2  tsutsui 
    165  1.3  tsutsui 	*file = __UNCONST(fname);
    166  1.1  minoura 	return xxopen(f);
    167  1.1  minoura }
    168