Skip to content

Commit

Permalink
Implement TPIDR2_EL0
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeWarnut committed Nov 19, 2024
1 parent fda79ef commit 40c5a31
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/ARMeilleure/Instructions/InstEmitSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public static void Mrs(ArmEmitterContext context)
case 0b11_011_1101_0000_011:
EmitGetTpidrroEl0(context);
return;
case 0b11_011_1101_0000_101:
EmitGetTpidr2El0(context);
return;
case 0b11_011_1110_0000_000:
info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetCntfrqEl0));
break;
Expand Down Expand Up @@ -84,6 +87,9 @@ public static void Msr(ArmEmitterContext context)
case 0b11_011_1101_0000_010:
EmitSetTpidrEl0(context);
return;
case 0b11_011_1101_0000_101:
EmitGetTpidr2El0(context);
return;

default:
throw new NotImplementedException($"Unknown MSR 0x{op.RawOpCode:X8} at 0x{op.Address:X16}.");
Expand Down Expand Up @@ -213,6 +219,17 @@ private static void EmitGetTpidrroEl0(ArmEmitterContext context)
SetIntOrZR(context, op.Rt, result);
}

private static void EmitGetTpidr2El0(ArmEmitterContext context)
{
OpCodeSystem op = (OpCodeSystem)context.CurrOp;

Operand nativeContext = context.LoadArgument(OperandType.I64, 0);

Operand result = context.Load(OperandType.I64, context.Add(nativeContext, Const((ulong)NativeContext.GetTpidr2El0Offset())));

SetIntOrZR(context, op.Rt, result);
}

private static void EmitSetNzcv(ArmEmitterContext context)
{
OpCodeSystem op = (OpCodeSystem)context.CurrOp;
Expand Down
9 changes: 9 additions & 0 deletions src/ARMeilleure/State/NativeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ private unsafe struct NativeCtxStorage
public ulong ExclusiveValueLow;
public ulong ExclusiveValueHigh;
public int Running;
public long Tpidr2El0;
}

private static NativeCtxStorage _dummyStorage = new();
Expand Down Expand Up @@ -176,6 +177,9 @@ public unsafe void SetFPState(uint value, uint mask = uint.MaxValue)
public long GetTpidrroEl0() => GetStorage().TpidrroEl0;
public void SetTpidrroEl0(long value) => GetStorage().TpidrroEl0 = value;

public long GetTpidr2El0() => GetStorage().Tpidr2El0;
public void SetTpidr2El0(long value) => GetStorage().Tpidr2El0 = value;

public int GetCounter() => GetStorage().Counter;
public void SetCounter(int value) => GetStorage().Counter = value;

Expand Down Expand Up @@ -232,6 +236,11 @@ public static int GetTpidrroEl0Offset()
return StorageOffset(ref _dummyStorage, ref _dummyStorage.TpidrroEl0);
}

public static int GetTpidr2El0Offset()
{
return StorageOffset(ref _dummyStorage, ref _dummyStorage.Tpidr2El0);
}

public static int GetCounterOffset()
{
return StorageOffset(ref _dummyStorage, ref _dummyStorage.Counter);
Expand Down

0 comments on commit 40c5a31

Please sign in to comment.