* ldexp.c: Add LOG2CEIL() builtin function to linker script language
[binutils-gdb.git] / opcodes / avr-dis.c
index 17f9eb1f93536be49042a3fc07df541f7559eed5..385b399f7afe57d3f8e473d27278fee152f1a366 100644 (file)
@@ -1,5 +1,5 @@
 /* Disassemble AVR instructions.
-   Copyright 1999, 2000, 2002, 2004, 2005, 2006, 2007
+   Copyright 1999, 2000, 2002, 2004, 2005, 2006, 2007, 2008, 2012
    Free Software Foundation, Inc.
 
    Contributed by Denis Chertykov <denisc@overta.ru>
@@ -21,8 +21,8 @@
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
    MA 02110-1301, USA.  */
 
-#include <assert.h>
 #include "sysdep.h"
+#include <assert.h>
 #include "dis-asm.h"
 #include "opintl.h"
 #include "libiberty.h"
@@ -50,7 +50,7 @@ static const char * comment_start = "0x";
 
 static int
 avr_operand (unsigned int insn, unsigned int insn2, unsigned int pc, int constraint,
-             char *buf, char *comment, int regs, int *sym, bfd_vma *sym_addr)
+             char *opcode_str, char *buf, char *comment, int regs, int *sym, bfd_vma *sym_addr)
 {
   int ok = 1;
   *sym = 0;
@@ -109,7 +109,7 @@ avr_operand (unsigned int insn, unsigned int insn2, unsigned int pc, int constra
            case 0x100e: xyz = "-X"; break;
            default: xyz = "??"; ok = 0;
          }
-       sprintf (buf, xyz);
+       strcpy (buf, xyz);
 
        if (AVR_UNDEF_P (insn))
          sprintf (comment, _("undefined"));
@@ -118,8 +118,19 @@ avr_operand (unsigned int insn, unsigned int insn2, unsigned int pc, int constra
 
     case 'z':
       *buf++ = 'Z';
-      if (insn & 0x1)
-       *buf++ = '+';
+
+      /* Check for post-increment. */
+      char *s;
+      for (s = opcode_str; *s; ++s)
+        {
+          if (*s == '+')
+            {
+             if (insn & (1 << (15 - (s - opcode_str))))
+               *buf++ = '+';
+              break;
+            }
+        }
+
       *buf = '\0';
       if (AVR_UNDEF_P (insn))
        sprintf (comment, _("undefined"));
@@ -149,7 +160,7 @@ avr_operand (unsigned int insn, unsigned int insn2, unsigned int pc, int constra
         value of the address only once, but this would mean recoding
         objdump_print_address() which would affect many targets.  */
       sprintf (buf, "%#lx", (unsigned long) *sym_addr);      
-      sprintf (comment, comment_start);
+      strcpy (comment, comment_start);
       break;
       
     case 'L':
@@ -158,7 +169,7 @@ avr_operand (unsigned int insn, unsigned int insn2, unsigned int pc, int constra
        sprintf (buf, ".%+-8d", rel_addr);
         *sym = 1;
         *sym_addr = pc + 2 + rel_addr;
-       sprintf (comment, comment_start);
+       strcpy (comment, comment_start);
       }
       break;
 
@@ -169,7 +180,7 @@ avr_operand (unsigned int insn, unsigned int insn2, unsigned int pc, int constra
        sprintf (buf, ".%+-8d", rel_addr);
         *sym = 1;
         *sym_addr = pc + 2 + rel_addr;
-       sprintf (comment, comment_start);
+       strcpy (comment, comment_start);
       }
       break;
 
@@ -227,6 +238,10 @@ avr_operand (unsigned int insn, unsigned int insn2, unsigned int pc, int constra
       }
       break;
       
+    case 'E':
+      sprintf (buf, "%d", (insn >> 4) & 15);
+      break;
+      
     case '?':
       *buf = '\0';
       break;
@@ -331,7 +346,8 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
 
   if (opcode->name)
     {
-      char *op = opcode->constraints;
+      char *constraints = opcode->constraints;
+      char *opcode_str = opcode->opcode;
 
       insn2 = 0;
       ok = 1;
@@ -342,14 +358,14 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
          cmd_len = 4;
        }
 
-      if (*op && *op != '?')
+      if (*constraints && *constraints != '?')
        {
-         int regs = REGISTER_P (*op);
+         int regs = REGISTER_P (*constraints);
 
-         ok = avr_operand (insn, insn2, addr, *op, op1, comment1, 0, &sym_op1, &sym_addr1);
+         ok = avr_operand (insn, insn2, addr, *constraints, opcode_str, op1, comment1, 0, &sym_op1, &sym_addr1);
 
-         if (ok && *(++op) == ',')
-           ok = avr_operand (insn, insn2, addr, *(++op), op2,
+         if (ok && *(++constraints) == ',')
+           ok = avr_operand (insn, insn2, addr, *(++constraints), opcode_str, op2,
                              *comment1 ? comment2 : comment1, regs, &sym_op2, &sym_addr2);
        }
     }