1 /* Print Motorola 68k instructions.
2 Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4 Free Software Foundation, Inc.
6 This file 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 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include "floatformat.h"
23 #include <libiberty.h>
26 #include "opcode/m68k.h"
28 /* Local function prototypes */
31 fetch_data
PARAMS ((struct disassemble_info
*, bfd_byte
*));
34 dummy_print_address
PARAMS ((bfd_vma
, struct disassemble_info
*));
37 fetch_arg
PARAMS ((unsigned char *, int, int, disassemble_info
*));
40 print_base
PARAMS ((int, bfd_vma
, disassemble_info
*));
42 static unsigned char *
43 print_indexed
PARAMS ((int, unsigned char *, bfd_vma
, disassemble_info
*));
46 print_insn_arg
PARAMS ((const char *, unsigned char *, unsigned char *,
47 bfd_vma
, disassemble_info
*));
49 CONST
char * CONST fpcr_names
[] =
51 "", "%fpiar", "%fpsr", "%fpiar/%fpsr", "%fpcr",
52 "%fpiar/%fpcr", "%fpsr/%fpcr", "%fpiar/%fpsr/%fpcr"
55 static char *const reg_names
[] =
57 "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6", "%d7",
58 "%a0", "%a1", "%a2", "%a3", "%a4", "%a5", "%fp", "%sp",
62 /* Sign-extend an (unsigned char). */
64 #define COERCE_SIGNED_CHAR(ch) ((signed char)(ch))
66 #define COERCE_SIGNED_CHAR(ch) ((int)(((ch) ^ 0x80) & 0xFF) - 128)
69 /* Get a 1 byte signed integer. */
70 #define NEXTBYTE(p) (p += 2, FETCH_DATA (info, p), COERCE_SIGNED_CHAR(p[-1]))
72 /* Get a 2 byte signed integer. */
73 #define COERCE16(x) ((int) (((x) ^ 0x8000) - 0x8000))
75 (p += 2, FETCH_DATA (info, p), \
76 COERCE16 ((p[-2] << 8) + p[-1]))
78 /* Get a 4 byte signed integer. */
79 #define COERCE32(x) ((bfd_signed_vma) ((x) ^ 0x80000000) - 0x80000000)
81 (p += 4, FETCH_DATA (info, p), \
82 (COERCE32 ((((((p[-4] << 8) + p[-3]) << 8) + p[-2]) << 8) + p[-1])))
84 /* Get a 4 byte unsigned integer. */
85 #define NEXTULONG(p) \
86 (p += 4, FETCH_DATA (info, p), \
87 (unsigned int) ((((((p[-4] << 8) + p[-3]) << 8) + p[-2]) << 8) + p[-1]))
89 /* Get a single precision float. */
90 #define NEXTSINGLE(val, p) \
91 (p += 4, FETCH_DATA (info, p), \
92 floatformat_to_double (&floatformat_ieee_single_big, (char *) p - 4, &val))
94 /* Get a double precision float. */
95 #define NEXTDOUBLE(val, p) \
96 (p += 8, FETCH_DATA (info, p), \
97 floatformat_to_double (&floatformat_ieee_double_big, (char *) p - 8, &val))
99 /* Get an extended precision float. */
100 #define NEXTEXTEND(val, p) \
101 (p += 12, FETCH_DATA (info, p), \
102 floatformat_to_double (&floatformat_m68881_ext, (char *) p - 12, &val))
104 /* Need a function to convert from packed to double
105 precision. Actually, it's easier to print a
106 packed number than a double anyway, so maybe
107 there should be a special case to handle this... */
108 #define NEXTPACKED(p) \
109 (p += 12, FETCH_DATA (info, p), 0.0)
112 /* Maximum length of an instruction. */
119 /* Points to first byte not fetched. */
120 bfd_byte
*max_fetched
;
121 bfd_byte the_buffer
[MAXLEN
];
126 /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
127 to ADDR (exclusive) are valid. Returns 1 for success, longjmps
129 #define FETCH_DATA(info, addr) \
130 ((addr) <= ((struct private *)(info->private_data))->max_fetched \
131 ? 1 : fetch_data ((info), (addr)))
134 fetch_data (info
, addr
)
135 struct disassemble_info
*info
;
139 struct private *priv
= (struct private *)info
->private_data
;
140 bfd_vma start
= priv
->insn_start
+ (priv
->max_fetched
- priv
->the_buffer
);
142 status
= (*info
->read_memory_func
) (start
,
144 addr
- priv
->max_fetched
,
148 (*info
->memory_error_func
) (status
, start
, info
);
149 longjmp (priv
->bailout
, 1);
152 priv
->max_fetched
= addr
;
156 /* This function is used to print to the bit-bucket. */
159 dummy_printer (FILE * file ATTRIBUTE_UNUSED
,
160 const char * format ATTRIBUTE_UNUSED
, ...)
162 dummy_printer (file
) FILE *file ATTRIBUTE_UNUSED
;
167 dummy_print_address (vma
, info
)
168 bfd_vma vma ATTRIBUTE_UNUSED
;
169 struct disassemble_info
*info ATTRIBUTE_UNUSED
;
173 /* Print the m68k instruction at address MEMADDR in debugged memory,
174 on INFO->STREAM. Returns length of the instruction, in bytes. */
177 print_insn_m68k (memaddr
, info
)
179 disassemble_info
*info
;
182 register unsigned char *p
;
183 unsigned char *save_p
;
184 register const char *d
;
185 register unsigned long bestmask
;
186 const struct m68k_opcode
*best
;
187 unsigned int arch_mask
;
189 bfd_byte
*buffer
= priv
.the_buffer
;
190 fprintf_ftype save_printer
= info
->fprintf_func
;
191 void (*save_print_address
) PARAMS((bfd_vma
, struct disassemble_info
*))
192 = info
->print_address_func
;
194 static int numopcodes
[16];
195 static const struct m68k_opcode
**opcodes
[16];
199 /* Speed up the matching by sorting the opcode table on the upper
200 four bits of the opcode. */
201 const struct m68k_opcode
**opc_pointer
[16];
203 /* First count how many opcodes are in each of the sixteen buckets. */
204 for (i
= 0; i
< m68k_numopcodes
; i
++)
205 numopcodes
[(m68k_opcodes
[i
].opcode
>> 28) & 15]++;
207 /* Then create a sorted table of pointers that point into the
209 opc_pointer
[0] = ((const struct m68k_opcode
**)
210 xmalloc (sizeof (struct m68k_opcode
*)
212 opcodes
[0] = opc_pointer
[0];
213 for (i
= 1; i
< 16; i
++)
215 opc_pointer
[i
] = opc_pointer
[i
- 1] + numopcodes
[i
- 1];
216 opcodes
[i
] = opc_pointer
[i
];
219 for (i
= 0; i
< m68k_numopcodes
; i
++)
220 *opc_pointer
[(m68k_opcodes
[i
].opcode
>> 28) & 15]++ = &m68k_opcodes
[i
];
224 info
->private_data
= (PTR
) &priv
;
225 /* Tell objdump to use two bytes per chunk and six bytes per line for
226 displaying raw data. */
227 info
->bytes_per_chunk
= 2;
228 info
->bytes_per_line
= 6;
229 info
->display_endian
= BFD_ENDIAN_BIG
;
230 priv
.max_fetched
= priv
.the_buffer
;
231 priv
.insn_start
= memaddr
;
232 if (setjmp (priv
.bailout
) != 0)
241 arch_mask
= (unsigned int) -1;
243 case bfd_mach_m68000
:
246 case bfd_mach_m68008
:
249 case bfd_mach_m68010
:
252 case bfd_mach_m68020
:
255 case bfd_mach_m68030
:
258 case bfd_mach_m68040
:
261 case bfd_mach_m68060
:
264 case bfd_mach_mcf5200
:
267 case bfd_mach_mcf5206e
:
268 arch_mask
= mcf5206e
;
270 case bfd_mach_mcf5307
:
273 case bfd_mach_mcf5407
:
278 arch_mask
|= m68881
| m68851
;
281 FETCH_DATA (info
, buffer
+ 2);
282 major_opcode
= (buffer
[0] >> 4) & 15;
283 for (i
= 0; i
< numopcodes
[major_opcode
]; i
++)
285 const struct m68k_opcode
*opc
= opcodes
[major_opcode
][i
];
286 unsigned long opcode
= opc
->opcode
;
287 unsigned long match
= opc
->match
;
289 if (((0xff & buffer
[0] & (match
>> 24)) == (0xff & (opcode
>> 24)))
290 && ((0xff & buffer
[1] & (match
>> 16)) == (0xff & (opcode
>> 16)))
291 /* Only fetch the next two bytes if we need to. */
292 && (((0xffff & match
) == 0)
294 (FETCH_DATA (info
, buffer
+ 4)
295 && ((0xff & buffer
[2] & (match
>> 8)) == (0xff & (opcode
>> 8)))
296 && ((0xff & buffer
[3] & match
) == (0xff & opcode
)))
298 && (opc
->arch
& arch_mask
) != 0)
300 /* Don't use for printout the variants of divul and divsl
301 that have the same register number in two places.
302 The more general variants will match instead. */
303 for (d
= opc
->args
; *d
; d
+= 2)
307 /* Don't use for printout the variants of most floating
308 point coprocessor instructions which use the same
309 register number in two places, as above. */
311 for (d
= opc
->args
; *d
; d
+= 2)
315 /* Don't match fmovel with more than one register; wait for
319 for (d
= opc
->args
; *d
; d
+= 2)
321 if (d
[0] == 's' && d
[1] == '8')
325 val
= fetch_arg (buffer
, d
[1], 3, info
);
326 if ((val
& (val
- 1)) != 0)
332 if (*d
== '\0' && match
> bestmask
)
343 /* Point at first word of argument data,
344 and at descriptor for first argument. */
347 /* Figure out how long the fixed-size portion of the instruction is.
348 The only place this is stored in the opcode table is
349 in the arguments--look for arguments which specify fields in the 2nd
350 or 3rd words of the instruction. */
351 for (d
= best
->args
; *d
; d
+= 2)
353 /* I don't think it is necessary to be checking d[0] here; I suspect
354 all this could be moved to the case statement below. */
357 if (d
[1] == 'l' && p
- buffer
< 6)
359 else if (p
- buffer
< 4 && d
[1] != 'C' && d
[1] != '8' )
362 if ((d
[0] == 'L' || d
[0] == 'l') && d
[1] == 'w' && p
- buffer
< 4)
387 /* pflusha is an exceptions. It takes no arguments but is two words
388 long. Recognize it by looking at the lower 16 bits of the mask. */
389 if (p
- buffer
< 4 && (best
->match
& 0xFFFF) != 0)
392 /* lpstop is another exception. It takes a one word argument but is
395 && (best
->match
& 0xffff) == 0xffff
396 && best
->args
[0] == '#'
397 && best
->args
[1] == 'w')
399 /* Copy the one word argument into the usual location for a one
400 word argument, to simplify printing it. We can get away with
401 this because we know exactly what the second word is, and we
402 aren't going to print anything based on it. */
404 FETCH_DATA (info
, p
);
405 buffer
[2] = buffer
[4];
406 buffer
[3] = buffer
[5];
409 FETCH_DATA (info
, p
);
413 /* We can the operands twice. The first time we don't print anything,
414 but look for errors. */
417 info
->print_address_func
= dummy_print_address
;
418 info
->fprintf_func
= (fprintf_ftype
)dummy_printer
;
421 int eaten
= print_insn_arg (d
, buffer
, p
, memaddr
+ (p
- buffer
), info
);
424 else if (eaten
== -1)
428 (*info
->fprintf_func
)(info
->stream
,
429 /* xgettext:c-format */
430 _("<internal error in opcode table: %s %s>\n"),
438 info
->fprintf_func
= save_printer
;
439 info
->print_address_func
= save_print_address
;
443 (*info
->fprintf_func
) (info
->stream
, "%s", best
->name
);
446 (*info
->fprintf_func
) (info
->stream
, " ");
450 p
+= print_insn_arg (d
, buffer
, p
, memaddr
+ (p
- buffer
), info
);
452 if (*d
&& *(d
- 2) != 'I' && *d
!= 'k')
453 (*info
->fprintf_func
) (info
->stream
, ",");
458 /* Handle undefined instructions. */
459 info
->fprintf_func
= save_printer
;
460 info
->print_address_func
= save_print_address
;
461 (*info
->fprintf_func
) (info
->stream
, "0%o",
462 (buffer
[0] << 8) + buffer
[1]);
466 /* Returns number of bytes "eaten" by the operand, or
467 return -1 if an invalid operand was found, or -2 if
468 an opcode tabe error was found. */
471 print_insn_arg (d
, buffer
, p0
, addr
, info
)
473 unsigned char *buffer
;
475 bfd_vma addr
; /* PC for this arg to be relative to */
476 disassemble_info
*info
;
478 register int val
= 0;
479 register int place
= d
[1];
480 register unsigned char *p
= p0
;
482 register CONST
char *regname
;
483 register unsigned char *p1
;
491 case 'c': /* cache identifier */
493 static char *const cacheFieldName
[] = { "nc", "dc", "ic", "bc" };
494 val
= fetch_arg (buffer
, place
, 2, info
);
495 (*info
->fprintf_func
) (info
->stream
, cacheFieldName
[val
]);
499 case 'a': /* address register indirect only. Cf. case '+'. */
501 (*info
->fprintf_func
)
504 reg_names
[fetch_arg (buffer
, place
, 3, info
) + 8]);
508 case '_': /* 32-bit absolute address for move16. */
510 uval
= NEXTULONG (p
);
511 (*info
->print_address_func
) (uval
, info
);
516 (*info
->fprintf_func
) (info
->stream
, "%%ccr");
520 (*info
->fprintf_func
) (info
->stream
, "%%sr");
524 (*info
->fprintf_func
) (info
->stream
, "%%usp");
528 (*info
->fprintf_func
) (info
->stream
, "%%acc");
532 (*info
->fprintf_func
) (info
->stream
, "%%macsr");
536 (*info
->fprintf_func
) (info
->stream
, "%%mask");
541 static const struct { char *name
; int value
; } names
[]
542 = {{"%sfc", 0x000}, {"%dfc", 0x001}, {"%cacr", 0x002},
543 {"%tc", 0x003}, {"%itt0",0x004}, {"%itt1", 0x005},
544 {"%dtt0",0x006}, {"%dtt1",0x007}, {"%buscr",0x008},
545 {"%usp", 0x800}, {"%vbr", 0x801}, {"%caar", 0x802},
546 {"%msp", 0x803}, {"%isp", 0x804},
548 /* Should we be calling this psr like we do in case 'Y'? */
551 {"%urp", 0x806}, {"%srp", 0x807}, {"%pcr", 0x808}};
553 val
= fetch_arg (buffer
, place
, 12, info
);
554 for (regno
= sizeof names
/ sizeof names
[0] - 1; regno
>= 0; regno
--)
555 if (names
[regno
].value
== val
)
557 (*info
->fprintf_func
) (info
->stream
, "%s", names
[regno
].name
);
561 (*info
->fprintf_func
) (info
->stream
, "%d", val
);
566 val
= fetch_arg (buffer
, place
, 3, info
);
567 /* 0 means 8, except for the bkpt instruction... */
568 if (val
== 0 && d
[1] != 's')
570 (*info
->fprintf_func
) (info
->stream
, "#%d", val
);
576 static char *const scalefactor_name
[] = { "<<", ">>" };
577 val
= fetch_arg (buffer
, place
, 1, info
);
578 (*info
->fprintf_func
) (info
->stream
, scalefactor_name
[val
]);
582 val
= fetch_arg (buffer
, place
, 8, info
);
585 (*info
->fprintf_func
) (info
->stream
, "#%d", val
);
590 val
= fetch_arg (buffer
, place
, 4, info
);
591 (*info
->fprintf_func
) (info
->stream
, "#%d", val
);
595 (*info
->fprintf_func
) (info
->stream
, "%s",
596 reg_names
[fetch_arg (buffer
, place
, 3, info
)]);
600 (*info
->fprintf_func
)
602 reg_names
[fetch_arg (buffer
, place
, 3, info
) + 010]);
606 (*info
->fprintf_func
)
608 reg_names
[fetch_arg (buffer
, place
, 4, info
)]);
612 regno
= fetch_arg (buffer
, place
, 4, info
);
614 (*info
->fprintf_func
) (info
->stream
, "%s@", reg_names
[regno
]);
616 (*info
->fprintf_func
) (info
->stream
, "@(%s)", reg_names
[regno
]);
620 (*info
->fprintf_func
)
621 (info
->stream
, "%%fp%d",
622 fetch_arg (buffer
, place
, 3, info
));
626 val
= fetch_arg (buffer
, place
, 6, info
);
628 (*info
->fprintf_func
) (info
->stream
, "%s", reg_names
[val
& 7]);
630 (*info
->fprintf_func
) (info
->stream
, "%d", val
);
634 (*info
->fprintf_func
)
635 (info
->stream
, "%s@+",
636 reg_names
[fetch_arg (buffer
, place
, 3, info
) + 8]);
640 (*info
->fprintf_func
)
641 (info
->stream
, "%s@-",
642 reg_names
[fetch_arg (buffer
, place
, 3, info
) + 8]);
647 (*info
->fprintf_func
)
648 (info
->stream
, "{%s}",
649 reg_names
[fetch_arg (buffer
, place
, 3, info
)]);
650 else if (place
== 'C')
652 val
= fetch_arg (buffer
, place
, 7, info
);
653 if ( val
> 63 ) /* This is a signed constant. */
655 (*info
->fprintf_func
) (info
->stream
, "{#%d}", val
);
663 p1
= buffer
+ (*d
== '#' ? 2 : 4);
665 val
= fetch_arg (buffer
, place
, 4, info
);
666 else if (place
== 'C')
667 val
= fetch_arg (buffer
, place
, 7, info
);
668 else if (place
== '8')
669 val
= fetch_arg (buffer
, place
, 3, info
);
670 else if (place
== '3')
671 val
= fetch_arg (buffer
, place
, 8, info
);
672 else if (place
== 'b')
674 else if (place
== 'w' || place
== 'W')
676 else if (place
== 'l')
680 (*info
->fprintf_func
) (info
->stream
, "#%d", val
);
686 else if (place
== 'B')
687 disp
= COERCE_SIGNED_CHAR(buffer
[1]);
688 else if (place
== 'w' || place
== 'W')
690 else if (place
== 'l' || place
== 'L' || place
== 'C')
692 else if (place
== 'g')
694 disp
= NEXTBYTE (buffer
);
700 else if (place
== 'c')
702 if (buffer
[1] & 0x40) /* If bit six is one, long offset */
710 (*info
->print_address_func
) (addr
+ disp
, info
);
715 (*info
->fprintf_func
)
716 (info
->stream
, "%s@(%d)",
717 reg_names
[fetch_arg (buffer
, place
, 3, info
) + 8], val
);
721 (*info
->fprintf_func
) (info
->stream
, "%s",
722 fpcr_names
[fetch_arg (buffer
, place
, 3, info
)]);
726 /* Get coprocessor ID... */
727 val
= fetch_arg (buffer
, 'd', 3, info
);
729 if (val
!= 1) /* Unusual coprocessor ID? */
730 (*info
->fprintf_func
) (info
->stream
, "(cpid=%d) ", val
);
755 val
= fetch_arg (buffer
, 'x', 6, info
);
756 val
= ((val
& 7) << 3) + ((val
>> 3) & 7);
759 val
= fetch_arg (buffer
, 's', 6, info
);
761 /* Get register number assuming address register. */
762 regno
= (val
& 7) + 8;
763 regname
= reg_names
[regno
];
767 (*info
->fprintf_func
) (info
->stream
, "%s", reg_names
[val
]);
771 (*info
->fprintf_func
) (info
->stream
, "%s", regname
);
775 (*info
->fprintf_func
) (info
->stream
, "%s@", regname
);
779 (*info
->fprintf_func
) (info
->stream
, "%s@+", regname
);
783 (*info
->fprintf_func
) (info
->stream
, "%s@-", regname
);
788 (*info
->fprintf_func
) (info
->stream
, "%s@(%d)", regname
, val
);
792 p
= print_indexed (regno
, p
, addr
, info
);
800 (*info
->print_address_func
) (val
, info
);
804 uval
= NEXTULONG (p
);
805 (*info
->print_address_func
) (uval
, info
);
810 (*info
->fprintf_func
) (info
->stream
, "%%pc@(");
811 (*info
->print_address_func
) (addr
+ val
, info
);
812 (*info
->fprintf_func
) (info
->stream
, ")");
816 p
= print_indexed (-1, p
, addr
, info
);
820 flt_p
= 1; /* Assume it's a float... */
839 NEXTSINGLE(flval
, p
);
843 NEXTDOUBLE(flval
, p
);
847 NEXTEXTEND(flval
, p
);
851 flval
= NEXTPACKED(p
);
857 if ( flt_p
) /* Print a float? */
858 (*info
->fprintf_func
) (info
->stream
, "#%g", flval
);
860 (*info
->fprintf_func
) (info
->stream
, "#%d", val
);
876 /* Move the pointer ahead if this point is farther ahead
881 (*info
->fprintf_func
) (info
->stream
, "#0");
886 register int newval
= 0;
887 for (regno
= 0; regno
< 16; ++regno
)
888 if (val
& (0x8000 >> regno
))
889 newval
|= 1 << regno
;
894 for (regno
= 0; regno
< 16; ++regno
)
895 if (val
& (1 << regno
))
899 (*info
->fprintf_func
) (info
->stream
, "/");
901 (*info
->fprintf_func
) (info
->stream
, "%s", reg_names
[regno
]);
903 while (val
& (1 << (regno
+ 1)))
905 if (regno
> first_regno
)
906 (*info
->fprintf_func
) (info
->stream
, "-%s",
910 else if (place
== '3')
914 val
= fetch_arg (buffer
, place
, 8, info
);
917 (*info
->fprintf_func
) (info
->stream
, "#0");
922 register int newval
= 0;
923 for (regno
= 0; regno
< 8; ++regno
)
924 if (val
& (0x80 >> regno
))
925 newval
|= 1 << regno
;
930 for (regno
= 0; regno
< 8; ++regno
)
931 if (val
& (1 << regno
))
935 (*info
->fprintf_func
) (info
->stream
, "/");
937 (*info
->fprintf_func
) (info
->stream
, "%%fp%d", regno
);
939 while (val
& (1 << (regno
+ 1)))
941 if (regno
> first_regno
)
942 (*info
->fprintf_func
) (info
->stream
, "-%%fp%d", regno
);
945 else if (place
== '8')
947 /* fmoveml for FP status registers */
948 (*info
->fprintf_func
) (info
->stream
, "%s",
949 fpcr_names
[fetch_arg (buffer
, place
, 3,
966 int val
= fetch_arg (buffer
, place
, 5, info
);
970 case 2: name
= "%tt0"; break;
971 case 3: name
= "%tt1"; break;
972 case 0x10: name
= "%tc"; break;
973 case 0x11: name
= "%drp"; break;
974 case 0x12: name
= "%srp"; break;
975 case 0x13: name
= "%crp"; break;
976 case 0x14: name
= "%cal"; break;
977 case 0x15: name
= "%val"; break;
978 case 0x16: name
= "%scc"; break;
979 case 0x17: name
= "%ac"; break;
980 case 0x18: name
= "%psr"; break;
981 case 0x19: name
= "%pcsr"; break;
985 int break_reg
= ((buffer
[3] >> 2) & 7);
986 (*info
->fprintf_func
)
987 (info
->stream
, val
== 0x1c ? "%%bad%d" : "%%bac%d",
992 (*info
->fprintf_func
) (info
->stream
, "<mmu register %d>", val
);
995 (*info
->fprintf_func
) (info
->stream
, "%s", name
);
1001 int fc
= fetch_arg (buffer
, place
, 5, info
);
1003 (*info
->fprintf_func
) (info
->stream
, "%%dfc");
1005 (*info
->fprintf_func
) (info
->stream
, "%%sfc");
1007 /* xgettext:c-format */
1008 (*info
->fprintf_func
) (info
->stream
, _("<function code %d>"), fc
);
1013 (*info
->fprintf_func
) (info
->stream
, "%%val");
1018 int level
= fetch_arg (buffer
, place
, 3, info
);
1019 (*info
->fprintf_func
) (info
->stream
, "%d", level
);
1026 int reg
= fetch_arg (buffer
, place
, 5, info
);
1033 (*info
->fprintf_func
) (info
->stream
, "%s%s",
1035 is_upper
? "u" : "l");
1046 /* Fetch BITS bits from a position in the instruction specified by CODE.
1047 CODE is a "place to put an argument", or 'x' for a destination
1048 that is a general address (mode and register).
1049 BUFFER contains the instruction. */
1052 fetch_arg (buffer
, code
, bits
, info
)
1053 unsigned char *buffer
;
1056 disassemble_info
*info
;
1058 register int val
= 0;
1065 case 'd': /* Destination, for register or quick. */
1066 val
= (buffer
[0] << 8) + buffer
[1];
1070 case 'x': /* Destination, for general arg */
1071 val
= (buffer
[0] << 8) + buffer
[1];
1076 FETCH_DATA (info
, buffer
+ 3);
1077 val
= (buffer
[3] >> 4);
1081 FETCH_DATA (info
, buffer
+ 3);
1086 FETCH_DATA (info
, buffer
+ 3);
1087 val
= (buffer
[2] << 8) + buffer
[3];
1092 FETCH_DATA (info
, buffer
+ 3);
1093 val
= (buffer
[2] << 8) + buffer
[3];
1099 FETCH_DATA (info
, buffer
+ 3);
1100 val
= (buffer
[2] << 8) + buffer
[3];
1104 FETCH_DATA (info
, buffer
+ 5);
1105 val
= (buffer
[4] << 8) + buffer
[5];
1110 FETCH_DATA (info
, buffer
+ 5);
1111 val
= (buffer
[4] << 8) + buffer
[5];
1116 FETCH_DATA (info
, buffer
+ 5);
1117 val
= (buffer
[4] << 8) + buffer
[5];
1121 FETCH_DATA (info
, buffer
+ 3);
1122 val
= (buffer
[2] << 8) + buffer
[3];
1127 FETCH_DATA (info
, buffer
+ 3);
1128 val
= (buffer
[2] << 8) + buffer
[3];
1133 FETCH_DATA (info
, buffer
+ 3);
1134 val
= (buffer
[2] << 8) + buffer
[3];
1139 val
= (buffer
[1] >> 6);
1143 val
= (buffer
[1] & 0x40 ? 0x8 : 0)
1144 | ((buffer
[0] >> 1) & 0x7)
1145 | (buffer
[3] & 0x80 ? 0x10 : 0);
1149 val
= (buffer
[1] & 0x40 ? 0x8 : 0) | ((buffer
[0] >> 1) & 0x7);
1153 val
= (buffer
[2] >> 4) | (buffer
[3] & 0x80 ? 0x10 : 0);
1157 val
= buffer
[1] | (buffer
[3] & 0x40 ? 0x10 : 0);
1161 val
= buffer
[3] | (buffer
[3] & 0x40 ? 0x10 : 0);
1165 val
= buffer
[2] >> 2;
1197 /* Print an indexed argument. The base register is BASEREG (-1 for pc).
1198 P points to extension word, in buffer.
1199 ADDR is the nominal core address of that extension word. */
1201 static unsigned char *
1202 print_indexed (basereg
, p
, addr
, info
)
1206 disassemble_info
*info
;
1209 static char *const scales
[] = {"", ":2", ":4", ":8"};
1215 word
= NEXTWORD (p
);
1217 /* Generate the text for the index register.
1218 Where this will be output is not yet determined. */
1219 sprintf (buf
, "%s:%c%s",
1220 reg_names
[(word
>> 12) & 0xf],
1221 (word
& 0x800) ? 'l' : 'w',
1222 scales
[(word
>> 9) & 3]);
1224 /* Handle the 68000 style of indexing. */
1226 if ((word
& 0x100) == 0)
1228 base_disp
= word
& 0xff;
1229 if ((base_disp
& 0x80) != 0)
1233 print_base (basereg
, base_disp
, info
);
1234 (*info
->fprintf_func
) (info
->stream
, ",%s)", buf
);
1238 /* Handle the generalized kind. */
1239 /* First, compute the displacement to add to the base register. */
1251 switch ((word
>> 4) & 3)
1254 base_disp
= NEXTWORD (p
);
1257 base_disp
= NEXTLONG (p
);
1262 /* Handle single-level case (not indirect) */
1264 if ((word
& 7) == 0)
1266 print_base (basereg
, base_disp
, info
);
1268 (*info
->fprintf_func
) (info
->stream
, ",%s", buf
);
1269 (*info
->fprintf_func
) (info
->stream
, ")");
1273 /* Two level. Compute displacement to add after indirection. */
1279 outer_disp
= NEXTWORD (p
);
1282 outer_disp
= NEXTLONG (p
);
1285 print_base (basereg
, base_disp
, info
);
1286 if ((word
& 4) == 0 && buf
[0] != '\0')
1288 (*info
->fprintf_func
) (info
->stream
, ",%s", buf
);
1291 sprintf_vma (vmabuf
, outer_disp
);
1292 (*info
->fprintf_func
) (info
->stream
, ")@(%s", vmabuf
);
1294 (*info
->fprintf_func
) (info
->stream
, ",%s", buf
);
1295 (*info
->fprintf_func
) (info
->stream
, ")");
1300 /* Print a base register REGNO and displacement DISP, on INFO->STREAM.
1301 REGNO = -1 for pc, -2 for none (suppressed). */
1304 print_base (regno
, disp
, info
)
1307 disassemble_info
*info
;
1311 (*info
->fprintf_func
) (info
->stream
, "%%pc@(");
1312 (*info
->print_address_func
) (disp
, info
);
1319 (*info
->fprintf_func
) (info
->stream
, "@(");
1320 else if (regno
== -3)
1321 (*info
->fprintf_func
) (info
->stream
, "%%zpc@(");
1323 (*info
->fprintf_func
) (info
->stream
, "%s@(", reg_names
[regno
]);
1325 sprintf_vma (buf
, disp
);
1326 (*info
->fprintf_func
) (info
->stream
, "%s", buf
);