home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 303_01 / iset.c < prev    next >
Text File  |  1990-05-15  |  36KB  |  1,645 lines

  1. /*
  2.  *    SCCS:    %W%    %G%    %U%
  3.  *    Decode instructions.
  4.  *
  5.  *EMACS_MODES:c
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <a.out.h>
  10. #ifdef    COFF
  11. #include <ldfcn.h>
  12. #endif    /*  COFF  */
  13. #include "unc.h"
  14.  
  15. ef_fids    mainfile;
  16. long    endt;
  17.  
  18. void    gette(), putte();
  19. void    mkdref();
  20. long    gettw();
  21. symbol    textlab();
  22.  
  23. int    l1(), l2(), el1(), lea(), lmove(), lcbch(), jj();
  24. int    limed(), lsbit(), lmvml(), lone(), loone(), lonew(), lonel();
  25.  
  26. int    pmove(), pcbch(), pdbcc(), pscc(), pcs(), pmovc(), pstop(), pexg();
  27. int    pimed(), pmovp(), psbit(), pdbit(), pcs2(), pone(), ppea();
  28. int    plea(), pdreg(), pmvml(), ptrap(), plink(), pareg(), podreg();
  29. int    pqu(), pmqu(), ptreg(), pcmpm(), pomode(), pmshf(), pshf();
  30.  
  31. struct    opstr    {
  32.     unsigned  short     mask;
  33.     unsigned  short  match;
  34.     int    (*opsize)();
  35.     int    (*opprin)();
  36.     char    *prarg;
  37. } optab[] = {
  38. #ifdef    COFF
  39.     0xf000, 0x2000, lmove, pmove, ".l",
  40.     0xf000, 0x3000, lmove, pmove, ".w",
  41.     0xf000, 0x1000, lmove, pmove, ".b",
  42. #else    /*  !COFF  */
  43.     0xf000, 0x2000, lmove, pmove, "l",
  44.     0xf000, 0x3000, lmove, pmove, "w",
  45.     0xf000, 0x1000, lmove, pmove, "b",
  46. #endif    /*  !COFF  */
  47.     0xf000, 0x6000, lcbch, pcbch, 0,
  48.     0xffbf, 0x003c, l2,    pcs,   "or",
  49.     0xff00, 0x0000, limed, pimed, "or",
  50.     0xffbf, 0x023c, l2,    pcs,   "and",
  51.     0xff00, 0x0200, limed, pimed, "and",
  52.     0xff00, 0x0400, limed, pimed, "sub",
  53.     0xff00, 0x0600, limed, pimed, "add",
  54.     0xffbf, 0x0a3c, l2,    pcs,   "eor",
  55.     0xff00, 0x0a00, limed, pimed, "eor",
  56.     0xff00, 0x0c00, limed, pimed, "cmp",
  57.     0xf138, 0x0108, l2,    pmovp, 0,
  58.     0xff00, 0x0800, lsbit, psbit, 0,
  59.     0xf100, 0x0100, lonew, pdbit, 0,
  60.     0xffc0, 0x40c0, lonew, pcs2,  "sr",
  61.     0xff00, 0x4000, lone,  pone,  "negx",
  62.     0xff00, 0x4200, lone,  pone,  "clr",
  63.     0xffc0, 0x44c0, lonew, pcs2,  "cc",
  64.     0xff00, 0x4400, lone,  pone,  "neg",
  65.     0xffc0, 0x46c0, lonew, pcs2,  "sr",
  66.     0xff00, 0x4600, lone,  pone,  "not",
  67.     0xffc0, 0x4800, lonew, ppea,  "nbcd",
  68. #ifdef    COFF
  69.     0xfff8, 0x4840, l1,    pdreg, "swap.w",
  70. #else    /*  !COFF  */
  71.     0xfff8, 0x4840, l1,    pdreg, "swap",
  72. #endif    /*  !COFF  */
  73.     0xffc0, 0x4840, lonel, ppea,  "pea",
  74. #ifdef    COFF
  75.     0xfff8, 0x4880, l1,    pdreg, "ext.w",
  76.     0xfff8, 0x48c0, l1,    pdreg, "ext.l",
  77. #else    /*  !COFF  */
  78.     0xfff8, 0x4880, l1,    pdreg, "extw",
  79.     0xfff8, 0x48c0, l1,    pdreg, "extl",
  80. #endif    /*  !COFF  */
  81.     0xfb80, 0x4880, lmvml, pmvml, 0,
  82.     0xffc0, 0x4ac0, lonew, ppea,  "tas",
  83.     0xff00, 0x4a00, lone,  pone,  "tst",
  84.     0xfff0, 0x4e40, l1,    ptrap, 0,
  85.     0xfff8, 0x4e50, l2,    plink, 0,
  86.     0xfff8, 0x4e58, l1,    pareg, "unlk\t%s",
  87. #ifdef    COFF
  88.     0xfff8, 0x4e60, l1,    pareg, "mov.l\t%s,%%usp",
  89.     0xfff8, 0x4e68, l1,    pareg, "mov.l\t%%usp,%s",
  90. #else    /*  !COFF  */
  91.     0xfff8, 0x4e60, l1,    pareg, "movl\t%s,usp",
  92.     0xfff8, 0x4e68, l1,    pareg, "movl\tusp,%s",
  93. #endif    /*  !COFF  */
  94.     0xffff, 0x4e70, l1,    pareg, "reset",
  95.     0xffff, 0x4e71, l1,    pareg, "nop",
  96.     0xffff, 0x4e72, l2,    pstop, 0,
  97.     0xffff, 0x4e73, el1,   pareg, "rte",
  98.     0xffff, 0x4e75, el1,   pareg, "rts",
  99.     0xffff, 0x4e76, l1,    pareg, "trapv",
  100.     0xffff, 0x4e77, el1,   pareg, "rtr",
  101.     0xfffe, 0x4e7a, l2,    pmovc, 0,
  102.     0xffc0, 0x4e80, jj,    ppea,  "jsr",
  103.     0xffc0, 0x4ec0, jj,    ppea,  "jmp",
  104.     0xf1c0, 0x4180, lonew, podreg,"chk",
  105.     0xf1c0, 0x41c0, lonel, plea,  0,
  106.     0xf0f8, 0x50c8, lcbch, pdbcc, 0,
  107.     0xf0c0, 0x50c0, lonew, pscc,  0,
  108.     0xf100, 0x5000, lone,  pqu,   "add",
  109.     0xf100, 0x5100, lone,  pqu,   "sub",
  110.     0xf100, 0x7000, l1,    pmqu,  0,
  111.     0xf1c0, 0x80c0, lonew, podreg,"divu",
  112.     0xf1c0, 0x81c0, lonew, podreg,"divs",
  113.     0xf1f0, 0x8100, l1,    ptreg, "sbcd",
  114.     0xf000, 0x8000, loone, pomode,"or",
  115. #ifdef    COFF
  116.     0xf1f0, 0x9100, l1,    ptreg, "subx.b",
  117.     0xf1f0, 0x9140, l1,    ptreg, "subx.w",
  118.     0xf1f0, 0x9180, l1,    ptreg, "subx.l",
  119. #else    /*  !COFF  */
  120.     0xf1f0, 0x9100, l1,    ptreg, "subxb",
  121.     0xf1f0, 0x9140, l1,    ptreg, "subxw",
  122.     0xf1f0, 0x9180, l1,    ptreg, "subxl",
  123. #endif    /*  !COFF  */
  124.     0xf000, 0x9000, loone, pomode,"sub",
  125. #ifdef    COFF
  126.     0xf1f8, 0xb108, l1,    pcmpm, "cmp.b",        /* CMPM    */
  127.     0xf1f8, 0xb148, l1,    pcmpm, "cmp.w",        /* CMPM    */
  128.     0xf1f8, 0xb188, l1,    pcmpm, "cmp.l",        /* CMPM    */
  129. #else    /*  !COFF  */
  130.     0xf1f8, 0xb108, l1,    pcmpm, "cmpmb",
  131.     0xf1f8, 0xb148, l1,    pcmpm, "cmpmw",
  132.     0xf1f8, 0xb188, l1,    pcmpm, "cmpml",
  133. #endif    /*  !COFF  */
  134.     0xf100, 0xb000, loone, pomode,"cmp",
  135.     0xf1c0, 0xb1c0, loone, pomode,"cmp",
  136.     0xf100, 0xb100, loone, pomode,"eor",
  137.     0xf1c0, 0xc0c0, lonew, podreg,"mulu",
  138.     0xf1c0, 0xc1c0, lonew, podreg,"muls",
  139.     0xf1f0, 0xc100, l1,    ptreg, "abcd",
  140.     0xf130, 0xc100, l1,    pexg,  0,
  141.     0xf000, 0xc000, loone, pomode,"and",
  142. #ifdef    COFF
  143.     0xf1f0, 0xd100, l1,    ptreg, "addx.b",
  144.     0xf1f0, 0xd140, l1,    ptreg, "addx.w",
  145.     0xf1f0, 0xd180, l1,    ptreg, "addx.l",
  146. #else    /*  !COFF  */
  147.     0xf1f0, 0xd100, l1,    ptreg, "addxb",
  148.     0xf1f0, 0xd140, l1,    ptreg, "addxw",
  149.     0xf1f0, 0xd180, l1,    ptreg, "addxl",
  150. #endif    /*  !COFF  */
  151.     0xf000, 0xd000, loone, pomode,"add",
  152.     0xf8c0, 0xe0c0, lonew, pmshf,  0,
  153.     0xf000, 0xe000, l1,    pshf,   0,
  154.     0
  155. };
  156.  
  157. #ifdef    COFF
  158. char    *areg[] = { "%a0", "%a1", "%a2", "%a3", "%a4", "%a5", "%fp", "%sp"};
  159. #else    /*  !COFF  */
  160. char    *areg[] = { "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp"};
  161. #endif    /*  !COFF  */
  162. char    *cclist[] = { "hi", "ls", "cc", "cs", "ne", "eq", "vc", "vs",
  163.             "pl", "mi", "ge", "lt", "gt", "le"};
  164.     
  165. char    *shtype[] = { "as", "ls", "rox", "ro" };
  166. char    *bittyp[] = { "tst", "chg", "clr", "set" };
  167.  
  168. #ifdef    COFF
  169. char    *creg[] = { "%sfc", "%dfc", "%usp", "%vbr" };
  170. #else    /*  !COFF  */
  171. char    *creg[] = { "sfc", "dfc", "usp", "vbr" };
  172. #endif    /*  !COFF  */
  173.  
  174. #ifdef    COFF
  175. int swbegflg = 0;
  176.  
  177. #endif    /*  COFF  */
  178. /*
  179.  *    Length functions.
  180.  */
  181.  
  182. int    l1()
  183. {
  184.     return    1;
  185. }
  186.  
  187. int    l2()
  188. {
  189.     return    2;
  190. }
  191.  
  192. int    el1(te)
  193. t_entry    *te;
  194. {
  195.     te->t_bchtyp = T_UNBR;
  196.     return    1;
  197. }
  198.  
  199. int    lea(instr, size, pos)
  200. unsigned  instr, size;
  201. long    pos;
  202. {
  203.     switch  ((instr >> 3) & 0x7)  {
  204.     case  0:
  205.     case  1:
  206.     case  2:
  207.     case  3:
  208.     case  4:
  209.         return    1;
  210.     case  5:
  211.     case  6:
  212.         return    2;
  213.     default:
  214.         switch  (instr & 0x7)  {
  215.         case  0:
  216.         case  2:
  217.         case  3:
  218.             return    2;
  219.         case  1:
  220.             mkdref(pos, size);
  221.             return    3;
  222.         case  4:
  223.             if  (size > 2)
  224.                 return    3;
  225.             return    2;
  226.         default:
  227.             return    0;
  228.         }
  229.     }
  230. }
  231.  
  232. /*
  233.  *    Lengths of move instructions.
  234.  */
  235.  
  236. int    lmove(te, pos)
  237. t_entry    *te;
  238. long    pos;
  239. {
  240.     register  unsigned  tc  =  te->t_contents;
  241.     unsigned  sz  =  1;
  242.     int    lng, lng2;
  243.     
  244.     lng  = tc & 0xf000;
  245.     if  (lng == 0x3000)
  246.         sz = 2;
  247.     else  if  (lng == 0x2000)
  248.         sz = 4;
  249.     
  250.     if  ((lng = lea(tc, sz, pos+2)) <= 0)
  251.         return    0;
  252.     lng2 = lea(((tc>>3) & 0x38) | ((tc>>9) & 0x7), sz, pos+lng+lng);
  253.     if  (lng2 <= 0)
  254.         return    0;
  255.     return    lng + lng2 - 1;
  256. }
  257.  
  258. /*
  259.  *    Lengths for conditional branches and dbcc instructions.
  260.  */
  261.  
  262. int    lcbch(te, pos)
  263. t_entry    *te;
  264. long    pos;
  265. {
  266.     unsigned  tc  =  te->t_contents;
  267.     long    dest  =  pos + 2;
  268.     int    res   =  2;
  269.     
  270.     if  ((tc & 0xf000) == 0x5000  ||  (tc & 0xff) == 0)
  271.         dest += (short)gettw(&mainfile, pos+2, R_WORD);
  272.     else  {
  273.         dest += (char) tc;
  274.         res = 1;
  275.     }
  276. #ifdef    COFF
  277.      if ( dest < 0x290000 && (dest < mainfile.ef_tbase 
  278.          || dest >= mainfile.ef_tbase+mainfile.ef_tsize 
  279.          || (dest & 1) != 0 ))
  280.          return 0;        /* Illegal branch destination */
  281. #endif    /*  COFF  */
  282.     if  ((tc & 0xff00) == 0x6000)
  283.         te->t_bchtyp = T_UNBR;
  284.     else  if  ((tc & 0xff00) == 0x6100)
  285.         te->t_bchtyp = T_JSR;
  286.     else
  287.         te->t_bchtyp = T_CONDBR;
  288.  
  289. #ifdef    COFF
  290.      if ( dest < 0x290000 && ((te->t_relsymb = textlab(dest, pos)) == NULL )) {
  291.          te->t_bchtyp = T_NOBR;/* Branch to a continuation */
  292.          return 0;
  293.      }
  294. #else    /*  !COFF  */
  295.     te->t_relsymb = textlab(dest, pos);
  296. #endif    /*  !COFF  */
  297.     return    res;
  298. }
  299.  
  300. int    jj(te, pos)
  301. t_entry    *te;
  302. long    pos;
  303. {
  304.     unsigned  tc  =  te->t_contents;
  305.     t_entry    nextl;
  306. #ifdef    COFF
  307.      long dest;
  308. #endif    /*  COFF  */
  309.     
  310.     te->t_bchtyp = (tc & 0x40)? T_UNBR: T_JSR;
  311. #ifdef    COFF
  312.     if ((tc & 0x3f) == 0x39) {
  313. #else    /*  !COFF  */
  314.     if  ((tc & 0x3f) == 0x39)  {
  315. #endif    /*  !COFF  */
  316.         gette(&mainfile, pos+2, &nextl);
  317.         if  (nextl.t_relsymb == NULL)  {
  318. #ifdef    COFF
  319.              dest = gettw(&mainfile, pos + 2, R_LONG );
  320.              if ( dest < 0x290000 && (dest < mainfile.ef_tbase
  321.                  || dest >= mainfile.ef_tbase+mainfile.ef_tsize
  322.                  || (dest & 1) != 0 ))
  323.                  return 0;    /* Illegal branch destination */
  324.              if ( dest < 0x290000 && ( nextl.t_relsymb = textlab(dest, pos) ) == NULL )
  325.              return 0;    /* Branch to a continuation */
  326. #else    /*  !COFF  */
  327.             nextl.t_relsymb = textlab(gettw(&mainfile, pos+2, R_LONG), pos);
  328. #endif    /*  !COFF  */
  329.             putte(&mainfile, pos+2, &nextl);
  330.         }
  331.         te->t_relsymb = nextl.t_relsymb;    /*  Easy ref  */
  332.     }
  333. #ifdef    COFF
  334.     else if ((tc & 0x3f) == 0x3a) {
  335.         gette(&mainfile, pos+2, &nextl);
  336.         if  (nextl.t_relsymb == NULL)  {
  337.             dest = pos+2+ (int)((short) 
  338.                 gettw(&mainfile, pos + 2, R_WORD ));
  339.              if ( dest < 0x290000 && (dest < mainfile.ef_tbase
  340.                  || dest >= mainfile.ef_tbase+mainfile.ef_tsize
  341.                  || (dest & 1) != 0 ))
  342.             return    lea(tc, 4, pos+2);
  343.              if (dest < 0x290000 && 
  344.                 (nextl.t_relsymb = textlab(dest, pos)) == NULL)
  345.                  return 0;    /* Branch to a continuation */
  346.             putte(&mainfile, pos+2, &nextl);
  347.         }
  348.         te->t_relsymb = nextl.t_relsymb;    /*  Easy ref  */
  349.     }
  350. #endif    /*  COFF  */
  351.     return    lea(tc, 4, pos+2);
  352. }
  353.  
  354. int    limed(te, pos)
  355. t_entry    *te;
  356. long    pos;
  357. {
  358.     unsigned  tc  =  te->t_contents;
  359.     int    lng;
  360.     
  361.     /*
  362.      *    Specifically exclude byte address register operands,
  363.      *    and ones which have lengths of 3.
  364.      */
  365.  
  366.     if  ((tc & 0xf8) == 0x08)
  367.         return  0;
  368.     
  369.     if  ((tc & 0xc0) >= 0x80)  {
  370.         if  (tc & 0x40)
  371.             return  0;
  372.         lng = lea(tc, 4, pos+6);
  373.         if  (lng > 0)
  374.             lng += 2;
  375.     }
  376.     else  {
  377.         lng = lea(tc, (unsigned)((tc & 0xc0)?2:1), pos+4);
  378.         if  (lng > 0)
  379.             lng++;
  380.     }
  381.     return    lng;
  382. }
  383.  
  384. int    lsbit(te, pos)
  385. t_entry    *te;
  386. long    pos;
  387. {
  388.     int    lng = lea(te->t_contents, 1, pos+4);
  389.     
  390.     if  (lng > 0)
  391.         lng++;
  392.     return    lng;
  393. }
  394.  
  395. int    lmvml(te, pos)
  396. t_entry    *te;
  397. long    pos;
  398. {
  399.     int    lng = lea(te->t_contents,
  400.             (unsigned)(te->t_contents&0x40? 4:2), pos+4);
  401.     
  402.     if  (lng > 0)
  403.         lng++;
  404.     return    lng;
  405. }
  406.  
  407. /*
  408.  *    Length depends on bits 6 and 7 of instruction.
  409.  */
  410.  
  411. int    lone(te, pos)
  412. t_entry    *te;
  413. long    pos;
  414. {
  415.     unsigned  tc  =  te->t_contents;
  416.     
  417.     return    lea(tc, 1 << ((tc >> 6) & 3), pos+2);
  418. }
  419.  
  420. /*
  421.  *    Length depends on bits 6-8 of instruction.
  422.  */
  423.  
  424. int    loone(te, pos)
  425. t_entry    *te;
  426. long    pos;
  427. {
  428.     unsigned  tc  =  te->t_contents;
  429.     
  430.     switch  ((tc >> 6) & 7)  {
  431.     case  0:
  432.     case  4:
  433.         return    lea(tc, 1, pos+2);
  434.     case  1:
  435.     case  3:
  436.     case  5:
  437.         return  lea(tc, 2, pos+2);
  438.     case  2:
  439.     case  6:
  440.     case  7:
  441.         return    lea(tc, 4, pos+2);
  442.     }
  443.     /*NOTREACHED*/
  444. }
  445.  
  446. int    lonew(te, pos)
  447. t_entry    *te;
  448. long    pos;
  449. {
  450. #ifdef    COFF
  451.     if (te->t_contents == 0x4afc) { /* swbeg ... */
  452.         swbegflg++;
  453.         return (2 + gettw(&mainfile,pos+2,2));
  454.     }
  455. #endif    /*  COFF  */
  456.     return    lea(te->t_contents, 2, pos+2);
  457. }
  458.  
  459. int    lonel(te, pos)
  460. t_entry    *te;
  461. long    pos;
  462. {
  463.     return    lea(te->t_contents, 4, pos+2);
  464. }
  465.  
  466. /*
  467.  *    Print routines.
  468.  */
  469.  
  470. #ifdef    COFF
  471. /*
  472.  * print out small integers in decamil notation, all others in hex.
  473.  */
  474.  
  475. void prind(n)
  476. unsigned short n;
  477. {
  478.     if ((short) n > -128 && (short) n < 128)
  479.         (void) printf("%d", (long) ((short) n));
  480.     else
  481.         (void) printf("0x%x",(unsigned long) n);
  482. }
  483.    
  484. #endif    /*  COFF  */
  485. int    findleng(tc)
  486. unsigned  tc;
  487. {
  488.     switch  ((tc >> 6) & 3)  {
  489.     case  0:
  490.         return    'b';
  491.     case  1:
  492.         return    'w';
  493.     default:
  494.         return    'l';
  495. #ifndef    COFF
  496.     }
  497. #endif    /*  !COFF  */
  498. }
  499. #ifdef    COFF
  500. }
  501. #endif    /*  COFF  */
  502.  
  503. #ifdef    COFF
  504. /* print @(0x4,d0.l) */
  505. void    piword(reg,disp)
  506. char * reg;
  507. #else    /*  !COFF  */
  508. void    piword(disp)
  509. #endif    /*  !COFF  */
  510. unsigned  disp;
  511. {
  512. #ifdef    COFF
  513. int    szc;
  514.  
  515.     (void) printf("%d(%s,", disp & 0xff, reg);
  516.     if  (disp & 0x8000) {
  517.         (void) fputs(areg[(disp >> 12) & 0x7]);
  518.         (void) putchar('.');
  519.     }
  520. #else    /*  !COFF  */
  521.     int    szc;
  522.     
  523.     (void) printf("@(0x%x,", disp & 0xff);
  524.     if  (disp & 0x8000)
  525.         (void) printf("%s", areg[(disp >> 12) & 0x7]);
  526. #endif    /*  !COFF  */
  527.     else
  528. #ifdef    COFF
  529.         (void) printf("%%d%d.", (disp >> 12) & 0x7);
  530.     (void) putchar((disp & (1 << 10)) ? 'l' :'w');
  531.     (void) putchar(')');
  532. #else    /*  !COFF  */
  533.         (void) printf("d%d", (disp >> 12) & 0x7);
  534.     szc = 'w';
  535.     if  (disp & (1 << 10))
  536.         szc = 'l';
  537.     (void) printf(":%c)", szc);
  538. #endif    /*  !COFF  */
  539. }
  540.  
  541. #ifdef    COFF
  542. extern struct    commit    abstab;
  543.  
  544. #endif    /*  COFF  */
  545. void    paddr(pos)
  546. long    pos;
  547. {
  548.     t_entry    tent;
  549.     symbol    symb;
  550.     
  551.  
  552.     gette(&mainfile, pos, &tent);
  553.     if  (tent.t_relsymb != NULL)  {
  554.         symb = tent.t_relsymb;
  555.         if  (symb->s_lsymb != 0)
  556. #ifdef    COFF
  557.             (void) printf("L%%%u", symb->s_lsymb);
  558.         else
  559.             (void) fputs(symb->s_name, stdout);
  560.         if  (tent.t_reldisp != 0)
  561.             (void) printf("+0x%x", tent.t_reldisp);
  562. #else    /*  !COFF  */
  563.             (void) printf("%u$", symb->s_lsymb);
  564.         else
  565.             (void) printf("%s", symb->s_name);
  566.         if  (tent.t_reldisp != 0)
  567.             (void) printf("+0x%x", tent.t_reldisp);
  568. #endif    /*  !COFF  */
  569.         return;
  570.     }
  571. #ifdef    COFF
  572.     if ((pos = gettw(&mainfile, pos, R_LONG)) >= 0x290000)
  573.      {
  574.         register int i;
  575.         for (i=0; i < abstab.c_int; i++)
  576.             if (abstab.c_symb[i]->s_value == pos)
  577.          {         
  578.             (void) fputs(abstab.c_symb[i]->s_name, stdout);
  579.             return;
  580.          }
  581.      }
  582.     (void) printf("0x%x", pos);
  583. #else    /*  !COFF  */
  584.     (void) printf("0x%x", gettw(&mainfile, pos, R_LONG));
  585. #endif    /*  !COFF  */
  586. }
  587.  
  588. int    prea(ea, pos, sz)
  589. unsigned  ea, sz;
  590. long    pos;            /*  Address of previous word to extn  */
  591. {
  592.     unsigned  reg  =  ea & 0x7;
  593.     long    disp;
  594. #ifdef    COFF
  595.     t_entry    tent;
  596. #endif    /*  COFF  */
  597.     
  598.     pos += 2;
  599.     
  600.     switch  ((ea >> 3) & 0x7)  {
  601.     case  0:
  602. #ifdef    COFF
  603.         (void) printf("%%d%d", reg);
  604. #else    /*  !COFF  */
  605.         (void) printf("d%d", reg);
  606. #endif    /*  !COFF  */
  607.         return    0;
  608.     case  1:
  609. #ifdef    COFF
  610.         (void) fputs(areg[reg], stdout);
  611. #else    /*  !COFF  */
  612.         (void) printf("%s", areg[reg]);
  613. #endif    /*  !COFF  */
  614.         return    0;
  615.     case  2:
  616. #ifdef    COFF
  617.         (void) printf("(%s)", areg[reg]);
  618. #else    /*  !COFF  */
  619.         (void) printf("%s@", areg[reg]);
  620. #endif    /*  !COFF  */
  621.         return    0;
  622.     case  3:
  623. #ifdef    COFF
  624.         (void) printf("(%s)+", areg[reg]);
  625. #else    /*  !COFF  */
  626.         (void) printf("%s@+", areg[reg]);
  627. #endif    /*  !COFF  */
  628.         return    0;
  629.     case  4:
  630. #ifdef    COFF
  631.         (void) printf("-(%s)", areg[reg]);
  632. #else    /*  !COFF  */
  633.         (void) printf("%s@-", areg[reg]);
  634. #endif    /*  !COFF  */
  635.         return    0;
  636.     case  5:
  637.         disp = gettw(&mainfile, pos, R_WORD);
  638. #ifdef    COFF
  639.         (void) prind(disp);
  640.         (void) printf("(%s)", areg[reg]);
  641. #else    /*  !COFF  */
  642.         (void) printf("%s@(0x%x)", areg[reg], disp);
  643. #endif    /*  !COFF  */
  644.         return    2;
  645.     case  6:
  646. #ifdef    COFF
  647.         piword(areg[reg], (unsigned) gettw(&mainfile, pos, R_WORD));
  648. #else    /*  !COFF  */
  649.         (void) printf("%s", areg[reg]);
  650.         piword((unsigned) gettw(&mainfile, pos, R_WORD));
  651. #endif    /*  !COFF  */
  652.         return    2;
  653.     default:
  654.         switch  (reg)  {
  655.         case  0:
  656.             disp = gettw(&mainfile, pos, R_WORD);
  657. #ifdef    COFF
  658.             (void) prind(disp);
  659.             (void) putchar('.');
  660.             (void) putchar('w');
  661. #else    /*  !COFF  */
  662.             (void) printf("0x%x:w", disp);
  663. #endif    /*  !COFF  */
  664.             return    2;
  665.         case  1:
  666.             paddr(pos);
  667.             return    4;
  668. #ifdef    COFF
  669.         case  2:{
  670.             symbol symb;
  671.             register int addr;
  672.             disp = 
  673.                 ((short) gettw(&mainfile, pos, R_WORD));
  674.               if ((addr=pos+disp) < 0  ||  
  675.                 addr-mainfile.ef_tbase > mainfile.ef_tsize ||
  676.                 (addr & 1) != 0)  
  677.                 goto skiplabs;
  678.             gette(&mainfile, addr, &tent);
  679.             if  (tent.t_relsymb != NULL)  {
  680.                 symb = tent.t_relsymb;
  681.             }
  682.             else if (tent.t_lab != NULL) {
  683.                 symb = tent.t_lab;
  684.             }
  685.             else {
  686.         skiplabs:
  687.                 (void) prind(disp);
  688.                 (void) fputs("(%pc)", stdout);
  689.                 return    2;
  690.             }
  691.             if  (symb->s_lsymb != 0)
  692.                 (void) printf("L%%%u", symb->s_lsymb);
  693.             else
  694.                 (void) fputs(symb->s_name, stdout);
  695.             if  (tent.t_reldisp != 0)
  696.                 (void) printf("+0x%x", tent.t_reldisp);
  697.             return 2;
  698.             }
  699. #else    /*  !COFF  */
  700.         case  2:
  701.             disp = gettw(&mainfile, pos, R_WORD);
  702.             (void) printf("pc@(0x%x)", disp);
  703.             return    2;
  704. #endif    /*  !COFF  */
  705.         case  3:
  706. #ifdef    COFF
  707.             piword("%pc", (unsigned)gettw(&mainfile, pos, R_WORD));
  708. #else    /*  !COFF  */
  709.             (void) printf("pc");
  710.             piword((unsigned) gettw(&mainfile, pos, R_WORD));
  711. #endif    /*  !COFF  */
  712.             return    2;
  713.         case  4:
  714. #ifdef    COFF
  715.             (void) putchar('&');
  716. #else    /*  !COFF  */
  717.             (void) printf("#");
  718. #endif    /*  !COFF  */
  719.             if  (sz < 4)
  720. #ifdef    COFF
  721.                 (void) prind(gettw(&mainfile, pos, R_WORD));
  722. #else    /*  !COFF  */
  723.                 (void) printf("0x%x", gettw(&mainfile, pos, R_WORD));
  724. #endif    /*  !COFF  */
  725.             else
  726.                 paddr(pos);
  727.             return    sz;
  728.         default:
  729.             (void) fprintf(stderr, "Funny mode\n");
  730.             exit(220);
  731.         }
  732.     }
  733.     /*NOTREACHED*/
  734. }
  735.     
  736. int    pmove(te, pos)
  737. t_entry    *te;
  738. long    pos;
  739. {
  740.     unsigned  sz  =  2;
  741.     unsigned  tc  =  te->t_contents;
  742.     
  743.     (void) printf("mov%s\t", optab[te->t_iindex].prarg);
  744.     
  745.     if  ((tc & 0xf000) == 0x2000)
  746.         sz = 4;
  747.     
  748.     pos += prea(tc, pos, sz);
  749. #ifdef    COFF
  750.     (void) putchar(',');
  751. #else    /*  !COFF  */
  752.     putchar(',');
  753. #endif    /*  !COFF  */
  754.     (void) prea(((tc >> 9) & 0x7) | ((tc >> 3) & 0x38), pos, sz);
  755. }
  756.  
  757. int    pcbch(te)
  758. t_entry    *te;
  759. {
  760.     int    cc = ((te->t_contents >> 8) & 0xf) - 2;
  761.     char    *msg;
  762.     register  symbol  ts;
  763.     
  764.     if  (cc < 0)
  765.         msg = cc < -1? "ra": "sr";
  766.     else
  767.         msg = cclist[cc];
  768.     (void) printf("b%s", msg);
  769. #ifdef    COFF
  770. /* this specifically requests that 8 bit addressing be used, 
  771.         but the unixpc assembler will do this automatically.    
  772.     if  (te->t_lng < 2) {
  773.         (void) putchar('.');
  774.         (void) putchar('b');
  775.     }
  776. */
  777. #else    /*  !COFF  */
  778.     if  (te->t_lng < 2)
  779.         (void) printf("s");
  780. #endif    /*  !COFF  */
  781.     ts = te->t_relsymb;
  782.     if  (ts->s_lsymb != 0)
  783. #ifdef    COFF
  784.         (void) printf("\tL%%%u", ts->s_lsymb);
  785. #else    /*  !COFF  */
  786.         (void) printf("\t%u$", ts->s_lsymb);
  787. #endif    /*  !COFF  */
  788.     else
  789. #ifdef    COFF
  790.     {
  791.         (void) putchar('\t');
  792.         (void) fputs(ts->s_name, stdout);
  793.     }
  794. #else    /*  !COFF  */
  795.         (void) printf("\t%s", ts->s_name);
  796. #endif    /*  !COFF  */
  797. }
  798.  
  799. int    pdbcc(te)
  800. t_entry    *te;
  801. {
  802.     unsigned  tc  =  te->t_contents;
  803.     int    cc = ((tc >> 8) & 0xf) - 2;
  804.     char    *msg;
  805.     register  symbol  ts;
  806.     
  807.     if  (cc < 0)
  808.         msg = cc < -1? "t": "f";
  809.     else
  810.         msg = cclist[cc];
  811.     ts = te->t_relsymb;
  812. #ifdef    COFF
  813.     (void) printf("db%s\t%%d%d,", msg, tc & 0x7);
  814.     if  (ts->s_lsymb)
  815.         (void) printf("L%%%u", ts->s_lsymb);
  816.     else
  817.         (void) fputs(ts->s_name, stdout);
  818. #else    /*  !COFF  */
  819.     (void) printf("db%s\td%d,", msg, tc & 0x7);
  820.     if  (ts->s_lsymb)
  821.         (void) printf("%u$", ts->s_lsymb);
  822.     else
  823.         (void) printf("%s", ts->s_name);
  824. #endif    /*  !COFF  */
  825. }
  826.  
  827. int    pscc(te, pos)
  828. t_entry    *te;
  829. long    pos;
  830. {
  831.     unsigned  tc  =  te->t_contents;
  832.     int    cc = ((tc >> 8) & 0xf) - 2;
  833.     char    *msg;
  834.     
  835.     if  (cc < 0)
  836.         msg = cc < -1? "t": "f";
  837.     else
  838.         msg = cclist[cc];
  839.     (void) printf("s%s\t", msg);
  840.     (void) prea(tc, pos, 1);
  841. }
  842.  
  843. int    pcs(te, pos)
  844. t_entry    *te;
  845. long    pos;
  846. {
  847.     long    disp  =  gettw(&mainfile, pos+2, R_WORD);
  848.     
  849. #ifdef    COFF
  850.     (void) fputs(optab[te->t_iindex].prarg, stdout);
  851.     if  ((te->t_contents & 0xc0) == 0){
  852.          (void) fputs(".b\t&", stdout);
  853.         (void) prind(disp);
  854.         (void) fputs(",%cc", stdout);
  855.     }
  856.     else {
  857.         (void) fputs(".w\t&", stdout);
  858.         (void) prind(disp);
  859.         (void) fputs(",%sr", stdout);
  860.     }
  861. #else    /*  !COFF  */
  862.     (void) printf("%s", optab[te->t_iindex].prarg);
  863.     if  ((te->t_contents & 0xc0) == 0)
  864.         (void) printf("b\t#0x%x,cc", disp);
  865.     else
  866.         (void) printf("w\t#0x%x,sr", disp);
  867. #endif    /*  !COFF  */
  868. }
  869.  
  870. int    pmovc(te, pos)
  871. t_entry    *te;
  872. long    pos;
  873. {
  874.     int    disp = gettw(&mainfile, pos+2, R_WORD);
  875.     int    ctrl = ((disp >> 10) & 2) | (disp & 1);
  876.  
  877. #ifdef    COFF
  878.     (void) fputs("movc\t", stdout);
  879. #else    /*  !COFF  */
  880.     (void) printf("movec\t");
  881. #endif    /*  !COFF  */
  882.     if  ((te->t_contents & 1) == 0)
  883. #ifdef    COFF
  884.         (void) fputs(creg[ctrl], stdout);
  885.     if  (disp & 0x8000)
  886.     {
  887.         (void) fputs(areg[(disp >> 12) & 7], stdout);
  888.         (void) putchar(',');
  889.     }
  890.     else
  891.         (void) printf("%%d%d,", disp >> 12);
  892.     if  (te->t_contents & 1)
  893.         (void) fputs(creg[ctrl], stdout);
  894. #else    /*  !COFF  */
  895.         (void) printf("%s,", creg[ctrl]);
  896.     if  (disp & 0x8000)
  897.         (void) printf("%s", areg[(disp >> 12) & 7]);
  898.     else
  899.         (void) printf("d%d", disp >> 12);
  900.     if  (te->t_contents & 1)
  901.         (void) printf(",%s", creg[ctrl]);
  902. #endif    /*  !COFF  */
  903. }
  904.  
  905. int    pimed(te, pos)
  906. t_entry    *te;
  907. long    pos;
  908. {
  909.     int    sz = findleng(te->t_contents);
  910. #ifdef    COFF
  911.  
  912.     /* we need to swith the operands to compare instrucions. */
  913.     if (strcmp (optab[te->t_iindex].prarg, "cmp")) {
  914.         (void) printf("%s.%c\t&", optab[te->t_iindex].prarg, sz);
  915.         if  (sz == 'l')  {
  916.             paddr(pos+2);
  917.             (void) putchar(',');
  918.             (void) prea(te->t_contents, pos+4, 4);
  919.         }
  920.         else  {
  921.             (void) prind(gettw(&mainfile, pos+2, R_WORD));
  922.             (void) putchar(',');
  923.             (void) prea(te->t_contents, pos+2, 2);
  924.         }
  925. #else    /*  !COFF  */
  926.     
  927.     (void) printf("%s%c\t#", optab[te->t_iindex].prarg, sz);
  928.     if  (sz == 'l')  {
  929.         paddr(pos+2);
  930.         putchar(',');
  931.         (void) prea(te->t_contents, pos+4, 4);
  932. #endif    /*  !COFF  */
  933.     }
  934. #ifdef    COFF
  935.     else {
  936.         (void) printf("%s.%c\t", optab[te->t_iindex].prarg, sz);
  937.         if  (sz == 'l')  {
  938.             (void) prea(te->t_contents, pos+4, 4);
  939.             (void) putchar(',');
  940.             (void) putchar('&');
  941.             paddr(pos+2);
  942.         }
  943.         else  {
  944.             (void) prea(te->t_contents, pos+2, 2);
  945.             (void) putchar(',');
  946.             (void) putchar('&');
  947.             (void) prind(gettw(&mainfile, pos+2, R_WORD));
  948.         }
  949. #else    /*  !COFF  */
  950.     else  {
  951.         (void) printf("0x%x,", gettw(&mainfile, pos+2, R_WORD));
  952.         (void) prea(te->t_contents, pos+2, 2);
  953. #endif    /*  !COFF  */
  954.     }
  955. }
  956.  
  957. int    pmovp(te, pos)
  958. t_entry    *te;
  959. long    pos;
  960. {
  961.     unsigned  tc  =  te->t_contents;
  962.     long    disp  =  gettw(&mainfile, pos+2, R_WORD);
  963.     int    dreg = tc >> 9;
  964.     char    *ar = areg[tc & 0x7];
  965.     
  966. #ifdef    COFF
  967.     (void) fputs("movp.", stdout);
  968.     if  (tc & (1 << 6))
  969.         (void) putchar('l');
  970.     else
  971.         (void) putchar('w');
  972. #else    /*  !COFF  */
  973.     (void) printf("movep");
  974.     if  (tc & (1 << 6))
  975.         putchar('l');
  976.     else
  977.         putchar('w');
  978. #endif    /*  !COFF  */
  979.  
  980. #ifdef    COFF
  981.     if  (tc & (1 << 7)) {
  982.         (void) printf("\t%%d%d,", dreg);
  983.         (void) prind(disp);
  984.         (void) printf("(%s)", ar);
  985.     }
  986.     else {
  987.         (void) putchar('\t');
  988.         (void) prind(disp);
  989.         (void) printf("(%s),%%d%d", ar, dreg);
  990.     }
  991. #else    /*  !COFF  */
  992.     if  (tc & (1 << 7))
  993.         (void) printf("\td%d,%s@(0x%x)", dreg, ar, disp);
  994.     else
  995.         (void) printf("\t%s@(0x%x),d%d", ar, disp, dreg);
  996. #endif    /*  !COFF  */
  997. }
  998.  
  999. int    psbit(te, pos)
  1000. t_entry    *te;
  1001. long    pos;
  1002. {
  1003.     unsigned  tc  =  te->t_contents;
  1004.     
  1005. #ifdef    COFF
  1006.     (void) printf("b%s\t&%d,", bittyp[(tc >> 6) & 0x3], gettw(&mainfile, pos+2, R_WORD));
  1007. #else    /*  !COFF  */
  1008.     (void) printf("b%s\t#%d,", bittyp[(tc >> 6) & 0x3], gettw(&mainfile, pos+2, R_WORD));
  1009. #endif    /*  !COFF  */
  1010.     (void) prea(tc, pos+2, 1);
  1011. }
  1012.  
  1013. /*ARGSUSED*/
  1014. int    pstop(te, pos)
  1015. t_entry    *te;
  1016. long    pos;
  1017. {
  1018. #ifdef    COFF
  1019.     (void) printf("stop\t&0x%x", gettw(&mainfile, pos+2, R_WORD));
  1020. #else    /*  !COFF  */
  1021.     (void) printf("stop\t#0x%x", gettw(&mainfile, pos+2, R_WORD));
  1022. #endif    /*  !COFF  */
  1023. }
  1024.  
  1025. int    pdbit(te, pos)
  1026. t_entry    *te;
  1027. long    pos;
  1028. {
  1029.     unsigned  tc  =  te->t_contents;
  1030.     
  1031. #ifdef    COFF
  1032.     (void) printf("b%s\t%%d%d,", bittyp[(tc >> 6) & 0x3], (tc >> 9) & 0x7);
  1033. #else    /*  !COFF  */
  1034.     (void) printf("b%s\td%d,", bittyp[(tc >> 6) & 0x3], (tc >> 9) & 0x7);
  1035. #endif    /*  !COFF  */
  1036.     (void) prea(tc, pos, 1);
  1037. }
  1038.  
  1039. int    pcs2(te, pos)
  1040. t_entry    *te;
  1041. long    pos;
  1042. {
  1043.     unsigned  tc  =  te->t_contents;
  1044.     
  1045. #ifdef    COFF
  1046.     (void) fputs("movw\t", stdout);
  1047. #else    /*  !COFF  */
  1048.     (void) printf("movw\t");
  1049. #endif    /*  !COFF  */
  1050.     if  ((tc & 0xffc0) == 0x40c0)  {
  1051. #ifdef    COFF
  1052.         (void) fputs("%sr,", stdout);
  1053. #else    /*  !COFF  */
  1054.         (void) printf("sr,");
  1055. #endif    /*  !COFF  */
  1056.         (void) prea(tc, pos, 2);
  1057.     }
  1058.     else  {
  1059.         (void) prea(tc, pos, 2);
  1060. #ifdef    COFF
  1061.         (void) putchar(',');
  1062.         (void) fputs(optab[te->t_iindex].prarg, stdout);
  1063. #else    /*  !COFF  */
  1064.         (void) printf(",%s", optab[te->t_iindex].prarg);
  1065. #endif    /*  !COFF  */
  1066.     }
  1067. }
  1068.  
  1069. int    pone(te, pos)
  1070. t_entry    *te;
  1071. long    pos;
  1072. {
  1073.     unsigned  tc  =  te->t_contents;
  1074.     int    sz = findleng(tc);
  1075.     
  1076. #ifdef    COFF
  1077.     (void) printf("%s.%c\t", optab[te->t_iindex].prarg, sz);
  1078. #else    /*  !COFF  */
  1079.     (void) printf("%s%c\t", optab[te->t_iindex].prarg, sz);
  1080. #endif    /*  !COFF  */
  1081.     (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  1082. }
  1083.  
  1084. int    ppea(te, pos)    /*  nbcd, pea, tas, jmp, jsr  */
  1085. t_entry    *te;
  1086. long    pos;
  1087. {
  1088. #ifdef    COFF
  1089.     if (! strncmp(optab[te->t_iindex].prarg, "tas") && 
  1090.         (te->t_contents & 0x3f) == 0x3c) {
  1091.         symbol symb;
  1092.         t_entry tstr;
  1093.         int counter = te->t_lng -2;
  1094.         int offset = (pos += 4);
  1095.         int dest;
  1096.         char * sw_label;
  1097.  
  1098.         (void) printf("swbeg\t&%d\n", counter);
  1099.  
  1100.         symb = textlab(pos, pos);
  1101.         printf("%s:\n", sw_label = symb->s_name);
  1102.  
  1103.         while (counter--) {
  1104.             gette(&mainfile, pos, &tstr);
  1105.             dest = tstr.t_contents + offset;
  1106.              if (tstr.t_contents > 0 &&
  1107.                 dest < 0x290000 && 
  1108.                 ! (dest < mainfile.ef_tbase
  1109.                   || dest >= mainfile.ef_tbase+mainfile.ef_tsize
  1110.                   || (dest & 1) != 0 )) {
  1111.                 if (symb = textlab(dest,offset))
  1112.                     printf("\tshort\t%s-%s\n", 
  1113.                         symb->s_name,sw_label);
  1114.                 else
  1115.                     printf("\tshort\t0x%x\t# Can't label destination.\n", 
  1116.                             tstr.t_contents);
  1117.             }
  1118.             else 
  1119.                 printf("\tshort\t0x%x\t# Illegal address\n", 
  1120.                         tstr.t_contents);
  1121.             pos += 2;
  1122.         }
  1123.     }
  1124.     else {
  1125.         (void) fputs(optab[te->t_iindex].prarg, stdout);
  1126.         (void) putchar('\t');
  1127.         (void) prea(te->t_contents, pos, (unsigned)(te->t_lng>2?4:2));
  1128.     }
  1129. #else    /*  !COFF  */
  1130.     (void) printf("%s\t", optab[te->t_iindex].prarg);
  1131.     (void) prea(te->t_contents, pos, (unsigned)(te->t_lng > 2? 4: 2));
  1132. #endif    /*  !COFF  */
  1133. }
  1134.  
  1135.  
  1136. int    plea(te, pos)
  1137. t_entry    *te;
  1138. long    pos;
  1139. {
  1140. #ifdef    COFF
  1141.     (void) fputs("lea\t", stdout);
  1142. #else    /*  !COFF  */
  1143.     (void) printf("lea\t");
  1144. #endif    /*  !COFF  */
  1145.     (void) prea(te->t_contents, pos, 4);
  1146. #ifdef    COFF
  1147.     (void) putchar(',');
  1148.     (void) fputs(areg[(te->t_contents >> 9) & 0x7], stdout);
  1149. #else    /*  !COFF  */
  1150.     (void) printf(",%s", areg[(te->t_contents >> 9) & 0x7]);
  1151. #endif    /*  !COFF  */
  1152. }
  1153.  
  1154. int    pdreg(te)
  1155. t_entry    *te;
  1156. {
  1157. #ifdef    COFF
  1158.     (void) printf("%s\t%%d%d", optab[te->t_iindex].prarg, te->t_contents & 7);
  1159. #else    /*  !COFF  */
  1160.     (void) printf("%s\td%d", optab[te->t_iindex].prarg, te->t_contents & 7);
  1161. #endif    /*  !COFF  */
  1162. }
  1163.  
  1164.  
  1165. int    pmvml(te, pos)
  1166. t_entry    *te;
  1167. long    pos;
  1168. {
  1169.     unsigned  tc  =  te->t_contents;
  1170.     register  unsigned  dw  =  gettw(&mainfile, pos+2, R_WORD);
  1171.     unsigned  sz = 4;
  1172.     int    sc = 'l';
  1173.     register  int    i;
  1174.     register  unsigned  bit;
  1175.     
  1176. #ifdef    COFF
  1177.     (void) fputs("movm.", stdout);
  1178.     if  ((tc & 0x40) == 0)  {
  1179.         sc = 'w';
  1180.         sz = 2;
  1181.     }
  1182.     (void) putchar(sc);    
  1183.     (void) putchar('\t');
  1184.     if  (tc & 0x400)  {
  1185.         (void) prea(tc, pos+2, sz);
  1186.         (void) printf(",&0x%x", dw);
  1187.     }
  1188.     else  {
  1189.         (void) printf("&0x%x,", dw);
  1190.         (void) prea(tc, pos+2, sz);
  1191.     }
  1192.     (void) printf("\t#\t");
  1193.  
  1194. #else    /*  !COFF  */
  1195.     (void) printf("movem");
  1196.     if  ((tc & 0x40) == 0)  {
  1197.         sc = 'w';
  1198.         sz = 2;
  1199.     }
  1200.     
  1201.     (void) printf("%c\t", sc);
  1202.     
  1203.     if  (tc & 0x400)  {
  1204.         (void) prea(tc, pos+2, sz);
  1205.         (void) printf(",#0x%x", dw);
  1206.     }
  1207.     else  {
  1208.         (void) printf("#0x%x,", dw);
  1209.         (void) prea(tc, pos+2, sz);
  1210.     }
  1211.     (void) printf("\t|");    
  1212. #endif    /*  !COFF  */
  1213.     
  1214.     (void) printf("\t|");
  1215.     
  1216.     if  ((tc & 0x38) == 0x20)  {
  1217.         bit = 0x8000;
  1218.         for  (i = 0;  i < 8;  i++)  {
  1219.             if  (dw & bit)
  1220. #ifdef    COFF
  1221.                 (void) printf(" %%d%d", i);
  1222. #else    /*  !COFF  */
  1223.                 (void) printf(" d%d", i);
  1224. #endif    /*  !COFF  */
  1225.             bit >>= 1;
  1226.         }
  1227.         for  (i = 0;  i < 8;  i++)  {
  1228. #ifdef    COFF
  1229.             if  (dw & bit) {
  1230.                     (void) putchar(' ');
  1231.                 (void) fputs(areg[i], stdout);
  1232.             }
  1233. #else    /*  !COFF  */
  1234.             if  (dw & bit)
  1235.                 (void) printf(" %s", areg[i]);
  1236. #endif    /*  !COFF  */
  1237.             bit >>= 1;
  1238.         }
  1239.     }
  1240.     else  {
  1241.         bit = 1;
  1242.         for  (i = 0;  i < 8;  i++)  {
  1243.             if  (dw & bit)
  1244. #ifdef    COFF
  1245.                 (void) printf(" %%d%d", i);
  1246. #else    /*  !COFF  */
  1247.                 (void) printf(" d%d", i);
  1248. #endif    /*  !COFF  */
  1249.             bit <<= 1;
  1250.         }
  1251.         for  (i = 0;  i < 8;  i++)  {
  1252. #ifdef    COFF
  1253.             if  (dw & bit) {
  1254.                 (void) putchar(' ');
  1255.                 (void) fputs(areg[i], stdout);
  1256.             }
  1257. #else    /*  !COFF  */
  1258.             if  (dw & bit)
  1259.                 (void) printf(" %s", areg[i]);
  1260. #endif    /*  !COFF  */
  1261.             bit <<= 1;
  1262.         }
  1263.     }
  1264. }
  1265.  
  1266. int    ptrap(te)
  1267. t_entry    *te;
  1268. {
  1269. #ifdef    COFF
  1270.     (void) printf("trap\t&%d", te->t_contents & 0xf);
  1271. #else    /*  !COFF  */
  1272.     (void) printf("trap\t#0x%x", te->t_contents & 0xf);
  1273. #endif    /*  !COFF  */
  1274. }
  1275.  
  1276. int    plink(te, pos)
  1277. t_entry    *te;
  1278. long    pos;
  1279. {
  1280. #ifdef    COFF
  1281.     (void) printf("link\t%s,&%d", areg[te->t_contents & 0x7],
  1282. #else    /*  !COFF  */
  1283.     (void) printf("link\t%s,#0x%x", areg[te->t_contents & 0x7],
  1284. #endif    /*  !COFF  */
  1285.                 gettw(&mainfile, pos+2, R_WORD));
  1286. }
  1287.  
  1288.  
  1289. int    pareg(te)
  1290. t_entry    *te;
  1291. {
  1292.     (void) printf(optab[te->t_iindex].prarg, areg[te->t_contents & 0x7]);
  1293. }
  1294.  
  1295. int    podreg(te, pos)
  1296. t_entry    *te;
  1297. long    pos;
  1298. {
  1299.     unsigned  tc  =  te->t_contents;
  1300.     
  1301.     (void) printf("%s\t", optab[te->t_iindex].prarg);
  1302.     (void) prea(tc, pos, 2);
  1303. #ifdef    COFF
  1304.     (void) printf(",%%d%d", (tc >> 9) & 0x7);
  1305. #else    /*  !COFF  */
  1306.     (void) printf(",d%d", (tc >> 9) & 0x7);
  1307. #endif    /*  !COFF  */
  1308. }
  1309.  
  1310. int    pqu(te, pos)
  1311. t_entry    *te;
  1312. long    pos;
  1313. {
  1314.     unsigned  tc  =  te->t_contents;
  1315.     int    sz  =  findleng(tc);
  1316.     int    amt = (tc >> 9) & 0x7;
  1317.     
  1318.     if  (amt == 0)
  1319.         amt = 8;
  1320. #ifdef    COFF
  1321.     (void) printf("%s.%c\t&%d,", optab[te->t_iindex].prarg, sz, amt);
  1322. #else    /*  !COFF  */
  1323.     (void) printf("%sq%c\t#%d,", optab[te->t_iindex].prarg, sz, amt);
  1324. #endif    /*  !COFF  */
  1325.     (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  1326. }
  1327.  
  1328. int    pmqu(te)
  1329. t_entry    *te;
  1330. {
  1331.     unsigned  tc  =  te->t_contents;
  1332.  
  1333. #ifdef    COFF
  1334.     (void) printf("mov.l\t&%d,%%d%d", (char)tc, (tc >> 9) & 0x7);
  1335. #else    /*  !COFF  */
  1336.     (void) printf("moveq\t#0x%x,d%d", (char)tc, (tc >> 9) & 0x7);
  1337. #endif    /*  !COFF  */
  1338. }
  1339.  
  1340. int    ptreg(te)
  1341. t_entry    *te;
  1342. {
  1343.     register  unsigned  tc  =  te->t_contents;
  1344.     int    rx = (tc >> 9) & 0x7;
  1345.     int    ry = tc & 0x7;
  1346.  
  1347. #ifdef    COFF
  1348.     (void) fputs(optab[te->t_iindex].prarg, stdout);
  1349.     (void) putchar('\t');
  1350.     if  (tc & 0x8)
  1351.         (void) printf("-(%s),-(%s)", areg[ry], areg[rx]);
  1352.     else
  1353.         (void) printf("%%d%d,%%d%d", ry, rx);
  1354. #else    /*  !COFF  */
  1355.     (void) printf("%s\t", optab[te->t_iindex].prarg);
  1356.     if  (tc & 0x8)
  1357.         (void) printf("%s@-,%s@-", areg[ry], areg[rx]);
  1358.     else
  1359.         (void) printf("d%d,d%d", ry, rx);
  1360. #endif    /*  !COFF  */
  1361.  
  1362. }
  1363.  
  1364. int    pcmpm(te)
  1365. t_entry    *te;
  1366. {
  1367.     register  unsigned  tc  =  te->t_contents;
  1368.  
  1369. #ifdef    COFF
  1370.     (void) printf("%s\t(%s)+,(%s)+", optab[te->t_iindex].prarg,
  1371. #else    /*  !COFF  */
  1372.     (void) printf("%s\t%s@+,%s@+", optab[te->t_iindex].prarg,
  1373. #endif    /*  !COFF  */
  1374.         areg[tc & 7], areg[(tc >> 9) & 7]);
  1375. }
  1376.  
  1377. int    pomode(te, pos)
  1378. t_entry    *te;
  1379. long    pos;
  1380. {
  1381.     unsigned  tc  =  te->t_contents;
  1382. #ifdef    COFF
  1383.     char    buf[5];
  1384. #else    /*  !COFF  */
  1385.     char    bef[4], aft[4];
  1386. #endif    /*  !COFF  */
  1387.     int    sz;
  1388.     int    reg = (tc >> 9) & 7;
  1389.  
  1390. #ifdef    COFF
  1391.     buf[0] = '\0';
  1392. #else    /*  !COFF  */
  1393.     bef[0] = aft[0] = '\0';
  1394. #endif    /*  !COFF  */
  1395.     
  1396.     switch  ((tc >> 6) & 7)  {
  1397.     case  0:
  1398.         sz = 'b';
  1399.         goto  toreg;
  1400.     case  1:
  1401.         sz = 'w';
  1402.         goto  toreg;
  1403.     case  2:
  1404.         sz = 'l';
  1405.     toreg:
  1406. #ifdef    COFF
  1407.          (void) sprintf(buf, "%%d%d", reg);
  1408.         goto printaft;
  1409. #else    /*  !COFF  */
  1410.         (void) sprintf(aft, ",d%d", reg);
  1411.         break;
  1412. #endif    /*  !COFF  */
  1413.     case  3:
  1414.         sz = 'w';
  1415.         goto  toareg;
  1416.     case  7:
  1417.         sz = 'l';
  1418.     toareg:
  1419. #ifdef    COFF
  1420.         (void) sprintf(buf, "%s", areg[reg]);
  1421.     printaft:
  1422.         if (strcmp("cmp", optab[te->t_iindex].prarg)) {
  1423.             (void) printf("%s.%c\t", optab[te->t_iindex].prarg,sz);
  1424.             (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  1425.             (void) putchar(',');
  1426.             (void) fputs(buf, stdout);
  1427.         }
  1428.         else {
  1429.             (void) printf("%s.%c\t%s,", optab[te->t_iindex].prarg,
  1430.                             sz, buf);
  1431.             (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  1432.         }
  1433. #else    /*  !COFF  */
  1434.         (void) sprintf(aft, ",%s", areg[reg]);
  1435. #endif    /*  !COFF  */
  1436.         break;
  1437.     case  4:
  1438.         sz = 'b';
  1439.         goto  frreg;
  1440.     case  5:
  1441.         sz = 'w';
  1442.         goto  frreg;
  1443.     case  6:
  1444.         sz = 'l';
  1445.     frreg:
  1446. #ifdef    COFF
  1447.         (void) sprintf(buf, "%%d%d", reg);
  1448.         if (strcmp("cmp", optab[te->t_iindex].prarg)) {
  1449.             (void) printf("%s.%c\t%s,", optab[te->t_iindex].prarg, 
  1450.                     sz, buf);
  1451.             (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  1452.         }
  1453.         else {
  1454.             (void) printf("%s.%c\t", optab[te->t_iindex].prarg,sz);
  1455.             (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  1456.             (void) putchar(',');
  1457.             (void) fputs(buf, stdout);
  1458.         }
  1459. #else    /*  !COFF  */
  1460.         (void) sprintf(bef, "d%d,", reg);
  1461.         break;
  1462. #endif    /*  !COFF  */
  1463.     }
  1464. #ifndef    COFF
  1465.  
  1466.     (void) printf("%s%c\t%s", optab[te->t_iindex].prarg, sz, bef);
  1467.     (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  1468.     (void) printf(aft);
  1469. #endif    /*  !COFF  */
  1470. }
  1471.  
  1472. int    pexg(te)
  1473. t_entry    *te;
  1474. {
  1475.     unsigned  tc  =  te->t_contents;
  1476.     int    r1 = (tc >> 9) & 7, r2 = tc & 7;
  1477.  
  1478.     (void) printf("exg\t");
  1479.     
  1480.  
  1481. #ifdef    COFF
  1482.     if  ((tc & 0x00f8) == 0x0048)    {
  1483.         (void) fputs(areg[r1], stdout);
  1484.         (void) putchar(',');
  1485.     }
  1486.     else
  1487.         (void) printf("%%d%d,", r1);
  1488.     if  (tc & 0x8)
  1489.         (void) fputs(areg[r2], stdout);
  1490.     else
  1491.         (void) printf("%%d%d", r2);
  1492. #else    /*  !COFF  */    
  1493.     if  ((tc & 0x00f8) == 0x0048)
  1494.         (void) printf("%s,", areg[r1]);
  1495.     else
  1496.         (void) printf("d%d,", r1);
  1497.     if  (tc & 0x8)
  1498.         (void) printf("%s", areg[r2]);
  1499.     else
  1500.         (void) printf("d%d", r2);
  1501. #endif    /*  !COFF  */
  1502.  
  1503. }
  1504.     
  1505. int    pmshf(te, pos)
  1506. t_entry    *te;
  1507. long    pos;
  1508. {
  1509.     unsigned  tc  =  te->t_contents;
  1510.     
  1511. #ifdef    COFF
  1512.     (void) printf("%s%c.w\t", shtype[(tc >> 9) & 3], tc & 0x100? 'l': 'r');
  1513. #else    /*  !COFF  */
  1514.     (void) printf("%s%cw\t", shtype[(tc >> 9) & 3], tc & 0x100? 'l': 'r');
  1515. #endif    /*  !COFF  */
  1516.     (void) prea(tc, pos, 2);
  1517. }
  1518.  
  1519. int    pshf(te)
  1520. t_entry    *te;
  1521. {
  1522.     unsigned  tc  =  te->t_contents;
  1523.     int    sz  =  findleng(tc);
  1524.     int    disp = (tc >> 9) & 7;
  1525.  
  1526. #ifdef    COFF
  1527.     (void) printf("%s%c.%c\t", shtype[(tc >> 3) & 3], tc & 0x100? 'l': 'r', sz);
  1528.     if  (tc & 0x20)
  1529.         (void) printf("%%d%d", disp);
  1530.     else
  1531.         (void) printf("&%d", disp == 0? 8: disp);
  1532.     (void) printf(",%%d%d", tc & 7);
  1533. #else    /*  !COFF  */
  1534.     (void) printf("%s%c%c\t", shtype[(tc >> 3) & 3], tc & 0x100? 'l': 'r', sz);
  1535.     if  (tc & 0x20)
  1536.         (void) printf("d%d", disp);
  1537.     else
  1538.         (void) printf("#%d", disp == 0? 8: disp);
  1539.     (void) printf(",d%d", tc & 7);
  1540. #endif    /*  !COFF  */
  1541.  
  1542. }
  1543.  
  1544. /*
  1545.  *    Find length etc of instruction.
  1546.  */
  1547.  
  1548. int    findinst(te, pos)
  1549. register  t_entry  *te;
  1550. long    pos;
  1551. {
  1552.     register  struct  opstr    *op;
  1553.     unsigned  tc  =  te->t_contents;
  1554.     int    lng = 0;
  1555.     register  int    i;
  1556.  
  1557.     te->t_type = T_BEGIN;
  1558.     te->t_bchtyp = T_NOBR;
  1559.     
  1560.     for  (op = &optab[0];  op->mask;  op++)  {
  1561.         if  ((tc & op->mask) == op->match)  {
  1562.             te->t_iindex = op - optab;
  1563.             lng = (op->opsize)(te, pos);
  1564.             break;
  1565.         }
  1566.     }
  1567.  
  1568.     for  (i = 1;  i < lng;  i++)  {
  1569.         t_entry    ctent;
  1570.         long    npos = pos+i+i;
  1571.         
  1572.         if  (npos >= endt)
  1573.             goto  clearem;
  1574.         gette(&mainfile, npos, &ctent);
  1575. #ifdef    COFF
  1576.         if (swbegflg) {
  1577.             ctent.t_type = T_UNKNOWN;
  1578.             putte(&mainfile, npos, &ctent);
  1579.         }
  1580.         else {
  1581.             if  (ctent.t_bdest || ctent.t_dref)  {
  1582. clearem:            for  (i--; i > 0; i--)  {
  1583.                     npos = pos + i + i;
  1584.                     gette(&mainfile, npos, &ctent);
  1585.                     ctent.t_type = T_UNKNOWN;
  1586.                     putte(&mainfile, npos, &ctent);
  1587.                 }
  1588.                 lng = 0;
  1589.                 goto  ginv;
  1590. #else    /*  !COFF  */
  1591.         if  (ctent.t_bdest || ctent.t_dref)  {
  1592. clearem:        for  (i--; i > 0; i--)  {
  1593.                 npos = pos + i + i;
  1594.                 gette(&mainfile, npos, &ctent);
  1595.                 ctent.t_type = T_UNKNOWN;
  1596.                 putte(&mainfile, npos, &ctent);
  1597. #endif    /*  !COFF  */
  1598.             }
  1599. #ifdef    COFF
  1600.             ctent.t_type = T_CONT;
  1601.             putte(&mainfile, npos, &ctent);
  1602. #else    /*  !COFF  */
  1603.             lng = 0;
  1604.             goto  ginv;
  1605. #endif    /*  !COFF  */
  1606.         }
  1607. #ifndef    COFF
  1608.         ctent.t_type = T_CONT;
  1609.         putte(&mainfile, npos, &ctent);
  1610. #endif    /*  !COFF  */
  1611.     }
  1612. #ifdef    COFF
  1613.     swbegflg = 0;
  1614.  
  1615. #else    /*  !COFF  */
  1616.     
  1617. #endif    /*  !COFF  */
  1618.     if  (lng <= 0)  {
  1619. ginv:        te->t_vins = 0;
  1620.         te->t_lng = 1;
  1621.         te->t_type = T_UNKNOWN;
  1622. #ifdef    COFF
  1623.         te->t_bchtyp = T_NOBR;
  1624. #else    /*  !COFF  */
  1625.         te->t_bchtype = T_NOBR;
  1626. #endif    /*  !COFF  */
  1627.     }
  1628.     else
  1629.         te->t_lng = lng;
  1630.     return    lng;
  1631. }
  1632.  
  1633. /*
  1634.  *    Print instruction.
  1635.  */
  1636.  
  1637. void    prinst(te, pos)
  1638. t_entry    *te;
  1639. long    pos;
  1640. {
  1641.     putchar('\t');
  1642.     (optab[te->t_iindex].opprin)(te, pos);
  1643.     putchar('\n');
  1644. }
  1645.