Remove the remaining SSE5 support
[deliverable/binutils-gdb.git] / opcodes / s390-dis.c
index 7c47c94d89299019aef5e8ce5c54df5def368243..813407324e63f24b0571d3510ed0ac19c2ead0ac 100644 (file)
@@ -1,5 +1,5 @@
 /* s390-dis.c -- Disassemble S390 instructions
-   Copyright (C) 2000-2015 Free Software Foundation, Inc.
+   Copyright (C) 2000-2016 Free Software Foundation, Inc.
    Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
 
    This file is part of the GNU opcodes library.
@@ -29,6 +29,7 @@
 static int init_flag = 0;
 static int opc_index[256];
 static int current_arch_mask = 0;
+static int option_use_insn_len_bits_p = 0;
 
 /* Set up index table for first opcode byte.  */
 
@@ -51,6 +52,8 @@ init_disasm (struct disassemble_info *info)
        current_arch_mask = 1 << S390_OPCODE_ESA;
       else if (CONST_STRNEQ (p, "zarch"))
        current_arch_mask = 1 << S390_OPCODE_ZARCH;
+      else if (CONST_STRNEQ (p, "insnlength"))
+       option_use_insn_len_bits_p = 1;
       else
        fprintf (stderr, "Unknown S/390 disassembler option: %s\n", p);
 
@@ -107,6 +110,7 @@ s390_extract_operand (const bfd_byte *insn,
   union operand_value ret;
   unsigned int val;
   int bits;
+  const bfd_byte *orig_insn = insn;
 
   /* Extract fragments of the operand byte for byte.  */
   insn += operand->shift / 8;
@@ -140,6 +144,16 @@ s390_extract_operand (const bfd_byte *insn,
   else if (operand->flags & S390_OPERAND_LENGTH)
     /* Length x in an instruction has real length x + 1.  */
     ret.u = val + 1;
+
+  else if (operand->flags & S390_OPERAND_VR)
+    {
+      /* Extract the extra bits for a vector register operand stored
+        in the RXB field.  */
+      unsigned vr = operand->shift == 32 ? 3
+       : (unsigned) operand->shift / 4 - 2;
+
+      ret.u = val | ((orig_insn[4] & (1 << (3 - vr))) << (vr + 1));
+    }
   else
     ret.u = val;
 
@@ -178,22 +192,45 @@ s390_print_insn_with_opcode (bfd_vma memaddr,
          continue;
        }
 
-      info->fprintf_func (info->stream, "%c", separator);
+      /* For instructions with a last optional operand don't print it
+        if zero.  */
+      if ((opcode->flags & S390_INSTR_FLAG_OPTPARM)
+         && val.u == 0
+         && opindex[1] == 0)
+       break;
 
       if (flags & S390_OPERAND_GPR)
-       info->fprintf_func (info->stream, "%%r%u", val.u);
+       info->fprintf_func (info->stream, "%c%%r%u", separator, val.u);
       else if (flags & S390_OPERAND_FPR)
-       info->fprintf_func (info->stream, "%%f%u", val.u);
+       info->fprintf_func (info->stream, "%c%%f%u", separator, val.u);
+      else if (flags & S390_OPERAND_VR)
+       info->fprintf_func (info->stream, "%c%%v%i", separator, val.u);
       else if (flags & S390_OPERAND_AR)
-       info->fprintf_func (info->stream, "%%a%u", val.u);
+       info->fprintf_func (info->stream, "%c%%a%u", separator, val.u);
       else if (flags & S390_OPERAND_CR)
-       info->fprintf_func (info->stream, "%%c%u", val.u);
+       info->fprintf_func (info->stream, "%c%%c%u", separator, val.u);
       else if (flags & S390_OPERAND_PCREL)
-       info->print_address_func (memaddr + val.i + val.i, info);
+       {
+         info->fprintf_func (info->stream, "%c", separator);
+         info->print_address_func (memaddr + val.i + val.i, info);
+       }
       else if (flags & S390_OPERAND_SIGNED)
-       info->fprintf_func (info->stream, "%i", val.i);
+       info->fprintf_func (info->stream, "%c%i", separator, val.i);
       else
-       info->fprintf_func (info->stream, "%u", val.u);
+       {
+         if (flags & S390_OPERAND_OR1)
+           val.u &= ~1;
+         if (flags & S390_OPERAND_OR2)
+           val.u &= ~2;
+         if (flags & S390_OPERAND_OR8)
+           val.u &= ~8;
+
+         if ((opcode->flags & S390_INSTR_FLAG_OPTPARM)
+             && val.u == 0
+             && opindex[1] == 0)
+           break;
+         info->fprintf_func (info->stream, "%c%u", separator, val.u);
+       }
 
       if (flags & S390_OPERAND_DISP)
        separator = '(';
@@ -227,7 +264,7 @@ print_insn_s390 (bfd_vma memaddr, struct disassemble_info *info)
   bfd_byte buffer[6];
   const struct s390_opcode *opcode = NULL;
   unsigned int value;
-  int status, opsize, bufsize;
+  int status, opsize, bufsize, bytes_to_dump, i;
 
   if (init_flag == 0)
     init_disasm (info);
@@ -273,38 +310,54 @@ print_insn_s390 (bfd_vma memaddr, struct disassemble_info *info)
                  || opcode_mask_more_specific (op, opcode)))
            opcode = op;
        }
-    }
 
-  if (opcode != NULL)
-    {
-      /* The instruction is valid.  Print it and return its size.  */
-      s390_print_insn_with_opcode (memaddr, info, buffer, opcode);
-      return opsize;
+      if (opcode != NULL)
+       {
+         /* The instruction is valid.  Print it and return its size.  */
+         s390_print_insn_with_opcode (memaddr, info, buffer, opcode);
+         return opsize;
+       }
     }
 
+  /* For code sections it makes sense to skip unknown instructions
+     according to their length bits.  */
+  if (status == 0
+      && option_use_insn_len_bits_p
+      && info->section != NULL
+      && (info->section->flags & SEC_CODE))
+    bytes_to_dump = opsize;
+  else
+    /* By default unknown instructions are printed as .long's/.short'
+       depending on how many bytes are available.  */
+    bytes_to_dump = bufsize >= 4 ? 4 : bufsize;
+
+  if (bytes_to_dump == 0)
+    return 0;
+
   /* Fall back to hex print.  */
-  if (bufsize >= 4)
+  switch (bytes_to_dump)
     {
+    case 4:
       value = (unsigned int) buffer[0];
       value = (value << 8) + (unsigned int) buffer[1];
       value = (value << 8) + (unsigned int) buffer[2];
       value = (value << 8) + (unsigned int) buffer[3];
       info->fprintf_func (info->stream, ".long\t0x%08x", value);
       return 4;
-    }
-  else if (bufsize >= 2)
-    {
+    case 2:
       value = (unsigned int) buffer[0];
       value = (value << 8) + (unsigned int) buffer[1];
       info->fprintf_func (info->stream, ".short\t0x%04x", value);
       return 2;
+    default:
+      info->fprintf_func (info->stream, ".byte\t0x%02x",
+                         (unsigned int) buffer[0]);
+      for (i = 1; i < bytes_to_dump; i++)
+       info->fprintf_func (info->stream, ",0x%02x",
+                         (unsigned int) buffer[i]);
+      return bytes_to_dump;
     }
-  else
-    {
-      value = (unsigned int) buffer[0];
-      info->fprintf_func (info->stream, ".byte\t0x%02x", value);
-      return 1;
-    }
+  return 0;
 }
 
 void
@@ -316,4 +369,6 @@ with the -M switch (multiple options should be separated by commas):\n"));
 
   fprintf (stream, _("  esa         Disassemble in ESA architecture mode\n"));
   fprintf (stream, _("  zarch       Disassemble in z/Architecture mode\n"));
+  fprintf (stream, _("  insnlength  Print unknown instructions according "
+                    "to length from first two bits\n"));
 }
This page took 0.025318 seconds and 4 git commands to generate.