1 /* Disassembler code for Renesas RX.
2 Copyright (C) 2008-2017 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", "<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 "", "", "", "", "", "", "", "",
105 print_insn_rx (bfd_vma addr, disassemble_info * dis)
109 RX_Opcode_Decoded opcode;
113 dis->private_data = (PTR) &priv;
117 if (OPCODES_SIGSETJMP (priv.bailout) != 0)
123 rv = rx_decode_opcode (addr, &opcode, rx_get_byte, &rx_data);
125 dis->bytes_per_line = 10;
127 #define PR (dis->fprintf_func)
128 #define PS (dis->stream)
129 #define PC(c) PR (PS, "%c", c)
131 /* Detect illegal instructions. */
132 if (opcode.op[0].size == RX_Bad_Size
133 || register_names [opcode.op[0].reg] == NULL
134 || register_names [opcode.op[1].reg] == NULL
135 || register_names [opcode.op[2].reg] == NULL)
141 rx_data.dis->read_memory_func (rx_data.pc - rv, buf, rv, rx_data.dis);
143 for (i = 0 ; i < rv; i++)
144 PR (PS, "0x%02x ", buf[i]);
148 for (s = opcode.syntax; *s; s++)
156 RX_Opcode_Operand * oper;
186 PR (PS, "%s", opsize_names[opcode.size]);
192 oper = opcode.op + *s - '0';
195 if (oper->type == RX_Operand_Indirect || oper->type == RX_Operand_Zero_Indirect)
196 PR (PS, "%s", size_names[oper->size]);
201 case RX_Operand_Immediate:
203 dis->print_address_func (oper->addend, dis);
205 || oper->addend > 999
206 || oper->addend < -999)
207 PR (PS, "%#x", oper->addend);
209 PR (PS, "%d", oper->addend);
211 case RX_Operand_Register:
212 case RX_Operand_TwoReg:
213 PR (PS, "%s", register_names[oper->reg]);
215 case RX_Operand_Indirect:
216 PR (PS, "%d[%s]", oper->addend, register_names[oper->reg]);
218 case RX_Operand_Zero_Indirect:
219 PR (PS, "[%s]", register_names[oper->reg]);
221 case RX_Operand_Postinc:
222 PR (PS, "[%s+]", register_names[oper->reg]);
224 case RX_Operand_Predec:
225 PR (PS, "[-%s]", register_names[oper->reg]);
227 case RX_Operand_Condition:
228 PR (PS, "%s", condition_names[oper->reg]);
230 case RX_Operand_Flag:
231 PR (PS, "%s", flag_names[oper->reg]);