From d79925f477abb00659c99f08c948ee606a558b46 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Sat, 23 Jan 2016 10:48:18 +0800 Subject: [PATCH] sparc: add SPARC32 mode (= UC_MODE_32) --- bindings/dotnet/UnicornManaged/Const/Common.fs | 1 + bindings/go/unicorn/unicorn_const.go | 1 + bindings/java/unicorn/UnicornConst.java | 1 + bindings/python/sample_sparc.py | 2 +- bindings/python/unicorn/unicorn_const.py | 1 + include/uc_priv.h | 2 +- include/unicorn/unicorn.h | 5 +++-- samples/sample_sparc.c | 2 +- tests/regress/sparc64.py | 2 +- tests/regress/sparc_jump_to_zero.c | 2 +- tests/regress/sparc_reg.py | 2 +- 11 files changed, 13 insertions(+), 8 deletions(-) diff --git a/bindings/dotnet/UnicornManaged/Const/Common.fs b/bindings/dotnet/UnicornManaged/Const/Common.fs index f5c2230c..3ec03c74 100644 --- a/bindings/dotnet/UnicornManaged/Const/Common.fs +++ b/bindings/dotnet/UnicornManaged/Const/Common.fs @@ -37,6 +37,7 @@ module Common = let UC_MODE_64 = 8 let UC_MODE_PPC64 = 8 let UC_MODE_QPX = 16 + let UC_MODE_SPARC32 = 4 let UC_MODE_SPARC64 = 8 let UC_MODE_V9 = 16 diff --git a/bindings/go/unicorn/unicorn_const.go b/bindings/go/unicorn/unicorn_const.go index fb44acd0..2d8d2c1a 100644 --- a/bindings/go/unicorn/unicorn_const.go +++ b/bindings/go/unicorn/unicorn_const.go @@ -32,6 +32,7 @@ const ( MODE_64 = 8 MODE_PPC64 = 8 MODE_QPX = 16 + MODE_SPARC32 = 4 MODE_SPARC64 = 8 MODE_V9 = 16 diff --git a/bindings/java/unicorn/UnicornConst.java b/bindings/java/unicorn/UnicornConst.java index 614326b3..5967d26b 100644 --- a/bindings/java/unicorn/UnicornConst.java +++ b/bindings/java/unicorn/UnicornConst.java @@ -34,6 +34,7 @@ public interface UnicornConst { public static final int UC_MODE_64 = 8; public static final int UC_MODE_PPC64 = 8; public static final int UC_MODE_QPX = 16; + public static final int UC_MODE_SPARC32 = 4; public static final int UC_MODE_SPARC64 = 8; public static final int UC_MODE_V9 = 16; diff --git a/bindings/python/sample_sparc.py b/bindings/python/sample_sparc.py index 307ba936..a8bdd586 100755 --- a/bindings/python/sample_sparc.py +++ b/bindings/python/sample_sparc.py @@ -28,7 +28,7 @@ def test_sparc(): print("Emulate SPARC code") try: # Initialize emulator in SPARC EB mode - mu = Uc(UC_ARCH_SPARC, UC_MODE_32) + mu = Uc(UC_ARCH_SPARC, UC_MODE_SPARC32) # map 2MB memory for this emulation mu.mem_map(ADDRESS, 2 * 1024 * 1024) diff --git a/bindings/python/unicorn/unicorn_const.py b/bindings/python/unicorn/unicorn_const.py index c99cb816..a1967684 100644 --- a/bindings/python/unicorn/unicorn_const.py +++ b/bindings/python/unicorn/unicorn_const.py @@ -30,6 +30,7 @@ UC_MODE_32 = 4 UC_MODE_64 = 8 UC_MODE_PPC64 = 8 UC_MODE_QPX = 16 +UC_MODE_SPARC32 = 4 UC_MODE_SPARC64 = 8 UC_MODE_V9 = 16 diff --git a/include/uc_priv.h b/include/uc_priv.h index 12f0b8bc..589a655f 100644 --- a/include/uc_priv.h +++ b/include/uc_priv.h @@ -17,7 +17,7 @@ #define UC_MODE_MIPS_MASK (UC_MODE_MIPS32|UC_MODE_MIPS64|UC_MODE_LITTLE_ENDIAN|UC_MODE_BIG_ENDIAN) #define UC_MODE_X86_MASK (UC_MODE_16|UC_MODE_32|UC_MODE_64|UC_MODE_LITTLE_ENDIAN) #define UC_MODE_PPC_MASK (UC_MODE_PPC64|UC_MODE_BIG_ENDIAN) -#define UC_MODE_SPARC_MASK (UC_MODE_SPARC64|UC_MODE_BIG_ENDIAN) +#define UC_MODE_SPARC_MASK (UC_MODE_SPARC32|UC_MODE_SPARC64|UC_MODE_BIG_ENDIAN) #define UC_MODE_M68K_MASK (UC_MODE_BIG_ENDIAN) #define ARR_SIZE(a) (sizeof(a)/sizeof(a[0])) diff --git a/include/unicorn/unicorn.h b/include/unicorn/unicorn.h index f3468ab6..a6bedfaf 100644 --- a/include/unicorn/unicorn.h +++ b/include/unicorn/unicorn.h @@ -89,8 +89,8 @@ typedef enum uc_mode { UC_MODE_LITTLE_ENDIAN = 0, // little-endian mode (default mode) UC_MODE_BIG_ENDIAN = 1 << 30, // big-endian mode // arm / arm64 - UC_MODE_ARM = 0, // Start executing in ARM mode - UC_MODE_THUMB = 1 << 4, // Start executing in THUMB mode (including Thumb-2) + UC_MODE_ARM = 0, // ARM mode + UC_MODE_THUMB = 1 << 4, // THUMB mode (including Thumb-2) UC_MODE_MCLASS = 1 << 5, // ARM's Cortex-M series (currently unsupported) UC_MODE_V8 = 1 << 6, // ARMv8 A32 encodings for ARM (currently unsupported) // mips @@ -107,6 +107,7 @@ typedef enum uc_mode { UC_MODE_PPC64 = 1 << 3, // 64-bit mode (currently unsupported) UC_MODE_QPX = 1 << 4, // Quad Processing eXtensions mode (currently unsupported) // sparc + UC_MODE_SPARC32 = 1 << 2, // 32-bit mode UC_MODE_SPARC64 = 1 << 3, // 64-bit mode UC_MODE_V9 = 1 << 4, // SparcV9 mode (currently unsupported) // m68k diff --git a/samples/sample_sparc.c b/samples/sample_sparc.c index c361232f..88bbd01e 100644 --- a/samples/sample_sparc.c +++ b/samples/sample_sparc.c @@ -57,7 +57,7 @@ static void test_sparc(void) printf("Emulate SPARC code\n"); // Initialize emulator in Sparc mode - err = uc_open(UC_ARCH_SPARC, 0, &uc); + err = uc_open(UC_ARCH_SPARC, UC_MODE_SPARC32, &uc); if (err) { printf("Failed on uc_open() with error returned: %u (%s)\n", err, uc_strerror(err)); diff --git a/tests/regress/sparc64.py b/tests/regress/sparc64.py index 27210bd1..12d3f547 100755 --- a/tests/regress/sparc64.py +++ b/tests/regress/sparc64.py @@ -5,7 +5,7 @@ from unicorn.sparc_const import * PAGE_SIZE = 1 * 1024 * 1024 -uc = Uc(UC_ARCH_SPARC, UC_MODE_64) +uc = Uc(UC_ARCH_SPARC, UC_MODE_SPARC64) uc.reg_write(UC_SPARC_REG_SP, 100) print 'writing sp = 100' diff --git a/tests/regress/sparc_jump_to_zero.c b/tests/regress/sparc_jump_to_zero.c index 96392f41..c816b700 100644 --- a/tests/regress/sparc_jump_to_zero.c +++ b/tests/regress/sparc_jump_to_zero.c @@ -1,7 +1,7 @@ #include #define HARDWARE_ARCHITECTURE UC_ARCH_SPARC -#define HARDWARE_MODE 0 +#define HARDWARE_MODE UC_ARCH_SPARC32 #define MEMORY_STARTING_ADDRESS 0x1000000 #define MEMORY_SIZE 2 * 1024 * 1024 diff --git a/tests/regress/sparc_reg.py b/tests/regress/sparc_reg.py index 4508efab..da6987d1 100755 --- a/tests/regress/sparc_reg.py +++ b/tests/regress/sparc_reg.py @@ -5,7 +5,7 @@ from unicorn.sparc_const import * PAGE_SIZE = 1 * 1024 * 1024 -uc = Uc(UC_ARCH_SPARC, 0) +uc = Uc(UC_ARCH_SPARC, UC_MODE_SPARC32) uc.reg_write(UC_SPARC_REG_SP, 100) uc.reg_write(UC_SPARC_REG_FP, 200)