[ opcodes/ChangeLog ]
[binutils-gdb.git] / opcodes / ppc-dis.c
index 19b16ef01e0f6c59a76b3bb14209bb89a9b04623..5d654c0b1adc2b8bb56c0a2a763b2a3d21376d97 100644 (file)
@@ -1,5 +1,5 @@
 /* ppc-dis.c -- Disassemble PowerPC instructions
-   Copyright 1994 Free Software Foundation, Inc.
+   Copyright 1994, 1995, 2000 Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support
 
 This file is part of GDB, GAS, and the GNU binutils.
@@ -16,10 +16,9 @@ the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this file; see the file COPYING.  If not, write to the Free
-Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include <stdio.h>
-#include "ansidecl.h"
 #include "sysdep.h"
 #include "dis-asm.h"
 #include "opcode/ppc.h"
@@ -33,6 +32,40 @@ Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 static int print_insn_powerpc PARAMS ((bfd_vma, struct disassemble_info *,
                                       int bigendian, int dialect));
 
+static int powerpc_dialect PARAMS ((struct disassemble_info *));
+
+/* Determine which set of machines to disassemble for.  PPC403/601 or
+   Motorola BookE.  For convenience, also disassemble instructions
+   supported by the AltiVec vector unit.  */
+
+int
+powerpc_dialect(info)
+     struct disassemble_info *info;
+{
+  int dialect = PPC_OPCODE_PPC | PPC_OPCODE_ALTIVEC;
+
+  if (BFD_DEFAULT_TARGET_SIZE == 64)
+    dialect |= PPC_OPCODE_64;
+
+  if (info->disassembler_options
+      && (strcmp (info->disassembler_options, "booke") == 0
+         || strcmp (info->disassembler_options, "booke32") == 0
+         || strcmp (info->disassembler_options, "booke64") == 0))
+    dialect |= PPC_OPCODE_BOOKE | PPC_OPCODE_BOOKE64;
+  else 
+    dialect |= PPC_OPCODE_403 | PPC_OPCODE_601;
+
+  if (info->disassembler_options)
+    {
+      if (strstr (info->disassembler_options, "32") != NULL)
+       dialect &= ~PPC_OPCODE_64;
+      else if (strstr (info->disassembler_options, "64") != NULL)
+       dialect |= PPC_OPCODE_64;
+    }
+
+  return dialect;
+}
+
 /* Print a big endian PowerPC instruction.  */
 
 int
@@ -40,7 +73,7 @@ print_insn_big_powerpc (memaddr, info)
      bfd_vma memaddr;
      struct disassemble_info *info;
 {
-  return print_insn_powerpc (memaddr, info, 1, PPC_OPCODE_PPC);
+  return print_insn_powerpc (memaddr, info, 1, powerpc_dialect(info));
 }
 
 /* Print a little endian PowerPC instruction.  */
@@ -50,7 +83,7 @@ print_insn_little_powerpc (memaddr, info)
      bfd_vma memaddr;
      struct disassemble_info *info;
 {
-  return print_insn_powerpc (memaddr, info, 0, PPC_OPCODE_PPC);
+  return print_insn_powerpc (memaddr, info, 0, powerpc_dialect(info));
 }
 
 /* Print a POWER (RS/6000) instruction.  */
@@ -124,7 +157,7 @@ print_insn_powerpc (memaddr, info, bigendian, dialect)
        {
          operand = powerpc_operands + *opindex;
          if (operand->extract)
-           (*operand->extract) (insn, &invalid);
+           (*operand->extract) (insn, dialect, &invalid);
        }
       if (invalid)
        continue;
@@ -151,11 +184,11 @@ print_insn_powerpc (memaddr, info, bigendian, dialect)
 
          /* Extract the value from the instruction.  */
          if (operand->extract)
-           value = (*operand->extract) (insn, (int *) NULL);
+           value = (*operand->extract) (insn, dialect, (int *) NULL);
          else
            {
              value = (insn >> operand->shift) & ((1 << operand->bits) - 1);
-             if (operand->signedp
+             if ((operand->flags & PPC_OPERAND_SIGNED) != 0
                  && (value & (1 << (operand->bits - 1))) != 0)
                value -= 1 << operand->bits;
            }
@@ -178,6 +211,8 @@ print_insn_powerpc (memaddr, info, bigendian, dialect)
            (*info->fprintf_func) (info->stream, "r%ld", value);
          else if ((operand->flags & PPC_OPERAND_FPR) != 0)
            (*info->fprintf_func) (info->stream, "f%ld", value);
+         else if ((operand->flags & PPC_OPERAND_VR) != 0)
+           (*info->fprintf_func) (info->stream, "v%ld", value);
          else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0)
            (*info->print_address_func) (memaddr + value, info);
          else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
@@ -228,7 +263,7 @@ print_insn_powerpc (memaddr, info, bigendian, dialect)
     }
 
   /* We could not find a match.  */
-  (*info->fprintf_func) (info->stream, "0x%lx", insn);
+  (*info->fprintf_func) (info->stream, ".long 0x%lx", insn);
 
   return 4;
 }