binutils-gdb/opcodes/v850-dis.c

854 lines
20 KiB
C
Raw Normal View History

1999-05-03 15:29:11 +08:00
/* Disassemble V850 instructions.
Copyright (C) 1996-2021 Free Software Foundation, Inc.
1999-05-03 15:29:11 +08:00
2007-07-05 17:49:03 +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
2007-07-05 17:49:03 +08:00
the Free Software Foundation; either version 3, or (at your option)
any later version.
1999-05-03 15:29:11 +08:00
2007-07-05 17:49:03 +08: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 15:29:11 +08:00
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. */
1999-05-03 15:29:11 +08:00
#include "sysdep.h"
PR 14072 * configure.in: Add check that sysdep.h has been included before any system header files. * configure: Regenerate. * config.in: Regenerate. * sysdep.h: Generate an error if included before config.h. * alpha-opc.c: Include sysdep.h before any other header file. * alpha-dis.c: Likewise. * avr-dis.c: Likewise. * cgen-opc.c: Likewise. * cr16-dis.c: Likewise. * cris-dis.c: Likewise. * crx-dis.c: Likewise. * d10v-dis.c: Likewise. * d10v-opc.c: Likewise. * d30v-dis.c: Likewise. * d30v-opc.c: Likewise. * h8500-dis.c: Likewise. * i370-dis.c: Likewise. * i370-opc.c: Likewise. * m10200-dis.c: Likewise. * m10300-dis.c: Likewise. * micromips-opc.c: Likewise. * mips-opc.c: Likewise. * mips61-opc.c: Likewise. * moxie-dis.c: Likewise. * or32-opc.c: Likewise. * pj-dis.c: Likewise. * ppc-dis.c: Likewise. * ppc-opc.c: Likewise. * s390-dis.c: Likewise. * sh-dis.c: Likewise. * sh64-dis.c: Likewise. * sparc-dis.c: Likewise. * sparc-opc.c: Likewise. * spu-dis.c: Likewise. * tic30-dis.c: Likewise. * tic54x-dis.c: Likewise. * tic80-dis.c: Likewise. * tic80-opc.c: Likewise. * tilegx-dis.c: Likewise. * tilepro-dis.c: Likewise. * v850-dis.c: Likewise. * v850-opc.c: Likewise. * vax-dis.c: Likewise. * w65-dis.c: Likewise. * xgate-dis.c: Likewise. * xtensa-dis.c: Likewise. * rl78-decode.opc: Likewise. * rl78-decode.c: Regenerate. * rx-decode.opc: Likewise. * rx-decode.c: Regenerate. * configure.in: Add check that sysdep.h has been included before any system header files. * configure: Regenerate. * config.in: Regenerate. * sysdep.h: Generate an error if included before config.h. * configure.in: Add check that sysdep.h has been included before any system header files. * configure: Regenerate. * config.in: Regenerate. * aclocal.m4: Regenerate. * bfd-in.h: Generate an error if included before config.h. * sysdep.h: Likewise. * bfd-in2.h: Regenerate. * compress.c: Remove #include "config.h". * plugin.c: Likewise. * elf32-m68hc1x.c: Include sysdep.h before alloca-conf.h. * elf64-hppa.c: Likewise. * som.c: Likewise. * xsymc.c: Likewise. * configure.in: Add check that sysdep.h has been included before any system header files. * configure: Regenerate. * config.in: Regenerate. * configure.in: Add check that sysdep.h has been included before any system header files. * configure: Regenerate. * config.in: Regenerate. * aclocal.m4: Regenerate. * Makefile.am: Use wrappers around C files generated by flex. * Makefile.in: Regenerate. * doc/Makefile.in: Regenerate. * itbl-lex-wrapper.c: New file. * config/bfin-lex-wrapper.c: New file. * cgen.c: Include as.h before setjmp.h. * config/tc-dlx.c: Include as.h before any other header. * config/tc-h8300.c: Likewise. * config/tc-lm32.c: Likewise. * config/tc-mep.c: Likewise. * config/tc-microblaze.c: Likewise. * config/tc-mmix.c: Likewise. * config/tc-msp430.c: Likewise. * config/tc-or32.c: Likewise. * config/tc-tic4x.c: Likewise. * config/tc-tic54x.c: Likewise. * config/tc-xtensa.c: Likewise. * configure.in: Add check that sysdep.h has been included before any system header files. * configure: Regenerate. * config.in: Regenerate. * unwind-ia64.h: Include config.h.
2012-05-17 23:13:28 +08:00
#include <stdio.h>
2013-01-24 19:14:05 +08:00
#include <string.h>
#include "opcode/v850.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"
1999-05-03 15:29:11 +08:00
#include "opintl.h"
#include "libiberty.h"
2013-01-24 19:14:05 +08:00
static const int v850_cacheop_codes[] =
2013-01-24 19:14:05 +08:00
{
0x00, 0x20, 0x40, 0x60, 0x61, 0x04, 0x06,
0x07, 0x24, 0x26, 0x27, 0x44, 0x64, 0x65, -1
};
static const int v850_prefop_codes[] =
2013-01-24 19:14:05 +08:00
{ 0x00, 0x04, -1};
2010-07-23 22:52:54 +08:00
static void
2013-01-24 19:14:05 +08:00
print_value (int flags,
bfd_vma memaddr,
struct disassemble_info *info,
long value)
2010-07-23 22:52:54 +08:00
{
if (flags & V850_PCREL)
{
bfd_vma addr = value + memaddr;
if (flags & V850_INVERSE_PCREL)
addr = memaddr - value;
2010-07-23 22:52:54 +08:00
info->print_address_func (addr, info);
}
else if (flags & V850_OPERAND_DISP)
{
if (flags & V850_OPERAND_SIGNED)
{
info->fprintf_func (info->stream, "%ld", value);
}
else
{
info->fprintf_func (info->stream, "%lu", value);
}
}
2013-01-24 19:14:05 +08:00
else if ((flags & V850E_IMMEDIATE32)
|| (flags & V850E_IMMEDIATE16HI))
2010-07-23 22:52:54 +08:00
{
info->fprintf_func (info->stream, "0x%lx", value);
}
else
{
if (flags & V850_OPERAND_SIGNED)
{
info->fprintf_func (info->stream, "%ld", value);
}
else
{
info->fprintf_func (info->stream, "%lu", value);
}
}
}
2010-07-23 22:52:54 +08:00
static long
get_operand_value (const struct v850_operand *operand,
unsigned long insn,
int bytes_read,
bfd_vma memaddr,
struct disassemble_info * info,
bfd_boolean noerror,
int *invalid)
{
unsigned long value;
2010-07-23 22:52:54 +08:00
bfd_byte buffer[4];
if ((operand->flags & V850E_IMMEDIATE16)
|| (operand->flags & V850E_IMMEDIATE16HI))
{
int status = info->read_memory_func (memaddr + bytes_read, buffer, 2, info);
if (status == 0)
{
value = bfd_getl16 (buffer);
if (operand->flags & V850E_IMMEDIATE16HI)
value <<= 16;
else if (value & 0x8000)
Fix compile time warnings generated when compiling with clang. bfd * bout.c (b_out_slurp_reloc_table): Cast constant to unsigned in order to avoid problems with left shifting negative values. (abs32code): Likewise. * mach-o.c (FILE_ALIGN): Likewise. * coff-rs6000.c (xcoff_debug_sections): Delete unused static array. * elf32-visium.c (visium_reloc_map): Likewise. * elf32-arm.c (elf32_arm_final_link_relocate): Remove useless calls to abs function. * elf32-frv.c (_frvfdpic_relax_tls_entries): Likewise. * elf32-score.c (score_elf_final_link_relocate): Likewise. * elf32-score7.c (score_elf_final_link_relocate): Likewise. * elf32-i860.c (i860_howto_pc26_reloc): Use multiplication instead of shifting to create a negative mask. * elf32-msp430.c (elf_backend_special_sections): Define. * elfxx-mips.c (got_ofst_reloc_p): Delete unused function. (got_hi16_reloc_p): Delete unused function. * ppcboot.c (ppcboot_bfd_print_private_bfd_data): Fix test of partition name. gas * config/tc-ppc.c (insn_validate): Cast PPC_OPSHIFT_INV to an int. opcode * ppc.h (PPC_OPSHIFT_INV): Use an unsigned constant when left shifting. ld * emultempl/elf32.em (ehdr_start_empty): New static variable. (before_allocation): Use it to initialise ehdr_start_save. * emultempl/pe.em (write_build_id): Remove useless double parenthesis. * emultempl/pep.em (write_build_id): Likewise. opcodes * bfin-dis.c (fmtconst): Remove unnecessary call to the abs function. * tic30-dis.c (print_branch): Likewise. * cgen-asm.c (cgen_parse_signed_integer): Cast integer to signed value before left shifting. * fr30-ibld.c (fr30_cgen_extract_operand): Likewise. * hppa-dis.c (print_insn_hppa): Likewise. * mips-dis.c (mips_cp0sel_names_mipsr5900): Delete unused static array. * msp430-dis.c (msp430_singleoperand): Likewise. (msp430_doubleoperand): Likewise. (print_insn_msp430): Likewise. * nds32-asm.c (parse_operand): Likewise. * sh-opc.h (MASK): Likewise. * v850-dis.c (get_operand_value): Likewise.
2015-09-24 01:05:16 +08:00
value |= (-1UL << 16);
2010-07-23 22:52:54 +08:00
return value;
}
if (!noerror)
info->memory_error_func (status, memaddr + bytes_read, info);
return 0;
}
if (operand->flags & V850E_IMMEDIATE23)
{
int status = info->read_memory_func (memaddr + 2, buffer, 4, info);
if (status == 0)
{
value = bfd_getl32 (buffer);
value = (operand->extract) (value, invalid);
return value;
}
if (!noerror)
info->memory_error_func (status, memaddr + bytes_read, info);
return 0;
}
if (operand->flags & V850E_IMMEDIATE32)
{
int status = info->read_memory_func (memaddr + bytes_read, buffer, 4, info);
if (status == 0)
{
bytes_read += 4;
value = bfd_getl32 (buffer);
return value;
}
if (!noerror)
info->memory_error_func (status, memaddr + bytes_read, info);
return 0;
}
if (operand->extract)
value = (operand->extract) (insn, invalid);
else
{
if (operand->bits == -1)
value = (insn & operand->shift);
else
value = (insn >> operand->shift) & ((1ul << operand->bits) - 1);
2010-07-23 22:52:54 +08:00
if (operand->flags & V850_OPERAND_SIGNED)
{
unsigned long sign = 1ul << (operand->bits - 1);
value = (value ^ sign) - sign;
}
2010-07-23 22:52:54 +08:00
}
return value;
}
static const char *
get_v850_sreg_name (unsigned int reg)
{
static const char *const v850_sreg_names[] =
{
"eipc/vip/mpm", "eipsw/mpc", "fepc/tid", "fepsw/ppa", "ecr/vmecr", "psw/vmtid",
"sr6/fpsr/vmadr/dcc", "sr7/fpepc/dc0",
"sr8/fpst/vpecr/dcv1", "sr9/fpcc/vptid", "sr10/fpcfg/vpadr/spal", "sr11/spau",
"sr12/vdecr/ipa0l", "eiic/vdtid/ipa0u", "feic/ipa1l", "dbic/ipa1u",
"ctpc/ipa2l", "ctpsw/ipa2u", "dbpc/ipa3l", "dbpsw/ipa3u", "ctbp/dpa0l",
"dir/dpa0u", "bpc/dpa0u", "asid/dpa1l",
"bpav/dpa1u", "bpam/dpa2l", "bpdv/dpa2u", "bpdm/dpa3l", "eiwr/dpa3u",
"fewr", "dbwr", "bsel"
};
if (reg < ARRAY_SIZE (v850_sreg_names))
return v850_sreg_names[reg];
return _("<invalid s-reg number>");
}
static const char *
get_v850_reg_name (unsigned int reg)
{
static const char *const v850_reg_names[] =
{
"r0", "r1", "r2", "sp", "gp", "r5", "r6", "r7",
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
"r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
"r24", "r25", "r26", "r27", "r28", "r29", "ep", "lp"
};
if (reg < ARRAY_SIZE (v850_reg_names))
return v850_reg_names[reg];
return _("<invalid reg number>");
}
static const char *
get_v850_vreg_name (unsigned int reg)
{
static const char *const v850_vreg_names[] =
{
"vr0", "vr1", "vr2", "vr3", "vr4", "vr5", "vr6", "vr7", "vr8", "vr9",
"vr10", "vr11", "vr12", "vr13", "vr14", "vr15", "vr16", "vr17", "vr18",
"vr19", "vr20", "vr21", "vr22", "vr23", "vr24", "vr25", "vr26", "vr27",
"vr28", "vr29", "vr30", "vr31"
};
if (reg < ARRAY_SIZE (v850_vreg_names))
return v850_vreg_names[reg];
return _("<invalid v-reg number>");
}
static const char *
get_v850_cc_name (unsigned int reg)
{
static const char *const v850_cc_names[] =
{
"v", "c/l", "z", "nh", "s/n", "t", "lt", "le",
"nv", "nc/nl", "nz", "h", "ns/p", "sa", "ge", "gt"
};
if (reg < ARRAY_SIZE (v850_cc_names))
return v850_cc_names[reg];
return _("<invalid CC-reg number>");
}
static const char *
get_v850_float_cc_name (unsigned int reg)
{
static const char *const v850_float_cc_names[] =
{
"f/t", "un/or", "eq/neq", "ueq/ogl", "olt/uge", "ult/oge", "ole/ugt", "ule/ogt",
"sf/st", "ngle/gle", "seq/sne", "ngl/gl", "lt/nlt", "nge/ge", "le/nle", "ngt/gt"
};
if (reg < ARRAY_SIZE (v850_float_cc_names))
return v850_float_cc_names[reg];
return _("<invalid float-CC-reg number>");
}
static const char *
get_v850_cacheop_name (unsigned int reg)
{
static const char *const v850_cacheop_names[] =
{
"chbii", "cibii", "cfali", "cisti", "cildi", "chbid", "chbiwbd",
"chbwbd", "cibid", "cibiwbd", "cibwbd", "cfald", "cistd", "cildd"
};
if (reg < ARRAY_SIZE (v850_cacheop_names))
return v850_cacheop_names[reg];
return _("<invalid cacheop number>");
}
static const char *
get_v850_prefop_name (unsigned int reg)
{
static const char *const v850_prefop_names[] =
{ "prefi", "prefd" };
if (reg < ARRAY_SIZE (v850_prefop_names))
return v850_prefop_names[reg];
return _("<invalid prefop number>");
}
2010-07-23 22:52:54 +08:00
static int
2013-01-24 19:14:05 +08:00
disassemble (bfd_vma memaddr,
struct disassemble_info *info,
int bytes_read,
unsigned long insn)
2010-07-23 22:52:54 +08:00
{
2013-01-24 19:14:05 +08:00
struct v850_opcode *op = (struct v850_opcode *) v850_opcodes;
2010-07-23 22:52:54 +08:00
const struct v850_operand *operand;
int match = 0;
int target_processor;
1999-05-03 15:29:11 +08:00
switch (info->mach)
{
case 0:
default:
target_processor = PROCESSOR_V850;
break;
case bfd_mach_v850e:
target_processor = PROCESSOR_V850E;
break;
case bfd_mach_v850e1:
2010-07-23 22:52:54 +08:00
target_processor = PROCESSOR_V850E;
break;
case bfd_mach_v850e2:
target_processor = PROCESSOR_V850E2;
break;
case bfd_mach_v850e2v3:
target_processor = PROCESSOR_V850E2V3;
break;
2013-01-24 19:14:05 +08:00
case bfd_mach_v850e3v5:
target_processor = PROCESSOR_V850E3V5;
break;
1999-05-03 15:29:11 +08:00
}
2010-07-23 22:52:54 +08:00
/* If this is a two byte insn, then mask off the high bits. */
if (bytes_read == 2)
insn &= 0xffff;
1999-05-03 15:29:11 +08:00
/* Find the opcode. */
while (op->name)
{
if ((op->mask & insn) == op->opcode
2010-07-23 22:52:54 +08:00
&& (op->processors & target_processor)
&& !(op->processors & PROCESSOR_OPTION_ALIAS))
1999-05-03 15:29:11 +08:00
{
2010-07-23 22:52:54 +08:00
/* Code check start. */
const unsigned char *opindex_ptr;
unsigned int opnum;
unsigned int memop;
1999-05-03 15:29:11 +08:00
2010-07-23 22:52:54 +08:00
for (opindex_ptr = op->operands, opnum = 1;
*opindex_ptr != 0;
opindex_ptr++, opnum++)
{
int invalid = 0;
long value;
operand = &v850_operands[*opindex_ptr];
2013-01-24 19:14:05 +08:00
value = get_operand_value (operand, insn, bytes_read, memaddr,
info, 1, &invalid);
2010-07-23 22:52:54 +08:00
if (invalid)
goto next_opcode;
if ((operand->flags & V850_NOT_R0) && value == 0 && (op->memop) <=2)
goto next_opcode;
if ((operand->flags & V850_NOT_SA) && value == 0xd)
goto next_opcode;
if ((operand->flags & V850_NOT_IMM0) && value == 0)
goto next_opcode;
}
/* Code check end. */
1999-05-03 15:29:11 +08:00
match = 1;
(*info->fprintf_func) (info->stream, "%s\t", op->name);
2010-07-23 22:52:54 +08:00
#if 0
fprintf (stderr, "match: insn: %lx, mask: %lx, opcode: %lx, name: %s\n",
insn, op->mask, op->opcode, op->name );
#endif
1999-05-03 15:29:11 +08:00
memop = op->memop;
/* Now print the operands.
MEMOP is the operand number at which a memory
address specification starts, or zero if this
instruction has no memory addresses.
A memory address is always two arguments.
This information allows us to determine when to
insert commas into the output stream as well as
when to insert disp[reg] expressions onto the
output stream. */
1999-05-03 15:29:11 +08:00
for (opindex_ptr = op->operands, opnum = 1;
*opindex_ptr != 0;
opindex_ptr++, opnum++)
{
bfd_boolean square = FALSE;
long value;
int flag;
2010-07-23 22:52:54 +08:00
char *prefix;
1999-05-03 15:29:11 +08:00
operand = &v850_operands[*opindex_ptr];
2013-01-24 19:14:05 +08:00
value = get_operand_value (operand, insn, bytes_read, memaddr,
info, 0, 0);
1999-05-03 15:29:11 +08:00
/* The first operand is always output without any
special handling.
For the following arguments:
If memop && opnum == memop + 1, then we need '[' since
we're about to output the register used in a memory
reference.
If memop && opnum == memop + 2, then we need ']' since
we just finished the register in a memory reference. We
also need a ',' before this operand.
Else we just need a comma.
We may need to output a trailing ']' if the last operand
in an instruction is the register for a memory address.
1999-05-03 15:29:11 +08:00
The exception (and there's always an exception) are the
1999-05-03 15:29:11 +08:00
"jmp" insn which needs square brackets around it's only
register argument, and the clr1/not1/set1/tst1 insns
which [...] around their second register argument. */
2010-07-23 22:52:54 +08:00
prefix = "";
if (operand->flags & V850_OPERAND_BANG)
{
prefix = "!";
}
else if (operand->flags & V850_OPERAND_PERCENT)
{
prefix = "%";
}
1999-05-03 15:29:11 +08:00
2010-07-23 22:52:54 +08:00
if (opnum == 1 && opnum == memop)
{
info->fprintf_func (info->stream, "%s[", prefix);
square = TRUE;
}
2013-01-24 19:14:05 +08:00
else if ( (strcmp ("stc.w", op->name) == 0
|| strcmp ("cache", op->name) == 0
|| strcmp ("pref", op->name) == 0)
&& opnum == 2 && opnum == memop)
{
info->fprintf_func (info->stream, ", [");
square = TRUE;
}
else if ( (strcmp (op->name, "pushsp") == 0
|| strcmp (op->name, "popsp") == 0
|| strcmp (op->name, "dbpush" ) == 0)
&& opnum == 2)
{
info->fprintf_func (info->stream, "-");
}
2010-07-23 22:52:54 +08:00
else if (opnum > 1
2013-01-24 19:14:05 +08:00
&& (v850_operands[*(opindex_ptr - 1)].flags
& V850_OPERAND_DISP) != 0
2010-07-23 22:52:54 +08:00
&& opnum == memop)
{
info->fprintf_func (info->stream, "%s[", prefix);
square = TRUE;
}
else if (opnum == 2
&& ( op->opcode == 0x00e407e0 /* clr1 */
|| op->opcode == 0x00e207e0 /* not1 */
|| op->opcode == 0x00e007e0 /* set1 */
|| op->opcode == 0x00e607e0 /* tst1 */
))
{
info->fprintf_func (info->stream, ", %s[", prefix);
square = TRUE;
}
2010-07-23 22:52:54 +08:00
else if (opnum > 1)
info->fprintf_func (info->stream, ", %s", prefix);
2013-01-24 19:14:05 +08:00
/* Extract the flags, ignoring ones which do not
effect disassembly output. */
2010-07-23 22:52:54 +08:00
flag = operand->flags & (V850_OPERAND_REG
| V850_REG_EVEN
| V850_OPERAND_EP
| V850_OPERAND_SRG
| V850E_OPERAND_REG_LIST
| V850_OPERAND_CC
2013-01-24 19:14:05 +08:00
| V850_OPERAND_VREG
| V850_OPERAND_CACHEOP
| V850_OPERAND_PREFOP
2010-07-23 22:52:54 +08:00
| V850_OPERAND_FLOAT_CC);
1999-05-03 15:29:11 +08:00
switch (flag)
{
2013-01-24 19:14:05 +08:00
case V850_OPERAND_REG:
info->fprintf_func (info->stream, "%s", get_v850_reg_name (value));
2013-01-24 19:14:05 +08:00
break;
case (V850_OPERAND_REG|V850_REG_EVEN):
info->fprintf_func (info->stream, "%s", get_v850_reg_name (value * 2));
2013-01-24 19:14:05 +08:00
break;
case V850_OPERAND_EP:
info->fprintf_func (info->stream, "ep");
break;
case V850_OPERAND_SRG:
info->fprintf_func (info->stream, "%s", get_v850_sreg_name (value));
2013-01-24 19:14:05 +08:00
break;
2010-07-23 22:52:54 +08:00
case V850E_OPERAND_REG_LIST:
1999-05-03 15:29:11 +08:00
{
2010-07-23 22:52:54 +08:00
static int list12_regs[32] = { 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24 };
int *regs;
int i;
unsigned int mask = 0;
int pc = 0;
2010-07-23 22:52:54 +08:00
1999-05-03 15:29:11 +08:00
switch (operand->shift)
{
case 0xffe00001: regs = list12_regs; break;
default:
/* xgettext:c-format */
opcodes error messages Another patch aimed at making binutils comply with the GNU coding standard. The generated files require https://sourceware.org/ml/cgen/2018-q1/msg00004.html cpu/ * frv.opc: Include opintl.h. (add_next_to_vliw): Use opcodes_error_handler to print error. Standardize error message. (fr500_check_insn_major_constraints, frv_vliw_add_insn): Likewise. opcodes/ * sysdep.h (opcodes_error_handler): Define. (_bfd_error_handler): Declare. * Makefile.am: Remove stray #. * opc2c.c (main): Remove bogus -l arg handling. Print "DO NOT EDIT" comment. * aarch64-dis.c, * arc-dis.c, * arm-dis.c, * avr-dis.c, * d30v-dis.c, * h8300-dis.c, * mmix-dis.c, * ppc-dis.c, * riscv-dis.c, * s390-dis.c, * sparc-dis.c, * v850-dis.c: Use opcodes_error_handler to print errors. Standardize error messages. * msp430-decode.opc, * nios2-dis.c, * rl78-decode.opc: Likewise, and include opintl.h. * nds32-asm.c: Likewise, and include sysdep.h and opintl.h. * i386-gen.c: Standardize error messages. * msp430-decode.c, * rl78-decode.c, rx-decode.c: Regenerate. * Makefile.in: Regenerate. * epiphany-asm.c, * epiphany-desc.c, * epiphany-dis.c, * epiphany-ibld.c, * fr30-asm.c, * fr30-desc.c, * fr30-dis.c, * fr30-ibld.c, * frv-asm.c, * frv-desc.c, * frv-dis.c, * frv-ibld.c, * frv-opc.c, * ip2k-asm.c, * ip2k-desc.c, * ip2k-dis.c, * ip2k-ibld.c, * iq2000-asm.c, * iq2000-desc.c, * iq2000-dis.c, * iq2000-ibld.c, * lm32-asm.c, * lm32-desc.c, * lm32-dis.c, * lm32-ibld.c, * m32c-asm.c, * m32c-desc.c, * m32c-dis.c, * m32c-ibld.c, * m32r-asm.c, * m32r-desc.c, * m32r-dis.c, * m32r-ibld.c, * mep-asm.c, * mep-desc.c, * mep-dis.c, * mep-ibld.c, * mt-asm.c, * mt-desc.c, * mt-dis.c, * mt-ibld.c, * or1k-asm.c, * or1k-desc.c, * or1k-dis.c, * or1k-ibld.c, * xc16x-asm.c, * xc16x-desc.c, * xc16x-dis.c, * xc16x-ibld.c, * xstormy16-asm.c, * xstormy16-desc.c, * xstormy16-dis.c, * xstormy16-ibld.c: Regenerate.
2018-03-02 05:53:50 +08:00
opcodes_error_handler (_("unknown operand shift: %x"),
operand->shift);
abort ();
1999-05-03 15:29:11 +08:00
}
for (i = 0; i < 32; i++)
{
if (value & (1u << i))
1999-05-03 15:29:11 +08:00
{
switch (regs[ i ])
{
opcodes error messages Another patch aimed at making binutils comply with the GNU coding standard. The generated files require https://sourceware.org/ml/cgen/2018-q1/msg00004.html cpu/ * frv.opc: Include opintl.h. (add_next_to_vliw): Use opcodes_error_handler to print error. Standardize error message. (fr500_check_insn_major_constraints, frv_vliw_add_insn): Likewise. opcodes/ * sysdep.h (opcodes_error_handler): Define. (_bfd_error_handler): Declare. * Makefile.am: Remove stray #. * opc2c.c (main): Remove bogus -l arg handling. Print "DO NOT EDIT" comment. * aarch64-dis.c, * arc-dis.c, * arm-dis.c, * avr-dis.c, * d30v-dis.c, * h8300-dis.c, * mmix-dis.c, * ppc-dis.c, * riscv-dis.c, * s390-dis.c, * sparc-dis.c, * v850-dis.c: Use opcodes_error_handler to print errors. Standardize error messages. * msp430-decode.opc, * nios2-dis.c, * rl78-decode.opc: Likewise, and include opintl.h. * nds32-asm.c: Likewise, and include sysdep.h and opintl.h. * i386-gen.c: Standardize error messages. * msp430-decode.c, * rl78-decode.c, rx-decode.c: Regenerate. * Makefile.in: Regenerate. * epiphany-asm.c, * epiphany-desc.c, * epiphany-dis.c, * epiphany-ibld.c, * fr30-asm.c, * fr30-desc.c, * fr30-dis.c, * fr30-ibld.c, * frv-asm.c, * frv-desc.c, * frv-dis.c, * frv-ibld.c, * frv-opc.c, * ip2k-asm.c, * ip2k-desc.c, * ip2k-dis.c, * ip2k-ibld.c, * iq2000-asm.c, * iq2000-desc.c, * iq2000-dis.c, * iq2000-ibld.c, * lm32-asm.c, * lm32-desc.c, * lm32-dis.c, * lm32-ibld.c, * m32c-asm.c, * m32c-desc.c, * m32c-dis.c, * m32c-ibld.c, * m32r-asm.c, * m32r-desc.c, * m32r-dis.c, * m32r-ibld.c, * mep-asm.c, * mep-desc.c, * mep-dis.c, * mep-ibld.c, * mt-asm.c, * mt-desc.c, * mt-dis.c, * mt-ibld.c, * or1k-asm.c, * or1k-desc.c, * or1k-dis.c, * or1k-ibld.c, * xc16x-asm.c, * xc16x-desc.c, * xc16x-dis.c, * xc16x-ibld.c, * xstormy16-asm.c, * xstormy16-desc.c, * xstormy16-dis.c, * xstormy16-ibld.c: Regenerate.
2018-03-02 05:53:50 +08:00
default:
mask |= (1u << regs[ i ]);
opcodes error messages Another patch aimed at making binutils comply with the GNU coding standard. The generated files require https://sourceware.org/ml/cgen/2018-q1/msg00004.html cpu/ * frv.opc: Include opintl.h. (add_next_to_vliw): Use opcodes_error_handler to print error. Standardize error message. (fr500_check_insn_major_constraints, frv_vliw_add_insn): Likewise. opcodes/ * sysdep.h (opcodes_error_handler): Define. (_bfd_error_handler): Declare. * Makefile.am: Remove stray #. * opc2c.c (main): Remove bogus -l arg handling. Print "DO NOT EDIT" comment. * aarch64-dis.c, * arc-dis.c, * arm-dis.c, * avr-dis.c, * d30v-dis.c, * h8300-dis.c, * mmix-dis.c, * ppc-dis.c, * riscv-dis.c, * s390-dis.c, * sparc-dis.c, * v850-dis.c: Use opcodes_error_handler to print errors. Standardize error messages. * msp430-decode.opc, * nios2-dis.c, * rl78-decode.opc: Likewise, and include opintl.h. * nds32-asm.c: Likewise, and include sysdep.h and opintl.h. * i386-gen.c: Standardize error messages. * msp430-decode.c, * rl78-decode.c, rx-decode.c: Regenerate. * Makefile.in: Regenerate. * epiphany-asm.c, * epiphany-desc.c, * epiphany-dis.c, * epiphany-ibld.c, * fr30-asm.c, * fr30-desc.c, * fr30-dis.c, * fr30-ibld.c, * frv-asm.c, * frv-desc.c, * frv-dis.c, * frv-ibld.c, * frv-opc.c, * ip2k-asm.c, * ip2k-desc.c, * ip2k-dis.c, * ip2k-ibld.c, * iq2000-asm.c, * iq2000-desc.c, * iq2000-dis.c, * iq2000-ibld.c, * lm32-asm.c, * lm32-desc.c, * lm32-dis.c, * lm32-ibld.c, * m32c-asm.c, * m32c-desc.c, * m32c-dis.c, * m32c-ibld.c, * m32r-asm.c, * m32r-desc.c, * m32r-dis.c, * m32r-ibld.c, * mep-asm.c, * mep-desc.c, * mep-dis.c, * mep-ibld.c, * mt-asm.c, * mt-desc.c, * mt-dis.c, * mt-ibld.c, * or1k-asm.c, * or1k-desc.c, * or1k-dis.c, * or1k-ibld.c, * xc16x-asm.c, * xc16x-desc.c, * xc16x-dis.c, * xc16x-ibld.c, * xstormy16-asm.c, * xstormy16-desc.c, * xstormy16-dis.c, * xstormy16-ibld.c: Regenerate.
2018-03-02 05:53:50 +08:00
break;
case 0:
1999-05-03 15:29:11 +08:00
/* xgettext:c-format */
opcodes error messages Another patch aimed at making binutils comply with the GNU coding standard. The generated files require https://sourceware.org/ml/cgen/2018-q1/msg00004.html cpu/ * frv.opc: Include opintl.h. (add_next_to_vliw): Use opcodes_error_handler to print error. Standardize error message. (fr500_check_insn_major_constraints, frv_vliw_add_insn): Likewise. opcodes/ * sysdep.h (opcodes_error_handler): Define. (_bfd_error_handler): Declare. * Makefile.am: Remove stray #. * opc2c.c (main): Remove bogus -l arg handling. Print "DO NOT EDIT" comment. * aarch64-dis.c, * arc-dis.c, * arm-dis.c, * avr-dis.c, * d30v-dis.c, * h8300-dis.c, * mmix-dis.c, * ppc-dis.c, * riscv-dis.c, * s390-dis.c, * sparc-dis.c, * v850-dis.c: Use opcodes_error_handler to print errors. Standardize error messages. * msp430-decode.opc, * nios2-dis.c, * rl78-decode.opc: Likewise, and include opintl.h. * nds32-asm.c: Likewise, and include sysdep.h and opintl.h. * i386-gen.c: Standardize error messages. * msp430-decode.c, * rl78-decode.c, rx-decode.c: Regenerate. * Makefile.in: Regenerate. * epiphany-asm.c, * epiphany-desc.c, * epiphany-dis.c, * epiphany-ibld.c, * fr30-asm.c, * fr30-desc.c, * fr30-dis.c, * fr30-ibld.c, * frv-asm.c, * frv-desc.c, * frv-dis.c, * frv-ibld.c, * frv-opc.c, * ip2k-asm.c, * ip2k-desc.c, * ip2k-dis.c, * ip2k-ibld.c, * iq2000-asm.c, * iq2000-desc.c, * iq2000-dis.c, * iq2000-ibld.c, * lm32-asm.c, * lm32-desc.c, * lm32-dis.c, * lm32-ibld.c, * m32c-asm.c, * m32c-desc.c, * m32c-dis.c, * m32c-ibld.c, * m32r-asm.c, * m32r-desc.c, * m32r-dis.c, * m32r-ibld.c, * mep-asm.c, * mep-desc.c, * mep-dis.c, * mep-ibld.c, * mt-asm.c, * mt-desc.c, * mt-dis.c, * mt-ibld.c, * or1k-asm.c, * or1k-desc.c, * or1k-dis.c, * or1k-ibld.c, * xc16x-asm.c, * xc16x-desc.c, * xc16x-dis.c, * xc16x-ibld.c, * xstormy16-asm.c, * xstormy16-desc.c, * xstormy16-dis.c, * xstormy16-ibld.c: Regenerate.
2018-03-02 05:53:50 +08:00
opcodes_error_handler (_("unknown reg: %d"), i);
abort ();
break;
case -1:
pc = 1;
break;
1999-05-03 15:29:11 +08:00
}
}
}
info->fprintf_func (info->stream, "{");
2010-07-23 22:52:54 +08:00
if (mask || pc)
1999-05-03 15:29:11 +08:00
{
if (mask)
{
unsigned int bit;
int shown_one = 0;
1999-05-03 15:29:11 +08:00
for (bit = 0; bit < 32; bit++)
if (mask & (1u << bit))
1999-05-03 15:29:11 +08:00
{
unsigned int first = bit;
unsigned int last;
1999-05-03 15:29:11 +08:00
if (shown_one)
info->fprintf_func (info->stream, ", ");
else
shown_one = 1;
info->fprintf_func (info->stream, "%s", get_v850_reg_name (first));
1999-05-03 15:29:11 +08:00
for (bit++; bit < 32; bit++)
if ((mask & (1u << bit)) == 0)
1999-05-03 15:29:11 +08:00
break;
last = bit;
if (last > first + 1)
2010-07-23 22:52:54 +08:00
{
info->fprintf_func (info->stream, " - %s", get_v850_reg_name (last - 1));
2010-07-23 22:52:54 +08:00
}
1999-05-03 15:29:11 +08:00
}
}
1999-05-03 15:29:11 +08:00
if (pc)
info->fprintf_func (info->stream, "%sPC", mask ? ", " : "");
}
1999-05-03 15:29:11 +08:00
info->fprintf_func (info->stream, "}");
}
break;
2013-01-24 19:14:05 +08:00
case V850_OPERAND_CC:
info->fprintf_func (info->stream, "%s", get_v850_cc_name (value));
2013-01-24 19:14:05 +08:00
break;
case V850_OPERAND_FLOAT_CC:
info->fprintf_func (info->stream, "%s", get_v850_float_cc_name (value));
2013-01-24 19:14:05 +08:00
break;
case V850_OPERAND_CACHEOP:
{
int idx;
for (idx = 0; v850_cacheop_codes[idx] != -1; idx++)
{
if (value == v850_cacheop_codes[idx])
{
info->fprintf_func (info->stream, "%s",
get_v850_cacheop_name (idx));
2013-01-24 19:14:05 +08:00
goto MATCH_CACHEOP_CODE;
}
}
info->fprintf_func (info->stream, "%d", (int) value);
}
MATCH_CACHEOP_CODE:
break;
case V850_OPERAND_PREFOP:
{
int idx;
for (idx = 0; v850_prefop_codes[idx] != -1; idx++)
{
if (value == v850_prefop_codes[idx])
{
info->fprintf_func (info->stream, "%s",
get_v850_prefop_name (idx));
2013-01-24 19:14:05 +08:00
goto MATCH_PREFOP_CODE;
}
}
info->fprintf_func (info->stream, "%d", (int) value);
}
MATCH_PREFOP_CODE:
break;
case V850_OPERAND_VREG:
info->fprintf_func (info->stream, "%s", get_v850_vreg_name (value));
2013-01-24 19:14:05 +08:00
break;
2010-07-23 22:52:54 +08:00
default:
print_value (operand->flags, memaddr, info, value);
1999-05-03 15:29:11 +08:00
break;
}
1999-05-03 15:29:11 +08:00
if (square)
1999-05-03 15:29:11 +08:00
(*info->fprintf_func) (info->stream, "]");
}
/* All done. */
break;
}
2010-07-23 22:52:54 +08:00
next_opcode:
1999-05-03 15:29:11 +08:00
op++;
}
2010-07-23 22:52:54 +08:00
return match;
1999-05-03 15:29:11 +08:00
}
int
print_insn_v850 (bfd_vma memaddr, struct disassemble_info * info)
1999-05-03 15:29:11 +08:00
{
2010-07-23 22:52:54 +08:00
int status, status2, match;
bfd_byte buffer[8];
int length = 0, code_length = 0;
unsigned long insn = 0, insn2 = 0;
int target_processor;
switch (info->mach)
{
case 0:
default:
target_processor = PROCESSOR_V850;
break;
case bfd_mach_v850e:
target_processor = PROCESSOR_V850E;
break;
case bfd_mach_v850e1:
target_processor = PROCESSOR_V850E;
break;
case bfd_mach_v850e2:
target_processor = PROCESSOR_V850E2;
break;
case bfd_mach_v850e2v3:
target_processor = PROCESSOR_V850E2V3;
break;
2013-01-24 19:14:05 +08:00
case bfd_mach_v850e3v5:
target_processor = PROCESSOR_V850E3V5;
break;
2010-07-23 22:52:54 +08:00
}
1999-05-03 15:29:11 +08:00
status = info->read_memory_func (memaddr, buffer, 2, info);
2010-07-23 22:52:54 +08:00
if (status)
{
info->memory_error_func (status, memaddr, info);
return -1;
}
insn = bfd_getl16 (buffer);
status2 = info->read_memory_func (memaddr+2, buffer, 2 , info);
if (!status2)
1999-05-03 15:29:11 +08:00
{
2010-07-23 22:52:54 +08:00
insn2 = bfd_getl16 (buffer);
/* fprintf (stderr, "insn2 0x%08lx\n", insn2); */
}
2010-07-23 22:52:54 +08:00
/* Special case. */
if (length == 0
2013-01-24 19:14:05 +08:00
&& ((target_processor & PROCESSOR_V850E2_UP) != 0))
2010-07-23 22:52:54 +08:00
{
if ((insn & 0xffff) == 0x02e0 /* jr 32bit */
&& !status2 && (insn2 & 0x1) == 0)
{
length = 2;
code_length = 6;
}
else if ((insn & 0xffe0) == 0x02e0 /* jarl 32bit */
&& !status2 && (insn2 & 0x1) == 0)
{
length = 2;
code_length = 6;
}
else if ((insn & 0xffe0) == 0x06e0 /* jmp 32bit */
&& !status2 && (insn2 & 0x1) == 0)
1999-05-03 15:29:11 +08:00
{
2010-07-23 22:52:54 +08:00
length = 2;
code_length = 6;
}
}
1999-05-03 15:29:11 +08:00
2010-07-23 22:52:54 +08:00
if (length == 0
2013-01-24 19:14:05 +08:00
&& ((target_processor & PROCESSOR_V850E3V5_UP) != 0))
{
if ( ((insn & 0xffe0) == 0x07a0 /* ld.dw 23bit (v850e3v5) */
&& !status2 && (insn2 & 0x000f) == 0x0009)
|| ((insn & 0xffe0) == 0x07a0 /* st.dw 23bit (v850e3v5) */
&& !status2 && (insn2 & 0x000f) == 0x000f))
{
length = 4;
code_length = 6;
}
}
if (length == 0
&& ((target_processor & PROCESSOR_V850E2V3_UP) != 0))
2010-07-23 22:52:54 +08:00
{
if (((insn & 0xffe0) == 0x0780 /* ld.b 23bit */
&& !status2 && (insn2 & 0x000f) == 0x0005)
|| ((insn & 0xffe0) == 0x07a0 /* ld.bu 23bit */
&& !status2 && (insn2 & 0x000f) == 0x0005)
|| ((insn & 0xffe0) == 0x0780 /* ld.h 23bit */
&& !status2 && (insn2 & 0x000f) == 0x0007)
|| ((insn & 0xffe0) == 0x07a0 /* ld.hu 23bit */
&& !status2 && (insn2 & 0x000f) == 0x0007)
|| ((insn & 0xffe0) == 0x0780 /* ld.w 23bit */
&& !status2 && (insn2 & 0x000f) == 0x0009))
{
length = 4;
code_length = 6;
}
else if (((insn & 0xffe0) == 0x0780 /* st.b 23bit */
&& !status2 && (insn2 & 0x000f) == 0x000d)
|| ((insn & 0xffe0) == 0x07a0 /* st.h 23bit */
&& !status2 && (insn2 & 0x000f) == 0x000d)
|| ((insn & 0xffe0) == 0x0780 /* st.w 23bit */
&& !status2 && (insn2 & 0x000f) == 0x000f))
{
length = 4;
code_length = 6;
1999-05-03 15:29:11 +08:00
}
}
2010-07-23 22:52:54 +08:00
if (length == 0
&& target_processor != PROCESSOR_V850)
1999-05-03 15:29:11 +08:00
{
2010-07-23 22:52:54 +08:00
if ((insn & 0xffe0) == 0x0620) /* 32 bit MOV */
{
length = 2;
code_length = 6;
}
else if ((insn & 0xffc0) == 0x0780 /* prepare {list}, imm5, imm16<<16 */
&& !status2 && (insn2 & 0x001f) == 0x0013)
{
length = 4;
code_length = 6;
}
else if ((insn & 0xffc0) == 0x0780 /* prepare {list}, imm5, imm16 */
&& !status2 && (insn2 & 0x001f) == 0x000b)
{
length = 4;
code_length = 6;
}
else if ((insn & 0xffc0) == 0x0780 /* prepare {list}, imm5, imm32 */
&& !status2 && (insn2 & 0x001f) == 0x001b)
{
length = 4;
code_length = 8;
}
}
if (length == 4
|| (length == 0
&& (insn & 0x0600) == 0x0600))
{
/* This is a 4 byte insn. */
status = info->read_memory_func (memaddr, buffer, 4, info);
if (!status)
{
insn = bfd_getl32 (buffer);
if (!length)
length = code_length = 4;
}
}
if (code_length > length)
{
status = info->read_memory_func (memaddr + length, buffer, code_length - length, info);
if (status)
length = 0;
}
if (length == 0 && !status)
length = code_length = 2;
if (length == 2)
insn &= 0xffff;
2013-01-24 19:14:05 +08:00
/* when the last 2 bytes of section is 0xffff, length will be 0 and cause infinitive loop */
if (length == 0)
return -1;
2010-07-23 22:52:54 +08:00
match = disassemble (memaddr, info, length, insn);
if (!match)
{
int l = 0;
status = info->read_memory_func (memaddr, buffer, code_length, info);
while (l < code_length)
{
if (code_length - l == 2)
{
insn = bfd_getl16 (buffer + l) & 0xffff;
info->fprintf_func (info->stream, ".short\t0x%04lx", insn);
l += 2;
}
else
{
insn = bfd_getl32 (buffer + l);
info->fprintf_func (info->stream, ".long\t0x%08lx", insn);
l += 4;
}
}
1999-05-03 15:29:11 +08:00
}
2010-07-23 22:52:54 +08:00
return code_length;
1999-05-03 15:29:11 +08:00
}