ArmProcessContextFactory.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. public ArmProcessContextFactory(ICpuEngine cpuEngine, GpuContext gpu)
  16. {
  17. _cpuEngine = cpuEngine;
  18. _gpu = gpu;
  19. }
  20. public IProcessContext Create(KernelContext context, ulong pid, ulong addressSpaceSize, InvalidAccessHandler invalidAccessHandler, bool for64Bit)
  21. {
  22. MemoryManagerMode mode = context.Device.Configuration.MemoryManagerMode;
  23. if (!MemoryBlock.SupportsFlags(MemoryAllocationFlags.ViewCompatible))
  24. {
  25. mode = MemoryManagerMode.SoftwarePageTable;
  26. }
  27. switch (mode)
  28. {
  29. case MemoryManagerMode.SoftwarePageTable:
  30. var memoryManager = new MemoryManager(context.Memory, addressSpaceSize, invalidAccessHandler);
  31. return new ArmProcessContext<MemoryManager>(pid, _cpuEngine, _gpu, memoryManager, for64Bit);
  32. case MemoryManagerMode.HostMapped:
  33. case MemoryManagerMode.HostMappedUnsafe:
  34. bool unsafeMode = mode == MemoryManagerMode.HostMappedUnsafe;
  35. var memoryManagerHostMapped = new MemoryManagerHostMapped(context.Memory, addressSpaceSize, unsafeMode, invalidAccessHandler);
  36. return new ArmProcessContext<MemoryManagerHostMapped>(pid, _cpuEngine, _gpu, memoryManagerHostMapped, for64Bit);
  37. default:
  38. throw new ArgumentOutOfRangeException();
  39. }
  40. }
  41. }
  42. }