Skip to content

Staging big changes for 2.2.0 #2145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 128 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ option(UNICORN_FUZZ "Enable fuzzing" OFF)
option(UNICORN_LOGGING "Enable logging" OFF)
option(UNICORN_BUILD_TESTS "Build unicorn tests" ${PROJECT_IS_TOP_LEVEL})
option(UNICORN_INSTALL "Enable unicorn installation" ${PROJECT_IS_TOP_LEVEL})
set(UNICORN_ARCH "x86;arm;aarch64;riscv;mips;sparc;m68k;ppc;s390x;tricore" CACHE STRING "Enabled unicorn architectures")
set(UNICORN_ARCH "x86;arm;aarch64;riscv;mips;sparc;m68k;ppc;rh850;s390x;tricore;avr" CACHE STRING "Enabled unicorn architectures")
option(UNICORN_TRACER "Trace unicorn execution" OFF)
option(UNICORN_INTERPRETER "Use interpreter mode" OFF)

foreach(ARCH_LOOP ${UNICORN_ARCH})
string(TOUPPER "${ARCH_LOOP}" ARCH_LOOP)
Expand Down Expand Up @@ -273,10 +274,24 @@ else()
set(UNICORN_TARGET_ARCH "tricore")
break()
endif()
string(FIND ${UC_COMPILER_MACRO} "__AVR__" UC_RET)
if (${UC_RET} GREATER_EQUAL "0")
set(UNICORN_TARGET_ARCH "avr")
break()
endif()
string(FIND ${UC_COMPILER_MACRO} "loongarch64" UC_RET)
if (${UC_RET} GREATER_EQUAL "0")
set(UNICORN_TARGET_ARCH "loongarch64")
break()
endif()
message(FATAL_ERROR "Unknown host compiler: ${CMAKE_C_COMPILER}.")
endwhile(TRUE)
endif()

if(UNICORN_INTERPRETER)
set(UNICORN_TARGET_ARCH "tci")
endif()

set(EXTRA_CFLAGS "--extra-cflags=")
if(UNICORN_HAS_X86)
set(EXTRA_CFLAGS "${EXTRA_CFLAGS}-DUNICORN_HAS_X86 ")
Expand All @@ -299,6 +314,9 @@ else()
if(UNICORN_HAS_PPC)
set(EXTRA_CFLAGS "${EXTRA_CFLAGS}-DUNICORN_HAS_PPC ")
endif()
if(UNICORN_HAS_RH850)
set(EXTRA_CFLAGS "${EXTRA_CFLAGS}-DUNICORN_HAS_RH850 ")
endif()
if(UNICORN_HAS_RISCV)
set(EXTRA_CFLAGS "${EXTRA_CFLAGS}-DUNICORN_HAS_RISCV ")
endif()
Expand All @@ -308,6 +326,9 @@ else()
if (UNICORN_HAS_TRICORE)
set (EXTRA_CFLAGS "${EXTRA_CFLAGS}-DUNICORN_HAS_TRICORE ")
endif()
if (UNICORN_HAS_AVR)
set (EXTRA_CFLAGS "${EXTRA_CFLAGS}-DUNICORN_HAS_AVR ")
endif()

set(EXTRA_CFLAGS "${EXTRA_CFLAGS}-fPIC")
if(ANDROID_ABI)
Expand Down Expand Up @@ -350,6 +371,9 @@ else()
if(UNICORN_HAS_PPC)
set(TARGET_LIST "${TARGET_LIST}ppc-softmmu, ppc64-softmmu, ")
endif()
if(UNICORN_HAS_RH850)
set(TARGET_LIST "${TARGET_LIST}rh850-softmmu, ")
endif()
if(UNICORN_HAS_RISCV)
set(TARGET_LIST "${TARGET_LIST}riscv32-softmmu, riscv64-softmmu, ")
endif()
Expand All @@ -359,13 +383,23 @@ else()
if (UNICORN_HAS_TRICORE)
set (TARGET_LIST "${TARGET_LIST}tricore-softmmu, ")
endif()
if (UNICORN_HAS_AVR)
set (TARGET_LIST "${TARGET_LIST}avr-softmmu, ")
endif()
set(TARGET_LIST "${TARGET_LIST} ")

# GEN config-host.mak & target directories
set(UNICORN_EXECUTION_MODE "")
if(UNICORN_INTERPRETER)
set(UNICORN_EXECUTION_MODE "--enable-interpreter")
else()
set(UNICORN_EXECUTION_MODE "--disable-interpreter")
endif()
execute_process(COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/qemu/configure
--cc=${CMAKE_C_COMPILER}
${EXTRA_CFLAGS}
${TARGET_LIST}
${UNICORN_EXECUTION_MODE}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
execute_process(COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/qemu/scripts/create_config
Expand Down Expand Up @@ -434,6 +468,12 @@ else()
OUTPUT_FILE ${CMAKE_BINARY_DIR}/ppc64-softmmu/config-target.h
)
endif()
if(UNICORN_HAS_RH850)
execute_process(COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/qemu/scripts/create_config
INPUT_FILE ${CMAKE_BINARY_DIR}/rh850-softmmu/config-target.mak
OUTPUT_FILE ${CMAKE_BINARY_DIR}/rh850-softmmu/config-target.h
)
endif()
if(UNICORN_HAS_RISCV)
execute_process(COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/qemu/scripts/create_config
INPUT_FILE ${CMAKE_BINARY_DIR}/riscv32-softmmu/config-target.mak
Expand All @@ -456,6 +496,12 @@ else()
OUTPUT_FILE ${CMAKE_BINARY_DIR}/tricore-softmmu/config-target.h
)
endif()
if (UNICORN_HAS_AVR)
execute_process(COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/qemu/scripts/create_config
INPUT_FILE ${CMAKE_BINARY_DIR}/avr-softmmu/config-target.mak
OUTPUT_FILE ${CMAKE_BINARY_DIR}/avr-softmmu/config-target.h
)
endif()
add_compile_options(
${UNICORN_CFLAGS}
-I${CMAKE_CURRENT_SOURCE_DIR}/qemu/tcg/${UNICORN_TARGET_ARCH}
Expand Down Expand Up @@ -507,6 +553,10 @@ set(UNICORN_ARCH_COMMON
qemu/softmmu/unicorn_vtlb.c
)

if(UNICORN_INTERPRETER)
list(APPEND UNICORN_ARCH_COMMON qemu/tcg/tci.c)
endif()

if(UNICORN_HAS_X86)
add_library(x86_64-softmmu STATIC
${UNICORN_ARCH_COMMON}
Expand Down Expand Up @@ -568,6 +618,7 @@ add_library(arm-softmmu STATIC
qemu/target/arm/helper.c
qemu/target/arm/iwmmxt_helper.c
qemu/target/arm/m_helper.c
qemu/target/arm/mte_helper.c
qemu/target/arm/neon_helper.c
qemu/target/arm/op_helper.c
qemu/target/arm/psci.c
Expand Down Expand Up @@ -612,6 +663,7 @@ add_library(aarch64-softmmu STATIC
qemu/target/arm/helper.c
qemu/target/arm/iwmmxt_helper.c
qemu/target/arm/m_helper.c
qemu/target/arm/mte_helper.c
qemu/target/arm/neon_helper.c
qemu/target/arm/op_helper.c
qemu/target/arm/pauth_helper.c
Expand Down Expand Up @@ -1019,6 +1071,7 @@ add_library(riscv32-softmmu STATIC
qemu/target/riscv/pmp.c
qemu/target/riscv/translate.c
qemu/target/riscv/unicorn.c
qemu/target/riscv/vector_helper.c
)

if(MSVC)
Expand Down Expand Up @@ -1052,6 +1105,7 @@ add_library(riscv64-softmmu STATIC
qemu/target/riscv/pmp.c
qemu/target/riscv/translate.c
qemu/target/riscv/unicorn.c
qemu/target/riscv/vector_helper.c
)

if(MSVC)
Expand Down Expand Up @@ -1154,6 +1208,65 @@ endif()
endif()


if (UNICORN_HAS_AVR)
add_library(avr-softmmu STATIC
${UNICORN_ARCH_COMMON}

qemu/target/avr/cpu.c
qemu/target/avr/helper.c
qemu/target/avr/translate.c
qemu/target/avr/unicorn.c
)

if(MSVC)
target_compile_options(avr-softmmu PRIVATE
-DNEED_CPU_H
/FIavr.h
/I${CMAKE_CURRENT_SOURCE_DIR}/msvc/avr-softmmu
/I${CMAKE_CURRENT_SOURCE_DIR}/qemu/target/avr
)
else()
target_compile_options(avr-softmmu PRIVATE
-DNEED_CPU_H
-include avr.h
-I${CMAKE_BINARY_DIR}/avr-softmmu
-I${CMAKE_CURRENT_SOURCE_DIR}/qemu/target/avr
)
endif()
endif()


if (UNICORN_HAS_RH850)
add_library(rh850-softmmu STATIC
${UNICORN_ARCH_COMMON}

qemu/target/rh850/cpu.c
qemu/target/rh850/fpu_helper.c
qemu/target/rh850/helper.c
qemu/target/rh850/op_helper.c
qemu/target/rh850/translate.c
qemu/target/rh850/fpu_translate.c
qemu/target/rh850/unicorn.c
)


if(MSVC)
target_compile_options(rh850-softmmu PRIVATE
-DNEED_CPU_H
/FIrh850.h
/I${CMAKE_CURRENT_SOURCE_DIR}/msvc/rh850-softmmu
/I${CMAKE_CURRENT_SOURCE_DIR}/qemu/target/rh850
)
else()
target_compile_options(rh850-softmmu PRIVATE
-DNEED_CPU_H
-include rh850.h
-I${CMAKE_BINARY_DIR}/rh850-softmmu
-I${CMAKE_CURRENT_SOURCE_DIR}/qemu/target/rh850
)
endif()
endif()

set(UNICORN_SRCS
uc.c

Expand Down Expand Up @@ -1306,6 +1419,13 @@ if(UNICORN_HAS_PPC)
target_link_libraries(ppc64-softmmu PRIVATE unicorn-common)
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_ppc)
endif()
if(UNICORN_HAS_RH850)
set(UNICORN_COMPILE_OPTIONS ${UNICORN_COMPILE_OPTIONS} -DUNICORN_HAS_RH850)
set(UNICORN_LINK_LIBRARIES ${UNICORN_LINK_LIBRARIES} rh850-softmmu rh850-softmmu)
set(UNICORN_SAMPLE_FILE ${UNICORN_SAMPLE_FILE} sample_rh850)
target_link_libraries(rh850-softmmu PRIVATE unicorn-common)
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_rh850)
endif()
if(UNICORN_HAS_RISCV)
set(UNICORN_COMPILE_OPTIONS ${UNICORN_COMPILE_OPTIONS} -DUNICORN_HAS_RISCV)
set(UNICORN_LINK_LIBRARIES ${UNICORN_LINK_LIBRARIES} riscv32-softmmu riscv64-softmmu)
Expand All @@ -1328,6 +1448,13 @@ if (UNICORN_HAS_TRICORE)
target_link_libraries(tricore-softmmu unicorn-common)
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_tricore)
endif()
if (UNICORN_HAS_AVR)
set(UNICORN_COMPILE_OPTIONS ${UNICORN_COMPILE_OPTIONS} -DUNICORN_HAS_AVR)
set(UNICORN_LINK_LIBRARIES ${UNICORN_LINK_LIBRARIES} avr-softmmu)
set(UNICORN_SAMPLE_FILE ${UNICORN_SAMPLE_FILE} sample_avr)
target_link_libraries(avr-softmmu unicorn-common)
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_avr)
endif()

# Extra tests
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_mem)
Expand Down
1 change: 1 addition & 0 deletions CREDITS.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ Ziqiao Kong (lazymio): uc_context_free() API and various bug fix & improvement.
Sven Almgren (blindmatrix): bug fix
Chenxu Wu (kabeor): Documentation
Philipp Takacs: virtual tlb, memory snapshots
Glenn Baker: AVR architecture support
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pkg-config = { version = "0.3" }
[features]
default = ["arch_all"]
dynamic_linkage = []
arch_all = ["arch_x86", "arch_arm", "arch_aarch64", "arch_riscv", "arch_mips", "arch_sparc", "arch_m68k", "arch_ppc", "arch_s390x", "arch_tricore"]
arch_all = ["arch_x86", "arch_arm", "arch_aarch64", "arch_riscv", "arch_mips", "arch_sparc", "arch_m68k", "arch_ppc", "arch_rh850", "arch_s390x", "arch_tricore", "arch_avr"]
arch_x86 = []
arch_arm = []
# NOTE: unicorn-c only separates on top-level arch name,
Expand All @@ -55,3 +55,5 @@ arch_m68k = []
arch_ppc = []
arch_s390x = []
arch_tricore = []
arch_avr = []
arch_rh850 = []
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Unicorn is a lightweight, multi-platform, multi-architecture CPU emulator framew

Unicorn offers some unparalleled features:

- Multi-architecture: ARM, ARM64 (ARMv8), M68K, MIPS, PowerPC, RISCV, SPARC, S390X, TriCore and X86 (16, 32, 64-bit)
- Multi-architecture: ARM, ARM64 (ARMv8), AVR, M68K, MIPS, PowerPC, RISCV, SPARC, S390X, TriCore and X86 (16, 32, 64-bit)
- Clean/simple/lightweight/intuitive architecture-neutral API
- Implemented in pure C language, with bindings for Crystal, Clojure, Visual Basic, Perl, Rust, Ruby, Python, Java, .NET, Go, Delphi/Free Pascal, Haskell, Pharo, Lua and Zig.
- Native support for Windows & *nix (with Mac OSX, Linux, Android, *BSD & Solaris confirmed)
Expand Down
16 changes: 15 additions & 1 deletion bindings/const_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

INCL_DIR = os.path.join('..', 'include', 'unicorn')

include = [ 'arm.h', 'arm64.h', 'mips.h', 'x86.h', 'sparc.h', 'm68k.h', 'ppc.h', 'riscv.h', 's390x.h', 'tricore.h', 'unicorn.h' ]
include = [ 'arm.h', 'arm64.h', 'avr.h', 'mips.h', 'x86.h', 'sparc.h', 'm68k.h', 'ppc.h', 'rh850.h', 'riscv.h', 's390x.h', 'tricore.h', 'unicorn.h' ]

template = {
'python': {
Expand All @@ -17,11 +17,13 @@
# prefixes for constant filenames of all archs - case sensitive
'arm.h': 'arm',
'arm64.h': 'arm64',
'avr.h': 'avr',
'mips.h': 'mips',
'x86.h': 'x86',
'sparc.h': 'sparc',
'm68k.h': 'm68k',
'ppc.h': 'ppc',
'rh850.h': 'rh850',
'riscv.h': 'riscv',
's390x.h' : 's390x',
'tricore.h' : 'tricore',
Expand All @@ -37,12 +39,14 @@
# prefixes for constant filenames of all archs - case sensitive
'arm.h': 'arm',
'arm64.h': 'arm64',
'avr.h': 'avr',
'mips.h': 'mips',
'x86.h': 'x86',
'sparc.h': 'sparc',
'm68k.h': 'm68k',
'ppc.h': 'ppc',
'riscv.h': 'riscv',
'rh850.h': 'rh850',
's390x.h' : 's390x',
'tricore.h' : 'tricore',
'unicorn.h': 'unicorn',
Expand All @@ -57,11 +61,13 @@
# prefixes for constant filenames of all archs - case sensitive
'arm.h': 'arm',
'arm64.h': 'arm64',
'avr.h': 'avr',
'mips.h': 'mips',
'x86.h': 'x86',
'sparc.h': 'sparc',
'm68k.h': 'm68k',
'ppc.h': 'ppc',
'rh850.h': 'rh850',
'riscv.h': 'riscv',
's390x.h' : 's390x',
'tricore.h' : 'tricore',
Expand All @@ -77,11 +83,13 @@
# prefixes for constant filenames of all archs - case sensitive
'arm.h': 'Arm',
'arm64.h': 'Arm64',
'avr.h': 'AVR',
'mips.h': 'Mips',
'x86.h': 'X86',
'sparc.h': 'Sparc',
'm68k.h': 'M68k',
'ppc.h': 'Ppc',
'rh850.h': 'Rh850',
'riscv.h': 'Riscv',
's390x.h' : 'S390x',
'tricore.h' : 'TriCore',
Expand All @@ -97,11 +105,13 @@
# prefixes for constant filenames of all archs - case sensitive
'arm.h': 'Arm',
'arm64.h': 'Arm64',
'avr.h': 'AVR',
'mips.h': 'Mips',
'x86.h': 'X86',
'sparc.h': 'Sparc',
'm68k.h': 'M68k',
'ppc.h': 'Ppc',
'rh850.h': 'Rh850',
'riscv.h': 'Riscv',
's390x.h' : 'S390x',
'tricore.h' : 'TriCore',
Expand All @@ -117,11 +127,13 @@
# prefixes for constant filenames of all archs - case sensitive
'arm.h': 'Arm',
'arm64.h': 'Arm64',
'avr.h': 'AVR',
'mips.h': 'Mips',
'x86.h': 'X86',
'sparc.h': 'Sparc',
'm68k.h': 'M68k',
'ppc.h': 'Ppc',
'rh850.h': 'Rh850',
'riscv.h': 'Riscv',
's390x.h' : 'S390x',
'tricore.h' : 'TriCore',
Expand All @@ -137,12 +149,14 @@
# prefixes for constant filenames of all archs - case sensitive
'arm.h': 'arm',
'arm64.h': 'arm64',
'avr.h': 'AVR',
'mips.h': 'mips',
'x86.h': 'x86',
'sparc.h': 'sparc',
'm68k.h': 'm68k',
'ppc.h': 'ppc',
'riscv.h': 'riscv',
'rh850.h': 'rh850',
's390x.h' : 's390x',
'tricore.h' : 'tricore',
'unicorn.h': 'unicorn',
Expand Down
Loading
Loading