[opcodes, ARM, 14/16] Add mode availability to coprocessor table entries
[binutils-gdb.git] / opcodes / rx-dis.c
blob1147d6438f492b054ab047e3e2899bc10741feb1
1 /* Disassembler code for Renesas RX.
2 Copyright (C) 2008-2019 Free Software Foundation, Inc.
3 Contributed by Red Hat.
4 Written by DJ Delorie.
6 This file is part of the GNU opcodes library.
8 This library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 It is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
23 #include "sysdep.h"
24 #include <stdio.h>
26 #include "bfd.h"
27 #include "dis-asm.h"
28 #include "opcode/rx.h"
30 #include <setjmp.h>
32 typedef struct
34 bfd_vma pc;
35 disassemble_info * dis;
36 } RX_Data;
38 struct private
40 OPCODES_SIGJMP_BUF bailout;
43 static int
44 rx_get_byte (void * vdata)
46 bfd_byte buf[1];
47 RX_Data *rx_data = (RX_Data *) vdata;
48 int status;
50 status = rx_data->dis->read_memory_func (rx_data->pc,
51 buf,
53 rx_data->dis);
54 if (status != 0)
56 struct private *priv = (struct private *) rx_data->dis->private_data;
58 rx_data->dis->memory_error_func (status, rx_data->pc,
59 rx_data->dis);
60 OPCODES_SIGLONGJMP (priv->bailout, 1);
63 rx_data->pc ++;
64 return buf[0];
67 static char const * size_names[RX_MAX_SIZE] =
69 "", ".b", ".ub", ".b", ".w", ".uw", ".w", ".a", ".l", "", "<error>"
72 static char const * opsize_names[RX_MAX_SIZE] =
74 "", ".b", ".b", ".b", ".w", ".w", ".w", ".a", ".l", ".d", "<error>"
77 static char const * register_names[] =
79 /* general registers */
80 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
81 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
82 /* control register */
83 "psw", "pc", "usp", "fpsw", NULL, NULL, NULL, NULL,
84 "bpsw", "bpc", "isp", "fintv", "intb", "extb", NULL, NULL,
85 "a0", "a1", NULL, NULL, NULL, NULL, NULL, NULL,
86 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
89 static char const * condition_names[] =
91 /* condition codes */
92 "eq", "ne", "c", "nc", "gtu", "leu", "pz", "n",
93 "ge", "lt", "gt", "le", "o", "no", "<invalid>", "<invalid>"
96 static const char * flag_names[] =
98 "c", "z", "s", "o", "", "", "", "",
99 "", "", "", "", "", "", "", "",
100 "i", "u", "", "", "", "", "", ""
101 "", "", "", "", "", "", "", "",
104 static const char * double_register_names[] =
106 "dr0", "dr1", "dr2", "dr3", "dr4", "dr5", "dr6", "dr7",
107 "dr8", "dr9", "dr10", "dr11", "dr12", "dr13", "dr14", "dr15",
110 static const char * double_register_high_names[] =
112 "drh0", "drh1", "drh2", "drh3", "drh4", "drh5", "drh6", "drh7",
113 "drh8", "drh9", "drh10", "drh11", "drh12", "drh13", "drh14", "drh15",
116 static const char * double_register_low_names[] =
118 "drl0", "drl1", "drl2", "drl3", "drl4", "drl5", "drl6", "drl7",
119 "drl8", "drl9", "drl10", "drl11", "drl12", "drl13", "drl14", "drl15",
122 static const char * double_control_register_names[] =
124 "dpsw", "dcmr", "decnt", "depc",
127 static const char * double_condition_names[] =
129 "", "un", "eq", "", "lt", "", "le",
133 print_insn_rx (bfd_vma addr, disassemble_info * dis)
135 int rv;
136 RX_Data rx_data;
137 RX_Opcode_Decoded opcode;
138 const char * s;
139 struct private priv;
141 dis->private_data = (PTR) &priv;
142 rx_data.pc = addr;
143 rx_data.dis = dis;
145 if (OPCODES_SIGSETJMP (priv.bailout) != 0)
147 /* Error return. */
148 return -1;
151 rv = rx_decode_opcode (addr, &opcode, rx_get_byte, &rx_data);
153 dis->bytes_per_line = 10;
155 #define PR (dis->fprintf_func)
156 #define PS (dis->stream)
157 #define PC(c) PR (PS, "%c", c)
159 /* Detect illegal instructions. */
160 if (opcode.op[0].size == RX_Bad_Size
161 || register_names [opcode.op[0].reg] == NULL
162 || register_names [opcode.op[1].reg] == NULL
163 || register_names [opcode.op[2].reg] == NULL)
165 bfd_byte buf[10];
166 int i;
168 PR (PS, ".byte ");
169 rx_data.dis->read_memory_func (rx_data.pc - rv, buf, rv, rx_data.dis);
171 for (i = 0 ; i < rv; i++)
172 PR (PS, "0x%02x ", buf[i]);
173 return rv;
176 for (s = opcode.syntax; *s; s++)
178 if (*s != '%')
180 PC (*s);
182 else
184 RX_Opcode_Operand * oper;
185 int do_size = 0;
186 int do_hex = 0;
187 int do_addr = 0;
189 s ++;
191 if (*s == 'S')
193 do_size = 1;
194 s++;
196 if (*s == 'x')
198 do_hex = 1;
199 s++;
201 if (*s == 'a')
203 do_addr = 1;
204 s++;
207 switch (*s)
209 case '%':
210 PC ('%');
211 break;
213 case 's':
214 PR (PS, "%s", opsize_names[opcode.size]);
215 break;
217 case 'b':
218 s ++;
219 if (*s == 'f') {
220 int imm = opcode.op[2].addend;
221 int slsb, dlsb, width;
222 dlsb = (imm >> 5) & 0x1f;
223 slsb = (imm & 0x1f);
224 slsb = (slsb >= 0x10?(slsb ^ 0x1f) + 1:slsb);
225 slsb = dlsb - slsb;
226 slsb = (slsb < 0?-slsb:slsb);
227 width = ((imm >> 10) & 0x1f) - dlsb;
228 PR (PS, "#%d, #%d, #%d, %s, %s",
229 slsb, dlsb, width,
230 register_names[opcode.op[1].reg],
231 register_names[opcode.op[0].reg]);
233 break;
234 case '0':
235 case '1':
236 case '2':
237 oper = opcode.op + *s - '0';
238 if (do_size)
240 if (oper->type == RX_Operand_Indirect || oper->type == RX_Operand_Zero_Indirect)
241 PR (PS, "%s", size_names[oper->size]);
243 else
244 switch (oper->type)
246 case RX_Operand_Immediate:
247 if (do_addr)
248 dis->print_address_func (oper->addend, dis);
249 else if (do_hex
250 || oper->addend > 999
251 || oper->addend < -999)
252 PR (PS, "%#x", oper->addend);
253 else
254 PR (PS, "%d", oper->addend);
255 break;
256 case RX_Operand_Register:
257 case RX_Operand_TwoReg:
258 PR (PS, "%s", register_names[oper->reg]);
259 break;
260 case RX_Operand_Indirect:
261 PR (PS, "%d[%s]", oper->addend, register_names[oper->reg]);
262 break;
263 case RX_Operand_Zero_Indirect:
264 PR (PS, "[%s]", register_names[oper->reg]);
265 break;
266 case RX_Operand_Postinc:
267 PR (PS, "[%s+]", register_names[oper->reg]);
268 break;
269 case RX_Operand_Predec:
270 PR (PS, "[-%s]", register_names[oper->reg]);
271 break;
272 case RX_Operand_Condition:
273 PR (PS, "%s", condition_names[oper->reg]);
274 break;
275 case RX_Operand_Flag:
276 PR (PS, "%s", flag_names[oper->reg]);
277 break;
278 case RX_Operand_DoubleReg:
279 PR (PS, "%s", double_register_names[oper->reg]);
280 break;
281 case RX_Operand_DoubleRegH:
282 PR (PS, "%s", double_register_high_names[oper->reg]);
283 break;
284 case RX_Operand_DoubleRegL:
285 PR (PS, "%s", double_register_low_names[oper->reg]);
286 break;
287 case RX_Operand_DoubleCReg:
288 PR (PS, "%s", double_control_register_names[oper->reg]);
289 break;
290 case RX_Operand_DoubleCond:
291 PR (PS, "%s", double_condition_names[oper->reg]);
292 break;
293 default:
294 PR (PS, "[???]");
295 break;
301 return rv;