diff --git a/Source/Core/Core/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/PowerPC/Jit64/Jit.cpp index 02b64bf729..6d506b3d06 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit.cpp @@ -229,9 +229,14 @@ void Jit64::Init() gpr.SetEmitter(this); fpr.SetEmitter(this); - trampolines.Init(jo.memcheck ? TRAMPOLINE_CODE_SIZE_MMU : TRAMPOLINE_CODE_SIZE); + const size_t routines_size = asm_routines.CODE_SIZE; + const size_t trampolines_size = jo.memcheck ? TRAMPOLINE_CODE_SIZE_MMU : TRAMPOLINE_CODE_SIZE; + const size_t farcode_size = jo.memcheck ? FARCODE_SIZE_MMU : FARCODE_SIZE; const size_t constpool_size = m_const_pool.CONST_POOL_SIZE; - AllocCodeSpace(CODE_SIZE + constpool_size); + AllocCodeSpace(CODE_SIZE + routines_size + trampolines_size + farcode_size + constpool_size); + AddChildCodeSpace(&asm_routines, routines_size); + AddChildCodeSpace(&trampolines, trampolines_size); + AddChildCodeSpace(&m_far_code, farcode_size); m_const_pool.Init(AllocChildCodeSpace(constpool_size), constpool_size); // BLR optimization has the same consequences as block linking, as well as @@ -250,7 +255,7 @@ void Jit64::Init() // important: do this *after* generating the global asm routines, because we can't use farcode in // them. // it'll crash because the farcode functions get cleared on JIT clears. - m_far_code.Init(jo.memcheck ? FARCODE_SIZE_MMU : FARCODE_SIZE); + m_far_code.Init(); Clear(); code_block.m_stats = &js.st; @@ -276,8 +281,6 @@ void Jit64::Shutdown() FreeCodeSpace(); blocks.Shutdown(); - trampolines.Shutdown(); - asm_routines.Shutdown(); m_far_code.Shutdown(); m_const_pool.Shutdown(); } diff --git a/Source/Core/Core/PowerPC/Jit64/JitAsm.cpp b/Source/Core/Core/PowerPC/Jit64/JitAsm.cpp index 1239570dbd..cb2d12156d 100644 --- a/Source/Core/Core/PowerPC/Jit64/JitAsm.cpp +++ b/Source/Core/Core/PowerPC/Jit64/JitAsm.cpp @@ -2,7 +2,7 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. -#include "Core/PowerPC/Jit64/Jit.h" +#include "Core/PowerPC/Jit64/JitAsm.h" #include "Common/CommonTypes.h" #include "Common/JitRegister.h" #include "Common/x64ABI.h" @@ -11,7 +11,7 @@ #include "Core/CoreTiming.h" #include "Core/HW/CPU.h" #include "Core/HW/Memmap.h" -#include "Core/PowerPC/Jit64/JitAsm.h" +#include "Core/PowerPC/Jit64/Jit.h" #include "Core/PowerPC/Jit64Common/Jit64PowerPCState.h" #include "Core/PowerPC/PowerPC.h" @@ -20,6 +20,14 @@ using namespace Gen; // Not PowerPC state. Can't put in 'this' because it's out of range... static void* s_saved_rsp; +void Jit64AsmRoutineManager::Init(u8* stack_top) +{ + m_const_pool.Init(AllocChildCodeSpace(4096), 4096); + m_stack_top = stack_top; + Generate(); + WriteProtect(); +} + // PLAN: no more block numbers - crazy opcodes just contain offset within // dynarec buffer // At this offset - 4, there is an int specifying the block number. diff --git a/Source/Core/Core/PowerPC/Jit64/JitAsm.h b/Source/Core/Core/PowerPC/Jit64/JitAsm.h index 2cdac46b45..6aaad10031 100644 --- a/Source/Core/Core/PowerPC/Jit64/JitAsm.h +++ b/Source/Core/Core/PowerPC/Jit64/JitAsm.h @@ -34,16 +34,11 @@ private: u8* m_stack_top; public: - void Init(u8* stack_top) - { - m_stack_top = stack_top; - // NOTE: When making large additions to the AsmCommon code, you might - // want to ensure this number is big enough. - AllocCodeSpace(16384); - Generate(); - WriteProtect(); - } + // NOTE: When making large additions to the AsmCommon code, you might + // want to ensure this number is big enough. + static constexpr size_t CODE_SIZE = 16384; + + void Init(u8* stack_top); - void Shutdown() { FreeCodeSpace(); } void ResetStack(Gen::X64CodeBlock& emitter); }; diff --git a/Source/Core/Core/PowerPC/Jit64Common/FarCodeCache.cpp b/Source/Core/Core/PowerPC/Jit64Common/FarCodeCache.cpp index 72909f6a6a..7efdd6f331 100644 --- a/Source/Core/Core/PowerPC/Jit64Common/FarCodeCache.cpp +++ b/Source/Core/Core/PowerPC/Jit64Common/FarCodeCache.cpp @@ -4,15 +4,13 @@ #include "Core/PowerPC/Jit64Common/FarCodeCache.h" -void FarCodeCache::Init(size_t size) +void FarCodeCache::Init() { - AllocCodeSpace(size); m_enabled = true; } void FarCodeCache::Shutdown() { - FreeCodeSpace(); m_enabled = false; } diff --git a/Source/Core/Core/PowerPC/Jit64Common/FarCodeCache.h b/Source/Core/Core/PowerPC/Jit64Common/FarCodeCache.h index bc82045870..9cbbf2c052 100644 --- a/Source/Core/Core/PowerPC/Jit64Common/FarCodeCache.h +++ b/Source/Core/Core/PowerPC/Jit64Common/FarCodeCache.h @@ -17,7 +17,7 @@ constexpr size_t FARCODE_SIZE_MMU = 1024 * 1024 * 48; class FarCodeCache : public Gen::X64CodeBlock { public: - void Init(size_t size); + void Init(); void Shutdown(); bool Enabled() const; diff --git a/Source/Core/Core/PowerPC/Jit64Common/TrampolineCache.cpp b/Source/Core/Core/PowerPC/Jit64Common/TrampolineCache.cpp index 5fa7c2d911..25848a1a24 100644 --- a/Source/Core/Core/PowerPC/Jit64Common/TrampolineCache.cpp +++ b/Source/Core/Core/PowerPC/Jit64Common/TrampolineCache.cpp @@ -23,21 +23,11 @@ using namespace Gen; -void TrampolineCache::Init(size_t size) -{ - AllocCodeSpace(size); -} - void TrampolineCache::ClearCodeSpace() { X64CodeBlock::ClearCodeSpace(); } -void TrampolineCache::Shutdown() -{ - FreeCodeSpace(); -} - const u8* TrampolineCache::GenerateTrampoline(const TrampolineInfo& info) { if (info.read) diff --git a/Source/Core/Core/PowerPC/Jit64Common/TrampolineCache.h b/Source/Core/Core/PowerPC/Jit64Common/TrampolineCache.h index 769c4b4c84..9fc9a0b940 100644 --- a/Source/Core/Core/PowerPC/Jit64Common/TrampolineCache.h +++ b/Source/Core/Core/PowerPC/Jit64Common/TrampolineCache.h @@ -24,8 +24,6 @@ class TrampolineCache : public EmuCodeBlock const u8* GenerateWriteTrampoline(const TrampolineInfo& info); public: - void Init(size_t size); - void Shutdown(); const u8* GenerateTrampoline(const TrampolineInfo& info); void ClearCodeSpace(); }; diff --git a/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp b/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp index 9a9730efc0..c2200791f2 100644 --- a/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp +++ b/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp @@ -262,12 +262,19 @@ void JitIL::Init() jo.accurateSinglePrecision = false; UpdateMemoryOptions(); - trampolines.Init(jo.memcheck ? TRAMPOLINE_CODE_SIZE_MMU : TRAMPOLINE_CODE_SIZE); - AllocCodeSpace(CODE_SIZE); + const size_t routines_size = asm_routines.CODE_SIZE; + const size_t trampolines_size = jo.memcheck ? TRAMPOLINE_CODE_SIZE_MMU : TRAMPOLINE_CODE_SIZE; + const size_t farcode_size = jo.memcheck ? FARCODE_SIZE_MMU : FARCODE_SIZE; + const size_t constpool_size = m_const_pool.CONST_POOL_SIZE; + AllocCodeSpace(CODE_SIZE + routines_size + trampolines_size + farcode_size + constpool_size); + AddChildCodeSpace(&asm_routines, routines_size); + AddChildCodeSpace(&trampolines, trampolines_size); + AddChildCodeSpace(&m_far_code, farcode_size); + m_const_pool.Init(AllocChildCodeSpace(constpool_size), constpool_size); + blocks.Init(); asm_routines.Init(nullptr); - - m_far_code.Init(jo.memcheck ? FARCODE_SIZE_MMU : FARCODE_SIZE); + m_far_code.Init(); Clear(); code_block.m_stats = &js.st; @@ -299,8 +306,6 @@ void JitIL::Shutdown() FreeCodeSpace(); blocks.Shutdown(); - trampolines.Shutdown(); - asm_routines.Shutdown(); m_far_code.Shutdown(); }