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

Annotation of sys/arch/aviion/stand/libsa/exec_aout.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: exec_aout.c,v 1.2 2006/05/20 22:40:46 miod Exp $      */
        !             2:
        !             3: /*-
        !             4:  * Copyright (c) 1982, 1986, 1990, 1993
        !             5:  *     The Regents of the University of California.  All rights reserved.
        !             6:  *
        !             7:  * Redistribution and use in source and binary forms, with or without
        !             8:  * modification, are permitted provided that the following conditions
        !             9:  * are met:
        !            10:  * 1. Redistributions of source code must retain the above copyright
        !            11:  *    notice, this list of conditions and the following disclaimer.
        !            12:  * 2. Redistributions in binary form must reproduce the above copyright
        !            13:  *    notice, this list of conditions and the following disclaimer in the
        !            14:  *    documentation and/or other materials provided with the distribution.
        !            15:  * 3. Neither the name of the University nor the names of its contributors
        !            16:  *    may be used to endorse or promote products derived from this software
        !            17:  *    without specific prior written permission.
        !            18:  *
        !            19:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            20:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            21:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            22:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            23:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            24:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            25:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            26:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            27:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            28:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            29:  * SUCH DAMAGE.
        !            30:  *
        !            31:  *     @(#)boot.c      8.1 (Berkeley) 6/10/93
        !            32:  */
        !            33:
        !            34: #include <sys/param.h>
        !            35: #include <sys/reboot.h>
        !            36: #include <machine/prom.h>
        !            37: #include <a.out.h>
        !            38:
        !            39: #include "stand.h"
        !            40: #include "libsa.h"
        !            41:
        !            42: #define        SYM_MAGIC       0x6274ef2e
        !            43:
        !            44: /*ARGSUSED*/
        !            45: void
        !            46: exec_aout(char *file, const char *args, int bootdev, int bootunit, int bootpart)
        !            47: {
        !            48:        char *loadaddr;
        !            49:        int io;
        !            50:        struct exec x;
        !            51:        int cc, magic;
        !            52:        void (*entry)();
        !            53:        char *cp;
        !            54:        int *ip;
        !            55:
        !            56:        io = open(file, 0);
        !            57:        if (io < 0)
        !            58:                return;
        !            59:
        !            60:        /*
        !            61:         * Read in the exec header, and validate it.
        !            62:         */
        !            63:        if (read(io, (char *)&x, sizeof(x)) != sizeof(x))
        !            64:                goto shread;
        !            65:
        !            66:        if (N_BADMAG(x)) {
        !            67:                errno = EFTYPE;
        !            68:                goto closeout;
        !            69:        }
        !            70:
        !            71:        /*
        !            72:         * note: on the mvme ports, the kernel is linked in such a way that
        !            73:         * its entry point is the first item in .text, and thus a_entry can
        !            74:         * be used to determine both the load address and the entry point.
        !            75:         * (also note that we make use of the fact that the kernel will live
        !            76:         *  in a VA == PA range of memory ... otherwise we would take
        !            77:         *  loadaddr as a parameter and let the kernel relocate itself!)
        !            78:         *
        !            79:         * note that ZMAGIC files included the a.out header in the text area
        !            80:         * so we must mask that off (has no effect on the other formats)
        !            81:         */
        !            82:        loadaddr = (void *)(x.a_entry & ~sizeof(x));
        !            83:
        !            84:        cp = loadaddr;
        !            85:        magic = N_GETMAGIC(x);
        !            86:        if (magic == ZMAGIC)
        !            87:                cp += sizeof(x);
        !            88:        entry = (void (*)())cp;
        !            89:
        !            90:        /*
        !            91:         * Read in the text segment.
        !            92:         */
        !            93:        printf("%d", x.a_text);
        !            94:        cc = x.a_text;
        !            95:        if (magic == ZMAGIC)
        !            96:                cc = cc - sizeof(x); /* a.out header part of text in zmagic */
        !            97:        if (read(io, cp, cc) != cc)
        !            98:                goto shread;
        !            99:        cp += cc;
        !           100:
        !           101:        /*
        !           102:         * NMAGIC may have a gap between text and data.
        !           103:         */
        !           104:        if (magic == NMAGIC) {
        !           105:                register int mask = N_PAGSIZ(x) - 1;
        !           106:                while ((int)cp & mask)
        !           107:                        *cp++ = 0;
        !           108:        }
        !           109:
        !           110:        /*
        !           111:         * Read in the data segment.
        !           112:         */
        !           113:        printf("+%d", x.a_data);
        !           114:        if (read(io, cp, x.a_data) != x.a_data)
        !           115:                goto shread;
        !           116:        cp += x.a_data;
        !           117:
        !           118:        /*
        !           119:         * Zero out the BSS section.
        !           120:         */
        !           121:        printf("+%d", x.a_bss);
        !           122:        cc = x.a_bss;
        !           123:        while ((int)cp & 3) {
        !           124:                *cp++ = 0;
        !           125:                --cc;
        !           126:        }
        !           127:        ip = (int *)cp;
        !           128:        cp += cc;
        !           129:        while ((char *)ip < cp)
        !           130:                *ip++ = 0;
        !           131:
        !           132:        /*
        !           133:         * Read in the symbol table and strings.
        !           134:         * (Always set the symtab size word.)
        !           135:         */
        !           136:        *ip++ = x.a_syms;
        !           137:        cp = (char *) ip;
        !           138:
        !           139:        if (x.a_syms > 0) {
        !           140:                /* Symbol table and string table length word. */
        !           141:                cc = x.a_syms;
        !           142:                printf("+[%d", cc);
        !           143:                cc += sizeof(int);      /* strtab length too */
        !           144:                if (read(io, cp, cc) != cc)
        !           145:                        goto shread;
        !           146:                cp += x.a_syms;
        !           147:                ip = (int *)cp;         /* points to strtab length */
        !           148:                cp += sizeof(int);
        !           149:
        !           150:                /* String table.  Length word includes itself. */
        !           151:                cc = *ip;
        !           152:                printf("+%d]", cc);
        !           153:                cc -= sizeof(int);
        !           154:                if (cc <= 0)
        !           155:                        goto shread;
        !           156:                if (read(io, cp, cc) != cc)
        !           157:                        goto shread;
        !           158:                cp += cc;
        !           159:        }
        !           160:        printf("=0x%lx\n", cp - loadaddr);
        !           161:        close(io);
        !           162:
        !           163:        (*entry)(args, bootdev, bootunit, bootpart, SYM_MAGIC, cp);
        !           164:
        !           165:        printf("exec: kernel returned!\n");
        !           166:        return;
        !           167:
        !           168: shread:
        !           169:        printf("exec: short read\n");
        !           170:        errno = EIO;
        !           171: closeout:
        !           172:        close(io);
        !           173:        return;
        !           174: }

CVSweb