From e86def732a58ddd343680154e04d1f6390cb0ac6 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 18 Jan 2017 16:03:31 -0500 Subject: [PATCH 1/3] PowerPC: Move zeroing of segment registers into ResetRegisters --- Source/Core/Core/PowerPC/PowerPC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Core/PowerPC/PowerPC.cpp b/Source/Core/Core/PowerPC/PowerPC.cpp index 6f2ae50a56..4d40f64343 100644 --- a/Source/Core/Core/PowerPC/PowerPC.cpp +++ b/Source/Core/Core/PowerPC/PowerPC.cpp @@ -88,6 +88,7 @@ void DoState(PointerWrap& p) static void ResetRegisters() { memset(ppcState.ps, 0, sizeof(ppcState.ps)); + memset(ppcState.sr, 0, sizeof(ppcState.sr)); memset(ppcState.gpr, 0, sizeof(ppcState.gpr)); memset(ppcState.spr, 0, sizeof(ppcState.spr)); /* @@ -135,7 +136,6 @@ void Init(int cpu_core) s_invalidate_cache_thread_safe = CoreTiming::RegisterEvent("invalidateEmulatedCache", InvalidateCacheThreadSafe); - memset(ppcState.sr, 0, sizeof(ppcState.sr)); ppcState.pagetable_base = 0; ppcState.pagetable_hashmask = 0; From b2351ddb29e812248b7fc5b9f574ea24b4e41cee Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 18 Jan 2017 19:13:52 -0500 Subject: [PATCH 2/3] PowerPC: Move CPU core initialization to its own function --- Source/Core/Core/PowerPC/PowerPC.cpp | 57 +++++++++++++++------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/Source/Core/Core/PowerPC/PowerPC.cpp b/Source/Core/Core/PowerPC/PowerPC.cpp index 4d40f64343..45f87607b0 100644 --- a/Source/Core/Core/PowerPC/PowerPC.cpp +++ b/Source/Core/Core/PowerPC/PowerPC.cpp @@ -127,33 +127,8 @@ static void ResetRegisters() SystemTimers::DecrementerSet(); } -void Init(int cpu_core) +static void InitializeCPUCore(int cpu_core) { - // NOTE: This function runs on EmuThread, not the CPU Thread. - // Changing the rounding mode has a limited effect. - FPURoundMode::SetPrecisionMode(FPURoundMode::PREC_53); - - s_invalidate_cache_thread_safe = - CoreTiming::RegisterEvent("invalidateEmulatedCache", InvalidateCacheThreadSafe); - - ppcState.pagetable_base = 0; - ppcState.pagetable_hashmask = 0; - - for (int tlb = 0; tlb < 2; tlb++) - { - for (int set = 0; set < 64; set++) - { - ppcState.tlb[tlb][set].recent = 0; - for (int way = 0; way < 2; way++) - { - ppcState.tlb[tlb][set].paddr[way] = 0; - ppcState.tlb[tlb][set].pte[way] = 0; - ppcState.tlb[tlb][set].tag[way] = TLB_TAG_INVALID; - } - } - } - - ResetRegisters(); PPCTables::InitTables(cpu_core); // We initialize the interpreter because @@ -184,7 +159,37 @@ void Init(int cpu_core) { s_mode = MODE_INTERPRETER; } +} +void Init(int cpu_core) +{ + // NOTE: This function runs on EmuThread, not the CPU Thread. + // Changing the rounding mode has a limited effect. + FPURoundMode::SetPrecisionMode(FPURoundMode::PREC_53); + + s_invalidate_cache_thread_safe = + CoreTiming::RegisterEvent("invalidateEmulatedCache", InvalidateCacheThreadSafe); + + ppcState.pagetable_base = 0; + ppcState.pagetable_hashmask = 0; + + for (int tlb = 0; tlb < 2; tlb++) + { + for (int set = 0; set < 64; set++) + { + ppcState.tlb[tlb][set].recent = 0; + for (int way = 0; way < 2; way++) + { + ppcState.tlb[tlb][set].paddr[way] = 0; + ppcState.tlb[tlb][set].pte[way] = 0; + ppcState.tlb[tlb][set].tag[way] = TLB_TAG_INVALID; + } + } + } + + ResetRegisters(); + + InitializeCPUCore(cpu_core); ppcState.iCache.Init(); if (SConfig::GetInstance().bEnableDebugging) From c761f98edec1c6424a6e197b2a2be2a2f7075b6a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 18 Jan 2017 19:15:46 -0500 Subject: [PATCH 3/3] PowerPC: Simplify TLB resetting Member initializers and std::array make this trivial for fixed value initialization. --- Source/Core/Core/PowerPC/PowerPC.cpp | 15 +-------------- Source/Core/Core/PowerPC/PowerPC.h | 10 +++++----- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/Source/Core/Core/PowerPC/PowerPC.cpp b/Source/Core/Core/PowerPC/PowerPC.cpp index 45f87607b0..b044f77834 100644 --- a/Source/Core/Core/PowerPC/PowerPC.cpp +++ b/Source/Core/Core/PowerPC/PowerPC.cpp @@ -172,20 +172,7 @@ void Init(int cpu_core) ppcState.pagetable_base = 0; ppcState.pagetable_hashmask = 0; - - for (int tlb = 0; tlb < 2; tlb++) - { - for (int set = 0; set < 64; set++) - { - ppcState.tlb[tlb][set].recent = 0; - for (int way = 0; way < 2; way++) - { - ppcState.tlb[tlb][set].paddr[way] = 0; - ppcState.tlb[tlb][set].pte[way] = 0; - ppcState.tlb[tlb][set].tag[way] = TLB_TAG_INVALID; - } - } - } + ppcState.tlb = {}; ResetRegisters(); diff --git a/Source/Core/Core/PowerPC/PowerPC.h b/Source/Core/Core/PowerPC/PowerPC.h index 885b8a5da2..2d8476e0c2 100644 --- a/Source/Core/Core/PowerPC/PowerPC.h +++ b/Source/Core/Core/PowerPC/PowerPC.h @@ -49,10 +49,10 @@ enum CoreMode struct tlb_entry { - u32 tag[TLB_WAYS]; - u32 paddr[TLB_WAYS]; - u32 pte[TLB_WAYS]; - u8 recent; + u32 tag[TLB_WAYS] = {TLB_TAG_INVALID, TLB_TAG_INVALID}; + u32 paddr[TLB_WAYS] = {}; + u32 pte[TLB_WAYS] = {}; + u8 recent = 0; }; // This contains the entire state of the emulated PowerPC "Gekko" CPU. @@ -116,7 +116,7 @@ struct PowerPCState // also for power management, but we don't care about that. u32 spr[1024]; - tlb_entry tlb[NUM_TLBS][TLB_SIZE / TLB_WAYS]; + std::array, NUM_TLBS> tlb; u32 pagetable_base; u32 pagetable_hashmask;