aboutsummaryrefslogtreecommitdiff
path: root/ARMeilleure
diff options
context:
space:
mode:
Diffstat (limited to 'ARMeilleure')
-rw-r--r--ARMeilleure/Instructions/InstEmitSystem.cs14
-rw-r--r--ARMeilleure/Instructions/NativeInterface.cs6
-rw-r--r--ARMeilleure/State/ExceptionCallback.cs5
-rw-r--r--ARMeilleure/State/ExecutionContext.cs82
-rw-r--r--ARMeilleure/State/ICounter.cs18
-rw-r--r--ARMeilleure/State/InstExceptionEventArgs.cs16
-rw-r--r--ARMeilleure/State/InstUndefinedEventArgs.cs16
-rw-r--r--ARMeilleure/State/NativeContext.cs6
-rw-r--r--ARMeilleure/Translation/Delegates.cs2
-rw-r--r--ARMeilleure/Translation/PTC/Ptc.cs2
10 files changed, 72 insertions, 95 deletions
diff --git a/ARMeilleure/Instructions/InstEmitSystem.cs b/ARMeilleure/Instructions/InstEmitSystem.cs
index 499f1648..50dab07d 100644
--- a/ARMeilleure/Instructions/InstEmitSystem.cs
+++ b/ARMeilleure/Instructions/InstEmitSystem.cs
@@ -33,13 +33,13 @@ namespace ARMeilleure.Instructions
switch (GetPackedId(op))
{
- case 0b11_011_0000_0000_001: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetCtrEl0)); break;
- case 0b11_011_0000_0000_111: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetDczidEl0)); break;
- case 0b11_011_0100_0010_000: EmitGetNzcv(context); return;
- case 0b11_011_0100_0100_000: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetFpcr)); break;
- case 0b11_011_0100_0100_001: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetFpsr)); break;
- case 0b11_011_1101_0000_010: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetTpidrEl0)); break;
- case 0b11_011_1101_0000_011: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetTpidr)); break;
+ case 0b11_011_0000_0000_001: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetCtrEl0)); break;
+ case 0b11_011_0000_0000_111: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetDczidEl0)); break;
+ case 0b11_011_0100_0010_000: EmitGetNzcv(context); return;
+ case 0b11_011_0100_0100_000: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetFpcr)); break;
+ case 0b11_011_0100_0100_001: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetFpsr)); break;
+ case 0b11_011_1101_0000_010: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetTpidrEl0)); break;
+ case 0b11_011_1101_0000_011: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetTpidrroEl0)); break;
case 0b11_011_1110_0000_000: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetCntfrqEl0)); break;
case 0b11_011_1110_0000_001: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetCntpctEl0)); break;
case 0b11_011_1110_0000_010: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetCntvctEl0)); break;
diff --git a/ARMeilleure/Instructions/NativeInterface.cs b/ARMeilleure/Instructions/NativeInterface.cs
index 0b76f681..eebb824e 100644
--- a/ARMeilleure/Instructions/NativeInterface.cs
+++ b/ARMeilleure/Instructions/NativeInterface.cs
@@ -107,14 +107,14 @@ namespace ARMeilleure.Instructions
return (uint)GetContext().TpidrEl0;
}
- public static ulong GetTpidr()
+ public static ulong GetTpidrroEl0()
{
- return (ulong)GetContext().Tpidr;
+ return (ulong)GetContext().TpidrroEl0;
}
public static uint GetTpidr32()
{
- return (uint)GetContext().Tpidr;
+ return (uint)GetContext().TpidrroEl0;
}
public static ulong GetCntfrqEl0()
diff --git a/ARMeilleure/State/ExceptionCallback.cs b/ARMeilleure/State/ExceptionCallback.cs
new file mode 100644
index 00000000..38d6eef7
--- /dev/null
+++ b/ARMeilleure/State/ExceptionCallback.cs
@@ -0,0 +1,5 @@
+namespace ARMeilleure.State
+{
+ public delegate void ExceptionCallbackNoArgs(ExecutionContext context);
+ public delegate void ExceptionCallback(ExecutionContext context, ulong address, int id);
+} \ No newline at end of file
diff --git a/ARMeilleure/State/ExecutionContext.cs b/ARMeilleure/State/ExecutionContext.cs
index 8309864f..c73ca197 100644
--- a/ARMeilleure/State/ExecutionContext.cs
+++ b/ARMeilleure/State/ExecutionContext.cs
@@ -1,6 +1,5 @@
using ARMeilleure.Memory;
using System;
-using System.Diagnostics;
namespace ARMeilleure.State
{
@@ -14,34 +13,22 @@ namespace ARMeilleure.State
private bool _interrupted;
- private static Stopwatch _tickCounter;
+ private readonly ICounter _counter;
- private static double _hostTickFreq;
+ public ulong Pc => _nativeContext.GetPc();
- public uint CtrEl0 => 0x8444c004;
+ public uint CtrEl0 => 0x8444c004;
public uint DczidEl0 => 0x00000004;
- public ulong CntfrqEl0 { get; set; }
- public ulong CntpctEl0
- {
- get
- {
- double ticks = _tickCounter.ElapsedTicks * _hostTickFreq;
-
- return (ulong)(ticks * CntfrqEl0);
- }
- }
+ public ulong CntfrqEl0 => _counter.Frequency;
+ public ulong CntpctEl0 => _counter.Counter;
// CNTVCT_EL0 = CNTPCT_EL0 - CNTVOFF_EL2
// Since EL2 isn't implemented, CNTVOFF_EL2 = 0
public ulong CntvctEl0 => CntpctEl0;
- public static TimeSpan ElapsedTime => _tickCounter.Elapsed;
- public static long ElapsedTicks => _tickCounter.ElapsedTicks;
- public static double TickFrequency => _hostTickFreq;
-
public long TpidrEl0 { get; set; }
- public long Tpidr { get; set; }
+ public long TpidrroEl0 { get; set; }
public uint Pstate
{
@@ -78,35 +65,38 @@ namespace ARMeilleure.State
private set => _nativeContext.SetRunning(value);
}
- public event EventHandler<EventArgs> Interrupt;
- public event EventHandler<InstExceptionEventArgs> Break;
- public event EventHandler<InstExceptionEventArgs> SupervisorCall;
- public event EventHandler<InstUndefinedEventArgs> Undefined;
-
- static ExecutionContext()
- {
- _hostTickFreq = 1.0 / Stopwatch.Frequency;
-
- _tickCounter = new Stopwatch();
- _tickCounter.Start();
- }
-
- public ExecutionContext(IJitMemoryAllocator allocator)
+ private readonly ExceptionCallbackNoArgs _interruptCallback;
+ private readonly ExceptionCallback _breakCallback;
+ private readonly ExceptionCallback _supervisorCallback;
+ private readonly ExceptionCallback _undefinedCallback;
+
+ public ExecutionContext(
+ IJitMemoryAllocator allocator,
+ ICounter counter,
+ ExceptionCallbackNoArgs interruptCallback = null,
+ ExceptionCallback breakCallback = null,
+ ExceptionCallback supervisorCallback = null,
+ ExceptionCallback undefinedCallback = null)
{
_nativeContext = new NativeContext(allocator);
+ _counter = counter;
+ _interruptCallback = interruptCallback;
+ _breakCallback = breakCallback;
+ _supervisorCallback = supervisorCallback;
+ _undefinedCallback = undefinedCallback;
Running = true;
_nativeContext.SetCounter(MinCountForCheck);
}
- public ulong GetX(int index) => _nativeContext.GetX(index);
- public void SetX(int index, ulong value) => _nativeContext.SetX(index, value);
+ public ulong GetX(int index) => _nativeContext.GetX(index);
+ public void SetX(int index, ulong value) => _nativeContext.SetX(index, value);
- public V128 GetV(int index) => _nativeContext.GetV(index);
+ public V128 GetV(int index) => _nativeContext.GetV(index);
public void SetV(int index, V128 value) => _nativeContext.SetV(index, value);
- public bool GetPstateFlag(PState flag) => _nativeContext.GetPstateFlag(flag);
+ public bool GetPstateFlag(PState flag) => _nativeContext.GetPstateFlag(flag);
public void SetPstateFlag(PState flag, bool value) => _nativeContext.SetPstateFlag(flag, value);
public bool GetFPstateFlag(FPState flag) => _nativeContext.GetFPStateFlag(flag);
@@ -118,7 +108,7 @@ namespace ARMeilleure.State
{
_interrupted = false;
- Interrupt?.Invoke(this, EventArgs.Empty);
+ _interruptCallback?.Invoke(this);
}
_nativeContext.SetCounter(MinCountForCheck);
@@ -131,17 +121,17 @@ namespace ARMeilleure.State
internal void OnBreak(ulong address, int imm)
{
- Break?.Invoke(this, new InstExceptionEventArgs(address, imm));
+ _breakCallback?.Invoke(this, address, imm);
}
internal void OnSupervisorCall(ulong address, int imm)
{
- SupervisorCall?.Invoke(this, new InstExceptionEventArgs(address, imm));
+ _supervisorCallback?.Invoke(this, address, imm);
}
internal void OnUndefined(ulong address, int opCode)
{
- Undefined?.Invoke(this, new InstUndefinedEventArgs(address, opCode));
+ _undefinedCallback?.Invoke(this, address, opCode);
}
public void StopRunning()
@@ -151,16 +141,6 @@ namespace ARMeilleure.State
_nativeContext.SetCounter(0);
}
- public static void SuspendCounter()
- {
- _tickCounter.Stop();
- }
-
- public static void ResumeCounter()
- {
- _tickCounter.Start();
- }
-
public void Dispose()
{
_nativeContext.Dispose();
diff --git a/ARMeilleure/State/ICounter.cs b/ARMeilleure/State/ICounter.cs
new file mode 100644
index 00000000..93e721ea
--- /dev/null
+++ b/ARMeilleure/State/ICounter.cs
@@ -0,0 +1,18 @@
+namespace ARMeilleure.State
+{
+ /// <summary>
+ /// CPU Counter interface.
+ /// </summary>
+ public interface ICounter
+ {
+ /// <summary>
+ /// Counter frequency in Hertz.
+ /// </summary>
+ ulong Frequency { get; }
+
+ /// <summary>
+ /// Current counter value.
+ /// </summary>
+ ulong Counter { get; }
+ }
+} \ No newline at end of file
diff --git a/ARMeilleure/State/InstExceptionEventArgs.cs b/ARMeilleure/State/InstExceptionEventArgs.cs
deleted file mode 100644
index c2460e4b..00000000
--- a/ARMeilleure/State/InstExceptionEventArgs.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using System;
-
-namespace ARMeilleure.State
-{
- public class InstExceptionEventArgs : EventArgs
- {
- public ulong Address { get; }
- public int Id { get; }
-
- public InstExceptionEventArgs(ulong address, int id)
- {
- Address = address;
- Id = id;
- }
- }
-} \ No newline at end of file
diff --git a/ARMeilleure/State/InstUndefinedEventArgs.cs b/ARMeilleure/State/InstUndefinedEventArgs.cs
deleted file mode 100644
index c02b648e..00000000
--- a/ARMeilleure/State/InstUndefinedEventArgs.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using System;
-
-namespace ARMeilleure.State
-{
- public class InstUndefinedEventArgs : EventArgs
- {
- public ulong Address { get; }
- public int OpCode { get; }
-
- public InstUndefinedEventArgs(ulong address, int opCode)
- {
- Address = address;
- OpCode = opCode;
- }
- }
-} \ No newline at end of file
diff --git a/ARMeilleure/State/NativeContext.cs b/ARMeilleure/State/NativeContext.cs
index f911f762..11ab5ca3 100644
--- a/ARMeilleure/State/NativeContext.cs
+++ b/ARMeilleure/State/NativeContext.cs
@@ -34,6 +34,12 @@ namespace ARMeilleure.State
GetStorage().ExclusiveAddress = ulong.MaxValue;
}
+ public ulong GetPc()
+ {
+ // TODO: More precise tracking of PC value.
+ return GetStorage().DispatchAddress;
+ }
+
public unsafe ulong GetX(int index)
{
if ((uint)index >= RegisterConsts.IntRegsCount)
diff --git a/ARMeilleure/Translation/Delegates.cs b/ARMeilleure/Translation/Delegates.cs
index 3cfe34b6..6d40dc96 100644
--- a/ARMeilleure/Translation/Delegates.cs
+++ b/ARMeilleure/Translation/Delegates.cs
@@ -115,7 +115,7 @@ namespace ARMeilleure.Translation
SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetFpsr)));
SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetFunctionAddress)));
SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.InvalidateCacheLine)));
- SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetTpidr)));
+ SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetTpidrroEl0)));
SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetTpidr32))); // A32 only.
SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetTpidrEl0)));
SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetTpidrEl032))); // A32 only.
diff --git a/ARMeilleure/Translation/PTC/Ptc.cs b/ARMeilleure/Translation/PTC/Ptc.cs
index 43f3b08b..9671a871 100644
--- a/ARMeilleure/Translation/PTC/Ptc.cs
+++ b/ARMeilleure/Translation/PTC/Ptc.cs
@@ -27,7 +27,7 @@ namespace ARMeilleure.Translation.PTC
private const string OuterHeaderMagicString = "PTCohd\0\0";
private const string InnerHeaderMagicString = "PTCihd\0\0";
- private const uint InternalVersion = 3267; //! To be incremented manually for each change to the ARMeilleure project.
+ private const uint InternalVersion = 3362; //! To be incremented manually for each change to the ARMeilleure project.
private const string ActualDir = "0";
private const string BackupDir = "1";