1 /* Select disassembly routine for specified architecture.
2 Copyright (C) 1994-2017 Free Software Foundation, Inc.
4 This file is part of the GNU opcodes library.
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.
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.
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. */
22 #include "disassemble.h"
23 #include "safe-ctype.h"
63 #define ARCH_microblaze
99 #define ARCH_xstormy16
105 #define INCLUDE_SHMEDIA
109 #include "m32c-desc.h"
113 disassembler (enum bfd_architecture a, bfd_boolean big, unsigned long mach,
116 disassembler_ftype disassemble;
120 /* Do some asserts that the first three parameters should equal
121 to what we can get from ABFD. On the other hand, these
122 asserts help removing some compiler errors on unused
124 assert (a == bfd_get_arch (abfd));
125 assert (big == bfd_big_endian (abfd));
126 assert (mach == bfd_get_mach (abfd));
131 /* If you add a case to this table, also add it to the
132 ARCH_all definition right above this function. */
134 case bfd_arch_aarch64:
135 disassemble = print_insn_aarch64;
140 disassemble = print_insn_alpha;
145 disassemble = arc_get_disassembler (abfd);
151 disassemble = print_insn_big_arm;
153 disassemble = print_insn_little_arm;
158 disassemble = print_insn_avr;
163 disassemble = print_insn_bfin;
168 disassemble = print_insn_cr16;
173 disassemble = cris_get_disassembler (abfd);
178 disassemble = print_insn_crx;
183 disassemble = print_insn_d10v;
188 disassemble = print_insn_d30v;
193 /* As far as I know we only handle big-endian DLX objects. */
194 disassemble = print_insn_dlx;
199 if (mach == bfd_mach_h8300h || mach == bfd_mach_h8300hn)
200 disassemble = print_insn_h8300h;
201 else if (mach == bfd_mach_h8300s
202 || mach == bfd_mach_h8300sn
203 || mach == bfd_mach_h8300sx
204 || mach == bfd_mach_h8300sxn)
205 disassemble = print_insn_h8300s;
207 disassemble = print_insn_h8300;
212 disassemble = print_insn_h8500;
217 disassemble = print_insn_hppa;
222 disassemble = print_insn_i370;
230 disassemble = print_insn_i386;
235 disassemble = print_insn_i860;
240 disassemble = print_insn_i960;
245 disassemble = print_insn_ia64;
250 disassemble = print_insn_ip2k;
254 case bfd_arch_epiphany:
255 disassemble = print_insn_epiphany;
260 disassemble = print_insn_fr30;
265 disassemble = print_insn_lm32;
270 disassemble = print_insn_m32r;
273 #if defined(ARCH_m68hc11) || defined(ARCH_m68hc12) \
274 || defined(ARCH_9s12x) || defined(ARCH_m9s12xg)
275 case bfd_arch_m68hc11:
276 disassemble = print_insn_m68hc11;
278 case bfd_arch_m68hc12:
279 disassemble = print_insn_m68hc12;
281 case bfd_arch_m9s12x:
282 disassemble = print_insn_m9s12x;
284 case bfd_arch_m9s12xg:
285 disassemble = print_insn_m9s12xg;
290 disassemble = print_insn_m68k;
295 disassemble = print_insn_m88k;
300 disassemble = print_insn_mt;
303 #ifdef ARCH_microblaze
304 case bfd_arch_microblaze:
305 disassemble = print_insn_microblaze;
309 case bfd_arch_msp430:
310 disassemble = print_insn_msp430;
315 disassemble = print_insn_nds32;
320 disassemble = print_insn_ns32k;
325 disassemble = print_insn_mcore;
330 disassemble = print_insn_mep;
335 disassemble = print_insn_metag;
341 disassemble = print_insn_big_mips;
343 disassemble = print_insn_little_mips;
348 disassemble = print_insn_mmix;
352 case bfd_arch_mn10200:
353 disassemble = print_insn_mn10200;
357 case bfd_arch_mn10300:
358 disassemble = print_insn_mn10300;
364 disassemble = print_insn_big_nios2;
366 disassemble = print_insn_little_nios2;
371 disassemble = print_insn_or1k;
376 disassemble = print_insn_pdp11;
381 disassemble = print_insn_pj;
385 case bfd_arch_powerpc:
387 disassemble = print_insn_big_powerpc;
389 disassemble = print_insn_little_powerpc;
394 disassemble = print_insn_pru;
399 disassemble = print_insn_riscv;
403 case bfd_arch_rs6000:
404 if (mach == bfd_mach_ppc_620)
405 disassemble = print_insn_big_powerpc;
407 disassemble = print_insn_rs6000;
412 disassemble = rl78_get_disassembler (abfd);
417 disassemble = print_insn_rx;
422 disassemble = print_insn_s390;
428 disassemble = print_insn_big_score;
430 disassemble = print_insn_little_score;
435 disassemble = print_insn_sh;
440 disassemble = print_insn_sparc;
445 disassemble = print_insn_spu;
450 disassemble = print_insn_tic30;
455 disassemble = print_insn_tic4x;
459 case bfd_arch_tic54x:
460 disassemble = print_insn_tic54x;
465 disassemble = print_insn_tic6x;
470 disassemble = print_insn_tic80;
475 disassemble = print_insn_ft32;
480 case bfd_arch_v850_rh850:
481 disassemble = print_insn_v850;
486 disassemble = print_insn_w65;
490 case bfd_arch_wasm32:
491 disassemble = print_insn_wasm32;
496 disassemble = print_insn_xgate;
499 #ifdef ARCH_xstormy16
500 case bfd_arch_xstormy16:
501 disassemble = print_insn_xstormy16;
506 disassemble = print_insn_xc16x;
510 case bfd_arch_xtensa:
511 disassemble = print_insn_xtensa;
516 disassemble = print_insn_z80;
521 if (mach == bfd_mach_z8001)
522 disassemble = print_insn_z8001;
524 disassemble = print_insn_z8002;
529 disassemble = print_insn_vax;
533 case bfd_arch_visium:
534 disassemble = print_insn_visium;
539 disassemble = print_insn_frv;
544 disassemble = print_insn_moxie;
548 case bfd_arch_iq2000:
549 disassemble = print_insn_iq2000;
554 disassemble = print_insn_m32c;
558 case bfd_arch_tilegx:
559 disassemble = print_insn_tilegx;
563 case bfd_arch_tilepro:
564 disassemble = print_insn_tilepro;
574 disassembler_usage (FILE *stream ATTRIBUTE_UNUSED)
577 print_aarch64_disassembler_options (stream);
580 print_arc_disassembler_options (stream);
583 print_arm_disassembler_options (stream);
586 print_mips_disassembler_options (stream);
589 print_ppc_disassembler_options (stream);
592 print_riscv_disassembler_options (stream);
595 print_i386_disassembler_options (stream);
598 print_s390_disassembler_options (stream);
601 print_wasm32_disassembler_options (stream);
608 disassemble_init_for_target (struct disassemble_info * info)
616 case bfd_arch_aarch64:
617 info->symbol_is_valid = aarch64_symbol_is_valid;
618 info->disassembler_needs_relocs = TRUE;
623 info->symbol_is_valid = arm_symbol_is_valid;
624 info->disassembler_needs_relocs = TRUE;
629 info->skip_zeroes = 16;
634 info->skip_zeroes = 32;
639 info->skip_zeroes = 256;
640 info->skip_zeroes_at_end = 0;
645 info->disassembler_needs_relocs = TRUE;
650 /* This processor in fact is little endian. The value set here
651 reflects the way opcodes are written in the cgen description. */
652 info->endian = BFD_ENDIAN_BIG;
653 if (! info->insn_sets)
655 info->insn_sets = cgen_bitset_create (ISA_MAX);
656 if (info->mach == bfd_mach_m16c)
657 cgen_bitset_set (info->insn_sets, ISA_M16C);
659 cgen_bitset_set (info->insn_sets, ISA_M32C);
664 case bfd_arch_powerpc:
667 case bfd_arch_rs6000:
669 #if defined (ARCH_powerpc) || defined (ARCH_rs6000)
670 disassemble_init_powerpc (info);
674 case bfd_arch_wasm32:
675 disassemble_init_wasm32 (info);
680 disassemble_init_s390 (info);
688 /* Remove whitespace and consecutive commas from OPTIONS. */
691 remove_whitespace_and_extra_commas (char *options)
699 /* Strip off all trailing whitespace and commas. */
700 for (len = strlen (options); len > 0; len--)
702 if (!ISSPACE (options[len - 1]) && options[len - 1] != ',')
704 options[len - 1] = '\0';
707 /* Convert all remaining whitespace to commas. */
708 for (i = 0; options[i] != '\0'; i++)
709 if (ISSPACE (options[i]))
712 /* Remove consecutive commas. */
713 for (str = options; *str != '\0'; str++)
714 if (*str == ',' && (*(str + 1) == ',' || str == options))
716 char *next = str + 1;
722 memmove (str, next, len);
723 next[len - (size_t)(next - str)] = '\0';
725 return (strlen (options) != 0) ? options : NULL;
728 /* Like STRCMP, but treat ',' the same as '\0' so that we match
729 strings like "foobar" against "foobar,xxyyzz,...". */
732 disassembler_options_cmp (const char *s1, const char *s2)
734 unsigned char c1, c2;
738 c1 = (unsigned char) *s1++;
741 c2 = (unsigned char) *s2++;