ArmProcessContext.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using ARMeilleure.Memory;
  2. using Ryujinx.Cpu;
  3. using Ryujinx.Graphics.Gpu;
  4. using Ryujinx.HLE.HOS.Kernel.Process;
  5. using Ryujinx.Memory;
  6. namespace Ryujinx.HLE.HOS
  7. {
  8. interface IArmProcessContext : IProcessContext
  9. {
  10. IDiskCacheLoadState Initialize(
  11. string titleIdText,
  12. string displayVersion,
  13. bool diskCacheEnabled,
  14. ulong codeAddress,
  15. ulong codeSize);
  16. }
  17. class ArmProcessContext<T> : IArmProcessContext where T : class, IVirtualMemoryManagerTracked, IMemoryManager
  18. {
  19. private readonly ulong _pid;
  20. private readonly GpuContext _gpuContext;
  21. private readonly ICpuContext _cpuContext;
  22. private T _memoryManager;
  23. public IVirtualMemoryManager AddressSpace => _memoryManager;
  24. public ArmProcessContext(ulong pid, ICpuEngine cpuEngine, GpuContext gpuContext, T memoryManager, bool for64Bit)
  25. {
  26. if (memoryManager is IRefCounted rc)
  27. {
  28. rc.IncrementReferenceCount();
  29. }
  30. gpuContext.RegisterProcess(pid, memoryManager);
  31. _pid = pid;
  32. _gpuContext = gpuContext;
  33. _cpuContext = cpuEngine.CreateCpuContext(memoryManager, for64Bit);
  34. _memoryManager = memoryManager;
  35. }
  36. public IExecutionContext CreateExecutionContext(ExceptionCallbacks exceptionCallbacks)
  37. {
  38. return _cpuContext.CreateExecutionContext(exceptionCallbacks);
  39. }
  40. public void Execute(IExecutionContext context, ulong codeAddress)
  41. {
  42. _cpuContext.Execute(context, codeAddress);
  43. }
  44. public IDiskCacheLoadState Initialize(
  45. string titleIdText,
  46. string displayVersion,
  47. bool diskCacheEnabled,
  48. ulong codeAddress,
  49. ulong codeSize)
  50. {
  51. _cpuContext.PrepareCodeRange(codeAddress, codeSize);
  52. return _cpuContext.LoadDiskCache(titleIdText, displayVersion, diskCacheEnabled);
  53. }
  54. public void InvalidateCacheRegion(ulong address, ulong size)
  55. {
  56. _cpuContext.InvalidateCacheRegion(address, size);
  57. }
  58. public void Dispose()
  59. {
  60. if (_memoryManager is IRefCounted rc)
  61. {
  62. rc.DecrementReferenceCount();
  63. _memoryManager = null;
  64. _gpuContext.UnregisterProcess(_pid);
  65. }
  66. }
  67. }
  68. }