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);
97 fpr (stream, "%s\t(%s), %s", opcode->name,
98 reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
101 fpr (stream, "%s\t%s, (%s)", opcode->name,
102 reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
107 if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
109 imm = bfd_getb32 (buffer);
110 fpr (stream, "%s\t0x%x, %s",
111 opcode->name, imm, reg_names[OP_A(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), %s", opcode->name,
123 reg_names[OP_A(iword)],
124 reg_names[OP_B(iword)]);
131 if ((status = info->read_memory_func (addr+2, buffer, 4, info)))
133 imm = bfd_getb32 (buffer);
134 fpr (stream, "%s\t%s, 0x%x(%s)",
136 reg_names[OP_A(iword)],
138 reg_names[OP_B(iword)]);
146 else if ((iword & (1<<14)) == 0)
148 /* Extract the Form 2 opcode. */
149 opcode = &moxie_form2_opc_info[(iword >> 12) & 3];
150 switch (opcode->itype)
153 fpr (stream, "%s\t%s, 0x%x",
155 reg_names[(iword >> 8) & 0xf],
156 iword & ((1 << 8) - 1));
159 fpr (stream, "%s", opcode->name);
167 /* Extract the Form 3 opcode. */
168 opcode = &moxie_form2_opc_info[(iword >> 12) & 3];
169 switch (opcode->itype)
172 fpr (stream, "%s", opcode->name);
182 info->memory_error_func (status, addr, info);