1 /* Disassemble MN10300 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/mn10300.h"
26 static void disassemble PARAMS ((bfd_vma, struct disassemble_info *,
27 unsigned long insn, unsigned int));
30 print_insn_mn10300 (memaddr, info)
32 struct disassemble_info *info;
39 /* First figure out how big the opcode is. */
40 status = (*info->read_memory_func) (memaddr, buffer, 1, info);
43 (*info->memory_error_func) (status, memaddr, info);
46 insn = *(unsigned char *) buffer;
48 /* These are one byte insns. */
49 if ((insn & 0xf3) == 0x00
50 || (insn & 0xf0) == 0x10
51 || (insn & 0xfc) == 0x3c
52 || (insn & 0xf3) == 0x41
53 || (insn & 0xf3) == 0x40
54 || (insn & 0xfc) == 0x50
55 || (insn & 0xfc) == 0x54
56 || (insn & 0xf0) == 0x60
57 || (insn & 0xf0) == 0x70
58 || ((insn & 0xf0) == 0x80
59 && (insn & 0x0c) >> 2 != (insn & 0x03))
60 || ((insn & 0xf0) == 0x90
61 && (insn & 0x0c) >> 2 != (insn & 0x03))
62 || ((insn & 0xf0) == 0xa0
63 && (insn & 0x0c) >> 2 != (insn & 0x03))
64 || ((insn & 0xf0) == 0xb0
65 && (insn & 0x0c) >> 2 != (insn & 0x03))
66 || (insn & 0xff) == 0xcb
67 || (insn & 0xfc) == 0xd0
68 || (insn & 0xfc) == 0xd4
69 || (insn & 0xfc) == 0xd8
70 || (insn & 0xf0) == 0xe0
71 || (insn & 0xff) == 0xff)
76 /* These are two byte insns. */
77 else if ((insn & 0xf0) == 0x80
78 || (insn & 0xf0) == 0x90
79 || (insn & 0xf0) == 0xa0
80 || (insn & 0xf0) == 0xb0
81 || (insn & 0xfc) == 0x20
82 || (insn & 0xfc) == 0x28
83 || (insn & 0xf3) == 0x43
84 || (insn & 0xf3) == 0x42
85 || (insn & 0xfc) == 0x58
86 || (insn & 0xfc) == 0x5c
87 || ((insn & 0xf0) == 0xc0
88 && (insn & 0xff) != 0xcb
89 && (insn & 0xff) != 0xcc
90 && (insn & 0xff) != 0xcd)
91 || (insn & 0xff) == 0xf0
92 || (insn & 0xff) == 0xf1
93 || (insn & 0xff) == 0xf2
94 || (insn & 0xff) == 0xf3
95 || (insn & 0xff) == 0xf4
96 || (insn & 0xff) == 0xf5
97 || (insn & 0xff) == 0xf6)
99 status = (*info->read_memory_func) (memaddr, buffer, 2, info);
102 (*info->memory_error_func) (status, memaddr, info);
105 insn = bfd_getb16 (buffer);
109 /* These are three byte insns. */
110 else if ((insn & 0xff) == 0xf8
111 || (insn & 0xff) == 0xcc
112 || (insn & 0xff) == 0xf9
113 || (insn & 0xf3) == 0x01
114 || (insn & 0xf3) == 0x02
115 || (insn & 0xf3) == 0x03
116 || (insn & 0xfc) == 0x24
117 || (insn & 0xfc) == 0x2c
118 || (insn & 0xfc) == 0x30
119 || (insn & 0xfc) == 0x34
120 || (insn & 0xfc) == 0x38
121 || (insn & 0xff) == 0xde
122 || (insn & 0xff) == 0xdf
123 /* start-sanitize-am33 */
124 || (insn & 0xff) == 0xf9
125 /* end-sanitize-am33 */
126 || (insn & 0xff) == 0xcc)
128 status = (*info->read_memory_func) (memaddr, buffer, 2, info);
131 (*info->memory_error_func) (status, memaddr, info);
134 insn = bfd_getb16 (buffer);
136 status = (*info->read_memory_func) (memaddr + 2, buffer, 1, info);
139 (*info->memory_error_func) (status, memaddr, info);
142 insn |= *(unsigned char *)buffer;
146 /* These are four byte insns. */
147 else if ((insn & 0xff) == 0xfa
148 /* start-sanitize-am33 */
149 || (insn & 0xff) == 0xf7
150 /* end-sanitize-am33 */
151 || (insn & 0xff) == 0xfb)
153 status = (*info->read_memory_func) (memaddr, buffer, 4, info);
156 (*info->memory_error_func) (status, memaddr, info);
159 insn = bfd_getb32 (buffer);
163 /* These are five byte insns. */
164 else if ((insn & 0xff) == 0xcd
165 || (insn & 0xff) == 0xdc)
167 status = (*info->read_memory_func) (memaddr, buffer, 4, info);
170 (*info->memory_error_func) (status, memaddr, info);
173 insn = bfd_getb32 (buffer);
177 /* These are six byte insns. */
178 else if ((insn & 0xff) == 0xfd
179 || (insn & 0xff) == 0xfc)
181 status = (*info->read_memory_func) (memaddr, buffer, 4, info);
184 (*info->memory_error_func) (status, memaddr, info);
188 insn = bfd_getb32 (buffer);
192 /* Else its a seven byte insns (in theory). */
195 status = (*info->read_memory_func) (memaddr, buffer, 4, info);
198 (*info->memory_error_func) (status, memaddr, info);
202 insn = bfd_getb32 (buffer);
206 disassemble (memaddr, info, insn, consume);
212 disassemble (memaddr, info, insn, size)
214 struct disassemble_info *info;
218 struct mn10300_opcode *op = (struct mn10300_opcode *)mn10300_opcodes;
219 const struct mn10300_operand *operand;
221 unsigned long extension = 0;
222 int status, match = 0;
224 /* Find the opcode. */
227 int mysize, extra_shift;
229 if (op->format == FMT_S0)
231 else if (op->format == FMT_S1
232 || op->format == FMT_D0)
234 else if (op->format == FMT_S2
235 || op->format == FMT_D1)
237 else if (op->format == FMT_S4)
239 else if (op->format == FMT_D2)
241 else if (op->format == FMT_D4)
243 /* start-sanitize-am33 */
244 else if (op->format == FMT_D6)
246 else if (op->format == FMT_D7 || op->format == FMT_D10)
248 else if (op->format == FMT_D8)
250 else if (op->format == FMT_D9)
252 /* end-sanitize-am33 */
256 if ((op->mask & insn) == op->opcode
257 && size == (unsigned int) mysize)
259 const unsigned char *opindex_ptr;
260 unsigned int nocomma;
263 if (op->format == FMT_D1 || op->format == FMT_S1)
265 else if (op->format == FMT_D2 || op->format == FMT_D4
266 || op->format == FMT_S2 || op->format == FMT_S4
267 || op->format == FMT_S6 || op->format == FMT_D5)
269 /* start-sanitize-am33 */
270 else if (op->format == FMT_D7
271 || op->format == FMT_D8
272 || op->format == FMT_D9)
274 /* end-sanitize-am33 */
278 if (size == 1 || size == 2)
283 && (op->format == FMT_D1
284 || op->opcode == 0xdf0000
285 || op->opcode == 0xde0000))
289 /* start-sanitize-am33 */
291 && op->format == FMT_D6)
295 /* end-sanitize-am33 */
299 status = (*info->read_memory_func) (memaddr + 1, buffer, 2, info);
302 (*info->memory_error_func) (status, memaddr, info);
306 insn |= bfd_getl16 (buffer);
310 && (op->opcode == 0xfaf80000
311 || op->opcode == 0xfaf00000
312 || op->opcode == 0xfaf40000))
316 /* start-sanitize-am33 */
318 && (op->format == FMT_D7
319 || op->format == FMT_D10))
323 /* end-sanitize-am33 */
327 status = (*info->read_memory_func) (memaddr + 2, buffer, 2, info);
330 (*info->memory_error_func) (status, memaddr, info);
334 insn |= bfd_getl16 (buffer);
337 else if (size == 5 && op->opcode == 0xdc000000)
339 unsigned long temp = 0;
340 status = (*info->read_memory_func) (memaddr + 1, buffer, 4, info);
343 (*info->memory_error_func) (status, memaddr, info);
346 temp |= bfd_getl32 (buffer);
349 insn |= (temp & 0xffffff00) >> 8;
350 extension = temp & 0xff;
354 unsigned long temp = 0;
355 status = (*info->read_memory_func) (memaddr + 1, buffer, 2, info);
358 (*info->memory_error_func) (status, memaddr, info);
361 temp |= bfd_getl16 (buffer);
366 status = (*info->read_memory_func) (memaddr + 4, buffer, 1, info);
369 (*info->memory_error_func) (status, memaddr, info);
372 extension = *(unsigned char *)buffer;
374 /* start-sanitize-am33 */
375 else if (size == 6 && op->format == FMT_D8)
378 status = (*info->read_memory_func) (memaddr + 5, buffer, 1, info);
381 (*info->memory_error_func) (status, memaddr, info);
384 insn |= *(unsigned char *)buffer;
386 status = (*info->read_memory_func) (memaddr + 3, buffer, 2, info);
389 (*info->memory_error_func) (status, memaddr, info);
392 extension = bfd_getl16 (buffer);
394 /* end-sanitize-am33 */
397 unsigned long temp = 0;
398 status = (*info->read_memory_func) (memaddr + 2, buffer, 4, info);
401 (*info->memory_error_func) (status, memaddr, info);
404 temp |= bfd_getl32 (buffer);
407 insn |= (temp >> 16) & 0xffff;
408 extension = temp & 0xffff;
410 /* start-sanitize-am33 */
411 else if (size == 7 && op->format == FMT_D9)
414 status = (*info->read_memory_func) (memaddr + 3, buffer, 4, info);
417 (*info->memory_error_func) (status, memaddr, info);
420 extension = bfd_getl32 (buffer);
421 insn |= (extension & 0xff000000) >> 24;
422 extension &= 0xffffff;
424 /* end-sanitize-am33 */
425 else if (size == 7 && op->opcode == 0xdd000000)
427 unsigned long temp = 0;
428 status = (*info->read_memory_func) (memaddr + 1, buffer, 4, info);
431 (*info->memory_error_func) (status, memaddr, info);
434 temp |= bfd_getl32 (buffer);
437 insn |= (temp >> 8) & 0xffffff;
438 extension = (temp & 0xff) << 16;
440 status = (*info->read_memory_func) (memaddr + 5, buffer, 2, info);
443 (*info->memory_error_func) (status, memaddr, info);
446 extension |= bfd_getb16 (buffer);
450 unsigned long temp = 0;
451 status = (*info->read_memory_func) (memaddr + 2, buffer, 4, info);
454 (*info->memory_error_func) (status, memaddr, info);
457 temp |= bfd_getl32 (buffer);
460 insn |= (temp >> 16) & 0xffff;
461 extension = (temp & 0xffff) << 8;
463 status = (*info->read_memory_func) (memaddr + 6, buffer, 1, info);
466 (*info->memory_error_func) (status, memaddr, info);
469 extension |= *(unsigned char *)buffer;
473 (*info->fprintf_func) (info->stream, "%s\t", op->name);
475 /* Now print the operands. */
476 for (opindex_ptr = op->operands, nocomma = 1;
482 operand = &mn10300_operands[*opindex_ptr];
484 if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
487 value = insn & ((1 << operand->bits) - 1);
488 value <<= (32 - operand->bits);
489 temp = extension >> operand->shift;
490 temp &= ((1 << (32 - operand->bits)) - 1);
493 /* start-sanitize-am33 */
494 else if ((operand->flags & MN10300_OPERAND_24BIT) != 0)
497 value = insn & ((1 << operand->bits) - 1);
498 value <<= (24 - operand->bits);
499 temp = extension >> operand->shift;
500 temp &= ((1 << (24 - operand->bits)) - 1);
502 if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
503 value = ((value & 0xffffff) ^ (~0x7fffff)) + 0x800000;
505 /* end-sanitize-am33 */
506 else if ((operand->flags & MN10300_OPERAND_EXTENDED) != 0)
508 value = ((extension >> (operand->shift))
509 & ((1 << operand->bits) - 1));
513 value = ((insn >> (operand->shift))
514 & ((1 << operand->bits) - 1));
517 if ((operand->flags & MN10300_OPERAND_SIGNED) != 0
518 /* start-sanitize-am33 */
519 /* These are properly extended by the code above. */
520 && ((operand->flags & MN10300_OPERAND_24BIT) == 0)
521 /* end-sanitize-am33 */
523 value = ((long)(value << (32 - operand->bits))
524 >> (32 - operand->bits));
528 || ((operand->flags & MN10300_OPERAND_PAREN) == 0)))
529 (*info->fprintf_func) (info->stream, ",");
533 if ((operand->flags & MN10300_OPERAND_DREG) != 0)
535 value = ((insn >> (operand->shift + extra_shift))
536 & ((1 << operand->bits) - 1));
537 (*info->fprintf_func) (info->stream, "d%d", value);
540 else if ((operand->flags & MN10300_OPERAND_AREG) != 0)
542 value = ((insn >> (operand->shift + extra_shift))
543 & ((1 << operand->bits) - 1));
544 (*info->fprintf_func) (info->stream, "a%d", value);
547 else if ((operand->flags & MN10300_OPERAND_SP) != 0)
548 (*info->fprintf_func) (info->stream, "sp");
550 else if ((operand->flags & MN10300_OPERAND_PSW) != 0)
551 (*info->fprintf_func) (info->stream, "psw");
553 else if ((operand->flags & MN10300_OPERAND_MDR) != 0)
554 (*info->fprintf_func) (info->stream, "mdr");
556 /* start-sanitize-am33 */
557 else if ((operand->flags & MN10300_OPERAND_RREG) != 0)
559 value = ((insn >> (operand->shift + extra_shift))
560 & ((1 << operand->bits) - 1));
561 (*info->fprintf_func) (info->stream, "r%d", value);
564 else if ((operand->flags & MN10300_OPERAND_XRREG) != 0)
566 value = ((insn >> (operand->shift + extra_shift))
567 & ((1 << operand->bits) - 1));
568 (*info->fprintf_func) (info->stream, "xr%d", value);
571 else if ((operand->flags & MN10300_OPERAND_USP) != 0)
572 (*info->fprintf_func) (info->stream, "usp");
574 else if ((operand->flags & MN10300_OPERAND_SSP) != 0)
575 (*info->fprintf_func) (info->stream, "ssp");
577 else if ((operand->flags & MN10300_OPERAND_MSP) != 0)
578 (*info->fprintf_func) (info->stream, "msp");
580 else if ((operand->flags & MN10300_OPERAND_PC) != 0)
581 (*info->fprintf_func) (info->stream, "pc");
583 else if ((operand->flags & MN10300_OPERAND_EPSW) != 0)
584 (*info->fprintf_func) (info->stream, "epsw");
586 else if ((operand->flags & MN10300_OPERAND_PLUS) != 0)
587 (*info->fprintf_func) (info->stream, "+");
588 /* end-sanitize-am33 */
590 else if ((operand->flags & MN10300_OPERAND_PAREN) != 0)
593 (*info->fprintf_func) (info->stream, ")");
596 (*info->fprintf_func) (info->stream, "(");
602 else if ((operand->flags & MN10300_OPERAND_PCREL) != 0)
603 (*info->print_address_func) ((long) value + memaddr, info);
605 else if ((operand->flags & MN10300_OPERAND_MEMADDR) != 0)
606 (*info->print_address_func) (value, info);
608 else if ((operand->flags & MN10300_OPERAND_REG_LIST) != 0)
612 (*info->fprintf_func) (info->stream, "[");
615 (*info->fprintf_func) (info->stream, "d2");
622 (*info->fprintf_func) (info->stream, ",");
623 (*info->fprintf_func) (info->stream, "d3");
630 (*info->fprintf_func) (info->stream, ",");
631 (*info->fprintf_func) (info->stream, "a2");
638 (*info->fprintf_func) (info->stream, ",");
639 (*info->fprintf_func) (info->stream, "a3");
646 (*info->fprintf_func) (info->stream, ",");
647 (*info->fprintf_func) (info->stream, "other");
651 /* start-sanitize-am33 */
655 (*info->fprintf_func) (info->stream, ",");
656 (*info->fprintf_func) (info->stream, "exreg0");
662 (*info->fprintf_func) (info->stream, ",");
663 (*info->fprintf_func) (info->stream, "exreg1");
669 (*info->fprintf_func) (info->stream, ",");
670 (*info->fprintf_func) (info->stream, "exother");
673 /* end-sanitize-am33 */
674 (*info->fprintf_func) (info->stream, "]");
678 (*info->fprintf_func) (info->stream, "%d", value);
688 /* xgettext:c-format */
689 (*info->fprintf_func) (info->stream, _("unknown\t0x%04x"), insn);