diff --git a/CMakeLists.txt b/CMakeLists.txt index c6831d44..5d85b84a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,20 @@ else() set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m64") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m64") endif() + elseif(ANDROID_ABI) + string(FIND "${ANDROID_ABI}" "arm64" UC_RET) + + if (${UC_RET} GREATER_EQUAL "0") + set(UNICORN_TARGET_ARCH "aarch64") + else() + string(FIND "${ANDROID_ABI}" "armeabi" UC_RET) + + if (${UC_RET} GREATER_EQUAL "0") + set(UNICORN_TARGET_ARCH "arm") + else() + set(UNICORN_TARGET_ARCH "i386") + endif() + endif() else() execute_process(COMMAND ${CMAKE_C_COMPILER} -dM -E - INPUT_FILE /dev/null @@ -185,6 +199,10 @@ else() endif() set (EXTRA_CFLAGS "${EXTRA_CFLAGS}-fPIC") + if(ANDROID_ABI) + set (EXTRA_CFLAGS "${EXTRA_CFLAGS} --target=${CMAKE_C_COMPILER_TARGET}") + set (EXTRA_CFLAGS "${EXTRA_CFLAGS} --sysroot=${CMAKE_SYSROOT}") + endif() set(TARGET_LIST "--target-list=") if (UNICORN_HAS_X86) @@ -994,7 +1012,7 @@ add_library(unicorn-common ${UNICORN_COMMON_SRCS} ) -if (NOT MSVC) +if (NOT MSVC AND NOT ANDROID_ABI) target_link_libraries(unicorn-common pthread) endif() @@ -1112,11 +1130,15 @@ if(MSVC) set(SAMPLES_LIB unicorn ) -else() +elseif(NOT ANDROID_ABI) set(SAMPLES_LIB unicorn pthread ) +else() + set(SAMPLES_LIB + unicorn + ) endif() foreach(SAMPLE_FILE ${UNICORN_SAMPLE_FILE}) diff --git a/qemu/aarch64.h b/qemu/aarch64.h index ffc68d52..75d71514 100644 --- a/qemu/aarch64.h +++ b/qemu/aarch64.h @@ -4,6 +4,7 @@ #ifndef UNICORN_ARCH_POSTFIX #define UNICORN_ARCH_POSTFIX _aarch64 #endif +#define use_idiv_instructions use_idiv_instructions_aarch64 #define arm_arch arm_arch_aarch64 #define tb_target_set_jmp_target tb_target_set_jmp_target_aarch64 #define have_bmi1 have_bmi1_aarch64 diff --git a/qemu/aarch64eb.h b/qemu/aarch64eb.h index da74a577..ee750153 100644 --- a/qemu/aarch64eb.h +++ b/qemu/aarch64eb.h @@ -4,6 +4,7 @@ #ifndef UNICORN_ARCH_POSTFIX #define UNICORN_ARCH_POSTFIX _aarch64eb #endif +#define use_idiv_instructions use_idiv_instructions_aarch64eb #define arm_arch arm_arch_aarch64eb #define tb_target_set_jmp_target tb_target_set_jmp_target_aarch64eb #define have_bmi1 have_bmi1_aarch64eb diff --git a/qemu/accel/tcg/cputlb.c b/qemu/accel/tcg/cputlb.c index c29f9455..80fbf2cb 100644 --- a/qemu/accel/tcg/cputlb.c +++ b/qemu/accel/tcg/cputlb.c @@ -963,10 +963,10 @@ static void tlb_fill(CPUState *cpu, target_ulong addr, int size, * should result in exception + longjmp to the cpu loop. */ ok = cc->tlb_fill(cpu, addr, size, access_type, mmu_idx, false, retaddr); + assert(ok); #else cc->tlb_fill(cpu, addr, size, access_type, mmu_idx, false, retaddr); #endif - assert(ok); } static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, diff --git a/qemu/arm.h b/qemu/arm.h index d8248f9f..d3cc372d 100644 --- a/qemu/arm.h +++ b/qemu/arm.h @@ -4,6 +4,7 @@ #ifndef UNICORN_ARCH_POSTFIX #define UNICORN_ARCH_POSTFIX _arm #endif +#define use_idiv_instructions use_idiv_instructions_arm #define arm_arch arm_arch_arm #define tb_target_set_jmp_target tb_target_set_jmp_target_arm #define have_bmi1 have_bmi1_arm diff --git a/qemu/armeb.h b/qemu/armeb.h index d8f379d8..0a51a80d 100644 --- a/qemu/armeb.h +++ b/qemu/armeb.h @@ -4,6 +4,7 @@ #ifndef UNICORN_ARCH_POSTFIX #define UNICORN_ARCH_POSTFIX _armeb #endif +#define use_idiv_instructions use_idiv_instructions_armeb #define arm_arch arm_arch_armeb #define tb_target_set_jmp_target tb_target_set_jmp_target_armeb #define have_bmi1 have_bmi1_armeb diff --git a/qemu/exec.c b/qemu/exec.c index 317552f8..5d65c7a2 100644 --- a/qemu/exec.c +++ b/qemu/exec.c @@ -1404,10 +1404,10 @@ AddressSpaceDispatch *address_space_dispatch_new(struct uc_struct *uc, FlatView uint16_t n; n = dummy_section(uc, &d->map, fv, &(uc->io_mem_unassigned)); + assert(n == PHYS_SECTION_UNASSIGNED); #else dummy_section(uc, &d->map, fv, &(uc->io_mem_unassigned)); #endif - assert(n == PHYS_SECTION_UNASSIGNED); d->phys_map = (PhysPageEntry) { .ptr = PHYS_MAP_NODE_NIL, .skip = 1 }; d->uc = uc; diff --git a/qemu/include/qemu/osdep.h b/qemu/include/qemu/osdep.h index dc9e655a..cbb93fe1 100644 --- a/qemu/include/qemu/osdep.h +++ b/qemu/include/qemu/osdep.h @@ -154,7 +154,8 @@ struct uc_struct; * code that is unreachable when features are disabled. * All supported versions of Glib's g_assert() satisfy this requirement. */ -#ifdef __MINGW32__ +// Unfortunately, NDK also has this problem. +#if defined(__MINGW32__ ) || defined(__ANDROID__) #undef assert #define assert(x) g_assert(x) #endif diff --git a/qemu/m68k.h b/qemu/m68k.h index ada19e15..cb3d430b 100644 --- a/qemu/m68k.h +++ b/qemu/m68k.h @@ -4,6 +4,7 @@ #ifndef UNICORN_ARCH_POSTFIX #define UNICORN_ARCH_POSTFIX _m68k #endif +#define use_idiv_instructions use_idiv_instructions_m68k #define arm_arch arm_arch_m68k #define tb_target_set_jmp_target tb_target_set_jmp_target_m68k #define have_bmi1 have_bmi1_m68k diff --git a/qemu/mips.h b/qemu/mips.h index c543784e..a2b78379 100644 --- a/qemu/mips.h +++ b/qemu/mips.h @@ -4,6 +4,7 @@ #ifndef UNICORN_ARCH_POSTFIX #define UNICORN_ARCH_POSTFIX _mips #endif +#define use_idiv_instructions use_idiv_instructions_mips #define arm_arch arm_arch_mips #define tb_target_set_jmp_target tb_target_set_jmp_target_mips #define have_bmi1 have_bmi1_mips diff --git a/qemu/mips64.h b/qemu/mips64.h index 14769400..9faef36b 100644 --- a/qemu/mips64.h +++ b/qemu/mips64.h @@ -4,6 +4,7 @@ #ifndef UNICORN_ARCH_POSTFIX #define UNICORN_ARCH_POSTFIX _mips64 #endif +#define use_idiv_instructions use_idiv_instructions_mips64 #define arm_arch arm_arch_mips64 #define tb_target_set_jmp_target tb_target_set_jmp_target_mips64 #define have_bmi1 have_bmi1_mips64 diff --git a/qemu/mips64el.h b/qemu/mips64el.h index f4337206..6f748b36 100644 --- a/qemu/mips64el.h +++ b/qemu/mips64el.h @@ -4,6 +4,7 @@ #ifndef UNICORN_ARCH_POSTFIX #define UNICORN_ARCH_POSTFIX _mips64el #endif +#define use_idiv_instructions use_idiv_instructions_mips64el #define arm_arch arm_arch_mips64el #define tb_target_set_jmp_target tb_target_set_jmp_target_mips64el #define have_bmi1 have_bmi1_mips64el diff --git a/qemu/mipsel.h b/qemu/mipsel.h index fca4abf3..a4831183 100644 --- a/qemu/mipsel.h +++ b/qemu/mipsel.h @@ -4,6 +4,7 @@ #ifndef UNICORN_ARCH_POSTFIX #define UNICORN_ARCH_POSTFIX _mipsel #endif +#define use_idiv_instructions use_idiv_instructions_mipsel #define arm_arch arm_arch_mipsel #define tb_target_set_jmp_target tb_target_set_jmp_target_mipsel #define have_bmi1 have_bmi1_mipsel diff --git a/qemu/ppc.h b/qemu/ppc.h index 67d0016c..8cb9ea3e 100644 --- a/qemu/ppc.h +++ b/qemu/ppc.h @@ -4,6 +4,7 @@ #ifndef UNICORN_ARCH_POSTFIX #define UNICORN_ARCH_POSTFIX _ppc #endif +#define use_idiv_instructions use_idiv_instructions_ppc #define arm_arch arm_arch_ppc #define tb_target_set_jmp_target tb_target_set_jmp_target_ppc #define have_bmi1 have_bmi1_ppc diff --git a/qemu/ppc64.h b/qemu/ppc64.h index 7f41ecc8..1d055072 100644 --- a/qemu/ppc64.h +++ b/qemu/ppc64.h @@ -4,6 +4,7 @@ #ifndef UNICORN_ARCH_POSTFIX #define UNICORN_ARCH_POSTFIX _ppc64 #endif +#define use_idiv_instructions use_idiv_instructions_ppc64 #define arm_arch arm_arch_ppc64 #define tb_target_set_jmp_target tb_target_set_jmp_target_ppc64 #define have_bmi1 have_bmi1_ppc64 diff --git a/qemu/riscv32.h b/qemu/riscv32.h index dceb3ead..df9eed70 100644 --- a/qemu/riscv32.h +++ b/qemu/riscv32.h @@ -4,6 +4,7 @@ #ifndef UNICORN_ARCH_POSTFIX #define UNICORN_ARCH_POSTFIX _riscv32 #endif +#define use_idiv_instructions use_idiv_instructions_riscv32 #define arm_arch arm_arch_riscv32 #define tb_target_set_jmp_target tb_target_set_jmp_target_riscv32 #define have_bmi1 have_bmi1_riscv32 diff --git a/qemu/riscv64.h b/qemu/riscv64.h index ada4239a..c41e7178 100644 --- a/qemu/riscv64.h +++ b/qemu/riscv64.h @@ -4,6 +4,7 @@ #ifndef UNICORN_ARCH_POSTFIX #define UNICORN_ARCH_POSTFIX _riscv64 #endif +#define use_idiv_instructions use_idiv_instructions_riscv64 #define arm_arch arm_arch_riscv64 #define tb_target_set_jmp_target tb_target_set_jmp_target_riscv64 #define have_bmi1 have_bmi1_riscv64 diff --git a/qemu/sparc.h b/qemu/sparc.h index b3ea2084..741e7565 100644 --- a/qemu/sparc.h +++ b/qemu/sparc.h @@ -4,6 +4,7 @@ #ifndef UNICORN_ARCH_POSTFIX #define UNICORN_ARCH_POSTFIX _sparc #endif +#define use_idiv_instructions use_idiv_instructions_sparc #define arm_arch arm_arch_sparc #define tb_target_set_jmp_target tb_target_set_jmp_target_sparc #define have_bmi1 have_bmi1_sparc diff --git a/qemu/sparc64.h b/qemu/sparc64.h index 5cee6484..5262a11b 100644 --- a/qemu/sparc64.h +++ b/qemu/sparc64.h @@ -4,6 +4,7 @@ #ifndef UNICORN_ARCH_POSTFIX #define UNICORN_ARCH_POSTFIX _sparc64 #endif +#define use_idiv_instructions use_idiv_instructions_sparc64 #define arm_arch arm_arch_sparc64 #define tb_target_set_jmp_target tb_target_set_jmp_target_sparc64 #define have_bmi1 have_bmi1_sparc64 diff --git a/qemu/target/arm/cpu.c b/qemu/target/arm/cpu.c index 36ef844c..d391ad21 100644 --- a/qemu/target/arm/cpu.c +++ b/qemu/target/arm/cpu.c @@ -143,8 +143,8 @@ static void cp_reg_check_reset(gpointer key, gpointer value, gpointer opaque) cp_reg_reset(key, value, opaque); #ifndef NDEBUG newvalue = read_raw_cp_reg(&cpu->env, ri); -#endif assert(oldvalue == newvalue); +#endif } static void arm_cpu_reset(CPUState *dev) @@ -919,7 +919,9 @@ void arm_cpu_realizefn(struct uc_struct *uc, CPUState *dev) * Presence of EL2 itself is ARM_FEATURE_EL2, and of the * Security Extensions is ARM_FEATURE_EL3. */ +#ifndef NDEBUG assert(no_aa32 || cpu_isar_feature(aa32_arm_div, cpu)); +#endif set_feature(env, ARM_FEATURE_LPAE); set_feature(env, ARM_FEATURE_V7); } @@ -945,7 +947,9 @@ void arm_cpu_realizefn(struct uc_struct *uc, CPUState *dev) if (arm_feature(env, ARM_FEATURE_V6)) { set_feature(env, ARM_FEATURE_V5); if (!arm_feature(env, ARM_FEATURE_M)) { +#ifndef NDEBUG assert(no_aa32 || cpu_isar_feature(aa32_jazelle, cpu)); +#endif set_feature(env, ARM_FEATURE_AUXCR); } } diff --git a/qemu/target/arm/helper.c b/qemu/target/arm/helper.c index 9789455b..629165b1 100644 --- a/qemu/target/arm/helper.c +++ b/qemu/target/arm/helper.c @@ -6027,12 +6027,11 @@ static void define_debug_regs(ARMCPU *cpu) wrps = arm_num_wrps(cpu); #ifndef NDEBUG ctx_cmps = arm_num_ctx_cmps(cpu); + assert(ctx_cmps <= brps); #else arm_num_ctx_cmps(cpu); #endif - assert(ctx_cmps <= brps); - define_one_arm_cp_reg(cpu, &dbgdidr); define_arm_cp_regs(cpu, debug_cp_reginfo); diff --git a/qemu/target/ppc/mmu-hash64.c b/qemu/target/ppc/mmu-hash64.c index 78e5540e..8facd2df 100644 --- a/qemu/target/ppc/mmu-hash64.c +++ b/qemu/target/ppc/mmu-hash64.c @@ -1172,7 +1172,9 @@ void ppc_hash64_init(PowerPCCPU *cpu) PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); if (!pcc->hash64_opts) { +#ifndef NDEBUG assert(!(env->mmu_model & POWERPC_MMU_64)); +#endif return; } diff --git a/qemu/tcg/arm/tcg-target.h b/qemu/tcg/arm/tcg-target.h index 17e77137..63d5b253 100644 --- a/qemu/tcg/arm/tcg-target.h +++ b/qemu/tcg/arm/tcg-target.h @@ -82,10 +82,8 @@ typedef enum { #define TCG_TARGET_NB_REGS 16 -#ifdef __ARM_ARCH_EXT_IDIV__ -#define use_idiv_instructions 1 -#else -extern bool use_idiv_instructions; +#ifndef __ARM_ARCH_EXT_IDIV__ +extern bool use_idiv_instructions; // Unicorn: Don't have the same name with macro #endif @@ -122,7 +120,11 @@ extern bool use_idiv_instructions; #define TCG_TARGET_HAS_muls2_i32 1 #define TCG_TARGET_HAS_muluh_i32 0 #define TCG_TARGET_HAS_mulsh_i32 0 +#ifdef __ARM_ARCH_EXT_IDIV__ +#define TCG_TARGET_HAS_div_i32 1 +#else #define TCG_TARGET_HAS_div_i32 use_idiv_instructions +#endif #define TCG_TARGET_HAS_rem_i32 0 #define TCG_TARGET_HAS_goto_ptr 1 #define TCG_TARGET_HAS_direct_jump 0 diff --git a/qemu/tcg/arm/tcg-target.inc.c b/qemu/tcg/arm/tcg-target.inc.c index 48ce5461..cbc4d81a 100644 --- a/qemu/tcg/arm/tcg-target.inc.c +++ b/qemu/tcg/arm/tcg-target.inc.c @@ -27,7 +27,7 @@ int arm_arch = __ARM_ARCH; -#ifndef use_idiv_instructions +#ifndef __ARM_ARCH_EXT_IDIV__ bool use_idiv_instructions; #endif @@ -2201,7 +2201,7 @@ static void tcg_target_init(TCGContext *s) { /* Only probe for the platform and capabilities if we havn't already determined maximum values at compile time. */ -#ifndef use_idiv_instructions +#ifndef __ARM_ARCH_EXT_IDIV__ { unsigned long hwcap = qemu_getauxval(AT_HWCAP); use_idiv_instructions = (hwcap & HWCAP_ARM_IDIVA) != 0; diff --git a/qemu/util/range.c b/qemu/util/range.c index f10f5664..3a60cd9b 100644 --- a/qemu/util/range.c +++ b/qemu/util/range.c @@ -68,10 +68,10 @@ GList *range_list_insert(GList *list, Range *data) g_free(l->next->data); #ifndef NDEBUG new_l = g_list_delete_link(list, l->next); + assert(new_l == list); #else g_list_delete_link(list, l->next); #endif - assert(new_l == list); } return list; diff --git a/qemu/x86_64.h b/qemu/x86_64.h index ceec9bbe..a1896af7 100644 --- a/qemu/x86_64.h +++ b/qemu/x86_64.h @@ -4,6 +4,7 @@ #ifndef UNICORN_ARCH_POSTFIX #define UNICORN_ARCH_POSTFIX _x86_64 #endif +#define use_idiv_instructions use_idiv_instructions_x86_64 #define arm_arch arm_arch_x86_64 #define tb_target_set_jmp_target tb_target_set_jmp_target_x86_64 #define have_bmi1 have_bmi1_x86_64 diff --git a/symbols.sh b/symbols.sh index 30b4b871..19997fb4 100755 --- a/symbols.sh +++ b/symbols.sh @@ -4,6 +4,7 @@ CMD_PATH=$(realpath $0) SOURCE_DIR=$(dirname ${CMD_PATH}) COMMON_SYMBOLS=" +use_idiv_instructions \ arm_arch \ tb_target_set_jmp_target \ have_bmi1 \