1999-05-03 09:29:11 +02:00
|
|
|
/* Disassemble h8500 instructions.
|
2017-01-02 04:36:43 +01:00
|
|
|
Copyright (C) 1993-2017 Free Software Foundation, Inc.
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2007-07-05 11:49:03 +02:00
|
|
|
This file is part of the GNU opcodes library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify
|
2004-07-22 18:52:43 +02:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-07-05 11:49:03 +02:00
|
|
|
the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
any later version.
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2007-07-05 11:49:03 +02:00
|
|
|
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.
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2004-07-22 18:52:43 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2005-07-01 13:16:33 +02:00
|
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA. */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2012-05-17 17:13:28 +02:00
|
|
|
#include "sysdep.h"
|
1999-05-03 09:29:11 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define DISASSEMBLER_TABLE
|
|
|
|
#define DEFINE_TABLE
|
|
|
|
|
|
|
|
#include "h8500-opc.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"
|
1999-05-03 09:29:11 +02:00
|
|
|
#include "opintl.h"
|
|
|
|
|
|
|
|
/* Maximum length of an instruction. */
|
|
|
|
#define MAXLEN 8
|
|
|
|
|
|
|
|
#include <setjmp.h>
|
|
|
|
|
|
|
|
struct private
|
|
|
|
{
|
|
|
|
/* Points to first byte not fetched. */
|
|
|
|
bfd_byte *max_fetched;
|
|
|
|
bfd_byte the_buffer[MAXLEN];
|
|
|
|
bfd_vma insn_start;
|
2014-05-02 17:27:16 +02:00
|
|
|
OPCODES_SIGJMP_BUF bailout;
|
1999-05-03 09:29:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
|
|
|
|
to ADDR (exclusive) are valid. Returns 1 for success, longjmps
|
|
|
|
on error. */
|
|
|
|
#define FETCH_DATA(info, addr) \
|
|
|
|
((addr) <= ((struct private *)(info->private_data))->max_fetched \
|
|
|
|
? 1 : fetch_data ((info), (addr)))
|
|
|
|
|
|
|
|
static int
|
2005-07-01 13:16:33 +02:00
|
|
|
fetch_data (struct disassemble_info *info, bfd_byte *addr)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
struct private *priv = (struct private *) info->private_data;
|
|
|
|
bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
|
|
|
|
|
|
|
|
status = (*info->read_memory_func) (start,
|
|
|
|
priv->max_fetched,
|
|
|
|
addr - priv->max_fetched,
|
|
|
|
info);
|
|
|
|
if (status != 0)
|
|
|
|
{
|
|
|
|
(*info->memory_error_func) (status, start, info);
|
2014-05-02 17:27:16 +02:00
|
|
|
OPCODES_SIGLONGJMP (priv->bailout, 1);
|
1999-05-03 09:29:11 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
priv->max_fetched = addr;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-07-03 23:52:37 +02:00
|
|
|
static char *crname[] = { "sr", "ccr", "*", "br", "ep", "dp", "*", "tp" };
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
int
|
2005-07-01 13:16:33 +02:00
|
|
|
print_insn_h8500 (bfd_vma addr, disassemble_info *info)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
2002-12-02 14:13:37 +01:00
|
|
|
const h8500_opcode_info *opcode;
|
1999-05-03 09:29:11 +02:00
|
|
|
void *stream = info->stream;
|
|
|
|
fprintf_ftype func = info->fprintf_func;
|
|
|
|
struct private priv;
|
|
|
|
bfd_byte *buffer = priv.the_buffer;
|
|
|
|
|
|
|
|
info->private_data = (PTR) & priv;
|
|
|
|
priv.max_fetched = priv.the_buffer;
|
|
|
|
priv.insn_start = addr;
|
2014-05-02 17:27:16 +02:00
|
|
|
if (OPCODES_SIGSETJMP (priv.bailout) != 0)
|
1999-05-03 09:29:11 +02:00
|
|
|
/* Error return. */
|
|
|
|
return -1;
|
|
|
|
|
2000-07-03 23:52:37 +02:00
|
|
|
/* Run down the table to find the one which matches. */
|
1999-05-03 09:29:11 +02:00
|
|
|
for (opcode = h8500_table; opcode->name; opcode++)
|
|
|
|
{
|
|
|
|
int byte;
|
|
|
|
int rn = 0;
|
|
|
|
int rd = 0;
|
|
|
|
int rs = 0;
|
|
|
|
int disp = 0;
|
2009-12-11 14:42:17 +01:00
|
|
|
int abs_val = 0;
|
1999-05-03 09:29:11 +02:00
|
|
|
int imm = 0;
|
|
|
|
int pcrel = 0;
|
|
|
|
int qim = 0;
|
|
|
|
int i;
|
|
|
|
int cr = 0;
|
2000-07-03 23:52:37 +02:00
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
for (byte = 0; byte < opcode->length; byte++)
|
|
|
|
{
|
|
|
|
FETCH_DATA (info, buffer + byte + 1);
|
|
|
|
if ((buffer[byte] & opcode->bytes[byte].mask)
|
|
|
|
!= (opcode->bytes[byte].contents))
|
2005-07-01 13:16:33 +02:00
|
|
|
goto next;
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
else
|
|
|
|
{
|
2000-07-03 23:52:37 +02:00
|
|
|
/* Extract any info parts. */
|
1999-05-03 09:29:11 +02:00
|
|
|
switch (opcode->bytes[byte].insert)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case FP:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* xgettext:c-format */
|
|
|
|
func (stream, _("can't cope with insert %d\n"),
|
|
|
|
opcode->bytes[byte].insert);
|
|
|
|
break;
|
|
|
|
case RN:
|
|
|
|
rn = buffer[byte] & 0x7;
|
|
|
|
break;
|
|
|
|
case RS:
|
|
|
|
rs = buffer[byte] & 0x7;
|
|
|
|
break;
|
|
|
|
case CRB:
|
|
|
|
cr = buffer[byte] & 0x7;
|
|
|
|
if (cr == 0)
|
|
|
|
goto next;
|
|
|
|
break;
|
|
|
|
case CRW:
|
|
|
|
cr = buffer[byte] & 0x7;
|
|
|
|
if (cr != 0)
|
|
|
|
goto next;
|
|
|
|
break;
|
|
|
|
case DISP16:
|
|
|
|
FETCH_DATA (info, buffer + byte + 2);
|
|
|
|
disp = (buffer[byte] << 8) | (buffer[byte + 1]);
|
|
|
|
break;
|
|
|
|
case FPIND_D8:
|
|
|
|
case DISP8:
|
|
|
|
disp = ((char) (buffer[byte]));
|
|
|
|
break;
|
|
|
|
case RD:
|
|
|
|
case RDIND:
|
|
|
|
rd = buffer[byte] & 0x7;
|
|
|
|
break;
|
|
|
|
case ABS24:
|
|
|
|
FETCH_DATA (info, buffer + byte + 3);
|
2009-12-11 14:42:17 +01:00
|
|
|
abs_val =
|
1999-05-03 09:29:11 +02:00
|
|
|
(buffer[byte] << 16)
|
|
|
|
| (buffer[byte + 1] << 8)
|
|
|
|
| (buffer[byte + 2]);
|
|
|
|
break;
|
|
|
|
case ABS16:
|
|
|
|
FETCH_DATA (info, buffer + byte + 2);
|
2009-12-11 14:42:17 +01:00
|
|
|
abs_val = (buffer[byte] << 8) | (buffer[byte + 1]);
|
1999-05-03 09:29:11 +02:00
|
|
|
break;
|
|
|
|
case ABS8:
|
2009-12-11 14:42:17 +01:00
|
|
|
abs_val = (buffer[byte]);
|
1999-05-03 09:29:11 +02:00
|
|
|
break;
|
|
|
|
case IMM16:
|
|
|
|
FETCH_DATA (info, buffer + byte + 2);
|
|
|
|
imm = (buffer[byte] << 8) | (buffer[byte + 1]);
|
|
|
|
break;
|
|
|
|
case IMM4:
|
|
|
|
imm = (buffer[byte]) & 0xf;
|
|
|
|
break;
|
|
|
|
case IMM8:
|
|
|
|
case RLIST:
|
|
|
|
imm = (buffer[byte]);
|
|
|
|
break;
|
|
|
|
case PCREL16:
|
|
|
|
FETCH_DATA (info, buffer + byte + 2);
|
|
|
|
pcrel = (buffer[byte] << 8) | (buffer[byte + 1]);
|
|
|
|
break;
|
|
|
|
case PCREL8:
|
|
|
|
pcrel = (buffer[byte]);
|
|
|
|
break;
|
|
|
|
case QIM:
|
|
|
|
switch (buffer[byte] & 0x7)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
qim = 1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
qim = 2;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
qim = -1;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
qim = -2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-07-03 23:52:37 +02:00
|
|
|
/* We get here when all the masks have passed so we can output
|
|
|
|
the operands. */
|
1999-05-03 09:29:11 +02:00
|
|
|
FETCH_DATA (info, buffer + opcode->length);
|
|
|
|
(func) (stream, "%s\t", opcode->name);
|
|
|
|
for (i = 0; i < opcode->nargs; i++)
|
|
|
|
{
|
|
|
|
if (i)
|
|
|
|
(func) (stream, ",");
|
|
|
|
switch (opcode->arg_type[i])
|
|
|
|
{
|
|
|
|
case FP:
|
|
|
|
func (stream, "fp");
|
|
|
|
break;
|
|
|
|
case RNIND_D16:
|
|
|
|
func (stream, "@(0x%x:16,r%d)", disp, rn);
|
|
|
|
break;
|
|
|
|
case RNIND_D8:
|
|
|
|
func (stream, "@(0x%x:8 (%d),r%d)", disp & 0xff, disp, rn);
|
|
|
|
break;
|
|
|
|
case RDIND_D16:
|
|
|
|
func (stream, "@(0x%x:16,r%d)", disp, rd);
|
|
|
|
break;
|
|
|
|
case RDIND_D8:
|
|
|
|
func (stream, "@(0x%x:8 (%d), r%d)", disp & 0xff, disp, rd);
|
|
|
|
break;
|
|
|
|
case FPIND_D8:
|
Kaveh Ghazi's printf format attribute checking patch.
bfd:
* elf32-xtensa.c (vsprint_msg): Add format attribute. Fix
format bugs.
* vms.h (_bfd_vms_debug): Add format attribute.
(_bfd_vms_debug, _bfd_hexdump): Fix typos.
binutils:
* bucomm.h (report): Add format attribute.
* dlltool.c (inform): Likewise.
* dllwrap.c (display, inform, warn): Likewise.
* objdump.c (objdump_sprintf): Likewise.
* readelf.c (error, warn): Likewise. Fix format bugs.
gas:
* config/tc-tic30.c (debug): Add format attribute. Fix format
bugs.
include:
* dis-asm.h (fprintf_ftype): Add format attribute.
opcodes:
* arc-dis.c, arm-dis.c, cris-dis.c, crx-dis.c, d10v-dis.c,
d30v-dis.c, fr30-dis.c, h8300-dis.c, h8500-dis.c, i860-dis.c,
ia64-dis.c, ip2k-dis.c, m10200-dis.c, m10300-dis.c,
m88k-dis.c, mcore-dis.c, mips-dis.c, ms1-dis.c, or32-dis.c,
ppc-dis.c, sh64-dis.c, sparc-dis.c, tic4x-dis.c, tic80-dis.c,
v850-dis.c: Fix format bugs.
* ia64-gen.c (fail, warn): Add format attribute.
* or32-opc.c (debug): Likewise.
2005-07-07 21:27:52 +02:00
|
|
|
func (stream, "@(0x%x:8 (%d), fp)", disp & 0xff, disp);
|
1999-05-03 09:29:11 +02:00
|
|
|
break;
|
|
|
|
case CRB:
|
|
|
|
case CRW:
|
|
|
|
func (stream, "%s", crname[cr]);
|
|
|
|
break;
|
|
|
|
case RN:
|
|
|
|
func (stream, "r%d", rn);
|
|
|
|
break;
|
|
|
|
case RD:
|
|
|
|
func (stream, "r%d", rd);
|
|
|
|
break;
|
|
|
|
case RS:
|
|
|
|
func (stream, "r%d", rs);
|
|
|
|
break;
|
|
|
|
case RNDEC:
|
|
|
|
func (stream, "@-r%d", rn);
|
|
|
|
break;
|
|
|
|
case RNINC:
|
|
|
|
func (stream, "@r%d+", rn);
|
|
|
|
break;
|
|
|
|
case RNIND:
|
|
|
|
func (stream, "@r%d", rn);
|
|
|
|
break;
|
|
|
|
case RDIND:
|
|
|
|
func (stream, "@r%d", rd);
|
|
|
|
break;
|
|
|
|
case SPINC:
|
|
|
|
func (stream, "@sp+");
|
|
|
|
break;
|
|
|
|
case SPDEC:
|
|
|
|
func (stream, "@-sp");
|
|
|
|
break;
|
|
|
|
case ABS24:
|
2009-12-11 14:42:17 +01:00
|
|
|
func (stream, "@0x%0x:24", abs_val);
|
1999-05-03 09:29:11 +02:00
|
|
|
break;
|
|
|
|
case ABS16:
|
2009-12-11 14:42:17 +01:00
|
|
|
func (stream, "@0x%0x:16", abs_val & 0xffff);
|
1999-05-03 09:29:11 +02:00
|
|
|
break;
|
|
|
|
case ABS8:
|
2009-12-11 14:42:17 +01:00
|
|
|
func (stream, "@0x%0x:8", abs_val & 0xff);
|
1999-05-03 09:29:11 +02:00
|
|
|
break;
|
|
|
|
case IMM16:
|
|
|
|
func (stream, "#0x%0x:16", imm & 0xffff);
|
|
|
|
break;
|
|
|
|
case RLIST:
|
|
|
|
{
|
2009-12-11 14:42:17 +01:00
|
|
|
int j;
|
1999-05-03 09:29:11 +02:00
|
|
|
int nc = 0;
|
2005-07-01 13:16:33 +02:00
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
func (stream, "(");
|
2009-12-11 14:42:17 +01:00
|
|
|
for (j = 0; j < 8; j++)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
2009-12-11 14:42:17 +01:00
|
|
|
if (imm & (1 << j))
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
2009-12-11 14:42:17 +01:00
|
|
|
func (stream, "r%d", j);
|
1999-05-03 09:29:11 +02:00
|
|
|
if (nc)
|
|
|
|
func (stream, ",");
|
|
|
|
nc = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (stream, ")");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IMM8:
|
|
|
|
func (stream, "#0x%0x:8", imm & 0xff);
|
|
|
|
break;
|
|
|
|
case PCREL16:
|
2000-07-03 23:52:37 +02:00
|
|
|
func (stream, "0x%0x:16",
|
Kaveh Ghazi's printf format attribute checking patch.
bfd:
* elf32-xtensa.c (vsprint_msg): Add format attribute. Fix
format bugs.
* vms.h (_bfd_vms_debug): Add format attribute.
(_bfd_vms_debug, _bfd_hexdump): Fix typos.
binutils:
* bucomm.h (report): Add format attribute.
* dlltool.c (inform): Likewise.
* dllwrap.c (display, inform, warn): Likewise.
* objdump.c (objdump_sprintf): Likewise.
* readelf.c (error, warn): Likewise. Fix format bugs.
gas:
* config/tc-tic30.c (debug): Add format attribute. Fix format
bugs.
include:
* dis-asm.h (fprintf_ftype): Add format attribute.
opcodes:
* arc-dis.c, arm-dis.c, cris-dis.c, crx-dis.c, d10v-dis.c,
d30v-dis.c, fr30-dis.c, h8300-dis.c, h8500-dis.c, i860-dis.c,
ia64-dis.c, ip2k-dis.c, m10200-dis.c, m10300-dis.c,
m88k-dis.c, mcore-dis.c, mips-dis.c, ms1-dis.c, or32-dis.c,
ppc-dis.c, sh64-dis.c, sparc-dis.c, tic4x-dis.c, tic80-dis.c,
v850-dis.c: Fix format bugs.
* ia64-gen.c (fail, warn): Add format attribute.
* or32-opc.c (debug): Likewise.
2005-07-07 21:27:52 +02:00
|
|
|
(int)(pcrel + addr + opcode->length) & 0xffff);
|
1999-05-03 09:29:11 +02:00
|
|
|
break;
|
|
|
|
case PCREL8:
|
|
|
|
func (stream, "#0x%0x:8",
|
Kaveh Ghazi's printf format attribute checking patch.
bfd:
* elf32-xtensa.c (vsprint_msg): Add format attribute. Fix
format bugs.
* vms.h (_bfd_vms_debug): Add format attribute.
(_bfd_vms_debug, _bfd_hexdump): Fix typos.
binutils:
* bucomm.h (report): Add format attribute.
* dlltool.c (inform): Likewise.
* dllwrap.c (display, inform, warn): Likewise.
* objdump.c (objdump_sprintf): Likewise.
* readelf.c (error, warn): Likewise. Fix format bugs.
gas:
* config/tc-tic30.c (debug): Add format attribute. Fix format
bugs.
include:
* dis-asm.h (fprintf_ftype): Add format attribute.
opcodes:
* arc-dis.c, arm-dis.c, cris-dis.c, crx-dis.c, d10v-dis.c,
d30v-dis.c, fr30-dis.c, h8300-dis.c, h8500-dis.c, i860-dis.c,
ia64-dis.c, ip2k-dis.c, m10200-dis.c, m10300-dis.c,
m88k-dis.c, mcore-dis.c, mips-dis.c, ms1-dis.c, or32-dis.c,
ppc-dis.c, sh64-dis.c, sparc-dis.c, tic4x-dis.c, tic80-dis.c,
v850-dis.c: Fix format bugs.
* ia64-gen.c (fail, warn): Add format attribute.
* or32-opc.c (debug): Likewise.
2005-07-07 21:27:52 +02:00
|
|
|
(int)((char) pcrel + addr + opcode->length) & 0xffff);
|
1999-05-03 09:29:11 +02:00
|
|
|
break;
|
|
|
|
case QIM:
|
|
|
|
func (stream, "#%d:q", qim);
|
|
|
|
break;
|
|
|
|
case IMM4:
|
|
|
|
func (stream, "#%d:4", imm);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return opcode->length;
|
2000-07-03 23:52:37 +02:00
|
|
|
next:
|
|
|
|
;
|
1999-05-03 09:29:11 +02:00
|
|
|
}
|
|
|
|
|
2000-07-03 23:52:37 +02:00
|
|
|
/* Couldn't understand anything. */
|
1999-05-03 09:29:11 +02:00
|
|
|
/* xgettext:c-format */
|
|
|
|
func (stream, _("%02x\t\t*unknown*"), buffer[0]);
|
|
|
|
return 1;
|
|
|
|
}
|