AInstEmitException.cs 2.1 KB

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