Add support for the AVR Tiny series of microcontrollers.
[deliverable/binutils-gdb.git] / opcodes / avr-dis.c
index aea807e9255d630346574492bfa219db40cc98d0..78c9948165955d4a819be0dfa2fb1254dbaf2b53 100644 (file)
@@ -1,25 +1,27 @@
 /* Disassemble AVR instructions.
-   Copyright 1999, 2000, 2002, 2004, 2005, 2006
-   Free Software Foundation, Inc.
+   Copyright (C) 1999-2014 Free Software Foundation, Inc.
 
    Contributed by Denis Chertykov <denisc@overta.ru>
 
-   This program is free software; you can redistribute it and/or modify
+   This file is part of libopcodes.
+
+   This library is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
 
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
+   It is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
+   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"
@@ -47,7 +49,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;
@@ -106,7 +108,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"));
@@ -115,8 +117,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"));
@@ -146,7 +159,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':
@@ -155,7 +168,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;
 
@@ -166,13 +179,24 @@ 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;
 
     case 'i':
       sprintf (buf, "0x%04X", insn2);
       break;
+
+    case 'j':
+      {
+        unsigned int val = ((insn & 0xf) | ((insn & 0x600) >> 5)
+                                         | ((insn & 0x100) >> 2));
+        if (val > 0 && !(insn & 0x100))
+          val |= 0x80;
+        sprintf (buf, "0x%02x", val);
+        sprintf (buf, "%d", val);
+      }
+      break;
       
     case 'M':
       sprintf (buf, "0x%02X", ((insn & 0xf00) >> 4) | (insn & 0xf));
@@ -224,6 +248,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;
@@ -312,8 +340,12 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
   for (opcode = avr_opcodes, maskptr = avr_bin_masks;
        opcode->name;
        opcode++, maskptr++)
-    if ((insn & *maskptr) == opcode->bin_opcode)
-      break;
+    {
+      if ((opcode->isa == AVR_ISA_TINY) && (info->mach != bfd_mach_avrtiny))
+        continue;
+      if ((insn & *maskptr) == opcode->bin_opcode)
+        break;
+    }
   
   /* Special case: disassemble `ldd r,b+0' as `ld r,b', and
      `std b+0,r' as `st b,r' (next entry in the table).  */
@@ -328,7 +360,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;
@@ -339,14 +372,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);
        }
     }
This page took 0.026615 seconds and 4 git commands to generate.