AInstEmitSystem.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using ChocolArm64.Decoder;
  2. using ChocolArm64.State;
  3. using ChocolArm64.Translation;
  4. using System.Reflection.Emit;
  5. namespace ChocolArm64.Instruction
  6. {
  7. static partial class AInstEmit
  8. {
  9. public static void Mrs(AILEmitterCtx Context)
  10. {
  11. AOpCodeSystem Op = (AOpCodeSystem)Context.CurrOp;
  12. Context.EmitLdarg(ATranslatedSub.RegistersArgIdx);
  13. Context.EmitLdc_I4(Op.Op0);
  14. Context.EmitLdc_I4(Op.Op1);
  15. Context.EmitLdc_I4(Op.CRn);
  16. Context.EmitLdc_I4(Op.CRm);
  17. Context.EmitLdc_I4(Op.Op2);
  18. Context.EmitCall(typeof(ARegisters), nameof(ARegisters.GetSystemReg));
  19. Context.EmitStintzr(Op.Rt);
  20. }
  21. public static void Msr(AILEmitterCtx Context)
  22. {
  23. AOpCodeSystem Op = (AOpCodeSystem)Context.CurrOp;
  24. Context.EmitLdarg(ATranslatedSub.RegistersArgIdx);
  25. Context.EmitLdc_I4(Op.Op0);
  26. Context.EmitLdc_I4(Op.Op1);
  27. Context.EmitLdc_I4(Op.CRn);
  28. Context.EmitLdc_I4(Op.CRm);
  29. Context.EmitLdc_I4(Op.Op2);
  30. Context.EmitLdintzr(Op.Rt);
  31. Context.EmitCall(typeof(ARegisters), nameof(ARegisters.SetSystemReg));
  32. }
  33. public static void Nop(AILEmitterCtx Context)
  34. {
  35. //Do nothing.
  36. }
  37. public static void Sys(AILEmitterCtx Context)
  38. {
  39. //This instruction is used to do some operations on the CPU like cache invalidation,
  40. //address translation and the like.
  41. //We treat it as no-op here since we don't have any cache being emulated anyway.
  42. AOpCodeSystem Op = (AOpCodeSystem)Context.CurrOp;
  43. int Id;
  44. Id = Op.Op2 << 0;
  45. Id |= Op.CRm << 3;
  46. Id |= Op.CRn << 7;
  47. Id |= Op.Op1 << 11;
  48. switch (Id)
  49. {
  50. case 0b011_0111_0100_001:
  51. {
  52. //DC ZVA
  53. for (int Offs = 0; Offs < 64; Offs += 8)
  54. {
  55. Context.EmitLdarg(ATranslatedSub.MemoryArgIdx);
  56. Context.EmitLdint(Op.Rt);
  57. Context.EmitLdc_I(Offs);
  58. Context.Emit(OpCodes.Add);
  59. Context.EmitLdc_I8(0);
  60. AInstEmitMemoryHelper.EmitWriteCall(Context, 3);
  61. }
  62. break;
  63. }
  64. }
  65. }
  66. }
  67. }