Skip to content

Commit cbdd83b

Browse files
glennsecamaanq
authored andcommitted
Squashed commit of unicorn-engine#2021
1 parent b4325f6 commit cbdd83b

Some content is hidden

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

53 files changed

+9803
-16
lines changed

CMakeLists.txt

Lines changed: 53 additions & 1 deletion
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;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()
@@ -313,6 +318,9 @@ else()
313318
if (UNICORN_HAS_TRICORE)
314319
set (EXTRA_CFLAGS "${EXTRA_CFLAGS}-DUNICORN_HAS_TRICORE ")
315320
endif()
321+
if (UNICORN_HAS_AVR)
322+
set (EXTRA_CFLAGS "${EXTRA_CFLAGS}-DUNICORN_HAS_AVR ")
323+
endif()
316324

317325
set(EXTRA_CFLAGS "${EXTRA_CFLAGS}-fPIC")
318326
if(ANDROID_ABI)
@@ -364,6 +372,9 @@ else()
364372
if (UNICORN_HAS_TRICORE)
365373
set (TARGET_LIST "${TARGET_LIST}tricore-softmmu, ")
366374
endif()
375+
if (UNICORN_HAS_AVR)
376+
set (TARGET_LIST "${TARGET_LIST}avr-softmmu, ")
377+
endif()
367378
set(TARGET_LIST "${TARGET_LIST} ")
368379

369380
# GEN config-host.mak & target directories
@@ -468,6 +479,12 @@ else()
468479
OUTPUT_FILE ${CMAKE_BINARY_DIR}/tricore-softmmu/config-target.h
469480
)
470481
endif()
482+
if (UNICORN_HAS_AVR)
483+
execute_process(COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/qemu/scripts/create_config
484+
INPUT_FILE ${CMAKE_BINARY_DIR}/avr-softmmu/config-target.mak
485+
OUTPUT_FILE ${CMAKE_BINARY_DIR}/avr-softmmu/config-target.h
486+
)
487+
endif()
471488
add_compile_options(
472489
${UNICORN_CFLAGS}
473490
-I${CMAKE_CURRENT_SOURCE_DIR}/qemu/tcg/${UNICORN_TARGET_ARCH}
@@ -1174,6 +1191,34 @@ endif()
11741191
endif()
11751192

11761193

1194+
if (UNICORN_HAS_AVR)
1195+
add_library(avr-softmmu STATIC
1196+
${UNICORN_ARCH_COMMON}
1197+
1198+
qemu/target/avr/cpu.c
1199+
qemu/target/avr/helper.c
1200+
qemu/target/avr/translate.c
1201+
qemu/target/avr/unicorn.c
1202+
)
1203+
1204+
if(MSVC)
1205+
target_compile_options(avr-softmmu PRIVATE
1206+
-DNEED_CPU_H
1207+
/FIavr.h
1208+
/I${CMAKE_CURRENT_SOURCE_DIR}/msvc/avr-softmmu
1209+
/I${CMAKE_CURRENT_SOURCE_DIR}/qemu/target/avr
1210+
)
1211+
else()
1212+
target_compile_options(avr-softmmu PRIVATE
1213+
-DNEED_CPU_H
1214+
-include avr.h
1215+
-I${CMAKE_BINARY_DIR}/avr-softmmu
1216+
-I${CMAKE_CURRENT_SOURCE_DIR}/qemu/target/avr
1217+
)
1218+
endif()
1219+
endif()
1220+
1221+
11771222
set(UNICORN_SRCS
11781223
uc.c
11791224

@@ -1348,6 +1393,13 @@ if (UNICORN_HAS_TRICORE)
13481393
target_link_libraries(tricore-softmmu unicorn-common)
13491394
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_tricore)
13501395
endif()
1396+
if (UNICORN_HAS_AVR)
1397+
set(UNICORN_COMPILE_OPTIONS ${UNICORN_COMPILE_OPTIONS} -DUNICORN_HAS_AVR)
1398+
set(UNICORN_LINK_LIBRARIES ${UNICORN_LINK_LIBRARIES} avr-softmmu)
1399+
set(UNICORN_SAMPLE_FILE ${UNICORN_SAMPLE_FILE} sample_avr)
1400+
target_link_libraries(avr-softmmu unicorn-common)
1401+
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_avr)
1402+
endif()
13511403

13521404
# Extra tests
13531405
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_mem)

CREDITS.TXT

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 1 deletion
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_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,4 @@ arch_m68k = []
5555
arch_ppc = []
5656
arch_s390x = []
5757
arch_tricore = []
58+
arch_avr = []

README.md

Lines changed: 1 addition & 1 deletion
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

Lines changed: 8 additions & 1 deletion
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', 'riscv.h', 's390x.h', 'tricore.h', 'unicorn.h' ]
1010

1111
template = {
1212
'python': {
@@ -17,6 +17,7 @@
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',
@@ -37,6 +38,7 @@
3738
# prefixes for constant filenames of all archs - case sensitive
3839
'arm.h': 'arm',
3940
'arm64.h': 'arm64',
41+
'avr.h': 'avr',
4042
'mips.h': 'mips',
4143
'x86.h': 'x86',
4244
'sparc.h': 'sparc',
@@ -57,6 +59,7 @@
5759
# prefixes for constant filenames of all archs - case sensitive
5860
'arm.h': 'arm',
5961
'arm64.h': 'arm64',
62+
'avr.h': 'avr',
6063
'mips.h': 'mips',
6164
'x86.h': 'x86',
6265
'sparc.h': 'sparc',
@@ -77,6 +80,7 @@
7780
# prefixes for constant filenames of all archs - case sensitive
7881
'arm.h': 'Arm',
7982
'arm64.h': 'Arm64',
83+
'avr.h': 'AVR',
8084
'mips.h': 'Mips',
8185
'x86.h': 'X86',
8286
'sparc.h': 'Sparc',
@@ -97,6 +101,7 @@
97101
# prefixes for constant filenames of all archs - case sensitive
98102
'arm.h': 'Arm',
99103
'arm64.h': 'Arm64',
104+
'avr.h': 'AVR',
100105
'mips.h': 'Mips',
101106
'x86.h': 'X86',
102107
'sparc.h': 'Sparc',
@@ -117,6 +122,7 @@
117122
# prefixes for constant filenames of all archs - case sensitive
118123
'arm.h': 'Arm',
119124
'arm64.h': 'Arm64',
125+
'avr.h': 'AVR',
120126
'mips.h': 'Mips',
121127
'x86.h': 'X86',
122128
'sparc.h': 'Sparc',
@@ -137,6 +143,7 @@
137143
# prefixes for constant filenames of all archs - case sensitive
138144
'arm.h': 'arm',
139145
'arm64.h': 'arm64',
146+
'avr.h': 'AVR',
140147
'mips.h': 'mips',
141148
'x86.h': 'x86',
142149
'sparc.h': 'sparc',
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
2+
3+
namespace UnicornEngine.Const
4+
5+
open System
6+
7+
[<AutoOpen>]
8+
module AVR =
9+
10+
// AVR architectures
11+
let UC_AVR_ARCH_AVR1 = 10
12+
let UC_AVR_ARCH_AVR2 = 20
13+
let UC_AVR_ARCH_AVR25 = 25
14+
let UC_AVR_ARCH_AVR3 = 30
15+
let UC_AVR_ARCH_AVR4 = 40
16+
let UC_AVR_ARCH_AVR5 = 50
17+
let UC_AVR_ARCH_AVR51 = 51
18+
let UC_AVR_ARCH_AVR6 = 60
19+
let UC_CPU_AVR_ARCH = 1000
20+
21+
// AVR CPU
22+
let UC_CPU_AVR_ATMEGA16 = 50016
23+
let UC_CPU_AVR_ATMEGA32 = 50032
24+
let UC_CPU_AVR_ATMEGA64 = 50064
25+
let UC_CPU_AVR_ATMEGA128 = 51128
26+
let UC_CPU_AVR_ATMEGA128RFR2 = 51129
27+
let UC_CPU_AVR_ATMEGA1280 = 51130
28+
let UC_CPU_AVR_ATMEGA256 = 60256
29+
let UC_CPU_AVR_ATMEGA256RFR2 = 60257
30+
let UC_CPU_AVR_ATMEGA2560 = 60258
31+
32+
// AVR memory
33+
let UC_AVR_MEM_FLASH = 134217728
34+
35+
// AVR registers
36+
37+
let UC_AVR_REG_INVALID = 0
38+
let UC_AVR_REG_R0 = 1
39+
let UC_AVR_REG_R1 = 2
40+
let UC_AVR_REG_R2 = 3
41+
let UC_AVR_REG_R3 = 4
42+
let UC_AVR_REG_R4 = 5
43+
let UC_AVR_REG_R5 = 6
44+
let UC_AVR_REG_R6 = 7
45+
let UC_AVR_REG_R7 = 8
46+
let UC_AVR_REG_R8 = 9
47+
let UC_AVR_REG_R9 = 10
48+
let UC_AVR_REG_R10 = 11
49+
let UC_AVR_REG_R11 = 12
50+
let UC_AVR_REG_R12 = 13
51+
let UC_AVR_REG_R13 = 14
52+
let UC_AVR_REG_R14 = 15
53+
let UC_AVR_REG_R15 = 16
54+
let UC_AVR_REG_R16 = 17
55+
let UC_AVR_REG_R17 = 18
56+
let UC_AVR_REG_R18 = 19
57+
let UC_AVR_REG_R19 = 20
58+
let UC_AVR_REG_R20 = 21
59+
let UC_AVR_REG_R21 = 22
60+
let UC_AVR_REG_R22 = 23
61+
let UC_AVR_REG_R23 = 24
62+
let UC_AVR_REG_R24 = 25
63+
let UC_AVR_REG_R25 = 26
64+
let UC_AVR_REG_R26 = 27
65+
let UC_AVR_REG_R27 = 28
66+
let UC_AVR_REG_R28 = 29
67+
let UC_AVR_REG_R29 = 30
68+
let UC_AVR_REG_R30 = 31
69+
let UC_AVR_REG_R31 = 32
70+
let UC_AVR_REG_PC = 33
71+
let UC_AVR_REG_SP = 34
72+
let UC_AVR_REG_RAMPD = 57
73+
let UC_AVR_REG_RAMPX = 58
74+
let UC_AVR_REG_RAMPY = 59
75+
let UC_AVR_REG_RAMPZ = 60
76+
let UC_AVR_REG_EIND = 61
77+
let UC_AVR_REG_SPL = 62
78+
let UC_AVR_REG_SPH = 63
79+
let UC_AVR_REG_SREG = 64
80+
81+
// 16-bit coalesced registers
82+
let UC_AVR_REG_R0W = 65
83+
let UC_AVR_REG_R1W = 66
84+
let UC_AVR_REG_R2W = 67
85+
let UC_AVR_REG_R3W = 68
86+
let UC_AVR_REG_R4W = 69
87+
let UC_AVR_REG_R5W = 70
88+
let UC_AVR_REG_R6W = 71
89+
let UC_AVR_REG_R7W = 72
90+
let UC_AVR_REG_R8W = 73
91+
let UC_AVR_REG_R9W = 74
92+
let UC_AVR_REG_R10W = 75
93+
let UC_AVR_REG_R11W = 76
94+
let UC_AVR_REG_R12W = 77
95+
let UC_AVR_REG_R13W = 78
96+
let UC_AVR_REG_R14W = 79
97+
let UC_AVR_REG_R15W = 80
98+
let UC_AVR_REG_R16W = 81
99+
let UC_AVR_REG_R17W = 82
100+
let UC_AVR_REG_R18W = 83
101+
let UC_AVR_REG_R19W = 84
102+
let UC_AVR_REG_R20W = 85
103+
let UC_AVR_REG_R21W = 86
104+
let UC_AVR_REG_R22W = 87
105+
let UC_AVR_REG_R23W = 88
106+
let UC_AVR_REG_R24W = 89
107+
let UC_AVR_REG_R25W = 90
108+
let UC_AVR_REG_R26W = 91
109+
let UC_AVR_REG_R27W = 92
110+
let UC_AVR_REG_R28W = 93
111+
let UC_AVR_REG_R29W = 94
112+
let UC_AVR_REG_R30W = 95
113+
114+
// 32-bit coalesced registers
115+
let UC_AVR_REG_R0D = 97
116+
let UC_AVR_REG_R1D = 98
117+
let UC_AVR_REG_R2D = 99
118+
let UC_AVR_REG_R3D = 100
119+
let UC_AVR_REG_R4D = 101
120+
let UC_AVR_REG_R5D = 102
121+
let UC_AVR_REG_R6D = 103
122+
let UC_AVR_REG_R7D = 104
123+
let UC_AVR_REG_R8D = 105
124+
let UC_AVR_REG_R9D = 106
125+
let UC_AVR_REG_R10D = 107
126+
let UC_AVR_REG_R11D = 108
127+
let UC_AVR_REG_R12D = 109
128+
let UC_AVR_REG_R13D = 110
129+
let UC_AVR_REG_R14D = 111
130+
let UC_AVR_REG_R15D = 112
131+
let UC_AVR_REG_R16D = 113
132+
let UC_AVR_REG_R17D = 114
133+
let UC_AVR_REG_R18D = 115
134+
let UC_AVR_REG_R19D = 116
135+
let UC_AVR_REG_R20D = 117
136+
let UC_AVR_REG_R21D = 118
137+
let UC_AVR_REG_R22D = 119
138+
let UC_AVR_REG_R23D = 120
139+
let UC_AVR_REG_R24D = 121
140+
let UC_AVR_REG_R25D = 122
141+
let UC_AVR_REG_R26D = 123
142+
let UC_AVR_REG_R27D = 124
143+
let UC_AVR_REG_R28D = 125
144+
145+
// Alias registers
146+
let UC_AVR_REG_Xhi = 28
147+
let UC_AVR_REG_Xlo = 27
148+
let UC_AVR_REG_Yhi = 30
149+
let UC_AVR_REG_Ylo = 29
150+
let UC_AVR_REG_Zhi = 32
151+
let UC_AVR_REG_Zlo = 31
152+
let UC_AVR_REG_X = 91
153+
let UC_AVR_REG_Y = 93
154+
let UC_AVR_REG_Z = 95
155+

bindings/dotnet/UnicornEngine/Const/Common.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ module Common =
2626
let UC_ARCH_RISCV = 8
2727
let UC_ARCH_S390X = 9
2828
let UC_ARCH_TRICORE = 10
29-
let UC_ARCH_MAX = 11
29+
let UC_ARCH_AVR = 11
30+
let UC_ARCH_MAX = 12
3031

3132
let UC_MODE_LITTLE_ENDIAN = 0
3233
let UC_MODE_BIG_ENDIAN = 1073741824

0 commit comments

Comments
 (0)