2021-04-04 13:06:59 +01:00
|
|
|
using Ryujinx.HLE.HOS.Kernel.Memory;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Kernel.Common
|
|
|
|
{
|
|
|
|
static class KSystemControl
|
|
|
|
{
|
2022-11-16 22:27:42 +00:00
|
|
|
private const ulong KiB = 1024;
|
|
|
|
private const ulong MiB = 1024 * KiB;
|
|
|
|
private const ulong GiB = 1024 * MiB;
|
2021-04-04 13:06:59 +01:00
|
|
|
|
2022-11-16 22:27:42 +00:00
|
|
|
private const ulong PageSize = 4 * KiB;
|
2021-04-04 13:06:59 +01:00
|
|
|
|
|
|
|
private const ulong RequiredNonSecureSystemPoolSizeVi = 0x2238 * PageSize;
|
|
|
|
private const ulong RequiredNonSecureSystemPoolSizeNvservices = 0x710 * PageSize;
|
|
|
|
private const ulong RequiredNonSecureSystemPoolSizeOther = 0x80 * PageSize;
|
|
|
|
|
|
|
|
private const ulong RequiredNonSecureSystemPoolSize =
|
|
|
|
RequiredNonSecureSystemPoolSizeVi +
|
|
|
|
RequiredNonSecureSystemPoolSizeNvservices +
|
|
|
|
RequiredNonSecureSystemPoolSizeOther;
|
|
|
|
|
|
|
|
public static ulong GetApplicationPoolSize(MemoryArrange arrange)
|
|
|
|
{
|
|
|
|
return arrange switch
|
|
|
|
{
|
2022-11-16 22:27:42 +00:00
|
|
|
MemoryArrange.MemoryArrange4GiB or
|
|
|
|
MemoryArrange.MemoryArrange4GiBSystemDev or
|
|
|
|
MemoryArrange.MemoryArrange6GiBAppletDev => 3285 * MiB,
|
|
|
|
MemoryArrange.MemoryArrange4GiBAppletDev => 2048 * MiB,
|
|
|
|
MemoryArrange.MemoryArrange6GiB or
|
|
|
|
MemoryArrange.MemoryArrange8GiB => 4916 * MiB,
|
2021-04-04 13:06:59 +01:00
|
|
|
_ => throw new ArgumentException($"Invalid memory arrange \"{arrange}\".")
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ulong GetAppletPoolSize(MemoryArrange arrange)
|
|
|
|
{
|
|
|
|
return arrange switch
|
|
|
|
{
|
2022-11-16 22:27:42 +00:00
|
|
|
MemoryArrange.MemoryArrange4GiB => 507 * MiB,
|
|
|
|
MemoryArrange.MemoryArrange4GiBAppletDev => 1554 * MiB,
|
|
|
|
MemoryArrange.MemoryArrange4GiBSystemDev => 448 * MiB,
|
|
|
|
MemoryArrange.MemoryArrange6GiB => 562 * MiB,
|
|
|
|
MemoryArrange.MemoryArrange6GiBAppletDev or
|
|
|
|
MemoryArrange.MemoryArrange8GiB => 2193 * MiB,
|
2021-04-04 13:06:59 +01:00
|
|
|
_ => throw new ArgumentException($"Invalid memory arrange \"{arrange}\".")
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ulong GetMinimumNonSecureSystemPoolSize()
|
|
|
|
{
|
|
|
|
return RequiredNonSecureSystemPoolSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ulong GetDramEndAddress(MemorySize size)
|
|
|
|
{
|
|
|
|
return DramMemoryMap.DramBase + GetDramSize(size);
|
|
|
|
}
|
|
|
|
|
2021-11-28 12:01:17 +00:00
|
|
|
public static ulong GenerateRandom()
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-04-04 13:06:59 +01:00
|
|
|
public static ulong GetDramSize(MemorySize size)
|
|
|
|
{
|
|
|
|
return size switch
|
|
|
|
{
|
2022-11-16 22:27:42 +00:00
|
|
|
MemorySize.MemorySize4GiB => 4 * GiB,
|
|
|
|
MemorySize.MemorySize6GiB => 6 * GiB,
|
|
|
|
MemorySize.MemorySize8GiB => 8 * GiB,
|
2021-04-04 13:06:59 +01:00
|
|
|
_ => throw new ArgumentException($"Invalid memory size \"{size}\".")
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|