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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [binutils-2.18.50/] [opcodes/] [h8500-dis.c] - Diff between revs 156 and 816

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

Rev 156 Rev 816
/* Disassemble h8500 instructions.
/* Disassemble h8500 instructions.
   Copyright 1993, 1998, 2000, 2001, 2002, 2004, 2005, 2007
   Copyright 1993, 1998, 2000, 2001, 2002, 2004, 2005, 2007
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
 
 
   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>
 
 
#define DISASSEMBLER_TABLE
#define DISASSEMBLER_TABLE
#define DEFINE_TABLE
#define DEFINE_TABLE
 
 
#include "sysdep.h"
#include "sysdep.h"
#include "h8500-opc.h"
#include "h8500-opc.h"
#include "dis-asm.h"
#include "dis-asm.h"
#include "opintl.h"
#include "opintl.h"
 
 
/* Maximum length of an instruction.  */
/* Maximum length of an instruction.  */
#define MAXLEN 8
#define MAXLEN 8
 
 
#include <setjmp.h>
#include <setjmp.h>
 
 
struct private
struct private
{
{
  /* Points to first byte not fetched.  */
  /* Points to first byte not fetched.  */
  bfd_byte *max_fetched;
  bfd_byte *max_fetched;
  bfd_byte the_buffer[MAXLEN];
  bfd_byte the_buffer[MAXLEN];
  bfd_vma insn_start;
  bfd_vma insn_start;
  jmp_buf bailout;
  jmp_buf bailout;
};
};
 
 
/* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
/* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
   to ADDR (exclusive) are valid.  Returns 1 for success, longjmps
   to ADDR (exclusive) are valid.  Returns 1 for success, longjmps
   on error.  */
   on error.  */
#define FETCH_DATA(info, addr) \
#define FETCH_DATA(info, addr) \
  ((addr) <= ((struct private *)(info->private_data))->max_fetched \
  ((addr) <= ((struct private *)(info->private_data))->max_fetched \
   ? 1 : fetch_data ((info), (addr)))
   ? 1 : fetch_data ((info), (addr)))
 
 
static int
static int
fetch_data (struct disassemble_info *info, bfd_byte *addr)
fetch_data (struct disassemble_info *info, bfd_byte *addr)
{
{
  int status;
  int status;
  struct private *priv = (struct private *) info->private_data;
  struct private *priv = (struct private *) info->private_data;
  bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
  bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
 
 
  status = (*info->read_memory_func) (start,
  status = (*info->read_memory_func) (start,
                                      priv->max_fetched,
                                      priv->max_fetched,
                                      addr - priv->max_fetched,
                                      addr - priv->max_fetched,
                                      info);
                                      info);
  if (status != 0)
  if (status != 0)
    {
    {
      (*info->memory_error_func) (status, start, info);
      (*info->memory_error_func) (status, start, info);
      longjmp (priv->bailout, 1);
      longjmp (priv->bailout, 1);
    }
    }
  else
  else
    priv->max_fetched = addr;
    priv->max_fetched = addr;
  return 1;
  return 1;
}
}
 
 
static char *crname[] = { "sr", "ccr", "*", "br", "ep", "dp", "*", "tp" };
static char *crname[] = { "sr", "ccr", "*", "br", "ep", "dp", "*", "tp" };
 
 
int
int
print_insn_h8500 (bfd_vma addr, disassemble_info *info)
print_insn_h8500 (bfd_vma addr, disassemble_info *info)
{
{
  const h8500_opcode_info *opcode;
  const h8500_opcode_info *opcode;
  void *stream = info->stream;
  void *stream = info->stream;
  fprintf_ftype func = info->fprintf_func;
  fprintf_ftype func = info->fprintf_func;
  struct private priv;
  struct private priv;
  bfd_byte *buffer = priv.the_buffer;
  bfd_byte *buffer = priv.the_buffer;
 
 
  info->private_data = (PTR) & priv;
  info->private_data = (PTR) & priv;
  priv.max_fetched = priv.the_buffer;
  priv.max_fetched = priv.the_buffer;
  priv.insn_start = addr;
  priv.insn_start = addr;
  if (setjmp (priv.bailout) != 0)
  if (setjmp (priv.bailout) != 0)
    /* Error return.  */
    /* Error return.  */
    return -1;
    return -1;
 
 
  /* Run down the table to find the one which matches.  */
  /* Run down the table to find the one which matches.  */
  for (opcode = h8500_table; opcode->name; opcode++)
  for (opcode = h8500_table; opcode->name; opcode++)
    {
    {
      int byte;
      int byte;
      int rn = 0;
      int rn = 0;
      int rd = 0;
      int rd = 0;
      int rs = 0;
      int rs = 0;
      int disp = 0;
      int disp = 0;
      int abs = 0;
      int abs = 0;
      int imm = 0;
      int imm = 0;
      int pcrel = 0;
      int pcrel = 0;
      int qim = 0;
      int qim = 0;
      int i;
      int i;
      int cr = 0;
      int cr = 0;
 
 
      for (byte = 0; byte < opcode->length; byte++)
      for (byte = 0; byte < opcode->length; byte++)
        {
        {
          FETCH_DATA (info, buffer + byte + 1);
          FETCH_DATA (info, buffer + byte + 1);
          if ((buffer[byte] & opcode->bytes[byte].mask)
          if ((buffer[byte] & opcode->bytes[byte].mask)
              != (opcode->bytes[byte].contents))
              != (opcode->bytes[byte].contents))
            goto next;
            goto next;
 
 
          else
          else
            {
            {
              /* Extract any info parts.  */
              /* Extract any info parts.  */
              switch (opcode->bytes[byte].insert)
              switch (opcode->bytes[byte].insert)
                {
                {
                case 0:
                case 0:
                case FP:
                case FP:
                  break;
                  break;
                default:
                default:
                  /* xgettext:c-format */
                  /* xgettext:c-format */
                  func (stream, _("can't cope with insert %d\n"),
                  func (stream, _("can't cope with insert %d\n"),
                        opcode->bytes[byte].insert);
                        opcode->bytes[byte].insert);
                  break;
                  break;
                case RN:
                case RN:
                  rn = buffer[byte] & 0x7;
                  rn = buffer[byte] & 0x7;
                  break;
                  break;
                case RS:
                case RS:
                  rs = buffer[byte] & 0x7;
                  rs = buffer[byte] & 0x7;
                  break;
                  break;
                case CRB:
                case CRB:
                  cr = buffer[byte] & 0x7;
                  cr = buffer[byte] & 0x7;
                  if (cr == 0)
                  if (cr == 0)
                    goto next;
                    goto next;
                  break;
                  break;
                case CRW:
                case CRW:
                  cr = buffer[byte] & 0x7;
                  cr = buffer[byte] & 0x7;
                  if (cr != 0)
                  if (cr != 0)
                    goto next;
                    goto next;
                  break;
                  break;
                case DISP16:
                case DISP16:
                  FETCH_DATA (info, buffer + byte + 2);
                  FETCH_DATA (info, buffer + byte + 2);
                  disp = (buffer[byte] << 8) | (buffer[byte + 1]);
                  disp = (buffer[byte] << 8) | (buffer[byte + 1]);
                  break;
                  break;
                case FPIND_D8:
                case FPIND_D8:
                case DISP8:
                case DISP8:
                  disp = ((char) (buffer[byte]));
                  disp = ((char) (buffer[byte]));
                  break;
                  break;
                case RD:
                case RD:
                case RDIND:
                case RDIND:
                  rd = buffer[byte] & 0x7;
                  rd = buffer[byte] & 0x7;
                  break;
                  break;
                case ABS24:
                case ABS24:
                  FETCH_DATA (info, buffer + byte + 3);
                  FETCH_DATA (info, buffer + byte + 3);
                  abs =
                  abs =
                    (buffer[byte] << 16)
                    (buffer[byte] << 16)
                    | (buffer[byte + 1] << 8)
                    | (buffer[byte + 1] << 8)
                    | (buffer[byte + 2]);
                    | (buffer[byte + 2]);
                  break;
                  break;
                case ABS16:
                case ABS16:
                  FETCH_DATA (info, buffer + byte + 2);
                  FETCH_DATA (info, buffer + byte + 2);
                  abs = (buffer[byte] << 8) | (buffer[byte + 1]);
                  abs = (buffer[byte] << 8) | (buffer[byte + 1]);
                  break;
                  break;
                case ABS8:
                case ABS8:
                  abs = (buffer[byte]);
                  abs = (buffer[byte]);
                  break;
                  break;
                case IMM16:
                case IMM16:
                  FETCH_DATA (info, buffer + byte + 2);
                  FETCH_DATA (info, buffer + byte + 2);
                  imm = (buffer[byte] << 8) | (buffer[byte + 1]);
                  imm = (buffer[byte] << 8) | (buffer[byte + 1]);
                  break;
                  break;
                case IMM4:
                case IMM4:
                  imm = (buffer[byte]) & 0xf;
                  imm = (buffer[byte]) & 0xf;
                  break;
                  break;
                case IMM8:
                case IMM8:
                case RLIST:
                case RLIST:
                  imm = (buffer[byte]);
                  imm = (buffer[byte]);
                  break;
                  break;
                case PCREL16:
                case PCREL16:
                  FETCH_DATA (info, buffer + byte + 2);
                  FETCH_DATA (info, buffer + byte + 2);
                  pcrel = (buffer[byte] << 8) | (buffer[byte + 1]);
                  pcrel = (buffer[byte] << 8) | (buffer[byte + 1]);
                  break;
                  break;
                case PCREL8:
                case PCREL8:
                  pcrel = (buffer[byte]);
                  pcrel = (buffer[byte]);
                  break;
                  break;
                case QIM:
                case QIM:
                  switch (buffer[byte] & 0x7)
                  switch (buffer[byte] & 0x7)
                    {
                    {
                    case 0:
                    case 0:
                      qim = 1;
                      qim = 1;
                      break;
                      break;
                    case 1:
                    case 1:
                      qim = 2;
                      qim = 2;
                      break;
                      break;
                    case 4:
                    case 4:
                      qim = -1;
                      qim = -1;
                      break;
                      break;
                    case 5:
                    case 5:
                      qim = -2;
                      qim = -2;
                      break;
                      break;
                    }
                    }
                  break;
                  break;
 
 
                }
                }
            }
            }
        }
        }
      /* We get here when all the masks have passed so we can output
      /* We get here when all the masks have passed so we can output
         the operands.  */
         the operands.  */
      FETCH_DATA (info, buffer + opcode->length);
      FETCH_DATA (info, buffer + opcode->length);
      (func) (stream, "%s\t", opcode->name);
      (func) (stream, "%s\t", opcode->name);
      for (i = 0; i < opcode->nargs; i++)
      for (i = 0; i < opcode->nargs; i++)
        {
        {
          if (i)
          if (i)
            (func) (stream, ",");
            (func) (stream, ",");
          switch (opcode->arg_type[i])
          switch (opcode->arg_type[i])
            {
            {
            case FP:
            case FP:
              func (stream, "fp");
              func (stream, "fp");
              break;
              break;
            case RNIND_D16:
            case RNIND_D16:
              func (stream, "@(0x%x:16,r%d)", disp, rn);
              func (stream, "@(0x%x:16,r%d)", disp, rn);
              break;
              break;
            case RNIND_D8:
            case RNIND_D8:
              func (stream, "@(0x%x:8 (%d),r%d)", disp & 0xff, disp, rn);
              func (stream, "@(0x%x:8 (%d),r%d)", disp & 0xff, disp, rn);
              break;
              break;
            case RDIND_D16:
            case RDIND_D16:
              func (stream, "@(0x%x:16,r%d)", disp, rd);
              func (stream, "@(0x%x:16,r%d)", disp, rd);
              break;
              break;
            case RDIND_D8:
            case RDIND_D8:
              func (stream, "@(0x%x:8 (%d), r%d)", disp & 0xff, disp, rd);
              func (stream, "@(0x%x:8 (%d), r%d)", disp & 0xff, disp, rd);
              break;
              break;
            case FPIND_D8:
            case FPIND_D8:
              func (stream, "@(0x%x:8 (%d), fp)", disp & 0xff, disp);
              func (stream, "@(0x%x:8 (%d), fp)", disp & 0xff, disp);
              break;
              break;
            case CRB:
            case CRB:
            case CRW:
            case CRW:
              func (stream, "%s", crname[cr]);
              func (stream, "%s", crname[cr]);
              break;
              break;
            case RN:
            case RN:
              func (stream, "r%d", rn);
              func (stream, "r%d", rn);
              break;
              break;
            case RD:
            case RD:
              func (stream, "r%d", rd);
              func (stream, "r%d", rd);
              break;
              break;
            case RS:
            case RS:
              func (stream, "r%d", rs);
              func (stream, "r%d", rs);
              break;
              break;
            case RNDEC:
            case RNDEC:
              func (stream, "@-r%d", rn);
              func (stream, "@-r%d", rn);
              break;
              break;
            case RNINC:
            case RNINC:
              func (stream, "@r%d+", rn);
              func (stream, "@r%d+", rn);
              break;
              break;
            case RNIND:
            case RNIND:
              func (stream, "@r%d", rn);
              func (stream, "@r%d", rn);
              break;
              break;
            case RDIND:
            case RDIND:
              func (stream, "@r%d", rd);
              func (stream, "@r%d", rd);
              break;
              break;
            case SPINC:
            case SPINC:
              func (stream, "@sp+");
              func (stream, "@sp+");
              break;
              break;
            case SPDEC:
            case SPDEC:
              func (stream, "@-sp");
              func (stream, "@-sp");
              break;
              break;
            case ABS24:
            case ABS24:
              func (stream, "@0x%0x:24", abs);
              func (stream, "@0x%0x:24", abs);
              break;
              break;
            case ABS16:
            case ABS16:
              func (stream, "@0x%0x:16", abs & 0xffff);
              func (stream, "@0x%0x:16", abs & 0xffff);
              break;
              break;
            case ABS8:
            case ABS8:
              func (stream, "@0x%0x:8", abs & 0xff);
              func (stream, "@0x%0x:8", abs & 0xff);
              break;
              break;
            case IMM16:
            case IMM16:
              func (stream, "#0x%0x:16", imm & 0xffff);
              func (stream, "#0x%0x:16", imm & 0xffff);
              break;
              break;
            case RLIST:
            case RLIST:
              {
              {
                int i;
                int i;
                int nc = 0;
                int nc = 0;
 
 
                func (stream, "(");
                func (stream, "(");
                for (i = 0; i < 8; i++)
                for (i = 0; i < 8; i++)
                  {
                  {
                    if (imm & (1 << i))
                    if (imm & (1 << i))
                      {
                      {
                        func (stream, "r%d", i);
                        func (stream, "r%d", i);
                        if (nc)
                        if (nc)
                          func (stream, ",");
                          func (stream, ",");
                        nc = 1;
                        nc = 1;
                      }
                      }
                  }
                  }
                func (stream, ")");
                func (stream, ")");
              }
              }
              break;
              break;
            case IMM8:
            case IMM8:
              func (stream, "#0x%0x:8", imm & 0xff);
              func (stream, "#0x%0x:8", imm & 0xff);
              break;
              break;
            case PCREL16:
            case PCREL16:
              func (stream, "0x%0x:16",
              func (stream, "0x%0x:16",
                    (int)(pcrel + addr + opcode->length) & 0xffff);
                    (int)(pcrel + addr + opcode->length) & 0xffff);
              break;
              break;
            case PCREL8:
            case PCREL8:
              func (stream, "#0x%0x:8",
              func (stream, "#0x%0x:8",
                    (int)((char) pcrel + addr + opcode->length) & 0xffff);
                    (int)((char) pcrel + addr + opcode->length) & 0xffff);
              break;
              break;
            case QIM:
            case QIM:
              func (stream, "#%d:q", qim);
              func (stream, "#%d:q", qim);
              break;
              break;
            case IMM4:
            case IMM4:
              func (stream, "#%d:4", imm);
              func (stream, "#%d:4", imm);
              break;
              break;
            }
            }
        }
        }
      return opcode->length;
      return opcode->length;
    next:
    next:
      ;
      ;
    }
    }
 
 
  /* Couldn't understand anything.  */
  /* Couldn't understand anything.  */
  /* xgettext:c-format */
  /* xgettext:c-format */
  func (stream, _("%02x\t\t*unknown*"), buffer[0]);
  func (stream, _("%02x\t\t*unknown*"), buffer[0]);
  return 1;
  return 1;
}
}
 
 

powered by: WebSVN 2.1.0

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