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:
@ -1,5 +1,4 @@
|
||||
using ARMeilleure.Memory;
|
||||
using ARMeilleure.State;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.Graphics.Gpu;
|
||||
using Ryujinx.HLE.HOS.Kernel.Process;
|
||||
@ -11,12 +10,12 @@ namespace Ryujinx.HLE.HOS
|
||||
{
|
||||
private readonly ulong _pid;
|
||||
private readonly GpuContext _gpuContext;
|
||||
private readonly CpuContext _cpuContext;
|
||||
private readonly ICpuContext _cpuContext;
|
||||
private T _memoryManager;
|
||||
|
||||
public IVirtualMemoryManager AddressSpace => _memoryManager;
|
||||
|
||||
public ArmProcessContext(ulong pid, GpuContext gpuContext, T memoryManager, bool for64Bit)
|
||||
public ArmProcessContext(ulong pid, ICpuEngine cpuEngine, GpuContext gpuContext, T memoryManager, bool for64Bit)
|
||||
{
|
||||
if (memoryManager is IRefCounted rc)
|
||||
{
|
||||
@ -27,11 +26,16 @@ namespace Ryujinx.HLE.HOS
|
||||
|
||||
_pid = pid;
|
||||
_gpuContext = gpuContext;
|
||||
_cpuContext = new CpuContext(memoryManager, for64Bit);
|
||||
_cpuContext = cpuEngine.CreateCpuContext(memoryManager, for64Bit);
|
||||
_memoryManager = memoryManager;
|
||||
}
|
||||
|
||||
public void Execute(ExecutionContext context, ulong codeAddress)
|
||||
public IExecutionContext CreateExecutionContext(ExceptionCallbacks exceptionCallbacks)
|
||||
{
|
||||
return _cpuContext.CreateExecutionContext(exceptionCallbacks);
|
||||
}
|
||||
|
||||
public void Execute(IExecutionContext context, ulong codeAddress)
|
||||
{
|
||||
_cpuContext.Execute(context, codeAddress);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Ryujinx.Common.Configuration;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.Cpu.Jit;
|
||||
using Ryujinx.Graphics.Gpu;
|
||||
using Ryujinx.HLE.HOS.Kernel;
|
||||
using Ryujinx.HLE.HOS.Kernel.Process;
|
||||
@ -10,10 +11,12 @@ namespace Ryujinx.HLE.HOS
|
||||
{
|
||||
class ArmProcessContextFactory : IProcessContextFactory
|
||||
{
|
||||
private readonly ICpuEngine _cpuEngine;
|
||||
private readonly GpuContext _gpu;
|
||||
|
||||
public ArmProcessContextFactory(GpuContext gpu)
|
||||
public ArmProcessContextFactory(ICpuEngine cpuEngine, GpuContext gpu)
|
||||
{
|
||||
_cpuEngine = cpuEngine;
|
||||
_gpu = gpu;
|
||||
}
|
||||
|
||||
@ -29,12 +32,14 @@ namespace Ryujinx.HLE.HOS
|
||||
switch (mode)
|
||||
{
|
||||
case MemoryManagerMode.SoftwarePageTable:
|
||||
return new ArmProcessContext<MemoryManager>(pid, _gpu, new MemoryManager(context.Memory, addressSpaceSize, invalidAccessHandler), for64Bit);
|
||||
var memoryManager = new MemoryManager(context.Memory, addressSpaceSize, invalidAccessHandler);
|
||||
return new ArmProcessContext<MemoryManager>(pid, _cpuEngine, _gpu, memoryManager, for64Bit);
|
||||
|
||||
case MemoryManagerMode.HostMapped:
|
||||
case MemoryManagerMode.HostMappedUnsafe:
|
||||
bool unsafeMode = mode == MemoryManagerMode.HostMappedUnsafe;
|
||||
return new ArmProcessContext<MemoryManagerHostMapped>(pid, _gpu, new MemoryManagerHostMapped(context.Memory, addressSpaceSize, unsafeMode, invalidAccessHandler), for64Bit);
|
||||
var memoryManagerHostMapped = new MemoryManagerHostMapped(context.Memory, addressSpaceSize, unsafeMode, invalidAccessHandler);
|
||||
return new ArmProcessContext<MemoryManagerHostMapped>(pid, _cpuEngine, _gpu, memoryManagerHostMapped, for64Bit);
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
|
@ -10,6 +10,8 @@ using Ryujinx.Audio.Integration;
|
||||
using Ryujinx.Audio.Output;
|
||||
using Ryujinx.Audio.Renderer.Device;
|
||||
using Ryujinx.Audio.Renderer.Server;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.Cpu.Jit;
|
||||
using Ryujinx.HLE.FileSystem;
|
||||
using Ryujinx.HLE.HOS.Kernel;
|
||||
using Ryujinx.HLE.HOS.Kernel.Memory;
|
||||
@ -57,6 +59,9 @@ namespace Ryujinx.HLE.HOS
|
||||
|
||||
internal Switch Device { get; private set; }
|
||||
|
||||
internal ITickSource TickSource { get; }
|
||||
internal ICpuEngine CpuEngine { get; }
|
||||
|
||||
internal SurfaceFlinger SurfaceFlinger { get; private set; }
|
||||
internal AudioManager AudioManager { get; private set; }
|
||||
internal AudioOutputManager AudioOutputManager { get; private set; }
|
||||
@ -121,7 +126,11 @@ namespace Ryujinx.HLE.HOS
|
||||
|
||||
public Horizon(Switch device)
|
||||
{
|
||||
TickSource = new TickSource(KernelConstants.CounterFrequency);
|
||||
CpuEngine = new JitEngine(TickSource);
|
||||
|
||||
KernelContext = new KernelContext(
|
||||
TickSource,
|
||||
device,
|
||||
device.Memory,
|
||||
device.Configuration.MemoryConfiguration.ToKernelMemorySize(),
|
||||
@ -215,40 +224,40 @@ namespace Ryujinx.HLE.HOS
|
||||
internalOffset = new TimeSpanType(-internalOffset.NanoSeconds);
|
||||
|
||||
// First init the standard steady clock
|
||||
TimeServiceManager.Instance.SetupStandardSteadyClock(null, clockSourceId, systemTime, internalOffset, TimeSpanType.Zero, false);
|
||||
TimeServiceManager.Instance.SetupStandardLocalSystemClock(null, new SystemClockContext(), systemTime.ToSeconds());
|
||||
TimeServiceManager.Instance.SetupStandardSteadyClock(TickSource, clockSourceId, systemTime, internalOffset, TimeSpanType.Zero, false);
|
||||
TimeServiceManager.Instance.SetupStandardLocalSystemClock(TickSource, new SystemClockContext(), systemTime.ToSeconds());
|
||||
|
||||
if (NxSettings.Settings.TryGetValue("time!standard_network_clock_sufficient_accuracy_minutes", out object standardNetworkClockSufficientAccuracyMinutes))
|
||||
{
|
||||
TimeSpanType standardNetworkClockSufficientAccuracy = new TimeSpanType((int)standardNetworkClockSufficientAccuracyMinutes * 60000000000);
|
||||
|
||||
// The network system clock needs a valid system clock, as such we setup this system clock using the local system clock.
|
||||
TimeServiceManager.Instance.StandardLocalSystemClock.GetClockContext(null, out SystemClockContext localSytemClockContext);
|
||||
TimeServiceManager.Instance.StandardLocalSystemClock.GetClockContext(TickSource, out SystemClockContext localSytemClockContext);
|
||||
TimeServiceManager.Instance.SetupStandardNetworkSystemClock(localSytemClockContext, standardNetworkClockSufficientAccuracy);
|
||||
}
|
||||
|
||||
TimeServiceManager.Instance.SetupStandardUserSystemClock(null, false, SteadyClockTimePoint.GetRandom());
|
||||
TimeServiceManager.Instance.SetupStandardUserSystemClock(TickSource, false, SteadyClockTimePoint.GetRandom());
|
||||
|
||||
// FIXME: TimeZone should be init here but it's actually done in ContentManager
|
||||
|
||||
TimeServiceManager.Instance.SetupEphemeralNetworkSystemClock();
|
||||
|
||||
DatabaseImpl.Instance.InitializeDatabase(LibHacHorizonManager.SdbClient);
|
||||
DatabaseImpl.Instance.InitializeDatabase(TickSource, LibHacHorizonManager.SdbClient);
|
||||
|
||||
HostSyncpoint = new NvHostSyncpt(device);
|
||||
|
||||
SurfaceFlinger = new SurfaceFlinger(device);
|
||||
|
||||
InitializeAudioRenderer();
|
||||
InitializeAudioRenderer(TickSource);
|
||||
InitializeServices();
|
||||
}
|
||||
|
||||
private void InitializeAudioRenderer()
|
||||
private void InitializeAudioRenderer(ITickSource tickSource)
|
||||
{
|
||||
AudioManager = new AudioManager();
|
||||
AudioOutputManager = new AudioOutputManager();
|
||||
AudioInputManager = new AudioInputManager();
|
||||
AudioRendererManager = new AudioRendererManager();
|
||||
AudioRendererManager = new AudioRendererManager(tickSource);
|
||||
AudioRendererManager.SetVolume(Device.Configuration.AudioVolume);
|
||||
AudioDeviceSessionRegistry = new VirtualDeviceSessionRegistry();
|
||||
|
||||
@ -492,12 +501,12 @@ namespace Ryujinx.HLE.HOS
|
||||
if (pause && !IsPaused)
|
||||
{
|
||||
Device.AudioDeviceDriver.GetPauseEvent().Reset();
|
||||
ARMeilleure.State.ExecutionContext.SuspendCounter();
|
||||
TickSource.Suspend();
|
||||
}
|
||||
else if (!pause && IsPaused)
|
||||
{
|
||||
Device.AudioDeviceDriver.GetPauseEvent().Set();
|
||||
ARMeilleure.State.ExecutionContext.ResumeCounter();
|
||||
TickSource.Resume();
|
||||
}
|
||||
}
|
||||
IsPaused = pause;
|
||||
|
@ -12,5 +12,7 @@ namespace Ryujinx.HLE.HOS.Kernel
|
||||
public const ulong UserSlabHeapBase = DramMemoryMap.SlabHeapBase;
|
||||
public const ulong UserSlabHeapItemSize = KPageTableBase.PageSize;
|
||||
public const ulong UserSlabHeapSize = 0x3de000;
|
||||
|
||||
public const ulong CounterFrequency = 19200000;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Ryujinx.HLE.HOS.Kernel.Common;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Kernel.Common;
|
||||
using Ryujinx.HLE.HOS.Kernel.Memory;
|
||||
using Ryujinx.HLE.HOS.Kernel.Process;
|
||||
using Ryujinx.HLE.HOS.Kernel.SupervisorCall;
|
||||
@ -23,6 +24,7 @@ namespace Ryujinx.HLE.HOS.Kernel
|
||||
|
||||
public Switch Device { get; }
|
||||
public MemoryBlock Memory { get; }
|
||||
public ITickSource TickSource { get; }
|
||||
public Syscall Syscall { get; }
|
||||
public SyscallHandler SyscallHandler { get; }
|
||||
|
||||
@ -52,11 +54,13 @@ namespace Ryujinx.HLE.HOS.Kernel
|
||||
private ulong _threadUid;
|
||||
|
||||
public KernelContext(
|
||||
ITickSource tickSource,
|
||||
Switch device,
|
||||
MemoryBlock memory,
|
||||
MemorySize memorySize,
|
||||
MemoryArrange memoryArrange)
|
||||
{
|
||||
TickSource = tickSource;
|
||||
Device = device;
|
||||
Memory = memory;
|
||||
|
||||
|
@ -115,7 +115,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
||||
|
||||
string GetReg(int x)
|
||||
{
|
||||
var v = x == 32 ? (ulong)thread.LastPc : context.GetX(x);
|
||||
var v = x == 32 ? context.Pc : context.GetX(x);
|
||||
if (!AnalyzePointer(out PointerInfo info, v, thread))
|
||||
{
|
||||
return $"0x{v:x16}";
|
||||
|
@ -1,4 +1,4 @@
|
||||
using ARMeilleure.State;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.Memory;
|
||||
using System;
|
||||
|
||||
@ -8,7 +8,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
||||
{
|
||||
IVirtualMemoryManager AddressSpace { get; }
|
||||
|
||||
void Execute(ExecutionContext context, ulong codeAddress);
|
||||
IExecutionContext CreateExecutionContext(ExceptionCallbacks exceptionCallbacks);
|
||||
void Execute(IExecutionContext context, ulong codeAddress);
|
||||
void InvalidateCacheRegion(ulong address, ulong size);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
using ARMeilleure.State;
|
||||
using Ryujinx.Common;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Cpu;
|
||||
@ -744,14 +743,16 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
||||
}
|
||||
}
|
||||
|
||||
public void SubscribeThreadEventHandlers(ARMeilleure.State.ExecutionContext context)
|
||||
public IExecutionContext CreateExecutionContext()
|
||||
{
|
||||
context.Interrupt += InterruptHandler;
|
||||
context.SupervisorCall += KernelContext.SyscallHandler.SvcCall;
|
||||
context.Undefined += UndefinedInstructionHandler;
|
||||
return Context?.CreateExecutionContext(new ExceptionCallbacks(
|
||||
InterruptHandler,
|
||||
null,
|
||||
KernelContext.SyscallHandler.SvcCall,
|
||||
UndefinedInstructionHandler));
|
||||
}
|
||||
|
||||
private void InterruptHandler(object sender, EventArgs e)
|
||||
private void InterruptHandler(IExecutionContext context)
|
||||
{
|
||||
KThread currentThread = KernelStatic.GetCurrentThread();
|
||||
|
||||
@ -1093,12 +1094,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
||||
return false;
|
||||
}
|
||||
|
||||
private void UndefinedInstructionHandler(object sender, InstUndefinedEventArgs e)
|
||||
private void UndefinedInstructionHandler(IExecutionContext context, ulong address, int opCode)
|
||||
{
|
||||
KernelStatic.GetCurrentThread().PrintGuestStackTrace();
|
||||
KernelStatic.GetCurrentThread()?.PrintGuestRegisterPrintout();
|
||||
|
||||
throw new UndefinedInstructionException(e.Address, e.OpCode);
|
||||
throw new UndefinedInstructionException(address, opCode);
|
||||
}
|
||||
|
||||
protected override void Destroy() => Context.Dispose();
|
||||
|
@ -1,4 +1,4 @@
|
||||
using ARMeilleure.State;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.Memory;
|
||||
using System;
|
||||
|
||||
@ -13,7 +13,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
||||
AddressSpace = asManager;
|
||||
}
|
||||
|
||||
public void Execute(ExecutionContext context, ulong codeAddress)
|
||||
public IExecutionContext CreateExecutionContext(ExceptionCallbacks exceptionCallbacks)
|
||||
{
|
||||
return new ProcessExecutionContext();
|
||||
}
|
||||
|
||||
public void Execute(IExecutionContext context, ulong codeAddress)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
44
Ryujinx.HLE/HOS/Kernel/Process/ProcessExecutionContext.cs
Normal file
44
Ryujinx.HLE/HOS/Kernel/Process/ProcessExecutionContext.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using ARMeilleure.State;
|
||||
using Ryujinx.Cpu;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Kernel.Process
|
||||
{
|
||||
class ProcessExecutionContext : IExecutionContext
|
||||
{
|
||||
public ulong Pc => 0UL;
|
||||
|
||||
public ulong CntfrqEl0 { get => 0; set { } }
|
||||
public ulong CntpctEl0 => 0UL;
|
||||
|
||||
public long TpidrEl0 { get => 0; set { } }
|
||||
public long TpidrroEl0 { get => 0; set { } }
|
||||
|
||||
public uint Pstate { get => 0; set { } }
|
||||
|
||||
public uint Fpcr { get => 0; set { } }
|
||||
public uint Fpsr { get => 0; set { } }
|
||||
|
||||
public bool IsAarch32 { get => false; set { } }
|
||||
|
||||
public bool Running { get; private set; } = true;
|
||||
|
||||
public ulong GetX(int index) => 0UL;
|
||||
public void SetX(int index, ulong value) { }
|
||||
|
||||
public V128 GetV(int index) => default;
|
||||
public void SetV(int index, V128 value) { }
|
||||
|
||||
public void RequestInterrupt()
|
||||
{
|
||||
}
|
||||
|
||||
public void StopRunning()
|
||||
{
|
||||
Running = false;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -1755,7 +1755,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
||||
|
||||
public ulong GetSystemTick()
|
||||
{
|
||||
return KernelStatic.GetCurrentThread().Context.CntpctEl0;
|
||||
return _context.TickSource.Counter;
|
||||
}
|
||||
|
||||
public void Break(ulong reason)
|
||||
|
@ -1,4 +1,4 @@
|
||||
using ARMeilleure.State;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using System;
|
||||
|
||||
@ -17,7 +17,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
||||
_syscall64 = new Syscall64(context.Syscall);
|
||||
}
|
||||
|
||||
public void SvcCall(object sender, InstExceptionEventArgs e)
|
||||
public void SvcCall(IExecutionContext context, ulong address, int id)
|
||||
{
|
||||
KThread currentThread = KernelStatic.GetCurrentThread();
|
||||
|
||||
@ -34,26 +34,24 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
||||
_context.CriticalSection.Leave();
|
||||
}
|
||||
|
||||
ExecutionContext context = (ExecutionContext)sender;
|
||||
|
||||
if (context.IsAarch32)
|
||||
{
|
||||
var svcFunc = SyscallTable.SvcTable32[e.Id];
|
||||
var svcFunc = SyscallTable.SvcTable32[id];
|
||||
|
||||
if (svcFunc == null)
|
||||
{
|
||||
throw new NotImplementedException($"SVC 0x{e.Id:X4} is not implemented.");
|
||||
throw new NotImplementedException($"SVC 0x{id:X4} is not implemented.");
|
||||
}
|
||||
|
||||
svcFunc(_syscall32, context);
|
||||
}
|
||||
else
|
||||
{
|
||||
var svcFunc = SyscallTable.SvcTable64[e.Id];
|
||||
var svcFunc = SyscallTable.SvcTable64[id];
|
||||
|
||||
if (svcFunc == null)
|
||||
{
|
||||
throw new NotImplementedException($"SVC 0x{e.Id:X4} is not implemented.");
|
||||
throw new NotImplementedException($"SVC 0x{id:X4} is not implemented.");
|
||||
}
|
||||
|
||||
svcFunc(_syscall64, context);
|
||||
|
@ -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)
|
||||
|
@ -23,7 +23,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
||||
|
||||
public Thread HostThread { get; private set; }
|
||||
|
||||
public ARMeilleure.State.ExecutionContext Context { get; private set; }
|
||||
public IExecutionContext Context { get; private set; }
|
||||
|
||||
public KThreadContext ThreadContext { get; private set; }
|
||||
|
||||
@ -115,9 +115,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
||||
|
||||
public bool WaitingInArbitration { get; set; }
|
||||
|
||||
public long LastPc { get; set; }
|
||||
|
||||
private object ActivityOperationLock = new object();
|
||||
private object _activityOperationLock;
|
||||
|
||||
public KThread(KernelContext context) : base(context)
|
||||
{
|
||||
@ -128,6 +126,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
||||
|
||||
_mutexWaiters = new LinkedList<KThread>();
|
||||
_pinnedWaiters = new LinkedList<KThread>();
|
||||
|
||||
_activityOperationLock = new object();
|
||||
}
|
||||
|
||||
public KernelResult Initialize(
|
||||
@ -192,7 +192,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
||||
|
||||
HostThread = new Thread(ThreadStart);
|
||||
|
||||
Context = CpuContext.CreateExecutionContext();
|
||||
Context = owner?.CreateExecutionContext() ?? new ProcessExecutionContext();
|
||||
|
||||
Context.IsAarch32 = !is64Bits;
|
||||
|
||||
@ -208,8 +208,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
||||
Context.SetX(13, (uint)stackTop);
|
||||
}
|
||||
|
||||
Context.CntfrqEl0 = 19200000;
|
||||
Context.Tpidr = (long)_tlsAddress;
|
||||
Context.TpidrroEl0 = (long)_tlsAddress;
|
||||
|
||||
ThreadUid = KernelContext.NewThreadUid();
|
||||
|
||||
@ -221,7 +220,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
||||
|
||||
if (owner != null)
|
||||
{
|
||||
owner.SubscribeThreadEventHandlers(Context);
|
||||
owner.AddThread(this);
|
||||
|
||||
if (owner.IsPaused)
|
||||
@ -538,7 +536,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
||||
|
||||
public KernelResult SetActivity(bool pause)
|
||||
{
|
||||
lock (ActivityOperationLock)
|
||||
lock (_activityOperationLock)
|
||||
{
|
||||
KernelResult result = KernelResult.Success;
|
||||
|
||||
@ -634,7 +632,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
||||
{
|
||||
context = default;
|
||||
|
||||
lock (ActivityOperationLock)
|
||||
lock (_activityOperationLock)
|
||||
{
|
||||
KernelContext.CriticalSection.Enter();
|
||||
|
||||
@ -656,7 +654,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
||||
return KernelResult.Success;
|
||||
}
|
||||
|
||||
private static uint GetPsr(ARMeilleure.State.ExecutionContext context)
|
||||
private static uint GetPsr(IExecutionContext context)
|
||||
{
|
||||
return context.Pstate & 0xFF0FFE20;
|
||||
}
|
||||
@ -683,9 +681,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
||||
context.Fp = Context.GetX(29);
|
||||
context.Lr = Context.GetX(30);
|
||||
context.Sp = Context.GetX(31);
|
||||
context.Pc = (ulong)LastPc;
|
||||
context.Pc = Context.Pc;
|
||||
context.Pstate = GetPsr(Context);
|
||||
context.Tpidr = (ulong)Context.Tpidr;
|
||||
context.Tpidr = (ulong)Context.TpidrroEl0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -699,9 +697,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
||||
context.FpuRegisters[i] = Context.GetV(i);
|
||||
}
|
||||
|
||||
context.Pc = (uint)LastPc;
|
||||
context.Pc = (uint)Context.Pc;
|
||||
context.Pstate = GetPsr(Context);
|
||||
context.Tpidr = (uint)Context.Tpidr;
|
||||
context.Tpidr = (uint)Context.TpidrroEl0;
|
||||
}
|
||||
|
||||
context.Fpcr = (uint)Context.Fpcr;
|
||||
@ -743,7 +741,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
||||
|
||||
public KernelResult SetCoreAndAffinityMask(int newCore, ulong newAffinityMask)
|
||||
{
|
||||
lock (ActivityOperationLock)
|
||||
lock (_activityOperationLock)
|
||||
{
|
||||
KernelContext.CriticalSection.Enter();
|
||||
|
||||
|
@ -101,7 +101,7 @@ namespace Ryujinx.HLE.HOS
|
||||
|
||||
KProcess process = new KProcess(context);
|
||||
|
||||
var processContextFactory = new ArmProcessContextFactory(context.Device.Gpu);
|
||||
var processContextFactory = new ArmProcessContextFactory(context.Device.System.CpuEngine, context.Device.Gpu);
|
||||
|
||||
result = process.InitializeKip(
|
||||
creationInfo,
|
||||
@ -264,7 +264,7 @@ namespace Ryujinx.HLE.HOS
|
||||
return false;
|
||||
}
|
||||
|
||||
var processContextFactory = new ArmProcessContextFactory(context.Device.Gpu);
|
||||
var processContextFactory = new ArmProcessContextFactory(context.Device.System.CpuEngine, context.Device.Gpu);
|
||||
|
||||
result = process.Initialize(
|
||||
creationInfo,
|
||||
|
@ -1,4 +1,5 @@
|
||||
using LibHac;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Services.Mii.Types;
|
||||
using System;
|
||||
|
||||
@ -27,7 +28,6 @@ namespace Ryujinx.HLE.HOS.Services.Mii
|
||||
|
||||
public DatabaseImpl()
|
||||
{
|
||||
_utilityImpl = new UtilityImpl();
|
||||
_miiDatabase = new MiiDatabaseManager();
|
||||
}
|
||||
|
||||
@ -148,12 +148,13 @@ namespace Ryujinx.HLE.HOS.Services.Mii
|
||||
return GetDefault(flag, ref count, elements);
|
||||
}
|
||||
|
||||
public ResultCode InitializeDatabase(HorizonClient horizonClient)
|
||||
public ResultCode InitializeDatabase(ITickSource tickSource, HorizonClient horizonClient)
|
||||
{
|
||||
_utilityImpl = new UtilityImpl(tickSource);
|
||||
_miiDatabase.InitializeDatabase(horizonClient);
|
||||
_miiDatabase.LoadFromFile(out _isBroken);
|
||||
|
||||
// Nintendo ignore any error code from before
|
||||
// Nintendo ignores any error code from before.
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Ryujinx.HLE.HOS.Services.Mii.Types;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Services.Mii.Types;
|
||||
using Ryujinx.HLE.HOS.Services.Time;
|
||||
using Ryujinx.HLE.HOS.Services.Time.Clock;
|
||||
using System;
|
||||
@ -12,12 +13,12 @@ namespace Ryujinx.HLE.HOS.Services.Mii
|
||||
private uint _z;
|
||||
private uint _w;
|
||||
|
||||
public UtilityImpl()
|
||||
public UtilityImpl(ITickSource tickSource)
|
||||
{
|
||||
_x = 123456789;
|
||||
_y = 362436069;
|
||||
|
||||
TimeSpanType time = TimeManager.Instance.TickBasedSteadyClock.GetCurrentRawTimePoint(null);
|
||||
TimeSpanType time = TimeManager.Instance.TickBasedSteadyClock.GetCurrentRawTimePoint(tickSource);
|
||||
|
||||
_w = (uint)(time.NanoSeconds & uint.MaxValue);
|
||||
_z = (uint)((time.NanoSeconds >> 32) & uint.MaxValue);
|
||||
|
@ -688,7 +688,10 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
|
||||
{
|
||||
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagMounted)
|
||||
{
|
||||
RegisterInfo registerInfo = VirtualAmiibo.GetRegisterInfo(context.Device.System.NfpDevices[i].AmiiboId, context.Device.System.AccountManager.LastOpenedUser.Name);
|
||||
RegisterInfo registerInfo = VirtualAmiibo.GetRegisterInfo(
|
||||
context.Device.System.TickSource,
|
||||
context.Device.System.NfpDevices[i].AmiiboId,
|
||||
context.Device.System.AccountManager.LastOpenedUser.Name);
|
||||
|
||||
context.Memory.Write(outputPosition, registerInfo);
|
||||
|
||||
@ -911,7 +914,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
|
||||
context.ResponseData.Write((uint)context.Device.System.NfpDevices[i].State);
|
||||
|
||||
return ResultCode.Success;
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Ryujinx.Common.Configuration;
|
||||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Services.Mii;
|
||||
using Ryujinx.HLE.HOS.Services.Mii.Types;
|
||||
using Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager;
|
||||
@ -63,11 +64,11 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
|
||||
};
|
||||
}
|
||||
|
||||
public static RegisterInfo GetRegisterInfo(string amiiboId, string nickname)
|
||||
public static RegisterInfo GetRegisterInfo(ITickSource tickSource, string amiiboId, string nickname)
|
||||
{
|
||||
VirtualAmiiboFile amiiboFile = LoadAmiiboFile(amiiboId);
|
||||
|
||||
UtilityImpl utilityImpl = new UtilityImpl();
|
||||
UtilityImpl utilityImpl = new UtilityImpl(tickSource);
|
||||
CharInfo charInfo = new CharInfo();
|
||||
|
||||
charInfo.SetFromStoreData(StoreData.BuildDefault(utilityImpl, 0));
|
||||
|
@ -6,7 +6,7 @@
|
||||
{
|
||||
BufferQueueCore core = new BufferQueueCore(device, pid);
|
||||
|
||||
producer = new BufferQueueProducer(core);
|
||||
producer = new BufferQueueProducer(core, device.System.TickSource);
|
||||
consumer = new BufferQueueConsumer(core);
|
||||
|
||||
return core;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.HLE.HOS.Kernel;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.HLE.HOS.Services.SurfaceFlinger.Types;
|
||||
using System;
|
||||
@ -241,7 +240,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||
{
|
||||
BufferSlot slot = Slots[item.Slot];
|
||||
|
||||
// TODO: Check this. On Android, this checks the "handle". I assume NvMapHandle is the handle, but it might not be.
|
||||
// TODO: Check this. On Android, this checks the "handle". I assume NvMapHandle is the handle, but it might not be.
|
||||
return !slot.GraphicBuffer.IsNull && slot.GraphicBuffer.Object.Buffer.Surfaces[0].NvMapHandle == item.GraphicBuffer.Object.Buffer.Surfaces[0].NvMapHandle;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.HLE.HOS.Services.Settings;
|
||||
using Ryujinx.HLE.HOS.Services.SurfaceFlinger.Types;
|
||||
@ -12,6 +13,8 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||
{
|
||||
public BufferQueueCore Core { get; }
|
||||
|
||||
private readonly ITickSource _tickSource;
|
||||
|
||||
private uint _stickyTransform;
|
||||
|
||||
private uint _nextCallbackTicket;
|
||||
@ -20,9 +23,10 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||
|
||||
private readonly object _callbackLock = new object();
|
||||
|
||||
public BufferQueueProducer(BufferQueueCore core)
|
||||
public BufferQueueProducer(BufferQueueCore core, ITickSource tickSource)
|
||||
{
|
||||
Core = core;
|
||||
_tickSource = tickSource;
|
||||
|
||||
_stickyTransform = 0;
|
||||
_callbackTicket = 0;
|
||||
@ -179,8 +183,8 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||
GraphicBuffer graphicBuffer = Core.Slots[slot].GraphicBuffer.Object;
|
||||
|
||||
if (Core.Slots[slot].GraphicBuffer.IsNull
|
||||
|| graphicBuffer.Width != width
|
||||
|| graphicBuffer.Height != height
|
||||
|| graphicBuffer.Width != width
|
||||
|| graphicBuffer.Height != height
|
||||
|| graphicBuffer.Format != format
|
||||
|| (graphicBuffer.Usage & usage) != usage)
|
||||
{
|
||||
@ -193,7 +197,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Error?.Print(LogClass.SurfaceFlinger,
|
||||
Logger.Error?.Print(LogClass.SurfaceFlinger,
|
||||
$"Preallocated buffer mismatch - slot {slot}\n" +
|
||||
$"available: Width = {graphicBuffer.Width} Height = {graphicBuffer.Height} Format = {graphicBuffer.Format} Usage = {graphicBuffer.Usage:x} " +
|
||||
$"requested: Width = {width} Height = {height} Format = {format} Usage = {usage:x}");
|
||||
@ -388,7 +392,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||
Core.Slots[slot].BufferState = BufferState.Queued;
|
||||
Core.FrameCounter++;
|
||||
Core.Slots[slot].FrameNumber = Core.FrameCounter;
|
||||
Core.Slots[slot].QueueTime = TimeSpanType.FromTimeSpan(ARMeilleure.State.ExecutionContext.ElapsedTime);
|
||||
Core.Slots[slot].QueueTime = TimeSpanType.FromTimeSpan(_tickSource.ElapsedTime);
|
||||
Core.Slots[slot].PresentationTime = TimeSpanType.Zero;
|
||||
|
||||
item.AcquireCalled = Core.Slots[slot].AcquireCalled;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.Cpu;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
{
|
||||
@ -11,14 +11,14 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
_standardNetworkClockSufficientAccuracy = new TimeSpanType(0);
|
||||
}
|
||||
|
||||
public bool IsStandardNetworkSystemClockAccuracySufficient(KThread thread)
|
||||
public bool IsStandardNetworkSystemClockAccuracySufficient(ITickSource tickSource)
|
||||
{
|
||||
SteadyClockCore steadyClockCore = GetSteadyClockCore();
|
||||
SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(thread);
|
||||
SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(tickSource);
|
||||
|
||||
bool isStandardNetworkClockSufficientAccuracy = false;
|
||||
|
||||
ResultCode result = GetClockContext(thread, out SystemClockContext context);
|
||||
ResultCode result = GetClockContext(tickSource, out SystemClockContext context);
|
||||
|
||||
if (result == ResultCode.Success && context.SteadyTimePoint.GetSpanBetween(currentTimePoint, out long outSpan) == ResultCode.Success)
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.Cpu;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
{
|
||||
@ -17,11 +17,11 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
_cachedRawTimePoint = TimeSpanType.Zero;
|
||||
}
|
||||
|
||||
public override SteadyClockTimePoint GetTimePoint(KThread thread)
|
||||
public override SteadyClockTimePoint GetTimePoint(ITickSource tickSource)
|
||||
{
|
||||
SteadyClockTimePoint result = new SteadyClockTimePoint
|
||||
{
|
||||
TimePoint = GetCurrentRawTimePoint(thread).ToSeconds(),
|
||||
TimePoint = GetCurrentRawTimePoint(tickSource).ToSeconds(),
|
||||
ClockSourceId = GetClockSourceId()
|
||||
};
|
||||
|
||||
@ -48,19 +48,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
_internalOffset = internalOffset;
|
||||
}
|
||||
|
||||
public override TimeSpanType GetCurrentRawTimePoint(KThread thread)
|
||||
public override TimeSpanType GetCurrentRawTimePoint(ITickSource tickSource)
|
||||
{
|
||||
TimeSpanType ticksTimeSpan;
|
||||
|
||||
// As this may be called before the guest code, we support passing a null thread to make this api usable.
|
||||
if (thread == null)
|
||||
{
|
||||
ticksTimeSpan = TimeSpanType.FromSeconds(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ticksTimeSpan = TimeSpanType.FromTicks(thread.Context.CntpctEl0, thread.Context.CntfrqEl0);
|
||||
}
|
||||
TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency);
|
||||
|
||||
TimeSpanType rawTimePoint = new TimeSpanType(_setupValue.NanoSeconds + ticksTimeSpan.NanoSeconds);
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
@ -26,15 +27,15 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override ResultCode GetClockContext(KThread thread, out SystemClockContext context)
|
||||
public override ResultCode GetClockContext(ITickSource tickSource, out SystemClockContext context)
|
||||
{
|
||||
ResultCode result = ApplyAutomaticCorrection(thread, false);
|
||||
ResultCode result = ApplyAutomaticCorrection(tickSource, false);
|
||||
|
||||
context = new SystemClockContext();
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
return _localSystemClockCore.GetClockContext(thread, out context);
|
||||
return _localSystemClockCore.GetClockContext(tickSource, out context);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -45,13 +46,13 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
return ResultCode.NotImplemented;
|
||||
}
|
||||
|
||||
private ResultCode ApplyAutomaticCorrection(KThread thread, bool autoCorrectionEnabled)
|
||||
private ResultCode ApplyAutomaticCorrection(ITickSource tickSource, bool autoCorrectionEnabled)
|
||||
{
|
||||
ResultCode result = ResultCode.Success;
|
||||
|
||||
if (_autoCorrectionEnabled != autoCorrectionEnabled && _networkSystemClockCore.IsClockSetup(thread))
|
||||
if (_autoCorrectionEnabled != autoCorrectionEnabled && _networkSystemClockCore.IsClockSetup(tickSource))
|
||||
{
|
||||
result = _networkSystemClockCore.GetClockContext(thread, out SystemClockContext context);
|
||||
result = _networkSystemClockCore.GetClockContext(tickSource, out SystemClockContext context);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
@ -67,9 +68,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
_autoCorrectionEvent = new KEvent(system.KernelContext);
|
||||
}
|
||||
|
||||
public ResultCode SetAutomaticCorrectionEnabled(KThread thread, bool autoCorrectionEnabled)
|
||||
public ResultCode SetAutomaticCorrectionEnabled(ITickSource tickSource, bool autoCorrectionEnabled)
|
||||
{
|
||||
ResultCode result = ApplyAutomaticCorrection(thread, autoCorrectionEnabled);
|
||||
ResultCode result = ApplyAutomaticCorrection(tickSource, autoCorrectionEnabled);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.Utilities;
|
||||
using System;
|
||||
|
||||
@ -63,21 +63,21 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
|
||||
public virtual void SetInternalOffset(TimeSpanType internalOffset) {}
|
||||
|
||||
public virtual SteadyClockTimePoint GetTimePoint(KThread thread)
|
||||
public virtual SteadyClockTimePoint GetTimePoint(ITickSource tickSource)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public virtual TimeSpanType GetCurrentRawTimePoint(KThread thread)
|
||||
public virtual TimeSpanType GetCurrentRawTimePoint(ITickSource tickSource)
|
||||
{
|
||||
SteadyClockTimePoint timePoint = GetTimePoint(thread);
|
||||
SteadyClockTimePoint timePoint = GetTimePoint(tickSource);
|
||||
|
||||
return TimeSpanType.FromSeconds(timePoint.TimePoint);
|
||||
}
|
||||
|
||||
public SteadyClockTimePoint GetCurrentTimePoint(KThread thread)
|
||||
public SteadyClockTimePoint GetCurrentTimePoint(ITickSource tickSource)
|
||||
{
|
||||
SteadyClockTimePoint result = GetTimePoint(thread);
|
||||
SteadyClockTimePoint result = GetTimePoint(tickSource);
|
||||
|
||||
result.TimePoint += GetTestOffset().ToSeconds();
|
||||
result.TimePoint += GetInternalOffset().ToSeconds();
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
@ -25,13 +25,13 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
return _steadyClockCore;
|
||||
}
|
||||
|
||||
public ResultCode GetCurrentTime(KThread thread, out long posixTime)
|
||||
public ResultCode GetCurrentTime(ITickSource tickSource, out long posixTime)
|
||||
{
|
||||
posixTime = 0;
|
||||
|
||||
SteadyClockTimePoint currentTimePoint = _steadyClockCore.GetCurrentTimePoint(thread);
|
||||
SteadyClockTimePoint currentTimePoint = _steadyClockCore.GetCurrentTimePoint(tickSource);
|
||||
|
||||
ResultCode result = GetClockContext(thread, out SystemClockContext clockContext);
|
||||
ResultCode result = GetClockContext(tickSource, out SystemClockContext clockContext);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
@ -48,9 +48,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
return result;
|
||||
}
|
||||
|
||||
public ResultCode SetCurrentTime(KThread thread, long posixTime)
|
||||
public ResultCode SetCurrentTime(ITickSource tickSource, long posixTime)
|
||||
{
|
||||
SteadyClockTimePoint currentTimePoint = _steadyClockCore.GetCurrentTimePoint(thread);
|
||||
SteadyClockTimePoint currentTimePoint = _steadyClockCore.GetCurrentTimePoint(tickSource);
|
||||
|
||||
SystemClockContext clockContext = new SystemClockContext()
|
||||
{
|
||||
@ -68,7 +68,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
return result;
|
||||
}
|
||||
|
||||
public virtual ResultCode GetClockContext(KThread thread, out SystemClockContext context)
|
||||
public virtual ResultCode GetClockContext(ITickSource tickSource, out SystemClockContext context)
|
||||
{
|
||||
context = _context;
|
||||
|
||||
@ -127,13 +127,13 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
public bool IsClockSetup(KThread thread)
|
||||
public bool IsClockSetup(ITickSource tickSource)
|
||||
{
|
||||
ResultCode result = GetClockContext(thread, out SystemClockContext context);
|
||||
ResultCode result = GetClockContext(tickSource, out SystemClockContext context);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
SteadyClockTimePoint steadyClockTimePoint = _steadyClockCore.GetCurrentTimePoint(thread);
|
||||
SteadyClockTimePoint steadyClockTimePoint = _steadyClockCore.GetCurrentTimePoint(tickSource);
|
||||
|
||||
return steadyClockTimePoint.ClockSourceId == context.SteadyTimePoint.ClockSourceId;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.Cpu;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
{
|
||||
@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
{
|
||||
public TickBasedSteadyClockCore() {}
|
||||
|
||||
public override SteadyClockTimePoint GetTimePoint(KThread thread)
|
||||
public override SteadyClockTimePoint GetTimePoint(ITickSource tickSource)
|
||||
{
|
||||
SteadyClockTimePoint result = new SteadyClockTimePoint
|
||||
{
|
||||
@ -14,17 +14,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
ClockSourceId = GetClockSourceId()
|
||||
};
|
||||
|
||||
TimeSpanType ticksTimeSpan;
|
||||
|
||||
// As this may be called before the guest code, we support passing a null thread to make this api usable.
|
||||
if (thread == null)
|
||||
{
|
||||
ticksTimeSpan = TimeSpanType.FromSeconds(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ticksTimeSpan = TimeSpanType.FromTicks(thread.Context.CntpctEl0, thread.Context.CntfrqEl0);
|
||||
}
|
||||
TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency);
|
||||
|
||||
result.TimePoint = ticksTimeSpan.ToSeconds();
|
||||
|
||||
|
@ -2,7 +2,6 @@ using Ryujinx.Common;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Ipc;
|
||||
using Ryujinx.HLE.HOS.Kernel.Common;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.HLE.HOS.Services.Time.Clock;
|
||||
using Ryujinx.HLE.HOS.Services.Time.StaticService;
|
||||
using Ryujinx.HLE.HOS.Services.Time.TimeZone;
|
||||
@ -163,13 +162,15 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||
|
||||
bool autoCorrectionEnabled = context.RequestData.ReadBoolean();
|
||||
|
||||
ResultCode result = userClock.SetAutomaticCorrectionEnabled(context.Thread, autoCorrectionEnabled);
|
||||
ITickSource tickSource = context.Device.System.TickSource;
|
||||
|
||||
ResultCode result = userClock.SetAutomaticCorrectionEnabled(tickSource, autoCorrectionEnabled);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
_timeManager.SharedMemory.SetAutomaticCorrectionEnabled(autoCorrectionEnabled);
|
||||
|
||||
SteadyClockTimePoint currentTimePoint = userClock.GetSteadyClockCore().GetCurrentTimePoint(context.Thread);
|
||||
SteadyClockTimePoint currentTimePoint = userClock.GetSteadyClockCore().GetCurrentTimePoint(tickSource);
|
||||
|
||||
userClock.SetAutomaticCorrectionUpdatedTime(currentTimePoint);
|
||||
userClock.SignalAutomaticCorrectionEvent();
|
||||
@ -190,7 +191,9 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||
// IsStandardNetworkSystemClockAccuracySufficient() -> bool
|
||||
public ResultCode IsStandardNetworkSystemClockAccuracySufficient(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write(_timeManager.StandardNetworkSystemClock.IsStandardNetworkSystemClockAccuracySufficient(context.Thread));
|
||||
ITickSource tickSource = context.Device.System.TickSource;
|
||||
|
||||
context.ResponseData.Write(_timeManager.StandardNetworkSystemClock.IsStandardNetworkSystemClockAccuracySufficient(tickSource));
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
@ -222,14 +225,16 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||
return ResultCode.UninitializedClock;
|
||||
}
|
||||
|
||||
ITickSource tickSource = context.Device.System.TickSource;
|
||||
|
||||
SystemClockContext otherContext = context.RequestData.ReadStruct<SystemClockContext>();
|
||||
SteadyClockTimePoint currentTimePoint = steadyClock.GetCurrentTimePoint(context.Thread);
|
||||
SteadyClockTimePoint currentTimePoint = steadyClock.GetCurrentTimePoint(tickSource);
|
||||
|
||||
ResultCode result = ResultCode.TimeMismatch;
|
||||
|
||||
if (currentTimePoint.ClockSourceId == otherContext.SteadyTimePoint.ClockSourceId)
|
||||
{
|
||||
TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(context.Thread.Context.CntpctEl0, context.Thread.Context.CntfrqEl0);
|
||||
TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency);
|
||||
long baseTimePoint = otherContext.Offset + currentTimePoint.TimePoint - ticksTimeSpan.ToSeconds();
|
||||
|
||||
context.ResponseData.Write(baseTimePoint);
|
||||
@ -248,15 +253,17 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||
|
||||
context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize((uint)Marshal.SizeOf<ClockSnapshot>());
|
||||
|
||||
ResultCode result = _timeManager.StandardUserSystemClock.GetClockContext(context.Thread, out SystemClockContext userContext);
|
||||
ITickSource tickSource = context.Device.System.TickSource;
|
||||
|
||||
ResultCode result = _timeManager.StandardUserSystemClock.GetClockContext(tickSource, out SystemClockContext userContext);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
result = _timeManager.StandardNetworkSystemClock.GetClockContext(context.Thread, out SystemClockContext networkContext);
|
||||
result = _timeManager.StandardNetworkSystemClock.GetClockContext(tickSource, out SystemClockContext networkContext);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
result = GetClockSnapshotFromSystemClockContextInternal(context.Thread, userContext, networkContext, type, out ClockSnapshot clockSnapshot);
|
||||
result = GetClockSnapshotFromSystemClockContextInternal(tickSource, userContext, networkContext, type, out ClockSnapshot clockSnapshot);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
@ -281,7 +288,9 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||
SystemClockContext userContext = context.RequestData.ReadStruct<SystemClockContext>();
|
||||
SystemClockContext networkContext = context.RequestData.ReadStruct<SystemClockContext>();
|
||||
|
||||
ResultCode result = GetClockSnapshotFromSystemClockContextInternal(context.Thread, userContext, networkContext, type, out ClockSnapshot clockSnapshot);
|
||||
ITickSource tickSource = context.Device.System.TickSource;
|
||||
|
||||
ResultCode result = GetClockSnapshotFromSystemClockContextInternal(tickSource, userContext, networkContext, type, out ClockSnapshot clockSnapshot);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
@ -344,12 +353,12 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
private ResultCode GetClockSnapshotFromSystemClockContextInternal(KThread thread, SystemClockContext userContext, SystemClockContext networkContext, byte type, out ClockSnapshot clockSnapshot)
|
||||
private ResultCode GetClockSnapshotFromSystemClockContextInternal(ITickSource tickSource, SystemClockContext userContext, SystemClockContext networkContext, byte type, out ClockSnapshot clockSnapshot)
|
||||
{
|
||||
clockSnapshot = new ClockSnapshot();
|
||||
|
||||
SteadyClockCore steadyClockCore = _timeManager.StandardSteadyClock;
|
||||
SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(thread);
|
||||
SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(tickSource);
|
||||
|
||||
clockSnapshot.IsAutomaticCorrectionEnabled = _timeManager.StandardUserSystemClock.IsAutomaticCorrectionEnabled();
|
||||
clockSnapshot.UserContext = userContext;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Ryujinx.Common;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.Exceptions;
|
||||
using Ryujinx.HLE.HOS.Ipc;
|
||||
using Ryujinx.HLE.HOS.Kernel.Common;
|
||||
@ -6,7 +7,6 @@ using Ryujinx.HLE.HOS.Services.Time.Clock;
|
||||
using Ryujinx.HLE.Utilities;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Time
|
||||
{
|
||||
@ -68,7 +68,9 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||
TimeSpanType testOffset = context.RequestData.ReadStruct<TimeSpanType>();
|
||||
bool isRtcResetDetected = context.RequestData.ReadBoolean();
|
||||
|
||||
_timeManager.SetupStandardSteadyClock(context.Thread, clockSourceId, setupValue, internalOffset, testOffset, isRtcResetDetected);
|
||||
ITickSource tickSource = context.Device.System.TickSource;
|
||||
|
||||
_timeManager.SetupStandardSteadyClock(tickSource, clockSourceId, setupValue, internalOffset, testOffset, isRtcResetDetected);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
@ -80,7 +82,9 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||
SystemClockContext clockContext = context.RequestData.ReadStruct<SystemClockContext>();
|
||||
long posixTime = context.RequestData.ReadInt64();
|
||||
|
||||
_timeManager.SetupStandardLocalSystemClock(context.Thread, clockContext, posixTime);
|
||||
ITickSource tickSource = context.Device.System.TickSource;
|
||||
|
||||
_timeManager.SetupStandardLocalSystemClock(tickSource, clockContext, posixTime);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
@ -107,7 +111,9 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||
|
||||
SteadyClockTimePoint steadyClockTimePoint = context.RequestData.ReadStruct<SteadyClockTimePoint>();
|
||||
|
||||
_timeManager.SetupStandardUserSystemClock(context.Thread, isAutomaticCorrectionEnabled, steadyClockTimePoint);
|
||||
ITickSource tickSource = context.Device.System.TickSource;
|
||||
|
||||
_timeManager.SetupStandardUserSystemClock(tickSource, isAutomaticCorrectionEnabled, steadyClockTimePoint);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
@ -191,7 +197,9 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||
{
|
||||
TimeSpanType rtcOffset = context.RequestData.ReadStruct<TimeSpanType>();
|
||||
|
||||
_timeManager.SetStandardSteadyClockRtcOffset(context.Thread, rtcOffset);
|
||||
ITickSource tickSource = context.Device.System.TickSource;
|
||||
|
||||
_timeManager.SetStandardSteadyClockRtcOffset(tickSource, rtcOffset);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Ryujinx.Common;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Services.Time.Clock;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Time.StaticService
|
||||
@ -25,7 +26,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService
|
||||
return ResultCode.UninitializedClock;
|
||||
}
|
||||
|
||||
SteadyClockTimePoint currentTimePoint = _steadyClock.GetCurrentTimePoint(context.Thread);
|
||||
ITickSource tickSource = context.Device.System.TickSource;
|
||||
|
||||
SteadyClockTimePoint currentTimePoint = _steadyClock.GetCurrentTimePoint(tickSource);
|
||||
|
||||
context.ResponseData.WriteStruct(currentTimePoint);
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Ryujinx.Common;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Ipc;
|
||||
using Ryujinx.HLE.HOS.Kernel.Common;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
@ -31,7 +32,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService
|
||||
return ResultCode.UninitializedClock;
|
||||
}
|
||||
|
||||
ResultCode result = _clockCore.GetCurrentTime(context.Thread, out long posixTime);
|
||||
ITickSource tickSource = context.Device.System.TickSource;
|
||||
|
||||
ResultCode result = _clockCore.GetCurrentTime(tickSource, out long posixTime);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
@ -57,7 +60,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService
|
||||
|
||||
long posixTime = context.RequestData.ReadInt64();
|
||||
|
||||
return _clockCore.SetCurrentTime(context.Thread, posixTime);
|
||||
ITickSource tickSource = context.Device.System.TickSource;
|
||||
|
||||
return _clockCore.SetCurrentTime(tickSource, posixTime);
|
||||
}
|
||||
|
||||
[CommandHipc(2)]
|
||||
@ -69,7 +74,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService
|
||||
return ResultCode.UninitializedClock;
|
||||
}
|
||||
|
||||
ResultCode result = _clockCore.GetClockContext(context.Thread, out SystemClockContext clockContext);
|
||||
ITickSource tickSource = context.Device.System.TickSource;
|
||||
|
||||
ResultCode result = _clockCore.GetClockContext(tickSource, out SystemClockContext clockContext);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
|
@ -7,7 +7,6 @@ using Ryujinx.HLE.Utilities;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Time.StaticService
|
||||
{
|
||||
@ -44,7 +43,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService
|
||||
{
|
||||
return ResultCode.PermissionDenied;
|
||||
}
|
||||
|
||||
|
||||
return ResultCode.NotImplemented;
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.Exceptions;
|
||||
using Ryujinx.HLE.HOS.Kernel.Memory;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.HLE.HOS.Services.Time.Clock;
|
||||
using Ryujinx.HLE.HOS.Services.Time.TimeZone;
|
||||
using Ryujinx.HLE.Utilities;
|
||||
using System.IO;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Time
|
||||
{
|
||||
@ -68,14 +67,13 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||
TimeZone.Initialize(this, device);
|
||||
}
|
||||
|
||||
|
||||
public void SetupStandardSteadyClock(KThread thread, UInt128 clockSourceId, TimeSpanType setupValue, TimeSpanType internalOffset, TimeSpanType testOffset, bool isRtcResetDetected)
|
||||
public void SetupStandardSteadyClock(ITickSource tickSource, UInt128 clockSourceId, TimeSpanType setupValue, TimeSpanType internalOffset, TimeSpanType testOffset, bool isRtcResetDetected)
|
||||
{
|
||||
SetupInternalStandardSteadyClock(clockSourceId, setupValue, internalOffset, testOffset, isRtcResetDetected);
|
||||
|
||||
TimeSpanType currentTimePoint = StandardSteadyClock.GetCurrentRawTimePoint(thread);
|
||||
TimeSpanType currentTimePoint = StandardSteadyClock.GetCurrentRawTimePoint(tickSource);
|
||||
|
||||
SharedMemory.SetupStandardSteadyClock(thread, clockSourceId, currentTimePoint);
|
||||
SharedMemory.SetupStandardSteadyClock(tickSource, clockSourceId, currentTimePoint);
|
||||
|
||||
// TODO: propagate IPC late binding of "time:s" and "time:p"
|
||||
}
|
||||
@ -97,18 +95,18 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||
// TODO: propagate IPC late binding of "time:s" and "time:p"
|
||||
}
|
||||
|
||||
public void SetupStandardLocalSystemClock(KThread thread, SystemClockContext clockContext, long posixTime)
|
||||
public void SetupStandardLocalSystemClock(ITickSource tickSource, SystemClockContext clockContext, long posixTime)
|
||||
{
|
||||
StandardLocalSystemClock.SetUpdateCallbackInstance(LocalClockContextWriter);
|
||||
|
||||
SteadyClockTimePoint currentTimePoint = StandardLocalSystemClock.GetSteadyClockCore().GetCurrentTimePoint(thread);
|
||||
SteadyClockTimePoint currentTimePoint = StandardLocalSystemClock.GetSteadyClockCore().GetCurrentTimePoint(tickSource);
|
||||
if (currentTimePoint.ClockSourceId == clockContext.SteadyTimePoint.ClockSourceId)
|
||||
{
|
||||
StandardLocalSystemClock.SetSystemClockContext(clockContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (StandardLocalSystemClock.SetCurrentTime(thread, posixTime) != ResultCode.Success)
|
||||
if (StandardLocalSystemClock.SetCurrentTime(tickSource, posixTime) != ResultCode.Success)
|
||||
{
|
||||
throw new InternalServiceException("Cannot set current local time");
|
||||
}
|
||||
@ -157,9 +155,9 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||
// TODO: propagate IPC late binding of "time:s" and "time:p"
|
||||
}
|
||||
|
||||
public void SetupStandardUserSystemClock(KThread thread, bool isAutomaticCorrectionEnabled, SteadyClockTimePoint steadyClockTimePoint)
|
||||
public void SetupStandardUserSystemClock(ITickSource tickSource, bool isAutomaticCorrectionEnabled, SteadyClockTimePoint steadyClockTimePoint)
|
||||
{
|
||||
if (StandardUserSystemClock.SetAutomaticCorrectionEnabled(thread, isAutomaticCorrectionEnabled) != ResultCode.Success)
|
||||
if (StandardUserSystemClock.SetAutomaticCorrectionEnabled(tickSource, isAutomaticCorrectionEnabled) != ResultCode.Success)
|
||||
{
|
||||
throw new InternalServiceException("Cannot set automatic user time correction state");
|
||||
}
|
||||
@ -172,13 +170,13 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||
// TODO: propagate IPC late binding of "time:s" and "time:p"
|
||||
}
|
||||
|
||||
public void SetStandardSteadyClockRtcOffset(KThread thread, TimeSpanType rtcOffset)
|
||||
public void SetStandardSteadyClockRtcOffset(ITickSource tickSource, TimeSpanType rtcOffset)
|
||||
{
|
||||
StandardSteadyClock.SetSetupValue(rtcOffset);
|
||||
|
||||
TimeSpanType currentTimePoint = StandardSteadyClock.GetCurrentRawTimePoint(thread);
|
||||
TimeSpanType currentTimePoint = StandardSteadyClock.GetCurrentRawTimePoint(tickSource);
|
||||
|
||||
SharedMemory.SetSteadyClockRawTimePoint(thread, currentTimePoint);
|
||||
SharedMemory.SetSteadyClockRawTimePoint(tickSource, currentTimePoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Kernel.Memory;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.HLE.HOS.Services.Time.Clock;
|
||||
using Ryujinx.HLE.HOS.Services.Time.Types;
|
||||
using Ryujinx.HLE.Utilities;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Time
|
||||
{
|
||||
@ -38,19 +37,9 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||
return _sharedMemory;
|
||||
}
|
||||
|
||||
public void SetupStandardSteadyClock(KThread thread, UInt128 clockSourceId, TimeSpanType currentTimePoint)
|
||||
public void SetupStandardSteadyClock(ITickSource tickSource, UInt128 clockSourceId, TimeSpanType currentTimePoint)
|
||||
{
|
||||
TimeSpanType ticksTimeSpan;
|
||||
|
||||
// As this may be called before the guest code, we support passing a null thread to make this api usable.
|
||||
if (thread == null)
|
||||
{
|
||||
ticksTimeSpan = TimeSpanType.FromSeconds(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ticksTimeSpan = TimeSpanType.FromTicks(thread.Context.CntpctEl0, thread.Context.CntfrqEl0);
|
||||
}
|
||||
TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency);
|
||||
|
||||
SteadyClockContext context = new SteadyClockContext
|
||||
{
|
||||
@ -67,10 +56,10 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||
WriteObjectToSharedMemory(AutomaticCorrectionEnabledOffset, 0, Convert.ToByte(isAutomaticCorrectionEnabled));
|
||||
}
|
||||
|
||||
public void SetSteadyClockRawTimePoint(KThread thread, TimeSpanType currentTimePoint)
|
||||
public void SetSteadyClockRawTimePoint(ITickSource tickSource, TimeSpanType currentTimePoint)
|
||||
{
|
||||
SteadyClockContext context = ReadObjectFromSharedMemory<SteadyClockContext>(SteadyClockContextOffset, 4);
|
||||
TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(thread.Context.CntpctEl0, thread.Context.CntfrqEl0);
|
||||
TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency);
|
||||
|
||||
context.InternalOffset = (ulong)(currentTimePoint.NanoSeconds - ticksTimeSpan.NanoSeconds);
|
||||
|
||||
|
@ -7,6 +7,7 @@ using LibHac.Ncm;
|
||||
using LibHac.Tools.FsSystem;
|
||||
using LibHac.Tools.FsSystem.NcaUtils;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.Exceptions;
|
||||
using Ryujinx.HLE.FileSystem;
|
||||
using Ryujinx.HLE.HOS.Services.Time.Clock;
|
||||
@ -63,7 +64,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
|
||||
{
|
||||
InitializeInstance(device.FileSystem, device.System.ContentManager, device.System.FsIntegrityCheckLevel);
|
||||
|
||||
SteadyClockTimePoint timeZoneUpdatedTimePoint = timeManager.StandardSteadyClock.GetCurrentTimePoint(null);
|
||||
ITickSource tickSource = device.System.TickSource;
|
||||
|
||||
SteadyClockTimePoint timeZoneUpdatedTimePoint = timeManager.StandardSteadyClock.GetCurrentTimePoint(tickSource);
|
||||
|
||||
string deviceLocationName = SanityCheckDeviceLocationName(device.Configuration.TimeZone);
|
||||
|
||||
|
Reference in New Issue
Block a user