Skip to content

Commit

Permalink
Merge branch 'next' into next_sh_op
Browse files Browse the repository at this point in the history
  • Loading branch information
david942j committed Sep 18, 2024
2 parents 0b9e8cb + 3a2cd3c commit 56861fa
Show file tree
Hide file tree
Showing 199 changed files with 181,611 additions and 69,031 deletions.
19 changes: 7 additions & 12 deletions .github/workflows/CITest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,20 @@ jobs:
# Work-around ASAN bug https://github.com/google/sanitizers/issues/1716
sudo sysctl vm.mmap_rnd_bits=28
- name: "Compatibility header test"
- name: unit tests
if: startsWith(matrix.config.build-system, 'cmake')
run: |
ctest --test-dir build --output-on-failure -R unit_*
- name: "Integration tests"
if: startsWith(matrix.config.build-system, 'cmake') && matrix.config.diet-build == 'OFF'
run: |
ctest --test-dir build --output-on-failure -R ASCompatibilityHeaderTest
ctest --test-dir build --output-on-failure -R integration_*
- name: cstool - reaches disassembler engine
run: |
sh suite/run_invalid_cstool.sh
- name: cstest unit tests
if: startsWith(matrix.config.build-system, 'cmake')
run: |
ctest --test-dir build --output-on-failure -R UnitCSTest
- name: cstest integration tests
if: startsWith(matrix.config.build-system, 'cmake')
run: |
ctest --test-dir build --output-on-failure -R IntegrationCSTest
- name: cstest MC
if: startsWith(matrix.config.build-system, 'cmake')
run: |
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/auto-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ jobs:
./src/autosync/ASUpdater.py -d -a PPC -s IncGen
./src/autosync/ASUpdater.py -d -a LoongArch -s IncGen
./src/autosync/ASUpdater.py -d -a Mips -s IncGen
./src/autosync/ASUpdater.py -d -a SystemZ -s IncGen
- name: CppTranslator - Patch tests
run: |
Expand All @@ -94,10 +95,4 @@ jobs:
./src/autosync/ASUpdater.py --ci -d -a PPC -s Translate
./src/autosync/ASUpdater.py --ci -d -a LoongArch -s Translate
./src/autosync/ASUpdater.py --ci -d -a Mips -s Translate
- name: Differ - Test save file is up-to-date
run: |
./src/autosync/cpptranslator/Differ.py -a AArch64 --check_saved
./src/autosync/cpptranslator/Differ.py -a ARM --check_saved
./src/autosync/cpptranslator/Differ.py -a PPC --check_saved
./src/autosync/cpptranslator/Differ.py -a LoongArch --check_saved
./src/autosync/ASUpdater.py --ci -d -a SystemZ -s Translate
2 changes: 1 addition & 1 deletion .github/workflows/coverity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Coverity Scan
on:
workflow_dispatch:
schedule:
- cron: '0 0 01 * *' # On the 1st every month at midnight UTC
- cron: '0 0 * * 1' # On every Monday at midnight UTC


# Automatically cancel any previous workflow on new push.
Expand Down
42 changes: 23 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ if(APPLE AND NOT CAPSTONE_BUILD_MACOS_THIN)
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
endif()

set(SUPPORTED_ARCHITECTURES ARM AARCH64 M68K MIPS PPC SPARC SYSZ XCORE X86 TMS320C64X M680X EVM MOS65XX WASM BPF RISCV SH TRICORE ALPHA HPPA LOONGARCH)
set(SUPPORTED_ARCHITECTURES ARM AARCH64 M68K MIPS PPC SPARC SYSTEMZ XCORE X86 TMS320C64X M680X EVM MOS65XX WASM BPF RISCV SH TRICORE ALPHA HPPA LOONGARCH)
set(SUPPORTED_ARCHITECTURE_LABELS ARM AARCH64 M68K MIPS PowerPC Sparc SystemZ XCore x86 TMS320C64x M680x EVM MOS65XX WASM BPF RISCV SH TriCore Alpha HPPA LoongArch)

# If building for OSX it's best to allow CMake to handle building both architectures
Expand Down Expand Up @@ -200,6 +200,7 @@ set(HEADERS_COMMON
include/capstone/x86.h
include/capstone/sparc.h
include/capstone/systemz.h
include/capstone/systemz_compatibility.h
include/capstone/xcore.h
include/capstone/m68k.h
include/capstone/tms320c64x.h
Expand Down Expand Up @@ -412,27 +413,34 @@ if(CAPSTONE_SPARC_SUPPORT)
)
endif()

if(CAPSTONE_SYSZ_SUPPORT)
add_definitions(-DCAPSTONE_HAS_SYSZ)
set(SOURCES_SYSZ
if(CAPSTONE_SYSTEMZ_SUPPORT)
add_definitions(-DCAPSTONE_HAS_SYSTEMZ)
set(SOURCES_SYSTEMZ
arch/SystemZ/SystemZDisassembler.c
arch/SystemZ/SystemZDisassemblerExtension.c
arch/SystemZ/SystemZInstPrinter.c
arch/SystemZ/SystemZMapping.c
arch/SystemZ/SystemZModule.c
arch/SystemZ/SystemZMCTargetDesc.c
)
set(HEADERS_SYSZ
arch/SystemZ/SystemZDisassembler.h
set(HEADERS_SYSTEMZ
arch/SystemZ/SystemZLinkage.h
arch/SystemZ/SystemZDisassemblerExtension.h
arch/SystemZ/SystemZInstPrinter.h
arch/SystemZ/SystemZMCTargetDesc.h
arch/SystemZ/SystemZMapping.h
arch/SystemZ/SystemZModule.h
arch/SystemZ/SystemZGenAsmWriter.inc
arch/SystemZ/SystemZGenCSAliasMnemMap.inc
arch/SystemZ/SystemZGenCSFeatureName.inc
arch/SystemZ/SystemZGenCSMappingInsn.inc
arch/SystemZ/SystemZGenCSMappingInsnName.inc
arch/SystemZ/SystemZGenCSMappingInsnOp.inc
arch/SystemZ/SystemZGenCSOpGroup.inc
arch/SystemZ/SystemZGenDisassemblerTables.inc
arch/SystemZ/SystemZGenInsnNameMaps.inc
arch/SystemZ/SystemZGenInstrInfo.inc
arch/SystemZ/SystemZGenRegisterInfo.inc
arch/SystemZ/SystemZGenSubtargetInfo.inc
arch/SystemZ/SystemZInstPrinter.h
arch/SystemZ/SystemZMapping.h
arch/SystemZ/SystemZMappingInsn.inc
arch/SystemZ/SystemZMCTargetDesc.h
)
endif()

Expand Down Expand Up @@ -688,7 +696,7 @@ set(ALL_SOURCES
${SOURCES_PPC}
${SOURCES_X86}
${SOURCES_SPARC}
${SOURCES_SYSZ}
${SOURCES_SYSTEMZ}
${SOURCES_XCORE}
${SOURCES_M68K}
${SOURCES_TMS320C64X}
Expand All @@ -714,7 +722,7 @@ set(ALL_HEADERS
${HEADERS_PPC}
${HEADERS_X86}
${HEADERS_SPARC}
${HEADERS_SYSZ}
${HEADERS_SYSTEMZ}
${HEADERS_XCORE}
${HEADERS_M68K}
${HEADERS_TMS320C64X}
Expand Down Expand Up @@ -765,7 +773,7 @@ source_group("Source\\AARCH64" FILES ${SOURCES_AARCH64})
source_group("Source\\Mips" FILES ${SOURCES_MIPS})
source_group("Source\\PowerPC" FILES ${SOURCES_PPC})
source_group("Source\\Sparc" FILES ${SOURCES_SPARC})
source_group("Source\\SystemZ" FILES ${SOURCES_SYSZ})
source_group("Source\\SystemZ" FILES ${SOURCES_SYSTEMZ})
source_group("Source\\X86" FILES ${SOURCES_X86})
source_group("Source\\XCore" FILES ${SOURCES_XCORE})
source_group("Source\\M68K" FILES ${SOURCES_M68K})
Expand All @@ -789,7 +797,7 @@ source_group("Include\\AARCH64" FILES ${HEADERS_AARCH64})
source_group("Include\\Mips" FILES ${HEADERS_MIPS})
source_group("Include\\PowerPC" FILES ${HEADERS_PPC})
source_group("Include\\Sparc" FILES ${HEADERS_SPARC})
source_group("Include\\SystemZ" FILES ${HEADERS_SYSZ})
source_group("Include\\SystemZ" FILES ${HEADERS_SYSTEMZ})
source_group("Include\\X86" FILES ${HEADERS_X86})
source_group("Include\\XCore" FILES ${HEADERS_XCORE})
source_group("Include\\M68K" FILES ${HEADERS_M68K})
Expand Down Expand Up @@ -898,8 +906,4 @@ if(CAPSTONE_BUILD_CSTEST)
add_subdirectory(${TESTS_INTEGRATION_DIR})
set(TESTS_UNIT_DIR ${PROJECT_SOURCE_DIR}/tests/unit)
add_subdirectory(${TESTS_UNIT_DIR})

# Unit tests for auto-sync
set(AUTO_SYNC_C_TEST_DIR ${PROJECT_SOURCE_DIR}/suite/auto-sync/c_tests/)
add_subdirectory(${AUTO_SYNC_C_TEST_DIR})
endif()
2 changes: 1 addition & 1 deletion COMPILE_CMAKE.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Get CMake for free from http://www.cmake.org.
- CAPSTONE_MOS65XX_SUPPORT: support MOS65XX. Run cmake with -DCAPSTONE_MOS65XX_SUPPORT=0 to remove MOS65XX.
- CAPSTONE_PPC_SUPPORT: support PPC. Run cmake with -DCAPSTONE_PPC_SUPPORT=0 to remove PPC.
- CAPSTONE_SPARC_SUPPORT: support Sparc. Run cmake with -DCAPSTONE_SPARC_SUPPORT=0 to remove Sparc.
- CAPSTONE_SYSZ_SUPPORT: support SystemZ. Run cmake with -DCAPSTONE_SYSZ_SUPPORT=0 to remove SystemZ.
- CAPSTONE_SYSTEMZ_SUPPORT: support SystemZ. Run cmake with -DCAPSTONE_SYSTEMZ_SUPPORT=0 to remove SystemZ.
- CAPSTONE_XCORE_SUPPORT: support XCore. Run cmake with -DCAPSTONE_XCORE_SUPPORT=0 to remove XCore.
- CAPSTONE_TRICORE_SUPPORT: support TriCore. Run cmake with -DCAPSTONE_TRICORE_SUPPORT=0 to remove TriCore.
- CAPSTONE_X86_SUPPORT: support X86. Run cmake with -DCAPSTONE_X86_SUPPORT=0 to remove X86.
Expand Down
19 changes: 19 additions & 0 deletions MCAsmInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright © 2024 Rot127 <[email protected]>
// SPDX-License-Identifier: BSD-3

/// The equivalent of the MCAsmInfo class in LLVM.
/// We save only some flags of the original class here.

#ifndef CS_MCASMINFO_H
#define CS_MCASMINFO_H

typedef enum {
SYSTEMZASMDIALECT_AD_ATT = 0,
SYSTEMZASMDIALECT_AD_HLASM = 1,
} MCAsmInfoAssemblerDialect;

typedef struct {
MCAsmInfoAssemblerDialect assemblerDialect;
} MCAsmInfo;

#endif // CS_MCASMINFO_H
16 changes: 15 additions & 1 deletion MCInst.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#define MCINST_CACHE (ARR_SIZE(mcInst->Operands) - 1)

void MCInst_Init(MCInst *inst)
void MCInst_Init(MCInst *inst, cs_arch arch)
{
// unnecessary to initialize in loop . its expensive and inst->size should be honored
inst->Operands[0].Kind = kInvalid;
Expand All @@ -37,6 +37,15 @@ void MCInst_Init(MCInst *inst)
inst->isAliasInstr = false;
inst->fillDetailOps = false;
memset(&inst->hppa_ext, 0, sizeof(inst->hppa_ext));

// Set default assembly dialect.
switch (arch) {
default:
break;
case CS_ARCH_SYSTEMZ:
inst->MAI.assemblerDialect = SYSTEMZASMDIALECT_AD_HLASM;
break;
}
}

void MCInst_clear(MCInst *inst)
Expand Down Expand Up @@ -150,6 +159,11 @@ int64_t MCOperand_getImm(const MCOperand *op)
return op->ImmVal;
}

int64_t MCOperand_getExpr(const MCOperand *op)
{
return op->ImmVal;
}

void MCOperand_setImm(MCOperand *op, int64_t Val)
{
op->ImmVal = Val;
Expand Down
6 changes: 5 additions & 1 deletion MCInst.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define CS_MCINST_H

#include "include/capstone/capstone.h"
#include "MCAsmInfo.h"
#include "MCInstrDesc.h"
#include "MCRegisterInfo.h"

Expand Down Expand Up @@ -73,6 +74,8 @@ int64_t MCOperand_getImm(const MCOperand *op);

void MCOperand_setImm(MCOperand *op, int64_t Val);

int64_t MCOperand_getExpr(const MCOperand *op);

double MCOperand_getFPImm(const MCOperand *op);

void MCOperand_setFPImm(MCOperand *op, double Val);
Expand Down Expand Up @@ -133,9 +136,10 @@ struct MCInst {
bool isAliasInstr; // Flag if this MCInst is an alias.
bool fillDetailOps; // If set, detail->operands gets filled.
hppa_ext hppa_ext; ///< for HPPA operand. Contains info about modifiers and their effect on the instruction
MCAsmInfo MAI; ///< The equivalent to MCAsmInfo in LLVM. It holds flags relevant for the asm style to print.
};

void MCInst_Init(MCInst *inst);
void MCInst_Init(MCInst *inst, cs_arch arch);

void MCInst_clear(MCInst *inst);

Expand Down
4 changes: 2 additions & 2 deletions MCInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ unsigned int binsearch_IndexTypeStrEncoding(const struct IndexTypeStr *index, si

right = size - 1;

size_t str_left_cmp = strcmp(name, index[0].name);
size_t str_right_cmp = strcmp(name, index[right].name);
int str_left_cmp = strcmp(name, index[0].name);
int str_right_cmp = strcmp(name, index[right].name);
if (str_left_cmp < 0 || str_right_cmp > 0)
// not found
return -1;
Expand Down
15 changes: 11 additions & 4 deletions Mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ void map_implicit_reads(MCInst *MI, const insn_map *imap)
return;
}
detail->regs_read[detail->regs_read_count++] = reg;
reg = imap[Opcode].regs_use[++i];
if (i + 1 < MAX_IMPL_R_REGS) {
// Select next one
reg = imap[Opcode].regs_use[++i];
}
}
#endif // CAPSTONE_DIET
}
Expand All @@ -175,7 +178,10 @@ void map_implicit_writes(MCInst *MI, const insn_map *imap)
return;
}
detail->regs_write[detail->regs_write_count++] = reg;
reg = imap[Opcode].regs_mod[++i];
if (i + 1 < MAX_IMPL_W_REGS) {
// Select next one
reg = imap[Opcode].regs_mod[++i];
}
}
#endif // CAPSTONE_DIET
}
Expand Down Expand Up @@ -340,14 +346,15 @@ DEFINE_get_detail_op(hppa, HPPA);
DEFINE_get_detail_op(loongarch, LoongArch);
DEFINE_get_detail_op(mips, Mips);
DEFINE_get_detail_op(riscv, RISCV);
DEFINE_get_detail_op(systemz, SystemZ);

/// Returns true if for this architecture the
/// alias operands should be filled.
/// TODO: Replace this with a proper option.
/// So it can be toggled between disas() calls.
bool map_use_alias_details(const MCInst *MI) {
assert(MI);
return !(MI->csh->detail_opt & CS_OPT_DETAIL_REAL);
return (MI->csh->detail_opt & CS_OPT_ON) && !(MI->csh->detail_opt & CS_OPT_DETAIL_REAL);
}

/// Sets the setDetailOps flag to @p Val.
Expand Down Expand Up @@ -433,7 +440,7 @@ uint64_t enum_map_bin_search(const cs_enum_id_map *map, size_t map_len,
} else if (id[i] > map[m].str[j]) {
l = m + 1;
}
if (m == 0 || (l + r) / 2 >= map_len) {
if ((m == 0 && id[i] < map[m].str[j]) || (l + r) / 2 >= map_len) {
// Break before we go out of bounds.
break;
}
Expand Down
21 changes: 21 additions & 0 deletions Mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef struct insn_map {
ppc_suppl_info ppc;
loongarch_suppl_info loongarch;
aarch64_suppl_info aarch64;
systemz_suppl_info systemz;
} suppl_info; // Supplementary information for each instruction.
#endif
} insn_map;
Expand Down Expand Up @@ -140,6 +141,7 @@ DECL_get_detail_op(hppa, HPPA);
DECL_get_detail_op(loongarch, LoongArch);
DECL_get_detail_op(mips, Mips);
DECL_get_detail_op(riscv, RISCV);
DECL_get_detail_op(systemz, SystemZ);

/// Increments the detail->arch.op_count by one.
#define DEFINE_inc_detail_op_count(arch, ARCH) \
Expand Down Expand Up @@ -173,6 +175,8 @@ DEFINE_inc_detail_op_count(mips, Mips);
DEFINE_dec_detail_op_count(mips, Mips);
DEFINE_inc_detail_op_count(riscv, RISCV);
DEFINE_dec_detail_op_count(riscv, RISCV);
DEFINE_inc_detail_op_count(systemz, SystemZ);
DEFINE_dec_detail_op_count(systemz, SystemZ);

/// Returns true if a memory operand is currently edited.
static inline bool doing_mem(const MCInst *MI)
Expand Down Expand Up @@ -203,6 +207,23 @@ DEFINE_get_arch_detail(hppa, HPPA);
DEFINE_get_arch_detail(loongarch, LoongArch);
DEFINE_get_arch_detail(mips, Mips);
DEFINE_get_arch_detail(riscv, RISCV);
DEFINE_get_arch_detail(systemz, SystemZ);

#define DEFINE_check_safe_inc(Arch, ARCH) \
static inline void Arch##_check_safe_inc() { \
CS_ASSERT(Arch##_get_detail(MI)->op_count + 1 < NUM_##ARCH##_OPS); \
}

DEFINE_check_safe_inc(ARM, ARM);
DEFINE_check_safe_inc(PPC, PPC);
DEFINE_check_safe_inc(TriCore, TRICORE);
DEFINE_check_safe_inc(AArch64, AARCH64);
DEFINE_check_safe_inc(Alpha, ALPHA);
DEFINE_check_safe_inc(HPPA, HPPA);
DEFINE_check_safe_inc(LoongArch, LOONGARCH);
DEFINE_check_safe_inc(RISCV, RISCV);
DEFINE_check_safe_inc(SystemZ, SYSTEMZ);
DEFINE_check_safe_inc(Mips, MIPS);

static inline bool detail_is_set(const MCInst *MI)
{
Expand Down
Loading

0 comments on commit 56861fa

Please sign in to comment.