KSystemControl.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using Ryujinx.HLE.HOS.Kernel.Memory;
  2. using System;
  3. namespace Ryujinx.HLE.HOS.Kernel.Common
  4. {
  5. static class KSystemControl
  6. {
  7. private const ulong Kb = 1024;
  8. private const ulong Mb = 1024 * Kb;
  9. private const ulong Gb = 1024 * Mb;
  10. private const ulong PageSize = 4 * Kb;
  11. private const ulong RequiredNonSecureSystemPoolSizeVi = 0x2238 * PageSize;
  12. private const ulong RequiredNonSecureSystemPoolSizeNvservices = 0x710 * PageSize;
  13. private const ulong RequiredNonSecureSystemPoolSizeOther = 0x80 * PageSize;
  14. private const ulong RequiredNonSecureSystemPoolSize =
  15. RequiredNonSecureSystemPoolSizeVi +
  16. RequiredNonSecureSystemPoolSizeNvservices +
  17. RequiredNonSecureSystemPoolSizeOther;
  18. public static ulong GetApplicationPoolSize(MemoryArrange arrange)
  19. {
  20. return arrange switch
  21. {
  22. MemoryArrange.MemoryArrange4GB or
  23. MemoryArrange.MemoryArrange4GBSystemDev or
  24. MemoryArrange.MemoryArrange6GBAppletDev => 3285 * Mb,
  25. MemoryArrange.MemoryArrange4GBAppletDev => 2048 * Mb,
  26. MemoryArrange.MemoryArrange6GB or
  27. MemoryArrange.MemoryArrange8GB => 4916 * Mb,
  28. _ => throw new ArgumentException($"Invalid memory arrange \"{arrange}\".")
  29. };
  30. }
  31. public static ulong GetAppletPoolSize(MemoryArrange arrange)
  32. {
  33. return arrange switch
  34. {
  35. MemoryArrange.MemoryArrange4GB => 507 * Mb,
  36. MemoryArrange.MemoryArrange4GBAppletDev => 1554 * Mb,
  37. MemoryArrange.MemoryArrange4GBSystemDev => 448 * Mb,
  38. MemoryArrange.MemoryArrange6GB => 562 * Mb,
  39. MemoryArrange.MemoryArrange6GBAppletDev or
  40. MemoryArrange.MemoryArrange8GB => 2193 * Mb,
  41. _ => throw new ArgumentException($"Invalid memory arrange \"{arrange}\".")
  42. };
  43. }
  44. public static ulong GetMinimumNonSecureSystemPoolSize()
  45. {
  46. return RequiredNonSecureSystemPoolSize;
  47. }
  48. public static ulong GetDramEndAddress(MemorySize size)
  49. {
  50. return DramMemoryMap.DramBase + GetDramSize(size);
  51. }
  52. public static ulong GenerateRandom()
  53. {
  54. // TODO
  55. return 0;
  56. }
  57. public static ulong GetDramSize(MemorySize size)
  58. {
  59. return size switch
  60. {
  61. MemorySize.MemorySize4GB => 4 * Gb,
  62. MemorySize.MemorySize6GB => 6 * Gb,
  63. MemorySize.MemorySize8GB => 8 * Gb,
  64. _ => throw new ArgumentException($"Invalid memory size \"{size}\".")
  65. };
  66. }
  67. }
  68. }