1 /* Print m68k instructions for objdump
2 Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
5 This file is part of the binutils.
7 The binutils are free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 The binutils are distributed in the hope that they will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with the binutils; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include "opcode/m68k.h"
28 #define fprintf_filtered fprintf
29 #define fputs_filtered fputs
32 /* Sign-extend an (unsigned char). */
34 #define COERCE_SIGNED_CHAR(ch) ((signed char)(ch))
36 #define COERCE_SIGNED_CHAR(ch) ((int)(((ch) ^ 0x80) & 0xFF) - 128)
39 extern void print_address();
41 /* 68k instructions are never longer than this many bytes. */
44 /* Number of elements in the opcode table. */
45 #define NOPCODES (sizeof m68k_opcodes / sizeof m68k_opcodes[0])
47 extern char *reg_names
[];
48 char *fpcr_names
[] = { "", "fpiar", "fpsr", "fpiar/fpsr", "fpcr",
49 "fpiar/fpcr", "fpsr/fpcr", "fpiar/fpsr/fpcr"};
51 char *reg_names
[] = {"d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp", "ps", "pc"};
52 static unsigned char *print_insn_arg ();
53 static unsigned char *print_indexed ();
54 static void print_base ();
55 static int fetch_arg ();
57 #define NEXTBYTE(p) (p += 2, COERCE_SIGNED_CHAR(p[-1]))
60 (p += 2, ((((char *)p)[-2]) << 8) + p[-1])
63 (p += 4, (((((p[-4] << 8) + p[-3]) << 8) + p[-2]) << 8) + p[-1])
65 /* NEXTSINGLE and NEXTDOUBLE handle alignment problems, but not
66 * byte-swapping or other float format differences. FIXME! */
74 #define NEXTSINGLE(val, p) \
75 { int i; union number u;\
76 for (i = 0; i < sizeof(float); i++) u.c[i] = *p++; \
79 #define NEXTDOUBLE(val, p) \
80 { int i; union number u;\
81 for (i = 0; i < sizeof(double); i++) u.c[i] = *p++; \
84 #define NEXTEXTEND(p) \
85 (p += 12, 0.0) /* Need a function to convert from extended to double
88 #define NEXTPACKED(p) \
89 (p += 12, 0.0) /* Need a function to convert from packed to double
90 precision. Actually, it's easier to print a
91 packed number than a double anyway, so maybe
92 there should be a special case to handle this... */
94 /* Print the m68k instruction at address MEMADDR in debugged memory,
95 on STREAM. Returns length of the instruction, in bytes. */
98 print_insn_m68k(addr
, buffer
, stream
)
100 unsigned char *buffer
;
103 register unsigned int i
;
104 register unsigned char *p
;
106 register unsigned int bestmask
;
113 for (i
= 0; i
< NOPCODES
; i
++)
115 register unsigned int opcode
= m68k_opcodes
[i
].opcode
;
116 register unsigned int match
= m68k_opcodes
[i
].match
;
117 if (((0xff & buffer
[0] & (match
>> 24)) == (0xff & (opcode
>> 24)))
118 && ((0xff & buffer
[1] & (match
>> 16)) == (0xff & (opcode
>> 16)))
119 && ((0xff & buffer
[2] & (match
>> 8)) == (0xff & (opcode
>> 8)))
120 && ((0xff & buffer
[3] & match
) == (0xff & opcode
)))
122 /* Don't use for printout the variants of divul and divsl
123 that have the same register number in two places.
124 The more general variants will match instead. */
125 for (d
= m68k_opcodes
[i
].args
; *d
; d
+= 2)
129 /* Don't use for printout the variants of most floating
130 point coprocessor instructions which use the same
131 register number in two places, as above. */
133 for (d
= m68k_opcodes
[i
].args
; *d
; d
+= 2)
137 if (*d
== 0 && match
> bestmask
)
145 /* Handle undefined instructions. */
148 fprintf_filtered (stream
, "0%o", (unsigned) (buffer
[0] << 8) + buffer
[1]);
152 fprintf_filtered (stream
, "%s", m68k_opcodes
[best
].name
);
154 /* Point at first word of argument data,
155 and at descriptor for first argument. */
158 /* Why do this this way? -MelloN */
159 for (d
= m68k_opcodes
[best
].args
; *d
; d
+= 2)
163 if (d
[1] == 'l' && p
- buffer
< 6)
165 else if (p
- buffer
< 4 && d
[1] != 'C' && d
[1] != '8' )
168 if (d
[1] >= '1' && d
[1] <= '3' && p
- buffer
< 4)
170 if (d
[1] >= '4' && d
[1] <= '6' && p
- buffer
< 6)
172 if ((d
[0] == 'L' || d
[0] == 'l') && d
[1] == 'w' && p
- buffer
< 4)
176 d
= m68k_opcodes
[best
].args
;
179 fputs_filtered (" ", stream
);
183 p
= print_insn_arg (d
, buffer
, p
, addr
+ p
- buffer
, stream
);
185 if (*d
&& *(d
- 2) != 'I' && *d
!= 'k')
186 fputs_filtered (",", stream
);
191 static unsigned char *
192 print_insn_arg (d
, buffer
, p
, addr
, stream
)
194 unsigned char *buffer
;
195 register unsigned char *p
;
196 bfd_vma addr
; /* PC for this arg to be relative to */
199 register int val
= 0;
200 register int place
= d
[1];
202 register char *regname
;
203 register unsigned char *p1
;
204 register double flval
= 0;
209 case 'c': /* cache identifier */
211 static char *cacheFieldName
[] = { "NOP", "dc", "ic", "bc" };
212 val
= fetch_arg (buffer
, place
, 2);
213 fprintf_filtered (stream
, cacheFieldName
[val
]);
217 case 'a': /* address register indirect only. Cf. case '+'. */
219 fprintf_filtered (stream
,
221 reg_names
[fetch_arg (buffer
, place
, 3) + 8]);
225 case '_': /* 32-bit absolute address for move16. */
228 fprintf_filtered (stream
, "@#");
229 print_address (val
, stream
);
234 fprintf_filtered (stream
, "ccr");
238 fprintf_filtered (stream
, "sr");
242 fprintf_filtered (stream
, "usp");
247 static struct { char *name
; int value
; } names
[]
248 = {{"sfc", 0x000}, {"dfc", 0x001}, {"cacr", 0x002},
249 {"tc", 0x003}, {"itt0",0x004}, {"itt1", 0x005},
250 {"dtt0",0x006}, {"dtt1",0x007},
251 {"usp", 0x800}, {"vbr", 0x801}, {"caar", 0x802},
252 {"msp", 0x803}, {"isp", 0x804}, {"mmusr",0x805},
253 {"urp", 0x806}, {"srp", 0x807}};
255 val
= fetch_arg (buffer
, place
, 12);
256 for (regno
= sizeof names
/ sizeof names
[0] - 1; regno
>= 0; regno
--)
257 if (names
[regno
].value
== val
)
259 fprintf_filtered (stream
, names
[regno
].name
);
263 fprintf_filtered (stream
, "%d", val
);
268 val
= fetch_arg (buffer
, place
, 3);
269 /* 0 means 8, except for the bkpt instruction... */
270 if (val
== 0 && d
[1] != 's')
272 fprintf_filtered (stream
, "#%d", val
);
276 val
= fetch_arg (buffer
, place
, 8);
279 fprintf_filtered (stream
, "#%d", val
);
283 val
= fetch_arg (buffer
, place
, 4);
284 fprintf_filtered (stream
, "#%d", val
);
288 fprintf_filtered (stream
, "%s", reg_names
[fetch_arg (buffer
, place
, 3)]);
292 fprintf_filtered (stream
, "%s",
293 reg_names
[fetch_arg (buffer
, place
, 3) + 010]);
297 fprintf_filtered (stream
, "%s", reg_names
[fetch_arg (buffer
, place
, 4)]);
301 fprintf_filtered (stream
, "%s@", reg_names
[fetch_arg (buffer
, place
, 4)]);
305 fprintf_filtered (stream
, "fp%d", fetch_arg (buffer
, place
, 3));
309 val
= fetch_arg (buffer
, place
, 6);
311 fprintf_filtered (stream
, "%s", reg_names
[val
& 7]);
313 fprintf_filtered (stream
, "%d", val
);
317 fprintf_filtered (stream
, "%s@+",
318 reg_names
[fetch_arg (buffer
, place
, 3) + 8]);
322 fprintf_filtered (stream
, "%s@-",
323 reg_names
[fetch_arg (buffer
, place
, 3) + 8]);
328 fprintf_filtered (stream
, "{%s}", reg_names
[fetch_arg (buffer
, place
, 3)]);
329 else if (place
== 'C')
331 val
= fetch_arg (buffer
, place
, 7);
332 if ( val
> 63 ) /* This is a signed constant. */
334 fprintf_filtered (stream
, "{#%d}", val
);
337 fprintf_filtered(stderr
, "Invalid arg format in opcode table: \"%c%c\".",
343 p1
= buffer
+ (*d
== '#' ? 2 : 4);
345 val
= fetch_arg (buffer
, place
, 4);
346 else if (place
== 'C')
347 val
= fetch_arg (buffer
, place
, 7);
348 else if (place
== '8')
349 val
= fetch_arg (buffer
, place
, 3);
350 else if (place
== '3')
351 val
= fetch_arg (buffer
, place
, 8);
352 else if (place
== 'b')
354 else if (place
== 'w')
356 else if (place
== 'l')
359 fprintf_filtered(stderr
, "Invalid arg format in opcode table: \"%c%c\".",
361 fprintf_filtered (stream
, "#%d", val
);
367 else if (place
== 'B')
368 val
= COERCE_SIGNED_CHAR(buffer
[1]);
369 else if (place
== 'w' || place
== 'W')
371 else if (place
== 'l' || place
== 'L')
373 else if (place
== 'g')
375 val
= ((char *)buffer
)[1];
381 else if (place
== 'c')
383 if (buffer
[1] & 0x40) /* If bit six is one, long offset */
389 fprintf_filtered(stderr
, "Invalid arg format in opcode table: \"%c%c\".",
391 print_address (addr
+ val
, stream
);
396 fprintf_filtered (stream
, "%s@(%d)",
397 reg_names
[fetch_arg (buffer
, place
, 3)], val
);
401 fprintf_filtered (stream
, "%s",
402 fpcr_names
[fetch_arg (buffer
, place
, 3)]);
406 val
= fetch_arg (buffer
, 'd', 3); /* Get coprocessor ID... */
407 if (val
!= 1) /* Unusual coprocessor ID? */
408 fprintf_filtered (stream
, "(cpid=%d) ", val
);
410 p
+= 2; /* Skip coprocessor extended operands */
427 val
= fetch_arg (buffer
, 'x', 6);
428 val
= ((val
& 7) << 3) + ((val
>> 3) & 7);
431 val
= fetch_arg (buffer
, 's', 6);
433 /* Get register number assuming address register. */
434 regno
= (val
& 7) + 8;
435 regname
= reg_names
[regno
];
439 fprintf_filtered (stream
, "%s", reg_names
[val
]);
443 fprintf_filtered (stream
, "%s", regname
);
447 fprintf_filtered (stream
, "%s@", regname
);
451 fprintf_filtered (stream
, "%s@+", regname
);
455 fprintf_filtered (stream
, "%s@-", regname
);
460 fprintf_filtered (stream
, "%s@(%d)", regname
, val
);
464 p
= print_indexed (regno
, p
, addr
, stream
);
472 fprintf_filtered (stream
, "@#");
473 print_address (val
, stream
);
478 fprintf_filtered (stream
, "@#");
479 print_address (val
, stream
);
484 print_address (addr
+ val
, stream
);
488 p
= print_indexed (-1, p
, addr
, stream
);
492 flt_p
= 1; /* Assume it's a float... */
511 NEXTSINGLE(flval
, p
);
515 NEXTDOUBLE(flval
, p
);
519 flval
= NEXTEXTEND(p
);
523 flval
= NEXTPACKED(p
);
527 fprintf_filtered(stderr
, "Invalid arg format in opcode table: \"%c%c\".",
530 if ( flt_p
) /* Print a float? */
531 fprintf_filtered (stream
, "#%g", flval
);
533 fprintf_filtered (stream
, "#%d", val
);
537 fprintf_filtered (stream
, "<invalid address mode 0%o>", (unsigned) val
);
549 /* Move the pointer ahead if this point is farther ahead
554 fputs_filtered ("#0", stream
);
559 register int newval
= 0;
560 for (regno
= 0; regno
< 16; ++regno
)
561 if (val
& (0x8000 >> regno
))
562 newval
|= 1 << regno
;
567 for (regno
= 0; regno
< 16; ++regno
)
568 if (val
& (1 << regno
))
572 fputs_filtered ("/", stream
);
574 fprintf_filtered (stream
, "%s", reg_names
[regno
]);
576 while (val
& (1 << (regno
+ 1)))
578 if (regno
> first_regno
)
579 fprintf_filtered (stream
, "-%s", reg_names
[regno
]);
582 else if (place
== '3')
586 val
= fetch_arg (buffer
, place
, 8);
589 fputs_filtered ("#0", stream
);
594 register int newval
= 0;
595 for (regno
= 0; regno
< 8; ++regno
)
596 if (val
& (0x80 >> regno
))
597 newval
|= 1 << regno
;
602 for (regno
= 0; regno
< 8; ++regno
)
603 if (val
& (1 << regno
))
607 fputs_filtered ("/", stream
);
609 fprintf_filtered (stream
, "fp%d", regno
);
611 while (val
& (1 << (regno
+ 1)))
613 if (regno
> first_regno
)
614 fprintf_filtered (stream
, "-fp%d", regno
);
622 fprintf_filtered(stderr
, "Invalid arg format in opcode table: \"%c\".", *d
);
625 return (unsigned char *) p
;
628 /* Fetch BITS bits from a position in the instruction specified by CODE.
629 CODE is a "place to put an argument", or 'x' for a destination
630 that is a general address (mode and register).
631 BUFFER contains the instruction. */
634 fetch_arg (buffer
, code
, bits
)
635 unsigned char *buffer
;
639 register int val
= 0;
646 case 'd': /* Destination, for register or quick. */
647 val
= (buffer
[0] << 8) + buffer
[1];
651 case 'x': /* Destination, for general arg */
652 val
= (buffer
[0] << 8) + buffer
[1];
657 val
= (buffer
[3] >> 4);
665 val
= (buffer
[2] << 8) + buffer
[3];
670 val
= (buffer
[2] << 8) + buffer
[3];
676 val
= (buffer
[2] << 8) + buffer
[3];
680 val
= (buffer
[4] << 8) + buffer
[5];
685 val
= (buffer
[4] << 8) + buffer
[5];
690 val
= (buffer
[4] << 8) + buffer
[5];
694 val
= (buffer
[2] << 8) + buffer
[3];
699 val
= (buffer
[2] << 8) + buffer
[3];
704 val
= (buffer
[1] >> 6);
735 /* Print an indexed argument. The base register is BASEREG (-1 for pc).
736 P points to extension word, in buffer.
737 ADDR is the nominal core address of that extension word. */
739 static unsigned char *
740 print_indexed (basereg
, p
, addr
, stream
)
747 static char *scales
[] = {"", "*2", "*4", "*8"};
748 register int base_disp
;
749 register int outer_disp
;
754 /* Generate the text for the index register.
755 Where this will be output is not yet determined. */
756 sprintf (buf
, "[%s.%c%s]",
757 reg_names
[(word
>> 12) & 0xf],
758 (word
& 0x800) ? 'l' : 'w',
759 scales
[(word
>> 9) & 3]);
761 /* Handle the 68000 style of indexing. */
763 if ((word
& 0x100) == 0)
766 ((word
& 0x80) ? word
| 0xff00 : word
& 0xff)
767 + ((basereg
== -1) ? addr
: 0),
769 fputs_filtered (buf
, stream
);
773 /* Handle the generalized kind. */
774 /* First, compute the displacement to add to the base register. */
781 switch ((word
>> 4) & 3)
784 base_disp
= NEXTWORD (p
);
787 base_disp
= NEXTLONG (p
);
792 /* Handle single-level case (not indirect) */
796 print_base (basereg
, base_disp
, stream
);
797 fputs_filtered (buf
, stream
);
801 /* Two level. Compute displacement to add after indirection. */
807 outer_disp
= NEXTWORD (p
);
810 outer_disp
= NEXTLONG (p
);
813 fprintf_filtered (stream
, "%d(", outer_disp
);
814 print_base (basereg
, base_disp
, stream
);
816 /* If postindexed, print the closeparen before the index. */
818 fprintf_filtered (stream
, ")%s", buf
);
819 /* If preindexed, print the closeparen after the index. */
821 fprintf_filtered (stream
, "%s)", buf
);
826 /* Print a base register REGNO and displacement DISP, on STREAM.
827 REGNO = -1 for pc, -2 for none (suppressed). */
830 print_base (regno
, disp
, stream
)
836 fprintf_filtered (stream
, "%d", disp
);
837 else if (regno
== -1)
838 fprintf_filtered (stream
, "0x%x", (unsigned) disp
);
840 fprintf_filtered (stream
, "%d(%s)", disp
, reg_names
[regno
]);
This page took 0.047361 seconds and 4 git commands to generate.