|
|
1.1 root 1: /*-
2: * Copyright (c) 1990 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * This code is derived from software contributed to Berkeley by
6: * William Jolitz.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed by the University of
19: * California, Berkeley and its contributors.
20: * 4. Neither the name of the University nor the names of its contributors
21: * may be used to endorse or promote products derived from this software
22: * without specific prior written permission.
23: *
24: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34: * SUCH DAMAGE.
35: */
36:
1.1.1.2 root 37: #ifdef lint
1.1 root 38: char copyright[] =
39: "@(#) Copyright (c) 1990 The Regents of the University of California.\n\
40: All rights reserved.\n";
41: #endif /* not lint */
42:
1.1.1.2 root 43: #ifdef lint
1.1.1.4 ! root 44: /* from: static char sccsid[] = "@(#)boot.c 7.3 (Berkeley) 5/4/91"; */
! 45: static char rcsid[] = "boot.c,v 1.4 1993/05/22 08:02:09 cgd Exp";
1.1 root 46: #endif /* not lint */
47:
48: #include "param.h"
49: #include "reboot.h"
50: #include <a.out.h>
51: #include "saio.h"
1.1.1.2 root 52: #include "disklabel.h"
53: #include "dinode.h"
1.1 root 54:
55: /*
1.1.1.2 root 56: * Boot program, loaded by boot block from remaing 7.5K of boot area.
57: * Sifts through disklabel and attempts to load an program image of
58: * a standalone program off the disk. If keyboard is hit during load,
59: * or if an error is encounter, try alternate files.
1.1 root 60: */
61:
1.1.1.4 ! root 62: char *files[] = { "netbsd", "onetbsd", "netbsd.old",
! 63: "386bsd", "o386bsd", "386bsd.old",
! 64: "vmunix", "ovmunix", "vmunix.old",
! 65: "boot", 0};
1.1 root 66: int retry = 0;
1.1.1.2 root 67: extern struct disklabel disklabel;
68: extern int bootdev, cyloffset;
1.1.1.3 root 69: static unsigned char *biosparams = (char *) 0x9ff00; /* XXX */
1.1 root 70:
1.1.1.2 root 71: /*
72: * Boot program... loads /boot out of filesystem indicated by arguements.
73: * We assume an autoboot unless we detect a misconfiguration.
74: */
1.1 root 75:
1.1.1.2 root 76: main(dev, unit, off)
77: {
78: register struct disklabel *lp;
79: register int io;
80: register char **bootfile = files;
81: int howto = 0;
1.1.1.3 root 82: extern int scsisn; /* XXX */
1.1.1.2 root 83:
84:
85: /* are we a disk, if so look at disklabel and do things */
86: lp = &disklabel;
1.1.1.3 root 87: if (lp->d_type == DTYPE_SCSI) /* XXX */
88: off = htonl(scsisn); /* XXX */
89:
90: /*printf("cyl %x %x hd %x sect %x ", biosparams[0], biosparams[1], biosparams[2], biosparams[0xe]);
91: printf("dev %x unit %x off %d\n", dev, unit, off);*/
92:
1.1.1.2 root 93: if (lp->d_magic == DISKMAGIC) {
94: /*
95: * Synthesize bootdev from dev, unit, type and partition
96: * information from the block 0 bootstrap.
97: * It's dirty work, but someone's got to do it.
98: * This will be used by the filesystem primatives, and
99: * drivers. Ultimately, opendev will be created corresponding
100: * to which drive to pass to top level bootstrap.
101: */
102: for (io = 0; io < lp->d_npartitions; io++) {
1.1.1.3 root 103: int sn;
104:
1.1.1.2 root 105: if (lp->d_partitions[io].p_size == 0)
106: continue;
1.1.1.3 root 107: if (lp->d_type == DTYPE_SCSI)
108: sn = off;
109: else
110: sn = off * lp->d_secpercyl;
111: if (lp->d_partitions[io].p_offset == sn)
1.1.1.2 root 112: break;
113: }
114:
1.1.1.3 root 115: if (io == lp->d_npartitions) goto screwed;
1.1.1.2 root 116: cyloffset = off;
117: } else {
118: screwed:
119: /* probably a bad or non-existant disklabel */
120: io = 0 ;
121: howto |= RB_SINGLE|RB_ASKNAME ;
1.1 root 122: }
123:
1.1.1.2 root 124: /* construct bootdev */
125: /* currently, PC has no way of booting off alternate controllers */
126: bootdev = MAKEBOOTDEV(/*i_dev*/ dev, /*i_adapt*/0, /*i_ctlr*/0,
127: unit, /*i_part*/io);
128:
129: for (;;) {
1.1 root 130:
1.1.1.2 root 131: /*printf("namei %s", *bootfile);*/
132: io = namei(*bootfile);
133: if (io > 2) {
1.1.1.3 root 134: copyunix(io, howto, off);
1.1 root 135: } else
1.1.1.2 root 136: printf("File not found");
1.1 root 137:
1.1.1.2 root 138: printf(" - didn't load %s, ",*bootfile);
139: if(*++bootfile == 0) bootfile = files;
140: printf("will try %s\n", *bootfile);
1.1 root 141:
1.1.1.2 root 142: wait(1<<((retry++) + 10));
1.1 root 143: }
144: }
145:
146: /*ARGSUSED*/
1.1.1.3 root 147: copyunix(io, howto, cyloff)
1.1 root 148: register io;
149: {
150: struct exec x;
151: int i;
152: char *addr,c;
1.1.1.2 root 153: struct dinode fil;
154: int off;
1.1 root 155:
1.1.1.2 root 156: fetchi(io, &fil);
157: /*printf("mode %o ", fil.di_mode);*/
158: i = iread(&fil, 0, (char *)&x, sizeof x);
159: off = sizeof x;
160: if (i != sizeof x || x.a_magic != 0413) {
161: printf("Not an executable format");
1.1 root 162: return;
163: }
164:
1.1.1.3 root 165: if (roundup(x.a_text, 4096) + x.a_data + x.a_bss > (unsigned)&fil) {
166: printf("File too big to load");
167: return;
168: }
169:
1.1.1.2 root 170: off = 4096;
171: if (iread(&fil, off, (char *)0, x.a_text) != x.a_text)
1.1 root 172: goto shread;
1.1.1.2 root 173: off += x.a_text;
1.1 root 174:
175: addr = (char *)x.a_text;
1.1.1.2 root 176: while ((int)addr & CLOFSET)
177: *addr++ = 0;
178:
179: if (iread(&fil, off, addr, x.a_data) != x.a_data)
1.1 root 180: goto shread;
181:
182: addr += x.a_data;
1.1.1.3 root 183:
184: if (addr + x.a_bss > (unsigned) &fil) {
185: printf("Warning: bss overlaps bootstrap");
186: x.a_bss = (unsigned)addr - (unsigned)&fil;
187: }
1.1.1.2 root 188: bzero(addr, x.a_bss);
1.1 root 189:
190: /* mask high order bits corresponding to relocated system base */
1.1.1.2 root 191: x.a_entry &= ~0xfff00000;
1.1 root 192:
1.1.1.2 root 193: /*if (scankbd()) {
194: printf("Operator abort");
195: kbdreset();
196: return;
197: }*/
1.1 root 198:
1.1.1.2 root 199: /* howto, bootdev, cyl */
1.1.1.3 root 200: /*printf("entry %x [%x] ", x.a_entry, *(int *) x.a_entry);*/
201: bcopy(0x9ff00, 0x300, 0x20); /* XXX */
202: i = (*((int (*)()) x.a_entry))(howto, bootdev, off);
1.1 root 203:
1.1.1.2 root 204: if (i) printf("Program exits with %d", i) ;
1.1 root 205: return;
206: shread:
1.1.1.2 root 207: printf("Read of file is incomplete");
1.1 root 208: return;
209: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.