2018-02-04 23:08:20 +00:00
|
|
|
using ChocolArm64.Decoder;
|
|
|
|
using ChocolArm64.State;
|
|
|
|
using ChocolArm64.Translation;
|
2018-02-12 03:37:20 +00:00
|
|
|
using System.Reflection;
|
2018-03-04 17:09:59 +00:00
|
|
|
using System.Reflection.Emit;
|
2018-02-04 23:08:20 +00:00
|
|
|
|
|
|
|
namespace ChocolArm64.Instruction
|
|
|
|
{
|
|
|
|
static partial class AInstEmit
|
|
|
|
{
|
2018-02-10 13:24:16 +00:00
|
|
|
public static void Brk(AILEmitterCtx Context)
|
|
|
|
{
|
2018-02-18 19:28:07 +00:00
|
|
|
EmitExceptionCall(Context, nameof(AThreadState.OnBreak));
|
2018-02-10 13:24:16 +00:00
|
|
|
}
|
|
|
|
|
2018-02-04 23:08:20 +00:00
|
|
|
public static void Svc(AILEmitterCtx Context)
|
2018-02-10 13:24:16 +00:00
|
|
|
{
|
2018-02-18 19:28:07 +00:00
|
|
|
EmitExceptionCall(Context, nameof(AThreadState.OnSvcCall));
|
2018-02-10 13:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitExceptionCall(AILEmitterCtx Context, string MthdName)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
|
|
|
AOpCodeException Op = (AOpCodeException)Context.CurrOp;
|
|
|
|
|
|
|
|
Context.EmitStoreState();
|
|
|
|
|
2018-02-18 19:28:07 +00:00
|
|
|
Context.EmitLdarg(ATranslatedSub.StateArgIdx);
|
2018-02-04 23:08:20 +00:00
|
|
|
|
|
|
|
Context.EmitLdc_I4(Op.Id);
|
|
|
|
|
2018-04-22 04:21:49 +00:00
|
|
|
Context.EmitPrivateCall(typeof(AThreadState), MthdName);
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-03-12 04:04:52 +00:00
|
|
|
//Check if the thread should still be running, if it isn't then we return 0
|
|
|
|
//to force a return to the dispatcher and then exit the thread.
|
|
|
|
Context.EmitLdarg(ATranslatedSub.StateArgIdx);
|
|
|
|
|
|
|
|
Context.EmitCallPropGet(typeof(AThreadState), nameof(AThreadState.Running));
|
|
|
|
|
|
|
|
AILLabel LblEnd = new AILLabel();
|
|
|
|
|
|
|
|
Context.Emit(OpCodes.Brtrue_S, LblEnd);
|
|
|
|
|
|
|
|
Context.EmitLdc_I8(0);
|
|
|
|
|
|
|
|
Context.Emit(OpCodes.Ret);
|
|
|
|
|
|
|
|
Context.MarkLabel(LblEnd);
|
|
|
|
|
2018-02-04 23:08:20 +00:00
|
|
|
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-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void Und(AILEmitterCtx Context)
|
|
|
|
{
|
2018-02-10 17:20:46 +00:00
|
|
|
AOpCode Op = Context.CurrOp;
|
|
|
|
|
|
|
|
Context.EmitStoreState();
|
|
|
|
|
2018-02-18 19:28:07 +00:00
|
|
|
Context.EmitLdarg(ATranslatedSub.StateArgIdx);
|
2018-02-10 17:20:46 +00:00
|
|
|
|
|
|
|
Context.EmitLdc_I8(Op.Position);
|
|
|
|
Context.EmitLdc_I4(Op.RawOpCode);
|
|
|
|
|
2018-04-22 04:21:49 +00:00
|
|
|
Context.EmitPrivateCall(typeof(AThreadState), nameof(AThreadState.OnUndefined));
|
2018-02-10 17:20:46 +00:00
|
|
|
|
|
|
|
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-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|