From 34b92fe7c542d87df5d3f0dd0148b25e52ed24b4 Mon Sep 17 00:00:00 2001 From: bushing Date: Thu, 25 Dec 2008 02:53:56 +0000 Subject: [PATCH] We need to be more careful about stack alignment on Darwin. These patches fix the alignment of gcc-generated code (as opposed to JIT code). There are probably more places this is needed :( git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1651 8ced0084-cf51-0410-be5f-012b33b47a6e --- SConstruct | 1 - Source/Core/Common/Src/Common.h | 8 ++++++++ Source/Core/Core/Src/HW/CommandProcessor.cpp | 2 +- Source/Core/Core/Src/HW/GPFifo.cpp | 15 +++++++-------- Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp | 4 ++-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/SConstruct b/SConstruct index 60ebc3c41e..d13dee7ba7 100644 --- a/SConstruct +++ b/SConstruct @@ -31,7 +31,6 @@ compileFlags = [ '-fno-strict-aliasing', '-msse2', '-fvisibility=hidden', -# '-mstackrealign', #'-fomit-frame-pointer' ] diff --git a/Source/Core/Common/Src/Common.h b/Source/Core/Common/Src/Common.h index e58a6e1a6f..107bee2a8b 100644 --- a/Source/Core/Common/Src/Common.h +++ b/Source/Core/Common/Src/Common.h @@ -50,6 +50,14 @@ #include "Paths.h" +// Darwin ABI requires that stack frames be aligned to 16-byte boundaries. +// This probably wouldn't break anyone either, but hey +#ifdef __APPLE__ +#define STACKALIGN __attribute__((__force_align_arg_pointer__)) +#else +#define STACKALIGN +#endif + // Function Cross-Compatibility #ifdef _WIN32 #define strcasecmp _stricmp diff --git a/Source/Core/Core/Src/HW/CommandProcessor.cpp b/Source/Core/Core/Src/HW/CommandProcessor.cpp index 3d20622027..f9a04fe875 100644 --- a/Source/Core/Core/Src/HW/CommandProcessor.cpp +++ b/Source/Core/Core/Src/HW/CommandProcessor.cpp @@ -564,7 +564,7 @@ void Write32(const u32 _Data, const u32 _Address) _dbg_assert_msg_(COMMANDPROCESSOR, 0, "Write32 at CommandProccessor at 0x%08x", _Address); } -void GatherPipeBursted() +void STACKALIGN GatherPipeBursted() { // if we aren't linked, we don't care about gather pipe data if (!fifo.bFF_GPLinkEnable) diff --git a/Source/Core/Core/Src/HW/GPFifo.cpp b/Source/Core/Core/Src/HW/GPFifo.cpp index 72a749f2d7..55eca024e7 100644 --- a/Source/Core/Core/Src/HW/GPFifo.cpp +++ b/Source/Core/Core/Src/HW/GPFifo.cpp @@ -64,7 +64,7 @@ void ResetGatherPipe() m_gatherPipeCount = 0; } -void CheckGatherPipe() +void STACKALIGN CheckGatherPipe() { while (m_gatherPipeCount >= GATHER_PIPE_SIZE) { @@ -75,16 +75,15 @@ void CheckGatherPipe() // move back the spill bytes m_gatherPipeCount -= GATHER_PIPE_SIZE; - // This could be dangerous, memmove or ? - // Assuming that memcpy does its thing in the ordinary direction, there should be no problem. - // Actually, this shouldn't ever be necessary. If we're above 2 "blocks" of data, - // the above memcpy could take care of that easily. TODO - memmove(m_gatherPipe, m_gatherPipe + GATHER_PIPE_SIZE, m_gatherPipeCount); - + for (u32 i=0; i < m_gatherPipeCount; i++) + m_gatherPipe[i] = m_gatherPipe[i + GATHER_PIPE_SIZE]; + // increase the CPUWritePointer CPeripheralInterface::Fifo_CPUWritePointer += GATHER_PIPE_SIZE; + if (CPeripheralInterface::Fifo_CPUWritePointer > CPeripheralInterface::Fifo_CPUEnd) - _assert_msg_(DYNA_REC, 0, "Fifo_CPUWritePointer out of bounds: %08x (end = %08x)", CPeripheralInterface::Fifo_CPUWritePointer, CPeripheralInterface::Fifo_CPUEnd); + _assert_msg_(DYNA_REC, 0, "Fifo_CPUWritePointer out of bounds: %08x (end = %08x)", + CPeripheralInterface::Fifo_CPUWritePointer, CPeripheralInterface::Fifo_CPUEnd); if (CPeripheralInterface::Fifo_CPUWritePointer >= CPeripheralInterface::Fifo_CPUEnd) CPeripheralInterface::Fifo_CPUWritePointer = CPeripheralInterface::Fifo_CPUBase; diff --git a/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp index 7889b673e2..d108bcac5e 100644 --- a/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp @@ -340,7 +340,7 @@ namespace CPUCompare JMP(asm_routines.testExceptions, true); } - void Jit64::Run() + void STACKALIGN Jit64::Run() { CompiledCode pExecAddr = (CompiledCode)asm_routines.enterCode; pExecAddr(); @@ -359,7 +359,7 @@ namespace CPUCompare pExecAddr();*/ } - void Jit64::Jit(u32 em_address) + void STACKALIGN Jit64::Jit(u32 em_address) { if (GetSpaceLeft() < 0x10000 || blocks.IsFull()) {