home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / 68kdisassem / part2 / iset.c next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  19.1 KB  |  1,015 lines

  1. /*
  2.  *    SCCS:    @(#)iset.c    1.2    11/2/84    14:18:23
  3.  *    Decode instructions.
  4.  *
  5.  ***********************************************************************
  6.  *    This software is copyright of
  7.  *
  8.  *        John M Collins
  9.  *        47 Cedarwood Drive
  10.  *        St Albans
  11.  *        Herts, AL4 0DN
  12.  *        England            +44 727 57267
  13.  *
  14.  *    and is released into the public domain on the following conditions:
  15.  *
  16.  *        1.  No free maintenance will be guaranteed.
  17.  *        2.  Nothing may be based on this software without
  18.  *            acknowledgement, including incorporation of this
  19.  *            notice.
  20.  *
  21.  *    Notwithstanding the above, the author welcomes correspondence and bug
  22.  *    fixes.
  23.  ***********************************************************************
  24.  */
  25.  
  26. #include <stdio.h>
  27. #include <a.out.h>
  28. #include "unc.h"
  29.  
  30. ef_fids    mainfile;
  31. long    endt;
  32.  
  33. void    gette(), putte();
  34. void    mkdref();
  35. long    gettw();
  36. symbol    textlab();
  37.  
  38. int    l1(), l2(), el1(), lea(), lmove(), lcbch(), jj();
  39. int    limed(), lsbit(), lmvml(), lone(), loone(), lonew(), lonel();
  40.  
  41. int    pmove(), pcbch(), pdbcc(), pscc(), pcs(), pmovc(), pstop(), pexg();
  42. int    pimed(), pmovp(), psbit(), pdbit(), pcs2(), pone(), ppea();
  43. int    plea(), pdreg(), pmvml(), ptrap(), plink(), pareg(), podreg();
  44. int    pqu(), pmqu(), ptreg(), pcmpm(), pomode(), pmshf(), pshf();
  45.  
  46. struct    opstr    {
  47.     unsigned  short     mask;
  48.     unsigned  short  match;
  49.     int    (*opsize)();
  50.     int    (*opprin)();
  51.     char    *prarg;
  52. } optab[] = {
  53.     0xf000, 0x2000, lmove, pmove, "l",
  54.     0xf000, 0x3000, lmove, pmove, "w",
  55.     0xf000, 0x1000, lmove, pmove, "b",
  56.     0xf000, 0x6000, lcbch, pcbch, 0,
  57.     0xffbf, 0x003c, l2,    pcs,   "or",
  58.     0xff00, 0x0000, limed, pimed, "or",
  59.     0xffbf, 0x023c, l2,    pcs,   "and",
  60.     0xff00, 0x0200, limed, pimed, "and",
  61.     0xff00, 0x0400, limed, pimed, "sub",
  62.     0xff00, 0x0600, limed, pimed, "add",
  63.     0xffbf, 0x0a3c, l2,    pcs,   "eor",
  64.     0xff00, 0x0a00, limed, pimed, "eor",
  65.     0xff00, 0x0c00, limed, pimed, "cmp",
  66.     0xf138, 0x0108, l2,    pmovp, 0,
  67.     0xff00, 0x0800, lsbit, psbit, 0,
  68.     0xf100, 0x0100, lonew, pdbit, 0,
  69.     0xffc0, 0x40c0, lonew, pcs2,  "sr",
  70.     0xff00, 0x4000, lone,  pone,  "negx",
  71.     0xff00, 0x4200, lone,  pone,  "clr",
  72.     0xffc0, 0x44c0, lonew, pcs2,  "cc",
  73.     0xff00, 0x4400, lone,  pone,  "neg",
  74.     0xffc0, 0x46c0, lonew, pcs2,  "sr",
  75.     0xff00, 0x4600, lone,  pone,  "not",
  76.     0xffc0, 0x4800, lonew, ppea,  "nbcd",
  77.     0xfff8, 0x4840, l1,    pdreg, "swap",
  78.     0xffc0, 0x4840, lonel, ppea,  "pea",
  79.     0xfff8, 0x4880, l1,    pdreg, "extw",
  80.     0xfff8, 0x48c0, l1,    pdreg, "extl",
  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.     0xfff8, 0x4e60, l1,    pareg, "movl\t%s,usp",
  88.     0xfff8, 0x4e68, l1,    pareg, "movl\tusp,%s",
  89.     0xffff, 0x4e70, l1,    pareg, "reset",
  90.     0xffff, 0x4e71, l1,    pareg, "nop",
  91.     0xffff, 0x4e72, l2,    pstop, 0,
  92.     0xffff, 0x4e73, el1,   pareg, "rte",
  93.     0xffff, 0x4e75, el1,   pareg, "rts",
  94.     0xffff, 0x4e76, l1,    pareg, "trapv",
  95.     0xffff, 0x4e77, el1,   pareg, "rtr",
  96.     0xfffe, 0x4e7a, l2,    pmovc, 0,
  97.     0xffc0, 0x4e80, jj,    ppea,  "jsr",
  98.     0xffc0, 0x4ec0, jj,    ppea,  "jmp",
  99.     0xf1c0, 0x4180, lonew, podreg,"chk",
  100.     0xf1c0, 0x41c0, lonel, plea,  0,
  101.     0xf0f8, 0x50c8, lcbch, pdbcc, 0,
  102.     0xf0c0, 0x50c0, lonew, pscc,  0,
  103.     0xf100, 0x5000, lone,  pqu,   "add",
  104.     0xf100, 0x5100, lone,  pqu,   "sub",
  105.     0xf100, 0x7000, l1,    pmqu,  0,
  106.     0xf1c0, 0x80c0, lonew, podreg,"divu",
  107.     0xf1c0, 0x81c0, lonew, podreg,"divs",
  108.     0xf1f0, 0x8100, l1,    ptreg, "sbcd",
  109.     0xf000, 0x8000, loone, pomode,"or",
  110.     0xf1f0, 0x9100, l1,    ptreg, "subxb",
  111.     0xf1f0, 0x9140, l1,    ptreg, "subxw",
  112.     0xf1f0, 0x9180, l1,    ptreg, "subxl",
  113.     0xf000, 0x9000, loone, pomode,"sub",
  114.     0xf1f8, 0xb108, l1,    pcmpm, "cmpmb",
  115.     0xf1f8, 0xb148, l1,    pcmpm, "cmpmw",
  116.     0xf1f8, 0xb188, l1,    pcmpm, "cmpml",
  117.     0xf100, 0xb000, loone, pomode,"cmp",
  118.     0xf1c0, 0xb1c0, loone, pomode,"cmp",
  119.     0xf100, 0xb100, loone, pomode,"eor",
  120.     0xf1c0, 0xc0c0, lonew, podreg,"mulu",
  121.     0xf1c0, 0xc1c0, lonew, podreg,"muls",
  122.     0xf1f0, 0xc100, l1,    ptreg, "abcd",
  123.     0xf130, 0xc100, l1,    pexg,  0,
  124.     0xf000, 0xc000, loone, pomode,"and",
  125.     0xf1f0, 0xd100, l1,    ptreg, "addxb",
  126.     0xf1f0, 0xd140, l1,    ptreg, "addxw",
  127.     0xf1f0, 0xd180, l1,    ptreg, "addxl",
  128.     0xf000, 0xd000, loone, pomode,"add",
  129.     0xf8c0, 0xe0c0, lonew, pmshf,  0,
  130.     0xf000, 0xe000, l1,    pshf,   0,
  131.     0
  132. };
  133.  
  134. char    *areg[] = { "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp"};
  135. char    *cclist[] = { "hi", "ls", "cc", "cs", "ne", "eq", "vc", "vs",
  136.             "pl", "mi", "ge", "lt", "gt", "le"};
  137.     
  138. char    *shtype[] = { "as", "ls", "rox", "ro" };
  139. char    *bittyp[] = { "tst", "chg", "clr", "set" };
  140.  
  141. char    *creg[] = { "sfc", "dfc", "usp", "vbr" };
  142.  
  143. /*
  144.  *    Length functions.
  145.  */
  146.  
  147. int    l1()
  148. {
  149.     return    1;
  150. }
  151.  
  152. int    l2()
  153. {
  154.     return    2;
  155. }
  156.  
  157. int    el1(te)
  158. t_entry    *te;
  159. {
  160.     te->t_bchtyp = T_UNBR;
  161.     return    1;
  162. }
  163.  
  164. int    lea(instr, size, pos)
  165. unsigned  instr, size;
  166. long    pos;
  167. {
  168.     switch  ((instr >> 3) & 0x7)  {
  169.     case  0:
  170.     case  1:
  171.     case  2:
  172.     case  3:
  173.     case  4:
  174.         return    1;
  175.     case  5:
  176.     case  6:
  177.         return    2;
  178.     default:
  179.         switch  (instr & 0x7)  {
  180.         case  0:
  181.         case  2:
  182.         case  3:
  183.             return    2;
  184.         case  1:
  185.             mkdref(pos, size);
  186.             return    3;
  187.         case  4:
  188.             if  (size > 2)
  189.                 return    3;
  190.             return    2;
  191.         default:
  192.             return    0;
  193.         }
  194.     }
  195. }
  196.  
  197. /*
  198.  *    Lengths of move instructions.
  199.  */
  200.  
  201. int    lmove(te, pos)
  202. t_entry    *te;
  203. long    pos;
  204. {
  205.     register  unsigned  tc  =  te->t_contents;
  206.     unsigned  sz  =  1;
  207.     int    lng, lng2;
  208.     
  209.     lng  = tc & 0xf000;
  210.     if  (lng == 0x3000)
  211.         sz = 2;
  212.     else  if  (lng == 0x2000)
  213.         sz = 4;
  214.     
  215.     if  ((lng = lea(tc, sz, pos+2)) <= 0)
  216.         return    0;
  217.     lng2 = lea(((tc>>3) & 0x38) | ((tc>>9) & 0x7), sz, pos+lng+lng);
  218.     if  (lng2 <= 0)
  219.         return    0;
  220.     return    lng + lng2 - 1;
  221. }
  222.  
  223. /*
  224.  *    Lengths for conditional branches and dbcc instructions.
  225.  */
  226.  
  227. int    lcbch(te, pos)
  228. t_entry    *te;
  229. long    pos;
  230. {
  231.     unsigned  tc  =  te->t_contents;
  232.     long    dest  =  pos + 2;
  233.     int    res   =  2;
  234.     
  235.     if  ((tc & 0xf000) == 0x5000  ||  (tc & 0xff) == 0)
  236.         dest += (short)gettw(&mainfile, pos+2, R_WORD);
  237.     else  {
  238.         dest += (char) tc;
  239.         res = 1;
  240.     }
  241.     if  ((tc & 0xff00) == 0x6000)
  242.         te->t_bchtyp = T_UNBR;
  243.     else  if  ((tc & 0xff00) == 0x6100)
  244.         te->t_bchtyp = T_JSR;
  245.     else
  246.         te->t_bchtyp = T_CONDBR;
  247.  
  248.     te->t_relsymb = textlab(dest, pos);
  249.     return    res;
  250. }
  251.  
  252. int    jj(te, pos)
  253. t_entry    *te;
  254. long    pos;
  255. {
  256.     unsigned  tc  =  te->t_contents;
  257.     t_entry    nextl;
  258.     
  259.     te->t_bchtyp = (tc & 0x40)? T_UNBR: T_JSR;
  260.     if  ((tc & 0x3f) == 0x39)  {
  261.         gette(&mainfile, pos+2, &nextl);
  262.         if  (nextl.t_relsymb == NULL)  {
  263.             nextl.t_relsymb = textlab(gettw(&mainfile, pos+2, R_LONG), pos);
  264.             putte(&mainfile, pos+2, &nextl);
  265.         }
  266.         te->t_relsymb = nextl.t_relsymb;    /*  Easy ref  */
  267.     }
  268.     return    lea(tc, 4, pos+2);
  269. }
  270.  
  271. int    limed(te, pos)
  272. t_entry    *te;
  273. long    pos;
  274. {
  275.     unsigned  tc  =  te->t_contents;
  276.     int    lng;
  277.     
  278.     /*
  279.      *    Specifically exclude byte address register operands,
  280.      *    and ones which have lengths of 3.
  281.      */
  282.  
  283.     if  ((tc & 0xf8) == 0x08)
  284.         return  0;
  285.     
  286.     if  ((tc & 0xc0) >= 0x80)  {
  287.         if  (tc & 0x40)
  288.             return  0;
  289.         lng = lea(tc, 4, pos+6);
  290.         if  (lng > 0)
  291.             lng += 2;
  292.     }
  293.     else  {
  294.         lng = lea(tc, (unsigned)((tc & 0xc0)?2:1), pos+4);
  295.         if  (lng > 0)
  296.             lng++;
  297.     }
  298.     return    lng;
  299. }
  300.  
  301. int    lsbit(te, pos)
  302. t_entry    *te;
  303. long    pos;
  304. {
  305.     int    lng = lea(te->t_contents, 1, pos+4);
  306.     
  307.     if  (lng > 0)
  308.         lng++;
  309.     return    lng;
  310. }
  311.  
  312. int    lmvml(te, pos)
  313. t_entry    *te;
  314. long    pos;
  315. {
  316.     int    lng = lea(te->t_contents,
  317.             (unsigned)(te->t_contents&0x40? 4:2), pos+4);
  318.     
  319.     if  (lng > 0)
  320.         lng++;
  321.     return    lng;
  322. }
  323.  
  324. /*
  325.  *    Length depends on bits 6 and 7 of instruction.
  326.  */
  327.  
  328. int    lone(te, pos)
  329. t_entry    *te;
  330. long    pos;
  331. {
  332.     unsigned  tc  =  te->t_contents;
  333.     
  334.     return    lea(tc, 1 << ((tc >> 6) & 3), pos+2);
  335. }
  336.  
  337. /*
  338.  *    Length depends on bits 6-8 of instruction.
  339.  */
  340.  
  341. int    loone(te, pos)
  342. t_entry    *te;
  343. long    pos;
  344. {
  345.     unsigned  tc  =  te->t_contents;
  346.     
  347.     switch  ((tc >> 6) & 7)  {
  348.     case  0:
  349.     case  4:
  350.         return    lea(tc, 1, pos+2);
  351.     case  1:
  352.     case  3:
  353.     case  5:
  354.         return  lea(tc, 2, pos+2);
  355.     case  2:
  356.     case  6:
  357.     case  7:
  358.         return    lea(tc, 4, pos+2);
  359.     }
  360.     /*NOTREACHED*/
  361. }
  362.  
  363. int    lonew(te, pos)
  364. t_entry    *te;
  365. long    pos;
  366. {
  367.     return    lea(te->t_contents, 2, pos+2);
  368. }
  369.  
  370. int    lonel(te, pos)
  371. t_entry    *te;
  372. long    pos;
  373. {
  374.     return    lea(te->t_contents, 4, pos+2);
  375. }
  376.  
  377. /*
  378.  *    Print routines.
  379.  */
  380.  
  381. int    findleng(tc)
  382. unsigned  tc;
  383. {
  384.     switch  ((tc >> 6) & 3)  {
  385.     case  0:
  386.         return    'b';
  387.     case  1:
  388.         return    'w';
  389.     default:
  390.         return    'l';
  391.     }
  392. }
  393.  
  394. void    piword(disp)
  395. unsigned  disp;
  396. {
  397.     int    szc;
  398.     
  399.     (void) printf("@(0x%x,", disp & 0xff);
  400.     if  (disp & 0x8000)
  401.         (void) printf("%s", areg[(disp >> 12) & 0x7]);
  402.     else
  403.         (void) printf("d%d", (disp >> 12) & 0x7);
  404.     szc = 'w';
  405.     if  (disp & (1 << 10))
  406.         szc = 'l';
  407.     (void) printf(":%c)", szc);
  408. }
  409.  
  410. void    paddr(pos)
  411. long    pos;
  412. {
  413.     t_entry    tent;
  414.     symbol    symb;
  415.     
  416.     gette(&mainfile, pos, &tent);
  417.     if  (tent.t_relsymb != NULL)  {
  418.         symb = tent.t_relsymb;
  419.         if  (symb->s_lsymb != 0)
  420.             (void) printf("%u$", symb->s_lsymb);
  421.         else
  422.             (void) printf("%s", symb->s_name);
  423.         if  (tent.t_reldisp != 0)
  424.             (void) printf("+0x%x", tent.t_reldisp);
  425.         return;
  426.     }
  427.     (void) printf("0x%x", gettw(&mainfile, pos, R_LONG));
  428. }
  429.  
  430. int    prea(ea, pos, sz)
  431. unsigned  ea, sz;
  432. long    pos;            /*  Address of previous word to extn  */
  433. {
  434.     unsigned  reg  =  ea & 0x7;
  435.     long    disp;
  436.     
  437.     pos += 2;
  438.     
  439.     switch  ((ea >> 3) & 0x7)  {
  440.     case  0:
  441.         (void) printf("d%d", reg);
  442.         return    0;
  443.     case  1:
  444.         (void) printf("%s", areg[reg]);
  445.         return    0;
  446.     case  2:
  447.         (void) printf("%s@", areg[reg]);
  448.         return    0;
  449.     case  3:
  450.         (void) printf("%s@+", areg[reg]);
  451.         return    0;
  452.     case  4:
  453.         (void) printf("%s@-", areg[reg]);
  454.         return    0;
  455.     case  5:
  456.         disp = gettw(&mainfile, pos, R_WORD);
  457.         (void) printf("%s@(0x%x)", areg[reg], disp);
  458.         return    2;
  459.     case  6:
  460.         (void) printf("%s", areg[reg]);
  461.         piword((unsigned) gettw(&mainfile, pos, R_WORD));
  462.         return    2;
  463.     default:
  464.         switch  (reg)  {
  465.         case  0:
  466.             disp = gettw(&mainfile, pos, R_WORD);
  467.             (void) printf("0x%x:w", disp);
  468.             return    2;
  469.         case  1:
  470.             paddr(pos);
  471.             return    4;
  472.         case  2:
  473.             disp = gettw(&mainfile, pos, R_WORD);
  474.             (void) printf("pc@(0x%x)", disp);
  475.             return    2;
  476.         case  3:
  477.             (void) printf("pc");
  478.             piword((unsigned) gettw(&mainfile, pos, R_WORD));
  479.             return    2;
  480.         case  4:
  481.             (void) printf("#");
  482.             if  (sz < 4)
  483.                 (void) printf("0x%x", gettw(&mainfile, pos, R_WORD));
  484.             else
  485.                 paddr(pos);
  486.             return    sz;
  487.         default:
  488.             (void) fprintf(stderr, "Funny mode\n");
  489.             exit(220);
  490.         }
  491.     }
  492.     /*NOTREACHED*/
  493. }
  494.     
  495. int    pmove(te, pos)
  496. t_entry    *te;
  497. long    pos;
  498. {
  499.     unsigned  sz  =  2;
  500.     unsigned  tc  =  te->t_contents;
  501.     
  502.     (void) printf("mov%s\t", optab[te->t_iindex].prarg);
  503.     
  504.     if  ((tc & 0xf000) == 0x2000)
  505.         sz = 4;
  506.     
  507.     pos += prea(tc, pos, sz);
  508.     putchar(',');
  509.     (void) prea(((tc >> 9) & 0x7) | ((tc >> 3) & 0x38), pos, sz);
  510. }
  511.  
  512. int    pcbch(te)
  513. t_entry    *te;
  514. {
  515.     int    cc = ((te->t_contents >> 8) & 0xf) - 2;
  516.     char    *msg;
  517.     register  symbol  ts;
  518.     
  519.     if  (cc < 0)
  520.         msg = cc < -1? "ra": "sr";
  521.     else
  522.         msg = cclist[cc];
  523.     (void) printf("b%s", msg);
  524.     if  (te->t_lng < 2)
  525.         (void) printf("s");
  526.     ts = te->t_relsymb;
  527.     if  (ts->s_lsymb != 0)
  528.         (void) printf("\t%u$", ts->s_lsymb);
  529.     else
  530.         (void) printf("\t%s", ts->s_name);
  531. }
  532.  
  533. int    pdbcc(te)
  534. t_entry    *te;
  535. {
  536.     unsigned  tc  =  te->t_contents;
  537.     int    cc = ((tc >> 8) & 0xf) - 2;
  538.     char    *msg;
  539.     register  symbol  ts;
  540.     
  541.     if  (cc < 0)
  542.         msg = cc < -1? "t": "f";
  543.     else
  544.         msg = cclist[cc];
  545.     ts = te->t_relsymb;
  546.     (void) printf("db%s\td%d,", msg, tc & 0x7);
  547.     if  (ts->s_lsymb)
  548.         (void) printf("%u$", ts->s_lsymb);
  549.     else
  550.         (void) printf("%s", ts->s_name);
  551. }
  552.  
  553. int    pscc(te, pos)
  554. t_entry    *te;
  555. long    pos;
  556. {
  557.     unsigned  tc  =  te->t_contents;
  558.     int    cc = ((tc >> 8) & 0xf) - 2;
  559.     char    *msg;
  560.     
  561.     if  (cc < 0)
  562.         msg = cc < -1? "t": "f";
  563.     else
  564.         msg = cclist[cc];
  565.     (void) printf("s%s\t", msg);
  566.     (void) prea(tc, pos, 1);
  567. }
  568.  
  569. int    pcs(te, pos)
  570. t_entry    *te;
  571. long    pos;
  572. {
  573.     long    disp  =  gettw(&mainfile, pos+2, R_WORD);
  574.     
  575.     (void) printf("%s", optab[te->t_iindex].prarg);
  576.     if  ((te->t_contents & 0xc0) == 0)
  577.         (void) printf("b\t#0x%x,cc", disp);
  578.     else
  579.         (void) printf("w\t#0x%x,sr", disp);
  580. }
  581.  
  582. int    pmovc(te, pos)
  583. t_entry    *te;
  584. long    pos;
  585. {
  586.     int    disp = gettw(&mainfile, pos+2, R_WORD);
  587.     int    ctrl = ((disp >> 10) & 2) | (disp & 1);
  588.  
  589.     (void) printf("movec\t");
  590.     if  ((te->t_contents & 1) == 0)
  591.         (void) printf("%s,", creg[ctrl]);
  592.     if  (disp & 0x8000)
  593.         (void) printf("%s", areg[(disp >> 12) & 7]);
  594.     else
  595.         (void) printf("d%d", disp >> 12);
  596.     if  (te->t_contents & 1)
  597.         (void) printf(",%s", creg[ctrl]);
  598. }
  599.  
  600. int    pimed(te, pos)
  601. t_entry    *te;
  602. long    pos;
  603. {
  604.     int    sz = findleng(te->t_contents);
  605.     
  606.     (void) printf("%s%c\t#", optab[te->t_iindex].prarg, sz);
  607.     if  (sz == 'l')  {
  608.         paddr(pos+2);
  609.         putchar(',');
  610.         (void) prea(te->t_contents, pos+4, 4);
  611.     }
  612.     else  {
  613.         (void) printf("0x%x,", gettw(&mainfile, pos+2, R_WORD));
  614.         (void) prea(te->t_contents, pos+2, 2);
  615.     }
  616. }
  617.  
  618. int    pmovp(te, pos)
  619. t_entry    *te;
  620. long    pos;
  621. {
  622.     unsigned  tc  =  te->t_contents;
  623.     long    disp  =  gettw(&mainfile, pos+2, R_WORD);
  624.     int    dreg = tc >> 9;
  625.     char    *ar = areg[tc & 0x7];
  626.     
  627.     (void) printf("movep");
  628.     if  (tc & (1 << 6))
  629.         putchar('l');
  630.     else
  631.         putchar('w');
  632.  
  633.     if  (tc & (1 << 7))
  634.         (void) printf("\td%d,%s@(0x%x)", dreg, ar, disp);
  635.     else
  636.         (void) printf("\t%s@(0x%x),d%d", ar, disp, dreg);
  637. }
  638.  
  639. int    psbit(te, pos)
  640. t_entry    *te;
  641. long    pos;
  642. {
  643.     unsigned  tc  =  te->t_contents;
  644.     
  645.     (void) printf("b%s\t#%d,", bittyp[(tc >> 6) & 0x3], gettw(&mainfile, pos+2, R_WORD));
  646.     (void) prea(tc, pos+2, 1);
  647. }
  648.  
  649. /*ARGSUSED*/
  650. int    pstop(te, pos)
  651. t_entry    *te;
  652. long    pos;
  653. {
  654.     (void) printf("stop\t#0x%x", gettw(&mainfile, pos+2, R_WORD));
  655. }
  656.  
  657. int    pdbit(te, pos)
  658. t_entry    *te;
  659. long    pos;
  660. {
  661.     unsigned  tc  =  te->t_contents;
  662.     
  663.     (void) printf("b%s\td%d,", bittyp[(tc >> 6) & 0x3], (tc >> 9) & 0x7);
  664.     (void) prea(tc, pos, 1);
  665. }
  666.  
  667. int    pcs2(te, pos)
  668. t_entry    *te;
  669. long    pos;
  670. {
  671.     unsigned  tc  =  te->t_contents;
  672.     
  673.     (void) printf("movw\t");
  674.     if  ((tc & 0xffc0) == 0x40c0)  {
  675.         (void) printf("sr,");
  676.         (void) prea(tc, pos, 2);
  677.     }
  678.     else  {
  679.         (void) prea(tc, pos, 2);
  680.         (void) printf(",%s", optab[te->t_iindex].prarg);
  681.     }
  682. }
  683.  
  684. int    pone(te, pos)
  685. t_entry    *te;
  686. long    pos;
  687. {
  688.     unsigned  tc  =  te->t_contents;
  689.     int    sz = findleng(tc);
  690.     
  691.     (void) printf("%s%c\t", optab[te->t_iindex].prarg, sz);
  692.     (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  693. }
  694.  
  695. int    ppea(te, pos)    /*  nbcd, pea, tas, jmp, jsr  */
  696. t_entry    *te;
  697. long    pos;
  698. {
  699.     (void) printf("%s\t", optab[te->t_iindex].prarg);
  700.     (void) prea(te->t_contents, pos, (unsigned)(te->t_lng > 2? 4: 2));
  701. }
  702.  
  703.  
  704. int    plea(te, pos)
  705. t_entry    *te;
  706. long    pos;
  707. {
  708.     (void) printf("lea\t");
  709.     (void) prea(te->t_contents, pos, 4);
  710.     (void) printf(",%s", areg[(te->t_contents >> 9) & 0x7]);
  711. }
  712.  
  713. int    pdreg(te)
  714. t_entry    *te;
  715. {
  716.     (void) printf("%s\td%d", optab[te->t_iindex].prarg, te->t_contents & 7);
  717. }
  718.  
  719.  
  720. int    pmvml(te, pos)
  721. t_entry    *te;
  722. long    pos;
  723. {
  724.     unsigned  tc  =  te->t_contents;
  725.     register  unsigned  dw  =  gettw(&mainfile, pos+2, R_WORD);
  726.     unsigned  sz = 4;
  727.     int    sc = 'l';
  728.     register  int    i;
  729.     register  unsigned  bit;
  730.     
  731.     (void) printf("movem");
  732.     if  ((tc & 0x40) == 0)  {
  733.         sc = 'w';
  734.         sz = 2;
  735.     }
  736.     
  737.     (void) printf("%c\t", sc);
  738.     
  739.     if  (tc & 0x400)  {
  740.         (void) prea(tc, pos+2, sz);
  741.         (void) printf(",#0x%x", dw);
  742.     }
  743.     else  {
  744.         (void) printf("#0x%x,", dw);
  745.         (void) prea(tc, pos+2, sz);
  746.     }
  747.     
  748.     (void) printf("\t|");
  749.     
  750.     if  ((tc & 0x38) == 0x20)  {
  751.         bit = 0x8000;
  752.         for  (i = 0;  i < 8;  i++)  {
  753.             if  (dw & bit)
  754.                 (void) printf(" d%d", i);
  755.             bit >>= 1;
  756.         }
  757.         for  (i = 0;  i < 8;  i++)  {
  758.             if  (dw & bit)
  759.                 (void) printf(" %s", areg[i]);
  760.             bit >>= 1;
  761.         }
  762.     }
  763.     else  {
  764.         bit = 1;
  765.         for  (i = 0;  i < 8;  i++)  {
  766.             if  (dw & bit)
  767.                 (void) printf(" d%d", i);
  768.             bit <<= 1;
  769.         }
  770.         for  (i = 0;  i < 8;  i++)  {
  771.             if  (dw & bit)
  772.                 (void) printf(" %s", areg[i]);
  773.             bit <<= 1;
  774.         }
  775.     }
  776. }
  777.  
  778. int    ptrap(te)
  779. t_entry    *te;
  780. {
  781.     (void) printf("trap\t#0x%x", te->t_contents & 0xf);
  782. }
  783.  
  784. int    plink(te, pos)
  785. t_entry    *te;
  786. long    pos;
  787. {
  788.     (void) printf("link\t%s,#0x%x", areg[te->t_contents & 0x7],
  789.                 gettw(&mainfile, pos+2, R_WORD));
  790. }
  791.  
  792.  
  793. int    pareg(te)
  794. t_entry    *te;
  795. {
  796.     (void) printf(optab[te->t_iindex].prarg, areg[te->t_contents & 0x7]);
  797. }
  798.  
  799. int    podreg(te, pos)
  800. t_entry    *te;
  801. long    pos;
  802. {
  803.     unsigned  tc  =  te->t_contents;
  804.     
  805.     (void) printf("%s\t", optab[te->t_iindex].prarg);
  806.     (void) prea(tc, pos, 2);
  807.     (void) printf(",d%d", (tc >> 9) & 0x7);
  808. }
  809.  
  810. int    pqu(te, pos)
  811. t_entry    *te;
  812. long    pos;
  813. {
  814.     unsigned  tc  =  te->t_contents;
  815.     int    sz  =  findleng(tc);
  816.     int    amt = (tc >> 9) & 0x7;
  817.     
  818.     if  (amt == 0)
  819.         amt = 8;
  820.     (void) printf("%sq%c\t#%d,", optab[te->t_iindex].prarg, sz, amt);
  821.     (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  822. }
  823.  
  824. int    pmqu(te)
  825. t_entry    *te;
  826. {
  827.     unsigned  tc  =  te->t_contents;
  828.  
  829.     (void) printf("moveq\t#0x%x,d%d", (char)tc, (tc >> 9) & 0x7);
  830. }
  831.  
  832. int    ptreg(te)
  833. t_entry    *te;
  834. {
  835.     register  unsigned  tc  =  te->t_contents;
  836.     int    rx = (tc >> 9) & 0x7;
  837.     int    ry = tc & 0x7;
  838.  
  839.     (void) printf("%s\t", optab[te->t_iindex].prarg);
  840.     if  (tc & 0x8)
  841.         (void) printf("%s@-,%s@-", areg[ry], areg[rx]);
  842.     else
  843.         (void) printf("d%d,d%d", ry, rx);
  844. }
  845.  
  846. int    pcmpm(te)
  847. t_entry    *te;
  848. {
  849.     register  unsigned  tc  =  te->t_contents;
  850.  
  851.     (void) printf("%s\t%s@+,%s@+", optab[te->t_iindex].prarg,
  852.         areg[tc & 7], areg[(tc >> 9) & 7]);
  853. }
  854.  
  855. int    pomode(te, pos)
  856. t_entry    *te;
  857. long    pos;
  858. {
  859.     unsigned  tc  =  te->t_contents;
  860.     char    bef[4], aft[4];
  861.     int    sz;
  862.     int    reg = (tc >> 9) & 7;
  863.  
  864.     bef[0] = aft[0] = '\0';
  865.     
  866.     switch  ((tc >> 6) & 7)  {
  867.     case  0:
  868.         sz = 'b';
  869.         goto  toreg;
  870.     case  1:
  871.         sz = 'w';
  872.         goto  toreg;
  873.     case  2:
  874.         sz = 'l';
  875.     toreg:
  876.         (void) sprintf(aft, ",d%d", reg);
  877.         break;
  878.     case  3:
  879.         sz = 'w';
  880.         goto  toareg;
  881.     case  7:
  882.         sz = 'l';
  883.     toareg:
  884.         (void) sprintf(aft, ",%s", areg[reg]);
  885.         break;
  886.     case  4:
  887.         sz = 'b';
  888.         goto  frreg;
  889.     case  5:
  890.         sz = 'w';
  891.         goto  frreg;
  892.     case  6:
  893.         sz = 'l';
  894.     frreg:
  895.         (void) sprintf(bef, "d%d,", reg);
  896.         break;
  897.     }
  898.  
  899.     (void) printf("%s%c\t%s", optab[te->t_iindex].prarg, sz, bef);
  900.     (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  901.     (void) printf(aft);
  902. }
  903.  
  904. int    pexg(te)
  905. t_entry    *te;
  906. {
  907.     unsigned  tc  =  te->t_contents;
  908.     int    r1 = (tc >> 9) & 7, r2 = tc & 7;
  909.  
  910.     (void) printf("exg\t");
  911.     
  912.     if  ((tc & 0x00f8) == 0x0048)
  913.         (void) printf("%s,", areg[r1]);
  914.     else
  915.         (void) printf("d%d,", r1);
  916.     if  (tc & 0x8)
  917.         (void) printf("%s", areg[r2]);
  918.     else
  919.         (void) printf("d%d", r2);
  920. }
  921.     
  922. int    pmshf(te, pos)
  923. t_entry    *te;
  924. long    pos;
  925. {
  926.     unsigned  tc  =  te->t_contents;
  927.     
  928.     (void) printf("%s%cw\t", shtype[(tc >> 9) & 3], tc & 0x100? 'l': 'r');
  929.     (void) prea(tc, pos, 2);
  930. }
  931.  
  932. int    pshf(te)
  933. t_entry    *te;
  934. {
  935.     unsigned  tc  =  te->t_contents;
  936.     int    sz  =  findleng(tc);
  937.     int    disp = (tc >> 9) & 7;
  938.  
  939.     (void) printf("%s%c%c\t", shtype[(tc >> 3) & 3], tc & 0x100? 'l': 'r', sz);
  940.     if  (tc & 0x20)
  941.         (void) printf("d%d", disp);
  942.     else
  943.         (void) printf("#%d", disp == 0? 8: disp);
  944.     (void) printf(",d%d", tc & 7);
  945. }
  946.  
  947. /*
  948.  *    Find length etc of instruction.
  949.  */
  950.  
  951. int    findinst(te, pos)
  952. register  t_entry  *te;
  953. long    pos;
  954. {
  955.     register  struct  opstr    *op;
  956.     unsigned  tc  =  te->t_contents;
  957.     int    lng = 0;
  958.     register  int    i;
  959.  
  960.     te->t_type = T_BEGIN;
  961.     te->t_bchtyp = T_NOBR;
  962.     
  963.     for  (op = &optab[0];  op->mask;  op++)  {
  964.         if  ((tc & op->mask) == op->match)  {
  965.             te->t_iindex = op - optab;
  966.             lng = (op->opsize)(te, pos);
  967.             break;
  968.         }
  969.     }
  970.  
  971.     for  (i = 1;  i < lng;  i++)  {
  972.         t_entry    ctent;
  973.         long    npos = pos+i+i;
  974.         
  975.         if  (npos >= endt)
  976.             goto  clearem;
  977.         gette(&mainfile, npos, &ctent);
  978.         if  (ctent.t_bdest || ctent.t_dref)  {
  979. clearem:        for  (i--; i > 0; i--)  {
  980.                 npos = pos + i + i;
  981.                 gette(&mainfile, npos, &ctent);
  982.                 ctent.t_type = T_UNKNOWN;
  983.                 putte(&mainfile, npos, &ctent);
  984.             }
  985.             lng = 0;
  986.             goto  ginv;
  987.         }
  988.         ctent.t_type = T_CONT;
  989.         putte(&mainfile, npos, &ctent);
  990.     }
  991.     
  992.     if  (lng <= 0)  {
  993. ginv:        te->t_vins = 0;
  994.         te->t_lng = 1;
  995.         te->t_type = T_UNKNOWN;
  996.         te->t_bchtype = T_NOBR;
  997.     }
  998.     else
  999.         te->t_lng = lng;
  1000.     return    lng;
  1001. }
  1002.  
  1003. /*
  1004.  *    Print instruction.
  1005.  */
  1006.  
  1007. void    prinst(te, pos)
  1008. t_entry    *te;
  1009. long    pos;
  1010. {
  1011.     putchar('\t');
  1012.     (optab[te->t_iindex].opprin)(te, pos);
  1013.     putchar('\n');
  1014. }
  1015.