AInstEmitException.cs 1.5 KB

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