JitExecutionContext.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using ARMeilleure.Memory;
  2. using ARMeilleure.State;
  3. namespace Ryujinx.Cpu.Jit
  4. {
  5. class JitExecutionContext : IExecutionContext
  6. {
  7. private readonly ExecutionContext _impl;
  8. internal ExecutionContext Impl => _impl;
  9. /// <inheritdoc/>
  10. public ulong Pc => _impl.Pc;
  11. /// <inheritdoc/>
  12. public long TpidrEl0
  13. {
  14. get => _impl.TpidrEl0;
  15. set => _impl.TpidrEl0 = value;
  16. }
  17. /// <inheritdoc/>
  18. public long TpidrroEl0
  19. {
  20. get => _impl.TpidrroEl0;
  21. set => _impl.TpidrroEl0 = value;
  22. }
  23. /// <inheritdoc/>
  24. public uint Pstate
  25. {
  26. get => _impl.Pstate;
  27. set => _impl.Pstate = value;
  28. }
  29. /// <inheritdoc/>
  30. public uint Fpcr
  31. {
  32. get => (uint)_impl.Fpcr;
  33. set => _impl.Fpcr = (FPCR)value;
  34. }
  35. /// <inheritdoc/>
  36. public uint Fpsr
  37. {
  38. get => (uint)_impl.Fpsr;
  39. set => _impl.Fpsr = (FPSR)value;
  40. }
  41. /// <inheritdoc/>
  42. public bool IsAarch32
  43. {
  44. get => _impl.IsAarch32;
  45. set => _impl.IsAarch32 = value;
  46. }
  47. /// <inheritdoc/>
  48. public bool Running => _impl.Running;
  49. private readonly ExceptionCallbacks _exceptionCallbacks;
  50. public JitExecutionContext(IJitMemoryAllocator allocator, ICounter counter, ExceptionCallbacks exceptionCallbacks)
  51. {
  52. _impl = new ExecutionContext(
  53. allocator,
  54. counter,
  55. InterruptHandler,
  56. BreakHandler,
  57. SupervisorCallHandler,
  58. UndefinedHandler);
  59. _exceptionCallbacks = exceptionCallbacks;
  60. }
  61. /// <inheritdoc/>
  62. public ulong GetX(int index) => _impl.GetX(index);
  63. /// <inheritdoc/>
  64. public void SetX(int index, ulong value) => _impl.SetX(index, value);
  65. /// <inheritdoc/>
  66. public V128 GetV(int index) => _impl.GetV(index);
  67. /// <inheritdoc/>
  68. public void SetV(int index, V128 value) => _impl.SetV(index, value);
  69. private void InterruptHandler(ExecutionContext context)
  70. {
  71. _exceptionCallbacks.InterruptCallback?.Invoke(this);
  72. }
  73. private void BreakHandler(ExecutionContext context, ulong address, int imm)
  74. {
  75. _exceptionCallbacks.BreakCallback?.Invoke(this, address, imm);
  76. }
  77. private void SupervisorCallHandler(ExecutionContext context, ulong address, int imm)
  78. {
  79. _exceptionCallbacks.SupervisorCallback?.Invoke(this, address, imm);
  80. }
  81. private void UndefinedHandler(ExecutionContext context, ulong address, int opCode)
  82. {
  83. _exceptionCallbacks.UndefinedCallback?.Invoke(this, address, opCode);
  84. }
  85. /// <inheritdoc/>
  86. public void RequestInterrupt()
  87. {
  88. _impl.RequestInterrupt();
  89. }
  90. /// <inheritdoc/>
  91. public void StopRunning()
  92. {
  93. _impl.StopRunning();
  94. }
  95. public void Dispose()
  96. {
  97. _impl.Dispose();
  98. }
  99. }
  100. }