No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / pmax / stand / common / boot.c
blobdb7bcfad553920d388311c1766477cfd8e512d8b
1 /* $NetBSD: boot.c,v 1.17 2009/03/14 14:46:04 dsl Exp $ */
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jonathan Stone, Michael Hitch and Simon Burge.
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1992, 1993
34 * The Regents of the University of California. All rights reserved.
36 * This code is derived from software contributed to Berkeley by
37 * Ralph Campbell.
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE.
63 * @(#)boot.c 8.1 (Berkeley) 6/10/93
66 #include <lib/libsa/stand.h>
67 #include <lib/libsa/loadfile.h>
68 #include <lib/libkern/libkern.h>
70 #include <sys/param.h>
71 #include <sys/exec.h>
72 #include <sys/exec_elf.h>
74 #include <machine/dec_prom.h>
76 #include "common.h"
77 #include "bootinfo.h"
80 * We won't go overboard with gzip'd kernel names. After all we can
81 * still boot a gzip'd kernel called "netbsd.pmax" - it doesn't need
82 * the .gz suffix.
84 char *kernelnames[] = {
85 "netbsd.pmax",
86 "netbsd", "netbsd.gz",
87 "netbsd.bak",
88 "netbsd.old",
89 "onetbsd",
90 "gennetbsd",
91 #ifdef notyet
92 "netbsd.el",
93 #endif /*notyet*/
94 NULL
98 static char *devname(char *);
99 int main(int, char **);
102 * This gets arguments from the first stage boot lader, calls PROM routines
103 * to open and load the program to boot, and then transfers execution to
104 * that new program.
106 * Argv[0] should be something like "rz(0,0,0)netbsd" on a DECstation 3100.
107 * Argv[0,1] should be something like "boot 5/rz0/netbsd" on a DECstation 5000.
108 * The argument "-a" means netbsd should do an automatic reboot.
111 main(int argc, char **argv)
113 char *name, **namep, *dev, *kernel;
114 char bootname[PATH_MAX], bootpath[PATH_MAX];
115 int entry, win;
116 u_long marks[MARK_MAX];
117 struct btinfo_symtab bi_syms;
118 struct btinfo_bootpath bi_bpath;
120 /* print a banner */
121 printf("\n");
122 printf("NetBSD/pmax " NETBSD_VERS " " BOOT_TYPE_NAME " Bootstrap, Revision %s\n",
123 bootprog_rev);
124 printf("(%s, %s)\n", bootprog_maker, bootprog_date);
125 printf("\n");
127 /* initialise bootinfo structure early */
128 bi_init(BOOTINFO_ADDR);
130 /* check for DS5000 boot */
131 if (strcmp(argv[0], "boot") == 0) {
132 argc--;
133 argv++;
135 name = argv[0];
136 printf("Boot: %s\n", name);
138 /* NOTE: devname() can modify bootname[]. */
139 strcpy(bootname, argv[0]);
140 if ((kernel = devname(bootname)) == NULL) {
141 dev = bootname;
142 name = NULL;
145 memset(marks, 0, sizeof marks);
146 if (name != NULL)
147 win = (loadfile(name, marks, LOAD_KERNEL) == 0);
148 else {
149 win = 0;
150 for (namep = kernelnames, win = 0; *namep != NULL && !win;
151 namep++) {
152 kernel = *namep;
153 strcpy(bootpath, dev);
154 strcat(bootpath, kernel);
155 printf("Loading: %s\n", bootpath);
156 win = (loadfile(bootpath, marks, LOAD_ALL) != -1);
157 if (win) {
158 name = bootpath;
162 if (!win)
163 goto fail;
165 strncpy(bi_bpath.bootpath, kernel, BTINFO_BOOTPATH_LEN);
166 bi_add(&bi_bpath, BTINFO_BOOTPATH, sizeof(bi_bpath));
168 entry = marks[MARK_ENTRY];
169 bi_syms.nsym = marks[MARK_NSYM];
170 bi_syms.ssym = marks[MARK_SYM];
171 bi_syms.esym = marks[MARK_END];
172 bi_add(&bi_syms, BTINFO_SYMTAB, sizeof(bi_syms));
174 printf("Starting at 0x%x\n\n", entry);
175 if (callv == &callvec)
176 startprog(entry, entry, argc, argv, 0, 0,
177 BOOTINFO_MAGIC, BOOTINFO_ADDR);
178 else
179 startprog(entry, entry, argc, argv, DEC_PROM_MAGIC,
180 callv, BOOTINFO_MAGIC, BOOTINFO_ADDR);
181 (void)printf("KERNEL RETURNED!\n");
183 fail:
184 (void)printf("Boot failed! Halting...\n");
185 return (0);
190 * Check whether or not fname is a device name only or a full
191 * bootpath including the kernel name. This code to do this
192 * is copied from loadfile() in the first stage bootblocks.
193 * Returns the kernel name, or NULL if no kernel name specified.
195 * NOTE: fname will be modified if it's of the form N/rzY
196 * without a trailing slash.
198 static char *
199 devname(char *fname)
201 char c;
203 while ((c = *fname++) != '\0') {
204 if (c == ')')
205 break;
206 if (c != '/')
207 continue;
208 while ((c = *fname++) != '\0')
209 if (c == '/')
210 break;
212 * Make "N/rzY" with no trailing '/' valid by adding
213 * the extra '/' before appending 'boot.pmax' to the path.
215 if (c != '/') {
216 fname--;
217 *fname++ = '/';
218 *fname = '\0';
220 break;
222 return (*fname == '\0' ? NULL : fname);