binutils-gdb/opcodes/d30v-dis.c

399 lines
9.5 KiB
C
Raw Normal View History

1999-05-03 09:29:11 +02:00
/* Disassemble D30V instructions.
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 17:13:28 +02:00
Copyright 1997, 1998, 2000, 2001, 2005, 2007, 2012
2007-07-05 11:49:03 +02:00
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
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
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 09:29:11 +02: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 17:13:28 +02:00
#include <stdio.h>
#include "opcode/d30v.h"
1999-05-03 09:29:11 +02:00
#include "dis-asm.h"
#include "opintl.h"
#define PC_MASK 0xFFFFFFFF
/* Return 0 if lookup fails,
1 if found and only one form,
2 if found and there are short and long forms. */
1999-05-03 09:29:11 +02:00
static int
lookup_opcode (struct d30v_insn *insn, long num, int is_long)
1999-05-03 09:29:11 +02:00
{
int i = 0, op_index;
1999-05-03 09:29:11 +02:00
struct d30v_format *f;
struct d30v_opcode *op = (struct d30v_opcode *) d30v_opcode_table;
1999-05-03 09:29:11 +02:00
int op1 = (num >> 25) & 0x7;
int op2 = (num >> 20) & 0x1f;
int mod = (num >> 18) & 0x3;
/* Find the opcode. */
do
{
if ((op->op1 == op1) && (op->op2 == op2))
break;
op++;
}
while (op->name);
1999-05-03 09:29:11 +02:00
if (!op || !op->name)
return 0;
while (op->op1 == op1 && op->op2 == op2)
{
/* Scan through all the formats for the opcode. */
op_index = op->format[i++];
do
1999-05-03 09:29:11 +02:00
{
f = (struct d30v_format *) &d30v_format_table[op_index];
while (f->form == op_index)
1999-05-03 09:29:11 +02:00
{
if ((!is_long || f->form >= LONG) && (f->modifier == mod))
{
insn->form = f;
break;
}
f++;
}
if (insn->form)
break;
}
while ((op_index = op->format[i++]) != 0);
1999-05-03 09:29:11 +02:00
if (insn->form)
break;
op++;
i = 0;
1999-05-03 09:29:11 +02:00
}
if (insn->form == NULL)
return 0;
insn->op = op;
insn->ecc = (num >> 28) & 0x7;
if (op->format[1])
return 2;
else
return 1;
}
static int
extract_value (long long num, struct d30v_operand *oper, int is_long)
{
int val;
int shift = 12 - oper->position;
int mask = (0xFFFFFFFF >> (32 - oper->bits));
if (is_long)
{
if (oper->bits == 32)
/* Piece together 32-bit constant. */
val = ((num & 0x3FFFF)
| ((num & 0xFF00000) >> 2)
| ((num & 0x3F00000000LL) >> 6));
else
val = (num >> (32 + shift)) & mask;
}
else
val = (num >> shift) & mask;
if (oper->flags & OPERAND_SHIFT)
val <<= 3;
return val;
}
static void
print_insn (struct disassemble_info *info,
bfd_vma memaddr,
long long num,
struct d30v_insn *insn,
int is_long,
int show_ext)
1999-05-03 09:29:11 +02:00
{
int val, opnum, need_comma = 0;
1999-05-03 09:29:11 +02:00
struct d30v_operand *oper;
int i, match, opind = 0, need_paren = 0, found_control = 0;
1999-05-03 09:29:11 +02:00
(*info->fprintf_func) (info->stream, "%s", insn->op->name);
1999-05-03 09:29:11 +02:00
/* Check for CMP or CMPU. */
1999-05-03 09:29:11 +02:00
if (d30v_operand_table[insn->form->operands[0]].flags & OPERAND_NAME)
{
opind++;
val =
extract_value (num,
(struct d30v_operand *) &d30v_operand_table[insn->form->operands[0]],
is_long);
(*info->fprintf_func) (info->stream, "%s", d30v_cc_names[val]);
1999-05-03 09:29:11 +02:00
}
/* Add in ".s" or ".l". */
1999-05-03 09:29:11 +02:00
if (show_ext == 2)
{
if (is_long)
(*info->fprintf_func) (info->stream, ".l");
else
(*info->fprintf_func) (info->stream, ".s");
}
if (insn->ecc)
(*info->fprintf_func) (info->stream, "/%s", d30v_ecc_names[insn->ecc]);
1999-05-03 09:29:11 +02:00
(*info->fprintf_func) (info->stream, "\t");
while ((opnum = insn->form->operands[opind++]) != 0)
{
int bits;
oper = (struct d30v_operand *) &d30v_operand_table[opnum];
1999-05-03 09:29:11 +02:00
bits = oper->bits;
if (oper->flags & OPERAND_SHIFT)
bits += 3;
if (need_comma
&& oper->flags != OPERAND_PLUS
&& oper->flags != OPERAND_MINUS)
1999-05-03 09:29:11 +02:00
{
need_comma = 0;
1999-05-03 09:29:11 +02:00
(*info->fprintf_func) (info->stream, ", ");
}
if (oper->flags == OPERAND_ATMINUS)
{
(*info->fprintf_func) (info->stream, "@-");
continue;
}
if (oper->flags == OPERAND_MINUS)
{
(*info->fprintf_func) (info->stream, "-");
1999-05-03 09:29:11 +02:00
continue;
}
if (oper->flags == OPERAND_PLUS)
{
(*info->fprintf_func) (info->stream, "+");
1999-05-03 09:29:11 +02:00
continue;
}
if (oper->flags == OPERAND_ATSIGN)
{
(*info->fprintf_func) (info->stream, "@");
1999-05-03 09:29:11 +02:00
continue;
}
if (oper->flags == OPERAND_ATPAR)
{
(*info->fprintf_func) (info->stream, "@(");
1999-05-03 09:29:11 +02:00
need_paren = 1;
continue;
}
if (oper->flags == OPERAND_SPECIAL)
continue;
val = extract_value (num, oper, is_long);
1999-05-03 09:29:11 +02:00
if (oper->flags & OPERAND_REG)
{
match = 0;
if (oper->flags & OPERAND_CONTROL)
{
struct d30v_operand *oper3 =
(struct d30v_operand *) &d30v_operand_table[insn->form->operands[2]];
int id = extract_value (num, oper3, is_long);
1999-05-03 09:29:11 +02:00
found_control = 1;
switch (id)
1999-05-03 09:29:11 +02:00
{
case 0:
val |= OPERAND_CONTROL;
break;
case 1:
case 2:
val = OPERAND_CONTROL + MAX_CONTROL_REG + id;
break;
case 3:
val |= OPERAND_FLAG;
break;
default:
fprintf (stderr, "illegal id (%d)\n", id);
1999-05-03 09:29:11 +02:00
}
}
else if (oper->flags & OPERAND_ACC)
val |= OPERAND_ACC;
else if (oper->flags & OPERAND_FLAG)
val |= OPERAND_FLAG;
for (i = 0; i < reg_name_cnt (); i++)
1999-05-03 09:29:11 +02:00
{
if (val == pre_defined_registers[i].value)
{
if (pre_defined_registers[i].pname)
(*info->fprintf_func)
(info->stream, "%s", pre_defined_registers[i].pname);
1999-05-03 09:29:11 +02:00
else
(*info->fprintf_func)
(info->stream, "%s", pre_defined_registers[i].name);
match = 1;
1999-05-03 09:29:11 +02:00
break;
}
}
if (match == 0)
1999-05-03 09:29:11 +02:00
{
/* This would only get executed if a register was not in
the register table. */
1999-05-03 09:29:11 +02:00
(*info->fprintf_func)
(info->stream, _("<unknown register %d>"), val & 0x3F);
1999-05-03 09:29:11 +02:00
}
}
2000-03-03 00:01:40 +01:00
/* repeati has a relocation, but its first argument is a plain
immediate. OTOH instructions like djsri have a pc-relative
2001-10-29 23:43:32 +01:00
delay target, but an absolute jump target. Therefore, a test
2000-03-03 00:01:40 +01:00
of insn->op->reloc_flag is not specific enough; we must test
if the actual operand we are handling now is pc-relative. */
else if (oper->flags & OPERAND_PCREL)
1999-05-03 09:29:11 +02:00
{
2000-03-03 00:01:40 +01:00
int neg = 0;
2000-03-03 00:01:40 +01:00
/* IMM6S3 is unsigned. */
if (oper->flags & OPERAND_SIGNED || bits == 32)
1999-05-03 09:29:11 +02:00
{
2000-03-03 00:01:40 +01:00
long max;
max = (1 << (bits - 1));
if (val & max)
{
if (bits == 32)
val = -val;
else
val = -val & ((1 << bits) - 1);
2000-03-03 00:01:40 +01:00
neg = 1;
}
}
if (neg)
{
(*info->fprintf_func) (info->stream, "-%x\t(", val);
2000-03-03 00:01:40 +01:00
(*info->print_address_func) ((memaddr - val) & PC_MASK, info);
(*info->fprintf_func) (info->stream, ")");
1999-05-03 09:29:11 +02:00
}
2000-03-03 00:01:40 +01:00
else
1999-05-03 09:29:11 +02:00
{
(*info->fprintf_func) (info->stream, "%x\t(", val);
2000-03-03 00:01:40 +01:00
(*info->print_address_func) ((memaddr + val) & PC_MASK, info);
(*info->fprintf_func) (info->stream, ")");
1999-05-03 09:29:11 +02:00
}
}
else if (insn->op->reloc_flag == RELOC_ABS)
{
(*info->print_address_func) (val, info);
}
else
{
if (oper->flags & OPERAND_SIGNED)
{
int max = (1 << (bits - 1));
1999-05-03 09:29:11 +02:00
if (val & max)
{
val = -val;
if (bits < 32)
val &= ((1 << bits) - 1);
(*info->fprintf_func) (info->stream, "-");
}
}
(*info->fprintf_func) (info->stream, "0x%x", val);
1999-05-03 09:29:11 +02:00
}
/* If there is another operand, then write a comma and space. */
1999-05-03 09:29:11 +02:00
if (insn->form->operands[opind] && !(found_control && opind == 2))
need_comma = 1;
}
if (need_paren)
(*info->fprintf_func) (info->stream, ")");
}
int
print_insn_d30v (bfd_vma memaddr, struct disassemble_info *info)
1999-05-03 09:29:11 +02:00
{
int status, result;
bfd_byte buffer[12];
unsigned long in1, in2;
struct d30v_insn insn;
long long num;
1999-05-03 09:29:11 +02:00
insn.form = NULL;
info->bytes_per_line = 8;
info->bytes_per_chunk = 4;
info->display_endian = BFD_ENDIAN_BIG;
status = (*info->read_memory_func) (memaddr, buffer, 4, info);
if (status != 0)
1999-05-03 09:29:11 +02:00
{
(*info->memory_error_func) (status, memaddr, info);
return -1;
}
in1 = bfd_getb32 (buffer);
status = (*info->read_memory_func) (memaddr + 4, buffer, 4, info);
if (status != 0)
{
info->bytes_per_line = 8;
if (!(result = lookup_opcode (&insn, in1, 0)))
(*info->fprintf_func) (info->stream, ".long\t0x%lx", in1);
else
print_insn (info, memaddr, (long long) in1, &insn, 0, result);
return 4;
}
in2 = bfd_getb32 (buffer);
if (in1 & in2 & FM01)
{
/* LONG instruction. */
if (!(result = lookup_opcode (&insn, in1, 1)))
1999-05-03 09:29:11 +02:00
{
(*info->fprintf_func) (info->stream, ".long\t0x%lx,0x%lx", in1, in2);
return 8;
1999-05-03 09:29:11 +02:00
}
num = (long long) in1 << 32 | in2;
print_insn (info, memaddr, num, &insn, 1, result);
1999-05-03 09:29:11 +02:00
}
else
{
num = in1;
if (!(result = lookup_opcode (&insn, in1, 0)))
(*info->fprintf_func) (info->stream, ".long\t0x%lx", in1);
else
print_insn (info, memaddr, num, &insn, 0, result);
1999-05-03 09:29:11 +02:00
switch (((in1 >> 31) << 1) | (in2 >> 31))
{
case 0:
(*info->fprintf_func) (info->stream, "\t||\t");
break;
case 1:
(*info->fprintf_func) (info->stream, "\t->\t");
break;
case 2:
(*info->fprintf_func) (info->stream, "\t<-\t");
default:
break;
}
1999-05-03 09:29:11 +02:00
insn.form = NULL;
num = in2;
if (!(result = lookup_opcode (&insn, in2, 0)))
(*info->fprintf_func) (info->stream, ".long\t0x%lx", in2);
else
print_insn (info, memaddr, num, &insn, 0, result);
}
return 8;
1999-05-03 09:29:11 +02:00
}