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)))
56 iword = bfd_getb16 (buffer);
58 /* Form 1 instructions have the high bit set to 0. */
59 if ((iword & (1<<15)) == 0)
61 /* Extract the Form 1 opcode. */
62 opcode = &moxie_form1_opc_info[iword >> 8];
63 switch (opcode->itype)
66 fpr (stream, "%s", opcode->name);
69 fpr (stream, "%s\t%s", opcode->name,
70 reg_names[OP_A(iword)]);
73 fpr (stream, "%s\t%s, %s", opcode->name,
74 reg_names[OP_A(iword)],
75 reg_names[OP_B(iword)]);
80 if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
82 imm = bfd_getb32 (buffer);
83 fpr (stream, "%s\t%s, 0x%x", opcode->name,
84 reg_names[OP_A(iword)], imm);
91 if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
93 imm = bfd_getb32 (buffer);
94 fpr (stream, "%s\t0x%x", opcode->name, imm);
101 if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
103 imm = bfd_getb32 (buffer);
104 fpr (stream, "%s\t", opcode->name);
105 info->print_address_func ((bfd_vma) imm, info);
110 fpr (stream, "%s\t(%s), %s", opcode->name,
111 reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
114 fpr (stream, "%s\t%s, (%s)", opcode->name,
115 reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
120 if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
122 imm = bfd_getb32 (buffer);
123 fpr (stream, "%s\t0x%x, %s",
124 opcode->name, imm, reg_names[OP_A(iword)]);
131 if ((status = info->read_memory_func (addr+2, buffer, 4, info)))
133 imm = bfd_getb32 (buffer);
134 fpr (stream, "%s\t0x%x(%s), %s", opcode->name,
136 reg_names[OP_A(iword)],
137 reg_names[OP_B(iword)]);
144 if ((status = info->read_memory_func (addr+2, buffer, 4, info)))
146 imm = bfd_getb32 (buffer);
147 fpr (stream, "%s\t%s, 0x%x(%s)",
149 reg_names[OP_A(iword)],
151 reg_names[OP_B(iword)]);
159 else if ((iword & (1<<14)) == 0)
161 /* Extract the Form 2 opcode. */
162 opcode = &moxie_form2_opc_info[(iword >> 12) & 3];
163 switch (opcode->itype)
166 fpr (stream, "%s\t%s, 0x%x",
168 reg_names[(iword >> 8) & 0xf],
169 iword & ((1 << 8) - 1));
172 fpr (stream, "%s", opcode->name);
180 /* Extract the Form 3 opcode. */
181 opcode = &moxie_form3_opc_info[(iword >> 10) & 15];
182 switch (opcode->itype)
185 fpr (stream, "%s\t", opcode->name);
186 info->print_address_func ((bfd_vma) (addr + INST2OFFSET(iword)),
197 info->memory_error_func (status, addr, info);