boot.c revision 1.2
1/*	$NetBSD: boot.c,v 1.2 2003/08/05 19:10:26 fredette 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 <machine/mon.h>
41
42#include <stand.h>
43#include <loadfile.h>
44#include "libsa.h"
45
46/*
47 * Default the name (really tape segment number).
48 * The defaults assume the following tape layout:
49 *   segment 0:  tapeboot
50 *   segment 1:  netbsd.sun3  (RAMDISK3)
51 *   segment 2:  netbsd.sun3x (RAMDISK3X)
52 *   segment 3:  miniroot image
53 *   segment 4:  netbsd.sun2  (RAMDISK)
54 * Therefore, the default name is "1" or "2" or "4"
55 * for sun3, sun3x, and sun2, respectively.
56 */
57
58char	defname[32] = "1";
59char	line[80];
60
61int
62main()
63{
64	char *cp, *file;
65	void *entry;
66	u_long marks[MARK_MAX];
67	u_long mark_start;
68	int fd;
69
70	printf(">> %s tapeboot [%s]\n", bootprog_name, bootprog_rev);
71	prom_get_boot_info();
72
73	/*
74	 * Can not hold open the tape device as is done
75	 * in the other boot programs because it does
76	 * its position-to-segment on open.
77	 */
78
79	/* Assume the Sun3/Sun3x load start. */
80	memset(marks, 0, sizeof(marks));
81	mark_start = 0;
82
83	/* If running on a Sun3X, use segment 2. */
84	if (_is3x)
85		defname[0] = '2';
86
87	/*
88	 * If running on a Sun2, use segment 4 and
89	 * do the special MMU setup.
90	 */
91	else if (_is2) {
92		defname[0] = '4';
93		mark_start = sun2_map_mem_load();
94	}
95
96	file = defname;
97
98	cp = prom_bootfile;
99	if (cp && *cp)
100		file = cp;
101
102	for (;;) {
103		if (prom_boothow & RB_ASKNAME) {
104			printf("tapeboot: segment? [%s]: ", defname);
105			gets(line);
106			if (line[0])
107				file = line;
108			else
109				file = defname;
110		} else
111			printf("tapeboot: loading segment %s\n", file);
112
113		marks[MARK_START] = mark_start;
114		if ((fd = loadfile(file, marks, LOAD_KERNEL)) != -1) {
115			break;
116		}
117		printf("tapeboot: segment %s: %s\n", file, strerror(errno));
118		prom_boothow |= RB_ASKNAME;
119	}
120	close(fd);
121
122	entry = (void *)marks[MARK_ENTRY];
123	if (_is2) {
124		printf("relocating program...");
125		entry = sun2_map_mem_run(entry);
126	}
127	printf("Starting program at 0x%x\n", entry);
128	chain_to(entry);
129}
130