1996-07-18 02:49:26 +02:00
|
|
|
/* Disassemble D10V instructions.
|
1997-02-24 00:05:35 +01:00
|
|
|
Copyright (C) 1996, 1997 Free Software Foundation, Inc.
|
1996-07-18 02:49:26 +02:00
|
|
|
|
|
|
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "opcode/d10v.h"
|
|
|
|
#include "dis-asm.h"
|
|
|
|
|
1997-02-24 00:05:35 +01:00
|
|
|
/* the PC wraps at 18 bits, except for the segment number */
|
|
|
|
/* so use this mask to keep the parts we want */
|
|
|
|
#define PC_MASK 0x03003FFF
|
|
|
|
|
1996-07-23 20:11:55 +02:00
|
|
|
static void dis_2_short PARAMS ((unsigned long insn, bfd_vma memaddr,
|
|
|
|
struct disassemble_info *info, int order));
|
|
|
|
static void dis_long PARAMS ((unsigned long insn, bfd_vma memaddr,
|
|
|
|
struct disassemble_info *info));
|
1996-07-18 02:49:26 +02:00
|
|
|
|
|
|
|
int
|
|
|
|
print_insn_d10v (memaddr, info)
|
|
|
|
bfd_vma memaddr;
|
|
|
|
struct disassemble_info *info;
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
bfd_byte buffer[4];
|
|
|
|
unsigned long insn;
|
|
|
|
|
|
|
|
status = (*info->read_memory_func) (memaddr, buffer, 4, info);
|
|
|
|
if (status != 0)
|
|
|
|
{
|
|
|
|
(*info->memory_error_func) (status, memaddr, info);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
insn = bfd_getb32 (buffer);
|
|
|
|
|
|
|
|
status = insn & FM11;
|
|
|
|
switch (status) {
|
|
|
|
case 0:
|
1996-07-23 20:11:55 +02:00
|
|
|
dis_2_short (insn, memaddr, info, 2);
|
1996-07-18 02:49:26 +02:00
|
|
|
break;
|
|
|
|
case FM01:
|
1996-07-23 20:11:55 +02:00
|
|
|
dis_2_short (insn, memaddr, info, 0);
|
1996-07-18 02:49:26 +02:00
|
|
|
break;
|
|
|
|
case FM10:
|
1996-07-23 20:11:55 +02:00
|
|
|
dis_2_short (insn, memaddr, info, 1);
|
1996-07-18 02:49:26 +02:00
|
|
|
break;
|
|
|
|
case FM11:
|
1996-07-23 20:11:55 +02:00
|
|
|
dis_long (insn, memaddr, info);
|
1996-07-18 02:49:26 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1996-07-23 20:11:55 +02:00
|
|
|
print_operand (oper, insn, op, memaddr, info)
|
1996-07-18 02:49:26 +02:00
|
|
|
struct d10v_operand *oper;
|
|
|
|
unsigned long insn;
|
|
|
|
struct d10v_opcode *op;
|
1996-07-23 20:11:55 +02:00
|
|
|
bfd_vma memaddr;
|
|
|
|
struct disassemble_info *info;
|
1996-07-18 02:49:26 +02:00
|
|
|
{
|
|
|
|
int num, shift;
|
|
|
|
|
|
|
|
if (oper->flags == OPERAND_ATMINUS)
|
|
|
|
{
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "@-");
|
1996-07-18 02:49:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (oper->flags == OPERAND_MINUS)
|
|
|
|
{
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "-");
|
1996-07-18 02:49:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (oper->flags == OPERAND_PLUS)
|
|
|
|
{
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "+");
|
1996-07-18 02:49:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (oper->flags == OPERAND_ATSIGN)
|
|
|
|
{
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "@");
|
1996-07-18 02:49:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (oper->flags == OPERAND_ATPAR)
|
|
|
|
{
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "@(");
|
1996-07-18 02:49:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
shift = oper->shift;
|
|
|
|
|
|
|
|
/* the LONG_L format shifts registers over by 15 */
|
|
|
|
if (op->format == LONG_L && (oper->flags & OPERAND_REG))
|
|
|
|
shift += 15;
|
|
|
|
|
|
|
|
num = (insn >> shift) & (0x7FFFFFFF >> (31 - oper->bits));
|
|
|
|
|
1996-07-22 20:57:20 +02:00
|
|
|
if (oper->flags & OPERAND_REG)
|
1996-07-18 02:49:26 +02:00
|
|
|
{
|
1996-07-22 20:57:20 +02:00
|
|
|
int i;
|
|
|
|
int match=0;
|
|
|
|
num += oper->flags & (OPERAND_ACC|OPERAND_FLAG|OPERAND_CONTROL);
|
|
|
|
for (i=0;i<reg_name_cnt();i++)
|
|
|
|
{
|
|
|
|
if (num == pre_defined_registers[i].value)
|
|
|
|
{
|
|
|
|
if (pre_defined_registers[i].pname)
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "%s",pre_defined_registers[i].pname);
|
1996-07-22 20:57:20 +02:00
|
|
|
else
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "%s",pre_defined_registers[i].name);
|
1996-07-22 20:57:20 +02:00
|
|
|
match=1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (match==0)
|
|
|
|
{
|
1996-07-23 20:11:55 +02:00
|
|
|
/* this would only get executed if a register was not in the
|
|
|
|
register table */
|
1996-07-22 20:57:20 +02:00
|
|
|
if (oper->flags & OPERAND_ACC)
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "a");
|
1996-07-22 20:57:20 +02:00
|
|
|
else if (oper->flags & OPERAND_CONTROL)
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "cr");
|
1996-07-22 20:57:20 +02:00
|
|
|
else if(oper->flags & OPERAND_REG)
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "r");
|
|
|
|
(*info->fprintf_func) (info->stream, "%d",num);
|
1996-07-22 20:57:20 +02:00
|
|
|
}
|
1996-07-18 02:49:26 +02:00
|
|
|
}
|
|
|
|
else
|
1996-07-23 20:11:55 +02:00
|
|
|
{
|
|
|
|
/* addresses are right-shifted by 2 */
|
|
|
|
if (oper->flags & OPERAND_ADDR)
|
|
|
|
{
|
|
|
|
long max;
|
|
|
|
int neg=0;
|
|
|
|
max = (1 << (oper->bits - 1));
|
|
|
|
if (num & max)
|
|
|
|
{
|
1997-02-24 00:05:35 +01:00
|
|
|
num = -num & ((1 << oper->bits)-1);
|
1996-07-23 20:11:55 +02:00
|
|
|
neg = 1;
|
|
|
|
}
|
|
|
|
num = num<<2;
|
|
|
|
if (neg)
|
1997-02-24 00:05:35 +01:00
|
|
|
(*info->print_address_func) ((memaddr - num) & PC_MASK, info);
|
1996-07-23 20:11:55 +02:00
|
|
|
else
|
1997-02-24 00:05:35 +01:00
|
|
|
(*info->print_address_func) ((memaddr + num) & PC_MASK, info);
|
1996-07-23 20:11:55 +02:00
|
|
|
}
|
|
|
|
else
|
1996-07-25 21:16:34 +02:00
|
|
|
{
|
|
|
|
if (oper->flags & OPERAND_SIGNED)
|
|
|
|
{
|
|
|
|
int max = (1 << (oper->bits - 1));
|
|
|
|
if (num & max)
|
|
|
|
{
|
1997-02-24 00:05:35 +01:00
|
|
|
num = -num & ((1 << oper->bits)-1);
|
1996-07-25 21:16:34 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "-");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(*info->fprintf_func) (info->stream, "0x%x",num);
|
|
|
|
}
|
1996-07-23 20:11:55 +02:00
|
|
|
}
|
1996-07-18 02:49:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
1996-07-23 20:11:55 +02:00
|
|
|
dis_long (insn, memaddr, info)
|
1996-07-18 02:49:26 +02:00
|
|
|
unsigned long insn;
|
1996-07-23 20:11:55 +02:00
|
|
|
bfd_vma memaddr;
|
|
|
|
struct disassemble_info *info;
|
1996-07-18 02:49:26 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char buf[32];
|
|
|
|
struct d10v_opcode *op = (struct d10v_opcode *)d10v_opcodes;
|
|
|
|
struct d10v_operand *oper;
|
|
|
|
int need_paren = 0;
|
1997-02-24 00:05:35 +01:00
|
|
|
int match = 0;
|
1996-07-18 02:49:26 +02:00
|
|
|
|
|
|
|
while (op->name)
|
|
|
|
{
|
|
|
|
if ((op->format & LONG_OPCODE) && ((op->mask & insn) == op->opcode))
|
|
|
|
{
|
1997-02-24 00:05:35 +01:00
|
|
|
match = 1;
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "%s\t", op->name);
|
1996-07-18 02:49:26 +02:00
|
|
|
for ( i=0; op->operands[i]; i++)
|
|
|
|
{
|
|
|
|
oper = (struct d10v_operand *)&d10v_operands[op->operands[i]];
|
|
|
|
if (oper->flags == OPERAND_ATPAR)
|
|
|
|
need_paren = 1;
|
1996-07-23 20:11:55 +02:00
|
|
|
print_operand (oper, insn, op, memaddr, info);
|
1996-07-18 02:49:26 +02:00
|
|
|
if (op->operands[i+1] && oper->bits &&
|
|
|
|
d10v_operands[op->operands[i+1]].flags != OPERAND_PLUS &&
|
|
|
|
d10v_operands[op->operands[i+1]].flags != OPERAND_MINUS)
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, ", ");
|
1996-07-18 02:49:26 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
op++;
|
|
|
|
}
|
1997-02-24 00:05:35 +01:00
|
|
|
|
|
|
|
if (!match)
|
|
|
|
(*info->fprintf_func) (info->stream, ".long\t0x%08x",insn);
|
|
|
|
|
1996-07-18 02:49:26 +02:00
|
|
|
if (need_paren)
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, ")");
|
1996-07-18 02:49:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1996-07-23 20:11:55 +02:00
|
|
|
dis_2_short (insn, memaddr, info, order)
|
1996-07-18 02:49:26 +02:00
|
|
|
unsigned long insn;
|
1996-07-23 20:11:55 +02:00
|
|
|
bfd_vma memaddr;
|
|
|
|
struct disassemble_info *info;
|
1996-07-18 02:49:26 +02:00
|
|
|
int order;
|
|
|
|
{
|
|
|
|
int i,j;
|
|
|
|
char astr[2][32];
|
|
|
|
unsigned int ins[2];
|
|
|
|
struct d10v_opcode *op;
|
|
|
|
char buf[32];
|
|
|
|
int match, num_match=0;
|
|
|
|
struct d10v_operand *oper;
|
|
|
|
int need_paren = 0;
|
|
|
|
|
|
|
|
ins[0] = (insn & 0x3FFFFFFF) >> 15;
|
|
|
|
ins[1] = insn & 0x00007FFF;
|
|
|
|
|
|
|
|
for(j=0;j<2;j++)
|
|
|
|
{
|
|
|
|
op = (struct d10v_opcode *)d10v_opcodes;
|
|
|
|
match=0;
|
|
|
|
while (op->name)
|
|
|
|
{
|
|
|
|
if ((op->format & SHORT_OPCODE) && ((op->mask & ins[j]) == op->opcode))
|
|
|
|
{
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "%s\t",op->name);
|
1996-07-18 02:49:26 +02:00
|
|
|
for (i=0; op->operands[i]; i++)
|
|
|
|
{
|
|
|
|
oper = (struct d10v_operand *)&d10v_operands[op->operands[i]];
|
|
|
|
if (oper->flags == OPERAND_ATPAR)
|
|
|
|
need_paren = 1;
|
1996-07-23 20:11:55 +02:00
|
|
|
print_operand (oper, ins[j], op, memaddr, info);
|
1996-07-18 02:49:26 +02:00
|
|
|
if (op->operands[i+1] && oper->bits &&
|
|
|
|
d10v_operands[op->operands[i+1]].flags != OPERAND_PLUS &&
|
|
|
|
d10v_operands[op->operands[i+1]].flags != OPERAND_MINUS)
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, ", ");
|
1996-07-18 02:49:26 +02:00
|
|
|
}
|
|
|
|
match = 1;
|
|
|
|
num_match++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
op++;
|
|
|
|
}
|
|
|
|
if (!match)
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "unknown");
|
1996-07-18 02:49:26 +02:00
|
|
|
|
|
|
|
switch (order)
|
|
|
|
{
|
|
|
|
case 0:
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "\t->\t");
|
1996-07-18 02:49:26 +02:00
|
|
|
order = -1;
|
|
|
|
break;
|
|
|
|
case 1:
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "\t<-\t");
|
1996-07-18 02:49:26 +02:00
|
|
|
order = -1;
|
|
|
|
break;
|
|
|
|
case 2:
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, "\t||\t");
|
1996-07-18 02:49:26 +02:00
|
|
|
order = -1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_match == 0)
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, ".long\t0x%08x",insn);
|
1996-07-18 02:49:26 +02:00
|
|
|
|
|
|
|
if (need_paren)
|
1996-07-23 20:11:55 +02:00
|
|
|
(*info->fprintf_func) (info->stream, ")");
|
1996-07-18 02:49:26 +02:00
|
|
|
}
|