Skip to content

Commit

Permalink
Add Unicorn2 bindings for s390
Browse files Browse the repository at this point in the history
s390 support was implemented in Unicorn2:
unicorn-engine/unicorn#1446

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
  • Loading branch information
iii-i committed Apr 4, 2022
1 parent abafead commit 5a6140e
Show file tree
Hide file tree
Showing 13 changed files with 498 additions and 53 deletions.
2 changes: 2 additions & 0 deletions serval/unicorn.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"unicorn/engine.rkt"
"unicorn/arm.rkt"
"unicorn/arm64.rkt"
"unicorn/s390.rkt"
"unicorn/x86.rkt")

(provide (except-out (all-defined-out)
Expand All @@ -26,6 +27,7 @@
(case arch
[(arm) arm-engine]
[(arm64) arm64-engine]
[(s390x) s390-engine]
[(x86) x86-engine]))

(define-fun-syntax _uc_engine
Expand Down
24 changes: 23 additions & 1 deletion serval/unicorn/const/arm.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,29 @@
msp = 115
psp = 116
control = 117
ending = 118
iapsr = 118
eapsr = 119
xpsr = 120
epsr = 121
iepsr = 122
primask = 123
basepri = 124
basepri-max = 125
faultmask = 126
apsr-nzcvq = 127
apsr-g = 128
apsr-nzcvqg = 129
iapsr-nzcvq = 130
iapsr-g = 131
iapsr-nzcvqg = 132
eapsr-nzcvq = 133
eapsr-g = 134
eapsr-nzcvqg = 135
xpsr-nzcvq = 136
xpsr-g = 137
xpsr-nzcvqg = 138
cp-reg = 139
ending = 140
r13 = 12
r14 = 10
r15 = 11
Expand Down
28 changes: 27 additions & 1 deletion serval/unicorn/const/arm64.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,33 @@
tpidr-el0 = 262
tpidrro-el0 = 263
tpidr-el1 = 264
ending = 265
pstate = 265
elr-el0 = 266
elr-el1 = 267
elr-el2 = 268
elr-el3 = 269
sp-el0 = 270
sp-el1 = 271
sp-el2 = 272
sp-el3 = 273
ttbr0-el1 = 274
ttbr1-el1 = 275
esr-el0 = 276
esr-el1 = 277
esr-el2 = 278
esr-el3 = 279
far-el0 = 280
far-el1 = 281
far-el2 = 282
far-el3 = 283
par-el1 = 284
mair-el1 = 285
vbar-el0 = 286
vbar-el1 = 287
vbar-el2 = 288
vbar-el3 = 289
cp-reg = 290
ending = 291
ip0 = 215
ip1 = 216
fp = 1
Expand Down
75 changes: 75 additions & 0 deletions serval/unicorn/const/s390.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#lang racket/base

(require ffi/unsafe)

(provide (all-defined-out))

(define _uc_s390x_reg
(_enum '(invalid = 0
r0 = 1
r1 = 2
r2 = 3
r3 = 4
r4 = 5
r5 = 6
r6 = 7
r7 = 8
r8 = 9
r9 = 10
r10 = 11
r11 = 12
r12 = 13
r13 = 14
r14 = 15
r15 = 16
f0 = 17
f1 = 18
f2 = 19
f3 = 20
f4 = 21
f5 = 22
f6 = 23
f7 = 24
f8 = 25
f9 = 26
f10 = 27
f11 = 28
f12 = 29
f13 = 30
f14 = 31
f15 = 32
f16 = 33
f17 = 34
f18 = 35
f19 = 36
f20 = 37
f21 = 38
f22 = 39
f23 = 40
f24 = 41
f25 = 42
f26 = 43
f27 = 44
f28 = 45
f29 = 46
f30 = 47
f31 = 48
a0 = 49
a1 = 50
a2 = 51
a3 = 52
a4 = 53
a5 = 54
a6 = 55
a7 = 56
a8 = 57
a9 = 58
a10 = 59
a11 = 60
a12 = 61
a13 = 62
a14 = 63
a15 = 64
pc = 65
pswm = 66
ending = 67)))
15 changes: 13 additions & 2 deletions serval/unicorn/const/unicorn.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
ppc = 5
sparc = 6
m68k = 7
max = 8)))
riscv = 8
s390x = 9
max = 10)))

(define _uc_err
(_enum '(ok = 0
Expand Down Expand Up @@ -65,6 +67,9 @@
mem-write = 2048
mem-fetch = 4096
mem-read-after = 8192
insn-invalid = 16384
edge-generated = 32768
tcg-opcode = 65536
mem-unmapped = 112
mem-prot = 896
mem-read-invalid = 144
Expand All @@ -80,6 +85,10 @@
thumb = 16
mclass = 32
v8 = 64
armbe8 = 128
arm926 = 128
arm946 = 256
arm1176 = 512
micro = 16
mips3 = 32
mips32r6 = 64
Expand All @@ -93,7 +102,9 @@
qpx = 16
sparc32 = 4
sparc64 = 8
v9 = 16)))
v9 = 16
riscv32 = 4
riscv64 = 8)))

(define _uc_prot
(_bitmask '(none = 0
Expand Down
31 changes: 10 additions & 21 deletions serval/unicorn/const/x86.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
edx = 24
eflags = 25
eip = 26
eiz = 27
es = 28
esi = 29
esp = 30
Expand All @@ -47,7 +46,6 @@
rdi = 39
rdx = 40
rip = 41
riz = 42
rsi = 43
rsp = 44
si = 45
Expand All @@ -60,17 +58,7 @@
cr2 = 52
cr3 = 53
cr4 = 54
cr5 = 55
cr6 = 56
cr7 = 57
cr8 = 58
cr9 = 59
cr10 = 60
cr11 = 61
cr12 = 62
cr13 = 63
cr14 = 64
cr15 = 65
dr0 = 66
dr1 = 67
dr2 = 68
Expand All @@ -79,14 +67,6 @@
dr5 = 71
dr6 = 72
dr7 = 73
dr8 = 74
dr9 = 75
dr10 = 76
dr11 = 77
dr12 = 78
dr13 = 79
dr14 = 80
dr15 = 81
fp0 = 82
fp1 = 83
fp2 = 84
Expand Down Expand Up @@ -255,7 +235,16 @@
fptag = 247
msr = 248
mxcsr = 249
ending = 250)))
fs-base = 250
gs-base = 251
flags = 252
rflags = 253
fip = 254
fcs = 255
fdp = 256
fds = 257
fop = 258
ending = 259)))

(define _uc_x86_ins
(_enum '(invalid = 0
Expand Down
7 changes: 7 additions & 0 deletions serval/unicorn/gen.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/sh
set -e

cd "$(dirname "$0")"

./const_generator.py python/unicorn_const.py \
--enum UC_ARCH \
Expand All @@ -21,3 +24,7 @@
./const_generator.py python/arm_const.py \
--enum UC_ARM_REG \
> const/arm.rkt

./const_generator.py python/s390x_const.py \
--enum UC_S390X_REG \
> const/s390.rkt
52 changes: 50 additions & 2 deletions serval/unicorn/python/arm64_const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT [arm64_const.py]

# ARM64 CPU

UC_CPU_AARCH64_A57 = 0
UC_CPU_AARCH64_A53 = 1
UC_CPU_AARCH64_A72 = 2
UC_CPU_AARCH64_MAX = 3

# ARM64 registers

UC_ARM64_REG_INVALID = 0
Expand Down Expand Up @@ -267,14 +274,55 @@
UC_ARM64_REG_PC = 260
UC_ARM64_REG_CPACR_EL1 = 261

# thread registers
# thread registers, depreciated, use UC_ARM64_REG_CP_REG instead
UC_ARM64_REG_TPIDR_EL0 = 262
UC_ARM64_REG_TPIDRRO_EL0 = 263
UC_ARM64_REG_TPIDR_EL1 = 264
UC_ARM64_REG_ENDING = 265
UC_ARM64_REG_PSTATE = 265

# exception link registers, depreciated, use UC_ARM64_REG_CP_REG instead
UC_ARM64_REG_ELR_EL0 = 266
UC_ARM64_REG_ELR_EL1 = 267
UC_ARM64_REG_ELR_EL2 = 268
UC_ARM64_REG_ELR_EL3 = 269

# stack pointers registers, depreciated, use UC_ARM64_REG_CP_REG instead
UC_ARM64_REG_SP_EL0 = 270
UC_ARM64_REG_SP_EL1 = 271
UC_ARM64_REG_SP_EL2 = 272
UC_ARM64_REG_SP_EL3 = 273

# other CP15 registers, depreciated, use UC_ARM64_REG_CP_REG instead
UC_ARM64_REG_TTBR0_EL1 = 274
UC_ARM64_REG_TTBR1_EL1 = 275
UC_ARM64_REG_ESR_EL0 = 276
UC_ARM64_REG_ESR_EL1 = 277
UC_ARM64_REG_ESR_EL2 = 278
UC_ARM64_REG_ESR_EL3 = 279
UC_ARM64_REG_FAR_EL0 = 280
UC_ARM64_REG_FAR_EL1 = 281
UC_ARM64_REG_FAR_EL2 = 282
UC_ARM64_REG_FAR_EL3 = 283
UC_ARM64_REG_PAR_EL1 = 284
UC_ARM64_REG_MAIR_EL1 = 285
UC_ARM64_REG_VBAR_EL0 = 286
UC_ARM64_REG_VBAR_EL1 = 287
UC_ARM64_REG_VBAR_EL2 = 288
UC_ARM64_REG_VBAR_EL3 = 289
UC_ARM64_REG_CP_REG = 290
UC_ARM64_REG_ENDING = 291

# alias registers
UC_ARM64_REG_IP0 = 215
UC_ARM64_REG_IP1 = 216
UC_ARM64_REG_FP = 1
UC_ARM64_REG_LR = 2

# ARM64 instructions

UC_ARM64_INS_INVALID = 0
UC_ARM64_INS_MRS = 1
UC_ARM64_INS_MSR = 2
UC_ARM64_INS_SYS = 3
UC_ARM64_INS_SYSL = 4
UC_ARM64_INS_ENDING = 5
Loading

0 comments on commit 5a6140e

Please sign in to comment.