[BACK]Return to bootxx.c CVS log [TXT][DIR] Up to [local] / sys / arch / sparc / stand / bootxx

Annotation of sys/arch/sparc/stand/bootxx/bootxx.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: bootxx.c,v 1.5 2003/11/14 19:05:36 miod Exp $ */
        !             2: /*     $NetBSD: bootxx.c,v 1.2 1997/09/14 19:28:17 pk Exp $    */
        !             3:
        !             4: /*
        !             5:  * Copyright (c) 1994 Paul Kranenburg
        !             6:  * 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. All advertising materials mentioning features or use of this software
        !            17:  *    must display the following acknowledgement:
        !            18:  *      This product includes software developed by Paul Kranenburg.
        !            19:  * 4. The name of the author may not be used to endorse or promote products
        !            20:  *    derived from this software without specific prior written permission
        !            21:  *
        !            22:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
        !            23:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
        !            24:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
        !            25:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
        !            26:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
        !            27:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
        !            28:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
        !            29:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        !            30:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
        !            31:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        !            32:  */
        !            33:
        !            34: #include <sys/param.h>
        !            35: #include <sys/time.h>
        !            36: #include <a.out.h>
        !            37:
        !            38: #include <lib/libsa/stand.h>
        !            39:
        !            40: #include <sparc/stand/common/promdev.h>
        !            41:
        !            42: int debug;
        !            43: int netif_debug;
        !            44:
        !            45: /*
        !            46:  * Boot device is derived from ROM provided information.
        !            47:  */
        !            48: char           progname[] = "bootxx";
        !            49: struct open_file       io;
        !            50:
        !            51: /*
        !            52:  * The contents of the block_* variables below is set by installboot(8)
        !            53:  * to hold the filesystem data of the second-stage boot program
        !            54:  * (typically `/boot'): filesystem block size, # of filesystem blocks and
        !            55:  * the block numbers themselves.
        !            56:  */
        !            57: #define MAXBLOCKNUM    256     /* enough for a 2MB boot program (bs 8K) */
        !            58: int32_t                        block_size = 0;
        !            59: int32_t                        block_count = MAXBLOCKNUM;
        !            60: daddr_t                        block_table[MAXBLOCKNUM] = { 0 };
        !            61:
        !            62:
        !            63: void   loadboot(struct open_file *, caddr_t);
        !            64:
        !            65: int
        !            66: main(int argc, char *argv[])
        !            67: {
        !            68:        char    *dummy;
        !            69:        size_t  n;
        !            70:        register void (*entry)(caddr_t) = (void (*)(caddr_t))LOADADDR;
        !            71:
        !            72:        prom_init();
        !            73:        io.f_flags = F_RAW;
        !            74:        if (devopen(&io, 0, &dummy)) {
        !            75:                panic("%s: can't open device", progname);
        !            76:        }
        !            77:
        !            78:        (void)loadboot(&io, LOADADDR);
        !            79:        (io.f_dev->dv_close)(&io);
        !            80:        (*entry)(cputyp == CPU_SUN4 ? LOADADDR : (caddr_t)promvec);
        !            81:        _rtt();
        !            82: }
        !            83:
        !            84: void
        !            85: loadboot(f, addr)
        !            86:        register struct open_file       *f;
        !            87:        register char                   *addr;
        !            88: {
        !            89:        register int    i;
        !            90:        register char   *buf;
        !            91:        size_t          n;
        !            92:        daddr_t         blk;
        !            93:
        !            94:        /*
        !            95:         * Allocate a buffer that we can map into DVMA space; only
        !            96:         * needed for sun4 architecture, but use it for all machines
        !            97:         * to keep code size down as much as possible.
        !            98:         */
        !            99:        buf = alloc(block_size);
        !           100:        if (buf == NULL)
        !           101:                panic("%s: alloc failed", progname);
        !           102:
        !           103:        for (i = 0; i < block_count; i++) {
        !           104:                if ((blk = block_table[i]) == 0)
        !           105:                        panic("%s: block table corrupt", progname);
        !           106:
        !           107: #ifdef DEBUG
        !           108:                printf("%s: block # %d = %d\n", progname, i, blk);
        !           109: #endif
        !           110:                if ((f->f_dev->dv_strategy)(f->f_devdata, F_READ,
        !           111:                                            blk, block_size, buf, &n)) {
        !           112:                        panic("%s: read failure", progname);
        !           113:                }
        !           114:                bcopy(buf, addr, block_size);
        !           115:                if (n != block_size)
        !           116:                        panic("%s: short read", progname);
        !           117:                if (i == 0) {
        !           118:                        register int m = N_GETMAGIC(*(struct exec *)addr);
        !           119:                        if (m == ZMAGIC || m == NMAGIC || m == OMAGIC) {
        !           120:                                /* Move exec header out of the way */
        !           121:                                bcopy(addr, addr - sizeof(struct exec), n);
        !           122:                                addr -= sizeof(struct exec);
        !           123:                        }
        !           124:                }
        !           125:                addr += n;
        !           126:        }
        !           127:
        !           128: }

CVSweb