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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [opcodes/] [moxie-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 moxie instructions.
/* Disassemble moxie instructions.
   Copyright 2009
   Copyright 2009
   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>
#include "sysdep.h"
#include "sysdep.h"
#define STATIC_TABLE
#define STATIC_TABLE
#define DEFINE_TABLE
#define DEFINE_TABLE
 
 
#include "opcode/moxie.h"
#include "opcode/moxie.h"
#include "dis-asm.h"
#include "dis-asm.h"
 
 
static fprintf_ftype fpr;
static fprintf_ftype fpr;
static void *stream;
static void *stream;
 
 
/* Macros to extract operands from the instruction word.  */
/* Macros to extract operands from the instruction word.  */
#define OP_A(i) ((i >> 4) & 0xf)
#define OP_A(i) ((i >> 4) & 0xf)
#define OP_B(i) (i & 0xf)
#define OP_B(i) (i & 0xf)
#define INST2OFFSET(o) ((((signed short)((o & ((1<<10)-1))<<6))>>6)<<1)
#define INST2OFFSET(o) ((((signed short)((o & ((1<<10)-1))<<6))>>6)<<1)
 
 
static const char * reg_names[16] =
static const char * reg_names[16] =
  { "$fp", "$sp", "$r0", "$r1", "$r2", "$r3", "$r4", "$r5",
  { "$fp", "$sp", "$r0", "$r1", "$r2", "$r3", "$r4", "$r5",
    "$r6", "$r7", "$r8", "$r9", "$r10", "$r11", "$r12", "$r13" };
    "$r6", "$r7", "$r8", "$r9", "$r10", "$r11", "$r12", "$r13" };
 
 
int
int
print_insn_moxie (bfd_vma addr, struct disassemble_info * info)
print_insn_moxie (bfd_vma addr, struct disassemble_info * info)
{
{
  int length = 2;
  int length = 2;
  int status;
  int status;
  stream = info->stream;
  stream = info->stream;
  const moxie_opc_info_t * opcode;
  const moxie_opc_info_t * opcode;
  bfd_byte buffer[4];
  bfd_byte buffer[4];
  unsigned short iword;
  unsigned short iword;
  fpr = info->fprintf_func;
  fpr = info->fprintf_func;
 
 
  if ((status = info->read_memory_func (addr, buffer, 2, info)))
  if ((status = info->read_memory_func (addr, buffer, 2, info)))
    goto fail;
    goto fail;
  iword = bfd_getb16 (buffer);
  iword = bfd_getb16 (buffer);
 
 
  /* Form 1 instructions have the high bit set to 0.  */
  /* Form 1 instructions have the high bit set to 0.  */
  if ((iword & (1<<15)) == 0)
  if ((iword & (1<<15)) == 0)
    {
    {
      /* Extract the Form 1 opcode.  */
      /* Extract the Form 1 opcode.  */
      opcode = &moxie_form1_opc_info[iword >> 8];
      opcode = &moxie_form1_opc_info[iword >> 8];
      switch (opcode->itype)
      switch (opcode->itype)
        {
        {
        case MOXIE_F1_NARG:
        case MOXIE_F1_NARG:
          fpr (stream, "%s", opcode->name);
          fpr (stream, "%s", opcode->name);
          break;
          break;
        case MOXIE_F1_A:
        case MOXIE_F1_A:
          fpr (stream, "%s\t%s", opcode->name,
          fpr (stream, "%s\t%s", opcode->name,
               reg_names[OP_A(iword)]);
               reg_names[OP_A(iword)]);
          break;
          break;
        case MOXIE_F1_AB:
        case MOXIE_F1_AB:
          fpr (stream, "%s\t%s, %s", opcode->name,
          fpr (stream, "%s\t%s, %s", opcode->name,
               reg_names[OP_A(iword)],
               reg_names[OP_A(iword)],
               reg_names[OP_B(iword)]);
               reg_names[OP_B(iword)]);
          break;
          break;
        case MOXIE_F1_A4:
        case MOXIE_F1_A4:
          {
          {
            unsigned imm;
            unsigned imm;
            if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
            if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
              goto fail;
              goto fail;
            imm = bfd_getb32 (buffer);
            imm = bfd_getb32 (buffer);
            fpr (stream, "%s\t%s, 0x%x", opcode->name,
            fpr (stream, "%s\t%s, 0x%x", opcode->name,
                 reg_names[OP_A(iword)], imm);
                 reg_names[OP_A(iword)], imm);
            length = 6;
            length = 6;
          }
          }
          break;
          break;
        case MOXIE_F1_4:
        case MOXIE_F1_4:
          {
          {
            unsigned imm;
            unsigned imm;
            if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
            if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
              goto fail;
              goto fail;
            imm = bfd_getb32 (buffer);
            imm = bfd_getb32 (buffer);
            fpr (stream, "%s\t0x%x", opcode->name, imm);
            fpr (stream, "%s\t0x%x", opcode->name, imm);
            length = 6;
            length = 6;
          }
          }
          break;
          break;
        case MOXIE_F1_M:
        case MOXIE_F1_M:
          {
          {
            unsigned imm;
            unsigned imm;
            if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
            if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
              goto fail;
              goto fail;
            imm = bfd_getb32 (buffer);
            imm = bfd_getb32 (buffer);
            fpr (stream, "%s\t", opcode->name);
            fpr (stream, "%s\t", opcode->name);
            info->print_address_func ((bfd_vma) imm, info);
            info->print_address_func ((bfd_vma) imm, info);
            length = 6;
            length = 6;
          }
          }
          break;
          break;
        case MOXIE_F1_AiB:
        case MOXIE_F1_AiB:
          fpr (stream, "%s\t(%s), %s", opcode->name,
          fpr (stream, "%s\t(%s), %s", opcode->name,
               reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
               reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
          break;
          break;
        case MOXIE_F1_ABi:
        case MOXIE_F1_ABi:
          fpr (stream, "%s\t%s, (%s)", opcode->name,
          fpr (stream, "%s\t%s, (%s)", opcode->name,
               reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
               reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
          break;
          break;
        case MOXIE_F1_4A:
        case MOXIE_F1_4A:
          {
          {
            unsigned imm;
            unsigned imm;
            if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
            if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
              goto fail;
              goto fail;
            imm = bfd_getb32 (buffer);
            imm = bfd_getb32 (buffer);
            fpr (stream, "%s\t0x%x, %s",
            fpr (stream, "%s\t0x%x, %s",
                 opcode->name, imm, reg_names[OP_A(iword)]);
                 opcode->name, imm, reg_names[OP_A(iword)]);
            length = 6;
            length = 6;
          }
          }
          break;
          break;
        case MOXIE_F1_AiB4:
        case MOXIE_F1_AiB4:
          {
          {
            unsigned imm;
            unsigned imm;
            if ((status = info->read_memory_func (addr+2, buffer, 4, info)))
            if ((status = info->read_memory_func (addr+2, buffer, 4, info)))
              goto fail;
              goto fail;
            imm = bfd_getb32 (buffer);
            imm = bfd_getb32 (buffer);
            fpr (stream, "%s\t0x%x(%s), %s", opcode->name,
            fpr (stream, "%s\t0x%x(%s), %s", opcode->name,
                 imm,
                 imm,
                 reg_names[OP_A(iword)],
                 reg_names[OP_A(iword)],
                 reg_names[OP_B(iword)]);
                 reg_names[OP_B(iword)]);
            length = 6;
            length = 6;
          }
          }
          break;
          break;
        case MOXIE_F1_ABi4:
        case MOXIE_F1_ABi4:
          {
          {
            unsigned imm;
            unsigned imm;
            if ((status = info->read_memory_func (addr+2, buffer, 4, info)))
            if ((status = info->read_memory_func (addr+2, buffer, 4, info)))
              goto fail;
              goto fail;
            imm = bfd_getb32 (buffer);
            imm = bfd_getb32 (buffer);
            fpr (stream, "%s\t%s, 0x%x(%s)",
            fpr (stream, "%s\t%s, 0x%x(%s)",
                 opcode->name,
                 opcode->name,
                 reg_names[OP_A(iword)],
                 reg_names[OP_A(iword)],
                 imm,
                 imm,
                 reg_names[OP_B(iword)]);
                 reg_names[OP_B(iword)]);
            length = 6;
            length = 6;
          }
          }
          break;
          break;
        default:
        default:
          abort ();
          abort ();
        }
        }
    }
    }
  else if ((iword & (1<<14)) == 0)
  else if ((iword & (1<<14)) == 0)
    {
    {
      /* Extract the Form 2 opcode.  */
      /* Extract the Form 2 opcode.  */
      opcode = &moxie_form2_opc_info[(iword >> 12) & 3];
      opcode = &moxie_form2_opc_info[(iword >> 12) & 3];
      switch (opcode->itype)
      switch (opcode->itype)
        {
        {
        case MOXIE_F2_A8V:
        case MOXIE_F2_A8V:
          fpr (stream, "%s\t%s, 0x%x",
          fpr (stream, "%s\t%s, 0x%x",
               opcode->name,
               opcode->name,
               reg_names[(iword >> 8) & 0xf],
               reg_names[(iword >> 8) & 0xf],
               iword & ((1 << 8) - 1));
               iword & ((1 << 8) - 1));
          break;
          break;
        case MOXIE_F2_NARG:
        case MOXIE_F2_NARG:
          fpr (stream, "%s", opcode->name);
          fpr (stream, "%s", opcode->name);
          break;
          break;
        default:
        default:
          abort();
          abort();
        }
        }
    }
    }
  else
  else
    {
    {
      /* Extract the Form 3 opcode.  */
      /* Extract the Form 3 opcode.  */
      opcode = &moxie_form3_opc_info[(iword >> 10) & 15];
      opcode = &moxie_form3_opc_info[(iword >> 10) & 15];
      switch (opcode->itype)
      switch (opcode->itype)
        {
        {
        case MOXIE_F3_PCREL:
        case MOXIE_F3_PCREL:
          fpr (stream, "%s\t", opcode->name);
          fpr (stream, "%s\t", opcode->name);
          info->print_address_func ((bfd_vma) (addr + INST2OFFSET(iword)),
          info->print_address_func ((bfd_vma) (addr + INST2OFFSET(iword)),
                                    info);
                                    info);
          break;
          break;
        default:
        default:
          abort();
          abort();
        }
        }
    }
    }
 
 
  return length;
  return length;
 
 
 fail:
 fail:
  info->memory_error_func (status, addr, info);
  info->memory_error_func (status, addr, info);
  return -1;
  return -1;
}
}
 
 

powered by: WebSVN 2.1.0

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