From 0c87bf9ea4b0655fc6b90b4ab20e93f237e7549b Mon Sep 17 00:00:00 2001 From: gdkchan Date: Tue, 31 May 2022 16:29:35 -0300 Subject: 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 --- .../HOS/Kernel/SupervisorCall/SyscallTable.cs | 40 +++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'Ryujinx.HLE/HOS/Kernel/SupervisorCall/SyscallTable.cs') diff --git a/Ryujinx.HLE/HOS/Kernel/SupervisorCall/SyscallTable.cs b/Ryujinx.HLE/HOS/Kernel/SupervisorCall/SyscallTable.cs index 6e0b7010..8b7e7fb8 100644 --- a/Ryujinx.HLE/HOS/Kernel/SupervisorCall/SyscallTable.cs +++ b/Ryujinx.HLE/HOS/Kernel/SupervisorCall/SyscallTable.cs @@ -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[] SvcTable32 { get; } - public static Action[] SvcTable64 { get; } + public static Action[] SvcTable32 { get; } + public static Action[] SvcTable64 { get; } static SyscallTable() { - SvcTable32 = new Action[SvcMax]; - SvcTable64 = new Action[SvcMax]; + SvcTable32 = new Action[SvcMax]; + SvcTable64 = new Action[SvcMax]; Dictionary svcFuncs64 = new Dictionary { @@ -182,9 +182,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall } } - private static Action GenerateMethod(string svcName, int registerCleanCount) + private static Action GenerateMethod(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>(); + return method.CreateDelegate>(); } private static void CheckIfTypeIsSupported(Type type, string svcName) -- cgit v1.2.3