OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [opcodes/] [msp430-dis.c] - Diff between revs 834 and 842

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 834 Rev 842
/* Disassemble MSP430 instructions.
/* Disassemble MSP430 instructions.
   Copyright (C) 2002, 2004, 2005, 2007, 2009 Free Software Foundation, Inc.
   Copyright (C) 2002, 2004, 2005, 2007, 2009 Free Software Foundation, Inc.
 
 
   Contributed by Dmitry Diky <diwil@mail.ru>
   Contributed by Dmitry Diky <diwil@mail.ru>
 
 
   This file is part of the GNU opcodes library.
   This file is part of the GNU opcodes library.
 
 
   This library is free software; you can redistribute it and/or modify
   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
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   the Free Software Foundation; either version 3, or (at your option)
   any later version.
   any later version.
 
 
   It is distributed in the hope that it will be useful, but WITHOUT
   It is distributed in the hope that it will be useful, but WITHOUT
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
   License for more details.
   License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
   MA 02110-1301, USA.  */
   MA 02110-1301, USA.  */
 
 
#include <stdio.h>
#include <stdio.h>
#include <ctype.h>
#include <ctype.h>
#include <string.h>
#include <string.h>
#include <sys/types.h>
#include <sys/types.h>
 
 
#include "dis-asm.h"
#include "dis-asm.h"
#include "opintl.h"
#include "opintl.h"
#include "libiberty.h"
#include "libiberty.h"
 
 
#define DASM_SECTION
#define DASM_SECTION
#include "opcode/msp430.h"
#include "opcode/msp430.h"
#undef DASM_SECTION
#undef DASM_SECTION
 
 
 
 
#define PS(x)   (0xffff & (x))
#define PS(x)   (0xffff & (x))
 
 
static unsigned short
static unsigned short
msp430dis_opcode (bfd_vma addr, disassemble_info *info)
msp430dis_opcode (bfd_vma addr, disassemble_info *info)
{
{
  bfd_byte buffer[2];
  bfd_byte buffer[2];
  int status;
  int status;
 
 
  status = info->read_memory_func (addr, buffer, 2, info);
  status = info->read_memory_func (addr, buffer, 2, info);
  if (status != 0)
  if (status != 0)
    {
    {
      info->memory_error_func (status, addr, info);
      info->memory_error_func (status, addr, info);
      return -1;
      return -1;
    }
    }
  return bfd_getl16 (buffer);
  return bfd_getl16 (buffer);
}
}
 
 
static int
static int
msp430_nooperands (struct msp430_opcode_s *opcode,
msp430_nooperands (struct msp430_opcode_s *opcode,
                   bfd_vma addr ATTRIBUTE_UNUSED,
                   bfd_vma addr ATTRIBUTE_UNUSED,
                   unsigned short insn ATTRIBUTE_UNUSED,
                   unsigned short insn ATTRIBUTE_UNUSED,
                   char *comm,
                   char *comm,
                   int *cycles)
                   int *cycles)
{
{
  /* Pop with constant.  */
  /* Pop with constant.  */
  if (insn == 0x43b2)
  if (insn == 0x43b2)
    return 0;
    return 0;
  if (insn == opcode->bin_opcode)
  if (insn == opcode->bin_opcode)
    return 2;
    return 2;
 
 
  if (opcode->fmt == 0)
  if (opcode->fmt == 0)
    {
    {
      if ((insn & 0x0f00) != 3 || (insn & 0x0f00) != 2)
      if ((insn & 0x0f00) != 3 || (insn & 0x0f00) != 2)
        return 0;
        return 0;
 
 
      strcpy (comm, "emulated...");
      strcpy (comm, "emulated...");
      *cycles = 1;
      *cycles = 1;
    }
    }
  else
  else
    {
    {
      strcpy (comm, "return from interupt");
      strcpy (comm, "return from interupt");
      *cycles = 5;
      *cycles = 5;
    }
    }
 
 
  return 2;
  return 2;
}
}
 
 
static int
static int
msp430_singleoperand (disassemble_info *info,
msp430_singleoperand (disassemble_info *info,
                      struct msp430_opcode_s *opcode,
                      struct msp430_opcode_s *opcode,
                      bfd_vma addr,
                      bfd_vma addr,
                      unsigned short insn,
                      unsigned short insn,
                      char *op,
                      char *op,
                      char *comm,
                      char *comm,
                      int *cycles)
                      int *cycles)
{
{
  int regs = 0, regd = 0;
  int regs = 0, regd = 0;
  int ad = 0, as = 0;
  int ad = 0, as = 0;
  int where = 0;
  int where = 0;
  int cmd_len = 2;
  int cmd_len = 2;
  short dst = 0;
  short dst = 0;
 
 
  regd = insn & 0x0f;
  regd = insn & 0x0f;
  regs = (insn & 0x0f00) >> 8;
  regs = (insn & 0x0f00) >> 8;
  as = (insn & 0x0030) >> 4;
  as = (insn & 0x0030) >> 4;
  ad = (insn & 0x0080) >> 7;
  ad = (insn & 0x0080) >> 7;
 
 
  switch (opcode->fmt)
  switch (opcode->fmt)
    {
    {
    case 0:                      /* Emulated work with dst register.  */
    case 0:                      /* Emulated work with dst register.  */
      if (regs != 2 && regs != 3 && regs != 1)
      if (regs != 2 && regs != 3 && regs != 1)
        return 0;
        return 0;
 
 
      /* Check if not clr insn.  */
      /* Check if not clr insn.  */
      if (opcode->bin_opcode == 0x4300 && (ad || as))
      if (opcode->bin_opcode == 0x4300 && (ad || as))
        return 0;
        return 0;
 
 
      /* Check if really inc, incd insns.  */
      /* Check if really inc, incd insns.  */
      if ((opcode->bin_opcode & 0xff00) == 0x5300 && as == 3)
      if ((opcode->bin_opcode & 0xff00) == 0x5300 && as == 3)
        return 0;
        return 0;
 
 
      if (ad == 0)
      if (ad == 0)
        {
        {
          *cycles = 1;
          *cycles = 1;
 
 
          /* Register.  */
          /* Register.  */
          if (regd == 0)
          if (regd == 0)
            {
            {
              *cycles += 1;
              *cycles += 1;
              sprintf (op, "r0");
              sprintf (op, "r0");
            }
            }
          else if (regd == 1)
          else if (regd == 1)
            sprintf (op, "r1");
            sprintf (op, "r1");
 
 
          else if (regd == 2)
          else if (regd == 2)
            sprintf (op, "r2");
            sprintf (op, "r2");
 
 
          else
          else
            sprintf (op, "r%d", regd);
            sprintf (op, "r%d", regd);
        }
        }
      else      /* ad == 1 msp430dis_opcode.  */
      else      /* ad == 1 msp430dis_opcode.  */
        {
        {
          if (regd == 0)
          if (regd == 0)
            {
            {
              /* PC relative.  */
              /* PC relative.  */
              dst = msp430dis_opcode (addr + 2, info);
              dst = msp430dis_opcode (addr + 2, info);
              cmd_len += 2;
              cmd_len += 2;
              *cycles = 4;
              *cycles = 4;
              sprintf (op, "0x%04x", dst);
              sprintf (op, "0x%04x", dst);
              sprintf (comm, "PC rel. abs addr 0x%04x",
              sprintf (comm, "PC rel. abs addr 0x%04x",
                       PS ((short) (addr + 2) + dst));
                       PS ((short) (addr + 2) + dst));
            }
            }
          else if (regd == 2)
          else if (regd == 2)
            {
            {
              /* Absolute.  */
              /* Absolute.  */
              dst = msp430dis_opcode (addr + 2, info);
              dst = msp430dis_opcode (addr + 2, info);
              cmd_len += 2;
              cmd_len += 2;
              *cycles = 4;
              *cycles = 4;
              sprintf (op, "&0x%04x", PS (dst));
              sprintf (op, "&0x%04x", PS (dst));
            }
            }
          else
          else
            {
            {
              dst = msp430dis_opcode (addr + 2, info);
              dst = msp430dis_opcode (addr + 2, info);
              cmd_len += 2;
              cmd_len += 2;
              *cycles = 4;
              *cycles = 4;
              sprintf (op, "%d(r%d)", dst, regd);
              sprintf (op, "%d(r%d)", dst, regd);
            }
            }
        }
        }
      break;
      break;
 
 
    case 2:     /* rrc, push, call, swpb, rra, sxt, push, call, reti etc...  */
    case 2:     /* rrc, push, call, swpb, rra, sxt, push, call, reti etc...  */
      if (as == 0)
      if (as == 0)
        {
        {
          if (regd == 3)
          if (regd == 3)
            {
            {
              /* Constsnts.  */
              /* Constsnts.  */
              sprintf (op, "#0");
              sprintf (op, "#0");
              sprintf (comm, "r3 As==00");
              sprintf (comm, "r3 As==00");
            }
            }
          else
          else
            {
            {
              /* Register.  */
              /* Register.  */
              sprintf (op, "r%d", regd);
              sprintf (op, "r%d", regd);
            }
            }
          *cycles = 1;
          *cycles = 1;
        }
        }
      else if (as == 2)
      else if (as == 2)
        {
        {
          *cycles = 1;
          *cycles = 1;
          if (regd == 2)
          if (regd == 2)
            {
            {
              sprintf (op, "#4");
              sprintf (op, "#4");
              sprintf (comm, "r2 As==10");
              sprintf (comm, "r2 As==10");
            }
            }
          else if (regd == 3)
          else if (regd == 3)
            {
            {
              sprintf (op, "#2");
              sprintf (op, "#2");
              sprintf (comm, "r3 As==10");
              sprintf (comm, "r3 As==10");
            }
            }
          else
          else
            {
            {
              *cycles = 3;
              *cycles = 3;
              /* Indexed register mode @Rn.  */
              /* Indexed register mode @Rn.  */
              sprintf (op, "@r%d", regd);
              sprintf (op, "@r%d", regd);
            }
            }
        }
        }
      else if (as == 3)
      else if (as == 3)
        {
        {
          *cycles = 1;
          *cycles = 1;
          if (regd == 2)
          if (regd == 2)
            {
            {
              sprintf (op, "#8");
              sprintf (op, "#8");
              sprintf (comm, "r2 As==11");
              sprintf (comm, "r2 As==11");
            }
            }
          else if (regd == 3)
          else if (regd == 3)
            {
            {
              sprintf (op, "#-1");
              sprintf (op, "#-1");
              sprintf (comm, "r3 As==11");
              sprintf (comm, "r3 As==11");
            }
            }
          else if (regd == 0)
          else if (regd == 0)
            {
            {
              *cycles = 3;
              *cycles = 3;
              /* absolute. @pc+ */
              /* absolute. @pc+ */
              dst = msp430dis_opcode (addr + 2, info);
              dst = msp430dis_opcode (addr + 2, info);
              cmd_len += 2;
              cmd_len += 2;
              sprintf (op, "#%d", dst);
              sprintf (op, "#%d", dst);
              sprintf (comm, "#0x%04x", PS (dst));
              sprintf (comm, "#0x%04x", PS (dst));
            }
            }
          else
          else
            {
            {
              *cycles = 3;
              *cycles = 3;
              sprintf (op, "@r%d+", regd);
              sprintf (op, "@r%d+", regd);
            }
            }
        }
        }
      else if (as == 1)
      else if (as == 1)
        {
        {
          *cycles = 4;
          *cycles = 4;
          if (regd == 0)
          if (regd == 0)
            {
            {
              /* PC relative.  */
              /* PC relative.  */
              dst = msp430dis_opcode (addr + 2, info);
              dst = msp430dis_opcode (addr + 2, info);
              cmd_len += 2;
              cmd_len += 2;
              sprintf (op, "0x%04x", PS (dst));
              sprintf (op, "0x%04x", PS (dst));
              sprintf (comm, "PC rel. 0x%04x",
              sprintf (comm, "PC rel. 0x%04x",
                       PS ((short) addr + 2 + dst));
                       PS ((short) addr + 2 + dst));
            }
            }
          else if (regd == 2)
          else if (regd == 2)
            {
            {
              /* Absolute.  */
              /* Absolute.  */
              dst = msp430dis_opcode (addr + 2, info);
              dst = msp430dis_opcode (addr + 2, info);
              cmd_len += 2;
              cmd_len += 2;
              sprintf (op, "&0x%04x", PS (dst));
              sprintf (op, "&0x%04x", PS (dst));
            }
            }
          else if (regd == 3)
          else if (regd == 3)
            {
            {
              *cycles = 1;
              *cycles = 1;
              sprintf (op, "#1");
              sprintf (op, "#1");
              sprintf (comm, "r3 As==01");
              sprintf (comm, "r3 As==01");
            }
            }
          else
          else
            {
            {
              /* Indexd.  */
              /* Indexd.  */
              dst = msp430dis_opcode (addr + 2, info);
              dst = msp430dis_opcode (addr + 2, info);
              cmd_len += 2;
              cmd_len += 2;
              sprintf (op, "%d(r%d)", dst, regd);
              sprintf (op, "%d(r%d)", dst, regd);
            }
            }
        }
        }
      break;
      break;
 
 
    case 3:                     /* Jumps.  */
    case 3:                     /* Jumps.  */
      where = insn & 0x03ff;
      where = insn & 0x03ff;
      if (where & 0x200)
      if (where & 0x200)
        where |= ~0x03ff;
        where |= ~0x03ff;
      if (where > 512 || where < -511)
      if (where > 512 || where < -511)
        return 0;
        return 0;
 
 
      where *= 2;
      where *= 2;
      sprintf (op, "$%+-8d", where + 2);
      sprintf (op, "$%+-8d", where + 2);
      sprintf (comm, "abs 0x%x", PS ((short) (addr) + 2 + where));
      sprintf (comm, "abs 0x%x", PS ((short) (addr) + 2 + where));
      *cycles = 2;
      *cycles = 2;
      return 2;
      return 2;
      break;
      break;
    default:
    default:
      cmd_len = 0;
      cmd_len = 0;
    }
    }
 
 
  return cmd_len;
  return cmd_len;
}
}
 
 
static int
static int
msp430_doubleoperand (disassemble_info *info,
msp430_doubleoperand (disassemble_info *info,
                      struct msp430_opcode_s *opcode,
                      struct msp430_opcode_s *opcode,
                      bfd_vma addr,
                      bfd_vma addr,
                      unsigned short insn,
                      unsigned short insn,
                      char *op1,
                      char *op1,
                      char *op2,
                      char *op2,
                      char *comm1,
                      char *comm1,
                      char *comm2,
                      char *comm2,
                      int *cycles)
                      int *cycles)
{
{
  int regs = 0, regd = 0;
  int regs = 0, regd = 0;
  int ad = 0, as = 0;
  int ad = 0, as = 0;
  int cmd_len = 2;
  int cmd_len = 2;
  short dst = 0;
  short dst = 0;
 
 
  regd = insn & 0x0f;
  regd = insn & 0x0f;
  regs = (insn & 0x0f00) >> 8;
  regs = (insn & 0x0f00) >> 8;
  as = (insn & 0x0030) >> 4;
  as = (insn & 0x0030) >> 4;
  ad = (insn & 0x0080) >> 7;
  ad = (insn & 0x0080) >> 7;
 
 
  if (opcode->fmt == 0)
  if (opcode->fmt == 0)
    {
    {
      /* Special case: rla and rlc are the only 2 emulated instructions that
      /* Special case: rla and rlc are the only 2 emulated instructions that
         fall into two operand instructions.  */
         fall into two operand instructions.  */
      /* With dst, there are only:
      /* With dst, there are only:
         Rm             Register,
         Rm             Register,
         x(Rm)          Indexed,
         x(Rm)          Indexed,
         0xXXXX         Relative,
         0xXXXX         Relative,
         &0xXXXX        Absolute
         &0xXXXX        Absolute
         emulated_ins   dst
         emulated_ins   dst
         basic_ins      dst, dst.  */
         basic_ins      dst, dst.  */
 
 
      if (regd != regs || as != ad)
      if (regd != regs || as != ad)
        return 0;                /* May be 'data' section.  */
        return 0;                /* May be 'data' section.  */
 
 
      if (ad == 0)
      if (ad == 0)
        {
        {
          /* Register mode.  */
          /* Register mode.  */
          if (regd == 3)
          if (regd == 3)
            {
            {
              strcpy (comm1, _("Illegal as emulation instr"));
              strcpy (comm1, _("Illegal as emulation instr"));
              return -1;
              return -1;
            }
            }
 
 
          sprintf (op1, "r%d", regd);
          sprintf (op1, "r%d", regd);
          *cycles = 1;
          *cycles = 1;
        }
        }
      else                      /* ad == 1 */
      else                      /* ad == 1 */
        {
        {
          if (regd == 0)
          if (regd == 0)
            {
            {
              /* PC relative, Symbolic.  */
              /* PC relative, Symbolic.  */
              dst = msp430dis_opcode (addr + 2, info);
              dst = msp430dis_opcode (addr + 2, info);
              cmd_len += 4;
              cmd_len += 4;
              *cycles = 6;
              *cycles = 6;
              sprintf (op1, "0x%04x", PS (dst));
              sprintf (op1, "0x%04x", PS (dst));
              sprintf (comm1, "PC rel. 0x%04x",
              sprintf (comm1, "PC rel. 0x%04x",
                       PS ((short) addr + 2 + dst));
                       PS ((short) addr + 2 + dst));
 
 
            }
            }
          else if (regd == 2)
          else if (regd == 2)
            {
            {
              /* Absolute.  */
              /* Absolute.  */
              dst = msp430dis_opcode (addr + 2, info);
              dst = msp430dis_opcode (addr + 2, info);
              /* If the 'src' field is not the same as the dst
              /* If the 'src' field is not the same as the dst
                 then this is not an rla instruction.  */
                 then this is not an rla instruction.  */
              if (dst != msp430dis_opcode (addr + 4, info))
              if (dst != msp430dis_opcode (addr + 4, info))
                return 0;
                return 0;
              cmd_len += 4;
              cmd_len += 4;
              *cycles = 6;
              *cycles = 6;
              sprintf (op1, "&0x%04x", PS (dst));
              sprintf (op1, "&0x%04x", PS (dst));
            }
            }
          else
          else
            {
            {
              /* Indexed.  */
              /* Indexed.  */
              dst = msp430dis_opcode (addr + 2, info);
              dst = msp430dis_opcode (addr + 2, info);
              cmd_len += 4;
              cmd_len += 4;
              *cycles = 6;
              *cycles = 6;
              sprintf (op1, "%d(r%d)", dst, regd);
              sprintf (op1, "%d(r%d)", dst, regd);
            }
            }
        }
        }
 
 
      *op2 = 0;
      *op2 = 0;
      *comm2 = 0;
      *comm2 = 0;
      return cmd_len;
      return cmd_len;
    }
    }
 
 
  /* Two operands exactly.  */
  /* Two operands exactly.  */
  if (ad == 0 && regd == 3)
  if (ad == 0 && regd == 3)
    {
    {
      /* R2/R3 are illegal as dest: may be data section.  */
      /* R2/R3 are illegal as dest: may be data section.  */
      strcpy (comm1, _("Illegal as 2-op instr"));
      strcpy (comm1, _("Illegal as 2-op instr"));
      return -1;
      return -1;
    }
    }
 
 
  /* Source.  */
  /* Source.  */
  if (as == 0)
  if (as == 0)
    {
    {
      *cycles = 1;
      *cycles = 1;
      if (regs == 3)
      if (regs == 3)
        {
        {
          /* Constsnts.  */
          /* Constsnts.  */
          sprintf (op1, "#0");
          sprintf (op1, "#0");
          sprintf (comm1, "r3 As==00");
          sprintf (comm1, "r3 As==00");
        }
        }
      else
      else
        {
        {
          /* Register.  */
          /* Register.  */
          sprintf (op1, "r%d", regs);
          sprintf (op1, "r%d", regs);
        }
        }
    }
    }
  else if (as == 2)
  else if (as == 2)
    {
    {
      *cycles = 1;
      *cycles = 1;
 
 
      if (regs == 2)
      if (regs == 2)
        {
        {
          sprintf (op1, "#4");
          sprintf (op1, "#4");
          sprintf (comm1, "r2 As==10");
          sprintf (comm1, "r2 As==10");
        }
        }
      else if (regs == 3)
      else if (regs == 3)
        {
        {
          sprintf (op1, "#2");
          sprintf (op1, "#2");
          sprintf (comm1, "r3 As==10");
          sprintf (comm1, "r3 As==10");
        }
        }
      else
      else
        {
        {
          *cycles = 2;
          *cycles = 2;
 
 
          /* Indexed register mode @Rn.  */
          /* Indexed register mode @Rn.  */
          sprintf (op1, "@r%d", regs);
          sprintf (op1, "@r%d", regs);
        }
        }
      if (!regs)
      if (!regs)
        *cycles = 3;
        *cycles = 3;
    }
    }
  else if (as == 3)
  else if (as == 3)
    {
    {
      if (regs == 2)
      if (regs == 2)
        {
        {
          sprintf (op1, "#8");
          sprintf (op1, "#8");
          sprintf (comm1, "r2 As==11");
          sprintf (comm1, "r2 As==11");
          *cycles = 1;
          *cycles = 1;
        }
        }
      else if (regs == 3)
      else if (regs == 3)
        {
        {
          sprintf (op1, "#-1");
          sprintf (op1, "#-1");
          sprintf (comm1, "r3 As==11");
          sprintf (comm1, "r3 As==11");
          *cycles = 1;
          *cycles = 1;
        }
        }
      else if (regs == 0)
      else if (regs == 0)
        {
        {
          *cycles = 3;
          *cycles = 3;
          /* Absolute. @pc+.  */
          /* Absolute. @pc+.  */
          dst = msp430dis_opcode (addr + 2, info);
          dst = msp430dis_opcode (addr + 2, info);
          cmd_len += 2;
          cmd_len += 2;
          sprintf (op1, "#%d", dst);
          sprintf (op1, "#%d", dst);
          sprintf (comm1, "#0x%04x", PS (dst));
          sprintf (comm1, "#0x%04x", PS (dst));
        }
        }
      else
      else
        {
        {
          *cycles = 2;
          *cycles = 2;
          sprintf (op1, "@r%d+", regs);
          sprintf (op1, "@r%d+", regs);
        }
        }
    }
    }
  else if (as == 1)
  else if (as == 1)
    {
    {
      if (regs == 0)
      if (regs == 0)
        {
        {
          *cycles = 4;
          *cycles = 4;
          /* PC relative.  */
          /* PC relative.  */
          dst = msp430dis_opcode (addr + 2, info);
          dst = msp430dis_opcode (addr + 2, info);
          cmd_len += 2;
          cmd_len += 2;
          sprintf (op1, "0x%04x", PS (dst));
          sprintf (op1, "0x%04x", PS (dst));
          sprintf (comm1, "PC rel. 0x%04x",
          sprintf (comm1, "PC rel. 0x%04x",
                   PS ((short) addr + 2 + dst));
                   PS ((short) addr + 2 + dst));
        }
        }
      else if (regs == 2)
      else if (regs == 2)
        {
        {
          *cycles = 2;
          *cycles = 2;
          /* Absolute.  */
          /* Absolute.  */
          dst = msp430dis_opcode (addr + 2, info);
          dst = msp430dis_opcode (addr + 2, info);
          cmd_len += 2;
          cmd_len += 2;
          sprintf (op1, "&0x%04x", PS (dst));
          sprintf (op1, "&0x%04x", PS (dst));
          sprintf (comm1, "0x%04x", PS (dst));
          sprintf (comm1, "0x%04x", PS (dst));
        }
        }
      else if (regs == 3)
      else if (regs == 3)
        {
        {
          *cycles = 1;
          *cycles = 1;
          sprintf (op1, "#1");
          sprintf (op1, "#1");
          sprintf (comm1, "r3 As==01");
          sprintf (comm1, "r3 As==01");
        }
        }
      else
      else
        {
        {
          *cycles = 3;
          *cycles = 3;
          /* Indexed.  */
          /* Indexed.  */
          dst = msp430dis_opcode (addr + 2, info);
          dst = msp430dis_opcode (addr + 2, info);
          cmd_len += 2;
          cmd_len += 2;
          sprintf (op1, "%d(r%d)", dst, regs);
          sprintf (op1, "%d(r%d)", dst, regs);
        }
        }
    }
    }
 
 
  /* Destination. Special care needed on addr + XXXX.  */
  /* Destination. Special care needed on addr + XXXX.  */
 
 
  if (ad == 0)
  if (ad == 0)
    {
    {
      /* Register.  */
      /* Register.  */
      if (regd == 0)
      if (regd == 0)
        {
        {
          *cycles += 1;
          *cycles += 1;
          sprintf (op2, "r0");
          sprintf (op2, "r0");
        }
        }
      else if (regd == 1)
      else if (regd == 1)
        sprintf (op2, "r1");
        sprintf (op2, "r1");
 
 
      else if (regd == 2)
      else if (regd == 2)
        sprintf (op2, "r2");
        sprintf (op2, "r2");
 
 
      else
      else
        sprintf (op2, "r%d", regd);
        sprintf (op2, "r%d", regd);
    }
    }
  else  /* ad == 1.  */
  else  /* ad == 1.  */
    {
    {
      * cycles += 3;
      * cycles += 3;
 
 
      if (regd == 0)
      if (regd == 0)
        {
        {
          /* PC relative.  */
          /* PC relative.  */
          *cycles += 1;
          *cycles += 1;
          dst = msp430dis_opcode (addr + cmd_len, info);
          dst = msp430dis_opcode (addr + cmd_len, info);
          sprintf (op2, "0x%04x", PS (dst));
          sprintf (op2, "0x%04x", PS (dst));
          sprintf (comm2, "PC rel. 0x%04x",
          sprintf (comm2, "PC rel. 0x%04x",
                   PS ((short) addr + cmd_len + dst));
                   PS ((short) addr + cmd_len + dst));
          cmd_len += 2;
          cmd_len += 2;
        }
        }
      else if (regd == 2)
      else if (regd == 2)
        {
        {
          /* Absolute.  */
          /* Absolute.  */
          dst = msp430dis_opcode (addr + cmd_len, info);
          dst = msp430dis_opcode (addr + cmd_len, info);
          cmd_len += 2;
          cmd_len += 2;
          sprintf (op2, "&0x%04x", PS (dst));
          sprintf (op2, "&0x%04x", PS (dst));
        }
        }
      else
      else
        {
        {
          dst = msp430dis_opcode (addr + cmd_len, info);
          dst = msp430dis_opcode (addr + cmd_len, info);
          cmd_len += 2;
          cmd_len += 2;
          sprintf (op2, "%d(r%d)", dst, regd);
          sprintf (op2, "%d(r%d)", dst, regd);
        }
        }
    }
    }
 
 
  return cmd_len;
  return cmd_len;
}
}
 
 
static int
static int
msp430_branchinstr (disassemble_info *info,
msp430_branchinstr (disassemble_info *info,
                    struct msp430_opcode_s *opcode ATTRIBUTE_UNUSED,
                    struct msp430_opcode_s *opcode ATTRIBUTE_UNUSED,
                    bfd_vma addr ATTRIBUTE_UNUSED,
                    bfd_vma addr ATTRIBUTE_UNUSED,
                    unsigned short insn,
                    unsigned short insn,
                    char *op1,
                    char *op1,
                    char *comm1,
                    char *comm1,
                    int *cycles)
                    int *cycles)
{
{
  int regs = 0, regd = 0;
  int regs = 0, regd = 0;
  int ad = 0, as = 0;
  int ad = 0, as = 0;
  int cmd_len = 2;
  int cmd_len = 2;
  short dst = 0;
  short dst = 0;
 
 
  regd = insn & 0x0f;
  regd = insn & 0x0f;
  regs = (insn & 0x0f00) >> 8;
  regs = (insn & 0x0f00) >> 8;
  as = (insn & 0x0030) >> 4;
  as = (insn & 0x0030) >> 4;
  ad = (insn & 0x0080) >> 7;
  ad = (insn & 0x0080) >> 7;
 
 
  if (regd != 0) /* Destination register is not a PC.  */
  if (regd != 0) /* Destination register is not a PC.  */
    return 0;
    return 0;
 
 
  /* dst is a source register.  */
  /* dst is a source register.  */
  if (as == 0)
  if (as == 0)
    {
    {
      /* Constants.  */
      /* Constants.  */
      if (regs == 3)
      if (regs == 3)
        {
        {
          *cycles = 1;
          *cycles = 1;
          sprintf (op1, "#0");
          sprintf (op1, "#0");
          sprintf (comm1, "r3 As==00");
          sprintf (comm1, "r3 As==00");
        }
        }
      else
      else
        {
        {
          /* Register.  */
          /* Register.  */
          *cycles = 1;
          *cycles = 1;
          sprintf (op1, "r%d", regs);
          sprintf (op1, "r%d", regs);
        }
        }
    }
    }
  else if (as == 2)
  else if (as == 2)
    {
    {
      if (regs == 2)
      if (regs == 2)
        {
        {
          *cycles = 2;
          *cycles = 2;
          sprintf (op1, "#4");
          sprintf (op1, "#4");
          sprintf (comm1, "r2 As==10");
          sprintf (comm1, "r2 As==10");
        }
        }
      else if (regs == 3)
      else if (regs == 3)
        {
        {
          *cycles = 1;
          *cycles = 1;
          sprintf (op1, "#2");
          sprintf (op1, "#2");
          sprintf (comm1, "r3 As==10");
          sprintf (comm1, "r3 As==10");
        }
        }
      else
      else
        {
        {
          /* Indexed register mode @Rn.  */
          /* Indexed register mode @Rn.  */
          *cycles = 2;
          *cycles = 2;
          sprintf (op1, "@r%d", regs);
          sprintf (op1, "@r%d", regs);
        }
        }
    }
    }
  else if (as == 3)
  else if (as == 3)
    {
    {
      if (regs == 2)
      if (regs == 2)
        {
        {
          *cycles = 1;
          *cycles = 1;
          sprintf (op1, "#8");
          sprintf (op1, "#8");
          sprintf (comm1, "r2 As==11");
          sprintf (comm1, "r2 As==11");
        }
        }
      else if (regs == 3)
      else if (regs == 3)
        {
        {
          *cycles = 1;
          *cycles = 1;
          sprintf (op1, "#-1");
          sprintf (op1, "#-1");
          sprintf (comm1, "r3 As==11");
          sprintf (comm1, "r3 As==11");
        }
        }
      else if (regs == 0)
      else if (regs == 0)
        {
        {
          /* Absolute. @pc+  */
          /* Absolute. @pc+  */
          *cycles = 3;
          *cycles = 3;
          dst = msp430dis_opcode (addr + 2, info);
          dst = msp430dis_opcode (addr + 2, info);
          cmd_len += 2;
          cmd_len += 2;
          sprintf (op1, "#0x%04x", PS (dst));
          sprintf (op1, "#0x%04x", PS (dst));
        }
        }
      else
      else
        {
        {
          *cycles = 2;
          *cycles = 2;
          sprintf (op1, "@r%d+", regs);
          sprintf (op1, "@r%d+", regs);
        }
        }
    }
    }
  else if (as == 1)
  else if (as == 1)
    {
    {
      * cycles = 3;
      * cycles = 3;
 
 
      if (regs == 0)
      if (regs == 0)
        {
        {
          /* PC relative.  */
          /* PC relative.  */
          dst = msp430dis_opcode (addr + 2, info);
          dst = msp430dis_opcode (addr + 2, info);
          cmd_len += 2;
          cmd_len += 2;
          (*cycles)++;
          (*cycles)++;
          sprintf (op1, "0x%04x", PS (dst));
          sprintf (op1, "0x%04x", PS (dst));
          sprintf (comm1, "PC rel. 0x%04x",
          sprintf (comm1, "PC rel. 0x%04x",
                   PS ((short) addr + 2 + dst));
                   PS ((short) addr + 2 + dst));
        }
        }
      else if (regs == 2)
      else if (regs == 2)
        {
        {
          /* Absolute.  */
          /* Absolute.  */
          dst = msp430dis_opcode (addr + 2, info);
          dst = msp430dis_opcode (addr + 2, info);
          cmd_len += 2;
          cmd_len += 2;
          sprintf (op1, "&0x%04x", PS (dst));
          sprintf (op1, "&0x%04x", PS (dst));
        }
        }
      else if (regs == 3)
      else if (regs == 3)
        {
        {
          (*cycles)--;
          (*cycles)--;
          sprintf (op1, "#1");
          sprintf (op1, "#1");
          sprintf (comm1, "r3 As==01");
          sprintf (comm1, "r3 As==01");
        }
        }
      else
      else
        {
        {
          /* Indexd.  */
          /* Indexd.  */
          dst = msp430dis_opcode (addr + 2, info);
          dst = msp430dis_opcode (addr + 2, info);
          cmd_len += 2;
          cmd_len += 2;
          sprintf (op1, "%d(r%d)", dst, regs);
          sprintf (op1, "%d(r%d)", dst, regs);
        }
        }
    }
    }
 
 
  return cmd_len;
  return cmd_len;
}
}
 
 
int
int
print_insn_msp430 (bfd_vma addr, disassemble_info *info)
print_insn_msp430 (bfd_vma addr, disassemble_info *info)
{
{
  void *stream = info->stream;
  void *stream = info->stream;
  fprintf_ftype prin = info->fprintf_func;
  fprintf_ftype prin = info->fprintf_func;
  struct msp430_opcode_s *opcode;
  struct msp430_opcode_s *opcode;
  char op1[32], op2[32], comm1[64], comm2[64];
  char op1[32], op2[32], comm1[64], comm2[64];
  int cmd_len = 0;
  int cmd_len = 0;
  unsigned short insn;
  unsigned short insn;
  int cycles = 0;
  int cycles = 0;
  char *bc = "";
  char *bc = "";
  char dinfo[32];               /* Debug purposes.  */
  char dinfo[32];               /* Debug purposes.  */
 
 
  insn = msp430dis_opcode (addr, info);
  insn = msp430dis_opcode (addr, info);
  sprintf (dinfo, "0x%04x", insn);
  sprintf (dinfo, "0x%04x", insn);
 
 
  if (((int) addr & 0xffff) > 0xffdf)
  if (((int) addr & 0xffff) > 0xffdf)
    {
    {
      (*prin) (stream, "interrupt service routine at 0x%04x", 0xffff & insn);
      (*prin) (stream, "interrupt service routine at 0x%04x", 0xffff & insn);
      return 2;
      return 2;
    }
    }
 
 
  *comm1 = 0;
  *comm1 = 0;
  *comm2 = 0;
  *comm2 = 0;
 
 
  for (opcode = msp430_opcodes; opcode->name; opcode++)
  for (opcode = msp430_opcodes; opcode->name; opcode++)
    {
    {
      if ((insn & opcode->bin_mask) == opcode->bin_opcode
      if ((insn & opcode->bin_mask) == opcode->bin_opcode
          && opcode->bin_opcode != 0x9300)
          && opcode->bin_opcode != 0x9300)
        {
        {
          *op1 = 0;
          *op1 = 0;
          *op2 = 0;
          *op2 = 0;
          *comm1 = 0;
          *comm1 = 0;
          *comm2 = 0;
          *comm2 = 0;
 
 
          /* r0 as destination. Ad should be zero.  */
          /* r0 as destination. Ad should be zero.  */
          if (opcode->insn_opnumb == 3 && (insn & 0x000f) == 0
          if (opcode->insn_opnumb == 3 && (insn & 0x000f) == 0
              && (0x0080 & insn) == 0)
              && (0x0080 & insn) == 0)
            {
            {
              cmd_len =
              cmd_len =
                msp430_branchinstr (info, opcode, addr, insn, op1, comm1,
                msp430_branchinstr (info, opcode, addr, insn, op1, comm1,
                                    &cycles);
                                    &cycles);
              if (cmd_len)
              if (cmd_len)
                break;
                break;
            }
            }
 
 
          switch (opcode->insn_opnumb)
          switch (opcode->insn_opnumb)
            {
            {
            case 0:
            case 0:
              cmd_len = msp430_nooperands (opcode, addr, insn, comm1, &cycles);
              cmd_len = msp430_nooperands (opcode, addr, insn, comm1, &cycles);
              break;
              break;
            case 2:
            case 2:
              cmd_len =
              cmd_len =
                msp430_doubleoperand (info, opcode, addr, insn, op1, op2,
                msp430_doubleoperand (info, opcode, addr, insn, op1, op2,
                                      comm1, comm2, &cycles);
                                      comm1, comm2, &cycles);
              if (insn & BYTE_OPERATION)
              if (insn & BYTE_OPERATION)
                bc = ".b";
                bc = ".b";
              break;
              break;
            case 1:
            case 1:
              cmd_len =
              cmd_len =
                msp430_singleoperand (info, opcode, addr, insn, op1, comm1,
                msp430_singleoperand (info, opcode, addr, insn, op1, comm1,
                                      &cycles);
                                      &cycles);
              if (insn & BYTE_OPERATION && opcode->fmt != 3)
              if (insn & BYTE_OPERATION && opcode->fmt != 3)
                bc = ".b";
                bc = ".b";
              break;
              break;
            default:
            default:
              break;
              break;
            }
            }
        }
        }
 
 
      if (cmd_len)
      if (cmd_len)
        break;
        break;
    }
    }
 
 
  dinfo[5] = 0;
  dinfo[5] = 0;
 
 
  if (cmd_len < 1)
  if (cmd_len < 1)
    {
    {
      /* Unknown opcode, or invalid combination of operands.  */
      /* Unknown opcode, or invalid combination of operands.  */
      (*prin) (stream, ".word   0x%04x; ????", PS (insn));
      (*prin) (stream, ".word   0x%04x; ????", PS (insn));
      return 2;
      return 2;
    }
    }
 
 
  (*prin) (stream, "%s%s", opcode->name, bc);
  (*prin) (stream, "%s%s", opcode->name, bc);
 
 
  if (*op1)
  if (*op1)
    (*prin) (stream, "\t%s", op1);
    (*prin) (stream, "\t%s", op1);
  if (*op2)
  if (*op2)
    (*prin) (stream, ",");
    (*prin) (stream, ",");
 
 
  if (strlen (op1) < 7)
  if (strlen (op1) < 7)
    (*prin) (stream, "\t");
    (*prin) (stream, "\t");
  if (!strlen (op1))
  if (!strlen (op1))
    (*prin) (stream, "\t");
    (*prin) (stream, "\t");
 
 
  if (*op2)
  if (*op2)
    (*prin) (stream, "%s", op2);
    (*prin) (stream, "%s", op2);
  if (strlen (op2) < 8)
  if (strlen (op2) < 8)
    (*prin) (stream, "\t");
    (*prin) (stream, "\t");
 
 
  if (*comm1 || *comm2)
  if (*comm1 || *comm2)
    (*prin) (stream, ";");
    (*prin) (stream, ";");
  else if (cycles)
  else if (cycles)
    {
    {
      if (*op2)
      if (*op2)
        (*prin) (stream, ";");
        (*prin) (stream, ";");
      else
      else
        {
        {
          if (strlen (op1) < 7)
          if (strlen (op1) < 7)
            (*prin) (stream, ";");
            (*prin) (stream, ";");
          else
          else
            (*prin) (stream, "\t;");
            (*prin) (stream, "\t;");
        }
        }
    }
    }
  if (*comm1)
  if (*comm1)
    (*prin) (stream, "%s", comm1);
    (*prin) (stream, "%s", comm1);
  if (*comm1 && *comm2)
  if (*comm1 && *comm2)
    (*prin) (stream, ",");
    (*prin) (stream, ",");
  if (*comm2)
  if (*comm2)
    (*prin) (stream, " %s", comm2);
    (*prin) (stream, " %s", comm2);
  return cmd_len;
  return cmd_len;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.