boot.c revision 1.2 1 /* $NetBSD: boot.c,v 1.2 2000/02/08 16:17:34 tsutsui Exp $ */
2
3 /*-
4 * Copyright (C) 1999 Izumi Tsutsui. All rights reserved.
5 * Copyright (C) 1999 Tsubai Masanari. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include <lib/libkern/libkern.h>
31 #include <lib/libsa/stand.h>
32 #include <lib/libsa/loadfile.h>
33
34 #include <machine/romcall.h>
35
36 void ICIA __P((void));
37 extern char edata[], end[];
38
39 char *devs[] = { "hd", "fh", "fd", NULL, NULL, "rd", "st" };
40 char *kernels[] = { "/netbsd", "/netbsd.gz", NULL };
41
42 #ifdef BOOT_DEBUG
43 # define DPRINTF printf
44 #else
45 # define DPRINTF while (0) printf
46 #endif
47
48 void
49 boot(d4, d5, d6, d7)
50 int d4, d5, d6, d7;
51 {
52 int fd, i;
53 int ctlr, unit, part, type;
54 int bootdev = d6;
55 char *netbsd = (char *)d5;
56 u_long marks[MARK_MAX];
57 char devname[32], file[32];
58 void (*entry)();
59
60 printf("\n");
61 printf("NetBSD/news68k Secondary Boot\n");
62
63 /* bootname is "boot" by default. */
64 if (netbsd == NULL || strcmp(netbsd, "boot") == 0 ||
65 strcmp(netbsd, "/boot") == 0)
66 netbsd = "";
67
68 DPRINTF("howto = 0x%x\n", d7);
69 DPRINTF("bootdev = 0x%x\n", bootdev);
70 DPRINTF("bootname = %s\n", netbsd);
71 DPRINTF("maxmem = 0x%x\n", d4);
72
73 #define SET_MAGIC(bootdev, magic) ((bootdev & 0x0fffffff)| (magic << 28))
74 /* PROM monitor passes 0xa, but NEWS-OS /boot passed 0x5... */
75 bootdev = SET_MAGIC(bootdev, 5);
76
77 ctlr = BOOTDEV_CTLR(bootdev);
78 unit = BOOTDEV_UNIT(bootdev);
79 part = BOOTDEV_PART(bootdev);
80 type = BOOTDEV_TYPE(bootdev);
81
82 marks[MARK_START] = 0;
83
84 if (devs[type] == NULL) {
85 printf("unknown bootdev (0x%x)\n", bootdev);
86 return;
87 }
88
89 sprintf(devname, "%s(%d,%d,%d)", devs[type], ctlr, unit, part);
90 printf("Booting %s%s\n", devname, netbsd);
91
92 /* use user specified kernel name if exists */
93 if (*netbsd) {
94 kernels[0] = netbsd;
95 kernels[1] = NULL;
96 }
97
98 for (i = 0; kernels[i]; i++) {
99 sprintf(file, "%s%s", devname, kernels[i]);
100 DPRINTF("trying %s...\n", file);
101 fd = loadfile(file, marks, LOAD_KERNEL);
102 if (fd != -1)
103 break;
104 }
105 if (fd == -1)
106 return;
107
108 DPRINTF("entry = 0x%x\n", (int)marks[MARK_ENTRY]);
109 DPRINTF("ssym = 0x%x\n", (int)marks[MARK_SYM]);
110 DPRINTF("esym = 0x%x\n", (int)marks[MARK_END]);
111
112 entry = (void *)marks[MARK_ENTRY];
113
114 printf("\n");
115
116 ICIA();
117 __asm __volatile ("movl %0,%%d7" : : "m" (d7));
118 __asm __volatile ("movl %0,%%d6" : : "m" (bootdev));
119 __asm __volatile ("movl %0,%%d5" : : "m" (netbsd));
120 __asm __volatile ("movl %0,%%d4" : : "m" (d4));
121 __asm __volatile ("movl %0,%%d2" : : "m" (marks[MARK_END]));
122 (*((int (*)())entry))();
123 }
124