From fdcf4f06f20457a31ebaa90344df9d09d85fcf0f Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Mon, 18 Feb 2019 14:02:39 +0100 Subject: [PATCH] Add x64Analyzer to Android.mk. Some minor cleanup --- CMakeLists.txt | 3 --- Common/ExceptionHandlerSetup.cpp | 9 +++++--- Common/MachineContext.h | 38 +++++++++++++++++++------------- Core/MIPS/MIPS.h | 6 +++-- Core/MemMap.cpp | 12 +++++----- android/jni/Android.mk | 2 ++ 6 files changed, 41 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9146253dc4..9d866fe92c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -340,9 +340,6 @@ macro(setup_target_project TargetName ProjectDir) endforeach() endmacro() -# Commented-out files are files that don't compile -# and were disabled in the original MSVC project anyway - set(CommonX86 Common/ABI.cpp Common/ABI.h diff --git a/Common/ExceptionHandlerSetup.cpp b/Common/ExceptionHandlerSetup.cpp index 64dc68286a..c5725c581c 100644 --- a/Common/ExceptionHandlerSetup.cpp +++ b/Common/ExceptionHandlerSetup.cpp @@ -4,6 +4,8 @@ // The corresponding file is called MemTools in the Dolphin project. +#include "ppsspp_config.h" + #include "Common/ExceptionHandlerSetup.h" #include #include @@ -17,7 +19,7 @@ #include "Common/Log.h" #include "ext/native/thread/threadutil.h" -#if defined(PPSSPP_ARCH_X86) || defined(PPSSPP_ARCH_AMD64) +#if PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64) #include "Common/MachineContext.h" #endif @@ -225,7 +227,7 @@ void InstallExceptionHandler(BadAccessHandler badAccessHandler) { void UninstallExceptionHandler() { } -#elif defined(_POSIX_VERSION) && !defined(_M_GENERIC) +#elif defined(_POSIX_VERSION) static struct sigaction old_sa_segv; static struct sigaction old_sa_bus; @@ -329,7 +331,8 @@ void UninstallExceptionHandler() { NOTICE_LOG(SYSTEM, "Uninstalled exception handler"); g_badAccessHandler = nullptr; } -#else // _M_GENERIC or unsupported platform + +#else // Unsupported platform. Could also #error void InstallExceptionHandler(BadAccessHandler badAccessHandler) { ERROR_LOG(SYSTEM, "Exception handler not implemented on this platform, can't install"); diff --git a/Common/MachineContext.h b/Common/MachineContext.h index 9ce074ba41..c39df38abd 100644 --- a/Common/MachineContext.h +++ b/Common/MachineContext.h @@ -9,7 +9,7 @@ #if PPSSPP_PLATFORM(WINDOWS) #include typedef CONTEXT SContext; -#if PPSSPP_ARCH_AMD64 +#if PPSSPP_ARCH(AMD64) #define CTX_RAX Rax #define CTX_RBX Rbx #define CTX_RCX Rcx @@ -46,7 +46,7 @@ typedef CONTEXT SContext; #include #include -#if PPSSPP_ARCH_AMD64 +#if PPSSPP_ARCH(AMD64) typedef x86_thread_state64_t SContext; #define CTX_RAX __rax #define CTX_RBX __rbx @@ -94,7 +94,7 @@ typedef _STRUCT_MCONTEXT64 SContext; #include typedef mcontext_t SContext; -#if PPSSPP_ARCH_AMD64 +#if PPSSPP_ARCH(AMD64) #define CTX_RAX gregs[REG_RAX] #define CTX_RBX gregs[REG_RBX] #define CTX_RCX gregs[REG_RCX] @@ -122,7 +122,7 @@ typedef mcontext_t SContext; #elif defined(__OpenBSD__) #include typedef ucontext_t SContext; -#if PPSSPP_ARCH_AMD64 +#if PPSSPP_ARCH(AMD64) #define CTX_RAX sc_rax #define CTX_RBX sc_rbx #define CTX_RCX sc_rcx @@ -146,7 +146,7 @@ typedef ucontext_t SContext; #elif defined(__NetBSD__) #include typedef mcontext_t SContext; -#if PPSSPP_ARCH_AMD64 +#if PPSSPP_ARCH(AMD64) #define CTX_RAX __gregs[_REG_RAX] #define CTX_RBX __gregs[_REG_RBX] #define CTX_RCX __gregs[_REG_RCX] @@ -170,7 +170,7 @@ typedef mcontext_t SContext; #elif defined(__FreeBSD__) #include typedef mcontext_t SContext; -#if PPSSPP_ARCH_AMD64 +#if PPSSPP_ARCH(AMD64) #define CTX_RAX mc_rax #define CTX_RBX mc_rbx #define CTX_RCX mc_rcx @@ -194,7 +194,7 @@ typedef mcontext_t SContext; #elif defined(__HAIKU__) #include typedef mcontext_t SContext; -#if PPSSPP_ARCH_AMD64 +#if PPSSPP_ARCH(AMD64) #define CTX_RAX rax #define CTX_RBX rbx #define CTX_RCX rcx @@ -219,17 +219,12 @@ typedef mcontext_t SContext; #error No context definition for OS #endif -#if defined(PPSSPP_ARCH_AMD64) || defined(PPSSPP_ARCH_X86) +#if PPSSPP_ARCH(AMD64) + #include #define CTX_PC CTX_RIP static inline u64* ContextRN(SContext* ctx, int n) { -#if PPSSPP_ARCH_32BIT - static const u8 offsets[] = { - offsetof(SContext, CTX_RAX), offsetof(SContext, CTX_RCX), offsetof(SContext, CTX_RDX), - offsetof(SContext, CTX_RBX), offsetof(SContext, CTX_RSP), offsetof(SContext, CTX_RBP), - offsetof(SContext, CTX_RSI), offsetof(SContext, CTX_RDI)}; -#else static const u8 offsets[] = { offsetof(SContext, CTX_RAX), offsetof(SContext, CTX_RCX), offsetof(SContext, CTX_RDX), offsetof(SContext, CTX_RBX), offsetof(SContext, CTX_RSP), offsetof(SContext, CTX_RBP), @@ -237,7 +232,20 @@ static inline u64* ContextRN(SContext* ctx, int n) offsetof(SContext, CTX_R9), offsetof(SContext, CTX_R10), offsetof(SContext, CTX_R11), offsetof(SContext, CTX_R12), offsetof(SContext, CTX_R13), offsetof(SContext, CTX_R14), offsetof(SContext, CTX_R15)}; -#endif return (u64*)((char*)ctx + offsets[n]); } + +#elif PPSSPP_ARCH(X86) + +#include +#define CTX_PC CTX_RIP + +static inline u32* ContextRN(SContext* ctx, int n) +{ + static const u8 offsets[] = { + offsetof(SContext, CTX_RAX), offsetof(SContext, CTX_RCX), offsetof(SContext, CTX_RDX), + offsetof(SContext, CTX_RBX), offsetof(SContext, CTX_RSP), offsetof(SContext, CTX_RBP), + offsetof(SContext, CTX_RSI), offsetof(SContext, CTX_RDI)}; + return (u32*)((char*)ctx + offsets[n]); +} #endif diff --git a/Core/MIPS/MIPS.h b/Core/MIPS/MIPS.h index 7d2c40e879..bcc9910358 100644 --- a/Core/MIPS/MIPS.h +++ b/Core/MIPS/MIPS.h @@ -17,6 +17,8 @@ #pragma once +#include "ppsspp_config.h" + #include #include "util/random/rng.h" @@ -148,7 +150,7 @@ extern u8 fromvoffset[128]; enum class CPUCore; -#if defined(PPSSPP_ARCH_X86) || defined(PPSSPP_ARCH_AMD64) +#if PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64) // Note that CTXREG is offset to point at the first floating point register, intentionally. This is so that a byte offset // can reach both GPR and FPR regs. @@ -246,7 +248,7 @@ public: static const u32 FCR0_VALUE = 0x00003351; -#if defined(PPSSPP_ARCH_X86) || defined(PPSSPP_ARCH_AMD64) +#if PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64) // FPU TEMP0, etc. are swapped in here if necessary (e.g. on x86.) float tempValues[NUM_X86_FPU_TEMPS]; #endif diff --git a/Core/MemMap.cpp b/Core/MemMap.cpp index 78abbaeacb..dc92f93121 100644 --- a/Core/MemMap.cpp +++ b/Core/MemMap.cpp @@ -30,14 +30,14 @@ #include "Common/ChunkFile.h" -#if defined(PPSSPP_ARCH_AMD64) || defined(PPSSPP_ARCH_X86) +#if PPSSPP_ARCH(AMD64) || PPSSPP_ARCH(X86) #include "Common/MachineContext.h" #include "Common/x64Analyzer.h" -#elif defined(PPSSPP_ARCH_ARM64) +#elif PPSSPP_ARCH(ARM64) #include "Core/Util/DisArm64.h" typedef sigcontext SContext; #define CTX_PC pc -#elif defined(PPSSPP_ARCH_ARM) +#elif PPSSPP_ARCH(ARM) #include "ext/disarm.h" typedef sigcontext SContext; #define CTX_PC arm_pc @@ -508,19 +508,19 @@ bool HandleFault(uintptr_t hostAddress, void *ctx) { // TODO: Share the struct between the various analyzers, that will allow us to share most of // the implementations here. -#if defined(PPSSPP_ARCH_AMD64) || defined(PPSSPP_ARCH_X86) +#if PPSSPP_ARCH(AMD64) || PPSSPP_ARCH(X86) // X86, X86-64. Variable instruction size so need to analyze the mov instruction in detail. // To ignore the access, we need to disassemble the instruction and modify context->CTX_PC LSInstructionInfo info; X86AnalyzeMOV(codePtr, info); -#elif defined(PPSSPP_ARCH_ARM64) +#elif PPSSPP_ARCH(ARM64) uint32_t word; memcpy(&word, codePtr, 4); // To ignore the access, we need to disassemble the instruction and modify context->CTX_PC Arm64LSInstructionInfo info; Arm64AnalyzeLoadStore((uint64_t)codePtr, word, &info); -#elif defined(PPSSPP_ARCH_ARM) +#elif PPSSPP_ARCH(ARM) uint32_t word; memcpy(&word, codePtr, 4); // To ignore the access, we need to disassemble the instruction and modify context->CTX_PC diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 0adfb91db9..44ab4a7332 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -15,6 +15,7 @@ ifeq ($(TARGET_ARCH_ABI),x86) ARCH_FILES := \ $(SRC)/Common/ABI.cpp \ $(SRC)/Common/x64Emitter.cpp \ + $(SRC)/Common/x64Analyzer.cpp \ $(SRC)/Common/CPUDetect.cpp \ $(SRC)/Common/Thunk.cpp \ $(SRC)/Core/MIPS/x86/CompALU.cpp \ @@ -36,6 +37,7 @@ ifeq ($(TARGET_ARCH_ABI),x86_64) ARCH_FILES := \ $(SRC)/Common/ABI.cpp \ $(SRC)/Common/x64Emitter.cpp \ + $(SRC)/Common/x64Analyzer.cpp \ $(SRC)/Common/CPUDetect.cpp \ $(SRC)/Common/Thunk.cpp \ $(SRC)/Core/MIPS/x86/CompALU.cpp \