* v850-dis.c (v850_cc_names): Fix stupid thinkos.
[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", "ge", "gt" };
40
41 int 
42 print_insn_v850 (memaddr, info)
43      bfd_vma memaddr;
44      struct disassemble_info *info;
45 {
46   int status;
47   bfd_byte buffer[4];
48   unsigned long insn;
49
50   status = (*info->read_memory_func) (memaddr, buffer, 4, info);
51   if (status != 0)
52     {
53       (*info->memory_error_func) (status, memaddr, info);
54       return -1;
55     }
56   insn = bfd_getl32 (buffer);
57
58   disassemble (insn, info);
59   if ((insn & 0x0600) == 0x0600)
60     return 4;
61   else
62     return 2;
63 }
64
65 disassemble (insn, info)
66      unsigned long insn;
67      struct disassemble_info *info;
68 {
69   struct v850_opcode *op = (struct v850_opcode *)v850_opcodes;
70   const struct v850_operand *operand;
71   int match = 0;
72   /* If this is a two byte insn, then mask off the high bits. */
73   if ((insn & 0x0600) != 0x0600)
74     insn &= 0xffff;
75
76   /* Find the opcode.  */
77   while (op->name)
78     {
79       if ((op->mask & insn) == op->opcode)
80         {
81           const unsigned char *opindex_ptr;
82
83           match = 1;
84           (*info->fprintf_func) (info->stream, "%s\t", op->name);
85
86           /* Now print the operands.  */
87           for (opindex_ptr = op->operands; *opindex_ptr != 0; opindex_ptr++)
88             {
89               unsigned long value;
90
91               operand = &v850_operands[*opindex_ptr];
92
93               if (operand->extract)
94                 value = (operand->extract) (insn, 0);
95               else
96                 value = (insn >> operand->shift) & ((1 << operand->bits) - 1);
97
98               if ((operand->flags & V850_OPERAND_SIGNED) != 0)
99                 value = ((signed long)(value << (32 - operand->bits))
100                           >> (32 - operand->bits));
101               if ((operand->flags & V850_OPERAND_REG) != 0)
102                 (*info->fprintf_func) (info->stream, "%s",
103                                       v850_reg_names[value]);
104               else if ((operand->flags & V850_OPERAND_SRG) != 0)
105                 (*info->fprintf_func) (info->stream, "%s",
106                                       v850_sreg_names[value]);
107               else if ((operand->flags & V850_OPERAND_CC) != 0)
108                 (*info->fprintf_func) (info->stream, "%s",
109                                       v850_cc_names[value]);
110               else if ((operand->flags & V850_OPERAND_EP) != 0)
111                 (*info->fprintf_func) (info->stream, "ep");
112               else
113                 (*info->fprintf_func) (info->stream, "%d", value);
114             }
115
116           /* All done. */
117           break;
118         }
119       op++;
120     }
121
122   if (!match)
123     {
124       if ((insn & 0x0600) != 0x0600)
125         (*info->fprintf_func) (info->stream, ".short\t0x%04x", insn);
126       else
127         (*info->fprintf_func) (info->stream, ".long\t0x%08x", insn);
128     }
129 }