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)
36 #define INST2OFFSET(o) ((((signed short)((o & ((1<<10)-1))<<6))>>6)<<1)
38 static const char * reg_names
[16] =
39 { "$fp", "$sp", "$r0", "$r1", "$r2", "$r3", "$r4", "$r5",
40 "$r6", "$r7", "$r8", "$r9", "$r10", "$r11", "$r12", "$r13" };
43 print_insn_moxie (bfd_vma addr
, struct disassemble_info
* info
)
47 stream
= info
->stream
;
48 const moxie_opc_info_t
* opcode
;
51 fpr
= info
->fprintf_func
;
53 if ((status
= info
->read_memory_func (addr
, buffer
, 2, info
)))
55 iword
= bfd_getb16 (buffer
);
57 /* Form 1 instructions have the high bit set to 0. */
58 if ((iword
& (1<<15)) == 0)
60 /* Extract the Form 1 opcode. */
61 opcode
= &moxie_form1_opc_info
[iword
>> 8];
62 switch (opcode
->itype
)
65 fpr (stream
, "%s", opcode
->name
);
68 fpr (stream
, "%s\t%s", opcode
->name
,
69 reg_names
[OP_A(iword
)]);
72 fpr (stream
, "%s\t%s, %s", opcode
->name
,
73 reg_names
[OP_A(iword
)],
74 reg_names
[OP_B(iword
)]);
79 if ((status
= info
->read_memory_func (addr
+ 2, buffer
, 4, info
)))
81 imm
= bfd_getb32 (buffer
);
82 fpr (stream
, "%s\t%s, 0x%x", opcode
->name
,
83 reg_names
[OP_A(iword
)], imm
);
90 if ((status
= info
->read_memory_func (addr
+ 2, buffer
, 4, info
)))
92 imm
= bfd_getb32 (buffer
);
93 fpr (stream
, "%s\t0x%x", opcode
->name
, imm
);
100 if ((status
= info
->read_memory_func (addr
+ 2, buffer
, 4, info
)))
102 imm
= bfd_getb32 (buffer
);
103 fpr (stream
, "%s\t", opcode
->name
);
104 info
->print_address_func ((bfd_vma
) imm
, info
);
109 fpr (stream
, "%s\t(%s), %s", opcode
->name
,
110 reg_names
[OP_A(iword
)], reg_names
[OP_B(iword
)]);
113 fpr (stream
, "%s\t%s, (%s)", opcode
->name
,
114 reg_names
[OP_A(iword
)], reg_names
[OP_B(iword
)]);
119 if ((status
= info
->read_memory_func (addr
+ 2, buffer
, 4, info
)))
121 imm
= bfd_getb32 (buffer
);
122 fpr (stream
, "%s\t0x%x, %s",
123 opcode
->name
, imm
, reg_names
[OP_A(iword
)]);
130 if ((status
= info
->read_memory_func (addr
+2, buffer
, 4, info
)))
132 imm
= bfd_getb32 (buffer
);
133 fpr (stream
, "%s\t0x%x(%s), %s", opcode
->name
,
135 reg_names
[OP_A(iword
)],
136 reg_names
[OP_B(iword
)]);
143 if ((status
= info
->read_memory_func (addr
+2, buffer
, 4, info
)))
145 imm
= bfd_getb32 (buffer
);
146 fpr (stream
, "%s\t%s, 0x%x(%s)",
148 reg_names
[OP_A(iword
)],
150 reg_names
[OP_B(iword
)]);
158 else if ((iword
& (1<<14)) == 0)
160 /* Extract the Form 2 opcode. */
161 opcode
= &moxie_form2_opc_info
[(iword
>> 12) & 3];
162 switch (opcode
->itype
)
165 fpr (stream
, "%s\t%s, 0x%x",
167 reg_names
[(iword
>> 8) & 0xf],
168 iword
& ((1 << 8) - 1));
171 fpr (stream
, "%s", opcode
->name
);
179 /* Extract the Form 3 opcode. */
180 opcode
= &moxie_form3_opc_info
[(iword
>> 10) & 15];
181 switch (opcode
->itype
)
184 fpr (stream
, "%s\t", opcode
->name
);
185 info
->print_address_func ((bfd_vma
) (addr
+ INST2OFFSET(iword
)),
196 info
->memory_error_func (status
, addr
, info
);
This page took 0.032458 seconds and 4 git commands to generate.