/src/binutils-gdb/opcodes/moxie-dis.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Disassemble moxie instructions. |
2 | | Copyright (C) 2009-2023 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 | 7.49k | #define OP_A(i) ((i >> 4) & 0xf) |
35 | 5.62k | #define OP_B(i) (i & 0xf) |
36 | 3.70k | #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 | 42.8k | { |
45 | 42.8k | int length = 2; |
46 | 42.8k | int status; |
47 | 42.8k | stream = info->stream; |
48 | 42.8k | const moxie_opc_info_t * opcode; |
49 | 42.8k | bfd_byte buffer[4]; |
50 | 42.8k | unsigned short iword; |
51 | 42.8k | fpr = info->fprintf_func; |
52 | | |
53 | 42.8k | if ((status = info->read_memory_func (addr, buffer, 2, info))) |
54 | 47 | goto fail; |
55 | | |
56 | 42.7k | if (info->endian == BFD_ENDIAN_BIG) |
57 | 6.04k | iword = bfd_getb16 (buffer); |
58 | 36.7k | else |
59 | 36.7k | iword = bfd_getl16 (buffer); |
60 | | |
61 | | /* Form 1 instructions have the high bit set to 0. */ |
62 | 42.7k | if ((iword & (1<<15)) == 0) |
63 | 26.5k | { |
64 | | /* Extract the Form 1 opcode. */ |
65 | 26.5k | opcode = &moxie_form1_opc_info[iword >> 8]; |
66 | 26.5k | switch (opcode->itype) |
67 | 26.5k | { |
68 | 726 | case MOXIE_F1_NARG: |
69 | 726 | fpr (stream, "%s", opcode->name); |
70 | 726 | break; |
71 | 320 | case MOXIE_F1_A: |
72 | 320 | fpr (stream, "%s\t%s", opcode->name, |
73 | 320 | reg_names[OP_A(iword)]); |
74 | 320 | break; |
75 | 3.58k | case MOXIE_F1_AB: |
76 | 3.58k | fpr (stream, "%s\t%s, %s", opcode->name, |
77 | 3.58k | reg_names[OP_A(iword)], |
78 | 3.58k | reg_names[OP_B(iword)]); |
79 | 3.58k | break; |
80 | 1.30k | case MOXIE_F1_A4: |
81 | 1.30k | { |
82 | 1.30k | unsigned imm; |
83 | 1.30k | if ((status = info->read_memory_func (addr + 2, buffer, 4, info))) |
84 | 9 | goto fail; |
85 | 1.29k | if (info->endian == BFD_ENDIAN_BIG) |
86 | 595 | imm = bfd_getb32 (buffer); |
87 | 701 | else |
88 | 701 | imm = bfd_getl32 (buffer); |
89 | 1.29k | fpr (stream, "%s\t%s, 0x%x", opcode->name, |
90 | 1.29k | reg_names[OP_A(iword)], imm); |
91 | 1.29k | length = 6; |
92 | 1.29k | } |
93 | 0 | break; |
94 | 323 | case MOXIE_F1_4: |
95 | 323 | { |
96 | 323 | unsigned imm; |
97 | 323 | if ((status = info->read_memory_func (addr + 2, buffer, 4, info))) |
98 | 5 | goto fail; |
99 | 318 | if (info->endian == BFD_ENDIAN_BIG) |
100 | 40 | imm = bfd_getb32 (buffer); |
101 | 278 | else |
102 | 278 | imm = bfd_getl32 (buffer); |
103 | 318 | fpr (stream, "%s\t0x%x", opcode->name, imm); |
104 | 318 | length = 6; |
105 | 318 | } |
106 | 0 | break; |
107 | 598 | case MOXIE_F1_M: |
108 | 598 | { |
109 | 598 | unsigned imm; |
110 | 598 | if ((status = info->read_memory_func (addr + 2, buffer, 4, info))) |
111 | 4 | goto fail; |
112 | 594 | if (info->endian == BFD_ENDIAN_BIG) |
113 | 59 | imm = bfd_getb32 (buffer); |
114 | 535 | else |
115 | 535 | imm = bfd_getl32 (buffer); |
116 | 594 | fpr (stream, "%s\t", opcode->name); |
117 | 594 | info->print_address_func ((bfd_vma) imm, info); |
118 | 594 | length = 6; |
119 | 594 | } |
120 | 0 | break; |
121 | 626 | case MOXIE_F1_AiB: |
122 | 626 | fpr (stream, "%s\t(%s), %s", opcode->name, |
123 | 626 | reg_names[OP_A(iword)], reg_names[OP_B(iword)]); |
124 | 626 | break; |
125 | 336 | case MOXIE_F1_ABi: |
126 | 336 | fpr (stream, "%s\t%s, (%s)", opcode->name, |
127 | 336 | reg_names[OP_A(iword)], reg_names[OP_B(iword)]); |
128 | 336 | break; |
129 | 263 | case MOXIE_F1_4A: |
130 | 263 | { |
131 | 263 | unsigned imm; |
132 | 263 | if ((status = info->read_memory_func (addr + 2, buffer, 4, info))) |
133 | 3 | goto fail; |
134 | 260 | if (info->endian == BFD_ENDIAN_BIG) |
135 | 45 | imm = bfd_getb32 (buffer); |
136 | 215 | else |
137 | 215 | imm = bfd_getl32 (buffer); |
138 | 260 | fpr (stream, "%s\t0x%x, %s", |
139 | 260 | opcode->name, imm, reg_names[OP_A(iword)]); |
140 | 260 | length = 6; |
141 | 260 | } |
142 | 0 | break; |
143 | 402 | case MOXIE_F1_AiB2: |
144 | 402 | { |
145 | 402 | unsigned imm; |
146 | 402 | if ((status = info->read_memory_func (addr+2, buffer, 2, info))) |
147 | 3 | goto fail; |
148 | 399 | if (info->endian == BFD_ENDIAN_BIG) |
149 | 57 | imm = bfd_getb16 (buffer); |
150 | 342 | else |
151 | 342 | imm = bfd_getl16 (buffer); |
152 | 399 | fpr (stream, "%s\t0x%x(%s), %s", opcode->name, |
153 | 399 | imm, |
154 | 399 | reg_names[OP_A(iword)], |
155 | 399 | reg_names[OP_B(iword)]); |
156 | 399 | length = 4; |
157 | 399 | } |
158 | 0 | break; |
159 | 677 | case MOXIE_F1_ABi2: |
160 | 677 | { |
161 | 677 | unsigned imm; |
162 | 677 | if ((status = info->read_memory_func (addr+2, buffer, 2, info))) |
163 | 2 | goto fail; |
164 | 675 | if (info->endian == BFD_ENDIAN_BIG) |
165 | 56 | imm = bfd_getb16 (buffer); |
166 | 619 | else |
167 | 619 | imm = bfd_getl16 (buffer); |
168 | 675 | fpr (stream, "%s\t%s, 0x%x(%s)", |
169 | 675 | opcode->name, |
170 | 675 | reg_names[OP_A(iword)], |
171 | 675 | imm, |
172 | 675 | reg_names[OP_B(iword)]); |
173 | 675 | length = 4; |
174 | 675 | } |
175 | 0 | break; |
176 | 17.4k | case MOXIE_BAD: |
177 | 17.4k | fpr (stream, "bad"); |
178 | 17.4k | break; |
179 | 0 | default: |
180 | 0 | abort(); |
181 | 26.5k | } |
182 | 26.5k | } |
183 | 16.1k | else if ((iword & (1<<14)) == 0) |
184 | 6.38k | { |
185 | | /* Extract the Form 2 opcode. */ |
186 | 6.38k | opcode = &moxie_form2_opc_info[(iword >> 12) & 3]; |
187 | 6.38k | switch (opcode->itype) |
188 | 6.38k | { |
189 | 6.38k | case MOXIE_F2_A8V: |
190 | 6.38k | fpr (stream, "%s\t%s, 0x%x", |
191 | 6.38k | opcode->name, |
192 | 6.38k | reg_names[(iword >> 8) & 0xf], |
193 | 6.38k | iword & ((1 << 8) - 1)); |
194 | 6.38k | 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 | 6.38k | } |
204 | 6.38k | } |
205 | 9.79k | else |
206 | 9.79k | { |
207 | | /* Extract the Form 3 opcode. */ |
208 | 9.79k | opcode = &moxie_form3_opc_info[(iword >> 10) & 15]; |
209 | 9.79k | switch (opcode->itype) |
210 | 9.79k | { |
211 | 3.70k | case MOXIE_F3_PCREL: |
212 | 3.70k | fpr (stream, "%s\t", opcode->name); |
213 | 3.70k | info->print_address_func (addr + INST2OFFSET (iword) + 2, info); |
214 | 3.70k | break; |
215 | 6.09k | case MOXIE_BAD: |
216 | 6.09k | fpr (stream, "bad"); |
217 | 6.09k | break; |
218 | 0 | default: |
219 | 0 | abort(); |
220 | 9.79k | } |
221 | 9.79k | } |
222 | | |
223 | 42.7k | return length; |
224 | | |
225 | 73 | fail: |
226 | 73 | info->memory_error_func (status, addr, info); |
227 | 73 | return -1; |
228 | 42.7k | } |