Skip to content

Commit d7ef910

Browse files
Rot127R33v0LT
andauthored
Rebased #2570 (#2614)
* Add ARC files * Added ARC files for successful compilation * Refactor ARC files * Add ARC c/cs tests * Add ARC python test/bindings * Add ARC to CI/CD * Avoid omitting parameter names * Update cs files * Fix ARC bugs * Update ARC python bindings * Refactor and update ARC test files * Add detail flag to arc test * Fix ARC test problems * Fix ARCMapping compile error * Replace __CHAR_BIT__ to CHAR_BIT * Add credits and ARC info * Update ARC to match the latest next * Python formatting * Remove asserts on 'Unknown condition code passed' * Add ARC to some more documentation * Add ARC to Targets constants * Add ARC support to llvm-tblgen * Replace asserts & add Expr handling * Check DecodeGPR32RegisterClass return value * Fix fieldFromInstruction patch * Refactor ARC * Reformat python files * Fix incorrect import * Update inc files and insn names * Update python files * Disable AArch64 Linux wheel build due to #2615. --------- Co-authored-by: R33v0LT <[email protected]>
1 parent c831cd5 commit d7ef910

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+21579
-27
lines changed

.github/labeler.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ Alpha:
4848
- tests/MC/Alpha/**
4949
- tests/details/alpha.yaml
5050

51+
ARC:
52+
- arch/ARC/*
53+
- cstool/cstool_arc.c
54+
- include/capstone/arc.h
55+
- suite/MC/ARC/*
56+
- tests/test_arc.c
57+
5158
BPF:
5259
- arch/BPF/**
5360
- cstool/cstool_bpf.c

.github/workflows/auto-sync.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
cd vendor/llvm_root
5656
mkdir build
5757
cd build
58-
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ../llvm
58+
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=ARC ../llvm
5959
cmake --build . --target llvm-tblgen --config Debug
6060
cd ../../../
6161
@@ -74,6 +74,7 @@ jobs:
7474
run: |
7575
./src/autosync/ASUpdater.py -d -a AArch64 -s IncGen
7676
./src/autosync/ASUpdater.py -d -a Alpha -s IncGen
77+
./src/autosync/ASUpdater.py -d -a ARC -s IncGen
7778
./src/autosync/ASUpdater.py -d -a ARM -s IncGen
7879
./src/autosync/ASUpdater.py -d -a PPC -s IncGen
7980
./src/autosync/ASUpdater.py -d -a LoongArch -s IncGen
@@ -93,6 +94,7 @@ jobs:
9394
- name: CppTranslator - Test translation
9495
run: |
9596
./src/autosync/ASUpdater.py --ci -d -a AArch64 -s Translate
97+
./src/autosync/ASUpdater.py --ci -d -a ARC -s Translate
9698
./src/autosync/ASUpdater.py --ci -d -a ARM -s Translate
9799
./src/autosync/ASUpdater.py --ci -d -a PPC -s Translate
98100
./src/autosync/ASUpdater.py --ci -d -a LoongArch -s Translate

.github/workflows/build-wheels-publish.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ jobs:
5252
# x86_64 - musllinux
5353
- { os: ubuntu-latest, arch: x86_64, cibw_build: 'cp38-musllinux* cp313-musllinux*', cibw_skip: '' }
5454
# aarch64 - manylinux
55-
- { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp38-manylinux* cp313-manylinux*', cibw_skip: '' }
55+
# Disabled for now due to: https://github.com/capstone-engine/capstone/issues/2615
56+
# - { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp38-manylinux* cp313-manylinux*', cibw_skip: '' }
5657
# aarch64 - musllinux
57-
- { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp38-musllinux* cp313-musllinux*', cibw_skip: '' }
58+
# Disabled for now due to: https://github.com/capstone-engine/capstone/issues/2615
59+
# - { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp38-musllinux* cp313-musllinux*', cibw_skip: '' }
5860
# macos - x86_64
5961
- { os: macos-13, arch: x86_64, cibw_build: 'cp38* cp313*', cibw_skip: '' }
6062
# macos - arm64
@@ -162,15 +164,17 @@ jobs:
162164
- { os: ubuntu-latest, arch: x86_64, cibw_build: 'cp311-musllinux*', cibw_skip: '' }
163165
- { os: ubuntu-latest, arch: x86_64, cibw_build: 'cp312-musllinux*', cibw_skip: '' }
164166
# aarch64 - manylinux
165-
- { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp39-manylinux*', cibw_skip: '' }
166-
- { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp310-manylinux*', cibw_skip: '' }
167-
- { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp311-manylinux*', cibw_skip: '' }
168-
- { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp312-manylinux*', cibw_skip: '' }
167+
# Disabled for now due to: https://github.com/capstone-engine/capstone/issues/2615
168+
# - { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp39-manylinux*', cibw_skip: '' }
169+
# - { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp310-manylinux*', cibw_skip: '' }
170+
# - { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp311-manylinux*', cibw_skip: '' }
171+
# - { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp312-manylinux*', cibw_skip: '' }
169172
# aarch64 - musllinux
170-
- { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp39-musllinux*', cibw_skip: '' }
171-
- { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp310-musllinux*', cibw_skip: '' }
172-
- { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp311-musllinux*', cibw_skip: '' }
173-
- { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp312-musllinux*', cibw_skip: '' }
173+
# Disabled for now due to: https://github.com/capstone-engine/capstone/issues/2615
174+
# - { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp39-musllinux*', cibw_skip: '' }
175+
# - { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp310-musllinux*', cibw_skip: '' }
176+
# - { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp311-musllinux*', cibw_skip: '' }
177+
# - { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp312-musllinux*', cibw_skip: '' }
174178
# macos - x86_64
175179
- { os: macos-13, arch: x86_64, cibw_build: 'cp*', cibw_skip: '*36* *37* *38* *313*' }
176180
# macos - arm64

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ tests/test_riscv
7979
tests/test_sh
8080
tests/test_alpha
8181
tests/test_hppa
82+
tests/test_arc
8283

8384
# regress binaries
8485
suite/regress/invalid_read_in_print_operand

BUILDING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ By default all are enabled.
4444
- `CAPSTONE_ARM_SUPPORT`: Support ARM.
4545
- `CAPSTONE_AARCH64_SUPPORT`: Support AARCH64.
4646
- `CAPSTONE_ALPHA_SUPPORT`: Support Alpha.
47+
- `CAPSTONE_ARC_SUPPORT`: Support ARC.
4748
- `CAPSTONE_HPPA_SUPPORT`: Support HPPA.
4849
- `CAPSTONE_LOONGARCH_SUPPORT`: Support LoongArch.
4950
- `CAPSTONE_M680X_SUPPORT`: Support M680X.

CMakeLists.txt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ if(APPLE AND NOT CAPSTONE_BUILD_MACOS_THIN)
105105
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
106106
endif()
107107

108-
set(SUPPORTED_ARCHITECTURES ARM AARCH64 M68K MIPS PPC SPARC SYSTEMZ XCORE X86 TMS320C64X M680X EVM MOS65XX WASM BPF RISCV SH TRICORE ALPHA HPPA LOONGARCH XTENSA)
109-
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 Xtensa)
108+
set(SUPPORTED_ARCHITECTURES ARM AARCH64 M68K MIPS PPC SPARC SYSTEMZ XCORE X86 TMS320C64X M680X EVM MOS65XX WASM BPF RISCV SH TRICORE ALPHA HPPA LOONGARCH XTENSA ARC)
109+
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 Xtensa ARC)
110110

111111
# If building for OSX it's best to allow CMake to handle building both architectures
112112
if(APPLE AND NOT CAPSTONE_BUILD_MACOS_THIN)
@@ -232,6 +232,7 @@ set(HEADERS_COMMON
232232
include/capstone/hppa.h
233233
include/capstone/loongarch.h
234234
include/capstone/xtensa.h
235+
include/capstone/arc.h
235236
)
236237

237238
## architecture support
@@ -716,6 +717,22 @@ if(CAPSTONE_XTENSA_SUPPORT)
716717
)
717718
endif()
718719

720+
if (CAPSTONE_ARC_SUPPORT)
721+
add_definitions(-DCAPSTONE_HAS_ARC)
722+
set(SOURCES_ARC
723+
arch/ARC/ARCDisassembler.c
724+
arch/ARC/ARCInstPrinter.c
725+
arch/ARC/ARCMapping.c
726+
arch/ARC/ARCModule.c
727+
)
728+
set(HEADERS_ARC
729+
arch/ARC/ARCInstPrinter.h
730+
arch/ARC/ARCMapping.h
731+
arch/ARC/ARCModule.h
732+
arch/ARC/ARCLinkage.h
733+
)
734+
endif ()
735+
719736
if (CAPSTONE_OSXKERNEL_SUPPORT)
720737
add_definitions(-DCAPSTONE_HAS_OSXKERNEL)
721738
endif()
@@ -744,6 +761,7 @@ set(ALL_SOURCES
744761
${SOURCES_HPPA}
745762
${SOURCES_LOONGARCH}
746763
${SOURCES_XTENSA}
764+
${SOURCES_ARC}
747765
)
748766

749767
set(ALL_HEADERS
@@ -771,6 +789,7 @@ set(ALL_HEADERS
771789
${HEADERS_HPPA}
772790
${HEADERS_LOONGARCH}
773791
${HEADERS_XTENSA}
792+
${HEADERS_ARC}
774793
)
775794

776795
## properties
@@ -839,6 +858,7 @@ source_group("Source\\Alpha" FILES ${SOURCES_ALPHA})
839858
source_group("Source\\HPPA" FILES ${SOURCES_HPPA})
840859
source_group("Source\\LoongArch" FILES ${SOURCES_LOONGARCH})
841860
source_group("Source\\Xtensa" FILES ${SOURCES_XTENSA})
861+
source_group("Source\\ARC" FILES ${SOURCES_ARC})
842862

843863
source_group("Include\\Common" FILES ${HEADERS_COMMON})
844864
source_group("Include\\Engine" FILES ${HEADERS_ENGINE})
@@ -864,6 +884,7 @@ source_group("Include\\Alpha" FILES ${HEADERS_ALPHA})
864884
source_group("Include\\HPPA" FILES ${HEADERS_HPPA})
865885
source_group("Include\\LoongArch" FILES ${HEADERS_LOONGARCH})
866886
source_group("Include\\Xtensa" FILES ${HEADERS_XTENSA})
887+
source_group("Include\\ARC" FILES ${HEADERS_ARC})
867888

868889
## installation
869890
if(CAPSTONE_INSTALL)

COMPILE_MAKE.TXT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Capstone requires no prerequisite packages, so it is easy to compile & install.
9494
/usr/include/capstone/arm.h
9595
/usr/include/capstone/arm64.h
9696
/usr/include/capstone/alpha.h
97+
/usr/include/capstone/arc.h
9798
/usr/include/capstone/bpf.h
9899
/usr/include/capstone/capstone.h
99100
/usr/include/capstone/evm.h

CREDITS.TXT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ fanfuqiang & citypw & porto703 : RISCV architecture.
8888
Josh "blacktop" Maine: Arm64 architecture improvements.
8989
Finn Wilkinson: AArch64 update to Armv9.2-a (SME + SVE2 support)
9090
Billow & Sidneyp: TriCore architecture.
91-
Dmitry Sibirtsev: Alpha & HPPA architecture.
91+
Dmitry Sibirtsev: Alpha, HPPA, ARC architecture.
9292
Jiajie Chen & Yanglin Xun: LoongArch architecture.
9393
Billow: Xtensa architecture.

Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,21 @@ ifneq (,$(findstring xtensa,$(CAPSTONE_ARCHS)))
365365
LIBOBJ_XTENSA += $(LIBSRC_XTENSA:%.c=$(OBJDIR)/%.o)
366366
endif
367367

368+
DEP_ARC =
369+
DEP_ARC += $(wildcard arch/ARC/ARC*.inc)
370+
371+
LIBOBJ_ARC =
372+
ifneq (,$(findstring arc,$(CAPSTONE_ARCHS)))
373+
CFLAGS += -DCAPSTONE_HAS_ARC
374+
LIBSRC_ARC += $(wildcard arch/ARC/ARC*.c)
375+
LIBOBJ_ARC += $(LIBSRC_ARC:%.c=$(OBJDIR)/%.o)
376+
endif
377+
368378
LIBOBJ =
369379
LIBOBJ += $(OBJDIR)/cs.o $(OBJDIR)/utils.o $(OBJDIR)/SStream.o $(OBJDIR)/MCInstrDesc.o $(OBJDIR)/MCRegisterInfo.o $(OBJDIR)/MCInst.o $(OBJDIR)/MCInstPrinter.o $(OBJDIR)/Mapping.o
370380
LIBOBJ += $(LIBOBJ_ARM) $(LIBOBJ_AARCH64) $(LIBOBJ_M68K) $(LIBOBJ_MIPS) $(LIBOBJ_PPC) $(LIBOBJ_RISCV) $(LIBOBJ_SPARC) $(LIBOBJ_SYSZ) $(LIBOBJ_SH)
371381
LIBOBJ += $(LIBOBJ_X86) $(LIBOBJ_XCORE) $(LIBOBJ_TMS320C64X) $(LIBOBJ_M680X) $(LIBOBJ_EVM) $(LIBOBJ_MOS65XX) $(LIBOBJ_WASM) $(LIBOBJ_BPF)
372-
LIBOBJ += $(LIBOBJ_TRICORE) $(LIBOBJ_ALPHA) $(LIBOBJ_HPPA) $(LIBOBJ_LOONGARCH) $(LIBOBJ_XTENSA)
382+
LIBOBJ += $(LIBOBJ_TRICORE) $(LIBOBJ_ALPHA) $(LIBOBJ_HPPA) $(LIBOBJ_LOONGARCH) $(LIBOBJ_XTENSA) $(LIBOBJ_ARC)
373383

374384

375385
ifeq ($(PKG_EXTRA),)
@@ -503,6 +513,7 @@ $(LIBOBJ_ALPHA): $(DEP_ALPHA)
503513
$(LIBOBJ_HPPA): $(DEP_HPPA)
504514
$(LIBOBJ_LOONGARCH): $(DEP_LOONGARCH)
505515
$(LIBOBJ_XTENSA): $(DEP_XTENSA)
516+
$(LIBOBJ_ARC): $(DEP_ARC)
506517

507518
ifeq ($(CAPSTONE_STATIC),yes)
508519
$(ARCHIVE): $(LIBOBJ)

Mapping.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ DEFINE_get_detail_op(riscv, RISCV);
354354
DEFINE_get_detail_op(systemz, SystemZ);
355355
DEFINE_get_detail_op(xtensa, Xtensa);
356356
DEFINE_get_detail_op(bpf, BPF);
357+
DEFINE_get_detail_op(arc, ARC);
357358

358359
/// Returns true if for this architecture the
359360
/// alias operands should be filled.

Mapping.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ DECL_get_detail_op(riscv, RISCV);
146146
DECL_get_detail_op(systemz, SystemZ);
147147
DECL_get_detail_op(xtensa, Xtensa);
148148
DECL_get_detail_op(bpf, BPF);
149+
DECL_get_detail_op(arc, ARC);
149150

150151
/// Increments the detail->arch.op_count by one.
151152
#define DEFINE_inc_detail_op_count(arch, ARCH) \
@@ -185,6 +186,8 @@ DEFINE_inc_detail_op_count(xtensa, Xtensa);
185186
DEFINE_dec_detail_op_count(xtensa, Xtensa);
186187
DEFINE_inc_detail_op_count(bpf, BPF);
187188
DEFINE_dec_detail_op_count(bpf, BPF);
189+
DEFINE_inc_detail_op_count(arc, ARC);
190+
DEFINE_dec_detail_op_count(arc, ARC);
188191

189192
/// Returns true if a memory operand is currently edited.
190193
static inline bool doing_mem(const MCInst *MI)
@@ -215,6 +218,7 @@ DEFINE_get_arch_detail(hppa, HPPA);
215218
DEFINE_get_arch_detail(loongarch, LoongArch);
216219
DEFINE_get_arch_detail(mips, Mips);
217220
DEFINE_get_arch_detail(riscv, RISCV);
221+
DEFINE_get_arch_detail(arc, ARC);
218222
DEFINE_get_arch_detail(systemz, SystemZ);
219223
DEFINE_get_arch_detail(xtensa, Xtensa);
220224
DEFINE_get_arch_detail(bpf, BPF);
@@ -235,6 +239,7 @@ DEFINE_check_safe_inc(RISCV, RISCV);
235239
DEFINE_check_safe_inc(SystemZ, SYSTEMZ);
236240
DEFINE_check_safe_inc(Mips, MIPS);
237241
DEFINE_check_safe_inc(BPF, BPF);
242+
DEFINE_check_safe_inc(ARC, ARC);
238243

239244
static inline bool detail_is_set(const MCInst *MI)
240245
{

MathExtras.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,4 +493,12 @@ static inline uint32_t get_insn_bit(uint32_t insn, uint8_t bit)
493493
return get_insn_field(insn, bit, bit);
494494
}
495495

496+
/// \brief Create a bitmask with the N right-most bits set to 1, and all other
497+
/// bits set to 0. Only unsigned types are allowed.
498+
static inline uint32_t maskTrailingOnes32(uint32_t N)
499+
{
500+
const unsigned Bits = CHAR_BIT * sizeof(uint32_t);
501+
return N == 0 ? 0 : (((uint32_t) -1) >> (Bits - N));
502+
}
503+
496504
#endif

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ disasm engine for binary analysis and reversing in the security community.
1616
Created by Nguyen Anh Quynh, then developed and maintained by a small community,
1717
Capstone offers some unparalleled features:
1818

19-
- Support multiple hardware architectures: ARM, AArch64, Alpha, BPF, Ethereum VM,
19+
- Support multiple hardware architectures: ARM, AArch64, Alpha, ARC, BPF, Ethereum VM,
2020
LoongArch, HP PA-RISC (HPPA), M68K, M680X, Mips, MOS65XX, PPC, RISC-V(rv32G/rv64G), SH,
2121
Sparc, SystemZ, TMS320C64X, TriCore, Webassembly, XCore and X86 (16, 32, 64), Xtensa.
2222

0 commit comments

Comments
 (0)