1 /* Disassemble MN10200 instructions.
2 Copyright 1996, 1997, 1998, 2000, 2005 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
17 MA 02110-1301, USA. */
22 #include "opcode/mn10200.h"
27 disassemble (bfd_vma memaddr,
28 struct disassemble_info *info,
30 unsigned long extension,
33 struct mn10200_opcode *op = (struct mn10200_opcode *)mn10200_opcodes;
34 const struct mn10200_operand *operand;
37 /* Find the opcode. */
40 int mysize, extra_shift;
42 if (op->format == FMT_1)
44 else if (op->format == FMT_2
45 || op->format == FMT_4)
47 else if (op->format == FMT_3
48 || op->format == FMT_5)
50 else if (op->format == FMT_6)
52 else if (op->format == FMT_7)
57 if (op->format == FMT_2 || op->format == FMT_5)
59 else if (op->format == FMT_3
60 || op->format == FMT_6
61 || op->format == FMT_7)
66 if ((op->mask & insn) == op->opcode
67 && size == (unsigned int) mysize)
69 const unsigned char *opindex_ptr;
74 (*info->fprintf_func) (info->stream, "%s\t", op->name);
76 /* Now print the operands. */
77 for (opindex_ptr = op->operands, nocomma = 1;
83 operand = &mn10200_operands[*opindex_ptr];
85 if ((operand->flags & MN10200_OPERAND_EXTENDED) != 0)
87 value = (insn & 0xffff) << 8;
92 value = ((insn >> (operand->shift))
93 & ((1L << operand->bits) - 1L));
96 if ((operand->flags & MN10200_OPERAND_SIGNED) != 0)
97 value = ((long)(value << (32 - operand->bits))
98 >> (32 - operand->bits));
102 || ((operand->flags & MN10200_OPERAND_PAREN) == 0)))
103 (*info->fprintf_func) (info->stream, ",");
107 if ((operand->flags & MN10200_OPERAND_DREG) != 0)
109 value = ((insn >> (operand->shift + extra_shift))
110 & ((1 << operand->bits) - 1));
111 (*info->fprintf_func) (info->stream, "d%d", value);
114 else if ((operand->flags & MN10200_OPERAND_AREG) != 0)
116 value = ((insn >> (operand->shift + extra_shift))
117 & ((1 << operand->bits) - 1));
118 (*info->fprintf_func) (info->stream, "a%d", value);
121 else if ((operand->flags & MN10200_OPERAND_PSW) != 0)
122 (*info->fprintf_func) (info->stream, "psw");
124 else if ((operand->flags & MN10200_OPERAND_MDR) != 0)
125 (*info->fprintf_func) (info->stream, "mdr");
127 else if ((operand->flags & MN10200_OPERAND_PAREN) != 0)
130 (*info->fprintf_func) (info->stream, ")");
133 (*info->fprintf_func) (info->stream, "(");
139 else if ((operand->flags & MN10200_OPERAND_PCREL) != 0)
140 (*info->print_address_func)
141 ((value + memaddr + mysize) & 0xffffff, info);
143 else if ((operand->flags & MN10200_OPERAND_MEMADDR) != 0)
144 (*info->print_address_func) (value, info);
147 (*info->fprintf_func) (info->stream, "%ld", value);
156 (*info->fprintf_func) (info->stream, _("unknown\t0x%04lx"), insn);
160 print_insn_mn10200 (bfd_vma memaddr, struct disassemble_info *info)
165 unsigned long extension = 0;
166 unsigned int consume;
168 /* First figure out how big the opcode is. */
169 status = (*info->read_memory_func) (memaddr, buffer, 1, info);
172 (*info->memory_error_func) (status, memaddr, info);
176 insn = *(unsigned char *) buffer;
178 /* These are one byte insns. */
179 if ((insn & 0xf0) == 0x00
180 || (insn & 0xf0) == 0x10
181 || (insn & 0xf0) == 0x20
182 || (insn & 0xf0) == 0x30
183 || ((insn & 0xf0) == 0x80
184 && (insn & 0x0c) >> 2 != (insn & 0x03))
185 || (insn & 0xf0) == 0x90
186 || (insn & 0xf0) == 0xa0
187 || (insn & 0xf0) == 0xb0
188 || (insn & 0xff) == 0xeb
189 || (insn & 0xff) == 0xf6
190 || (insn & 0xff) == 0xfe
191 || (insn & 0xff) == 0xff)
197 /* These are two byte insns. */
198 else if ((insn & 0xf0) == 0x40
199 || (insn & 0xf0) == 0x50
200 || (insn & 0xf0) == 0x60
201 || (insn & 0xf0) == 0x70
202 || (insn & 0xf0) == 0x80
203 || (insn & 0xfc) == 0xd0
204 || (insn & 0xfc) == 0xd4
205 || (insn & 0xfc) == 0xd8
206 || (insn & 0xfc) == 0xe0
207 || (insn & 0xfc) == 0xe4
208 || (insn & 0xff) == 0xe8
209 || (insn & 0xff) == 0xe9
210 || (insn & 0xff) == 0xea
211 || (insn & 0xff) == 0xf0
212 || (insn & 0xff) == 0xf1
213 || (insn & 0xff) == 0xf2
214 || (insn & 0xff) == 0xf3)
216 status = (*info->read_memory_func) (memaddr, buffer, 2, info);
219 (*info->memory_error_func) (status, memaddr, info);
222 insn = bfd_getb16 (buffer);
226 /* These are three byte insns with a 16bit operand in little
228 else if ((insn & 0xf0) == 0xc0
229 || (insn & 0xfc) == 0xdc
230 || (insn & 0xfc) == 0xec
231 || (insn & 0xff) == 0xf8
232 || (insn & 0xff) == 0xf9
233 || (insn & 0xff) == 0xfa
234 || (insn & 0xff) == 0xfb
235 || (insn & 0xff) == 0xfc
236 || (insn & 0xff) == 0xfd)
238 status = (*info->read_memory_func) (memaddr + 1, buffer, 2, info);
241 (*info->memory_error_func) (status, memaddr, info);
245 insn |= bfd_getl16 (buffer);
249 /* These are three byte insns too, but we don't have to mess with
251 else if ((insn & 0xff) == 0xf5)
253 status = (*info->read_memory_func) (memaddr + 1, buffer, 2, info);
256 (*info->memory_error_func) (status, memaddr, info);
260 insn |= bfd_getb16 (buffer);
265 /* These are four byte insns. */
266 else if ((insn & 0xff) == 0xf7)
268 status = (*info->read_memory_func) (memaddr, buffer, 2, info);
271 (*info->memory_error_func) (status, memaddr, info);
274 insn = bfd_getb16 (buffer);
276 status = (*info->read_memory_func) (memaddr + 2, buffer, 2, info);
279 (*info->memory_error_func) (status, memaddr, info);
282 insn |= bfd_getl16 (buffer);
287 /* These are five byte insns. */
288 else if ((insn & 0xff) == 0xf4)
290 status = (*info->read_memory_func) (memaddr, buffer, 2, info);
293 (*info->memory_error_func) (status, memaddr, info);
296 insn = bfd_getb16 (buffer);
299 status = (*info->read_memory_func) (memaddr + 4, buffer, 1, info);
302 (*info->memory_error_func) (status, memaddr, info);
305 insn |= (*(unsigned char *)buffer << 8) & 0xff00;
307 status = (*info->read_memory_func) (memaddr + 3, buffer, 1, info);
310 (*info->memory_error_func) (status, memaddr, info);
313 insn |= (*(unsigned char *)buffer) & 0xff;
315 status = (*info->read_memory_func) (memaddr + 2, buffer, 1, info);
318 (*info->memory_error_func) (status, memaddr, info);
321 extension = (*(unsigned char *)buffer) & 0xff;
326 (*info->fprintf_func) (info->stream, _("unknown\t0x%02x"), insn);
330 disassemble (memaddr, info, insn, extension, consume);