exo2: resolve remaining erista TODOs, clean up debugging code

This commit is contained in:
Michael Scire 2020-06-14 22:06:44 -07:00 committed by SciresM
parent 23d3f786e3
commit 0698338312
5 changed files with 62 additions and 90 deletions

View file

@ -20,8 +20,21 @@
namespace ams::secmon::smc {
SmcResult SmcShowError(SmcArguments &args) {
/* TODO */
return SmcResult::NotImplemented;
/* Decode arguments. */
const u32 r = ((args.r[1] >> 8) & 0xF);
const u32 g = ((args.r[1] >> 4) & 0xF);
const u32 b = ((args.r[1] >> 0) & 0xF);
const u32 rgb = (b << 8) | (g << 4) | (r << 0);
/* Set the error info. */
SetError(pkg1::MakeKernelPanicResetInfo(rgb));
/* Reboot. */
ErrorReboot();
/* This point will never be reached. */
__builtin_unreachable();
}
}

View file

@ -239,40 +239,6 @@ namespace ams::secmon::smc {
return info.handler(args);
}
constinit std::atomic<int> g_logged = 0;
constexpr int LogMin = 0x1000000;
constexpr int LogMax = 0x1000000;
constexpr size_t LogBufSize = 0x5000;
void DebugLog(SmcArguments &args) {
const int current = g_logged.fetch_add(1);
if (current == 0) {
std::memset(MemoryRegionVirtualDebug.GetPointer<void>(), 0xCC, LogBufSize);
}
if (current < LogMin) {
return;
}
const int ind = current - LogMin;
const int ofs = (ind * sizeof(args)) % LogBufSize;
for (size_t i = 0; i < sizeof(args) / sizeof(u32); ++i) {
((volatile u32 *)(MemoryRegionVirtualDebug.GetAddress() + ofs))[i] = reinterpret_cast<u32 *>(std::addressof(args))[i];
}
if (current >= LogMax) {
*(volatile u32 *)(MemoryRegionVirtualDevicePmc.GetAddress() + 0x50) = 0x02;
*(volatile u32 *)(MemoryRegionVirtualDevicePmc.GetAddress() + 0x00) = 0x10;
util::WaitMicroSeconds(1000);
}
}
}
void ConfigureSmcHandlersForTargetFirmware() {
@ -288,45 +254,11 @@ namespace ams::secmon::smc {
/* Get the table. */
const auto &table = GetHandlerTable(static_cast<HandlerType>(type), args.r[0]);
if (std::addressof(table) == std::addressof(g_handler_tables[HandlerType_User])) {
DebugLog(args);
}
/* Get the handler info. */
const auto &info = GetHandlerInfo(table, args.r[0]);
/* Set the invocation result. */
args.r[0] = static_cast<u64>(InvokeSmcHandler(info, args));
if (std::addressof(table) == std::addressof(g_handler_tables[HandlerType_User])) {
DebugLog(args);
}
/* TODO: For debugging. Remove this when exo2 is complete. */
#if 1
if (args.r[0] == static_cast<u64>(SmcResult::NotImplemented)) {
*(volatile u32 *)(MemoryRegionVirtualDebug.GetAddress()) = 0xBBBBBBBB;
*(volatile u32 *)(MemoryRegionVirtualDebug.GetAddress() + 0x10) = static_cast<u32>(info.function_id);
for (size_t i = 0; i < sizeof(args) / sizeof(u32); ++i) {
((volatile u32 *)(MemoryRegionVirtualDebug.GetAddress() + 0x20))[i] = reinterpret_cast<u32 *>(std::addressof(args))[i];
}
*(volatile u32 *)(MemoryRegionVirtualDevicePmc.GetAddress() + 0x50) = 0x02;
*(volatile u32 *)(MemoryRegionVirtualDevicePmc.GetAddress() + 0x00) = 0x10;
util::WaitMicroSeconds(1000);
}
if (args.r[0] != static_cast<u64>(SmcResult::Success) && info.function_id != 0xC3000007 /* generate aes key fails during SetupKekAccessKeys */) {
*(volatile u32 *)(MemoryRegionVirtualDebug.GetAddress()) = 0xCCCCCCCC;
*(volatile u32 *)(MemoryRegionVirtualDebug.GetAddress() + 0x10) = static_cast<u32>(info.function_id);
for (size_t i = 0; i < sizeof(args) / sizeof(u32); ++i) {
((volatile u32 *)(MemoryRegionVirtualDebug.GetAddress() + 0x20))[i] = reinterpret_cast<u32 *>(std::addressof(args))[i];
}
*(volatile u32 *)(MemoryRegionVirtualDevicePmc.GetAddress() + 0x50) = 0x02;
*(volatile u32 *)(MemoryRegionVirtualDevicePmc.GetAddress() + 0x00) = 0x10;
util::WaitMicroSeconds(1000);
}
#endif
}
}

View file

@ -325,7 +325,7 @@ namespace ams::secmon::smc {
}
void SaveSecureContextForMariko() {
/* TODO */
/* TODO: Implement this when adding ams-on-mariko support. */
}
void SaveSecureContext() {