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