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:
parent
9827dc35e1
commit
0c87bf9ea4
64 changed files with 877 additions and 322 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue