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