home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / gdb-4.12.tar.gz / gdb-4.12.tar / gdb-4.12 / opcodes / m68k-dis.c < prev    next >
C/C++ Source or Header  |  1994-02-03  |  27KB  |  1,106 lines

  1. /* Print Motorola 68k instructions.
  2.    Copyright 1986, 1987, 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  3.  
  4. This file is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. #include "dis-asm.h"
  19. #include "ieee-float.h"
  20.  
  21. extern CONST struct ext_format ext_format_68881;
  22.  
  23. /* Opcode/m68k.h is a massive table.  As a kludge, break it up into
  24.    two pieces.  This makes nonportable C -- FIXME -- it assumes that
  25.    two data items declared near each other will be contiguous in
  26.    memory.  This kludge can be removed, FIXME, when GCC is fixed to not
  27.    be a hog about initializers.  */
  28.  
  29. #ifdef __GNUC__
  30. #define    BREAK_UP_BIG_DECL    }; \
  31.                 struct m68k_opcode m68k_opcodes_2[] = {
  32. #define    AND_OTHER_PART        sizeof (m68k_opcodes_2)
  33. #endif
  34.  
  35. #include "opcode/m68k.h"
  36.  
  37.  
  38. /* Local function prototypes */
  39.  
  40. static int
  41. fetch_arg PARAMS ((unsigned char *, int, int, disassemble_info *));
  42.  
  43. static void
  44. print_base PARAMS ((int, int, disassemble_info*));
  45.  
  46. static unsigned char *
  47. print_indexed PARAMS ((int, unsigned char *, bfd_vma, disassemble_info *));
  48.  
  49. static int
  50. print_insn_arg PARAMS ((char *, unsigned char *, unsigned char *, bfd_vma,
  51.             disassemble_info *));
  52.  
  53. CONST char * CONST fpcr_names[] = {
  54.   "", "fpiar", "fpsr", "fpiar/fpsr", "fpcr",
  55.   "fpiar/fpcr", "fpsr/fpcr", "fpiar/fpsr/fpcr"};
  56.  
  57. static char *reg_names[] = {
  58.   "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a0",
  59.   "a1", "a2", "a3", "a4", "a5", "fp", "sp", "ps", "pc"};
  60.  
  61. /* Sign-extend an (unsigned char). */
  62. #if __STDC__ == 1
  63. #define COERCE_SIGNED_CHAR(ch) ((signed char)(ch))
  64. #else
  65. #define COERCE_SIGNED_CHAR(ch) ((int)(((ch) ^ 0x80) & 0xFF) - 128)
  66. #endif
  67.  
  68. /* Get a 1 byte signed integer.  */
  69. #define NEXTBYTE(p)  (p += 2, FETCH_DATA (info, p), COERCE_SIGNED_CHAR(p[-1]))
  70.  
  71. /* Get a 2 byte signed integer.  */
  72. #define COERCE16(x) ((int) (((x) ^ 0x8000) - 0x8000))
  73. #define NEXTWORD(p)  \
  74.   (p += 2, FETCH_DATA (info, p), \
  75.    COERCE16 ((p[-2] << 8) + p[-1]))
  76.  
  77. /* Get a 4 byte signed integer.  */
  78. #define COERCE32(x) ((int) (((x) ^ 0x80000000) - 0x80000000))
  79. #define NEXTLONG(p)  \
  80.   (p += 4, FETCH_DATA (info, p), \
  81.    (COERCE32 ((((((p[-4] << 8) + p[-3]) << 8) + p[-2]) << 8) + p[-1])))
  82.  
  83. /* NEXTSINGLE and NEXTDOUBLE handle alignment problems, but not
  84.  * byte-swapping or other float format differences.  FIXME! */
  85.  
  86. union number {
  87.     double d;
  88.     float f;
  89.     char c[10];
  90. };
  91.  
  92. #define NEXTSINGLE(val, p) \
  93.   { int i; union number u;\
  94.     FETCH_DATA (info, p + sizeof (float));\
  95.     for (i = 0; i < sizeof(float); i++) u.c[i] = *p++; \
  96.     val = u.f; }
  97.  
  98. #define NEXTDOUBLE(val, p) \
  99.   { int i; union number u;\
  100.     FETCH_DATA (info, p + sizeof (double));\
  101.     for (i = 0; i < sizeof(double); i++) u.c[i] = *p++; \
  102.     val = u.d; }
  103.  
  104. /* Need a function to convert from extended to double precision... */
  105. #define NEXTEXTEND(p) \
  106.   (p += 12, FETCH_DATA (info, p), 0.0)
  107.  
  108. /* Need a function to convert from packed to double
  109.    precision.   Actually, it's easier to print a
  110.    packed number than a double anyway, so maybe
  111.    there should be a special case to handle this... */
  112. #define NEXTPACKED(p) \
  113.   (p += 12, FETCH_DATA (info, p), 0.0)
  114.  
  115.  
  116. /* Maximum length of an instruction.  */
  117. #define MAXLEN 22
  118.  
  119. #include <setjmp.h>
  120.  
  121. struct private
  122. {
  123.   /* Points to first byte not fetched.  */
  124.   bfd_byte *max_fetched;
  125.   bfd_byte the_buffer[MAXLEN];
  126.   bfd_vma insn_start;
  127.   jmp_buf bailout;
  128. };
  129.  
  130. /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
  131.    to ADDR (exclusive) are valid.  Returns 1 for success, longjmps
  132.    on error.  */
  133. #define FETCH_DATA(info, addr) \
  134.   ((addr) <= ((struct private *)(info->private_data))->max_fetched \
  135.    ? 1 : fetch_data ((info), (addr)))
  136.  
  137. static int
  138. fetch_data (info, addr)
  139.      struct disassemble_info *info;
  140.      bfd_byte *addr;
  141. {
  142.   int status;
  143.   struct private *priv = (struct private *)info->private_data;
  144.   bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
  145.  
  146.   status = (*info->read_memory_func) (start,
  147.                       priv->max_fetched,
  148.                       addr - priv->max_fetched,
  149.                       info);
  150.   if (status != 0)
  151.     {
  152.       (*info->memory_error_func) (status, start, info);
  153.       longjmp (priv->bailout, 1);
  154.     }
  155.   else
  156.     priv->max_fetched = addr;
  157.   return 1;
  158. }
  159.  
  160. /* This function is used to print to the bit-bucket. */
  161. static int
  162. #ifdef __STDC__
  163. dummy_printer (FILE * file, const char * format, ...)
  164. #else
  165. dummy_printer (file) FILE *file;
  166. #endif
  167.  { return 0; }
  168.  
  169. void
  170. dummy_print_address (vma, info)
  171.      bfd_vma vma;
  172.      struct disassemble_info *info;
  173. {
  174. }
  175.  
  176. /* Print the m68k instruction at address MEMADDR in debugged memory,
  177.    on INFO->STREAM.  Returns length of the instruction, in bytes.  */
  178.  
  179. int
  180. print_insn_m68k (memaddr, info)
  181.      bfd_vma memaddr;
  182.      disassemble_info *info;
  183. {
  184.   register int i;
  185.   register unsigned char *p;
  186.   unsigned char *save_p;
  187.   register char *d;
  188.   register unsigned long bestmask;
  189.   int best;
  190.   struct private priv;
  191.   bfd_byte *buffer = priv.the_buffer;
  192.   fprintf_ftype save_printer = info->fprintf_func;
  193.   void (*save_print_address) PARAMS((bfd_vma, struct disassemble_info*))
  194.     = info->print_address_func;
  195.  
  196.   info->private_data = (PTR) &priv;
  197.   priv.max_fetched = priv.the_buffer;
  198.   priv.insn_start = memaddr;
  199.   if (setjmp (priv.bailout) != 0)
  200.     /* Error return.  */
  201.     return -1;
  202.  
  203.   bestmask = 0;
  204.   best = -1;
  205.   FETCH_DATA (info, buffer + 2);
  206.   for (i = 0; i < numopcodes; i++)
  207.     {
  208.       register unsigned long opcode = m68k_opcodes[i].opcode;
  209.       register unsigned long match = m68k_opcodes[i].match;
  210.       if (((0xff & buffer[0] & (match >> 24)) == (0xff & (opcode >> 24)))
  211.       && ((0xff & buffer[1] & (match >> 16)) == (0xff & (opcode >> 16)))
  212.       /* Only fetch the next two bytes if we need to.  */
  213.       && (((0xffff & match) == 0)
  214.           ||
  215.           (FETCH_DATA (info, buffer + 4)
  216.            && ((0xff & buffer[2] & (match >> 8)) == (0xff & (opcode >> 8)))
  217.            && ((0xff & buffer[3] & match) == (0xff & opcode)))
  218.           ))
  219.     {
  220.       /* Don't use for printout the variants of divul and divsl
  221.          that have the same register number in two places.
  222.          The more general variants will match instead.  */
  223.       for (d = m68k_opcodes[i].args; *d; d += 2)
  224.         if (d[1] == 'D')
  225.           break;
  226.  
  227.       /* Don't use for printout the variants of most floating
  228.          point coprocessor instructions which use the same
  229.          register number in two places, as above. */
  230.       if (*d == 0)
  231.         for (d = m68k_opcodes[i].args; *d; d += 2)
  232.           if (d[1] == 't')
  233.         break;
  234.  
  235.       if (*d == 0 && match > bestmask)
  236.         {
  237.           best = i;
  238.           bestmask = match;
  239.         }
  240.     }
  241.     }
  242.  
  243.   if (best < 0)
  244.     goto invalid;
  245.  
  246.   /* Point at first word of argument data,
  247.      and at descriptor for first argument.  */
  248.   p = buffer + 2;
  249.   
  250.   /* Figure out how long the fixed-size portion of the instruction is.
  251.      The only place this is stored in the opcode table is
  252.      in the arguments--look for arguments which specify fields in the 2nd
  253.      or 3rd words of the instruction.  */
  254.   for (d = m68k_opcodes[best].args; *d; d += 2)
  255.     {
  256.       /* I don't think it is necessary to be checking d[0] here; I suspect
  257.      all this could be moved to the case statement below.  */
  258.       if (d[0] == '#')
  259.     {
  260.       if (d[1] == 'l' && p - buffer < 6)
  261.         p = buffer + 6;
  262.       else if (p - buffer < 4 && d[1] != 'C' && d[1] != '8' )
  263.         p = buffer + 4;
  264.     }
  265.       if ((d[0] == 'L' || d[0] == 'l') && d[1] == 'w' && p - buffer < 4)
  266.     p = buffer + 4;
  267.       switch (d[1])
  268.     {
  269.     case '1':
  270.     case '2':
  271.     case '3':
  272.     case '7':
  273.     case '8':
  274.     case '9':
  275.       if (p - buffer < 4)
  276.         p = buffer + 4;
  277.       break;
  278.     case '4':
  279.     case '5':
  280.     case '6':
  281.       if (p - buffer < 6)
  282.         p = buffer + 6;
  283.       break;
  284.     default:
  285.       break;
  286.     }
  287.     }
  288.   /* pflusha is an exception; it takes no arguments but is two words long.  */
  289.   if (buffer[0] == 0xf0 && buffer[1] == 0 && buffer[2] == 0x24 &&
  290.       buffer[3] == 0)
  291.     p = buffer + 4;
  292.   
  293.   FETCH_DATA (info, p);
  294.   
  295.   d = m68k_opcodes[best].args;
  296.  
  297.   /* We can the operands twice.  The first time we don't print anything,
  298.      but look for errors. */
  299.  
  300.   save_p = p;
  301.   info->print_address_func = dummy_print_address;
  302.   info->fprintf_func = (fprintf_ftype)dummy_printer;
  303.   for ( ; *d; d += 2)
  304.     {
  305.       int eaten = print_insn_arg (d, buffer, p, memaddr + p - buffer, info);
  306.       if (eaten >= 0)
  307.     p += eaten;
  308.       else if (eaten == -1)
  309.     goto invalid;
  310.       else
  311.     {
  312.       (*info->fprintf_func)(info->stream,
  313.                 "<internal error in opcode table: %s %s>\n",
  314.                 m68k_opcodes[best].name,
  315.                 m68k_opcodes[best].args);
  316.       goto invalid;
  317.     }
  318.  
  319.     }
  320.   p = save_p;
  321.   info->fprintf_func = save_printer;
  322.   info->print_address_func = save_print_address;
  323.  
  324.   d = m68k_opcodes[best].args;
  325.  
  326.   (*info->fprintf_func) (info->stream, "%s", m68k_opcodes[best].name);
  327.  
  328.   if (*d)
  329.     (*info->fprintf_func) (info->stream, " ");
  330.  
  331.   while (*d)
  332.     {
  333.       p += print_insn_arg (d, buffer, p, memaddr + p - buffer, info);
  334.       d += 2;
  335.       if (*d && *(d - 2) != 'I' && *d != 'k')
  336.     (*info->fprintf_func) (info->stream, ",");
  337.     }
  338.   return p - buffer;
  339.  
  340.  invalid:
  341.   /* Handle undefined instructions.  */
  342.   info->fprintf_func = save_printer;
  343.   info->print_address_func = save_print_address;
  344.   (*info->fprintf_func) (info->stream, "0%o",
  345.              (buffer[0] << 8) + buffer[1]);
  346.   return 2;
  347. }
  348.  
  349. /* Returns number of bytes "eaten" by the operand, or
  350.    return -1 if an invalid operand was found, or -2 if
  351.    an opcode tabe error was found. */
  352.  
  353. static int
  354. print_insn_arg (d, buffer, p0, addr, info)
  355.      char *d;
  356.      unsigned char *buffer;
  357.      unsigned char *p0;
  358.      bfd_vma addr;        /* PC for this arg to be relative to */
  359.      disassemble_info *info;
  360. {
  361.   register int val = 0;
  362.   register int place = d[1];
  363.   register unsigned char *p = p0;
  364.   int regno;
  365.   register CONST char *regname;
  366.   register unsigned char *p1;
  367.   double flval;
  368.   int flt_p;
  369.  
  370.   switch (*d)
  371.     {
  372.     case 'c':        /* cache identifier */
  373.       {
  374.         static char *cacheFieldName[] = { "NOP", "dc", "ic", "bc" };
  375.         val = fetch_arg (buffer, place, 2, info);
  376.         (*info->fprintf_func) (info->stream, cacheFieldName[val]);
  377.         break;
  378.       }
  379.  
  380.     case 'a':        /* address register indirect only. Cf. case '+'. */
  381.       {
  382.         (*info->fprintf_func)
  383.       (info->stream,
  384.        "%s@",
  385.        reg_names [fetch_arg (buffer, place, 3, info) + 8]);
  386.         break;
  387.       }
  388.  
  389.     case '_':        /* 32-bit absolute address for move16. */
  390.       {
  391.         val = NEXTLONG (p);
  392.         (*info->fprintf_func) (info->stream, "@#");
  393.     (*info->print_address_func) (val, info);
  394.         break;
  395.       }
  396.  
  397.     case 'C':
  398.       (*info->fprintf_func) (info->stream, "ccr");
  399.       break;
  400.  
  401.     case 'S':
  402.       (*info->fprintf_func) (info->stream, "sr");
  403.       break;
  404.  
  405.     case 'U':
  406.       (*info->fprintf_func) (info->stream, "usp");
  407.       break;
  408.  
  409.     case 'J':
  410.       {
  411.     static struct { char *name; int value; } names[]
  412.       = {{"sfc", 0x000}, {"dfc", 0x001}, {"cacr", 0x002},
  413.          {"tc",  0x003}, {"itt0",0x004}, {"itt1", 0x005},
  414.              {"dtt0",0x006}, {"dtt1",0x007},
  415.          {"usp", 0x800}, {"vbr", 0x801}, {"caar", 0x802},
  416.          {"msp", 0x803}, {"isp", 0x804},
  417.  
  418.          /* Should we be calling this psr like we do in case 'Y'?  */
  419.          {"mmusr",0x805},
  420.  
  421.              {"urp", 0x806}, {"srp", 0x807}};
  422.  
  423.     val = fetch_arg (buffer, place, 12, info);
  424.     for (regno = sizeof names / sizeof names[0] - 1; regno >= 0; regno--)
  425.       if (names[regno].value == val)
  426.         {
  427.           (*info->fprintf_func) (info->stream, names[regno].name);
  428.           break;
  429.         }
  430.     if (regno < 0)
  431.       (*info->fprintf_func) (info->stream, "%d", val);
  432.       }
  433.       break;
  434.  
  435.     case 'Q':
  436.       val = fetch_arg (buffer, place, 3, info);
  437.       /* 0 means 8, except for the bkpt instruction... */
  438.       if (val == 0 && d[1] != 's')
  439.     val = 8;
  440.       (*info->fprintf_func) (info->stream, "#%d", val);
  441.       break;
  442.  
  443.     case 'M':
  444.       val = fetch_arg (buffer, place, 8, info);
  445.       if (val & 0x80)
  446.     val = val - 0x100;
  447.       (*info->fprintf_func) (info->stream, "#%d", val);
  448.       break;
  449.  
  450.     case 'T':
  451.       val = fetch_arg (buffer, place, 4, info);
  452.       (*info->fprintf_func) (info->stream, "#%d", val);
  453.       break;
  454.  
  455.     case 'D':
  456.       (*info->fprintf_func) (info->stream, "%s",
  457.                  reg_names[fetch_arg (buffer, place, 3, info)]);
  458.       break;
  459.  
  460.     case 'A':
  461.       (*info->fprintf_func)
  462.     (info->stream, "%s",
  463.      reg_names[fetch_arg (buffer, place, 3, info) + 010]);
  464.       break;
  465.  
  466.     case 'R':
  467.       (*info->fprintf_func)
  468.     (info->stream, "%s",
  469.      reg_names[fetch_arg (buffer, place, 4, info)]);
  470.       break;
  471.  
  472.     case 'r':
  473.       (*info->fprintf_func)
  474.     (info->stream, "%s@",
  475.      reg_names[fetch_arg (buffer, place, 4, info)]);
  476.       break;
  477.  
  478.     case 'F':
  479.       (*info->fprintf_func)
  480.     (info->stream, "fp%d",
  481.      fetch_arg (buffer, place, 3, info));
  482.       break;
  483.  
  484.     case 'O':
  485.       val = fetch_arg (buffer, place, 6, info);
  486.       if (val & 0x20)
  487.     (*info->fprintf_func) (info->stream, "%s", reg_names [val & 7]);
  488.       else
  489.     (*info->fprintf_func) (info->stream, "%d", val);
  490.       break;
  491.  
  492.     case '+':
  493.       (*info->fprintf_func)
  494.     (info->stream, "%s@+",
  495.      reg_names[fetch_arg (buffer, place, 3, info) + 8]);
  496.       break;
  497.  
  498.     case '-':
  499.       (*info->fprintf_func)
  500.     (info->stream, "%s@-",
  501.      reg_names[fetch_arg (buffer, place, 3, info) + 8]);
  502.       break;
  503.  
  504.     case 'k':
  505.       if (place == 'k')
  506.     (*info->fprintf_func)
  507.       (info->stream, "{%s}",
  508.        reg_names[fetch_arg (buffer, place, 3, info)]);
  509.       else if (place == 'C')
  510.     {
  511.       val = fetch_arg (buffer, place, 7, info);
  512.       if ( val > 63 )        /* This is a signed constant. */
  513.         val -= 128;
  514.       (*info->fprintf_func) (info->stream, "{#%d}", val);
  515.     }
  516.       else
  517.     return -2;
  518.       break;
  519.  
  520.     case '#':
  521.     case '^':
  522.       p1 = buffer + (*d == '#' ? 2 : 4);
  523.       if (place == 's')
  524.     val = fetch_arg (buffer, place, 4, info);
  525.       else if (place == 'C')
  526.     val = fetch_arg (buffer, place, 7, info);
  527.       else if (place == '8')
  528.     val = fetch_arg (buffer, place, 3, info);
  529.       else if (place == '3')
  530.     val = fetch_arg (buffer, place, 8, info);
  531.       else if (place == 'b')
  532.     val = NEXTBYTE (p1);
  533.       else if (place == 'w')
  534.     val = NEXTWORD (p1);
  535.       else if (place == 'l')
  536.     val = NEXTLONG (p1);
  537.       else
  538.     return -2;
  539.       (*info->fprintf_func) (info->stream, "#%d", val);
  540.       break;
  541.  
  542.     case 'B':
  543.       if (place == 'b')
  544.     val = NEXTBYTE (p);
  545.       else if (place == 'B')
  546.     val = COERCE_SIGNED_CHAR(buffer[1]);
  547.       else if (place == 'w' || place == 'W')
  548.     val = NEXTWORD (p);
  549.       else if (place == 'l' || place == 'L')
  550.     val = NEXTLONG (p);
  551.       else if (place == 'g')
  552.     {
  553.       val = NEXTBYTE (buffer);
  554.       if (val == 0)
  555.         val = NEXTWORD (p);
  556.       else if (val == -1)
  557.         val = NEXTLONG (p);
  558.     }
  559.       else if (place == 'c')
  560.     {
  561.       if (buffer[1] & 0x40)        /* If bit six is one, long offset */
  562.         val = NEXTLONG (p);
  563.       else
  564.         val = NEXTWORD (p);
  565.     }
  566.       else
  567.     return -2;
  568.  
  569.       (*info->print_address_func) (addr + val, info);
  570.       break;
  571.  
  572.     case 'd':
  573.       val = NEXTWORD (p);
  574.       (*info->fprintf_func)
  575.     (info->stream, "%s@(%d)",
  576.      reg_names[fetch_arg (buffer, place, 3, info)], val);
  577.       break;
  578.  
  579.     case 's':
  580.       (*info->fprintf_func) (info->stream, "%s",
  581.                  fpcr_names[fetch_arg (buffer, place, 3, info)]);
  582.       break;
  583.  
  584.     case 'I':
  585.       /* Get coprocessor ID... */
  586.       val = fetch_arg (buffer, 'd', 3, info);
  587.       
  588.       if (val != 1)                /* Unusual coprocessor ID? */
  589.     (*info->fprintf_func) (info->stream, "(cpid=%d) ", val);
  590.       if (place == 'i')
  591.     p += 2;                 /* Skip coprocessor extended operands */
  592.       break;
  593.  
  594.     case '*':
  595.     case '~':
  596.     case '%':
  597.     case ';':
  598.     case '@':
  599.     case '!':
  600.     case '$':
  601.     case '?':
  602.     case '/':
  603.     case '&':
  604.     case '`':
  605.     case '|':
  606.  
  607.       if (place == 'd')
  608.     {
  609.       val = fetch_arg (buffer, 'x', 6, info);
  610.       val = ((val & 7) << 3) + ((val >> 3) & 7);
  611.     }
  612.       else
  613.     val = fetch_arg (buffer, 's', 6, info);
  614.  
  615.       /* Get register number assuming address register.  */
  616.       regno = (val & 7) + 8;
  617.       regname = reg_names[regno];
  618.       switch (val >> 3)
  619.     {
  620.     case 0:
  621.       (*info->fprintf_func) (info->stream, "%s", reg_names[val]);
  622.       break;
  623.  
  624.     case 1:
  625.       (*info->fprintf_func) (info->stream, "%s", regname);
  626.       break;
  627.  
  628.     case 2:
  629.       (*info->fprintf_func) (info->stream, "%s@", regname);
  630.       break;
  631.  
  632.     case 3:
  633.       (*info->fprintf_func) (info->stream, "%s@+", regname);
  634.       break;
  635.  
  636.     case 4:
  637.       (*info->fprintf_func) (info->stream, "%s@-", regname);
  638.       break;
  639.  
  640.     case 5:
  641.       val = NEXTWORD (p);
  642.       (*info->fprintf_func) (info->stream, "%s@(%d)", regname, val);
  643.       break;
  644.  
  645.     case 6:
  646.       p = print_indexed (regno, p, addr, info);
  647.       break;
  648.  
  649.     case 7:
  650.       switch (val & 7)
  651.         {
  652.         case 0:
  653.           val = NEXTWORD (p);
  654.           (*info->fprintf_func) (info->stream, "@#");
  655.           (*info->print_address_func) (val, info);
  656.           break;
  657.  
  658.         case 1:
  659.           val = NEXTLONG (p);
  660.           (*info->fprintf_func) (info->stream, "@#");
  661.           (*info->print_address_func) (val, info);
  662.           break;
  663.  
  664.         case 2:
  665.           val = NEXTWORD (p);
  666.           (*info->print_address_func) (addr + val, info);
  667.           break;
  668.  
  669.         case 3:
  670.           p = print_indexed (-1, p, addr, info);
  671.           break;
  672.  
  673.         case 4:
  674.           flt_p = 1;    /* Assume it's a float... */
  675.           switch( place )
  676.           {
  677.         case 'b':
  678.           val = NEXTBYTE (p);
  679.           flt_p = 0;
  680.           break;
  681.  
  682.         case 'w':
  683.           val = NEXTWORD (p);
  684.           flt_p = 0;
  685.           break;
  686.  
  687.         case 'l':
  688.           val = NEXTLONG (p);
  689.           flt_p = 0;
  690.           break;
  691.  
  692.         case 'f':
  693.           NEXTSINGLE(flval, p);
  694.           break;
  695.  
  696.         case 'F':
  697.           NEXTDOUBLE(flval, p);
  698.           break;
  699.  
  700.         case 'x':
  701.           ieee_extended_to_double (&ext_format_68881,
  702.                        (char *)p, &flval);
  703.           p += 12;
  704.           break;
  705.  
  706.         case 'p':
  707.           flval = NEXTPACKED(p);
  708.           break;
  709.  
  710.         default:
  711.           return -1;
  712.           }
  713.           if ( flt_p )    /* Print a float? */
  714.         (*info->fprintf_func) (info->stream, "#%g", flval);
  715.           else
  716.         (*info->fprintf_func) (info->stream, "#%d", val);
  717.           break;
  718.  
  719.         default:
  720.           return -1;
  721.         }
  722.     }
  723.       break;
  724.  
  725.     case 'L':
  726.     case 'l':
  727.     if (place == 'w')
  728.       {
  729.         char doneany;
  730.         p1 = buffer + 2;
  731.         val = NEXTWORD (p1);
  732.         /* Move the pointer ahead if this point is farther ahead
  733.            than the last.  */
  734.         p = p1 > p ? p1 : p;
  735.         if (val == 0)
  736.           {
  737.         (*info->fprintf_func) (info->stream, "#0");
  738.         break;
  739.           }
  740.         if (*d == 'l')
  741.           {
  742.         register int newval = 0;
  743.         for (regno = 0; regno < 16; ++regno)
  744.           if (val & (0x8000 >> regno))
  745.             newval |= 1 << regno;
  746.         val = newval;
  747.           }
  748.         val &= 0xffff;
  749.         doneany = 0;
  750.         for (regno = 0; regno < 16; ++regno)
  751.           if (val & (1 << regno))
  752.         {
  753.           int first_regno;
  754.           if (doneany)
  755.             (*info->fprintf_func) (info->stream, "/");
  756.           doneany = 1;
  757.           (*info->fprintf_func) (info->stream, "%s", reg_names[regno]);
  758.           first_regno = regno;
  759.           while (val & (1 << (regno + 1)))
  760.             ++regno;
  761.           if (regno > first_regno)
  762.             (*info->fprintf_func) (info->stream, "-%s",
  763.                        reg_names[regno]);
  764.         }
  765.       }
  766.     else if (place == '3')
  767.       {
  768.         /* `fmovem' insn.  */
  769.         char doneany;
  770.         val = fetch_arg (buffer, place, 8, info);
  771.         if (val == 0)
  772.           {
  773.         (*info->fprintf_func) (info->stream, "#0");
  774.         break;
  775.           }
  776.         if (*d == 'l')
  777.           {
  778.         register int newval = 0;
  779.         for (regno = 0; regno < 8; ++regno)
  780.           if (val & (0x80 >> regno))
  781.             newval |= 1 << regno;
  782.         val = newval;
  783.           }
  784.         val &= 0xff;
  785.         doneany = 0;
  786.         for (regno = 0; regno < 8; ++regno)
  787.           if (val & (1 << regno))
  788.         {
  789.           int first_regno;
  790.           if (doneany)
  791.             (*info->fprintf_func) (info->stream, "/");
  792.           doneany = 1;
  793.           (*info->fprintf_func) (info->stream, "fp%d", regno);
  794.           first_regno = regno;
  795.           while (val & (1 << (regno + 1)))
  796.             ++regno;
  797.           if (regno > first_regno)
  798.             (*info->fprintf_func) (info->stream, "-fp%d", regno);
  799.         }
  800.       }
  801.     else
  802.       return -2;
  803.       break;
  804.  
  805.     case 'X':
  806.       place = '8';
  807.     case 'Y':
  808.     case 'Z':
  809.     case 'W':
  810.     case '3':
  811.     case 'P':
  812.       {
  813.     int val = fetch_arg (buffer, place, 5, info);
  814.     char *name = 0;
  815.     switch (val)
  816.       {
  817.       case 2: name = "tt0"; break;
  818.       case 3: name = "tt1"; break;
  819.       case 0x10: name = "tc"; break;
  820.       case 0x11: name = "drp"; break;
  821.       case 0x12: name = "srp"; break;
  822.       case 0x13: name = "crp"; break;
  823.       case 0x14: name = "cal"; break;
  824.       case 0x15: name = "val"; break;
  825.       case 0x16: name = "scc"; break;
  826.       case 0x17: name = "ac"; break;
  827.        case 0x18: name = "psr"; break;
  828.       case 0x19: name = "pcsr"; break;
  829.       case 0x1c:
  830.       case 0x1d:
  831.         {
  832.           int break_reg = ((buffer[3] >> 2) & 7);
  833.           (*info->fprintf_func)
  834.         (info->stream, val == 0x1c ? "bad%d" : "bac%d",
  835.          break_reg);
  836.         }
  837.         break;
  838.       default:
  839.         (*info->fprintf_func) (info->stream, "<mmu register %d>", val);
  840.       }
  841.     if (name)
  842.       (*info->fprintf_func) (info->stream, name);
  843.       }
  844.       break;
  845.  
  846.     case 'f':
  847.       {
  848.     int fc = fetch_arg (buffer, place, 5, info);
  849.     if (fc == 1)
  850.       (*info->fprintf_func) (info->stream, "dfc");
  851.     else if (fc == 0)
  852.       (*info->fprintf_func) (info->stream, "sfc");
  853.     else
  854.       (*info->fprintf_func) (info->stream, "<function code %d>", fc);
  855.       }
  856.       break;
  857.  
  858.     case 'V':
  859.       (*info->fprintf_func) (info->stream, "val");
  860.       break;
  861.  
  862.     case 't':
  863.       {
  864.     int level = fetch_arg (buffer, place, 3, info);
  865.     (*info->fprintf_func) (info->stream, "%d", level);
  866.       }
  867.       break;
  868.  
  869.     default:
  870.       return -2;
  871.     }
  872.  
  873.   return p - p0;
  874. }
  875.  
  876. /* Fetch BITS bits from a position in the instruction specified by CODE.
  877.    CODE is a "place to put an argument", or 'x' for a destination
  878.    that is a general address (mode and register).
  879.    BUFFER contains the instruction.  */
  880.  
  881. static int
  882. fetch_arg (buffer, code, bits, info)
  883.      unsigned char *buffer;
  884.      int code;
  885.      int bits;
  886.      disassemble_info *info;
  887. {
  888.   register int val = 0;
  889.   switch (code)
  890.     {
  891.     case 's':
  892.       val = buffer[1];
  893.       break;
  894.  
  895.     case 'd':            /* Destination, for register or quick.  */
  896.       val = (buffer[0] << 8) + buffer[1];
  897.       val >>= 9;
  898.       break;
  899.  
  900.     case 'x':            /* Destination, for general arg */
  901.       val = (buffer[0] << 8) + buffer[1];
  902.       val >>= 6;
  903.       break;
  904.  
  905.     case 'k':
  906.       FETCH_DATA (info, buffer + 3);
  907.       val = (buffer[3] >> 4);
  908.       break;
  909.  
  910.     case 'C':
  911.       FETCH_DATA (info, buffer + 3);
  912.       val = buffer[3];
  913.       break;
  914.  
  915.     case '1':
  916.       FETCH_DATA (info, buffer + 3);
  917.       val = (buffer[2] << 8) + buffer[3];
  918.       val >>= 12;
  919.       break;
  920.  
  921.     case '2':
  922.       FETCH_DATA (info, buffer + 3);
  923.       val = (buffer[2] << 8) + buffer[3];
  924.       val >>= 6;
  925.       break;
  926.  
  927.     case '3':
  928.     case 'j':
  929.       FETCH_DATA (info, buffer + 3);
  930.       val = (buffer[2] << 8) + buffer[3];
  931.       break;
  932.  
  933.     case '4':
  934.       FETCH_DATA (info, buffer + 5);
  935.       val = (buffer[4] << 8) + buffer[5];
  936.       val >>= 12;
  937.       break;
  938.  
  939.     case '5':
  940.       FETCH_DATA (info, buffer + 5);
  941.       val = (buffer[4] << 8) + buffer[5];
  942.       val >>= 6;
  943.       break;
  944.  
  945.     case '6':
  946.       FETCH_DATA (info, buffer + 5);
  947.       val = (buffer[4] << 8) + buffer[5];
  948.       break;
  949.  
  950.     case '7':
  951.       FETCH_DATA (info, buffer + 3);
  952.       val = (buffer[2] << 8) + buffer[3];
  953.       val >>= 7;
  954.       break;
  955.       
  956.     case '8':
  957.       FETCH_DATA (info, buffer + 3);
  958.       val = (buffer[2] << 8) + buffer[3];
  959.       val >>= 10;
  960.       break;
  961.  
  962.     case '9':
  963.       FETCH_DATA (info, buffer + 3);
  964.       val = (buffer[2] << 8) + buffer[3];
  965.       val >>= 5;
  966.       break;
  967.  
  968.     case 'e':
  969.       val = (buffer[1] >> 6);
  970.       break;
  971.  
  972.     default:
  973.       abort ();
  974.     }
  975.  
  976.   switch (bits)
  977.     {
  978.     case 2:
  979.       return val & 3;
  980.     case 3:
  981.       return val & 7;
  982.     case 4:
  983.       return val & 017;
  984.     case 5:
  985.       return val & 037;
  986.     case 6:
  987.       return val & 077;
  988.     case 7:
  989.       return val & 0177;
  990.     case 8:
  991.       return val & 0377;
  992.     case 12:
  993.       return val & 07777;
  994.     default:
  995.       abort ();
  996.     }
  997. }
  998.  
  999. /* Print an indexed argument.  The base register is BASEREG (-1 for pc).
  1000.    P points to extension word, in buffer.
  1001.    ADDR is the nominal core address of that extension word.  */
  1002.  
  1003. static unsigned char *
  1004. print_indexed (basereg, p, addr, info)
  1005.      int basereg;
  1006.      unsigned char *p;
  1007.      bfd_vma addr;
  1008.      disassemble_info *info;
  1009. {
  1010.   register int word;
  1011.   static char *scales[] = {"", "*2", "*4", "*8"};
  1012.   register int base_disp;
  1013.   register int outer_disp;
  1014.   char buf[40];
  1015.  
  1016.   word = NEXTWORD (p);
  1017.  
  1018.   /* Generate the text for the index register.
  1019.      Where this will be output is not yet determined.  */
  1020.   sprintf (buf, "[%s.%c%s]",
  1021.        reg_names[(word >> 12) & 0xf],
  1022.        (word & 0x800) ? 'l' : 'w',
  1023.        scales[(word >> 9) & 3]);
  1024.  
  1025.   /* Handle the 68000 style of indexing.  */
  1026.  
  1027.   if ((word & 0x100) == 0)
  1028.     {
  1029.       print_base (basereg,
  1030.           ((word & 0x80) ? word | 0xff00 : word & 0xff)
  1031.           + ((basereg == -1) ? addr : 0),
  1032.           info);
  1033.       (*info->fprintf_func) (info->stream, "%s", buf);
  1034.       return p;
  1035.     }
  1036.  
  1037.   /* Handle the generalized kind.  */
  1038.   /* First, compute the displacement to add to the base register.  */
  1039.  
  1040.   if (word & 0200)
  1041.     basereg = -2;
  1042.   if (word & 0100)
  1043.     buf[0] = 0;
  1044.   base_disp = 0;
  1045.   switch ((word >> 4) & 3)
  1046.     {
  1047.     case 2:
  1048.       base_disp = NEXTWORD (p);
  1049.       break;
  1050.     case 3:
  1051.       base_disp = NEXTLONG (p);
  1052.     }
  1053.   if (basereg == -1)
  1054.     base_disp += addr;
  1055.  
  1056.   /* Handle single-level case (not indirect) */
  1057.  
  1058.   if ((word & 7) == 0)
  1059.     {
  1060.       print_base (basereg, base_disp, info);
  1061.       (*info->fprintf_func) (info->stream, "%s", buf);
  1062.       return p;
  1063.     }
  1064.  
  1065.   /* Two level.  Compute displacement to add after indirection.  */
  1066.  
  1067.   outer_disp = 0;
  1068.   switch (word & 3)
  1069.     {
  1070.     case 2:
  1071.       outer_disp = NEXTWORD (p);
  1072.       break;
  1073.     case 3:
  1074.       outer_disp = NEXTLONG (p);
  1075.     }
  1076.  
  1077.   (*info->fprintf_func) (info->stream, "%d(", outer_disp);
  1078.   print_base (basereg, base_disp, info);
  1079.  
  1080.   /* If postindexed, print the closeparen before the index.  */
  1081.   if (word & 4)
  1082.     (*info->fprintf_func) (info->stream, ")%s", buf);
  1083.   /* If preindexed, print the closeparen after the index.  */
  1084.   else
  1085.     (*info->fprintf_func) (info->stream, "%s)", buf);
  1086.  
  1087.   return p;
  1088. }
  1089.  
  1090. /* Print a base register REGNO and displacement DISP, on INFO->STREAM.
  1091.    REGNO = -1 for pc, -2 for none (suppressed).  */
  1092.  
  1093. static void
  1094. print_base (regno, disp, info)
  1095.      int regno;
  1096.      int disp;
  1097.      disassemble_info *info;
  1098. {
  1099.   if (regno == -2)
  1100.     (*info->fprintf_func) (info->stream, "%d", disp);
  1101.   else if (regno == -1)
  1102.     (*info->fprintf_func) (info->stream, "0x%x", (unsigned) disp);
  1103.   else
  1104.     (*info->fprintf_func) (info->stream, "%d(%s)", disp, reg_names[regno]);
  1105. }
  1106.