1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
/* $NetBSD: boot.c,v 1.5 1995/11/30 00:59:06 jtc Exp $ */
/*-
* Copyright (c) 1982, 1986, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)boot.c 8.1 (Berkeley) 6/10/93
*/
#ifndef lint
static char rcsid[] = "$NetBSD: boot.c,v 1.5 1995/11/30 00:59:06 jtc Exp $";
#endif /* not lint */
#include <sys/param.h>
#include <sys/reboot.h>
#include <a.out.h>
#include "stand.h"
#include "samachdep.h"
/*
* Boot program... bits in `howto' determine whether boot stops to
* ask for system name. Boot device is derived from ROM provided
* information.
*/
extern unsigned opendev;
extern int noconsole;
extern int testing;
char *ssym, *esym;
char *name;
char *names[] = {
"/netbsd", "/onetbsd", "/netbsd.old",
};
#define NUMNAMES (sizeof(names)/sizeof(char *))
#define LOADADDR ((char *)0x2000)
static int bdev, bctlr, bunit, bpart;
main()
{
int currname = 0;
int io;
cninit();
scsiinit();
printf("\n>> NetBSD BOOT pc532 [$Revision: 1.3 $]\n");
bdev = B_TYPE(bootdev);
bctlr = B_CONTROLLER(bootdev);
bunit = B_UNIT(bootdev);
bpart = B_PARTITION(bootdev);
for (;;) {
name = names[currname++];
if (currname == NUMNAMES)
currname = 0;
if (!noconsole) {
howto = 0;
getbootdev(&howto);
}
else
printf(": %s\n", name);
io = open(name, 0);
if (io >= 0) {
copyunix(howto, opendev, io);
close(io);
}
else
printf("boot: %s\n", strerror(errno));
}
}
/*ARGSUSED*/
copyunix(howto, devtype, io)
register int howto; /* boot flags */
register u_int devtype; /* boot device */
register int io;
{
struct exec x;
int i;
register char *load; /* load addr for unix */
register char *addr;
char *file;
int dev, ctlr, unit, part;
/* XXX use devtype? */
dev = B_TYPE(opendev);
ctlr = B_CONTROLLER(opendev);
unit = B_UNIT(opendev);
part = B_PARTITION(opendev);
/* get the file name part of name */
devparse(name, &i, &i, &i, &i, &i, &file);
i = read(io, (char *)&x, sizeof(x));
if (i != sizeof(x) || N_BADMAG(x)) {
printf("Bad format\n");
return;
}
addr = LOADADDR; /* Always load at LOADADDR */
load = (char *)(x.a_entry & 0x00ffff00); /* XXX make less magical? */
printf("Booting %s%d%c:%s @ 0x%x\n",
devsw[dev].dv_name, unit + (8*ctlr), 'a' + part, file, load);
if (testing) {
load = addr = alloc(2*1024*1024); /* XXX stat the file? */
if (!addr) {
printf("alloc failed\n");
exit(1);
}
}
/* Text */
printf("%d", x.a_text);
if (N_GETMAGIC(x) == ZMAGIC && lseek(io, 0, SEEK_SET) == -1)
goto shread;
if (read(io, addr, x.a_text) != x.a_text)
goto shread;
addr += x.a_text;
if (N_GETMAGIC(x) == NMAGIC)
while ((int)addr & CLOFSET)
*addr++ = 0;
/* Data */
printf("+%d", x.a_data);
if (read(io, addr, x.a_data) != x.a_data)
goto shread;
addr += x.a_data;
/* Bss */
printf("+%d", x.a_bss);
bzero( addr, x.a_bss );
addr += x.a_bss;
/* Symbols */
ssym = load + (addr - LOADADDR);
bcopy(&x.a_syms, addr, sizeof(x.a_syms));
addr += sizeof(x.a_syms);
printf(" [%d+", x.a_syms);
if (x.a_syms && read(io, addr, x.a_syms) != x.a_syms)
goto shread;
addr += x.a_syms;
/* read size of string table */
i = 0;
if (x.a_syms && read(io, &i, sizeof(int)) != sizeof(int))
goto shread;
/* read strings */
printf("%d]", i);
bcopy(&i, addr, sizeof(int));
if (i) {
i -= sizeof(int);
addr += sizeof(int);
if (read(io, addr, i) != i)
goto shread;
addr += i;
}
if (load != LOADADDR) {
bcopy(LOADADDR, load, addr - LOADADDR);
addr = load + (addr - LOADADDR);
}
#define round_to_size(x,t) \
(((int)(x) + sizeof(t) - 1) & ~(sizeof(t) - 1))
esym = (char *)round_to_size(addr - load,int);
#undef round_to_size
/* and note the end address of all this */
printf(" total=0x%x", addr);
x.a_entry &= 0xffffff;
printf(" start 0x%x\n", x.a_entry);
#ifdef DEBUG
printf("ssym=0x%x esym=0x%x\n", ssym, esym);
printf("\n\nReturn to boot...\n");
getchar();
#endif
if (!testing) {
#ifdef __GNUC__
/* do NOT change order!!
* the following are passed as args, and are in registers
* clobbered by the last two movd's!!!
*/
asm(" movd %0,r5" : : "g" (load));
asm(" movd %0,r6" : : "g" (devtype));
asm(" movd %0,r7" : : "g" (howto));
/* magic value for locore.s to look for (3253232532) */
asm(" movd %0,r3" : : "i" (0xc1e86394));
asm(" movd %0,r4" : : "g" (esym));
#endif /* __GNUC__ */
(*((int (*)()) x.a_entry))();
}
return;
shread:
printf("Short read\n");
return;
}
char line[100];
getbootdev(howto)
int *howto;
{
char c, *ptr = line;
printf("Boot: [[[%s%d%c:]%s][-abdrs]] :- ",
devsw[bdev].dv_name, bunit + (8 * bctlr), 'a'+bpart, name);
if (tgets(line)) {
while (c = *ptr) {
while (c == ' ')
c = *++ptr;
if (!c)
return;
if (c == '-')
while ((c = *++ptr) && c != ' ')
switch (c) {
case 'a':
*howto |= RB_ASKNAME;
continue;
case 'b':
*howto |= RB_HALT;
continue;
case 'd':
*howto |= RB_KDB;
continue;
case 'r':
*howto |= RB_DFLTROOT;
continue;
case 's':
*howto |= RB_SINGLE;
continue;
}
else {
name = ptr;
while ((c = *++ptr) && c != ' ');
if (c)
*ptr++ = 0;
}
}
} else
printf("\n");
}
|