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. */
27 #include "opcode/moxie.h"
30 static fprintf_ftype fpr;
33 /* Macros to extract operands from the instruction word. */
34 #define OP_A(i) ((i >> 4) & 0xf)
35 #define OP_B(i) (i & 0xf)
37 static const char * reg_names[16] =
38 { "$fp", "$sp", "$r0", "$r1", "$r2", "$r3", "$r4", "$r5",
39 "$r6", "$r7", "$r8", "$r9", "$r10", "$r11", "$r12", "$r13" };
42 print_insn_moxie (bfd_vma addr, struct disassemble_info * info)
46 stream = info->stream;
47 const moxie_opc_info_t * opcode;
50 fpr = info->fprintf_func;
52 if ((status = info->read_memory_func (addr, buffer, 2, info)))
54 iword = bfd_getb16 (buffer);
56 /* Form 1 instructions have the high bit set to 0. */
57 if ((iword & (1<<15)) == 0)
59 /* Extract the Form 1 opcode. */
60 opcode = &moxie_form1_opc_info[iword >> 8];
61 switch (opcode->itype)
64 fpr (stream, "%s", opcode->name);
67 fpr (stream, "%s\t%s", opcode->name,
68 reg_names[OP_A(iword)]);
71 fpr (stream, "%s\t%s, %s", opcode->name,
72 reg_names[OP_A(iword)],
73 reg_names[OP_B(iword)]);
78 if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
80 imm = bfd_getb32 (buffer);
81 fpr (stream, "%s\t%s, 0x%x", opcode->name,
82 reg_names[OP_A(iword)], imm);
89 if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
91 imm = bfd_getb32 (buffer);
92 fpr (stream, "%s\t0x%x", opcode->name, imm);
99 if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
101 imm = bfd_getb32 (buffer);
102 fpr (stream, "%s\t", opcode->name);
103 info->print_address_func ((bfd_vma) imm, info);
108 fpr (stream, "%s\t(%s), %s", opcode->name,
109 reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
112 fpr (stream, "%s\t%s, (%s)", opcode->name,
113 reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
118 if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
120 imm = bfd_getb32 (buffer);
121 fpr (stream, "%s\t0x%x, %s",
122 opcode->name, imm, reg_names[OP_A(iword)]);
129 if ((status = info->read_memory_func (addr+2, buffer, 4, info)))
131 imm = bfd_getb32 (buffer);
132 fpr (stream, "%s\t0x%x(%s), %s", opcode->name,
134 reg_names[OP_A(iword)],
135 reg_names[OP_B(iword)]);
142 if ((status = info->read_memory_func (addr+2, buffer, 4, info)))
144 imm = bfd_getb32 (buffer);
145 fpr (stream, "%s\t%s, 0x%x(%s)",
147 reg_names[OP_A(iword)],
149 reg_names[OP_B(iword)]);
157 else if ((iword & (1<<14)) == 0)
159 /* Extract the Form 2 opcode. */
160 opcode = &moxie_form2_opc_info[(iword >> 12) & 3];
161 switch (opcode->itype)
164 fpr (stream, "%s\t%s, 0x%x",
166 reg_names[(iword >> 8) & 0xf],
167 iword & ((1 << 8) - 1));
170 fpr (stream, "%s", opcode->name);
178 /* Extract the Form 3 opcode. */
179 opcode = &moxie_form2_opc_info[(iword >> 12) & 3];
180 switch (opcode->itype)
183 fpr (stream, "%s", opcode->name);
193 info->memory_error_func (status, addr, info);