1 /* $NetBSD: boot.c,v 1.8 2016/06/11 06:49:46 dholland 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
main(void)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 kgets(line, sizeof(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,
111 LOAD_KERNEL & ~LOAD_BACKWARDS)) != -1) {
112 break;
113 }
114 printf("tapeboot: segment %s: %s\n", file, strerror(errno));
115 prom_boothow |= RB_ASKNAME;
116 }
117 close(fd);
118
119 entry = (void *)marks[MARK_ENTRY];
120 if (_is2) {
121 printf("relocating program...");
122 entry = sun2_map_mem_run(entry);
123 }
124 printf("Starting program at 0x%x\n", (u_int)entry);
125 chain_to(entry);
126
127 return 0;
128 }
129