Refactor CPU interface to allow the implementation of other CPU emulators (#3362)

* Refactor CPU interface

* Use IExecutionContext interface on SVC handler, change how CPU interrupts invokes the handlers

* Make CpuEngine take a ITickSource rather than returning one

The previous implementation had the scenario where the CPU engine had to implement the tick source in mind, like for example, when we have a hypervisor and the game can read CNTPCT on the host directly. However given that we need to do conversion due to different frequencies anyway, it's not worth it. It's better to just let the user pass the tick source and redirect any reads to CNTPCT to the user tick source

* XML docs for the public interfaces

* PPTC invalidation due to NativeInterface function name changes

* Fix build of the CPU tests

* PR feedback
This commit is contained in:
gdkchan 2022-05-31 16:29:35 -03:00 committed by GitHub
parent 9827dc35e1
commit 0c87bf9ea4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
64 changed files with 877 additions and 322 deletions

View file

@ -1,5 +1,5 @@
using ARMeilleure.State;
using Ryujinx.Common.Logging;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Kernel.Common;
using System;
using System.Collections.Generic;
@ -14,13 +14,13 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
private const int SvcFuncMaxArguments32 = 4;
private const int SvcMax = 0x80;
public static Action<Syscall32, ExecutionContext>[] SvcTable32 { get; }
public static Action<Syscall64, ExecutionContext>[] SvcTable64 { get; }
public static Action<Syscall32, IExecutionContext>[] SvcTable32 { get; }
public static Action<Syscall64, IExecutionContext>[] SvcTable64 { get; }
static SyscallTable()
{
SvcTable32 = new Action<Syscall32, ExecutionContext>[SvcMax];
SvcTable64 = new Action<Syscall64, ExecutionContext>[SvcMax];
SvcTable32 = new Action<Syscall32, IExecutionContext>[SvcMax];
SvcTable64 = new Action<Syscall64, IExecutionContext>[SvcMax];
Dictionary<int, string> svcFuncs64 = new Dictionary<int, string>
{
@ -182,9 +182,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
}
private static Action<T, ExecutionContext> GenerateMethod<T>(string svcName, int registerCleanCount)
private static Action<T, IExecutionContext> GenerateMethod<T>(string svcName, int registerCleanCount)
{
Type[] argTypes = new Type[] { typeof(T), typeof(ExecutionContext) };
Type[] argTypes = new Type[] { typeof(T), typeof(IExecutionContext) };
DynamicMethod method = new DynamicMethod(svcName, null, argTypes);
@ -292,9 +292,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
generator.Emit(OpCodes.Ldarg_1);
generator.Emit(OpCodes.Ldc_I4, registerAttribute.Index);
MethodInfo info = typeof(ExecutionContext).GetMethod(nameof(ExecutionContext.GetX));
MethodInfo info = typeof(IExecutionContext).GetMethod(nameof(IExecutionContext.GetX));
generator.Emit(OpCodes.Call, info);
generator.Emit(OpCodes.Callvirt, info);
generator.Emit(OpCodes.Box, typeof(ulong));
@ -339,9 +339,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
generator.Emit(OpCodes.Ldarg_1);
generator.Emit(OpCodes.Ldc_I4, registerAttribute.Index);
MethodInfo info = typeof(ExecutionContext).GetMethod(nameof(ExecutionContext.GetX));
MethodInfo info = typeof(IExecutionContext).GetMethod(nameof(IExecutionContext.GetX));
generator.Emit(OpCodes.Call, info);
generator.Emit(OpCodes.Callvirt, info);
ConvertToArgType(argType);
@ -355,9 +355,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
generator.Emit(OpCodes.Ldarg_1);
generator.Emit(OpCodes.Ldc_I4, registerAttribute.Index);
MethodInfo info = typeof(ExecutionContext).GetMethod(nameof(ExecutionContext.GetX));
MethodInfo info = typeof(IExecutionContext).GetMethod(nameof(IExecutionContext.GetX));
generator.Emit(OpCodes.Call, info);
generator.Emit(OpCodes.Callvirt, info);
ConvertToArgType(argType);
}
@ -393,9 +393,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
ConvertToFieldType(retType);
MethodInfo info = typeof(ExecutionContext).GetMethod(nameof(ExecutionContext.SetX));
MethodInfo info = typeof(IExecutionContext).GetMethod(nameof(IExecutionContext.SetX));
generator.Emit(OpCodes.Call, info);
generator.Emit(OpCodes.Callvirt, info);
registerInUse |= 1u << 0;
}
@ -415,9 +415,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
ConvertToFieldType(local.LocalType);
MethodInfo info = typeof(ExecutionContext).GetMethod(nameof(ExecutionContext.SetX));
MethodInfo info = typeof(IExecutionContext).GetMethod(nameof(IExecutionContext.SetX));
generator.Emit(OpCodes.Call, info);
generator.Emit(OpCodes.Callvirt, info);
registerInUse |= 1u << attribute.Index;
}
@ -434,14 +434,14 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
generator.Emit(OpCodes.Ldc_I4, i);
generator.Emit(OpCodes.Ldc_I8, 0L);
MethodInfo info = typeof(ExecutionContext).GetMethod(nameof(ExecutionContext.SetX));
MethodInfo info = typeof(IExecutionContext).GetMethod(nameof(IExecutionContext.SetX));
generator.Emit(OpCodes.Call, info);
generator.Emit(OpCodes.Callvirt, info);
}
generator.Emit(OpCodes.Ret);
return method.CreateDelegate<Action<T, ExecutionContext>>();
return method.CreateDelegate<Action<T, IExecutionContext>>();
}
private static void CheckIfTypeIsSupported(Type type, string svcName)