2001-02-19 00:33:11 +01:00
|
|
|
/* Print DEC PDP-11 instructions.
|
2019-01-01 11:31:27 +01:00
|
|
|
Copyright (C) 2001-2019 Free Software Foundation, Inc.
|
2001-02-19 00:33:11 +01:00
|
|
|
|
2007-07-05 11:49:03 +02:00
|
|
|
This file is part of the GNU opcodes library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify
|
2005-07-01 13:16:33 +02:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-07-05 11:49:03 +02:00
|
|
|
the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
any later version.
|
2001-02-19 00:33:11 +01:00
|
|
|
|
2007-07-05 11:49:03 +02:00
|
|
|
It 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.
|
2001-02-19 00:33:11 +01:00
|
|
|
|
2005-07-01 13:16:33 +02:00
|
|
|
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. */
|
2001-02-19 00:33:11 +01:00
|
|
|
|
2001-09-20 17:28:25 +02:00
|
|
|
#include "sysdep.h"
|
Move print_insn_XXX to an opcodes internal header
With the changes done in previous patches, print_insn_XXX functions
don't have to be external visible out of opcodes, because both gdb
and objdump select disassemblers through a single interface.
This patch moves these print_insn_XXX declarations from
include/dis-asm.h to opcodes/disassemble.h, which is a new header
added by this patch.
include:
2017-05-24 Yao Qi <yao.qi@linaro.org>
* dis-asm.h: Move some function declarations to
opcodes/disassemble.h.
opcodes:
2017-05-24 Yao Qi <yao.qi@linaro.org>
* alpha-dis.c: Include disassemble.h, don't include
dis-asm.h.
* avr-dis.c, bfin-dis.c, cr16-dis.c: Likewise.
* crx-dis.c, d10v-dis.c, d30v-dis.c: Likewise.
* disassemble.c, dlx-dis.c, epiphany-dis.c: Likewise.
* fr30-dis.c, ft32-dis.c, h8300-dis.c, h8500-dis.c: Likewise.
* hppa-dis.c, i370-dis.c, i386-dis.c: Likewise.
* i860-dis.c, i960-dis.c, ip2k-dis.c: Likewise.
* iq2000-dis.c, lm32-dis.c, m10200-dis.c: Likewise.
* m10300-dis.c, m32r-dis.c, m68hc11-dis.c: Likewise.
* m68k-dis.c, m88k-dis.c, mcore-dis.c: Likewise.
* metag-dis.c, microblaze-dis.c, mmix-dis.c: Likewise.
* moxie-dis.c, msp430-dis.c, mt-dis.c:
* nds32-dis.c, nios2-dis.c, ns32k-dis.c: Likewise.
* or1k-dis.c, pdp11-dis.c, pj-dis.c: Likewise.
* ppc-dis.c, pru-dis.c, riscv-dis.c: Likewise.
* rl78-dis.c, s390-dis.c, score-dis.c: Likewise.
* sh-dis.c, sh64-dis.c, tic30-dis.c: Likewise.
* tic4x-dis.c, tic54x-dis.c, tic6x-dis.c: Likewise.
* tic80-dis.c, tilegx-dis.c, tilepro-dis.c: Likewise.
* v850-dis.c, vax-dis.c, visium-dis.c: Likewise.
* w65-dis.c, wasm32-dis.c, xc16x-dis.c: Likewise.
* xgate-dis.c, xstormy16-dis.c, xtensa-dis.c: Likewise.
* z80-dis.c, z8k-dis.c: Likewise.
* disassemble.h: New file.
2017-05-24 18:23:52 +02:00
|
|
|
#include "disassemble.h"
|
2001-02-19 00:33:11 +01:00
|
|
|
#include "opcode/pdp11.h"
|
|
|
|
|
|
|
|
#define AFTER_INSTRUCTION "\t"
|
|
|
|
#define OPERAND_SEPARATOR ", "
|
|
|
|
|
2005-07-01 13:16:33 +02:00
|
|
|
#define JUMP 0x1000 /* Flag that this operand is used in a jump. */
|
2001-02-19 00:33:11 +01:00
|
|
|
|
|
|
|
#define FPRINTF (*info->fprintf_func)
|
|
|
|
#define F info->stream
|
|
|
|
|
2005-07-01 13:16:33 +02:00
|
|
|
/* Sign-extend a 16-bit number in an int. */
|
2001-02-19 00:33:11 +01:00
|
|
|
#define SIGN_BITS (8 * sizeof (int) - 16)
|
|
|
|
#define sign_extend(x) (((x) << SIGN_BITS) >> SIGN_BITS)
|
|
|
|
|
|
|
|
static int
|
2005-07-01 13:16:33 +02:00
|
|
|
read_word (bfd_vma memaddr, int *word, disassemble_info *info)
|
2001-02-19 00:33:11 +01:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
bfd_byte x[2];
|
|
|
|
|
|
|
|
status = (*info->read_memory_func) (memaddr, x, 2, info);
|
|
|
|
if (status != 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*word = x[1] << 8 | x[0];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-07-01 13:16:33 +02:00
|
|
|
print_signed_octal (int n, disassemble_info *info)
|
2001-02-19 00:33:11 +01:00
|
|
|
{
|
|
|
|
if (n < 0)
|
|
|
|
FPRINTF (F, "-%o", -n);
|
|
|
|
else
|
|
|
|
FPRINTF (F, "%o", n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-07-01 13:16:33 +02:00
|
|
|
print_reg (int reg, disassemble_info *info)
|
2001-02-19 00:33:11 +01:00
|
|
|
{
|
2005-07-01 13:16:33 +02:00
|
|
|
/* Mask off the addressing mode, if any. */
|
2001-02-19 00:33:11 +01:00
|
|
|
reg &= 7;
|
|
|
|
|
|
|
|
switch (reg)
|
|
|
|
{
|
|
|
|
case 0: case 1: case 2: case 3: case 4: case 5:
|
|
|
|
FPRINTF (F, "r%d", reg); break;
|
|
|
|
case 6: FPRINTF (F, "sp"); break;
|
|
|
|
case 7: FPRINTF (F, "pc"); break;
|
2002-12-02 14:13:37 +01:00
|
|
|
default: ; /* error */
|
2001-02-19 00:33:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-07-01 13:16:33 +02:00
|
|
|
print_freg (int freg, disassemble_info *info)
|
2001-02-19 00:33:11 +01:00
|
|
|
{
|
|
|
|
FPRINTF (F, "fr%d", freg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-07-01 13:16:33 +02:00
|
|
|
print_operand (bfd_vma *memaddr, int code, disassemble_info *info)
|
2001-02-19 00:33:11 +01:00
|
|
|
{
|
|
|
|
int mode = (code >> 3) & 7;
|
|
|
|
int reg = code & 7;
|
|
|
|
int disp;
|
|
|
|
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
print_reg (reg, info);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
FPRINTF (F, "(");
|
|
|
|
print_reg (reg, info);
|
|
|
|
FPRINTF (F, ")");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (reg == 7)
|
|
|
|
{
|
|
|
|
int data;
|
2005-07-01 13:16:33 +02:00
|
|
|
|
2001-02-19 00:33:11 +01:00
|
|
|
if (read_word (*memaddr, &data, info) < 0)
|
|
|
|
return -1;
|
|
|
|
FPRINTF (F, "$");
|
|
|
|
print_signed_octal (sign_extend (data), info);
|
|
|
|
*memaddr += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FPRINTF (F, "(");
|
|
|
|
print_reg (reg, info);
|
|
|
|
FPRINTF (F, ")+");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (reg == 7)
|
|
|
|
{
|
|
|
|
int address;
|
2005-07-01 13:16:33 +02:00
|
|
|
|
2001-02-19 00:33:11 +01:00
|
|
|
if (read_word (*memaddr, &address, info) < 0)
|
|
|
|
return -1;
|
|
|
|
FPRINTF (F, "*$%o", address);
|
|
|
|
*memaddr += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FPRINTF (F, "*(");
|
|
|
|
print_reg (reg, info);
|
|
|
|
FPRINTF (F, ")+");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
FPRINTF (F, "-(");
|
|
|
|
print_reg (reg, info);
|
|
|
|
FPRINTF (F, ")");
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
FPRINTF (F, "*-(");
|
|
|
|
print_reg (reg, info);
|
|
|
|
FPRINTF (F, ")");
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
case 7:
|
|
|
|
if (read_word (*memaddr, &disp, info) < 0)
|
|
|
|
return -1;
|
|
|
|
*memaddr += 2;
|
|
|
|
if (reg == 7)
|
|
|
|
{
|
|
|
|
bfd_vma address = *memaddr + sign_extend (disp);
|
2005-07-01 13:16:33 +02:00
|
|
|
|
2002-03-05 04:09:53 +01:00
|
|
|
if (mode == 7)
|
|
|
|
FPRINTF (F, "*");
|
2001-02-19 00:33:11 +01:00
|
|
|
if (!(code & JUMP))
|
2002-03-05 04:09:53 +01:00
|
|
|
FPRINTF (F, "$");
|
2001-02-19 00:33:11 +01:00
|
|
|
(*info->print_address_func) (address, info);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (mode == 7)
|
|
|
|
FPRINTF (F, "*");
|
|
|
|
print_signed_octal (sign_extend (disp), info);
|
|
|
|
FPRINTF (F, "(");
|
|
|
|
print_reg (reg, info);
|
|
|
|
FPRINTF (F, ")");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-03-05 04:09:53 +01:00
|
|
|
static int
|
2005-07-01 13:16:33 +02:00
|
|
|
print_foperand (bfd_vma *memaddr, int code, disassemble_info *info)
|
2002-03-05 04:09:53 +01:00
|
|
|
{
|
|
|
|
int mode = (code >> 3) & 7;
|
|
|
|
int reg = code & 7;
|
|
|
|
|
|
|
|
if (mode == 0)
|
|
|
|
print_freg (reg, info);
|
|
|
|
else
|
|
|
|
return print_operand (memaddr, code, info);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-02-19 00:33:11 +01:00
|
|
|
/* Print the PDP-11 instruction at address MEMADDR in debugged memory,
|
|
|
|
on INFO->STREAM. Returns length of the instruction, in bytes. */
|
|
|
|
|
|
|
|
int
|
2005-07-01 13:16:33 +02:00
|
|
|
print_insn_pdp11 (bfd_vma memaddr, disassemble_info *info)
|
2001-02-19 00:33:11 +01:00
|
|
|
{
|
|
|
|
bfd_vma start_memaddr = memaddr;
|
|
|
|
int opcode;
|
|
|
|
int src, dst;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
info->bytes_per_line = 6;
|
|
|
|
info->bytes_per_chunk = 2;
|
|
|
|
info->display_endian = BFD_ENDIAN_LITTLE;
|
|
|
|
|
|
|
|
if (read_word (memaddr, &opcode, info) != 0)
|
|
|
|
return -1;
|
|
|
|
memaddr += 2;
|
|
|
|
|
|
|
|
src = (opcode >> 6) & 0x3f;
|
|
|
|
dst = opcode & 0x3f;
|
|
|
|
|
|
|
|
for (i = 0; i < pdp11_num_opcodes; i++)
|
|
|
|
{
|
|
|
|
#define OP pdp11_opcodes[i]
|
|
|
|
if ((opcode & OP.mask) == OP.opcode)
|
|
|
|
switch (OP.type)
|
|
|
|
{
|
|
|
|
case PDP11_OPCODE_NO_OPS:
|
2012-08-01 02:41:35 +02:00
|
|
|
FPRINTF (F, "%s", OP.name);
|
2001-11-23 08:09:48 +01:00
|
|
|
goto done;
|
2001-02-19 00:33:11 +01:00
|
|
|
case PDP11_OPCODE_REG:
|
2012-08-01 02:41:35 +02:00
|
|
|
FPRINTF (F, "%s", OP.name);
|
2001-02-19 00:33:11 +01:00
|
|
|
FPRINTF (F, AFTER_INSTRUCTION);
|
|
|
|
print_reg (dst, info);
|
2001-11-23 08:09:48 +01:00
|
|
|
goto done;
|
2001-02-19 00:33:11 +01:00
|
|
|
case PDP11_OPCODE_OP:
|
2012-08-01 02:41:35 +02:00
|
|
|
FPRINTF (F, "%s", OP.name);
|
2001-02-19 00:33:11 +01:00
|
|
|
FPRINTF (F, AFTER_INSTRUCTION);
|
|
|
|
if (strcmp (OP.name, "jmp") == 0)
|
|
|
|
dst |= JUMP;
|
|
|
|
if (print_operand (&memaddr, dst, info) < 0)
|
|
|
|
return -1;
|
2001-11-23 08:09:48 +01:00
|
|
|
goto done;
|
2002-03-05 04:09:53 +01:00
|
|
|
case PDP11_OPCODE_FOP:
|
2012-08-01 02:41:35 +02:00
|
|
|
FPRINTF (F, "%s", OP.name);
|
2002-03-05 04:09:53 +01:00
|
|
|
FPRINTF (F, AFTER_INSTRUCTION);
|
|
|
|
if (strcmp (OP.name, "jmp") == 0)
|
|
|
|
dst |= JUMP;
|
|
|
|
if (print_foperand (&memaddr, dst, info) < 0)
|
|
|
|
return -1;
|
|
|
|
goto done;
|
2001-02-19 00:33:11 +01:00
|
|
|
case PDP11_OPCODE_REG_OP:
|
2012-08-01 02:41:35 +02:00
|
|
|
FPRINTF (F, "%s", OP.name);
|
2001-02-19 00:33:11 +01:00
|
|
|
FPRINTF (F, AFTER_INSTRUCTION);
|
|
|
|
print_reg (src, info);
|
|
|
|
FPRINTF (F, OPERAND_SEPARATOR);
|
|
|
|
if (strcmp (OP.name, "jsr") == 0)
|
|
|
|
dst |= JUMP;
|
|
|
|
if (print_operand (&memaddr, dst, info) < 0)
|
|
|
|
return -1;
|
2001-11-23 08:09:48 +01:00
|
|
|
goto done;
|
2001-02-19 00:33:11 +01:00
|
|
|
case PDP11_OPCODE_REG_OP_REV:
|
2012-08-01 02:41:35 +02:00
|
|
|
FPRINTF (F, "%s", OP.name);
|
2001-02-19 00:33:11 +01:00
|
|
|
FPRINTF (F, AFTER_INSTRUCTION);
|
|
|
|
if (print_operand (&memaddr, dst, info) < 0)
|
|
|
|
return -1;
|
|
|
|
FPRINTF (F, OPERAND_SEPARATOR);
|
|
|
|
print_reg (src, info);
|
2001-11-23 08:09:48 +01:00
|
|
|
goto done;
|
2002-03-05 04:09:53 +01:00
|
|
|
case PDP11_OPCODE_AC_FOP:
|
|
|
|
{
|
|
|
|
int ac = (opcode & 0xe0) >> 6;
|
2012-08-01 02:41:35 +02:00
|
|
|
FPRINTF (F, "%s", OP.name);
|
2002-03-05 04:09:53 +01:00
|
|
|
FPRINTF (F, AFTER_INSTRUCTION);
|
|
|
|
print_freg (ac, info);
|
|
|
|
FPRINTF (F, OPERAND_SEPARATOR);
|
|
|
|
if (print_foperand (&memaddr, dst, info) < 0)
|
|
|
|
return -1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
case PDP11_OPCODE_FOP_AC:
|
|
|
|
{
|
|
|
|
int ac = (opcode & 0xe0) >> 6;
|
2012-08-01 02:41:35 +02:00
|
|
|
FPRINTF (F, "%s", OP.name);
|
2002-03-05 04:09:53 +01:00
|
|
|
FPRINTF (F, AFTER_INSTRUCTION);
|
|
|
|
if (print_foperand (&memaddr, dst, info) < 0)
|
|
|
|
return -1;
|
|
|
|
FPRINTF (F, OPERAND_SEPARATOR);
|
|
|
|
print_freg (ac, info);
|
|
|
|
goto done;
|
|
|
|
}
|
2001-02-19 00:33:11 +01:00
|
|
|
case PDP11_OPCODE_AC_OP:
|
|
|
|
{
|
|
|
|
int ac = (opcode & 0xe0) >> 6;
|
2012-08-01 02:41:35 +02:00
|
|
|
FPRINTF (F, "%s", OP.name);
|
2001-02-19 00:33:11 +01:00
|
|
|
FPRINTF (F, AFTER_INSTRUCTION);
|
|
|
|
print_freg (ac, info);
|
|
|
|
FPRINTF (F, OPERAND_SEPARATOR);
|
|
|
|
if (print_operand (&memaddr, dst, info) < 0)
|
|
|
|
return -1;
|
2001-11-23 08:09:48 +01:00
|
|
|
goto done;
|
2001-02-19 00:33:11 +01:00
|
|
|
}
|
2002-03-05 04:09:53 +01:00
|
|
|
case PDP11_OPCODE_OP_AC:
|
|
|
|
{
|
|
|
|
int ac = (opcode & 0xe0) >> 6;
|
2012-08-01 02:41:35 +02:00
|
|
|
FPRINTF (F, "%s", OP.name);
|
2002-03-05 04:09:53 +01:00
|
|
|
FPRINTF (F, AFTER_INSTRUCTION);
|
|
|
|
if (print_operand (&memaddr, dst, info) < 0)
|
|
|
|
return -1;
|
|
|
|
FPRINTF (F, OPERAND_SEPARATOR);
|
|
|
|
print_freg (ac, info);
|
|
|
|
goto done;
|
|
|
|
}
|
2001-02-19 00:33:11 +01:00
|
|
|
case PDP11_OPCODE_OP_OP:
|
2012-08-01 02:41:35 +02:00
|
|
|
FPRINTF (F, "%s", OP.name);
|
2001-02-19 00:33:11 +01:00
|
|
|
FPRINTF (F, AFTER_INSTRUCTION);
|
|
|
|
if (print_operand (&memaddr, src, info) < 0)
|
|
|
|
return -1;
|
|
|
|
FPRINTF (F, OPERAND_SEPARATOR);
|
|
|
|
if (print_operand (&memaddr, dst, info) < 0)
|
|
|
|
return -1;
|
2001-11-23 08:09:48 +01:00
|
|
|
goto done;
|
2001-02-19 00:33:11 +01:00
|
|
|
case PDP11_OPCODE_DISPL:
|
|
|
|
{
|
|
|
|
int displ = (opcode & 0xff) << 8;
|
|
|
|
bfd_vma address = memaddr + (sign_extend (displ) >> 7);
|
2012-08-01 02:41:35 +02:00
|
|
|
FPRINTF (F, "%s", OP.name);
|
2001-02-19 00:33:11 +01:00
|
|
|
FPRINTF (F, AFTER_INSTRUCTION);
|
|
|
|
(*info->print_address_func) (address, info);
|
2001-11-23 08:09:48 +01:00
|
|
|
goto done;
|
2001-02-19 00:33:11 +01:00
|
|
|
}
|
|
|
|
case PDP11_OPCODE_REG_DISPL:
|
|
|
|
{
|
|
|
|
int displ = (opcode & 0x3f) << 10;
|
2004-10-01 13:19:38 +02:00
|
|
|
bfd_vma address = memaddr - (displ >> 9);
|
|
|
|
|
2012-08-01 02:41:35 +02:00
|
|
|
FPRINTF (F, "%s", OP.name);
|
2001-02-19 00:33:11 +01:00
|
|
|
FPRINTF (F, AFTER_INSTRUCTION);
|
|
|
|
print_reg (src, info);
|
|
|
|
FPRINTF (F, OPERAND_SEPARATOR);
|
|
|
|
(*info->print_address_func) (address, info);
|
2001-11-23 08:09:48 +01:00
|
|
|
goto done;
|
2001-02-19 00:33:11 +01:00
|
|
|
}
|
|
|
|
case PDP11_OPCODE_IMM8:
|
|
|
|
{
|
|
|
|
int code = opcode & 0xff;
|
2012-08-01 02:41:35 +02:00
|
|
|
FPRINTF (F, "%s", OP.name);
|
2001-02-19 00:33:11 +01:00
|
|
|
FPRINTF (F, AFTER_INSTRUCTION);
|
|
|
|
FPRINTF (F, "%o", code);
|
2001-11-23 08:09:48 +01:00
|
|
|
goto done;
|
2001-02-19 00:33:11 +01:00
|
|
|
}
|
|
|
|
case PDP11_OPCODE_IMM6:
|
|
|
|
{
|
|
|
|
int code = opcode & 0x3f;
|
2012-08-01 02:41:35 +02:00
|
|
|
FPRINTF (F, "%s", OP.name);
|
2001-02-19 00:33:11 +01:00
|
|
|
FPRINTF (F, AFTER_INSTRUCTION);
|
|
|
|
FPRINTF (F, "%o", code);
|
2001-11-23 08:09:48 +01:00
|
|
|
goto done;
|
2001-02-19 00:33:11 +01:00
|
|
|
}
|
|
|
|
case PDP11_OPCODE_IMM3:
|
|
|
|
{
|
|
|
|
int code = opcode & 7;
|
2012-08-01 02:41:35 +02:00
|
|
|
FPRINTF (F, "%s", OP.name);
|
2001-02-19 00:33:11 +01:00
|
|
|
FPRINTF (F, AFTER_INSTRUCTION);
|
|
|
|
FPRINTF (F, "%o", code);
|
2001-11-23 08:09:48 +01:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
case PDP11_OPCODE_ILLEGAL:
|
|
|
|
{
|
|
|
|
FPRINTF (F, ".word");
|
|
|
|
FPRINTF (F, AFTER_INSTRUCTION);
|
|
|
|
FPRINTF (F, "%o", opcode);
|
|
|
|
goto done;
|
2001-02-19 00:33:11 +01:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
/* TODO: is this a proper way of signalling an error? */
|
|
|
|
FPRINTF (F, "<internal error: unrecognized instruction type>");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#undef OP
|
|
|
|
}
|
2001-11-23 08:09:48 +01:00
|
|
|
done:
|
2001-02-19 00:33:11 +01:00
|
|
|
|
|
|
|
return memaddr - start_memaddr;
|
|
|
|
}
|