|
|
1.1 root 1: /*-
2: * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms, with or without
6: * modification, are permitted provided that the following conditions
7: * are met:
8: * 1. Redistributions of source code must retain the above copyright
9: * notice, this list of conditions and the following disclaimer.
10: * 2. Redistributions in binary form must reproduce the above copyright
11: * notice, this list of conditions and the following disclaimer in the
12: * documentation and/or other materials provided with the distribution.
13: * 3. All advertising materials mentioning features or use of this software
14: * must display the following acknowledgement:
15: * This product includes software developed by the University of
16: * California, Berkeley and its contributors.
17: * 4. Neither the name of the University nor the names of its contributors
18: * may be used to endorse or promote products derived from this software
19: * without specific prior written permission.
20: *
21: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31: * SUCH DAMAGE.
32: *
1.1.1.2 ! root 33: * from: @(#)boot.c 7.4 (Berkeley) 5/5/91
! 34: * boot.c,v 1.2 1993/05/22 07:58:44 cgd Exp
1.1 root 35: */
36:
37: #include <sys/param.h>
38: #include <sys/reboot.h>
39: #include <a.out.h>
40: #include "saio.h"
41:
42: #ifndef INSECURE
43: #include "sys/stat.h"
44: struct stat sb;
45: #endif
46: /* XXX -- see sys/reboot.h */
47: #define B_MAKEDEV(a,u,p,t) \
48: (((a) << B_ADAPTORSHIFT) | ((u) << B_UNITSHIFT) | \
49: ((p) << B_PARTITIONSHIFT) | ((t) << B_TYPESHIFT))
50:
51: /*
52: * Boot program... arguments in `devtype' and `howto' determine
53: * whether boot stops to ask for system name and which device
54: * boot comes from.
55: */
56:
57: /* Types in `devtype' specifying major device */
58: char devname[][2] = {
59: '\0', '\0', /* 0 = ct */
60: '\0', '\0', /* 1 = fd */
61: 'r', 'd', /* 2 = rd */
62: '\0', '\0', /* 3 = sw */
63: 's', 'd', /* 4 = sd */
64: };
65: #define MAXTYPE (sizeof(devname) / sizeof(devname[0]))
66:
67: char line[100];
68:
69: int retry = 0;
70: extern char *lowram;
71: extern int noconsole;
72: extern int howto, devtype;
73:
74: #define MSUS (0xfffffedc)
75:
76: char rom2mdev[] = {
77: 0, /* 0 - none */
78: 0, /* 1 - none */
79: 0, /* 2 - none */
80: 0, /* 3 - none */
81: 0, /* 4 - none */
82: 0, /* 5 - none */
83: 0, /* 6 - none */
84: 0, /* 7 - none */
85: 0, /* 8 - none */
86: 0, /* 9 - none */
87: 0, /* 10 - none */
88: 0, /* 11 - none */
89: 0, /* 12 - none */
90: 0, /* 13 - none */
91: 4, /* 14 - SCSI disk */
92: 0, /* 15 - none */
93: 2, /* 16 - CS/80 device on HPIB */
94: 2, /* 17 - CS/80 device on HPIB */
95: 0, /* 18 - none */
96: 0, /* 19 - none */
97: 0, /* 20 - none */
98: 0, /* 21 - none */
99: 0, /* 22 - none */
100: 0, /* 23 - none */
101: 0, /* 24 - none */
102: 0, /* 25 - none */
103: 0, /* 26 - none */
104: 0, /* 27 - none */
105: 0, /* 28 - none */
106: 0, /* 29 - none */
107: 0, /* 30 - none */
108: 0, /* 31 - none */
109: };
110:
111: main()
112: {
113: register type, part, unit, io;
114: register char *cp;
115:
116: printf("\nBoot\n");
117: #ifdef JUSTASK
118: howto = RB_ASKNAME|RB_SINGLE;
119: #else
120: type = (devtype >> B_TYPESHIFT) & B_TYPEMASK;
121: unit = (devtype >> B_UNITSHIFT) & B_UNITMASK;
122: unit += 8 * ((devtype >> B_ADAPTORSHIFT) & B_ADAPTORMASK);
123: part = (devtype >> B_PARTITIONSHIFT) & B_PARTITIONMASK;
124: if ((howto & RB_ASKNAME) == 0) {
125: if ((devtype & B_MAGICMASK) != B_DEVMAGIC) {
126: /*
127: * we have to map the ROM device type codes
128: * to Unix major device numbers.
129: */
130: type = rom2mdev[*(char *)MSUS & 0x1f];
131: devtype = (devtype &~ (B_TYPEMASK << B_TYPESHIFT))
132: | (type << B_TYPESHIFT);
133: }
134: if (type >= 0 && type <= MAXTYPE && devname[type][0]) {
135: cp = line;
136: *cp++ = devname[type][0];
137: *cp++ = devname[type][1];
138: *cp++ = '(';
139: if (unit >= 10)
140: *cp++ = unit / 10 + '0';
141: *cp++ = unit % 10 + '0';
142: *cp++ = ',';
143: *cp++ = part + '0';
144: *cp++ = ')';
145: strcpy(cp, UNIX);
146: } else
147: howto = RB_SINGLE|RB_ASKNAME;
148: }
149: #endif
150: for (;;) {
151: if (!noconsole && (howto & RB_ASKNAME)) {
152: printf(": ");
153: gets(line);
154: } else
155: printf(": %s\n", line);
156: io = open(line, 0);
157: if (io >= 0) {
158: #ifndef INSECURE
159: (void) fstat(io, &sb);
160: if (sb.st_uid || (sb.st_mode & 2)) {
161: printf("non-secure file, will not load\n");
162: howto = RB_SINGLE|RB_ASKNAME;
163: continue;
164: }
165: #endif
166: if (howto & RB_ASKNAME) {
167: /*
168: * Build up devtype register to pass on to
169: * booted program.
170: */
171: cp = line;
172: for (type = 0; type <= MAXTYPE; type++)
173: if ((devname[type][0] == cp[0]) &&
174: (devname[type][1] == cp[1]))
175: break;
176: if (type <= MAXTYPE) {
177: cp += 3;
178: unit = *cp++ - '0';
179: if (*cp >= '0' && *cp <= '9')
180: unit = unit * 10 + *cp++ - '0';
181: cp++;
182: part = atol(cp);
183: devtype = B_MAKEDEV(unit >> 3, unit & 7, part, type);
184: }
185: }
186: devtype |= B_DEVMAGIC;
187: copyunix(howto, devtype, io);
188: close(io);
189: howto = RB_SINGLE|RB_ASKNAME;
190: }
191: bad:
192: if (++retry > 2)
193: howto = RB_SINGLE|RB_ASKNAME;
194: }
195: }
196:
197: /*ARGSUSED*/
198: copyunix(howto, devtype, io)
199: register howto; /* d7 contains boot flags */
200: register devtype; /* d6 contains boot device */
201: register io;
202: {
203: struct exec x;
204: register int i;
205: register char *load; /* a5 contains load addr for unix */
206: register char *addr;
207:
208: i = read(io, (char *)&x, sizeof x);
209: if (i != sizeof x ||
210: (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410))
211: _stop("Bad format\n");
212: printf("%d", x.a_text);
213: if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1)
214: goto shread;
215: load = addr = lowram;
216: if (read(io, (char *)addr, x.a_text) != x.a_text)
217: goto shread;
218: addr += x.a_text;
219: if (x.a_magic == 0413 || x.a_magic == 0410)
220: while ((int)addr & CLOFSET)
221: *addr++ = 0;
222: printf("+%d", x.a_data);
223: if (read(io, addr, x.a_data) != x.a_data)
224: goto shread;
225: addr += x.a_data;
226: printf("+%d", x.a_bss);
227: x.a_bss += 128*512; /* slop */
228: for (i = 0; i < x.a_bss; i++)
229: *addr++ = 0;
230: x.a_entry += (int)lowram;
231: printf(" start 0x%x\n", x.a_entry);
232: #ifdef __GNUC__
233: asm(" movl %0,d7" : : "m" (howto));
234: asm(" movl %0,d6" : : "m" (devtype));
235: asm(" movl %0,a5" : : "a" (load));
236: #endif
237: (*((int (*)()) x.a_entry))();
238: exit();
239: shread:
240: _stop("Short read\n");
241: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.