From e4081b29f9d91b7128b7b91aeb7708e695e23dfe Mon Sep 17 00:00:00 2001 From: magumagu Date: Tue, 25 Mar 2014 20:46:36 -0700 Subject: [PATCH 1/3] Use unaligned stores to save XMM regs to stack. On Win32, the stack isn't aligned, so aligned stores will cause crashes. --- Source/Core/Common/x64ABI.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/Common/x64ABI.cpp b/Source/Core/Common/x64ABI.cpp index 525ecb538b..6955a34a14 100644 --- a/Source/Core/Common/x64ABI.cpp +++ b/Source/Core/Common/x64ABI.cpp @@ -92,7 +92,7 @@ void XEmitter::ABI_PushRegistersAndAdjustStack(u32 mask, bool noProlog) { if (mask & (1 << (16 + x))) { - MOVAPD(MDisp(RSP, offset), (X64Reg) x); + MOVUPD(MDisp(RSP, offset), (X64Reg) x); offset += 16; } } @@ -114,7 +114,7 @@ void XEmitter::ABI_PopRegistersAndAdjustStack(u32 mask, bool noProlog) { if (mask & (1 << (16 + x))) { - MOVAPD((X64Reg) x, MDisp(RSP, size)); + MOVUPD((X64Reg) x, MDisp(RSP, size)); size += 16; } } From 4eab240e259b48c7a15e2021363165cb5112dbf0 Mon Sep 17 00:00:00 2001 From: magumagu Date: Tue, 25 Mar 2014 20:48:25 -0700 Subject: [PATCH 2/3] Compute stack usage correctly in ABI_CallFunctionPC. (The numbers need to be consistent with the actual usage, or else the stack gets corrupted.) --- Source/Core/Common/x64ABI.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/Common/x64ABI.cpp b/Source/Core/Common/x64ABI.cpp index 6955a34a14..5a09201825 100644 --- a/Source/Core/Common/x64ABI.cpp +++ b/Source/Core/Common/x64ABI.cpp @@ -213,11 +213,11 @@ void XEmitter::ABI_CallFunctionCCCP(void *func, u32 param1, u32 param2,u32 param } void XEmitter::ABI_CallFunctionPC(void *func, void *param1, u32 param2) { - ABI_AlignStack(3 * 4); + ABI_AlignStack(2 * 4); PUSH(32, Imm32(param2)); PUSH(32, Imm32((u32)param1)); CALL(func); - ABI_RestoreStack(3 * 4); + ABI_RestoreStack(2 * 4); } void XEmitter::ABI_CallFunctionPPC(void *func, void *param1, void *param2,u32 param3) { From ca4e0495c03b72cb2e2cf47f093db54409cb3937 Mon Sep 17 00:00:00 2001 From: magumagu Date: Tue, 25 Mar 2014 20:50:14 -0700 Subject: [PATCH 3/3] Save registers before calls in x86-32 JIT. I have no idea what the person who added RegistersInUse() was thinking, but not correctly saving registers is an easy way to end up with crashes. --- Source/Core/Core/PowerPC/Jit64/Jit.cpp | 5 ----- Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp | 5 ----- 2 files changed, 10 deletions(-) diff --git a/Source/Core/Core/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/PowerPC/Jit64/Jit.cpp index 686805bce2..9e1eeec222 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit.cpp @@ -726,7 +726,6 @@ const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBloc u32 Jit64::RegistersInUse() { -#if _M_X86_64 u32 result = 0; for (int i = 0; i < NUMXREGS; i++) { @@ -736,8 +735,4 @@ u32 Jit64::RegistersInUse() result |= (1 << (16 + i)); } return result; -#else - // not needed - return 0; -#endif } diff --git a/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp b/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp index 689b4c48bd..53d0323c71 100644 --- a/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp +++ b/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp @@ -61,7 +61,6 @@ struct RegInfo { }; static u32 regsInUse(RegInfo& R) { -#if _M_X86_64 u32 result = 0; for (unsigned i = 0; i < MAX_NUMBER_OF_REGS; i++) { @@ -71,10 +70,6 @@ static u32 regsInUse(RegInfo& R) { result |= (1 << (16 + i)); } return result; -#else - // not needed - return 0; -#endif } static void regMarkUse(RegInfo& R, InstLoc I, InstLoc Op, unsigned OpNum) {