Home | History | Annotate | Line # | Download | only in xxboot
bootmain.c revision 1.4.2.2
      1 /*	$NetBSD: bootmain.c,v 1.4.2.2 2012/11/18 19:05:17 riz 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_cd9660.S */
     49 extern int badbaddr __P((volatile void *adr));
     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(devstr)
     64 	char *devstr;
     65 {
     66 	char *bootrom;
     67 	int ha;
     68 
     69 	*(int *)devstr = '/' << 24 | 's' << 16 | 'p' << 8 | 'c';
     70 	*(int *)(devstr + 4) = '@' << 24 | '0' << 16 | '/' << 8 | 'c';
     71 	*(int *)(devstr + 8) = 'd' << 24 | '@' << 16 | '0' << 8 | ',';
     72 	*(int *)(devstr + 12) = '0' << 24 | ':' << 16 | 'a' << 8 | '\0';
     73 
     74 	bootrom = (char *) (BOOT_INFO & 0x00ffffe0);
     75 	/*
     76 	 * bootrom+0x24	"SCSIIN" ... Internal SCSI (spc@0)
     77 	 *		"SCSIEX" ... External SCSI (spc@1 or mha@0)
     78 	 */
     79 	if (*(u_short *)(bootrom + 0x24 + 4) == 0x494e) {	/* "IN" */
     80 		ha = (X68K_BOOT_SCSIIF_SPC << 4) | 0;
     81 	} else if (badbaddr(EXSCSI_BDID)) {
     82 		ha = (X68K_BOOT_SCSIIF_MHA << 4) | 0;
     83 		*(int *)devstr = '/' << 24 | 'm' << 16 | 'h' << 8 | 'a';
     84 	} else {
     85 		ha = (X68K_BOOT_SCSIIF_SPC << 4) | 1;
     86 		devstr[5] = '1';
     87 	}
     88 
     89 	return ha;
     90 }
     91 
     92 extern const char bootprog_name[], bootprog_rev[];
     93 
     94 void
     95 bootmain(void)
     96 {
     97 	int bootdev, ha, fd;
     98 	char bootdevstr[16];
     99 	u_long marks[MARK_MAX];
    100 
    101 #ifdef DEBUG
    102 	printf("%s rev.%s\n", bootprog_name, bootprog_rev);
    103 #endif
    104 
    105 	ha = get_scsi_host_adapter(bootdevstr);
    106 	bootdevstr[10] = '0' + (ID & 7);
    107 	bootdevstr[14] = 'a';
    108 	bootdev = X68K_MAKESCSIBOOTDEV(X68K_MAJOR_CD, ha >> 4, ha & 15,
    109 				       ID & 7, 0, 0);
    110 #ifdef DEBUG
    111 	printf(" boot device: %s\n", bootdevstr);
    112 #endif
    113 
    114 	marks[MARK_START] = BOOT_TEXTADDR;
    115 	fd = loadfile("x68k/boot", marks, LOAD_TEXT|LOAD_DATA|LOAD_BSS);
    116 	if (fd < 0)
    117 		fd = loadfile("boot", marks, LOAD_TEXT|LOAD_DATA|LOAD_BSS);
    118 	if (fd >= 0) {
    119 		close(fd);
    120 		exec_image(BOOT_TEXTADDR, /* image loaded at */
    121 			   BOOT_TEXTADDR, /* image executed at */
    122 			   BOOT_TEXTADDR, /* XXX: entry point */
    123 			   0, 		  /* XXX: image size */
    124 			   bootdev, 0);	  /* arguments */
    125 	}
    126 	IOCS_B_PRINT("can't load the secondary bootstrap.");
    127 	exit(0);
    128 }
    129 
    130 extern int xxboot(struct open_file *);
    131 int
    132 devopen(struct open_file *f, const char *fname, char **file)
    133 {
    134 	return xxopen(f);
    135 }
    136