From:	CSBVAX::CSBVAX::MRGATE::"SMTP::VAXMFG.TECH.NWU.EDU::CHOJNACKI"  2-MAR-1989 21:56
To:	MRGATE::"ARISIA::EVERHART"
Subj:	March 2 UNMACRO source 3/8


Received: from vaxmfg.tech.nwu.edu by accuvax.nwu.edu id aa11816;
          2 Mar 89 10:49 CST
Date: Thu, 2 Mar 89 11:00 CST
From: Bob Chojnacki <CHOJNACKI@vaxmfg.tech.nwu.edu>
Subject: March 2 UNMACRO source 3/8
To: EVERHART%ARISIA.decnet@ge-crd.arpa
X-VMS-To: IN%"EVERHART%ARISIA.decnet@ge-crd.arpa"
Message-ID:  <8903021050.aa11816@accuvax.nwu.edu>

+-+-+-+ Beginning of part 3 +-+-+-+
X  `009  fread(hb[i], 512, 1, sfp);
X        `125 else `123
X  `009  fprintf(stderr, "could not allocate room for header block %d\n", i);
X  `009  fread(block, 512, 1, sfp);
X        `125
X      `125
X    `125
X/*
X  interpret image section descriptors
X*/
X    i = h_size;`009`009/* this is where the isd's start */
X    while ((ghw(i) > 0) `124`124 (i/512 < h_blocks-1)) `123
X      if ((i/512 < h_blocks-1) && (ghw(i) < 0))
X`009i += (512 - i%512);`009/* bump it to start of next block */
V      if ((h_isd[h_nisd] = malloc(sizeof(h_isd_type))) && (h_nisd < MAXISD)) `1
X23
X        h_isd[h_nisd]->size = ghw(i);
X        h_isd[h_nisd]->pages = ghw(i+2);
X        h_isd[h_nisd]->vpn = ghw(i+4);
X        h_isd[h_nisd]->pfc = ghb(i+7);
X        h_isd[h_nisd]->flags = ghl(i+8);
X`009if (!(h_isd[h_nisd]->flags & ISD_DZERO))
X          h_isd[h_nisd]->bvbn = ghl(i+12);
X`009else
X          h_isd[h_nisd]->bvbn = 0;
X`009if (h_isd[h_nisd]->flags & ISD_GLOBAL) `123
X          h_isd[h_nisd]->gsid = ghl(i+16);
X          h_isd[h_nisd]->gsnlen = ghb(i+20) & 0xff;
X`009  for (j=0; j<h_isd[h_nisd]->gsnlen; j++)
X`009    h_isd[h_nisd]->gsn[j] = ghb(i+21+j);
X`009`125
X/* find number of pages in memory and base address */
X`009if (!(h_isd[h_nisd]->flags & ISD_GLOBAL) &&
X`009 !(h_isd[h_nisd]->flags & 0xff000000)) `123
X`009  mem_pages = h_isd[h_nisd]->pages + h_isd[h_nisd]->vpn;
X`009  if ((h_isd[h_nisd]->vpn & 0xffff) < lowest_vpn)
X`009    lowest_vpn = h_isd[h_nisd]->vpn & 0xffff;
X`009`125
X      `125 else `123
X        fprintf(stderr, "could not allocate room for isd %d\n", h_isd);
X      `125
X      i += ghw(i);
X      h_nisd++;
X    `125
X/*
X  no image header
X*/
X  `125 else `123
X    h_size = 0;
X    b_offset = 0;
X    c_offset = 0;
X    d_offset = 0;
X    e_offset = 0;
X    h_majid = 0;
X    h_minid = 0;
X    h_blocks = 0;
X    h_itype = 0;
X    h_rpriv[0] = 0;
X    h_rpriv[1] = 0;
X    h_iochans = 0;
X    h_iosegpag = 0;
X    h_iflags = 0;
X    h_gsid = 0;
X    h_sysver = 0;
X    h_transfer1 = 0;
X    h_transfer2 = 0;
X    h_transfer3 = 0;
X  `125
X`125
X
Xchar ghb(i)
Xint i;
X`123
X  int b;
X
X  i &= 0xffff;
X  b = i/512;
X  i %= 512;
X  return (hb[b][i] & 0xff);
X`125
X
Xshort int ghw(i)
Xint i;
X`123
X  int b;
X
X  i &= 0xffff;
X  b = i/512;
X  i %= 512;
X  return (((hb[b][i] & 0xff) + (hb[b][i+1] & 0xff)*256) & 0xffff);
X`125
X
Xint ghl(i)
Xint i;
X`123
X  int b;
X
X  i &= 0xffff;
X  b = i/512;
X  i %= 512;
X  return ((hb[b][i] & 0xff) + (hb[b][i+1] & 0xff)*256
X   + (hb[b][i+2] & 0xff)*65536 + (hb[b][i+3] & 0xff)*16777216);
X`125
X
X/*
X  display header information
X*/
Xdisph(fp)
XFILE *fp;
X`123
X  int i, j, gsnlen;
X
X  if (image_header == 'y') `123
X    fprintf(fp, ";header statistics:\n");
X    fprintf(fp, ";\theader size = %d. bytes\n", h_size);
X    fprintf(fp, ";\toffsets to b, c, d, e = %04X, %04X, %04X, %04X\n",
X     b_offset, c_offset, d_offset, e_offset);
X    fprintf(fp, ";\tmajor id = %02X, minor id = %02X\n", h_majid, h_minid);
X    fprintf(fp, ";\tnumber of header blocks = %d.\n", h_blocks);
X    fprintf(fp, ";\timage type, priv mask = %02X, %08X, %08X\n", h_itype,
X     h_rpriv[0], h_rpriv[1]);
X    fprintf(fp, ";\ti/o channels = %d., i/o seg pages = %d.\n", h_iochans,
X     h_iosegpag);
X    fprintf(fp, ";\timage flags = %08X, gsid = %08X, sys version = %08X\n",
X     h_iflags, h_gsid, h_sysver);
X    if (h_iflags & FLAGS_LNKDEBUG)
X      fprintf(fp, ";\t    LNKDEBUG\n");
X    if (h_iflags & FLAGS_LNKNOTFR)
X      fprintf(fp, ";\t    LNKNOTFR\n");
X    if (h_iflags & FLAGS_NOP0BUFS)
X      fprintf(fp, ";\t    NOP0BUFS\n");
X    if (h_iflags & FLAGS_PICIMG)
X      fprintf(fp, ";\t    PICIMG\n");
X    if (h_iflags & FLAGS_P0IMAGE)
X      fprintf(fp, ";\t    P0IMAGE\n");
X    if (h_iflags & FLAGS_DBGDMT)
X      fprintf(fp, ";\t    DBGDMT\n");
X    if (h_iflags & FLAGS_INISHR)
X      fprintf(fp, ";\t    INISHR\n");
X    fprintf(fp, ";\ttransfer addresses = %08X, %08X, %08X\n", h_transfer1,
X     h_transfer2, h_transfer3);
X    fprintf(fp, ";image section descriptors:\n");
X    for (i=0; i<h_nisd; i++) `123
X      fprintf(fp, ";    isd %d\n", i);
X      fprintf(fp, ";\tsize = %04X", h_isd[i]->size & 0xffff);
X      fprintf(fp, " pages = %04X", h_isd[i]->pages & 0xffff);
X      fprintf(fp, " starting vpn = %04X", h_isd[i]->vpn & 0xffff);
X      fprintf(fp, " pfc = %02X\n", h_isd[i]->pfc & 0xff);
X      fprintf(fp, ";\tflags = %08X", h_isd[i]->flags);
X      if (!(h_isd[i]->flags & ISD_DZERO))
X        fprintf(fp, " base vbn = %04X", h_isd[i]->bvbn);
X      putc('\n', fp);
X      if (h_isd[i]->flags & ISD_GLOBAL)
X`009fprintf(fp, ";\t    Global section\n");
X      if (h_isd[i]->flags & ISD_COR)
X`009fprintf(fp, ";\t    Copy on reference\n");
X      if (h_isd[i]->flags & ISD_DZERO)
X`009fprintf(fp, ";\t    Demand zero\n");
X      if (h_isd[i]->flags & ISD_WRITE)
X`009fprintf(fp, ";\t    Writable\n");
X      if (h_isd[i]->flags & ISD_LC)
X`009fprintf(fp, ";\t    Last cluster in P0 space\n");
X      if (h_isd[i]->flags & ISD_CA)
X`009fprintf(fp, ";\t    Copy always\n");
X      if (h_isd[i]->flags & ISD_BI)
X`009fprintf(fp, ";\t    Based Image\n");
X      if (h_isd[i]->flags & ISD_FV)
X`009fprintf(fp, ";\t    Fixup vector\n");
X      if (h_isd[i]->flags & ISD_ISP)
X`009fprintf(fp, ";\t    Image section is protected\n");
X      if (h_isd[i]->flags & ISD_GLOBAL) `123
X        fprintf(fp, ";\tgsid = %08X name = '", h_isd[i]->gsid);
X        gsnlen = h_isd[i]->gsnlen;
X`009for (j=0; j<gsnlen; j++)
X`009  putc(h_isd[i]->gsn[j], fp);
X`009fprintf(fp, "'\n");
X      `125
X    `125
X  `125 else `123
X    fprintf(fp, ";no file header\n");
X  `125
X`125
$ GOSUB UNPACK_FILE
$ FILE_IS = "HEADER.H"
$ CHECKSUM_IS = 320868829
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/*
X  Image header definitions
X
X  Copyright (c) 1989 By Robert Thomas Chojnacki
X*/
X
X#define`009MAXHB`00932`009`009/* max number of header blocks */
X#define MAXISD`009256`009`009/* max number of isd's */
X
Xtypedef struct h_isd_struct `123`009/* isd = image section descriptor */
X  short int size;`009`009/* size of isd in bytes */
X  short int pages;`009`009/* number of pages in this section */
X  short int vpn;`009`009/* starting virtual page number */
X  char fill_1;
X  char pfc;`009`009`009/* page fault cluster */
X  int flags;`009`009`009/* section flags */
X  int bvbn;`009`009`009/* base virtual block number */
X  int gsid;`009`009`009/* identifier for global section */
X  int gsnlen;`009`009`009/* length of global section name */
X  char gsn[44];`009`009`009/* global section name */
X`125 h_isd_type;
X
X#define ISD_GLOBAL`0091`009/* global section */
X#define ISD_COR`009`0092`009/* copy on reference */
X#define ISD_DZERO`0094`009/* demand zero */
X#define ISD_WRITE`0098`009/* writeable */
X#define ISD_MCF`009`009112`009/* match control field */
X#define ISD_LC`009`009128`009/* last cluster in P0 space */
X#define ISD_CA`009`009256`009/* copy always */
X#define ISD_BI`009`009512`009/* based image */
X#define ISD_FV`009`0091024`009/* fixed vector */
X#define ISD_VCIS`009262144`009/* vector contained in image section */
X#define ISD_ISP`009`009524288`009/* image section is protected */
X
X#define FLAGS_LNKDEBUG`0091
X#define FLAGS_LNKNOTFR`0092
X#define FLAGS_NOP0BUFS`0094
X#define FLAGS_PICIMG`0098
X#define FLAGS_P0IMAGE`00916
X#define FLAGS_DBGDMT`00932
X#define FLAGS_INISHR`00964
X
Xchar ghb();`009`009`009/* get header byte */
Xshort int ghw();`009`009/* get header word */
X
X#ifdef header_main
Xchar *hb[MAXHB];
Xchar image_header;
Xh_isd_type *h_isd[MAXISD];
Xint h_nisd=0;
Xint h_size;
Xint b_offset, c_offset, d_offset, e_offset;
Xint h_majid, h_minid, h_blocks, h_itype;
Xint h_rpriv[2], h_iochans, h_iosegpag, h_iflags, h_gsid, h_sysver;
Xint h_transfer1, h_transfer2, h_transfer3;
Xint mem_pages=0, lowest_vpn = 0x7fffffff;
X#else
Xextern char *hb[];
Xextern char image_header;
Xextern h_isd_type *h_isd[];
Xextern int h_nisd;
Xextern int h_size;
Xextern int b_offset, c_offset, d_offset, e_offset;
Xextern int h_majid, h_minid, h_blocks, h_itype;
Xextern int h_rpriv[2], h_iochans, h_iosegpag, h_iflags, h_gsid, h_sysver;
Xextern int h_transfer1, h_transfer2, h_transfer3;
Xextern int mem_pages, lowest_vpn;
X#endif
$ GOSUB UNPACK_FILE
$ FILE_IS = "INSTALL.DOC"
$ CHECKSUM_IS = 993946384
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
XInstallation procedure:
X
X  1 - create a directory and put all the UNMACRO files in it
X  2 - Edit UNMACRO.C and change the line $DESCRIPTOR(help,"HELP/LIBRARY=..."
X      to point to the directory with all the unmacro stuff in it
X  3 - $ @MAKE_UNMACRO
X  4 - Define UNMACRO_DIR to point at unmacro source
X  5 - Define unmacro:  $ UNMACRO :==$UNMACRO_DIR:UNMACRO
X
XMAKE_UNMACRO.COM took under 3 minutes on a lightly loaded VAX 11/785.
$ GOSUB UNPACK_FILE
$ FILE_IS = "INSTRUCTIONS.C"
$ CHECKSUM_IS = 52417280
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/*
X  this converts an opcode to an ascii string.  It returns the number
X  of operands that the opcode requires.  If it returns -1 then this
X  is a reserved instruction.
X
X  Copyright (c) 1988, Robert Thomas Chojnacki, All rights reserved.
X*/
X#include <stdio.h>
X#include "unmacro.h"
X#include "debug.h"
Xinstructions(opcode, line, alt, altline)
Xint opcode;`009/* input: opcode to decode */
Xchar *line;`009/* output: text line with ascii instruction */
Xint *alt;`009/* output: 1 if this may have a FD byte after the instrx,
X                           2 if this has an alternate name (i.e. branches),
X                           3 if this may have a FF byte after the instrx,
X                           0 if no alterante possibilities */
Xchar *altline;`009/* output: alternate line */
X`123
X  char *opcodes[256] = `123
X   "halt", "nop", "rei", "bpt", "ret", "rsb", "ldpctx", "svpctx",
X   "cvtps", "cvtsp", "index", "crc", "prober", "probew", "insque", "remque",
X   "bsbb", "brb", "bneq", "beql", "bgtr", "bleq", "jsb", "jmp",
X   "bgeq", "blss", "bgtru", "blequ", "bvc", "bvs", "bcc", "bcs",
X   "addp4", "addp6", "subp4", "subp6", "cvtpt", "mulp", "cvttp", "divp",
X   "movc3", "cmpc3", "scanc", "spanc", "movc5", "cmpc5", "movtc", "movtuc",
X   "bsbw", "brw", "cvtwl", "cvtwb", "movp", "cmpp3", "cvtpl", "cmpp4",
X   "editpc", "matchc", "locc", "skpc", "movzwl", "acbw", "movaw", "pushaw",
X   "addf2", "addf3", "subf2", "subf3", "mulf2", "mulf3", "divf2", "divf3",
X   "cvtfb", "cvtfw", "cvtfl", "cvtrfl", "cvtbf", "cvtwf", "cvtlf", "acbf",
X   "movf", "cmpf", "mnegf", "tstf", "emodf", "polyf", "cvtfd", "Reserved",
V   "adawi","Reserved","Reserved","Reserved","insqhi","insqti","remqhi","remqti"
X,
X   "addd2", "addd3", "subd2", "subd3", "muld2", "muld3", "divd2", "divd3",
X   "cvtdb", "cvtdw", "cvtdl", "cvtrdl", "cvtbd", "cvtwd", "cvtld", "acbd",
X   "movd", "cmpd", "mnegd", "tstd", "emodd", "polyd", "cvtdf", "Reserved",
X   "ashl", "ashq", "emul", "ediv", "clrq", "movq", "movaq", "pushaq",
X   "addb2", "addb3", "subb2", "subb3", "mulb2", "mulb3", "divb2", "divb3",
X   "bisb2", "bisb3", "bicb2", "bicb3", "xorb2", "xorb3", "mnegb", "caseb",
X   "movb", "cmpb", "mcomb", "bitb", "clrb", "tstb", "incb", "decb",
X   "cvtbl", "cvtbw", "movzbl", "movzbw", "rotl", "acbb", "movab", "pushab",
X   "addw2", "addw3", "subw2", "subw3", "mulw2", "mulw3", "divw2", "divbw3",
X   "bisw2", "bisw3", "bicw2", "bicw3", "xorw2", "xorw3", "mnegw", "casew",
X   "movw", "cmpw", "mcomw", "bitw", "clrw", "tstw", "incw", "decw",
X   "bispsw", "bicpsw", "popr", "pushr", "chmk", "chme", "chms", "chmu",
X   "addl2", "addl3", "subl2", "subl3", "mull2", "mull3", "divl2", "divl3",
X   "bisl2", "bisl3", "bicl2", "bicl3", "xorl2", "xorl3", "mnegl", "casel",
X   "movl", "cmpl", "mcoml", "bitl", "clrl", "tstl", "incl", "decl",
X   "adwc", "sbwc", "mtpr", "mfpr", "movpsl", "pushl", "moval", "pushal",
X   "bbs", "bbc", "bbss", "bbcs", "bbsc", "bbcc", "bbssi", "bbcci",
X   "blbs", "blbc", "ffs", "ffc", "cmpv", "cmpzv", "extv", "extzv",
X   "insv", "acbl", "aoblss", "aobleq", "sobgeq", "sobgtr", "cvtlb", "cvtlw",
X   "ashp", "cvtlp", "callg", "calls", "xfc", "escd", "esce", "escf"`125;
X  char *alt_opcodes[256] = `123
X   "0", "0", "0", "0", "0", "0", "0", "0",
X   "0", "0", "0", "0", "0", "0", "0", "0",
X   "0", "0", "bnequ", "0", "beqlu", "0", "0", "0",
X   "0", "0", "0", "0", "0", "0", "bgequ", "blssu",
X   "0", "0", "0", "0", "0", "0", "0", "0",
X   "0", "0", "0", "0", "0", "0", "0", "0",
X   "0", "0", "cvtdh", "cvtgf", "0", "0", "0", "0",
X   "0", "0", "0", "0", "0", "0", "0", "0",
X   "addg2", "addg3", "subg2", "subg3", "mulg2", "mulg3", "divg2", "divg3",
X   "cvtgb", "cvtgw", "cvtgl", "cvtrgl", "cvtbg", "cvtwg", "cvtlg", "acbg",
X   "movg", "cmpg", "mnegg", "tstg", "emodg", "polyg", "cvtgh", "0",
X   "0", "0", "0", "0", "0", "0", "0", "0",
X   "addh2", "addh3", "subh2", "subh3", "mulh2", "mulh3", "divh2", "divh3",
X   "cvthb", "cvthw", "cvthl", "cvtrhl", "cvtbh", "cvtwh", "cvtlh", "acbh",
X   "movh", "cmph", "mnegh", "tsth", "emodh", "polyh", "cvthg", "0",
X   "0", "0", "0", "0", "clro", "movo", "movao", "pushao",
X   "0", "0", "0", "0", "0", "0", "0", "0",
X   "0", "0", "0", "0", "0", "0", "0", "0",
X   "0", "0", "0", "0", "0", "0", "0", "0",
X   "cvtfh", "cvtfg", "0", "0", "0", "0", "0", "0",
X   "0", "0", "0", "0", "0", "0", "0", "0",
X   "0", "0", "0", "0", "0", "0", "0", "0",
X   "0", "0", "0", "0", "0", "0", "0", "0",
X   "0", "0", "0", "0", "0", "0", "0", "0",
X   "0", "0", "0", "0", "0", "0", "0", "0",
X   "0", "0", "0", "0", "0", "0", "0", "0",
X   "0", "0", "0", "0", "clrf", "0", "0", "0",
X   "0", "0", "0", "0", "0", "0", "movaf", "pushaf",
X   "0", "0", "0", "0", "0", "0", "0", "0",
X   "0", "0", "0", "0", "0", "0", "0", "0",
X   "0", "0", "0", "0", "0", "0", "cvthf", "cvthd",
X   "0", "0", "0", "0", "0", "bugl", "bugw", "0"`125;
X  int opcode_flags[256] = `123
X   0, 0, 0, 0, 0, 0, 0, 0,`009/* 00 */
X   0, 0, 0, 0, 0, 0, 0, 0,
X   0, 0, 2, 0, 2, 0, 0, 0,`009/* 10 */
X   0, 0, 0, 0, 0, 0, 2, 2,
X   0, 0, 0, 0, 0, 0, 0, 0,`009/* 20 */
X   0, 0, 0, 0, 0, 0, 0, 0,
X   0, 0, 1, 1, 0, 0, 0, 0,`009/* 30 */
X   0, 0, 0, 0, 0, 0, 0, 0,
X   1, 1, 1, 1, 1, 1, 1, 1,`009/* 40 */
X   1, 1, 1, 1, 1, 1, 1, 1,
X   1, 1, 1, 1, 1, 1, 1, -1,`009/* 50 */
X   0, -1, -1, -1, 0, 0, 0, 0,
X   1, 1, 1, 1, 1, 1, 1, 1,`009/* 60 */
X   1, 1, 1, 1, 1, 1, 1, 1,
X   1, 1, 1, 1, 1, 1, 1, -1,`009/* 70 */
X   0, 0, 0, 0, 2, 2, 2, 2,
X   0, 0, 0, 0, 0, 0, 0, 0,`009/* 80 */
X   0, 0, 0, 0, 0, 0, 0, 0,
X   0, 0, 0, 0, 0, 0, 0, 0,`009/* 90 */
X   1, 1, 0, 0, 0, 0, 0, 0,
X   0, 0, 0, 0, 0, 0, 0, 0,`009/* A0 */
X   0, 0, 0, 0, 0, 0, 0, 0,
X   0, 0, 0, 0, 0, 0, 0, 0,`009/* B0 */
X   0, 0, 0, 0, 0, 0, 0, 0,
X   0, 0, 0, 0, 0, 0, 0, 0,`009/* C0 */
X   0, 0, 0, 0, 0, 0, 0, 0,
X   0, 0, 0, 0, 2, 0, 0, 0,`009/* D0 */
X   0, 0, 0, 0, 0, 0, 2, 2,
X   0, 0, 0, 0, 0, 0, 0, 0,`009/* E0 */
X   0, 0, 0, 0, 0, 0, 0, 0,
X   0, 0, 0, 0, 0, 0, 1, 1,`009/* F0 */
X   0, 0, 0, 0, 0, 3, 3, 0`125;
X  int opcode_args[256] = `123
X   0, 0, 0, 0, 0, 0, 0, 0,`009/* 00 */
X   4, 4, 6, 4, 3, 3, 2, 2,
X   1, 1, 1, 1, 1, 1, 1, 1,`009/* 10 */
X   1, 1, 1, 1, 1, 1, 1, 1,
X   4, 6, 4, 6, 5, 6, 5, 6,`009/* 20 */
-+-+-+-+-+ End of part 3 +-+-+-+-+-
