1: /*   Object File Interpreter  */
   2: 
   3: #define WORD    unsigned int
   4: char *tack();
   5: WORD getword();
   6: 
   7: # include   <stdio.h>
   8: 
   9: main(argc, argv)
  10: int argc;
  11: char    *argv[];
  12: 
  13: {
  14:     int     whicharg;
  15:     char    *filename;
  16:     char    *cat_obj();
  17: 
  18:     if (argc == 1)
  19:     {
  20:         fprintf(stderr, "Error: no argument specified\n");
  21:         exit(1);
  22:     }
  23: 
  24:     for (whicharg = 1; whicharg < argc; whicharg++)
  25:     {
  26:         filename = tack(argv[whicharg], ".obj");
  27:         printf("\n\n\nFile Name: %s\n", filename);
  28:         gsd(filename);
  29:         code(filename);
  30:         lst(filename);
  31:     }
  32: }
  33: 
  34: gsd(fname)
  35: char    *fname;
  36: {
  37:     char    sname[7];   /* symbol name */
  38:     int attr;       /* byte specifing attributes */
  39:     int type;       /* byte specifing type of symbol */
  40:     int value;      /* value of the symbol */
  41:     char    *pstring(); /* function returning pointer to psect attribute string */
  42:     char    *gsstring();    /* function returning global symbol attribute string */
  43: 
  44:     printf("\n\nProgram Sections, Global Symbols and Definitions:\n\n");
  45:     ch_input(fname, 001);
  46:     while(morebytes())
  47:     {
  48:         dc_symbol(sname);
  49:         attr = getbyte();
  50:         type = getbyte();
  51:         value = getword();
  52:         switch(type)
  53:         {
  54:             case 0:
  55:                 printf("program title: %s\n", sname);
  56:                 break;
  57: 
  58:             case 1:
  59:                 printf("program section: <%s>", sname);
  60:                 printf(" %s, size: %06o\n", pstring(attr), value);
  61:                 break;
  62: 
  63:             case 2:
  64:                 printf("internal symbol table: %s", sname);
  65:                 printf(" %03o %06o\n", attr, value);
  66:                 break;
  67: 
  68:             case 3:
  69:                 printf("transfer address in <%s>, ", sname);
  70:                 printf("location: %06o\n", value);
  71:                 break;
  72: 
  73:             case 4:
  74:                 printf("global symbol: %s", sname);
  75:                 printf(" %s, value: %06o\n", gsstring(attr), value);
  76:                 break;
  77: 
  78:             case 5:
  79:                 printf("program section: <%s>", sname);
  80:                 printf(" %s, size: %06o\n", pstring(attr), value);
  81:                 break;
  82: 
  83:             case 6:
  84:                 printf("version identification: %s\n", sname);
  85:                 break;
  86: 
  87:             default:
  88:                 fprintf(stderr, "gsd type out of range %03o\n", type);
  89:                 exit(0);
  90:         }
  91:     }
  92: }
  93: 
  94: code(fname)
  95: char    *fname;
  96: {
  97:     char        sname[7];   /* symbol name buffer */
  98:     char        vrstring[40];   /* string used as an argument to */
  99:                     /* a virtual register directive */
 100:     int     drctv;      /* code directive */
 101:     int     i;
 102:     int     temp;       /* possible virtual register directive */
 103:     int     getbyte();  /* returns byte from checksum buffer */
 104:     WORD    getword();  /* returns word from checksum buffer */
 105: 
 106:     printf("\n\nCode and Directives:\n\n");
 107:     ch_input(fname, 017);
 108:     while (morebytes())
 109:     {
 110:         switch (drctv = getbyte())
 111:         {
 112:             case 000:
 113:                 printf("load zero word\n");
 114:                 break;
 115: 
 116:             case 002:
 117:                 printf("load zero relative \n");
 118:                 break;
 119: 
 120:             case 004:
 121:                 printf("load %06o\n", getword());
 122:                 break;
 123: 
 124:             case 006:
 125:                 printf("load %06o - (glc + 2)\n", getword());
 126:                 break;
 127: 
 128:             case 010:
 129:                 printf("load rel const of current psect\n");
 130:                 break;
 131: 
 132:             case 014:
 133:                 printf("load %06o + (rel const of current psect)\n", getword());
 134:                 break;
 135: 
 136:             case 020:
 137:                 dc_symbol(sname);
 138:                 regcheck(sname);
 139:                 printf("load %s\n", sname);
 140:                 break;
 141: 
 142:             case 022:
 143:                 dc_symbol(sname);
 144:                 regcheck(sname);
 145:                 printf("load %s - (glc + 2)\n", sname);
 146:                 break;
 147: 
 148:             case 030:
 149:                 dc_symbol(sname);
 150:                 printf("load rel const of <%s>\n", sname);
 151:                 break;
 152: 
 153:             case 032:
 154:                 dc_symbol(sname);
 155:                 printf("load rel const of <%s> - (glc + 2)\n", sname);
 156:                 break;
 157: 
 158:             case 034:
 159:                 dc_symbol(sname);
 160:                 printf("load rel const of <%s> + %06o\n", sname, getword());
 161:                 break;
 162: 
 163:             case 036:
 164:                 dc_symbol(sname);
 165:                 printf("load rel const of <%s> + %06o - (glc + 2)\n", sname, getword());
 166:                 break;
 167: 
 168:             case 040:
 169:                 do040();
 170:                 break;
 171: 
 172:             case 044:
 173:                 sprintf(vrstring, "%06o", getword());
 174:                 vrdirect(vrstring, getbyte());
 175:                 break;
 176: 
 177:             case 050:
 178:                 strcpy(vrstring, "current psect rel const");
 179:                 if ((temp = getbyte()) == 0)
 180:                     printf("reset glc to %s\n", vrstring);
 181:                 else
 182:                     vrdirect(vrstring, temp);
 183:                 break;
 184: 
 185:             case 054:
 186:                 sprintf(vrstring, "(%06o + current psect rel const)", getword());
 187:                 if ((temp = getbyte()) == 0)
 188:                     printf("reset glc to %s\n", vrstring);
 189:                 else
 190:                     vrdirect(vrstring, temp);
 191:                 break;
 192: 
 193:             case 060:
 194:                 dc_symbol(sname);
 195:                 regcheck(sname);
 196:                 vrdirect(sname, getbyte());
 197:                 break;
 198: 
 199:             case 070:
 200:                 dc_symbol(sname);
 201:                 sprintf(vrstring, "rel const of <%s>", sname);
 202:                 if ((temp = getbyte()) == 0)
 203:                     printf("current psect is <%s>; reset glc to %s\n", sname, vrstring);
 204:                 else
 205:                     vrdirect(vrstring, temp);
 206:                 break;
 207: 
 208:             case 074:
 209:                 dc_symbol(sname);
 210:                 sprintf(vrstring, "(rel const of <%s> + %06o)", sname, getword());
 211:                 if ((temp = getbyte()) == 0)
 212:                     printf("current psect is <%s>; reset glc to %s\n", sname, vrstring);
 213:                 else
 214:                     vrdirect(vrstring, temp);
 215:                 break;
 216: 
 217:             case 0200:
 218:                 printf("load zero byte\n");
 219:                 break;
 220: 
 221:             case 0204:
 222:                 printf("load byte %03o\n", getbyte());
 223:                 break;
 224: 
 225:             case 0220:
 226:                 dc_symbol(sname);
 227:                 regcheck(sname);
 228:                 printf("load %s as a byte\n", sname);
 229:                 break;
 230: 
 231:             default:
 232:                 fprintf(stderr, "Unrecognizable code command: %03o\n", drctv);
 233:                 for (i = 0; i < 8; i++)
 234:                     fprintf(stderr, "%03o ", getbyte());
 235:                 printf("\n");
 236:                 exit(1);
 237:         }
 238:     }
 239: }
 240: 
 241: 
 242: lst(fname)  /* local symbol table dump */
 243: char    *fname;
 244: {
 245:     char    sname[7];
 246:     char    *sattr;     /* local symbol attributes */
 247:     int pnumb;      /* number of psect the symbol is defined in */
 248:     char    *lsstring();    /* returns string of attributes */
 249: 
 250:     printf("\n\nLocal Symbols:\n\n");
 251:     ch_input(fname, 022);   /* change input to local symbols */
 252:     while (morebytes())
 253:     {
 254:         dc_symbol(sname);
 255:         sattr = lsstring(getbyte());
 256:         pnumb = getbyte();
 257:         printf("%s  %06o  section: %03o  %s\n", sname, getword(), pnumb, sattr);
 258:     }
 259: }
 260: 
 261: 
 262: char    *pstring(attr)  /* decodes attr (which specifies psect attributes) */
 263:             /* into a string, returns pointer to the string */
 264: int attr;
 265: {
 266:     static char string[80];
 267: 
 268:     if (attr & 001)
 269:         strcpy(string, "shr ");
 270:     else
 271:         strcpy(string, "prv ");
 272:     if (attr & 002)
 273:         strcat(string, "ins ");
 274:     else if (attr & 004)
 275:         strcat(string, "bss ");
 276:     else
 277:         strcat(string, "dat ");
 278:     if (attr & 020)
 279:         strcat(string, "ovr ");
 280:     else
 281:         strcat(string, "cat ");
 282:     if (attr & 040)
 283:         strcat(string, "rel ");
 284:     else
 285:         strcat(string, "abs ");
 286:     if (attr & 0100)
 287:         strcat(string, "gbl");
 288:     else
 289:         strcat(string, "loc");
 290:     return(string);
 291: }
 292: 
 293: 
 294: regcheck(s) /* checks to see if the string is suppossed to */
 295:         /* represent a register rather than a symbol, */
 296:         /* if so it adds "reg." to the string */
 297: char    *s;
 298: {
 299:     if (*s == ' ')
 300:     {
 301:         strcpy(s, "reg.");
 302:         *(s + 4) = ' ';
 303:         *(s + 5) += 'A' - 'a';
 304:     }
 305: }
 306: 
 307: 
 308: vrdirect(s, drctv)      /* print virtual register directive */
 309: char        *s;     /* string argument to directive */
 310: WORD drctv; /* the directive */
 311: {
 312:     char    reg;    /* destination character register */
 313: 
 314:     reg = 'A' + getbyte() - 1;
 315:     switch (drctv)
 316:     {
 317:         case 0200:
 318:             printf("move %s to reg  %c\n", s, reg);
 319:             break;
 320: 
 321:         case 0201:
 322:             printf("add %s to reg  %c\n", s, reg);
 323:             break;
 324: 
 325:         case 0202:
 326:             printf("subtract %s from reg  %c\n", s, reg);
 327:             break;
 328: 
 329:         case 0203:
 330:             printf("multiply %s into reg  %c\n", s, reg);
 331:             break;
 332: 
 333:         case 0204:
 334:             printf("divide %s int reg  %c\n", s, reg);
 335:             break;
 336: 
 337:         case 0205:
 338:             printf("bit \"and\" %s with reg  %c\n", s, reg);
 339:             break;
 340: 
 341:         case 0206:
 342:             printf("bit \"or\" %s with reg  %c\n", s, reg);
 343:             break;
 344: 
 345:         default:
 346:             fprintf(stderr, "Unrecognizable v.r. directive: %03o\n", drctv);
 347:             exit(1);
 348:     }
 349: }
 350: 
 351: 
 352: do040()     /* 040 is used for misc. directives to virtual registers */
 353: 
 354: {
 355:     int drctv;      /* the drctv */
 356:     char    getreg();   /* destination character register */
 357:     char    sname[7];   /* symbol name */
 358: 
 359:     switch (drctv = getbyte())
 360:     {
 361:         case 001:
 362:             printf("move low address of relocatable code to reg  %c\n", getreg());
 363:             break;
 364: 
 365:         case 002:
 366:             printf("move high address of relocatable code to reg %c\n", getreg());
 367:             break;
 368: 
 369:         case 003:
 370:             dc_symbol(sname);
 371:             printf("move low reloc address of %s to reg %c\n", sname, getreg());
 372:             break;
 373: 
 374:         case 004:
 375:             dc_symbol(sname);
 376:             printf("move high reloc address of %s to reg %c\n", sname, getreg());
 377:             break;
 378: 
 379:         case 0200:
 380:             printf("clear reg  %c\n", getreg());
 381:             break;
 382: 
 383:         case 0201:
 384:             printf("do nothing to reg  %c\n", getreg());
 385:             break;
 386: 
 387:         default:
 388:             fprintf(stderr, "Unrecognizable 040 directive: %03o, reg %c\n", drctv, getreg());
 389:             exit(1);
 390:     }
 391: }
 392: 
 393: 
 394: char    getreg()    /* reads a byte to determine register character */
 395: 
 396: {
 397:     return('A' + getbyte() - 1);
 398: }
 399: 
 400: char    *gsstring(attr) /* decodes attr (which specifies global symbol */
 401:             /* attributes) into a string */
 402: int attr;
 403: {
 404:     static char string[50];
 405: 
 406:     if (!(attr & 010))
 407:         strcpy(string, "und ");
 408:     else
 409:     {
 410:         strcpy(string, "def ");
 411:         if (attr & 040)
 412:             strcat(string, "rel ");
 413:         else
 414:             strcat(string, "abs ");
 415:     }
 416:     return (string);
 417: }
 418: 
 419: 
 420: char    *lsstring(attr) /* decodes attr (which specifies local symbol */
 421:             /* attributes) into a string */
 422: int attr;
 423: {
 424:     static char string[50];
 425: 
 426:     if (!(attr & 010))
 427:         strcpy(string, "und ");
 428:     else
 429:     {
 430:         strcpy(string, "def ");
 431:         if (attr & 040)
 432:             strcat(string, "rel ");
 433:         else
 434:             strcat(string, "abs ");
 435:         if (attr & 0100)
 436:             strcat(string, "gbl ");
 437:         if (attr & 001)
 438:             strcat(string, "reg ");
 439:         if (attr & 002)
 440:             strcat(string, "lbl ");
 441:         if (attr & 0200)
 442:             strcat(string, "hkl ");
 443:     }
 444:     return (string);
 445: }
 446: 
 447: 
 448: /***********************  bail_out  ****************************************/
 449: 
 450: 
 451: bail_out()
 452: {
 453:     exit();
 454: }

Defined functions

bail_out defined in line 451; never used
code defined in line 94; used 1 times
  • in line 29
do040 defined in line 352; used 1 times
getreg defined in line 394; used 8 times
gsd defined in line 34; used 1 times
  • in line 28
gsstring defined in line 400; used 2 times
lsstring defined in line 420; used 2 times
lst defined in line 242; used 1 times
  • in line 30
main defined in line 9; never used
pstring defined in line 262; used 3 times
regcheck defined in line 294; used 4 times
vrdirect defined in line 308; used 6 times

Defined macros

WORD defined in line 3; used 3 times
Last modified: 1982-12-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3088
Valid CSS Valid XHTML 1.0 Strict