[BACK]Return to exec_mvme.c CVS log [TXT][DIR] Up to [local] / sys / arch / mvme88k / stand / libsa

Annotation of sys/arch/mvme88k/stand/libsa/exec_mvme.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: exec_mvme.c,v 1.13 2006/05/17 06:21:34 miod Exp $     */
        !             2:
        !             3:
        !             4: /*-
        !             5:  * Copyright (c) 1982, 1986, 1990, 1993
        !             6:  *     The Regents of the University of California.  All rights reserved.
        !             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. Neither the name of the University nor the names of its contributors
        !            17:  *    may be used to endorse or promote products derived from this software
        !            18:  *    without specific prior written permission.
        !            19:  *
        !            20:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            21:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            22:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            23:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            24:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            25:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            26:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            28:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            29:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            30:  * SUCH DAMAGE.
        !            31:  *
        !            32:  *     @(#)boot.c      8.1 (Berkeley) 6/10/93
        !            33:  */
        !            34:
        !            35: #include <sys/param.h>
        !            36: #include <sys/reboot.h>
        !            37: #include <machine/prom.h>
        !            38: #include <a.out.h>
        !            39:
        !            40: #include "stand.h"
        !            41: #include "libsa.h"
        !            42:
        !            43: struct kernel {
        !            44:        void    *entry;
        !            45:        void    *symtab;
        !            46:        void    *esym;
        !            47:        int     bflags;
        !            48:        int     bdev;
        !            49:        char    *kname;
        !            50:        void    *smini;
        !            51:        void    *emini;
        !            52:        u_int   end_loaded;
        !            53: } kernel;
        !            54:
        !            55: /*ARGSUSED*/
        !            56: void
        !            57: exec_mvme(file, flag)
        !            58:        char    *file;
        !            59:        int     flag;
        !            60: {
        !            61:        char *loadaddr;
        !            62:        int io;
        !            63:        struct exec x;
        !            64:        int cc, magic;
        !            65:        void (*entry)();
        !            66:        char *cp;
        !            67:        int *ip;
        !            68:        int bootdev;
        !            69:        struct mvmeprom_brdid *id;
        !            70:
        !            71:        id = mvmeprom_brdid();
        !            72:
        !            73: #ifdef DEBUG
        !            74:        printf("exec_mvme: file=%s flag=0x%x cputyp=%x\n", file, flag, id->model);
        !            75: #endif
        !            76:
        !            77:        io = open(file, 0);
        !            78:        if (io < 0)
        !            79:                return;
        !            80:
        !            81:        /*
        !            82:         * Read in the exec header, and validate it.
        !            83:         */
        !            84:        if (read(io, (char *)&x, sizeof(x)) != sizeof(x))
        !            85:                goto shread;
        !            86:
        !            87:        if (N_BADMAG(x)) {
        !            88:                errno = EFTYPE;
        !            89:                goto closeout;
        !            90:        }
        !            91:
        !            92:        /*
        !            93:         * note: on the mvme ports, the kernel is linked in such a way that
        !            94:         * its entry point is the first item in .text, and thus a_entry can
        !            95:         * be used to determine both the load address and the entry point.
        !            96:         * (also note that we make use of the fact that the kernel will live
        !            97:         *  in a VA == PA range of memory ... otherwise we would take
        !            98:         *  loadaddr as a parameter and let the kernel relocate itself!)
        !            99:         *
        !           100:         * note that ZMAGIC files included the a.out header in the text area
        !           101:         * so we must mask that off (has no effect on the other formats)
        !           102:         */
        !           103:        loadaddr = (void *)(x.a_entry & ~sizeof(x));
        !           104:
        !           105:        cp = loadaddr;
        !           106:        magic = N_GETMAGIC(x);
        !           107:        if (magic == ZMAGIC)
        !           108:                cp += sizeof(x);
        !           109:        entry = (void (*)())cp;
        !           110:
        !           111:        /*
        !           112:         * Leave a copy of the exec header before the text.
        !           113:         * The sun3 kernel uses this to verify that the
        !           114:         * symbols were loaded by this boot program.
        !           115:         */
        !           116:        bcopy(&x, cp - sizeof(x), sizeof(x));
        !           117:
        !           118:        /*
        !           119:         * Read in the text segment.
        !           120:         */
        !           121:        printf("%d", x.a_text);
        !           122:        cc = x.a_text;
        !           123:        if (magic == ZMAGIC)
        !           124:                cc = cc - sizeof(x); /* a.out header part of text in zmagic */
        !           125:        if (read(io, cp, cc) != cc)
        !           126:                goto shread;
        !           127:        cp += cc;
        !           128:
        !           129:        /*
        !           130:         * NMAGIC may have a gap between text and data.
        !           131:         */
        !           132:        if (magic == NMAGIC) {
        !           133:                register int mask = N_PAGSIZ(x) - 1;
        !           134:                while ((int)cp & mask)
        !           135:                        *cp++ = 0;
        !           136:        }
        !           137:
        !           138:        /*
        !           139:         * Read in the data segment.
        !           140:         */
        !           141:        printf("+%d", x.a_data);
        !           142:        if (read(io, cp, x.a_data) != x.a_data)
        !           143:                goto shread;
        !           144:        cp += x.a_data;
        !           145:
        !           146:        /*
        !           147:         * Zero out the BSS section.
        !           148:         * (Kernel doesn't care, but do it anyway.)
        !           149:         */
        !           150:        printf("+%d", x.a_bss);
        !           151:        cc = x.a_bss;
        !           152:        while ((int)cp & 3) {
        !           153:                *cp++ = 0;
        !           154:                --cc;
        !           155:        }
        !           156:        ip = (int *)cp;
        !           157:        cp += cc;
        !           158:        while ((char *)ip < cp)
        !           159:                *ip++ = 0;
        !           160:
        !           161:        /*
        !           162:         * Read in the symbol table and strings.
        !           163:         * (Always set the symtab size word.)
        !           164:         */
        !           165:        *ip++ = x.a_syms;
        !           166:        cp = (char *) ip;
        !           167:
        !           168:        if (x.a_syms > 0 && (flag & RB_NOSYM) == 0) {
        !           169:
        !           170:                /* Symbol table and string table length word. */
        !           171:                cc = x.a_syms;
        !           172:                printf("+[%d", cc);
        !           173:                cc += sizeof(int);      /* strtab length too */
        !           174:                if (read(io, cp, cc) != cc)
        !           175:                        goto shread;
        !           176:                cp += x.a_syms;
        !           177:                ip = (int *)cp;         /* points to strtab length */
        !           178:                cp += sizeof(int);
        !           179:
        !           180:                /* String table.  Length word includes itself. */
        !           181:                cc = *ip;
        !           182:                printf("+%d]", cc);
        !           183:                cc -= sizeof(int);
        !           184:                if (cc <= 0)
        !           185:                        goto shread;
        !           186:                if (read(io, cp, cc) != cc)
        !           187:                        goto shread;
        !           188:                cp += cc;
        !           189:        }
        !           190:        printf("=0x%lx\n", cp - loadaddr);
        !           191:        close(io);
        !           192:
        !           193:        printf("Start @ 0x%x\n", (int)entry);
        !           194:        printf("Controller Address 0x%x\n", bugargs.ctrl_addr);
        !           195:        if (flag & RB_HALT)
        !           196:                _rtt();
        !           197:
        !           198:        bootdev = (bugargs.ctrl_lun << 8) | (bugargs.dev_lun & 0xFF);
        !           199:
        !           200:        (*entry)(flag, bugargs.ctrl_addr, cp, kernel.smini, kernel.emini, bootdev, id->model);
        !           201:        printf("exec: kernel returned!\n");
        !           202:        return;
        !           203:
        !           204: shread:
        !           205:        printf("exec: short read\n");
        !           206:        errno = EIO;
        !           207: closeout:
        !           208:        close(io);
        !           209:        return;
        !           210: }

CVSweb