aboutsummaryrefslogtreecommitdiff
path: root/ChocolArm64
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2018-03-13 21:24:17 -0300
committergdkchan <gab.dark.100@gmail.com>2018-03-13 21:24:32 -0300
commit2ed24af756f60391dade07ac371a2cf630628eb3 (patch)
tree12aae4ef51461f908ca32384b8a8172df1025fcc /ChocolArm64
parent4d90d60119992556b28cde119e9a94b8ac4aebf8 (diff)
Add pl:u stub, use higher precision on CNTPCT_EL0 register tick count
Diffstat (limited to 'ChocolArm64')
-rw-r--r--ChocolArm64/Instruction/AInstEmitSystem.cs1
-rw-r--r--ChocolArm64/State/AThreadState.cs26
2 files changed, 24 insertions, 3 deletions
diff --git a/ChocolArm64/Instruction/AInstEmitSystem.cs b/ChocolArm64/Instruction/AInstEmitSystem.cs
index 42a62009..1c5d0263 100644
--- a/ChocolArm64/Instruction/AInstEmitSystem.cs
+++ b/ChocolArm64/Instruction/AInstEmitSystem.cs
@@ -30,6 +30,7 @@ namespace ChocolArm64.Instruction
case 0b11_011_0100_0100_001: PropName = nameof(AThreadState.Fpsr); break;
case 0b11_011_1101_0000_010: PropName = nameof(AThreadState.TpidrEl0); break;
case 0b11_011_1101_0000_011: PropName = nameof(AThreadState.Tpidr); break;
+ case 0b11_011_1110_0000_000: PropName = nameof(AThreadState.CntfrqEl0); break;
case 0b11_011_1110_0000_001: PropName = nameof(AThreadState.CntpctEl0); break;
default: throw new NotImplementedException($"Unknown MRS at {Op.Position:x16}");
diff --git a/ChocolArm64/State/AThreadState.cs b/ChocolArm64/State/AThreadState.cs
index ec8621b8..6f3f62f6 100644
--- a/ChocolArm64/State/AThreadState.cs
+++ b/ChocolArm64/State/AThreadState.cs
@@ -1,5 +1,6 @@
using ChocolArm64.Events;
using System;
+using System.Diagnostics;
namespace ChocolArm64.State
{
@@ -40,15 +41,34 @@ namespace ChocolArm64.State
public uint CtrEl0 => 0x8444c004;
public uint DczidEl0 => 0x00000004;
- private const ulong TicksPerS = 19_200_000;
- private const ulong TicksPerMS = TicksPerS / 1_000;
+ public ulong CntfrqEl0 { get; set; }
+ public ulong CntpctEl0
+ {
+ get
+ {
+ double Ticks = TickCounter.ElapsedTicks * HostTickFreq;
- public ulong CntpctEl0 => (ulong)Environment.TickCount * TicksPerMS;
+ return (ulong)(Ticks * CntfrqEl0);
+ }
+ }
public event EventHandler<AInstExceptionEventArgs> Break;
public event EventHandler<AInstExceptionEventArgs> SvcCall;
public event EventHandler<AInstUndefinedEventArgs> Undefined;
+ private static Stopwatch TickCounter;
+
+ private static double HostTickFreq;
+
+ static AThreadState()
+ {
+ HostTickFreq = 1.0 / Stopwatch.Frequency;
+
+ TickCounter = new Stopwatch();
+
+ TickCounter.Start();
+ }
+
internal void OnBreak(int Imm)
{
Break?.Invoke(this, new AInstExceptionEventArgs(Imm));