1 /* Disassemble MN10200 instructions.
2 Copyright (C) 1996-2021 Free Software Foundation, Inc.
4 This file is part of the GNU opcodes library.
6 This library 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 3, or (at your option)
11 It is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 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., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
23 #include "opcode/mn10200.h"
24 #include "disassemble.h"
28 disassemble (bfd_vma memaddr
,
29 struct disassemble_info
*info
,
31 unsigned long extension
,
34 struct mn10200_opcode
*op
= (struct mn10200_opcode
*)mn10200_opcodes
;
35 const struct mn10200_operand
*operand
;
38 /* Find the opcode. */
41 int mysize
, extra_shift
;
43 if (op
->format
== FMT_1
)
45 else if (op
->format
== FMT_2
46 || op
->format
== FMT_4
)
48 else if (op
->format
== FMT_3
49 || op
->format
== FMT_5
)
51 else if (op
->format
== FMT_6
)
53 else if (op
->format
== FMT_7
)
58 if (op
->format
== FMT_2
|| op
->format
== FMT_5
)
60 else if (op
->format
== FMT_3
61 || op
->format
== FMT_6
62 || op
->format
== FMT_7
)
67 if ((op
->mask
& insn
) == op
->opcode
68 && size
== (unsigned int) mysize
)
70 const unsigned char *opindex_ptr
;
75 (*info
->fprintf_func
) (info
->stream
, "%s\t", op
->name
);
77 /* Now print the operands. */
78 for (opindex_ptr
= op
->operands
, nocomma
= 1;
84 operand
= &mn10200_operands
[*opindex_ptr
];
86 if ((operand
->flags
& MN10200_OPERAND_DREG
) != 0
87 || (operand
->flags
& MN10200_OPERAND_AREG
) != 0)
88 value
= ((insn
>> (operand
->shift
+ extra_shift
))
89 & ((1 << operand
->bits
) - 1));
90 else if ((operand
->flags
& MN10200_OPERAND_EXTENDED
) != 0)
92 value
= (insn
& 0xffff) << 8;
96 value
= ((insn
>> (operand
->shift
))
97 & ((1L << operand
->bits
) - 1L));
99 if ((operand
->flags
& MN10200_OPERAND_SIGNED
) != 0)
100 value
= ((long)(value
<< (32 - operand
->bits
))
101 >> (32 - operand
->bits
));
105 || ((operand
->flags
& MN10200_OPERAND_PAREN
) == 0)))
106 (*info
->fprintf_func
) (info
->stream
, ",");
110 if ((operand
->flags
& MN10200_OPERAND_DREG
) != 0)
111 (*info
->fprintf_func
) (info
->stream
, "d%ld", value
);
113 else if ((operand
->flags
& MN10200_OPERAND_AREG
) != 0)
114 (*info
->fprintf_func
) (info
->stream
, "a%ld", value
);
116 else if ((operand
->flags
& MN10200_OPERAND_PSW
) != 0)
117 (*info
->fprintf_func
) (info
->stream
, "psw");
119 else if ((operand
->flags
& MN10200_OPERAND_MDR
) != 0)
120 (*info
->fprintf_func
) (info
->stream
, "mdr");
122 else if ((operand
->flags
& MN10200_OPERAND_PAREN
) != 0)
125 (*info
->fprintf_func
) (info
->stream
, ")");
128 (*info
->fprintf_func
) (info
->stream
, "(");
134 else if ((operand
->flags
& MN10200_OPERAND_PCREL
) != 0)
135 (*info
->print_address_func
)
136 ((value
+ memaddr
+ mysize
) & 0xffffff, info
);
138 else if ((operand
->flags
& MN10200_OPERAND_MEMADDR
) != 0)
139 (*info
->print_address_func
) (value
, info
);
142 (*info
->fprintf_func
) (info
->stream
, "%ld", value
);
151 (*info
->fprintf_func
) (info
->stream
, _("unknown\t0x%04lx"), insn
);
155 print_insn_mn10200 (bfd_vma memaddr
, struct disassemble_info
*info
)
160 unsigned long extension
= 0;
161 unsigned int consume
;
163 /* First figure out how big the opcode is. */
164 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 1, info
);
167 (*info
->memory_error_func
) (status
, memaddr
, info
);
171 insn
= *(unsigned char *) buffer
;
173 /* These are one byte insns. */
174 if ((insn
& 0xf0) == 0x00
175 || (insn
& 0xf0) == 0x10
176 || (insn
& 0xf0) == 0x20
177 || (insn
& 0xf0) == 0x30
178 || ((insn
& 0xf0) == 0x80
179 && (insn
& 0x0c) >> 2 != (insn
& 0x03))
180 || (insn
& 0xf0) == 0x90
181 || (insn
& 0xf0) == 0xa0
182 || (insn
& 0xf0) == 0xb0
183 || (insn
& 0xff) == 0xeb
184 || (insn
& 0xff) == 0xf6
185 || (insn
& 0xff) == 0xfe
186 || (insn
& 0xff) == 0xff)
192 /* These are two byte insns. */
193 else if ((insn
& 0xf0) == 0x40
194 || (insn
& 0xf0) == 0x50
195 || (insn
& 0xf0) == 0x60
196 || (insn
& 0xf0) == 0x70
197 || (insn
& 0xf0) == 0x80
198 || (insn
& 0xfc) == 0xd0
199 || (insn
& 0xfc) == 0xd4
200 || (insn
& 0xfc) == 0xd8
201 || (insn
& 0xfc) == 0xe0
202 || (insn
& 0xfc) == 0xe4
203 || (insn
& 0xff) == 0xe8
204 || (insn
& 0xff) == 0xe9
205 || (insn
& 0xff) == 0xea
206 || (insn
& 0xff) == 0xf0
207 || (insn
& 0xff) == 0xf1
208 || (insn
& 0xff) == 0xf2
209 || (insn
& 0xff) == 0xf3)
211 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 2, info
);
214 (*info
->memory_error_func
) (status
, memaddr
, info
);
217 insn
= bfd_getb16 (buffer
);
221 /* These are three byte insns with a 16bit operand in little
223 else if ((insn
& 0xf0) == 0xc0
224 || (insn
& 0xfc) == 0xdc
225 || (insn
& 0xfc) == 0xec
226 || (insn
& 0xff) == 0xf8
227 || (insn
& 0xff) == 0xf9
228 || (insn
& 0xff) == 0xfa
229 || (insn
& 0xff) == 0xfb
230 || (insn
& 0xff) == 0xfc
231 || (insn
& 0xff) == 0xfd)
233 status
= (*info
->read_memory_func
) (memaddr
+ 1, buffer
, 2, info
);
236 (*info
->memory_error_func
) (status
, memaddr
, info
);
240 insn
|= bfd_getl16 (buffer
);
244 /* These are three byte insns too, but we don't have to mess with
246 else if ((insn
& 0xff) == 0xf5)
248 status
= (*info
->read_memory_func
) (memaddr
+ 1, buffer
, 2, info
);
251 (*info
->memory_error_func
) (status
, memaddr
, info
);
255 insn
|= bfd_getb16 (buffer
);
260 /* These are four byte insns. */
261 else if ((insn
& 0xff) == 0xf7)
263 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 2, info
);
266 (*info
->memory_error_func
) (status
, memaddr
, info
);
269 insn
= bfd_getb16 (buffer
);
271 status
= (*info
->read_memory_func
) (memaddr
+ 2, buffer
, 2, info
);
274 (*info
->memory_error_func
) (status
, memaddr
, info
);
277 insn
|= bfd_getl16 (buffer
);
282 /* These are five byte insns. */
283 else if ((insn
& 0xff) == 0xf4)
285 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 2, info
);
288 (*info
->memory_error_func
) (status
, memaddr
, info
);
291 insn
= bfd_getb16 (buffer
);
294 status
= (*info
->read_memory_func
) (memaddr
+ 4, buffer
, 1, info
);
297 (*info
->memory_error_func
) (status
, memaddr
, info
);
300 insn
|= (*(unsigned char *)buffer
<< 8) & 0xff00;
302 status
= (*info
->read_memory_func
) (memaddr
+ 3, buffer
, 1, info
);
305 (*info
->memory_error_func
) (status
, memaddr
, info
);
308 insn
|= (*(unsigned char *)buffer
) & 0xff;
310 status
= (*info
->read_memory_func
) (memaddr
+ 2, buffer
, 1, info
);
313 (*info
->memory_error_func
) (status
, memaddr
, info
);
316 extension
= (*(unsigned char *)buffer
) & 0xff;
321 (*info
->fprintf_func
) (info
->stream
, _("unknown\t0x%02lx"), insn
);
325 disassemble (memaddr
, info
, insn
, extension
, consume
);
This page took 0.034944 seconds and 4 git commands to generate.