1 /* Disassemble MN10200 instructions.
2 Copyright 1996, 1997, 1998, 2000 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, MA 02110-1301, USA. */
22 #include "opcode/mn10200.h"
26 static void disassemble
PARAMS ((bfd_vma
, struct disassemble_info
*,
27 unsigned long insn
, unsigned long,
31 print_insn_mn10200 (memaddr
, info
)
33 struct disassemble_info
*info
;
38 unsigned long extension
= 0;
41 /* First figure out how big the opcode is. */
42 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 1, info
);
45 (*info
->memory_error_func
) (status
, memaddr
, info
);
49 insn
= *(unsigned char *) buffer
;
51 /* These are one byte insns. */
52 if ((insn
& 0xf0) == 0x00
53 || (insn
& 0xf0) == 0x10
54 || (insn
& 0xf0) == 0x20
55 || (insn
& 0xf0) == 0x30
56 || ((insn
& 0xf0) == 0x80
57 && (insn
& 0x0c) >> 2 != (insn
& 0x03))
58 || (insn
& 0xf0) == 0x90
59 || (insn
& 0xf0) == 0xa0
60 || (insn
& 0xf0) == 0xb0
61 || (insn
& 0xff) == 0xeb
62 || (insn
& 0xff) == 0xf6
63 || (insn
& 0xff) == 0xfe
64 || (insn
& 0xff) == 0xff)
70 /* These are two byte insns. */
71 else if ((insn
& 0xf0) == 0x40
72 || (insn
& 0xf0) == 0x50
73 || (insn
& 0xf0) == 0x60
74 || (insn
& 0xf0) == 0x70
75 || (insn
& 0xf0) == 0x80
76 || (insn
& 0xfc) == 0xd0
77 || (insn
& 0xfc) == 0xd4
78 || (insn
& 0xfc) == 0xd8
79 || (insn
& 0xfc) == 0xe0
80 || (insn
& 0xfc) == 0xe4
81 || (insn
& 0xff) == 0xe8
82 || (insn
& 0xff) == 0xe9
83 || (insn
& 0xff) == 0xea
84 || (insn
& 0xff) == 0xf0
85 || (insn
& 0xff) == 0xf1
86 || (insn
& 0xff) == 0xf2
87 || (insn
& 0xff) == 0xf3)
89 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 2, info
);
92 (*info
->memory_error_func
) (status
, memaddr
, info
);
95 insn
= bfd_getb16 (buffer
);
99 /* These are three byte insns with a 16bit operand in little
101 else if ((insn
& 0xf0) == 0xc0
102 || (insn
& 0xfc) == 0xdc
103 || (insn
& 0xfc) == 0xec
104 || (insn
& 0xff) == 0xf8
105 || (insn
& 0xff) == 0xf9
106 || (insn
& 0xff) == 0xfa
107 || (insn
& 0xff) == 0xfb
108 || (insn
& 0xff) == 0xfc
109 || (insn
& 0xff) == 0xfd)
111 status
= (*info
->read_memory_func
) (memaddr
+ 1, buffer
, 2, info
);
114 (*info
->memory_error_func
) (status
, memaddr
, info
);
118 insn
|= bfd_getl16 (buffer
);
122 /* These are three byte insns too, but we don't have to mess with
124 else if ((insn
& 0xff) == 0xf5)
126 status
= (*info
->read_memory_func
) (memaddr
+ 1, buffer
, 2, info
);
129 (*info
->memory_error_func
) (status
, memaddr
, info
);
133 insn
|= bfd_getb16 (buffer
);
138 /* These are four byte insns. */
139 else if ((insn
& 0xff) == 0xf7)
141 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 2, info
);
144 (*info
->memory_error_func
) (status
, memaddr
, info
);
147 insn
= bfd_getb16 (buffer
);
149 status
= (*info
->read_memory_func
) (memaddr
+ 2, buffer
, 2, info
);
152 (*info
->memory_error_func
) (status
, memaddr
, info
);
155 insn
|= bfd_getl16 (buffer
);
160 /* These are five byte insns. */
161 else if ((insn
& 0xff) == 0xf4)
163 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 2, info
);
166 (*info
->memory_error_func
) (status
, memaddr
, info
);
169 insn
= bfd_getb16 (buffer
);
172 status
= (*info
->read_memory_func
) (memaddr
+ 4, buffer
, 1, info
);
175 (*info
->memory_error_func
) (status
, memaddr
, info
);
178 insn
|= (*(unsigned char *)buffer
<< 8) & 0xff00;
180 status
= (*info
->read_memory_func
) (memaddr
+ 3, buffer
, 1, info
);
183 (*info
->memory_error_func
) (status
, memaddr
, info
);
186 insn
|= (*(unsigned char *)buffer
) & 0xff;
188 status
= (*info
->read_memory_func
) (memaddr
+ 2, buffer
, 1, info
);
191 (*info
->memory_error_func
) (status
, memaddr
, info
);
194 extension
= (*(unsigned char *)buffer
) & 0xff;
199 (*info
->fprintf_func
) (info
->stream
, _("unknown\t0x%02x"), insn
);
203 disassemble (memaddr
, info
, insn
, extension
, consume
);
209 disassemble (memaddr
, info
, insn
, extension
, size
)
211 struct disassemble_info
*info
;
213 unsigned long extension
;
216 struct mn10200_opcode
*op
= (struct mn10200_opcode
*)mn10200_opcodes
;
217 const struct mn10200_operand
*operand
;
220 /* Find the opcode. */
223 int mysize
, extra_shift
;
225 if (op
->format
== FMT_1
)
227 else if (op
->format
== FMT_2
228 || op
->format
== FMT_4
)
230 else if (op
->format
== FMT_3
231 || op
->format
== FMT_5
)
233 else if (op
->format
== FMT_6
)
235 else if (op
->format
== FMT_7
)
240 if (op
->format
== FMT_2
|| op
->format
== FMT_5
)
242 else if (op
->format
== FMT_3
243 || op
->format
== FMT_6
244 || op
->format
== FMT_7
)
249 if ((op
->mask
& insn
) == op
->opcode
250 && size
== (unsigned int) mysize
)
252 const unsigned char *opindex_ptr
;
253 unsigned int nocomma
;
257 (*info
->fprintf_func
) (info
->stream
, "%s\t", op
->name
);
259 /* Now print the operands. */
260 for (opindex_ptr
= op
->operands
, nocomma
= 1;
266 operand
= &mn10200_operands
[*opindex_ptr
];
268 if ((operand
->flags
& MN10200_OPERAND_EXTENDED
) != 0)
270 value
= (insn
& 0xffff) << 8;
275 value
= ((insn
>> (operand
->shift
))
276 & ((1L << operand
->bits
) - 1L));
279 if ((operand
->flags
& MN10200_OPERAND_SIGNED
) != 0)
280 value
= ((long)(value
<< (32 - operand
->bits
))
281 >> (32 - operand
->bits
));
285 || ((operand
->flags
& MN10200_OPERAND_PAREN
) == 0)))
286 (*info
->fprintf_func
) (info
->stream
, ",");
290 if ((operand
->flags
& MN10200_OPERAND_DREG
) != 0)
292 value
= ((insn
>> (operand
->shift
+ extra_shift
))
293 & ((1 << operand
->bits
) - 1));
294 (*info
->fprintf_func
) (info
->stream
, "d%d", value
);
297 else if ((operand
->flags
& MN10200_OPERAND_AREG
) != 0)
299 value
= ((insn
>> (operand
->shift
+ extra_shift
))
300 & ((1 << operand
->bits
) - 1));
301 (*info
->fprintf_func
) (info
->stream
, "a%d", value
);
304 else if ((operand
->flags
& MN10200_OPERAND_PSW
) != 0)
305 (*info
->fprintf_func
) (info
->stream
, "psw");
307 else if ((operand
->flags
& MN10200_OPERAND_MDR
) != 0)
308 (*info
->fprintf_func
) (info
->stream
, "mdr");
310 else if ((operand
->flags
& MN10200_OPERAND_PAREN
) != 0)
313 (*info
->fprintf_func
) (info
->stream
, ")");
316 (*info
->fprintf_func
) (info
->stream
, "(");
322 else if ((operand
->flags
& MN10200_OPERAND_PCREL
) != 0)
323 (*info
->print_address_func
) ((value
+ memaddr
+ mysize
) & 0xffffff, info
);
325 else if ((operand
->flags
& MN10200_OPERAND_MEMADDR
) != 0)
326 (*info
->print_address_func
) (value
, info
);
329 (*info
->fprintf_func
) (info
->stream
, "%ld", value
);
339 (*info
->fprintf_func
) (info
->stream
, _("unknown\t0x%04lx"), insn
);