[BACK]Return to bootxx.c CVS log [TXT][DIR] Up to [local] / sys / arch / vax / boot / xxboot

Annotation of sys/arch/vax/boot/xxboot/bootxx.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: bootxx.c,v 1.10 2003/08/15 23:16:30 deraadt Exp $ */
        !             2: /* $NetBSD: bootxx.c,v 1.16 2002/03/29 05:45:08 matt Exp $ */
        !             3:
        !             4: /*-
        !             5:  * Copyright (c) 1982, 1986 The Regents of the University of California.
        !             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. 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      7.15 (Berkeley) 5/4/91
        !            33:  */
        !            34:
        !            35: #include "sys/param.h"
        !            36: #include "sys/reboot.h"
        !            37: #include "sys/disklabel.h"
        !            38: #include "sys/exec.h"
        !            39: #include "sys/exec_elf.h"
        !            40:
        !            41: #include "lib/libsa/stand.h"
        !            42: #include "lib/libsa/ufs.h"
        !            43: #include "lib/libsa/cd9660.h"
        !            44:
        !            45: #include "machine/pte.h"
        !            46: #include "machine/sid.h"
        !            47: #include "machine/mtpr.h"
        !            48: #include "machine/reg.h"
        !            49: #include "machine/rpb.h"
        !            50: #include "../vax/gencons.h"
        !            51:
        !            52: #include "../mba/mbareg.h"
        !            53: #include "../mba/hpreg.h"
        !            54:
        !            55: #define NRSP 1 /* Kludge */
        !            56: #define NCMD 1 /* Kludge */
        !            57: #define LIBSA_TOO_OLD
        !            58:
        !            59: #include "arch/vax/mscp/mscp.h"
        !            60: #include "arch/vax/mscp/mscpreg.h"
        !            61:
        !            62: #include "../boot/data.h"
        !            63:
        !            64: #define        RF_PROTECTED_SECTORS    64      /* XXX refer to <.../rf_optnames.h> */
        !            65:
        !            66: void   Xmain(void);
        !            67: void   hoppabort(int);
        !            68: void   romread_uvax(int lbn, int size, void *buf, struct rpb *rpb);
        !            69: void   hpread(int block);
        !            70: int    read750(int block, int *regs);
        !            71: int    unit_init(int, struct rpb *, int);
        !            72:
        !            73: struct open_file file;
        !            74:
        !            75: unsigned *bootregs;
        !            76: struct rpb *rpb;
        !            77: struct bqo *bqo;
        !            78: int    vax_cputype;
        !            79: int    vax_load_failure;
        !            80: struct udadevice {u_short udaip;u_short udasa;};
        !            81: volatile struct udadevice *csr;
        !            82: static int moved;
        !            83:
        !            84: extern int from;
        !            85: #define        FROM750 1
        !            86: #define        FROMMV  2
        !            87: #define        FROMVMB 4
        !            88:
        !            89: /*
        !            90:  * The boot block are used by 11/750, 8200, MicroVAX II/III, VS2000,
        !            91:  * VS3100/??, VS4000 and VAX6000/???, and only when booting from disk.
        !            92:  */
        !            93: void
        !            94: Xmain(void)
        !            95: {
        !            96:        union {
        !            97:                struct exec aout;
        !            98:                Elf32_Ehdr elf;
        !            99:        } hdr;
        !           100:        int io;
        !           101:        u_long entry;
        !           102:
        !           103:        vax_cputype = (mfpr(PR_SID) >> 24) & 0xFF;
        !           104:        moved = 0;
        !           105:        /*
        !           106:         */
        !           107:        rpb = (void *)0xf0000; /* Safe address right now */
        !           108:        bqo = (void *)0xf1000;
        !           109:         if (from == FROMMV) {
        !           110:                /*
        !           111:                 * now relocate rpb/bqo (which are used by ROM-routines)
        !           112:                 */
        !           113:                bcopy ((void *)bootregs[11], rpb, sizeof(struct rpb));
        !           114:                bcopy ((void*)rpb->iovec, bqo, rpb->iovecsz);
        !           115: #if 0
        !           116:                if (rpb->devtyp == BDEV_SDN)
        !           117:                        rpb->devtyp = BDEV_SD;  /* XXX until driver fixed */
        !           118: #endif
        !           119:        } else {
        !           120:                bzero(rpb, sizeof(struct rpb));
        !           121:                rpb->devtyp = bootregs[0];
        !           122:                rpb->unit = bootregs[3];
        !           123:                rpb->rpb_bootr5 = bootregs[5];
        !           124:                rpb->csrphy = bootregs[2];
        !           125:                rpb->adpphy = bootregs[1];      /* BI node on 8200 */
        !           126:                if (rpb->devtyp != BDEV_HP && vax_cputype == VAX_TYP_750)
        !           127:                        rpb->adpphy =
        !           128:                            (bootregs[1] == 0xffe000 ? 0xf30000 : 0xf32000);
        !           129:         }
        !           130:        rpb->rpb_base = rpb;
        !           131:        rpb->iovec = (int)bqo;
        !           132:
        !           133:        io = open("/boot.vax", 0);
        !           134:        if (io < 0)
        !           135:                io = open("/boot", 0);
        !           136:        if (io < 0)
        !           137:                asm("movl $0xbeef1, r0; halt");
        !           138:
        !           139:        read(io, (void *)&hdr.aout, sizeof(hdr.aout));
        !           140:        if (N_GETMAGIC(hdr.aout) == OMAGIC && N_GETMID(hdr.aout) == MID_VAX) {
        !           141:                vax_load_failure++;
        !           142:                entry = hdr.aout.a_entry;
        !           143:                if (entry < sizeof(hdr.aout))
        !           144:                        entry = sizeof(hdr.aout);
        !           145:                read(io, (void *) entry, hdr.aout.a_text + hdr.aout.a_data);
        !           146:                memset((void *) (entry + hdr.aout.a_text + hdr.aout.a_data),
        !           147:                       0, hdr.aout.a_bss);
        !           148:        } else if (memcmp(hdr.elf.e_ident, ELFMAG, SELFMAG) == 0) {
        !           149:                Elf32_Phdr ph;
        !           150:                size_t off = sizeof(hdr.elf);
        !           151:                vax_load_failure += 2;
        !           152:                read(io, (caddr_t)(&hdr.elf) + sizeof(hdr.aout),
        !           153:                     sizeof(hdr.elf) - sizeof(hdr.aout));
        !           154:                if (hdr.elf.e_machine != EM_VAX || hdr.elf.e_type != ET_EXEC
        !           155:                    || hdr.elf.e_phnum != 1)
        !           156:                        goto die;
        !           157:                vax_load_failure++;
        !           158:                entry = hdr.elf.e_entry;
        !           159:                if (hdr.elf.e_phoff != sizeof(hdr.elf))
        !           160:                        goto die;
        !           161:                vax_load_failure++;
        !           162:                read(io, &ph, sizeof(ph));
        !           163:                off += sizeof(ph);
        !           164:                if (ph.p_type != PT_LOAD)
        !           165:                        goto die;
        !           166:                vax_load_failure++;
        !           167:                while (off < ph.p_offset) {
        !           168:                        u_int32_t tmp;
        !           169:                        read(io, &tmp, sizeof(tmp));
        !           170:                        off += sizeof(tmp);
        !           171:                }
        !           172:                read(io, (void *) ph.p_paddr, ph.p_filesz);
        !           173:                memset((void *) (ph.p_paddr + ph.p_filesz), 0,
        !           174:                       ph.p_memsz - ph.p_filesz);
        !           175:        } else {
        !           176:                goto die;
        !           177:        }
        !           178:        hoppabort(entry);
        !           179: die:
        !           180:        asm("movl $0xbeef2, r0; halt");
        !           181: }
        !           182:
        !           183: /*
        !           184:  * Write an extremely limited version of a (us)tar filesystem, suitable
        !           185:  * for loading secondary-stage boot loader.
        !           186:  * - Can only load file "boot".
        !           187:  * - Must be the first file on tape.
        !           188:  */
        !           189: struct fs_ops file_system[] = {
        !           190: #ifdef NEED_UFS
        !           191:        { ufs_open, 0, ufs_read, 0, 0, ufs_stat },
        !           192: #endif
        !           193: #ifdef NEED_CD9660
        !           194:        { cd9660_open, 0, cd9660_read, 0, 0, cd9660_stat },
        !           195: #endif
        !           196: #ifdef NEED_USTARFS
        !           197:        { ustarfs_open, 0, ustarfs_read, 0, 0, ustarfs_stat },
        !           198: #endif
        !           199: };
        !           200:
        !           201: int nfsys = (sizeof(file_system) / sizeof(struct fs_ops));
        !           202:
        !           203: #ifdef LIBSA_TOO_OLD
        !           204: #include "../boot/vaxstand.h"
        !           205:
        !           206: struct rom_softc {
        !           207:        int part;
        !           208:        int unit;
        !           209: } rom_softc;
        !           210:
        !           211: int    romstrategy(void *, int, daddr_t, size_t, void *, size_t *);
        !           212: int romopen(struct open_file *, int, int, int, int);
        !           213: struct devsw   devsw[] = {
        !           214:        SADEV("rom", romstrategy, romopen, nullsys, noioctl),
        !           215: };
        !           216: int    ndevs = (sizeof(devsw)/sizeof(devsw[0]));
        !           217:
        !           218: int
        !           219: romopen(struct open_file *f, int adapt, int ctlr, int unit, int part)
        !           220: {
        !           221:        rom_softc.unit = unit;
        !           222:        rom_softc.part = part;
        !           223:
        !           224:        f->f_devdata = (void *)&rom_softc;
        !           225:
        !           226:        return 0;
        !           227: }
        !           228:
        !           229: #endif
        !           230:
        !           231: int
        !           232: devopen(struct open_file *f, const char *fname, char **file)
        !           233: {
        !           234:
        !           235: #ifdef LIBSA_TOO_OLD
        !           236:        int i;
        !           237:        struct devsw    *dp;
        !           238:        f->f_dev = &devsw[0];
        !           239: #endif
        !           240:        *file = (char *)fname;
        !           241:
        !           242:        if (from == FROM750)
        !           243:                return 0;
        !           244:        /*
        !           245:         * Reinit the VMB boot device.
        !           246:         */
        !           247:        if (bqo->unit_init && (moved++ == 0)) {
        !           248:                int initfn;
        !           249:
        !           250:                initfn = rpb->iovec + bqo->unit_init;
        !           251:                if (rpb->devtyp == BDEV_UDA || rpb->devtyp == BDEV_TK) {
        !           252:                        /*
        !           253:                         * This reset do not seem to be done in the
        !           254:                         * ROM routines, so we have to do it manually.
        !           255:                         */
        !           256:                        csr = (struct udadevice *)rpb->csrphy;
        !           257:                        csr->udaip = 0;
        !           258:                        while ((csr->udasa & MP_STEP1) == 0)
        !           259:                                ;
        !           260:                }
        !           261:                /*
        !           262:                 * AP (R12) have a pointer to the VMB argument list,
        !           263:                 * wanted by bqo->unit_init.
        !           264:                 */
        !           265:                unit_init(initfn, rpb, bootregs[12]);
        !           266:        }
        !           267:        return 0;
        !           268: }
        !           269:
        !           270: extern struct disklabel romlabel;
        !           271:
        !           272: int
        !           273: romstrategy(sc, func, dblk, size, buf, rsize)
        !           274:        void    *sc;
        !           275:        int     func;
        !           276:        daddr_t dblk;
        !           277:        size_t  size;
        !           278:        void    *buf;
        !           279:        size_t  *rsize;
        !           280: {
        !           281:        int     block = dblk;
        !           282:        int     nsize = size;
        !           283:
        !           284:        if (romlabel.d_magic == DISKMAGIC && romlabel.d_magic2 == DISKMAGIC) {
        !           285:                if (romlabel.d_npartitions > 1) {
        !           286:                        block += romlabel.d_partitions[0].p_offset;
        !           287:                        if (romlabel.d_partitions[0].p_fstype == FS_RAID) {
        !           288:                                block += RF_PROTECTED_SECTORS;
        !           289:                        }
        !           290:                }
        !           291:        }
        !           292:
        !           293:        if (from == FROMMV) {
        !           294:                romread_uvax(block, size, buf, rpb);
        !           295:        } else /* if (from == FROM750) */ {
        !           296:                while (size > 0) {
        !           297:                        if (rpb->devtyp == BDEV_HP)
        !           298:                                hpread(block);
        !           299:                        else
        !           300:                                read750(block, bootregs);
        !           301:                        bcopy(0, buf, 512);
        !           302:                        size -= 512;
        !           303:                        (char *)buf += 512;
        !           304:                        block++;
        !           305:                }
        !           306:        }
        !           307:
        !           308:        if (rsize)
        !           309:                *rsize = nsize;
        !           310:        return 0;
        !           311: }
        !           312:
        !           313: /*
        !           314:  * The 11/750 boot ROM for Massbus disks doesn't seen to have layout info
        !           315:  * for all RP disks (not RP07 at least) so therefore a very small and dumb
        !           316:  * device driver is used. It assumes that there is a label on the disk
        !           317:  * already that has valid layout info. If there is no label, we can't boot
        !           318:  * anyway.
        !           319:  */
        !           320:
        !           321: #define MBA_WCSR(reg, val) \
        !           322:        ((void)(*(volatile u_int32_t *)((adpadr) + (reg)) = (val)));
        !           323: #define MBA_RCSR(reg) \
        !           324:        (*(volatile u_int32_t *)((adpadr) + (reg)))
        !           325: #define HP_WCSR(reg, val) \
        !           326:        ((void)(*(volatile u_int32_t *)((unitadr) + (reg)) = (val)));
        !           327: #define HP_RCSR(reg) \
        !           328:        (*(volatile u_int32_t *)((unitadr) + (reg)))
        !           329:
        !           330: void
        !           331: hpread(int bn)
        !           332: {
        !           333:        int adpadr = bootregs[1];
        !           334:        int unitadr = adpadr + MUREG(bootregs[3], 0);
        !           335:        u_int cn, sn, tn;
        !           336:        struct disklabel *dp;
        !           337:        extern char start;
        !           338:
        !           339:        dp = (struct disklabel *)(LABELOFFSET + &start);
        !           340:        MBA_WCSR(MAPREG(0), PG_V);
        !           341:
        !           342:        MBA_WCSR(MBA_VAR, 0);
        !           343:        MBA_WCSR(MBA_BC, (~512) + 1);
        !           344: #ifdef __GNUC__
        !           345:        /*
        !           346:         * Avoid four subroutine calls by using hardware division.
        !           347:         */
        !           348:        asm("clrl %r1;"
        !           349:            "movl %3,%r0;"
        !           350:            "ediv %4,%r0,%0,%1;"
        !           351:            "movl %1,%r0;"
        !           352:            "ediv %5,%r0,%2,%1"
        !           353:            : "=g"(cn),"=g"(sn),"=g"(tn)
        !           354:            : "g"(bn),"g"(dp->d_secpercyl),"g"(dp->d_nsectors)
        !           355:            : "r0","r1","cc");
        !           356: #else
        !           357:        cn = bn / dp->d_secpercyl;
        !           358:        sn = bn % dp->d_secpercyl;
        !           359:        tn = sn / dp->d_nsectors;
        !           360:        sn = sn % dp->d_nsectors;
        !           361: #endif
        !           362:        HP_WCSR(HP_DC, cn);
        !           363:        HP_WCSR(HP_DA, (tn << 8) | sn);
        !           364:        HP_WCSR(HP_CS1, HPCS_READ);
        !           365:
        !           366:        while (MBA_RCSR(MBA_SR) & MBASR_DTBUSY)
        !           367:                ;
        !           368:        return;
        !           369: }
        !           370:
        !           371: extern char end[];
        !           372: static char *top = (char*)end;
        !           373:
        !           374: void *
        !           375: alloc(unsigned int size)
        !           376: {
        !           377:        void *ut = top;
        !           378:        top += size;
        !           379:        return ut;
        !           380: }
        !           381:
        !           382: void
        !           383: free(void *ptr, unsigned int size)
        !           384: {
        !           385: }
        !           386:
        !           387: #ifdef USE_PRINTF
        !           388: void
        !           389: putchar(int ch)
        !           390: {
        !           391:        /*
        !           392:         * On KA88 we may get C-S/C-Q from the console.
        !           393:         * Must obey it.
        !           394:         */
        !           395:        while (mfpr(PR_RXCS) & GC_DON) {
        !           396:                if ((mfpr(PR_RXDB) & 0x7f) == 19) {
        !           397:                        while (1) {
        !           398:                                while ((mfpr(PR_RXCS) & GC_DON) == 0)
        !           399:                                        ;
        !           400:                                if ((mfpr(PR_RXDB) & 0x7f) == 17)
        !           401:                                        break;
        !           402:                        }
        !           403:                }
        !           404:        }
        !           405:
        !           406:        while ((mfpr(PR_TXCS) & GC_RDY) == 0)
        !           407:                ;
        !           408:        mtpr(0, PR_TXCS);
        !           409:        mtpr(ch & 0377, PR_TXDB);
        !           410:        if (ch == 10)
        !           411:                putchar(13);
        !           412: }
        !           413: #endif

CVSweb