ArmProcessContextFactory.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Ryujinx.Common.Configuration;
  2. using Ryujinx.Cpu;
  3. using Ryujinx.Cpu.Jit;
  4. using Ryujinx.Graphics.Gpu;
  5. using Ryujinx.HLE.HOS.Kernel;
  6. using Ryujinx.HLE.HOS.Kernel.Process;
  7. using Ryujinx.Memory;
  8. using System;
  9. namespace Ryujinx.HLE.HOS
  10. {
  11. class ArmProcessContextFactory : IProcessContextFactory
  12. {
  13. private readonly ICpuEngine _cpuEngine;
  14. private readonly GpuContext _gpu;
  15. private readonly string _titleIdText;
  16. private readonly string _displayVersion;
  17. private readonly bool _diskCacheEnabled;
  18. private readonly ulong _codeAddress;
  19. private readonly ulong _codeSize;
  20. public IDiskCacheLoadState DiskCacheLoadState { get; private set; }
  21. public ArmProcessContextFactory(
  22. ICpuEngine cpuEngine,
  23. GpuContext gpu,
  24. string titleIdText,
  25. string displayVersion,
  26. bool diskCacheEnabled,
  27. ulong codeAddress,
  28. ulong codeSize)
  29. {
  30. _cpuEngine = cpuEngine;
  31. _gpu = gpu;
  32. _titleIdText = titleIdText;
  33. _displayVersion = displayVersion;
  34. _diskCacheEnabled = diskCacheEnabled;
  35. _codeAddress = codeAddress;
  36. _codeSize = codeSize;
  37. }
  38. public IProcessContext Create(KernelContext context, ulong pid, ulong addressSpaceSize, InvalidAccessHandler invalidAccessHandler, bool for64Bit)
  39. {
  40. MemoryManagerMode mode = context.Device.Configuration.MemoryManagerMode;
  41. if (!MemoryBlock.SupportsFlags(MemoryAllocationFlags.ViewCompatible))
  42. {
  43. mode = MemoryManagerMode.SoftwarePageTable;
  44. }
  45. IArmProcessContext processContext;
  46. switch (mode)
  47. {
  48. case MemoryManagerMode.SoftwarePageTable:
  49. var memoryManager = new MemoryManager(context.Memory, addressSpaceSize, invalidAccessHandler);
  50. processContext = new ArmProcessContext<MemoryManager>(pid, _cpuEngine, _gpu, memoryManager, for64Bit);
  51. break;
  52. case MemoryManagerMode.HostMapped:
  53. case MemoryManagerMode.HostMappedUnsafe:
  54. bool unsafeMode = mode == MemoryManagerMode.HostMappedUnsafe;
  55. var memoryManagerHostMapped = new MemoryManagerHostMapped(context.Memory, addressSpaceSize, unsafeMode, invalidAccessHandler);
  56. processContext = new ArmProcessContext<MemoryManagerHostMapped>(pid, _cpuEngine, _gpu, memoryManagerHostMapped, for64Bit);
  57. break;
  58. default:
  59. throw new ArgumentOutOfRangeException();
  60. }
  61. DiskCacheLoadState = processContext.Initialize(_titleIdText, _displayVersion, _diskCacheEnabled, _codeAddress, _codeSize);
  62. return processContext;
  63. }
  64. }
  65. }