1 /* Disassemble Motorola M*Core instructions.
2 Copyright 1993, 1999, 2000, 2001, 2002, 2005, 2007, 2009
3 Free Software Foundation, Inc.
5 This file is part of the GNU opcodes library.
7 This library is 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 3, or (at your option)
12 It is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
27 #include "mcore-opc.h"
30 /* Mask for each mcore_opclass: */
31 static const unsigned short imsk
[] = {
65 /* OPSR */ 0xFFF8, /* psrset/psrclr */
67 /* JC */ 0, /* JC,JU,JL don't appear in object */
72 /* OB2 */ 0 /* OB2 won't appear in object. */
75 static const char *grname
[] = {
76 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
77 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
80 static const char X
[] = "??";
82 static const char *crname
[] = {
83 "psr", "vbr", "epsr", "fpsr", "epc", "fpc", "ss0", "ss1",
84 "ss2", "ss3", "ss4", "gcr", "gsr", X
, X
, X
,
85 X
, X
, X
, X
, X
, X
, X
, X
,
86 X
, X
, X
, X
, X
, X
, X
, X
89 static const unsigned isiz
[] = { 2, 0, 1, 0 };
92 print_insn_mcore (memaddr
, info
)
94 struct disassemble_info
*info
;
96 unsigned char ibytes
[4];
97 fprintf_ftype print_func
= info
->fprintf_func
;
98 void *stream
= info
->stream
;
100 const mcore_opcode_info
*op
;
103 info
->bytes_per_chunk
= 2;
105 status
= info
->read_memory_func (memaddr
, ibytes
, 2, info
);
109 info
->memory_error_func (status
, memaddr
, info
);
113 if (info
->endian
== BFD_ENDIAN_BIG
)
114 inst
= (ibytes
[0] << 8) | ibytes
[1];
115 else if (info
->endian
== BFD_ENDIAN_LITTLE
)
116 inst
= (ibytes
[1] << 8) | ibytes
[0];
120 /* Just a linear search of the table. */
121 for (op
= mcore_table
; op
->name
!= 0; op
++)
122 if (op
->inst
== (inst
& imsk
[op
->opclass
]))
126 (*print_func
) (stream
, ".short 0x%04x", inst
);
129 const char *name
= grname
[inst
& 0x0F];
131 (*print_func
) (stream
, "%s", op
->name
);
139 (*print_func
) (stream
, "\t%d", inst
& 0x3);
145 (*print_func
) (stream
, "\t%s", name
);
149 (*print_func
) (stream
, "\t%s, %s", name
, crname
[(inst
>> 4) & 0x1F]);
153 (*print_func
) (stream
, "\t%s, r1", name
);
158 (*print_func
) (stream
, "\t%s, %s", name
, grname
[(inst
>> 4) & 0xF]);
162 (*print_func
) (stream
, "\tr1, %s", name
);
166 (*print_func
) (stream
, "\t%s, %d", name
, ((inst
>> 4) & 0x1F) + 1);
170 (*print_func
) (stream
, "\t%s-r15, (r0)", name
);
174 (*print_func
) (stream
, "\tr4-r7, (%s)", name
);
186 (*print_func
) (stream
, "\t%s, %d", name
, (inst
>> 4) & 0x1F);
190 (*print_func
) (stream
, "\t%s, %d", name
, (inst
>> 4) & 0x7F);
194 (*print_func
) (stream
, "\t%s, (%s, %d)", grname
[(inst
>> 8) & 0xF],
195 name
, ((inst
>> 4) & 0xF) << isiz
[(inst
>> 13) & 3]);
200 long val
= inst
& 0x3FF;
205 (*print_func
) (stream
, "\t0x%lx", (long)(memaddr
+ 2 + (val
<< 1)));
207 if (strcmp (op
->name
, "bsr") == 0)
209 /* For bsr, we'll try to get a symbol for the target. */
210 val
= memaddr
+ 2 + (val
<< 1);
212 if (info
->print_address_func
&& val
!= 0)
214 (*print_func
) (stream
, "\t// ");
215 info
->print_address_func (val
, info
);
224 val
= (inst
& 0x000F);
225 (*print_func
) (stream
, "\t%s, 0x%lx",
226 grname
[(inst
>> 4) & 0xF],
227 (long) (memaddr
- (val
<< 1)));
235 val
= (memaddr
+ 2 + ((inst
& 0xFF) << 2)) & 0xFFFFFFFC;
237 status
= info
->read_memory_func (val
, ibytes
, 4, info
);
240 info
->memory_error_func (status
, memaddr
, info
);
244 if (info
->endian
== BFD_ENDIAN_LITTLE
)
245 val
= (ibytes
[3] << 24) | (ibytes
[2] << 16)
246 | (ibytes
[1] << 8) | (ibytes
[0]);
248 val
= (ibytes
[0] << 24) | (ibytes
[1] << 16)
249 | (ibytes
[2] << 8) | (ibytes
[3]);
251 /* Removed [] around literal value to match ABI syntax 12/95. */
252 (*print_func
) (stream
, "\t%s, 0x%lX", grname
[(inst
>> 8) & 0xF], val
);
255 (*print_func
) (stream
, "\t// from address pool at 0x%lx",
257 + ((inst
& 0xFF) << 2)) & 0xFFFFFFFC);
265 val
= (memaddr
+ 2 + ((inst
& 0xFF) << 2)) & 0xFFFFFFFC;
267 status
= info
->read_memory_func (val
, ibytes
, 4, info
);
270 info
->memory_error_func (status
, memaddr
, info
);
274 if (info
->endian
== BFD_ENDIAN_LITTLE
)
275 val
= (ibytes
[3] << 24) | (ibytes
[2] << 16)
276 | (ibytes
[1] << 8) | (ibytes
[0]);
278 val
= (ibytes
[0] << 24) | (ibytes
[1] << 16)
279 | (ibytes
[2] << 8) | (ibytes
[3]);
281 /* Removed [] around literal value to match ABI syntax 12/95. */
282 (*print_func
) (stream
, "\t0x%lX", val
);
283 /* For jmpi/jsri, we'll try to get a symbol for the target. */
284 if (info
->print_address_func
&& val
!= 0)
286 (*print_func
) (stream
, "\t// ");
287 info
->print_address_func (val
, info
);
291 (*print_func
) (stream
, "\t// from address pool at 0x%lx",
293 + ((inst
& 0xFF) << 2)) & 0xFFFFFFFC);
300 static char *fields
[] = {
301 "af", "ie", "fe", "fe,ie",
302 "ee", "ee,ie", "ee,fe", "ee,fe,ie"
305 (*print_func
) (stream
, "\t%s", fields
[inst
& 0x7]);
310 /* If the disassembler lags the instruction set. */
311 (*print_func
) (stream
, "\tundecoded operands, inst is 0x%04x", inst
);
316 /* Say how many bytes we consumed. */
This page took 0.036148 seconds and 4 git commands to generate.