Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / sgimips / stand / common / boot.c
blobbc531393e2a3037b7573a42f0183522d934f4851
1 /* $NetBSD: boot.c,v 1.16 2008/03/28 16:40:25 tsutsui 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>
73 #include <sys/boot_flag.h>
75 #include <dev/arcbios/arcbios.h>
77 #include "common.h"
78 #include "bootinfo.h"
81 * We won't go overboard with gzip'd kernel names. After all we can
82 * still boot a gzip'd kernel called "netbsd.sgimips" - it doesn't need
83 * the .gz suffix.
85 * For arcane reasons, the first byte of the first element of this struct will
86 * contain a zero. We therefore start from one.
89 const char *kernelnames[] = {
90 "placekeeper",
91 "netbsd.sgimips",
92 "netbsd",
93 "netbsd.gz",
94 "netbsd.bak",
95 "netbsd.old",
96 "onetbsd",
97 "gennetbsd",
98 NULL
101 extern const struct arcbios_fv *ARCBIOS;
102 static int debug = 0;
104 int main(int, char **);
106 /* Storage must be static. */
107 struct btinfo_symtab bi_syms;
108 struct btinfo_bootpath bi_bpath;
110 static uint8_t bootinfo[BOOTINFO_SIZE];
113 * This gets arguments from the ARCS monitor, calls ARCS routines to open
114 * and load the program to boot, then transfers execution to the new program.
116 * argv[0] will be the ARCS path to the bootloader (i.e.,
117 * "pci(0)scsi(0)disk(2)rdisk(0)partition(8)/boot.ip3").
119 * argv[1] through argv[n] will contain arguments passed from the PROM, if any.
123 main(int argc, char **argv)
125 const char *kernel = NULL;
126 const char *bootpath = NULL;
127 char bootfile[PATH_MAX];
128 void (*entry) (int, char *[], int, void *);
129 u_long marks[MARK_MAX];
130 int win = 0;
131 int i;
132 int ch;
134 /* print a banner */
135 printf("\n");
136 printf("%s " NETBSD_VERS " Bootstrap, Revision %s\n",
137 bootprog_name, bootprog_rev);
138 printf("(%s, %s)\n", bootprog_maker, bootprog_date);
139 printf("\n");
141 memset(marks, 0, sizeof marks);
143 /* initialise bootinfo structure early */
144 bi_init(bootinfo);
146 /* Parse arguments, if present. */
147 while ((ch = getopt(argc, argv, "v")) != -1) {
148 switch (ch) {
149 case 'v':
150 debug = 1;
151 break;
156 * How to find partition and file to load?
158 * If argv[0] contains the string "cdrom(", we're probably doing an
159 * install. The bootpath will therefore be partition 0 of whatever
160 * device we've booted from. Derive the install kernel name from
161 * the bootloader name ("ip3xboot", "ip2xboot", or "aoutboot").
164 if (strstr(argv[0], "cdrom(")) {
165 strcpy(bootfile, argv[0]);
166 i = (strrchr(bootfile, ')') - bootfile);
167 bootfile[i - 1] = '0';
168 if (strstr(bootfile, "ip3x"))
169 kernel = "ip3x";
170 else
171 kernel = "ip2x";
172 sprintf((strrchr(bootfile, ')') + 1), kernel);
173 if ((loadfile(bootfile, marks, LOAD_KERNEL)) >= 0)
174 goto finish;
177 bootpath = ARCBIOS->GetEnvironmentVariable("OSLoadPartition");
179 if (bootpath == NULL) {
180 /* XXX need to actually do the fixup */
181 printf("\nPlease set the OSLoadPartition "
182 "environment variable.\n");
183 return 0;
187 * Grab OSLoadFilename from ARCS.
190 kernel = ARCBIOS->GetEnvironmentVariable("OSLoadFilename");
193 * argv[1] is assumed to contain the name of the kernel to boot,
194 * if it a) does not start with a hyphen and b) does not contain
195 * an equals sign.
198 if (((strchr(argv[1], '=')) == NULL) && (argv[1][0] != '-'))
199 kernel = argv[1];
201 if (kernel != NULL) {
203 * if the name contains parenthesis, we assume that it
204 * contains the bootpath and ignore anything passed through
205 * the environment
207 if (strchr(kernel, '('))
208 win = loadfile(kernel, marks, LOAD_KERNEL);
209 else {
210 strcpy(bootfile, bootpath);
211 strcat(bootfile, kernel);
212 win = loadfile(bootfile, marks, LOAD_KERNEL);
215 } else {
216 i = 1;
217 while (kernelnames[i] != NULL) {
218 strcpy(bootfile, bootpath);
219 strcat(bootfile, kernelnames[i]);
220 kernel = kernelnames[i];
221 win = loadfile(bootfile, marks, LOAD_KERNEL);
222 if (win != -1)
223 break;
224 i++;
228 if (win < 0) {
229 printf("Boot failed! Halting...\n");
230 return 0;
233 finish:
234 strlcpy(bi_bpath.bootpath, bootfile, BTINFO_BOOTPATH_LEN);
235 bi_add(&bi_bpath, BTINFO_BOOTPATH, sizeof(bi_bpath));
237 bi_syms.nsym = marks[MARK_NSYM];
238 bi_syms.ssym = marks[MARK_SYM];
239 bi_syms.esym = marks[MARK_END];
240 bi_add(&bi_syms, BTINFO_SYMTAB, sizeof(bi_syms));
241 entry = (void *)marks[MARK_ENTRY];
243 if (debug) {
244 printf("Starting at %p\n\n", entry);
245 printf("nsym 0x%lx ssym 0x%lx esym 0x%lx\n", marks[MARK_NSYM],
246 marks[MARK_SYM], marks[MARK_END]);
248 (*entry)(argc, argv, BOOTINFO_MAGIC, bootinfo);
250 printf("Kernel returned! Halting...\n");
251 return 0;