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

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: 
        !            37: #ifndef lint
        !            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: 
        !            43: #ifndef lint
        !            44: static char sccsid[] = "@(#)boot.c     7.3 (Berkeley) 5/4/91";
        !            45: #endif /* not lint */
        !            46: 
        !            47: #include "param.h"
        !            48: #include "reboot.h"
        !            49: #include <a.out.h>
        !            50: #include <setjmp.h>
        !            51: #include "saio.h"
        !            52: 
        !            53: /*
        !            54:  * Boot program... arguments from lower-level bootstrap determine
        !            55:  * whether boot stops to ask for system name and which device
        !            56:  * boot comes from.
        !            57:  */
        !            58: 
        !            59: char line[100] = UNIX;
        !            60: extern int opendev, bootdev, cyloffset;
        !            61: int    retry = 0;
        !            62: extern jmp_buf  exception;
        !            63: 
        !            64: main(howto, dev, off)
        !            65: {
        !            66:        int io;
        !            67: 
        !            68:        if((dev&B_MAGICMASK) == B_DEVMAGIC) {
        !            69:                bootdev = dev;
        !            70:                cyloffset = off;
        !            71:        } else  goto again;
        !            72: 
        !            73:        if(_setjmp(exception)) {
        !            74:                close(io);
        !            75:                printf("- load aborted\n");
        !            76: again:
        !            77:                howto = RB_SINGLE|RB_ASKNAME;
        !            78:                cyloffset = 0; 
        !            79:        }
        !            80:                
        !            81:        for (;;) {
        !            82:                if (howto & RB_ASKNAME) {
        !            83:                        char *cp;
        !            84: 
        !            85:                        printf("Boot: ");
        !            86:                        gets(line);
        !            87: 
        !            88:                        /* process additional flags if any */
        !            89:                        if(cp = (char *)index(line, ' ')) {
        !            90:                                howto = strtol (cp, 0, 0);
        !            91:                                *cp = '\0';
        !            92:                        }
        !            93:                        cyloffset = 0;
        !            94:                } else
        !            95:                        printf("Boot: %s\n", line);
        !            96: 
        !            97:                if (line[0] == 0) {
        !            98:                        strcpy(line, UNIX);
        !            99:                        printf("Boot: %s\n", line);
        !           100:                }
        !           101: 
        !           102:                io = open(line, 0);
        !           103:                if (io >= 0) {
        !           104:                        copyunix(io, howto);
        !           105:                        goto again;
        !           106:                } else if (++retry > 2)
        !           107:                        goto again;
        !           108:        }
        !           109: }
        !           110: 
        !           111: /*ARGSUSED*/
        !           112: copyunix(io, howto)
        !           113:        register io;
        !           114: {
        !           115:        struct exec x;
        !           116:        int i;
        !           117:        char *addr,c;
        !           118: 
        !           119:        i = read(io, (char *)&x, sizeof x);
        !           120:        if (i != sizeof x ||
        !           121:            (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410)) {
        !           122:                printf("Bad format\n");
        !           123:                return;
        !           124:        }
        !           125: 
        !           126:        printf("%d", x.a_text);
        !           127:        if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1)
        !           128:                goto shread;
        !           129:        if (read(io, (char *)0, x.a_text) != x.a_text)
        !           130:                goto shread;
        !           131: 
        !           132:        addr = (char *)x.a_text;
        !           133:        if (x.a_magic == 0413 || x.a_magic == 0410)
        !           134:                while ((int)addr & CLOFSET)
        !           135:                        *addr++ = 0;
        !           136:        printf("+%d", x.a_data);
        !           137:        if (read(io, addr, x.a_data) != x.a_data)
        !           138:                goto shread;
        !           139: 
        !           140:        addr += x.a_data;
        !           141:        printf("+%d", x.a_bss);
        !           142:        x.a_bss += 128*512;     /* slop */
        !           143:        for (i = 0; i < x.a_bss; i++)
        !           144:                *addr++ = 0;
        !           145: 
        !           146:        /* mask high order bits corresponding to relocated system base */
        !           147:        x.a_entry &= 0xfff00000;
        !           148:        printf(" start 0x%x\n", x.a_entry);
        !           149: 
        !           150:        if(c=scankbd())
        !           151:                _longjmp(&exception,1);
        !           152: 
        !           153:        i = (*((int (*)()) x.a_entry))(howto, opendev, 0, cyloffset);
        !           154: 
        !           155:        if (i) printf("exit %d\n", i) ; 
        !           156:        return;
        !           157: shread:
        !           158:        printf("Short read\n");
        !           159:        return;
        !           160: }

unix.superglobalmegacorp.com

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