1 /* Print Motorola 68k instructions for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 #include "ieee-float.h"
25 /* Opcode/m68k.h is a massive table. As a kludge, break it up into
26 two pieces. This makes nonportable C -- FIXME -- it assumes that
27 two data items declared near each other will be contiguous in
28 memory. This kludge can be removed, FIXME, when GCC is fixed to not
29 be a hog about initializers. */
32 #define BREAK_UP_BIG_DECL }; \
33 struct m68k_opcode m68k_opcodes_2[] = {
34 #define AND_OTHER_PART sizeof (m68k_opcodes_2)
37 #include "opcode/m68k.h"
40 /* Local function prototypes */
43 fetch_arg
PARAMS ((unsigned char *, int, int));
46 print_base
PARAMS ((int, int, FILE *));
48 static unsigned char *
49 print_indexed
PARAMS ((int, unsigned char *, CORE_ADDR
, FILE *));
51 static unsigned char *
52 print_insn_arg
PARAMS ((char *, unsigned char *, unsigned char *, CORE_ADDR
,
55 /* 68k instructions are never longer than this many bytes. */
58 const char * const fpcr_names
[] = {
59 "", "fpiar", "fpsr", "fpiar/fpsr", "fpcr",
60 "fpiar/fpcr", "fpsr/fpcr", "fpiar/fpsr/fpcr"};
62 /* Define accessors for 68K's 1, 2, and 4-byte signed quantities.
63 The _SHIFT values move the quantity to the high order end of an
64 `int' value, so it will sign-extend. Probably a few more casts
65 are needed to make it compile without warnings on finicky systems. */
66 #define BITS_PER_BYTE 8
67 #define BYTE_SHIFT (BITS_PER_BYTE * ((sizeof (int)) - 1))
68 #define WORD_SHIFT (BITS_PER_BYTE * ((sizeof (int)) - 2))
69 #define LONG_SHIFT (BITS_PER_BYTE * ((sizeof (int)) - 4))
71 #define NEXTBYTE(p) (p += 2, ((int)(p[-1]) << BYTE_SHIFT) >> BYTE_SHIFT)
74 (p += 2, (((int)((p[-2] << 8) + p[-1])) << WORD_SHIFT) >> WORD_SHIFT)
77 (p += 4, (((int)((((((p[-4] << 8) + p[-3]) << 8) + p[-2]) << 8) + p[-1])) \
78 << LONG_SHIFT) >> LONG_SHIFT)
80 /* Ecch -- assumes host == target float formats. FIXME. */
81 #define NEXTSINGLE(p) \
82 (p += 4, *((float *)(p - 4)))
84 #define NEXTDOUBLE(p) \
85 (p += 8, *((double *)(p - 8)))
87 /* Print the m68k instruction at address MEMADDR in debugged memory,
88 on STREAM. Returns length of the instruction, in bytes. */
91 print_insn (memaddr
, stream
)
95 unsigned char buffer
[MAXLEN
];
97 register unsigned char *p
;
99 register int bestmask
;
102 read_memory (memaddr
, (char *) buffer
, MAXLEN
);
106 for (i
= 0; i
< numopcodes
; i
++)
108 register unsigned int opcode
= m68k_opcodes
[i
].opcode
;
109 register unsigned int match
= m68k_opcodes
[i
].match
;
110 if (((0xff & buffer
[0] & (match
>> 24)) == (0xff & (opcode
>> 24)))
111 && ((0xff & buffer
[1] & (match
>> 16)) == (0xff & (opcode
>> 16)))
112 && ((0xff & buffer
[2] & (match
>> 8)) == (0xff & (opcode
>> 8)))
113 && ((0xff & buffer
[3] & match
) == (0xff & opcode
)))
115 /* Don't use for printout the variants of divul and divsl
116 that have the same register number in two places.
117 The more general variants will match instead. */
118 for (d
= m68k_opcodes
[i
].args
; *d
; d
+= 2)
122 /* Don't use for printout the variants of most floating
123 point coprocessor instructions which use the same
124 register number in two places, as above. */
126 for (d
= m68k_opcodes
[i
].args
; *d
; d
+= 2)
130 if (*d
== 0 && match
> bestmask
)
138 /* Handle undefined instructions. */
141 fprintf_filtered (stream
, "0%o", (buffer
[0] << 8) + buffer
[1]);
145 fprintf_filtered (stream
, "%s", m68k_opcodes
[best
].name
);
147 /* Point at first word of argument data,
148 and at descriptor for first argument. */
151 /* Why do this this way? -MelloN */
152 for (d
= m68k_opcodes
[best
].args
; *d
; d
+= 2)
156 if (d
[1] == 'l' && p
- buffer
< 6)
158 else if (p
- buffer
< 4 && d
[1] != 'C' && d
[1] != '8' )
161 if (d
[1] >= '1' && d
[1] <= '3' && p
- buffer
< 4)
163 if (d
[1] >= '4' && d
[1] <= '6' && p
- buffer
< 6)
165 if ((d
[0] == 'L' || d
[0] == 'l') && d
[1] == 'w' && p
- buffer
< 4)
169 d
= m68k_opcodes
[best
].args
;
172 fputs_filtered (" ", stream
);
176 p
= print_insn_arg (d
, buffer
, p
, memaddr
+ p
- buffer
, stream
);
178 if (*d
&& *(d
- 2) != 'I' && *d
!= 'k')
179 fputs_filtered (",", stream
);
184 static unsigned char *
185 print_insn_arg (d
, buffer
, p
, addr
, stream
)
187 unsigned char *buffer
;
188 register unsigned char *p
;
189 CORE_ADDR addr
; /* PC for this arg to be relative to */
193 register int place
= d
[1];
195 register const char *regname
;
196 register unsigned char *p1
;
202 case 'c': /* cache identifier */
204 static char *cacheFieldName
[] = { "NOP", "dc", "ic", "bc" };
205 val
= fetch_arg (buffer
, place
, 2);
206 fprintf_filtered (stream
, cacheFieldName
[val
]);
210 case 'a': /* address register indirect only. Cf. case '+'. */
212 fprintf_filtered (stream
,
214 reg_names
[fetch_arg (buffer
, place
, 3) + 8]);
218 case '_': /* 32-bit absolute address for move16. */
221 fprintf_filtered (stream
, "@#");
222 print_address (val
, stream
);
227 fprintf_filtered (stream
, "ccr");
231 fprintf_filtered (stream
, "sr");
235 fprintf_filtered (stream
, "usp");
240 static struct { char *name
; int value
; } names
[]
241 = {{"sfc", 0x000}, {"dfc", 0x001}, {"cacr", 0x002},
242 {"tc", 0x003}, {"itt0",0x004}, {"itt1", 0x005},
243 {"dtt0",0x006}, {"dtt1",0x007},
244 {"usp", 0x800}, {"vbr", 0x801}, {"caar", 0x802},
245 {"msp", 0x803}, {"isp", 0x804}, {"mmusr",0x805},
246 {"urp", 0x806}, {"srp", 0x807}};
248 val
= fetch_arg (buffer
, place
, 12);
249 for (regno
= sizeof names
/ sizeof names
[0] - 1; regno
>= 0; regno
--)
250 if (names
[regno
].value
== val
)
252 fprintf_filtered (stream
, names
[regno
].name
);
256 fprintf_filtered (stream
, "%d", val
);
261 val
= fetch_arg (buffer
, place
, 3);
262 /* 0 means 8, except for the bkpt instruction... */
263 if (val
== 0 && d
[1] != 's')
265 fprintf_filtered (stream
, "#%d", val
);
269 val
= fetch_arg (buffer
, place
, 8);
272 fprintf_filtered (stream
, "#%d", val
);
276 val
= fetch_arg (buffer
, place
, 4);
277 fprintf_filtered (stream
, "#%d", val
);
281 fprintf_filtered (stream
, "%s", reg_names
[fetch_arg (buffer
, place
, 3)]);
285 fprintf_filtered (stream
, "%s",
286 reg_names
[fetch_arg (buffer
, place
, 3) + 010]);
290 fprintf_filtered (stream
, "%s", reg_names
[fetch_arg (buffer
, place
, 4)]);
294 fprintf_filtered (stream
, "%s@", reg_names
[fetch_arg (buffer
, place
, 4)]);
298 fprintf_filtered (stream
, "fp%d", fetch_arg (buffer
, place
, 3));
302 val
= fetch_arg (buffer
, place
, 6);
304 fprintf_filtered (stream
, "%s", reg_names
[val
& 7]);
306 fprintf_filtered (stream
, "%d", val
);
310 fprintf_filtered (stream
, "%s@+",
311 reg_names
[fetch_arg (buffer
, place
, 3) + 8]);
315 fprintf_filtered (stream
, "%s@-",
316 reg_names
[fetch_arg (buffer
, place
, 3) + 8]);
321 fprintf_filtered (stream
, "{%s}", reg_names
[fetch_arg (buffer
, place
, 3)]);
322 else if (place
== 'C')
324 val
= fetch_arg (buffer
, place
, 7);
325 if ( val
> 63 ) /* This is a signed constant. */
327 fprintf_filtered (stream
, "{#%d}", val
);
330 error ("Invalid arg format in opcode table: \"%c%c\".",
336 p1
= buffer
+ (*d
== '#' ? 2 : 4);
338 val
= fetch_arg (buffer
, place
, 4);
339 else if (place
== 'C')
340 val
= fetch_arg (buffer
, place
, 7);
341 else if (place
== '8')
342 val
= fetch_arg (buffer
, place
, 3);
343 else if (place
== '3')
344 val
= fetch_arg (buffer
, place
, 8);
345 else if (place
== 'b')
347 else if (place
== 'w')
349 else if (place
== 'l')
352 error ("Invalid arg format in opcode table: \"%c%c\".",
354 fprintf_filtered (stream
, "#%d", val
);
360 else if (place
== 'B')
361 val
= NEXTBYTE (buffer
); /* from the opcode word */
362 else if (place
== 'w' || place
== 'W')
364 else if (place
== 'l' || place
== 'L')
366 else if (place
== 'g')
368 val
= NEXTBYTE (buffer
);
374 else if (place
== 'c')
376 if (buffer
[1] & 0x40) /* If bit six is one, long offset */
382 error ("Invalid arg format in opcode table: \"%c%c\".",
385 print_address (addr
+ val
, stream
);
390 fprintf_filtered (stream
, "%s@(%d)",
391 reg_names
[fetch_arg (buffer
, place
, 3)], val
);
395 fprintf_filtered (stream
, "%s",
396 fpcr_names
[fetch_arg (buffer
, place
, 3)]);
400 val
= fetch_arg (buffer
, 'd', 3); /* Get coprocessor ID... */
401 if (val
!= 1) /* Unusual coprocessor ID? */
402 fprintf_filtered (stream
, "(cpid=%d) ", val
);
404 p
+= 2; /* Skip coprocessor extended operands */
421 val
= fetch_arg (buffer
, 'x', 6);
422 val
= ((val
& 7) << 3) + ((val
>> 3) & 7);
425 val
= fetch_arg (buffer
, 's', 6);
427 /* Get register number assuming address register. */
428 regno
= (val
& 7) + 8;
429 regname
= reg_names
[regno
];
433 fprintf_filtered (stream
, "%s", reg_names
[val
]);
437 fprintf_filtered (stream
, "%s", regname
);
441 fprintf_filtered (stream
, "%s@", regname
);
445 fprintf_filtered (stream
, "%s@+", regname
);
449 fprintf_filtered (stream
, "%s@-", regname
);
454 fprintf_filtered (stream
, "%s@(%d)", regname
, val
);
458 p
= print_indexed (regno
, p
, addr
, stream
);
466 fprintf_filtered (stream
, "@#");
467 print_address (val
, stream
);
472 fprintf_filtered (stream
, "@#");
473 print_address (val
, stream
);
478 print_address (addr
+ val
, stream
);
482 p
= print_indexed (-1, p
, addr
, stream
);
486 flt_p
= 1; /* Assume it's a float... */
505 flval
= NEXTSINGLE(p
);
509 flval
= NEXTDOUBLE(p
);
514 ieee_extended_to_double (&ext_format_68881
,
522 flval
= 0; /* FIXME, handle packed decimal someday. */
526 error ("Invalid arg format in opcode table: \"%c%c\".",
529 if ( flt_p
) /* Print a float? */
530 fprintf_filtered (stream
, "#%g", flval
);
532 fprintf_filtered (stream
, "#%d", val
);
536 fprintf_filtered (stream
, "<invalid address mode 0%o>", val
);
548 /* Move the pointer ahead if this point is farther ahead
553 fputs_filtered ("#0", stream
);
558 register int newval
= 0;
559 for (regno
= 0; regno
< 16; ++regno
)
560 if (val
& (0x8000 >> regno
))
561 newval
|= 1 << regno
;
566 for (regno
= 0; regno
< 16; ++regno
)
567 if (val
& (1 << regno
))
571 fputs_filtered ("/", stream
);
573 fprintf_filtered (stream
, "%s", reg_names
[regno
]);
575 while (val
& (1 << (regno
+ 1)))
577 if (regno
> first_regno
)
578 fprintf_filtered (stream
, "-%s", reg_names
[regno
]);
581 else if (place
== '3')
585 val
= fetch_arg (buffer
, place
, 8);
588 fputs_filtered ("#0", stream
);
593 register int newval
= 0;
594 for (regno
= 0; regno
< 8; ++regno
)
595 if (val
& (0x80 >> regno
))
596 newval
|= 1 << regno
;
601 for (regno
= 0; regno
< 8; ++regno
)
602 if (val
& (1 << regno
))
606 fputs_filtered ("/", stream
);
608 fprintf_filtered (stream
, "fp%d", regno
);
610 while (val
& (1 << (regno
+ 1)))
612 if (regno
> first_regno
)
613 fprintf_filtered (stream
, "-fp%d", regno
);
621 error ("Invalid arg format in opcode table: \"%c\".", *d
);
624 return (unsigned char *) p
;
627 /* Fetch BITS bits from a position in the instruction specified by CODE.
628 CODE is a "place to put an argument", or 'x' for a destination
629 that is a general address (mode and register).
630 BUFFER contains the instruction. */
633 fetch_arg (buffer
, code
, bits
)
634 unsigned char *buffer
;
645 case 'd': /* Destination, for register or quick. */
646 val
= (buffer
[0] << 8) + buffer
[1];
650 case 'x': /* Destination, for general arg */
651 val
= (buffer
[0] << 8) + buffer
[1];
656 val
= (buffer
[3] >> 4);
664 val
= (buffer
[2] << 8) + buffer
[3];
669 val
= (buffer
[2] << 8) + buffer
[3];
675 val
= (buffer
[2] << 8) + buffer
[3];
679 val
= (buffer
[4] << 8) + buffer
[5];
684 val
= (buffer
[4] << 8) + buffer
[5];
689 val
= (buffer
[4] << 8) + buffer
[5];
693 val
= (buffer
[2] << 8) + buffer
[3];
698 val
= (buffer
[2] << 8) + buffer
[3];
703 val
= (buffer
[1] >> 6);
733 /* Print an indexed argument. The base register is BASEREG (-1 for pc).
734 P points to extension word, in buffer.
735 ADDR is the nominal core address of that extension word. */
737 static unsigned char *
738 print_indexed (basereg
, p
, addr
, stream
)
745 static char *scales
[] = {"", "*2", "*4", "*8"};
746 register int base_disp
;
747 register int outer_disp
;
752 /* Generate the text for the index register.
753 Where this will be output is not yet determined. */
754 sprintf (buf
, "[%s.%c%s]",
755 reg_names
[(word
>> 12) & 0xf],
756 (word
& 0x800) ? 'l' : 'w',
757 scales
[(word
>> 9) & 3]);
759 /* Handle the 68000 style of indexing. */
761 if ((word
& 0x100) == 0)
764 ((word
& 0x80) ? word
| 0xff00 : word
& 0xff)
765 + ((basereg
== -1) ? addr
: 0),
767 fputs_filtered (buf
, stream
);
771 /* Handle the generalized kind. */
772 /* First, compute the displacement to add to the base register. */
779 switch ((word
>> 4) & 3)
782 base_disp
= NEXTWORD (p
);
785 base_disp
= NEXTLONG (p
);
790 /* Handle single-level case (not indirect) */
794 print_base (basereg
, base_disp
, stream
);
795 fputs_filtered (buf
, stream
);
799 /* Two level. Compute displacement to add after indirection. */
805 outer_disp
= NEXTWORD (p
);
808 outer_disp
= NEXTLONG (p
);
811 fprintf_filtered (stream
, "%d(", outer_disp
);
812 print_base (basereg
, base_disp
, stream
);
814 /* If postindexed, print the closeparen before the index. */
816 fprintf_filtered (stream
, ")%s", buf
);
817 /* If preindexed, print the closeparen after the index. */
819 fprintf_filtered (stream
, "%s)", buf
);
824 /* Print a base register REGNO and displacement DISP, on STREAM.
825 REGNO = -1 for pc, -2 for none (suppressed). */
828 print_base (regno
, disp
, stream
)
834 fprintf_filtered (stream
, "%d", disp
);
835 else if (regno
== -1)
836 fprintf_filtered (stream
, "0x%x", disp
);
838 fprintf_filtered (stream
, "%d(%s)", disp
, reg_names
[regno
]);
This page took 0.131867 seconds and 4 git commands to generate.