Refactor busReloc to use hooks.

Also add sd logging and temporarily remove new Erista timings; they're still slightly too explosive.
Todo: Rename stuff and fix uart redirect.
This commit is contained in:
Lightos1 committed 2026-08-25 20:40:32 +02:00
1 parent 7fea98a72d
commit eba5573711
9 files changed
+200 -76

No files matched your search

@@ -155,4 +155,63 @@ namespace ams::ldr::hoc {
while(true) { }
#endif
}
namespace {
constexpr size_t SdLogBufferSize = 0x1000;
char sdLogBuffer[SdLogBufferSize];
size_t workingLength = 0;
}
void SdLog(const char *data, ...) {
if (workingLength >= SdLogBufferSize - 1) {
return;
}
va_list args;
va_start(args, data);
s32 res = vsnprintf(sdLogBuffer + workingLength, SdLogBufferSize - workingLength, data, args);
va_end(args);
if (res < 0) {
return;
}
workingLength = std::min(workingLength + static_cast<size_t>(res), SdLogBufferSize - 1);
}
void SaveLog() {
static bool saved = false;
if (workingLength == 0 || saved) {
return;
}
if (!cfg::IsSdCardInitialized()) {
return;
}
if (R_FAILED(fs::MountSdCard("sdmc"))) {
return;
}
ON_SCOPE_EXIT { fs::Unmount("sdmc"); };
constexpr const char *Path = "sdmc:/config/horizon-oc/ldr_log.txt";
R_DISCARD(fs::DeleteFile(Path));
if (R_FAILED(fs::CreateFile(Path, workingLength))) {
return;
}
fs::FileHandle file;
if (R_FAILED(fs::OpenFile(std::addressof(file), Path, fs::OpenMode_Write))) {
return;
}
ON_SCOPE_EXIT { fs::CloseFile(file); };
if (R_FAILED(fs::WriteFile(file, 0, sdLogBuffer, workingLength, fs::WriteOption::Flush))) {
return;
}
saved = true;
}
}