1 /* Disassemble Motorola M*Core instructions.
2 Copyright 1993, 1999, 2000, 2002 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. */
23 #include "mcore-opc.h"
26 /* Mask for each mcore_opclass: */
27 static const unsigned short imsk
[] = {
61 /* OPSR */ 0xFFF8, /* psrset/psrclr */
63 /* JC */ 0, /* JC,JU,JL don't appear in object */
68 /* OB2 */ 0 /* OB2 won't appear in object. */
71 static const char *grname
[] = {
72 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
73 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
76 static const char X
[] = "??";
78 static const char *crname
[] = {
79 "psr", "vbr", "epsr", "fpsr", "epc", "fpc", "ss0", "ss1",
80 "ss2", "ss3", "ss4", "gcr", "gsr", X
, X
, X
,
81 X
, X
, X
, X
, X
, X
, X
, X
,
82 X
, X
, X
, X
, X
, X
, X
, X
85 static const unsigned isiz
[] = { 2, 0, 1, 0 };
88 print_insn_mcore (memaddr
, info
)
90 struct disassemble_info
*info
;
92 unsigned char ibytes
[4];
93 fprintf_ftype fprintf
= info
->fprintf_func
;
94 void *stream
= info
->stream
;
96 const mcore_opcode_info
*op
;
99 info
->bytes_per_chunk
= 2;
101 status
= info
->read_memory_func (memaddr
, ibytes
, 2, info
);
105 info
->memory_error_func (status
, memaddr
, info
);
109 if (info
->endian
== BFD_ENDIAN_BIG
)
110 inst
= (ibytes
[0] << 8) | ibytes
[1];
111 else if (info
->endian
== BFD_ENDIAN_LITTLE
)
112 inst
= (ibytes
[1] << 8) | ibytes
[0];
116 /* Just a linear search of the table. */
117 for (op
= mcore_table
; op
->name
!= 0; op
++)
118 if (op
->inst
== (inst
& imsk
[op
->opclass
]))
122 fprintf (stream
, ".short 0x%04x", inst
);
125 const char *name
= grname
[inst
& 0x0F];
127 fprintf (stream
, "%s", op
->name
);
135 fprintf (stream
, "\t%d", inst
& 0x3);
141 fprintf (stream
, "\t%s", name
);
145 fprintf (stream
, "\t%s, %s", name
, crname
[(inst
>> 4) & 0x1F]);
149 fprintf (stream
, "\t%s, r1", name
);
154 fprintf (stream
, "\t%s, %s", name
, grname
[(inst
>> 4) & 0xF]);
158 fprintf (stream
, "\tr1, %s", name
);
162 fprintf (stream
, "\t%s, %d", name
, ((inst
>> 4) & 0x1F) + 1);
166 fprintf (stream
, "\t%s-r15, (r0)", name
);
170 fprintf (stream
, "\tr4-r7, (%s)", name
);
182 fprintf (stream
, "\t%s, %d", name
, (inst
>> 4) & 0x1F);
186 fprintf (stream
, "\t%s, %d", name
, (inst
>> 4) & 0x7F);
190 fprintf (stream
, "\t%s, (%s, %d)", grname
[(inst
>> 8) & 0xF],
191 name
, ((inst
>> 4) & 0xF) << isiz
[(inst
>> 13) & 3]);
196 long val
= inst
& 0x3FF;
201 fprintf (stream
, "\t0x%x", memaddr
+ 2 + (val
<< 1));
203 if (strcmp (op
->name
, "bsr") == 0)
205 /* For bsr, we'll try to get a symbol for the target. */
206 val
= memaddr
+ 2 + (val
<< 1);
208 if (info
->print_address_func
&& val
!= 0)
210 fprintf (stream
, "\t// ");
211 info
->print_address_func (val
, info
);
220 val
= (inst
& 0x000F);
221 fprintf (stream
, "\t%s, 0x%x",
222 grname
[(inst
>> 4) & 0xF], memaddr
- (val
<< 1));
230 val
= (memaddr
+ 2 + ((inst
& 0xFF) << 2)) & 0xFFFFFFFC;
232 status
= info
->read_memory_func (val
, ibytes
, 4, info
);
235 info
->memory_error_func (status
, memaddr
, info
);
239 if (info
->endian
== BFD_ENDIAN_LITTLE
)
240 val
= (ibytes
[3] << 24) | (ibytes
[2] << 16)
241 | (ibytes
[1] << 8) | (ibytes
[0]);
243 val
= (ibytes
[0] << 24) | (ibytes
[1] << 16)
244 | (ibytes
[2] << 8) | (ibytes
[3]);
246 /* Removed [] around literal value to match ABI syntax 12/95. */
247 fprintf (stream
, "\t%s, 0x%X", grname
[(inst
>> 8) & 0xF], val
);
250 fprintf (stream
, "\t// from address pool at 0x%x",
251 (memaddr
+ 2 + ((inst
& 0xFF) << 2)) & 0xFFFFFFFC);
259 val
= (memaddr
+ 2 + ((inst
& 0xFF) << 2)) & 0xFFFFFFFC;
261 status
= info
->read_memory_func (val
, ibytes
, 4, info
);
264 info
->memory_error_func (status
, memaddr
, info
);
268 if (info
->endian
== BFD_ENDIAN_LITTLE
)
269 val
= (ibytes
[3] << 24) | (ibytes
[2] << 16)
270 | (ibytes
[1] << 8) | (ibytes
[0]);
272 val
= (ibytes
[0] << 24) | (ibytes
[1] << 16)
273 | (ibytes
[2] << 8) | (ibytes
[3]);
275 /* Removed [] around literal value to match ABI syntax 12/95. */
276 fprintf (stream
, "\t0x%X", val
);
277 /* For jmpi/jsri, we'll try to get a symbol for the target. */
278 if (info
->print_address_func
&& val
!= 0)
280 fprintf (stream
, "\t// ");
281 info
->print_address_func (val
, info
);
285 fprintf (stream
, "\t// from address pool at 0x%x",
286 (memaddr
+ 2 + ((inst
& 0xFF) << 2)) & 0xFFFFFFFC);
293 static char *fields
[] = {
294 "af", "ie", "fe", "fe,ie",
295 "ee", "ee,ie", "ee,fe", "ee,fe,ie"
298 fprintf (stream
, "\t%s", fields
[inst
& 0x7]);
303 /* If the disassembler lags the instruction set. */
304 fprintf (stream
, "\tundecoded operands, inst is 0x%04x", inst
);
309 /* Say how many bytes we consumed. */