1991-11-21 03:37:15 +01:00
|
|
|
/* Print IBM RS/6000 instructions for GNU software.
|
|
|
|
Copyright 1991 Free Software Foundation, Inc.
|
|
|
|
Contributed by IBM Corporation.
|
1991-11-12 16:50:47 +01:00
|
|
|
|
1991-11-21 03:37:15 +01:00
|
|
|
This file is part of GDB and the GNU 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
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
1991-11-12 16:50:47 +01:00
|
|
|
|
|
|
|
#include "defs.h"
|
1992-04-07 22:45:16 +02:00
|
|
|
#include "opcode/rs6k.h"
|
1991-11-12 16:50:47 +01:00
|
|
|
|
|
|
|
/* Print the rs6k instruction at address MEMADDR in debugged memory,
|
|
|
|
on STREAM. Returns length of the instruction, in bytes. */
|
|
|
|
|
|
|
|
int
|
|
|
|
print_insn (memaddr, stream)
|
|
|
|
CORE_ADDR memaddr;
|
|
|
|
FILE *stream;
|
|
|
|
{
|
1992-04-17 03:35:42 +02:00
|
|
|
int pop, eop, probable_eop; /* primary and extended opcodes */
|
1991-11-12 16:50:47 +01:00
|
|
|
int min, max;
|
|
|
|
int best = -1; /* found best opcode index */
|
|
|
|
int oldbest = -1;
|
|
|
|
unsigned int the_insn;
|
|
|
|
|
|
|
|
read_memory (memaddr, &the_insn, sizeof (the_insn));
|
|
|
|
pop = (unsigned)(the_insn >> 26);
|
|
|
|
min = 0, max = NOPCODES-1;
|
|
|
|
|
|
|
|
while (min < max) {
|
|
|
|
best = (min + max) / 2;
|
|
|
|
|
|
|
|
/* see if we are running in loops */
|
|
|
|
if (best == oldbest)
|
|
|
|
goto not_found;
|
|
|
|
oldbest = best;
|
|
|
|
|
|
|
|
if (pop < rs6k_ops [best].p_opcode)
|
|
|
|
max = best;
|
|
|
|
|
|
|
|
else if (pop > rs6k_ops [best].p_opcode)
|
|
|
|
min = best;
|
|
|
|
|
|
|
|
else {
|
1992-04-17 03:35:42 +02:00
|
|
|
/* Opcode matched, check extended opcode. */
|
1991-11-12 16:50:47 +01:00
|
|
|
|
|
|
|
if (rs6k_ops [best].e_opcode == -1) {
|
|
|
|
/* there is no valid extended opcode, what we've got is
|
|
|
|
just fine. */
|
|
|
|
goto insn_found;
|
|
|
|
}
|
|
|
|
|
1992-04-17 03:35:42 +02:00
|
|
|
/* Largest possible value of extended opcode. */
|
|
|
|
probable_eop = ((the_insn) >> 1) & 0x3ff;
|
|
|
|
|
|
|
|
eop = probable_eop & eopMask [rs6k_ops [best].format];
|
|
|
|
|
|
|
|
if (eop < rs6k_ops [best].e_opcode) {
|
1991-11-12 16:50:47 +01:00
|
|
|
|
|
|
|
while (pop == rs6k_ops [best].p_opcode) {
|
|
|
|
if (eop == rs6k_ops [best].e_opcode) /* found it! */
|
|
|
|
goto insn_found;
|
|
|
|
--best;
|
1992-04-17 03:35:42 +02:00
|
|
|
eop = probable_eop & eopMask [rs6k_ops [best].format];
|
1991-11-12 16:50:47 +01:00
|
|
|
}
|
|
|
|
goto not_found;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (eop > rs6k_ops [best].e_opcode) {
|
|
|
|
|
|
|
|
while (pop == rs6k_ops [best].p_opcode) {
|
|
|
|
if (eop == rs6k_ops [best].e_opcode) /* found it! */
|
|
|
|
goto insn_found;
|
|
|
|
++best;
|
1992-04-17 03:35:42 +02:00
|
|
|
eop = probable_eop & eopMask [rs6k_ops [best].format];
|
1991-11-12 16:50:47 +01:00
|
|
|
}
|
|
|
|
goto not_found;
|
|
|
|
}
|
|
|
|
|
|
|
|
else /* eop == rs6k_ops [best].e_opcode */
|
|
|
|
goto insn_found;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
best = min;
|
|
|
|
if (pop == rs6k_ops [best].p_opcode &&
|
|
|
|
(rs6k_ops [best].e_opcode == -1 || rs6k_ops [best].e_opcode == eop))
|
|
|
|
goto insn_found;
|
|
|
|
|
|
|
|
else
|
|
|
|
goto not_found;
|
|
|
|
|
|
|
|
|
|
|
|
insn_found:
|
|
|
|
print_operator (stream, memaddr, the_insn, best);
|
|
|
|
return 4;
|
|
|
|
|
|
|
|
not_found:
|
|
|
|
fprintf (stream, "0x%08x", the_insn);
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* condition code names */
|
|
|
|
static char *cond_code [] = {
|
|
|
|
"lt", "gt", "eq", "so", "ge", "le", "ne", "ns", "nl", "ng", "z", "nz" };
|
|
|
|
|
|
|
|
|
|
|
|
print_operator (stream, memaddr, insn_word, insn_no)
|
|
|
|
FILE *stream;
|
|
|
|
long memaddr;
|
|
|
|
long insn_word;
|
|
|
|
int insn_no;
|
|
|
|
{
|
1992-03-26 22:22:50 +01:00
|
|
|
char buf [20];
|
1991-11-12 16:50:47 +01:00
|
|
|
char *qq = buf;
|
|
|
|
char *pp = rs6k_ops[insn_no].opr_ext;
|
|
|
|
int tmp;
|
|
|
|
int nocomma = 0; /* true if no comma needed */
|
|
|
|
|
|
|
|
if (pp) {
|
|
|
|
while (*pp) {
|
|
|
|
|
|
|
|
switch ( *pp ) {
|
|
|
|
case '.':
|
|
|
|
if (insn_word & 0x1)
|
1992-03-26 22:22:50 +01:00
|
|
|
*qq++ = '.';
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l':
|
|
|
|
if (insn_word & 0x1)
|
|
|
|
*qq++ = 'l';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't':
|
|
|
|
if ((insn_word & 0x03e00000) == 0x01800000)
|
|
|
|
*qq++ = 't';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
if ((insn_word & 0x03e00000) == 0x00800000)
|
|
|
|
*qq++ = 'f';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'a':
|
|
|
|
if (insn_word & 0x2)
|
|
|
|
*qq++ = 'a';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'o':
|
|
|
|
if (insn_word & 0x4000)
|
|
|
|
*qq++ = 'o';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '1': /* exception #1 for bb/bc ambiguity */
|
|
|
|
tmp = (insn_word >> 21) & 0x1f; /* extract BO */
|
|
|
|
if (tmp != 0xc && tmp != 0x4) {
|
|
|
|
/* you can't use `bb' now. switch to `bc' */
|
|
|
|
*(qq-1) = 'c';
|
|
|
|
++insn_no;
|
|
|
|
pp = rs6k_ops[insn_no].opr_ext;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
++pp;
|
|
|
|
}
|
|
|
|
}
|
1992-03-26 22:22:50 +01:00
|
|
|
*qq = '\0';
|
1991-11-12 16:50:47 +01:00
|
|
|
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%s%s\t", rs6k_ops[insn_no].operator, buf);
|
1991-11-12 16:50:47 +01:00
|
|
|
|
|
|
|
/* parse the operand now. */
|
|
|
|
pp = rs6k_ops[insn_no].oprnd_format;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
switch (*pp) {
|
|
|
|
case TO :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d", (insn_word >> 21) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RT :
|
|
|
|
case RS :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "r%d", (insn_word >> 21) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LI :
|
|
|
|
tmp = (insn_word >> 16) & 0x1f;
|
|
|
|
if (tmp > 11) {
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "{unknown cond code: 0x%x}", insn_word);
|
1991-11-12 16:50:47 +01:00
|
|
|
tmp = 0;
|
|
|
|
}
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%s", cond_code [tmp]);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case A2 :
|
|
|
|
case TA14 :
|
|
|
|
tmp = (insn_word & 0xfffc);
|
|
|
|
if (tmp & 0x8000) /* fix sign extension */
|
|
|
|
tmp -= 0x10000;
|
|
|
|
|
|
|
|
if ((insn_word & 0x2) == 0) /* if AA not set */
|
|
|
|
tmp += memaddr;
|
|
|
|
|
1992-03-26 22:22:50 +01:00
|
|
|
print_address (tmp, stream);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TA24 :
|
|
|
|
tmp = insn_word & 0x03fffffc;
|
|
|
|
if (tmp & 0x2000000)
|
|
|
|
tmp -= 0x4000000;
|
|
|
|
|
|
|
|
if ((insn_word & 0x2) == 0) /* if no AA bit set */
|
|
|
|
tmp += memaddr;
|
|
|
|
|
1992-03-26 22:22:50 +01:00
|
|
|
print_address (tmp, stream);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LEV : /* for svc only */
|
|
|
|
if (insn_word & 0x2) { /* SA is set */
|
|
|
|
nocomma = 1;
|
|
|
|
}
|
|
|
|
else
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d", (insn_word >> 5) & 0x7f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FL1 : /* for svc only */
|
|
|
|
if (insn_word & 0x2) { /* SA is set */
|
|
|
|
nocomma = 1;
|
|
|
|
}
|
|
|
|
else
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d", (insn_word >> 12) & 0xf);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FL2 : /* for svc only */
|
|
|
|
nocomma = 0;
|
|
|
|
if (insn_word & 0x2) /* SA is set */
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d", (insn_word >> 2) & 0x3fff);
|
1991-11-12 16:50:47 +01:00
|
|
|
else
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d", (insn_word >> 2) & 0x7);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RA :
|
|
|
|
if (nocomma) {
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "r%d)", (insn_word >> 16) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
nocomma = 0;
|
|
|
|
}
|
|
|
|
else
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "r%d", (insn_word >> 16) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RB :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "r%d", (insn_word >> 11) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SI :
|
|
|
|
tmp = insn_word & 0xffff;
|
|
|
|
if (tmp & 0x8000)
|
|
|
|
tmp -= 0x10000;
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d", tmp);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UI :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d", insn_word & 0xffff);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BF :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d", (insn_word >> 23) & 0x7);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BFA :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d", (insn_word >> 18) & 0x7);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BT :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d", (insn_word >> 21) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BA :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d", (insn_word >> 16) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BB :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d", (insn_word >> 11) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BO :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d", (insn_word >> 21) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BI :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d", (insn_word >> 16) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SH :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d", (insn_word >> 11) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MB :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "0x%x", (insn_word >> 6) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ME :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "0x%x", (insn_word >> 1) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SPR :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d", (insn_word >> 16) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DIS :
|
|
|
|
nocomma = 1;
|
|
|
|
tmp = insn_word & 0xffff;
|
|
|
|
if (tmp & 0x8000)
|
|
|
|
tmp -= 0x10000;
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d(", tmp);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FXM :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "0x%x", (insn_word >> 12) & 0xff);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FRT :
|
|
|
|
case FRS :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "f%d", (insn_word >> 21) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FRA :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "f%d", (insn_word >> 16) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FRB :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "f%d", (insn_word >> 11) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FRC :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "f%d", (insn_word >> 6) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FLM :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "0x%x", (insn_word >> 17) & 0xff);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NB :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d", (insn_word >> 11) & 0x1f);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case I :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream, "%d", (insn_word >> 12) & 0xf);
|
1991-11-12 16:50:47 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default :
|
1992-03-26 22:22:50 +01:00
|
|
|
fprintf (stream,
|
|
|
|
"{Internal error: Unknown operand format identifier %d}",
|
|
|
|
*pp);
|
1991-11-12 16:50:47 +01:00
|
|
|
}
|
|
|
|
++pp;
|
|
|
|
|
|
|
|
if (*pp == '\0')
|
|
|
|
break;
|
|
|
|
else if (!nocomma)
|
1992-03-26 22:22:50 +01:00
|
|
|
fputc(',', stream);
|
1991-11-12 16:50:47 +01:00
|
|
|
}
|
|
|
|
}
|