/src/binutils-gdb/opcodes/moxie-dis.c
Line | Count | Source |
1 | | /* Disassemble moxie instructions. |
2 | | Copyright (C) 2009-2026 Free Software Foundation, Inc. |
3 | | |
4 | | This file is part of the GNU opcodes library. |
5 | | |
6 | | This library is free software; you can redistribute it and/or modify |
7 | | it under the terms of the GNU General Public License as published by |
8 | | the Free Software Foundation; either version 3, or (at your option) |
9 | | any later version. |
10 | | |
11 | | It is distributed in the hope that it will be useful, but WITHOUT |
12 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
13 | | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
14 | | License for more details. |
15 | | |
16 | | You should have received a copy of the GNU General Public License |
17 | | along with this program; if not, write to the Free Software |
18 | | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
19 | | MA 02110-1301, USA. */ |
20 | | |
21 | | #include "sysdep.h" |
22 | | #include <stdio.h> |
23 | | |
24 | | #define STATIC_TABLE |
25 | | #define DEFINE_TABLE |
26 | | |
27 | | #include "opcode/moxie.h" |
28 | | #include "disassemble.h" |
29 | | |
30 | | static fprintf_ftype fpr; |
31 | | static void *stream; |
32 | | |
33 | | /* Macros to extract operands from the instruction word. */ |
34 | 17.4k | #define OP_A(i) ((i >> 4) & 0xf) |
35 | 13.1k | #define OP_B(i) (i & 0xf) |
36 | 6.73k | #define INST2OFFSET(o) (((((o) & 0x3ff) ^ 0x200) - 0x200) * 2) |
37 | | |
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" }; |
41 | | |
42 | | int |
43 | | print_insn_moxie (bfd_vma addr, struct disassemble_info * info) |
44 | 85.9k | { |
45 | 85.9k | int length = 2; |
46 | 85.9k | int status; |
47 | 85.9k | stream = info->stream; |
48 | 85.9k | const moxie_opc_info_t * opcode; |
49 | 85.9k | bfd_byte buffer[4]; |
50 | 85.9k | unsigned short iword; |
51 | 85.9k | fpr = info->fprintf_func; |
52 | | |
53 | 85.9k | if ((status = info->read_memory_func (addr, buffer, 2, info))) |
54 | 52 | goto fail; |
55 | | |
56 | 85.9k | if (info->endian == BFD_ENDIAN_BIG) |
57 | 23.4k | iword = bfd_getb16 (buffer); |
58 | 62.4k | else |
59 | 62.4k | iword = bfd_getl16 (buffer); |
60 | | |
61 | | /* Form 1 instructions have the high bit set to 0. */ |
62 | 85.9k | if ((iword & (1<<15)) == 0) |
63 | 57.3k | { |
64 | | /* Extract the Form 1 opcode. */ |
65 | 57.3k | opcode = &moxie_form1_opc_info[iword >> 8]; |
66 | 57.3k | switch (opcode->itype) |
67 | 57.3k | { |
68 | 2.28k | case MOXIE_F1_NARG: |
69 | 2.28k | fpr (stream, "%s", opcode->name); |
70 | 2.28k | break; |
71 | 852 | case MOXIE_F1_A: |
72 | 852 | fpr (stream, "%s\t%s", opcode->name, |
73 | 852 | reg_names[OP_A(iword)]); |
74 | 852 | break; |
75 | 7.57k | case MOXIE_F1_AB: |
76 | 7.57k | fpr (stream, "%s\t%s, %s", opcode->name, |
77 | 7.57k | reg_names[OP_A(iword)], |
78 | 7.57k | reg_names[OP_B(iword)]); |
79 | 7.57k | break; |
80 | 2.55k | case MOXIE_F1_A4: |
81 | 2.55k | { |
82 | 2.55k | unsigned imm; |
83 | 2.55k | if ((status = info->read_memory_func (addr + 2, buffer, 4, info))) |
84 | 4 | goto fail; |
85 | 2.55k | if (info->endian == BFD_ENDIAN_BIG) |
86 | 996 | imm = bfd_getb32 (buffer); |
87 | 1.55k | else |
88 | 1.55k | imm = bfd_getl32 (buffer); |
89 | 2.55k | fpr (stream, "%s\t%s, 0x%x", opcode->name, |
90 | 2.55k | reg_names[OP_A(iword)], imm); |
91 | 2.55k | length = 6; |
92 | 2.55k | } |
93 | 0 | break; |
94 | 653 | case MOXIE_F1_4: |
95 | 653 | { |
96 | 653 | unsigned imm; |
97 | 653 | if ((status = info->read_memory_func (addr + 2, buffer, 4, info))) |
98 | 5 | goto fail; |
99 | 648 | if (info->endian == BFD_ENDIAN_BIG) |
100 | 49 | imm = bfd_getb32 (buffer); |
101 | 599 | else |
102 | 599 | imm = bfd_getl32 (buffer); |
103 | 648 | fpr (stream, "%s\t0x%x", opcode->name, imm); |
104 | 648 | length = 6; |
105 | 648 | } |
106 | 0 | break; |
107 | 723 | case MOXIE_F1_M: |
108 | 723 | { |
109 | 723 | unsigned imm; |
110 | 723 | if ((status = info->read_memory_func (addr + 2, buffer, 4, info))) |
111 | 7 | goto fail; |
112 | 716 | if (info->endian == BFD_ENDIAN_BIG) |
113 | 146 | imm = bfd_getb32 (buffer); |
114 | 570 | else |
115 | 570 | imm = bfd_getl32 (buffer); |
116 | 716 | fpr (stream, "%s\t", opcode->name); |
117 | 716 | info->print_address_func ((bfd_vma) imm, info); |
118 | 716 | length = 6; |
119 | 716 | } |
120 | 0 | break; |
121 | 1.16k | case MOXIE_F1_AiB: |
122 | 1.16k | fpr (stream, "%s\t(%s), %s", opcode->name, |
123 | 1.16k | reg_names[OP_A(iword)], reg_names[OP_B(iword)]); |
124 | 1.16k | break; |
125 | 1.15k | case MOXIE_F1_ABi: |
126 | 1.15k | fpr (stream, "%s\t%s, (%s)", opcode->name, |
127 | 1.15k | reg_names[OP_A(iword)], reg_names[OP_B(iword)]); |
128 | 1.15k | break; |
129 | 818 | case MOXIE_F1_4A: |
130 | 818 | { |
131 | 818 | unsigned imm; |
132 | 818 | if ((status = info->read_memory_func (addr + 2, buffer, 4, info))) |
133 | 4 | goto fail; |
134 | 814 | if (info->endian == BFD_ENDIAN_BIG) |
135 | 254 | imm = bfd_getb32 (buffer); |
136 | 560 | else |
137 | 560 | imm = bfd_getl32 (buffer); |
138 | 814 | fpr (stream, "%s\t0x%x, %s", |
139 | 814 | opcode->name, imm, reg_names[OP_A(iword)]); |
140 | 814 | length = 6; |
141 | 814 | } |
142 | 0 | break; |
143 | 948 | case MOXIE_F1_AiB2: |
144 | 948 | { |
145 | 948 | unsigned imm; |
146 | 948 | if ((status = info->read_memory_func (addr+2, buffer, 2, info))) |
147 | 3 | goto fail; |
148 | 945 | if (info->endian == BFD_ENDIAN_BIG) |
149 | 169 | imm = bfd_getb16 (buffer); |
150 | 776 | else |
151 | 776 | imm = bfd_getl16 (buffer); |
152 | 945 | fpr (stream, "%s\t0x%x(%s), %s", opcode->name, |
153 | 945 | imm, |
154 | 945 | reg_names[OP_A(iword)], |
155 | 945 | reg_names[OP_B(iword)]); |
156 | 945 | length = 4; |
157 | 945 | } |
158 | 0 | break; |
159 | 2.34k | case MOXIE_F1_ABi2: |
160 | 2.34k | { |
161 | 2.34k | unsigned imm; |
162 | 2.34k | if ((status = info->read_memory_func (addr+2, buffer, 2, info))) |
163 | 1 | goto fail; |
164 | 2.34k | if (info->endian == BFD_ENDIAN_BIG) |
165 | 229 | imm = bfd_getb16 (buffer); |
166 | 2.11k | else |
167 | 2.11k | imm = bfd_getl16 (buffer); |
168 | 2.34k | fpr (stream, "%s\t%s, 0x%x(%s)", |
169 | 2.34k | opcode->name, |
170 | 2.34k | reg_names[OP_A(iword)], |
171 | 2.34k | imm, |
172 | 2.34k | reg_names[OP_B(iword)]); |
173 | 2.34k | length = 4; |
174 | 2.34k | } |
175 | 0 | break; |
176 | 36.2k | case MOXIE_BAD: |
177 | 36.2k | fpr (stream, "bad"); |
178 | 36.2k | break; |
179 | 0 | default: |
180 | 0 | abort(); |
181 | 57.3k | } |
182 | 57.3k | } |
183 | 28.6k | else if ((iword & (1<<14)) == 0) |
184 | 10.5k | { |
185 | | /* Extract the Form 2 opcode. */ |
186 | 10.5k | opcode = &moxie_form2_opc_info[(iword >> 12) & 3]; |
187 | 10.5k | switch (opcode->itype) |
188 | 10.5k | { |
189 | 10.5k | case MOXIE_F2_A8V: |
190 | 10.5k | fpr (stream, "%s\t%s, 0x%x", |
191 | 10.5k | opcode->name, |
192 | 10.5k | reg_names[(iword >> 8) & 0xf], |
193 | 10.5k | iword & ((1 << 8) - 1)); |
194 | 10.5k | break; |
195 | 0 | case MOXIE_F2_NARG: |
196 | 0 | fpr (stream, "%s", opcode->name); |
197 | 0 | break; |
198 | 0 | case MOXIE_BAD: |
199 | 0 | fpr (stream, "bad"); |
200 | 0 | break; |
201 | 0 | default: |
202 | 0 | abort(); |
203 | 10.5k | } |
204 | 10.5k | } |
205 | 18.0k | else |
206 | 18.0k | { |
207 | | /* Extract the Form 3 opcode. */ |
208 | 18.0k | opcode = &moxie_form3_opc_info[(iword >> 10) & 15]; |
209 | 18.0k | switch (opcode->itype) |
210 | 18.0k | { |
211 | 6.73k | case MOXIE_F3_PCREL: |
212 | 6.73k | fpr (stream, "%s\t", opcode->name); |
213 | 6.73k | info->print_address_func (addr + INST2OFFSET (iword) + 2, info); |
214 | 6.73k | break; |
215 | 11.3k | case MOXIE_BAD: |
216 | 11.3k | fpr (stream, "bad"); |
217 | 11.3k | break; |
218 | 0 | default: |
219 | 0 | abort(); |
220 | 18.0k | } |
221 | 18.0k | } |
222 | | |
223 | 85.9k | return length; |
224 | | |
225 | 76 | fail: |
226 | 76 | info->memory_error_func (status, addr, info); |
227 | 76 | return -1; |
228 | 85.9k | } |