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