1 /* Disassemble MN10200 instructions.
2 Copyright 1996, 1997, 1998, 2000, 2005, 2007 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. */
24 #include "opcode/mn10200.h"
29 disassemble (bfd_vma memaddr
,
30 struct disassemble_info
*info
,
32 unsigned long extension
,
35 struct mn10200_opcode
*op
= (struct mn10200_opcode
*)mn10200_opcodes
;
36 const struct mn10200_operand
*operand
;
39 /* Find the opcode. */
42 int mysize
, extra_shift
;
44 if (op
->format
== FMT_1
)
46 else if (op
->format
== FMT_2
47 || op
->format
== FMT_4
)
49 else if (op
->format
== FMT_3
50 || op
->format
== FMT_5
)
52 else if (op
->format
== FMT_6
)
54 else if (op
->format
== FMT_7
)
59 if (op
->format
== FMT_2
|| op
->format
== FMT_5
)
61 else if (op
->format
== FMT_3
62 || op
->format
== FMT_6
63 || op
->format
== FMT_7
)
68 if ((op
->mask
& insn
) == op
->opcode
69 && size
== (unsigned int) mysize
)
71 const unsigned char *opindex_ptr
;
76 (*info
->fprintf_func
) (info
->stream
, "%s\t", op
->name
);
78 /* Now print the operands. */
79 for (opindex_ptr
= op
->operands
, nocomma
= 1;
85 operand
= &mn10200_operands
[*opindex_ptr
];
87 if ((operand
->flags
& MN10200_OPERAND_EXTENDED
) != 0)
89 value
= (insn
& 0xffff) << 8;
94 value
= ((insn
>> (operand
->shift
))
95 & ((1L << operand
->bits
) - 1L));
98 if ((operand
->flags
& MN10200_OPERAND_SIGNED
) != 0)
99 value
= ((long)(value
<< (32 - operand
->bits
))
100 >> (32 - operand
->bits
));
104 || ((operand
->flags
& MN10200_OPERAND_PAREN
) == 0)))
105 (*info
->fprintf_func
) (info
->stream
, ",");
109 if ((operand
->flags
& MN10200_OPERAND_DREG
) != 0)
111 value
= ((insn
>> (operand
->shift
+ extra_shift
))
112 & ((1 << operand
->bits
) - 1));
113 (*info
->fprintf_func
) (info
->stream
, "d%ld", value
);
116 else if ((operand
->flags
& MN10200_OPERAND_AREG
) != 0)
118 value
= ((insn
>> (operand
->shift
+ extra_shift
))
119 & ((1 << operand
->bits
) - 1));
120 (*info
->fprintf_func
) (info
->stream
, "a%ld", value
);
123 else if ((operand
->flags
& MN10200_OPERAND_PSW
) != 0)
124 (*info
->fprintf_func
) (info
->stream
, "psw");
126 else if ((operand
->flags
& MN10200_OPERAND_MDR
) != 0)
127 (*info
->fprintf_func
) (info
->stream
, "mdr");
129 else if ((operand
->flags
& MN10200_OPERAND_PAREN
) != 0)
132 (*info
->fprintf_func
) (info
->stream
, ")");
135 (*info
->fprintf_func
) (info
->stream
, "(");
141 else if ((operand
->flags
& MN10200_OPERAND_PCREL
) != 0)
142 (*info
->print_address_func
)
143 ((value
+ memaddr
+ mysize
) & 0xffffff, info
);
145 else if ((operand
->flags
& MN10200_OPERAND_MEMADDR
) != 0)
146 (*info
->print_address_func
) (value
, info
);
149 (*info
->fprintf_func
) (info
->stream
, "%ld", value
);
158 (*info
->fprintf_func
) (info
->stream
, _("unknown\t0x%04lx"), insn
);
162 print_insn_mn10200 (bfd_vma memaddr
, struct disassemble_info
*info
)
167 unsigned long extension
= 0;
168 unsigned int consume
;
170 /* First figure out how big the opcode is. */
171 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 1, info
);
174 (*info
->memory_error_func
) (status
, memaddr
, info
);
178 insn
= *(unsigned char *) buffer
;
180 /* These are one byte insns. */
181 if ((insn
& 0xf0) == 0x00
182 || (insn
& 0xf0) == 0x10
183 || (insn
& 0xf0) == 0x20
184 || (insn
& 0xf0) == 0x30
185 || ((insn
& 0xf0) == 0x80
186 && (insn
& 0x0c) >> 2 != (insn
& 0x03))
187 || (insn
& 0xf0) == 0x90
188 || (insn
& 0xf0) == 0xa0
189 || (insn
& 0xf0) == 0xb0
190 || (insn
& 0xff) == 0xeb
191 || (insn
& 0xff) == 0xf6
192 || (insn
& 0xff) == 0xfe
193 || (insn
& 0xff) == 0xff)
199 /* These are two byte insns. */
200 else if ((insn
& 0xf0) == 0x40
201 || (insn
& 0xf0) == 0x50
202 || (insn
& 0xf0) == 0x60
203 || (insn
& 0xf0) == 0x70
204 || (insn
& 0xf0) == 0x80
205 || (insn
& 0xfc) == 0xd0
206 || (insn
& 0xfc) == 0xd4
207 || (insn
& 0xfc) == 0xd8
208 || (insn
& 0xfc) == 0xe0
209 || (insn
& 0xfc) == 0xe4
210 || (insn
& 0xff) == 0xe8
211 || (insn
& 0xff) == 0xe9
212 || (insn
& 0xff) == 0xea
213 || (insn
& 0xff) == 0xf0
214 || (insn
& 0xff) == 0xf1
215 || (insn
& 0xff) == 0xf2
216 || (insn
& 0xff) == 0xf3)
218 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 2, info
);
221 (*info
->memory_error_func
) (status
, memaddr
, info
);
224 insn
= bfd_getb16 (buffer
);
228 /* These are three byte insns with a 16bit operand in little
230 else if ((insn
& 0xf0) == 0xc0
231 || (insn
& 0xfc) == 0xdc
232 || (insn
& 0xfc) == 0xec
233 || (insn
& 0xff) == 0xf8
234 || (insn
& 0xff) == 0xf9
235 || (insn
& 0xff) == 0xfa
236 || (insn
& 0xff) == 0xfb
237 || (insn
& 0xff) == 0xfc
238 || (insn
& 0xff) == 0xfd)
240 status
= (*info
->read_memory_func
) (memaddr
+ 1, buffer
, 2, info
);
243 (*info
->memory_error_func
) (status
, memaddr
, info
);
247 insn
|= bfd_getl16 (buffer
);
251 /* These are three byte insns too, but we don't have to mess with
253 else if ((insn
& 0xff) == 0xf5)
255 status
= (*info
->read_memory_func
) (memaddr
+ 1, buffer
, 2, info
);
258 (*info
->memory_error_func
) (status
, memaddr
, info
);
262 insn
|= bfd_getb16 (buffer
);
267 /* These are four byte insns. */
268 else if ((insn
& 0xff) == 0xf7)
270 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 2, info
);
273 (*info
->memory_error_func
) (status
, memaddr
, info
);
276 insn
= bfd_getb16 (buffer
);
278 status
= (*info
->read_memory_func
) (memaddr
+ 2, buffer
, 2, info
);
281 (*info
->memory_error_func
) (status
, memaddr
, info
);
284 insn
|= bfd_getl16 (buffer
);
289 /* These are five byte insns. */
290 else if ((insn
& 0xff) == 0xf4)
292 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 2, info
);
295 (*info
->memory_error_func
) (status
, memaddr
, info
);
298 insn
= bfd_getb16 (buffer
);
301 status
= (*info
->read_memory_func
) (memaddr
+ 4, buffer
, 1, info
);
304 (*info
->memory_error_func
) (status
, memaddr
, info
);
307 insn
|= (*(unsigned char *)buffer
<< 8) & 0xff00;
309 status
= (*info
->read_memory_func
) (memaddr
+ 3, buffer
, 1, info
);
312 (*info
->memory_error_func
) (status
, memaddr
, info
);
315 insn
|= (*(unsigned char *)buffer
) & 0xff;
317 status
= (*info
->read_memory_func
) (memaddr
+ 2, buffer
, 1, info
);
320 (*info
->memory_error_func
) (status
, memaddr
, info
);
323 extension
= (*(unsigned char *)buffer
) & 0xff;
328 (*info
->fprintf_func
) (info
->stream
, _("unknown\t0x%02lx"), insn
);
332 disassemble (memaddr
, info
, insn
, extension
, consume
);