2009-04-16 23:39:48 +08:00
|
|
|
/* Disassemble moxie instructions.
|
2017-01-02 11:36:43 +08:00
|
|
|
Copyright (C) 2009-2017 Free Software Foundation, Inc.
|
2009-04-16 23:39:48 +08:00
|
|
|
|
|
|
|
This file is part of the GNU opcodes library.
|
|
|
|
|
|
|
|
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 3, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
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. */
|
|
|
|
|
|
|
|
#include "sysdep.h"
|
2012-05-17 23:13:28 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2009-04-16 23:39:48 +08:00
|
|
|
#define STATIC_TABLE
|
|
|
|
#define DEFINE_TABLE
|
|
|
|
|
|
|
|
#include "opcode/moxie.h"
|
Move print_insn_XXX to an opcodes internal header
With the changes done in previous patches, print_insn_XXX functions
don't have to be external visible out of opcodes, because both gdb
and objdump select disassemblers through a single interface.
This patch moves these print_insn_XXX declarations from
include/dis-asm.h to opcodes/disassemble.h, which is a new header
added by this patch.
include:
2017-05-24 Yao Qi <yao.qi@linaro.org>
* dis-asm.h: Move some function declarations to
opcodes/disassemble.h.
opcodes:
2017-05-24 Yao Qi <yao.qi@linaro.org>
* alpha-dis.c: Include disassemble.h, don't include
dis-asm.h.
* avr-dis.c, bfin-dis.c, cr16-dis.c: Likewise.
* crx-dis.c, d10v-dis.c, d30v-dis.c: Likewise.
* disassemble.c, dlx-dis.c, epiphany-dis.c: Likewise.
* fr30-dis.c, ft32-dis.c, h8300-dis.c, h8500-dis.c: Likewise.
* hppa-dis.c, i370-dis.c, i386-dis.c: Likewise.
* i860-dis.c, i960-dis.c, ip2k-dis.c: Likewise.
* iq2000-dis.c, lm32-dis.c, m10200-dis.c: Likewise.
* m10300-dis.c, m32r-dis.c, m68hc11-dis.c: Likewise.
* m68k-dis.c, m88k-dis.c, mcore-dis.c: Likewise.
* metag-dis.c, microblaze-dis.c, mmix-dis.c: Likewise.
* moxie-dis.c, msp430-dis.c, mt-dis.c:
* nds32-dis.c, nios2-dis.c, ns32k-dis.c: Likewise.
* or1k-dis.c, pdp11-dis.c, pj-dis.c: Likewise.
* ppc-dis.c, pru-dis.c, riscv-dis.c: Likewise.
* rl78-dis.c, s390-dis.c, score-dis.c: Likewise.
* sh-dis.c, sh64-dis.c, tic30-dis.c: Likewise.
* tic4x-dis.c, tic54x-dis.c, tic6x-dis.c: Likewise.
* tic80-dis.c, tilegx-dis.c, tilepro-dis.c: Likewise.
* v850-dis.c, vax-dis.c, visium-dis.c: Likewise.
* w65-dis.c, wasm32-dis.c, xc16x-dis.c: Likewise.
* xgate-dis.c, xstormy16-dis.c, xtensa-dis.c: Likewise.
* z80-dis.c, z8k-dis.c: Likewise.
* disassemble.h: New file.
2017-05-25 00:23:52 +08:00
|
|
|
#include "disassemble.h"
|
2009-04-16 23:39:48 +08:00
|
|
|
|
|
|
|
static fprintf_ftype fpr;
|
|
|
|
static void *stream;
|
|
|
|
|
|
|
|
/* Macros to extract operands from the instruction word. */
|
|
|
|
#define OP_A(i) ((i >> 4) & 0xf)
|
|
|
|
#define OP_B(i) (i & 0xf)
|
2009-06-11 19:27:58 +08:00
|
|
|
#define INST2OFFSET(o) ((((signed short)((o & ((1<<10)-1))<<6))>>6)<<1)
|
2009-04-16 23:39:48 +08:00
|
|
|
|
|
|
|
static const char * reg_names[16] =
|
|
|
|
{ "$fp", "$sp", "$r0", "$r1", "$r2", "$r3", "$r4", "$r5",
|
|
|
|
"$r6", "$r7", "$r8", "$r9", "$r10", "$r11", "$r12", "$r13" };
|
|
|
|
|
|
|
|
int
|
|
|
|
print_insn_moxie (bfd_vma addr, struct disassemble_info * info)
|
|
|
|
{
|
|
|
|
int length = 2;
|
|
|
|
int status;
|
|
|
|
stream = info->stream;
|
|
|
|
const moxie_opc_info_t * opcode;
|
|
|
|
bfd_byte buffer[4];
|
|
|
|
unsigned short iword;
|
|
|
|
fpr = info->fprintf_func;
|
|
|
|
|
|
|
|
if ((status = info->read_memory_func (addr, buffer, 2, info)))
|
|
|
|
goto fail;
|
2012-09-14 06:24:51 +08:00
|
|
|
|
|
|
|
if (info->endian == BFD_ENDIAN_BIG)
|
|
|
|
iword = bfd_getb16 (buffer);
|
|
|
|
else
|
|
|
|
iword = bfd_getl16 (buffer);
|
2009-04-16 23:39:48 +08:00
|
|
|
|
|
|
|
/* Form 1 instructions have the high bit set to 0. */
|
|
|
|
if ((iword & (1<<15)) == 0)
|
|
|
|
{
|
|
|
|
/* Extract the Form 1 opcode. */
|
|
|
|
opcode = &moxie_form1_opc_info[iword >> 8];
|
|
|
|
switch (opcode->itype)
|
|
|
|
{
|
|
|
|
case MOXIE_F1_NARG:
|
|
|
|
fpr (stream, "%s", opcode->name);
|
|
|
|
break;
|
|
|
|
case MOXIE_F1_A:
|
|
|
|
fpr (stream, "%s\t%s", opcode->name,
|
|
|
|
reg_names[OP_A(iword)]);
|
|
|
|
break;
|
|
|
|
case MOXIE_F1_AB:
|
|
|
|
fpr (stream, "%s\t%s, %s", opcode->name,
|
|
|
|
reg_names[OP_A(iword)],
|
|
|
|
reg_names[OP_B(iword)]);
|
|
|
|
break;
|
|
|
|
case MOXIE_F1_A4:
|
|
|
|
{
|
|
|
|
unsigned imm;
|
|
|
|
if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
|
|
|
|
goto fail;
|
2012-09-14 06:24:51 +08:00
|
|
|
if (info->endian == BFD_ENDIAN_BIG)
|
|
|
|
imm = bfd_getb32 (buffer);
|
|
|
|
else
|
|
|
|
imm = bfd_getl32 (buffer);
|
2009-04-16 23:39:48 +08:00
|
|
|
fpr (stream, "%s\t%s, 0x%x", opcode->name,
|
|
|
|
reg_names[OP_A(iword)], imm);
|
|
|
|
length = 6;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MOXIE_F1_4:
|
|
|
|
{
|
|
|
|
unsigned imm;
|
|
|
|
if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
|
|
|
|
goto fail;
|
2012-09-14 06:24:51 +08:00
|
|
|
if (info->endian == BFD_ENDIAN_BIG)
|
|
|
|
imm = bfd_getb32 (buffer);
|
|
|
|
else
|
|
|
|
imm = bfd_getl32 (buffer);
|
2009-04-16 23:39:48 +08:00
|
|
|
fpr (stream, "%s\t0x%x", opcode->name, imm);
|
|
|
|
length = 6;
|
|
|
|
}
|
|
|
|
break;
|
2009-06-06 21:02:21 +08:00
|
|
|
case MOXIE_F1_M:
|
|
|
|
{
|
|
|
|
unsigned imm;
|
|
|
|
if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
|
|
|
|
goto fail;
|
2012-09-14 06:24:51 +08:00
|
|
|
if (info->endian == BFD_ENDIAN_BIG)
|
|
|
|
imm = bfd_getb32 (buffer);
|
|
|
|
else
|
|
|
|
imm = bfd_getl32 (buffer);
|
2009-06-06 21:02:21 +08:00
|
|
|
fpr (stream, "%s\t", opcode->name);
|
|
|
|
info->print_address_func ((bfd_vma) imm, info);
|
|
|
|
length = 6;
|
|
|
|
}
|
|
|
|
break;
|
2009-04-16 23:39:48 +08:00
|
|
|
case MOXIE_F1_AiB:
|
|
|
|
fpr (stream, "%s\t(%s), %s", opcode->name,
|
|
|
|
reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
|
|
|
|
break;
|
|
|
|
case MOXIE_F1_ABi:
|
|
|
|
fpr (stream, "%s\t%s, (%s)", opcode->name,
|
|
|
|
reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
|
|
|
|
break;
|
|
|
|
case MOXIE_F1_4A:
|
|
|
|
{
|
|
|
|
unsigned imm;
|
|
|
|
if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
|
|
|
|
goto fail;
|
2012-09-14 06:24:51 +08:00
|
|
|
if (info->endian == BFD_ENDIAN_BIG)
|
|
|
|
imm = bfd_getb32 (buffer);
|
|
|
|
else
|
|
|
|
imm = bfd_getl32 (buffer);
|
2009-04-16 23:39:48 +08:00
|
|
|
fpr (stream, "%s\t0x%x, %s",
|
|
|
|
opcode->name, imm, reg_names[OP_A(iword)]);
|
|
|
|
length = 6;
|
|
|
|
}
|
|
|
|
break;
|
2014-12-27 23:57:04 +08:00
|
|
|
case MOXIE_F1_AiB2:
|
2009-04-16 23:39:48 +08:00
|
|
|
{
|
|
|
|
unsigned imm;
|
2014-12-27 23:57:04 +08:00
|
|
|
if ((status = info->read_memory_func (addr+2, buffer, 2, info)))
|
2009-04-16 23:39:48 +08:00
|
|
|
goto fail;
|
2012-09-14 06:24:51 +08:00
|
|
|
if (info->endian == BFD_ENDIAN_BIG)
|
2014-12-27 23:57:04 +08:00
|
|
|
imm = bfd_getb16 (buffer);
|
2012-09-14 06:24:51 +08:00
|
|
|
else
|
2014-12-27 23:57:04 +08:00
|
|
|
imm = bfd_getl16 (buffer);
|
2009-04-16 23:39:48 +08:00
|
|
|
fpr (stream, "%s\t0x%x(%s), %s", opcode->name,
|
|
|
|
imm,
|
|
|
|
reg_names[OP_A(iword)],
|
|
|
|
reg_names[OP_B(iword)]);
|
2014-12-27 23:57:04 +08:00
|
|
|
length = 4;
|
2009-04-16 23:39:48 +08:00
|
|
|
}
|
|
|
|
break;
|
2014-12-27 23:57:04 +08:00
|
|
|
case MOXIE_F1_ABi2:
|
2009-04-16 23:39:48 +08:00
|
|
|
{
|
|
|
|
unsigned imm;
|
2014-12-27 23:57:04 +08:00
|
|
|
if ((status = info->read_memory_func (addr+2, buffer, 2, info)))
|
2009-04-16 23:39:48 +08:00
|
|
|
goto fail;
|
2012-09-14 06:24:51 +08:00
|
|
|
if (info->endian == BFD_ENDIAN_BIG)
|
2014-12-27 23:57:04 +08:00
|
|
|
imm = bfd_getb16 (buffer);
|
2012-09-14 06:24:51 +08:00
|
|
|
else
|
2014-12-27 23:57:04 +08:00
|
|
|
imm = bfd_getl16 (buffer);
|
2009-04-16 23:39:48 +08:00
|
|
|
fpr (stream, "%s\t%s, 0x%x(%s)",
|
|
|
|
opcode->name,
|
|
|
|
reg_names[OP_A(iword)],
|
|
|
|
imm,
|
|
|
|
reg_names[OP_B(iword)]);
|
2014-12-27 23:57:04 +08:00
|
|
|
length = 4;
|
2009-04-16 23:39:48 +08:00
|
|
|
}
|
|
|
|
break;
|
2012-09-28 11:53:39 +08:00
|
|
|
case MOXIE_BAD:
|
|
|
|
fpr (stream, "bad");
|
|
|
|
break;
|
2009-04-16 23:39:48 +08:00
|
|
|
default:
|
2012-09-28 11:53:39 +08:00
|
|
|
abort();
|
2009-04-16 23:39:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((iword & (1<<14)) == 0)
|
|
|
|
{
|
|
|
|
/* Extract the Form 2 opcode. */
|
|
|
|
opcode = &moxie_form2_opc_info[(iword >> 12) & 3];
|
|
|
|
switch (opcode->itype)
|
|
|
|
{
|
|
|
|
case MOXIE_F2_A8V:
|
|
|
|
fpr (stream, "%s\t%s, 0x%x",
|
|
|
|
opcode->name,
|
|
|
|
reg_names[(iword >> 8) & 0xf],
|
|
|
|
iword & ((1 << 8) - 1));
|
|
|
|
break;
|
|
|
|
case MOXIE_F2_NARG:
|
|
|
|
fpr (stream, "%s", opcode->name);
|
|
|
|
break;
|
2012-09-28 11:53:39 +08:00
|
|
|
case MOXIE_BAD:
|
|
|
|
fpr (stream, "bad");
|
|
|
|
break;
|
2009-04-16 23:39:48 +08:00
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Extract the Form 3 opcode. */
|
2009-06-11 19:27:58 +08:00
|
|
|
opcode = &moxie_form3_opc_info[(iword >> 10) & 15];
|
2009-04-16 23:39:48 +08:00
|
|
|
switch (opcode->itype)
|
|
|
|
{
|
2009-06-11 19:27:58 +08:00
|
|
|
case MOXIE_F3_PCREL:
|
|
|
|
fpr (stream, "%s\t", opcode->name);
|
2015-08-12 19:45:07 +08:00
|
|
|
info->print_address_func ((bfd_vma) (addr + INST2OFFSET(iword) + 2),
|
2009-06-11 19:27:58 +08:00
|
|
|
info);
|
2009-04-16 23:39:48 +08:00
|
|
|
break;
|
2012-09-28 11:53:39 +08:00
|
|
|
case MOXIE_BAD:
|
|
|
|
fpr (stream, "bad");
|
|
|
|
break;
|
2009-04-16 23:39:48 +08:00
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return length;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
info->memory_error_func (status, addr, info);
|
|
|
|
return -1;
|
|
|
|
}
|