1 /* Disassemble V850 instructions.
2 Copyright (C) 1996 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include "opcode/v850.h"
25 static const char *const v850_reg_names[] =
26 { "r0", "r1", "r2", "sp", "gp", "r5", "r6", "r7",
27 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
28 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
29 "r24", "r25", "r26", "r27", "r28", "r29", "ep", "r31" };
31 static const char *const v850_sreg_names[] =
32 { "eipc", "eipsw", "fepc", "fepsw", "ecr", "psw", "sr6", "sr7",
33 "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15",
34 "sr16", "sr17", "sr18", "sr19", "sr20", "sr21", "sr22", "sr23",
35 "sr24", "sr25", "sr26", "sr27", "sr28", "sr29", "sr30", "sr31" };
37 static const char *const v850_cc_names[] =
38 { "v", "c/l", "z", "nh", "s/n", "t", "lt", "le",
39 "nv", "nc/nl", "nz", "h", "ns/p", "sa", "lt", "ge",
43 print_insn_v850 (memaddr, info)
45 struct disassemble_info *info;
51 status = (*info->read_memory_func) (memaddr, buffer, 4, info);
54 (*info->memory_error_func) (status, memaddr, info);
57 insn = bfd_getl32 (buffer);
59 disassemble (insn, info);
60 if ((insn & 0x0600) == 0x0600)
66 disassemble (insn, info)
68 struct disassemble_info *info;
70 struct v850_opcode *op = (struct v850_opcode *)v850_opcodes;
71 const struct v850_operand *operand;
73 /* If this is a two byte insn, then mask off the high bits. */
74 if ((insn & 0x0600) != 0x0600)
77 /* Find the opcode. */
80 if ((op->mask & insn) == op->opcode)
82 const unsigned char *opindex_ptr;
85 (*info->fprintf_func) (info->stream, "%s\t", op->name);
87 /* Now print the operands. */
88 for (opindex_ptr = op->operands; *opindex_ptr != 0; opindex_ptr++)
92 operand = &v850_operands[*opindex_ptr];
95 value = (operand->extract) (insn, 0);
97 value = (insn >> operand->shift) & ((1 << operand->bits) - 1);
99 if ((operand->flags & V850_OPERAND_SIGNED) != 0)
100 value = ((signed long)(value << (32 - operand->bits))
101 >> (32 - operand->bits));
102 if ((operand->flags & V850_OPERAND_REG) != 0)
103 (*info->fprintf_func) (info->stream, "%s",
104 v850_reg_names[value]);
105 else if ((operand->flags & V850_OPERAND_SRG) != 0)
106 (*info->fprintf_func) (info->stream, "%s",
107 v850_sreg_names[value]);
108 else if ((operand->flags & V850_OPERAND_CC) != 0)
109 (*info->fprintf_func) (info->stream, "%s",
110 v850_cc_names[value]);
111 else if ((operand->flags & V850_OPERAND_EP) != 0)
112 (*info->fprintf_func) (info->stream, "ep");
114 (*info->fprintf_func) (info->stream, "%d", value);
125 if ((insn & 0x0600) != 0x0600)
126 (*info->fprintf_func) (info->stream, ".short\t0x%04x", insn);
128 (*info->fprintf_func) (info->stream, ".long\t0x%08x", insn);