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