boot.c revision 1.10.8.3 1 1.10.8.3 nathanw /* $NetBSD: boot.c,v 1.10.8.3 2002/11/11 22:04:37 nathanw Exp $ */
2 1.10.8.2 nathanw
3 1.10.8.2 nathanw /*-
4 1.10.8.2 nathanw * Copyright (c) 1982, 1986, 1990, 1993
5 1.10.8.2 nathanw * The Regents of the University of California. All rights reserved.
6 1.10.8.2 nathanw *
7 1.10.8.2 nathanw * Redistribution and use in source and binary forms, with or without
8 1.10.8.2 nathanw * modification, are permitted provided that the following conditions
9 1.10.8.2 nathanw * are met:
10 1.10.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
11 1.10.8.2 nathanw * notice, this list of conditions and the following disclaimer.
12 1.10.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
13 1.10.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
14 1.10.8.2 nathanw * documentation and/or other materials provided with the distribution.
15 1.10.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
16 1.10.8.2 nathanw * must display the following acknowledgement:
17 1.10.8.2 nathanw * This product includes software developed by the University of
18 1.10.8.2 nathanw * California, Berkeley and its contributors.
19 1.10.8.2 nathanw * 4. Neither the name of the University nor the names of its contributors
20 1.10.8.2 nathanw * may be used to endorse or promote products derived from this software
21 1.10.8.2 nathanw * without specific prior written permission.
22 1.10.8.2 nathanw *
23 1.10.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.10.8.2 nathanw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.10.8.2 nathanw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.10.8.2 nathanw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.10.8.2 nathanw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.10.8.2 nathanw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.10.8.2 nathanw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.10.8.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.10.8.2 nathanw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.10.8.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.10.8.2 nathanw * SUCH DAMAGE.
34 1.10.8.2 nathanw *
35 1.10.8.2 nathanw * @(#)boot.c 8.1 (Berkeley) 6/10/93
36 1.10.8.2 nathanw */
37 1.10.8.2 nathanw
38 1.10.8.2 nathanw #include <sys/param.h>
39 1.10.8.2 nathanw #include <sys/reboot.h>
40 1.10.8.3 nathanw #include <sys/boot_flag.h>
41 1.10.8.2 nathanw #include <sys/exec.h>
42 1.10.8.2 nathanw
43 1.10.8.2 nathanw #include <lib/libsa/stand.h>
44 1.10.8.2 nathanw #include <lib/libsa/loadfile.h>
45 1.10.8.2 nathanw
46 1.10.8.2 nathanw #include <machine/promlib.h>
47 1.10.8.2 nathanw #include <sparc/stand/common/promdev.h>
48 1.10.8.2 nathanw
49 1.10.8.2 nathanw #include "bootinfo.h"
50 1.10.8.2 nathanw
51 1.10.8.2 nathanw extern void prom_patch __P((void)); /* prompatch.c */
52 1.10.8.2 nathanw
53 1.10.8.2 nathanw static int bootoptions __P((char *));
54 1.10.8.2 nathanw #if 0
55 1.10.8.2 nathanw static void promsyms __P((int, struct exec *));
56 1.10.8.2 nathanw #endif
57 1.10.8.2 nathanw
58 1.10.8.2 nathanw int debug;
59 1.10.8.2 nathanw int netif_debug;
60 1.10.8.2 nathanw
61 1.10.8.2 nathanw extern char bootprog_name[], bootprog_rev[], bootprog_date[], bootprog_maker[];
62 1.10.8.2 nathanw unsigned long esym;
63 1.10.8.2 nathanw char *strtab;
64 1.10.8.2 nathanw int strtablen;
65 1.10.8.2 nathanw char fbuf[80], dbuf[128];
66 1.10.8.2 nathanw
67 1.10.8.2 nathanw int main __P((void));
68 1.10.8.2 nathanw typedef void (*entry_t)__P((caddr_t, int, int, int, long, long));
69 1.10.8.2 nathanw
70 1.10.8.2 nathanw /*
71 1.10.8.2 nathanw * Boot device is derived from ROM provided information, or if there is none,
72 1.10.8.2 nathanw * this list is used in sequence, to find a kernel.
73 1.10.8.2 nathanw */
74 1.10.8.2 nathanw char *kernels[] = {
75 1.10.8.2 nathanw "netbsd",
76 1.10.8.2 nathanw "netbsd.gz",
77 1.10.8.2 nathanw "netbsd.old",
78 1.10.8.2 nathanw "netbsd.old.gz",
79 1.10.8.2 nathanw "onetbsd",
80 1.10.8.2 nathanw "onetbsd.gz",
81 1.10.8.2 nathanw "vmunix",
82 1.10.8.2 nathanw #ifdef notyet
83 1.10.8.2 nathanw "netbsd.pl",
84 1.10.8.2 nathanw "netbsd.pl.gz",
85 1.10.8.2 nathanw "netbsd.el",
86 1.10.8.2 nathanw "netbsd.el.gz",
87 1.10.8.2 nathanw #endif
88 1.10.8.2 nathanw NULL
89 1.10.8.2 nathanw };
90 1.10.8.2 nathanw
91 1.10.8.2 nathanw int
92 1.10.8.2 nathanw bootoptions(ap)
93 1.10.8.2 nathanw char *ap;
94 1.10.8.2 nathanw {
95 1.10.8.2 nathanw int v = 0;
96 1.10.8.2 nathanw if (ap == NULL || *ap++ != '-')
97 1.10.8.2 nathanw return (0);
98 1.10.8.2 nathanw
99 1.10.8.2 nathanw while (*ap != '\0' && *ap != ' ' && *ap != '\t' && *ap != '\n') {
100 1.10.8.3 nathanw BOOT_FLAG(*ap, v);
101 1.10.8.2 nathanw ap++;
102 1.10.8.2 nathanw }
103 1.10.8.2 nathanw
104 1.10.8.3 nathanw if ((v & RB_KDB) != 0)
105 1.10.8.3 nathanw debug = 1;
106 1.10.8.3 nathanw
107 1.10.8.2 nathanw return (v);
108 1.10.8.2 nathanw }
109 1.10.8.2 nathanw
110 1.10.8.2 nathanw int
111 1.10.8.2 nathanw main()
112 1.10.8.2 nathanw {
113 1.10.8.2 nathanw int io, i;
114 1.10.8.2 nathanw char *kernel;
115 1.10.8.2 nathanw int how;
116 1.10.8.2 nathanw u_long marks[MARK_MAX], bootinfo;
117 1.10.8.2 nathanw struct btinfo_symtab bi_sym;
118 1.10.8.2 nathanw void *arg;
119 1.10.8.2 nathanw
120 1.10.8.2 nathanw #ifdef HEAP_VARIABLE
121 1.10.8.2 nathanw {
122 1.10.8.2 nathanw extern char end[];
123 1.10.8.2 nathanw setheap((void *)ALIGN(end), (void *)0xffffffff);
124 1.10.8.2 nathanw }
125 1.10.8.2 nathanw #endif
126 1.10.8.2 nathanw prom_init();
127 1.10.8.2 nathanw
128 1.10.8.2 nathanw printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
129 1.10.8.2 nathanw printf(">> (%s, %s)\n", bootprog_maker, bootprog_date);
130 1.10.8.2 nathanw
131 1.10.8.2 nathanw /* massage machine prom */
132 1.10.8.2 nathanw prom_patch();
133 1.10.8.2 nathanw
134 1.10.8.2 nathanw /*
135 1.10.8.2 nathanw * get default kernel.
136 1.10.8.2 nathanw */
137 1.10.8.2 nathanw prom_bootdevice = prom_getbootpath();
138 1.10.8.2 nathanw kernel = prom_getbootfile();
139 1.10.8.2 nathanw how = bootoptions(prom_getbootargs());
140 1.10.8.2 nathanw
141 1.10.8.2 nathanw if (kernel != NULL && *kernel != '\0') {
142 1.10.8.2 nathanw i = -1; /* not using the kernels */
143 1.10.8.2 nathanw } else {
144 1.10.8.2 nathanw i = 0;
145 1.10.8.2 nathanw kernel = kernels[i];
146 1.10.8.2 nathanw }
147 1.10.8.2 nathanw
148 1.10.8.2 nathanw for (;;) {
149 1.10.8.2 nathanw /*
150 1.10.8.2 nathanw * ask for a kernel first ..
151 1.10.8.2 nathanw */
152 1.10.8.2 nathanw if (how & RB_ASKNAME) {
153 1.10.8.2 nathanw printf("device[%s] (\"halt\" to halt): ",
154 1.10.8.2 nathanw prom_bootdevice);
155 1.10.8.2 nathanw gets(dbuf);
156 1.10.8.2 nathanw if (strcmp(dbuf, "halt") == 0)
157 1.10.8.2 nathanw _rtt();
158 1.10.8.2 nathanw if (dbuf[0])
159 1.10.8.2 nathanw prom_bootdevice = dbuf;
160 1.10.8.2 nathanw printf("boot (press RETURN to try default list): ");
161 1.10.8.2 nathanw gets(fbuf);
162 1.10.8.2 nathanw if (fbuf[0])
163 1.10.8.2 nathanw kernel = fbuf;
164 1.10.8.2 nathanw else {
165 1.10.8.2 nathanw how &= ~RB_ASKNAME;
166 1.10.8.2 nathanw i = 0;
167 1.10.8.2 nathanw kernel = kernels[i];
168 1.10.8.2 nathanw }
169 1.10.8.2 nathanw }
170 1.10.8.2 nathanw
171 1.10.8.2 nathanw marks[MARK_START] = 0;
172 1.10.8.2 nathanw printf("Booting %s\n", kernel);
173 1.10.8.2 nathanw if ((io = loadfile(kernel, marks, LOAD_KERNEL)) != -1)
174 1.10.8.2 nathanw break;
175 1.10.8.2 nathanw
176 1.10.8.2 nathanw /*
177 1.10.8.2 nathanw * if we have are not in askname mode, and we aren't using the
178 1.10.8.2 nathanw * prom bootfile, try the next one (if it exits). otherwise,
179 1.10.8.2 nathanw * go into askname mode.
180 1.10.8.2 nathanw */
181 1.10.8.2 nathanw if ((how & RB_ASKNAME) == 0 &&
182 1.10.8.2 nathanw i != -1 && kernels[++i]) {
183 1.10.8.2 nathanw kernel = kernels[i];
184 1.10.8.2 nathanw printf(": trying %s...\n", kernel);
185 1.10.8.2 nathanw } else {
186 1.10.8.2 nathanw printf("\n");
187 1.10.8.2 nathanw how |= RB_ASKNAME;
188 1.10.8.2 nathanw }
189 1.10.8.2 nathanw }
190 1.10.8.2 nathanw
191 1.10.8.2 nathanw marks[MARK_END] = (((u_long)marks[MARK_END] + sizeof(int) - 1)) &
192 1.10.8.2 nathanw (-sizeof(int));
193 1.10.8.2 nathanw arg = (prom_version() == PROM_OLDMON) ? (caddr_t)PROM_LOADADDR : romp;
194 1.10.8.2 nathanw #if 0
195 1.10.8.2 nathanw /* Old style cruft; works only with a.out */
196 1.10.8.2 nathanw marks[MARK_END] |= 0xf0000000;
197 1.10.8.2 nathanw (*(entry_t)marks[MARK_ENTRY])(arg, 0, 0, 0, marks[MARK_END],
198 1.10.8.2 nathanw DDB_MAGIC1);
199 1.10.8.2 nathanw #else
200 1.10.8.2 nathanw /* Should work with both a.out and ELF, but somehow ELF is busted */
201 1.10.8.2 nathanw bootinfo = bi_init(marks[MARK_END]);
202 1.10.8.2 nathanw
203 1.10.8.2 nathanw bi_sym.nsym = marks[MARK_NSYM];
204 1.10.8.2 nathanw bi_sym.ssym = marks[MARK_SYM];
205 1.10.8.2 nathanw bi_sym.esym = marks[MARK_END];
206 1.10.8.2 nathanw bi_add(&bi_sym, BTINFO_SYMTAB, sizeof(bi_sym));
207 1.10.8.2 nathanw
208 1.10.8.2 nathanw /*
209 1.10.8.2 nathanw * Add kernel path to bootinfo
210 1.10.8.2 nathanw */
211 1.10.8.2 nathanw i = sizeof(struct btinfo_common) + strlen(kernel) + 1;
212 1.10.8.2 nathanw /* Impose limit (somewhat arbitrary) */
213 1.10.8.2 nathanw if (i < BOOTINFO_SIZE / 2) {
214 1.10.8.2 nathanw union {
215 1.10.8.2 nathanw struct btinfo_kernelfile bi_file;
216 1.10.8.2 nathanw char x[i];
217 1.10.8.2 nathanw } U;
218 1.10.8.2 nathanw strcpy(U.bi_file.name, kernel);
219 1.10.8.2 nathanw bi_add(&U.bi_file, BTINFO_KERNELFILE, i);
220 1.10.8.2 nathanw }
221 1.10.8.2 nathanw
222 1.10.8.2 nathanw (*(entry_t)marks[MARK_ENTRY])(arg, 0, 0, 0, bootinfo, DDB_MAGIC2);
223 1.10.8.2 nathanw #endif
224 1.10.8.2 nathanw
225 1.10.8.2 nathanw _rtt();
226 1.10.8.2 nathanw }
227