PR 10288
[deliverable/binutils-gdb.git] / opcodes / arm-dis.c
index aedc9f2278f5d9ec6c4ace503f188d219d4880a2..bee845493226ff571e885ea706ce2a837b5d3b86 100644 (file)
@@ -1,6 +1,6 @@
 /* Instruction printing code for the ARM
-   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
-   2007, Free Software Foundation, Inc.
+   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
+   2004, 2007, 2009  Free Software Foundation, Inc.
    Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
    Modification by James G. Smith (jsmith@cygnus.co.uk)
 
@@ -48,8 +48,9 @@
 struct opcode32
 {
   unsigned long arch;          /* Architecture defining this insn.  */
-  unsigned long value, mask;   /* Recognise insn if (op&mask)==value.  */
-  const char *assembler;       /* How to disassemble this insn.  */
+  unsigned long value;         /* Recognise insn if (op & mask) == value.  */
+  unsigned long mask;          /* If arch == 0 then value is a sentinel.  */
+  const char *  assembler;     /* How to disassemble this insn.  */
 };
 
 struct opcode16
@@ -106,6 +107,15 @@ struct opcode16
    %r                  print register offset address for wldt/wstr instruction
 */
 
+enum
+{
+  SENTINEL_IWMMXT_START = 1,
+  SENTINEL_IWMMXT_END,
+  SENTINEL_GENERIC_START
+} opcode_sentinels;
+
+#define UNDEFINED_INSTRUCTION "undefined instruction %0-31x"
+
 /* Common coprocessor opcodes shared between Arm and Thumb-2.  */
 
 static const struct opcode32 coprocessor_opcodes[] =
@@ -116,10 +126,9 @@ static const struct opcode32 coprocessor_opcodes[] =
   {ARM_CEXT_XSCALE, 0x0e2c0010, 0x0ffc0ff0, "mia%17'T%17`B%16'T%16`B%c\tacc0, %0-3r, %12-15r"},
   {ARM_CEXT_XSCALE, 0x0c400000, 0x0ff00fff, "mar%c\tacc0, %12-15r, %16-19r"},
   {ARM_CEXT_XSCALE, 0x0c500000, 0x0ff00fff, "mra%c\t%12-15r, %16-19r, acc0"},
-    
+
   /* Intel Wireless MMX technology instructions.  */
-#define FIRST_IWMMXT_INSN 0x0e130130
-#define IWMMXT_INSN_COUNT 73
+  { 0, SENTINEL_IWMMXT_START, 0, "" },
   {ARM_CEXT_IWMMXT, 0x0e130130, 0x0f3f0fff, "tandc%22-23w%c\t%12-15r"},
   {ARM_CEXT_XSCALE, 0x0e400010, 0x0ff00f3f, "tbcst%6-7w%c\t%16-19g, %12-15r"},
   {ARM_CEXT_XSCALE, 0x0e130170, 0x0f3f0ff8, "textrc%22-23w%c\t%12-15r, #%0-2d"},
@@ -195,6 +204,7 @@ static const struct opcode32 coprocessor_opcodes[] =
   {ARM_CEXT_XSCALE, 0x0e1000c0, 0x0f300ff0, "wunpckih%22-23w%c\t%12-15g, %16-19g, %0-3g"},
   {ARM_CEXT_XSCALE, 0x0e1000e0, 0x0f300ff0, "wunpckil%22-23w%c\t%12-15g, %16-19g, %0-3g"},
   {ARM_CEXT_XSCALE, 0x0e100000, 0x0ff00ff0, "wxor%c\t%12-15g, %16-19g, %0-3g"},
+  { 0, SENTINEL_IWMMXT_END, 0, "" },
 
   /* Floating point coprocessor (FPA) instructions */
   {FPU_FPA_EXT_V1, 0x0e000100, 0x0ff08f10, "adf%c%P%R\t%12-14f, %16-18f, %0-3f"},
@@ -438,20 +448,21 @@ static const struct opcode32 coprocessor_opcodes[] =
   {ARM_CEXT_MAVERICK, 0x0e200600, 0x0ff00f10, "cfmadda32%c\tmvax%5-7d, mvax%12-15d, mvfx%16-19d, mvfx%0-3d"},
   {ARM_CEXT_MAVERICK, 0x0e300600, 0x0ff00f10, "cfmsuba32%c\tmvax%5-7d, mvax%12-15d, mvfx%16-19d, mvfx%0-3d"},
 
-  /* Generic coprocessor instructions */
-  {ARM_EXT_V2, 0x0c400000, 0x0ff00000, "mcrr%c\t%8-11d, %4-7d, %12-15r, %16-19r, cr%0-3d"},
-  {ARM_EXT_V2, 0x0c500000, 0x0ff00000, "mrrc%c\t%8-11d, %4-7d, %12-15r, %16-19r, cr%0-3d"},
+  /* Generic coprocessor instructions.  */
+  { 0, SENTINEL_GENERIC_START, 0, "" },
+  {ARM_EXT_V5E, 0x0c400000, 0x0ff00000, "mcrr%c\t%8-11d, %4-7d, %12-15r, %16-19r, cr%0-3d"},
+  {ARM_EXT_V5E, 0x0c500000, 0x0ff00000, "mrrc%c\t%8-11d, %4-7d, %12-15r, %16-19r, cr%0-3d"},
   {ARM_EXT_V2, 0x0e000000, 0x0f000010, "cdp%c\t%8-11d, %20-23d, cr%12-15d, cr%16-19d, cr%0-3d, {%5-7d}"},
   {ARM_EXT_V2, 0x0e100010, 0x0f100010, "mrc%c\t%8-11d, %21-23d, %12-15r, cr%16-19d, cr%0-3d, {%5-7d}"},
   {ARM_EXT_V2, 0x0e000010, 0x0f100010, "mcr%c\t%8-11d, %21-23d, %12-15r, cr%16-19d, cr%0-3d, {%5-7d}"},
   {ARM_EXT_V2, 0x0c000000, 0x0e100000, "stc%22'l%c\t%8-11d, cr%12-15d, %A"},
   {ARM_EXT_V2, 0x0c100000, 0x0e100000, "ldc%22'l%c\t%8-11d, cr%12-15d, %A"},
 
-  /* V6 coprocessor instructions */
+  /* V6 coprocessor instructions */
   {ARM_EXT_V6, 0xfc500000, 0xfff00000, "mrrc2%c\t%8-11d, %4-7d, %12-15r, %16-19r, cr%0-3d"},
   {ARM_EXT_V6, 0xfc400000, 0xfff00000, "mcrr2%c\t%8-11d, %4-7d, %12-15r, %16-19r, cr%0-3d"},
 
-  /* V5 coprocessor instructions */
+  /* V5 coprocessor instructions */
   {ARM_EXT_V5, 0xfc100000, 0xfe100000, "ldc2%22'l%c\t%8-11d, cr%12-15d, %A"},
   {ARM_EXT_V5, 0xfc000000, 0xfe100000, "stc2%22'l%c\t%8-11d, cr%12-15d, %A"},
   {ARM_EXT_V5, 0xfe000000, 0xff000010, "cdp2%c\t%8-11d, %20-23d, cr%12-15d, cr%16-19d, cr%0-3d, {%5-7d}"},
@@ -989,7 +1000,12 @@ static const struct opcode32 arm_opcodes[] =
   {ARM_EXT_V5ExP, 0x01600050, 0x0ff00ff0, "qdsub%c\t%12-15r, %0-3r, %16-19r"},
 
   /* ARM Instructions.  */
-  {ARM_EXT_V1, 0x00000090, 0x0e100090, "str%6's%5?hb%c\t%12-15r, %s"},
+  {ARM_EXT_V1, 0x052d0004, 0x0fff0fff, "push%c\t{%12-15r}\t\t; (str%c %12-15r, %a)"},
+  {ARM_EXT_V1, 0x04000000, 0x0e100000, "str%22'b%t%c\t%12-15r, %a"},
+  {ARM_EXT_V1, 0x06000000, 0x0e100ff0, "str%22'b%t%c\t%12-15r, %a"},
+  {ARM_EXT_V1, 0x04000000, 0x0c100010, "str%22'b%t%c\t%12-15r, %a"},
+  {ARM_EXT_V1, 0x04400000, 0x0c500000, "strb%c\t%12-15r, %a"},
+  {ARM_EXT_V1, 0x000000b0, 0x0e1000f0, "strh%c\t%12-15r, %s"},
   {ARM_EXT_V1, 0x00100090, 0x0e100090, "ldr%6's%5?hb%c\t%12-15r, %s"},
   {ARM_EXT_V1, 0x00000000, 0x0de00000, "and%20's%c\t%12-15r, %16-19r, %o"},
   {ARM_EXT_V1, 0x00200000, 0x0de00000, "eor%20's%c\t%12-15r, %16-19r, %o"},
@@ -1015,11 +1031,7 @@ static const struct opcode32 arm_opcodes[] =
   {ARM_EXT_V1, 0x01a00060, 0x0def0060, "ror%20's%c\t%12-15r, %q"},
   {ARM_EXT_V1, 0x01c00000, 0x0de00000, "bic%20's%c\t%12-15r, %16-19r, %o"},
   {ARM_EXT_V1, 0x01e00000, 0x0de00000, "mvn%20's%c\t%12-15r, %o"},
-  {ARM_EXT_V1, 0x052d0004, 0x0fff0fff, "push%c\t{%12-15r}\t\t; (str%c %12-15r, %a)"},
-  {ARM_EXT_V1, 0x04000000, 0x0e100000, "str%22'b%t%c\t%12-15r, %a"},
-  {ARM_EXT_V1, 0x06000000, 0x0e100ff0, "str%22'b%t%c\t%12-15r, %a"},
-  {ARM_EXT_V1, 0x04000000, 0x0c100010, "str%22'b%t%c\t%12-15r, %a"},
-  {ARM_EXT_V1, 0x06000010, 0x0e000010, "undefined"},
+  {ARM_EXT_V1, 0x06000010, 0x0e000010, UNDEFINED_INSTRUCTION},
   {ARM_EXT_V1, 0x049d0004, 0x0fff0fff, "pop%c\t{%12-15r}\t\t; (ldr%c %12-15r, %a)"},
   {ARM_EXT_V1, 0x04100000, 0x0c100000, "ldr%22'b%t%c\t%12-15r, %a"},
   {ARM_EXT_V1, 0x092d0000, 0x0fff0000, "push%c\t%m"},
@@ -1032,7 +1044,7 @@ static const struct opcode32 arm_opcodes[] =
   {ARM_EXT_V1, 0x0f000000, 0x0f000000, "svc%c\t%0-23x"},
 
   /* The rest.  */
-  {ARM_EXT_V1, 0x00000000, 0x00000000, "undefined instruction %0-31x"},
+  {ARM_EXT_V1, 0x00000000, 0x00000000, UNDEFINED_INSTRUCTION},
   {0, 0x00000000, 0x00000000, 0}
 };
 
@@ -1169,7 +1181,7 @@ static const struct opcode16 thumb_opcodes[] =
   /* format 17 */
   {ARM_EXT_V4T, 0xDF00, 0xFF00, "svc%c\t%0-7d"},
   /* format 16 */
-  {ARM_EXT_V4T, 0xDE00, 0xFE00, "undefined"},
+  {ARM_EXT_V4T, 0xDE00, 0xFE00, UNDEFINED_INSTRUCTION},
   {ARM_EXT_V4T, 0xD000, 0xF000, "b%8-11c.n\t%0-7B%X"},
   /* format 18 */
   {ARM_EXT_V4T, 0xE000, 0xF800, "b%c.n\t%0-10B%x"},
@@ -1178,7 +1190,7 @@ static const struct opcode16 thumb_opcodes[] =
      32-bit table, because even in pre-V6T2 ISAs, BL and BLX(1) pairs
      are processed via that table.  Thus, we can never encounter a
      bare "second half of BL/BLX(1)" instruction here.  */
-  {ARM_EXT_V1,  0x0000, 0x0000, "undefined"},
+  {ARM_EXT_V1,  0x0000, 0x0000, UNDEFINED_INSTRUCTION},
   {0, 0, 0, 0}
 };
 
@@ -1245,7 +1257,7 @@ static const struct opcode32 thumb32_opcodes[] =
   {ARM_EXT_V6T2, 0xf3af8001, 0xffffffff, "yield%c.w"},
   {ARM_EXT_V6T2, 0xf3af8002, 0xffffffff, "wfe%c.w"},
   {ARM_EXT_V6T2, 0xf3af8003, 0xffffffff, "wfi%c.w"},
-  {ARM_EXT_V6T2, 0xf3af9004, 0xffffffff, "sev%c.w"},
+  {ARM_EXT_V6T2, 0xf3af8004, 0xffffffff, "sev%c.w"},
   {ARM_EXT_V6T2, 0xf3af8000, 0xffffff00, "nop%c.w\t{%0-7d}"},
 
   {ARM_EXT_V6T2, 0xf3bf8f2f, 0xffffffff, "clrex%c"},
@@ -1432,7 +1444,7 @@ static const struct opcode32 thumb32_opcodes[] =
   {ARM_EXT_V4T,  0xf000d000, 0xf800d000, "bl%c\t%B%x"},
 
   /* Fallback.  */
-  {ARM_EXT_V1,   0x00000000, 0x00000000, "undefined"},
+  {ARM_EXT_V1,   0x00000000, 0x00000000, UNDEFINED_INSTRUCTION},
   {0, 0, 0, 0}
 };
    
@@ -1631,15 +1643,36 @@ print_insn_coprocessor (bfd_vma pc, struct disassemble_info *info, long given,
   fprintf_ftype func = info->fprintf_func;
   unsigned long mask;
   unsigned long value;
+  unsigned long allowed_arches = ((arm_feature_set *) info->private_data)->coproc;
   int cond;
 
   for (insn = coprocessor_opcodes; insn->assembler; insn++)
     {
-      if (insn->value == FIRST_IWMMXT_INSN
-         && info->mach != bfd_mach_arm_XScale
-         && info->mach != bfd_mach_arm_iWMMXt
-         && info->mach != bfd_mach_arm_iWMMXt2)
-       insn = insn + IWMMXT_INSN_COUNT;
+      signed long value_in_comment = 0;
+      const char *c;
+
+      if (insn->arch == 0)
+       switch (insn->value)
+         {
+         case SENTINEL_IWMMXT_START:
+           if (info->mach != bfd_mach_arm_XScale
+               && info->mach != bfd_mach_arm_iWMMXt
+               && info->mach != bfd_mach_arm_iWMMXt2)
+             do
+               insn++;
+             while (insn->arch != 0 && insn->value != SENTINEL_IWMMXT_END);
+           continue;
+
+         case SENTINEL_IWMMXT_END:
+           continue;
+
+         case SENTINEL_GENERIC_START:
+           allowed_arches = ((arm_feature_set *) info->private_data)->core;
+           continue;
+
+         default:
+           abort ();
+         }
 
       mask = insn->mask;
       value = insn->value;
@@ -1671,461 +1704,483 @@ print_insn_coprocessor (bfd_vma pc, struct disassemble_info *info, long given,
                cond = 16;
            }
        }
-      if ((given & mask) == value)
-       {
-         const char *c;
+      
+      if ((given & mask) != value)
+       continue;
 
-         for (c = insn->assembler; *c; c++)
+      if ((insn->arch & allowed_arches) == 0)
+       continue;
+
+      for (c = insn->assembler; *c; c++)
+       {
+         if (*c == '%')
            {
-             if (*c == '%')
+             switch (*++c)
                {
-                 switch (*++c)
-                   {
-                   case '%':
-                     func (stream, "%%");
-                     break;
-
-                   case 'A':
-                     func (stream, "[%s", arm_regnames [(given >> 16) & 0xf]);
-
-                     if ((given & (1 << 24)) != 0)
-                       {
-                         int offset = given & 0xff;
-
-                         if (offset)
-                           func (stream, ", #%s%d]%s",
-                                 ((given & 0x00800000) == 0 ? "-" : ""),
-                                 offset * 4,
-                                 ((given & 0x00200000) != 0 ? "!" : ""));
-                         else
-                           func (stream, "]");
-                       }
-                     else
-                       {
-                         int offset = given & 0xff;
+               case '%':
+                 func (stream, "%%");
+                 break;
 
-                         func (stream, "]");
+               case 'A':
+                 {
+                   int offset = given & 0xff;
 
-                         if (given & (1 << 21))
-                           {
-                             if (offset)
-                               func (stream, ", #%s%d",
-                                     ((given & 0x00800000) == 0 ? "-" : ""),
-                                     offset * 4);
-                           }
-                         else
-                           func (stream, ", {%d}", offset);
-                       }
-                     break;
+                   func (stream, "[%s", arm_regnames [(given >> 16) & 0xf]);
 
-                   case 'B':
+                   value_in_comment = offset * 4;
+                   if ((given & 0x00800000) == 0)
+                     value_in_comment = - value_in_comment;
+                   
+                   if ((given & (1 << 24)) != 0)
                      {
-                       int regno = ((given >> 12) & 0xf) | ((given >> (22 - 4)) & 0x10);
-                       int offset = (given >> 1) & 0x3f;
-                       
-                       if (offset == 1)
-                         func (stream, "{d%d}", regno);
-                       else if (regno + offset > 32)
-                         func (stream, "{d%d-<overflow reg d%d>}", regno, regno + offset - 1);
+                       if (offset)
+                         func (stream, ", #%s%d]%s",
+                               ((given & 0x00800000) == 0 ? "-" : ""),
+                               offset * 4,
+                               ((given & 0x00200000) != 0 ? "!" : ""));
                        else
-                         func (stream, "{d%d-d%d}", regno, regno + offset - 1);
+                         func (stream, "]");
                      }
-                     break;
-                     
-                   case 'C':
+                   else
                      {
-                       int rn = (given >> 16) & 0xf;
-                       int offset = (given & 0xff) * 4;
-                       int add = (given >> 23) & 1;
-                       
-                       func (stream, "[%s", arm_regnames[rn]);
-                       
-                       if (offset)
-                         {
-                           if (!add)
-                             offset = -offset;
-                           func (stream, ", #%d", offset);
-                         }
                        func (stream, "]");
-                       if (rn == 15)
+
+                       if (given & (1 << 21))
                          {
-                           func (stream, "\t; ");
-                            /* FIXME: Unsure if info->bytes_per_chunk is the
-                               right thing to use here.  */
-                           info->print_address_func (offset + pc
-                              + info->bytes_per_chunk * 2, info);
+                           if (offset)
+                             func (stream, ", #%s%d",
+                                   ((given & 0x00800000) == 0 ? "-" : ""),
+                                   offset * 4);
                          }
+                       else
+                         func (stream, ", {%d}", offset);
                      }
-                     break;
+                 }
+                 break;
 
-                   case 'c':
-                     func (stream, "%s", arm_conditional[cond]);
-                     break;
+               case 'B':
+                 {
+                   int regno = ((given >> 12) & 0xf) | ((given >> (22 - 4)) & 0x10);
+                   int offset = (given >> 1) & 0x3f;
+
+                   if (offset == 1)
+                     func (stream, "{d%d}", regno);
+                   else if (regno + offset > 32)
+                     func (stream, "{d%d-<overflow reg d%d>}", regno, regno + offset - 1);
+                   else
+                     func (stream, "{d%d-d%d}", regno, regno + offset - 1);
+                 }
+                 break;
+
+               case 'C':
+                 {
+                   int rn = (given >> 16) & 0xf;
+                   int offset = (given & 0xff) * 4;
+                   int add = (given >> 23) & 1;
 
-                   case 'I':
-                     /* Print a Cirrus/DSP shift immediate.  */
-                     /* Immediates are 7bit signed ints with bits 0..3 in
-                        bits 0..3 of opcode and bits 4..6 in bits 5..7
-                        of opcode.  */
+                   func (stream, "[%s", arm_regnames[rn]);
+
+                   if (offset)
+                     {
+                       if (!add)
+                         offset = -offset;
+                       func (stream, ", #%d", offset);
+                     }
+                   func (stream, "]");
+                   if (rn == 15)
                      {
-                       int imm;
+                       func (stream, "\t; ");
+                       /* FIXME: Unsure if info->bytes_per_chunk is the
+                          right thing to use here.  */
+                       info->print_address_func (offset + pc
+                                                 + info->bytes_per_chunk * 2, info);
+                     }
+                 }
+                 break;
 
-                       imm = (given & 0xf) | ((given & 0xe0) >> 1);
+               case 'c':
+                 func (stream, "%s", arm_conditional[cond]);
+                 break;
 
-                       /* Is ``imm'' a negative number?  */
-                       if (imm & 0x40)
-                         imm |= (-1 << 7);
+               case 'I':
+                 /* Print a Cirrus/DSP shift immediate.  */
+                 /* Immediates are 7bit signed ints with bits 0..3 in
+                    bits 0..3 of opcode and bits 4..6 in bits 5..7
+                    of opcode.  */
+                 {
+                   int imm;
 
-                       func (stream, "%d", imm);
-                     }
+                   imm = (given & 0xf) | ((given & 0xe0) >> 1);
+
+                   /* Is ``imm'' a negative number?  */
+                   if (imm & 0x40)
+                     imm |= (-1 << 7);
+
+                   func (stream, "%d", imm);
+                 }
 
+                 break;
+
+               case 'F':
+                 switch (given & 0x00408000)
+                   {
+                   case 0:
+                     func (stream, "4");
+                     break;
+                   case 0x8000:
+                     func (stream, "1");
+                     break;
+                   case 0x00400000:
+                     func (stream, "2");
                      break;
+                   default:
+                     func (stream, "3");
+                   }
+                 break;
 
-                   case 'F':
-                     switch (given & 0x00408000)
-                       {
-                       case 0:
-                         func (stream, "4");
-                         break;
-                       case 0x8000:
-                         func (stream, "1");
-                         break;
-                       case 0x00400000:
-                         func (stream, "2");
-                         break;
-                       default:
-                         func (stream, "3");
-                       }
+               case 'P':
+                 switch (given & 0x00080080)
+                   {
+                   case 0:
+                     func (stream, "s");
                      break;
+                   case 0x80:
+                     func (stream, "d");
+                     break;
+                   case 0x00080000:
+                     func (stream, "e");
+                     break;
+                   default:
+                     func (stream, _("<illegal precision>"));
+                     break;
+                   }
+                 break;
 
-                   case 'P':
-                     switch (given & 0x00080080)
-                       {
-                       case 0:
-                         func (stream, "s");
-                         break;
-                       case 0x80:
-                         func (stream, "d");
-                         break;
-                       case 0x00080000:
-                         func (stream, "e");
-                         break;
-                       default:
-                         func (stream, _("<illegal precision>"));
-                         break;
-                       }
+               case 'Q':
+                 switch (given & 0x00408000)
+                   {
+                   case 0:
+                     func (stream, "s");
                      break;
-                   case 'Q':
-                     switch (given & 0x00408000)
-                       {
-                       case 0:
-                         func (stream, "s");
-                         break;
-                       case 0x8000:
-                         func (stream, "d");
-                         break;
-                       case 0x00400000:
-                         func (stream, "e");
-                         break;
-                       default:
-                         func (stream, "p");
-                         break;
-                       }
+                   case 0x8000:
+                     func (stream, "d");
                      break;
-                   case 'R':
-                     switch (given & 0x60)
-                       {
-                       case 0:
-                         break;
-                       case 0x20:
-                         func (stream, "p");
-                         break;
-                       case 0x40:
-                         func (stream, "m");
-                         break;
-                       default:
-                         func (stream, "z");
-                         break;
-                       }
+                   case 0x00400000:
+                     func (stream, "e");
                      break;
+                   default:
+                     func (stream, "p");
+                     break;
+                   }
+                 break;
 
-                   case '0': case '1': case '2': case '3': case '4':
-                   case '5': case '6': case '7': case '8': case '9':
-                     {
-                       int width;
-                       unsigned long value;
+               case 'R':
+                 switch (given & 0x60)
+                   {
+                   case 0:
+                     break;
+                   case 0x20:
+                     func (stream, "p");
+                     break;
+                   case 0x40:
+                     func (stream, "m");
+                     break;
+                   default:
+                     func (stream, "z");
+                     break;
+                   }
+                 break;
 
-                       c = arm_decode_bitfield (c, given, &value, &width);
+               case '0': case '1': case '2': case '3': case '4':
+               case '5': case '6': case '7': case '8': case '9':
+                 {
+                   int width;
+                   unsigned long value;
 
-                       switch (*c)
-                         {
-                         case 'r':
-                           func (stream, "%s", arm_regnames[value]);
-                           break;
-                         case 'D':
-                           func (stream, "d%ld", value);
-                           break;
-                         case 'Q':
-                           if (value & 1)
-                             func (stream, "<illegal reg q%ld.5>", value >> 1);
-                           else
-                             func (stream, "q%ld", value >> 1);
-                           break;
-                         case 'd':
-                           func (stream, "%ld", value);
-                           break;
-                          case 'k':
-                            {
-                              int from = (given & (1 << 7)) ? 32 : 16;
-                              func (stream, "%ld", from - value);
-                            }
-                            break;
-                            
-                         case 'f':
-                           if (value > 7)
-                             func (stream, "#%s", arm_fp_const[value & 7]);
-                           else
-                             func (stream, "f%ld", value);
-                           break;
+                   c = arm_decode_bitfield (c, given, &value, &width);
 
-                         case 'w':
-                           if (width == 2)
-                             func (stream, "%s", iwmmxt_wwnames[value]);
-                           else
-                             func (stream, "%s", iwmmxt_wwssnames[value]);
-                           break;
+                   switch (*c)
+                     {
+                     case 'r':
+                       func (stream, "%s", arm_regnames[value]);
+                       break;
+                     case 'D':
+                       func (stream, "d%ld", value);
+                       break;
+                     case 'Q':
+                       if (value & 1)
+                         func (stream, "<illegal reg q%ld.5>", value >> 1);
+                       else
+                         func (stream, "q%ld", value >> 1);
+                       break;
+                     case 'd':
+                       func (stream, "%ld", value);
+                       value_in_comment = value;
+                       break;
+                     case 'k':
+                       {
+                         int from = (given & (1 << 7)) ? 32 : 16;
+                         func (stream, "%ld", from - value);
+                       }
+                       break;
 
-                         case 'g':
-                           func (stream, "%s", iwmmxt_regnames[value]);
-                           break;
-                         case 'G':
-                           func (stream, "%s", iwmmxt_cregnames[value]);
-                           break;
+                     case 'f':
+                       if (value > 7)
+                         func (stream, "#%s", arm_fp_const[value & 7]);
+                       else
+                         func (stream, "f%ld", value);
+                       break;
 
-                         case 'x':
-                           func (stream, "0x%lx", value);
-                           break;
+                     case 'w':
+                       if (width == 2)
+                         func (stream, "%s", iwmmxt_wwnames[value]);
+                       else
+                         func (stream, "%s", iwmmxt_wwssnames[value]);
+                       break;
 
-                         case '`':
-                           c++;
-                           if (value == 0)
-                             func (stream, "%c", *c);
-                           break;
-                         case '\'':
-                           c++;
-                           if (value == ((1ul << width) - 1))
-                             func (stream, "%c", *c);
-                           break;
-                         case '?':
-                           func (stream, "%c", c[(1 << width) - (int)value]);
-                           c += 1 << width;
-                           break;
-                         default:
-                           abort ();
-                         }
+                     case 'g':
+                       func (stream, "%s", iwmmxt_regnames[value]);
+                       break;
+                     case 'G':
+                       func (stream, "%s", iwmmxt_cregnames[value]);
                        break;
 
-                     case 'y':
-                     case 'z':
-                       {
-                         int single = *c++ == 'y';
-                         int regno;
-                         
-                         switch (*c)
-                           {
-                           case '4': /* Sm pair */
-                           case '0': /* Sm, Dm */
-                             regno = given & 0x0000000f;
-                             if (single)
-                               {
-                                 regno <<= 1;
-                                 regno += (given >> 5) & 1;
-                               }
-                              else
-                                regno += ((given >> 5) & 1) << 4;
-                             break;
+                     case 'x':
+                       func (stream, "0x%lx", value);
+                       break;
 
-                           case '1': /* Sd, Dd */
-                             regno = (given >> 12) & 0x0000000f;
-                             if (single)
-                               {
-                                 regno <<= 1;
-                                 regno += (given >> 22) & 1;
-                               }
-                              else
-                                regno += ((given >> 22) & 1) << 4;
-                             break;
+                     case '`':
+                       c++;
+                       if (value == 0)
+                         func (stream, "%c", *c);
+                       break;
+                     case '\'':
+                       c++;
+                       if (value == ((1ul << width) - 1))
+                         func (stream, "%c", *c);
+                       break;
+                     case '?':
+                       func (stream, "%c", c[(1 << width) - (int)value]);
+                       c += 1 << width;
+                       break;
+                     default:
+                       abort ();
+                     }
+                   break;
 
-                           case '2': /* Sn, Dn */
-                             regno = (given >> 16) & 0x0000000f;
-                             if (single)
-                               {
-                                 regno <<= 1;
-                                 regno += (given >> 7) & 1;
-                               }
-                              else
-                                regno += ((given >> 7) & 1) << 4;
-                             break;
-                             
-                           case '3': /* List */
-                             func (stream, "{");
-                             regno = (given >> 12) & 0x0000000f;
-                             if (single)
-                               {
-                                 regno <<= 1;
-                                 regno += (given >> 22) & 1;
-                               }
-                              else
-                                regno += ((given >> 22) & 1) << 4;
-                             break;
-                             
-                           default:
-                             abort ();
+                 case 'y':
+                 case 'z':
+                   {
+                     int single = *c++ == 'y';
+                     int regno;
+
+                     switch (*c)
+                       {
+                       case '4': /* Sm pair */
+                       case '0': /* Sm, Dm */
+                         regno = given & 0x0000000f;
+                         if (single)
+                           {
+                             regno <<= 1;
+                             regno += (given >> 5) & 1;
                            }
+                         else
+                           regno += ((given >> 5) & 1) << 4;
+                         break;
 
-                         func (stream, "%c%d", single ? 's' : 'd', regno);
+                       case '1': /* Sd, Dd */
+                         regno = (given >> 12) & 0x0000000f;
+                         if (single)
+                           {
+                             regno <<= 1;
+                             regno += (given >> 22) & 1;
+                           }
+                         else
+                           regno += ((given >> 22) & 1) << 4;
+                         break;
 
-                         if (*c == '3')
+                       case '2': /* Sn, Dn */
+                         regno = (given >> 16) & 0x0000000f;
+                         if (single)
                            {
-                             int count = given & 0xff;
-                             
-                             if (single == 0)
-                               count >>= 1;
-                             
-                             if (--count)
-                               {
-                                 func (stream, "-%c%d",
-                                       single ? 's' : 'd',
-                                       regno + count);
-                               }
-                             
-                             func (stream, "}");
+                             regno <<= 1;
+                             regno += (given >> 7) & 1;
                            }
-                         else if (*c == '4')
-                           func (stream, ", %c%d", single ? 's' : 'd',
-                                 regno + 1);
-                       }
-                       break;
+                         else
+                           regno += ((given >> 7) & 1) << 4;
+                         break;
 
-                     case 'L':
-                       switch (given & 0x00400100)
-                         {
-                         case 0x00000000: func (stream, "b"); break;
-                         case 0x00400000: func (stream, "h"); break;
-                         case 0x00000100: func (stream, "w"); break;
-                         case 0x00400100: func (stream, "d"); break;
-                         default:
-                           break;
-                         }
-                       break;
+                       case '3': /* List */
+                         func (stream, "{");
+                         regno = (given >> 12) & 0x0000000f;
+                         if (single)
+                           {
+                             regno <<= 1;
+                             regno += (given >> 22) & 1;
+                           }
+                         else
+                           regno += ((given >> 22) & 1) << 4;
+                         break;
 
-                     case 'Z':
-                       {
-                         int value;
-                         /* given (20, 23) | given (0, 3) */
-                         value = ((given >> 16) & 0xf0) | (given & 0xf);
-                         func (stream, "%d", value);
+                       default:
+                         abort ();
                        }
-                       break;
 
-                     case 'l':
-                       /* This is like the 'A' operator, except that if
-                          the width field "M" is zero, then the offset is
-                          *not* multiplied by four.  */
+                     func (stream, "%c%d", single ? 's' : 'd', regno);
+
+                     if (*c == '3')
                        {
-                         int offset = given & 0xff;
-                         int multiplier = (given & 0x00000100) ? 4 : 1;
+                         int count = given & 0xff;
 
-                         func (stream, "[%s", arm_regnames [(given >> 16) & 0xf]);
+                         if (single == 0)
+                           count >>= 1;
 
-                         if (offset)
+                         if (--count)
                            {
-                             if ((given & 0x01000000) != 0)
-                               func (stream, ", #%s%d]%s",
-                                     ((given & 0x00800000) == 0 ? "-" : ""),
-                                     offset * multiplier,
-                                     ((given & 0x00200000) != 0 ? "!" : ""));
-                             else
-                               func (stream, "], #%s%d",
-                                     ((given & 0x00800000) == 0 ? "-" : ""),
-                                     offset * multiplier);
+                             func (stream, "-%c%d",
+                                   single ? 's' : 'd',
+                                   regno + count);
                            }
-                         else
-                           func (stream, "]");
+
+                         func (stream, "}");
                        }
+                     else if (*c == '4')
+                       func (stream, ", %c%d", single ? 's' : 'd',
+                             regno + 1);
+                   }
+                   break;
+
+                 case 'L':
+                   switch (given & 0x00400100)
+                     {
+                     case 0x00000000: func (stream, "b"); break;
+                     case 0x00400000: func (stream, "h"); break;
+                     case 0x00000100: func (stream, "w"); break;
+                     case 0x00400100: func (stream, "d"); break;
+                     default:
                        break;
+                     }
+                   break;
 
-                     case 'r':
-                       {
-                         int imm4 = (given >> 4) & 0xf;
-                         int puw_bits = ((given >> 22) & 6) | ((given >> 21) & 1);
-                         int ubit = (given >> 23) & 1;
-                         const char *rm = arm_regnames [given & 0xf];
-                         const char *rn = arm_regnames [(given >> 16) & 0xf];
+                 case 'Z':
+                   {
+                     int value;
+                     /* given (20, 23) | given (0, 3) */
+                     value = ((given >> 16) & 0xf0) | (given & 0xf);
+                     func (stream, "%d", value);
+                   }
+                   break;
 
-                         switch (puw_bits)
-                           {
-                           case 1:
-                             /* fall through */
-                           case 3:
-                             func (stream, "[%s], %c%s", rn, ubit ? '+' : '-', rm);
-                             if (imm4)
-                               func (stream, ", lsl #%d", imm4);
-                             break;
-
-                           case 4:
-                             /* fall through */
-                           case 5:
-                             /* fall through */
-                           case 6:
-                             /* fall through */
-                           case 7:
-                             func (stream, "[%s, %c%s", rn, ubit ? '+' : '-', rm);
-                             if (imm4 > 0)
-                               func (stream, ", lsl #%d", imm4);
-                             func (stream, "]");
-                             if (puw_bits == 5 || puw_bits == 7)
-                               func (stream, "!");
-                             break;
+                 case 'l':
+                   /* This is like the 'A' operator, except that if
+                      the width field "M" is zero, then the offset is
+                      *not* multiplied by four.  */
+                   {
+                     int offset = given & 0xff;
+                     int multiplier = (given & 0x00000100) ? 4 : 1;
 
-                           default:
-                             func (stream, "INVALID");
-                           }
+                     func (stream, "[%s", arm_regnames [(given >> 16) & 0xf]);
+
+                     if (multiplier > 1)
+                       {
+                         value_in_comment = offset * multiplier;
+                         if ((given & 0x00800000) == 0)
+                           value_in_comment = - value_in_comment;
                        }
-                       break;
 
-                     case 'i':
+                     if (offset)
                        {
-                         long imm5;
-                         imm5 = ((given & 0x100) >> 4) | (given & 0xf);
-                         func (stream, "%ld", (imm5 == 0) ? 32 : imm5);
+                         if ((given & 0x01000000) != 0)
+                           func (stream, ", #%s%d]%s",
+                                 ((given & 0x00800000) == 0 ? "-" : ""),
+                                 offset * multiplier,
+                                 ((given & 0x00200000) != 0 ? "!" : ""));
+                         else
+                           func (stream, "], #%s%d",
+                                 ((given & 0x00800000) == 0 ? "-" : ""),
+                                 offset * multiplier);
                        }
-                       break;
+                     else
+                       func (stream, "]");
+                   }
+                   break;
 
-                     default:
-                       abort ();
-                     }
+                 case 'r':
+                   {
+                     int imm4 = (given >> 4) & 0xf;
+                     int puw_bits = ((given >> 22) & 6) | ((given >> 21) & 1);
+                     int ubit = (given >> 23) & 1;
+                     const char *rm = arm_regnames [given & 0xf];
+                     const char *rn = arm_regnames [(given >> 16) & 0xf];
+
+                     switch (puw_bits)
+                       {
+                       case 1:
+                       case 3:
+                         func (stream, "[%s], %c%s", rn, ubit ? '+' : '-', rm);
+                         if (imm4)
+                           func (stream, ", lsl #%d", imm4);
+                         break;
+
+                       case 4:
+                       case 5:
+                       case 6:
+                       case 7:
+                         func (stream, "[%s, %c%s", rn, ubit ? '+' : '-', rm);
+                         if (imm4 > 0)
+                           func (stream, ", lsl #%d", imm4);
+                         func (stream, "]");
+                         if (puw_bits == 5 || puw_bits == 7)
+                           func (stream, "!");
+                         break;
+
+                       default:
+                         func (stream, "INVALID");
+                       }
+                   }
+                   break;
+
+                 case 'i':
+                   {
+                     long imm5;
+                     imm5 = ((given & 0x100) >> 4) | (given & 0xf);
+                     func (stream, "%ld", (imm5 == 0) ? 32 : imm5);
                    }
+                   break;
+
+                 default:
+                   abort ();
+                 }
                }
-             else
-               func (stream, "%c", *c);
            }
-         return TRUE;
+         else
+           func (stream, "%c", *c);
        }
+
+      if (value_in_comment > 32 || value_in_comment < -16)
+       func (stream, "\t; 0x%lx", value_in_comment);
+
+      return TRUE;
     }
   return FALSE;
 }
 
-static void
+/* Decodes and prints ARM addressing modes.  Returns the offset
+   used in the address, if any, if it is worthwhile printing the
+   offset as a hexadecimal value in a comment at the end of the
+   line of disassembly.  */
+
+static signed long
 print_arm_address (bfd_vma pc, struct disassemble_info *info, long given)
 {
   void *stream = info->stream;
   fprintf_ftype func = info->fprintf_func;
+  int offset = 0;
 
   if (((given & 0x000f0000) == 0x000f0000)
       && ((given & 0x02000000) == 0))
     {
-      int offset = given & 0xfff;
+      offset = given & 0xfff;
 
       func (stream, "[pc");
 
@@ -2157,6 +2212,7 @@ print_arm_address (bfd_vma pc, struct disassemble_info *info, long given)
 
       func (stream, "\t; ");
       info->print_address_func (offset, info);
+      offset = 0;
     }
   else
     {
@@ -2166,7 +2222,7 @@ print_arm_address (bfd_vma pc, struct disassemble_info *info, long given)
        {
          if ((given & 0x02000000) == 0)
            {
-             int offset = given & 0xfff;
+             offset = given & 0xfff;
              if (offset)
                func (stream, ", #%s%d",
                      (((given & 0x00800000) == 0)
@@ -2187,7 +2243,7 @@ print_arm_address (bfd_vma pc, struct disassemble_info *info, long given)
        {
          if ((given & 0x02000000) == 0)
            {
-             int offset = given & 0xfff;
+             offset = given & 0xfff;
              if (offset)
                func (stream, "], #%s%d",
                      (((given & 0x00800000) == 0)
@@ -2204,6 +2260,8 @@ print_arm_address (bfd_vma pc, struct disassemble_info *info, long given)
            }
        }
     }
+
+  return (signed long) offset;
 }
 
 /* Print one neon instruction on INFO->STREAM.
@@ -2221,7 +2279,7 @@ print_insn_neon (struct disassemble_info *info, long given, bfd_boolean thumb)
     {
       if ((given & 0xef000000) == 0xef000000)
        {
-         /* move bit 28 to bit 24 to translate Thumb2 to ARM encoding.  */
+         /* Move bit 28 to bit 24 to translate Thumb2 to ARM encoding.  */
          unsigned long bit28 = given & (1 << 28);
 
          given &= 0x00ffffff;
@@ -2240,6 +2298,7 @@ print_insn_neon (struct disassemble_info *info, long given, bfd_boolean thumb)
     {
       if ((given & insn->mask) == insn->value)
        {
+         signed long value_in_comment = 0;
          const char *c;
 
          for (c = insn->assembler; *c; c++)
@@ -2587,6 +2646,7 @@ print_insn_neon (struct disassemble_info *info, long given, bfd_boolean thumb)
                            break;
                          case 'd':
                            func (stream, "%ld", value);
+                           value_in_comment = value;
                            break;
                          case 'e':
                            func (stream, "%ld", (1ul << width) - value);
@@ -2595,7 +2655,7 @@ print_insn_neon (struct disassemble_info *info, long given, bfd_boolean thumb)
                          case 'S':
                          case 'T':
                          case 'U':
-                           /* various width encodings */
+                           /* Various width encodings.  */
                            {
                              int base = 8 << (*c - 'S'); /* 8,16 or 32 */
                              int limit;
@@ -2659,6 +2719,10 @@ print_insn_neon (struct disassemble_info *info, long given, bfd_boolean thumb)
              else
                func (stream, "%c", *c);
            }
+
+         if (value_in_comment > 32 || value_in_comment < -16)
+           func (stream, "\t; 0x%lx", value_in_comment);
+
          return TRUE;
        }
     }
@@ -2682,19 +2746,20 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info, long given)
 
   for (insn = arm_opcodes; insn->assembler; insn++)
     {
-      if (insn->value == FIRST_IWMMXT_INSN
-         && info->mach != bfd_mach_arm_XScale
-         && info->mach != bfd_mach_arm_iWMMXt)
-       insn = insn + IWMMXT_INSN_COUNT;
-
-      if ((given & insn->mask) == insn->value
-         /* Special case: an instruction with all bits set in the condition field
-            (0xFnnn_nnnn) is only matched if all those bits are set in insn->mask,
-            or by the catchall at the end of the table.  */
-         && ((given & 0xF0000000) != 0xF0000000
-             || (insn->mask & 0xF0000000) == 0xF0000000
-             || (insn->mask == 0 && insn->value == 0)))
+      if ((given & insn->mask) != insn->value)
+       continue;
+    
+      if ((insn->arch & ((arm_feature_set *) info->private_data)->core) == 0)
+       continue;
+
+      /* Special case: an instruction with all bits set in the condition field
+        (0xFnnn_nnnn) is only matched if all those bits are set in insn->mask,
+        or by the catchall at the end of the table.  */
+      if ((given & 0xF0000000) != 0xF0000000
+         || (insn->mask & 0xF0000000) == 0xF0000000
+         || (insn->mask == 0 && insn->value == 0))
        {
+         signed long value_in_comment = 0;
          const char *c;
 
          for (c = insn->assembler; *c; c++)
@@ -2708,13 +2773,13 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info, long given)
                      break;
 
                    case 'a':
-                     print_arm_address (pc, info, given);
+                     value_in_comment = print_arm_address (pc, info, given);
                      break;
 
                    case 'P':
                      /* Set P address bit and use normal address
                         printing routine.  */
-                     print_arm_address (pc, info, given | (1 << 24));
+                     value_in_comment = print_arm_address (pc, info, given | (1 << 24));
                      break;
 
                    case 's':
@@ -2740,6 +2805,7 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info, long given)
                                {
                                   /* Immediate.  */
                                   int offset = ((given & 0xf00) >> 4) | (given & 0xf);
+
                                  if (offset)
                                    func (stream, ", #%s%d",
                                          (((given & 0x00800000) == 0)
@@ -2764,6 +2830,7 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info, long given)
                                {
                                   /* Immediate.  */
                                   int offset = ((given & 0xf00) >> 4) | (given & 0xf);
+
                                  if (offset)
                                    func (stream, "], #%s%d",
                                          (((given & 0x00800000) == 0)
@@ -2786,7 +2853,7 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info, long given)
                    case 'b':
                      {
                        int disp = (((given & 0xffffff) ^ 0x800000) - 0x800000);
-                       info->print_address_func (disp*4 + pc + 8, info);
+                       info->print_address_func (disp * 4 + pc + 8, info);
                      }
                      break;
 
@@ -2842,36 +2909,40 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info, long given)
                      break;
 
                    case 'A':
-                     func (stream, "[%s", arm_regnames [(given >> 16) & 0xf]);
+                     {
+                       int offset = given & 0xff;
 
-                     if ((given & (1 << 24)) != 0)
-                       {
-                         int offset = given & 0xff;
+                       value_in_comment = offset * 4;
+                       if ((given & 0x00800000) == 0)
+                         value_in_comment = - value_in_comment;
 
-                         if (offset)
-                           func (stream, ", #%s%d]%s",
-                                 ((given & 0x00800000) == 0 ? "-" : ""),
-                                 offset * 4,
-                                 ((given & 0x00200000) != 0 ? "!" : ""));
-                         else
-                           func (stream, "]");
-                       }
-                     else
-                       {
-                         int offset = given & 0xff;
+                       func (stream, "[%s", arm_regnames [(given >> 16) & 0xf]);
 
-                         func (stream, "]");
+                       if ((given & (1 << 24)) != 0)
+                         {
+                           if (offset)
+                             func (stream, ", #%s%d]%s",
+                                   ((given & 0x00800000) == 0 ? "-" : ""),
+                                   offset * 4,
+                                   ((given & 0x00200000) != 0 ? "!" : ""));
+                           else
+                             func (stream, "]");
+                         }
+                       else
+                         {
+                           func (stream, "]");
 
-                         if (given & (1 << 21))
-                           {
-                             if (offset)
-                               func (stream, ", #%s%d",
-                                     ((given & 0x00800000) == 0 ? "-" : ""),
-                                     offset * 4);
-                           }
-                         else
-                           func (stream, ", {%d}", offset);
-                       }
+                           if (given & (1 << 21))
+                             {
+                               if (offset)
+                                 func (stream, ", #%s%d",
+                                       ((given & 0x00800000) == 0 ? "-" : ""),
+                                       offset * 4);
+                             }
+                           else
+                             func (stream, ", {%d}", offset);
+                         }
+                     }
                      break;
 
                    case 'B':
@@ -2937,12 +3008,15 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info, long given)
                            break;
                          case 'd':
                            func (stream, "%ld", value);
+                           value_in_comment = value;
                            break;
                          case 'b':
                            func (stream, "%ld", value * 8);
+                           value_in_comment = value * 8;
                            break;
                          case 'W':
                            func (stream, "%ld", value + 1);
+                           value_in_comment = value + 1;
                            break;
                          case 'x':
                            func (stream, "0x%08lx", value);
@@ -2956,6 +3030,7 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info, long given)
                            break;
                          case 'X':
                            func (stream, "%01lx", value & 0xf);
+                           value_in_comment = value;
                            break;
                          case '`':
                            c++;
@@ -3019,6 +3094,9 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info, long given)
              else
                func (stream, "%c", *c);
            }
+
+         if (value_in_comment > 32 || value_in_comment < -16)
+           func (stream, "\t; 0x%lx", value_in_comment);
          return;
        }
     }
@@ -3037,7 +3115,9 @@ print_insn_thumb16 (bfd_vma pc, struct disassemble_info *info, long given)
   for (insn = thumb_opcodes; insn->assembler; insn++)
     if ((given & insn->mask) == insn->value)
       {
+       signed long value_in_comment = 0;
        const char *c = insn->assembler;
+
        for (; *c; c++)
          {
            int domaskpc = 0;
@@ -3209,14 +3289,17 @@ print_insn_thumb16 (bfd_vma pc, struct disassemble_info *info, long given)
 
                          case 'd':
                            func (stream, "%ld", reg);
+                           value_in_comment = reg;
                            break;
 
                          case 'H':
                            func (stream, "%ld", reg << 1);
+                           value_in_comment = reg << 1;
                            break;
 
                          case 'W':
                            func (stream, "%ld", reg << 2);
+                           value_in_comment = reg << 2;
                            break;
 
                          case 'a':
@@ -3225,6 +3308,7 @@ print_insn_thumb16 (bfd_vma pc, struct disassemble_info *info, long given)
                               before the calculation.  */
                            info->print_address_func
                              (((pc + 4) & ~3) + (reg << 2), info);
+                           value_in_comment = 0;
                            break;
 
                          case 'x':
@@ -3234,6 +3318,7 @@ print_insn_thumb16 (bfd_vma pc, struct disassemble_info *info, long given)
                          case 'B':
                            reg = ((reg ^ (1 << bitend)) - (1 << bitend));
                            info->print_address_func (reg * 2 + pc + 4, info);
+                           value_in_comment = 0;
                            break;
 
                          case 'c':
@@ -3270,6 +3355,9 @@ print_insn_thumb16 (bfd_vma pc, struct disassemble_info *info, long given)
                abort ();
              }
          }
+
+       if (value_in_comment > 32 || value_in_comment < -16)
+         func (stream, "\t; 0x%lx", value_in_comment);
        return;
       }
 
@@ -3319,7 +3407,9 @@ print_insn_thumb32 (bfd_vma pc, struct disassemble_info *info, long given)
   for (insn = thumb32_opcodes; insn->assembler; insn++)
     if ((given & insn->mask) == insn->value)
       {
+       signed long value_in_comment = 0;
        const char *c = insn->assembler;
+
        for (; *c; c++)
          {
            if (*c != '%')
@@ -3452,14 +3542,19 @@ print_insn_thumb32 (bfd_vma pc, struct disassemble_info *info, long given)
                  int offset = 0;
 
                  func (stream, "[%s", arm_regnames[Rn]);
-                 if (U) /* 12-bit positive immediate offset */
-                   offset = i12;
-                 else if (Rn == 15) /* 12-bit negative immediate offset */
-                   offset = -(int)i12;
-                 else if (op == 0x0) /* shifted register offset */
+                 if (U) /* 12-bit positive immediate offset.  */
+                   {
+                     offset = i12;
+                     if (Rn != 15)
+                       value_in_comment = offset;
+                   }
+                 else if (Rn == 15) /* 12-bit negative immediate offset.  */
+                   offset = - (int) i12;
+                 else if (op == 0x0) /* Shifted register offset.  */
                    {
                      unsigned int Rm = (i8 & 0x0f);
                      unsigned int sh = (i8 & 0x30) >> 4;
+
                      func (stream, ", %s", arm_regnames[Rm]);
                      if (sh)
                        func (stream, ", lsl #%u", sh);
@@ -3468,30 +3563,30 @@ print_insn_thumb32 (bfd_vma pc, struct disassemble_info *info, long given)
                    }
                  else switch (op)
                    {
-                   case 0xE:  /* 8-bit positive immediate offset */
+                   case 0xE:  /* 8-bit positive immediate offset */
                      offset = i8;
                      break;
 
-                   case 0xC:  /* 8-bit negative immediate offset */
+                   case 0xC:  /* 8-bit negative immediate offset */
                      offset = -i8;
                      break;
 
-                   case 0xF:  /* 8-bit + preindex with wb */
+                   case 0xF:  /* 8-bit + preindex with wb */
                      offset = i8;
                      writeback = TRUE;
                      break;
 
-                   case 0xD:  /* 8-bit - preindex with wb */
+                   case 0xD:  /* 8-bit - preindex with wb */
                      offset = -i8;
                      writeback = TRUE;
                      break;
 
-                   case 0xB:  /* 8-bit + postindex */
+                   case 0xB:  /* 8-bit + postindex */
                      offset = i8;
                      postind = TRUE;
                      break;
 
-                   case 0x9:  /* 8-bit - postindex */
+                   case 0x9:  /* 8-bit - postindex */
                      offset = -i8;
                      postind = TRUE;
                      break;
@@ -3531,7 +3626,10 @@ print_insn_thumb32 (bfd_vma pc, struct disassemble_info *info, long given)
                  if (P)
                    {
                      if (off || !U)
-                       func (stream, ", #%c%u", U ? '+' : '-', off * 4);
+                       {
+                         func (stream, ", #%c%u", U ? '+' : '-', off * 4);
+                         value_in_comment = off * 4 * U ? 1 : -1;
+                       }
                      func (stream, "]");
                      if (W)
                        func (stream, "!");
@@ -3540,7 +3638,10 @@ print_insn_thumb32 (bfd_vma pc, struct disassemble_info *info, long given)
                    {
                      func (stream, "], ");
                      if (W)
-                       func (stream, "#%c%u", U ? '+' : '-', off * 4);
+                       {
+                         func (stream, "#%c%u", U ? '+' : '-', off * 4);
+                         value_in_comment = off * 4 * U ? 1 : -1;
+                       }
                      else
                        func (stream, "{%u}", off);
                    }
@@ -3551,6 +3652,7 @@ print_insn_thumb32 (bfd_vma pc, struct disassemble_info *info, long given)
                {
                  unsigned int Sbit = (given & 0x01000000) >> 24;
                  unsigned int type = (given & 0x00600000) >> 21;
+
                  switch (type)
                    {
                    case 0: func (stream, Sbit ? "sb" : "b"); break;
@@ -3715,8 +3817,14 @@ print_insn_thumb32 (bfd_vma pc, struct disassemble_info *info, long given)
                        
                  switch (*c)
                    {
-                   case 'd': func (stream, "%lu", val); break;
-                   case 'W': func (stream, "%lu", val * 4); break;
+                   case 'd':
+                     func (stream, "%lu", val);
+                     value_in_comment = val;
+                     break;
+                   case 'W':
+                     func (stream, "%lu", val * 4);
+                     value_in_comment = val * 4;
+                     break;
                    case 'r': func (stream, "%s", arm_regnames[val]); break;
 
                    case 'c':
@@ -3750,6 +3858,9 @@ print_insn_thumb32 (bfd_vma pc, struct disassemble_info *info, long given)
                abort ();
              }
          }
+
+       if (value_in_comment > 32 || value_in_comment < -16)
+         func (stream, "\t; 0x%lx", value_in_comment);
        return;
       }
 
@@ -3967,6 +4078,47 @@ get_sym_code_type (struct disassemble_info *info, int n,
   return FALSE;
 }
 
+/* Given a bfd_mach_arm_XXX value, this function fills in the fields
+   of the supplied arm_feature_set structure with bitmasks indicating
+   the support base architectures and coprocessor extensions.
+
+   FIXME: This could more efficiently implemented as a constant array,
+   although it would also be less robust.  */
+
+static void
+select_arm_features (unsigned long mach,
+                    arm_feature_set * features)
+{
+#undef  ARM_FEATURE
+#define ARM_FEATURE(ARCH,CEXT) \
+  features->core = (ARCH); \
+  features->coproc = (CEXT) | FPU_FPA; \
+  return
+
+  switch (mach)
+    {
+    case bfd_mach_arm_2:       ARM_ARCH_V2;
+    case bfd_mach_arm_2a:      ARM_ARCH_V2S;
+    case bfd_mach_arm_3:       ARM_ARCH_V3;
+    case bfd_mach_arm_3M:      ARM_ARCH_V3M;
+    case bfd_mach_arm_4:       ARM_ARCH_V4;
+    case bfd_mach_arm_4T:      ARM_ARCH_V4T;
+    case bfd_mach_arm_5:       ARM_ARCH_V5;
+    case bfd_mach_arm_5T:      ARM_ARCH_V5T;
+    case bfd_mach_arm_5TE:     ARM_ARCH_V5TE;
+    case bfd_mach_arm_XScale:  ARM_ARCH_XSCALE;
+    case bfd_mach_arm_ep9312:  ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK | FPU_MAVERICK);
+    case bfd_mach_arm_iWMMXt:  ARM_ARCH_IWMMXT;
+    case bfd_mach_arm_iWMMXt2: ARM_ARCH_IWMMXT2;
+      /* If the machine type is unknown allow all
+        architecture types and all extensions.  */
+    case bfd_mach_arm_unknown: ARM_FEATURE (-1UL, -1UL);
+    default:
+      abort ();
+    }
+}
+
+
 /* NOTE: There are no checks in these routines that
    the relevant number of data bytes exist.  */
 
@@ -3991,6 +4143,40 @@ print_insn (bfd_vma pc, struct disassemble_info *info, bfd_boolean little)
       info->disassembler_options = NULL;
     }
 
+  /* PR 10288: Control which instructions will be disassembled.  */
+  if (info->private_data == NULL)
+    {
+      static arm_feature_set features;
+
+      if ((info->flags & USER_SPECIFIED_MACHINE_TYPE) == 0)
+       /* If the user did not use the -m command line switch then default to
+          disassembling all types of ARM instruction.
+          
+          The info->mach value has to be ignored as this will be based on
+          the default archictecture for the target and/or hints in the notes
+          section, but it will never be greater than the current largest arm
+          machine value (iWMMXt2), which is only equivalent to the V5TE
+          architecture.  ARM architectures have advanced beyond the machine
+          value encoding, and these newer architectures would be ignored if
+          the machine value was used.
+
+          Ie the -m switch is used to restrict which instructions will be
+          disassembled.  If it is necessary to use the -m switch to tell
+          objdump that an ARM binary is being disassembled, eg because the
+          input is a raw binary file, but it is also desired to disassemble
+          all ARM instructions then use "-marm".  This will select the
+          "unknown" arm architecture which is compatible with any ARM
+          instruction.  */
+         info->mach = bfd_mach_arm_unknown;
+
+      /* Compute the architecture bitmask from the machine number.
+        Note: This assumes that the machine number will not change
+        during disassembly....  */
+      select_arm_features (info->mach, & features);
+
+      info->private_data = & features;
+    }
+  
   /* Decide if our code is going to be little-endian, despite what the
      function argument might say.  */
   little_code = ((info->endian_code == BFD_ENDIAN_LITTLE) || little);
@@ -4041,7 +4227,9 @@ print_insn (bfd_vma pc, struct disassemble_info *info, bfd_boolean little)
             for a preceeding one.  */
          for (; n >= 0; n--)
            {
-             if (get_sym_code_type (info, n, &type))
+             if ((info->section == NULL
+                  || info->section == info->symtab[n]->section)
+                 && get_sym_code_type (info, n, &type))
                {
                  last_sym = n;
                  found = TRUE;
@@ -4111,14 +4299,19 @@ print_insn (bfd_vma pc, struct disassemble_info *info, bfd_boolean little)
   if (force_thumb)
     is_thumb = TRUE;
 
-  info->display_endian = little ? BFD_ENDIAN_LITTLE : BFD_ENDIAN_BIG;
+  if (is_data)
+    info->display_endian = little ? BFD_ENDIAN_LITTLE : BFD_ENDIAN_BIG;
+  else
+    info->display_endian = little_code ? BFD_ENDIAN_LITTLE : BFD_ENDIAN_BIG;
+
   info->bytes_per_line = 4;
 
-  if (is_data)
+  /* PR 10263: Disassemble data if requested to do so by the user.  */
+  if (is_data && ((info->flags & DISASSEMBLE_DATA) == 0))
     {
       int i;
 
-      /* size was already set above.  */
+      /* Size was already set above.  */
       info->bytes_per_chunk = size;
       printer = print_insn_data;
 
@@ -4139,7 +4332,7 @@ print_insn (bfd_vma pc, struct disassemble_info *info, bfd_boolean little)
       info->bytes_per_chunk = 4;
       size = 4;
 
-      status = info->read_memory_func (pc, (bfd_byte *)b, 4, info);
+      status = info->read_memory_func (pc, (bfd_byte *) b, 4, info);
       if (little_code)
        given = (b[0]) | (b[1] << 8) | (b[2] << 16) | (b[3] << 24);
       else
@@ -4169,7 +4362,7 @@ print_insn (bfd_vma pc, struct disassemble_info *info, bfd_boolean little)
              || (given & 0xF800) == 0xF000
              || (given & 0xF800) == 0xE800)
            {
-             status = info->read_memory_func (pc + 2, (bfd_byte *)b, 2, info);
+             status = info->read_memory_func (pc + 2, (bfd_byte *) b, 2, info);
              if (little_code)
                given = (b[0]) | (b[1] << 8) | (given << 16);
              else
@@ -4181,7 +4374,7 @@ print_insn (bfd_vma pc, struct disassemble_info *info, bfd_boolean little)
        }
 
       if (ifthen_address != pc)
-       find_ifthen_state(pc, info, little_code);
+       find_ifthen_state (pc, info, little_code);
 
       if (ifthen_state)
        {
This page took 0.055328 seconds and 4 git commands to generate.