1 /* Disassemble MN10200 instructions.
2 Copyright (C) 1996-2018 Free Software Foundation, Inc.
4 This file is part of the GNU opcodes library.
6 This library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 It is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
23 #include "opcode/mn10200.h"
24 #include "disassemble.h"
28 disassemble (bfd_vma memaddr,
29 struct disassemble_info *info,
31 unsigned long extension,
34 struct mn10200_opcode *op = (struct mn10200_opcode *)mn10200_opcodes;
35 const struct mn10200_operand *operand;
38 /* Find the opcode. */
41 int mysize, extra_shift;
43 if (op->format == FMT_1)
45 else if (op->format == FMT_2
46 || op->format == FMT_4)
48 else if (op->format == FMT_3
49 || op->format == FMT_5)
51 else if (op->format == FMT_6)
53 else if (op->format == FMT_7)
58 if (op->format == FMT_2 || op->format == FMT_5)
60 else if (op->format == FMT_3
61 || op->format == FMT_6
62 || op->format == FMT_7)
67 if ((op->mask & insn) == op->opcode
68 && size == (unsigned int) mysize)
70 const unsigned char *opindex_ptr;
75 (*info->fprintf_func) (info->stream, "%s\t", op->name);
77 /* Now print the operands. */
78 for (opindex_ptr = op->operands, nocomma = 1;
84 operand = &mn10200_operands[*opindex_ptr];
86 if ((operand->flags & MN10200_OPERAND_EXTENDED) != 0)
88 value = (insn & 0xffff) << 8;
93 value = ((insn >> (operand->shift))
94 & ((1L << operand->bits) - 1L));
97 if ((operand->flags & MN10200_OPERAND_SIGNED) != 0)
98 value = ((long)(value << (32 - operand->bits))
99 >> (32 - operand->bits));
103 || ((operand->flags & MN10200_OPERAND_PAREN) == 0)))
104 (*info->fprintf_func) (info->stream, ",");
108 if ((operand->flags & MN10200_OPERAND_DREG) != 0)
110 value = ((insn >> (operand->shift + extra_shift))
111 & ((1 << operand->bits) - 1));
112 (*info->fprintf_func) (info->stream, "d%ld", value);
115 else if ((operand->flags & MN10200_OPERAND_AREG) != 0)
117 value = ((insn >> (operand->shift + extra_shift))
118 & ((1 << operand->bits) - 1));
119 (*info->fprintf_func) (info->stream, "a%ld", value);
122 else if ((operand->flags & MN10200_OPERAND_PSW) != 0)
123 (*info->fprintf_func) (info->stream, "psw");
125 else if ((operand->flags & MN10200_OPERAND_MDR) != 0)
126 (*info->fprintf_func) (info->stream, "mdr");
128 else if ((operand->flags & MN10200_OPERAND_PAREN) != 0)
131 (*info->fprintf_func) (info->stream, ")");
134 (*info->fprintf_func) (info->stream, "(");
140 else if ((operand->flags & MN10200_OPERAND_PCREL) != 0)
141 (*info->print_address_func)
142 ((value + memaddr + mysize) & 0xffffff, info);
144 else if ((operand->flags & MN10200_OPERAND_MEMADDR) != 0)
145 (*info->print_address_func) (value, info);
148 (*info->fprintf_func) (info->stream, "%ld", value);
157 (*info->fprintf_func) (info->stream, _("unknown\t0x%04lx"), insn);
161 print_insn_mn10200 (bfd_vma memaddr, struct disassemble_info *info)
166 unsigned long extension = 0;
167 unsigned int consume;
169 /* First figure out how big the opcode is. */
170 status = (*info->read_memory_func) (memaddr, buffer, 1, info);
173 (*info->memory_error_func) (status, memaddr, info);
177 insn = *(unsigned char *) buffer;
179 /* These are one byte insns. */
180 if ((insn & 0xf0) == 0x00
181 || (insn & 0xf0) == 0x10
182 || (insn & 0xf0) == 0x20
183 || (insn & 0xf0) == 0x30
184 || ((insn & 0xf0) == 0x80
185 && (insn & 0x0c) >> 2 != (insn & 0x03))
186 || (insn & 0xf0) == 0x90
187 || (insn & 0xf0) == 0xa0
188 || (insn & 0xf0) == 0xb0
189 || (insn & 0xff) == 0xeb
190 || (insn & 0xff) == 0xf6
191 || (insn & 0xff) == 0xfe
192 || (insn & 0xff) == 0xff)
198 /* These are two byte insns. */
199 else if ((insn & 0xf0) == 0x40
200 || (insn & 0xf0) == 0x50
201 || (insn & 0xf0) == 0x60
202 || (insn & 0xf0) == 0x70
203 || (insn & 0xf0) == 0x80
204 || (insn & 0xfc) == 0xd0
205 || (insn & 0xfc) == 0xd4
206 || (insn & 0xfc) == 0xd8
207 || (insn & 0xfc) == 0xe0
208 || (insn & 0xfc) == 0xe4
209 || (insn & 0xff) == 0xe8
210 || (insn & 0xff) == 0xe9
211 || (insn & 0xff) == 0xea
212 || (insn & 0xff) == 0xf0
213 || (insn & 0xff) == 0xf1
214 || (insn & 0xff) == 0xf2
215 || (insn & 0xff) == 0xf3)
217 status = (*info->read_memory_func) (memaddr, buffer, 2, info);
220 (*info->memory_error_func) (status, memaddr, info);
223 insn = bfd_getb16 (buffer);
227 /* These are three byte insns with a 16bit operand in little
229 else if ((insn & 0xf0) == 0xc0
230 || (insn & 0xfc) == 0xdc
231 || (insn & 0xfc) == 0xec
232 || (insn & 0xff) == 0xf8
233 || (insn & 0xff) == 0xf9
234 || (insn & 0xff) == 0xfa
235 || (insn & 0xff) == 0xfb
236 || (insn & 0xff) == 0xfc
237 || (insn & 0xff) == 0xfd)
239 status = (*info->read_memory_func) (memaddr + 1, buffer, 2, info);
242 (*info->memory_error_func) (status, memaddr, info);
246 insn |= bfd_getl16 (buffer);
250 /* These are three byte insns too, but we don't have to mess with
252 else if ((insn & 0xff) == 0xf5)
254 status = (*info->read_memory_func) (memaddr + 1, buffer, 2, info);
257 (*info->memory_error_func) (status, memaddr, info);
261 insn |= bfd_getb16 (buffer);
266 /* These are four byte insns. */
267 else if ((insn & 0xff) == 0xf7)
269 status = (*info->read_memory_func) (memaddr, buffer, 2, info);
272 (*info->memory_error_func) (status, memaddr, info);
275 insn = bfd_getb16 (buffer);
277 status = (*info->read_memory_func) (memaddr + 2, buffer, 2, info);
280 (*info->memory_error_func) (status, memaddr, info);
283 insn |= bfd_getl16 (buffer);
288 /* These are five byte insns. */
289 else if ((insn & 0xff) == 0xf4)
291 status = (*info->read_memory_func) (memaddr, buffer, 2, info);
294 (*info->memory_error_func) (status, memaddr, info);
297 insn = bfd_getb16 (buffer);
300 status = (*info->read_memory_func) (memaddr + 4, buffer, 1, info);
303 (*info->memory_error_func) (status, memaddr, info);
306 insn |= (*(unsigned char *)buffer << 8) & 0xff00;
308 status = (*info->read_memory_func) (memaddr + 3, buffer, 1, info);
311 (*info->memory_error_func) (status, memaddr, info);
314 insn |= (*(unsigned char *)buffer) & 0xff;
316 status = (*info->read_memory_func) (memaddr + 2, buffer, 1, info);
319 (*info->memory_error_func) (status, memaddr, info);
322 extension = (*(unsigned char *)buffer) & 0xff;
327 (*info->fprintf_func) (info->stream, _("unknown\t0x%02lx"), insn);
331 disassemble (memaddr, info, insn, extension, consume);