From 255a0083a186a78068643bdae3acbdc82f4665a7 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 21 Feb 2023 14:02:13 -0700 Subject: [PATCH] kern: better divide non-secure size, don't waste fatal memory unless necessary --- .../source/board/nintendo/nx/kern_k_system_control.cpp | 10 +++++++--- .../include/stratosphere/hos/hos_types.hpp | 2 ++ .../include/vapours/ams/ams_target_firmware.h | 6 +++++- .../vapours/svc/board/nintendo/nx/svc_device_name.hpp | 7 +++++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/libraries/libmesosphere/source/board/nintendo/nx/kern_k_system_control.cpp b/libraries/libmesosphere/source/board/nintendo/nx/kern_k_system_control.cpp index efe391c16..bb8c7c9f0 100644 --- a/libraries/libmesosphere/source/board/nintendo/nx/kern_k_system_control.cpp +++ b/libraries/libmesosphere/source/board/nintendo/nx/kern_k_system_control.cpp @@ -367,10 +367,14 @@ namespace ams::kern::board::nintendo::nx { size_t KSystemControl::Init::GetMinimumNonSecureSystemPoolSize() { /* Verify that our minimum is at least as large as Nintendo's. */ - constexpr size_t MinimumSize = ::ams::svc::RequiredNonSecureSystemMemorySize; - static_assert(MinimumSize >= 0x2C04000); + constexpr size_t MinimumSizeWithFatal = ::ams::svc::RequiredNonSecureSystemMemorySizeWithFatal; + static_assert(MinimumSizeWithFatal >= 0x2C04000); - return MinimumSize; + constexpr size_t MinimumSizeWithoutFatal = ::ams::svc::RequiredNonSecureSystemMemorySize; + static_assert(MinimumSizeWithoutFatal >= 0x2A00000); + + /* Include fatal in non-seure size on 16.0.0+. */ + return kern::GetTargetFirmware() >= ams::TargetFirmware_16_0_0 ? MinimumSizeWithFatal : MinimumSizeWithoutFatal; } u8 KSystemControl::Init::GetDebugLogUartPort() { diff --git a/libraries/libstratosphere/include/stratosphere/hos/hos_types.hpp b/libraries/libstratosphere/include/stratosphere/hos/hos_types.hpp index fd33701be..53778d277 100644 --- a/libraries/libstratosphere/include/stratosphere/hos/hos_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/hos/hos_types.hpp @@ -74,6 +74,8 @@ namespace ams::hos { Version_14_1_1 = ::ams::TargetFirmware_14_1_1, Version_14_1_2 = ::ams::TargetFirmware_14_1_2, Version_15_0_0 = ::ams::TargetFirmware_15_0_0, + Version_15_0_1 = ::ams::TargetFirmware_15_0_1, + Version_16_0_0 = ::ams::TargetFirmware_16_0_0, Version_Current = ::ams::TargetFirmware_Current, diff --git a/libraries/libvapours/include/vapours/ams/ams_target_firmware.h b/libraries/libvapours/include/vapours/ams/ams_target_firmware.h index 4c84dbba1..1fd01d5cc 100644 --- a/libraries/libvapours/include/vapours/ams/ams_target_firmware.h +++ b/libraries/libvapours/include/vapours/ams/ams_target_firmware.h @@ -72,8 +72,10 @@ #define ATMOSPHERE_TARGET_FIRMWARE_14_1_1 ATMOSPHERE_TARGET_FIRMWARE(14, 1, 1) #define ATMOSPHERE_TARGET_FIRMWARE_14_1_2 ATMOSPHERE_TARGET_FIRMWARE(14, 1, 2) #define ATMOSPHERE_TARGET_FIRMWARE_15_0_0 ATMOSPHERE_TARGET_FIRMWARE(15, 0, 0) +#define ATMOSPHERE_TARGET_FIRMWARE_15_0_1 ATMOSPHERE_TARGET_FIRMWARE(15, 0, 1) +#define ATMOSPHERE_TARGET_FIRMWARE_16_0_0 ATMOSPHERE_TARGET_FIRMWARE(16, 0, 0) -#define ATMOSPHERE_TARGET_FIRMWARE_CURRENT ATMOSPHERE_TARGET_FIRMWARE_15_0_0 +#define ATMOSPHERE_TARGET_FIRMWARE_CURRENT ATMOSPHERE_TARGET_FIRMWARE_16_0_0 #define ATMOSPHERE_TARGET_FIRMWARE_MIN ATMOSPHERE_TARGET_FIRMWARE(0, 0, 0) #define ATMOSPHERE_TARGET_FIRMWARE_MAX ATMOSPHERE_TARGET_FIRMWARE_CURRENT @@ -138,6 +140,8 @@ namespace ams { TargetFirmware_14_1_1 = ATMOSPHERE_TARGET_FIRMWARE_14_1_1, TargetFirmware_14_1_2 = ATMOSPHERE_TARGET_FIRMWARE_14_1_2, TargetFirmware_15_0_0 = ATMOSPHERE_TARGET_FIRMWARE_15_0_0, + TargetFirmware_15_0_1 = ATMOSPHERE_TARGET_FIRMWARE_15_0_1, + TargetFirmware_16_0_0 = ATMOSPHERE_TARGET_FIRMWARE_16_0_0, TargetFirmware_Current = ATMOSPHERE_TARGET_FIRMWARE_CURRENT, diff --git a/libraries/libvapours/include/vapours/svc/board/nintendo/nx/svc_device_name.hpp b/libraries/libvapours/include/vapours/svc/board/nintendo/nx/svc_device_name.hpp index 0148eea3f..d033ce273 100644 --- a/libraries/libvapours/include/vapours/svc/board/nintendo/nx/svc_device_name.hpp +++ b/libraries/libvapours/include/vapours/svc/board/nintendo/nx/svc_device_name.hpp @@ -64,8 +64,9 @@ namespace ams::svc::board::nintendo::nx { namespace impl { - constexpr inline const size_t RequiredNonSecureSystemMemorySizeVi = 0x2400 * 4_KB; - constexpr inline const size_t RequiredNonSecureSystemMemorySizeNvservices = 0x784 * 4_KB; + constexpr inline const size_t RequiredNonSecureSystemMemorySizeVi = 0x2280 * 4_KB; + constexpr inline const size_t RequiredNonSecureSystemMemorySizeViFatal = 0x200 * 4_KB; + constexpr inline const size_t RequiredNonSecureSystemMemorySizeNvservices = 0x704 * 4_KB; constexpr inline const size_t RequiredNonSecureSystemMemorySizeMisc = 0x80 * 4_KB; } @@ -74,4 +75,6 @@ namespace ams::svc::board::nintendo::nx { impl::RequiredNonSecureSystemMemorySizeNvservices + impl::RequiredNonSecureSystemMemorySizeMisc; + constexpr inline const size_t RequiredNonSecureSystemMemorySizeWithFatal = RequiredNonSecureSystemMemorySize + impl::RequiredNonSecureSystemMemorySizeViFatal; + }