1993-01-07 18:21:29 +00:00
|
|
|
|
/* Print mips instructions for GDB, the GNU debugger, or for objdump.
|
|
|
|
|
Copyright 1989, 1991, 1992 Free Software Foundation, Inc.
|
|
|
|
|
Contributed by Nobuyuki Hikichi(hikichi@sra.co.jp).
|
|
|
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
|
|
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
|
1996-09-09 18:27:10 +00:00
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
1993-01-07 18:21:29 +00:00
|
|
|
|
|
1993-03-31 21:43:25 +00:00
|
|
|
|
#include <ansidecl.h>
|
1993-01-07 18:21:29 +00:00
|
|
|
|
#include "sysdep.h"
|
1993-03-31 21:43:25 +00:00
|
|
|
|
#include "dis-asm.h"
|
1993-01-07 18:21:29 +00:00
|
|
|
|
#include "opcode/mips.h"
|
|
|
|
|
|
|
|
|
|
/* Mips instructions are never longer than this many bytes. */
|
|
|
|
|
#define MAXLEN 4
|
|
|
|
|
|
|
|
|
|
/* FIXME: This should be shared with gdb somehow. */
|
|
|
|
|
#define REGISTER_NAMES \
|
|
|
|
|
{ "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", \
|
|
|
|
|
"t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", \
|
|
|
|
|
"s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", \
|
|
|
|
|
"t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", \
|
|
|
|
|
"sr", "lo", "hi", "bad", "cause","pc", \
|
|
|
|
|
"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
|
|
|
|
|
"f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
|
|
|
|
|
"f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",\
|
|
|
|
|
"f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",\
|
|
|
|
|
"fsr", "fir", "fp", "inx", "rand", "tlblo","ctxt", "tlbhi",\
|
|
|
|
|
"epc", "prid"\
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static CONST char * CONST reg_names[] = REGISTER_NAMES;
|
|
|
|
|
|
|
|
|
|
/* subroutine */
|
1993-03-31 21:43:25 +00:00
|
|
|
|
static void
|
|
|
|
|
print_insn_arg (d, l, pc, info)
|
* mips-opc.c: Change div machine instruction to be z,s,t rather
than s,t. Change div macro to be d,v,t rather than d,s,t.
Likewise for divu, ddiv, ddivu. Added z,s,t case for drem, dremu,
rem and remu which generates only the corresponding div
instruction. This is for compatibility with the MIPS assembler,
which only generates the simple machine instruction when an
explicit destination of $0 is used.
* mips-dis.c (print_insn_arg): Handle 'z' (always register zero).
1993-09-02 17:14:10 +00:00
|
|
|
|
const char *d;
|
1993-03-31 21:43:25 +00:00
|
|
|
|
register unsigned long int l;
|
1993-01-07 18:21:29 +00:00
|
|
|
|
bfd_vma pc;
|
1993-03-31 21:43:25 +00:00
|
|
|
|
struct disassemble_info *info;
|
1993-01-07 18:21:29 +00:00
|
|
|
|
{
|
1993-07-07 17:37:11 +00:00
|
|
|
|
int delta;
|
|
|
|
|
|
1993-01-07 18:21:29 +00:00
|
|
|
|
switch (*d)
|
|
|
|
|
{
|
|
|
|
|
case ',':
|
|
|
|
|
case '(':
|
|
|
|
|
case ')':
|
1993-03-31 21:43:25 +00:00
|
|
|
|
(*info->fprintf_func) (info->stream, "%c", *d);
|
1993-01-07 18:21:29 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 's':
|
1993-07-07 17:37:11 +00:00
|
|
|
|
case 'b':
|
|
|
|
|
case 'r':
|
|
|
|
|
case 'v':
|
1993-03-31 21:43:25 +00:00
|
|
|
|
(*info->fprintf_func) (info->stream, "$%s",
|
|
|
|
|
reg_names[(l >> OP_SH_RS) & OP_MASK_RS]);
|
1993-01-07 18:21:29 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 't':
|
1993-07-07 17:37:11 +00:00
|
|
|
|
case 'w':
|
1993-03-31 21:43:25 +00:00
|
|
|
|
(*info->fprintf_func) (info->stream, "$%s",
|
|
|
|
|
reg_names[(l >> OP_SH_RT) & OP_MASK_RT]);
|
1993-01-07 18:21:29 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'i':
|
1993-07-07 17:37:11 +00:00
|
|
|
|
case 'u':
|
1996-09-09 18:27:10 +00:00
|
|
|
|
(*info->fprintf_func) (info->stream, "0x%x",
|
1993-03-31 21:43:25 +00:00
|
|
|
|
(l >> OP_SH_IMMEDIATE) & OP_MASK_IMMEDIATE);
|
1993-01-07 18:21:29 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'j': /* same as i, but sign-extended */
|
1993-07-07 17:37:11 +00:00
|
|
|
|
case 'o':
|
|
|
|
|
delta = (l >> OP_SH_DELTA) & OP_MASK_DELTA;
|
|
|
|
|
if (delta & 0x8000)
|
|
|
|
|
delta |= ~0xffff;
|
1993-03-31 21:43:25 +00:00
|
|
|
|
(*info->fprintf_func) (info->stream, "%d",
|
1993-07-07 17:37:11 +00:00
|
|
|
|
delta);
|
1993-01-07 18:21:29 +00:00
|
|
|
|
break;
|
|
|
|
|
|
1996-09-09 18:27:10 +00:00
|
|
|
|
case 'h':
|
|
|
|
|
(*info->fprintf_func) (info->stream, "0x%x",
|
|
|
|
|
(unsigned int) ((l >> OP_SH_PREFX)
|
|
|
|
|
& OP_MASK_PREFX));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'k':
|
|
|
|
|
(*info->fprintf_func) (info->stream, "0x%x",
|
|
|
|
|
(unsigned int) ((l >> OP_SH_CACHE)
|
|
|
|
|
& OP_MASK_CACHE));
|
|
|
|
|
break;
|
|
|
|
|
|
1993-01-07 18:21:29 +00:00
|
|
|
|
case 'a':
|
1993-07-07 17:37:11 +00:00
|
|
|
|
(*info->print_address_func)
|
|
|
|
|
(((pc & 0xF0000000) | (((l >> OP_SH_TARGET) & OP_MASK_TARGET) << 2)),
|
|
|
|
|
info);
|
1993-01-07 18:21:29 +00:00
|
|
|
|
break;
|
|
|
|
|
|
1993-07-07 17:37:11 +00:00
|
|
|
|
case 'p':
|
|
|
|
|
/* sign extend the displacement */
|
|
|
|
|
delta = (l >> OP_SH_DELTA) & OP_MASK_DELTA;
|
|
|
|
|
if (delta & 0x8000)
|
|
|
|
|
delta |= ~0xffff;
|
|
|
|
|
(*info->print_address_func)
|
|
|
|
|
((delta << 2) + pc + 4,
|
|
|
|
|
info);
|
1993-01-07 18:21:29 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'd':
|
1993-03-31 21:43:25 +00:00
|
|
|
|
(*info->fprintf_func) (info->stream, "$%s",
|
|
|
|
|
reg_names[(l >> OP_SH_RD) & OP_MASK_RD]);
|
1993-01-07 18:21:29 +00:00
|
|
|
|
break;
|
|
|
|
|
|
* mips-opc.c: Change div machine instruction to be z,s,t rather
than s,t. Change div macro to be d,v,t rather than d,s,t.
Likewise for divu, ddiv, ddivu. Added z,s,t case for drem, dremu,
rem and remu which generates only the corresponding div
instruction. This is for compatibility with the MIPS assembler,
which only generates the simple machine instruction when an
explicit destination of $0 is used.
* mips-dis.c (print_insn_arg): Handle 'z' (always register zero).
1993-09-02 17:14:10 +00:00
|
|
|
|
case 'z':
|
|
|
|
|
(*info->fprintf_func) (info->stream, "$%s", reg_names[0]);
|
|
|
|
|
break;
|
|
|
|
|
|
1993-07-07 17:37:11 +00:00
|
|
|
|
case '<':
|
1993-03-31 21:43:25 +00:00
|
|
|
|
(*info->fprintf_func) (info->stream, "0x%x",
|
|
|
|
|
(l >> OP_SH_SHAMT) & OP_MASK_SHAMT);
|
1993-01-07 18:21:29 +00:00
|
|
|
|
break;
|
|
|
|
|
|
1993-07-07 17:37:11 +00:00
|
|
|
|
case 'c':
|
1993-03-31 21:43:25 +00:00
|
|
|
|
(*info->fprintf_func) (info->stream, "0x%x",
|
|
|
|
|
(l >> OP_SH_CODE) & OP_MASK_CODE);
|
1993-01-07 18:21:29 +00:00
|
|
|
|
break;
|
|
|
|
|
|
1993-07-07 17:37:11 +00:00
|
|
|
|
case 'C':
|
|
|
|
|
(*info->fprintf_func) (info->stream, "0x%x",
|
|
|
|
|
(l >> OP_SH_COPZ) & OP_MASK_COPZ);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'B':
|
|
|
|
|
(*info->fprintf_func) (info->stream, "0x%x",
|
|
|
|
|
(l >> OP_SH_SYSCALL) & OP_MASK_SYSCALL);
|
|
|
|
|
break;
|
|
|
|
|
|
1993-01-07 18:21:29 +00:00
|
|
|
|
case 'S':
|
1993-07-07 17:37:11 +00:00
|
|
|
|
case 'V':
|
1993-03-31 21:43:25 +00:00
|
|
|
|
(*info->fprintf_func) (info->stream, "$f%d",
|
|
|
|
|
(l >> OP_SH_FS) & OP_MASK_FS);
|
1993-01-07 18:21:29 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'T':
|
1993-07-07 17:37:11 +00:00
|
|
|
|
case 'W':
|
1993-03-31 21:43:25 +00:00
|
|
|
|
(*info->fprintf_func) (info->stream, "$f%d",
|
|
|
|
|
(l >> OP_SH_FT) & OP_MASK_FT);
|
1993-01-07 18:21:29 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'D':
|
1993-03-31 21:43:25 +00:00
|
|
|
|
(*info->fprintf_func) (info->stream, "$f%d",
|
|
|
|
|
(l >> OP_SH_FD) & OP_MASK_FD);
|
1993-01-07 18:21:29 +00:00
|
|
|
|
break;
|
|
|
|
|
|
1996-09-09 18:27:10 +00:00
|
|
|
|
case 'R':
|
|
|
|
|
(*info->fprintf_func) (info->stream, "$f%d",
|
|
|
|
|
(l >> OP_SH_FR) & OP_MASK_FR);
|
|
|
|
|
break;
|
|
|
|
|
|
1993-07-07 17:37:11 +00:00
|
|
|
|
case 'E':
|
|
|
|
|
(*info->fprintf_func) (info->stream, "$%d",
|
|
|
|
|
(l >> OP_SH_RT) & OP_MASK_RT);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'G':
|
|
|
|
|
(*info->fprintf_func) (info->stream, "$%d",
|
|
|
|
|
(l >> OP_SH_RD) & OP_MASK_RD);
|
|
|
|
|
break;
|
|
|
|
|
|
1996-09-09 18:27:10 +00:00
|
|
|
|
case 'N':
|
|
|
|
|
(*info->fprintf_func) (info->stream, "$fcc%d",
|
|
|
|
|
(l >> OP_SH_BCC) & OP_MASK_BCC);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'M':
|
|
|
|
|
(*info->fprintf_func) (info->stream, "$fcc%d",
|
|
|
|
|
(l >> OP_SH_CCC) & OP_MASK_CCC);
|
|
|
|
|
break;
|
|
|
|
|
|
1993-01-07 18:21:29 +00:00
|
|
|
|
default:
|
1993-03-31 21:43:25 +00:00
|
|
|
|
(*info->fprintf_func) (info->stream,
|
|
|
|
|
"# internal error, undefined modifier(%c)", *d);
|
1993-01-07 18:21:29 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print the mips instruction at address MEMADDR in debugged memory,
|
1993-03-31 21:43:25 +00:00
|
|
|
|
on using INFO. Returns length of the instruction, in bytes, which is
|
1993-01-07 18:21:29 +00:00
|
|
|
|
always 4. BIGENDIAN must be 1 if this is big-endian code, 0 if
|
|
|
|
|
this is little-endian code. */
|
|
|
|
|
|
1996-09-09 18:27:10 +00:00
|
|
|
|
static int
|
1993-03-31 21:43:25 +00:00
|
|
|
|
_print_insn_mips (memaddr, word, info)
|
1993-01-07 18:21:29 +00:00
|
|
|
|
bfd_vma memaddr;
|
1993-03-31 21:43:25 +00:00
|
|
|
|
struct disassemble_info *info;
|
|
|
|
|
unsigned long int word;
|
1993-01-07 18:21:29 +00:00
|
|
|
|
{
|
1996-09-09 18:27:10 +00:00
|
|
|
|
register const struct mips_opcode *op;
|
|
|
|
|
static boolean init = 0;
|
|
|
|
|
static const struct mips_opcode *mips_hash[OP_MASK_OP + 1];
|
1993-01-07 18:21:29 +00:00
|
|
|
|
|
1996-09-09 18:27:10 +00:00
|
|
|
|
/* Build a hash table to shorten the search time. */
|
|
|
|
|
if (! init)
|
1993-01-07 18:21:29 +00:00
|
|
|
|
{
|
1996-09-09 18:27:10 +00:00
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i <= OP_MASK_OP; i++)
|
1993-07-07 17:37:11 +00:00
|
|
|
|
{
|
1996-09-09 18:27:10 +00:00
|
|
|
|
for (op = mips_opcodes; op < &mips_opcodes[NUMOPCODES]; op++)
|
|
|
|
|
{
|
|
|
|
|
if (op->pinfo == INSN_MACRO)
|
|
|
|
|
continue;
|
|
|
|
|
if (i == ((op->match >> OP_SH_OP) & OP_MASK_OP))
|
|
|
|
|
{
|
|
|
|
|
mips_hash[i] = op;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init = 1;
|
1993-01-07 18:21:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-09-09 18:27:10 +00:00
|
|
|
|
op = mips_hash[(word >> OP_SH_OP) & OP_MASK_OP];
|
|
|
|
|
if (op != NULL)
|
1993-01-07 18:21:29 +00:00
|
|
|
|
{
|
1996-09-09 18:27:10 +00:00
|
|
|
|
for (; op < &mips_opcodes[NUMOPCODES]; op++)
|
|
|
|
|
{
|
|
|
|
|
if (op->pinfo != INSN_MACRO && (word & op->mask) == op->match)
|
|
|
|
|
{
|
|
|
|
|
register const char *d;
|
|
|
|
|
|
|
|
|
|
(*info->fprintf_func) (info->stream, "%s", op->name);
|
|
|
|
|
|
|
|
|
|
d = op->args;
|
|
|
|
|
if (d != NULL)
|
|
|
|
|
{
|
|
|
|
|
(*info->fprintf_func) (info->stream, " ");
|
|
|
|
|
for (; *d != '\0'; d++)
|
|
|
|
|
print_insn_arg (d, word, memaddr, info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
1993-01-07 18:21:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-09-09 18:27:10 +00:00
|
|
|
|
/* Handle undefined instructions. */
|
|
|
|
|
(*info->fprintf_func) (info->stream, "0x%x", word);
|
1993-01-07 18:21:29 +00:00
|
|
|
|
return 4;
|
|
|
|
|
}
|
1993-03-31 21:43:25 +00:00
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
print_insn_big_mips (memaddr, info)
|
|
|
|
|
bfd_vma memaddr;
|
|
|
|
|
struct disassemble_info *info;
|
|
|
|
|
{
|
|
|
|
|
bfd_byte buffer[4];
|
|
|
|
|
int status = (*info->read_memory_func) (memaddr, buffer, 4, info);
|
|
|
|
|
if (status == 0)
|
1996-09-09 18:27:10 +00:00
|
|
|
|
return _print_insn_mips (memaddr, (unsigned long) bfd_getb32 (buffer), info);
|
1993-03-31 21:43:25 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
(*info->memory_error_func) (status, memaddr, info);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
print_insn_little_mips (memaddr, info)
|
|
|
|
|
bfd_vma memaddr;
|
|
|
|
|
struct disassemble_info *info;
|
|
|
|
|
{
|
|
|
|
|
bfd_byte buffer[4];
|
|
|
|
|
int status = (*info->read_memory_func) (memaddr, buffer, 4, info);
|
|
|
|
|
if (status == 0)
|
1996-09-09 18:27:10 +00:00
|
|
|
|
return _print_insn_mips (memaddr, (unsigned long) bfd_getl32 (buffer), info);
|
1993-03-31 21:43:25 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
(*info->memory_error_func) (status, memaddr, info);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|