boot.c revision 1.2 1 /* $NetBSD: boot.c,v 1.2 2001/11/21 22:13:55 soren Exp $ */
2
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jonathan Stone, Michael Hitch and Simon Burge.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Copyright (c) 1992, 1993
41 * The Regents of the University of California. All rights reserved.
42 *
43 * This code is derived from software contributed to Berkeley by
44 * Ralph Campbell.
45 *
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
48 * are met:
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. All advertising materials mentioning features or use of this software
55 * must display the following acknowledgement:
56 * This product includes software developed by the University of
57 * California, Berkeley and its contributors.
58 * 4. Neither the name of the University nor the names of its contributors
59 * may be used to endorse or promote products derived from this software
60 * without specific prior written permission.
61 *
62 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 * SUCH DAMAGE.
73 *
74 * @(#)boot.c 8.1 (Berkeley) 6/10/93
75 */
76
77 #include <lib/libsa/stand.h>
78 #include <lib/libsa/loadfile.h>
79 #include <lib/libkern/libkern.h>
80
81 #include <sys/param.h>
82 #include <sys/exec.h>
83 #include <sys/exec_elf.h>
84
85 #include <dev/arcbios/arcbios.h>
86
87 #include "common.h"
88 #if 0
89 #include "bootinfo.h"
90 #endif
91
92 /*
93 * We won't go overboard with gzip'd kernel names. After all we can
94 * still boot a gzip'd kernel called "netbsd.sgimips" - it doesn't need
95 * the .gz suffix.
96 */
97 char *kernelnames[] = {
98 "netbsd.sgimips",
99 "netbsd", "netbsd.gz",
100 "netbsd.bak",
101 "netbsd.old",
102 "onetbsd",
103 "gennetbsd",
104 #ifdef notyet
105 "netbsd.el",
106 #endif /*notyet*/
107 NULL
108 };
109
110 extern const struct arcbios_fv *ARCBIOS;
111
112 #if 0
113 static char *devname __P((char *));
114 #endif
115 int main __P((int, char **, char **));
116
117 #ifdef HEAP_VARIABLE
118 void setheap(void *, void*);
119 #endif
120
121 /*
122 * This gets arguments from the first stage boot lader, calls PROM routines
123 * to open and load the program to boot, and then transfers execution to
124 * that new program.
125 *
126 * Argv[0] should be something like "rz(0,0,0)netbsd" on a DECstation 3100.
127 * Argv[0,1] should be something like "boot 5/rz0/netbsd" on a DECstation 5000.
128 * The argument "-a" means netbsd should do an automatic reboot.
129 */
130 int
131 main(argc, argv, envp)
132 int argc;
133 char **argv;
134 char **envp;
135 {
136 char *name/*, **namep, *dev, *kernel*/;
137 char /*bootname[PATH_MAX],*/ bootpath[PATH_MAX];
138 int entry, win;
139 u_long marks[MARK_MAX];
140 struct arcbios_mem *mem;
141 #if 0
142 struct btinfo_symtab bi_syms;
143 struct btinfo_bootpath bi_bpath;
144 #endif
145
146 /* print a banner */
147 printf("\n");
148 printf("NetBSD/sgimips " NETBSD_VERS " "/* BOOT_TYPE_NAME */" Bootstrap, Revision %s\n",
149 bootprog_rev);
150 printf("(%s, %s)\n", bootprog_maker, bootprog_date);
151 printf("\n");
152
153 /* Initialize heap from free memory descriptors */
154 mem = 0;
155 do {
156 mem = ARCBIOS->GetMemoryDescriptor(mem);
157 if (mem != 0)
158 printf("Mem block: type %d base 0x%x size 0x%x\n",
159 mem->Type, mem->BasePage * 4096, mem->PageCount * 4096);
160 } while (mem != 0);
161 #ifdef HEAP_VARIABLE
162 setheap((void *)0x88200000, (void *)0x88300000); /* XXXX */
163 #endif
164 printf("Local storage %x\n", (int)&mem);
165 for (win = 0; win < argc; ++win)
166 printf("argv[%d]: %s\n", win, argv[win]);
167
168 /* initialise bootinfo structure early */
169 #if 0
170 bi_init(BOOTINFO_ADDR);
171 #endif
172
173 /*
174 * How to find partition and file to load?
175 * OSLoaderPartition=scsi(n)disk(n)rdisk(n)partition(n)
176 * OSLoadFilename=netbsd
177 * path=???
178 * argument passed to boot program
179 */
180 bootpath[0] = 0;
181 name = ARCBIOS->GetEnvironmentVariable("OSLoadPartition");
182 if (name) {
183 strcpy(bootpath, name);
184 name = ARCBIOS->GetEnvironmentVariable("OSLoadFilename");
185 if (name)
186 strcat(bootpath, name);
187 else
188 strcat(bootpath, "netbsd");
189 }
190 if (strchr(argv[1], '=') == NULL) {
191 strcpy(bootpath, argv[1]);
192 if (strchr(argv[1], '(') == NULL) {
193 strcpy(bootpath, ARCBIOS->GetEnvironmentVariable("OSLoadPartition"));
194 strcat(bootpath, argv[1]);
195 }
196 }
197 printf("Boot: %s\n", bootpath);
198
199 #if 0
200 /* NOTE: devname() can modify bootname[]. */
201 strcpy(bootname, argv[1]);
202 if ((kernel = devname(bootname)) == NULL) {
203 dev = bootname;
204 name = NULL;
205 }
206 #endif
207
208 memset(marks, 0, sizeof marks);
209 #if 0
210 if (name != NULL)
211 win = (loadfile(name, marks, LOAD_KERNEL) == 0);
212 else {
213 win = 0;
214 for (namep = kernelnames, win = 0; *namep != NULL && !win;
215 namep++) {
216 kernel = *namep;
217 strcpy(bootpath, dev);
218 strcat(bootpath, kernel);
219 printf("Loading: %s\n", bootpath);
220 win = (loadfile(bootpath, marks, LOAD_ALL) != -1);
221 if (win) {
222 name = bootpath;
223 }
224 }
225 }
226 #else
227 win = loadfile(bootpath, marks, LOAD_KERNEL) == 0;
228 #endif
229 if (!win)
230 goto fail;
231
232 #if 0
233 strncpy(bi_bpath.bootpath, kernel, BTINFO_BOOTPATH_LEN);
234 bi_add(&bi_bpath, BTINFO_BOOTPATH, sizeof(bi_bpath));
235 #endif
236
237 entry = marks[MARK_ENTRY];
238 #if 0
239 bi_syms.nsym = marks[MARK_NSYM];
240 bi_syms.ssym = marks[MARK_SYM];
241 bi_syms.esym = marks[MARK_END];
242 bi_add(&bi_syms, BTINFO_SYMTAB, sizeof(bi_syms));
243 #endif
244
245 printf("Starting at 0x%x\n\n", entry);
246 printf("nsym 0x%lx ssym 0x%lx esym 0x%lx\n", marks[MARK_NSYM], marks[MARK_SYM],
247 marks[MARK_END]);
248 ARCBIOS->FlushAllCaches();
249 startprog(entry, entry, argc, argv, envp, (void *)marks[MARK_END],
250 #if 0
251 BOOTINFO_MAGIC, BOOTINFO_ADDR);
252 #else
253 0, 0);
254 #endif
255 (void)printf("KERNEL RETURNED!\n");
256
257 fail:
258 (void)printf("Boot failed! Halting...\n");
259 return (0);
260 }
261
262
263 /*
264 * Check whether or not fname is a device name only or a full
265 * bootpath including the kernel name. This code to do this
266 * is copied from loadfile() in the first stage bootblocks.
267 * Returns the kernel name, or NULL if no kernel name specified.
268 *
269 * NOTE: fname will be modified if it's of the form N/rzY
270 * without a trailing slash.
271 */
272 #if 0
273 static char *
274 devname(fname)
275 char *fname;
276 {
277 char c;
278
279 while ((c = *fname++) != '\0') {
280 if (c == ')')
281 break;
282 if (c != '/')
283 continue;
284 while ((c = *fname++) != '\0')
285 if (c == '/')
286 break;
287 /*
288 * Make "N/rzY" with no trailing '/' valid by adding
289 * the extra '/' before appending 'boot.sgimips' to the path.
290 */
291 if (c != '/') {
292 fname--;
293 *fname++ = '/';
294 *fname = '\0';
295 }
296 break;
297 }
298 return (*fname == '\0' ? NULL : fname);
299 }
300 #endif
301