From 1bcd129683549db3581801a6220e531a558567c2 Mon Sep 17 00:00:00 2001 From: EmptyChaos Date: Fri, 2 Sep 2016 07:10:51 +0000 Subject: [PATCH] Interpreter: Fix CoreTiming contract The interpreter does not use CoreTiming correctly. Calls to Advance must be made in advance of executing the associated slice, not afterwards. --- Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp index 336371914e..ec147c41bd 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp @@ -196,11 +196,14 @@ int Interpreter::SingleStepInner() void Interpreter::SingleStep() { + // Declare start of new slice + CoreTiming::Advance(); + SingleStepInner(); + // The interpreter ignores instruction timing information outside the 'fast runloop'. CoreTiming::g_slice_length = 1; PowerPC::ppcState.downcount = 0; - CoreTiming::Advance(); if (PowerPC::ppcState.Exceptions) { @@ -222,6 +225,11 @@ void Interpreter::Run() { while (!CPU::GetState()) { + // CoreTiming Advance() ends the previous slice and declares the start of the next + // one so it must always be called at the start. At boot, we are in slice -1 and must + // advance into slice 0 to get a correct slice length before executing any cycles. + CoreTiming::Advance(); + // we have to check exceptions at branches apparently (or maybe just rfi?) if (SConfig::GetInstance().bEnableDebugging) { @@ -295,8 +303,6 @@ void Interpreter::Run() PowerPC::ppcState.downcount -= cycles; } } - - CoreTiming::Advance(); } }