diff --git a/ARMeilleure/State/ExecutionContext.cs b/ARMeilleure/State/ExecutionContext.cs index 5d18e6ed8..43f4e0065 100644 --- a/ARMeilleure/State/ExecutionContext.cs +++ b/ARMeilleure/State/ExecutionContext.cs @@ -5,14 +5,10 @@ namespace ARMeilleure.State { public class ExecutionContext { - private const int MinCountForCheck = 4000; - private NativeContext _nativeContext; internal IntPtr NativeContextPtr => _nativeContext.BasePtr; - private bool _interrupted; - private readonly ICounter _counter; public ulong Pc => _nativeContext.GetPc(); @@ -101,8 +97,7 @@ namespace ARMeilleure.State _undefinedCallback = undefinedCallback; Running = true; - - _nativeContext.SetCounter(MinCountForCheck); + _nativeContext.SetInterruptState(0); } public ulong GetX(int index) => _nativeContext.GetX(index); @@ -119,19 +114,13 @@ namespace ARMeilleure.State internal void CheckInterrupt() { - if (_interrupted) - { - _interrupted = false; - - _interruptCallback?.Invoke(this); - } - - _nativeContext.SetCounter(MinCountForCheck); + _nativeContext.SetInterruptState(0); + _interruptCallback?.Invoke(this); } public void RequestInterrupt() { - _interrupted = true; + _nativeContext.SetInterruptState(1); } internal void OnBreak(ulong address, int imm) @@ -152,8 +141,7 @@ namespace ARMeilleure.State public void StopRunning() { Running = false; - - _nativeContext.SetCounter(0); + _nativeContext.SetInterruptState(1); } public void Dispose() diff --git a/ARMeilleure/State/NativeContext.cs b/ARMeilleure/State/NativeContext.cs index 89e875d12..4885322c8 100644 --- a/ARMeilleure/State/NativeContext.cs +++ b/ARMeilleure/State/NativeContext.cs @@ -13,7 +13,7 @@ namespace ARMeilleure.State public fixed ulong V[RegisterConsts.VecRegsCount * 2]; public fixed uint Flags[RegisterConsts.FlagsCount]; public fixed uint FpFlags[RegisterConsts.FpFlagsCount]; - public int Counter; + public int InterruptState; public ulong DispatchAddress; public ulong ExclusiveAddress; public ulong ExclusiveValueLow; @@ -168,8 +168,8 @@ namespace ARMeilleure.State } } - public int GetCounter() => GetStorage().Counter; - public void SetCounter(int value) => GetStorage().Counter = value; + public int GetInterruptState() => GetStorage().InterruptState; + public void SetInterruptState(int value) => GetStorage().InterruptState = value; public bool GetRunning() => GetStorage().Running != 0; public void SetRunning(bool value) => GetStorage().Running = value ? 1 : 0; @@ -214,9 +214,9 @@ namespace ARMeilleure.State } } - public static int GetCounterOffset() + public static int GetInterruptStateOffset() { - return StorageOffset(ref _dummyStorage, ref _dummyStorage.Counter); + return StorageOffset(ref _dummyStorage, ref _dummyStorage.InterruptState); } public static int GetDispatchAddressOffset() diff --git a/ARMeilleure/Translation/PTC/Ptc.cs b/ARMeilleure/Translation/PTC/Ptc.cs index db373bfc9..f15e422f4 100644 --- a/ARMeilleure/Translation/PTC/Ptc.cs +++ b/ARMeilleure/Translation/PTC/Ptc.cs @@ -27,7 +27,7 @@ namespace ARMeilleure.Translation.PTC private const string OuterHeaderMagicString = "PTCohd\0\0"; private const string InnerHeaderMagicString = "PTCihd\0\0"; - private const uint InternalVersion = 4140; //! To be incremented manually for each change to the ARMeilleure project. + private const int InternalVersion = 123; //! To be incremented manually for each change to the ARMeilleure project. private const string ActualDir = "0"; private const string BackupDir = "1"; diff --git a/ARMeilleure/Translation/Translator.cs b/ARMeilleure/Translation/Translator.cs index 2edbe4011..697142d82 100644 --- a/ARMeilleure/Translation/Translator.cs +++ b/ARMeilleure/Translation/Translator.cs @@ -432,24 +432,18 @@ namespace ARMeilleure.Translation internal static void EmitSynchronization(EmitterContext context) { - long countOffs = NativeContext.GetCounterOffset(); + long interruptedOffs = NativeContext.GetInterruptStateOffset(); - Operand lblNonZero = Label(); + Operand interruptedAddr = context.Add(context.LoadArgument(OperandType.I64, 0), Const(interruptedOffs)); + Operand interrupted = context.Load(OperandType.I32, interruptedAddr); Operand lblExit = Label(); - Operand countAddr = context.Add(context.LoadArgument(OperandType.I64, 0), Const(countOffs)); - Operand count = context.Load(OperandType.I32, countAddr); - context.BranchIfTrue(lblNonZero, count, BasicBlockFrequency.Cold); + context.BranchIfFalse(lblExit, interrupted, BasicBlockFrequency.Cold); Operand running = context.Call(typeof(NativeInterface).GetMethod(nameof(NativeInterface.CheckSynchronization))); context.BranchIfTrue(lblExit, running, BasicBlockFrequency.Cold); - context.Return(Const(0L)); - context.MarkLabel(lblNonZero); - count = context.Subtract(count, Const(1)); - context.Store(countAddr, count); - context.MarkLabel(lblExit); }