bootmain.c revision 1.6 1 /* $NetBSD: bootmain.c,v 1.6 2020/08/14 03:34:22 isaki 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 "xxboot.h"
43 #include "libx68k.h"
44 #include "iocs.h"
45 #include "exec_image.h"
46
47 #define EXSCSI_BDID ((void *)0x00ea0001)
48
49 /* for debug */
50 unsigned int startregs[16];
51
52 static int get_scsi_host_adapter(char *);
53 void bootmain(void) __attribute__ ((__noreturn__));
54
55 /*
56 * Check the type of SCSI interface
57 */
58 static int
59 get_scsi_host_adapter(char *devstr)
60 {
61 uint8_t *bootrom;
62 int ha;
63
64 #ifdef XXBOOT_DEBUG
65 *(uint32_t *)(devstr + 0) = '/' << 24 | 's' << 16 | 'p' << 8 | 'c';
66 #if defined(CDBOOT)
67 *(uint32_t *)(devstr + 4) = '@' << 24 | '0' << 16 | '/' << 8 | 'c';
68 #else
69 *(uint32_t *)(devstr + 4) = '@' << 24 | '0' << 16 | '/' << 8 | 's';
70 #endif
71 *(uint32_t *)(devstr + 8) = 'd' << 24 | '@' << 16 | '0' << 8 | ',';
72 *(uint32_t *)(devstr + 12) = '0' << 24 | ':' << 16 | 'a' << 8 | '\0';
73 #endif
74
75 bootrom = (uint8_t *)(BOOT_INFO & 0x00ffffe0);
76 /*
77 * bootrom+0x24 "SCSIIN" ... Internal SCSI (spc@0)
78 * "SCSIEX" ... External SCSI (spc@1 or mha@0)
79 */
80 if (*(uint16_t *)(bootrom + 0x24 + 4) == 0x494e) { /* "IN" */
81 ha = (X68K_BOOT_SCSIIF_SPC << 4) | 0;
82 } else if (badbaddr(EXSCSI_BDID)) {
83 ha = (X68K_BOOT_SCSIIF_MHA << 4) | 0;
84 #ifdef XXBOOT_DEBUG
85 *(uint32_t *)devstr = '/' << 24 | 'm' << 16 | 'h' << 8 | 'a';
86 #endif
87 } else {
88 ha = (X68K_BOOT_SCSIIF_SPC << 4) | 1;
89 #ifdef XXBOOT_DEBUG
90 devstr[5] = '1';
91 #endif
92 }
93
94 return ha;
95 }
96
97 void
98 bootmain(void)
99 {
100 int bootdev, ha, fd;
101 char bootdevstr[16];
102 u_long marks[MARK_MAX];
103
104 IOCS_B_PRINT(bootprog_name);
105 IOCS_B_PRINT(" rev.");
106 IOCS_B_PRINT(bootprog_rev);
107 IOCS_B_PRINT("\r\n");
108
109 ha = get_scsi_host_adapter(bootdevstr);
110 #ifdef XXBOOT_DEBUG
111 bootdevstr[10] = '0' + (ID & 7);
112 bootdevstr[14] = 'a';
113 #endif
114
115 #if defined(CDBOOT)
116 bootdev = X68K_MAKESCSIBOOTDEV(X68K_MAJOR_CD, ha >> 4, ha & 15,
117 ID & 7, 0, 0);
118 #elif defined(FDBOOT) || defined(SDBOOT)
119 if (BINF_ISFD(&BOOT_INFO)) {
120 /* floppy */
121 #ifdef XXBOOT_DEBUG
122 *(uint32_t *)bootdevstr =
123 ('f' << 24) | ('d' << 16) | ('@' << 8) |
124 ('0' + (BOOT_INFO & 3));
125 bootdevstr[4] = '\0';
126 #endif
127 /* fdNa for 1024 bytes/sector, fdNc for 512 bytes/sector */
128 bootdev = X68K_MAKEBOOTDEV(X68K_MAJOR_FD, BOOT_INFO & 3,
129 (FDSECMINMAX.minsec.N == 3) ? 0 : 2);
130 } else {
131 /* SCSI */
132 bootdev = X68K_MAKESCSIBOOTDEV(X68K_MAJOR_SD, ha >> 4, ha & 15,
133 ID & 7, 0, 0 /* XXX: assume partition a */);
134 }
135 #else
136 bootdev = 0;
137 #endif
138
139 #ifdef XXBOOT_DEBUG
140 IOCS_B_PRINT("boot device: ");
141 IOCS_B_PRINT(bootdevstr);
142 #endif
143 IOCS_B_PRINT("\r\n");
144
145 marks[MARK_START] = BOOT_TEXTADDR;
146 fd = loadfile("x68k/boot", marks, LOAD_TEXT|LOAD_DATA|LOAD_BSS);
147 if (fd < 0)
148 fd = loadfile("boot", marks, LOAD_TEXT|LOAD_DATA|LOAD_BSS);
149 if (fd >= 0) {
150 close(fd);
151 exec_image(BOOT_TEXTADDR, /* image loaded at */
152 BOOT_TEXTADDR, /* image executed at */
153 BOOT_TEXTADDR, /* XXX: entry point */
154 0, /* XXX: image size */
155 bootdev, 0); /* arguments */
156 }
157 IOCS_B_PRINT("can't load the secondary bootstrap.");
158 exit(0);
159 }
160
161 int
162 devopen(struct open_file *f, const char *fname, char **file)
163 {
164
165 *file = __UNCONST(fname);
166 return xxopen(f);
167 }
168