forked from Mirror/Ryujinx
a694420d11
* Implement speculative translation on the cpu, and change the way how branches to unknown or untranslated addresses works * Port t0opt changes and other cleanups * Change namespace from translation related classes to ChocolArm64.Translation, other minor tweaks * Fix typo * Translate higher quality code for indirect jumps aswell, and on some cases that were missed when lower quality (tier 0) code was available * Remove debug print * Remove direct argument passing optimization, and enable tail calls for BR instructions * Call delegates directly with Callvirt rather than calling Execute, do not emit calls for tier 0 code * Remove unused property * Rename argument on ArmSubroutine delegate
68 lines
No EOL
1.5 KiB
C#
68 lines
No EOL
1.5 KiB
C#
using ChocolArm64.Memory;
|
|
using ChocolArm64.State;
|
|
using ChocolArm64.Translation;
|
|
using System;
|
|
using System.Threading;
|
|
|
|
namespace ChocolArm64
|
|
{
|
|
public class CpuThread
|
|
{
|
|
public CpuThreadState ThreadState { get; private set; }
|
|
public MemoryManager Memory { get; private set; }
|
|
|
|
private Translator _translator;
|
|
|
|
public Thread Work;
|
|
|
|
public event EventHandler WorkFinished;
|
|
|
|
private int _isExecuting;
|
|
|
|
public CpuThread(Translator translator, MemoryManager memory, long entrypoint)
|
|
{
|
|
_translator = translator;
|
|
Memory = memory;
|
|
|
|
ThreadState = new CpuThreadState();
|
|
|
|
ThreadState.Running = true;
|
|
|
|
Work = new Thread(delegate()
|
|
{
|
|
translator.ExecuteSubroutine(this, entrypoint);
|
|
|
|
memory.RemoveMonitor(ThreadState.Core);
|
|
|
|
WorkFinished?.Invoke(this, EventArgs.Empty);
|
|
});
|
|
}
|
|
|
|
public bool Execute()
|
|
{
|
|
if (Interlocked.Exchange(ref _isExecuting, 1) == 1)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
Work.Start();
|
|
|
|
return true;
|
|
}
|
|
|
|
public void StopExecution()
|
|
{
|
|
ThreadState.Running = false;
|
|
}
|
|
|
|
public void RequestInterrupt()
|
|
{
|
|
ThreadState.RequestInterrupt();
|
|
}
|
|
|
|
public bool IsCurrentThread()
|
|
{
|
|
return Thread.CurrentThread == Work;
|
|
}
|
|
}
|
|
} |