1 /* Disassemble moxie instructions.
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. */
28 #include "opcode/moxie.h"
31 static fprintf_ftype fpr;
34 /* Macros to extract operands from the instruction word. */
35 #define OP_A(i) ((i >> 4) & 0xf)
36 #define OP_B(i) (i & 0xf)
37 #define INST2OFFSET(o) ((((signed short)((o & ((1<<10)-1))<<6))>>6)<<1)
39 static const char * reg_names[16] =
40 { "$fp", "$sp", "$r0", "$r1", "$r2", "$r3", "$r4", "$r5",
41 "$r6", "$r7", "$r8", "$r9", "$r10", "$r11", "$r12", "$r13" };
44 print_insn_moxie (bfd_vma addr, struct disassemble_info * info)
48 stream = info->stream;
49 const moxie_opc_info_t * opcode;
52 fpr = info->fprintf_func;
54 if ((status = info->read_memory_func (addr, buffer, 2, info)))
57 if (info->endian == BFD_ENDIAN_BIG)
58 iword = bfd_getb16 (buffer);
60 iword = bfd_getl16 (buffer);
62 /* Form 1 instructions have the high bit set to 0. */
63 if ((iword & (1<<15)) == 0)
65 /* Extract the Form 1 opcode. */
66 opcode = &moxie_form1_opc_info[iword >> 8];
67 switch (opcode->itype)
70 fpr (stream, "%s", opcode->name);
73 fpr (stream, "%s\t%s", opcode->name,
74 reg_names[OP_A(iword)]);
77 fpr (stream, "%s\t%s, %s", opcode->name,
78 reg_names[OP_A(iword)],
79 reg_names[OP_B(iword)]);
84 if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
86 if (info->endian == BFD_ENDIAN_BIG)
87 imm = bfd_getb32 (buffer);
89 imm = bfd_getl32 (buffer);
90 fpr (stream, "%s\t%s, 0x%x", opcode->name,
91 reg_names[OP_A(iword)], imm);
98 if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
100 if (info->endian == BFD_ENDIAN_BIG)
101 imm = bfd_getb32 (buffer);
103 imm = bfd_getl32 (buffer);
104 fpr (stream, "%s\t0x%x", opcode->name, imm);
111 if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
113 if (info->endian == BFD_ENDIAN_BIG)
114 imm = bfd_getb32 (buffer);
116 imm = bfd_getl32 (buffer);
117 fpr (stream, "%s\t", opcode->name);
118 info->print_address_func ((bfd_vma) imm, info);
123 fpr (stream, "%s\t(%s), %s", opcode->name,
124 reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
127 fpr (stream, "%s\t%s, (%s)", opcode->name,
128 reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
133 if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
135 if (info->endian == BFD_ENDIAN_BIG)
136 imm = bfd_getb32 (buffer);
138 imm = bfd_getl32 (buffer);
139 fpr (stream, "%s\t0x%x, %s",
140 opcode->name, imm, reg_names[OP_A(iword)]);
147 if ((status = info->read_memory_func (addr+2, buffer, 4, info)))
149 if (info->endian == BFD_ENDIAN_BIG)
150 imm = bfd_getb32 (buffer);
152 imm = bfd_getl32 (buffer);
153 fpr (stream, "%s\t0x%x(%s), %s", opcode->name,
155 reg_names[OP_A(iword)],
156 reg_names[OP_B(iword)]);
163 if ((status = info->read_memory_func (addr+2, buffer, 4, info)))
165 if (info->endian == BFD_ENDIAN_BIG)
166 imm = bfd_getb32 (buffer);
168 imm = bfd_getl32 (buffer);
169 fpr (stream, "%s\t%s, 0x%x(%s)",
171 reg_names[OP_A(iword)],
173 reg_names[OP_B(iword)]);
184 else if ((iword & (1<<14)) == 0)
186 /* Extract the Form 2 opcode. */
187 opcode = &moxie_form2_opc_info[(iword >> 12) & 3];
188 switch (opcode->itype)
191 fpr (stream, "%s\t%s, 0x%x",
193 reg_names[(iword >> 8) & 0xf],
194 iword & ((1 << 8) - 1));
197 fpr (stream, "%s", opcode->name);
208 /* Extract the Form 3 opcode. */
209 opcode = &moxie_form3_opc_info[(iword >> 10) & 15];
210 switch (opcode->itype)
213 fpr (stream, "%s\t", opcode->name);
214 info->print_address_func ((bfd_vma) (addr + INST2OFFSET(iword) + 2),
228 info->memory_error_func (status, addr, info);