2015-01-28 06:06:43 +01:00
|
|
|
/* Disassemble ft32 instructions.
|
2019-01-01 11:31:27 +01:00
|
|
|
Copyright (C) 2013-2019 Free Software Foundation, Inc.
|
2015-01-28 06:06:43 +01:00
|
|
|
Contributed by FTDI (support@ftdichip.com)
|
|
|
|
|
|
|
|
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"
|
|
|
|
#include <stdio.h>
|
|
|
|
#define STATIC_TABLE
|
|
|
|
#define DEFINE_TABLE
|
|
|
|
|
|
|
|
#include "opcode/ft32.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-24 18:23:52 +02:00
|
|
|
#include "disassemble.h"
|
2015-01-28 06:06:43 +01:00
|
|
|
|
|
|
|
extern const ft32_opc_info_t ft32_opc_info[128];
|
|
|
|
|
|
|
|
static fprintf_ftype fpr;
|
|
|
|
static void *stream;
|
|
|
|
|
2017-08-31 04:51:49 +02:00
|
|
|
static int
|
|
|
|
sign_extend(int bit, int value)
|
|
|
|
{
|
|
|
|
int onebit = (1 << bit);
|
|
|
|
return (value & (onebit - 1)) - (value & onebit);
|
|
|
|
}
|
|
|
|
|
2017-10-13 03:37:40 +02:00
|
|
|
static void
|
|
|
|
ft32_opcode(bfd_vma addr ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int iword,
|
|
|
|
struct disassemble_info *info)
|
2015-01-28 06:06:43 +01:00
|
|
|
{
|
|
|
|
const ft32_opc_info_t *oo;
|
|
|
|
|
|
|
|
for (oo = ft32_opc_info; oo->name; oo++)
|
|
|
|
if ((iword & oo->mask) == oo->bits)
|
|
|
|
break;
|
|
|
|
|
2017-10-13 03:37:40 +02:00
|
|
|
unsigned int sc[2];
|
|
|
|
if (ft32_decode_shortcode((unsigned int)addr, iword, sc))
|
|
|
|
{
|
|
|
|
ft32_opcode(addr, sc[0], info);
|
|
|
|
fpr (stream, " ; ");
|
|
|
|
ft32_opcode(addr, sc[1], info);
|
|
|
|
}
|
|
|
|
|
2015-01-28 06:06:43 +01:00
|
|
|
if (oo->name)
|
|
|
|
{
|
|
|
|
int f = oo->fields;
|
|
|
|
int imm;
|
|
|
|
|
2017-10-13 03:37:40 +02:00
|
|
|
fpr (stream, "%s", oo->name);
|
2015-01-28 06:06:43 +01:00
|
|
|
if (oo->dw)
|
|
|
|
{
|
|
|
|
fpr (stream, ".%c ", "bsl"[(iword >> FT32_FLD_DW_BIT) & 3]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fpr (stream, " ");
|
|
|
|
}
|
|
|
|
|
|
|
|
while (f)
|
|
|
|
{
|
|
|
|
int lobit = f & -f;
|
|
|
|
if (f & lobit)
|
|
|
|
{
|
|
|
|
switch (lobit)
|
|
|
|
{
|
|
|
|
case FT32_FLD_CBCRCV:
|
|
|
|
// imm is {CB, CV}
|
|
|
|
imm = ((iword >> FT32_FLD_CB_BIT) & ((1 << FT32_FLD_CB_SIZ) - 1)) << 4;
|
|
|
|
imm |= ((iword >> FT32_FLD_CV_BIT) & ((1 << FT32_FLD_CV_SIZ) - 1));
|
|
|
|
switch (imm)
|
|
|
|
{
|
|
|
|
case 0x00: fpr(stream, "nz"); break;
|
|
|
|
case 0x01: fpr(stream, "z"); break;
|
|
|
|
case 0x10: fpr(stream, "ae"); break;
|
|
|
|
case 0x11: fpr(stream, "b"); break;
|
|
|
|
case 0x20: fpr(stream, "no"); break;
|
|
|
|
case 0x21: fpr(stream, "o"); break;
|
|
|
|
case 0x30: fpr(stream, "ns"); break;
|
|
|
|
case 0x31: fpr(stream, "s"); break;
|
|
|
|
case 0x40: fpr(stream, "lt"); break;
|
|
|
|
case 0x41: fpr(stream, "gte"); break;
|
|
|
|
case 0x50: fpr(stream, "lte"); break;
|
|
|
|
case 0x51: fpr(stream, "gt"); break;
|
|
|
|
case 0x60: fpr(stream, "be"); break;
|
|
|
|
case 0x61: fpr(stream, "a"); break;
|
|
|
|
default: fpr(stream, "%d,$r30,%d", (imm >> 4), (imm & 1)); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FT32_FLD_CB:
|
|
|
|
imm = (iword >> FT32_FLD_CB_BIT) & ((1 << FT32_FLD_CB_SIZ) - 1);
|
|
|
|
fpr(stream, "%d", imm);
|
|
|
|
break;
|
|
|
|
case FT32_FLD_R_D:
|
|
|
|
fpr(stream, "$r%d", (iword >> FT32_FLD_R_D_BIT) & 0x1f);
|
|
|
|
break;
|
|
|
|
case FT32_FLD_CR:
|
|
|
|
imm = (iword >> FT32_FLD_CR_BIT) & ((1 << FT32_FLD_CR_SIZ) - 1);
|
|
|
|
fpr(stream, "$r%d", 28 + imm);
|
|
|
|
break;
|
|
|
|
case FT32_FLD_CV:
|
|
|
|
imm = (iword >> FT32_FLD_CV_BIT) & ((1 << FT32_FLD_CV_SIZ) - 1);
|
|
|
|
fpr(stream, "%d", imm);
|
|
|
|
break;
|
|
|
|
case FT32_FLD_R_1:
|
|
|
|
fpr(stream, "$r%d", (iword >> FT32_FLD_R_1_BIT) & 0x1f);
|
|
|
|
break;
|
|
|
|
case FT32_FLD_RIMM:
|
|
|
|
imm = (iword >> FT32_FLD_RIMM_BIT) & ((1 << FT32_FLD_RIMM_SIZ) - 1);
|
|
|
|
if (imm & 0x400)
|
2017-08-31 04:51:49 +02:00
|
|
|
fpr(stream, "%d", sign_extend(9, imm));
|
2015-01-28 06:06:43 +01:00
|
|
|
else
|
|
|
|
fpr(stream, "$r%d", imm & 0x1f);
|
|
|
|
break;
|
|
|
|
case FT32_FLD_R_2:
|
|
|
|
fpr(stream, "$r%d", (iword >> FT32_FLD_R_2_BIT) & 0x1f);
|
|
|
|
break;
|
|
|
|
case FT32_FLD_K20:
|
|
|
|
imm = iword & ((1 << FT32_FLD_K20_SIZ) - 1);
|
2017-08-31 04:51:49 +02:00
|
|
|
fpr(stream, "%d", sign_extend(19, imm));
|
2015-01-28 06:06:43 +01:00
|
|
|
break;
|
|
|
|
case FT32_FLD_PA:
|
|
|
|
imm = (iword & ((1 << FT32_FLD_PA_SIZ) - 1)) << 2;
|
|
|
|
info->print_address_func ((bfd_vma) imm, info);
|
|
|
|
break;
|
|
|
|
case FT32_FLD_AA:
|
|
|
|
imm = iword & ((1 << FT32_FLD_AA_SIZ) - 1);
|
2017-08-31 04:51:49 +02:00
|
|
|
info->print_address_func ((1 << 23) | (bfd_vma) imm, info);
|
2015-01-28 06:06:43 +01:00
|
|
|
break;
|
|
|
|
case FT32_FLD_K16:
|
|
|
|
imm = iword & ((1 << FT32_FLD_K16_SIZ) - 1);
|
2017-08-31 04:51:49 +02:00
|
|
|
fpr(stream, "%d", imm);
|
2015-01-28 06:06:43 +01:00
|
|
|
break;
|
2017-10-13 03:37:40 +02:00
|
|
|
case FT32_FLD_K15:
|
|
|
|
imm = iword & ((1 << FT32_FLD_K15_SIZ) - 1);
|
|
|
|
fpr(stream, "%d", sign_extend(14, imm));
|
2015-01-28 06:06:43 +01:00
|
|
|
break;
|
|
|
|
case FT32_FLD_R_D_POST:
|
|
|
|
fpr(stream, "$r%d", (iword >> FT32_FLD_R_D_BIT) & 0x1f);
|
|
|
|
break;
|
|
|
|
case FT32_FLD_R_1_POST:
|
|
|
|
fpr(stream, "$r%d", (iword >> FT32_FLD_R_1_BIT) & 0x1f);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
f &= ~lobit;
|
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
fpr(stream, ",");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-13 03:37:40 +02:00
|
|
|
fpr (stream, "!");
|
2015-01-28 06:06:43 +01:00
|
|
|
}
|
2017-10-13 03:37:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
print_insn_ft32 (bfd_vma addr, struct disassemble_info *info)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
stream = info->stream;
|
|
|
|
bfd_byte buffer[4];
|
|
|
|
unsigned int iword;
|
|
|
|
|
|
|
|
fpr = info->fprintf_func;
|
|
|
|
|
|
|
|
if ((status = info->read_memory_func (addr, buffer, 4, info)))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
iword = bfd_getl32 (buffer);
|
|
|
|
|
|
|
|
fpr (stream, "%08x ", iword);
|
|
|
|
|
|
|
|
ft32_opcode(addr, iword, info);
|
2015-01-28 06:06:43 +01:00
|
|
|
|
|
|
|
return 4;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
info->memory_error_func (status, addr, info);
|
|
|
|
return -1;
|
|
|
|
}
|