* breakpoint.c (read_memory_nobpt): Use ALL_BP_LOCATIONS
[deliverable/binutils-gdb.git] / opcodes / ppc-dis.c
index bd4dfaca6deeb785742823d77888509b904e6301..76af4e7af1240ce920f40be426a614ff00deae1d 100644 (file)
@@ -1,5 +1,6 @@
 /* ppc-dis.c -- Disassemble PowerPC instructions
-   Copyright 1994, 1995, 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright 1994, 1995, 2000, 2001, 2002, 2003
+   Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support
 
 This file is part of GDB, GAS, and the GNU binutils.
@@ -29,18 +30,19 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  *
    in both big and little endian mode and also for the POWER (RS/6000)
    chip.  */
 
-static int print_insn_powerpc PARAMS ((bfd_vma, struct disassemble_info *,
-                                      int bigendian, int dialect));
+static int print_insn_powerpc (bfd_vma, struct disassemble_info *, int, int);
 
-static int powerpc_dialect PARAMS ((struct disassemble_info *));
+struct dis_private {
+  /* Stash the result of parsing disassembler_options here.  */
+  int dialect;
+};
 
 /* Determine which set of machines to disassemble for.  PPC403/601 or
    BookE.  For convenience, also disassemble instructions supported
    by the AltiVec vector unit.  */
 
-int
-powerpc_dialect(info)
-     struct disassemble_info *info;
+static int
+powerpc_dialect (struct disassemble_info *info)
 {
   int dialect = PPC_OPCODE_PPC | PPC_OPCODE_ALTIVEC;
 
@@ -48,39 +50,39 @@ powerpc_dialect(info)
     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))
+      && strstr (info->disassembler_options, "booke") != NULL)
     dialect |= PPC_OPCODE_BOOKE | PPC_OPCODE_BOOKE64;
-  else 
-    if ((info->mach == bfd_mach_ppc_e500)
-        || (info->disassembler_options
-       && (   strcmp (info->disassembler_options, "e500") == 0
-           || strcmp (info->disassembler_options, "e500x2") == 0)))
-      {
-        dialect |= PPC_OPCODE_BOOKE
-         | PPC_OPCODE_SPE | PPC_OPCODE_ISEL
-         | PPC_OPCODE_EFS | PPC_OPCODE_BRLOCK
-         | PPC_OPCODE_PMR | PPC_OPCODE_CACHELCK
-         | PPC_OPCODE_RFMCI;
-       /* efs* and AltiVec conflict.  */
-       dialect &= ~PPC_OPCODE_ALTIVEC;
-      }
-  else 
-    if (info->disassembler_options
-       && (strcmp (info->disassembler_options, "efs") == 0))
-      {
-       dialect |= PPC_OPCODE_EFS;
-       /* efs* and AltiVec conflict.  */
-       dialect &= ~PPC_OPCODE_ALTIVEC;
-      }
+  else if ((info->mach == bfd_mach_ppc_e500)
+          || (info->disassembler_options
+              && strstr (info->disassembler_options, "e500") != NULL))
+    {
+      dialect |= PPC_OPCODE_BOOKE
+       | PPC_OPCODE_SPE | PPC_OPCODE_ISEL
+       | PPC_OPCODE_EFS | PPC_OPCODE_BRLOCK
+       | PPC_OPCODE_PMR | PPC_OPCODE_CACHELCK
+       | PPC_OPCODE_RFMCI;
+      /* efs* and AltiVec conflict.  */
+      dialect &= ~PPC_OPCODE_ALTIVEC;
+    }
+  else if (info->disassembler_options
+          && strstr (info->disassembler_options, "efs") != NULL)
+    {
+      dialect |= PPC_OPCODE_EFS;
+      /* efs* and AltiVec conflict.  */
+      dialect &= ~PPC_OPCODE_ALTIVEC;
+    }
   else
-    dialect |= PPC_OPCODE_403 | PPC_OPCODE_601 | PPC_OPCODE_COMMON;
+    dialect |= (PPC_OPCODE_403 | PPC_OPCODE_601 | PPC_OPCODE_CLASSIC
+               | PPC_OPCODE_COMMON);
 
   if (info->disassembler_options
-      && strcmp (info->disassembler_options, "power4") == 0)
+      && strstr (info->disassembler_options, "power4") != NULL)
     dialect |= PPC_OPCODE_POWER4;
 
+  if (info->disassembler_options
+      && strstr (info->disassembler_options, "any") != NULL)
+    dialect |= PPC_OPCODE_ANY;
+
   if (info->disassembler_options)
     {
       if (strstr (info->disassembler_options, "32") != NULL)
@@ -89,35 +91,32 @@ powerpc_dialect(info)
        dialect |= PPC_OPCODE_64;
     }
 
+  ((struct dis_private *) &info->private_data)->dialect = dialect;
   return dialect;
 }
 
 /* Print a big endian PowerPC instruction.  */
 
 int
-print_insn_big_powerpc (memaddr, info)
-     bfd_vma memaddr;
-     struct disassemble_info *info;
+print_insn_big_powerpc (bfd_vma memaddr, struct disassemble_info *info)
 {
-  return print_insn_powerpc (memaddr, info, 1, powerpc_dialect(info));
+  int dialect = ((struct dis_private *) &info->private_data)->dialect;
+  return print_insn_powerpc (memaddr, info, 1, dialect);
 }
 
 /* Print a little endian PowerPC instruction.  */
 
 int
-print_insn_little_powerpc (memaddr, info)
-     bfd_vma memaddr;
-     struct disassemble_info *info;
+print_insn_little_powerpc (bfd_vma memaddr, struct disassemble_info *info)
 {
-  return print_insn_powerpc (memaddr, info, 0, powerpc_dialect(info));
+  int dialect = ((struct dis_private *) &info->private_data)->dialect;
+  return print_insn_powerpc (memaddr, info, 0, dialect);
 }
 
 /* Print a POWER (RS/6000) instruction.  */
 
 int
-print_insn_rs6000 (memaddr, info)
-     bfd_vma memaddr;
-     struct disassemble_info *info;
+print_insn_rs6000 (bfd_vma memaddr, struct disassemble_info *info)
 {
   return print_insn_powerpc (memaddr, info, 1, PPC_OPCODE_POWER);
 }
@@ -125,11 +124,10 @@ print_insn_rs6000 (memaddr, info)
 /* Print a PowerPC or POWER instruction.  */
 
 static int
-print_insn_powerpc (memaddr, info, bigendian, dialect)
-     bfd_vma memaddr;
-     struct disassemble_info *info;
-     int bigendian;
-     int dialect;
+print_insn_powerpc (bfd_vma memaddr,
+                   struct disassemble_info *info,
+                   int bigendian,
+                   int dialect)
 {
   bfd_byte buffer[4];
   int status;
@@ -138,6 +136,9 @@ print_insn_powerpc (memaddr, info, bigendian, dialect)
   const struct powerpc_opcode *opcode_end;
   unsigned long op;
 
+  if (dialect == 0)
+    dialect = powerpc_dialect (info);
+
   status = (*info->read_memory_func) (memaddr, buffer, 4, info);
   if (status != 0)
     {
@@ -156,6 +157,7 @@ print_insn_powerpc (memaddr, info, bigendian, dialect)
   /* Find the first match in the opcode table.  We could speed this up
      a bit by doing a binary search on the major opcode.  */
   opcode_end = powerpc_opcodes + powerpc_num_opcodes;
+ again:
   for (opcode = powerpc_opcodes; opcode < opcode_end; opcode++)
     {
       unsigned long table_op;
@@ -175,9 +177,6 @@ print_insn_powerpc (memaddr, info, bigendian, dialect)
          || (opcode->flags & dialect) == 0)
        continue;
 
-      if ((dialect & PPC_OPCODE_EFS) && (opcode->flags & PPC_OPCODE_ALTIVEC))
-        continue;
-
       /* Make two passes over the operands.  First see if any of them
         have extraction functions, and, if they do, make sure the
         instruction is valid.  */
@@ -213,7 +212,7 @@ print_insn_powerpc (memaddr, info, bigendian, dialect)
 
          /* Extract the value from the instruction.  */
          if (operand->extract)
-           value = (*operand->extract) (insn, dialect, (int *) NULL);
+           value = (*operand->extract) (insn, dialect, &invalid);
          else
            {
              value = (insn >> operand->shift) & ((1 << operand->bits) - 1);
@@ -261,14 +260,9 @@ print_insn_powerpc (memaddr, info, bigendian, dialect)
 
                  cr = value >> 2;
                  if (cr != 0)
-                   (*info->fprintf_func) (info->stream, "4*cr%d", cr);
+                   (*info->fprintf_func) (info->stream, "4*cr%d+", cr);
                  cc = value & 3;
-                 if (cc != 0)
-                   {
-                     if (cr != 0)
-                       (*info->fprintf_func) (info->stream, "+");
-                     (*info->fprintf_func) (info->stream, "%s", cbnames[cc]);
-                   }
+                 (*info->fprintf_func) (info->stream, "%s", cbnames[cc]);
                }
            }
 
@@ -291,8 +285,29 @@ print_insn_powerpc (memaddr, info, bigendian, dialect)
       return 4;
     }
 
+  if ((dialect & PPC_OPCODE_ANY) != 0)
+    {
+      dialect = ~PPC_OPCODE_ANY;
+      goto again;
+    }
+
   /* We could not find a match.  */
   (*info->fprintf_func) (info->stream, ".long 0x%lx", insn);
 
   return 4;
 }
+
+void
+print_ppc_disassembler_options (FILE *stream)
+{
+  fprintf (stream, "\n\
+The following PPC specific disassembler options are supported for use with\n\
+the -M switch:\n");
+
+  fprintf (stream, "  booke|booke32|booke64    Disassemble the BookE instructions\n");
+  fprintf (stream, "  e500|e500x2              Disassemble the e500 instructions\n");
+  fprintf (stream, "  efs                      Disassemble the EFS instructions\n");
+  fprintf (stream, "  power4                   Disassemble the Power4 instructions\n");
+  fprintf (stream, "  32                       Do not disassemble 64-bit instructions\n");
+  fprintf (stream, "  64                       Allow disassembly of 64-bit instructions\n");
+}
This page took 0.025313 seconds and 4 git commands to generate.