No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / hp700 / stand / boot / boot.c
blobf0201de5a8deed015c8e4722e0796947fb50da08
1 /* $NetBSD: boot.c,v 1.10 2009/05/08 09:33:58 skrll Exp $ */
3 /*-
4 * Copyright (c) 1982, 1986, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
31 * @(#)boot.c 8.1 (Berkeley) 6/10/93
35 * Copyright (c) 1998-2004 Michael Shalayeff
36 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
47 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
48 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
51 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
52 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
53 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
55 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
56 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
57 * THE POSSIBILITY OF SUCH DAMAGE.
61 #include <sys/param.h>
62 #include <sys/reboot.h>
63 #include <sys/boot_flag.h>
65 #include <arch/hp700/stand/common/libsa.h>
66 #include <lib/libsa/loadfile.h>
68 #include <machine/pdc.h>
69 #include <machine/vmparam.h>
71 #include <arch/hp700/stand/common/dev_hppa.h>
73 #include "bootinfo.h"
76 * Boot program... bits in `howto' determine whether boot stops to
77 * ask for system name. Boot device is derived from ROM provided
78 * information.
81 #define MAXLEN 100
83 char line[MAXLEN];
84 char devname_buffer[16];
86 extern u_int opendev;
87 extern char *lowram;
88 extern int noconsole;
91 * XXX UFS accepts a /, NFS doesn't.
93 char *name;
94 char *names[] = {
95 "netbsd", "netbsd.gz",
96 "netbsd.bak", "netbsd.bak.gz",
97 "netbsd.old", "netbsd.old.gz",
98 "onetbsd", "onetbsd.gz",
99 NULL
101 #define NUMNAMES (sizeof(names) / sizeof(char *))
103 void boot(dev_t boot_dev);
104 int main(void);
105 void getbootdev(int *);
106 void exec_hp700(char *, u_long, int);
108 int tgets(char *);
109 void _rtt(void);
111 typedef void (*startfuncp)(int, int, int, int, int, void *)
112 __attribute__ ((noreturn));
114 int howto;
116 void
117 boot(dev_t boot_dev)
119 machdep();
120 #ifdef DEBUGBUG
121 debug = 1;
122 #endif
123 devboot(boot_dev, devname_buffer);
124 main();
128 main(void)
130 int currname = 0;
131 char *filename, filename_buffer[MAXLEN];
133 printf("\n");
134 printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
135 printf(">> (%s, %s)\n", bootprog_maker, bootprog_date);
136 printf(">> Enter \"reset\" to reset system.\n");
138 for (;;) {
139 size_t size;
141 /* reset bootinfo structure */
142 bi_init();
144 name = names[currname++];
145 if (currname == NUMNAMES)
146 currname = 0;
148 if (!noconsole) {
149 howto = 0;
150 getbootdev(&howto);
151 } else
152 printf(": %s\n", name);
153 if (strchr(name, ':') != 0) {
154 filename = name;
155 } else {
156 strcpy(filename_buffer, devname_buffer);
157 strcat(filename_buffer, ":");
158 strcat(filename_buffer, name);
159 filename = filename_buffer;
162 size = sizeof(struct btinfo_common) + strlen(name) + 1;
163 /* Impose limit (somewhat arbitrary) */
164 if (size < BOOTINFO_MAXSIZE / 2) {
165 union {
166 struct btinfo_kernelfile bi_file;
167 char x[size];
168 } U;
169 strcpy(U.bi_file.name, name);
170 BI_ADD(&U.bi_file, BTINFO_KERNELFILE, size);
173 exec_hp700(filename, 0, howto);
174 printf("boot: %s\n", strerror(errno));
178 void
179 getbootdev(int *boot_howto)
181 char c, *ptr = line;
182 int bdev, badapt, bctlr, bunit, bpart;
184 bdev = B_TYPE(bootdev);
185 badapt = B_ADAPTOR(bootdev);
186 bctlr = B_CONTROLLER(bootdev);
187 bunit = B_UNIT(bootdev);
188 bpart = B_PARTITION(bootdev);
190 printf("Boot: [[[%s%d%c:]%s][-a][-c][-d][-s][-v][-q]] :- ",
191 devsw[bdev].dv_name, badapt << 8 | bctlr << 4 | bunit,
192 'a' + bpart, name);
194 if (tgets(line)) {
195 if (strcmp(line, "reset") == 0) {
196 _rtt();
197 printf("panic: can't reboot\n");
198 return;
200 while ((c = *ptr) != '\0') {
201 while (c == ' ')
202 c = *++ptr;
203 if (!c)
204 return;
205 if (c == '-')
206 while ((c = *++ptr) && c != ' ')
207 BOOT_FLAG(c, *boot_howto);
208 else {
209 name = ptr;
210 while ((c = *++ptr) && c != ' ');
211 if (c)
212 *ptr++ = 0;
215 } else
216 printf("\n");
219 #define round_to_size(x) \
220 (((x) + sizeof(u_long) - 1) & ~(sizeof(u_long) - 1))
222 void
223 exec_hp700(char *file, u_long loadaddr, int boot_howto)
225 #ifdef EXEC_DEBUG
226 extern int debug;
227 int i;
228 #endif
229 struct btinfo_symtab bi_syms;
230 u_long marks[MARK_MAX];
231 int fd;
233 marks[MARK_START] = loadaddr;
234 #ifdef EXEC_DEBUG
235 printf("file=%s loadaddr=%x howto=%x\n",
236 file, loadaddr, boot_howto);
237 #endif
238 if ((fd = loadfile(file, marks, LOAD_KERNEL)) == -1)
239 return;
241 marks[MARK_END] = round_to_size(marks[MARK_END] - loadaddr);
242 printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n",
243 marks[MARK_ENTRY], marks[MARK_NSYM],
244 marks[MARK_SYM], marks[MARK_END]);
246 #ifdef EXEC_DEBUG
247 if (debug) {
248 printf("ep=0x%x [", marks[MARK_ENTRY]);
249 for (i = 0; i < 10240; i++) {
250 if (!(i % 8)) {
251 printf("\b\n%p:", &((u_int *)marks[MARK_ENTRY])[i]);
252 if (getchar() != ' ')
253 break;
255 printf("%x,", ((int *)marks[MARK_ENTRY])[i]);
257 printf("\b\b ]\n");
259 #endif
261 bi_syms.nsym = marks[MARK_NSYM];
262 bi_syms.ssym = marks[MARK_SYM];
263 bi_syms.esym = marks[MARK_END];
264 BI_ADD(&bi_syms, BTINFO_SYMTAB, sizeof(bi_syms));
266 fcacheall();
268 __asm("mtctl %r0, %cr17");
269 __asm("mtctl %r0, %cr17");
271 /* stack and the gung is ok at this point, so, no need for asm setup */
272 (*(startfuncp)(marks[MARK_ENTRY])) ((int)pdc, boot_howto, bootdev,
273 marks[MARK_END], BOOTARG_APIVER, &bootinfo);
274 /* not reached */