From 4f603ef7303c5e79f6bdfaca1304b46e8684f7f0 Mon Sep 17 00:00:00 2001 From: pierre Date: Mon, 11 Apr 2011 20:54:52 +0000 Subject: [PATCH] Core/DSP/Jit: Ensure aligned stack when pushing registers for ABI calls This fixes issue 4378: DSP LLE Jit not working on OSX git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7450 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Core/Core/Src/DSP/Jit/DSPJitRegCache.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Source/Core/Core/Src/DSP/Jit/DSPJitRegCache.cpp b/Source/Core/Core/Src/DSP/Jit/DSPJitRegCache.cpp index 9201157618..6bcbeca35e 100644 --- a/Source/Core/Core/Src/DSP/Jit/DSPJitRegCache.cpp +++ b/Source/Core/Core/Src/DSP/Jit/DSPJitRegCache.cpp @@ -418,6 +418,21 @@ void DSPJitRegCache::pushRegs() { movToMemory(i); } + int push_count = 0; + for(unsigned int i = 0; i < NUMXREGS; i++) { + if (xregs[i].guest_reg == DSP_REG_USED) + push_count++; + } + + //hardcoding alignment to 16 bytes +#ifdef _M_X64 + if (push_count & 1) + emitter.SUB(64,R(RSP),Imm32(8)); +#else + if (push_count & 3) + emitter.SUB(32,R(ESP),Imm32(16 - 4 * (push_count & 3))); +#endif + for(unsigned int i = 0; i < NUMXREGS; i++) { if (xregs[i].guest_reg == DSP_REG_USED) { emitter.PUSH((X64Reg)i); @@ -452,6 +467,12 @@ void DSPJitRegCache::popRegs() { #else emitter.MOV(32, M(&ebp_store), R(EBP)); #endif + int push_count = 0; + for(unsigned int i = 0; i < NUMXREGS; i++) { + if (xregs[i].pushed) + push_count++; + } + for(int i = NUMXREGS-1; i >= 0; i--) { if (xregs[i].pushed) { emitter.POP((X64Reg)i); @@ -460,6 +481,15 @@ void DSPJitRegCache::popRegs() { } } + //hardcoding alignment to 16 bytes +#ifdef _M_X64 + if (push_count & 1) + emitter.ADD(64,R(RSP),Imm32(8)); +#else + if (push_count & 3) + emitter.ADD(32,R(ESP),Imm32(16 - 4 * (push_count & 3))); +#endif + for(unsigned int i = 0; i <= DSP_REG_MAX_MEM_BACKED; i++) { if (regs[i].host_reg != INVALID_REG) movToHostReg(i,regs[i].host_reg);