Files
Ryubing/src/Ryujinx.HLE/HOS/Kernel/Common/KSystemControl.cs
Keaton f76a97c976 Replace 'Expand DRAM' option with dropdown menu (#32)
Allows to use mods that require a larger memory pool to allocate from.
2024-10-21 23:16:41 -05:00

82 lines
3.0 KiB
C#

using Ryujinx.HLE.HOS.Kernel.Memory;
using System;
namespace Ryujinx.HLE.HOS.Kernel.Common
{
static class KSystemControl
{
private const ulong KiB = 1024;
private const ulong MiB = 1024 * KiB;
private const ulong GiB = 1024 * MiB;
private const ulong PageSize = 4 * KiB;
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
{
MemoryArrange.MemoryArrange4GiB or
MemoryArrange.MemoryArrange4GiBSystemDev or
MemoryArrange.MemoryArrange6GiBAppletDev => 3285 * MiB,
MemoryArrange.MemoryArrange4GiBAppletDev => 2048 * MiB,
MemoryArrange.MemoryArrange6GiB => 4916 * MiB,
MemoryArrange.MemoryArrange8GiB => 6964 * MiB,
MemoryArrange.MemoryArrange12GiB => 11060 * MiB,
_ => throw new ArgumentException($"Invalid memory arrange \"{arrange}\"."),
};
}
public static ulong GetAppletPoolSize(MemoryArrange arrange)
{
return arrange switch
{
MemoryArrange.MemoryArrange4GiB => 507 * MiB,
MemoryArrange.MemoryArrange4GiBAppletDev => 1554 * MiB,
MemoryArrange.MemoryArrange4GiBSystemDev => 448 * MiB,
MemoryArrange.MemoryArrange6GiB => 562 * MiB,
MemoryArrange.MemoryArrange6GiBAppletDev => 2193 * MiB,
MemoryArrange.MemoryArrange8GiB or
MemoryArrange.MemoryArrange12GiB => 562 * MiB,
_ => throw new ArgumentException($"Invalid memory arrange \"{arrange}\"."),
};
}
public static ulong GetMinimumNonSecureSystemPoolSize()
{
return RequiredNonSecureSystemPoolSize;
}
public static ulong GetDramEndAddress(MemorySize size)
{
return DramMemoryMap.DramBase + GetDramSize(size);
}
public static ulong GenerateRandom()
{
// TODO
return 0;
}
public static ulong GetDramSize(MemorySize size)
{
return size switch
{
MemorySize.MemorySize4GiB => 4 * GiB,
MemorySize.MemorySize6GiB => 6 * GiB,
MemorySize.MemorySize8GiB => 8 * GiB,
MemorySize.MemorySize12GiB => 12 * GiB,
_ => throw new ArgumentException($"Invalid memory size \"{size}\"."),
};
}
}
}