|
|
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
! 44: static char sccsid[] = "from:@(#)boot.c 7.3 (Berkeley) 5/4/91";
1.1 root 45: #endif /* not lint */
46:
47: #include "param.h"
48: #include "reboot.h"
49: #include <a.out.h>
50: #include "saio.h"
1.1.1.2 ! root 51: #include "disklabel.h"
! 52: #include "dinode.h"
1.1 root 53:
54: /*
1.1.1.2 ! root 55: * Boot program, loaded by boot block from remaing 7.5K of boot area.
! 56: * Sifts through disklabel and attempts to load an program image of
! 57: * a standalone program off the disk. If keyboard is hit during load,
! 58: * or if an error is encounter, try alternate files.
1.1 root 59: */
60:
1.1.1.2 ! root 61: char *files[] = { "386bsd", "386bsd.alt", "386bsd.old", "boot" , "vmunix", 0};
1.1 root 62: int retry = 0;
1.1.1.2 ! root 63: extern struct disklabel disklabel;
! 64: extern int bootdev, cyloffset;
1.1 root 65:
1.1.1.2 ! root 66: /*
! 67: * Boot program... loads /boot out of filesystem indicated by arguements.
! 68: * We assume an autoboot unless we detect a misconfiguration.
! 69: */
1.1 root 70:
1.1.1.2 ! root 71: main(dev, unit, off)
! 72: {
! 73: register struct disklabel *lp;
! 74: register int io;
! 75: register char **bootfile = files;
! 76: int howto = 0;
! 77:
! 78: /*printf("dev %x unit %x off %d\n", dev, unit, off);*/
! 79: /*unit = off = 0;
! 80: dev = 2;*/
! 81:
! 82: /* are we a disk, if so look at disklabel and do things */
! 83: lp = &disklabel;
! 84: if (lp->d_magic == DISKMAGIC) {
! 85: /*
! 86: * Synthesize bootdev from dev, unit, type and partition
! 87: * information from the block 0 bootstrap.
! 88: * It's dirty work, but someone's got to do it.
! 89: * This will be used by the filesystem primatives, and
! 90: * drivers. Ultimately, opendev will be created corresponding
! 91: * to which drive to pass to top level bootstrap.
! 92: */
! 93: for (io = 0; io < lp->d_npartitions; io++) {
! 94: #ifdef notyetSCSI
! 95: if (lp->d_type == DTYPE_SCSI) {
! 96: if (lp->d_partitions[io].p_offset == off)
! 97: break;
! 98: } else
! 99: #endif
! 100: if (lp->d_partitions[io].p_size == 0)
! 101: continue;
! 102: if (lp->d_partitions[io].p_offset == off*lp->d_secpercyl)
! 103: break;
! 104: }
! 105:
! 106: if (io == 8) goto screwed;
! 107: cyloffset = off;
! 108: } else {
! 109: screwed:
! 110: /* probably a bad or non-existant disklabel */
! 111: io = 0 ;
! 112: howto |= RB_SINGLE|RB_ASKNAME ;
1.1 root 113: }
114:
1.1.1.2 ! root 115: /* construct bootdev */
! 116: /* currently, PC has no way of booting off alternate controllers */
! 117: bootdev = MAKEBOOTDEV(/*i_dev*/ dev, /*i_adapt*/0, /*i_ctlr*/0,
! 118: unit, /*i_part*/io);
! 119:
! 120: for (;;) {
1.1 root 121:
1.1.1.2 ! root 122: /*printf("namei %s", *bootfile);*/
! 123: io = namei(*bootfile);
! 124: if (io > 2) {
! 125: copyunix(io, howto);
1.1 root 126: } else
1.1.1.2 ! root 127: printf("File not found");
1.1 root 128:
1.1.1.2 ! root 129: printf(" - didn't load %s, ",*bootfile);
! 130: if(*++bootfile == 0) bootfile = files;
! 131: printf("will try %s\n", *bootfile);
1.1 root 132:
1.1.1.2 ! root 133: wait(1<<((retry++) + 10));
1.1 root 134: }
135: }
136:
137: /*ARGSUSED*/
138: copyunix(io, howto)
139: register io;
140: {
141: struct exec x;
142: int i;
143: char *addr,c;
1.1.1.2 ! root 144: struct dinode fil;
! 145: int off;
1.1 root 146:
1.1.1.2 ! root 147: fetchi(io, &fil);
! 148: /*printf("mode %o ", fil.di_mode);*/
! 149: i = iread(&fil, 0, (char *)&x, sizeof x);
! 150: off = sizeof x;
! 151: if (i != sizeof x || x.a_magic != 0413) {
! 152: printf("Not an executable format");
1.1 root 153: return;
154: }
155:
1.1.1.2 ! root 156: off = 4096;
! 157: if (iread(&fil, off, (char *)0, x.a_text) != x.a_text)
1.1 root 158: goto shread;
1.1.1.2 ! root 159: off += x.a_text;
1.1 root 160:
161: addr = (char *)x.a_text;
1.1.1.2 ! root 162: while ((int)addr & CLOFSET)
! 163: *addr++ = 0;
! 164:
! 165: if (iread(&fil, off, addr, x.a_data) != x.a_data)
1.1 root 166: goto shread;
167:
168: addr += x.a_data;
1.1.1.2 ! root 169: bzero(addr, x.a_bss);
1.1 root 170:
171: /* mask high order bits corresponding to relocated system base */
1.1.1.2 ! root 172: x.a_entry &= ~0xfff00000;
1.1 root 173:
1.1.1.2 ! root 174: /*if (scankbd()) {
! 175: printf("Operator abort");
! 176: kbdreset();
! 177: return;
! 178: }*/
1.1 root 179:
1.1.1.2 ! root 180: /* howto, bootdev, cyl */
! 181: i = (*((int (*)()) x.a_entry))(3, bootdev, 0);
1.1 root 182:
1.1.1.2 ! root 183: if (i) printf("Program exits with %d", i) ;
1.1 root 184: return;
185: shread:
1.1.1.2 ! root 186: printf("Read of file is incomplete");
1.1 root 187: return;
188: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.