Add NCE code

This commit is contained in:
gdk 2023-07-03 19:28:05 -03:00 committed by Emmanuel Hansen
parent a1e34041fa
commit 0970972f0d
40 changed files with 2702 additions and 40 deletions

View file

@ -0,0 +1,55 @@
using System;
using System.Runtime.InteropServices;
namespace Ryujinx.Cpu.Nce
{
static class NceNativeInterface
{
private delegate ulong GetTickCounterDelegate();
private delegate bool SuspendThreadHandlerDelegate();
private static GetTickCounterDelegate _getTickCounter;
private static SuspendThreadHandlerDelegate _suspendThreadHandler;
private static IntPtr _getTickCounterPtr;
private static IntPtr _suspendThreadHandlerPtr;
[ThreadStatic]
private static NceExecutionContext _context;
[ThreadStatic]
private static ITickSource _tickSource;
static NceNativeInterface()
{
_getTickCounter = GetTickCounter;
_suspendThreadHandler = SuspendThreadHandler;
_getTickCounterPtr = Marshal.GetFunctionPointerForDelegate(_getTickCounter);
_suspendThreadHandlerPtr = Marshal.GetFunctionPointerForDelegate(_suspendThreadHandler);
}
public static void RegisterThread(NceExecutionContext context, ITickSource tickSource)
{
_context = context;
_tickSource = tickSource;
}
public static ulong GetTickCounter()
{
return _tickSource.Counter;
}
public static bool SuspendThreadHandler()
{
return _context.OnInterrupt();
}
public static IntPtr GetTickCounterAccessFunctionPointer()
{
return _getTickCounterPtr;
}
public static IntPtr GetSuspendThreadHandlerFunctionPointer()
{
return _suspendThreadHandlerPtr;
}
}
}