uboot.c revision 1.5
1/*	$NetBSD: uboot.c,v 1.5 2001/01/02 04:14:35 simonb Exp $	*/
2
3/*-
4 * Copyright (c) 1982, 1986, 1990, 1993
5 *	The Regents of the University of California.  All rights reserved.
6 *
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. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *	This product includes software developed by the University of
18 *	California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 *    may be used to endorse or promote products derived from this software
21 *    without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 *	@(#)boot.c	8.1 (Berkeley) 6/10/93
36 */
37
38#include <sys/param.h>
39#include <sys/reboot.h>
40#include <sys/boot_flag.h>
41#include <a.out.h>
42
43#include <lib/libsa/stand.h>
44#include <lib/libsa/loadfile.h>
45
46#include <hp300/stand/common/samachdep.h>
47
48/*
49 * Boot program... bits in `howto' determine whether boot stops to
50 * ask for system name.	 Boot device is derived from ROM provided
51 * information.
52 */
53
54char line[100];
55
56extern	u_int opendev;
57extern	char *lowram;
58extern	int noconsole;
59
60/*
61 * XXX UFS accepts a /, NFS doesn't.
62 */
63char *name;
64char *names[] = {
65	"netbsd",		"netbsd.gz",
66	"netbsd.bak",		"netbsd.bak.gz",
67	"netbsd.old",		"netbsd.old.gz",
68	"onetbsd",		"onetbsd.gz",
69	NULL
70};
71#define NUMNAMES	(sizeof(names) / sizeof(char *))
72
73static int bdev, badapt, bctlr, bunit, bpart;
74
75void main __P((void));
76void getbootdev __P((int *));
77void exec_hp300 __P((char *, u_long, int));
78
79void
80main()
81{
82	int currname = 0;
83
84	printf("\n");
85	printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
86	printf(">> (%s, %s)\n", bootprog_maker, bootprog_date);
87	printf(">> HP 9000/%s SPU\n", getmachineid());
88	printf(">> Enter \"reset\" to reset system.\n");
89
90	bdev   = B_TYPE(bootdev);
91	badapt = B_ADAPTOR(bootdev);
92	bctlr  = B_CONTROLLER(bootdev);
93	bunit  = B_UNIT(bootdev);
94	bpart  = B_PARTITION(bootdev);
95
96	for (;;) {
97		name = names[currname++];
98		if (currname == NUMNAMES)
99			currname = 0;
100
101		if (!noconsole) {
102			howto = 0;
103			getbootdev(&howto);
104		} else
105			printf(": %s\n", name);
106		exec_hp300(name, (u_long)lowram, howto);
107		printf("boot: %s\n", strerror(errno));
108	}
109}
110
111void
112getbootdev(howto)
113	int *howto;
114{
115	char c, *ptr = line;
116
117	printf("Boot: [[[%s%d%c:]%s][-s][-a][-d][-v][-q]] :- ",
118	    devsw[bdev].dv_name, bctlr + (8 * badapt), 'a' + bpart, name);
119
120	if (tgets(line)) {
121		if (strcmp(line, "reset") == 0) {
122			call_req_reboot();      /* reset machine */
123			printf("panic: can't reboot, halting\n");
124			asm("stop #0x2700");
125		}
126		while ((c = *ptr) != '\0') {
127			while (c == ' ')
128				c = *++ptr;
129			if (!c)
130				return;
131			if (c == '-')
132				while ((c = *++ptr) && c != ' ')
133					BOOT_FLAG(c, *howto);
134			else {
135				name = ptr;
136				while ((c = *++ptr) && c != ' ');
137				if (c)
138					*ptr++ = 0;
139			}
140		}
141	} else
142		printf("\n");
143}
144
145#define	round_to_size(x) \
146	(((x) + sizeof(u_long) - 1) & ~(sizeof(u_long) - 1))
147
148void
149exec_hp300(file, loadaddr, howto)
150	char *file;
151	u_long loadaddr;
152	int howto;
153{
154	u_long marks[MARK_MAX];
155	int fd;
156
157	marks[MARK_START] = loadaddr;
158	if ((fd = loadfile(name, marks, LOAD_KERNEL)) == -1)
159		return;
160
161	marks[MARK_END] = round_to_size(marks[MARK_END] - loadaddr);
162	printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n",
163	    marks[MARK_ENTRY], marks[MARK_NSYM],
164	    marks[MARK_SYM], marks[MARK_END]);
165
166	machdep_start((char *)marks[MARK_ENTRY], howto,
167	    (char *)loadaddr, (char *)marks[MARK_SYM],
168	    (char *)marks[MARK_END]);
169}
170