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