Introduce basic_safe_range
[deliverable/binutils-gdb.git] / opcodes / z8k-dis.c
index 02f5dcb7705e3d0642d9a3a0d53752de3c8751c8..b2533b082752b1336152077e5247f14cd8585216 100644 (file)
@@ -1,32 +1,31 @@
 /* Disassemble z8000 code.
-   Copyright 1992, 1993, 1998, 2000, 2001, 2002, 2003
-   Free Software Foundation, Inc.
+   Copyright (C) 1992-2019 Free Software Foundation, Inc.
 
-   This file is part of GNU Binutils.
+   This file is part of the GNU opcodes library.
 
-   This program is free software; you can redistribute it and/or modify
+   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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-   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 "sysdep.h"
-#include "dis-asm.h"
+#include "disassemble.h"
 
 #define DEFINE_TABLE
 #include "z8k-opc.h"
 
 #include <setjmp.h>
-\f
+
 typedef struct
 {
   /* These are all indexed by nibble number (i.e only every other entry
@@ -38,7 +37,7 @@ typedef struct
   /* Nibble number of first word not yet fetched.  */
   int max_fetched;
   bfd_vma insn_start;
-  jmp_buf bailout;
+  OPCODES_SIGJMP_BUF bailout;
 
   int tabl_index;
   char instr_asmsrc[80];
@@ -77,7 +76,7 @@ fetch_data (struct disassemble_info *info, int nibble)
   if (status != 0)
     {
       (*info->memory_error_func) (status, priv->insn_start, info);
-      longjmp (priv->bailout, 1);
+      OPCODES_SIGLONGJMP (priv->bailout, 1);
     }
 
   {
@@ -150,7 +149,7 @@ print_insn_z8k (bfd_vma addr, disassemble_info *info, int is_segmented)
   info->private_data = (PTR) &instr_data;
   instr_data.max_fetched = 0;
   instr_data.insn_start = addr;
-  if (setjmp (instr_data.bailout) != 0)
+  if (OPCODES_SIGSETJMP (instr_data.bailout) != 0)
     /* Error return.  */
     return -1;
 
@@ -472,12 +471,53 @@ unpack_instr (instr_data_s *instr_data, int is_segmented, disassemble_info *info
     }
 }
 
-static char *intr_names[] = {
-  "all",    /* 0 */
-  "vi",     /* 1 */
-  "nvi",    /* 2 */
-  "none"    /* 3 */
-};
+static void
+print_intr(char *tmp_str, unsigned long interrupts)
+{
+  int comma = 0;
+
+  *tmp_str = 0;
+  if (! (interrupts & 2))
+    {
+      strcat (tmp_str, "vi");
+      comma = 1;
+    }
+  if (! (interrupts & 1))
+    {
+      if (comma) strcat (tmp_str, ",");
+      strcat (tmp_str, "nvi");
+    }
+}
+
+static void
+print_flags(char *tmp_str, unsigned long flags)
+{
+  int comma = 0;
+
+  *tmp_str = 0;
+  if (flags & 8)
+    {
+      strcat (tmp_str, "c");
+      comma = 1;
+    }
+  if (flags & 4)
+    {
+      if (comma) strcat (tmp_str, ",");
+      strcat (tmp_str, "z");
+      comma = 1;
+    }
+  if (flags & 2)
+    {
+      if (comma) strcat (tmp_str, ",");
+      strcat (tmp_str, "s");
+      comma = 1;
+    }
+  if (flags & 1)
+    {
+      if (comma) strcat (tmp_str, ",");
+      strcat (tmp_str, "p");
+    }
+}
 
 static void
 unparse_instr (instr_data_s *instr_data, int is_segmented)
@@ -529,12 +569,12 @@ unparse_instr (instr_data_s *instr_data, int is_segmented)
          strcat (out_str, tmp_str);
          break;
        case CLASS_IMM:
-          if (datum_value == ARG_IMM2)  /* True with EI/DI instructions only.  */
-            {
-              sprintf (tmp_str, "%s", intr_names[instr_data->interrupts]);
-              strcat (out_str, tmp_str);
-              break;
-            }
+         if (datum_value == ARG_IMM2)  /* True with EI/DI instructions only.  */
+           {
+             print_intr (tmp_str, instr_data->interrupts);
+             strcat (out_str, tmp_str);
+             break;
+           }
          sprintf (tmp_str, "#0x%0lx", instr_data->immediate);
          strcat (out_str, tmp_str);
          break;
@@ -563,7 +603,7 @@ unparse_instr (instr_data_s *instr_data, int is_segmented)
          strcat (out_str, tmp_str);
          break;
        case CLASS_FLAGS:
-         sprintf (tmp_str, "0x%0lx", instr_data->flags);
+         print_flags(tmp_str, instr_data->flags);
          strcat (out_str, tmp_str);
          break;
        case CLASS_REG_BYTE:
This page took 0.027849 seconds and 4 git commands to generate.