1 /* Select disassembly routine for specified architecture.
2 Copyright (C) 1994-2018 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"
58 #define ARCH_microblaze
94 #define ARCH_xstormy16
103 #include "m32c-desc.h"
107 disassembler (enum bfd_architecture a
,
108 bfd_boolean big ATTRIBUTE_UNUSED
,
109 unsigned long mach ATTRIBUTE_UNUSED
,
110 bfd
*abfd ATTRIBUTE_UNUSED
)
112 disassembler_ftype disassemble
;
116 /* If you add a case to this table, also add it to the
117 ARCH_all definition right above this function. */
119 case bfd_arch_aarch64
:
120 disassemble
= print_insn_aarch64
;
125 disassemble
= print_insn_alpha
;
130 disassemble
= arc_get_disassembler (abfd
);
136 disassemble
= print_insn_big_arm
;
138 disassemble
= print_insn_little_arm
;
143 disassemble
= print_insn_avr
;
148 disassemble
= print_insn_bfin
;
153 disassemble
= print_insn_cr16
;
158 disassemble
= cris_get_disassembler (abfd
);
163 disassemble
= print_insn_crx
;
168 disassemble
= print_insn_d10v
;
173 disassemble
= print_insn_d30v
;
178 /* As far as I know we only handle big-endian DLX objects. */
179 disassemble
= print_insn_dlx
;
184 if (mach
== bfd_mach_h8300h
|| mach
== bfd_mach_h8300hn
)
185 disassemble
= print_insn_h8300h
;
186 else if (mach
== bfd_mach_h8300s
187 || mach
== bfd_mach_h8300sn
188 || mach
== bfd_mach_h8300sx
189 || mach
== bfd_mach_h8300sxn
)
190 disassemble
= print_insn_h8300s
;
192 disassemble
= print_insn_h8300
;
197 disassemble
= print_insn_hppa
;
205 disassemble
= print_insn_i386
;
210 disassemble
= print_insn_ia64
;
215 disassemble
= print_insn_ip2k
;
219 case bfd_arch_epiphany
:
220 disassemble
= print_insn_epiphany
;
225 disassemble
= print_insn_fr30
;
230 disassemble
= print_insn_lm32
;
235 disassemble
= print_insn_m32r
;
238 #if defined(ARCH_m68hc11) || defined(ARCH_m68hc12) \
239 || defined(ARCH_9s12x) || defined(ARCH_m9s12xg)
240 case bfd_arch_m68hc11
:
241 disassemble
= print_insn_m68hc11
;
243 case bfd_arch_m68hc12
:
244 disassemble
= print_insn_m68hc12
;
246 case bfd_arch_m9s12x
:
247 disassemble
= print_insn_m9s12x
;
249 case bfd_arch_m9s12xg
:
250 disassemble
= print_insn_m9s12xg
;
255 disassemble
= print_insn_m68k
;
260 disassemble
= print_insn_mt
;
263 #ifdef ARCH_microblaze
264 case bfd_arch_microblaze
:
265 disassemble
= print_insn_microblaze
;
269 case bfd_arch_msp430
:
270 disassemble
= print_insn_msp430
;
275 disassemble
= print_insn_nds32
;
280 disassemble
= print_insn_ns32k
;
285 disassemble
= print_insn_mcore
;
290 disassemble
= print_insn_mep
;
295 disassemble
= print_insn_metag
;
301 disassemble
= print_insn_big_mips
;
303 disassemble
= print_insn_little_mips
;
308 disassemble
= print_insn_mmix
;
312 case bfd_arch_mn10200
:
313 disassemble
= print_insn_mn10200
;
317 case bfd_arch_mn10300
:
318 disassemble
= print_insn_mn10300
;
324 disassemble
= print_insn_big_nios2
;
326 disassemble
= print_insn_little_nios2
;
331 disassemble
= print_insn_or1k
;
336 disassemble
= print_insn_pdp11
;
341 disassemble
= print_insn_pj
;
345 case bfd_arch_powerpc
:
348 case bfd_arch_rs6000
:
350 #if defined ARCH_powerpc || defined ARCH_rs6000
352 disassemble
= print_insn_big_powerpc
;
354 disassemble
= print_insn_little_powerpc
;
359 disassemble
= print_insn_pru
;
364 disassemble
= print_insn_riscv
;
369 disassemble
= rl78_get_disassembler (abfd
);
374 disassemble
= print_insn_rx
;
379 disassemble
= print_insn_s390
;
385 disassemble
= print_insn_big_score
;
387 disassemble
= print_insn_little_score
;
392 disassemble
= print_insn_sh
;
397 disassemble
= print_insn_sparc
;
402 disassemble
= print_insn_spu
;
407 disassemble
= print_insn_tic30
;
412 disassemble
= print_insn_tic4x
;
416 case bfd_arch_tic54x
:
417 disassemble
= print_insn_tic54x
;
422 disassemble
= print_insn_tic6x
;
427 disassemble
= print_insn_tic80
;
432 disassemble
= print_insn_ft32
;
437 case bfd_arch_v850_rh850
:
438 disassemble
= print_insn_v850
;
442 case bfd_arch_wasm32
:
443 disassemble
= print_insn_wasm32
;
448 disassemble
= print_insn_xgate
;
451 #ifdef ARCH_xstormy16
452 case bfd_arch_xstormy16
:
453 disassemble
= print_insn_xstormy16
;
458 disassemble
= print_insn_xc16x
;
462 case bfd_arch_xtensa
:
463 disassemble
= print_insn_xtensa
;
468 disassemble
= print_insn_z80
;
473 if (mach
== bfd_mach_z8001
)
474 disassemble
= print_insn_z8001
;
476 disassemble
= print_insn_z8002
;
481 disassemble
= print_insn_vax
;
485 case bfd_arch_visium
:
486 disassemble
= print_insn_visium
;
491 disassemble
= print_insn_frv
;
496 disassemble
= print_insn_moxie
;
500 case bfd_arch_iq2000
:
501 disassemble
= print_insn_iq2000
;
506 disassemble
= print_insn_m32c
;
510 case bfd_arch_tilegx
:
511 disassemble
= print_insn_tilegx
;
515 case bfd_arch_tilepro
:
516 disassemble
= print_insn_tilepro
;
526 disassembler_usage (FILE *stream ATTRIBUTE_UNUSED
)
529 print_aarch64_disassembler_options (stream
);
532 print_arc_disassembler_options (stream
);
535 print_arm_disassembler_options (stream
);
538 print_mips_disassembler_options (stream
);
541 print_ppc_disassembler_options (stream
);
544 print_riscv_disassembler_options (stream
);
547 print_i386_disassembler_options (stream
);
550 print_s390_disassembler_options (stream
);
553 print_wasm32_disassembler_options (stream
);
560 disassemble_init_for_target (struct disassemble_info
* info
)
568 case bfd_arch_aarch64
:
569 info
->symbol_is_valid
= aarch64_symbol_is_valid
;
570 info
->disassembler_needs_relocs
= TRUE
;
575 info
->symbol_is_valid
= arm_symbol_is_valid
;
576 info
->disassembler_needs_relocs
= TRUE
;
581 info
->skip_zeroes
= 16;
586 info
->skip_zeroes
= 32;
591 info
->skip_zeroes
= 256;
592 info
->skip_zeroes_at_end
= 0;
597 info
->disassembler_needs_relocs
= TRUE
;
602 /* This processor in fact is little endian. The value set here
603 reflects the way opcodes are written in the cgen description. */
604 info
->endian
= BFD_ENDIAN_BIG
;
605 if (! info
->insn_sets
)
607 info
->insn_sets
= cgen_bitset_create (ISA_MAX
);
608 if (info
->mach
== bfd_mach_m16c
)
609 cgen_bitset_set (info
->insn_sets
, ISA_M16C
);
611 cgen_bitset_set (info
->insn_sets
, ISA_M32C
);
617 info
->disassembler_needs_relocs
= TRUE
;
621 case bfd_arch_powerpc
:
624 case bfd_arch_rs6000
:
626 #if defined (ARCH_powerpc) || defined (ARCH_rs6000)
627 disassemble_init_powerpc (info
);
631 case bfd_arch_wasm32
:
632 disassemble_init_wasm32 (info
);
637 disassemble_init_s390 (info
);
645 /* Remove whitespace and consecutive commas from OPTIONS. */
648 remove_whitespace_and_extra_commas (char *options
)
656 /* Strip off all trailing whitespace and commas. */
657 for (len
= strlen (options
); len
> 0; len
--)
659 if (!ISSPACE (options
[len
- 1]) && options
[len
- 1] != ',')
661 options
[len
- 1] = '\0';
664 /* Convert all remaining whitespace to commas. */
665 for (i
= 0; options
[i
] != '\0'; i
++)
666 if (ISSPACE (options
[i
]))
669 /* Remove consecutive commas. */
670 for (str
= options
; *str
!= '\0'; str
++)
671 if (*str
== ',' && (*(str
+ 1) == ',' || str
== options
))
673 char *next
= str
+ 1;
679 memmove (str
, next
, len
);
680 next
[len
- (size_t)(next
- str
)] = '\0';
682 return (strlen (options
) != 0) ? options
: NULL
;
685 /* Like STRCMP, but treat ',' the same as '\0' so that we match
686 strings like "foobar" against "foobar,xxyyzz,...". */
689 disassembler_options_cmp (const char *s1
, const char *s2
)
691 unsigned char c1
, c2
;
695 c1
= (unsigned char) *s1
++;
698 c2
= (unsigned char) *s2
++;