1991-07-16 01:43:15 +02:00
|
|
|
/* Instruction printing code for the AMD 29000
|
|
|
|
Copyright (C) 1990 Free Software Foundation, Inc.
|
|
|
|
Contributed by Cygnus Support. Written by Jim Kingdon.
|
|
|
|
|
|
|
|
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
|
1993-04-02 02:18:47 +02:00
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
1991-07-16 01:43:15 +02:00
|
|
|
|
|
|
|
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
|
1993-04-02 02:18:47 +02:00
|
|
|
along with this program; if not, write to the Free Software
|
1995-07-08 00:49:42 +02:00
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
1991-07-16 01:43:15 +02:00
|
|
|
|
1993-04-02 02:18:47 +02:00
|
|
|
#include "dis-asm.h"
|
|
|
|
#include "opcode/a29k.h"
|
1991-07-16 01:43:15 +02:00
|
|
|
|
|
|
|
/* Print a symbolic representation of a general-purpose
|
|
|
|
register number NUM on STREAM.
|
|
|
|
NUM is a number as found in the instruction, not as found in
|
|
|
|
debugging symbols; it must be in the range 0-255. */
|
|
|
|
static void
|
1993-04-02 02:18:47 +02:00
|
|
|
print_general (num, info)
|
1991-07-16 01:43:15 +02:00
|
|
|
int num;
|
1993-04-02 02:18:47 +02:00
|
|
|
struct disassemble_info *info;
|
1991-07-16 01:43:15 +02:00
|
|
|
{
|
|
|
|
if (num < 128)
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "gr%d", num);
|
1991-07-16 01:43:15 +02:00
|
|
|
else
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "lr%d", num - 128);
|
1991-07-16 01:43:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Like print_general but a special-purpose register.
|
|
|
|
|
|
|
|
The mnemonics used by the AMD assembler are not quite the same
|
|
|
|
as the ones in the User's Manual. We use the ones that the
|
|
|
|
assembler uses. */
|
|
|
|
static void
|
1993-04-02 02:18:47 +02:00
|
|
|
print_special (num, info)
|
1995-11-09 02:20:32 +01:00
|
|
|
unsigned int num;
|
1993-04-02 02:18:47 +02:00
|
|
|
struct disassemble_info *info;
|
1991-07-16 01:43:15 +02:00
|
|
|
{
|
|
|
|
/* Register names of registers 0-SPEC0_NUM-1. */
|
|
|
|
static char *spec0_names[] = {
|
|
|
|
"vab", "ops", "cps", "cfg", "cha", "chd", "chc", "rbp", "tmc", "tmr",
|
1994-10-19 18:41:18 +01:00
|
|
|
"pc0", "pc1", "pc2", "mmu", "lru", "rsn", "rma0", "rmc0", "rma1", "rmc1",
|
|
|
|
"spc0", "spc1", "spc2", "iba0", "ibc0", "iba1", "ibc1", "dba", "dbc",
|
|
|
|
"cir", "cdr"
|
1991-07-16 01:43:15 +02:00
|
|
|
};
|
|
|
|
#define SPEC0_NUM ((sizeof spec0_names) / (sizeof spec0_names[0]))
|
|
|
|
|
|
|
|
/* Register names of registers 128-128+SPEC128_NUM-1. */
|
|
|
|
static char *spec128_names[] = {
|
|
|
|
"ipc", "ipa", "ipb", "q", "alu", "bp", "fc", "cr"
|
|
|
|
};
|
|
|
|
#define SPEC128_NUM ((sizeof spec128_names) / (sizeof spec128_names[0]))
|
|
|
|
|
|
|
|
/* Register names of registers 160-160+SPEC160_NUM-1. */
|
|
|
|
static char *spec160_names[] = {
|
|
|
|
"fpe", "inte", "fps", "sr163", "exop"
|
|
|
|
};
|
|
|
|
#define SPEC160_NUM ((sizeof spec160_names) / (sizeof spec160_names[0]))
|
|
|
|
|
|
|
|
if (num < SPEC0_NUM)
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, spec0_names[num]);
|
1991-07-16 01:43:15 +02:00
|
|
|
else if (num >= 128 && num < 128 + SPEC128_NUM)
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, spec128_names[num-128]);
|
1991-07-16 01:43:15 +02:00
|
|
|
else if (num >= 160 && num < 160 + SPEC160_NUM)
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, spec160_names[num-160]);
|
1991-07-16 01:43:15 +02:00
|
|
|
else
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "sr%d", num);
|
1991-07-16 01:43:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Is an instruction with OPCODE a delayed branch? */
|
|
|
|
static int
|
|
|
|
is_delayed_branch (opcode)
|
|
|
|
int opcode;
|
|
|
|
{
|
|
|
|
return (opcode == 0xa8 || opcode == 0xa9 || opcode == 0xa0 || opcode == 0xa1
|
|
|
|
|| opcode == 0xa4 || opcode == 0xa5
|
|
|
|
|| opcode == 0xb4 || opcode == 0xb5
|
|
|
|
|| opcode == 0xc4 || opcode == 0xc0
|
|
|
|
|| opcode == 0xac || opcode == 0xad
|
|
|
|
|| opcode == 0xcc);
|
|
|
|
}
|
|
|
|
|
1993-04-02 02:18:47 +02:00
|
|
|
/* Now find the four bytes of INSN and put them in *INSN{0,8,16,24}. */
|
1991-07-16 01:43:15 +02:00
|
|
|
static void
|
1993-04-02 02:18:47 +02:00
|
|
|
find_bytes_big (insn, insn0, insn8, insn16, insn24)
|
1991-07-16 01:43:15 +02:00
|
|
|
char *insn;
|
|
|
|
unsigned char *insn0;
|
|
|
|
unsigned char *insn8;
|
|
|
|
unsigned char *insn16;
|
|
|
|
unsigned char *insn24;
|
|
|
|
{
|
|
|
|
*insn24 = insn[0];
|
|
|
|
*insn16 = insn[1];
|
|
|
|
*insn8 = insn[2];
|
|
|
|
*insn0 = insn[3];
|
1993-04-02 02:18:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
find_bytes_little (insn, insn0, insn8, insn16, insn24)
|
|
|
|
char *insn;
|
|
|
|
unsigned char *insn0;
|
|
|
|
unsigned char *insn8;
|
|
|
|
unsigned char *insn16;
|
|
|
|
unsigned char *insn24;
|
|
|
|
{
|
1991-07-16 01:43:15 +02:00
|
|
|
*insn24 = insn[3];
|
|
|
|
*insn16 = insn[2];
|
|
|
|
*insn8 = insn[1];
|
|
|
|
*insn0 = insn[0];
|
|
|
|
}
|
|
|
|
|
1993-04-02 02:18:47 +02:00
|
|
|
typedef (*find_byte_func_type)
|
|
|
|
PARAMS ((char *, unsigned char *, unsigned char *,
|
|
|
|
unsigned char *, unsigned char *));
|
|
|
|
|
1994-01-06 21:37:47 +01:00
|
|
|
/* Print one instruction from MEMADDR on INFO->STREAM.
|
1993-04-02 02:18:47 +02:00
|
|
|
Return the size of the instruction (always 4 on a29k). */
|
1994-01-06 21:37:47 +01:00
|
|
|
|
1993-04-02 02:18:47 +02:00
|
|
|
static int
|
|
|
|
print_insn (memaddr, info)
|
1991-07-16 01:43:15 +02:00
|
|
|
bfd_vma memaddr;
|
1993-04-02 02:18:47 +02:00
|
|
|
struct disassemble_info *info;
|
1991-07-16 01:43:15 +02:00
|
|
|
{
|
|
|
|
/* The raw instruction. */
|
|
|
|
char insn[4];
|
|
|
|
|
|
|
|
/* The four bytes of the instruction. */
|
|
|
|
unsigned char insn24, insn16, insn8, insn0;
|
|
|
|
|
1993-04-02 02:18:47 +02:00
|
|
|
find_byte_func_type find_byte_func = (find_byte_func_type)info->private_data;
|
|
|
|
|
1993-04-02 17:27:17 +02:00
|
|
|
struct a29k_opcode CONST * opcode;
|
1991-07-16 01:43:15 +02:00
|
|
|
|
1993-04-02 02:18:47 +02:00
|
|
|
{
|
|
|
|
int status =
|
1993-05-07 05:55:10 +02:00
|
|
|
(*info->read_memory_func) (memaddr, (bfd_byte *) &insn[0], 4, info);
|
1993-04-02 02:18:47 +02:00
|
|
|
if (status != 0)
|
|
|
|
{
|
|
|
|
(*info->memory_error_func) (status, memaddr, info);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(*find_byte_func) (insn, &insn0, &insn8, &insn16, &insn24);
|
1991-07-16 01:43:15 +02:00
|
|
|
|
1994-09-15 22:46:46 +02:00
|
|
|
printf ("%02x%02x%02x%02x ", insn24, insn16, insn8, insn0);
|
|
|
|
|
1991-07-16 01:43:15 +02:00
|
|
|
/* Handle the nop (aseq 0x40,gr1,gr1) specially */
|
|
|
|
if ((insn24==0x70) && (insn16==0x40) && (insn8==0x01) && (insn0==0x01)) {
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream,"nop");
|
1991-07-16 01:43:15 +02:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The opcode is always in insn24. */
|
1993-04-02 02:18:47 +02:00
|
|
|
for (opcode = &a29k_opcodes[0];
|
|
|
|
opcode < &a29k_opcodes[num_opcodes];
|
1991-07-16 01:43:15 +02:00
|
|
|
++opcode)
|
|
|
|
{
|
1995-11-09 02:20:32 +01:00
|
|
|
if (((unsigned long) insn24 << 24) == opcode->opcode)
|
1991-07-16 01:43:15 +02:00
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "%s ", opcode->name);
|
1991-07-16 01:43:15 +02:00
|
|
|
for (s = opcode->args; *s != '\0'; ++s)
|
|
|
|
{
|
|
|
|
switch (*s)
|
|
|
|
{
|
|
|
|
case 'a':
|
1993-04-02 02:18:47 +02:00
|
|
|
print_general (insn8, info);
|
1991-07-16 01:43:15 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'b':
|
1993-04-02 02:18:47 +02:00
|
|
|
print_general (insn0, info);
|
1991-07-16 01:43:15 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
1993-04-02 02:18:47 +02:00
|
|
|
print_general (insn16, info);
|
1991-07-16 01:43:15 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'i':
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "%d", insn0);
|
1991-07-16 01:43:15 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'x':
|
1994-05-08 02:19:06 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "0x%x", (insn16 << 8) + insn0);
|
1991-07-16 01:43:15 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'h':
|
1993-04-02 02:18:47 +02:00
|
|
|
/* This used to be %x for binutils. */
|
|
|
|
(*info->fprintf_func) (info->stream, "0x%x",
|
1991-07-16 01:43:15 +02:00
|
|
|
(insn16 << 24) + (insn0 << 16));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'X':
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "%d",
|
1991-07-16 01:43:15 +02:00
|
|
|
((insn16 << 8) + insn0) | 0xffff0000);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'P':
|
|
|
|
/* This output looks just like absolute addressing, but
|
1993-04-02 02:18:47 +02:00
|
|
|
maybe that's OK (it's what the GDB m68k and EBMON
|
|
|
|
a29k disassemblers do). */
|
1991-07-16 01:43:15 +02:00
|
|
|
/* All the shifting is to sign-extend it. p*/
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->print_address_func)
|
1991-07-16 01:43:15 +02:00
|
|
|
(memaddr +
|
|
|
|
(((int)((insn16 << 10) + (insn0 << 2)) << 14) >> 14),
|
1993-04-02 02:18:47 +02:00
|
|
|
info);
|
1991-07-16 01:43:15 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'A':
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->print_address_func)
|
|
|
|
((insn16 << 10) + (insn0 << 2), info);
|
1991-07-16 01:43:15 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'e':
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "%d", insn16 >> 7);
|
1991-07-16 01:43:15 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n':
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "0x%x", insn16 & 0x7f);
|
1991-07-16 01:43:15 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v':
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "0x%x", insn16);
|
1991-07-16 01:43:15 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
1993-04-02 02:18:47 +02:00
|
|
|
print_special (insn8, info);
|
1991-07-16 01:43:15 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'u':
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "%d", insn0 >> 7);
|
1991-07-16 01:43:15 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'r':
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "%d", (insn0 >> 4) & 7);
|
1991-07-16 01:43:15 +02:00
|
|
|
break;
|
|
|
|
|
1994-10-19 18:41:18 +01:00
|
|
|
case 'I':
|
|
|
|
if ((insn16 & 3) != 0)
|
|
|
|
(*info->fprintf_func) (info->stream, "%d", insn16 & 3);
|
|
|
|
break;
|
|
|
|
|
1991-07-16 01:43:15 +02:00
|
|
|
case 'd':
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "%d", (insn0 >> 2) & 3);
|
1991-07-16 01:43:15 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "%d", insn0 & 3);
|
1991-07-16 01:43:15 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'F':
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "%d", (insn16 >> 2) & 15);
|
1991-07-16 01:43:15 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C':
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "%d", insn16 & 3);
|
1991-07-16 01:43:15 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "%c", *s);
|
1991-07-16 01:43:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now we look for a const,consth pair of instructions,
|
|
|
|
in which case we try to print the symbolic address. */
|
|
|
|
if (insn24 == 2) /* consth */
|
|
|
|
{
|
|
|
|
int errcode;
|
|
|
|
char prev_insn[4];
|
|
|
|
unsigned char prev_insn0, prev_insn8, prev_insn16, prev_insn24;
|
|
|
|
|
1993-04-02 02:18:47 +02:00
|
|
|
errcode = (*info->read_memory_func) (memaddr - 4,
|
1993-05-07 05:55:10 +02:00
|
|
|
(bfd_byte *) &prev_insn[0],
|
1993-04-02 02:18:47 +02:00
|
|
|
4,
|
|
|
|
info);
|
1991-07-16 01:43:15 +02:00
|
|
|
if (errcode == 0)
|
|
|
|
{
|
|
|
|
/* If it is a delayed branch, we need to look at the
|
|
|
|
instruction before the delayed brach to handle
|
|
|
|
things like
|
|
|
|
|
|
|
|
const _foo
|
|
|
|
call _printf
|
|
|
|
consth _foo
|
|
|
|
*/
|
1993-04-02 02:18:47 +02:00
|
|
|
(*find_byte_func) (prev_insn, &prev_insn0, &prev_insn8,
|
|
|
|
&prev_insn16, &prev_insn24);
|
1991-07-16 01:43:15 +02:00
|
|
|
if (is_delayed_branch (prev_insn24))
|
|
|
|
{
|
1993-04-02 02:18:47 +02:00
|
|
|
errcode = (*info->read_memory_func)
|
1993-05-07 05:55:10 +02:00
|
|
|
(memaddr - 8, (bfd_byte *) &prev_insn[0], 4, info);
|
1993-04-02 02:18:47 +02:00
|
|
|
(*find_byte_func) (prev_insn, &prev_insn0, &prev_insn8,
|
|
|
|
&prev_insn16, &prev_insn24);
|
1991-07-16 01:43:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If there was a problem reading memory, then assume
|
|
|
|
the previous instruction was not const. */
|
|
|
|
if (errcode == 0)
|
|
|
|
{
|
|
|
|
/* Is it const to the same register? */
|
|
|
|
if (prev_insn24 == 3
|
|
|
|
&& prev_insn8 == insn8)
|
|
|
|
{
|
1993-04-02 02:18:47 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "\t; ");
|
|
|
|
(*info->print_address_func)
|
|
|
|
(((insn16 << 24) + (insn0 << 16)
|
|
|
|
+ (prev_insn16 << 8) + (prev_insn0)),
|
|
|
|
info);
|
1991-07-16 01:43:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
1993-04-02 02:18:47 +02:00
|
|
|
/* This used to be %8x for binutils. */
|
|
|
|
(*info->fprintf_func)
|
1993-10-28 22:43:14 +01:00
|
|
|
(info->stream, ".word 0x%08x",
|
1993-04-02 02:18:47 +02:00
|
|
|
(insn24 << 24) + (insn16 << 16) + (insn8 << 8) + insn0);
|
1991-07-16 01:43:15 +02:00
|
|
|
return 4;
|
|
|
|
}
|
1993-04-02 02:18:47 +02:00
|
|
|
|
|
|
|
/* Disassemble an big-endian a29k instruction. */
|
|
|
|
int
|
|
|
|
print_insn_big_a29k (memaddr, info)
|
|
|
|
bfd_vma memaddr;
|
|
|
|
struct disassemble_info *info;
|
|
|
|
{
|
|
|
|
info->private_data = (PTR) find_bytes_big;
|
|
|
|
return print_insn (memaddr, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disassemble a little-endian a29k instruction. */
|
|
|
|
int
|
|
|
|
print_insn_little_a29k (memaddr, info)
|
|
|
|
bfd_vma memaddr;
|
|
|
|
struct disassemble_info *info;
|
|
|
|
{
|
|
|
|
info->private_data = (PTR) find_bytes_little;
|
|
|
|
return print_insn (memaddr, info);
|
|
|
|
}
|