ARMeilleure: Add debuggable CPU loop

This commit is contained in:
merry 2022-02-08 19:00:47 +00:00
parent 9f72c3efee
commit cffa8905ab
3 changed files with 31 additions and 5 deletions

View file

@ -8,6 +8,7 @@ namespace ARMeilleure
public static bool AllowLcqInFunctionTable { get; set; } = true; public static bool AllowLcqInFunctionTable { get; set; } = true;
public static bool UseUnmanagedDispatchLoop { get; set; } = true; public static bool UseUnmanagedDispatchLoop { get; set; } = true;
public static bool EnableDebugging { get; set; } = false;
public static bool UseSseIfAvailable { get; set; } = true; public static bool UseSseIfAvailable { get; set; } = true;
public static bool UseSse2IfAvailable { get; set; } = true; public static bool UseSse2IfAvailable { get; set; } = true;

View file

@ -68,7 +68,7 @@ namespace ARMeilleure.Translation
bool highCq, bool highCq,
Aarch32Mode mode) Aarch32Mode mode)
{ {
HasPtc = Ptc.State != PtcState.Disabled; HasPtc = Ptc.State != PtcState.Disabled && !Optimizations.EnableDebugging;
Memory = memory; Memory = memory;
CountTable = countTable; CountTable = countTable;
FunctionTable = funcTable; FunctionTable = funcTable;

View file

@ -169,7 +169,33 @@ namespace ARMeilleure.Translation
NativeInterface.RegisterThread(context, Memory, this); NativeInterface.RegisterThread(context, Memory, this);
if (Optimizations.UseUnmanagedDispatchLoop) if (Optimizations.EnableDebugging)
{
context.DebugPc = address;
do
{
context.DebugPc = ExecuteSingle(context, context.DebugPc);
while (context._debugState != (int)DebugState.Running)
{
Interlocked.CompareExchange(ref context._debugState, (int)DebugState.Stopped, (int)DebugState.Stopping);
context._debugHalt.WaitOne();
if (Interlocked.CompareExchange(ref context._shouldStep, 0, 1) == 1)
{
context.DebugPc = Step(context, context.DebugPc);
context._stepBarrier.SignalAndWait();
context._stepBarrier.SignalAndWait();
}
else
{
Interlocked.CompareExchange(ref context._debugState, (int)DebugState.Running, (int)DebugState.Stopped);
}
}
}
while (context.Running && context.DebugPc != 0);
}
else if (Optimizations.UseUnmanagedDispatchLoop)
{ {
Stubs.DispatchLoop(context.NativeContextPtr, address); Stubs.DispatchLoop(context.NativeContextPtr, address);
} }
@ -368,9 +394,8 @@ namespace ARMeilleure.Translation
if (block.Exit) if (block.Exit)
{ {
// Left option here as it may be useful if we need to return to managed rather than tail call in // Return to managed rather than tail call.
// future. (eg. for debug) bool useReturns = Optimizations.EnableDebugging;
bool useReturns = false;
InstEmitFlowHelper.EmitVirtualJump(context, Const(block.Address), isReturn: useReturns); InstEmitFlowHelper.EmitVirtualJump(context, Const(block.Address), isReturn: useReturns);
} }