* v850-dis.c (v850_reg_names): Define.
[external/binutils.git] / opcodes / v850-dis.c
1 /* Disassemble V850 instructions.
2    Copyright (C) 1996 Free Software Foundation, Inc.
3
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.
8
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.
13
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.  */
17
18
19 #include <stdio.h>
20
21 #include "ansidecl.h"
22 #include "opcode/v850.h" 
23 #include "dis-asm.h"
24
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" };
30
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" };
36
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", 
40   "le", "gt" };
41
42 int 
43 print_insn_v850 (memaddr, info)
44      bfd_vma memaddr;
45      struct disassemble_info *info;
46 {
47   int status;
48   bfd_byte buffer[4];
49   unsigned long insn;
50
51   status = (*info->read_memory_func) (memaddr, buffer, 4, info);
52   if (status != 0)
53     {
54       (*info->memory_error_func) (status, memaddr, info);
55       return -1;
56     }
57   insn = bfd_getl32 (buffer);
58
59   disassemble (insn, info);
60   if ((insn & 0x0600) == 0x0600)
61     return 4;
62   else
63     return 2;
64 }
65
66 disassemble (insn, info)
67      unsigned long insn;
68      struct disassemble_info *info;
69 {
70   struct v850_opcode *op = (struct v850_opcode *)v850_opcodes;
71   const struct v850_operand *operand;
72   int match = 0;
73   /* If this is a two byte insn, then mask off the high bits. */
74   if ((insn & 0x0600) != 0x0600)
75     insn &= 0xffff;
76
77   /* Find the opcode.  */
78   while (op->name)
79     {
80       if ((op->mask & insn) == op->opcode)
81         {
82           const unsigned char *opindex_ptr;
83
84           match = 1;
85           (*info->fprintf_func) (info->stream, "%s\t", op->name);
86
87           /* Now print the operands.  */
88           for (opindex_ptr = op->operands; *opindex_ptr != 0; opindex_ptr++)
89             {
90               unsigned long value;
91
92               operand = &v850_operands[*opindex_ptr];
93
94               if (operand->extract)
95                 value = (operand->extract) (insn, 0);
96               else
97                 value = (insn >> operand->shift) & ((1 << operand->bits) - 1);
98
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");
113               else
114                 (*info->fprintf_func) (info->stream, "%d", value);
115             }
116
117           /* All done. */
118           break;
119         }
120       op++;
121     }
122
123   if (!match)
124     {
125       if ((insn & 0x0600) != 0x0600)
126         (*info->fprintf_func) (info->stream, ".short\t0x%04x", insn);
127       else
128         (*info->fprintf_func) (info->stream, ".long\t0x%08x", insn);
129     }
130 }