Annotation of sys/arch/mvme68k/stand/wrtvid/wrtvid.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: wrtvid.c,v 1.7 2007/06/17 00:28:56 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 <fcntl.h>
! 23: #include <unistd.h>
! 24: #include <stdio.h>
! 25: #define __DBINTERFACE_PRIVATE
! 26: #include <db.h>
! 27:
! 28: #define BUF_SIZ 512
! 29: static void
! 30: copy_exe(int exe_file, int tape_exe)
! 31: {
! 32: char *buf;
! 33: int cnt = 0;
! 34:
! 35: buf = (char *)malloc(BUF_SIZ);
! 36:
! 37: lseek (exe_file, 0x20, SEEK_SET);
! 38: while (BUF_SIZ == (cnt = read(exe_file, buf, BUF_SIZ)))
! 39: write(tape_exe, buf, cnt);
! 40: bzero(&buf[cnt], BUF_SIZ-cnt);
! 41: write(tape_exe, buf, BUF_SIZ);
! 42: }
! 43:
! 44: static void
! 45: swabvid(struct mvmedisklabel *pcpul)
! 46: {
! 47: M_32_SWAP(pcpul->vid_oss);
! 48: M_16_SWAP(pcpul->vid_osl);
! 49: /*
! 50: M_16_SWAP(pcpul->vid_osa_u);
! 51: M_16_SWAP(pcpul->vid_osa_l);
! 52: */
! 53: M_32_SWAP(pcpul->vid_cas);
! 54: }
! 55:
! 56: static void
! 57: swabcfg(struct mvmedisklabel *pcpul)
! 58: {
! 59: M_16_SWAP(pcpul->cfg_atm);
! 60: M_16_SWAP(pcpul->cfg_prm);
! 61: M_16_SWAP(pcpul->cfg_atm);
! 62: M_16_SWAP(pcpul->cfg_rec);
! 63: M_16_SWAP(pcpul->cfg_trk);
! 64: M_16_SWAP(pcpul->cfg_psm);
! 65: M_16_SWAP(pcpul->cfg_shd);
! 66: M_16_SWAP(pcpul->cfg_pcom);
! 67: M_16_SWAP(pcpul->cfg_rwcc);
! 68: M_16_SWAP(pcpul->cfg_ecc);
! 69: M_16_SWAP(pcpul->cfg_eatm);
! 70: M_16_SWAP(pcpul->cfg_eprm);
! 71: M_16_SWAP(pcpul->cfg_eatw);
! 72: M_16_SWAP(pcpul->cfg_rsvc1);
! 73: M_16_SWAP(pcpul->cfg_rsvc2);
! 74: }
! 75:
! 76: int
! 77: main(int argc, char *argv[])
! 78: {
! 79: struct mvmedisklabel *pcpul;
! 80: struct stat stat;
! 81: int exe_file;
! 82: int tape_vid;
! 83: int tape_exe;
! 84: unsigned int exe_addr;
! 85: unsigned short exe_addr_u;
! 86: unsigned short exe_addr_l;
! 87: char *filename;
! 88: char fileext[256];
! 89: char filebase[256];
! 90:
! 91: if (argc == 0)
! 92: filename = "a.out";
! 93: else
! 94: filename = argv[1];
! 95:
! 96: exe_file = open(filename, O_RDONLY,0444);
! 97: if (exe_file == -1) {
! 98: perror(filename);
! 99: exit(2);
! 100: }
! 101: snprintf(fileext, sizeof fileext, "%c%cboot", filename[4], filename[5]);
! 102: tape_vid = open(fileext, O_WRONLY|O_CREAT|O_TRUNC, 0644);
! 103: snprintf(fileext, sizeof fileext, "boot%c%c", filename[4], filename[5]);
! 104: tape_exe = open(fileext, O_WRONLY|O_CREAT|O_TRUNC,0644);
! 105:
! 106: pcpul = (struct mvmedisklabel *)malloc(sizeof(struct mvmedisklabel));
! 107: bzero(pcpul, sizeof(struct mvmedisklabel));
! 108:
! 109: memcpy(pcpul->vid_id, "NBSD", sizeof pcpul->vid_id);
! 110:
! 111: fstat(exe_file, &stat);
! 112: /* size in 256 byte blocks round up after a.out header removed */
! 113:
! 114: if (filename[5] == 't' ) {
! 115: pcpul->vid_oss = 1;
! 116: } else {
! 117: pcpul->vid_oss = 2;
! 118: }
! 119: pcpul->vid_osl = (((stat.st_size -0x20) +511) / 512) *2;
! 120:
! 121: lseek(exe_file, 0x14, SEEK_SET);
! 122: read(exe_file, &exe_addr, 4);
! 123:
! 124: /* check this, it may not work in both endian. */
! 125: {
! 126: union {
! 127: struct s {
! 128: unsigned short s1;
! 129: unsigned short s2;
! 130: } s;
! 131: unsigned long l;
! 132: } a;
! 133: a.l = exe_addr;
! 134: pcpul->vid_osa_u = a.s.s1;
! 135: pcpul->vid_osa_l = a.s.s2;
! 136:
! 137: }
! 138: pcpul->vid_cas = 1;
! 139: pcpul->vid_cal = 1;
! 140: /* do not want to write past end of structure, not null terminated */
! 141: strncpy(pcpul->vid_mot, "MOTOROLA", 8);
! 142:
! 143: if (BYTE_ORDER != BIG_ENDIAN)
! 144: swabvid(pcpul);
! 145:
! 146: pcpul->cfg_rec = 0x100;
! 147: pcpul->cfg_psm = 0x200;
! 148:
! 149: if (BYTE_ORDER != BIG_ENDIAN)
! 150: swabcfg(pcpul);
! 151:
! 152: write(tape_vid, pcpul, sizeof(struct mvmedisklabel));
! 153:
! 154: free(pcpul);
! 155:
! 156: copy_exe(exe_file, tape_exe);
! 157: close(exe_file);
! 158: close(tape_vid);
! 159: close(tape_exe);
! 160: return (0);
! 161: }
CVSweb