1 /* Print Motorola 68k instructions.
2 Copyright (C) 1986-2019 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. */
22 #include "disassemble.h"
23 #include "floatformat.h"
24 #include "libiberty.h"
27 #include "opcode/m68k.h"
29 /* Local function prototypes. */
31 const char * const fpcr_names
[] =
33 "", "%fpiar", "%fpsr", "%fpiar/%fpsr", "%fpcr",
34 "%fpiar/%fpcr", "%fpsr/%fpcr", "%fpiar/%fpsr/%fpcr"
37 static char *const reg_names
[] =
39 "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6", "%d7",
40 "%a0", "%a1", "%a2", "%a3", "%a4", "%a5", "%fp", "%sp",
44 /* Name of register halves for MAC/EMAC.
45 Seperate from reg_names since 'spu', 'fpl' look weird. */
46 static char *const reg_half_names
[] =
48 "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6", "%d7",
49 "%a0", "%a1", "%a2", "%a3", "%a4", "%a5", "%a6", "%a7",
53 /* Sign-extend an (unsigned char). */
55 #define COERCE_SIGNED_CHAR(ch) ((signed char) (ch))
57 #define COERCE_SIGNED_CHAR(ch) ((int) (((ch) ^ 0x80) & 0xFF) - 128)
60 /* Error code of print_insn_arg's return value. */
62 enum print_insn_arg_error
64 /* An invalid operand is found. */
65 PRINT_INSN_ARG_INVALID_OPERAND
= -1,
67 /* An opcode table error. */
68 PRINT_INSN_ARG_INVALID_OP_TABLE
= -2,
71 PRINT_INSN_ARG_MEMORY_ERROR
= -3,
74 /* Get a 1 byte signed integer. */
75 #define NEXTBYTE(p, val) \
79 if (!FETCH_DATA (info, p)) \
80 return PRINT_INSN_ARG_MEMORY_ERROR; \
81 val = COERCE_SIGNED_CHAR (p[-1]); \
85 /* Get a 2 byte signed integer. */
86 #define COERCE16(x) ((int) (((x) ^ 0x8000) - 0x8000))
88 #define NEXTWORD(p, val, ret_val) \
92 if (!FETCH_DATA (info, p)) \
94 val = COERCE16 ((p[-2] << 8) + p[-1]); \
98 /* Get a 4 byte signed integer. */
99 #define COERCE32(x) (((bfd_vma) (x) ^ 0x80000000) - 0x80000000)
101 #define NEXTLONG(p, val, ret_val) \
105 if (!FETCH_DATA (info, p)) \
107 val = COERCE32 (((((((unsigned) p[-4] << 8) + p[-3]) << 8) \
108 + p[-2]) << 8) + p[-1]); \
112 /* Get a 4 byte unsigned integer. */
113 #define NEXTULONG(p, val) \
117 if (!FETCH_DATA (info, p)) \
118 return PRINT_INSN_ARG_MEMORY_ERROR; \
119 val = (((((((unsigned) p[-4] << 8) + p[-3]) << 8) \
120 + p[-2]) << 8) + p[-1]); \
124 /* Get a single precision float. */
125 #define NEXTSINGLE(val, p) \
129 if (!FETCH_DATA (info, p)) \
130 return PRINT_INSN_ARG_MEMORY_ERROR; \
131 floatformat_to_double (& floatformat_ieee_single_big, \
132 (char *) p - 4, & val); \
136 /* Get a double precision float. */
137 #define NEXTDOUBLE(val, p) \
141 if (!FETCH_DATA (info, p)) \
142 return PRINT_INSN_ARG_MEMORY_ERROR; \
143 floatformat_to_double (& floatformat_ieee_double_big, \
144 (char *) p - 8, & val); \
148 /* Get an extended precision float. */
149 #define NEXTEXTEND(val, p) \
153 if (!FETCH_DATA (info, p)) \
154 return PRINT_INSN_ARG_MEMORY_ERROR; \
155 floatformat_to_double (& floatformat_m68881_ext, \
156 (char *) p - 12, & val); \
160 /* Need a function to convert from packed to double
161 precision. Actually, it's easier to print a
162 packed number than a double anyway, so maybe
163 there should be a special case to handle this... */
164 #define NEXTPACKED(p, val) \
168 if (!FETCH_DATA (info, p)) \
169 return PRINT_INSN_ARG_MEMORY_ERROR; \
175 /* Maximum length of an instruction. */
180 /* Points to first byte not fetched. */
181 bfd_byte
*max_fetched
;
182 bfd_byte the_buffer
[MAXLEN
];
186 /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
187 to ADDR (exclusive) are valid. Returns 1 for success, 0 on memory
189 #define FETCH_DATA(info, addr) \
190 ((addr) <= ((struct private *) (info->private_data))->max_fetched \
191 ? 1 : fetch_data ((info), (addr)))
194 fetch_data (struct disassemble_info
*info
, bfd_byte
*addr
)
197 struct private *priv
= (struct private *)info
->private_data
;
198 bfd_vma start
= priv
->insn_start
+ (priv
->max_fetched
- priv
->the_buffer
);
200 status
= (*info
->read_memory_func
) (start
,
202 addr
- priv
->max_fetched
,
206 (*info
->memory_error_func
) (status
, start
, info
);
210 priv
->max_fetched
= addr
;
214 /* This function is used to print to the bit-bucket. */
216 dummy_printer (FILE *file ATTRIBUTE_UNUSED
,
217 const char *format ATTRIBUTE_UNUSED
,
224 dummy_print_address (bfd_vma vma ATTRIBUTE_UNUSED
,
225 struct disassemble_info
*info ATTRIBUTE_UNUSED
)
229 /* Fetch BITS bits from a position in the instruction specified by CODE.
230 CODE is a "place to put an argument", or 'x' for a destination
231 that is a general address (mode and register).
232 BUFFER contains the instruction.
233 Returns -1 on failure. */
236 fetch_arg (unsigned char *buffer
,
239 disassemble_info
*info
)
245 case '/': /* MAC/EMAC mask bit. */
246 val
= buffer
[3] >> 5;
249 case 'G': /* EMAC ACC load. */
250 val
= ((buffer
[3] >> 3) & 0x2) | ((~buffer
[1] >> 7) & 0x1);
253 case 'H': /* EMAC ACC !load. */
254 val
= ((buffer
[3] >> 3) & 0x2) | ((buffer
[1] >> 7) & 0x1);
257 case ']': /* EMAC ACCEXT bit. */
258 val
= buffer
[0] >> 2;
261 case 'I': /* MAC/EMAC scale factor. */
262 val
= buffer
[2] >> 1;
265 case 'F': /* EMAC ACCx. */
266 val
= buffer
[0] >> 1;
277 case 'd': /* Destination, for register or quick. */
278 val
= (buffer
[0] << 8) + buffer
[1];
282 case 'x': /* Destination, for general arg. */
283 val
= (buffer
[0] << 8) + buffer
[1];
288 if (! FETCH_DATA (info
, buffer
+ 3))
290 val
= (buffer
[3] >> 4);
294 if (! FETCH_DATA (info
, buffer
+ 3))
300 if (! FETCH_DATA (info
, buffer
+ 3))
302 val
= (buffer
[2] << 8) + buffer
[3];
307 if (! FETCH_DATA (info
, buffer
+ 3))
309 val
= (buffer
[2] << 8) + buffer
[3];
315 if (! FETCH_DATA (info
, buffer
+ 3))
317 val
= (buffer
[2] << 8) + buffer
[3];
321 if (! FETCH_DATA (info
, buffer
+ 5))
323 val
= (buffer
[4] << 8) + buffer
[5];
328 if (! FETCH_DATA (info
, buffer
+ 5))
330 val
= (buffer
[4] << 8) + buffer
[5];
335 if (! FETCH_DATA (info
, buffer
+ 5))
337 val
= (buffer
[4] << 8) + buffer
[5];
341 if (! FETCH_DATA (info
, buffer
+ 3))
343 val
= (buffer
[2] << 8) + buffer
[3];
348 if (! FETCH_DATA (info
, buffer
+ 3))
350 val
= (buffer
[2] << 8) + buffer
[3];
355 if (! FETCH_DATA (info
, buffer
+ 3))
357 val
= (buffer
[2] << 8) + buffer
[3];
362 val
= (buffer
[1] >> 6);
366 if (! FETCH_DATA (info
, buffer
+ 3))
368 val
= (buffer
[2] >> 1);
372 val
= (buffer
[1] & 0x40 ? 0x8 : 0)
373 | ((buffer
[0] >> 1) & 0x7)
374 | (buffer
[3] & 0x80 ? 0x10 : 0);
378 val
= (buffer
[1] & 0x40 ? 0x8 : 0) | ((buffer
[0] >> 1) & 0x7);
382 val
= (buffer
[2] >> 4) | (buffer
[3] & 0x80 ? 0x10 : 0);
386 val
= (buffer
[1] & 0xf) | (buffer
[3] & 0x40 ? 0x10 : 0);
390 val
= (buffer
[3] & 0xf) | (buffer
[3] & 0x40 ? 0x10 : 0);
394 val
= buffer
[2] >> 2;
401 /* bits is never too big. */
402 return val
& ((1 << bits
) - 1);
405 /* Check if an EA is valid for a particular code. This is required
406 for the EMAC instructions since the type of source address determines
407 if it is a EMAC-load instruciton if the EA is mode 2-5, otherwise it
408 is a non-load EMAC instruction and the bits mean register Ry.
409 A similar case exists for the movem instructions where the register
410 mask is interpreted differently for different EAs. */
413 m68k_valid_ea (char code
, int val
)
416 #define M(n0,n1,n2,n3,n4,n5,n6,n70,n71,n72,n73,n74) \
417 (n0 | n1 << 1 | n2 << 2 | n3 << 3 | n4 << 4 | n5 << 5 | n6 << 6 \
418 | n70 << 7 | n71 << 8 | n72 << 9 | n73 << 10 | n74 << 11)
423 mask
= M (1,1,1,1,1,1,1,1,1,1,1,1);
426 mask
= M (0,0,1,1,1,1,1,1,1,0,0,0);
429 mask
= M (1,1,1,1,1,1,1,1,1,0,0,0);
432 mask
= M (1,0,1,1,1,1,1,1,1,1,1,1);
435 mask
= M (1,0,1,1,1,1,1,1,1,1,1,0);
438 mask
= M (0,0,1,0,0,1,1,1,1,1,1,0);
441 mask
= M (0,0,1,0,0,1,1,1,1,0,0,0);
444 mask
= M (1,0,1,1,1,1,1,1,1,0,0,0);
447 mask
= M (1,0,1,0,0,1,1,1,1,0,0,0);
450 mask
= M (1,0,1,0,0,1,1,1,1,1,1,0);
453 mask
= M (0,0,1,0,0,1,1,1,1,1,1,0);
456 mask
= M (0,0,1,0,1,1,1,1,1,0,0,0);
459 mask
= M (0,0,1,1,0,1,1,1,1,1,1,0);
462 mask
= M (1,1,1,1,1,0,0,0,0,0,0,0);
465 mask
= M (0,0,0,0,0,1,0,0,0,1,0,0);
468 mask
= M (0,0,0,0,0,0,1,1,1,0,1,1);
471 mask
= M (1,1,1,1,1,1,0,0,0,0,0,0);
474 mask
= M (1,0,1,1,1,1,0,0,0,0,0,0);
477 mask
= M (1,0,1,1,1,1,0,1,1,0,0,0);
480 mask
= M (1,0,1,1,1,1,0,0,0,1,0,0);
483 mask
= M (0,0,1,1,1,1,0,0,0,1,0,0);
486 mask
= M (0,0,1,0,0,1,0,0,0,0,0,0);
489 mask
= M (0,0,1,0,0,1,0,0,0,1,0,0);
492 mask
= M (0,0,1,1,1,1,0,0,0,0,0,0);
499 mode
= (val
>> 3) & 7;
502 return (mask
& (1 << mode
)) != 0;
505 /* Print a base register REGNO and displacement DISP, on INFO->STREAM.
506 REGNO = -1 for pc, -2 for none (suppressed). */
509 print_base (int regno
, bfd_vma disp
, disassemble_info
*info
)
513 (*info
->fprintf_func
) (info
->stream
, "%%pc@(");
514 (*info
->print_address_func
) (disp
, info
);
521 (*info
->fprintf_func
) (info
->stream
, "@(");
522 else if (regno
== -3)
523 (*info
->fprintf_func
) (info
->stream
, "%%zpc@(");
525 (*info
->fprintf_func
) (info
->stream
, "%s@(", reg_names
[regno
]);
527 sprintf_vma (buf
, disp
);
528 (*info
->fprintf_func
) (info
->stream
, "%s", buf
);
532 /* Print an indexed argument. The base register is BASEREG (-1 for pc).
533 P points to extension word, in buffer.
534 ADDR is the nominal core address of that extension word.
535 Returns NULL upon error. */
537 static unsigned char *
538 print_indexed (int basereg
,
541 disassemble_info
*info
)
544 static char *const scales
[] = { "", ":2", ":4", ":8" };
550 NEXTWORD (p
, word
, NULL
);
552 /* Generate the text for the index register.
553 Where this will be output is not yet determined. */
554 sprintf (buf
, "%s:%c%s",
555 reg_names
[(word
>> 12) & 0xf],
556 (word
& 0x800) ? 'l' : 'w',
557 scales
[(word
>> 9) & 3]);
559 /* Handle the 68000 style of indexing. */
561 if ((word
& 0x100) == 0)
563 base_disp
= word
& 0xff;
564 if ((base_disp
& 0x80) != 0)
568 print_base (basereg
, base_disp
, info
);
569 (*info
->fprintf_func
) (info
->stream
, ",%s)", buf
);
573 /* Handle the generalized kind. */
574 /* First, compute the displacement to add to the base register. */
585 switch ((word
>> 4) & 3)
588 NEXTWORD (p
, base_disp
, NULL
);
591 NEXTLONG (p
, base_disp
, NULL
);
596 /* Handle single-level case (not indirect). */
599 print_base (basereg
, base_disp
, info
);
601 (*info
->fprintf_func
) (info
->stream
, ",%s", buf
);
602 (*info
->fprintf_func
) (info
->stream
, ")");
606 /* Two level. Compute displacement to add after indirection. */
611 NEXTWORD (p
, outer_disp
, NULL
);
614 NEXTLONG (p
, outer_disp
, NULL
);
617 print_base (basereg
, base_disp
, info
);
618 if ((word
& 4) == 0 && buf
[0] != '\0')
620 (*info
->fprintf_func
) (info
->stream
, ",%s", buf
);
623 sprintf_vma (vmabuf
, outer_disp
);
624 (*info
->fprintf_func
) (info
->stream
, ")@(%s", vmabuf
);
626 (*info
->fprintf_func
) (info
->stream
, ",%s", buf
);
627 (*info
->fprintf_func
) (info
->stream
, ")");
632 #define FETCH_ARG(size, val) \
635 val = fetch_arg (buffer, place, size, info); \
637 return PRINT_INSN_ARG_MEMORY_ERROR; \
641 /* Returns number of bytes "eaten" by the operand, or
642 return enum print_insn_arg_error. ADDR is the pc for this arg to be
646 print_insn_arg (const char *d
,
647 unsigned char *buffer
,
650 disassemble_info
*info
)
654 unsigned char *p
= p0
;
665 case 'c': /* Cache identifier. */
667 static char *const cacheFieldName
[] = { "nc", "dc", "ic", "bc" };
669 (*info
->fprintf_func
) (info
->stream
, "%s", cacheFieldName
[val
]);
673 case 'a': /* Address register indirect only. Cf. case '+'. */
676 (*info
->fprintf_func
) (info
->stream
, "%s@", reg_names
[val
+ 8]);
680 case '_': /* 32-bit absolute address for move16. */
683 (*info
->print_address_func
) (uval
, info
);
688 (*info
->fprintf_func
) (info
->stream
, "%%ccr");
692 (*info
->fprintf_func
) (info
->stream
, "%%sr");
696 (*info
->fprintf_func
) (info
->stream
, "%%usp");
700 (*info
->fprintf_func
) (info
->stream
, "%%acc");
704 (*info
->fprintf_func
) (info
->stream
, "%%macsr");
708 (*info
->fprintf_func
) (info
->stream
, "%%mask");
713 /* FIXME: There's a problem here, different m68k processors call the
714 same address different names. The tables below try to get it right
715 using info->mach, but only for v4e. */
716 struct regname
{ char * name
; int value
; };
717 static const struct regname names
[] =
719 {"%sfc", 0x000}, {"%dfc", 0x001}, {"%cacr", 0x002},
720 {"%tc", 0x003}, {"%itt0",0x004}, {"%itt1", 0x005},
721 {"%dtt0",0x006}, {"%dtt1",0x007}, {"%buscr",0x008},
722 {"%rgpiobar", 0x009}, {"%acr4",0x00c},
723 {"%acr5",0x00d}, {"%acr6",0x00e}, {"%acr7", 0x00f},
724 {"%usp", 0x800}, {"%vbr", 0x801}, {"%caar", 0x802},
725 {"%msp", 0x803}, {"%isp", 0x804},
727 /* Reg c04 is sometimes called flashbar or rambar.
728 Reg c05 is also sometimes called rambar. */
729 {"%rambar0", 0xc04}, {"%rambar1", 0xc05},
731 /* reg c0e is sometimes called mbar2 or secmbar.
732 reg c0f is sometimes called mbar. */
733 {"%mbar0", 0xc0e}, {"%mbar1", 0xc0f},
735 /* Should we be calling this psr like we do in case 'Y'? */
738 {"%urp", 0x806}, {"%srp", 0x807}, {"%pcr", 0x808},
740 /* Fido added these. */
741 {"%cac", 0xffe}, {"%mbo", 0xfff}
743 /* Alternate names for v4e (MCF5407/5445x/MCF547x/MCF548x), at least. */
744 static const struct regname names_v4e
[] =
746 {"%asid",0x003}, {"%acr0",0x004}, {"%acr1",0x005},
747 {"%acr2",0x006}, {"%acr3",0x007}, {"%mmubar",0x008},
749 unsigned int arch_mask
;
751 arch_mask
= bfd_m68k_mach_to_features (info
->mach
);
753 if (arch_mask
& (mcfisa_b
| mcfisa_c
))
755 for (regno
= ARRAY_SIZE (names_v4e
); --regno
>= 0;)
756 if (names_v4e
[regno
].value
== val
)
758 (*info
->fprintf_func
) (info
->stream
, "%s", names_v4e
[regno
].name
);
764 for (regno
= ARRAY_SIZE (names
) - 1; regno
>= 0; regno
--)
765 if (names
[regno
].value
== val
)
767 (*info
->fprintf_func
) (info
->stream
, "%s", names
[regno
].name
);
771 (*info
->fprintf_func
) (info
->stream
, "0x%x", val
);
777 /* 0 means 8, except for the bkpt instruction... */
778 if (val
== 0 && d
[1] != 's')
780 (*info
->fprintf_func
) (info
->stream
, "#%d", val
);
788 (*info
->fprintf_func
) (info
->stream
, "#%d", val
);
793 (*info
->fprintf_func
) (info
->stream
, "#%d", val
+1);
798 (*info
->fprintf_func
) (info
->stream
, "#%d", val
);
804 static char *const scalefactor_name
[] = { "<<", ">>" };
807 (*info
->fprintf_func
) (info
->stream
, "%s", scalefactor_name
[val
]);
814 (*info
->fprintf_func
) (info
->stream
, "#%d", val
);
820 (*info
->fprintf_func
) (info
->stream
, "#%d", val
);
825 (*info
->fprintf_func
) (info
->stream
, "%s", reg_names
[val
]);
830 (*info
->fprintf_func
) (info
->stream
, "%s", reg_names
[val
+ 010]);
835 (*info
->fprintf_func
) (info
->stream
, "%s", reg_names
[val
]);
839 FETCH_ARG (4, regno
);
841 (*info
->fprintf_func
) (info
->stream
, "%s@", reg_names
[regno
]);
843 (*info
->fprintf_func
) (info
->stream
, "@(%s)", reg_names
[regno
]);
848 (*info
->fprintf_func
) (info
->stream
, "%%fp%d", val
);
854 (*info
->fprintf_func
) (info
->stream
, "%s", reg_names
[val
& 7]);
856 (*info
->fprintf_func
) (info
->stream
, "%d", val
);
861 (*info
->fprintf_func
) (info
->stream
, "%s@+", reg_names
[val
+ 8]);
866 (*info
->fprintf_func
) (info
->stream
, "%s@-", reg_names
[val
+ 8]);
873 (*info
->fprintf_func
) (info
->stream
, "{%s}", reg_names
[val
]);
875 else if (place
== 'C')
878 if (val
> 63) /* This is a signed constant. */
880 (*info
->fprintf_func
) (info
->stream
, "{#%d}", val
);
883 return PRINT_INSN_ARG_INVALID_OPERAND
;
888 p1
= buffer
+ (*d
== '#' ? 2 : 4);
891 else if (place
== 'C')
893 else if (place
== '8')
895 else if (place
== '3')
897 else if (place
== 'b')
899 else if (place
== 'w' || place
== 'W')
900 NEXTWORD (p1
, val
, PRINT_INSN_ARG_MEMORY_ERROR
);
901 else if (place
== 'l')
902 NEXTLONG (p1
, val
, PRINT_INSN_ARG_MEMORY_ERROR
);
904 return PRINT_INSN_ARG_INVALID_OP_TABLE
;
906 (*info
->fprintf_func
) (info
->stream
, "#%d", val
);
912 else if (place
== 'B')
913 disp
= COERCE_SIGNED_CHAR (buffer
[1]);
914 else if (place
== 'w' || place
== 'W')
915 NEXTWORD (p
, disp
, PRINT_INSN_ARG_MEMORY_ERROR
);
916 else if (place
== 'l' || place
== 'L' || place
== 'C')
917 NEXTLONG (p
, disp
, PRINT_INSN_ARG_MEMORY_ERROR
);
918 else if (place
== 'g')
920 NEXTBYTE (buffer
, disp
);
922 NEXTWORD (p
, disp
, PRINT_INSN_ARG_MEMORY_ERROR
);
924 NEXTLONG (p
, disp
, PRINT_INSN_ARG_MEMORY_ERROR
);
926 else if (place
== 'c')
928 if (buffer
[1] & 0x40) /* If bit six is one, long offset. */
929 NEXTLONG (p
, disp
, PRINT_INSN_ARG_MEMORY_ERROR
);
931 NEXTWORD (p
, disp
, PRINT_INSN_ARG_MEMORY_ERROR
);
934 return PRINT_INSN_ARG_INVALID_OP_TABLE
;
936 (*info
->print_address_func
) (addr
+ disp
, info
);
943 NEXTWORD (p
, val
, PRINT_INSN_ARG_MEMORY_ERROR
);
945 (*info
->fprintf_func
) (info
->stream
, "%s@(%d)", reg_names
[val1
+ 8], val
);
951 (*info
->fprintf_func
) (info
->stream
, "%s", fpcr_names
[val
]);
956 (*info
->fprintf_func
) (info
->stream
, "%%acc%d", val
);
961 (*info
->fprintf_func
) (info
->stream
, "%%accext%s", val
== 0 ? "01" : "23");
967 (*info
->fprintf_func
) (info
->stream
, "<<");
969 (*info
->fprintf_func
) (info
->stream
, ">>");
971 return PRINT_INSN_ARG_INVALID_OPERAND
;
975 /* Get coprocessor ID... */
976 val
= fetch_arg (buffer
, 'd', 3, info
);
978 return PRINT_INSN_ARG_MEMORY_ERROR
;
979 if (val
!= 1) /* Unusual coprocessor ID? */
980 (*info
->fprintf_func
) (info
->stream
, "(cpid=%d) ", val
);
1009 val
= fetch_arg (buffer
, 'x', 6, info
);
1011 return PRINT_INSN_ARG_MEMORY_ERROR
;
1012 val
= ((val
& 7) << 3) + ((val
>> 3) & 7);
1016 val
= fetch_arg (buffer
, 's', 6, info
);
1018 return PRINT_INSN_ARG_MEMORY_ERROR
;
1021 /* If the <ea> is invalid for *d, then reject this match. */
1022 if (!m68k_valid_ea (*d
, val
))
1023 return PRINT_INSN_ARG_INVALID_OPERAND
;
1025 /* Get register number assuming address register. */
1026 regno
= (val
& 7) + 8;
1027 regname
= reg_names
[regno
];
1031 (*info
->fprintf_func
) (info
->stream
, "%s", reg_names
[val
]);
1035 (*info
->fprintf_func
) (info
->stream
, "%s", regname
);
1039 (*info
->fprintf_func
) (info
->stream
, "%s@", regname
);
1043 (*info
->fprintf_func
) (info
->stream
, "%s@+", regname
);
1047 (*info
->fprintf_func
) (info
->stream
, "%s@-", regname
);
1051 NEXTWORD (p
, val
, PRINT_INSN_ARG_MEMORY_ERROR
);
1052 (*info
->fprintf_func
) (info
->stream
, "%s@(%d)", regname
, val
);
1056 p
= print_indexed (regno
, p
, addr
, info
);
1058 return PRINT_INSN_ARG_MEMORY_ERROR
;
1065 NEXTWORD (p
, val
, PRINT_INSN_ARG_MEMORY_ERROR
);
1066 (*info
->print_address_func
) (val
, info
);
1070 NEXTULONG (p
, uval
);
1071 (*info
->print_address_func
) (uval
, info
);
1075 NEXTWORD (p
, val
, PRINT_INSN_ARG_MEMORY_ERROR
);
1076 (*info
->fprintf_func
) (info
->stream
, "%%pc@(");
1077 (*info
->print_address_func
) (addr
+ val
, info
);
1078 (*info
->fprintf_func
) (info
->stream
, ")");
1082 p
= print_indexed (-1, p
, addr
, info
);
1084 return PRINT_INSN_ARG_MEMORY_ERROR
;
1088 flt_p
= 1; /* Assume it's a float... */
1097 NEXTWORD (p
, val
, PRINT_INSN_ARG_MEMORY_ERROR
);
1102 NEXTLONG (p
, val
, PRINT_INSN_ARG_MEMORY_ERROR
);
1107 NEXTSINGLE (flval
, p
);
1111 NEXTDOUBLE (flval
, p
);
1115 NEXTEXTEND (flval
, p
);
1119 NEXTPACKED (p
, flval
);
1123 return PRINT_INSN_ARG_INVALID_OPERAND
;
1125 if (flt_p
) /* Print a float? */
1126 (*info
->fprintf_func
) (info
->stream
, "#0e%g", flval
);
1128 (*info
->fprintf_func
) (info
->stream
, "#%d", val
);
1132 return PRINT_INSN_ARG_INVALID_OPERAND
;
1136 /* If place is '/', then this is the case of the mask bit for
1137 mac/emac loads. Now that the arg has been printed, grab the
1138 mask bit and if set, add a '&' to the arg. */
1143 info
->fprintf_func (info
->stream
, "&");
1153 NEXTWORD (p1
, val
, PRINT_INSN_ARG_MEMORY_ERROR
);
1154 /* Move the pointer ahead if this point is farther ahead
1156 p
= p1
> p
? p1
: p
;
1159 (*info
->fprintf_func
) (info
->stream
, "#0");
1166 for (regno
= 0; regno
< 16; ++regno
)
1167 if (val
& (0x8000 >> regno
))
1168 newval
|= 1 << regno
;
1173 for (regno
= 0; regno
< 16; ++regno
)
1174 if (val
& (1 << regno
))
1179 (*info
->fprintf_func
) (info
->stream
, "/");
1181 (*info
->fprintf_func
) (info
->stream
, "%s", reg_names
[regno
]);
1182 first_regno
= regno
;
1183 while (val
& (1 << (regno
+ 1)))
1185 if (regno
> first_regno
)
1186 (*info
->fprintf_func
) (info
->stream
, "-%s",
1190 else if (place
== '3')
1192 /* `fmovem' insn. */
1198 (*info
->fprintf_func
) (info
->stream
, "#0");
1205 for (regno
= 0; regno
< 8; ++regno
)
1206 if (val
& (0x80 >> regno
))
1207 newval
|= 1 << regno
;
1212 for (regno
= 0; regno
< 8; ++regno
)
1213 if (val
& (1 << regno
))
1217 (*info
->fprintf_func
) (info
->stream
, "/");
1219 (*info
->fprintf_func
) (info
->stream
, "%%fp%d", regno
);
1220 first_regno
= regno
;
1221 while (val
& (1 << (regno
+ 1)))
1223 if (regno
> first_regno
)
1224 (*info
->fprintf_func
) (info
->stream
, "-%%fp%d", regno
);
1227 else if (place
== '8')
1230 /* fmoveml for FP status registers. */
1231 (*info
->fprintf_func
) (info
->stream
, "%s", fpcr_names
[val
]);
1234 return PRINT_INSN_ARG_INVALID_OP_TABLE
;
1253 case 2: name
= "%tt0"; break;
1254 case 3: name
= "%tt1"; break;
1255 case 0x10: name
= "%tc"; break;
1256 case 0x11: name
= "%drp"; break;
1257 case 0x12: name
= "%srp"; break;
1258 case 0x13: name
= "%crp"; break;
1259 case 0x14: name
= "%cal"; break;
1260 case 0x15: name
= "%val"; break;
1261 case 0x16: name
= "%scc"; break;
1262 case 0x17: name
= "%ac"; break;
1263 case 0x18: name
= "%psr"; break;
1264 case 0x19: name
= "%pcsr"; break;
1268 int break_reg
= ((buffer
[3] >> 2) & 7);
1270 (*info
->fprintf_func
)
1271 (info
->stream
, val
== 0x1c ? "%%bad%d" : "%%bac%d",
1276 (*info
->fprintf_func
) (info
->stream
, "<mmu register %d>", val
);
1279 (*info
->fprintf_func
) (info
->stream
, "%s", name
);
1289 (*info
->fprintf_func
) (info
->stream
, "%%dfc");
1291 (*info
->fprintf_func
) (info
->stream
, "%%sfc");
1293 /* xgettext:c-format */
1294 (*info
->fprintf_func
) (info
->stream
, _("<function code %d>"), fc
);
1299 (*info
->fprintf_func
) (info
->stream
, "%%val");
1306 FETCH_ARG (3, level
);
1307 (*info
->fprintf_func
) (info
->stream
, "%d", level
);
1322 (*info
->fprintf_func
) (info
->stream
, "%s%s",
1323 reg_half_names
[reg
],
1324 is_upper
? "u" : "l");
1329 return PRINT_INSN_ARG_INVALID_OP_TABLE
;
1335 /* Try to match the current instruction to best and if so, return the
1336 number of bytes consumed from the instruction stream, else zero.
1337 Return -1 on memory error. */
1340 match_insn_m68k (bfd_vma memaddr
,
1341 disassemble_info
* info
,
1342 const struct m68k_opcode
* best
)
1344 unsigned char *save_p
;
1347 const char *args
= best
->args
;
1349 struct private *priv
= (struct private *) info
->private_data
;
1350 bfd_byte
*buffer
= priv
->the_buffer
;
1351 fprintf_ftype save_printer
= info
->fprintf_func
;
1352 void (* save_print_address
) (bfd_vma
, struct disassemble_info
*)
1353 = info
->print_address_func
;
1358 /* Point at first word of argument data,
1359 and at descriptor for first argument. */
1362 /* Figure out how long the fixed-size portion of the instruction is.
1363 The only place this is stored in the opcode table is
1364 in the arguments--look for arguments which specify fields in the 2nd
1365 or 3rd words of the instruction. */
1366 for (d
= args
; *d
; d
+= 2)
1368 /* I don't think it is necessary to be checking d[0] here;
1369 I suspect all this could be moved to the case statement below. */
1372 if (d
[1] == 'l' && p
- buffer
< 6)
1374 else if (p
- buffer
< 4 && d
[1] != 'C' && d
[1] != '8')
1378 if ((d
[0] == 'L' || d
[0] == 'l') && d
[1] == 'w' && p
- buffer
< 4)
1404 /* pflusha is an exceptions. It takes no arguments but is two words
1405 long. Recognize it by looking at the lower 16 bits of the mask. */
1406 if (p
- buffer
< 4 && (best
->match
& 0xFFFF) != 0)
1409 /* lpstop is another exception. It takes a one word argument but is
1410 three words long. */
1412 && (best
->match
& 0xffff) == 0xffff
1416 /* Copy the one word argument into the usual location for a one
1417 word argument, to simplify printing it. We can get away with
1418 this because we know exactly what the second word is, and we
1419 aren't going to print anything based on it. */
1421 if (!FETCH_DATA (info
, p
))
1423 buffer
[2] = buffer
[4];
1424 buffer
[3] = buffer
[5];
1427 if (!FETCH_DATA (info
, p
))
1431 info
->print_address_func
= dummy_print_address
;
1432 info
->fprintf_func
= (fprintf_ftype
) dummy_printer
;
1434 /* We scan the operands twice. The first time we don't print anything,
1435 but look for errors. */
1436 for (d
= args
; *d
; d
+= 2)
1438 int eaten
= print_insn_arg (d
, buffer
, p
, memaddr
+ (p
- buffer
), info
);
1442 else if (eaten
== PRINT_INSN_ARG_INVALID_OPERAND
1443 || eaten
== PRINT_INSN_ARG_MEMORY_ERROR
)
1445 info
->fprintf_func
= save_printer
;
1446 info
->print_address_func
= save_print_address
;
1447 return eaten
== PRINT_INSN_ARG_MEMORY_ERROR
? -1 : 0;
1451 /* We must restore the print functions before trying to print the
1453 info
->fprintf_func
= save_printer
;
1454 info
->print_address_func
= save_print_address
;
1455 info
->fprintf_func (info
->stream
,
1456 /* xgettext:c-format */
1457 _("<internal error in opcode table: %s %s>\n"),
1458 best
->name
, best
->args
);
1464 info
->fprintf_func
= save_printer
;
1465 info
->print_address_func
= save_print_address
;
1469 info
->fprintf_func (info
->stream
, "%s", best
->name
);
1472 info
->fprintf_func (info
->stream
, " ");
1476 p
+= print_insn_arg (d
, buffer
, p
, memaddr
+ (p
- buffer
), info
);
1479 if (*d
&& *(d
- 2) != 'I' && *d
!= 'k')
1480 info
->fprintf_func (info
->stream
, ",");
1486 /* Try to interpret the instruction at address MEMADDR as one that
1487 can execute on a processor with the features given by ARCH_MASK.
1488 If successful, print the instruction to INFO->STREAM and return
1489 its length in bytes. Return 0 otherwise. Return -1 on memory
1493 m68k_scan_mask (bfd_vma memaddr
, disassemble_info
*info
,
1494 unsigned int arch_mask
)
1498 static const struct m68k_opcode
**opcodes
[16];
1499 static int numopcodes
[16];
1503 struct private *priv
= (struct private *) info
->private_data
;
1504 bfd_byte
*buffer
= priv
->the_buffer
;
1508 /* Speed up the matching by sorting the opcode
1509 table on the upper four bits of the opcode. */
1510 const struct m68k_opcode
**opc_pointer
[16];
1512 /* First count how many opcodes are in each of the sixteen buckets. */
1513 for (i
= 0; i
< m68k_numopcodes
; i
++)
1514 numopcodes
[(m68k_opcodes
[i
].opcode
>> 28) & 15]++;
1516 /* Then create a sorted table of pointers
1517 that point into the unsorted table. */
1518 opc_pointer
[0] = xmalloc (sizeof (struct m68k_opcode
*)
1520 opcodes
[0] = opc_pointer
[0];
1522 for (i
= 1; i
< 16; i
++)
1524 opc_pointer
[i
] = opc_pointer
[i
- 1] + numopcodes
[i
- 1];
1525 opcodes
[i
] = opc_pointer
[i
];
1528 for (i
= 0; i
< m68k_numopcodes
; i
++)
1529 *opc_pointer
[(m68k_opcodes
[i
].opcode
>> 28) & 15]++ = &m68k_opcodes
[i
];
1532 if (!FETCH_DATA (info
, buffer
+ 2))
1534 major_opcode
= (buffer
[0] >> 4) & 15;
1536 for (i
= 0; i
< numopcodes
[major_opcode
]; i
++)
1538 const struct m68k_opcode
*opc
= opcodes
[major_opcode
][i
];
1539 unsigned long opcode
= opc
->opcode
;
1540 unsigned long match
= opc
->match
;
1541 const char *args
= opc
->args
;
1546 if (((0xff & buffer
[0] & (match
>> 24)) == (0xff & (opcode
>> 24)))
1547 && ((0xff & buffer
[1] & (match
>> 16)) == (0xff & (opcode
>> 16)))
1548 /* Only fetch the next two bytes if we need to. */
1549 && (((0xffff & match
) == 0)
1551 (FETCH_DATA (info
, buffer
+ 4)
1552 && ((0xff & buffer
[2] & (match
>> 8)) == (0xff & (opcode
>> 8)))
1553 && ((0xff & buffer
[3] & match
) == (0xff & opcode
)))
1555 && (opc
->arch
& arch_mask
) != 0)
1557 /* Don't use for printout the variants of divul and divsl
1558 that have the same register number in two places.
1559 The more general variants will match instead. */
1560 for (d
= args
; *d
; d
+= 2)
1564 /* Don't use for printout the variants of most floating
1565 point coprocessor instructions which use the same
1566 register number in two places, as above. */
1568 for (d
= args
; *d
; d
+= 2)
1572 /* Don't match fmovel with more than one register;
1573 wait for fmoveml. */
1576 for (d
= args
; *d
; d
+= 2)
1578 if (d
[0] == 's' && d
[1] == '8')
1580 val
= fetch_arg (buffer
, d
[1], 3, info
);
1583 if ((val
& (val
- 1)) != 0)
1589 /* Don't match FPU insns with non-default coprocessor ID. */
1592 for (d
= args
; *d
; d
+= 2)
1596 val
= fetch_arg (buffer
, 'd', 3, info
);
1604 if ((val
= match_insn_m68k (memaddr
, info
, opc
)))
1611 /* Print the m68k instruction at address MEMADDR in debugged memory,
1612 on INFO->STREAM. Returns length of the instruction, in bytes. */
1615 print_insn_m68k (bfd_vma memaddr
, disassemble_info
*info
)
1617 unsigned int arch_mask
;
1618 struct private priv
;
1621 bfd_byte
*buffer
= priv
.the_buffer
;
1623 info
->private_data
= & priv
;
1624 /* Tell objdump to use two bytes per chunk
1625 and six bytes per line for displaying raw data. */
1626 info
->bytes_per_chunk
= 2;
1627 info
->bytes_per_line
= 6;
1628 info
->display_endian
= BFD_ENDIAN_BIG
;
1629 priv
.max_fetched
= priv
.the_buffer
;
1630 priv
.insn_start
= memaddr
;
1632 arch_mask
= bfd_m68k_mach_to_features (info
->mach
);
1635 /* First try printing an m680x0 instruction. Try printing a Coldfire
1636 one if that fails. */
1637 val
= m68k_scan_mask (memaddr
, info
, m68k_mask
);
1639 val
= m68k_scan_mask (memaddr
, info
, mcf_mask
);
1643 val
= m68k_scan_mask (memaddr
, info
, arch_mask
);
1647 /* Handle undefined instructions. */
1648 info
->fprintf_func (info
->stream
, ".short 0x%04x", (buffer
[0] << 8) + buffer
[1]);
1650 return val
? val
: 2;