diff --git a/stratosphere/loader/source/ldr_capabilities.cpp b/stratosphere/loader/source/ldr_capabilities.cpp index b3bc25e65..7c535fa77 100644 --- a/stratosphere/loader/source/ldr_capabilities.cpp +++ b/stratosphere/loader/source/ldr_capabilities.cpp @@ -425,29 +425,35 @@ namespace ams::ldr { } } - void FixDebugCapabilityForHbl(util::BitPack32 *kac, size_t count) { - for (size_t i = 0; i < count; ++i) { - const auto cap = kac[i]; - switch (GetCapabilityId(cap)) { - case CapabilityId::DebugFlags: - /* 19.0.0+ disallows more than one flag set; we are always DebugMode for kernel, so ForceDebug is the most powerful/flexible flag to set. */ - kac[i] = CapabilityDebugFlags::Encode(false, false, true); - break; - default: - break; - } - } - } - void PreProcessCapability(util::BitPack32 *kac, size_t count) { for (size_t i = 0; i < count; ++i) { const auto cap = kac[i]; switch (GetCapabilityId(cap)) { - /* NOTE: Currently, there is no pre-processing necessary. */ + case CapabilityId::DebugFlags: + { + // Ensure that only one debug flag is set + auto debug_cap = CapabilityDebugFlags::Decode(cap); + u32 total_flags = 0; + if (debug_cap.GetAllowDebug()) { ++total_flags; } + if (debug_cap.GetForceDebugProd()) { ++total_flags; } + if (debug_cap.GetForceDebug()) { ++total_flags; } + + // If more than one flag is set, adjust the capability + if (total_flags > 1) { + // Set the most appropriate flag (e.g., ForceDebug) + kac[i] = CapabilityDebugFlags::Encode( + false, // AllowDebug + false, // ForceDebugProd + true // ForceDebug + ); + } + } + break; default: break; } } } + } diff --git a/stratosphere/loader/source/ldr_capabilities.hpp b/stratosphere/loader/source/ldr_capabilities.hpp index 21748a7fb..0a91b23cc 100644 --- a/stratosphere/loader/source/ldr_capabilities.hpp +++ b/stratosphere/loader/source/ldr_capabilities.hpp @@ -23,8 +23,6 @@ namespace ams::ldr { u16 MakeProgramInfoFlag(const util::BitPack32 *kac, size_t count); void UpdateProgramInfoFlag(u16 flags, util::BitPack32 *kac, size_t count); - void FixDebugCapabilityForHbl(util::BitPack32 *kac, size_t count); - void PreProcessCapability(util::BitPack32 *kac, size_t count); } diff --git a/stratosphere/loader/source/ldr_meta.cpp b/stratosphere/loader/source/ldr_meta.cpp index b1d1a85ad..637beb441 100644 --- a/stratosphere/loader/source/ldr_meta.cpp +++ b/stratosphere/loader/source/ldr_meta.cpp @@ -253,9 +253,6 @@ namespace ams::ldr { } } - /* Fix the debug capabilities, to prevent needing a hbl recompilation. */ - FixDebugCapabilityForHbl(static_cast(meta->acid_kac), meta->acid->kac_size / sizeof(util::BitPack32)); - FixDebugCapabilityForHbl(static_cast(meta->aci_kac), meta->aci->kac_size / sizeof(util::BitPack32)); } else if (hos::GetVersion() >= hos::Version_10_0_0) { /* If storage id is none, there is no base code filesystem, and thus it is impossible for us to validate. */ /* However, if we're an application, we are guaranteed a base code filesystem. */