]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - opcodes/m68k-dis.c
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / opcodes / m68k-dis.c
index a14db9a1f6a523d4bfef4802c665be7740afbfb5..5396a0ce1325fd21027626798bc0da226ca522bb 100644 (file)
@@ -1,5 +1,5 @@
 /* Print Motorola 68k instructions.
-   Copyright (C) 1986-2017 Free Software Foundation, Inc.
+   Copyright (C) 1986-2021 Free Software Foundation, Inc.
 
    This file is part of the GNU opcodes library.
 
    MA 02110-1301, USA.  */
 
 #include "sysdep.h"
-#include "dis-asm.h"
+#include "disassemble.h"
 #include "floatformat.h"
 #include "libiberty.h"
 #include "opintl.h"
-
+#include "cpu-m68k.h"
 #include "opcode/m68k.h"
 
 /* Local function prototypes.  */
@@ -96,7 +96,7 @@ enum print_insn_arg_error
   while (0)
 
 /* Get a 4 byte signed integer.  */
-#define COERCE32(x) ((bfd_signed_vma) ((x) ^ 0x80000000) - 0x80000000)
+#define COERCE32(x) (((bfd_vma) (x) ^ 0x80000000) - 0x80000000)
 
 #define NEXTLONG(p, val, ret_val)                                      \
   do                                                                   \
@@ -104,7 +104,8 @@ enum print_insn_arg_error
       p += 4;                                                          \
       if (!FETCH_DATA (info, p))                                       \
        return ret_val;                                                 \
-      val = COERCE32 ((((((p[-4] << 8) + p[-3]) << 8) + p[-2]) << 8) + p[-1]); \
+      val = COERCE32 (((((((unsigned) p[-4] << 8) + p[-3]) << 8)       \
+                       + p[-2]) << 8) + p[-1]);                        \
     }                                                                  \
   while (0)
 
@@ -115,7 +116,8 @@ enum print_insn_arg_error
       p += 4;                                                          \
       if (!FETCH_DATA (info, p))                                       \
        return PRINT_INSN_ARG_MEMORY_ERROR;                             \
-      val = (unsigned int) ((((((p[-4] << 8) + p[-3]) << 8) + p[-2]) << 8) + p[-1]); \
+      val = (((((((unsigned) p[-4] << 8) + p[-3]) << 8)                        \
+              + p[-2]) << 8) + p[-1]);                                 \
     }                                                                  \
   while (0)
 
@@ -1331,7 +1333,8 @@ print_insn_arg (const char *d,
 }
 
 /* Try to match the current instruction to best and if so, return the
-   number of bytes consumed from the instruction stream, else zero.  */
+   number of bytes consumed from the instruction stream, else zero.
+   Return -1 on memory error.  */
 
 static int
 match_insn_m68k (bfd_vma memaddr,
@@ -1415,12 +1418,14 @@ match_insn_m68k (bfd_vma memaddr,
         this because we know exactly what the second word is, and we
         aren't going to print anything based on it.  */
       p = buffer + 6;
-      FETCH_DATA (info, p);
+      if (!FETCH_DATA (info, p))
+       return -1;
       buffer[2] = buffer[4];
       buffer[3] = buffer[5];
     }
 
-  FETCH_DATA (info, p);
+  if (!FETCH_DATA (info, p))
+    return -1;
 
   save_p = p;
   info->print_address_func = dummy_print_address;
@@ -1439,7 +1444,7 @@ match_insn_m68k (bfd_vma memaddr,
        {
          info->fprintf_func = save_printer;
          info->print_address_func = save_print_address;
-         return 0;
+         return eaten == PRINT_INSN_ARG_MEMORY_ERROR ? -1 : 0;
        }
       else
        {
@@ -1481,7 +1486,8 @@ match_insn_m68k (bfd_vma memaddr,
 /* Try to interpret the instruction at address MEMADDR as one that
    can execute on a processor with the features given by ARCH_MASK.
    If successful, print the instruction to INFO->STREAM and return
-   its length in bytes.  Return 0 otherwise.  */
+   its length in bytes.  Return 0 otherwise.  Return -1 on memory
+   error.  */
 
 static int
 m68k_scan_mask (bfd_vma memaddr, disassemble_info *info,
@@ -1523,7 +1529,8 @@ m68k_scan_mask (bfd_vma memaddr, disassemble_info *info,
        *opc_pointer[(m68k_opcodes[i].opcode >> 28) & 15]++ = &m68k_opcodes[i];
     }
 
-  FETCH_DATA (info, buffer + 2);
+  if (!FETCH_DATA (info, buffer + 2))
+    return -1;
   major_opcode = (buffer[0] >> 4) & 15;
 
   for (i = 0; i < numopcodes[major_opcode]; i++)
@@ -1628,7 +1635,7 @@ print_insn_m68k (bfd_vma memaddr, disassemble_info *info)
       /* First try printing an m680x0 instruction.  Try printing a Coldfire
         one if that fails.  */
       val = m68k_scan_mask (memaddr, info, m68k_mask);
-      if (val == 0)
+      if (val <= 0)
        val = m68k_scan_mask (memaddr, info, mcf_mask);
     }
   else