/src/binutils-gdb/opcodes/sh-dis.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Disassemble SH instructions. |
2 | | Copyright (C) 1993-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 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 | 0 | { |
37 | 0 | int n; |
38 | |
|
39 | 0 | fprintf_fn (stream, "%s\t", op->name); |
40 | 0 | for (n = 0; n < 2; n++) |
41 | 0 | { |
42 | 0 | switch (op->arg[n]) |
43 | 0 | { |
44 | 0 | case A_IND_N: |
45 | 0 | case AX_IND_N: |
46 | 0 | case AXY_IND_N: |
47 | 0 | case AY_IND_N: |
48 | 0 | case AYX_IND_N: |
49 | 0 | fprintf_fn (stream, "@r%d", rn); |
50 | 0 | break; |
51 | 0 | case A_INC_N: |
52 | 0 | case AX_INC_N: |
53 | 0 | case AXY_INC_N: |
54 | 0 | case AY_INC_N: |
55 | 0 | case AYX_INC_N: |
56 | 0 | fprintf_fn (stream, "@r%d+", rn); |
57 | 0 | break; |
58 | 0 | case AX_PMOD_N: |
59 | 0 | case AXY_PMOD_N: |
60 | 0 | fprintf_fn (stream, "@r%d+r8", rn); |
61 | 0 | break; |
62 | 0 | case AY_PMOD_N: |
63 | 0 | case AYX_PMOD_N: |
64 | 0 | fprintf_fn (stream, "@r%d+r9", rn); |
65 | 0 | break; |
66 | 0 | case DSP_REG_A_M: |
67 | 0 | fprintf_fn (stream, "a%c", '0' + rm); |
68 | 0 | break; |
69 | 0 | case DSP_REG_X: |
70 | 0 | fprintf_fn (stream, "x%c", '0' + rm); |
71 | 0 | break; |
72 | 0 | case DSP_REG_Y: |
73 | 0 | fprintf_fn (stream, "y%c", '0' + rm); |
74 | 0 | break; |
75 | 0 | case DSP_REG_AX: |
76 | 0 | fprintf_fn (stream, "%c%c", |
77 | 0 | (rm & 1) ? 'x' : 'a', |
78 | 0 | (rm & 2) ? '1' : '0'); |
79 | 0 | break; |
80 | 0 | case DSP_REG_XY: |
81 | 0 | fprintf_fn (stream, "%c%c", |
82 | 0 | (rm & 1) ? 'y' : 'x', |
83 | 0 | (rm & 2) ? '1' : '0'); |
84 | 0 | break; |
85 | 0 | case DSP_REG_AY: |
86 | 0 | fprintf_fn (stream, "%c%c", |
87 | 0 | (rm & 2) ? 'y' : 'a', |
88 | 0 | (rm & 1) ? '1' : '0'); |
89 | 0 | break; |
90 | 0 | case DSP_REG_YX: |
91 | 0 | fprintf_fn (stream, "%c%c", |
92 | 0 | (rm & 2) ? 'x' : 'y', |
93 | 0 | (rm & 1) ? '1' : '0'); |
94 | 0 | break; |
95 | 0 | default: |
96 | 0 | abort (); |
97 | 0 | } |
98 | 0 | if (n == 0) |
99 | 0 | fprintf_fn (stream, ","); |
100 | 0 | } |
101 | 0 | } |
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 | 0 | { |
110 | 0 | fprintf_ftype fprintf_fn = info->fprintf_func; |
111 | 0 | void *stream = info->stream; |
112 | | |
113 | | /* If this is just a nop, make sure to emit something. */ |
114 | 0 | if (insn == 0x000) |
115 | 0 | { |
116 | 0 | fprintf_fn (stream, "nopx\tnopy"); |
117 | 0 | return; |
118 | 0 | } |
119 | | |
120 | | /* If a parallel processing insn was printed before, |
121 | | and we got a non-nop, emit a tab. */ |
122 | 0 | if ((insn & 0x800) && (insn & 0x3ff)) |
123 | 0 | fprintf_fn (stream, "\t"); |
124 | | |
125 | | /* Check if either the x or y part is invalid. */ |
126 | 0 | if (((insn & 3) != 0 && (insn & 0xc) == 0 && (insn & 0x2a0)) |
127 | 0 | || ((insn & 3) == 0 && (insn & 0xc) != 0 && (insn & 0x150))) |
128 | 0 | if (info->mach != bfd_mach_sh_dsp |
129 | 0 | && info->mach != bfd_mach_sh3_dsp) |
130 | 0 | { |
131 | 0 | static const sh_opcode_info *first_movx, *first_movy; |
132 | 0 | const sh_opcode_info *op; |
133 | 0 | int is_movy; |
134 | |
|
135 | 0 | if (! first_movx) |
136 | 0 | { |
137 | 0 | for (first_movx = sh_table; first_movx->nibbles[1] != MOVX_NOPY;) |
138 | 0 | first_movx++; |
139 | 0 | for (first_movy = first_movx; first_movy->nibbles[1] != MOVY_NOPX;) |
140 | 0 | first_movy++; |
141 | 0 | } |
142 | |
|
143 | 0 | is_movy = ((insn & 3) != 0); |
144 | |
|
145 | 0 | if (is_movy) |
146 | 0 | op = first_movy; |
147 | 0 | else |
148 | 0 | op = first_movx; |
149 | |
|
150 | 0 | while (op->nibbles[2] != (unsigned) ((insn >> 4) & 3) |
151 | 0 | || op->nibbles[3] != (unsigned) (insn & 0xf)) |
152 | 0 | op++; |
153 | |
|
154 | 0 | print_movxy (op, |
155 | 0 | (4 * ((insn & (is_movy ? 0x200 : 0x100)) == 0) |
156 | 0 | + 2 * is_movy |
157 | 0 | + 1 * ((insn & (is_movy ? 0x100 : 0x200)) != 0)), |
158 | 0 | (insn >> 6) & 3, |
159 | 0 | fprintf_fn, stream); |
160 | 0 | } |
161 | 0 | else |
162 | 0 | fprintf_fn (stream, ".word 0x%x", insn | 0xf000); |
163 | 0 | else |
164 | 0 | { |
165 | 0 | static const sh_opcode_info *first_movx, *first_movy; |
166 | 0 | const sh_opcode_info *opx, *opy; |
167 | 0 | unsigned int insn_x, insn_y; |
168 | |
|
169 | 0 | if (! first_movx) |
170 | 0 | { |
171 | 0 | for (first_movx = sh_table; first_movx->nibbles[1] != MOVX;) |
172 | 0 | first_movx++; |
173 | 0 | for (first_movy = first_movx; first_movy->nibbles[1] != MOVY;) |
174 | 0 | first_movy++; |
175 | 0 | } |
176 | 0 | insn_x = (insn >> 2) & 0xb; |
177 | 0 | if (insn_x) |
178 | 0 | { |
179 | 0 | for (opx = first_movx; opx->nibbles[2] != insn_x;) |
180 | 0 | opx++; |
181 | 0 | print_movxy (opx, ((insn >> 9) & 1) + 4, (insn >> 7) & 1, |
182 | 0 | fprintf_fn, stream); |
183 | 0 | } |
184 | 0 | insn_y = (insn & 3) | ((insn >> 1) & 8); |
185 | 0 | if (insn_y) |
186 | 0 | { |
187 | 0 | if (insn_x) |
188 | 0 | fprintf_fn (stream, "\t"); |
189 | 0 | for (opy = first_movy; opy->nibbles[2] != insn_y;) |
190 | 0 | opy++; |
191 | 0 | print_movxy (opy, ((insn >> 8) & 1) + 6, (insn >> 6) & 1, |
192 | 0 | fprintf_fn, stream); |
193 | 0 | } |
194 | 0 | if (!insn_x && !insn_y && ((insn & 0x3ff) != 0 || (insn & 0x800) == 0)) |
195 | 0 | fprintf_fn (stream, ".word 0x%x", insn | 0xf000); |
196 | 0 | } |
197 | 0 | } |
198 | | |
199 | | static void |
200 | | print_dsp_reg (int rm, fprintf_ftype fprintf_fn, void *stream) |
201 | 0 | { |
202 | 0 | switch (rm) |
203 | 0 | { |
204 | 0 | case A_A1_NUM: |
205 | 0 | fprintf_fn (stream, "a1"); |
206 | 0 | break; |
207 | 0 | case A_A0_NUM: |
208 | 0 | fprintf_fn (stream, "a0"); |
209 | 0 | break; |
210 | 0 | case A_X0_NUM: |
211 | 0 | fprintf_fn (stream, "x0"); |
212 | 0 | break; |
213 | 0 | case A_X1_NUM: |
214 | 0 | fprintf_fn (stream, "x1"); |
215 | 0 | break; |
216 | 0 | case A_Y0_NUM: |
217 | 0 | fprintf_fn (stream, "y0"); |
218 | 0 | break; |
219 | 0 | case A_Y1_NUM: |
220 | 0 | fprintf_fn (stream, "y1"); |
221 | 0 | break; |
222 | 0 | case A_M0_NUM: |
223 | 0 | fprintf_fn (stream, "m0"); |
224 | 0 | break; |
225 | 0 | case A_A1G_NUM: |
226 | 0 | fprintf_fn (stream, "a1g"); |
227 | 0 | break; |
228 | 0 | case A_M1_NUM: |
229 | 0 | fprintf_fn (stream, "m1"); |
230 | 0 | break; |
231 | 0 | case A_A0G_NUM: |
232 | 0 | fprintf_fn (stream, "a0g"); |
233 | 0 | break; |
234 | 0 | default: |
235 | 0 | fprintf_fn (stream, "0x%x", rm); |
236 | 0 | break; |
237 | 0 | } |
238 | 0 | } |
239 | | |
240 | | static void |
241 | | print_insn_ppi (int field_b, struct disassemble_info *info) |
242 | 0 | { |
243 | 0 | static char *sx_tab[] = { "x0", "x1", "a0", "a1" }; |
244 | 0 | static char *sy_tab[] = { "y0", "y1", "m0", "m1" }; |
245 | 0 | fprintf_ftype fprintf_fn = info->fprintf_func; |
246 | 0 | void *stream = info->stream; |
247 | 0 | unsigned int nib1, nib2, nib3; |
248 | 0 | unsigned int altnib1, nib4; |
249 | 0 | char *dc = NULL; |
250 | 0 | const sh_opcode_info *op; |
251 | |
|
252 | 0 | if ((field_b & 0xe800) == 0) |
253 | 0 | { |
254 | 0 | fprintf_fn (stream, "psh%c\t#%d,", |
255 | 0 | field_b & 0x1000 ? 'a' : 'l', |
256 | 0 | (field_b >> 4) & 127); |
257 | 0 | print_dsp_reg (field_b & 0xf, fprintf_fn, stream); |
258 | 0 | return; |
259 | 0 | } |
260 | 0 | if ((field_b & 0xc000) == 0x4000 && (field_b & 0x3000) != 0x1000) |
261 | 0 | { |
262 | 0 | static char *du_tab[] = { "x0", "y0", "a0", "a1" }; |
263 | 0 | static char *se_tab[] = { "x0", "x1", "y0", "a1" }; |
264 | 0 | static char *sf_tab[] = { "y0", "y1", "x0", "a1" }; |
265 | 0 | static char *sg_tab[] = { "m0", "m1", "a0", "a1" }; |
266 | |
|
267 | 0 | if (field_b & 0x2000) |
268 | 0 | fprintf_fn (stream, "p%s %s,%s,%s\t", |
269 | 0 | (field_b & 0x1000) ? "add" : "sub", |
270 | 0 | sx_tab[(field_b >> 6) & 3], |
271 | 0 | sy_tab[(field_b >> 4) & 3], |
272 | 0 | du_tab[(field_b >> 0) & 3]); |
273 | | |
274 | 0 | else if ((field_b & 0xf0) == 0x10 |
275 | 0 | && info->mach != bfd_mach_sh_dsp |
276 | 0 | && info->mach != bfd_mach_sh3_dsp) |
277 | 0 | fprintf_fn (stream, "pclr %s \t", du_tab[(field_b >> 0) & 3]); |
278 | | |
279 | 0 | else if ((field_b & 0xf3) != 0) |
280 | 0 | fprintf_fn (stream, ".word 0x%x\t", field_b); |
281 | |
|
282 | 0 | fprintf_fn (stream, "pmuls%c%s,%s,%s", |
283 | 0 | field_b & 0x2000 ? ' ' : '\t', |
284 | 0 | se_tab[(field_b >> 10) & 3], |
285 | 0 | sf_tab[(field_b >> 8) & 3], |
286 | 0 | sg_tab[(field_b >> 2) & 3]); |
287 | 0 | return; |
288 | 0 | } |
289 | | |
290 | 0 | nib1 = PPIC; |
291 | 0 | nib2 = field_b >> 12 & 0xf; |
292 | 0 | nib3 = field_b >> 8 & 0xf; |
293 | 0 | nib4 = field_b >> 4 & 0xf; |
294 | 0 | switch (nib3 & 0x3) |
295 | 0 | { |
296 | 0 | case 0: |
297 | 0 | dc = ""; |
298 | 0 | nib1 = PPI3; |
299 | 0 | break; |
300 | 0 | case 1: |
301 | 0 | dc = ""; |
302 | 0 | break; |
303 | 0 | case 2: |
304 | 0 | dc = "dct "; |
305 | 0 | nib3 -= 1; |
306 | 0 | break; |
307 | 0 | case 3: |
308 | 0 | dc = "dcf "; |
309 | 0 | nib3 -= 2; |
310 | 0 | break; |
311 | 0 | } |
312 | 0 | if (nib1 == PPI3) |
313 | 0 | altnib1 = PPI3NC; |
314 | 0 | else |
315 | 0 | altnib1 = nib1; |
316 | 0 | for (op = sh_table; op->name; op++) |
317 | 0 | { |
318 | 0 | if ((op->nibbles[1] == nib1 || op->nibbles[1] == altnib1) |
319 | 0 | && op->nibbles[2] == nib2 |
320 | 0 | && op->nibbles[3] == nib3) |
321 | 0 | { |
322 | 0 | int n; |
323 | |
|
324 | 0 | switch (op->nibbles[4]) |
325 | 0 | { |
326 | 0 | case HEX_0: |
327 | 0 | break; |
328 | 0 | case HEX_XX00: |
329 | 0 | if ((nib4 & 3) != 0) |
330 | 0 | continue; |
331 | 0 | break; |
332 | 0 | case HEX_1: |
333 | 0 | if ((nib4 & 3) != 1) |
334 | 0 | continue; |
335 | 0 | break; |
336 | 0 | case HEX_00YY: |
337 | 0 | if ((nib4 & 0xc) != 0) |
338 | 0 | continue; |
339 | 0 | break; |
340 | 0 | case HEX_4: |
341 | 0 | if ((nib4 & 0xc) != 4) |
342 | 0 | continue; |
343 | 0 | break; |
344 | 0 | default: |
345 | 0 | abort (); |
346 | 0 | } |
347 | 0 | fprintf_fn (stream, "%s%s\t", dc, op->name); |
348 | 0 | for (n = 0; n < 3 && op->arg[n] != A_END; n++) |
349 | 0 | { |
350 | 0 | if (n && op->arg[1] != A_END) |
351 | 0 | fprintf_fn (stream, ","); |
352 | 0 | switch (op->arg[n]) |
353 | 0 | { |
354 | 0 | case DSP_REG_N: |
355 | 0 | print_dsp_reg (field_b & 0xf, fprintf_fn, stream); |
356 | 0 | break; |
357 | 0 | case DSP_REG_X: |
358 | 0 | fprintf_fn (stream, "%s", sx_tab[(field_b >> 6) & 3]); |
359 | 0 | break; |
360 | 0 | case DSP_REG_Y: |
361 | 0 | fprintf_fn (stream, "%s", sy_tab[(field_b >> 4) & 3]); |
362 | 0 | break; |
363 | 0 | case A_MACH: |
364 | 0 | fprintf_fn (stream, "mach"); |
365 | 0 | break; |
366 | 0 | case A_MACL: |
367 | 0 | fprintf_fn (stream, "macl"); |
368 | 0 | break; |
369 | 0 | default: |
370 | 0 | abort (); |
371 | 0 | } |
372 | 0 | } |
373 | 0 | return; |
374 | 0 | } |
375 | 0 | } |
376 | | /* Not found. */ |
377 | 0 | fprintf_fn (stream, ".word 0x%x", field_b); |
378 | 0 | } |
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 | 0 | { |
386 | 0 | fprintf_ftype fprintf_fn = info->fprintf_func; |
387 | 0 | void *stream = info->stream; |
388 | 0 | unsigned char insn[4]; |
389 | 0 | unsigned char nibs[8]; |
390 | 0 | int status; |
391 | 0 | bfd_vma relmask = ~(bfd_vma) 0; |
392 | 0 | const sh_opcode_info *op; |
393 | 0 | unsigned int target_arch; |
394 | 0 | int allow_op32; |
395 | |
|
396 | 0 | switch (info->mach) |
397 | 0 | { |
398 | 0 | case bfd_mach_sh: |
399 | 0 | 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 | 0 | if (info->symbols |
404 | 0 | && bfd_asymbol_flavour(*info->symbols) == bfd_target_coff_flavour) |
405 | 0 | target_arch = arch_sh4; |
406 | 0 | break; |
407 | 0 | default: |
408 | 0 | target_arch = sh_get_arch_from_bfd_mach (info->mach); |
409 | 0 | } |
410 | | |
411 | 0 | status = info->read_memory_func (memaddr, insn, 2, info); |
412 | |
|
413 | 0 | if (status != 0) |
414 | 0 | { |
415 | 0 | info->memory_error_func (status, memaddr, info); |
416 | 0 | return -1; |
417 | 0 | } |
418 | | |
419 | 0 | if (info->endian == BFD_ENDIAN_LITTLE) |
420 | 0 | { |
421 | 0 | nibs[0] = (insn[1] >> 4) & 0xf; |
422 | 0 | nibs[1] = insn[1] & 0xf; |
423 | |
|
424 | 0 | nibs[2] = (insn[0] >> 4) & 0xf; |
425 | 0 | nibs[3] = insn[0] & 0xf; |
426 | 0 | } |
427 | 0 | else |
428 | 0 | { |
429 | 0 | nibs[0] = (insn[0] >> 4) & 0xf; |
430 | 0 | nibs[1] = insn[0] & 0xf; |
431 | |
|
432 | 0 | nibs[2] = (insn[1] >> 4) & 0xf; |
433 | 0 | nibs[3] = insn[1] & 0xf; |
434 | 0 | } |
435 | 0 | status = info->read_memory_func (memaddr + 2, insn + 2, 2, info); |
436 | 0 | if (status != 0) |
437 | 0 | allow_op32 = 0; |
438 | 0 | else |
439 | 0 | { |
440 | 0 | allow_op32 = 1; |
441 | |
|
442 | 0 | if (info->endian == BFD_ENDIAN_LITTLE) |
443 | 0 | { |
444 | 0 | nibs[4] = (insn[3] >> 4) & 0xf; |
445 | 0 | nibs[5] = insn[3] & 0xf; |
446 | |
|
447 | 0 | nibs[6] = (insn[2] >> 4) & 0xf; |
448 | 0 | nibs[7] = insn[2] & 0xf; |
449 | 0 | } |
450 | 0 | else |
451 | 0 | { |
452 | 0 | nibs[4] = (insn[2] >> 4) & 0xf; |
453 | 0 | nibs[5] = insn[2] & 0xf; |
454 | |
|
455 | 0 | nibs[6] = (insn[3] >> 4) & 0xf; |
456 | 0 | nibs[7] = insn[3] & 0xf; |
457 | 0 | } |
458 | 0 | } |
459 | |
|
460 | 0 | if (nibs[0] == 0xf && (nibs[1] & 4) == 0 |
461 | 0 | && SH_MERGE_ARCH_SET_VALID (target_arch, arch_sh_dsp_up)) |
462 | 0 | { |
463 | 0 | if (nibs[1] & 8) |
464 | 0 | { |
465 | 0 | int field_b; |
466 | |
|
467 | 0 | status = info->read_memory_func (memaddr + 2, insn, 2, info); |
468 | |
|
469 | 0 | if (status != 0) |
470 | 0 | { |
471 | 0 | info->memory_error_func (status, memaddr + 2, info); |
472 | 0 | return -1; |
473 | 0 | } |
474 | | |
475 | 0 | if (info->endian == BFD_ENDIAN_LITTLE) |
476 | 0 | field_b = insn[1] << 8 | insn[0]; |
477 | 0 | else |
478 | 0 | field_b = insn[0] << 8 | insn[1]; |
479 | |
|
480 | 0 | print_insn_ppi (field_b, info); |
481 | 0 | print_insn_ddt ((nibs[1] << 8) | (nibs[2] << 4) | nibs[3], info); |
482 | 0 | return 4; |
483 | 0 | } |
484 | 0 | print_insn_ddt ((nibs[1] << 8) | (nibs[2] << 4) | nibs[3], info); |
485 | 0 | return 2; |
486 | 0 | } |
487 | 0 | for (op = sh_table; op->name; op++) |
488 | 0 | { |
489 | 0 | int n; |
490 | 0 | int imm = 0; |
491 | 0 | int rn = 0; |
492 | 0 | int rm = 0; |
493 | 0 | int rb = 0; |
494 | 0 | int disp_pc; |
495 | 0 | bfd_vma disp_pc_addr = 0; |
496 | 0 | int disp = 0; |
497 | 0 | int has_disp = 0; |
498 | 0 | int max_n = SH_MERGE_ARCH_SET (op->arch, arch_op32) ? 8 : 4; |
499 | |
|
500 | 0 | if (!allow_op32 |
501 | 0 | && SH_MERGE_ARCH_SET (op->arch, arch_op32)) |
502 | 0 | goto fail; |
503 | | |
504 | 0 | if (!SH_MERGE_ARCH_SET_VALID (op->arch, target_arch)) |
505 | 0 | goto fail; |
506 | 0 | for (n = 0; n < max_n; n++) |
507 | 0 | { |
508 | 0 | int i = op->nibbles[n]; |
509 | |
|
510 | 0 | if (i < 16) |
511 | 0 | { |
512 | 0 | if (nibs[n] == i) |
513 | 0 | continue; |
514 | 0 | goto fail; |
515 | 0 | } |
516 | 0 | switch (i) |
517 | 0 | { |
518 | 0 | case BRANCH_8: |
519 | 0 | imm = (nibs[2] << 4) | (nibs[3]); |
520 | 0 | if (imm & 0x80) |
521 | 0 | imm |= ~0xff; |
522 | 0 | imm = ((char) imm) * 2 + 4; |
523 | 0 | goto ok; |
524 | 0 | case BRANCH_12: |
525 | 0 | imm = ((nibs[1]) << 8) | (nibs[2] << 4) | (nibs[3]); |
526 | 0 | if (imm & 0x800) |
527 | 0 | imm |= ~0xfff; |
528 | 0 | imm = imm * 2 + 4; |
529 | 0 | goto ok; |
530 | 0 | case IMM0_3c: |
531 | 0 | if (nibs[3] & 0x8) |
532 | 0 | goto fail; |
533 | 0 | imm = nibs[3] & 0x7; |
534 | 0 | break; |
535 | 0 | case IMM0_3s: |
536 | 0 | if (!(nibs[3] & 0x8)) |
537 | 0 | goto fail; |
538 | 0 | imm = nibs[3] & 0x7; |
539 | 0 | break; |
540 | 0 | case IMM0_3Uc: |
541 | 0 | if (nibs[2] & 0x8) |
542 | 0 | goto fail; |
543 | 0 | imm = nibs[2] & 0x7; |
544 | 0 | 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 | 0 | case DISP0_12: |
551 | 0 | case DISP1_12: |
552 | 0 | disp = (nibs[5] << 8) | (nibs[6] << 4) | nibs[7]; |
553 | 0 | has_disp = 1; |
554 | 0 | goto ok; |
555 | 0 | case DISP0_12BY2: |
556 | 0 | case DISP1_12BY2: |
557 | 0 | disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 1; |
558 | 0 | relmask = ~(bfd_vma) 1; |
559 | 0 | has_disp = 1; |
560 | 0 | goto ok; |
561 | 0 | case DISP0_12BY4: |
562 | 0 | case DISP1_12BY4: |
563 | 0 | disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 2; |
564 | 0 | relmask = ~(bfd_vma) 3; |
565 | 0 | has_disp = 1; |
566 | 0 | goto ok; |
567 | 0 | case DISP0_12BY8: |
568 | 0 | case DISP1_12BY8: |
569 | 0 | disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 3; |
570 | 0 | relmask = ~(bfd_vma) 7; |
571 | 0 | has_disp = 1; |
572 | 0 | goto ok; |
573 | 0 | case IMM0_20_4: |
574 | 0 | break; |
575 | 0 | case IMM0_20: |
576 | 0 | imm = ((nibs[2] << 16) | (nibs[4] << 12) | (nibs[5] << 8) |
577 | 0 | | (nibs[6] << 4) | nibs[7]); |
578 | 0 | if (imm & 0x80000) |
579 | 0 | imm -= 0x100000; |
580 | 0 | goto ok; |
581 | 0 | case IMM0_20BY8: |
582 | 0 | imm = ((nibs[2] << 16) | (nibs[4] << 12) | (nibs[5] << 8) |
583 | 0 | | (nibs[6] << 4) | nibs[7]); |
584 | 0 | imm <<= 8; |
585 | 0 | if (imm & 0x8000000) |
586 | 0 | imm -= 0x10000000; |
587 | 0 | goto ok; |
588 | 0 | case IMM0_4: |
589 | 0 | case IMM1_4: |
590 | 0 | imm = nibs[3]; |
591 | 0 | goto ok; |
592 | 0 | case IMM0_4BY2: |
593 | 0 | case IMM1_4BY2: |
594 | 0 | imm = nibs[3] << 1; |
595 | 0 | goto ok; |
596 | 0 | case IMM0_4BY4: |
597 | 0 | case IMM1_4BY4: |
598 | 0 | imm = nibs[3] << 2; |
599 | 0 | goto ok; |
600 | 0 | case IMM0_8S: |
601 | 0 | case IMM1_8: |
602 | 0 | imm = (nibs[2] << 4) | nibs[3]; |
603 | 0 | disp = imm; |
604 | 0 | has_disp = 1; |
605 | 0 | if (imm & 0x80) |
606 | 0 | imm -= 0x100; |
607 | 0 | goto ok; |
608 | 0 | case IMM0_8U: |
609 | 0 | disp = imm = (nibs[2] << 4) | nibs[3]; |
610 | 0 | has_disp = 1; |
611 | 0 | goto ok; |
612 | 0 | case PCRELIMM_8BY2: |
613 | 0 | imm = ((nibs[2] << 4) | nibs[3]) << 1; |
614 | 0 | relmask = ~(bfd_vma) 1; |
615 | 0 | goto ok; |
616 | 0 | case PCRELIMM_8BY4: |
617 | 0 | imm = ((nibs[2] << 4) | nibs[3]) << 2; |
618 | 0 | relmask = ~(bfd_vma) 3; |
619 | 0 | goto ok; |
620 | 0 | case IMM0_8BY2: |
621 | 0 | case IMM1_8BY2: |
622 | 0 | imm = ((nibs[2] << 4) | nibs[3]) << 1; |
623 | 0 | goto ok; |
624 | 0 | case IMM0_8BY4: |
625 | 0 | case IMM1_8BY4: |
626 | 0 | imm = ((nibs[2] << 4) | nibs[3]) << 2; |
627 | 0 | goto ok; |
628 | 0 | case REG_N_D: |
629 | 0 | if ((nibs[n] & 1) != 0) |
630 | 0 | goto fail; |
631 | | /* Fall through. */ |
632 | 0 | case REG_N: |
633 | 0 | rn = nibs[n]; |
634 | 0 | break; |
635 | 0 | case REG_M: |
636 | 0 | rm = nibs[n]; |
637 | 0 | break; |
638 | 0 | case REG_N_B01: |
639 | 0 | if ((nibs[n] & 0x3) != 1 /* binary 01 */) |
640 | 0 | goto fail; |
641 | 0 | rn = (nibs[n] & 0xc) >> 2; |
642 | 0 | break; |
643 | 0 | case REG_NM: |
644 | 0 | rn = (nibs[n] & 0xc) >> 2; |
645 | 0 | rm = (nibs[n] & 0x3); |
646 | 0 | break; |
647 | 0 | case REG_B: |
648 | 0 | if (!(nibs[n] & 0x08)) /* Must always be 1. */ |
649 | 0 | goto fail; |
650 | 0 | rb = nibs[n] & 0x07; |
651 | 0 | break; |
652 | 0 | case SDT_REG_N: |
653 | | /* sh-dsp: single data transfer. */ |
654 | 0 | rn = nibs[n]; |
655 | 0 | if ((rn & 0xc) != 4) |
656 | 0 | goto fail; |
657 | 0 | rn = rn & 0x3; |
658 | 0 | rn |= (!(rn & 2)) << 2; |
659 | 0 | break; |
660 | 0 | case PPI: |
661 | 0 | case REPEAT: |
662 | 0 | goto fail; |
663 | 0 | default: |
664 | 0 | abort (); |
665 | 0 | } |
666 | 0 | } |
667 | | |
668 | 0 | 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 | 0 | if (target_arch == arch_sh2a |
673 | 0 | && ((op->arg[0] == DX_REG_M && (rm & 1) != 0) |
674 | 0 | || (op->arg[1] == DX_REG_N && (rn & 1) != 0))) |
675 | 0 | goto fail; |
676 | | |
677 | 0 | fprintf_fn (stream, "%s\t", op->name); |
678 | 0 | disp_pc = 0; |
679 | 0 | for (n = 0; n < 3 && op->arg[n] != A_END; n++) |
680 | 0 | { |
681 | 0 | if (n && op->arg[1] != A_END) |
682 | 0 | fprintf_fn (stream, ","); |
683 | 0 | switch (op->arg[n]) |
684 | 0 | { |
685 | 0 | case A_IMM: |
686 | 0 | fprintf_fn (stream, "#%d", imm); |
687 | 0 | break; |
688 | 0 | case A_R0: |
689 | 0 | fprintf_fn (stream, "r0"); |
690 | 0 | break; |
691 | 0 | case A_REG_N: |
692 | 0 | fprintf_fn (stream, "r%d", rn); |
693 | 0 | break; |
694 | 0 | case A_INC_N: |
695 | 0 | case AS_INC_N: |
696 | 0 | fprintf_fn (stream, "@r%d+", rn); |
697 | 0 | break; |
698 | 0 | case A_DEC_N: |
699 | 0 | case AS_DEC_N: |
700 | 0 | fprintf_fn (stream, "@-r%d", rn); |
701 | 0 | break; |
702 | 0 | case A_IND_N: |
703 | 0 | case AS_IND_N: |
704 | 0 | fprintf_fn (stream, "@r%d", rn); |
705 | 0 | break; |
706 | 0 | case A_DISP_REG_N: |
707 | 0 | fprintf_fn (stream, "@(%d,r%d)", has_disp?disp:imm, rn); |
708 | 0 | break; |
709 | 0 | case AS_PMOD_N: |
710 | 0 | fprintf_fn (stream, "@r%d+r8", rn); |
711 | 0 | break; |
712 | 0 | case A_REG_M: |
713 | 0 | fprintf_fn (stream, "r%d", rm); |
714 | 0 | break; |
715 | 0 | case A_INC_M: |
716 | 0 | fprintf_fn (stream, "@r%d+", rm); |
717 | 0 | break; |
718 | 0 | case A_DEC_M: |
719 | 0 | fprintf_fn (stream, "@-r%d", rm); |
720 | 0 | break; |
721 | 0 | case A_IND_M: |
722 | 0 | fprintf_fn (stream, "@r%d", rm); |
723 | 0 | break; |
724 | 0 | case A_DISP_REG_M: |
725 | 0 | fprintf_fn (stream, "@(%d,r%d)", has_disp?disp:imm, rm); |
726 | 0 | break; |
727 | 0 | case A_REG_B: |
728 | 0 | fprintf_fn (stream, "r%d_bank", rb); |
729 | 0 | break; |
730 | 0 | case A_DISP_PC: |
731 | 0 | disp_pc = 1; |
732 | 0 | disp_pc_addr = imm + 4 + (memaddr & relmask); |
733 | 0 | (*info->print_address_func) (disp_pc_addr, info); |
734 | 0 | break; |
735 | 0 | case A_IND_R0_REG_N: |
736 | 0 | fprintf_fn (stream, "@(r0,r%d)", rn); |
737 | 0 | break; |
738 | 0 | case A_IND_R0_REG_M: |
739 | 0 | fprintf_fn (stream, "@(r0,r%d)", rm); |
740 | 0 | break; |
741 | 0 | case A_DISP_GBR: |
742 | 0 | fprintf_fn (stream, "@(%d,gbr)", has_disp?disp:imm); |
743 | 0 | break; |
744 | 0 | case A_TBR: |
745 | 0 | fprintf_fn (stream, "tbr"); |
746 | 0 | break; |
747 | 0 | case A_DISP2_TBR: |
748 | 0 | fprintf_fn (stream, "@@(%d,tbr)", has_disp?disp:imm); |
749 | 0 | break; |
750 | 0 | case A_INC_R15: |
751 | 0 | fprintf_fn (stream, "@r15+"); |
752 | 0 | break; |
753 | 0 | case A_DEC_R15: |
754 | 0 | fprintf_fn (stream, "@-r15"); |
755 | 0 | break; |
756 | 0 | case A_R0_GBR: |
757 | 0 | fprintf_fn (stream, "@(r0,gbr)"); |
758 | 0 | break; |
759 | 0 | case A_BDISP12: |
760 | 0 | case A_BDISP8: |
761 | 0 | (*info->print_address_func) (imm + memaddr, info); |
762 | 0 | break; |
763 | 0 | case A_SR: |
764 | 0 | fprintf_fn (stream, "sr"); |
765 | 0 | break; |
766 | 0 | case A_GBR: |
767 | 0 | fprintf_fn (stream, "gbr"); |
768 | 0 | break; |
769 | 0 | case A_VBR: |
770 | 0 | fprintf_fn (stream, "vbr"); |
771 | 0 | break; |
772 | 0 | case A_DSR: |
773 | 0 | fprintf_fn (stream, "dsr"); |
774 | 0 | break; |
775 | 0 | case A_MOD: |
776 | 0 | fprintf_fn (stream, "mod"); |
777 | 0 | break; |
778 | 0 | case A_RE: |
779 | 0 | fprintf_fn (stream, "re"); |
780 | 0 | break; |
781 | 0 | case A_RS: |
782 | 0 | fprintf_fn (stream, "rs"); |
783 | 0 | break; |
784 | 0 | case A_A0: |
785 | 0 | fprintf_fn (stream, "a0"); |
786 | 0 | break; |
787 | 0 | case A_X0: |
788 | 0 | fprintf_fn (stream, "x0"); |
789 | 0 | break; |
790 | 0 | case A_X1: |
791 | 0 | fprintf_fn (stream, "x1"); |
792 | 0 | break; |
793 | 0 | case A_Y0: |
794 | 0 | fprintf_fn (stream, "y0"); |
795 | 0 | break; |
796 | 0 | case A_Y1: |
797 | 0 | fprintf_fn (stream, "y1"); |
798 | 0 | break; |
799 | 0 | case DSP_REG_M: |
800 | 0 | print_dsp_reg (rm, fprintf_fn, stream); |
801 | 0 | break; |
802 | 0 | case A_SSR: |
803 | 0 | fprintf_fn (stream, "ssr"); |
804 | 0 | break; |
805 | 0 | case A_SPC: |
806 | 0 | fprintf_fn (stream, "spc"); |
807 | 0 | break; |
808 | 0 | case A_MACH: |
809 | 0 | fprintf_fn (stream, "mach"); |
810 | 0 | break; |
811 | 0 | case A_MACL: |
812 | 0 | fprintf_fn (stream, "macl"); |
813 | 0 | break; |
814 | 0 | case A_PR: |
815 | 0 | fprintf_fn (stream, "pr"); |
816 | 0 | break; |
817 | 0 | case A_SGR: |
818 | 0 | fprintf_fn (stream, "sgr"); |
819 | 0 | break; |
820 | 0 | case A_DBR: |
821 | 0 | fprintf_fn (stream, "dbr"); |
822 | 0 | break; |
823 | 0 | case F_REG_N: |
824 | 0 | fprintf_fn (stream, "fr%d", rn); |
825 | 0 | break; |
826 | 0 | case F_REG_M: |
827 | 0 | fprintf_fn (stream, "fr%d", rm); |
828 | 0 | break; |
829 | 0 | case DX_REG_N: |
830 | 0 | if (rn & 1) |
831 | 0 | { |
832 | 0 | fprintf_fn (stream, "xd%d", rn & ~1); |
833 | 0 | break; |
834 | 0 | } |
835 | | /* Fall through. */ |
836 | 0 | case D_REG_N: |
837 | 0 | fprintf_fn (stream, "dr%d", rn); |
838 | 0 | break; |
839 | 0 | case DX_REG_M: |
840 | 0 | if (rm & 1) |
841 | 0 | { |
842 | 0 | fprintf_fn (stream, "xd%d", rm & ~1); |
843 | 0 | break; |
844 | 0 | } |
845 | | /* Fall through. */ |
846 | 0 | case D_REG_M: |
847 | 0 | fprintf_fn (stream, "dr%d", rm); |
848 | 0 | break; |
849 | 0 | case FPSCR_M: |
850 | 0 | case FPSCR_N: |
851 | 0 | fprintf_fn (stream, "fpscr"); |
852 | 0 | break; |
853 | 0 | case FPUL_M: |
854 | 0 | case FPUL_N: |
855 | 0 | fprintf_fn (stream, "fpul"); |
856 | 0 | break; |
857 | 0 | case F_FR0: |
858 | 0 | fprintf_fn (stream, "fr0"); |
859 | 0 | break; |
860 | 0 | case V_REG_N: |
861 | 0 | fprintf_fn (stream, "fv%d", rn * 4); |
862 | 0 | break; |
863 | 0 | case V_REG_M: |
864 | 0 | fprintf_fn (stream, "fv%d", rm * 4); |
865 | 0 | break; |
866 | 0 | case XMTRX_M4: |
867 | 0 | fprintf_fn (stream, "xmtrx"); |
868 | 0 | break; |
869 | 0 | default: |
870 | 0 | abort (); |
871 | 0 | } |
872 | 0 | } |
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 | 0 | if (disp_pc && strcmp (op->name, "mova") != 0) |
898 | 0 | { |
899 | 0 | int size; |
900 | 0 | bfd_byte bytes[4]; |
901 | |
|
902 | 0 | if (relmask == ~(bfd_vma) 1) |
903 | 0 | size = 2; |
904 | 0 | else |
905 | 0 | size = 4; |
906 | | /* Not reading an instruction - disable stop_vma. */ |
907 | 0 | info->stop_vma = 0; |
908 | 0 | status = info->read_memory_func (disp_pc_addr, bytes, size, info); |
909 | 0 | if (status == 0) |
910 | 0 | { |
911 | 0 | unsigned int val; |
912 | |
|
913 | 0 | if (size == 2) |
914 | 0 | { |
915 | 0 | if (info->endian == BFD_ENDIAN_LITTLE) |
916 | 0 | val = bfd_getl16 (bytes); |
917 | 0 | else |
918 | 0 | val = bfd_getb16 (bytes); |
919 | 0 | } |
920 | 0 | else |
921 | 0 | { |
922 | 0 | if (info->endian == BFD_ENDIAN_LITTLE) |
923 | 0 | val = bfd_getl32 (bytes); |
924 | 0 | else |
925 | 0 | val = bfd_getb32 (bytes); |
926 | 0 | } |
927 | 0 | if ((*info->symbol_at_address_func) (val, info)) |
928 | 0 | { |
929 | 0 | fprintf_fn (stream, "\t! "); |
930 | 0 | (*info->print_address_func) (val, info); |
931 | 0 | } |
932 | 0 | else |
933 | 0 | fprintf_fn (stream, "\t! %x", val); |
934 | 0 | } |
935 | 0 | } |
936 | |
|
937 | 0 | return SH_MERGE_ARCH_SET (op->arch, arch_op32) ? 4 : 2; |
938 | 0 | fail: |
939 | 0 | ; |
940 | |
|
941 | 0 | } |
942 | 0 | fprintf_fn (stream, ".word 0x%x%x%x%x", nibs[0], nibs[1], nibs[2], nibs[3]); |
943 | 0 | return 2; |
944 | 0 | } |