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