doc/gdbinv-s.m4.in: remove text on special procedures to continue after
[deliverable/binutils-gdb.git] / gdb / m68k-pinsn.c
index c080d8cad2619c0c47021ad0c7626df9c2a96b8e..7f442d5024136b9eb2a345c9aa1ea3a0b4a427b5 100644 (file)
@@ -1,5 +1,5 @@
-/* Print m68k instructions for GDB, the GNU debugger.
-   Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc.
+/* Print Motorola 68k instructions for GDB, the GNU debugger.
+   Copyright 1986, 1987, 1989, 1991, 1992 Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -17,13 +17,26 @@ You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
-#include <stdio.h>
-
 #include "defs.h"
-#include "param.h"
 #include "symtab.h"
-#include "m68k-opcode.h"
+#include "opcode/m68k.h"
 #include "gdbcore.h"
+#include "ieee-float.h"
+
+/* Local function prototypes */
+
+static int
+fetch_arg PARAMS ((unsigned char *, int, int));
+
+static void
+print_base PARAMS ((int, int, FILE *));
+
+static unsigned char *
+print_indexed PARAMS ((int, unsigned char *, CORE_ADDR, FILE *));
+
+static unsigned char *
+print_insn_arg PARAMS ((char *, unsigned char *, unsigned char *, CORE_ADDR,
+                       FILE *));
 
 /* 68k instructions are never longer than this many bytes.  */
 #define MAXLEN 22
@@ -31,38 +44,34 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 /* Number of elements in the opcode table.  */
 #define NOPCODES (sizeof m68k_opcodes / sizeof m68k_opcodes[0])
 
-extern char *reg_names[];
-char *fpcr_names[] = { "", "fpiar", "fpsr", "fpiar/fpsr", "fpcr",
-                    "fpiar/fpcr", "fpsr/fpcr", "fpiar-fpcr"};
+const char * const fpcr_names[] = {
+  "", "fpiar", "fpsr", "fpiar/fpsr", "fpcr",
+  "fpiar/fpcr", "fpsr/fpcr", "fpiar/fpsr/fpcr"};
 
-static unsigned char *print_insn_arg ();
-static unsigned char *print_indexed ();
-static void print_base ();
-static int fetch_arg ();
+/* Define accessors for 68K's 1, 2, and 4-byte signed quantities.
+   The _SHIFT values move the quantity to the high order end of an
+   `int' value, so it will sign-extend.  Probably a few more casts
+   are needed to make it compile without warnings on finicky systems.  */
+#define        BITS_PER_BYTE   8
+#define        BYTE_SHIFT (BITS_PER_BYTE * ((sizeof (int)) - 1))
+#define        WORD_SHIFT (BITS_PER_BYTE * ((sizeof (int)) - 2))
+#define        LONG_SHIFT (BITS_PER_BYTE * ((sizeof (int)) - 4))
 
-#define NEXTBYTE(p)  (p += 2, ((char *)p)[-1])
+#define NEXTBYTE(p)  (p += 2, ((int)(p[-1]) << BYTE_SHIFT) >> BYTE_SHIFT)
 
 #define NEXTWORD(p)  \
-  (p += 2, ((((char *)p)[-2]) << 8) + p[-1])
+  (p += 2, (((int)((p[-2] << 8) + p[-1])) << WORD_SHIFT) >> WORD_SHIFT)
 
 #define NEXTLONG(p)  \
-  (p += 4, (((((p[-4] << 8) + p[-3]) << 8) + p[-2]) << 8) + p[-1])
+  (p += 4, (((int)((((((p[-4] << 8) + p[-3]) << 8) + p[-2]) << 8) + p[-1])) \
+                                  << LONG_SHIFT) >> LONG_SHIFT)
 
+/* Ecch -- assumes host == target float formats.  FIXME.  */
 #define NEXTSINGLE(p) \
   (p += 4, *((float *)(p - 4)))
 
 #define NEXTDOUBLE(p) \
   (p += 8, *((double *)(p - 8)))
-
-#define NEXTEXTEND(p) \
-  (p += 12, 0.0)       /* Need a function to convert from extended to double
-                          precision... */
-
-#define NEXTPACKED(p) \
-  (p += 12, 0.0)       /* Need a function to convert from packed to double
-                          precision.   Actually, it's easier to print a
-                          packed number than a double anyway, so maybe
-                          there should be a special case to handle this... */
 \f
 /* Print the m68k instruction at address MEMADDR in debugged memory,
    on STREAM.  Returns length of the instruction, in bytes.  */
@@ -79,7 +88,7 @@ print_insn (memaddr, stream)
   register int bestmask;
   int best;
 
-  read_memory (memaddr, buffer, MAXLEN);
+  read_memory (memaddr, (char *) buffer, MAXLEN);
 
   bestmask = 0;
   best = -1;
@@ -172,9 +181,9 @@ print_insn_arg (d, buffer, p, addr, stream)
   register int val;
   register int place = d[1];
   int regno;
-  register char *regname;
+  register const char *regname;
   register unsigned char *p1;
-  register double flval;
+  double flval;
   int flt_p;
 
   switch (*d)
@@ -243,6 +252,10 @@ print_insn_arg (d, buffer, p, addr, stream)
       fprintf_filtered (stream, "%s", reg_names[fetch_arg (buffer, place, 4)]);
       break;
 
+    case 'r':
+      fprintf_filtered (stream, "%s@", reg_names[fetch_arg (buffer, place, 4)]);
+      break;
+
     case 'F':
       fprintf_filtered (stream, "fp%d", fetch_arg (buffer, place, 3));
       break;
@@ -306,13 +319,15 @@ print_insn_arg (d, buffer, p, addr, stream)
     case 'B':
       if (place == 'b')
        val = NEXTBYTE (p);
-      else if (place == 'w')
+      else if (place == 'B')
+       val = NEXTBYTE (buffer);        /* from the opcode word */
+      else if (place == 'w' || place == 'W')
        val = NEXTWORD (p);
-      else if (place == 'l')
+      else if (place == 'l' || place == 'L')
        val = NEXTLONG (p);
       else if (place == 'g')
        {
-         val = ((char *)buffer)[1];
+         val = NEXTBYTE (buffer);
          if (val == 0)
            val = NEXTWORD (p);
          else if (val == -1)
@@ -455,12 +470,16 @@ print_insn_arg (d, buffer, p, addr, stream)
                  flval = NEXTDOUBLE(p);
                  break;
 
+#ifdef HAVE_68881
                case 'x':
-                 flval = NEXTEXTEND(p);
+                 ieee_extended_to_double (&ext_format_68881, p, &flval);
+                 p += 12;
                  break;
+#endif
 
                case 'p':
-                 flval = NEXTPACKED(p);
+                 p += 12;
+                 flval = 0;    /* FIXME, handle packed decimal someday.  */
                  break;
 
                default:
@@ -555,10 +574,10 @@ print_insn_arg (d, buffer, p, addr, stream)
                }
          }
        else
-         abort ();
+         goto de_fault;
       break;
 
-    default:
+    default:  de_fault:
       error ("Invalid arg format in opcode table: \"%c\".", *d);
     }
 
@@ -573,7 +592,7 @@ print_insn_arg (d, buffer, p, addr, stream)
 static int
 fetch_arg (buffer, code, bits)
      unsigned char *buffer;
-     char code;
+     int code;
      int bits;
 {
   register int val;
@@ -673,8 +692,8 @@ static unsigned char *
 print_indexed (basereg, p, addr, stream)
      int basereg;
      unsigned char *p;
-     FILE *stream;
      CORE_ADDR addr;
+     FILE *stream;
 {
   register int word;
   static char *scales[] = {"", "*2", "*4", "*8"};
This page took 0.027472 seconds and 4 git commands to generate.