init_main.c revision 1.16 1 /* $NetBSD: init_main.c,v 1.16 2015/02/14 13:07:39 tsutsui Exp $ */
2
3 /*
4 * Copyright (c) 1992 OMRON Corporation.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * OMRON Corporation.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 * @(#)init_main.c 8.2 (Berkeley) 8/15/93
38 */
39 /*
40 * Copyright (c) 1992, 1993
41 * The Regents of the University of California. All rights reserved.
42 *
43 * This code is derived from software contributed to Berkeley by
44 * OMRON Corporation.
45 *
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
48 * are met:
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. Neither the name of the University nor the names of its contributors
55 * may be used to endorse or promote products derived from this software
56 * without specific prior written permission.
57 *
58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE.
69 *
70 * @(#)init_main.c 8.2 (Berkeley) 8/15/93
71 */
72
73 #include <sys/param.h>
74 #include <sys/boot_flag.h>
75 #include <machine/cpu.h>
76 #include <luna68k/stand/boot/samachdep.h>
77 #include <luna68k/stand/boot/romvec.h>
78 #include <luna68k/stand/boot/status.h>
79 #include <lib/libsa/loadfile.h>
80 #ifdef SUPPORT_ETHERNET
81 #include <lib/libsa/dev_net.h>
82 #endif
83
84 static int get_plane_numbers(void);
85 static int reorder_dipsw(int);
86
87 int cpuspeed; /* for DELAY() macro */
88 int hz = 60;
89 int machtype;
90 char default_file[64];
91 const char *default_bootdev;
92 int default_unit;
93
94 #define VERS_LOCAL "Phase-31"
95
96 int nplane;
97
98 /* for command parser */
99
100 #define BUFFSIZE 100
101 #define MAXARGS 30
102
103 char buffer[BUFFSIZE];
104
105 int argc;
106 char *argv[MAXARGS];
107
108 #define BOOT_TIMEOUT 10
109 int boot_timeout = BOOT_TIMEOUT;
110
111 static const char prompt[] = "boot> ";
112
113 /*
114 * PROM monitor's boot device info
115 */
116
117 /* LUNA-I monitor's bootinfo structure */
118 /* This bootinfo data address is investigated on ROM Ver4.22 and Ver4.25 */
119 #define LUNA1_BOOTINFOADDR 0x000008c0
120 struct luna1_bootinfo {
121 uint8_t bi_xxx1[3]; /* 0x08c0: ??? */
122 uint8_t bi_device; /* 0x08c3: boot device */
123 #define LUNA1_BTDEV_DK 0 /* Hard-Disk */
124 #define LUNA1_BTDEV_FB 1 /* Floppy-Disk */
125 #define LUNA1_BTDEV_SD 2 /* Streamer-Tape */
126 #define LUNA1_BTDEV_P0 3 /* RS232c */
127 #define LUNA1_BTDEV_ET 4 /* Ether-net */
128 #define LUNA1_NBTDEV 5
129
130 struct {
131 uint8_t bd_xxx1; /* 0: ??? */
132 uint8_t bd_boot; /* 1: 1 == booted */
133 char bd_name[2]; /* 2: device name (dk, fb, sd ... ) */
134 uint8_t bd_drv; /* 4: drive number (not ID) */
135 uint8_t bd_xxx2; /* 5: ??? */
136 uint8_t bd_xxx3; /* 6: ??? */
137 uint8_t bd_part; /* 7: dk partition / st record # */
138 uint8_t bd_xxx4[4]; /* 8: ??? */
139 uint8_t bd_xxx5[4]; /* 12: ??? */
140 } bi_devinfo[LUNA1_NBTDEV];
141 } __packed;
142
143 /* LUNA-II monitor's bootinfo structure */
144 /* This bootinfo data address is investigated on ROM Version 1.11 */
145 #define LUNA2_BOOTINFOADDR 0x00001d80
146 struct luna2_bootinfo {
147 uint8_t bi_xxx1[13]; /* 0x1d80: ??? */
148 uint8_t bi_device; /* 0x1d8d: boot device */
149 #define LUNA2_BTDEV_DK 0 /* Hard-Disk */
150 #define LUNA2_BTDEV_FT 1 /* Floppy-Disk */
151 #define LUNA2_BTDEV_SD 2 /* Streamer-Tape */
152 #define LUNA2_BTDEV_P0 3 /* RS232c */
153 #define LUNA2_NBTDEV 4
154
155 struct {
156 uint8_t bd_xxx1; /* 0: ??? */
157 uint8_t bd_boot; /* 1: 1 == booted */
158 char bd_name[4]; /* 2: device name (dk, ft, sd ... ) */
159 uint8_t bd_xxx2; /* 6: ??? */
160 uint8_t bd_ctlr; /* 7: SCSI controller number */
161 uint8_t bd_id; /* 8: SCSI ID number */
162 uint8_t bd_xxx3; /* 9: device number index? */
163 uint8_t bd_xxx4; /* 10: ??? */
164 uint8_t bd_part; /* 11: dk partition / st record # */
165 uint8_t bd_xxx5[4]; /* 12: ??? */
166 uint8_t bd_xxx6[4]; /* 16: ??? */
167 } bi_devinfo[LUNA2_NBTDEV];
168 } __packed;
169
170 /* #define BTINFO_DEBUG */
171
172 void
173 main(void)
174 {
175 int i, status = ST_NORMAL;
176 const char *machstr;
177 const char *bootdev;
178 uint32_t howto;
179 int unit, part;
180 int bdev, ctlr, id;
181
182 /*
183 * Initialize the console before we print anything out.
184 */
185 if (cputype == CPU_68030) {
186 machtype = LUNA_I;
187 machstr = "LUNA-I";
188 cpuspeed = MHZ_25;
189 hz = 60;
190 } else {
191 machtype = LUNA_II;
192 machstr = "LUNA-II";
193 cpuspeed = MHZ_25 * 2; /* XXX */
194 hz = 100;
195 }
196
197 nplane = get_plane_numbers();
198
199 cninit();
200
201 printf("\n");
202 printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
203 printf(">> (based on Stinger ver 0.0 [%s])\n", VERS_LOCAL);
204 printf("\n");
205
206 i = ROM_memsize;
207 printf("Machine model = %s\n", machstr);
208 printf("Physical Memory = 0x%x ", i);
209 i >>= 20;
210 printf("(%d MB)\n", i);
211 printf("\n");
212
213 /*
214 * IO configuration
215 */
216
217 #ifdef SUPPORT_ETHERNET
218 try_bootp = 1;
219 #endif
220
221 find_devs();
222 printf("\n");
223
224 /* use sd(0,0) for the default boot device */
225 bootdev = "sd";
226 unit = 0;
227 part = 0;
228
229 if (machtype == LUNA_I) {
230 const struct luna1_bootinfo *bi1 = (void *)LUNA1_BOOTINFOADDR;
231
232 bdev = bi1->bi_device;
233 switch (bdev) {
234 case LUNA1_BTDEV_DK:
235 /* note: bd_drv is not SCSI ID */
236 ctlr = 0;
237 id = 6 - bi1->bi_devinfo[bdev].bd_drv;
238 unit = UNIT(ctlr, id);
239 break;
240 case LUNA1_BTDEV_ET:
241 bootdev = "le";
242 unit = 0;
243 break;
244 default:
245 /* not supported */
246 break;
247 }
248 #ifdef BTINFO_DEBUG
249 printf("bi1->bi_device = 0x%02x\n", bi1->bi_device);
250 printf("bi1->bi_devinfo[bdev].bd_boot = 0x%02x\n",
251 bi1->bi_devinfo[bdev].bd_boot);
252 printf("bi1->bi_devinfo[bdev].bd_name = %c%c\n",
253 bi1->bi_devinfo[bdev].bd_name[0],
254 bi1->bi_devinfo[bdev].bd_name[1]);
255 printf("bi1->bi_devinfo[bdev].bd_drv = 0x%02x\n",
256 bi1->bi_devinfo[bdev].bd_drv);
257 printf("bi1->bi_devinfo[bdev].bd_part = 0x%02x\n",
258 bi1->bi_devinfo[bdev].bd_part);
259 #endif
260 } else {
261 const struct luna2_bootinfo *bi2 = (void *)LUNA2_BOOTINFOADDR;
262
263 bdev = bi2->bi_device;
264 switch (bdev) {
265 case LUNA2_BTDEV_DK:
266 ctlr = bi2->bi_devinfo[bdev].bd_ctlr;
267 id = bi2->bi_devinfo[bdev].bd_id;
268 unit = UNIT(ctlr, id);
269 break;
270 default:
271 /* not supported */
272 break;
273 }
274 #ifdef BTINFO_DEBUG
275 printf("bi2->bi_device = 0x%02x\n", bi2->bi_device);
276 printf("bi2->bi_devinfo[bdev].bd_boot = 0x%02x\n",
277 bi2->bi_devinfo[bdev].bd_boot);
278 printf("bi2->bi_devinfo[bdev].bd_name = %s\n",
279 bi2->bi_devinfo[bdev].bd_name);
280 printf("bi2->bi_devinfo[bdev].bd_ctlr = 0x%02x\n",
281 bi2->bi_devinfo[bdev].bd_ctlr);
282 printf("bi2->bi_devinfo[bdev].bd_id = 0x%02x\n",
283 bi2->bi_devinfo[bdev].bd_id);
284 printf("bi2->bi_devinfo[bdev].bd_part = 0x%02x\n",
285 bi2->bi_devinfo[bdev].bd_part);
286 #endif
287 }
288
289 snprintf(default_file, sizeof(default_file),
290 "%s(%d,%d)%s", bootdev, unit, part, "netbsd");
291 default_bootdev = bootdev;
292 default_unit = unit;
293
294 howto = reorder_dipsw(dipsw2);
295
296 if ((howto & 0xFE) == 0) {
297 char c;
298
299 printf("Press return to boot now,"
300 " any other key for boot menu\n");
301 printf("booting %s - starting in ", default_file);
302 c = awaitkey("%d seconds. ", boot_timeout, true);
303 if (c == '\r' || c == '\n' || c == 0) {
304 printf("auto-boot %s\n", default_file);
305 bootnetbsd(default_file, 0);
306 }
307 }
308
309 /*
310 * Main Loop
311 */
312
313 printf("type \"help\" for help.\n");
314
315 do {
316 memset(buffer, 0, BUFFSIZE);
317 if (getline(prompt, buffer) > 0) {
318 argc = getargs(buffer, argv,
319 sizeof(argv) / sizeof(char *));
320
321 status = parse(argc, argv);
322 if (status == ST_NOTFOUND)
323 printf("Command \"%s\" is not found !!\n",
324 argv[0]);
325 }
326 } while (status != ST_EXIT);
327
328 exit(0);
329 }
330
331 static int
332 get_plane_numbers(void)
333 {
334 int r = ROM_plane;
335 int n = 0;
336
337 for (; r ; r >>= 1)
338 if (r & 0x1)
339 n++;
340
341 return n;
342 }
343
344 static int
345 reorder_dipsw(int dipsw)
346 {
347 int i, sw = 0;
348
349 for (i = 0; i < 8; i++) {
350 if ((dipsw & 0x01) == 0)
351 sw += 1;
352
353 if (i == 7)
354 break;
355
356 sw <<= 1;
357 dipsw >>= 1;
358 }
359
360 return sw;
361 }
362