From 0861f561ebdd283e389c2c2fdb099bffadffecfa Mon Sep 17 00:00:00 2001 From: Cooper Qu Date: Wed, 26 Aug 2020 11:21:14 +0800 Subject: CSKY: Support attribute section. bfd * elf32-csky.c (csky_archs): Fix arch names. (csky_find_arch_with_name): New. (elf32_csky_merge_attributes): New. (csky_elf_merge_private_bfd_data): Add process of merge attribute section. (elf32_csky_obj_attrs_arg_type): New. (elf32_csky_obj_attrs_handle_unknown): New. (elf_backend_obj_attrs_vendor): Define. (elf_backend_obj_attrs_section): Define. (elf_backend_obj_attrs_arg_type): Define. (elf_backend_obj_attrs_section_type): Define. binutils/ * readelf.c (get_csky_section_type_name): New. (get_section_type_name): Add handler for CSKY. (display_csky_attribute): New. (process_arch_specific): Add handler for CSKY. * testsuite/binutils-all/strip-3.d: Remove .csky.attributes section. elfcpp/ * elfcpp.h (enum SHT): New enum SHT_CSKY_ATTRIBUTES. gas/ * gas/config/tc-csky.c (md_begin): Set attributes. (isa_flag): Change type to unsigned 64 bits. (struct csky_cpu_info): Likewise. (struct csky_macro_info): Likewise. (set_csky_attribute): New. * testsuite/gas/csky/802j.d: Ignore .csky.attributes section. * testsuite/gas/csky/all.d: Likewise. * testsuite/gas/csky/bsr1.d: Likewise. * testsuite/gas/csky/csky_vdsp.d: Likewise. * testsuite/gas/csky/cskyv2_all.d: Likewise. * testsuite/gas/csky/cskyv2_ck803r2.d: Likewise. * testsuite/gas/csky/cskyv2_ck860.d: Likewise. * testsuite/gas/csky/cskyv2_dsp.d: Likewise. * testsuite/gas/csky/cskyv2_elrw.d: Likewise. * testsuite/gas/csky/cskyv2_float.d: Likewise. * testsuite/gas/csky/enhance_dsp.d: Likewise. * testsuite/gas/csky/java.d: Likewise. * testsuite/gas/csky/v1_float.d: Likewise. * testsuite/gas/csky/v2_float_part1.d: Likewise. * testsuite/gas/csky/v2_float_part2.d: Likewise. * testsuite/gas/csky/v2_tls_gd.d: Likewise. * testsuite/gas/csky/v2_tls_ie.d: Likewise. * testsuite/gas/csky/v2_tls_ld.d: Likewise. * testsuite/gas/csky/v2_tls_le.d: Likewise. * testsuite/gas/elf/elf.exp: Add handler for CSKY. * testsuite/gas/elf/section2.e-csky: New. include/ * elf/csky.h (SHT_CSKY_ATTRIBUTES): Define. (Tag_CSKY_ARCH_NAME): New enum constant. (Tag_CSKY_CPU_NAME): Likewise. (Tag_CSKY_ISA_FLAGS): Likewise. (Tag_CSKY_DSP_VERSION): Likewise. (Tag_CSKY_VDSP_VERSION): Likewise. (Tag_CSKY_FPU_VERSION): Likewise. (Tag_CSKY_FPU_ABI): Likewise. (Tag_CSKY_FPU_ROUNDING): Likewise. (Tag_CSKY_FPU_DENORMAL): Likewise. (Tag_CSKY_FPU_Exception): Likewise. (Tag_CSKY_FPU_NUMBER_MODULE): Likewise. (Tag_CSKY_FPU_HARDFP): Likewise. (Tag_CSKY_MAX): Likewise. (VAL_CSKY_DSP_VERSION_EXTENSION): Likewise. (VAL_CSKY_DSP_VERSION_2): Likewise. (VAL_CSKY_VDSP_VERSION_1): Likewise. (VAL_CSKY_VDSP_VERSION_2): Likewise. (VAL_CSKY_FPU_ABI_SOFT): Likewise. (VAL_CSKY_FPU_ABI_SOFTFP): Likewise. (VAL_CSKY_FPU_ABI_HARD): Likewise. (VAL_CSKY_FPU_HARDFP_HALF): Likewise. (VAL_CSKY_FPU_HARDFP_SINGLE): Likewise. (VAL_CSKY_FPU_HARDFP_DOUBLE): Likewise. * opcode/csky.h (CSKY_ISA_VDSP_V2): Define. CSKYV1_ISA_E1: Change to long constant type. CSKYV2_ISA_E1: Likewise. CSKYV2_ISA_1E2: Likewise. CSKYV2_ISA_2E3: Likewise. CSKYV2_ISA_3E7: Likewise. CSKYV2_ISA_7E10: Likewise. CSKYV2_ISA_3E3R1: Likewise. CSKYV2_ISA_3E3R2: Likewise. CSKYV2_ISA_10E60: Likewise. CSKY_ISA_TRUST: Likewise. CSKY_ISA_CACHE: Likewise. CSKY_ISA_NVIC: Likewise. CSKY_ISA_CP: Likewise. CSKY_ISA_MP: Likewise. CSKY_ISA_MP_1E2: Likewise. CSKY_ISA_JAVA: Likewise. CSKY_ISA_MAC: Likewise. CSKY_ISA_MAC_DSP: Likewise. CSKY_ISA_DSP: Likewise. CSKY_ISA_DSP_1E2: Likewise. CSKY_ISA_DSP_ENHANCE: Likewise. CSKY_ISA_FLOAT_E1: Likewise. CSKY_ISA_FLOAT_1E2: Likewise. CSKY_ISA_FLOAT_1E3: Likewise. CSKY_ISA_FLOAT_3E4: Likewise. CSKY_ISA_VDSP: Likewise. ld/ * emulparams/cskyelf.sh: Support attribute section. * testsuite/ld-csky/tls-le-v1.d: Match .csky.attributes section. * ld/testsuite/ld-csky/tls-le.d: Likewise. * testsuite/ld-elf/non-contiguous.ld: Ignore .csky.attributes section. opcodes/ * csky-dis.c (CSKY_DEFAULT_ISA): Define. (csky_dis_info): Add member isa. (csky_find_inst_info): Skip instructions that do not belong to current CPU. (csky_get_disassembler): Get infomation from attribute section. (print_insn_csky): Set defualt ISA flag. * csky.h (CSKY_ISA_VDSP_2): Rename from CSKY_ISA_VDSP_V2. * csky-opc.h (struct csky_opcode): Change isa_flag16 and isa_flag32'type to unsigned 64 bits. --- opcodes/ChangeLog | 12 ++++++++++++ opcodes/csky-dis.c | 44 +++++++++++++++++++++++++++++++++++--------- opcodes/csky-opc.h | 4 ++-- 3 files changed, 49 insertions(+), 11 deletions(-) (limited to 'opcodes') diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index 9bf8562..71826bd 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,3 +1,15 @@ +2020-08-28 Cooper Qu + + * csky-dis.c (CSKY_DEFAULT_ISA): Define. + (csky_dis_info): Add member isa. + (csky_find_inst_info): Skip instructions that do not belong to + current CPU. + (csky_get_disassembler): Get infomation from attribute section. + (print_insn_csky): Set defualt ISA flag. + * csky.h (CSKY_ISA_VDSP_2): Rename from CSKY_ISA_VDSP_V2. + * csky-opc.h (struct csky_opcode): Change isa_flag16 and + isa_flag32'type to unsigned 64 bits. + 2020-08-26 Jose E. Marchesi * disassemble.c (enum epbf_isa_attr): Add ISA_XBPFBE, ISA_EBPFMAX. diff --git a/opcodes/csky-dis.c b/opcodes/csky-dis.c index 537725b..6becad0 100644 --- a/opcodes/csky-dis.c +++ b/opcodes/csky-dis.c @@ -23,6 +23,7 @@ #include "config.h" #include #include "bfd_stdint.h" +#include #include "disassemble.h" #include "elf-bfd.h" #include "opcode/csky.h" @@ -32,6 +33,7 @@ #define CSKY_INST_TYPE unsigned long #define HAS_SUB_OPERAND (unsigned int)0xffffffff +#define CSKY_DEFAULT_ISA 0xffffffff enum sym_type { @@ -47,6 +49,7 @@ struct csky_dis_info disassemble_info *info; /* Opcode information. */ struct csky_opcode_info const *opinfo; + BFD_HOST_U_64_BIT isa; /* The value of operand to show. */ int value; /* Whether to look up/print a symbol name. */ @@ -159,10 +162,8 @@ csky_find_inst_info (struct csky_opcode_info const **pinfo, p = g_opcodeP; while (p->mnemonic) { - /* FIXME: Skip 860's instruction in other CPUs. It is not suitable. - These codes need to be optimized. */ - if (((CSKY_ARCH_MASK & mach_flag) != CSKY_ARCH_860) - && (p->isa_flag32 & CSKYV2_ISA_10E60)) + if (!(p->isa_flag16 & dis_info.isa) + && !(p->isa_flag32 & dis_info.isa)) { p++; continue; @@ -235,9 +236,28 @@ csky_symbol_is_valid (asymbol *sym, disassembler_ftype csky_get_disassembler (bfd *abfd) { - if (abfd != NULL) - mach_flag = elf_elfheader (abfd)->e_flags; - return print_insn_csky; + obj_attribute *attr; + const char *sec_name = NULL; + if (!abfd) + return NULL; + + mach_flag = elf_elfheader (abfd)->e_flags; + + sec_name = get_elf_backend_data (abfd)->obj_attrs_section; + /* Skip any input that hasn't attribute section. + This enables to link object files without attribute section with + any others. */ + if (bfd_get_section_by_name (abfd, sec_name) != NULL) + { + attr = elf_known_obj_attributes_proc (abfd); + dis_info.isa = attr[Tag_CSKY_ISA_EXT_FLAGS].i; + dis_info.isa <<= 32; + dis_info.isa |= attr[Tag_CSKY_ISA_FLAGS].i; + } + else + dis_info.isa = CSKY_DEFAULT_ISA; + + return print_insn_csky; } static int @@ -937,10 +957,16 @@ print_insn_csky (bfd_vma memaddr, struct disassemble_info *info) if (mach_flag != INIT_MACH_FLAG && mach_flag != BINARY_MACH_FLAG) info->mach = mach_flag; else if (mach_flag == INIT_MACH_FLAG) - mach_flag = info->mach; + { + mach_flag = info->mach; + dis_info.isa = CSKY_DEFAULT_ISA; + } if (mach_flag == BINARY_MACH_FLAG && info->endian == BFD_ENDIAN_UNKNOWN) - info->endian = BFD_ENDIAN_LITTLE; + { + info->endian = BFD_ENDIAN_LITTLE; + dis_info.isa = CSKY_DEFAULT_ISA; + } /* First check the full symtab for a mapping symbol, even if there are no usable non-mapping symbols for this address. */ diff --git a/opcodes/csky-opc.h b/opcodes/csky-opc.h index 796d375..95df44d 100644 --- a/opcodes/csky-opc.h +++ b/opcodes/csky-opc.h @@ -262,8 +262,8 @@ struct csky_opcode /* Encodings for 32-bit opcodes. */ struct csky_opcode_info op32[OP_TABLE_NUM]; /* Instruction set flag. */ - unsigned int isa_flag16; - unsigned int isa_flag32; + BFD_HOST_U_64_BIT isa_flag16; + BFD_HOST_U_64_BIT isa_flag32; /* Whether this insn needs relocation, 0: no, !=0: yes. */ signed int reloc16; signed int reloc32; -- cgit v1.1