Ryujinx/ChocolArm64/Instruction/AInstEmitException.cs

65 lines
1.8 KiB
C#
Raw Normal View History

2018-02-04 15:08:20 -08:00
using ChocolArm64.Decoder;
using ChocolArm64.State;
using ChocolArm64.Translation;
using System.Reflection;
2018-02-04 15:08:20 -08:00
namespace ChocolArm64.Instruction
{
static partial class AInstEmit
{
private const BindingFlags Binding = BindingFlags.NonPublic | BindingFlags.Instance;
public static void Brk(AILEmitterCtx Context)
{
2018-02-18 11:28:07 -08:00
EmitExceptionCall(Context, nameof(AThreadState.OnBreak));
}
2018-02-04 15:08:20 -08:00
public static void Svc(AILEmitterCtx Context)
{
2018-02-18 11:28:07 -08:00
EmitExceptionCall(Context, nameof(AThreadState.OnSvcCall));
}
private static void EmitExceptionCall(AILEmitterCtx Context, string MthdName)
2018-02-04 15:08:20 -08:00
{
AOpCodeException Op = (AOpCodeException)Context.CurrOp;
Context.EmitStoreState();
2018-02-18 11:28:07 -08:00
Context.EmitLdarg(ATranslatedSub.StateArgIdx);
2018-02-04 15:08:20 -08:00
Context.EmitLdc_I4(Op.Id);
2018-02-18 11:28:07 -08:00
MethodInfo MthdInfo = typeof(AThreadState).GetMethod(MthdName, Binding);
Context.EmitCall(MthdInfo);
2018-02-04 15:08:20 -08:00
if (Context.CurrBlock.Next != null)
{
Context.EmitLoadState(Context.CurrBlock.Next);
}
}
public static void Und(AILEmitterCtx Context)
{
AOpCode Op = Context.CurrOp;
Context.EmitStoreState();
2018-02-18 11:28:07 -08:00
Context.EmitLdarg(ATranslatedSub.StateArgIdx);
Context.EmitLdc_I8(Op.Position);
Context.EmitLdc_I4(Op.RawOpCode);
2018-02-18 11:28:07 -08:00
string MthdName = nameof(AThreadState.OnUndefined);
2018-02-18 11:28:07 -08:00
MethodInfo MthdInfo = typeof(AThreadState).GetMethod(MthdName, Binding);
Context.EmitCall(MthdInfo);
if (Context.CurrBlock.Next != null)
{
Context.EmitLoadState(Context.CurrBlock.Next);
}
2018-02-04 15:08:20 -08:00
}
}
}