aboutsummaryrefslogtreecommitdiff
path: root/opcodes/v850-dis.c
blob: 2970ab913b94d5cf7da84a9f157e82b7761581b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* Disassemble V850 instructions.
   Copyright (C) 1996 Free Software Foundation, Inc.

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 "ansidecl.h"
#include "opcode/v850.h" 
#include "dis-asm.h"

static const char *const v850_reg_names[] =
{ "r0", "r1", "r2", "sp", "gp", "r5", "r6", "r7", 
  "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 
  "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 
  "r24", "r25", "r26", "r27", "r28", "r29", "ep", "r31" };

static const char *const v850_sreg_names[] =
{ "eipc", "eipsw", "fepc", "fepsw", "ecr", "psw", "sr6", "sr7", 
  "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15", 
  "sr16", "sr17", "sr18", "sr19", "sr20", "sr21", "sr22", "sr23", 
  "sr24", "sr25", "sr26", "sr27", "sr28", "sr29", "sr30", "sr31" };

static const char *const v850_cc_names[] =
{ "v", "c/l", "z", "nh", "s/n", "t", "lt", "le", 
  "nv", "nc/nl", "nz", "h", "ns/p", "sa", "ge", "gt" };

int 
print_insn_v850 (memaddr, info)
     bfd_vma memaddr;
     struct disassemble_info *info;
{
  int status;
  bfd_byte buffer[4];
  unsigned long insn;

  /* First figure out how big the opcode is.  */
  status = (*info->read_memory_func) (memaddr, buffer, 2, info);
  if (status != 0)
    {
      (*info->memory_error_func) (status, memaddr, info);
      return -1;
    }
  insn = bfd_getl16 (buffer);

  /* If this is a 4 byte insn, read 4 bytes of stuff.  */
  if ((insn & 0x0600) == 0x0600)
    {
      status = (*info->read_memory_func) (memaddr, buffer, 2, info);
      if (status != 0)
	{
	  (*info->memory_error_func) (status, memaddr, info);
	  return -1;
	}
      insn = bfd_getl32 (buffer);
    }

  disassemble (insn, info);

  /* Make sure we tell our caller how many bytes we consumed.  */
  if ((insn & 0x0600) == 0x0600)
    return 4;
  else
    return 2;
}

disassemble (insn, info)
     unsigned long insn;
     struct disassemble_info *info;
{
  struct v850_opcode *op = (struct v850_opcode *)v850_opcodes;
  const struct v850_operand *operand;
  int match = 0;
  /* If this is a two byte insn, then mask off the high bits. */
  if ((insn & 0x0600) != 0x0600)
    insn &= 0xffff;

  /* Find the opcode.  */
  while (op->name)
    {
      if ((op->mask & insn) == op->opcode)
	{
	  const unsigned char *opindex_ptr;

	  match = 1;
	  (*info->fprintf_func) (info->stream, "%s\t", op->name);

	  /* Now print the operands.  */
	  for (opindex_ptr = op->operands; *opindex_ptr != 0; opindex_ptr++)
	    {
	      unsigned long value;

	      operand = &v850_operands[*opindex_ptr];

	      if (operand->extract)
		value = (operand->extract) (insn, 0);
	      else
		value = (insn >> operand->shift) & ((1 << operand->bits) - 1);

	      if ((operand->flags & V850_OPERAND_SIGNED) != 0)
		value = ((signed long)(value << (32 - operand->bits))
			  >> (32 - operand->bits));
	      if ((operand->flags & V850_OPERAND_REG) != 0)
		(*info->fprintf_func) (info->stream, "%s",
				      v850_reg_names[value]);
	      else if ((operand->flags & V850_OPERAND_SRG) != 0)
		(*info->fprintf_func) (info->stream, "%s",
				      v850_sreg_names[value]);
	      else if ((operand->flags & V850_OPERAND_CC) != 0)
		(*info->fprintf_func) (info->stream, "%s",
				      v850_cc_names[value]);
	      else if ((operand->flags & V850_OPERAND_EP) != 0)
		(*info->fprintf_func) (info->stream, "ep");
	      else
		(*info->fprintf_func) (info->stream, "%d", value);
	    }

	  /* All done. */
	  break;
	}
      op++;
    }

  if (!match)
    {
      if ((insn & 0x0600) != 0x0600)
	(*info->fprintf_func) (info->stream, ".short\t0x%04x", insn);
      else
	(*info->fprintf_func) (info->stream, ".long\t0x%08x", insn);
    }
}