Skip to content

Commit cb5aab0

Browse files
amaanqglennsecvirtualabs
authored
squash avr & rh850 (#2146)
* Squashed commit of #2021 * Squashed commit of #1918 --------- Co-authored-by: Glenn Baker <glenn.baker@gmx.com> Co-authored-by: Damien Cauquil <dcauquil@quarkslab.com>
1 parent b4325f6 commit cb5aab0

Some content is hidden

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

88 files changed

+23454
-21
lines changed

CMakeLists.txt

+103-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ option(UNICORN_FUZZ "Enable fuzzing" OFF)
8686
option(UNICORN_LOGGING "Enable logging" OFF)
8787
option(UNICORN_BUILD_TESTS "Build unicorn tests" ${PROJECT_IS_TOP_LEVEL})
8888
option(UNICORN_INSTALL "Enable unicorn installation" ${PROJECT_IS_TOP_LEVEL})
89-
set(UNICORN_ARCH "x86;arm;aarch64;riscv;mips;sparc;m68k;ppc;s390x;tricore" CACHE STRING "Enabled unicorn architectures")
89+
set(UNICORN_ARCH "x86;arm;aarch64;riscv;mips;sparc;m68k;ppc;rh850;s390x;tricore;avr" CACHE STRING "Enabled unicorn architectures")
9090
option(UNICORN_TRACER "Trace unicorn execution" OFF)
9191
option(UNICORN_INTERPRETER "Use interpreter mode" OFF)
9292

@@ -274,6 +274,11 @@ else()
274274
set(UNICORN_TARGET_ARCH "tricore")
275275
break()
276276
endif()
277+
string(FIND ${UC_COMPILER_MACRO} "__AVR__" UC_RET)
278+
if (${UC_RET} GREATER_EQUAL "0")
279+
set(UNICORN_TARGET_ARCH "avr")
280+
break()
281+
endif()
277282
message(FATAL_ERROR "Unknown host compiler: ${CMAKE_C_COMPILER}.")
278283
endwhile(TRUE)
279284
endif()
@@ -304,6 +309,9 @@ else()
304309
if(UNICORN_HAS_PPC)
305310
set(EXTRA_CFLAGS "${EXTRA_CFLAGS}-DUNICORN_HAS_PPC ")
306311
endif()
312+
if(UNICORN_HAS_RH850)
313+
set(EXTRA_CFLAGS "${EXTRA_CFLAGS}-DUNICORN_HAS_RH850 ")
314+
endif()
307315
if(UNICORN_HAS_RISCV)
308316
set(EXTRA_CFLAGS "${EXTRA_CFLAGS}-DUNICORN_HAS_RISCV ")
309317
endif()
@@ -313,6 +321,9 @@ else()
313321
if (UNICORN_HAS_TRICORE)
314322
set (EXTRA_CFLAGS "${EXTRA_CFLAGS}-DUNICORN_HAS_TRICORE ")
315323
endif()
324+
if (UNICORN_HAS_AVR)
325+
set (EXTRA_CFLAGS "${EXTRA_CFLAGS}-DUNICORN_HAS_AVR ")
326+
endif()
316327

317328
set(EXTRA_CFLAGS "${EXTRA_CFLAGS}-fPIC")
318329
if(ANDROID_ABI)
@@ -355,6 +366,9 @@ else()
355366
if(UNICORN_HAS_PPC)
356367
set(TARGET_LIST "${TARGET_LIST}ppc-softmmu, ppc64-softmmu, ")
357368
endif()
369+
if(UNICORN_HAS_RH850)
370+
set(TARGET_LIST "${TARGET_LIST}rh850-softmmu, ")
371+
endif()
358372
if(UNICORN_HAS_RISCV)
359373
set(TARGET_LIST "${TARGET_LIST}riscv32-softmmu, riscv64-softmmu, ")
360374
endif()
@@ -364,6 +378,9 @@ else()
364378
if (UNICORN_HAS_TRICORE)
365379
set (TARGET_LIST "${TARGET_LIST}tricore-softmmu, ")
366380
endif()
381+
if (UNICORN_HAS_AVR)
382+
set (TARGET_LIST "${TARGET_LIST}avr-softmmu, ")
383+
endif()
367384
set(TARGET_LIST "${TARGET_LIST} ")
368385

369386
# GEN config-host.mak & target directories
@@ -446,6 +463,12 @@ else()
446463
OUTPUT_FILE ${CMAKE_BINARY_DIR}/ppc64-softmmu/config-target.h
447464
)
448465
endif()
466+
if(UNICORN_HAS_RH850)
467+
execute_process(COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/qemu/scripts/create_config
468+
INPUT_FILE ${CMAKE_BINARY_DIR}/rh850-softmmu/config-target.mak
469+
OUTPUT_FILE ${CMAKE_BINARY_DIR}/rh850-softmmu/config-target.h
470+
)
471+
endif()
449472
if(UNICORN_HAS_RISCV)
450473
execute_process(COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/qemu/scripts/create_config
451474
INPUT_FILE ${CMAKE_BINARY_DIR}/riscv32-softmmu/config-target.mak
@@ -468,6 +491,12 @@ else()
468491
OUTPUT_FILE ${CMAKE_BINARY_DIR}/tricore-softmmu/config-target.h
469492
)
470493
endif()
494+
if (UNICORN_HAS_AVR)
495+
execute_process(COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/qemu/scripts/create_config
496+
INPUT_FILE ${CMAKE_BINARY_DIR}/avr-softmmu/config-target.mak
497+
OUTPUT_FILE ${CMAKE_BINARY_DIR}/avr-softmmu/config-target.h
498+
)
499+
endif()
471500
add_compile_options(
472501
${UNICORN_CFLAGS}
473502
-I${CMAKE_CURRENT_SOURCE_DIR}/qemu/tcg/${UNICORN_TARGET_ARCH}
@@ -1174,6 +1203,65 @@ endif()
11741203
endif()
11751204

11761205

1206+
if (UNICORN_HAS_AVR)
1207+
add_library(avr-softmmu STATIC
1208+
${UNICORN_ARCH_COMMON}
1209+
1210+
qemu/target/avr/cpu.c
1211+
qemu/target/avr/helper.c
1212+
qemu/target/avr/translate.c
1213+
qemu/target/avr/unicorn.c
1214+
)
1215+
1216+
if(MSVC)
1217+
target_compile_options(avr-softmmu PRIVATE
1218+
-DNEED_CPU_H
1219+
/FIavr.h
1220+
/I${CMAKE_CURRENT_SOURCE_DIR}/msvc/avr-softmmu
1221+
/I${CMAKE_CURRENT_SOURCE_DIR}/qemu/target/avr
1222+
)
1223+
else()
1224+
target_compile_options(avr-softmmu PRIVATE
1225+
-DNEED_CPU_H
1226+
-include avr.h
1227+
-I${CMAKE_BINARY_DIR}/avr-softmmu
1228+
-I${CMAKE_CURRENT_SOURCE_DIR}/qemu/target/avr
1229+
)
1230+
endif()
1231+
endif()
1232+
1233+
1234+
if (UNICORN_HAS_RH850)
1235+
add_library(rh850-softmmu STATIC
1236+
${UNICORN_ARCH_COMMON}
1237+
1238+
qemu/target/rh850/cpu.c
1239+
qemu/target/rh850/fpu_helper.c
1240+
qemu/target/rh850/helper.c
1241+
qemu/target/rh850/op_helper.c
1242+
qemu/target/rh850/translate.c
1243+
qemu/target/rh850/fpu_translate.c
1244+
qemu/target/rh850/unicorn.c
1245+
)
1246+
1247+
1248+
if(MSVC)
1249+
target_compile_options(rh850-softmmu PRIVATE
1250+
-DNEED_CPU_H
1251+
/FIrh850.h
1252+
/I${CMAKE_CURRENT_SOURCE_DIR}/msvc/rh850-softmmu
1253+
/I${CMAKE_CURRENT_SOURCE_DIR}/qemu/target/rh850
1254+
)
1255+
else()
1256+
target_compile_options(rh850-softmmu PRIVATE
1257+
-DNEED_CPU_H
1258+
-include rh850.h
1259+
-I${CMAKE_BINARY_DIR}/rh850-softmmu
1260+
-I${CMAKE_CURRENT_SOURCE_DIR}/qemu/target/rh850
1261+
)
1262+
endif()
1263+
endif()
1264+
11771265
set(UNICORN_SRCS
11781266
uc.c
11791267

@@ -1326,6 +1414,13 @@ if(UNICORN_HAS_PPC)
13261414
target_link_libraries(ppc64-softmmu PRIVATE unicorn-common)
13271415
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_ppc)
13281416
endif()
1417+
if(UNICORN_HAS_RH850)
1418+
set(UNICORN_COMPILE_OPTIONS ${UNICORN_COMPILE_OPTIONS} -DUNICORN_HAS_RH850)
1419+
set(UNICORN_LINK_LIBRARIES ${UNICORN_LINK_LIBRARIES} rh850-softmmu rh850-softmmu)
1420+
set(UNICORN_SAMPLE_FILE ${UNICORN_SAMPLE_FILE} sample_rh850)
1421+
target_link_libraries(rh850-softmmu PRIVATE unicorn-common)
1422+
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_rh850)
1423+
endif()
13291424
if(UNICORN_HAS_RISCV)
13301425
set(UNICORN_COMPILE_OPTIONS ${UNICORN_COMPILE_OPTIONS} -DUNICORN_HAS_RISCV)
13311426
set(UNICORN_LINK_LIBRARIES ${UNICORN_LINK_LIBRARIES} riscv32-softmmu riscv64-softmmu)
@@ -1348,6 +1443,13 @@ if (UNICORN_HAS_TRICORE)
13481443
target_link_libraries(tricore-softmmu unicorn-common)
13491444
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_tricore)
13501445
endif()
1446+
if (UNICORN_HAS_AVR)
1447+
set(UNICORN_COMPILE_OPTIONS ${UNICORN_COMPILE_OPTIONS} -DUNICORN_HAS_AVR)
1448+
set(UNICORN_LINK_LIBRARIES ${UNICORN_LINK_LIBRARIES} avr-softmmu)
1449+
set(UNICORN_SAMPLE_FILE ${UNICORN_SAMPLE_FILE} sample_avr)
1450+
target_link_libraries(avr-softmmu unicorn-common)
1451+
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_avr)
1452+
endif()
13511453

13521454
# Extra tests
13531455
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_mem)

CREDITS.TXT

+1
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,4 @@ Ziqiao Kong (lazymio): uc_context_free() API and various bug fix & improvement.
8181
Sven Almgren (blindmatrix): bug fix
8282
Chenxu Wu (kabeor): Documentation
8383
Philipp Takacs: virtual tlb, memory snapshots
84+
Glenn Baker: AVR architecture support

Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pkg-config = { version = "0.3" }
4242
[features]
4343
default = ["arch_all"]
4444
dynamic_linkage = []
45-
arch_all = ["arch_x86", "arch_arm", "arch_aarch64", "arch_riscv", "arch_mips", "arch_sparc", "arch_m68k", "arch_ppc", "arch_s390x", "arch_tricore"]
45+
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"]
4646
arch_x86 = []
4747
arch_arm = []
4848
# NOTE: unicorn-c only separates on top-level arch name,
@@ -55,3 +55,5 @@ arch_m68k = []
5555
arch_ppc = []
5656
arch_s390x = []
5757
arch_tricore = []
58+
arch_avr = []
59+
arch_rh850 = []

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Unicorn is a lightweight, multi-platform, multi-architecture CPU emulator framew
1313

1414
Unicorn offers some unparalleled features:
1515

16-
- Multi-architecture: ARM, ARM64 (ARMv8), M68K, MIPS, PowerPC, RISCV, SPARC, S390X, TriCore and X86 (16, 32, 64-bit)
16+
- Multi-architecture: ARM, ARM64 (ARMv8), AVR, M68K, MIPS, PowerPC, RISCV, SPARC, S390X, TriCore and X86 (16, 32, 64-bit)
1717
- Clean/simple/lightweight/intuitive architecture-neutral API
1818
- 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.
1919
- Native support for Windows & *nix (with Mac OSX, Linux, Android, *BSD & Solaris confirmed)

bindings/const_generator.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

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

9-
include = [ 'arm.h', 'arm64.h', 'mips.h', 'x86.h', 'sparc.h', 'm68k.h', 'ppc.h', 'riscv.h', 's390x.h', 'tricore.h', 'unicorn.h' ]
9+
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' ]
1010

1111
template = {
1212
'python': {
@@ -17,11 +17,13 @@
1717
# prefixes for constant filenames of all archs - case sensitive
1818
'arm.h': 'arm',
1919
'arm64.h': 'arm64',
20+
'avr.h': 'avr',
2021
'mips.h': 'mips',
2122
'x86.h': 'x86',
2223
'sparc.h': 'sparc',
2324
'm68k.h': 'm68k',
2425
'ppc.h': 'ppc',
26+
'rh850.h': 'rh850',
2527
'riscv.h': 'riscv',
2628
's390x.h' : 's390x',
2729
'tricore.h' : 'tricore',
@@ -37,12 +39,14 @@
3739
# prefixes for constant filenames of all archs - case sensitive
3840
'arm.h': 'arm',
3941
'arm64.h': 'arm64',
42+
'avr.h': 'avr',
4043
'mips.h': 'mips',
4144
'x86.h': 'x86',
4245
'sparc.h': 'sparc',
4346
'm68k.h': 'm68k',
4447
'ppc.h': 'ppc',
4548
'riscv.h': 'riscv',
49+
'rh850.h': 'rh850',
4650
's390x.h' : 's390x',
4751
'tricore.h' : 'tricore',
4852
'unicorn.h': 'unicorn',
@@ -57,11 +61,13 @@
5761
# prefixes for constant filenames of all archs - case sensitive
5862
'arm.h': 'arm',
5963
'arm64.h': 'arm64',
64+
'avr.h': 'avr',
6065
'mips.h': 'mips',
6166
'x86.h': 'x86',
6267
'sparc.h': 'sparc',
6368
'm68k.h': 'm68k',
6469
'ppc.h': 'ppc',
70+
'rh850.h': 'rh850',
6571
'riscv.h': 'riscv',
6672
's390x.h' : 's390x',
6773
'tricore.h' : 'tricore',
@@ -77,11 +83,13 @@
7783
# prefixes for constant filenames of all archs - case sensitive
7884
'arm.h': 'Arm',
7985
'arm64.h': 'Arm64',
86+
'avr.h': 'AVR',
8087
'mips.h': 'Mips',
8188
'x86.h': 'X86',
8289
'sparc.h': 'Sparc',
8390
'm68k.h': 'M68k',
8491
'ppc.h': 'Ppc',
92+
'rh850.h': 'Rh850',
8593
'riscv.h': 'Riscv',
8694
's390x.h' : 'S390x',
8795
'tricore.h' : 'TriCore',
@@ -97,11 +105,13 @@
97105
# prefixes for constant filenames of all archs - case sensitive
98106
'arm.h': 'Arm',
99107
'arm64.h': 'Arm64',
108+
'avr.h': 'AVR',
100109
'mips.h': 'Mips',
101110
'x86.h': 'X86',
102111
'sparc.h': 'Sparc',
103112
'm68k.h': 'M68k',
104113
'ppc.h': 'Ppc',
114+
'rh850.h': 'Rh850',
105115
'riscv.h': 'Riscv',
106116
's390x.h' : 'S390x',
107117
'tricore.h' : 'TriCore',
@@ -117,11 +127,13 @@
117127
# prefixes for constant filenames of all archs - case sensitive
118128
'arm.h': 'Arm',
119129
'arm64.h': 'Arm64',
130+
'avr.h': 'AVR',
120131
'mips.h': 'Mips',
121132
'x86.h': 'X86',
122133
'sparc.h': 'Sparc',
123134
'm68k.h': 'M68k',
124135
'ppc.h': 'Ppc',
136+
'rh850.h': 'Rh850',
125137
'riscv.h': 'Riscv',
126138
's390x.h' : 'S390x',
127139
'tricore.h' : 'TriCore',
@@ -137,12 +149,14 @@
137149
# prefixes for constant filenames of all archs - case sensitive
138150
'arm.h': 'arm',
139151
'arm64.h': 'arm64',
152+
'avr.h': 'AVR',
140153
'mips.h': 'mips',
141154
'x86.h': 'x86',
142155
'sparc.h': 'sparc',
143156
'm68k.h': 'm68k',
144157
'ppc.h': 'ppc',
145158
'riscv.h': 'riscv',
159+
'rh850.h': 'rh850',
146160
's390x.h' : 's390x',
147161
'tricore.h' : 'tricore',
148162
'unicorn.h': 'unicorn',

0 commit comments

Comments
 (0)