1 /* Disassemble Motorola M*Core instructions.
2 Copyright (C) 1993, 1999 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. */
22 #include "mcore-opc.h"
25 /* Mask for each mcore_opclass: */
26 static const unsigned short imsk
[] =
60 /* JC */ 0, /* JC,JU,JL don't appear in object */
65 /* OB2 */ 0 /* OB2 won't appear in object. */
68 static const char * grname
[] =
70 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
71 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
74 static const char X
[] = "??";
76 static const char * crname
[] =
78 "psr", "vbr", "epsr", "fpsr", "epc", "fpc", "ss0", "ss1",
79 "ss2", "ss3", "ss4", "gcr", "gsr", X
, X
, X
,
80 X
, X
, X
, X
, X
, X
, X
, X
,
81 X
, X
, X
, X
, X
, X
, X
, X
84 static const unsigned isiz
[] = { 2, 0, 1, 0 };
87 print_insn_mcore (memaddr
, info
)
89 struct disassemble_info
* info
;
91 unsigned char ibytes
[4];
92 fprintf_ftype fprintf
= info
->fprintf_func
;
93 void * stream
= info
->stream
;
95 mcore_opcode_info
* op
;
98 info
->bytes_per_chunk
= 2;
100 status
= info
->read_memory_func (memaddr
, ibytes
, 2, info
);
104 info
->memory_error_func (status
, memaddr
, info
);
108 inst
= (ibytes
[0] << 8) | ibytes
[1];
110 /* Just a linear search of the table. */
111 for (op
= mcore_table
; op
->name
!= 0; op
++)
112 if (op
->inst
== (inst
& imsk
[op
->opclass
]))
116 fprintf (stream
, ".short 0x%04x", inst
);
119 const char * name
= grname
[inst
& 0x0F];
121 fprintf (stream
, "%s", op
->name
);
126 case OT
: fprintf (stream
, "\t%d", inst
& 0x3); break;
129 case JSR
: fprintf (stream
, "\t%s", name
); break;
130 case OC
: fprintf (stream
, "\t%s, %s", name
, crname
[(inst
>> 4) & 0x1F]); break;
131 case O1R1
: fprintf (stream
, "\t%s, r1", name
); break;
132 case O2
: fprintf (stream
, "\t%s, %s", name
, grname
[(inst
>> 4) & 0xF]); break;
133 case X1
: fprintf (stream
, "\tr1, %s", name
); break;
134 case OI
: fprintf (stream
, "\t%s, %d", name
, ((inst
>> 4) & 0x1F) + 1); break;
135 case RM
: fprintf (stream
, "\t%s-r15, (r0)", name
); break;
136 case RQ
: fprintf (stream
, "\tr4-r7, (%s)", name
); break;
145 case OMc
: fprintf (stream
, "\t%s, %d", name
, (inst
>> 4) & 0x1F); break;
146 case I7
: fprintf (stream
, "\t%s, %d", name
, (inst
>> 4) & 0x7F); break;
147 case LS
: fprintf (stream
, "\t%s, (%s, %d)", grname
[(inst
>> 8) & 0xF],
148 name
, ((inst
>> 4) & 0xF) << isiz
[(inst
>> 13) & 3]);
153 long val
= inst
& 0x3FF;
158 fprintf (stream
, "\t0x%x", memaddr
+ 2 + (val
<<1));
160 if (strcmp (op
->name
, "bsr") == 0)
162 /* for bsr, we'll try to get a symbol for the target */
163 val
= memaddr
+ 2 + (val
<< 1);
165 if (info
->print_address_func
&& val
!= 0)
167 fprintf (stream
, "\t// ");
168 info
->print_address_func (val
, info
);
177 val
= (inst
& 0x000F);
178 fprintf (stream
, "\t%s, 0x%x",
179 grname
[(inst
>> 4) & 0xF], memaddr
- (val
<< 1));
187 val
= (memaddr
+ 2 + ((inst
& 0xFF) << 2)) & 0xFFFFFFFC;
189 status
= info
->read_memory_func (val
, ibytes
, 4, info
);
192 info
->memory_error_func (status
, memaddr
, info
);
196 val
= (ibytes
[0] << 24) | (ibytes
[1] << 16)
197 | (ibytes
[2] << 8) | (ibytes
[3]);
199 /* Removed [] around literal value to match ABI syntax 12/95. */
200 fprintf (stream
, "\t%s, 0x%X", grname
[(inst
>> 8) & 0xF], val
);
203 fprintf (stream
, "\t// from address pool at 0x%x",
204 (memaddr
+ 2 + ((inst
& 0xFF) << 2)) & 0xFFFFFFFC);
212 val
= (memaddr
+ 2 + ((inst
& 0xFF) << 2)) & 0xFFFFFFFC;
214 status
= info
->read_memory_func (val
, ibytes
, 4, info
);
217 info
->memory_error_func (status
, memaddr
, info
);
221 val
= (ibytes
[0] << 24) | (ibytes
[1] << 16)
222 | (ibytes
[2] << 8) | (ibytes
[3]);
224 /* Removed [] around literal value to match ABI syntax 12/95. */
225 fprintf (stream
, "\t0x%X", val
);
226 /* For jmpi/jsri, we'll try to get a symbol for the target. */
227 if (info
->print_address_func
&& val
!= 0)
229 fprintf (stream
, "\t// ");
230 info
->print_address_func (val
, info
);
234 fprintf (stream
, "\t// from address pool at 0x%x",
235 (memaddr
+ 2 + ((inst
& 0xFF) << 2)) & 0xFFFFFFFC);
241 /* if the disassembler lags the instruction set */
242 fprintf (stream
, "\tundecoded operands, inst is 0x%04x", inst
);
247 /* Say how many bytes we consumed? */
This page took 0.0623 seconds and 4 git commands to generate.