2002-01-31 18:33:08 +01:00
|
|
|
/* Instruction printing code for the OpenRISC 1000
|
2005-07-01 13:16:33 +02:00
|
|
|
Copyright (C) 2002, 2005 Free Software Foundation, Inc.
|
2002-01-31 18:33:08 +01:00
|
|
|
Contributed by Damjan Lampret <lampret@opencores.org>.
|
|
|
|
Modified from a29k port.
|
|
|
|
|
|
|
|
This file is part of Binutils.
|
|
|
|
|
|
|
|
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 2 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
|
2005-07-01 13:16:33 +02:00
|
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA. */
|
2002-01-31 18:33:08 +01:00
|
|
|
|
|
|
|
#define DEBUG 0
|
|
|
|
|
|
|
|
#include "dis-asm.h"
|
|
|
|
#include "opcode/or32.h"
|
|
|
|
#include "safe-ctype.h"
|
|
|
|
#include <string.h>
|
2002-02-08 13:12:15 +01:00
|
|
|
#include <stdlib.h>
|
2002-01-31 18:33:08 +01:00
|
|
|
|
2002-02-08 13:12:15 +01:00
|
|
|
#define EXTEND29(x) ((x) & (unsigned long) 0x10000000 ? ((x) | (unsigned long) 0xf0000000) : ((x)))
|
2002-01-31 18:33:08 +01:00
|
|
|
|
|
|
|
/* Now find the four bytes of INSN_CH and put them in *INSN. */
|
|
|
|
|
|
|
|
static void
|
2005-07-01 13:16:33 +02:00
|
|
|
find_bytes_big (unsigned char *insn_ch, unsigned long *insn)
|
2002-01-31 18:33:08 +01:00
|
|
|
{
|
|
|
|
*insn =
|
|
|
|
((unsigned long) insn_ch[0] << 24) +
|
|
|
|
((unsigned long) insn_ch[1] << 16) +
|
|
|
|
((unsigned long) insn_ch[2] << 8) +
|
|
|
|
((unsigned long) insn_ch[3]);
|
|
|
|
#if DEBUG
|
|
|
|
printf ("find_bytes_big3: %x\n", *insn);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-07-01 13:16:33 +02:00
|
|
|
find_bytes_little (unsigned char *insn_ch, unsigned long *insn)
|
2002-01-31 18:33:08 +01:00
|
|
|
{
|
|
|
|
*insn =
|
|
|
|
((unsigned long) insn_ch[3] << 24) +
|
|
|
|
((unsigned long) insn_ch[2] << 16) +
|
|
|
|
((unsigned long) insn_ch[1] << 8) +
|
|
|
|
((unsigned long) insn_ch[0]);
|
|
|
|
}
|
|
|
|
|
2005-07-01 13:16:33 +02:00
|
|
|
typedef void (*find_byte_func_type) (unsigned char *, unsigned long *);
|
2002-01-31 18:33:08 +01:00
|
|
|
|
|
|
|
static unsigned long
|
2005-07-01 13:16:33 +02:00
|
|
|
or32_extract (char param_ch, char *enc_initial, unsigned long insn)
|
2002-01-31 18:33:08 +01:00
|
|
|
{
|
|
|
|
char *enc;
|
|
|
|
unsigned long ret = 0;
|
|
|
|
int opc_pos = 0;
|
|
|
|
int param_pos = 0;
|
|
|
|
|
|
|
|
for (enc = enc_initial; *enc != '\0'; enc++)
|
|
|
|
if (*enc == param_ch)
|
2002-02-08 13:12:15 +01:00
|
|
|
{
|
|
|
|
if (enc - 2 >= enc_initial && (*(enc - 2) == '0') && (*(enc - 1) == 'x'))
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
param_pos++;
|
|
|
|
}
|
2002-01-31 18:33:08 +01:00
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
printf ("or32_extract: %c %x ", param_ch, param_pos);
|
|
|
|
#endif
|
|
|
|
opc_pos = 32;
|
|
|
|
|
|
|
|
for (enc = enc_initial; *enc != '\0'; )
|
|
|
|
if ((*enc == '0') && (*(enc + 1) == 'x'))
|
|
|
|
{
|
|
|
|
opc_pos -= 4;
|
|
|
|
|
|
|
|
if ((param_ch == '0') || (param_ch == '1'))
|
|
|
|
{
|
2002-02-08 13:12:15 +01:00
|
|
|
unsigned long tmp = strtoul (enc, NULL, 16);
|
2002-01-31 18:33:08 +01:00
|
|
|
#if DEBUG
|
|
|
|
printf (" enc=%s, tmp=%x ", enc, tmp);
|
|
|
|
#endif
|
|
|
|
if (param_ch == '0')
|
|
|
|
tmp = 15 - tmp;
|
|
|
|
ret |= tmp << opc_pos;
|
|
|
|
}
|
|
|
|
enc += 3;
|
|
|
|
}
|
|
|
|
else if ((*enc == '0') || (*enc == '1'))
|
|
|
|
{
|
|
|
|
opc_pos--;
|
|
|
|
if (param_ch == *enc)
|
|
|
|
ret |= 1 << opc_pos;
|
|
|
|
enc++;
|
|
|
|
}
|
|
|
|
else if (*enc == param_ch)
|
|
|
|
{
|
|
|
|
opc_pos--;
|
|
|
|
param_pos--;
|
|
|
|
#if DEBUG
|
|
|
|
printf ("\n ret=%x opc_pos=%x, param_pos=%x\n", ret, opc_pos, param_pos);
|
|
|
|
#endif
|
|
|
|
ret += ((insn >> opc_pos) & 0x1) << param_pos;
|
|
|
|
|
|
|
|
if (!param_pos
|
|
|
|
&& letter_signed (param_ch)
|
2002-02-08 13:12:15 +01:00
|
|
|
&& ret >> (letter_range (param_ch) - 1))
|
2002-01-31 18:33:08 +01:00
|
|
|
{
|
|
|
|
#if DEBUG
|
|
|
|
printf ("\n ret=%x opc_pos=%x, param_pos=%x\n",
|
|
|
|
ret, opc_pos, param_pos);
|
|
|
|
#endif
|
|
|
|
ret |= 0xffffffff << letter_range(param_ch);
|
|
|
|
#if DEBUG
|
|
|
|
printf ("\n after conversion to signed: ret=%x\n", ret);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
enc++;
|
|
|
|
}
|
|
|
|
else if (ISALPHA (*enc))
|
|
|
|
{
|
|
|
|
opc_pos--;
|
|
|
|
enc++;
|
|
|
|
}
|
|
|
|
else if (*enc == '-')
|
|
|
|
{
|
|
|
|
opc_pos--;
|
|
|
|
enc++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
enc++;
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
printf ("ret=%x\n", ret);
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-07-01 13:16:33 +02:00
|
|
|
or32_opcode_match (unsigned long insn, char *encoding)
|
2002-01-31 18:33:08 +01:00
|
|
|
{
|
|
|
|
unsigned long ones, zeros;
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
printf ("or32_opcode_match: %.8lx\n", insn);
|
|
|
|
#endif
|
|
|
|
ones = or32_extract ('1', encoding, insn);
|
|
|
|
zeros = or32_extract ('0', encoding, insn);
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
printf ("ones: %x \n", ones);
|
|
|
|
printf ("zeros: %x \n", zeros);
|
|
|
|
#endif
|
|
|
|
if ((insn & ones) != ones)
|
|
|
|
{
|
|
|
|
#if DEBUG
|
|
|
|
printf ("ret1\n");
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((~insn & zeros) != zeros)
|
|
|
|
{
|
|
|
|
#if DEBUG
|
|
|
|
printf ("ret2\n");
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
printf ("ret3\n");
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print register to INFO->STREAM. Used only by print_insn. */
|
|
|
|
|
|
|
|
static void
|
2005-07-01 13:16:33 +02:00
|
|
|
or32_print_register (char param_ch,
|
|
|
|
char *encoding,
|
|
|
|
unsigned long insn,
|
|
|
|
struct disassemble_info *info)
|
2002-01-31 18:33:08 +01:00
|
|
|
{
|
|
|
|
int regnum = or32_extract (param_ch, encoding, insn);
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
printf ("or32_print_register: %c, %s, %x\n", param_ch, encoding, insn);
|
|
|
|
#endif
|
|
|
|
if (param_ch == 'A')
|
|
|
|
(*info->fprintf_func) (info->stream, "r%d", regnum);
|
|
|
|
else if (param_ch == 'B')
|
|
|
|
(*info->fprintf_func) (info->stream, "r%d", regnum);
|
|
|
|
else if (param_ch == 'D')
|
|
|
|
(*info->fprintf_func) (info->stream, "r%d", regnum);
|
|
|
|
else if (regnum < 16)
|
|
|
|
(*info->fprintf_func) (info->stream, "r%d", regnum);
|
|
|
|
else if (regnum < 32)
|
|
|
|
(*info->fprintf_func) (info->stream, "r%d", regnum-16);
|
|
|
|
else
|
|
|
|
(*info->fprintf_func) (info->stream, "X%d", regnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print immediate to INFO->STREAM. Used only by print_insn. */
|
|
|
|
|
|
|
|
static void
|
2005-07-01 13:16:33 +02:00
|
|
|
or32_print_immediate (char param_ch,
|
|
|
|
char *encoding,
|
|
|
|
unsigned long insn,
|
|
|
|
struct disassemble_info *info)
|
2002-01-31 18:33:08 +01:00
|
|
|
{
|
|
|
|
int imm = or32_extract(param_ch, encoding, insn);
|
|
|
|
|
|
|
|
if (letter_signed(param_ch))
|
|
|
|
(*info->fprintf_func) (info->stream, "0x%x", imm);
|
|
|
|
/* (*info->fprintf_func) (info->stream, "%d", imm); */
|
|
|
|
else
|
|
|
|
(*info->fprintf_func) (info->stream, "0x%x", imm);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print one instruction from MEMADDR on INFO->STREAM.
|
|
|
|
Return the size of the instruction (always 4 on or32). */
|
|
|
|
|
|
|
|
static int
|
2005-07-01 13:16:33 +02:00
|
|
|
print_insn (bfd_vma memaddr, struct disassemble_info *info)
|
2002-01-31 18:33:08 +01:00
|
|
|
{
|
|
|
|
/* The raw instruction. */
|
|
|
|
unsigned char insn_ch[4];
|
|
|
|
/* Address. Will be sign extened 27-bit. */
|
2002-02-08 13:12:15 +01:00
|
|
|
unsigned long addr;
|
2002-01-31 18:33:08 +01:00
|
|
|
/* The four bytes of the instruction. */
|
|
|
|
unsigned long insn;
|
2005-07-01 13:16:33 +02:00
|
|
|
find_byte_func_type find_byte_func = (find_byte_func_type) info->private_data;
|
2002-06-08 09:29:27 +02:00
|
|
|
struct or32_opcode const * opcode;
|
2002-01-31 18:33:08 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
int status =
|
|
|
|
(*info->read_memory_func) (memaddr, (bfd_byte *) &insn_ch[0], 4, info);
|
|
|
|
|
|
|
|
if (status != 0)
|
|
|
|
{
|
|
|
|
(*info->memory_error_func) (status, memaddr, info);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(*find_byte_func) (&insn_ch[0], &insn);
|
|
|
|
|
|
|
|
for (opcode = &or32_opcodes[0];
|
|
|
|
opcode < &or32_opcodes[or32_num_opcodes];
|
|
|
|
++opcode)
|
|
|
|
{
|
|
|
|
if (or32_opcode_match (insn, opcode->encoding))
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
(*info->fprintf_func) (info->stream, "%s ", opcode->name);
|
|
|
|
|
|
|
|
for (s = opcode->args; *s != '\0'; ++s)
|
|
|
|
{
|
|
|
|
switch (*s)
|
|
|
|
{
|
|
|
|
case '\0':
|
|
|
|
return 4;
|
|
|
|
|
|
|
|
case 'r':
|
|
|
|
or32_print_register (*++s, opcode->encoding, insn, info);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'X':
|
|
|
|
addr = or32_extract ('X', opcode->encoding, insn) << 2;
|
|
|
|
|
|
|
|
/* Calulate the correct address. XXX is this really correct ?? */
|
|
|
|
addr = memaddr + EXTEND29 (addr);
|
|
|
|
|
|
|
|
(*info->print_address_func)
|
|
|
|
(addr, info);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (strchr (opcode->encoding, *s))
|
|
|
|
or32_print_immediate (*s, opcode->encoding, insn, info);
|
|
|
|
else
|
|
|
|
(*info->fprintf_func) (info->stream, "%c", *s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This used to be %8x for binutils. */
|
|
|
|
(*info->fprintf_func)
|
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
|
|
|
(info->stream, ".word 0x%08lx", insn);
|
2002-01-31 18:33:08 +01:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disassemble a big-endian or32 instruction. */
|
|
|
|
|
|
|
|
int
|
2005-07-01 13:16:33 +02:00
|
|
|
print_insn_big_or32 (bfd_vma memaddr, struct disassemble_info *info)
|
2002-01-31 18:33:08 +01:00
|
|
|
{
|
2005-07-01 13:16:33 +02:00
|
|
|
info->private_data = find_bytes_big;
|
|
|
|
|
2002-01-31 18:33:08 +01:00
|
|
|
return print_insn (memaddr, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disassemble a little-endian or32 instruction. */
|
|
|
|
|
|
|
|
int
|
2005-07-01 13:16:33 +02:00
|
|
|
print_insn_little_or32 (bfd_vma memaddr, struct disassemble_info *info)
|
2002-01-31 18:33:08 +01:00
|
|
|
{
|
2005-07-01 13:16:33 +02:00
|
|
|
info->private_data = find_bytes_little;
|
2002-01-31 18:33:08 +01:00
|
|
|
return print_insn (memaddr, info);
|
|
|
|
}
|