Remove i860, i960, bout and aout-adobe targets
[deliverable/binutils-gdb.git] / opcodes / disassemble.c
1 /* Select disassembly routine for specified architecture.
2 Copyright (C) 1994-2018 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 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public 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 "disassemble.h"
23 #include "safe-ctype.h"
24 #include <assert.h>
25
26 #ifdef ARCH_all
27 #define ARCH_aarch64
28 #define ARCH_alpha
29 #define ARCH_arc
30 #define ARCH_arm
31 #define ARCH_avr
32 #define ARCH_bfin
33 #define ARCH_cr16
34 #define ARCH_cris
35 #define ARCH_crx
36 #define ARCH_d10v
37 #define ARCH_d30v
38 #define ARCH_dlx
39 #define ARCH_epiphany
40 #define ARCH_fr30
41 #define ARCH_frv
42 #define ARCH_ft32
43 #define ARCH_h8300
44 #define ARCH_h8500
45 #define ARCH_hppa
46 #define ARCH_i370
47 #define ARCH_i386
48 #define ARCH_ia64
49 #define ARCH_ip2k
50 #define ARCH_iq2000
51 #define ARCH_lm32
52 #define ARCH_m32c
53 #define ARCH_m32r
54 #define ARCH_m68hc11
55 #define ARCH_m68hc12
56 #define ARCH_m68k
57 #define ARCH_m88k
58 #define ARCH_mcore
59 #define ARCH_mep
60 #define ARCH_metag
61 #define ARCH_microblaze
62 #define ARCH_mips
63 #define ARCH_mmix
64 #define ARCH_mn10200
65 #define ARCH_mn10300
66 #define ARCH_moxie
67 #define ARCH_mt
68 #define ARCH_msp430
69 #define ARCH_nds32
70 #define ARCH_nios2
71 #define ARCH_ns32k
72 #define ARCH_or1k
73 #define ARCH_pdp11
74 #define ARCH_pj
75 #define ARCH_powerpc
76 #define ARCH_pru
77 #define ARCH_riscv
78 #define ARCH_rs6000
79 #define ARCH_rl78
80 #define ARCH_rx
81 #define ARCH_s390
82 #define ARCH_score
83 #define ARCH_sh
84 #define ARCH_sparc
85 #define ARCH_spu
86 #define ARCH_tic30
87 #define ARCH_tic4x
88 #define ARCH_tic54x
89 #define ARCH_tic6x
90 #define ARCH_tic80
91 #define ARCH_tilegx
92 #define ARCH_tilepro
93 #define ARCH_v850
94 #define ARCH_vax
95 #define ARCH_visium
96 #define ARCH_w65
97 #define ARCH_wasm32
98 #define ARCH_xstormy16
99 #define ARCH_xc16x
100 #define ARCH_xgate
101 #define ARCH_xtensa
102 #define ARCH_z80
103 #define ARCH_z8k
104 #define INCLUDE_SHMEDIA
105 #endif
106
107 #ifdef ARCH_m32c
108 #include "m32c-desc.h"
109 #endif
110
111 disassembler_ftype
112 disassembler (enum bfd_architecture a,
113 bfd_boolean big ATTRIBUTE_UNUSED,
114 unsigned long mach ATTRIBUTE_UNUSED,
115 bfd *abfd ATTRIBUTE_UNUSED)
116 {
117 disassembler_ftype disassemble;
118
119 switch (a)
120 {
121 /* If you add a case to this table, also add it to the
122 ARCH_all definition right above this function. */
123 #ifdef ARCH_aarch64
124 case bfd_arch_aarch64:
125 disassemble = print_insn_aarch64;
126 break;
127 #endif
128 #ifdef ARCH_alpha
129 case bfd_arch_alpha:
130 disassemble = print_insn_alpha;
131 break;
132 #endif
133 #ifdef ARCH_arc
134 case bfd_arch_arc:
135 disassemble = arc_get_disassembler (abfd);
136 break;
137 #endif
138 #ifdef ARCH_arm
139 case bfd_arch_arm:
140 if (big)
141 disassemble = print_insn_big_arm;
142 else
143 disassemble = print_insn_little_arm;
144 break;
145 #endif
146 #ifdef ARCH_avr
147 case bfd_arch_avr:
148 disassemble = print_insn_avr;
149 break;
150 #endif
151 #ifdef ARCH_bfin
152 case bfd_arch_bfin:
153 disassemble = print_insn_bfin;
154 break;
155 #endif
156 #ifdef ARCH_cr16
157 case bfd_arch_cr16:
158 disassemble = print_insn_cr16;
159 break;
160 #endif
161 #ifdef ARCH_cris
162 case bfd_arch_cris:
163 disassemble = cris_get_disassembler (abfd);
164 break;
165 #endif
166 #ifdef ARCH_crx
167 case bfd_arch_crx:
168 disassemble = print_insn_crx;
169 break;
170 #endif
171 #ifdef ARCH_d10v
172 case bfd_arch_d10v:
173 disassemble = print_insn_d10v;
174 break;
175 #endif
176 #ifdef ARCH_d30v
177 case bfd_arch_d30v:
178 disassemble = print_insn_d30v;
179 break;
180 #endif
181 #ifdef ARCH_dlx
182 case bfd_arch_dlx:
183 /* As far as I know we only handle big-endian DLX objects. */
184 disassemble = print_insn_dlx;
185 break;
186 #endif
187 #ifdef ARCH_h8300
188 case bfd_arch_h8300:
189 if (mach == bfd_mach_h8300h || mach == bfd_mach_h8300hn)
190 disassemble = print_insn_h8300h;
191 else if (mach == bfd_mach_h8300s
192 || mach == bfd_mach_h8300sn
193 || mach == bfd_mach_h8300sx
194 || mach == bfd_mach_h8300sxn)
195 disassemble = print_insn_h8300s;
196 else
197 disassemble = print_insn_h8300;
198 break;
199 #endif
200 #ifdef ARCH_h8500
201 case bfd_arch_h8500:
202 disassemble = print_insn_h8500;
203 break;
204 #endif
205 #ifdef ARCH_hppa
206 case bfd_arch_hppa:
207 disassemble = print_insn_hppa;
208 break;
209 #endif
210 #ifdef ARCH_i370
211 case bfd_arch_i370:
212 disassemble = print_insn_i370;
213 break;
214 #endif
215 #ifdef ARCH_i386
216 case bfd_arch_i386:
217 case bfd_arch_iamcu:
218 case bfd_arch_l1om:
219 case bfd_arch_k1om:
220 disassemble = print_insn_i386;
221 break;
222 #endif
223 #ifdef ARCH_ia64
224 case bfd_arch_ia64:
225 disassemble = print_insn_ia64;
226 break;
227 #endif
228 #ifdef ARCH_ip2k
229 case bfd_arch_ip2k:
230 disassemble = print_insn_ip2k;
231 break;
232 #endif
233 #ifdef ARCH_epiphany
234 case bfd_arch_epiphany:
235 disassemble = print_insn_epiphany;
236 break;
237 #endif
238 #ifdef ARCH_fr30
239 case bfd_arch_fr30:
240 disassemble = print_insn_fr30;
241 break;
242 #endif
243 #ifdef ARCH_lm32
244 case bfd_arch_lm32:
245 disassemble = print_insn_lm32;
246 break;
247 #endif
248 #ifdef ARCH_m32r
249 case bfd_arch_m32r:
250 disassemble = print_insn_m32r;
251 break;
252 #endif
253 #if defined(ARCH_m68hc11) || defined(ARCH_m68hc12) \
254 || defined(ARCH_9s12x) || defined(ARCH_m9s12xg)
255 case bfd_arch_m68hc11:
256 disassemble = print_insn_m68hc11;
257 break;
258 case bfd_arch_m68hc12:
259 disassemble = print_insn_m68hc12;
260 break;
261 case bfd_arch_m9s12x:
262 disassemble = print_insn_m9s12x;
263 break;
264 case bfd_arch_m9s12xg:
265 disassemble = print_insn_m9s12xg;
266 break;
267 #endif
268 #ifdef ARCH_m68k
269 case bfd_arch_m68k:
270 disassemble = print_insn_m68k;
271 break;
272 #endif
273 #ifdef ARCH_m88k
274 case bfd_arch_m88k:
275 disassemble = print_insn_m88k;
276 break;
277 #endif
278 #ifdef ARCH_mt
279 case bfd_arch_mt:
280 disassemble = print_insn_mt;
281 break;
282 #endif
283 #ifdef ARCH_microblaze
284 case bfd_arch_microblaze:
285 disassemble = print_insn_microblaze;
286 break;
287 #endif
288 #ifdef ARCH_msp430
289 case bfd_arch_msp430:
290 disassemble = print_insn_msp430;
291 break;
292 #endif
293 #ifdef ARCH_nds32
294 case bfd_arch_nds32:
295 disassemble = print_insn_nds32;
296 break;
297 #endif
298 #ifdef ARCH_ns32k
299 case bfd_arch_ns32k:
300 disassemble = print_insn_ns32k;
301 break;
302 #endif
303 #ifdef ARCH_mcore
304 case bfd_arch_mcore:
305 disassemble = print_insn_mcore;
306 break;
307 #endif
308 #ifdef ARCH_mep
309 case bfd_arch_mep:
310 disassemble = print_insn_mep;
311 break;
312 #endif
313 #ifdef ARCH_metag
314 case bfd_arch_metag:
315 disassemble = print_insn_metag;
316 break;
317 #endif
318 #ifdef ARCH_mips
319 case bfd_arch_mips:
320 if (big)
321 disassemble = print_insn_big_mips;
322 else
323 disassemble = print_insn_little_mips;
324 break;
325 #endif
326 #ifdef ARCH_mmix
327 case bfd_arch_mmix:
328 disassemble = print_insn_mmix;
329 break;
330 #endif
331 #ifdef ARCH_mn10200
332 case bfd_arch_mn10200:
333 disassemble = print_insn_mn10200;
334 break;
335 #endif
336 #ifdef ARCH_mn10300
337 case bfd_arch_mn10300:
338 disassemble = print_insn_mn10300;
339 break;
340 #endif
341 #ifdef ARCH_nios2
342 case bfd_arch_nios2:
343 if (big)
344 disassemble = print_insn_big_nios2;
345 else
346 disassemble = print_insn_little_nios2;
347 break;
348 #endif
349 #ifdef ARCH_or1k
350 case bfd_arch_or1k:
351 disassemble = print_insn_or1k;
352 break;
353 #endif
354 #ifdef ARCH_pdp11
355 case bfd_arch_pdp11:
356 disassemble = print_insn_pdp11;
357 break;
358 #endif
359 #ifdef ARCH_pj
360 case bfd_arch_pj:
361 disassemble = print_insn_pj;
362 break;
363 #endif
364 #ifdef ARCH_powerpc
365 case bfd_arch_powerpc:
366 #endif
367 #ifdef ARCH_rs6000
368 case bfd_arch_rs6000:
369 #endif
370 #if defined ARCH_powerpc || defined ARCH_rs6000
371 if (big)
372 disassemble = print_insn_big_powerpc;
373 else
374 disassemble = print_insn_little_powerpc;
375 break;
376 #endif
377 #ifdef ARCH_pru
378 case bfd_arch_pru:
379 disassemble = print_insn_pru;
380 break;
381 #endif
382 #ifdef ARCH_riscv
383 case bfd_arch_riscv:
384 disassemble = print_insn_riscv;
385 break;
386 #endif
387 #ifdef ARCH_rl78
388 case bfd_arch_rl78:
389 disassemble = rl78_get_disassembler (abfd);
390 break;
391 #endif
392 #ifdef ARCH_rx
393 case bfd_arch_rx:
394 disassemble = print_insn_rx;
395 break;
396 #endif
397 #ifdef ARCH_s390
398 case bfd_arch_s390:
399 disassemble = print_insn_s390;
400 break;
401 #endif
402 #ifdef ARCH_score
403 case bfd_arch_score:
404 if (big)
405 disassemble = print_insn_big_score;
406 else
407 disassemble = print_insn_little_score;
408 break;
409 #endif
410 #ifdef ARCH_sh
411 case bfd_arch_sh:
412 disassemble = print_insn_sh;
413 break;
414 #endif
415 #ifdef ARCH_sparc
416 case bfd_arch_sparc:
417 disassemble = print_insn_sparc;
418 break;
419 #endif
420 #ifdef ARCH_spu
421 case bfd_arch_spu:
422 disassemble = print_insn_spu;
423 break;
424 #endif
425 #ifdef ARCH_tic30
426 case bfd_arch_tic30:
427 disassemble = print_insn_tic30;
428 break;
429 #endif
430 #ifdef ARCH_tic4x
431 case bfd_arch_tic4x:
432 disassemble = print_insn_tic4x;
433 break;
434 #endif
435 #ifdef ARCH_tic54x
436 case bfd_arch_tic54x:
437 disassemble = print_insn_tic54x;
438 break;
439 #endif
440 #ifdef ARCH_tic6x
441 case bfd_arch_tic6x:
442 disassemble = print_insn_tic6x;
443 break;
444 #endif
445 #ifdef ARCH_tic80
446 case bfd_arch_tic80:
447 disassemble = print_insn_tic80;
448 break;
449 #endif
450 #ifdef ARCH_ft32
451 case bfd_arch_ft32:
452 disassemble = print_insn_ft32;
453 break;
454 #endif
455 #ifdef ARCH_v850
456 case bfd_arch_v850:
457 case bfd_arch_v850_rh850:
458 disassemble = print_insn_v850;
459 break;
460 #endif
461 #ifdef ARCH_w65
462 case bfd_arch_w65:
463 disassemble = print_insn_w65;
464 break;
465 #endif
466 #ifdef ARCH_wasm32
467 case bfd_arch_wasm32:
468 disassemble = print_insn_wasm32;
469 break;
470 #endif
471 #ifdef ARCH_xgate
472 case bfd_arch_xgate:
473 disassemble = print_insn_xgate;
474 break;
475 #endif
476 #ifdef ARCH_xstormy16
477 case bfd_arch_xstormy16:
478 disassemble = print_insn_xstormy16;
479 break;
480 #endif
481 #ifdef ARCH_xc16x
482 case bfd_arch_xc16x:
483 disassemble = print_insn_xc16x;
484 break;
485 #endif
486 #ifdef ARCH_xtensa
487 case bfd_arch_xtensa:
488 disassemble = print_insn_xtensa;
489 break;
490 #endif
491 #ifdef ARCH_z80
492 case bfd_arch_z80:
493 disassemble = print_insn_z80;
494 break;
495 #endif
496 #ifdef ARCH_z8k
497 case bfd_arch_z8k:
498 if (mach == bfd_mach_z8001)
499 disassemble = print_insn_z8001;
500 else
501 disassemble = print_insn_z8002;
502 break;
503 #endif
504 #ifdef ARCH_vax
505 case bfd_arch_vax:
506 disassemble = print_insn_vax;
507 break;
508 #endif
509 #ifdef ARCH_visium
510 case bfd_arch_visium:
511 disassemble = print_insn_visium;
512 break;
513 #endif
514 #ifdef ARCH_frv
515 case bfd_arch_frv:
516 disassemble = print_insn_frv;
517 break;
518 #endif
519 #ifdef ARCH_moxie
520 case bfd_arch_moxie:
521 disassemble = print_insn_moxie;
522 break;
523 #endif
524 #ifdef ARCH_iq2000
525 case bfd_arch_iq2000:
526 disassemble = print_insn_iq2000;
527 break;
528 #endif
529 #ifdef ARCH_m32c
530 case bfd_arch_m32c:
531 disassemble = print_insn_m32c;
532 break;
533 #endif
534 #ifdef ARCH_tilegx
535 case bfd_arch_tilegx:
536 disassemble = print_insn_tilegx;
537 break;
538 #endif
539 #ifdef ARCH_tilepro
540 case bfd_arch_tilepro:
541 disassemble = print_insn_tilepro;
542 break;
543 #endif
544 default:
545 return 0;
546 }
547 return disassemble;
548 }
549
550 void
551 disassembler_usage (FILE *stream ATTRIBUTE_UNUSED)
552 {
553 #ifdef ARCH_aarch64
554 print_aarch64_disassembler_options (stream);
555 #endif
556 #ifdef ARCH_arc
557 print_arc_disassembler_options (stream);
558 #endif
559 #ifdef ARCH_arm
560 print_arm_disassembler_options (stream);
561 #endif
562 #ifdef ARCH_mips
563 print_mips_disassembler_options (stream);
564 #endif
565 #ifdef ARCH_powerpc
566 print_ppc_disassembler_options (stream);
567 #endif
568 #ifdef ARCH_riscv
569 print_riscv_disassembler_options (stream);
570 #endif
571 #ifdef ARCH_i386
572 print_i386_disassembler_options (stream);
573 #endif
574 #ifdef ARCH_s390
575 print_s390_disassembler_options (stream);
576 #endif
577 #ifdef ARCH_wasm32
578 print_wasm32_disassembler_options (stream);
579 #endif
580
581 return;
582 }
583
584 void
585 disassemble_init_for_target (struct disassemble_info * info)
586 {
587 if (info == NULL)
588 return;
589
590 switch (info->arch)
591 {
592 #ifdef ARCH_aarch64
593 case bfd_arch_aarch64:
594 info->symbol_is_valid = aarch64_symbol_is_valid;
595 info->disassembler_needs_relocs = TRUE;
596 break;
597 #endif
598 #ifdef ARCH_arm
599 case bfd_arch_arm:
600 info->symbol_is_valid = arm_symbol_is_valid;
601 info->disassembler_needs_relocs = TRUE;
602 break;
603 #endif
604 #ifdef ARCH_ia64
605 case bfd_arch_ia64:
606 info->skip_zeroes = 16;
607 break;
608 #endif
609 #ifdef ARCH_tic4x
610 case bfd_arch_tic4x:
611 info->skip_zeroes = 32;
612 break;
613 #endif
614 #ifdef ARCH_mep
615 case bfd_arch_mep:
616 info->skip_zeroes = 256;
617 info->skip_zeroes_at_end = 0;
618 break;
619 #endif
620 #ifdef ARCH_metag
621 case bfd_arch_metag:
622 info->disassembler_needs_relocs = TRUE;
623 break;
624 #endif
625 #ifdef ARCH_m32c
626 case bfd_arch_m32c:
627 /* This processor in fact is little endian. The value set here
628 reflects the way opcodes are written in the cgen description. */
629 info->endian = BFD_ENDIAN_BIG;
630 if (! info->insn_sets)
631 {
632 info->insn_sets = cgen_bitset_create (ISA_MAX);
633 if (info->mach == bfd_mach_m16c)
634 cgen_bitset_set (info->insn_sets, ISA_M16C);
635 else
636 cgen_bitset_set (info->insn_sets, ISA_M32C);
637 }
638 break;
639 #endif
640 #ifdef ARCH_pru
641 case bfd_arch_pru:
642 info->disassembler_needs_relocs = TRUE;
643 break;
644 #endif
645 #ifdef ARCH_powerpc
646 case bfd_arch_powerpc:
647 #endif
648 #ifdef ARCH_rs6000
649 case bfd_arch_rs6000:
650 #endif
651 #if defined (ARCH_powerpc) || defined (ARCH_rs6000)
652 disassemble_init_powerpc (info);
653 break;
654 #endif
655 #ifdef ARCH_wasm32
656 case bfd_arch_wasm32:
657 disassemble_init_wasm32 (info);
658 break;
659 #endif
660 #ifdef ARCH_s390
661 case bfd_arch_s390:
662 disassemble_init_s390 (info);
663 break;
664 #endif
665 default:
666 break;
667 }
668 }
669
670 /* Remove whitespace and consecutive commas from OPTIONS. */
671
672 char *
673 remove_whitespace_and_extra_commas (char *options)
674 {
675 char *str;
676 size_t i, len;
677
678 if (options == NULL)
679 return NULL;
680
681 /* Strip off all trailing whitespace and commas. */
682 for (len = strlen (options); len > 0; len--)
683 {
684 if (!ISSPACE (options[len - 1]) && options[len - 1] != ',')
685 break;
686 options[len - 1] = '\0';
687 }
688
689 /* Convert all remaining whitespace to commas. */
690 for (i = 0; options[i] != '\0'; i++)
691 if (ISSPACE (options[i]))
692 options[i] = ',';
693
694 /* Remove consecutive commas. */
695 for (str = options; *str != '\0'; str++)
696 if (*str == ',' && (*(str + 1) == ',' || str == options))
697 {
698 char *next = str + 1;
699 while (*next == ',')
700 next++;
701 len = strlen (next);
702 if (str != options)
703 str++;
704 memmove (str, next, len);
705 next[len - (size_t)(next - str)] = '\0';
706 }
707 return (strlen (options) != 0) ? options : NULL;
708 }
709
710 /* Like STRCMP, but treat ',' the same as '\0' so that we match
711 strings like "foobar" against "foobar,xxyyzz,...". */
712
713 int
714 disassembler_options_cmp (const char *s1, const char *s2)
715 {
716 unsigned char c1, c2;
717
718 do
719 {
720 c1 = (unsigned char) *s1++;
721 if (c1 == ',')
722 c1 = '\0';
723 c2 = (unsigned char) *s2++;
724 if (c2 == ',')
725 c2 = '\0';
726 if (c1 == '\0')
727 return c1 - c2;
728 }
729 while (c1 == c2);
730
731 return c1 - c2;
732 }
This page took 0.049956 seconds and 5 git commands to generate.