home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / SRC / unc.lzh / UNC / iset.c < prev    next >
Text File  |  1991-06-12  |  25KB  |  1,170 lines

  1. /*
  2.  *   SCCS:   %W%   %G%   %U%
  3.  *   Decode instructions.
  4.  *
  5.  *EMACS_MODES:c
  6.  */
  7.  
  8. #include <stdio.h>
  9. #ifdef OSK
  10. #include "a.out.h"
  11. #else
  12. #include <a.out.h>
  13. #endif
  14. #include "unc.h"
  15.  
  16. extern ef_fids   mainfile;
  17.  
  18. void   gette(), putte();
  19. void   mkdref();
  20. long   gettw();
  21. symbol   textlab(), inventsymb();
  22. void gopos();
  23.  
  24. int   l1(), l2(), el1(), lea(), lmove(), lcbch(), jj();
  25. int   limed(), lsbit(), lmvml(), lone(), loone(), lonew(), lonel();
  26. int   ltrap(), linvalid();
  27.  
  28. int   pmove(), pcbch(), pdbcc(), pscc(), pcs(), pmovc(), pstop(), pexg();
  29. int   pimed(), pmovp(), psbit(), pdbit(), pcs2(), pone(), ppea();
  30. int   plea(), pdreg(), pmvml(), ptrap(), plink(), pareg(), podreg();
  31. int   pqu(), pmqu(), ptreg(), pcmpm(), pomode(), pmshf(), pshf();
  32.  
  33.     
  34.  
  35. struct   opstr   {
  36.    unsigned  short    mask;
  37.    unsigned  short  match;
  38.    int   (*opsize)();
  39.    int   (*opprin)();
  40.    char   *prarg;
  41. } optab[] = {
  42.    0xf000, 0x2000, lmove, pmove, ".l",
  43.    0xf000, 0x3000, lmove, pmove, ".w",
  44.    0xf000, 0x1000, lmove, pmove, ".b",
  45.    0xf000, 0x6000, lcbch,  pcbch, 0,
  46.    0xffbf, 0x003c, l2,  pcs,   "or",
  47.    0xff00, 0x0000, limed, pimed, "or",
  48.    0xffbf, 0x023c, l2,  pcs,   "and",
  49.    0xff00, 0x0200, limed, pimed, "and",
  50.    0xff00, 0x0400, limed, pimed, "sub",
  51.    0xff00, 0x0600, limed, pimed, "add",
  52.    0xffbf, 0x0a3c, l2,  pcs,   "eor",
  53.    0xff00, 0x0a00, limed, pimed, "eor",
  54.    0xff00, 0x0c00, limed, pimed, "cmp",
  55.    0xf138, 0x0108, l2,  pmovp, 0,
  56.    0xff00, 0x0800, lsbit, psbit, 0,
  57.    0xf100, 0x0100, lonew, pdbit, 0,
  58.    0xffc0, 0x40c0, lonew,  pcs2,  "sr",
  59.    0xff00, 0x4000, lone,  pone,  "negx",
  60.    0xff00, 0x4200, lone,  pone,  "clr",
  61.    0xffc0, 0x44c0, lonew,  pcs2,  "cc",
  62.    0xff00, 0x4400, lone,  pone,  "neg",
  63.    0xffc0, 0x46c0, lonew,  pcs2,  "sr",
  64.    0xff00, 0x4600, lone,  pone,  "not",
  65.    0xffc0, 0x4800, lonew,  ppea,  "nbcd",
  66.    0xfff8, 0x4840, l1,  pdreg, "swap.w",
  67.    0xffc0, 0x4840, lonel,  ppea,  "pea",
  68.    0xfff8, 0x4880, l1,  pdreg, "ext.w",
  69.    0xfff8, 0x48c0, l1,  pdreg, "ext.l",
  70.    0xfb80, 0x4880, lmvml, pmvml, 0,
  71.    0xffc0, 0x4ac0, lonew,  ppea,  "tas",
  72.    0xff00, 0x4a00, lone,  pone,  "tst",
  73.    0xfff0, 0x4e40, ltrap, ptrap, 0,
  74.    0xfff8, 0x4e50, l2, plink, 0,
  75.    0xfff8, 0x4e58, l1, pareg, "unlk     %s",
  76.    0xfff8, 0x4e60, l1, pareg, "move.l   %s,usp",
  77.    0xfff8, 0x4e68, l1, pareg, "move.l   usp,%s",
  78.    0xffff, 0x4e70, l1, pareg, "reset",
  79.    0xffff, 0x4e71, l1, pareg, "nop",
  80.    0xffff, 0x4e72, l2, pstop, 0,
  81.    0xffff, 0x4e73, el1, pareg, "rte",
  82.    0xffff, 0x4e75, el1, pareg, "rts",
  83.    0xffff, 0x4e76, el1, pareg, "trapv",
  84.    0xffff, 0x4e77, el1, pareg, "rtr",
  85.    0xfffe, 0x4e7a, l2, pmovc, 0,
  86.    0xffc0, 0x4e80, jj,  ppea,  "jsr",
  87.    0xffc0, 0x4ec0, jj,  ppea,  "jmp",
  88.    0xf1c0, 0x4180, lonew,podreg,"chk",
  89.    0xf1c0, 0x41c0, lonel,  plea,  0,
  90.    0xf0f8, 0x50c8, lcbch, pdbcc, 0,
  91.    0xf0c0, 0x50c0, lonew,  pscc,  0,
  92.    0xf100, 0x5000, lone,   pqu,   "add",
  93.    0xf100, 0x5100, lone,   pqu,   "sub",
  94.    0xf100, 0x7000, l1, pmqu,  0,
  95.    0xf1c0, 0x80c0, lonew, podreg,"divu",
  96.    0xf1c0, 0x81c0, lonew, podreg,"divs",
  97.    0xf1f0, 0x8100, l1, ptreg, "sbcd",
  98.    0xf000, 0x8000, loone, pomode,"or",
  99.    0xf1f0, 0x9100, l1, ptreg, "subx.b",
  100.    0xf1f0, 0x9140, l1, ptreg, "subx.w",
  101.    0xf1f0, 0x9180, l1, ptreg, "subx.l",
  102.    0xf000, 0x9000, loone, pomode,"sub",
  103.    0xf1f8, 0xb108, l1, pcmpm, "cmp.b",      /* CMPM   */
  104.    0xf1f8, 0xb148, l1, pcmpm, "cmp.w",      /* CMPM   */
  105.    0xf1f8, 0xb188, l1, pcmpm, "cmp.l",      /* CMPM   */
  106.    0xf100, 0xb000, loone, pomode,"cmp",
  107.    0xf1c0, 0xb1c0, loone, pomode,"cmp",
  108.    0xf100, 0xb100, loone, pomode,"eor",
  109.    0xf1c0, 0xc0c0, lonew, podreg,"mulu",
  110.    0xf1c0, 0xc1c0, lonew, podreg,"muls",
  111.    0xf1f0, 0xc100, l1, ptreg, "abcd",
  112.    0xf130, 0xc100, l1, pexg,  0,
  113.    0xf000, 0xc000, loone, pomode,"and",
  114.    0xf1f0, 0xd100, l1, ptreg, "addx.b",
  115.    0xf1f0, 0xd140, l1, ptreg, "addx.w",
  116.    0xf1f0, 0xd180, l1, ptreg, "addx.l",
  117.    0xf000, 0xd000, loone, pomode,"add",
  118.    0xf8c0, 0xe0c0, lonew, pmshf,  0,
  119.    0xf000, 0xe000, l1, pshf,   0,
  120.    0,      0,      linvalid, NULL, NULL
  121. };
  122.  
  123. char   *areg[] = { "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp"};
  124. char   *cclist[] = { "hi", "ls", "cc", "cs", "ne", "eq", "vc", "vs",
  125.          "pl", "mi", "ge", "lt", "gt", "le"};
  126.    
  127. char   *shtype[] = { "as", "ls", "rox", "ro" };
  128. char   *bittyp[] = { "tst", "chg", "clr", "set" };
  129.  
  130. char   *creg[] = { "sfc", "dfc", "usp", "vbr" };
  131.  
  132.  
  133. #define MAX_SYSTRAP 0x60
  134. #define MAX_IOTRAP 0x93
  135.  
  136. /*
  137.  *   Length functions.
  138.  */
  139.  
  140. int   l1()
  141. {
  142.    return   1;
  143. }
  144.  
  145. int   l2()
  146. {
  147.    return   2;
  148. }
  149.  
  150. int   el1(te)
  151. t_entry   *te;
  152. {
  153.    te->t_bchtyp = T_UNBR;
  154.    return   1;
  155. }
  156.  
  157. /* Extrawurscht für OS9-Trap */
  158. int ltrap(te, pos)
  159. t_entry *te;
  160. long pos;
  161. {
  162.    unsigned tc;
  163.             
  164.    if (te->t_contents == 0x4e40 && ropt == 0)
  165.    {    /* os9 syscall */
  166.       switch (tc = gettw(pos+2, R_WORD))
  167.       {
  168.          case 5:    /* F$Chain */
  169.          case 6:    /* F$Exit */
  170.          case 0x24:    /* F$DExit */
  171.          case 0x34:    /* F$SLink */
  172.          case 0x35:    /* resvd */
  173.          case 0x36:    /* resvd */
  174.          case 0x90:
  175.          case 0x91:
  176.             te->t_bchtyp = T_UNBR;
  177.          default:
  178.             if ((tc > 0x5a && tc < 0x80) || (tc > 0x93) ) /* undefined codes */
  179.                te->t_bchtyp = T_UNBR;
  180.          return(2);
  181.       } /* switch */
  182.    }  /* if */
  183.    te->t_bchtyp = T_UNBR;
  184.    return(1);
  185. }
  186.    
  187.    
  188. int   lea(instr, size, pos)
  189. unsigned  instr, size;
  190. long   pos;
  191. {
  192.    switch  ((instr >> 3) & 0x7)  {
  193.    case  0:
  194.    case  1:
  195.    case  2:
  196.    case  3:
  197.    case  4:
  198.       return   1;
  199.    case  5:
  200.    case  6:
  201.       return   2;
  202.    default:
  203.       switch  (instr & 0x7)  {
  204.       case  0:
  205.       case  2:
  206.       case  3:
  207.          return   2;
  208.       case  1:
  209.          return   3;
  210.       case  4:
  211.          if  (size > 2)
  212.             return   3;
  213.          return   2;
  214.       default:
  215.          return   0;
  216.       }
  217.    }
  218. }
  219.  
  220. /*
  221.  *   Lengths of move instructions.
  222.  */
  223.  
  224. int   lmove(te, pos)
  225. t_entry   *te;
  226. long   pos;
  227. {
  228.    register  unsigned  tc  =  te->t_contents;
  229.    unsigned  sz  =  1;
  230.    int   lng, lng2;
  231.    
  232.    lng  = tc & 0xf000;
  233.    if  (lng == 0x3000)
  234.       sz = 2;
  235.    else  if  (lng == 0x2000)
  236.       sz = 4;
  237.    
  238.    if  ((lng = lea(tc, sz, pos+2)) <= 0)
  239.       return   0;
  240.    lng2 = lea(((tc>>3) & 0x38) | ((tc>>9) & 0x7), sz, pos+lng+lng);
  241.    if  (lng2 <= 0)
  242.       return   0;
  243.    return   lng + lng2 - 1;
  244. }
  245.  
  246. /*
  247.  *   Lengths for conditional branches and dbcc instructions.
  248.  */
  249.  
  250. int   lcbch(te, pos)
  251. t_entry   *te;
  252. long   pos;
  253. {
  254.    unsigned  tc  =  te->t_contents;
  255.    long   dest  =  pos + 2;
  256.    int   res   =  2;
  257.    
  258.    if  ((tc & 0xf000) == 0x5000  ||  (tc & 0xff) == 0)
  259.       dest += (short)gettw(pos+2, R_WORD);
  260.    else  {
  261.       dest += (char) tc;
  262.       res = 1;
  263.    }
  264.     if (  dest < hdr._mexec
  265.        || dest >= endp
  266.        || (dest & 1) != 0
  267.            )
  268.        return 0;      /* Illegal branch destination */
  269.    if  ((tc & 0xff00) == 0x6000)
  270.       te->t_bchtyp = T_UNBR;
  271.    else  if  ((tc & 0xff00) == 0x6100)
  272.       te->t_bchtyp = T_JSR;
  273.    else
  274.       te->t_bchtyp = T_CONDBR;
  275.  
  276.    if ((te->t_relsymb = textlab(dest, pos)) == NULL)
  277.       return (0);    /* Sprungziel ungültig */
  278.    return   res;
  279. }
  280.  
  281. int   jj(te, pos)
  282. t_entry   *te;
  283. long   pos;
  284. {
  285.    unsigned  tc  =  te->t_contents;
  286.    t_entry   nextl;
  287.     long dest;
  288.    
  289.    te->t_bchtyp = (tc & 0x40)? T_UNBR: T_JSR;
  290.    if ((tc & 0x3f) == 0x39) {
  291.       gette(pos+2, &nextl);
  292.       if  (nextl.t_relsymb == NULL)  {
  293.           dest = gettw(pos + 2, R_LONG );
  294.           if ( (dest < hdr._mexec
  295.              || dest >= endp
  296.              || (dest & 1) != 0 ))
  297.              return 0;   /* Illegal branch destination */
  298.           if ( dest < 0x290000 && ( nextl.t_relsymb = textlab(dest, pos) ) == NULL )
  299.           return 0;   /* Branch to a continuation */
  300.          putte(&mainfile, pos+2, &nextl);
  301.       }
  302.       te->t_relsymb = nextl.t_relsymb;   /*  Easy ref  */
  303.    }
  304.    return   lea(tc, 4, pos+2);
  305. }
  306.  
  307. int   limed(te, pos)
  308. t_entry   *te;
  309. long   pos;
  310. {
  311.    unsigned  tc  =  te->t_contents;
  312.    int   lng;
  313.    
  314.    /*
  315.     *   Specifically exclude byte address register operands,
  316.     *   and ones which have lengths of 3.
  317.     */
  318.  
  319.    if  ((tc & 0xf8) == 0x08)
  320.       return  0;
  321.    
  322.    if  ((tc & 0xc0) >= 0x80)  {
  323.       if  (tc & 0x40)
  324.          return  0;
  325.       lng = lea(tc, 4, pos+6);
  326.       if  (lng > 0)
  327.          lng += 2;
  328.    }
  329.    else  {
  330.       lng = lea(tc, (unsigned)((tc & 0xc0)?2:1), pos+4);
  331.       if  (lng > 0)
  332.          lng++;
  333.    }
  334.    return   lng;
  335. }
  336.  
  337. int   lsbit(te, pos)
  338. t_entry   *te;
  339. long   pos;
  340. {
  341.    int   lng = lea(te->t_contents, 1, pos+4);
  342.    
  343.    if  (lng > 0)
  344.       lng++;
  345.    return   lng;
  346. }
  347.  
  348. int   lmvml(te, pos)
  349. t_entry   *te;
  350. long   pos;
  351. {
  352.    int   lng = lea(te->t_contents,
  353.          (unsigned)(te->t_contents&0x40? 4:2), pos+4);
  354.    
  355.    if  (lng > 0)
  356.       lng++;
  357.    return   lng;
  358. }
  359.  
  360. /*
  361.  *   Length depends on bits 6 and 7 of instruction.
  362.  */
  363.  
  364. int   lone(te, pos)
  365. t_entry   *te;
  366. long   pos;
  367. {
  368.    unsigned  tc  =  te->t_contents;
  369.    
  370.    return   lea(tc, 1 << ((tc >> 6) & 3), pos+2);
  371. }
  372.  
  373. /*
  374.  *   Length depends on bits 6-8 of instruction.
  375.  */
  376.  
  377. int   loone(te, pos)
  378. t_entry   *te;
  379. long   pos;
  380. {
  381.    unsigned  tc  =  te->t_contents;
  382.    
  383.    switch  ((tc >> 6) & 7)  {
  384.    case  0:
  385.    case  4:
  386.       return   lea(tc, 1, pos+2);
  387.    case  1:
  388.    case  3:
  389.    case  5:
  390.       return  lea(tc, 2, pos+2);
  391.    case  2:
  392.    case  6:
  393.    case  7:
  394.       return   lea(tc, 4, pos+2);
  395.    }
  396.    /*NOTREACHED*/
  397. }
  398.  
  399. int   lonew(te, pos)
  400. t_entry   *te;
  401. long   pos;
  402. {
  403.    return   lea(te->t_contents, 2, pos+2);
  404. }
  405.  
  406. int   lonel(te, pos)
  407. t_entry   *te;
  408. long   pos;
  409. {
  410.    return   lea(te->t_contents, 4, pos+2);
  411. }
  412.  
  413. /*
  414.  *   Print routines.
  415.  */
  416.  
  417. /*
  418.  * print out small integers in decamil notation, all others in hex.
  419.  */
  420.  
  421. void prind(n)
  422. unsigned short n;
  423. {
  424.    if ((short) n > -128 && (short) n < 128)
  425.       xp += printf("%d", (long) ((short) n));
  426.    else
  427.       xp += printf("$%x",(unsigned long) n);
  428. }
  429.    
  430. int   findleng(tc)
  431. unsigned  tc;
  432. {
  433.    switch  ((tc >> 6) & 3)  {
  434.    case  0:
  435.       return   'b';
  436.    case  1:
  437.       return   'w';
  438.    default:
  439.       return   'l';
  440.    }
  441. }
  442.  
  443. void   piword(reg,disp)
  444. char * reg;
  445. unsigned  disp;
  446. {
  447. int   szc;
  448.  
  449.    xp += printf("%d(%s,", disp & 0xff, reg);
  450.    if  (disp & 0x8000) {
  451.       xp += printf("%s.", areg[(disp >> 12) & 0x7]);
  452.    }
  453.    else
  454.       xp += printf("d%d.%c)", (disp >> 12) & 0x7, disp & (1 << 10) ? 'l' :'w');
  455. }
  456.  
  457. void   paddr(pos)
  458. long   pos;
  459. {
  460.    t_entry   tent;
  461.    symbol   symb;
  462.    
  463.  
  464.    gette(pos, &tent);
  465.    if  (tent.t_relsymb != NULL)
  466.    {
  467.       xp += printf("%s", symb->s_name);
  468.       return;
  469.    }
  470.    xp += printf("$%x", gettw(pos, R_LONG));
  471. }
  472.  
  473. int   prea(ea, pos, sz)
  474. unsigned  ea, sz;
  475. long   pos;         /*  Address of previous word to extn  */
  476. {
  477.    unsigned  reg  =  ea & 0x7;
  478.    long   disp;
  479.    t_entry   tent;
  480.    d_entry dent;
  481.    
  482.    pos += 2;
  483.    
  484.    switch  ((ea >> 3) & 0x7)  {
  485.    case  0:
  486.       xp += printf("d%d", reg);
  487.       return   0;
  488.    case  1:
  489.       xp += printf("%s", areg[reg]);
  490.       return   0;
  491.    case  2:
  492.       xp += printf("(%s)", areg[reg]);
  493.       return   0;
  494.    case  3:
  495.       xp += printf("(%s)+", areg[reg]);
  496.       return   0;
  497.    case  4:
  498.       xp += printf("-(%s)", areg[reg]);
  499.       return   0;
  500.    case  5:
  501.       disp = gettw(pos, R_WORD);
  502.       if (reg == 6 && (getde(disp, &dent) == 0))
  503.       {
  504.          if (dent.d_lab == NULL)
  505.          {
  506.             dent.d_lab = inventsymb("V");
  507.             putde(disp, &dent);
  508.          }
  509.          if (dent.d_lab != NULL)
  510.             xp += printf("%s", dent.d_lab->s_name);
  511.          else   
  512.             (void) prind(disp);
  513.       }
  514.       else   
  515.          (void) prind(disp);
  516.       xp += printf("(%s)", areg[reg]);
  517.       return   2;
  518.    case  6:
  519.       piword(areg[reg], (unsigned) gettw(pos, R_WORD));
  520.       return   2;
  521.    default:
  522.       switch  (reg)  {
  523.       case  0:
  524.          disp = gettw(&mainfile, pos, R_WORD);
  525.          (void) prind(disp);
  526.          xp += printf(".w");
  527.          return   2;
  528.       case  1:
  529.          paddr(pos);
  530.          return   4;
  531.       case  2:{
  532.          symbol symb;
  533.          register int addr;
  534.          disp = ((short) gettw(pos, R_WORD));
  535.          if ((addr=pos+disp) < hdr._mexec  ||  
  536.              addr >= endp ||
  537.              (addr & 1) != 0)  
  538.             goto skiplabs;
  539.          gette(addr, &tent);
  540.          if  (tent.t_relsymb != NULL)  {
  541.             symb = tent.t_relsymb;
  542.          }
  543.          else if (tent.t_lab != NULL) {
  544.             symb = tent.t_lab;
  545.          }
  546.          else {
  547.       skiplabs:
  548.             (void) prind(disp);
  549.             xp += printf("(pc)");
  550.             return   2;
  551.          }
  552.          xp += printf("%s", symb->s_name);
  553.          return 2;
  554.          }
  555.       case  3:
  556.          piword("pc", (unsigned)gettw(pos, R_WORD));
  557.          return   2;
  558.       case  4:
  559.          xp += printf("#");
  560.          if  (sz < 4)
  561.             xp += printf("$%x", gettw(pos, R_WORD));
  562.          else
  563.             paddr(pos);
  564.          return   sz;
  565.       default:
  566.          (void) fprintf(stderr, "Funny mode\n");
  567. /*         exit(220); */
  568.       }
  569.    }
  570.    /*NOTREACHED*/
  571. }
  572.  
  573.  
  574.  
  575.    
  576. int   pmove(te, pos)
  577. t_entry   *te;
  578. long   pos;
  579. {
  580.    unsigned  sz  =  2;
  581.    unsigned  tc  =  te->t_contents;
  582.    
  583.    xp += printf("move%s", optab[te->t_iindex].prarg);
  584.    
  585.    if  ((tc & 0xf000) == 0x2000)
  586.       sz = 4;
  587.    gopos(ARGUMENT);
  588.    pos += prea(tc, pos, sz);
  589.    xp += printf(",");
  590.    (void) prea(((tc >> 9) & 0x7) | ((tc >> 3) & 0x38), pos, sz);
  591. }
  592.  
  593.  
  594. int   pcbch(te)
  595. t_entry   *te;
  596. {
  597.    int   cc = ((te->t_contents >> 8) & 0xf) - 2;
  598.    char   *msg;
  599.    register  symbol  ts;
  600.    
  601.    if  (cc < 0)
  602.       msg = cc < -1? "ra": "sr";
  603.    else
  604.       msg = cclist[cc];
  605.    xp += printf("b%s", msg);
  606.    if  (te->t_lng < 2)
  607.       xp += printf(".s");
  608.    ts = te->t_relsymb;
  609.    
  610.    gopos(ARGUMENT);
  611.    if (ts != 0)
  612.    {
  613.       xp += printf("%s", ts->s_name);
  614.       gopos(COMMENT);
  615.       xp += printf("($%x)", ts->s_value);
  616.    }
  617.    else
  618.     printf("???     ts == NULL in pcbch (!)");
  619. }
  620.  
  621. int   pdbcc(te)
  622. t_entry   *te;
  623. {
  624.    unsigned  tc  =  te->t_contents;
  625.    int   cc = ((tc >> 8) & 0xf) - 2;
  626.    char   *msg;
  627.    register  symbol  ts;
  628.    
  629.    if  (cc < 0)
  630.       msg = cc < -1? "t": "f";
  631.    else
  632.       msg = cclist[cc];
  633.    ts = te->t_relsymb;
  634.    xp += printf("db%s", msg);
  635.    gopos(ARGUMENT);
  636.    xp += printf("d%d,", tc & 0x7);
  637.    xp += printf("%s", ts->s_name);
  638. }
  639.  
  640. int   pscc(te, pos)
  641. t_entry   *te;
  642. long   pos;
  643. {
  644.    unsigned  tc  =  te->t_contents;
  645.    int   cc = ((tc >> 8) & 0xf) - 2;
  646.    char   *msg;
  647.    
  648.    if  (cc < 0)
  649.       msg = cc < -1? "t": "f";
  650.    else
  651.       msg = cclist[cc];
  652.    xp += printf("s%s", msg);
  653.    gopos(ARGUMENT);
  654.    (void) prea(tc, pos, 1);
  655. }
  656.  
  657. int   pcs(te, pos)
  658. t_entry   *te;
  659. long   pos;
  660. {
  661.    long   disp  =  gettw(pos+2, R_WORD);
  662.    
  663.    xp += printf("%s", optab[te->t_iindex].prarg);
  664.    if  ((te->t_contents & 0xc0) == 0){
  665.        xp += printf(".b");
  666.        gopos(ARGUMENT);
  667.       (void) prind(disp);
  668.       xp += printf(",cc");
  669.    }
  670.    else {
  671.       xp += printf(".w");
  672.       gopos(ARGUMENT);
  673.       (void) prind(disp);
  674.       xp += printf(",sr");
  675.    }
  676. }
  677.  
  678. int   pmovc(te, pos)
  679. t_entry   *te;
  680. long   pos;
  681. {
  682.    int   disp = gettw(pos+2, R_WORD);
  683.    int   ctrl = ((disp >> 10) & 2) | (disp & 1);
  684.  
  685.    xp += printf("movec");
  686.    gopos(ARGUMENT);
  687.    if  ((te->t_contents & 1) == 0)
  688.       xp += printf("%s", creg[ctrl]);
  689.    if  (disp & 0x8000)
  690.    {
  691.       xp += printf("%s", areg[(disp >> 12) & 7]);
  692.    }
  693.    else
  694.       xp += printf("d%d,", disp >> 12);
  695.    if  (te->t_contents & 1)
  696.       xp += printf("%s", creg[ctrl]);
  697. }
  698.  
  699. int   pimed(te, pos)
  700. t_entry   *te;
  701. long   pos;
  702. {
  703.    int   sz = findleng(te->t_contents);
  704.    
  705.    xp += printf("%s.%c", optab[te->t_iindex].prarg, sz);
  706.    gopos(ARGUMENT);
  707.    xp += printf("#");
  708.    if  (sz == 'l')  {
  709.       paddr(pos+2);
  710.       xp += printf(",");
  711.       (void) prea(te->t_contents, pos+4, 4);
  712.    }
  713.    else  {
  714.       xp += printf("$%x,", gettw(pos+2, R_WORD));
  715.       (void) prea(te->t_contents, pos+2, 2);
  716.    }
  717. }
  718.  
  719.  
  720. int   pmovp(te, pos)
  721. t_entry   *te;
  722. long   pos;
  723. {
  724.    unsigned  tc  =  te->t_contents;
  725.    long   disp  =  gettw(pos+2, R_WORD);
  726.    int   dreg = tc >> 9;
  727.    char   *ar = areg[tc & 0x7];
  728.    
  729.    xp += printf("movep.%c", tc & (1 << 6) ? 'l' : 'w');
  730.  
  731.    gopos(ARGUMENT);
  732.    if  (tc & (1 << 7)) {
  733.       xp += printf("%%d%d,", dreg);
  734.       (void) prind(disp);
  735.       xp += printf("(%s)", ar);
  736.    }
  737.    else {
  738.       (void) prind(disp);
  739.       xp += printf("(%s),%%d%d", ar, dreg);
  740.    }
  741. }
  742.  
  743. int   psbit(te, pos)
  744. t_entry   *te;
  745. long   pos;
  746. {
  747.    unsigned  tc  =  te->t_contents;
  748.    
  749.    xp += printf("b%s", bittyp[(tc >> 6) & 0x3]);
  750.    gopos(ARGUMENT);
  751.    xp += printf("#%d,", gettw(pos+2, R_WORD));
  752.    (void) prea(tc, pos+2, 1);
  753. }
  754.  
  755.  
  756. /*ARGSUSED*/
  757. int   pstop(te, pos)
  758. t_entry   *te;
  759. long   pos;
  760. {
  761.    xp += printf("stop");
  762.    gopos(ARGUMENT);
  763.    xp += printf("#$%x", gettw(pos+2, R_WORD));
  764. }
  765.  
  766. int   pdbit(te, pos)
  767. t_entry   *te;
  768. long   pos;
  769. {
  770.    unsigned  tc  =  te->t_contents;
  771.    
  772.    xp += printf("b%s", bittyp[(tc >> 6) & 0x3]);
  773.    gopos(ARGUMENT);
  774.    xp += printf("d%d,", (tc >> 9) & 0x7);
  775.    (void) prea(tc, pos, 1);
  776. }
  777.  
  778.  
  779. int   pcs2(te, pos)
  780. t_entry   *te;
  781. long   pos;
  782. {
  783.    unsigned  tc  =  te->t_contents;
  784.    
  785.    xp += printf("move.w");
  786.    gopos(ARGUMENT);
  787.    if  ((tc & 0xffc0) == 0x40c0)  {
  788.       xp += printf("sr,");
  789.       (void) prea(tc, pos, 2);
  790.    }
  791.    else  {
  792.       (void) prea(tc, pos, 2);
  793.       xp += printf(",%s", optab[te->t_iindex].prarg);
  794.    }
  795. }
  796.  
  797.  
  798. int   pone(te, pos)
  799. t_entry   *te;
  800. long   pos;
  801. {
  802.    unsigned  tc  =  te->t_contents;
  803.    int   sz = findleng(tc);
  804.    
  805.    xp += printf("%s.%c", optab[te->t_iindex].prarg, sz);
  806.    gopos(ARGUMENT);
  807.    (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  808. }
  809.  
  810. int   ppea(te, pos)   /*  nbcd, pea, tas, jmp, jsr  */
  811. t_entry   *te;
  812. long   pos;
  813. {
  814.    xp += printf("%s", optab[te->t_iindex].prarg);
  815.    gopos(ARGUMENT);
  816.    (void) prea(te->t_contents, pos, (unsigned)(te->t_lng > 2? 4: 2));
  817. }
  818.  
  819.  
  820. int   plea(te, pos)
  821. t_entry   *te;
  822. long   pos;
  823. {
  824.    xp += printf("lea");
  825.    gopos(ARGUMENT);
  826.    (void) prea(te->t_contents, pos, 4);
  827.    xp += printf(",%s", areg[(te->t_contents >> 9) & 0x7]);
  828. }
  829.  
  830.  
  831. int   pdreg(te)
  832. t_entry   *te;
  833. {
  834.    xp += printf("%s", optab[te->t_iindex].prarg);
  835.    gopos(ARGUMENT);
  836.    xp += printf("d%d", te->t_contents & 7);
  837. }
  838.  
  839.  
  840. int   pmvml(te, pos)
  841. t_entry   *te;
  842. long   pos;
  843. {
  844.    unsigned  tc  =  te->t_contents;
  845.    register  unsigned  dw  =  gettw(pos+2, R_WORD);
  846.    unsigned  sz = 4;
  847.    int   sc = 'l';
  848.    register  int   i;
  849.    register  unsigned  bit;
  850.    
  851.    xp += printf("movem.");
  852.    if  ((tc & 0x40) == 0)  {
  853.       sc = 'w';
  854.       sz = 2;
  855.    }
  856.    xp += printf("%c", sc);
  857.    gopos(ARGUMENT);
  858.    if  (tc & 0x400)  {
  859.       (void) prea(tc, pos+2, sz);
  860.       xp += printf(",&$%x", dw);
  861.    }
  862.    else  {
  863.       xp += printf("&$%x,", dw);
  864.       (void) prea(tc, pos+2, sz);
  865.    }
  866.    xp += printf("\t#\t");
  867.  
  868.    
  869.    xp += printf("\t|");
  870.    
  871.    if  ((tc & 0x38) == 0x20)  {
  872.       bit = 0x8000;
  873.       for  (i = 0;  i < 8;  i++)  {
  874.          if  (dw & bit)
  875.             xp += printf(" d%d", i);
  876.          bit >>= 1;
  877.       }
  878.       for  (i = 0;  i < 8;  i++)  {
  879.          if  (dw & bit)
  880.             xp += printf(" %s", areg[i]);
  881.          bit >>= 1;
  882.       }
  883.    }
  884.    else  {
  885.       bit = 1;
  886.       for  (i = 0;  i < 8;  i++)  {
  887.          if  (dw & bit)
  888.             xp += printf(" d%d", i);
  889.          bit <<= 1;
  890.       }
  891.       for  (i = 0;  i < 8;  i++)  {
  892.          if  (dw & bit)
  893.             xp += printf(" %s", areg[i]);
  894.          bit <<= 1;
  895.       }
  896.    }
  897. }
  898.  
  899. int ptrap(te, pos)
  900. t_entry   *te;
  901. long pos;
  902. {
  903.    if (te->t_contents != 0x4e40)
  904.    {
  905.       xp += printf("trap");
  906.       gopos(ARGUMENT);
  907.       xp += printf("#$%x", te->t_contents & 0xf);
  908.    }
  909.    else
  910.    {
  911.       char deftext[8];
  912.       char *s = deftext;
  913.       t_entry postword;
  914.       unsigned short trapcode;
  915.       extern char *systraps[], *iotraps[];
  916.       
  917.       gette(pos+2, &postword);
  918.       if ((trapcode = postword.t_contents) <= MAX_SYSTRAP)
  919.          s = systraps[trapcode];
  920.       else if (trapcode >= 0x80 && trapcode <= MAX_IOTRAP)   
  921.          s = iotraps[trapcode - 0x80];
  922.       else   
  923.          sprintf(deftext, "#$%x", trapcode);
  924.       xp += printf("os9");
  925.       gopos(ARGUMENT);
  926.       printf("%s", s);
  927.    }
  928.    return(0);
  929. }
  930.  
  931. int   plink(te, pos)
  932. t_entry   *te;
  933. long   pos;
  934. {
  935.    xp += printf("link");
  936.    gopos(ARGUMENT);
  937.    xp += printf("%s,#$%x", areg[te->t_contents & 0x7],
  938.             gettw(pos+2, R_WORD));
  939. }
  940.  
  941.  
  942. int   pareg(te)
  943. t_entry   *te;
  944. {
  945.    xp += printf(optab[te->t_iindex].prarg, areg[te->t_contents & 0x7]);
  946. }
  947.  
  948. int   podreg(te, pos)
  949. t_entry   *te;
  950. long   pos;
  951. {
  952.    unsigned  tc  =  te->t_contents;
  953.    
  954.    xp += printf("%s", optab[te->t_iindex].prarg);
  955.    gopos(ARGUMENT);
  956.    (void) prea(tc, pos, 2);
  957.    xp += printf(",d%d", (tc >> 9) & 0x7);
  958. }
  959.  
  960.  
  961. int   pqu(te, pos)
  962. t_entry   *te;
  963. long   pos;
  964. {
  965.    unsigned  tc  =  te->t_contents;
  966.    int   sz  =  findleng(tc);
  967.    int   amt = (tc >> 9) & 0x7;
  968.    
  969.    if  (amt == 0)
  970.       amt = 8;
  971.    xp += printf("%s.%c", optab[te->t_iindex].prarg, sz);
  972.    gopos(ARGUMENT);
  973.    xp += printf("#%d,", amt);
  974.    (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  975. }
  976.  
  977.  
  978. int   pmqu(te)
  979. t_entry   *te;
  980. {
  981.    unsigned  tc  =  te->t_contents;
  982.  
  983.    xp += printf("moveq.l");
  984.    gopos(ARGUMENT);
  985.    xp += printf("#$%x,d%d", (char)tc, (tc >> 9) & 0x7);
  986. }
  987.  
  988. int   ptreg(te)
  989. t_entry   *te;
  990. {
  991.    register  unsigned  tc  =  te->t_contents;
  992.    int   rx = (tc >> 9) & 0x7;
  993.    int   ry = tc & 0x7;
  994.  
  995.    xp += printf("%s", optab[te->t_iindex].prarg);
  996.    gopos(ARGUMENT);
  997.    if  (tc & 0x8)
  998.       xp += printf("-(%s),-(%s)", areg[ry], areg[rx]);
  999.    else
  1000.       xp += printf("%%d%d,%%d%d", ry, rx);
  1001.  
  1002. }
  1003.  
  1004. int   pcmpm(te)
  1005. t_entry   *te;
  1006. {
  1007.    register  unsigned  tc  =  te->t_contents;
  1008.  
  1009.    xp += printf("%s", optab[te->t_iindex].prarg);
  1010.    gopos(ARGUMENT);
  1011.    xp += printf("(%s)+,(%s)+", areg[tc & 7], areg[(tc >> 9) & 7]);
  1012. }
  1013.  
  1014. int   pomode(te, pos)
  1015. t_entry   *te;
  1016. long   pos;
  1017. {
  1018.    unsigned  tc  =  te->t_contents;
  1019.    char   buf[5];
  1020.    char   bef[4], aft[4];
  1021.    int   sz;
  1022.    int   reg = (tc >> 9) & 7;
  1023.  
  1024.    buf[0] = '\0';
  1025.    bef[0] = aft[0] = '\0';
  1026.    
  1027.    switch  ((tc >> 6) & 7)  {
  1028.    case  0:
  1029.       sz = 'b';
  1030.       goto  toreg;
  1031.    case  1:
  1032.       sz = 'w';
  1033.       goto  toreg;
  1034.    case  2:
  1035.       sz = 'l';
  1036.    toreg:
  1037.       (void) sprintf(aft, ",d%d", reg);
  1038.       break;
  1039.    case  3:
  1040.       sz = 'w';
  1041.       goto  toareg;
  1042.    case  7:
  1043.       sz = 'l';
  1044.    toareg:
  1045.       (void) sprintf(aft, ",%s", areg[reg]);
  1046.       break;
  1047.    case  4:
  1048.       sz = 'b';
  1049.       goto  frreg;
  1050.    case  5:
  1051.       sz = 'w';
  1052.       goto  frreg;
  1053.    case  6:
  1054.       sz = 'l';
  1055.    frreg:
  1056.       (void) sprintf(bef, "d%d,", reg);
  1057.       break;
  1058.    }
  1059.  
  1060.    xp += printf("%s.%c", optab[te->t_iindex].prarg, sz);
  1061.    gopos(ARGUMENT);
  1062.    xp += printf("%s", bef);
  1063.    (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  1064.    xp += printf(aft);
  1065. }
  1066.  
  1067. int   pexg(te)
  1068. t_entry   *te;
  1069. {
  1070.    unsigned  tc  =  te->t_contents;
  1071.    int   r1 = (tc >> 9) & 7, r2 = tc & 7;
  1072.  
  1073.    xp += printf("exg");
  1074.    gopos(ARGUMENT);
  1075.    
  1076.  
  1077.    if  ((tc & 0x00f8) == 0x0048)
  1078.       xp += printf("%s,", areg[r1]);
  1079.    else
  1080.       xp += printf("d%d,", r1);
  1081.    if  (tc & 0x8)
  1082.       xp += printf("%s", areg[r2]);
  1083.    else
  1084.       xp += printf("d%d", r2);
  1085.  
  1086. }
  1087.    
  1088. int   pmshf(te, pos)
  1089. t_entry   *te;
  1090. long   pos;
  1091. {
  1092.    unsigned  tc  =  te->t_contents;
  1093.    
  1094.    xp += printf("%s%c.w", shtype[(tc >> 9) & 3], tc & 0x100? 'l': 'r');
  1095.    gopos(ARGUMENT);
  1096.    (void) prea(tc, pos, 2);
  1097. }
  1098.  
  1099. int   pshf(te)
  1100. t_entry   *te;
  1101. {
  1102.    unsigned  tc  =  te->t_contents;
  1103.    int   sz  =  findleng(tc);
  1104.    int   disp = (tc >> 9) & 7;
  1105.  
  1106.    xp += printf("%s%c.%c", shtype[(tc >> 3) & 3], tc & 0x100? 'l': 'r', sz);
  1107.    gopos(ARGUMENT);
  1108.    if  (tc & 0x20)
  1109.       xp += printf("%%d%d", disp);
  1110.    else
  1111.       xp += printf("&%d", disp == 0? 8: disp);
  1112.    xp += printf(",%%d%d", tc & 7);
  1113.  
  1114. }
  1115.  
  1116. int linvalid()
  1117. {
  1118.    return (0);
  1119. }
  1120.  
  1121. /*
  1122.  *   Find length etc of instruction.
  1123.  */
  1124.  
  1125. int   findinst(te, pos)
  1126. register  t_entry  *te;
  1127. long   pos;
  1128. /*
  1129.    Disassembliert die Instruktion in te, die die ADresse pos haben muss.
  1130.    Rückkehrwert:
  1131.       ISFALSCH, wenn kein gültiger Opcode. 
  1132.       ISOK ansonsten. Dann sind folgende Felder gültig (aber nicht
  1133.          aus File rausgeschrieben):
  1134.          t_iindex    Index in OpCode-Tafel
  1135.          t_bchtyp    T_CONDBR (bedingte Verzweigung),
  1136.                  T_UNBR (unbedingte Verzweigung),
  1137.                  T_JSR
  1138.                  T_NOBR (unbedingte Verzweigung)
  1139.          t_lng         Länge der Instruktion
  1140.          t_relsymb    (nur bei Verzweigungen): Zieladresse
  1141. */                    
  1142. {
  1143.    register  struct  opstr   *op;
  1144.    unsigned  tc  =  te->t_contents;
  1145.    int  endpos, npos;
  1146.  
  1147.    for  (op = &optab[0];  (tc & op->mask) != op->match;  op++)
  1148.     ;
  1149.    te->t_iindex = op - optab;
  1150.    te->t_bchtyp = T_NOBR;
  1151.    if ((te->t_lng = (op->opsize)(te, pos)) == 0)
  1152.       return(ISFALSCH);   
  1153.    return(ISOK);
  1154. }
  1155.  
  1156. /*
  1157.  *   Print instruction.
  1158.  */
  1159.  
  1160. void   prinst(te, pos)
  1161. t_entry   *te;
  1162. long   pos;
  1163. {
  1164.    (optab[te->t_iindex].opprin)(te, pos);
  1165.    if (te->t_bchtyp == T_UNBR)
  1166.       putchar('\n');
  1167.    putchar('\n');
  1168. }
  1169.  
  1170.