Annotation of Net2/arch/i386/stand/boot.c, revision 1.1.1.3

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.1.3 ! root       65: static unsigned char *biosparams = (char *) 0x9ff00; /* XXX */
1.1       root       66: 
1.1.1.2   root       67: /*
                     68:  * Boot program... loads /boot out of filesystem indicated by arguements.
                     69:  * We assume an autoboot unless we detect a misconfiguration.
                     70:  */
1.1       root       71: 
1.1.1.2   root       72: main(dev, unit, off)
                     73: {
                     74:        register struct disklabel *lp;
                     75:        register int io;
                     76:        register char **bootfile = files;
                     77:        int howto = 0;
1.1.1.3 ! root       78:        extern int scsisn; /* XXX */
1.1.1.2   root       79: 
                     80: 
                     81:        /* are we a disk, if so look at disklabel and do things */
                     82:        lp = &disklabel;
1.1.1.3 ! root       83:        if (lp->d_type == DTYPE_SCSI)           /* XXX */
        !            84:                off = htonl(scsisn);            /* XXX */
        !            85: 
        !            86: /*printf("cyl %x %x hd %x sect %x ", biosparams[0], biosparams[1], biosparams[2], biosparams[0xe]);
        !            87:        printf("dev %x unit %x off %d\n", dev, unit, off);*/
        !            88: 
1.1.1.2   root       89:        if (lp->d_magic == DISKMAGIC) {
                     90:            /*
                     91:             * Synthesize bootdev from dev, unit, type and partition
                     92:             * information from the block 0 bootstrap.
                     93:             * It's dirty work, but someone's got to do it.
                     94:             * This will be used by the filesystem primatives, and
                     95:             * drivers. Ultimately, opendev will be created corresponding
                     96:             * to which drive to pass to top level bootstrap.
                     97:             */
                     98:            for (io = 0; io < lp->d_npartitions; io++) {
1.1.1.3 ! root       99:                int sn;
        !           100: 
1.1.1.2   root      101:                if (lp->d_partitions[io].p_size == 0)
                    102:                        continue;
1.1.1.3 ! root      103:                if (lp->d_type == DTYPE_SCSI)
        !           104:                        sn = off;
        !           105:                else
        !           106:                        sn = off * lp->d_secpercyl;
        !           107:                if (lp->d_partitions[io].p_offset == sn)
1.1.1.2   root      108:                        break;
                    109:            }
                    110: 
1.1.1.3 ! root      111:            if (io == lp->d_npartitions) goto screwed;
1.1.1.2   root      112:             cyloffset = off;
                    113:        } else {
                    114: screwed:
                    115:                /* probably a bad or non-existant disklabel */
                    116:                io = 0 ;
                    117:                howto |= RB_SINGLE|RB_ASKNAME ;
1.1       root      118:        }
                    119: 
1.1.1.2   root      120:        /* construct bootdev */
                    121:        /* currently, PC has no way of booting off alternate controllers */
                    122:        bootdev = MAKEBOOTDEV(/*i_dev*/ dev, /*i_adapt*/0, /*i_ctlr*/0,
                    123:            unit, /*i_part*/io);
                    124: 
                    125:        for (;;) {
1.1       root      126: 
1.1.1.2   root      127: /*printf("namei %s", *bootfile);*/
                    128:                io = namei(*bootfile);
                    129:                if (io > 2) {
1.1.1.3 ! root      130:                        copyunix(io, howto, off);
1.1       root      131:                } else
1.1.1.2   root      132:                        printf("File not found");
1.1       root      133: 
1.1.1.2   root      134:                printf(" - didn't load %s, ",*bootfile);
                    135:                if(*++bootfile == 0) bootfile = files;
                    136:                printf("will try %s\n", *bootfile);
1.1       root      137: 
1.1.1.2   root      138:                wait(1<<((retry++) + 10));
1.1       root      139:        }
                    140: }
                    141: 
                    142: /*ARGSUSED*/
1.1.1.3 ! root      143: copyunix(io, howto, cyloff)
1.1       root      144:        register io;
                    145: {
                    146:        struct exec x;
                    147:        int i;
                    148:        char *addr,c;
1.1.1.2   root      149:        struct dinode fil;
                    150:        int off;
1.1       root      151: 
1.1.1.2   root      152:        fetchi(io, &fil);
                    153: /*printf("mode %o ", fil.di_mode);*/
                    154:        i = iread(&fil, 0,  (char *)&x, sizeof x);
                    155:        off = sizeof x;
                    156:        if (i != sizeof x || x.a_magic != 0413) {
                    157:                printf("Not an executable format");
1.1       root      158:                return;
                    159:        }
                    160: 
1.1.1.3 ! root      161:        if (roundup(x.a_text, 4096) + x.a_data + x.a_bss > (unsigned)&fil) {
        !           162:                printf("File too big to load");
        !           163:                return;
        !           164:        }
        !           165: 
1.1.1.2   root      166:        off = 4096;
                    167:        if (iread(&fil, off, (char *)0, x.a_text) != x.a_text)
1.1       root      168:                goto shread;
1.1.1.2   root      169:        off += x.a_text;
1.1       root      170: 
                    171:        addr = (char *)x.a_text;
1.1.1.2   root      172:        while ((int)addr & CLOFSET)
                    173:                *addr++ = 0;
                    174:        
                    175:        if (iread(&fil, off, addr, x.a_data) != x.a_data)
1.1       root      176:                goto shread;
                    177: 
                    178:        addr += x.a_data;
1.1.1.3 ! root      179: 
        !           180:        if (addr + x.a_bss > (unsigned) &fil) {
        !           181:                printf("Warning: bss overlaps bootstrap");
        !           182:                x.a_bss = (unsigned)addr - (unsigned)&fil;
        !           183:        }
1.1.1.2   root      184:        bzero(addr, x.a_bss);
1.1       root      185: 
                    186:        /* mask high order bits corresponding to relocated system base */
1.1.1.2   root      187:        x.a_entry &= ~0xfff00000;
1.1       root      188: 
1.1.1.2   root      189:        /*if (scankbd()) {
                    190:                printf("Operator abort");
                    191:                kbdreset();
                    192:                return;
                    193:        }*/
1.1       root      194: 
1.1.1.2   root      195:        /* howto, bootdev, cyl */
1.1.1.3 ! root      196:        /*printf("entry %x [%x] ", x.a_entry, *(int *) x.a_entry);*/
        !           197:        bcopy(0x9ff00, 0x300, 0x20); /* XXX */
        !           198:        i = (*((int (*)()) x.a_entry))(howto, bootdev, off);
1.1       root      199: 
1.1.1.2   root      200:        if (i) printf("Program exits with %d", i) ; 
1.1       root      201:        return;
                    202: shread:
1.1.1.2   root      203:        printf("Read of file is incomplete");
1.1       root      204:        return;
                    205: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.