1 /* Disassembler code for Renesas RX.
2 Copyright (C) 2008-2019 Free Software Foundation, Inc.
3 Contributed by Red Hat.
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)
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. */
28 #include "opcode/rx.h"
35 disassemble_info * dis;
40 OPCODES_SIGJMP_BUF bailout;
44 rx_get_byte (void * vdata)
47 RX_Data *rx_data = (RX_Data *) vdata;
50 status = rx_data->dis->read_memory_func (rx_data->pc,
56 struct private *priv = (struct private *) rx_data->dis->private_data;
58 rx_data->dis->memory_error_func (status, rx_data->pc,
60 OPCODES_SIGLONGJMP (priv->bailout, 1);
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[] =
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)
137 RX_Opcode_Decoded opcode;
141 dis->private_data = (PTR) &priv;
145 if (OPCODES_SIGSETJMP (priv.bailout) != 0)
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)
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]);
176 for (s = opcode.syntax; *s; s++)
184 RX_Opcode_Operand * oper;
214 PR (PS, "%s", opsize_names[opcode.size]);
220 int imm = opcode.op[2].addend;
221 int slsb, dlsb, width;
222 dlsb = (imm >> 5) & 0x1f;
224 slsb = (slsb >= 0x10?(slsb ^ 0x1f) + 1:slsb);
226 slsb = (slsb < 0?-slsb:slsb);
227 width = ((imm >> 10) & 0x1f) - dlsb;
228 PR (PS, "#%d, #%d, #%d, %s, %s",
230 register_names[opcode.op[1].reg],
231 register_names[opcode.op[0].reg]);
237 oper = opcode.op + *s - '0';
240 if (oper->type == RX_Operand_Indirect || oper->type == RX_Operand_Zero_Indirect)
241 PR (PS, "%s", size_names[oper->size]);
246 case RX_Operand_Immediate:
248 dis->print_address_func (oper->addend, dis);
250 || oper->addend > 999
251 || oper->addend < -999)
252 PR (PS, "%#x", oper->addend);
254 PR (PS, "%d", oper->addend);
256 case RX_Operand_Register:
257 case RX_Operand_TwoReg:
258 PR (PS, "%s", register_names[oper->reg]);
260 case RX_Operand_Indirect:
261 PR (PS, "%d[%s]", oper->addend, register_names[oper->reg]);
263 case RX_Operand_Zero_Indirect:
264 PR (PS, "[%s]", register_names[oper->reg]);
266 case RX_Operand_Postinc:
267 PR (PS, "[%s+]", register_names[oper->reg]);
269 case RX_Operand_Predec:
270 PR (PS, "[-%s]", register_names[oper->reg]);
272 case RX_Operand_Condition:
273 PR (PS, "%s", condition_names[oper->reg]);
275 case RX_Operand_Flag:
276 PR (PS, "%s", flag_names[oper->reg]);
278 case RX_Operand_DoubleReg:
279 PR (PS, "%s", double_register_names[oper->reg]);
281 case RX_Operand_DoubleRegH:
282 PR (PS, "%s", double_register_high_names[oper->reg]);
284 case RX_Operand_DoubleRegL:
285 PR (PS, "%s", double_register_low_names[oper->reg]);
287 case RX_Operand_DoubleCReg:
288 PR (PS, "%s", double_control_register_names[oper->reg]);
290 case RX_Operand_DoubleCond:
291 PR (PS, "%s", double_condition_names[oper->reg]);