1999-05-03 15:29:11 +08:00
|
|
|
|
/* Print TI TMS320C80 (MVP) instructions
|
2007-07-05 17:49:03 +08:00
|
|
|
|
Copyright 1996, 1997, 1998, 2000, 2005, 2007 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
|
2005-07-01 19:16:33 +08:00
|
|
|
|
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
|
|
|
|
|
2005-07-01 19:16:33 +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 <stdio.h>
|
|
|
|
|
|
2000-04-14 12:16:58 +08:00
|
|
|
|
#include "sysdep.h"
|
1999-05-03 15:29:11 +08:00
|
|
|
|
#include "opcode/tic80.h"
|
|
|
|
|
#include "dis-asm.h"
|
|
|
|
|
|
|
|
|
|
static int length;
|
|
|
|
|
|
|
|
|
|
/* Print an integer operand. Try to be somewhat smart about the
|
|
|
|
|
format by assuming that small positive or negative integers are
|
|
|
|
|
probably loop increment values, structure offsets, or similar
|
|
|
|
|
values that are more meaningful printed as signed decimal values.
|
2000-08-31 02:51:25 +08:00
|
|
|
|
Larger numbers are probably better printed as hex values. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
static void
|
2005-07-01 19:16:33 +08:00
|
|
|
|
print_operand_integer (struct disassemble_info *info, long value)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
if ((value > 9999 || value < -9999))
|
2005-07-01 19:16:33 +08:00
|
|
|
|
(*info->fprintf_func) (info->stream, "%#lx", value);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
else
|
2005-07-01 19:16:33 +08:00
|
|
|
|
(*info->fprintf_func) (info->stream, "%ld", value);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* FIXME: depends upon sizeof (long) == sizeof (float) and
|
|
|
|
|
also upon host floating point format matching target
|
2000-08-31 02:51:25 +08:00
|
|
|
|
floating point format. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
static void
|
2005-07-01 19:16:33 +08:00
|
|
|
|
print_operand_float (struct disassemble_info *info, long value)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
union { float f; long l; } fval;
|
|
|
|
|
|
|
|
|
|
fval.l = value;
|
2000-08-31 02:51:25 +08:00
|
|
|
|
(*info->fprintf_func) (info->stream, "%g", fval.f);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
2005-07-01 19:16:33 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
static void
|
2005-07-01 19:16:33 +08:00
|
|
|
|
print_operand_control_register (struct disassemble_info *info, long value)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
const char *tmp;
|
|
|
|
|
|
|
|
|
|
tmp = tic80_value_to_symbol (value, TIC80_OPERAND_CR);
|
|
|
|
|
if (tmp != NULL)
|
2005-07-01 19:16:33 +08:00
|
|
|
|
(*info->fprintf_func) (info->stream, "%s", tmp);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
else
|
2005-07-01 19:16:33 +08:00
|
|
|
|
(*info->fprintf_func) (info->stream, "%#lx", value);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
2005-07-01 19:16:33 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
static void
|
2005-07-01 19:16:33 +08:00
|
|
|
|
print_operand_condition_code (struct disassemble_info *info, long value)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
const char *tmp;
|
|
|
|
|
|
|
|
|
|
tmp = tic80_value_to_symbol (value, TIC80_OPERAND_CC);
|
|
|
|
|
if (tmp != NULL)
|
2005-07-01 19:16:33 +08:00
|
|
|
|
(*info->fprintf_func) (info->stream, "%s", tmp);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
else
|
2005-07-01 19:16:33 +08:00
|
|
|
|
(*info->fprintf_func) (info->stream, "%ld", value);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
2005-07-01 19:16:33 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
static void
|
2005-07-01 19:16:33 +08:00
|
|
|
|
print_operand_bitnum (struct disassemble_info *info, long value)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
int bitnum;
|
|
|
|
|
const char *tmp;
|
|
|
|
|
|
|
|
|
|
bitnum = ~value & 0x1F;
|
|
|
|
|
tmp = tic80_value_to_symbol (bitnum, TIC80_OPERAND_BITNUM);
|
|
|
|
|
if (tmp != NULL)
|
2005-07-01 19:16:33 +08:00
|
|
|
|
(*info->fprintf_func) (info->stream, "%s", tmp);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
else
|
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-08 03:27:52 +08:00
|
|
|
|
(*info->fprintf_func) (info->stream, "%d", bitnum);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print the operand as directed by the flags. */
|
|
|
|
|
|
2000-08-31 02:51:25 +08:00
|
|
|
|
#define M_SI(insn,op) ((((op)->flags & TIC80_OPERAND_M_SI) != 0) && ((insn) & (1 << 17)))
|
|
|
|
|
#define M_LI(insn,op) ((((op)->flags & TIC80_OPERAND_M_LI) != 0) && ((insn) & (1 << 15)))
|
|
|
|
|
#define R_SCALED(insn,op) ((((op)->flags & TIC80_OPERAND_SCALED) != 0) && ((insn) & (1 << 11)))
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
static void
|
2005-07-01 19:16:33 +08:00
|
|
|
|
print_operand (struct disassemble_info *info,
|
|
|
|
|
long value,
|
|
|
|
|
unsigned long insn,
|
|
|
|
|
const struct tic80_operand *operand,
|
|
|
|
|
bfd_vma memaddr)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
2000-08-31 02:51:25 +08:00
|
|
|
|
if ((operand->flags & TIC80_OPERAND_GPR) != 0)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
2000-08-31 02:51:25 +08:00
|
|
|
|
(*info->fprintf_func) (info->stream, "r%ld", value);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (M_SI (insn, operand) || M_LI (insn, operand))
|
|
|
|
|
{
|
2000-08-31 02:51:25 +08:00
|
|
|
|
(*info->fprintf_func) (info->stream, ":m");
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2000-08-31 02:51:25 +08:00
|
|
|
|
else if ((operand->flags & TIC80_OPERAND_FPA) != 0)
|
2005-07-01 19:16:33 +08:00
|
|
|
|
(*info->fprintf_func) (info->stream, "a%ld", value);
|
|
|
|
|
|
2000-08-31 02:51:25 +08:00
|
|
|
|
else if ((operand->flags & TIC80_OPERAND_PCREL) != 0)
|
2005-07-01 19:16:33 +08:00
|
|
|
|
(*info->print_address_func) (memaddr + 4 * value, info);
|
|
|
|
|
|
2000-08-31 02:51:25 +08:00
|
|
|
|
else if ((operand->flags & TIC80_OPERAND_BASEREL) != 0)
|
2005-07-01 19:16:33 +08:00
|
|
|
|
(*info->print_address_func) (value, info);
|
|
|
|
|
|
2000-08-31 02:51:25 +08:00
|
|
|
|
else if ((operand->flags & TIC80_OPERAND_BITNUM) != 0)
|
2005-07-01 19:16:33 +08:00
|
|
|
|
print_operand_bitnum (info, value);
|
|
|
|
|
|
2000-08-31 02:51:25 +08:00
|
|
|
|
else if ((operand->flags & TIC80_OPERAND_CC) != 0)
|
2005-07-01 19:16:33 +08:00
|
|
|
|
print_operand_condition_code (info, value);
|
|
|
|
|
|
2000-08-31 02:51:25 +08:00
|
|
|
|
else if ((operand->flags & TIC80_OPERAND_CR) != 0)
|
2005-07-01 19:16:33 +08:00
|
|
|
|
print_operand_control_register (info, value);
|
|
|
|
|
|
2000-08-31 02:51:25 +08:00
|
|
|
|
else if ((operand->flags & TIC80_OPERAND_FLOAT) != 0)
|
2005-07-01 19:16:33 +08:00
|
|
|
|
print_operand_float (info, value);
|
|
|
|
|
|
2000-08-31 02:51:25 +08:00
|
|
|
|
else if ((operand->flags & TIC80_OPERAND_BITFIELD))
|
2005-07-01 19:16:33 +08:00
|
|
|
|
(*info->fprintf_func) (info->stream, "%#lx", value);
|
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
else
|
2005-07-01 19:16:33 +08:00
|
|
|
|
print_operand_integer (info, value);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2000-08-31 02:51:25 +08:00
|
|
|
|
/* If this is a scaled operand, then print the modifier. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (R_SCALED (insn, operand))
|
2005-07-01 19:16:33 +08:00
|
|
|
|
(*info->fprintf_func) (info->stream, ":s");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Get the next 32 bit word from the instruction stream and convert it
|
|
|
|
|
into internal format in the unsigned long INSN, for which we are
|
|
|
|
|
passed the address. Return 0 on success, -1 on error. */
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
fill_instruction (struct disassemble_info *info,
|
|
|
|
|
bfd_vma memaddr,
|
|
|
|
|
unsigned long *insnp)
|
|
|
|
|
{
|
|
|
|
|
bfd_byte buffer[4];
|
|
|
|
|
int status;
|
|
|
|
|
|
|
|
|
|
/* Get the bits for the next 32 bit word and put in buffer. */
|
|
|
|
|
status = (*info->read_memory_func) (memaddr + length, buffer, 4, info);
|
|
|
|
|
if (status != 0)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
2005-07-01 19:16:33 +08:00
|
|
|
|
(*info->memory_error_func) (status, memaddr, info);
|
|
|
|
|
return -1;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
2005-07-01 19:16:33 +08:00
|
|
|
|
|
|
|
|
|
/* Read was successful, so increment count of bytes read and convert
|
|
|
|
|
the bits into internal format. */
|
|
|
|
|
|
|
|
|
|
length += 4;
|
|
|
|
|
if (info->endian == BFD_ENDIAN_LITTLE)
|
|
|
|
|
*insnp = bfd_getl32 (buffer);
|
|
|
|
|
|
|
|
|
|
else if (info->endian == BFD_ENDIAN_BIG)
|
|
|
|
|
*insnp = bfd_getb32 (buffer);
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
/* FIXME: Should probably just default to one or the other. */
|
|
|
|
|
abort ();
|
|
|
|
|
|
|
|
|
|
return 0;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
2005-07-01 19:16:33 +08:00
|
|
|
|
|
2000-08-31 02:51:25 +08:00
|
|
|
|
/* We have chosen an opcode table entry. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
static int
|
2005-07-01 19:16:33 +08:00
|
|
|
|
print_one_instruction (struct disassemble_info *info,
|
|
|
|
|
bfd_vma memaddr,
|
|
|
|
|
unsigned long insn,
|
|
|
|
|
const struct tic80_opcode *opcode)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
const struct tic80_operand *operand;
|
|
|
|
|
long value;
|
|
|
|
|
int status;
|
|
|
|
|
const unsigned char *opindex;
|
|
|
|
|
int close_paren;
|
|
|
|
|
|
2000-08-31 02:51:25 +08:00
|
|
|
|
(*info->fprintf_func) (info->stream, "%-10s", opcode->name);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2000-08-31 02:51:25 +08:00
|
|
|
|
for (opindex = opcode->operands; *opindex != 0; opindex++)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
operand = tic80_operands + *opindex;
|
|
|
|
|
|
|
|
|
|
/* Extract the value from the instruction. */
|
2000-08-31 02:51:25 +08:00
|
|
|
|
if (operand->extract)
|
2005-07-01 19:16:33 +08:00
|
|
|
|
value = (*operand->extract) (insn, NULL);
|
|
|
|
|
|
2000-08-31 02:51:25 +08:00
|
|
|
|
else if (operand->bits == 32)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
status = fill_instruction (info, memaddr, (unsigned long *) &value);
|
|
|
|
|
if (status == -1)
|
2005-07-01 19:16:33 +08:00
|
|
|
|
return status;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2000-08-31 02:51:25 +08:00
|
|
|
|
value = (insn >> operand->shift) & ((1 << operand->bits) - 1);
|
2005-07-01 19:16:33 +08:00
|
|
|
|
|
2000-08-31 02:51:25 +08:00
|
|
|
|
if ((operand->flags & TIC80_OPERAND_SIGNED) != 0
|
|
|
|
|
&& (value & (1 << (operand->bits - 1))) != 0)
|
2005-07-01 19:16:33 +08:00
|
|
|
|
value -= 1 << operand->bits;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If this operand is enclosed in parenthesis, then print
|
|
|
|
|
the open paren, otherwise just print the regular comma
|
2000-08-31 02:51:25 +08:00
|
|
|
|
separator, except for the first operand. */
|
|
|
|
|
if ((operand->flags & TIC80_OPERAND_PARENS) == 0)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
close_paren = 0;
|
2000-08-31 02:51:25 +08:00
|
|
|
|
if (opindex != opcode->operands)
|
2005-07-01 19:16:33 +08:00
|
|
|
|
(*info->fprintf_func) (info->stream, ",");
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
close_paren = 1;
|
2000-08-31 02:51:25 +08:00
|
|
|
|
(*info->fprintf_func) (info->stream, "(");
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print_operand (info, value, insn, operand, memaddr);
|
|
|
|
|
|
|
|
|
|
/* If we printed an open paren before printing this operand, close
|
2000-08-31 02:51:25 +08:00
|
|
|
|
it now. The flag gets reset on each loop. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (close_paren)
|
2005-07-01 19:16:33 +08:00
|
|
|
|
(*info->fprintf_func) (info->stream, ")");
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
2005-07-01 19:16:33 +08:00
|
|
|
|
|
|
|
|
|
return length;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* There are no specific bits that tell us for certain whether a vector
|
|
|
|
|
instruction opcode contains one or two instructions. However since
|
|
|
|
|
a destination register of r0 is illegal, we can check for nonzero
|
|
|
|
|
values in both destination register fields. Only opcodes that have
|
2000-08-31 02:51:25 +08:00
|
|
|
|
two valid instructions will have non-zero in both. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
#define TWO_INSN(insn) ((((insn) & (0x1F << 27)) != 0) && (((insn) & (0x1F << 22)) != 0))
|
|
|
|
|
|
|
|
|
|
static int
|
2005-07-01 19:16:33 +08:00
|
|
|
|
print_instruction (struct disassemble_info *info,
|
|
|
|
|
bfd_vma memaddr,
|
|
|
|
|
unsigned long insn,
|
|
|
|
|
const struct tic80_opcode *vec_opcode)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
const struct tic80_opcode *opcode;
|
|
|
|
|
const struct tic80_opcode *opcode_end;
|
|
|
|
|
|
|
|
|
|
/* Find the first opcode match in the opcodes table. For vector
|
|
|
|
|
opcodes (vec_opcode != NULL) find the first match that is not the
|
|
|
|
|
previously found match. FIXME: there should be faster ways to
|
|
|
|
|
search (hash table or binary search), but don't worry too much
|
2000-08-31 02:51:25 +08:00
|
|
|
|
about it until other TIc80 support is finished. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
opcode_end = tic80_opcodes + tic80_num_opcodes;
|
|
|
|
|
for (opcode = tic80_opcodes; opcode < opcode_end; opcode++)
|
|
|
|
|
{
|
2000-08-31 02:51:25 +08:00
|
|
|
|
if ((insn & opcode->mask) == opcode->opcode &&
|
1999-05-03 15:29:11 +08:00
|
|
|
|
opcode != vec_opcode)
|
2005-07-01 19:16:33 +08:00
|
|
|
|
break;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (opcode == opcode_end)
|
|
|
|
|
{
|
2000-08-31 02:51:25 +08:00
|
|
|
|
/* No match found, just print the bits as a .word directive. */
|
|
|
|
|
(*info->fprintf_func) (info->stream, ".word %#08lx", insn);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Match found, decode the instruction. */
|
|
|
|
|
length = print_one_instruction (info, memaddr, insn, opcode);
|
2000-08-31 02:51:25 +08:00
|
|
|
|
if (opcode->flags & TIC80_VECTOR && vec_opcode == NULL && TWO_INSN (insn))
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
/* There is another instruction to print from the same opcode.
|
|
|
|
|
Print the separator and then find and print the other
|
2000-08-31 02:51:25 +08:00
|
|
|
|
instruction. */
|
|
|
|
|
(*info->fprintf_func) (info->stream, " || ");
|
1999-05-03 15:29:11 +08:00
|
|
|
|
length = print_instruction (info, memaddr, insn, opcode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-01 19:16:33 +08:00
|
|
|
|
return length;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2000-08-31 02:51:25 +08:00
|
|
|
|
int
|
2005-07-01 19:16:33 +08:00
|
|
|
|
print_insn_tic80 (bfd_vma memaddr, struct disassemble_info *info)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned long insn;
|
|
|
|
|
int status;
|
|
|
|
|
|
|
|
|
|
length = 0;
|
|
|
|
|
info->bytes_per_line = 8;
|
|
|
|
|
status = fill_instruction (info, memaddr, &insn);
|
|
|
|
|
if (status != -1)
|
2005-07-01 19:16:33 +08:00
|
|
|
|
status = print_instruction (info, memaddr, insn, NULL);
|
|
|
|
|
|
|
|
|
|
return status;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|