From 8b5b430287377951e44e9586fbd744276d2eef72 Mon Sep 17 00:00:00 2001 From: billow Date: Thu, 4 May 2023 19:51:53 +0800 Subject: [PATCH 1/2] fix tricore compiler warn `-Wmissing-prototypes` --- arch/TriCore/TriCoreDisassembler.c | 2 ++ arch/TriCore/TriCoreDisassembler.h | 2 ++ arch/TriCore/TriCoreInstPrinter.c | 5 ++++- arch/TriCore/TriCoreMapping.h | 3 +++ cstool/cstool.c | 20 +------------------- cstool/cstool.h | 23 +++++++++++++++++++++++ cstool/cstool_tricore.c | 2 ++ 7 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 cstool/cstool.h diff --git a/arch/TriCore/TriCoreDisassembler.c b/arch/TriCore/TriCoreDisassembler.c index b94b1fc928..dc7e05f57a 100644 --- a/arch/TriCore/TriCoreDisassembler.c +++ b/arch/TriCore/TriCoreDisassembler.c @@ -26,6 +26,8 @@ #include "../../MCDisassembler.h" #include "../../MathExtras.h" +#include "TriCoreDisassembler.h" + static bool readInstruction16(const uint8_t *code, size_t code_len, uint16_t *insn) { diff --git a/arch/TriCore/TriCoreDisassembler.h b/arch/TriCore/TriCoreDisassembler.h index 30bb4d12af..de4f53bf9a 100644 --- a/arch/TriCore/TriCoreDisassembler.h +++ b/arch/TriCore/TriCoreDisassembler.h @@ -18,4 +18,6 @@ bool TriCore_getInstruction(csh ud, const uint8_t *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *info); +bool TriCore_getFeatureBits(unsigned int mode, unsigned int feature); + #endif diff --git a/arch/TriCore/TriCoreInstPrinter.c b/arch/TriCore/TriCoreInstPrinter.c index 254b7d073e..7385f33f8a 100644 --- a/arch/TriCore/TriCoreInstPrinter.c +++ b/arch/TriCore/TriCoreInstPrinter.c @@ -514,11 +514,14 @@ typedef struct { uint64_t second; // Bits } MnemonicBitsInfo; -void set_mem_access(MCInst *MI, unsigned int access) +static void set_mem_access(MCInst *MI, unsigned int access) { // TODO: TriCore } +MnemonicBitsInfo getMnemonic(MCInst *MI, SStream *O); +bool printAliasInstr(MCInst *MI, uint64_t Address, SStream *OS); + #define PRINT_ALIAS_INSTR #include "TriCoreGenAsmWriter.inc" diff --git a/arch/TriCore/TriCoreMapping.h b/arch/TriCore/TriCoreMapping.h index 1eac1d3515..57ef507d27 100644 --- a/arch/TriCore/TriCoreMapping.h +++ b/arch/TriCore/TriCoreMapping.h @@ -15,4 +15,7 @@ const char *TriCore_insn_name(csh handle, unsigned int id); const char *TriCore_group_name(csh handle, unsigned int id); +cs_err TRICORE_global_init(cs_struct *ud); +cs_err TRICORE_option(cs_struct *handle, cs_opt_type type, size_t value); + #endif diff --git a/cstool/cstool.c b/cstool/cstool.c index 68e9051563..de1205c845 100644 --- a/cstool/cstool.c +++ b/cstool/cstool.c @@ -7,6 +7,7 @@ #include "getopt.h" #include +#include "cstool.h" void print_string_hex(const char *comment, unsigned char *str, size_t len); @@ -115,25 +116,6 @@ static struct { { NULL } }; -void print_insn_detail_x86(csh ud, cs_mode mode, cs_insn *ins); -void print_insn_detail_arm(csh handle, cs_insn *ins); -void print_insn_detail_arm64(csh handle, cs_insn *ins); -void print_insn_detail_mips(csh handle, cs_insn *ins); -void print_insn_detail_ppc(csh handle, cs_insn *ins); -void print_insn_detail_sparc(csh handle, cs_insn *ins); -void print_insn_detail_sysz(csh handle, cs_insn *ins); -void print_insn_detail_xcore(csh handle, cs_insn *ins); -void print_insn_detail_m68k(csh handle, cs_insn *ins); -void print_insn_detail_tms320c64x(csh handle, cs_insn *ins); -void print_insn_detail_m680x(csh handle, cs_insn *ins); -void print_insn_detail_evm(csh handle, cs_insn *ins); -void print_insn_detail_riscv(csh handle, cs_insn *ins); -void print_insn_detail_wasm(csh handle, cs_insn *ins); -void print_insn_detail_mos65xx(csh handle, cs_insn *ins); -void print_insn_detail_bpf(csh handle, cs_insn *ins); -void print_insn_detail_sh(csh handle, cs_insn *ins); -void print_insn_detail_tricore(csh handle, cs_insn *ins); - static void print_details(csh handle, cs_arch arch, cs_mode md, cs_insn *ins); void print_string_hex(const char *comment, unsigned char *str, size_t len) diff --git a/cstool/cstool.h b/cstool/cstool.h new file mode 100644 index 0000000000..118167618e --- /dev/null +++ b/cstool/cstool.h @@ -0,0 +1,23 @@ +#ifndef CAPSTONE_CSTOOL_CSTOOL_H_ +#define CAPSTONE_CSTOOL_CSTOOL_H_ + +void print_insn_detail_x86(csh ud, cs_mode mode, cs_insn *ins); +void print_insn_detail_arm(csh handle, cs_insn *ins); +void print_insn_detail_arm64(csh handle, cs_insn *ins); +void print_insn_detail_mips(csh handle, cs_insn *ins); +void print_insn_detail_ppc(csh handle, cs_insn *ins); +void print_insn_detail_sparc(csh handle, cs_insn *ins); +void print_insn_detail_sysz(csh handle, cs_insn *ins); +void print_insn_detail_xcore(csh handle, cs_insn *ins); +void print_insn_detail_m68k(csh handle, cs_insn *ins); +void print_insn_detail_tms320c64x(csh handle, cs_insn *ins); +void print_insn_detail_m680x(csh handle, cs_insn *ins); +void print_insn_detail_evm(csh handle, cs_insn *ins); +void print_insn_detail_riscv(csh handle, cs_insn *ins); +void print_insn_detail_wasm(csh handle, cs_insn *ins); +void print_insn_detail_mos65xx(csh handle, cs_insn *ins); +void print_insn_detail_bpf(csh handle, cs_insn *ins); +void print_insn_detail_sh(csh handle, cs_insn *ins); +void print_insn_detail_tricore(csh handle, cs_insn *ins); + +#endif //CAPSTONE_CSTOOL_CSTOOL_H_ diff --git a/cstool/cstool_tricore.c b/cstool/cstool_tricore.c index 45b0f53b20..8208317ac9 100644 --- a/cstool/cstool_tricore.c +++ b/cstool/cstool_tricore.c @@ -3,6 +3,8 @@ #include +#include "cstool.h" + void print_insn_detail_tricore(csh handle, cs_insn *ins) { cs_tricore *tricore; From 4f481272427d144cf2450a40e79bb857572783b0 Mon Sep 17 00:00:00 2001 From: billow Date: Mon, 8 May 2023 18:36:01 +0800 Subject: [PATCH 2/2] include cstool.h --- cstool/cstool_arm.c | 3 +-- cstool/cstool_arm64.c | 3 +-- cstool/cstool_bpf.c | 3 +-- cstool/cstool_evm.c | 3 +-- cstool/cstool_m680x.c | 4 +--- cstool/cstool_m68k.c | 3 +-- cstool/cstool_mips.c | 3 +-- cstool/cstool_mos65xx.c | 5 +---- cstool/{cstool_ppc.c => cstool_powerpc.c} | 4 +--- cstool/cstool_riscv.c | 3 +-- cstool/cstool_sh.c | 3 +-- cstool/cstool_sparc.c | 4 +--- cstool/cstool_systemz.c | 3 +-- cstool/cstool_tms320c64x.c | 3 +-- cstool/cstool_tricore.c | 3 +-- cstool/cstool_wasm.c | 3 +-- cstool/cstool_x86.c | 3 +-- cstool/cstool_xcore.c | 3 +-- 18 files changed, 18 insertions(+), 41 deletions(-) rename cstool/{cstool_ppc.c => cstool_powerpc.c} (97%) diff --git a/cstool/cstool_arm.c b/cstool/cstool_arm.c index 26cba3bd05..9ec6b43376 100644 --- a/cstool/cstool_arm.c +++ b/cstool/cstool_arm.c @@ -2,8 +2,7 @@ #include #include - -void print_insn_detail_arm(csh handle, cs_insn *ins); +#include "cstool.h" void print_insn_detail_arm(csh handle, cs_insn *ins) { diff --git a/cstool/cstool_arm64.c b/cstool/cstool_arm64.c index 065aa86238..f22328222e 100644 --- a/cstool/cstool_arm64.c +++ b/cstool/cstool_arm64.c @@ -5,8 +5,7 @@ #include #include - -void print_insn_detail_arm64(csh handle, cs_insn *ins); +#include "cstool.h" void print_insn_detail_arm64(csh handle, cs_insn *ins) { diff --git a/cstool/cstool_bpf.c b/cstool/cstool_bpf.c index 879f45fef6..a20f0aef5c 100644 --- a/cstool/cstool_bpf.c +++ b/cstool/cstool_bpf.c @@ -2,13 +2,12 @@ #include #include +#include "cstool.h" static const char * ext_name[] = { [BPF_EXT_LEN] = "#len", }; -void print_insn_detail_bpf(csh handle, cs_insn *ins); - void print_insn_detail_bpf(csh handle, cs_insn *ins) { unsigned i; diff --git a/cstool/cstool_evm.c b/cstool/cstool_evm.c index d3ecb5c341..9262eba0c8 100644 --- a/cstool/cstool_evm.c +++ b/cstool/cstool_evm.c @@ -2,8 +2,7 @@ #include #include - -void print_insn_detail_evm(csh handle, cs_insn *ins); +#include "cstool.h" void print_insn_detail_evm(csh handle, cs_insn *ins) { diff --git a/cstool/cstool_m680x.c b/cstool/cstool_m680x.c index b1f931a76e..c744b686e1 100644 --- a/cstool/cstool_m680x.c +++ b/cstool/cstool_m680x.c @@ -3,14 +3,12 @@ #include #include - -void print_insn_detail_m680x(csh handle, cs_insn *insn); +#include "cstool.h" static const char *s_access[] = { "UNCHANGED", "READ", "WRITE", "READ | WRITE", }; - static void print_read_write_regs(csh handle, cs_detail *detail) { int i; diff --git a/cstool/cstool_m68k.c b/cstool/cstool_m68k.c index 9d860ea99b..ca884a4169 100644 --- a/cstool/cstool_m68k.c +++ b/cstool/cstool_m68k.c @@ -8,8 +8,7 @@ #include #include - -void print_insn_detail_m68k(csh handle, cs_insn *ins); +#include "cstool.h" static const char* s_addressing_modes[] = { "", diff --git a/cstool/cstool_mips.c b/cstool/cstool_mips.c index df87aeae19..a2d7e35a0d 100644 --- a/cstool/cstool_mips.c +++ b/cstool/cstool_mips.c @@ -5,8 +5,7 @@ #include #include - -void print_insn_detail_mips(csh handle, cs_insn *ins); +#include "cstool.h" void print_insn_detail_mips(csh handle, cs_insn *ins) { diff --git a/cstool/cstool_mos65xx.c b/cstool/cstool_mos65xx.c index 316253f6ee..6791fdd01f 100644 --- a/cstool/cstool_mos65xx.c +++ b/cstool/cstool_mos65xx.c @@ -2,9 +2,7 @@ #include #include - -void print_insn_detail_mos65xx(csh handle, cs_insn *ins); - +#include "cstool.h" static const char *get_am_name(mos65xx_address_mode mode) { @@ -65,7 +63,6 @@ static const char *get_am_name(mos65xx_address_mode mode) } } - void print_insn_detail_mos65xx(csh handle, cs_insn *ins) { int i; diff --git a/cstool/cstool_ppc.c b/cstool/cstool_powerpc.c similarity index 97% rename from cstool/cstool_ppc.c rename to cstool/cstool_powerpc.c index 73de772fdf..79d1b55b6f 100644 --- a/cstool/cstool_ppc.c +++ b/cstool/cstool_powerpc.c @@ -4,9 +4,7 @@ #include #include - -void print_insn_detail_ppc(csh handle, cs_insn *ins); - +#include "cstool.h" static const char* get_bc_name(int bc) { diff --git a/cstool/cstool_riscv.c b/cstool/cstool_riscv.c index 2fd5b5be35..fcd60d09a9 100644 --- a/cstool/cstool_riscv.c +++ b/cstool/cstool_riscv.c @@ -3,8 +3,7 @@ #include #include - -void print_insn_detail_riscv(csh handle, cs_insn *ins); +#include "cstool.h" void print_insn_detail_riscv(csh handle, cs_insn *ins) { diff --git a/cstool/cstool_sh.c b/cstool/cstool_sh.c index 4440382ed1..5ce604c88b 100644 --- a/cstool/cstool_sh.c +++ b/cstool/cstool_sh.c @@ -6,8 +6,7 @@ #include #include - -void print_insn_detail_sh(csh handle, cs_insn *ins); +#include "cstool.h" static const char* s_addressing_modes[] = { "", diff --git a/cstool/cstool_sparc.c b/cstool/cstool_sparc.c index f3594a5969..0acdf8b706 100644 --- a/cstool/cstool_sparc.c +++ b/cstool/cstool_sparc.c @@ -4,9 +4,7 @@ #include #include - -void print_insn_detail_sparc(csh handle, cs_insn *ins); - +#include "cstool.h" void print_insn_detail_sparc(csh handle, cs_insn *ins) { diff --git a/cstool/cstool_systemz.c b/cstool/cstool_systemz.c index 002f9a80d1..aa3962685a 100644 --- a/cstool/cstool_systemz.c +++ b/cstool/cstool_systemz.c @@ -4,8 +4,7 @@ #include #include - -void print_insn_detail_sysz(csh handle, cs_insn *ins); +#include "cstool.h" void print_insn_detail_sysz(csh handle, cs_insn *ins) { diff --git a/cstool/cstool_tms320c64x.c b/cstool/cstool_tms320c64x.c index 7eae894aa8..f0db9a12ae 100644 --- a/cstool/cstool_tms320c64x.c +++ b/cstool/cstool_tms320c64x.c @@ -3,8 +3,7 @@ #include #include - -void print_insn_detail_tms320c64x(csh handle, cs_insn *ins); +#include "cstool.h" void print_insn_detail_tms320c64x(csh handle, cs_insn *ins) { diff --git a/cstool/cstool_tricore.c b/cstool/cstool_tricore.c index 8208317ac9..d5ac10dc6c 100644 --- a/cstool/cstool_tricore.c +++ b/cstool/cstool_tricore.c @@ -2,7 +2,6 @@ #include #include - #include "cstool.h" void print_insn_detail_tricore(csh handle, cs_insn *ins) @@ -70,4 +69,4 @@ void print_insn_detail_tricore(csh handle, cs_insn *ins) } } } -} \ No newline at end of file +} diff --git a/cstool/cstool_wasm.c b/cstool/cstool_wasm.c index 80bb2b9121..f353d8dfc4 100644 --- a/cstool/cstool_wasm.c +++ b/cstool/cstool_wasm.c @@ -2,8 +2,7 @@ #include #include - -void print_insn_detail_wasm(csh handle, cs_insn *ins); +#include "cstool.h" void print_insn_detail_wasm(csh handle, cs_insn *ins) { diff --git a/cstool/cstool_x86.c b/cstool/cstool_x86.c index e504e8a142..bba46d848b 100644 --- a/cstool/cstool_x86.c +++ b/cstool/cstool_x86.c @@ -4,8 +4,7 @@ #include #include - -void print_insn_detail_x86(csh ud, cs_mode mode, cs_insn *ins); +#include "cstool.h" void print_string_hex(const char *comment, unsigned char *str, size_t len); diff --git a/cstool/cstool_xcore.c b/cstool/cstool_xcore.c index 2ab95507a1..cab8be3b41 100644 --- a/cstool/cstool_xcore.c +++ b/cstool/cstool_xcore.c @@ -3,8 +3,7 @@ #include #include - -void print_insn_detail_xcore(csh handle, cs_insn *ins); +#include "cstool.h" void print_insn_detail_xcore(csh handle, cs_insn *ins) {