1 /* Select disassembly routine for specified architecture.
2 Copyright (C) 1994-2019 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"
60 #define ARCH_microblaze
97 #define ARCH_xstormy16
106 #include "m32c-desc.h"
110 /* XXX this should be including bpf-desc.h instead of this hackery,
111 but at the moment it is not possible to include several CGEN
112 generated *-desc.h files simultaneously. To be fixed in
118 ISA_EBPFLE
, ISA_EBPFBE
, ISA_EBPFMAX
121 # include "bpf-desc.h"
122 # define ISA_EBPFMAX ISA_MAX
124 #endif /* ARCH_bpf */
127 disassembler (enum bfd_architecture a
,
128 bfd_boolean big ATTRIBUTE_UNUSED
,
129 unsigned long mach ATTRIBUTE_UNUSED
,
130 bfd
*abfd ATTRIBUTE_UNUSED
)
132 disassembler_ftype disassemble
;
136 /* If you add a case to this table, also add it to the
137 ARCH_all definition right above this function. */
139 case bfd_arch_aarch64
:
140 disassemble
= print_insn_aarch64
;
145 disassemble
= print_insn_alpha
;
150 disassemble
= arc_get_disassembler (abfd
);
156 disassemble
= print_insn_big_arm
;
158 disassemble
= print_insn_little_arm
;
163 disassemble
= print_insn_avr
;
168 disassemble
= print_insn_bfin
;
173 disassemble
= print_insn_cr16
;
178 disassemble
= cris_get_disassembler (abfd
);
183 disassemble
= print_insn_crx
;
188 disassemble
= csky_get_disassembler (abfd
);
194 disassemble
= print_insn_d10v
;
199 disassemble
= print_insn_d30v
;
204 /* As far as I know we only handle big-endian DLX objects. */
205 disassemble
= print_insn_dlx
;
210 if (mach
== bfd_mach_h8300h
|| mach
== bfd_mach_h8300hn
)
211 disassemble
= print_insn_h8300h
;
212 else if (mach
== bfd_mach_h8300s
213 || mach
== bfd_mach_h8300sn
214 || mach
== bfd_mach_h8300sx
215 || mach
== bfd_mach_h8300sxn
)
216 disassemble
= print_insn_h8300s
;
218 disassemble
= print_insn_h8300
;
223 disassemble
= print_insn_hppa
;
231 disassemble
= print_insn_i386
;
236 disassemble
= print_insn_ia64
;
241 disassemble
= print_insn_ip2k
;
246 disassemble
= print_insn_bpf
;
250 case bfd_arch_epiphany
:
251 disassemble
= print_insn_epiphany
;
256 disassemble
= print_insn_fr30
;
261 disassemble
= print_insn_lm32
;
266 disassemble
= print_insn_m32r
;
269 #if defined(ARCH_m68hc11) || defined(ARCH_m68hc12) \
270 || defined(ARCH_9s12x) || defined(ARCH_m9s12xg)
271 case bfd_arch_m68hc11
:
272 disassemble
= print_insn_m68hc11
;
274 case bfd_arch_m68hc12
:
275 disassemble
= print_insn_m68hc12
;
277 case bfd_arch_m9s12x
:
278 disassemble
= print_insn_m9s12x
;
280 case bfd_arch_m9s12xg
:
281 disassemble
= print_insn_m9s12xg
;
284 #if defined(ARCH_s12z)
286 disassemble
= print_insn_s12z
;
291 disassemble
= print_insn_m68k
;
296 disassemble
= print_insn_mt
;
299 #ifdef ARCH_microblaze
300 case bfd_arch_microblaze
:
301 disassemble
= print_insn_microblaze
;
305 case bfd_arch_msp430
:
306 disassemble
= print_insn_msp430
;
311 disassemble
= print_insn_nds32
;
316 disassemble
= print_insn_nfp
;
321 disassemble
= print_insn_ns32k
;
326 disassemble
= print_insn_mcore
;
331 disassemble
= print_insn_mep
;
336 disassemble
= print_insn_metag
;
342 disassemble
= print_insn_big_mips
;
344 disassemble
= print_insn_little_mips
;
349 disassemble
= print_insn_mmix
;
353 case bfd_arch_mn10200
:
354 disassemble
= print_insn_mn10200
;
358 case bfd_arch_mn10300
:
359 disassemble
= print_insn_mn10300
;
365 disassemble
= print_insn_big_nios2
;
367 disassemble
= print_insn_little_nios2
;
372 disassemble
= print_insn_or1k
;
377 disassemble
= print_insn_pdp11
;
382 disassemble
= print_insn_pj
;
386 case bfd_arch_powerpc
:
389 case bfd_arch_rs6000
:
391 #if defined ARCH_powerpc || defined ARCH_rs6000
393 disassemble
= print_insn_big_powerpc
;
395 disassemble
= print_insn_little_powerpc
;
400 disassemble
= print_insn_pru
;
405 disassemble
= print_insn_riscv
;
410 disassemble
= rl78_get_disassembler (abfd
);
415 disassemble
= print_insn_rx
;
420 disassemble
= print_insn_s390
;
426 disassemble
= print_insn_big_score
;
428 disassemble
= print_insn_little_score
;
433 disassemble
= print_insn_sh
;
438 disassemble
= print_insn_sparc
;
443 disassemble
= print_insn_spu
;
448 disassemble
= print_insn_tic30
;
453 disassemble
= print_insn_tic4x
;
457 case bfd_arch_tic54x
:
458 disassemble
= print_insn_tic54x
;
463 disassemble
= print_insn_tic6x
;
468 disassemble
= print_insn_ft32
;
473 case bfd_arch_v850_rh850
:
474 disassemble
= print_insn_v850
;
478 case bfd_arch_wasm32
:
479 disassemble
= print_insn_wasm32
;
484 disassemble
= print_insn_xgate
;
487 #ifdef ARCH_xstormy16
488 case bfd_arch_xstormy16
:
489 disassemble
= print_insn_xstormy16
;
494 disassemble
= print_insn_xc16x
;
498 case bfd_arch_xtensa
:
499 disassemble
= print_insn_xtensa
;
504 disassemble
= print_insn_z80
;
509 if (mach
== bfd_mach_z8001
)
510 disassemble
= print_insn_z8001
;
512 disassemble
= print_insn_z8002
;
517 disassemble
= print_insn_vax
;
521 case bfd_arch_visium
:
522 disassemble
= print_insn_visium
;
527 disassemble
= print_insn_frv
;
532 disassemble
= print_insn_moxie
;
536 case bfd_arch_iq2000
:
537 disassemble
= print_insn_iq2000
;
542 disassemble
= print_insn_m32c
;
546 case bfd_arch_tilegx
:
547 disassemble
= print_insn_tilegx
;
551 case bfd_arch_tilepro
:
552 disassemble
= print_insn_tilepro
;
562 disassembler_usage (FILE *stream ATTRIBUTE_UNUSED
)
565 print_aarch64_disassembler_options (stream
);
568 print_arc_disassembler_options (stream
);
571 print_arm_disassembler_options (stream
);
574 print_mips_disassembler_options (stream
);
577 print_nfp_disassembler_options (stream
);
580 print_ppc_disassembler_options (stream
);
583 print_riscv_disassembler_options (stream
);
586 print_i386_disassembler_options (stream
);
589 print_s390_disassembler_options (stream
);
592 print_wasm32_disassembler_options (stream
);
599 disassemble_init_for_target (struct disassemble_info
* info
)
607 case bfd_arch_aarch64
:
608 info
->symbol_is_valid
= aarch64_symbol_is_valid
;
609 info
->disassembler_needs_relocs
= TRUE
;
614 info
->symbol_is_valid
= arm_symbol_is_valid
;
615 info
->disassembler_needs_relocs
= TRUE
;
620 info
->symbol_is_valid
= csky_symbol_is_valid
;
621 info
->disassembler_needs_relocs
= TRUE
;
627 info
->skip_zeroes
= 16;
632 info
->skip_zeroes
= 32;
637 info
->skip_zeroes
= 256;
638 info
->skip_zeroes_at_end
= 0;
643 info
->disassembler_needs_relocs
= TRUE
;
648 /* This processor in fact is little endian. The value set here
649 reflects the way opcodes are written in the cgen description. */
650 info
->endian
= BFD_ENDIAN_BIG
;
651 if (!info
->private_data
)
653 info
->private_data
= cgen_bitset_create (ISA_MAX
);
654 if (info
->mach
== bfd_mach_m16c
)
655 cgen_bitset_set (info
->private_data
, ISA_M16C
);
657 cgen_bitset_set (info
->private_data
, ISA_M32C
);
663 if (!info
->private_data
)
665 info
->private_data
= cgen_bitset_create (ISA_EBPFMAX
);
666 if (info
->endian
== BFD_ENDIAN_BIG
)
667 cgen_bitset_set (info
->private_data
, ISA_EBPFBE
);
669 cgen_bitset_set (info
->private_data
, ISA_EBPFLE
);
675 info
->disassembler_needs_relocs
= TRUE
;
679 case bfd_arch_powerpc
:
682 case bfd_arch_rs6000
:
684 #if defined (ARCH_powerpc) || defined (ARCH_rs6000)
685 disassemble_init_powerpc (info
);
690 info
->symbol_is_valid
= riscv_symbol_is_valid
;
694 case bfd_arch_wasm32
:
695 disassemble_init_wasm32 (info
);
700 disassemble_init_s390 (info
);
705 disassemble_init_nds32 (info
);
714 disassemble_free_target (struct disassemble_info
*info
)
730 #if defined ARCH_bpf || defined ARCH_m32c
731 if (info
->private_data
)
733 CGEN_BITSET
*mask
= info
->private_data
;
756 case bfd_arch_powerpc
:
764 case bfd_arch_rs6000
:
769 free (info
->private_data
);
772 /* Remove whitespace and consecutive commas from OPTIONS. */
775 remove_whitespace_and_extra_commas (char *options
)
783 /* Strip off all trailing whitespace and commas. */
784 for (len
= strlen (options
); len
> 0; len
--)
786 if (!ISSPACE (options
[len
- 1]) && options
[len
- 1] != ',')
788 options
[len
- 1] = '\0';
791 /* Convert all remaining whitespace to commas. */
792 for (i
= 0; options
[i
] != '\0'; i
++)
793 if (ISSPACE (options
[i
]))
796 /* Remove consecutive commas. */
797 for (str
= options
; *str
!= '\0'; str
++)
798 if (*str
== ',' && (*(str
+ 1) == ',' || str
== options
))
800 char *next
= str
+ 1;
806 memmove (str
, next
, len
);
807 next
[len
- (size_t)(next
- str
)] = '\0';
809 return (strlen (options
) != 0) ? options
: NULL
;
812 /* Like STRCMP, but treat ',' the same as '\0' so that we match
813 strings like "foobar" against "foobar,xxyyzz,...". */
816 disassembler_options_cmp (const char *s1
, const char *s2
)
818 unsigned char c1
, c2
;
822 c1
= (unsigned char) *s1
++;
825 c2
= (unsigned char) *s2
++;