Fix handling of null stap semaphores
[deliverable/binutils-gdb.git] / opcodes / sh-dis.c
index 5381d6aa53ffac91b3cd909a87ef128f4e9895c6..5d771a53a50a5732c43d91f6a860faa7550bf898 100644 (file)
@@ -1,45 +1,38 @@
 /* Disassemble SH instructions.
-   Copyright 1993, 1994, 1995, 1997, 1998, 2000, 2001, 2002, 2003, 2004
-   Free Software Foundation, Inc.
+   Copyright (C) 1993-2020 Free Software Foundation, Inc.
 
-   This program is free software; you can redistribute it and/or modify
+   This file is part of the GNU opcodes library.
+
+   This library is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
 
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
+   It is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
 
    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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
+   along with this file; see the file COPYING.  If not, write to the
+   Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
 
-#include <stdio.h>
 #include "sysdep.h"
+#include <stdio.h>
+
 #define STATIC_TABLE
 #define DEFINE_TABLE
 
 #include "sh-opc.h"
-#include "dis-asm.h"
-
-#ifdef ARCH_all
-#define INCLUDE_SHMEDIA
-#endif
-
-static void print_movxy
-  PARAMS ((const sh_opcode_info *, int, int, fprintf_ftype, void *));
-static void print_insn_ddt PARAMS ((int, struct disassemble_info *));
-static void print_dsp_reg PARAMS ((int, fprintf_ftype, void *));
-static void print_insn_ppi PARAMS ((int, struct disassemble_info *));
+#include "disassemble.h"
 
 static void
-print_movxy (op, rn, rm, fprintf_fn, stream)
-     const sh_opcode_info *op;
-     int rn, rm;
-     fprintf_ftype fprintf_fn;
-     void *stream;
+print_movxy (const sh_opcode_info *op,
+            int rn,
+            int rm,
+            fprintf_ftype fprintf_fn,
+            void *stream)
 {
   int n;
 
@@ -109,20 +102,20 @@ print_movxy (op, rn, rm, fprintf_fn, stream)
 
 /* Print a double data transfer insn.  INSN is just the lower three
    nibbles of the insn, i.e. field a and the bit that indicates if
-   a parallel processing insn follows.
-   Return nonzero if a field b of a parallel processing insns follows.  */
+   a parallel processing insn follows.  */
 
 static void
-print_insn_ddt (insn, info)
-     int insn;
-     struct disassemble_info *info;
+print_insn_ddt (int insn, struct disassemble_info *info)
 {
   fprintf_ftype fprintf_fn = info->fprintf_func;
   void *stream = info->stream;
 
   /* If this is just a nop, make sure to emit something.  */
   if (insn == 0x000)
-    fprintf_fn (stream, "nopx\tnopy");
+    {
+      fprintf_fn (stream, "nopx\tnopy");
+      return;
+    }
 
   /* If a parallel processing insn was printed before,
      and we got a non-nop, emit a tab.  */
@@ -130,8 +123,8 @@ print_insn_ddt (insn, info)
     fprintf_fn (stream, "\t");
 
   /* Check if either the x or y part is invalid.  */
-  if (((insn & 0xc) == 0 && (insn & 0x2a0))
-      || ((insn & 3) == 0 && (insn & 0x150)))
+  if (((insn & 3) != 0 && (insn & 0xc) == 0 && (insn & 0x2a0))
+      || ((insn & 3) == 0 && (insn & 0xc) != 0 && (insn & 0x150)))
     if (info->mach != bfd_mach_sh_dsp
         && info->mach != bfd_mach_sh3_dsp)
       {
@@ -157,7 +150,7 @@ print_insn_ddt (insn, info)
        while (op->nibbles[2] != (unsigned) ((insn >> 4) & 3)
               || op->nibbles[3] != (unsigned) (insn & 0xf))
          op++;
-       
+
        print_movxy (op,
                     (4 * ((insn & (is_movy ? 0x200 : 0x100)) == 0)
                      + 2 * is_movy
@@ -166,7 +159,7 @@ print_insn_ddt (insn, info)
                     fprintf_fn, stream);
       }
     else
-      fprintf_fn (stream, ".word 0x%x", insn);
+      fprintf_fn (stream, ".word 0x%x", insn | 0xf000);
   else
     {
       static const sh_opcode_info *first_movx, *first_movy;
@@ -198,14 +191,13 @@ print_insn_ddt (insn, info)
          print_movxy (opy, ((insn >> 8) & 1) + 6, (insn >> 6) & 1,
                       fprintf_fn, stream);
        }
+      if (!insn_x && !insn_y && ((insn & 0x3ff) != 0 || (insn & 0x800) == 0))
+       fprintf_fn (stream, ".word 0x%x", insn | 0xf000);
     }
 }
 
 static void
-print_dsp_reg (rm, fprintf_fn, stream)
-     int rm;
-     fprintf_ftype fprintf_fn;
-     void *stream;
+print_dsp_reg (int rm, fprintf_ftype fprintf_fn, void *stream)
 {
   switch (rm)
     {
@@ -246,9 +238,7 @@ print_dsp_reg (rm, fprintf_fn, stream)
 }
 
 static void
-print_insn_ppi (field_b, info)
-     int field_b;
-     struct disassemble_info *info;
+print_insn_ppi (int field_b, struct disassemble_info *info)
 {
   static char *sx_tab[] = { "x0", "x1", "a0", "a1" };
   static char *sy_tab[] = { "y0", "y1", "m0", "m1" };
@@ -275,23 +265,20 @@ print_insn_ppi (field_b, info)
       static char *sg_tab[] = { "m0", "m1", "a0", "a1" };
 
       if (field_b & 0x2000)
-       {
-         fprintf_fn (stream, "p%s %s,%s,%s\t",
-                     (field_b & 0x1000) ? "add" : "sub",
-                     sx_tab[(field_b >> 6) & 3],
-                     sy_tab[(field_b >> 4) & 3],
-                     du_tab[(field_b >> 0) & 3]);
-       }
+       fprintf_fn (stream, "p%s %s,%s,%s\t",
+                   (field_b & 0x1000) ? "add" : "sub",
+                   sx_tab[(field_b >> 6) & 3],
+                   sy_tab[(field_b >> 4) & 3],
+                   du_tab[(field_b >> 0) & 3]);
+
       else if ((field_b & 0xf0) == 0x10
               && info->mach != bfd_mach_sh_dsp
               && info->mach != bfd_mach_sh3_dsp)
-       {
-         fprintf_fn (stream, "pclr %s \t", du_tab[(field_b >> 0) & 3]);
-       }
+       fprintf_fn (stream, "pclr %s \t", du_tab[(field_b >> 0) & 3]);
+
       else if ((field_b & 0xf3) != 0)
-       {
-         fprintf_fn (stream, ".word 0x%x\t", field_b);
-       }
+       fprintf_fn (stream, ".word 0x%x\t", field_b);
+
       fprintf_fn (stream, "pmuls%c%s,%s,%s",
                  field_b & 0x2000 ? ' ' : '\t',
                  se_tab[(field_b >> 10) & 3],
@@ -368,10 +355,10 @@ print_insn_ppi (field_b, info)
                  print_dsp_reg (field_b & 0xf, fprintf_fn, stream);
                  break;
                case DSP_REG_X:
-                 fprintf_fn (stream, sx_tab[(field_b >> 6) & 3]);
+                 fprintf_fn (stream, "%s", sx_tab[(field_b >> 6) & 3]);
                  break;
                case DSP_REG_Y:
-                 fprintf_fn (stream, sy_tab[(field_b >> 4) & 3]);
+                 fprintf_fn (stream, "%s", sy_tab[(field_b >> 4) & 3]);
                  break;
                case A_MACH:
                  fprintf_fn (stream, "mach");
@@ -392,10 +379,9 @@ print_insn_ppi (field_b, info)
 
 /* FIXME mvs: movx insns print as ".word 0x%03x", insn & 0xfff
    (ie. the upper nibble is missing).  */
+
 int
-print_insn_sh (memaddr, info)
-     bfd_vma memaddr;
-     struct disassemble_info *info;
+print_insn_sh (bfd_vma memaddr, struct disassemble_info *info)
 {
   fprintf_ftype fprintf_fn = info->fprintf_func;
   void *stream = info->stream;
@@ -418,16 +404,6 @@ print_insn_sh (memaddr, info)
          && bfd_asymbol_flavour(*info->symbols) == bfd_target_coff_flavour)
        target_arch = arch_sh4;
       break;
-    case bfd_mach_sh5:
-#ifdef INCLUDE_SHMEDIA
-      status = print_insn_sh64 (memaddr, info);
-      if (status != -2)
-       return status;
-#endif
-      /* When we get here for sh64, it's because we want to disassemble
-        SHcompact, i.e. arch_sh4.  */
-      target_arch = arch_sh4;
-      break;
     default:
       target_arch = sh_get_arch_from_bfd_mach (info->mach);
     }
@@ -648,7 +624,7 @@ print_insn_sh (memaddr, info)
            case REG_N_D:
              if ((nibs[n] & 1) != 0)
                goto fail;
-             /* fall through */
+             /* Fall through.  */
            case REG_N:
              rn = nibs[n];
              break;
@@ -850,6 +826,7 @@ print_insn_sh (memaddr, info)
                  fprintf_fn (stream, "xd%d", rn & ~1);
                  break;
                }
+             /* Fall through.  */
            case D_REG_N:
              fprintf_fn (stream, "dr%d", rn);
              break;
@@ -859,6 +836,7 @@ print_insn_sh (memaddr, info)
                  fprintf_fn (stream, "xd%d", rm & ~1);
                  break;
                }
+             /* Fall through.  */
            case D_REG_M:
              fprintf_fn (stream, "dr%d", rm);
              break;
@@ -919,6 +897,8 @@ print_insn_sh (memaddr, info)
            size = 2;
          else
            size = 4;
+         /* Not reading an instruction - disable stop_vma.  */
+         info->stop_vma = 0;
          status = info->read_memory_func (disp_pc_addr, bytes, size, info);
          if (status == 0)
            {
@@ -940,11 +920,11 @@ print_insn_sh (memaddr, info)
                }
              if ((*info->symbol_at_address_func) (val, info))
                {
-                 fprintf_fn (stream, "\t! 0x");
+                 fprintf_fn (stream, "\t! ");
                  (*info->print_address_func) (val, info);
                }
              else
-               fprintf_fn (stream, "\t! 0x%x", val);
+               fprintf_fn (stream, "\t! %x", val);
            }
        }
 
This page took 0.031712 seconds and 4 git commands to generate.