AInstEmitException.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using ChocolArm64.Decoder;
  2. using ChocolArm64.State;
  3. using ChocolArm64.Translation;
  4. using System.Reflection;
  5. namespace ChocolArm64.Instruction
  6. {
  7. static partial class AInstEmit
  8. {
  9. private const BindingFlags Binding = BindingFlags.NonPublic | BindingFlags.Instance;
  10. public static void Brk(AILEmitterCtx Context)
  11. {
  12. EmitExceptionCall(Context, nameof(AThreadState.OnBreak));
  13. }
  14. public static void Svc(AILEmitterCtx Context)
  15. {
  16. EmitExceptionCall(Context, nameof(AThreadState.OnSvcCall));
  17. }
  18. private static void EmitExceptionCall(AILEmitterCtx Context, string MthdName)
  19. {
  20. AOpCodeException Op = (AOpCodeException)Context.CurrOp;
  21. Context.EmitStoreState();
  22. Context.EmitLdarg(ATranslatedSub.StateArgIdx);
  23. Context.EmitLdc_I4(Op.Id);
  24. MethodInfo MthdInfo = typeof(AThreadState).GetMethod(MthdName, Binding);
  25. Context.EmitCall(MthdInfo);
  26. if (Context.CurrBlock.Next != null)
  27. {
  28. Context.EmitLoadState(Context.CurrBlock.Next);
  29. }
  30. }
  31. public static void Und(AILEmitterCtx Context)
  32. {
  33. AOpCode Op = Context.CurrOp;
  34. Context.EmitStoreState();
  35. Context.EmitLdarg(ATranslatedSub.StateArgIdx);
  36. Context.EmitLdc_I8(Op.Position);
  37. Context.EmitLdc_I4(Op.RawOpCode);
  38. string MthdName = nameof(AThreadState.OnUndefined);
  39. MethodInfo MthdInfo = typeof(AThreadState).GetMethod(MthdName, Binding);
  40. Context.EmitCall(MthdInfo);
  41. if (Context.CurrBlock.Next != null)
  42. {
  43. Context.EmitLoadState(Context.CurrBlock.Next);
  44. }
  45. }
  46. }
  47. }