aboutsummaryrefslogtreecommitdiff
path: root/ChocolArm64
diff options
context:
space:
mode:
Diffstat (limited to 'ChocolArm64')
-rw-r--r--ChocolArm64/AThread.cs28
-rw-r--r--ChocolArm64/Instruction/AInstEmitMemoryEx.cs3
-rw-r--r--ChocolArm64/Memory/AMemory.cs28
-rw-r--r--ChocolArm64/State/AThreadState.cs21
4 files changed, 54 insertions, 26 deletions
diff --git a/ChocolArm64/AThread.cs b/ChocolArm64/AThread.cs
index 7b8360f8..76b36da4 100644
--- a/ChocolArm64/AThread.cs
+++ b/ChocolArm64/AThread.cs
@@ -10,11 +10,9 @@ namespace ChocolArm64
public AThreadState ThreadState { get; private set; }
public AMemory Memory { get; private set; }
- private long EntryPoint;
-
private ATranslator Translator;
- private Thread Work;
+ public Thread Work;
public event EventHandler WorkFinished;
@@ -24,13 +22,21 @@ namespace ChocolArm64
{
this.Translator = Translator;
this.Memory = Memory;
- this.EntryPoint = EntryPoint;
ThreadState = new AThreadState();
ThreadState.ExecutionMode = AExecutionMode.AArch64;
ThreadState.Running = true;
+
+ Work = new Thread(delegate()
+ {
+ Translator.ExecuteSubroutine(this, EntryPoint);
+
+ Memory.RemoveMonitor(ThreadState.Core);
+
+ WorkFinished?.Invoke(this, EventArgs.Empty);
+ });
}
public bool Execute()
@@ -40,14 +46,7 @@ namespace ChocolArm64
return false;
}
- Work = new Thread(delegate()
- {
- Translator.ExecuteSubroutine(this, EntryPoint);
-
- Memory.RemoveMonitor(ThreadState);
-
- WorkFinished?.Invoke(this, EventArgs.Empty);
- });
+ Work.Name = "cpu_thread_" + Work.ManagedThreadId;
Work.Start();
@@ -59,6 +58,11 @@ namespace ChocolArm64
ThreadState.Running = false;
}
+ public void RequestInterrupt()
+ {
+ ThreadState.RequestInterrupt();
+ }
+
public bool IsCurrentThread()
{
return Thread.CurrentThread == Work;
diff --git a/ChocolArm64/Instruction/AInstEmitMemoryEx.cs b/ChocolArm64/Instruction/AInstEmitMemoryEx.cs
index e59cadd4..cf19b4a1 100644
--- a/ChocolArm64/Instruction/AInstEmitMemoryEx.cs
+++ b/ChocolArm64/Instruction/AInstEmitMemoryEx.cs
@@ -1,5 +1,6 @@
using ChocolArm64.Decoder;
using ChocolArm64.Memory;
+using ChocolArm64.State;
using ChocolArm64.Translation;
using System;
using System.Reflection.Emit;
@@ -170,6 +171,8 @@ namespace ChocolArm64.Instruction
Context.EmitLdarg(ATranslatedSub.MemoryArgIdx);
Context.EmitLdarg(ATranslatedSub.StateArgIdx);
+ Context.EmitCallPropGet(typeof(AThreadState), nameof(AThreadState.Core));
+
if (Rn != -1)
{
Context.EmitLdint(Rn);
diff --git a/ChocolArm64/Memory/AMemory.cs b/ChocolArm64/Memory/AMemory.cs
index 806a0b86..2cb9b16c 100644
--- a/ChocolArm64/Memory/AMemory.cs
+++ b/ChocolArm64/Memory/AMemory.cs
@@ -41,7 +41,7 @@ namespace ChocolArm64.Memory
}
}
- private Dictionary<AThreadState, ArmMonitor> Monitors;
+ private Dictionary<int, ArmMonitor> Monitors;
private ConcurrentDictionary<long, IntPtr> ObservedPages;
@@ -53,7 +53,7 @@ namespace ChocolArm64.Memory
public AMemory(IntPtr Ram)
{
- Monitors = new Dictionary<AThreadState, ArmMonitor>();
+ Monitors = new Dictionary<int, ArmMonitor>();
ObservedPages = new ConcurrentDictionary<long, IntPtr>();
@@ -69,17 +69,17 @@ namespace ChocolArm64.Memory
}
}
- public void RemoveMonitor(AThreadState State)
+ public void RemoveMonitor(int Core)
{
lock (Monitors)
{
- ClearExclusive(State);
+ ClearExclusive(Core);
- Monitors.Remove(State);
+ Monitors.Remove(Core);
}
}
- public void SetExclusive(AThreadState ThreadState, long Position)
+ public void SetExclusive(int Core, long Position)
{
Position &= ~ErgMask;
@@ -93,11 +93,11 @@ namespace ChocolArm64.Memory
}
}
- if (!Monitors.TryGetValue(ThreadState, out ArmMonitor ThreadMon))
+ if (!Monitors.TryGetValue(Core, out ArmMonitor ThreadMon))
{
ThreadMon = new ArmMonitor();
- Monitors.Add(ThreadState, ThreadMon);
+ Monitors.Add(Core, ThreadMon);
}
ThreadMon.Position = Position;
@@ -105,7 +105,7 @@ namespace ChocolArm64.Memory
}
}
- public bool TestExclusive(AThreadState ThreadState, long Position)
+ public bool TestExclusive(int Core, long Position)
{
//Note: Any call to this method also should be followed by a
//call to ClearExclusiveForStore if this method returns true.
@@ -113,7 +113,7 @@ namespace ChocolArm64.Memory
Monitor.Enter(Monitors);
- if (!Monitors.TryGetValue(ThreadState, out ArmMonitor ThreadMon))
+ if (!Monitors.TryGetValue(Core, out ArmMonitor ThreadMon))
{
return false;
}
@@ -128,9 +128,9 @@ namespace ChocolArm64.Memory
return ExState;
}
- public void ClearExclusiveForStore(AThreadState ThreadState)
+ public void ClearExclusiveForStore(int Core)
{
- if (Monitors.TryGetValue(ThreadState, out ArmMonitor ThreadMon))
+ if (Monitors.TryGetValue(Core, out ArmMonitor ThreadMon))
{
ThreadMon.ExState = false;
}
@@ -138,11 +138,11 @@ namespace ChocolArm64.Memory
Monitor.Exit(Monitors);
}
- public void ClearExclusive(AThreadState ThreadState)
+ public void ClearExclusive(int Core)
{
lock (Monitors)
{
- if (Monitors.TryGetValue(ThreadState, out ArmMonitor ThreadMon))
+ if (Monitors.TryGetValue(Core, out ArmMonitor ThreadMon))
{
ThreadMon.ExState = false;
}
diff --git a/ChocolArm64/State/AThreadState.cs b/ChocolArm64/State/AThreadState.cs
index 7b69d817..783f5a12 100644
--- a/ChocolArm64/State/AThreadState.cs
+++ b/ChocolArm64/State/AThreadState.cs
@@ -41,6 +41,9 @@ namespace ChocolArm64.State
public bool Negative;
public bool Running { get; set; }
+ public int Core { get; set; }
+
+ private bool Interrupted;
public long TpidrEl0 { get; set; }
public long Tpidr { get; set; }
@@ -73,6 +76,7 @@ namespace ChocolArm64.State
}
}
+ public event EventHandler<EventArgs> Interrupt;
public event EventHandler<AInstExceptionEventArgs> Break;
public event EventHandler<AInstExceptionEventArgs> SvcCall;
public event EventHandler<AInstUndefinedEventArgs> Undefined;
@@ -99,9 +103,26 @@ namespace ChocolArm64.State
internal bool Synchronize()
{
+ if (Interrupted)
+ {
+ Interrupted = false;
+
+ OnInterrupt();
+ }
+
return Running;
}
+ internal void RequestInterrupt()
+ {
+ Interrupted = true;
+ }
+
+ private void OnInterrupt()
+ {
+ Interrupt?.Invoke(this, EventArgs.Empty);
+ }
+
internal void OnBreak(long Position, int Imm)
{
Break?.Invoke(this, new AInstExceptionEventArgs(Position, Imm));