1 /* Disassembler code for Renesas RX.
2 Copyright (C) 2008-2015 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"
33 disassemble_info * dis;
37 rx_get_byte (void * vdata)
40 RX_Data *rx_data = (RX_Data *) vdata;
42 rx_data->dis->read_memory_func (rx_data->pc,
51 static char const * size_names[RX_MAX_SIZE] =
53 "", ".b", ".ub", ".b", ".w", ".uw", ".w", ".a", ".l", "<error>"
56 static char const * opsize_names[RX_MAX_SIZE] =
58 "", ".b", ".b", ".b", ".w", ".w", ".w", ".a", ".l", "<error>"
61 static char const * register_names[] =
63 /* general registers */
64 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
65 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
66 /* control register */
67 "psw", "pc", "usp", "fpsw", NULL, NULL, NULL, NULL,
68 "bpsw", "bpc", "isp", "fintv", "intb", NULL, NULL, NULL,
69 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
70 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
73 static char const * condition_names[] =
76 "eq", "ne", "c", "nc", "gtu", "leu", "pz", "n",
77 "ge", "lt", "gt", "le", "o", "no", "always", "never"
80 static const char * flag_names[] =
82 "c", "z", "s", "o", "", "", "", "",
83 "", "", "", "", "", "", "", "",
84 "i", "u", "", "", "", "", "", ""
85 "", "", "", "", "", "", "", "",
89 print_insn_rx (bfd_vma addr, disassemble_info * dis)
93 RX_Opcode_Decoded opcode;
99 rv = rx_decode_opcode (addr, &opcode, rx_get_byte, &rx_data);
101 dis->bytes_per_line = 10;
103 #define PR (dis->fprintf_func)
104 #define PS (dis->stream)
105 #define PC(c) PR (PS, "%c", c)
107 /* Detect illegal instructions. */
108 if (opcode.op[0].size == RX_Bad_Size
109 || register_names [opcode.op[0].reg] == NULL
110 || register_names [opcode.op[1].reg] == NULL
111 || register_names [opcode.op[2].reg] == NULL)
117 rx_data.dis->read_memory_func (rx_data.pc - rv, buf, rv, rx_data.dis);
119 for (i = 0 ; i < rv; i++)
120 PR (PS, "0x%02x ", buf[i]);
124 for (s = opcode.syntax; *s; s++)
132 RX_Opcode_Operand * oper;
162 PR (PS, "%s", opsize_names[opcode.size]);
168 oper = opcode.op + *s - '0';
171 if (oper->type == RX_Operand_Indirect)
172 PR (PS, "%s", size_names[oper->size]);
177 case RX_Operand_Immediate:
179 dis->print_address_func (oper->addend, dis);
181 || oper->addend > 999
182 || oper->addend < -999)
183 PR (PS, "%#x", oper->addend);
185 PR (PS, "%d", oper->addend);
187 case RX_Operand_Register:
188 case RX_Operand_TwoReg:
189 PR (PS, "%s", register_names[oper->reg]);
191 case RX_Operand_Indirect:
193 PR (PS, "%d[%s]", oper->addend, register_names[oper->reg]);
195 PR (PS, "[%s]", register_names[oper->reg]);
197 case RX_Operand_Postinc:
198 PR (PS, "[%s+]", register_names[oper->reg]);
200 case RX_Operand_Predec:
201 PR (PS, "[-%s]", register_names[oper->reg]);
203 case RX_Operand_Condition:
204 PR (PS, "%s", condition_names[oper->reg]);
206 case RX_Operand_Flag:
207 PR (PS, "%s", flag_names[oper->reg]);