boot.c revision 1.7 1 /* $NetBSD: boot.c,v 1.7 2002/04/30 13:10:56 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 extern void ICIA(void);
37
38 /* version strings in vers.c (generated by newvers.sh) */
39 extern const char bootprog_name[];
40 extern const char bootprog_rev[];
41 extern const char bootprog_date[];
42 extern const char bootprog_maker[];
43
44 char *devs[] = { "hd", "fh", "fd", NULL, NULL, "rd", "st" };
45 char *kernels[] = { "/netbsd", "/netbsd.gz", NULL };
46
47 #ifdef BOOT_DEBUG
48 # define DPRINTF(x) printf x
49 #else
50 # define DPRINTF(x)
51 #endif
52
53 void
54 boot(d4, d5, d6, d7)
55 u_int32_t d4, d5, d6, d7;
56 {
57 int fd, i;
58 int ctlr, unit, part, type;
59 u_int32_t bootdev = d6;
60 char *netbsd = (char *)d5;
61 u_long marks[MARK_MAX];
62 static char devname[32], file[32];
63 void (*entry)(void);
64
65 printf("\n");
66 printf("%s Secondary Boot, Revision %s\n",
67 bootprog_name, bootprog_rev);
68 printf("(%s, %s)\n", bootprog_maker, bootprog_date);
69 printf("\n");
70
71 /* bootname is "boot" by default. */
72 if (netbsd == NULL || strcmp(netbsd, "boot") == 0 ||
73 strcmp(netbsd, "/boot") == 0)
74 netbsd = "";
75
76 DPRINTF(("howto = 0x%x\n", d7));
77 DPRINTF(("bootdev = 0x%x\n", bootdev));
78 DPRINTF(("bootname = %s\n", netbsd));
79 DPRINTF(("maxmem = 0x%x\n", d4));
80
81 #define SET_MAGIC(bootdev, magic) ((bootdev & 0x0fffffff)| (magic << 28))
82 /* PROM monitor passes 0xa, but NEWS-OS /boot passed 0x5... */
83 bootdev = SET_MAGIC(bootdev, 5);
84
85 ctlr = BOOTDEV_CTLR(bootdev);
86 unit = BOOTDEV_UNIT(bootdev);
87 part = BOOTDEV_PART(bootdev);
88 type = BOOTDEV_TYPE(bootdev);
89
90 marks[MARK_START] = 0;
91
92 if (devs[type] == NULL) {
93 printf("unknown bootdev (0x%x)\n", bootdev);
94 return;
95 }
96
97 sprintf(devname, "%s(%d,%d,%d)", devs[type], ctlr, unit, part);
98 printf("Booting %s%s\n", devname, netbsd);
99
100 /* use user specified kernel name if exists */
101 if (*netbsd) {
102 kernels[0] = netbsd;
103 kernels[1] = NULL;
104 }
105
106 for (i = 0; kernels[i]; i++) {
107 sprintf(file, "%s%s", devname, kernels[i]);
108 DPRINTF(("trying %s...\n", file));
109 fd = loadfile(file, marks, LOAD_KERNEL);
110 if (fd != -1)
111 break;
112 }
113 if (kernels[i] == NULL) {
114 #if 0 /* bootxx() may be overrided by loaded kernel */
115 return;
116 #else
117 rom_halt();
118 /* NOTREACHED */
119 #endif
120 }
121
122 DPRINTF(("entry = 0x%x\n", (int)marks[MARK_ENTRY]));
123 DPRINTF(("ssym = 0x%x\n", (int)marks[MARK_SYM]));
124 DPRINTF(("esym = 0x%x\n", (int)marks[MARK_END]));
125
126 entry = (void *)marks[MARK_ENTRY];
127
128 printf("\n");
129
130 ICIA();
131 __asm __volatile ("movl %0,%%d7" : : "m" (d7));
132 __asm __volatile ("movl %0,%%d6" : : "m" (bootdev));
133 __asm __volatile ("movl %0,%%d5" : : "m" (netbsd));
134 __asm __volatile ("movl %0,%%d4" : : "m" (d4));
135 __asm __volatile ("movl %0,%%d2" : : "m" (marks[MARK_END]));
136 (*entry)();
137 }
138
139 void
140 _rtt()
141 {
142
143 rom_halt();
144 for (;;)
145 ;
146 /* NOTREACHED */
147 }
148