1 /* Disassemble MN10200 instructions.
2 Copyright (C) 1996, 1997, 1998 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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
);
48 insn
= *(unsigned char *) buffer
;
50 /* These are one byte insns. */
51 if ((insn
& 0xf0) == 0x00
52 || (insn
& 0xf0) == 0x10
53 || (insn
& 0xf0) == 0x20
54 || (insn
& 0xf0) == 0x30
55 || ((insn
& 0xf0) == 0x80
56 && (insn
& 0x0c) >> 2 != (insn
& 0x03))
57 || (insn
& 0xf0) == 0x90
58 || (insn
& 0xf0) == 0xa0
59 || (insn
& 0xf0) == 0xb0
60 || (insn
& 0xff) == 0xeb
61 || (insn
& 0xff) == 0xf6
62 || (insn
& 0xff) == 0xfe
63 || (insn
& 0xff) == 0xff)
69 /* These are two byte insns. */
70 else if ((insn
& 0xf0) == 0x40
71 || (insn
& 0xf0) == 0x50
72 || (insn
& 0xf0) == 0x60
73 || (insn
& 0xf0) == 0x70
74 || (insn
& 0xf0) == 0x80
75 || (insn
& 0xfc) == 0xd0
76 || (insn
& 0xfc) == 0xd4
77 || (insn
& 0xfc) == 0xd8
78 || (insn
& 0xfc) == 0xe0
79 || (insn
& 0xfc) == 0xe4
80 || (insn
& 0xff) == 0xe8
81 || (insn
& 0xff) == 0xe9
82 || (insn
& 0xff) == 0xea
83 || (insn
& 0xff) == 0xf0
84 || (insn
& 0xff) == 0xf1
85 || (insn
& 0xff) == 0xf2
86 || (insn
& 0xff) == 0xf3)
88 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 2, info
);
91 (*info
->memory_error_func
) (status
, memaddr
, info
);
94 insn
= bfd_getb16 (buffer
);
98 /* These are three byte insns with a 16bit operand in little
100 else if ((insn
& 0xf0) == 0xc0
101 || (insn
& 0xfc) == 0xdc
102 || (insn
& 0xfc) == 0xec
103 || (insn
& 0xff) == 0xf8
104 || (insn
& 0xff) == 0xf9
105 || (insn
& 0xff) == 0xfa
106 || (insn
& 0xff) == 0xfb
107 || (insn
& 0xff) == 0xfc
108 || (insn
& 0xff) == 0xfd)
110 status
= (*info
->read_memory_func
) (memaddr
+ 1, buffer
, 2, info
);
113 (*info
->memory_error_func
) (status
, memaddr
, info
);
117 insn
|= bfd_getl16 (buffer
);
121 /* These are three byte insns too, but we don't have to mess with
123 else if ((insn
& 0xff) == 0xf5)
125 status
= (*info
->read_memory_func
) (memaddr
+ 1, buffer
, 2, info
);
128 (*info
->memory_error_func
) (status
, memaddr
, info
);
132 insn
|= bfd_getb16 (buffer
);
137 /* These are four byte insns. */
138 else if ((insn
& 0xff) == 0xf7)
140 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 2, info
);
143 (*info
->memory_error_func
) (status
, memaddr
, info
);
146 insn
= bfd_getb16 (buffer
);
148 status
= (*info
->read_memory_func
) (memaddr
+ 2, buffer
, 2, info
);
151 (*info
->memory_error_func
) (status
, memaddr
, info
);
154 insn
|= bfd_getl16 (buffer
);
159 /* These are five byte insns. */
160 else if ((insn
& 0xff) == 0xf4)
162 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 2, info
);
165 (*info
->memory_error_func
) (status
, memaddr
, info
);
168 insn
= bfd_getb16 (buffer
);
171 status
= (*info
->read_memory_func
) (memaddr
+ 4, buffer
, 1, info
);
174 (*info
->memory_error_func
) (status
, memaddr
, info
);
177 insn
|= *(unsigned char *)buffer
<< 8;
179 status
= (*info
->read_memory_func
) (memaddr
+ 3, buffer
, 1, info
);
182 (*info
->memory_error_func
) (status
, memaddr
, info
);
185 insn
|= *(unsigned char *)buffer
;
187 status
= (*info
->read_memory_func
) (memaddr
+ 2, buffer
, 1, info
);
190 (*info
->memory_error_func
) (status
, memaddr
, info
);
193 extension
= *(unsigned char *)buffer
;
198 (*info
->fprintf_func
) (info
->stream
, _("unknown\t0x%02x"), insn
);
202 disassemble (memaddr
, info
, insn
, extension
, consume
);
208 disassemble (memaddr
, info
, insn
, extension
, size
)
210 struct disassemble_info
*info
;
212 unsigned long extension
;
215 struct mn10200_opcode
*op
= (struct mn10200_opcode
*)mn10200_opcodes
;
216 const struct mn10200_operand
*operand
;
219 /* Find the opcode. */
222 int mysize
, extra_shift
;
224 if (op
->format
== FMT_1
)
226 else if (op
->format
== FMT_2
227 || op
->format
== FMT_4
)
229 else if (op
->format
== FMT_3
230 || op
->format
== FMT_5
)
232 else if (op
->format
== FMT_6
)
234 else if (op
->format
== FMT_7
)
239 if (op
->format
== FMT_2
|| op
->format
== FMT_5
)
241 else if (op
->format
== FMT_3
242 || op
->format
== FMT_6
243 || op
->format
== FMT_7
)
248 if ((op
->mask
& insn
) == op
->opcode
249 && size
== (unsigned int) mysize
)
251 const unsigned char *opindex_ptr
;
252 unsigned int nocomma
;
256 (*info
->fprintf_func
) (info
->stream
, "%s\t", op
->name
);
258 /* Now print the operands. */
259 for (opindex_ptr
= op
->operands
, nocomma
= 1;
265 operand
= &mn10200_operands
[*opindex_ptr
];
267 if ((operand
->flags
& MN10200_OPERAND_EXTENDED
) != 0)
269 value
= (insn
& 0xffff) << 8;
274 value
= ((insn
>> (operand
->shift
))
275 & ((1 << operand
->bits
) - 1));
278 if ((operand
->flags
& MN10200_OPERAND_SIGNED
) != 0)
279 value
= ((long)(value
<< (32 - operand
->bits
))
280 >> (32 - operand
->bits
));
284 || ((operand
->flags
& MN10200_OPERAND_PAREN
) == 0)))
285 (*info
->fprintf_func
) (info
->stream
, ",");
289 if ((operand
->flags
& MN10200_OPERAND_DREG
) != 0)
291 value
= ((insn
>> (operand
->shift
+ extra_shift
))
292 & ((1 << operand
->bits
) - 1));
293 (*info
->fprintf_func
) (info
->stream
, "d%d", value
);
296 else if ((operand
->flags
& MN10200_OPERAND_AREG
) != 0)
298 value
= ((insn
>> (operand
->shift
+ extra_shift
))
299 & ((1 << operand
->bits
) - 1));
300 (*info
->fprintf_func
) (info
->stream
, "a%d", value
);
303 else if ((operand
->flags
& MN10200_OPERAND_PSW
) != 0)
304 (*info
->fprintf_func
) (info
->stream
, "psw");
306 else if ((operand
->flags
& MN10200_OPERAND_MDR
) != 0)
307 (*info
->fprintf_func
) (info
->stream
, "mdr");
309 else if ((operand
->flags
& MN10200_OPERAND_PAREN
) != 0)
312 (*info
->fprintf_func
) (info
->stream
, ")");
315 (*info
->fprintf_func
) (info
->stream
, "(");
321 else if ((operand
->flags
& MN10200_OPERAND_PCREL
) != 0)
322 (*info
->print_address_func
) ((value
+ memaddr
+ mysize
) & 0xffffff, info
);
324 else if ((operand
->flags
& MN10200_OPERAND_MEMADDR
) != 0)
325 (*info
->print_address_func
) (value
, info
);
328 (*info
->fprintf_func
) (info
->stream
, "%d", value
);
338 (*info
->fprintf_func
) (info
->stream
, _("unknown\t0x%04x"), insn
);