1 /* Select disassembly routine for specified architecture.
2 Copyright (C) 1994-2024 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"
32 #define ARCH_loongarch
70 #define ARCH_microblaze
101 #define ARCH_xstormy16
109 #include "m32c-desc.h"
113 disassembler (enum bfd_architecture a
,
114 bool big ATTRIBUTE_UNUSED
,
115 unsigned long mach ATTRIBUTE_UNUSED
,
116 bfd
*abfd ATTRIBUTE_UNUSED
)
118 disassembler_ftype disassemble
;
122 /* If you add a case to this table, also add it to the
123 ARCH_all definition right above this function. */
125 case bfd_arch_aarch64
:
126 disassemble
= print_insn_aarch64
;
131 disassemble
= print_insn_alpha
;
136 disassemble
= arc_get_disassembler (abfd
);
142 disassemble
= print_insn_big_arm
;
144 disassemble
= print_insn_little_arm
;
149 disassemble
= print_insn_avr
;
154 disassemble
= print_insn_bfin
;
159 disassemble
= print_insn_cr16
;
164 disassemble
= cris_get_disassembler (abfd
);
169 disassemble
= print_insn_crx
;
174 disassemble
= csky_get_disassembler (abfd
);
180 disassemble
= print_insn_d10v
;
185 disassemble
= print_insn_d30v
;
190 /* As far as I know we only handle big-endian DLX objects. */
191 disassemble
= print_insn_dlx
;
196 if (mach
== bfd_mach_h8300h
|| mach
== bfd_mach_h8300hn
)
197 disassemble
= print_insn_h8300h
;
198 else if (mach
== bfd_mach_h8300s
199 || mach
== bfd_mach_h8300sn
200 || mach
== bfd_mach_h8300sx
201 || mach
== bfd_mach_h8300sxn
)
202 disassemble
= print_insn_h8300s
;
204 disassemble
= print_insn_h8300
;
209 disassemble
= print_insn_hppa
;
215 disassemble
= print_insn_i386
;
220 disassemble
= print_insn_ia64
;
225 disassemble
= print_insn_ip2k
;
230 disassemble
= print_insn_bpf
;
234 case bfd_arch_epiphany
:
235 disassemble
= print_insn_epiphany
;
240 disassemble
= print_insn_fr30
;
245 disassemble
= print_insn_kvx
;
250 disassemble
= print_insn_lm32
;
255 disassemble
= print_insn_m32r
;
258 #if defined(ARCH_m68hc11) || defined(ARCH_m68hc12) \
259 || defined(ARCH_9s12x) || defined(ARCH_m9s12xg)
260 case bfd_arch_m68hc11
:
261 disassemble
= print_insn_m68hc11
;
263 case bfd_arch_m68hc12
:
264 disassemble
= print_insn_m68hc12
;
266 case bfd_arch_m9s12x
:
267 disassemble
= print_insn_m9s12x
;
269 case bfd_arch_m9s12xg
:
270 disassemble
= print_insn_m9s12xg
;
273 #if defined(ARCH_s12z)
275 disassemble
= print_insn_s12z
;
280 disassemble
= print_insn_m68k
;
285 disassemble
= print_insn_mt
;
288 #ifdef ARCH_microblaze
289 case bfd_arch_microblaze
:
290 disassemble
= print_insn_microblaze
;
294 case bfd_arch_msp430
:
295 disassemble
= print_insn_msp430
;
300 disassemble
= print_insn_nds32
;
305 disassemble
= print_insn_nfp
;
310 disassemble
= print_insn_ns32k
;
315 disassemble
= print_insn_mcore
;
320 disassemble
= print_insn_mep
;
325 disassemble
= print_insn_metag
;
331 disassemble
= print_insn_big_mips
;
333 disassemble
= print_insn_little_mips
;
338 disassemble
= print_insn_mmix
;
342 case bfd_arch_mn10200
:
343 disassemble
= print_insn_mn10200
;
347 case bfd_arch_mn10300
:
348 disassemble
= print_insn_mn10300
;
354 disassemble
= print_insn_big_nios2
;
356 disassemble
= print_insn_little_nios2
;
361 disassemble
= print_insn_or1k
;
366 disassemble
= print_insn_pdp11
;
371 disassemble
= print_insn_pj
;
375 case bfd_arch_powerpc
:
378 case bfd_arch_rs6000
:
380 #if defined ARCH_powerpc || defined ARCH_rs6000
382 disassemble
= print_insn_big_powerpc
;
384 disassemble
= print_insn_little_powerpc
;
389 disassemble
= print_insn_pru
;
394 disassemble
= riscv_get_disassembler (abfd
);
399 disassemble
= rl78_get_disassembler (abfd
);
404 disassemble
= print_insn_rx
;
409 disassemble
= print_insn_s390
;
415 disassemble
= print_insn_big_score
;
417 disassemble
= print_insn_little_score
;
422 disassemble
= print_insn_sh
;
427 disassemble
= print_insn_sparc
;
432 disassemble
= print_insn_spu
;
437 disassemble
= print_insn_tic30
;
442 disassemble
= print_insn_tic4x
;
446 case bfd_arch_tic54x
:
447 disassemble
= print_insn_tic54x
;
452 disassemble
= print_insn_tic6x
;
457 disassemble
= print_insn_ft32
;
462 case bfd_arch_v850_rh850
:
463 disassemble
= print_insn_v850
;
467 case bfd_arch_wasm32
:
468 disassemble
= print_insn_wasm32
;
473 disassemble
= print_insn_xgate
;
476 #ifdef ARCH_xstormy16
477 case bfd_arch_xstormy16
:
478 disassemble
= print_insn_xstormy16
;
482 case bfd_arch_xtensa
:
483 disassemble
= print_insn_xtensa
;
488 disassemble
= print_insn_z80
;
493 if (mach
== bfd_mach_z8001
)
494 disassemble
= print_insn_z8001
;
496 disassemble
= print_insn_z8002
;
501 disassemble
= print_insn_vax
;
505 case bfd_arch_visium
:
506 disassemble
= print_insn_visium
;
511 disassemble
= print_insn_frv
;
516 disassemble
= print_insn_moxie
;
520 case bfd_arch_iq2000
:
521 disassemble
= print_insn_iq2000
;
526 disassemble
= print_insn_m32c
;
530 case bfd_arch_tilegx
:
531 disassemble
= print_insn_tilegx
;
535 case bfd_arch_tilepro
:
536 disassemble
= print_insn_tilepro
;
539 #ifdef ARCH_loongarch
540 case bfd_arch_loongarch
:
541 disassemble
= print_insn_loongarch
;
551 disassembler_usage (FILE *stream ATTRIBUTE_UNUSED
)
554 print_aarch64_disassembler_options (stream
);
557 print_arc_disassembler_options (stream
);
560 print_arm_disassembler_options (stream
);
563 print_mips_disassembler_options (stream
);
566 print_nfp_disassembler_options (stream
);
569 print_ppc_disassembler_options (stream
);
572 print_riscv_disassembler_options (stream
);
575 print_i386_disassembler_options (stream
);
578 print_kvx_disassembler_options (stream
);
581 print_s390_disassembler_options (stream
);
584 print_wasm32_disassembler_options (stream
);
586 #ifdef ARCH_loongarch
587 print_loongarch_disassembler_options (stream
);
590 print_bpf_disassembler_options (stream
);
596 disassemble_init_for_target (struct disassemble_info
* info
)
604 case bfd_arch_aarch64
:
605 info
->symbol_is_valid
= aarch64_symbol_is_valid
;
606 info
->disassembler_needs_relocs
= true;
607 info
->created_styled_output
= true;
612 info
->created_styled_output
= true;
617 info
->symbol_is_valid
= arm_symbol_is_valid
;
618 info
->disassembler_needs_relocs
= true;
619 info
->created_styled_output
= true;
624 info
->created_styled_output
= true;
629 info
->symbol_is_valid
= csky_symbol_is_valid
;
630 info
->disassembler_needs_relocs
= true;
636 info
->created_styled_output
= true;
641 info
->skip_zeroes
= 16;
644 #ifdef ARCH_loongarch
645 case bfd_arch_loongarch
:
646 info
->created_styled_output
= true;
651 info
->skip_zeroes
= 32;
656 info
->created_styled_output
= true;
661 info
->skip_zeroes
= 256;
662 info
->skip_zeroes_at_end
= 0;
667 info
->disassembler_needs_relocs
= true;
672 info
->created_styled_output
= true;
677 /* This processor in fact is little endian. The value set here
678 reflects the way opcodes are written in the cgen description. */
679 info
->endian
= BFD_ENDIAN_BIG
;
680 if (!info
->private_data
)
682 info
->private_data
= cgen_bitset_create (ISA_MAX
);
683 if (info
->mach
== bfd_mach_m16c
)
684 cgen_bitset_set (info
->private_data
, ISA_M16C
);
686 cgen_bitset_set (info
->private_data
, ISA_M32C
);
692 info
->created_styled_output
= true;
697 info
->disassembler_needs_relocs
= true;
701 case bfd_arch_powerpc
:
704 case bfd_arch_rs6000
:
706 #if defined (ARCH_powerpc) || defined (ARCH_rs6000)
707 disassemble_init_powerpc (info
);
708 info
->created_styled_output
= true;
713 info
->symbol_is_valid
= riscv_symbol_is_valid
;
714 info
->created_styled_output
= true;
718 case bfd_arch_wasm32
:
719 disassemble_init_wasm32 (info
);
724 disassemble_init_s390 (info
);
725 info
->created_styled_output
= true;
730 disassemble_init_nds32 (info
);
739 disassemble_free_target (struct disassemble_info
*info
)
752 #if defined ARCH_m32c
753 if (info
->private_data
)
755 CGEN_BITSET
*mask
= info
->private_data
;
778 case bfd_arch_powerpc
:
783 disassemble_free_riscv (info
);
787 case bfd_arch_rs6000
:
792 free (info
->private_data
);
795 /* Remove whitespace and consecutive commas from OPTIONS. */
798 remove_whitespace_and_extra_commas (char *options
)
806 /* Strip off all trailing whitespace and commas. */
807 for (len
= strlen (options
); len
> 0; len
--)
809 if (!ISSPACE (options
[len
- 1]) && options
[len
- 1] != ',')
811 options
[len
- 1] = '\0';
814 /* Convert all remaining whitespace to commas. */
815 for (i
= 0; options
[i
] != '\0'; i
++)
816 if (ISSPACE (options
[i
]))
819 /* Remove consecutive commas. */
820 for (str
= options
; *str
!= '\0'; str
++)
821 if (*str
== ',' && (*(str
+ 1) == ',' || str
== options
))
823 char *next
= str
+ 1;
829 memmove (str
, next
, len
);
830 next
[len
- (size_t)(next
- str
)] = '\0';
832 return (strlen (options
) != 0) ? options
: NULL
;
835 /* Like STRCMP, but treat ',' the same as '\0' so that we match
836 strings like "foobar" against "foobar,xxyyzz,...". */
839 disassembler_options_cmp (const char *s1
, const char *s2
)
841 unsigned char c1
, c2
;
845 c1
= (unsigned char) *s1
++;
848 c2
= (unsigned char) *s2
++;
860 opcodes_assert (const char *file
, int line
)
862 opcodes_error_handler (_("assertion fail %s:%d"), file
, line
);
863 opcodes_error_handler (_("Please report this bug"));
867 /* Set the stream, and the styled and unstyled printf functions within
871 disassemble_set_printf (struct disassemble_info
*info
, void *stream
,
872 fprintf_ftype unstyled_printf
,
873 fprintf_styled_ftype styled_printf
)
875 info
->stream
= stream
;
876 info
->fprintf_func
= unstyled_printf
;
877 info
->fprintf_styled_func
= styled_printf
;