OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [opcodes/] [pdp11-dis.c] - Diff between revs 578 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 578 Rev 1765
/* Print DEC PDP-11 instructions.
/* Print DEC PDP-11 instructions.
   Copyright 2001 Free Software Foundation, Inc.
   Copyright 2001 Free Software Foundation, Inc.
 
 
This file is free software; you can redistribute it and/or modify
This file is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
(at your option) any later version.
 
 
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
GNU General Public License for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 
#include "dis-asm.h"
#include "dis-asm.h"
#include "opcode/pdp11.h"
#include "opcode/pdp11.h"
 
 
#define AFTER_INSTRUCTION       "\t"
#define AFTER_INSTRUCTION       "\t"
#define OPERAND_SEPARATOR       ", "
#define OPERAND_SEPARATOR       ", "
 
 
#define JUMP    0x1000  /* flag that this operand is used in a jump */
#define JUMP    0x1000  /* flag that this operand is used in a jump */
 
 
#define FPRINTF (*info->fprintf_func)
#define FPRINTF (*info->fprintf_func)
#define F       info->stream
#define F       info->stream
 
 
/* sign-extend a 16-bit number in an int */
/* sign-extend a 16-bit number in an int */
#define SIGN_BITS       (8 * sizeof (int) - 16)
#define SIGN_BITS       (8 * sizeof (int) - 16)
#define sign_extend(x) (((x) << SIGN_BITS) >> SIGN_BITS)
#define sign_extend(x) (((x) << SIGN_BITS) >> SIGN_BITS)
 
 
static int read_word PARAMS ((bfd_vma memaddr, int *word,
static int read_word PARAMS ((bfd_vma memaddr, int *word,
                              disassemble_info *info));
                              disassemble_info *info));
static void print_signed_octal PARAMS ((int n, disassemble_info *info));
static void print_signed_octal PARAMS ((int n, disassemble_info *info));
static void print_reg PARAMS ((int reg, disassemble_info *info));
static void print_reg PARAMS ((int reg, disassemble_info *info));
static void print_freg PARAMS ((int freg, disassemble_info *info));
static void print_freg PARAMS ((int freg, disassemble_info *info));
static int print_operand PARAMS ((bfd_vma *memaddr, int code,
static int print_operand PARAMS ((bfd_vma *memaddr, int code,
                                  disassemble_info *info));
                                  disassemble_info *info));
int print_insn_pdp11 PARAMS ((bfd_vma memaddr, disassemble_info *info));
int print_insn_pdp11 PARAMS ((bfd_vma memaddr, disassemble_info *info));
 
 
static int
static int
read_word (memaddr, word, info)
read_word (memaddr, word, info)
     bfd_vma memaddr;
     bfd_vma memaddr;
     int *word;
     int *word;
     disassemble_info *info;
     disassemble_info *info;
{
{
  int status;
  int status;
  bfd_byte x[2];
  bfd_byte x[2];
 
 
  status = (*info->read_memory_func) (memaddr, x, 2, info);
  status = (*info->read_memory_func) (memaddr, x, 2, info);
  if (status != 0)
  if (status != 0)
    return -1;
    return -1;
 
 
  *word = x[1] << 8 | x[0];
  *word = x[1] << 8 | x[0];
  return 0;
  return 0;
}
}
 
 
static void
static void
print_signed_octal (n, info)
print_signed_octal (n, info)
     int n;
     int n;
     disassemble_info *info;
     disassemble_info *info;
{
{
  if (n < 0)
  if (n < 0)
    FPRINTF (F, "-%o", -n);
    FPRINTF (F, "-%o", -n);
  else
  else
    FPRINTF (F, "%o", n);
    FPRINTF (F, "%o", n);
}
}
 
 
static void
static void
print_reg (reg, info)
print_reg (reg, info)
     int reg;
     int reg;
     disassemble_info *info;
     disassemble_info *info;
{
{
  /* mask off the addressing mode, if any */
  /* mask off the addressing mode, if any */
  reg &= 7;
  reg &= 7;
 
 
  switch (reg)
  switch (reg)
    {
    {
    case 0: case 1: case 2: case 3: case 4: case 5:
    case 0: case 1: case 2: case 3: case 4: case 5:
                FPRINTF (F, "r%d", reg); break;
                FPRINTF (F, "r%d", reg); break;
    case 6:     FPRINTF (F, "sp"); break;
    case 6:     FPRINTF (F, "sp"); break;
    case 7:     FPRINTF (F, "pc"); break;
    case 7:     FPRINTF (F, "pc"); break;
    default:    /* error */
    default:    /* error */
    }
    }
}
}
 
 
static void
static void
print_freg (freg, info)
print_freg (freg, info)
     int freg;
     int freg;
     disassemble_info *info;
     disassemble_info *info;
{
{
  FPRINTF (F, "fr%d", freg);
  FPRINTF (F, "fr%d", freg);
}
}
 
 
static int
static int
print_operand (memaddr, code, info)
print_operand (memaddr, code, info)
     bfd_vma *memaddr;
     bfd_vma *memaddr;
     int code;
     int code;
     disassemble_info *info;
     disassemble_info *info;
{
{
  int mode = (code >> 3) & 7;
  int mode = (code >> 3) & 7;
  int reg = code & 7;
  int reg = code & 7;
  int disp;
  int disp;
 
 
  switch (mode)
  switch (mode)
    {
    {
    case 0:
    case 0:
      print_reg (reg, info);
      print_reg (reg, info);
      break;
      break;
    case 1:
    case 1:
      FPRINTF (F, "(");
      FPRINTF (F, "(");
      print_reg (reg, info);
      print_reg (reg, info);
      FPRINTF (F, ")");
      FPRINTF (F, ")");
      break;
      break;
    case 2:
    case 2:
      if (reg == 7)
      if (reg == 7)
        {
        {
          int data;
          int data;
          if (read_word (*memaddr, &data, info) < 0)
          if (read_word (*memaddr, &data, info) < 0)
            return -1;
            return -1;
          FPRINTF (F, "$");
          FPRINTF (F, "$");
          print_signed_octal (sign_extend (data), info);
          print_signed_octal (sign_extend (data), info);
          *memaddr += 2;
          *memaddr += 2;
        }
        }
      else
      else
        {
        {
          FPRINTF (F, "(");
          FPRINTF (F, "(");
          print_reg (reg, info);
          print_reg (reg, info);
          FPRINTF (F, ")+");
          FPRINTF (F, ")+");
        }
        }
        break;
        break;
    case 3:
    case 3:
      if (reg == 7)
      if (reg == 7)
        {
        {
          int address;
          int address;
          if (read_word (*memaddr, &address, info) < 0)
          if (read_word (*memaddr, &address, info) < 0)
            return -1;
            return -1;
          FPRINTF (F, "*$%o", address);
          FPRINTF (F, "*$%o", address);
          *memaddr += 2;
          *memaddr += 2;
        }
        }
      else
      else
        {
        {
          FPRINTF (F, "*(");
          FPRINTF (F, "*(");
          print_reg (reg, info);
          print_reg (reg, info);
          FPRINTF (F, ")+");
          FPRINTF (F, ")+");
        }
        }
        break;
        break;
    case 4:
    case 4:
      FPRINTF (F, "-(");
      FPRINTF (F, "-(");
      print_reg (reg, info);
      print_reg (reg, info);
      FPRINTF (F, ")");
      FPRINTF (F, ")");
      break;
      break;
    case 5:
    case 5:
      FPRINTF (F, "*-(");
      FPRINTF (F, "*-(");
      print_reg (reg, info);
      print_reg (reg, info);
      FPRINTF (F, ")");
      FPRINTF (F, ")");
      break;
      break;
    case 6:
    case 6:
    case 7:
    case 7:
      if (read_word (*memaddr, &disp, info) < 0)
      if (read_word (*memaddr, &disp, info) < 0)
        return -1;
        return -1;
      *memaddr += 2;
      *memaddr += 2;
      if (reg == 7)
      if (reg == 7)
        {
        {
          bfd_vma address = *memaddr + sign_extend (disp);
          bfd_vma address = *memaddr + sign_extend (disp);
          if (!(code & JUMP))
          if (!(code & JUMP))
            FPRINTF (F, "*$");
            FPRINTF (F, "*$");
          (*info->print_address_func) (address, info);
          (*info->print_address_func) (address, info);
        }
        }
      else
      else
        {
        {
          if (mode == 7)
          if (mode == 7)
            FPRINTF (F, "*");
            FPRINTF (F, "*");
          print_signed_octal (sign_extend (disp), info);
          print_signed_octal (sign_extend (disp), info);
          FPRINTF (F, "(");
          FPRINTF (F, "(");
          print_reg (reg, info);
          print_reg (reg, info);
          FPRINTF (F, ")");
          FPRINTF (F, ")");
        }
        }
      break;
      break;
    }
    }
 
 
  return 0;
  return 0;
}
}
 
 
/* Print the PDP-11 instruction at address MEMADDR in debugged memory,
/* Print the PDP-11 instruction at address MEMADDR in debugged memory,
   on INFO->STREAM.  Returns length of the instruction, in bytes.  */
   on INFO->STREAM.  Returns length of the instruction, in bytes.  */
 
 
int
int
print_insn_pdp11 (memaddr, info)
print_insn_pdp11 (memaddr, info)
     bfd_vma memaddr;
     bfd_vma memaddr;
     disassemble_info *info;
     disassemble_info *info;
{
{
  bfd_vma start_memaddr = memaddr;
  bfd_vma start_memaddr = memaddr;
  int opcode;
  int opcode;
  int src, dst;
  int src, dst;
  int i;
  int i;
 
 
  info->bytes_per_line = 6;
  info->bytes_per_line = 6;
  info->bytes_per_chunk = 2;
  info->bytes_per_chunk = 2;
  info->display_endian = BFD_ENDIAN_LITTLE;
  info->display_endian = BFD_ENDIAN_LITTLE;
 
 
  if (read_word (memaddr, &opcode, info) != 0)
  if (read_word (memaddr, &opcode, info) != 0)
    return -1;
    return -1;
  memaddr += 2;
  memaddr += 2;
 
 
  src = (opcode >> 6) & 0x3f;
  src = (opcode >> 6) & 0x3f;
  dst = opcode & 0x3f;
  dst = opcode & 0x3f;
 
 
  for (i = 0; i < pdp11_num_opcodes; i++)
  for (i = 0; i < pdp11_num_opcodes; i++)
    {
    {
#define OP pdp11_opcodes[i]
#define OP pdp11_opcodes[i]
      if ((opcode & OP.mask) == OP.opcode)
      if ((opcode & OP.mask) == OP.opcode)
        switch (OP.type)
        switch (OP.type)
          {
          {
          case PDP11_OPCODE_NO_OPS:
          case PDP11_OPCODE_NO_OPS:
            FPRINTF (F, OP.name);
            FPRINTF (F, OP.name);
            break;
            break;
          case PDP11_OPCODE_REG:
          case PDP11_OPCODE_REG:
            FPRINTF (F, OP.name);
            FPRINTF (F, OP.name);
            FPRINTF (F, AFTER_INSTRUCTION);
            FPRINTF (F, AFTER_INSTRUCTION);
            print_reg (dst, info);
            print_reg (dst, info);
            break;
            break;
          case PDP11_OPCODE_OP:
          case PDP11_OPCODE_OP:
            FPRINTF (F, OP.name);
            FPRINTF (F, OP.name);
            FPRINTF (F, AFTER_INSTRUCTION);
            FPRINTF (F, AFTER_INSTRUCTION);
            if (strcmp (OP.name, "jmp") == 0)
            if (strcmp (OP.name, "jmp") == 0)
              dst |= JUMP;
              dst |= JUMP;
            if (print_operand (&memaddr, dst, info) < 0)
            if (print_operand (&memaddr, dst, info) < 0)
              return -1;
              return -1;
            break;
            break;
          case PDP11_OPCODE_REG_OP:
          case PDP11_OPCODE_REG_OP:
            FPRINTF (F, OP.name);
            FPRINTF (F, OP.name);
            FPRINTF (F, AFTER_INSTRUCTION);
            FPRINTF (F, AFTER_INSTRUCTION);
            print_reg (src, info);
            print_reg (src, info);
            FPRINTF (F, OPERAND_SEPARATOR);
            FPRINTF (F, OPERAND_SEPARATOR);
            if (strcmp (OP.name, "jsr") == 0)
            if (strcmp (OP.name, "jsr") == 0)
              dst |= JUMP;
              dst |= JUMP;
            if (print_operand (&memaddr, dst, info) < 0)
            if (print_operand (&memaddr, dst, info) < 0)
              return -1;
              return -1;
            break;
            break;
          case PDP11_OPCODE_REG_OP_REV:
          case PDP11_OPCODE_REG_OP_REV:
            FPRINTF (F, OP.name);
            FPRINTF (F, OP.name);
            FPRINTF (F, AFTER_INSTRUCTION);
            FPRINTF (F, AFTER_INSTRUCTION);
            if (print_operand (&memaddr, dst, info) < 0)
            if (print_operand (&memaddr, dst, info) < 0)
              return -1;
              return -1;
            FPRINTF (F, OPERAND_SEPARATOR);
            FPRINTF (F, OPERAND_SEPARATOR);
            print_reg (src, info);
            print_reg (src, info);
            break;
            break;
          case PDP11_OPCODE_AC_OP:
          case PDP11_OPCODE_AC_OP:
            {
            {
              int ac = (opcode & 0xe0) >> 6;
              int ac = (opcode & 0xe0) >> 6;
              FPRINTF (F, OP.name);
              FPRINTF (F, OP.name);
              FPRINTF (F, AFTER_INSTRUCTION);
              FPRINTF (F, AFTER_INSTRUCTION);
              print_freg (ac, info);
              print_freg (ac, info);
              FPRINTF (F, OPERAND_SEPARATOR);
              FPRINTF (F, OPERAND_SEPARATOR);
              if (print_operand (&memaddr, dst, info) < 0)
              if (print_operand (&memaddr, dst, info) < 0)
                return -1;
                return -1;
              break;
              break;
            }
            }
          case PDP11_OPCODE_OP_OP:
          case PDP11_OPCODE_OP_OP:
            FPRINTF (F, OP.name);
            FPRINTF (F, OP.name);
            FPRINTF (F, AFTER_INSTRUCTION);
            FPRINTF (F, AFTER_INSTRUCTION);
            if (print_operand (&memaddr, src, info) < 0)
            if (print_operand (&memaddr, src, info) < 0)
              return -1;
              return -1;
            FPRINTF (F, OPERAND_SEPARATOR);
            FPRINTF (F, OPERAND_SEPARATOR);
            if (print_operand (&memaddr, dst, info) < 0)
            if (print_operand (&memaddr, dst, info) < 0)
              return -1;
              return -1;
            break;
            break;
          case PDP11_OPCODE_DISPL:
          case PDP11_OPCODE_DISPL:
            {
            {
              int displ = (opcode & 0xff) << 8;
              int displ = (opcode & 0xff) << 8;
              bfd_vma address = memaddr + (sign_extend (displ) >> 7);
              bfd_vma address = memaddr + (sign_extend (displ) >> 7);
              FPRINTF (F, OP.name);
              FPRINTF (F, OP.name);
              FPRINTF (F, AFTER_INSTRUCTION);
              FPRINTF (F, AFTER_INSTRUCTION);
              (*info->print_address_func) (address, info);
              (*info->print_address_func) (address, info);
              break;
              break;
            }
            }
          case PDP11_OPCODE_REG_DISPL:
          case PDP11_OPCODE_REG_DISPL:
            {
            {
              int displ = (opcode & 0x3f) << 10;
              int displ = (opcode & 0x3f) << 10;
              bfd_vma address = memaddr + (sign_extend (displ) >> 9);
              bfd_vma address = memaddr + (sign_extend (displ) >> 9);
              FPRINTF (F, OP.name);
              FPRINTF (F, OP.name);
              FPRINTF (F, AFTER_INSTRUCTION);
              FPRINTF (F, AFTER_INSTRUCTION);
              print_reg (src, info);
              print_reg (src, info);
              FPRINTF (F, OPERAND_SEPARATOR);
              FPRINTF (F, OPERAND_SEPARATOR);
              (*info->print_address_func) (address, info);
              (*info->print_address_func) (address, info);
              break;
              break;
            }
            }
          case PDP11_OPCODE_IMM8:
          case PDP11_OPCODE_IMM8:
            {
            {
              int code = opcode & 0xff;
              int code = opcode & 0xff;
              FPRINTF (F, OP.name);
              FPRINTF (F, OP.name);
              FPRINTF (F, AFTER_INSTRUCTION);
              FPRINTF (F, AFTER_INSTRUCTION);
              FPRINTF (F, "%o", code);
              FPRINTF (F, "%o", code);
              break;
              break;
            }
            }
          case PDP11_OPCODE_IMM6:
          case PDP11_OPCODE_IMM6:
            {
            {
              int code = opcode & 0x3f;
              int code = opcode & 0x3f;
              FPRINTF (F, OP.name);
              FPRINTF (F, OP.name);
              FPRINTF (F, AFTER_INSTRUCTION);
              FPRINTF (F, AFTER_INSTRUCTION);
              FPRINTF (F, "%o", code);
              FPRINTF (F, "%o", code);
              break;
              break;
            }
            }
          case PDP11_OPCODE_IMM3:
          case PDP11_OPCODE_IMM3:
            {
            {
              int code = opcode & 7;
              int code = opcode & 7;
              FPRINTF (F, OP.name);
              FPRINTF (F, OP.name);
              FPRINTF (F, AFTER_INSTRUCTION);
              FPRINTF (F, AFTER_INSTRUCTION);
              FPRINTF (F, "%o", code);
              FPRINTF (F, "%o", code);
              break;
              break;
            }
            }
          default:
          default:
            /* TODO: is this a proper way of signalling an error? */
            /* TODO: is this a proper way of signalling an error? */
            FPRINTF (F, "<internal error: unrecognized instruction type>");
            FPRINTF (F, "<internal error: unrecognized instruction type>");
            return -1;
            return -1;
          }
          }
#undef OP
#undef OP
    }
    }
 
 
  return memaddr - start_memaddr;
  return memaddr - start_memaddr;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.