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

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

1.1     ! nbrk        1: /*     $OpenBSD: wrtvid.c,v 1.7 2007/06/17 00:28:57 deraadt Exp $ */
        !             2:
        !             3: /*
        !             4:  * Copyright (c) 1995 Dale Rahn <drahn@openbsd.org>
        !             5:  *
        !             6:  * Permission to use, copy, modify, and distribute this software for any
        !             7:  * purpose with or without fee is hereby granted, provided that the above
        !             8:  * copyright notice and this permission notice appear in all copies.
        !             9:  *
        !            10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
        !            11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
        !            12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
        !            13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
        !            14:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
        !            15:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
        !            16:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
        !            17:  */
        !            18:
        !            19: #include <sys/types.h>
        !            20: #include <sys/stat.h>
        !            21: #include <sys/disklabel.h>
        !            22: #include <unistd.h>
        !            23: #include <fcntl.h>
        !            24: #include <stdio.h>
        !            25: #include <stdlib.h>
        !            26: #include <string.h>
        !            27:
        !            28: void   copy_exe(int, int);
        !            29: void   swabcfg(struct mvmedisklabel *);
        !            30: void   swabvid(struct mvmedisklabel *);
        !            31:
        !            32: int
        !            33: main(argc, argv)
        !            34:        int argc;
        !            35:        char **argv;
        !            36: {
        !            37:        struct mvmedisklabel *pcpul;
        !            38:        struct stat stat;
        !            39:        int exe_file;
        !            40:        int tape_vid;
        !            41:        int tape_exe;
        !            42:        unsigned int exe_addr;
        !            43:        char *filename;
        !            44:        char fileext[256];
        !            45:
        !            46:        if (argc == 1)
        !            47:                filename = "a.out";
        !            48:        else
        !            49:                filename = argv[1];
        !            50:
        !            51:        exe_file = open(filename, O_RDONLY,0444);
        !            52:        if (exe_file == -1) {
        !            53:                perror(filename);
        !            54:                exit(2);
        !            55:        }
        !            56:        snprintf(fileext, sizeof fileext, "%c%cboot", filename[4], filename[5]);
        !            57:        tape_vid = open(fileext, O_WRONLY|O_CREAT|O_TRUNC, 0644);
        !            58:        snprintf(fileext, sizeof fileext, "boot%c%c", filename[4], filename[5]);
        !            59:        tape_exe = open(fileext, O_WRONLY|O_CREAT|O_TRUNC,0644);
        !            60:
        !            61:        pcpul = (struct mvmedisklabel *)malloc(sizeof(struct mvmedisklabel));
        !            62:        bzero(pcpul, sizeof(struct mvmedisklabel));
        !            63:
        !            64:        pcpul->version = 1;
        !            65:        memcpy(pcpul->vid_id, "M88K", sizeof pcpul->vid_id);
        !            66:
        !            67:        fstat(exe_file, &stat);
        !            68:        /* size in 256 byte blocks round up after a.out header removed */
        !            69:
        !            70:        if (filename[5] == 't' ) {
        !            71:                pcpul->vid_oss = 1;
        !            72:        }else {
        !            73:                pcpul->vid_oss = 2;
        !            74:        }
        !            75:        pcpul->vid_osl = (((stat.st_size -0x20) +511) / 512) *2;
        !            76:
        !            77:        lseek(exe_file, 0x14, SEEK_SET);
        !            78:        read(exe_file, &exe_addr, 4);
        !            79:
        !            80:        /* check this, it may not work in both endian. */
        !            81:        /* No, it doesn't.  Use a big endian machine for now. SPM */
        !            82:
        !            83:        {
        !            84:                union {
        !            85:                        struct s {
        !            86:                                unsigned short s1;
        !            87:                                unsigned short s2;
        !            88:                        } s;
        !            89:                        unsigned long l;
        !            90:                } a;
        !            91:                a.l = exe_addr;
        !            92:                pcpul->vid_osa_u = a.s.s1;
        !            93:                pcpul->vid_osa_l = a.s.s2;
        !            94:
        !            95:        }
        !            96:        pcpul->vid_cas = 1;
        !            97:        pcpul->vid_cal = 1;
        !            98:        /* do not want to write past end of structure, not null terminated */
        !            99:        strncpy(pcpul->vid_mot, "MOTOROLA", 8);
        !           100:
        !           101:        if (BYTE_ORDER != BIG_ENDIAN)
        !           102:                swabvid(pcpul);
        !           103:
        !           104:        pcpul->cfg_rec = 0x100;
        !           105:        pcpul->cfg_psm = 0x200;
        !           106:
        !           107:        if (BYTE_ORDER != BIG_ENDIAN)
        !           108:                swabcfg(pcpul);
        !           109:
        !           110:        write(tape_vid, pcpul, sizeof(struct mvmedisklabel));
        !           111:
        !           112:        free(pcpul);
        !           113:
        !           114:        copy_exe(exe_file, tape_exe);
        !           115:        close(exe_file);
        !           116:        close(tape_vid);
        !           117:        close(tape_exe);
        !           118:        return (0);
        !           119: }
        !           120:
        !           121: #define BUF_SIZ 512
        !           122: void
        !           123: copy_exe(exe_file, tape_exe)
        !           124:        int exe_file, tape_exe;
        !           125: {
        !           126:        char *buf;
        !           127:        int cnt = 0;
        !           128:
        !           129:        buf = (char *)malloc(BUF_SIZ);
        !           130:
        !           131:        lseek (exe_file, 0x20, SEEK_SET);
        !           132:        while (BUF_SIZ == (cnt = read(exe_file, buf, BUF_SIZ))) {
        !           133:                write(tape_exe, buf, cnt);
        !           134:        }
        !           135:        bzero(&buf[cnt], BUF_SIZ-cnt);
        !           136:        write(tape_exe, buf, BUF_SIZ);
        !           137: }
        !           138:
        !           139: void
        !           140: swabvid(pcpul)
        !           141:        struct mvmedisklabel *pcpul;
        !           142: {
        !           143:        swap32(pcpul->vid_oss);
        !           144:        swap16(pcpul->vid_osl);
        !           145: #if 0
        !           146:        swap16(pcpul->vid_osa_u);
        !           147:        swap16(pcpul->vid_osa_l);
        !           148: #endif
        !           149:        swap32(pcpul->vid_cas);
        !           150: }
        !           151:
        !           152: void
        !           153: swabcfg(pcpul)
        !           154:        struct mvmedisklabel *pcpul;
        !           155: {
        !           156:        swap16(pcpul->cfg_atm);
        !           157:        swap16(pcpul->cfg_prm);
        !           158:        swap16(pcpul->cfg_atm);
        !           159:        swap16(pcpul->cfg_rec);
        !           160:        swap16(pcpul->cfg_trk);
        !           161:        swap16(pcpul->cfg_psm);
        !           162:        swap16(pcpul->cfg_shd);
        !           163:        swap16(pcpul->cfg_pcom);
        !           164:        swap16(pcpul->cfg_rwcc);
        !           165:        swap16(pcpul->cfg_ecc);
        !           166:        swap16(pcpul->cfg_eatm);
        !           167:        swap16(pcpul->cfg_eprm);
        !           168:        swap16(pcpul->cfg_eatw);
        !           169:        swap16(pcpul->cfg_rsvc1);
        !           170:        swap16(pcpul->cfg_rsvc2);
        !           171: }

CVSweb