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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [opcodes/] [rx-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
/* Disassembler code for Renesas RX.
/* Disassembler code for Renesas RX.
   Copyright 2008, 2009 Free Software Foundation, Inc.
   Copyright 2008, 2009 Free Software Foundation, Inc.
   Contributed by Red Hat.
   Contributed by Red Hat.
   Written by DJ Delorie.
   Written by DJ Delorie.
 
 
   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 "bfd.h"
#include "bfd.h"
#include "dis-asm.h"
#include "dis-asm.h"
#include "opcode/rx.h"
#include "opcode/rx.h"
 
 
typedef struct
typedef struct
{
{
  bfd_vma pc;
  bfd_vma pc;
  disassemble_info * dis;
  disassemble_info * dis;
} RX_Data;
} RX_Data;
 
 
static int
static int
rx_get_byte (void * vdata)
rx_get_byte (void * vdata)
{
{
  bfd_byte buf[1];
  bfd_byte buf[1];
  RX_Data *rx_data = (RX_Data *) vdata;
  RX_Data *rx_data = (RX_Data *) vdata;
 
 
  rx_data->dis->read_memory_func (rx_data->pc,
  rx_data->dis->read_memory_func (rx_data->pc,
                                  buf,
                                  buf,
                                  1,
                                  1,
                                  rx_data->dis);
                                  rx_data->dis);
 
 
  rx_data->pc ++;
  rx_data->pc ++;
  return buf[0];
  return buf[0];
}
}
 
 
static char const * size_names[] =
static char const * size_names[] =
{
{
  "", ".b", ".ub", ".b", ".w", ".uw", ".w", ".a", ".l"
  "", ".b", ".ub", ".b", ".w", ".uw", ".w", ".a", ".l"
};
};
 
 
static char const * opsize_names[] =
static char const * opsize_names[] =
{
{
  "", ".b", ".b", ".b", ".w", ".w", ".w", ".a", ".l"
  "", ".b", ".b", ".b", ".w", ".w", ".w", ".a", ".l"
};
};
 
 
static char const * register_names[] =
static char const * register_names[] =
{
{
  /* general registers */
  /* general registers */
  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  /* control register */
  /* control register */
  "psw", "pc", "usp", "fpsw", "", "", "", "wr",
  "psw", "pc", "usp", "fpsw", "", "", "", "wr",
  "bpsw", "bpc", "isp", "fintv", "intb", "", "", "",
  "bpsw", "bpc", "isp", "fintv", "intb", "", "", "",
  "pbp", "pben", "", "", "", "", "", "",
  "pbp", "pben", "", "", "", "", "", "",
  "bbpsw", "bbpc", "", "", "", "", "", ""
  "bbpsw", "bbpc", "", "", "", "", "", ""
};
};
 
 
static char const * condition_names[] =
static char const * condition_names[] =
{
{
  /* condition codes */
  /* condition codes */
  "eq", "ne", "c", "nc", "gtu", "leu", "pz", "n",
  "eq", "ne", "c", "nc", "gtu", "leu", "pz", "n",
  "ge", "lt", "gt", "le", "o", "no", "always", "never"
  "ge", "lt", "gt", "le", "o", "no", "always", "never"
};
};
 
 
static const char * flag_names[] =
static const char * flag_names[] =
{
{
  "c", "z", "s", "o", "", "", "", "",
  "c", "z", "s", "o", "", "", "", "",
  "", "", "", "", "", "", "", "",
  "", "", "", "", "", "", "", "",
  "i", "u", "", "", "", "", "", ""
  "i", "u", "", "", "", "", "", ""
  "", "", "", "", "", "", "", "",
  "", "", "", "", "", "", "", "",
};
};
 
 
int
int
print_insn_rx (bfd_vma addr, disassemble_info * dis)
print_insn_rx (bfd_vma addr, disassemble_info * dis)
{
{
  int rv;
  int rv;
  RX_Data rx_data;
  RX_Data rx_data;
  RX_Opcode_Decoded opcode;
  RX_Opcode_Decoded opcode;
  const char * s;
  const char * s;
 
 
  rx_data.pc = addr;
  rx_data.pc = addr;
  rx_data.dis = dis;
  rx_data.dis = dis;
 
 
  rv = rx_decode_opcode (addr, &opcode, rx_get_byte, &rx_data);
  rv = rx_decode_opcode (addr, &opcode, rx_get_byte, &rx_data);
 
 
  dis->bytes_per_line = 10;
  dis->bytes_per_line = 10;
 
 
#define PR (dis->fprintf_func)
#define PR (dis->fprintf_func)
#define PS (dis->stream)
#define PS (dis->stream)
#define PC(c) PR (PS, "%c", c)
#define PC(c) PR (PS, "%c", c)
 
 
  for (s = opcode.syntax; *s; s++)
  for (s = opcode.syntax; *s; s++)
    {
    {
      if (*s != '%')
      if (*s != '%')
        {
        {
          PC (*s);
          PC (*s);
        }
        }
      else
      else
        {
        {
          RX_Opcode_Operand * oper;
          RX_Opcode_Operand * oper;
          int do_size = 0;
          int do_size = 0;
          int do_hex = 0;
          int do_hex = 0;
          int do_addr = 0;
          int do_addr = 0;
 
 
          s ++;
          s ++;
 
 
          if (*s == 'S')
          if (*s == 'S')
            {
            {
              do_size = 1;
              do_size = 1;
              s++;
              s++;
            }
            }
          if (*s == 'x')
          if (*s == 'x')
            {
            {
              do_hex = 1;
              do_hex = 1;
              s++;
              s++;
            }
            }
          if (*s == 'a')
          if (*s == 'a')
            {
            {
              do_addr = 1;
              do_addr = 1;
              s++;
              s++;
            }
            }
 
 
          switch (*s)
          switch (*s)
            {
            {
            case '%':
            case '%':
              PC ('%');
              PC ('%');
              break;
              break;
 
 
            case 's':
            case 's':
              PR (PS, "%s", opsize_names[opcode.size]);
              PR (PS, "%s", opsize_names[opcode.size]);
              break;
              break;
 
 
            case '0':
            case '0':
            case '1':
            case '1':
            case '2':
            case '2':
              oper = opcode.op + *s - '0';
              oper = opcode.op + *s - '0';
              if (do_size)
              if (do_size)
                {
                {
                  if (oper->type == RX_Operand_Indirect)
                  if (oper->type == RX_Operand_Indirect)
                    PR (PS, "%s", size_names[oper->size]);
                    PR (PS, "%s", size_names[oper->size]);
                }
                }
              else
              else
                switch (oper->type)
                switch (oper->type)
                  {
                  {
                  case RX_Operand_Immediate:
                  case RX_Operand_Immediate:
                    if (do_addr)
                    if (do_addr)
                      dis->print_address_func (oper->addend, dis);
                      dis->print_address_func (oper->addend, dis);
                    else if (do_hex
                    else if (do_hex
                             || oper->addend > 999
                             || oper->addend > 999
                             || oper->addend < -999)
                             || oper->addend < -999)
                      PR (PS, "%#x", oper->addend);
                      PR (PS, "%#x", oper->addend);
                    else
                    else
                      PR (PS, "%d", oper->addend);
                      PR (PS, "%d", oper->addend);
                    break;
                    break;
                  case RX_Operand_Register:
                  case RX_Operand_Register:
                    PR (PS, "%s", register_names[oper->reg]);
                    PR (PS, "%s", register_names[oper->reg]);
                    break;
                    break;
                  case RX_Operand_Indirect:
                  case RX_Operand_Indirect:
                    if (oper->addend)
                    if (oper->addend)
                      PR (PS, "%d[%s]", oper->addend, register_names[oper->reg]);
                      PR (PS, "%d[%s]", oper->addend, register_names[oper->reg]);
                    else
                    else
                      PR (PS, "[%s]", register_names[oper->reg]);
                      PR (PS, "[%s]", register_names[oper->reg]);
                    break;
                    break;
                  case RX_Operand_Postinc:
                  case RX_Operand_Postinc:
                    PR (PS, "[%s+]", register_names[oper->reg]);
                    PR (PS, "[%s+]", register_names[oper->reg]);
                    break;
                    break;
                  case RX_Operand_Predec:
                  case RX_Operand_Predec:
                    PR (PS, "[-%s]", register_names[oper->reg]);
                    PR (PS, "[-%s]", register_names[oper->reg]);
                    break;
                    break;
                  case RX_Operand_Condition:
                  case RX_Operand_Condition:
                    PR (PS, "%s", condition_names[oper->reg]);
                    PR (PS, "%s", condition_names[oper->reg]);
                    break;
                    break;
                  case RX_Operand_Flag:
                  case RX_Operand_Flag:
                    PR (PS, "%s", flag_names[oper->reg]);
                    PR (PS, "%s", flag_names[oper->reg]);
                    break;
                    break;
                  default:
                  default:
                    PR (PS, "[???]");
                    PR (PS, "[???]");
                    break;
                    break;
                  }
                  }
            }
            }
        }
        }
    }
    }
 
 
  return rv;
  return rv;
}
}
 
 

powered by: WebSVN 2.1.0

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