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