/src/binutils-gdb/opcodes/sh-dis.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Disassemble SH instructions. |
2 | | Copyright (C) 1993-2025 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 file; see the file COPYING. If not, write to the |
18 | | Free Software Foundation, 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 "sh-opc.h" |
28 | | #include "disassemble.h" |
29 | | |
30 | | static void |
31 | | print_movxy (const sh_opcode_info *op, |
32 | | int rn, |
33 | | int rm, |
34 | | fprintf_ftype fprintf_fn, |
35 | | void *stream) |
36 | 80.9k | { |
37 | 80.9k | int n; |
38 | | |
39 | 80.9k | fprintf_fn (stream, "%s\t", op->name); |
40 | 242k | for (n = 0; n < 2; n++) |
41 | 161k | { |
42 | 161k | switch (op->arg[n]) |
43 | 161k | { |
44 | 0 | case A_IND_N: |
45 | 6.61k | case AX_IND_N: |
46 | 8.14k | case AXY_IND_N: |
47 | 17.5k | case AY_IND_N: |
48 | 19.0k | case AYX_IND_N: |
49 | 19.0k | fprintf_fn (stream, "@r%d", rn); |
50 | 19.0k | break; |
51 | 0 | case A_INC_N: |
52 | 14.0k | case AX_INC_N: |
53 | 18.3k | case AXY_INC_N: |
54 | 27.4k | case AY_INC_N: |
55 | 28.8k | case AYX_INC_N: |
56 | 28.8k | fprintf_fn (stream, "@r%d+", rn); |
57 | 28.8k | break; |
58 | 8.33k | case AX_PMOD_N: |
59 | 9.26k | case AXY_PMOD_N: |
60 | 9.26k | fprintf_fn (stream, "@r%d+r8", rn); |
61 | 9.26k | break; |
62 | 10.1k | case AY_PMOD_N: |
63 | 11.9k | case AYX_PMOD_N: |
64 | 11.9k | fprintf_fn (stream, "@r%d+r9", rn); |
65 | 11.9k | break; |
66 | 36.3k | case DSP_REG_A_M: |
67 | 36.3k | fprintf_fn (stream, "a%c", '0' + rm); |
68 | 36.3k | break; |
69 | 22.9k | case DSP_REG_X: |
70 | 22.9k | fprintf_fn (stream, "x%c", '0' + rm); |
71 | 22.9k | break; |
72 | 21.9k | case DSP_REG_Y: |
73 | 21.9k | fprintf_fn (stream, "y%c", '0' + rm); |
74 | 21.9k | break; |
75 | 5.00k | case DSP_REG_AX: |
76 | 5.00k | fprintf_fn (stream, "%c%c", |
77 | 5.00k | (rm & 1) ? 'x' : 'a', |
78 | 5.00k | (rm & 2) ? '1' : '0'); |
79 | 5.00k | break; |
80 | 1.76k | case DSP_REG_XY: |
81 | 1.76k | fprintf_fn (stream, "%c%c", |
82 | 1.76k | (rm & 1) ? 'y' : 'x', |
83 | 1.76k | (rm & 2) ? '1' : '0'); |
84 | 1.76k | break; |
85 | 3.23k | case DSP_REG_AY: |
86 | 3.23k | fprintf_fn (stream, "%c%c", |
87 | 3.23k | (rm & 2) ? 'y' : 'a', |
88 | 3.23k | (rm & 1) ? '1' : '0'); |
89 | 3.23k | break; |
90 | 1.43k | case DSP_REG_YX: |
91 | 1.43k | fprintf_fn (stream, "%c%c", |
92 | 1.43k | (rm & 2) ? 'x' : 'y', |
93 | 1.43k | (rm & 1) ? '1' : '0'); |
94 | 1.43k | break; |
95 | 0 | default: |
96 | 0 | abort (); |
97 | 161k | } |
98 | 161k | if (n == 0) |
99 | 80.9k | fprintf_fn (stream, ","); |
100 | 161k | } |
101 | 80.9k | } |
102 | | |
103 | | /* Print a double data transfer insn. INSN is just the lower three |
104 | | nibbles of the insn, i.e. field a and the bit that indicates if |
105 | | a parallel processing insn follows. */ |
106 | | |
107 | | static void |
108 | | print_insn_ddt (int insn, struct disassemble_info *info) |
109 | 64.3k | { |
110 | 64.3k | fprintf_ftype fprintf_fn = info->fprintf_func; |
111 | 64.3k | void *stream = info->stream; |
112 | | |
113 | | /* If this is just a nop, make sure to emit something. */ |
114 | 64.3k | if (insn == 0x000) |
115 | 931 | { |
116 | 931 | fprintf_fn (stream, "nopx\tnopy"); |
117 | 931 | return; |
118 | 931 | } |
119 | | |
120 | | /* If a parallel processing insn was printed before, |
121 | | and we got a non-nop, emit a tab. */ |
122 | 63.4k | if ((insn & 0x800) && (insn & 0x3ff)) |
123 | 36.5k | fprintf_fn (stream, "\t"); |
124 | | |
125 | | /* Check if either the x or y part is invalid. */ |
126 | 63.4k | if (((insn & 3) != 0 && (insn & 0xc) == 0 && (insn & 0x2a0)) |
127 | 63.4k | || ((insn & 3) == 0 && (insn & 0xc) != 0 && (insn & 0x150))) |
128 | 20.9k | if (info->mach != bfd_mach_sh_dsp |
129 | 20.9k | && info->mach != bfd_mach_sh3_dsp) |
130 | 11.4k | { |
131 | 11.4k | static const sh_opcode_info *first_movx, *first_movy; |
132 | 11.4k | const sh_opcode_info *op; |
133 | 11.4k | int is_movy; |
134 | | |
135 | 11.4k | if (! first_movx) |
136 | 2 | { |
137 | 554 | for (first_movx = sh_table; first_movx->nibbles[1] != MOVX_NOPY;) |
138 | 552 | first_movx++; |
139 | 38 | for (first_movy = first_movx; first_movy->nibbles[1] != MOVY_NOPX;) |
140 | 36 | first_movy++; |
141 | 2 | } |
142 | | |
143 | 11.4k | is_movy = ((insn & 3) != 0); |
144 | | |
145 | 11.4k | if (is_movy) |
146 | 4.66k | op = first_movy; |
147 | 6.76k | else |
148 | 6.76k | op = first_movx; |
149 | | |
150 | 97.1k | while (op->nibbles[2] != (unsigned) ((insn >> 4) & 3) |
151 | 97.1k | || op->nibbles[3] != (unsigned) (insn & 0xf)) |
152 | 85.7k | op++; |
153 | | |
154 | 11.4k | print_movxy (op, |
155 | 11.4k | (4 * ((insn & (is_movy ? 0x200 : 0x100)) == 0) |
156 | 11.4k | + 2 * is_movy |
157 | 11.4k | + 1 * ((insn & (is_movy ? 0x100 : 0x200)) != 0)), |
158 | 11.4k | (insn >> 6) & 3, |
159 | 11.4k | fprintf_fn, stream); |
160 | 11.4k | } |
161 | 9.53k | else |
162 | 9.53k | fprintf_fn (stream, ".word 0x%x", insn | 0xf000); |
163 | 42.4k | else |
164 | 42.4k | { |
165 | 42.4k | static const sh_opcode_info *first_movx, *first_movy; |
166 | 42.4k | const sh_opcode_info *opx, *opy; |
167 | 42.4k | unsigned int insn_x, insn_y; |
168 | | |
169 | 42.4k | if (! first_movx) |
170 | 2 | { |
171 | 542 | for (first_movx = sh_table; first_movx->nibbles[1] != MOVX;) |
172 | 540 | first_movx++; |
173 | 38 | for (first_movy = first_movx; first_movy->nibbles[1] != MOVY;) |
174 | 36 | first_movy++; |
175 | 2 | } |
176 | 42.4k | insn_x = (insn >> 2) & 0xb; |
177 | 42.4k | if (insn_x) |
178 | 35.0k | { |
179 | 354k | for (opx = first_movx; opx->nibbles[2] != insn_x;) |
180 | 319k | opx++; |
181 | 35.0k | print_movxy (opx, ((insn >> 9) & 1) + 4, (insn >> 7) & 1, |
182 | 35.0k | fprintf_fn, stream); |
183 | 35.0k | } |
184 | 42.4k | insn_y = (insn & 3) | ((insn >> 1) & 8); |
185 | 42.4k | if (insn_y) |
186 | 34.4k | { |
187 | 34.4k | if (insn_x) |
188 | 31.8k | fprintf_fn (stream, "\t"); |
189 | 240k | for (opy = first_movy; opy->nibbles[2] != insn_y;) |
190 | 206k | opy++; |
191 | 34.4k | print_movxy (opy, ((insn >> 8) & 1) + 6, (insn >> 6) & 1, |
192 | 34.4k | fprintf_fn, stream); |
193 | 34.4k | } |
194 | 42.4k | if (!insn_x && !insn_y && ((insn & 0x3ff) != 0 || (insn & 0x800) == 0)) |
195 | 3.69k | fprintf_fn (stream, ".word 0x%x", insn | 0xf000); |
196 | 42.4k | } |
197 | 63.4k | } |
198 | | |
199 | | static void |
200 | | print_dsp_reg (int rm, fprintf_ftype fprintf_fn, void *stream) |
201 | 36.8k | { |
202 | 36.8k | switch (rm) |
203 | 36.8k | { |
204 | 1.10k | case A_A1_NUM: |
205 | 1.10k | fprintf_fn (stream, "a1"); |
206 | 1.10k | break; |
207 | 1.75k | case A_A0_NUM: |
208 | 1.75k | fprintf_fn (stream, "a0"); |
209 | 1.75k | break; |
210 | 2.65k | case A_X0_NUM: |
211 | 2.65k | fprintf_fn (stream, "x0"); |
212 | 2.65k | break; |
213 | 3.06k | case A_X1_NUM: |
214 | 3.06k | fprintf_fn (stream, "x1"); |
215 | 3.06k | break; |
216 | 3.77k | case A_Y0_NUM: |
217 | 3.77k | fprintf_fn (stream, "y0"); |
218 | 3.77k | break; |
219 | 2.15k | case A_Y1_NUM: |
220 | 2.15k | fprintf_fn (stream, "y1"); |
221 | 2.15k | break; |
222 | 1.52k | case A_M0_NUM: |
223 | 1.52k | fprintf_fn (stream, "m0"); |
224 | 1.52k | break; |
225 | 1.32k | case A_A1G_NUM: |
226 | 1.32k | fprintf_fn (stream, "a1g"); |
227 | 1.32k | break; |
228 | 1.77k | case A_M1_NUM: |
229 | 1.77k | fprintf_fn (stream, "m1"); |
230 | 1.77k | break; |
231 | 4.99k | case A_A0G_NUM: |
232 | 4.99k | fprintf_fn (stream, "a0g"); |
233 | 4.99k | break; |
234 | 12.7k | default: |
235 | 12.7k | fprintf_fn (stream, "0x%x", rm); |
236 | 12.7k | break; |
237 | 36.8k | } |
238 | 36.8k | } |
239 | | |
240 | | static void |
241 | | print_insn_ppi (int field_b, struct disassemble_info *info) |
242 | 37.6k | { |
243 | 37.6k | static char *sx_tab[] = { "x0", "x1", "a0", "a1" }; |
244 | 37.6k | static char *sy_tab[] = { "y0", "y1", "m0", "m1" }; |
245 | 37.6k | fprintf_ftype fprintf_fn = info->fprintf_func; |
246 | 37.6k | void *stream = info->stream; |
247 | 37.6k | unsigned int nib1, nib2, nib3; |
248 | 37.6k | unsigned int altnib1, nib4; |
249 | 37.6k | char *dc = NULL; |
250 | 37.6k | const sh_opcode_info *op; |
251 | | |
252 | 37.6k | if ((field_b & 0xe800) == 0) |
253 | 6.45k | { |
254 | 6.45k | fprintf_fn (stream, "psh%c\t#%d,", |
255 | 6.45k | field_b & 0x1000 ? 'a' : 'l', |
256 | 6.45k | (field_b >> 4) & 127); |
257 | 6.45k | print_dsp_reg (field_b & 0xf, fprintf_fn, stream); |
258 | 6.45k | return; |
259 | 6.45k | } |
260 | 31.2k | if ((field_b & 0xc000) == 0x4000 && (field_b & 0x3000) != 0x1000) |
261 | 3.82k | { |
262 | 3.82k | static char *du_tab[] = { "x0", "y0", "a0", "a1" }; |
263 | 3.82k | static char *se_tab[] = { "x0", "x1", "y0", "a1" }; |
264 | 3.82k | static char *sf_tab[] = { "y0", "y1", "x0", "a1" }; |
265 | 3.82k | static char *sg_tab[] = { "m0", "m1", "a0", "a1" }; |
266 | | |
267 | 3.82k | if (field_b & 0x2000) |
268 | 1.99k | fprintf_fn (stream, "p%s %s,%s,%s\t", |
269 | 1.99k | (field_b & 0x1000) ? "add" : "sub", |
270 | 1.99k | sx_tab[(field_b >> 6) & 3], |
271 | 1.99k | sy_tab[(field_b >> 4) & 3], |
272 | 1.99k | du_tab[(field_b >> 0) & 3]); |
273 | | |
274 | 1.83k | else if ((field_b & 0xf0) == 0x10 |
275 | 1.83k | && info->mach != bfd_mach_sh_dsp |
276 | 1.83k | && info->mach != bfd_mach_sh3_dsp) |
277 | 35 | fprintf_fn (stream, "pclr %s \t", du_tab[(field_b >> 0) & 3]); |
278 | | |
279 | 1.79k | else if ((field_b & 0xf3) != 0) |
280 | 1.57k | fprintf_fn (stream, ".word 0x%x\t", field_b); |
281 | | |
282 | 3.82k | fprintf_fn (stream, "pmuls%c%s,%s,%s", |
283 | 3.82k | field_b & 0x2000 ? ' ' : '\t', |
284 | 3.82k | se_tab[(field_b >> 10) & 3], |
285 | 3.82k | sf_tab[(field_b >> 8) & 3], |
286 | 3.82k | sg_tab[(field_b >> 2) & 3]); |
287 | 3.82k | return; |
288 | 3.82k | } |
289 | | |
290 | 27.4k | nib1 = PPIC; |
291 | 27.4k | nib2 = field_b >> 12 & 0xf; |
292 | 27.4k | nib3 = field_b >> 8 & 0xf; |
293 | 27.4k | nib4 = field_b >> 4 & 0xf; |
294 | 27.4k | switch (nib3 & 0x3) |
295 | 27.4k | { |
296 | 8.76k | case 0: |
297 | 8.76k | dc = ""; |
298 | 8.76k | nib1 = PPI3; |
299 | 8.76k | break; |
300 | 6.69k | case 1: |
301 | 6.69k | dc = ""; |
302 | 6.69k | break; |
303 | 5.59k | case 2: |
304 | 5.59k | dc = "dct "; |
305 | 5.59k | nib3 -= 1; |
306 | 5.59k | break; |
307 | 6.36k | case 3: |
308 | 6.36k | dc = "dcf "; |
309 | 6.36k | nib3 -= 2; |
310 | 6.36k | break; |
311 | 27.4k | } |
312 | 27.4k | if (nib1 == PPI3) |
313 | 8.76k | altnib1 = PPI3NC; |
314 | 18.6k | else |
315 | 18.6k | altnib1 = nib1; |
316 | 10.9M | for (op = sh_table; op->name; op++) |
317 | 10.9M | { |
318 | 10.9M | if ((op->nibbles[1] == nib1 || op->nibbles[1] == altnib1) |
319 | 10.9M | && op->nibbles[2] == nib2 |
320 | 10.9M | && op->nibbles[3] == nib3) |
321 | 15.4k | { |
322 | 15.4k | int n; |
323 | | |
324 | 15.4k | switch (op->nibbles[4]) |
325 | 15.4k | { |
326 | 11.8k | case HEX_0: |
327 | 11.8k | break; |
328 | 819 | case HEX_XX00: |
329 | 819 | if ((nib4 & 3) != 0) |
330 | 717 | continue; |
331 | 102 | break; |
332 | 1.19k | case HEX_1: |
333 | 1.19k | if ((nib4 & 3) != 1) |
334 | 811 | continue; |
335 | 381 | break; |
336 | 753 | case HEX_00YY: |
337 | 753 | if ((nib4 & 0xc) != 0) |
338 | 549 | continue; |
339 | 204 | break; |
340 | 834 | case HEX_4: |
341 | 834 | if ((nib4 & 0xc) != 4) |
342 | 671 | continue; |
343 | 163 | break; |
344 | 163 | default: |
345 | 0 | abort (); |
346 | 15.4k | } |
347 | 12.6k | fprintf_fn (stream, "%s%s\t", dc, op->name); |
348 | 39.1k | for (n = 0; n < 3 && op->arg[n] != A_END; n++) |
349 | 26.5k | { |
350 | 26.5k | if (n && op->arg[1] != A_END) |
351 | 13.8k | fprintf_fn (stream, ","); |
352 | 26.5k | switch (op->arg[n]) |
353 | 26.5k | { |
354 | 12.5k | case DSP_REG_N: |
355 | 12.5k | print_dsp_reg (field_b & 0xf, fprintf_fn, stream); |
356 | 12.5k | break; |
357 | 2.53k | case DSP_REG_X: |
358 | 2.53k | fprintf_fn (stream, "%s", sx_tab[(field_b >> 6) & 3]); |
359 | 2.53k | break; |
360 | 9.03k | case DSP_REG_Y: |
361 | 9.03k | fprintf_fn (stream, "%s", sy_tab[(field_b >> 4) & 3]); |
362 | 9.03k | break; |
363 | 481 | case A_MACH: |
364 | 481 | fprintf_fn (stream, "mach"); |
365 | 481 | break; |
366 | 1.91k | case A_MACL: |
367 | 1.91k | fprintf_fn (stream, "macl"); |
368 | 1.91k | break; |
369 | 0 | default: |
370 | 0 | abort (); |
371 | 26.5k | } |
372 | 26.5k | } |
373 | 12.6k | return; |
374 | 12.6k | } |
375 | 10.9M | } |
376 | | /* Not found. */ |
377 | 14.7k | fprintf_fn (stream, ".word 0x%x", field_b); |
378 | 14.7k | } |
379 | | |
380 | | /* FIXME mvs: movx insns print as ".word 0x%03x", insn & 0xfff |
381 | | (ie. the upper nibble is missing). */ |
382 | | |
383 | | int |
384 | | print_insn_sh (bfd_vma memaddr, struct disassemble_info *info) |
385 | 4.61M | { |
386 | 4.61M | fprintf_ftype fprintf_fn = info->fprintf_func; |
387 | 4.61M | void *stream = info->stream; |
388 | 4.61M | unsigned char insn[4]; |
389 | 4.61M | unsigned char nibs[8]; |
390 | 4.61M | int status; |
391 | 4.61M | bfd_vma relmask = ~(bfd_vma) 0; |
392 | 4.61M | const sh_opcode_info *op; |
393 | 4.61M | unsigned int target_arch; |
394 | 4.61M | int allow_op32; |
395 | | |
396 | 4.61M | switch (info->mach) |
397 | 4.61M | { |
398 | 596k | case bfd_mach_sh: |
399 | 596k | target_arch = arch_sh1; |
400 | | /* SH coff object files lack information about the machine type, so |
401 | | we end up with bfd_mach_sh unless it was set explicitly (which |
402 | | could have happended if this is a call from gdb or the simulator.) */ |
403 | 596k | if (info->symbols |
404 | 596k | && bfd_asymbol_flavour(*info->symbols) == bfd_target_coff_flavour) |
405 | 0 | target_arch = arch_sh4; |
406 | 596k | break; |
407 | 4.01M | default: |
408 | 4.01M | target_arch = sh_get_arch_from_bfd_mach (info->mach); |
409 | 4.61M | } |
410 | | |
411 | 4.61M | status = info->read_memory_func (memaddr, insn, 2, info); |
412 | | |
413 | 4.61M | if (status != 0) |
414 | 775 | { |
415 | 775 | info->memory_error_func (status, memaddr, info); |
416 | 775 | return -1; |
417 | 775 | } |
418 | | |
419 | 4.61M | if (info->endian == BFD_ENDIAN_LITTLE) |
420 | 1.71M | { |
421 | 1.71M | nibs[0] = (insn[1] >> 4) & 0xf; |
422 | 1.71M | nibs[1] = insn[1] & 0xf; |
423 | | |
424 | 1.71M | nibs[2] = (insn[0] >> 4) & 0xf; |
425 | 1.71M | nibs[3] = insn[0] & 0xf; |
426 | 1.71M | } |
427 | 2.90M | else |
428 | 2.90M | { |
429 | 2.90M | nibs[0] = (insn[0] >> 4) & 0xf; |
430 | 2.90M | nibs[1] = insn[0] & 0xf; |
431 | | |
432 | 2.90M | nibs[2] = (insn[1] >> 4) & 0xf; |
433 | 2.90M | nibs[3] = insn[1] & 0xf; |
434 | 2.90M | } |
435 | 4.61M | status = info->read_memory_func (memaddr + 2, insn + 2, 2, info); |
436 | 4.61M | if (status != 0) |
437 | 2.13k | allow_op32 = 0; |
438 | 4.61M | else |
439 | 4.61M | { |
440 | 4.61M | allow_op32 = 1; |
441 | | |
442 | 4.61M | if (info->endian == BFD_ENDIAN_LITTLE) |
443 | 1.71M | { |
444 | 1.71M | nibs[4] = (insn[3] >> 4) & 0xf; |
445 | 1.71M | nibs[5] = insn[3] & 0xf; |
446 | | |
447 | 1.71M | nibs[6] = (insn[2] >> 4) & 0xf; |
448 | 1.71M | nibs[7] = insn[2] & 0xf; |
449 | 1.71M | } |
450 | 2.90M | else |
451 | 2.90M | { |
452 | 2.90M | nibs[4] = (insn[2] >> 4) & 0xf; |
453 | 2.90M | nibs[5] = insn[2] & 0xf; |
454 | | |
455 | 2.90M | nibs[6] = (insn[3] >> 4) & 0xf; |
456 | 2.90M | nibs[7] = insn[3] & 0xf; |
457 | 2.90M | } |
458 | 4.61M | } |
459 | | |
460 | 4.61M | if (nibs[0] == 0xf && (nibs[1] & 4) == 0 |
461 | 4.61M | && SH_MERGE_ARCH_SET_VALID (target_arch, arch_sh_dsp_up)) |
462 | 64.3k | { |
463 | 64.3k | if (nibs[1] & 8) |
464 | 37.7k | { |
465 | 37.7k | int field_b; |
466 | | |
467 | 37.7k | status = info->read_memory_func (memaddr + 2, insn, 2, info); |
468 | | |
469 | 37.7k | if (status != 0) |
470 | 20 | { |
471 | 20 | info->memory_error_func (status, memaddr + 2, info); |
472 | 20 | return -1; |
473 | 20 | } |
474 | | |
475 | 37.6k | if (info->endian == BFD_ENDIAN_LITTLE) |
476 | 18.9k | field_b = insn[1] << 8 | insn[0]; |
477 | 18.7k | else |
478 | 18.7k | field_b = insn[0] << 8 | insn[1]; |
479 | | |
480 | 37.6k | print_insn_ppi (field_b, info); |
481 | 37.6k | print_insn_ddt ((nibs[1] << 8) | (nibs[2] << 4) | nibs[3], info); |
482 | 37.6k | return 4; |
483 | 37.7k | } |
484 | 26.6k | print_insn_ddt ((nibs[1] << 8) | (nibs[2] << 4) | nibs[3], info); |
485 | 26.6k | return 2; |
486 | 64.3k | } |
487 | 1.02G | for (op = sh_table; op->name; op++) |
488 | 1.02G | { |
489 | 1.02G | int n; |
490 | 1.02G | int imm = 0; |
491 | 1.02G | int rn = 0; |
492 | 1.02G | int rm = 0; |
493 | 1.02G | int rb = 0; |
494 | 1.02G | int disp_pc; |
495 | 1.02G | bfd_vma disp_pc_addr = 0; |
496 | 1.02G | int disp = 0; |
497 | 1.02G | int has_disp = 0; |
498 | 1.02G | int max_n = SH_MERGE_ARCH_SET (op->arch, arch_op32) ? 8 : 4; |
499 | | |
500 | 1.02G | if (!allow_op32 |
501 | 1.02G | && SH_MERGE_ARCH_SET (op->arch, arch_op32)) |
502 | 20.1k | goto fail; |
503 | | |
504 | 1.02G | if (!SH_MERGE_ARCH_SET_VALID (op->arch, target_arch)) |
505 | 405M | goto fail; |
506 | 790M | for (n = 0; n < max_n; n++) |
507 | 789M | { |
508 | 789M | int i = op->nibbles[n]; |
509 | | |
510 | 789M | if (i < 16) |
511 | 658M | { |
512 | 658M | if (nibs[n] == i) |
513 | 94.4M | continue; |
514 | 564M | goto fail; |
515 | 658M | } |
516 | 130M | switch (i) |
517 | 130M | { |
518 | 61.1k | case BRANCH_8: |
519 | 61.1k | imm = (nibs[2] << 4) | (nibs[3]); |
520 | 61.1k | if (imm & 0x80) |
521 | 20.5k | imm |= ~0xff; |
522 | 61.1k | imm = ((char) imm) * 2 + 4; |
523 | 61.1k | goto ok; |
524 | 221k | case BRANCH_12: |
525 | 221k | imm = ((nibs[1]) << 8) | (nibs[2] << 4) | (nibs[3]); |
526 | 221k | if (imm & 0x800) |
527 | 121k | imm |= ~0xfff; |
528 | 221k | imm = imm * 2 + 4; |
529 | 221k | goto ok; |
530 | 3.89k | case IMM0_3c: |
531 | 3.89k | if (nibs[3] & 0x8) |
532 | 476 | goto fail; |
533 | 3.41k | imm = nibs[3] & 0x7; |
534 | 3.41k | break; |
535 | 4.30k | case IMM0_3s: |
536 | 4.30k | if (!(nibs[3] & 0x8)) |
537 | 2.24k | goto fail; |
538 | 2.06k | imm = nibs[3] & 0x7; |
539 | 2.06k | break; |
540 | 45.0k | case IMM0_3Uc: |
541 | 45.0k | if (nibs[2] & 0x8) |
542 | 17.6k | goto fail; |
543 | 27.4k | imm = nibs[2] & 0x7; |
544 | 27.4k | break; |
545 | 0 | case IMM0_3Us: |
546 | 0 | if (!(nibs[2] & 0x8)) |
547 | 0 | goto fail; |
548 | 0 | imm = nibs[2] & 0x7; |
549 | 0 | break; |
550 | 592 | case DISP0_12: |
551 | 4.65k | case DISP1_12: |
552 | 4.65k | disp = (nibs[5] << 8) | (nibs[6] << 4) | nibs[7]; |
553 | 4.65k | has_disp = 1; |
554 | 4.65k | goto ok; |
555 | 488 | case DISP0_12BY2: |
556 | 720 | case DISP1_12BY2: |
557 | 720 | disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 1; |
558 | 720 | relmask = ~(bfd_vma) 1; |
559 | 720 | has_disp = 1; |
560 | 720 | goto ok; |
561 | 488 | case DISP0_12BY4: |
562 | 3.34k | case DISP1_12BY4: |
563 | 3.34k | disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 2; |
564 | 3.34k | relmask = ~(bfd_vma) 3; |
565 | 3.34k | has_disp = 1; |
566 | 3.34k | goto ok; |
567 | 915 | case DISP0_12BY8: |
568 | 6.13k | case DISP1_12BY8: |
569 | 6.13k | disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 3; |
570 | 6.13k | relmask = ~(bfd_vma) 7; |
571 | 6.13k | has_disp = 1; |
572 | 6.13k | goto ok; |
573 | 483k | case IMM0_20_4: |
574 | 483k | break; |
575 | 273k | case IMM0_20: |
576 | 273k | imm = ((nibs[2] << 16) | (nibs[4] << 12) | (nibs[5] << 8) |
577 | 273k | | (nibs[6] << 4) | nibs[7]); |
578 | 273k | if (imm & 0x80000) |
579 | 6.09k | imm -= 0x100000; |
580 | 273k | goto ok; |
581 | 20.4k | case IMM0_20BY8: |
582 | 20.4k | imm = ((nibs[2] << 16) | (nibs[4] << 12) | (nibs[5] << 8) |
583 | 20.4k | | (nibs[6] << 4) | nibs[7]); |
584 | 20.4k | imm <<= 8; |
585 | 20.4k | if (imm & 0x8000000) |
586 | 3.72k | imm -= 0x10000000; |
587 | 20.4k | goto ok; |
588 | 8.32k | case IMM0_4: |
589 | 28.6k | case IMM1_4: |
590 | 28.6k | imm = nibs[3]; |
591 | 28.6k | goto ok; |
592 | 8.50k | case IMM0_4BY2: |
593 | 17.9k | case IMM1_4BY2: |
594 | 17.9k | imm = nibs[3] << 1; |
595 | 17.9k | goto ok; |
596 | 155k | case IMM0_4BY4: |
597 | 372k | case IMM1_4BY4: |
598 | 372k | imm = nibs[3] << 2; |
599 | 372k | goto ok; |
600 | 398k | case IMM0_8S: |
601 | 411k | case IMM1_8: |
602 | 411k | imm = (nibs[2] << 4) | nibs[3]; |
603 | 411k | disp = imm; |
604 | 411k | has_disp = 1; |
605 | 411k | if (imm & 0x80) |
606 | 130k | imm -= 0x100; |
607 | 411k | goto ok; |
608 | 76.6k | case IMM0_8U: |
609 | 76.6k | disp = imm = (nibs[2] << 4) | nibs[3]; |
610 | 76.6k | has_disp = 1; |
611 | 76.6k | goto ok; |
612 | 121k | case PCRELIMM_8BY2: |
613 | 121k | imm = ((nibs[2] << 4) | nibs[3]) << 1; |
614 | 121k | relmask = ~(bfd_vma) 1; |
615 | 121k | goto ok; |
616 | 146k | case PCRELIMM_8BY4: |
617 | 146k | imm = ((nibs[2] << 4) | nibs[3]) << 2; |
618 | 146k | relmask = ~(bfd_vma) 3; |
619 | 146k | goto ok; |
620 | 8.99k | case IMM0_8BY2: |
621 | 18.1k | case IMM1_8BY2: |
622 | 18.1k | imm = ((nibs[2] << 4) | nibs[3]) << 1; |
623 | 18.1k | goto ok; |
624 | 10.4k | case IMM0_8BY4: |
625 | 16.3k | case IMM1_8BY4: |
626 | 16.3k | imm = ((nibs[2] << 4) | nibs[3]) << 2; |
627 | 16.3k | goto ok; |
628 | 259k | case REG_N_D: |
629 | 259k | if ((nibs[n] & 1) != 0) |
630 | 210k | goto fail; |
631 | | /* Fall through. */ |
632 | 55.4M | case REG_N: |
633 | 55.4M | rn = nibs[n]; |
634 | 55.4M | break; |
635 | 24.3M | case REG_M: |
636 | 24.3M | rm = nibs[n]; |
637 | 24.3M | break; |
638 | 25.0k | case REG_N_B01: |
639 | 25.0k | if ((nibs[n] & 0x3) != 1 /* binary 01 */) |
640 | 22.6k | goto fail; |
641 | 2.31k | rn = (nibs[n] & 0xc) >> 2; |
642 | 2.31k | break; |
643 | 32.9k | case REG_NM: |
644 | 32.9k | rn = (nibs[n] & 0xc) >> 2; |
645 | 32.9k | rm = (nibs[n] & 0x3); |
646 | 32.9k | break; |
647 | 206k | case REG_B: |
648 | 206k | if (!(nibs[n] & 0x08)) /* Must always be 1. */ |
649 | 160k | goto fail; |
650 | 46.0k | rb = nibs[n] & 0x07; |
651 | 46.0k | break; |
652 | 2.12M | case SDT_REG_N: |
653 | | /* sh-dsp: single data transfer. */ |
654 | 2.12M | rn = nibs[n]; |
655 | 2.12M | if ((rn & 0xc) != 4) |
656 | 1.98M | goto fail; |
657 | 143k | rn = rn & 0x3; |
658 | 143k | rn |= (!(rn & 2)) << 2; |
659 | 143k | break; |
660 | 44.2M | case PPI: |
661 | 46.1M | case REPEAT: |
662 | 46.1M | goto fail; |
663 | 0 | default: |
664 | 0 | abort (); |
665 | 130M | } |
666 | 130M | } |
667 | | |
668 | 3.32M | ok: |
669 | | /* sh2a has D_REG but not X_REG. We don't know the pattern |
670 | | doesn't match unless we check the output args to see if they |
671 | | make sense. */ |
672 | 3.32M | if (target_arch == arch_sh2a |
673 | 3.32M | && ((op->arg[0] == DX_REG_M && (rm & 1) != 0) |
674 | 1.01M | || (op->arg[1] == DX_REG_N && (rn & 1) != 0))) |
675 | 3.00k | goto fail; |
676 | | |
677 | 3.32M | fprintf_fn (stream, "%s\t", op->name); |
678 | 3.32M | disp_pc = 0; |
679 | 9.26M | for (n = 0; n < 3 && op->arg[n] != A_END; n++) |
680 | 5.94M | { |
681 | 5.94M | if (n && op->arg[1] != A_END) |
682 | 2.76M | fprintf_fn (stream, ","); |
683 | 5.94M | switch (op->arg[n]) |
684 | 5.94M | { |
685 | 771k | case A_IMM: |
686 | 771k | fprintf_fn (stream, "#%d", imm); |
687 | 771k | break; |
688 | 164k | case A_R0: |
689 | 164k | fprintf_fn (stream, "r0"); |
690 | 164k | break; |
691 | 1.98M | case A_REG_N: |
692 | 1.98M | fprintf_fn (stream, "r%d", rn); |
693 | 1.98M | break; |
694 | 65.2k | case A_INC_N: |
695 | 65.2k | case AS_INC_N: |
696 | 65.2k | fprintf_fn (stream, "@r%d+", rn); |
697 | 65.2k | break; |
698 | 67.9k | case A_DEC_N: |
699 | 67.9k | case AS_DEC_N: |
700 | 67.9k | fprintf_fn (stream, "@-r%d", rn); |
701 | 67.9k | break; |
702 | 134k | case A_IND_N: |
703 | 134k | case AS_IND_N: |
704 | 134k | fprintf_fn (stream, "@r%d", rn); |
705 | 134k | break; |
706 | 227k | case A_DISP_REG_N: |
707 | 227k | fprintf_fn (stream, "@(%d,r%d)", has_disp?disp:imm, rn); |
708 | 227k | break; |
709 | 4.40k | case AS_PMOD_N: |
710 | 4.40k | fprintf_fn (stream, "@r%d+r8", rn); |
711 | 4.40k | break; |
712 | 974k | case A_REG_M: |
713 | 974k | fprintf_fn (stream, "r%d", rm); |
714 | 974k | break; |
715 | 127k | case A_INC_M: |
716 | 127k | fprintf_fn (stream, "@r%d+", rm); |
717 | 127k | break; |
718 | 732 | case A_DEC_M: |
719 | 732 | fprintf_fn (stream, "@-r%d", rm); |
720 | 732 | break; |
721 | 105k | case A_IND_M: |
722 | 105k | fprintf_fn (stream, "@r%d", rm); |
723 | 105k | break; |
724 | 203k | case A_DISP_REG_M: |
725 | 203k | fprintf_fn (stream, "@(%d,r%d)", has_disp?disp:imm, rm); |
726 | 203k | break; |
727 | 2.83k | case A_REG_B: |
728 | 2.83k | fprintf_fn (stream, "r%d_bank", rb); |
729 | 2.83k | break; |
730 | 267k | case A_DISP_PC: |
731 | 267k | disp_pc = 1; |
732 | 267k | disp_pc_addr = imm + 4 + (memaddr & relmask); |
733 | 267k | (*info->print_address_func) (disp_pc_addr, info); |
734 | 267k | break; |
735 | 135k | case A_IND_R0_REG_N: |
736 | 135k | fprintf_fn (stream, "@(r0,r%d)", rn); |
737 | 135k | break; |
738 | 89.6k | case A_IND_R0_REG_M: |
739 | 89.6k | fprintf_fn (stream, "@(r0,r%d)", rm); |
740 | 89.6k | break; |
741 | 49.6k | case A_DISP_GBR: |
742 | 49.6k | fprintf_fn (stream, "@(%d,gbr)", has_disp?disp:imm); |
743 | 49.6k | break; |
744 | 1.46k | case A_TBR: |
745 | 1.46k | fprintf_fn (stream, "tbr"); |
746 | 1.46k | break; |
747 | 3.80k | case A_DISP2_TBR: |
748 | 3.80k | fprintf_fn (stream, "@@(%d,tbr)", has_disp?disp:imm); |
749 | 3.80k | break; |
750 | 343 | case A_INC_R15: |
751 | 343 | fprintf_fn (stream, "@r15+"); |
752 | 343 | break; |
753 | 866 | case A_DEC_R15: |
754 | 866 | fprintf_fn (stream, "@-r15"); |
755 | 866 | break; |
756 | 26.8k | case A_R0_GBR: |
757 | 26.8k | fprintf_fn (stream, "@(r0,gbr)"); |
758 | 26.8k | break; |
759 | 221k | case A_BDISP12: |
760 | 283k | case A_BDISP8: |
761 | 283k | (*info->print_address_func) (imm + memaddr, info); |
762 | 283k | break; |
763 | 41.6k | case A_SR: |
764 | 41.6k | fprintf_fn (stream, "sr"); |
765 | 41.6k | break; |
766 | 12.3k | case A_GBR: |
767 | 12.3k | fprintf_fn (stream, "gbr"); |
768 | 12.3k | break; |
769 | 2.65k | case A_VBR: |
770 | 2.65k | fprintf_fn (stream, "vbr"); |
771 | 2.65k | break; |
772 | 2.24k | case A_DSR: |
773 | 2.24k | fprintf_fn (stream, "dsr"); |
774 | 2.24k | break; |
775 | 1.71k | case A_MOD: |
776 | 1.71k | fprintf_fn (stream, "mod"); |
777 | 1.71k | break; |
778 | 1.50k | case A_RE: |
779 | 1.50k | fprintf_fn (stream, "re"); |
780 | 1.50k | break; |
781 | 1.15k | case A_RS: |
782 | 1.15k | fprintf_fn (stream, "rs"); |
783 | 1.15k | break; |
784 | 2.26k | case A_A0: |
785 | 2.26k | fprintf_fn (stream, "a0"); |
786 | 2.26k | break; |
787 | 1.33k | case A_X0: |
788 | 1.33k | fprintf_fn (stream, "x0"); |
789 | 1.33k | break; |
790 | 1.53k | case A_X1: |
791 | 1.53k | fprintf_fn (stream, "x1"); |
792 | 1.53k | break; |
793 | 1.28k | case A_Y0: |
794 | 1.28k | fprintf_fn (stream, "y0"); |
795 | 1.28k | break; |
796 | 1.21k | case A_Y1: |
797 | 1.21k | fprintf_fn (stream, "y1"); |
798 | 1.21k | break; |
799 | 17.8k | case DSP_REG_M: |
800 | 17.8k | print_dsp_reg (rm, fprintf_fn, stream); |
801 | 17.8k | break; |
802 | 621 | case A_SSR: |
803 | 621 | fprintf_fn (stream, "ssr"); |
804 | 621 | break; |
805 | 2.59k | case A_SPC: |
806 | 2.59k | fprintf_fn (stream, "spc"); |
807 | 2.59k | break; |
808 | 11.4k | case A_MACH: |
809 | 11.4k | fprintf_fn (stream, "mach"); |
810 | 11.4k | break; |
811 | 3.36k | case A_MACL: |
812 | 3.36k | fprintf_fn (stream, "macl"); |
813 | 3.36k | break; |
814 | 9.95k | case A_PR: |
815 | 9.95k | fprintf_fn (stream, "pr"); |
816 | 9.95k | break; |
817 | 1.23k | case A_SGR: |
818 | 1.23k | fprintf_fn (stream, "sgr"); |
819 | 1.23k | break; |
820 | 1.21k | case A_DBR: |
821 | 1.21k | fprintf_fn (stream, "dbr"); |
822 | 1.21k | break; |
823 | 61.8k | case F_REG_N: |
824 | 61.8k | fprintf_fn (stream, "fr%d", rn); |
825 | 61.8k | break; |
826 | 53.3k | case F_REG_M: |
827 | 53.3k | fprintf_fn (stream, "fr%d", rm); |
828 | 53.3k | break; |
829 | 576 | case DX_REG_N: |
830 | 576 | if (rn & 1) |
831 | 253 | { |
832 | 253 | fprintf_fn (stream, "xd%d", rn & ~1); |
833 | 253 | break; |
834 | 253 | } |
835 | | /* Fall through. */ |
836 | 539 | case D_REG_N: |
837 | 539 | fprintf_fn (stream, "dr%d", rn); |
838 | 539 | break; |
839 | 2.55k | case DX_REG_M: |
840 | 2.55k | if (rm & 1) |
841 | 1.77k | { |
842 | 1.77k | fprintf_fn (stream, "xd%d", rm & ~1); |
843 | 1.77k | break; |
844 | 1.77k | } |
845 | | /* Fall through. */ |
846 | 774 | case D_REG_M: |
847 | 774 | fprintf_fn (stream, "dr%d", rm); |
848 | 774 | break; |
849 | 649 | case FPSCR_M: |
850 | 821 | case FPSCR_N: |
851 | 821 | fprintf_fn (stream, "fpscr"); |
852 | 821 | break; |
853 | 1.80k | case FPUL_M: |
854 | 2.48k | case FPUL_N: |
855 | 2.48k | fprintf_fn (stream, "fpul"); |
856 | 2.48k | break; |
857 | 3.89k | case F_FR0: |
858 | 3.89k | fprintf_fn (stream, "fr0"); |
859 | 3.89k | break; |
860 | 2.38k | case V_REG_N: |
861 | 2.38k | fprintf_fn (stream, "fv%d", rn * 4); |
862 | 2.38k | break; |
863 | 311 | case V_REG_M: |
864 | 311 | fprintf_fn (stream, "fv%d", rm * 4); |
865 | 311 | break; |
866 | 2.07k | case XMTRX_M4: |
867 | 2.07k | fprintf_fn (stream, "xmtrx"); |
868 | 2.07k | break; |
869 | 0 | default: |
870 | 0 | abort (); |
871 | 5.94M | } |
872 | 5.94M | } |
873 | | |
874 | | #if 0 |
875 | | /* This code prints instructions in delay slots on the same line |
876 | | as the instruction which needs the delay slots. This can be |
877 | | confusing, since other disassembler don't work this way, and |
878 | | it means that the instructions are not all in a line. So I |
879 | | disabled it. Ian. */ |
880 | | if (!(info->flags & 1) |
881 | | && (op->name[0] == 'j' |
882 | | || (op->name[0] == 'b' |
883 | | && (op->name[1] == 'r' |
884 | | || op->name[1] == 's')) |
885 | | || (op->name[0] == 'r' && op->name[1] == 't') |
886 | | || (op->name[0] == 'b' && op->name[2] == '.'))) |
887 | | { |
888 | | info->flags |= 1; |
889 | | fprintf_fn (stream, "\t(slot "); |
890 | | print_insn_sh (memaddr + 2, info); |
891 | | info->flags &= ~1; |
892 | | fprintf_fn (stream, ")"); |
893 | | return 4; |
894 | | } |
895 | | #endif |
896 | | |
897 | 3.32M | if (disp_pc && strcmp (op->name, "mova") != 0) |
898 | 260k | { |
899 | 260k | int size; |
900 | 260k | bfd_byte bytes[4]; |
901 | | |
902 | 260k | if (relmask == ~(bfd_vma) 1) |
903 | 121k | size = 2; |
904 | 139k | else |
905 | 139k | size = 4; |
906 | | /* Not reading an instruction - disable stop_vma. */ |
907 | 260k | info->stop_vma = 0; |
908 | 260k | status = info->read_memory_func (disp_pc_addr, bytes, size, info); |
909 | 260k | if (status == 0) |
910 | 245k | { |
911 | 245k | unsigned int val; |
912 | | |
913 | 245k | if (size == 2) |
914 | 116k | { |
915 | 116k | if (info->endian == BFD_ENDIAN_LITTLE) |
916 | 33.6k | val = bfd_getl16 (bytes); |
917 | 82.7k | else |
918 | 82.7k | val = bfd_getb16 (bytes); |
919 | 116k | } |
920 | 129k | else |
921 | 129k | { |
922 | 129k | if (info->endian == BFD_ENDIAN_LITTLE) |
923 | 55.1k | val = bfd_getl32 (bytes); |
924 | 74.2k | else |
925 | 74.2k | val = bfd_getb32 (bytes); |
926 | 129k | } |
927 | 245k | if ((*info->symbol_at_address_func) (val, info)) |
928 | 21.2k | { |
929 | 21.2k | fprintf_fn (stream, "\t! "); |
930 | 21.2k | (*info->print_address_func) (val, info); |
931 | 21.2k | } |
932 | 224k | else |
933 | 224k | fprintf_fn (stream, "\t! %x", val); |
934 | 245k | } |
935 | 260k | } |
936 | | |
937 | 3.32M | return SH_MERGE_ARCH_SET (op->arch, arch_op32) ? 4 : 2; |
938 | 1.01G | fail: |
939 | 1.01G | ; |
940 | | |
941 | 1.01G | } |
942 | 1.22M | fprintf_fn (stream, ".word 0x%x%x%x%x", nibs[0], nibs[1], nibs[2], nibs[3]); |
943 | 1.22M | return 2; |
944 | 4.54M | } |