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
98 #define ARCH_xstormy16
107 #include "m32c-desc.h"
111 /* XXX this should be including bpf-desc.h instead of this hackery,
112 but at the moment it is not possible to include several CGEN
113 generated *-desc.h files simultaneously. To be fixed in
119 ISA_EBPFLE
, ISA_EBPFBE
, ISA_EBPFMAX
122 # include "bpf-desc.h"
123 # define ISA_EBPFMAX ISA_MAX
125 #endif /* ARCH_bpf */
128 disassembler (enum bfd_architecture a
,
129 bfd_boolean big ATTRIBUTE_UNUSED
,
130 unsigned long mach ATTRIBUTE_UNUSED
,
131 bfd
*abfd ATTRIBUTE_UNUSED
)
133 disassembler_ftype disassemble
;
137 /* If you add a case to this table, also add it to the
138 ARCH_all definition right above this function. */
140 case bfd_arch_aarch64
:
141 disassemble
= print_insn_aarch64
;
146 disassemble
= print_insn_alpha
;
151 disassemble
= arc_get_disassembler (abfd
);
157 disassemble
= print_insn_big_arm
;
159 disassemble
= print_insn_little_arm
;
164 disassemble
= print_insn_avr
;
169 disassemble
= print_insn_bfin
;
174 disassemble
= print_insn_cr16
;
179 disassemble
= cris_get_disassembler (abfd
);
184 disassemble
= print_insn_crx
;
189 disassemble
= csky_get_disassembler (abfd
);
195 disassemble
= print_insn_d10v
;
200 disassemble
= print_insn_d30v
;
205 /* As far as I know we only handle big-endian DLX objects. */
206 disassemble
= print_insn_dlx
;
211 if (mach
== bfd_mach_h8300h
|| mach
== bfd_mach_h8300hn
)
212 disassemble
= print_insn_h8300h
;
213 else if (mach
== bfd_mach_h8300s
214 || mach
== bfd_mach_h8300sn
215 || mach
== bfd_mach_h8300sx
216 || mach
== bfd_mach_h8300sxn
)
217 disassemble
= print_insn_h8300s
;
219 disassemble
= print_insn_h8300
;
224 disassemble
= print_insn_hppa
;
232 disassemble
= print_insn_i386
;
237 disassemble
= print_insn_ia64
;
242 disassemble
= print_insn_ip2k
;
247 disassemble
= print_insn_bpf
;
251 case bfd_arch_epiphany
:
252 disassemble
= print_insn_epiphany
;
257 disassemble
= print_insn_fr30
;
262 disassemble
= print_insn_lm32
;
267 disassemble
= print_insn_m32r
;
270 #if defined(ARCH_m68hc11) || defined(ARCH_m68hc12) \
271 || defined(ARCH_9s12x) || defined(ARCH_m9s12xg)
272 case bfd_arch_m68hc11
:
273 disassemble
= print_insn_m68hc11
;
275 case bfd_arch_m68hc12
:
276 disassemble
= print_insn_m68hc12
;
278 case bfd_arch_m9s12x
:
279 disassemble
= print_insn_m9s12x
;
281 case bfd_arch_m9s12xg
:
282 disassemble
= print_insn_m9s12xg
;
285 #if defined(ARCH_s12z)
287 disassemble
= print_insn_s12z
;
292 disassemble
= print_insn_m68k
;
297 disassemble
= print_insn_mt
;
300 #ifdef ARCH_microblaze
301 case bfd_arch_microblaze
:
302 disassemble
= print_insn_microblaze
;
306 case bfd_arch_msp430
:
307 disassemble
= print_insn_msp430
;
312 disassemble
= print_insn_nds32
;
317 disassemble
= print_insn_nfp
;
322 disassemble
= print_insn_ns32k
;
327 disassemble
= print_insn_mcore
;
332 disassemble
= print_insn_mep
;
337 disassemble
= print_insn_metag
;
343 disassemble
= print_insn_big_mips
;
345 disassemble
= print_insn_little_mips
;
350 disassemble
= print_insn_mmix
;
354 case bfd_arch_mn10200
:
355 disassemble
= print_insn_mn10200
;
359 case bfd_arch_mn10300
:
360 disassemble
= print_insn_mn10300
;
366 disassemble
= print_insn_big_nios2
;
368 disassemble
= print_insn_little_nios2
;
373 disassemble
= print_insn_or1k
;
378 disassemble
= print_insn_pdp11
;
383 disassemble
= print_insn_pj
;
387 case bfd_arch_powerpc
:
390 case bfd_arch_rs6000
:
392 #if defined ARCH_powerpc || defined ARCH_rs6000
394 disassemble
= print_insn_big_powerpc
;
396 disassemble
= print_insn_little_powerpc
;
401 disassemble
= print_insn_pru
;
406 disassemble
= print_insn_riscv
;
411 disassemble
= rl78_get_disassembler (abfd
);
416 disassemble
= print_insn_rx
;
421 disassemble
= print_insn_s390
;
427 disassemble
= print_insn_big_score
;
429 disassemble
= print_insn_little_score
;
434 disassemble
= print_insn_sh
;
439 disassemble
= print_insn_sparc
;
444 disassemble
= print_insn_spu
;
449 disassemble
= print_insn_tic30
;
454 disassemble
= print_insn_tic4x
;
458 case bfd_arch_tic54x
:
459 disassemble
= print_insn_tic54x
;
464 disassemble
= print_insn_tic6x
;
469 disassemble
= print_insn_tic80
;
474 disassemble
= print_insn_ft32
;
479 case bfd_arch_v850_rh850
:
480 disassemble
= print_insn_v850
;
484 case bfd_arch_wasm32
:
485 disassemble
= print_insn_wasm32
;
490 disassemble
= print_insn_xgate
;
493 #ifdef ARCH_xstormy16
494 case bfd_arch_xstormy16
:
495 disassemble
= print_insn_xstormy16
;
500 disassemble
= print_insn_xc16x
;
504 case bfd_arch_xtensa
:
505 disassemble
= print_insn_xtensa
;
510 disassemble
= print_insn_z80
;
515 if (mach
== bfd_mach_z8001
)
516 disassemble
= print_insn_z8001
;
518 disassemble
= print_insn_z8002
;
523 disassemble
= print_insn_vax
;
527 case bfd_arch_visium
:
528 disassemble
= print_insn_visium
;
533 disassemble
= print_insn_frv
;
538 disassemble
= print_insn_moxie
;
542 case bfd_arch_iq2000
:
543 disassemble
= print_insn_iq2000
;
548 disassemble
= print_insn_m32c
;
552 case bfd_arch_tilegx
:
553 disassemble
= print_insn_tilegx
;
557 case bfd_arch_tilepro
:
558 disassemble
= print_insn_tilepro
;
568 disassembler_usage (FILE *stream ATTRIBUTE_UNUSED
)
571 print_aarch64_disassembler_options (stream
);
574 print_arc_disassembler_options (stream
);
577 print_arm_disassembler_options (stream
);
580 print_mips_disassembler_options (stream
);
583 print_nfp_disassembler_options (stream
);
586 print_ppc_disassembler_options (stream
);
589 print_riscv_disassembler_options (stream
);
592 print_i386_disassembler_options (stream
);
595 print_s390_disassembler_options (stream
);
598 print_wasm32_disassembler_options (stream
);
605 disassemble_init_for_target (struct disassemble_info
* info
)
613 case bfd_arch_aarch64
:
614 info
->symbol_is_valid
= aarch64_symbol_is_valid
;
615 info
->disassembler_needs_relocs
= TRUE
;
620 info
->symbol_is_valid
= arm_symbol_is_valid
;
621 info
->disassembler_needs_relocs
= TRUE
;
626 info
->symbol_is_valid
= csky_symbol_is_valid
;
627 info
->disassembler_needs_relocs
= TRUE
;
633 info
->skip_zeroes
= 16;
638 info
->skip_zeroes
= 32;
643 info
->skip_zeroes
= 256;
644 info
->skip_zeroes_at_end
= 0;
649 info
->disassembler_needs_relocs
= TRUE
;
654 /* This processor in fact is little endian. The value set here
655 reflects the way opcodes are written in the cgen description. */
656 info
->endian
= BFD_ENDIAN_BIG
;
657 if (!info
->private_data
)
659 info
->private_data
= cgen_bitset_create (ISA_MAX
);
660 if (info
->mach
== bfd_mach_m16c
)
661 cgen_bitset_set (info
->private_data
, ISA_M16C
);
663 cgen_bitset_set (info
->private_data
, ISA_M32C
);
669 if (!info
->private_data
)
671 info
->private_data
= cgen_bitset_create (ISA_EBPFMAX
);
672 if (info
->endian
== BFD_ENDIAN_BIG
)
673 cgen_bitset_set (info
->private_data
, ISA_EBPFBE
);
675 cgen_bitset_set (info
->private_data
, ISA_EBPFLE
);
681 info
->disassembler_needs_relocs
= TRUE
;
685 case bfd_arch_powerpc
:
688 case bfd_arch_rs6000
:
690 #if defined (ARCH_powerpc) || defined (ARCH_rs6000)
691 disassemble_init_powerpc (info
);
696 info
->symbol_is_valid
= riscv_symbol_is_valid
;
700 case bfd_arch_wasm32
:
701 disassemble_init_wasm32 (info
);
706 disassemble_init_s390 (info
);
711 disassemble_init_nds32 (info
);
720 disassemble_free_target (struct disassemble_info
*info
)
736 #if defined ARCH_bpf || defined ARCH_m32c
737 if (info
->private_data
)
739 CGEN_BITSET
*mask
= info
->private_data
;
762 case bfd_arch_powerpc
:
770 case bfd_arch_rs6000
:
775 free (info
->private_data
);
778 /* Remove whitespace and consecutive commas from OPTIONS. */
781 remove_whitespace_and_extra_commas (char *options
)
789 /* Strip off all trailing whitespace and commas. */
790 for (len
= strlen (options
); len
> 0; len
--)
792 if (!ISSPACE (options
[len
- 1]) && options
[len
- 1] != ',')
794 options
[len
- 1] = '\0';
797 /* Convert all remaining whitespace to commas. */
798 for (i
= 0; options
[i
] != '\0'; i
++)
799 if (ISSPACE (options
[i
]))
802 /* Remove consecutive commas. */
803 for (str
= options
; *str
!= '\0'; str
++)
804 if (*str
== ',' && (*(str
+ 1) == ',' || str
== options
))
806 char *next
= str
+ 1;
812 memmove (str
, next
, len
);
813 next
[len
- (size_t)(next
- str
)] = '\0';
815 return (strlen (options
) != 0) ? options
: NULL
;
818 /* Like STRCMP, but treat ',' the same as '\0' so that we match
819 strings like "foobar" against "foobar,xxyyzz,...". */
822 disassembler_options_cmp (const char *s1
, const char *s2
)
824 unsigned char c1
, c2
;
828 c1
= (unsigned char) *s1
++;
831 c2
= (unsigned char) *s2
++;