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