From 539cd5846465dc48f08a69432a7cc901897cc00c Mon Sep 17 00:00:00 2001 From: souldbminersmwc Date: Thu, 13 Aug 2026 19:11:00 -0400 Subject: [PATCH] verbosity patch rework --- .../loader/source/oc/customize.cpp | 12 +++++- .../loader/source/oc/customize.hpp | 4 +- .../loader/source/oc/oc_common.hpp | 1 - .../source/oc/pcv/mariko/pcv_mariko.cpp | 42 +++++++++---------- .../source/oc/pcv/mariko/pcv_mariko.hpp | 2 +- 5 files changed, 35 insertions(+), 26 deletions(-) diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/customize.cpp b/Source/Atmosphere/stratosphere/loader/source/oc/customize.cpp index 8563a0d0..4550d8ea 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/customize.cpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/customize.cpp @@ -132,7 +132,7 @@ volatile CustomizeTable C = { AUTO /* 153 */, AUTO /* 192 */, AUTO /* 230 */, - AUTO /* 269 */, + AUTO /* 268 */, AUTO /* 307 */, AUTO /* 346 */, AUTO /* 384 */, @@ -219,6 +219,16 @@ volatile CustomizeTable C = { .fineTune_t6_tRTW = 0, .fineTune_t7_tWTR = 0, +/* Debugging options */ + +/* PCV Log Verbosity */ +/* -1: Nothing */ +/* 0: Basic logging */ +/* 1: More advanced logging */ +/* 2: All logging excluding MMIO */ +/* 3: All logging including MMIO */ +.pcvLogVerbosity = 2, + /* You shouldn't have to anything past here. */ .eristaCpuDvfsTable = { { 204000, { 721094, }, { } }, diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/customize.hpp b/Source/Atmosphere/stratosphere/loader/source/oc/customize.hpp index a898e20b..2e8be644 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/customize.hpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/customize.hpp @@ -132,7 +132,9 @@ struct CustomizeTable { u32 fineTune_t6_tRTW; u32 fineTune_t7_tWTR; - u32 reserved[60]; + u32 pcvLogVerbosity; + + u32 reserved[58]; CustomizeCpuDvfsTable eristaCpuDvfsTable; CustomizeCpuDvfsTable eristaCpuDvfsTableSLT; diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/oc_common.hpp b/Source/Atmosphere/stratosphere/loader/source/oc/oc_common.hpp index 2e79da3b..374730c8 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/oc_common.hpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/oc_common.hpp @@ -32,7 +32,6 @@ #endif #define HOC_PCV_NVLOG_PATCH 1 -#define HOC_PCV_FORCE_VERBOSITY 1 #include "customize.hpp" #include "oc_log.hpp" diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/mariko/pcv_mariko.cpp b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/mariko/pcv_mariko.cpp index 0c65ea57..9a1937c6 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/mariko/pcv_mariko.cpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/mariko/pcv_mariko.cpp @@ -142,29 +142,27 @@ namespace ams::ldr::hoc::pcv::mariko { /* Redirect the call sites as patching the actual function causes crash */ const uintptr_t roStart = g_pcv_cave + g_pcv_cave_size; /* module .rodata start */ size_t patchedSites = 0; - if (HOC_PCV_NVLOG_PATCH) { - for (u32 *p = nsoStart; reinterpret_cast(p + 1) <= textEnd; ++p) { - if (!AsmIsBl(*p)) { - continue; - } - const uintptr_t pc = reinterpret_cast(p); - if (AsmBranchTarget(*p, pc) != nvlog_addr) { - continue; - } - bool isFmtCall = false; - for (u32 j = 1; j <= 8 && reinterpret_cast(p - j) >= reinterpret_cast(nsoStart); ++j) { - const u32 w = *(p - j); - if (AsmIsAdrp(w) && asm_get_rd(w) == 0) { /* adrp x0, */ - const uintptr_t wpc = pc - j * 4; - const uintptr_t tgtPage = (wpc & ~static_cast(0xFFFu)) + static_cast(AsmAdrpPageOffset(w)); - if (tgtPage >= (roStart & ~static_cast(0xFFFu))) { isFmtCall = true; break; } - } - } - if (isFmtCall) { - PATCH_OFFSET(p, AsmMakeBl(pc, helper)); - ++patchedSites; + for (u32 *p = nsoStart; reinterpret_cast(p + 1) <= textEnd; ++p) { + if (!AsmIsBl(*p)) { + continue; + } + const uintptr_t pc = reinterpret_cast(p); + if (AsmBranchTarget(*p, pc) != nvlog_addr) { + continue; + } + bool isFmtCall = false; + for (u32 j = 1; j <= 8 && reinterpret_cast(p - j) >= reinterpret_cast(nsoStart); ++j) { + const u32 w = *(p - j); + if (AsmIsAdrp(w) && asm_get_rd(w) == 0) { /* adrp x0, */ + const uintptr_t wpc = pc - j * 4; + const uintptr_t tgtPage = (wpc & ~static_cast(0xFFFu)) + static_cast(AsmAdrpPageOffset(w)); + if (tgtPage >= (roStart & ~static_cast(0xFFFu))) { isFmtCall = true; break; } } } + if (isFmtCall) { + PATCH_OFFSET(p, AsmMakeBl(pc, helper)); + ++patchedSites; + } } LOGGING("NvLogRedirect: stub@+%lx vsnprintf@+%lx helper@+%lx instr=%zu sites=%zu", @@ -221,7 +219,7 @@ namespace ams::ldr::hoc::pcv::mariko { #if HOC_UART_LOG /* Force GetEffectiveVerbosityLevel to return a non-zero level so all NvLog runs. */ Result ForceVerbosity(u32 *ptr) { - PATCH_OFFSET(&ptr[0], AsmMakeMovzW(0, static_cast(HOC_PCV_FORCE_VERBOSITY))); /* movz w0,#level */ + PATCH_OFFSET(&ptr[0], AsmMakeMovzW(0, static_cast(C.pcvLogVerbosity))); /* movz w0,#level */ PATCH_OFFSET(&ptr[1], RetIns); /* ret */ R_SUCCEED(); } diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/mariko/pcv_mariko.hpp b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/mariko/pcv_mariko.hpp index 00bda587..95ac2a89 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/mariko/pcv_mariko.hpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/mariko/pcv_mariko.hpp @@ -151,7 +151,7 @@ namespace ams::ldr::hoc::pcv::mariko { } inline bool ForceVerbosityPatternFn(u32 *ptr) { - if (HOC_PCV_FORCE_VERBOSITY == 0 || g_pcv_cave == 0) { + if (g_pcv_cave == 0) { return false; } if (reinterpret_cast(ptr + 11) > g_pcv_cave) { /* .text only */