summaryrefslogtreecommitdiff
path: root/opcodes/tilepro-dis.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2011-06-13 15:18:54 +0000
committerNick Clifton <nickc@redhat.com>2011-06-13 15:18:54 +0000
commitaa137e4d51ba6638b2714f8b3856d8abfd0bf143 (patch)
treecadadb81304aeee046e706c4f71e968bba7c8fb8 /opcodes/tilepro-dis.c
parentaf199b06016f0acab1e98de12c017f51b5d3780a (diff)
* Makefile.am (ALL_MACHINES): Add cpu-tilegx.lo and cpu-tilepro.lo.
(ALL_MACHINE_CFILES): Add cpu-tilegx.c and cpu-tilepro.c. (BFD32_BACKENDS): Add elf32-tilegx.lo, elf32-tilepro.lo, and elfxx-tilegx.lo. (BFD32_BACKENDS_CFILES): Add elf32-tilegx.c elf32-tilepro.c, and elfxx-tilegx.c. (BFD64_BACKENDS): Add elf64-tilegx.lo. (BFD64_BACKENDS_CFILES): Add elf64-tilegx.c. * Makefile.in: Regenerate. * arctures.c (bfd_architecture): Define bfd_arch_tilepro, bfd_arch_tilegx, bfd_mach_tilepro, bfd_mach_tilegx. (bfd_arch_info): Add bfd_tilegx_arch, bfd_tilepro_arch. (bfd_archures_list): Add bfd_tilegx_arch, bfd_tilepro_arch. bfd-in2.h: Regenerate. * config.bfd: Handle tilegx-*-* and tilepro-*-*. * configure.in: Handle bfd_elf32_tilegx_vec, bfd_elf32_tilepro_vec, and bfd_elf64_tilegx_vec. * configure: Regenerate. * elf-bfd.h (enum elf_target_id): Define TILEGX_ELF_DATA and TILEPRO_ELF_DATA. * libbfd.h: Regenerate. * reloc.c: Add BFD_RELOC_TILEPRO_{COPY, GLOB_DAT, JMP_SLOT, RELATIVE, BROFF_X1, JOFFLONG_X1, JOFFLONG_X1_PLT, IMM8_X0, IMM8_Y0, IMM8_X1, IMM8_Y1, DEST_IMM8_X1, MT_IMM15_X1, MF_IMM15_X1, IMM16_X0, IMM16_X1, IMM16_X0_LO, IMM16_X1_LO, IMM16_X0_HI, IMM16_X1_HI, IMM16_X0_HA, IMM16_X1_HA, IMM16_X0_PCREL, IMM16_X1_PCREL, IMM16_X0_LO_PCREL, IMM16_X1_LO_PCREL, IMM16_X0_HI_PCREL, IMM16_X1_HI_PCREL, IMM16_X0_HA_PCREL, IMM16_X1_HA_PCREL, IMM16_X0_GOT, IMM16_X1_GOT, IMM16_X0_GOT_LO, IMM16_X1_GOT_LO, IMM16_X0_GOT_HI, IMM16_X1_GOT_HI, IMM16_X0_GOT_HA, IMM16_X1_GOT_HA, MMSTART_X0, MMEND_X0, MMSTART_X1, MMEND_X1, SHAMT_X0, SHAMT_X1, SHAMT_Y0, SHAMT_Y1, IMM16_X0_TLS_GD, IMM16_X1_TLS_GD, IMM16_X0_TLS_GD_LO, IMM16_X1_TLS_GD_LO, IMM16_X0_TLS_GD_HI, IMM16_X1_TLS_GD_HI, IMM16_X0_TLS_GD_HA, IMM16_X1_TLS_GD_HA, IMM16_X0_TLS_IE, IMM16_X1_TLS_IE, IMM16_X0_TLS_IE_LO, IMM16_X1_TLS_IE_LO, IMM16_X0_TLS_IE_HI, IMM16_X1_TLS_IE_HI, IMM16_X0_TLS_IE_HA, IMM16_X1_TLS_IE_HA, TLS_DTPMOD32, TLS_DTPOFF32, TLS_TPOFF32} Add BFD_RELOC_TILEGX_{HW0, HW1, HW2, HW3, HW0_LAST, HW1_LAST, HW2_LAST, COPY, GLOB_DAT, JMP_SLOT, RELATIVE, BROFF_X1, JUMPOFF_X1, JUMPOFF_X1_PLT, IMM8_X0, IMM8_Y0, IMM8_X1, IMM8_Y1, DEST_IMM8_X1, MT_IMM14_X1, MF_IMM14_X1, MMSTART_X0, MMEND_X0, SHAMT_X0, SHAMT_X1, SHAMT_Y0, SHAMT_Y1, IMM16_X0_HW0, IMM16_X1_HW0, IMM16_X0_HW1, IMM16_X1_HW1, IMM16_X0_HW2, IMM16_X1_HW2, IMM16_X0_HW3, IMM16_X1_HW3, IMM16_X0_HW0_LAST, IMM16_X1_HW0_LAST, IMM16_X0_HW1_LAST, IMM16_X1_HW1_LAST, IMM16_X0_HW2_LAST, IMM16_X1_HW2_LAST, IMM16_X0_HW0_PCREL, IMM16_X1_HW0_PCREL, IMM16_X0_HW1_PCREL, IMM16_X1_HW1_PCREL, IMM16_X0_HW2_PCREL, IMM16_X1_HW2_PCREL, IMM16_X0_HW3_PCREL, IMM16_X1_HW3_PCREL, IMM16_X0_HW0_LAST_PCREL, IMM16_X1_HW0_LAST_PCREL, IMM16_X0_HW1_LAST_PCREL, IMM16_X1_HW1_LAST_PCREL, IMM16_X0_HW2_LAST_PCREL, IMM16_X1_HW2_LAST_PCREL, IMM16_X0_HW0_GOT, IMM16_X1_HW0_GOT, IMM16_X0_HW1_GOT, IMM16_X1_HW1_GOT, IMM16_X0_HW2_GOT, IMM16_X1_HW2_GOT, IMM16_X0_HW3_GOT, IMM16_X1_HW3_GOT, IMM16_X0_HW0_LAST_GOT, IMM16_X1_HW0_LAST_GOT, IMM16_X0_HW1_LAST_GOT, IMM16_X1_HW1_LAST_GOT, IMM16_X0_HW2_LAST_GOT, IMM16_X1_HW2_LAST_GOT, IMM16_X0_HW0_TLS_GD, IMM16_X1_HW0_TLS_GD, IMM16_X0_HW1_TLS_GD, IMM16_X1_HW1_TLS_GD, IMM16_X0_HW2_TLS_GD, IMM16_X1_HW2_TLS_GD, IMM16_X0_HW3_TLS_GD, IMM16_X1_HW3_TLS_GD, IMM16_X0_HW0_LAST_TLS_GD, IMM16_X1_HW0_LAST_TLS_GD, IMM16_X0_HW1_LAST_TLS_GD, IMM16_X1_HW1_LAST_TLS_GD, IMM16_X0_HW2_LAST_TLS_GD, IMM16_X1_HW2_LAST_TLS_GD, IMM16_X0_HW0_TLS_IE, IMM16_X1_HW0_TLS_IE, IMM16_X0_HW1_TLS_IE, IMM16_X1_HW1_TLS_IE, IMM16_X0_HW2_TLS_IE, IMM16_X1_HW2_TLS_IE, IMM16_X0_HW3_TLS_IE, IMM16_X1_HW3_TLS_IE, IMM16_X0_HW0_LAST_TLS_IE, IMM16_X1_HW0_LAST_TLS_IE, IMM16_X0_HW1_LAST_TLS_IE, IMM16_X1_HW1_LAST_TLS_IE, IMM16_X0_HW2_LAST_TLS_IE, IMM16_X1_HW2_LAST_TLS_IE, TLS_DTPMOD64, TLS_DTPOFF64, TLS_TPOFF64, TLS_DTPMOD32, TLS_DTPOFF32, TLS_TPOFF32} * targets.c (bfd_elf32_tilegx_vec): Declare. (bfd_elf32_tilepro_vec): Declare. (bfd_elf64_tilegx_vec): Declare. (bfd_target_vector): Add bfd_elf32_tilegx_vec, bfd_elf32_tilepro_vec, and bfd_elf64_tilegx_vec. * cpu-tilegx.c: New file. * cpu-tilepro.c: New file. * elf32-tilepro.h: New file. * elf32-tilepro.c: New file. * elf32-tilegx.c: New file. * elf32-tilegx.h: New file. * elf64-tilegx.c: New file. * elf64-tilegx.h: New file. * elfxx-tilegx.c: New file. * elfxx-tilegx.h: New file. * Makefile.am (TARGET_CPU_CFILES): Add config/tc-tilegx.c and config/tc-tilepro.c. (TARGET_CPU_HFILES): Add config/tc-tilegx.h and config/tc-tilepro.h. * Makefile.in: Regenerate. * configure.tgt (tilepro-*-*): New. (tilegx-*-*): Likewise. * config/tc-tilegx.c: New file. * config/tc-tilegx.h: Likewise. * config/tc-tilepro.h: Likewise. * config/tc-tilepro.c: Likewise. * doc/Makefile.am (CPU_DOCS): Add c-tilegx.texi and c-tilepro.texi. * doc/Makefile.in: Regenerate. * doc/all.texi (TILEGX): Define. (TILEPRO): Define. * doc/as.texinfo: Add Tile-Gx and TILEPro documentation. Include c-tilegx.texi and c-tilepro.texi. * doc/c-tilegx.texi: New. * doc/c-tilepro.texi: New. * gas/tilepro/t_constants.s: New file. * gas/tilepro/t_constants.d: Likewise. * gas/tilepro/t_insns.s: Likewise. * gas/tilepro/tilepro.exp: Likewise. * gas/tilepro/t_insns.d: Likewise. * gas/tilegx/tilegx.exp: Likewise. * gas/tilegx/t_insns.d: Likewise. * gas/tilegx/t_insns.s: Likewise. * dis-asm.h (print_insn_tilegx): Declare. (print_insn_tilepro): Likewise. * tilegx.h: New file. * tilepro.h: New file. * common.h: Add EM_TILEGX. * tilegx.h: New file. * tilepro.h: New file. * Makefile.am (ALL_EMULATION_SOURCES): Add eelf32tilegx.c and eelf32tilepro.c. (ALL_64_EMULATION_SOURCES): Add eelf64tilegx.c. (eelf32tilegx.c): New target. (eelf32tilepro.c): Likewise. (eelf64tilegx.c): Likewise. * Makefile.in: Regenerate. * configure.tgt: Handle tilegx-*-* and tilepro-*-*. * emulparams/elf32tilegx.sh: New file. * emulparams/elf64tilegx.sh: New file. * emulparams/elf32tilepro.sh: New file. * ld-elf/eh5.d: Don't run on tile*. * ld-srec/srec.exp: xfail on tile*. * ld-tilegx/external.s: New file. * ld-tilegx/reloc.d: New file. * ld-tilegx/reloc.s: New file. * ld-tilegx/tilegx.exp: New file. * ld-tilepro/external.s: New file. * ld-tilepro/reloc.d: New file. * ld-tilepro/reloc.s: New file. * ld-tilepro/tilepro.exp: New file. * Makefile.am (TARGET_LIBOPCODES_CFILES): Add tilegx-dis.c, tilegx-opc.c, tilepro-dis.c, and tilepro-opc.c. * Makefile.in: Regenerate. * configure.in: Handle bfd_tilegx_arch and bfd_tilepro_arch. * configure: Regenerate. * disassemble.c (disassembler): Add ARCH_tilegx and ARCH_tilepro. * po/POTFILES.in: Regenerate. * tilegx-dis.c: New file. * tilegx-opc.c: New file. * tilepro-dis.c: New file. * tilepro-opc.c: New file.
Diffstat (limited to 'opcodes/tilepro-dis.c')
-rw-r--r--opcodes/tilepro-dis.c232
1 files changed, 232 insertions, 0 deletions
diff --git a/opcodes/tilepro-dis.c b/opcodes/tilepro-dis.c
new file mode 100644
index 0000000000..bf9910cab4
--- /dev/null
+++ b/opcodes/tilepro-dis.c
@@ -0,0 +1,232 @@
+/* tilepro-dis.c. Disassembly routines for the TILEPro architecture.
+ Copyright 2011 Free Software Foundation, Inc.
+
+ This file is part of the GNU opcodes library.
+
+ This program 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 of the License, or
+ (at your option) any later version.
+
+ This program 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 <stddef.h>
+#include <assert.h>
+#include "bfd.h"
+#include "elf/tilepro.h"
+#include "elf-bfd.h"
+#include "sysdep.h"
+#include "dis-asm.h"
+#include "opcode/tilepro.h"
+
+
+#define TREG_ZERO 63
+
+static int
+contains_insn (tilepro_mnemonic expected_mnemonic,
+ int expected_first_operand,
+ int expected_second_operand,
+ bfd_vma memaddr,
+ int *last_operand_ret,
+ disassemble_info *info)
+{
+ struct tilepro_decoded_instruction
+ decoded[TILEPRO_MAX_INSTRUCTIONS_PER_BUNDLE];
+ bfd_byte opbuf[TILEPRO_BUNDLE_SIZE_IN_BYTES];
+ int i, num_instructions;
+
+ if ((*info->read_memory_func) (memaddr, opbuf,
+ TILEPRO_BUNDLE_SIZE_IN_BYTES, info) != 0)
+ /* If we cannot even read the memory, it obviously does not have the
+ instruction for which we are looking. */
+ return 0;
+
+ /* Parse the instructions in the bundle. */
+ num_instructions = parse_insn_tilepro (bfd_getl64 (opbuf), memaddr, decoded);
+
+ for (i = 0; i < num_instructions; i++)
+ {
+ const struct tilepro_opcode *opcode = decoded[i].opcode;
+
+ if (opcode->mnemonic != expected_mnemonic)
+ continue;
+
+ if (expected_first_operand != -1
+ && decoded[i].operand_values[0] != expected_first_operand)
+ continue;
+
+ if (expected_second_operand != -1
+ && decoded[i].operand_values[1] != expected_second_operand)
+ continue;
+
+ *last_operand_ret = decoded[i].operand_values[opcode->num_operands - 1];
+ return 1;
+ }
+
+ /* No match. */
+ return 0;
+}
+
+
+int
+print_insn_tilepro (bfd_vma memaddr, disassemble_info *info)
+{
+ struct tilepro_decoded_instruction
+ decoded[TILEPRO_MAX_INSTRUCTIONS_PER_BUNDLE];
+ bfd_byte opbuf[TILEPRO_BUNDLE_SIZE_IN_BYTES];
+ int status, i, num_instructions, num_printed;
+ tilepro_mnemonic padding_mnemonic;
+
+ status = (*info->read_memory_func) (memaddr, opbuf,
+ TILEPRO_BUNDLE_SIZE_IN_BYTES, info);
+ if (status != 0)
+ {
+ (*info->memory_error_func) (status, memaddr, info);
+ return -1;
+ }
+
+ info->bytes_per_line = TILEPRO_BUNDLE_SIZE_IN_BYTES;
+ info->bytes_per_chunk = TILEPRO_BUNDLE_SIZE_IN_BYTES;
+ info->octets_per_byte = 1;
+ info->display_endian = BFD_ENDIAN_LITTLE;
+
+ /* Parse the instructions in the bundle. */
+ num_instructions = parse_insn_tilepro (bfd_getl64 (opbuf), memaddr, decoded);
+
+ /* Print the instructions in the bundle. */
+ info->fprintf_func (info->stream, "{ ");
+ num_printed = 0;
+
+ /* Determine which nop opcode is used for padding and should be skipped. */
+ padding_mnemonic = TILEPRO_OPC_FNOP;
+ for (i = 0; i < num_instructions; i++)
+ {
+ if (!decoded[i].opcode->can_bundle)
+ {
+ /* Instructions that cannot be bundled are padded out with nops,
+ rather than fnops. Displaying them is always clutter. */
+ padding_mnemonic = TILEPRO_OPC_NOP;
+ break;
+ }
+ }
+
+ for (i = 0; i < num_instructions; i++)
+ {
+ const struct tilepro_opcode *opcode = decoded[i].opcode;
+ const char *name;
+ int j;
+
+ /* Do not print out fnops, unless everything is an fnop, in
+ which case we will print out just the last one. */
+ if (opcode->mnemonic == padding_mnemonic
+ && (num_printed > 0 || i + 1 < num_instructions))
+ continue;
+
+ if (num_printed > 0)
+ info->fprintf_func (info->stream, " ; ");
+ ++num_printed;
+
+ name = opcode->name;
+ if (name == NULL)
+ name = "<invalid>";
+ info->fprintf_func (info->stream, "%s", name);
+
+ for (j = 0; j < opcode->num_operands; j++)
+ {
+ int num;
+ const struct tilepro_operand *op;
+ const char *spr_name;
+
+ if (j > 0)
+ info->fprintf_func (info->stream, ",");
+ info->fprintf_func (info->stream, " ");
+
+ num = decoded[i].operand_values[j];
+
+ op = decoded[i].operands[j];
+ switch (op->type)
+ {
+ case TILEPRO_OP_TYPE_REGISTER:
+ info->fprintf_func (info->stream, "%s",
+ tilepro_register_names[num]);
+ break;
+
+ case TILEPRO_OP_TYPE_SPR:
+ spr_name = get_tilepro_spr_name(num);
+ if (spr_name != NULL)
+ info->fprintf_func (info->stream, "%s", spr_name);
+ else
+ info->fprintf_func (info->stream, "%d", num);
+ break;
+
+ case TILEPRO_OP_TYPE_IMMEDIATE:
+ {
+ bfd_vma addr = 0;
+ int found_addr = 0;
+ int addr_piece;
+
+ switch (opcode->mnemonic)
+ {
+ case TILEPRO_OPC_ADDLI:
+ if (contains_insn (TILEPRO_OPC_AULI,
+ decoded[i].operand_values[1],
+ TREG_ZERO,
+ memaddr - TILEPRO_BUNDLE_SIZE_IN_BYTES,
+ &addr_piece,
+ info))
+ {
+ addr = num + (addr_piece << 16);
+ found_addr = 1;
+ }
+ break;
+
+ case TILEPRO_OPC_AULI:
+ if (contains_insn (TILEPRO_OPC_MOVELI,
+ decoded[i].operand_values[1],
+ -1,
+ memaddr - TILEPRO_BUNDLE_SIZE_IN_BYTES,
+ &addr_piece,
+ info))
+ {
+ addr = (num << 16) + addr_piece;
+ found_addr = 1;
+ }
+ break;
+
+ default:
+ /* Operand does not look like a constructed address. */
+ break;
+ }
+
+ info->fprintf_func (info->stream, "%d", num);
+
+ if (found_addr)
+ {
+ info->fprintf_func (info->stream, " /* ");
+ info->print_address_func (addr, info);
+ info->fprintf_func (info->stream, " */");
+ }
+ }
+ break;
+
+ case TILEPRO_OP_TYPE_ADDRESS:
+ info->print_address_func ((bfd_vma)(unsigned int) num, info);
+ break;
+
+ default:
+ abort ();
+ }
+ }
+ }
+ info->fprintf_func (info->stream, " }");
+
+ return TILEPRO_BUNDLE_SIZE_IN_BYTES;
+}