mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 20:31:14 +00:00
exo2: fix a number of bugs, add temp debug-log code
This commit is contained in:
parent
aa50944568
commit
bb3a8a888f
5 changed files with 48 additions and 5 deletions
|
@ -166,7 +166,7 @@ namespace ams::secmon::boot {
|
|||
se::DecryptAes128(work_block, se::AesBlockSize, slot, is_prod ? MasterKeyVectorsProd[i] : MasterKeyVectorsDev[i], se::AesBlockSize);
|
||||
|
||||
/* Set the old master key. */
|
||||
SetMasterKey(generation - 1, work_block, se::AesBlockSize);
|
||||
SetMasterKey(i - 1, work_block, se::AesBlockSize);
|
||||
|
||||
/* Set the old master key into a temporary keyslot. */
|
||||
se::SetAesKey(pkg1::AesKeySlot_Temporary, work_block, se::AesBlockSize);
|
||||
|
|
|
@ -86,7 +86,7 @@ namespace ams::secmon {
|
|||
}
|
||||
|
||||
void LoadMasterKey(int slot, int generation) {
|
||||
const int index = std::min(0, generation - pkg1::KeyGeneration_Min);
|
||||
const int index = std::max(0, generation - pkg1::KeyGeneration_Min);
|
||||
se::SetEncryptedAesKey128(slot, pkg1::AesKeySlot_RandomForKeyStorageWrap, GetMasterKeyStorage(index), se::AesBlockSize);
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ namespace ams::secmon {
|
|||
}
|
||||
|
||||
void LoadDeviceMasterKey(int slot, int generation) {
|
||||
const int index = std::min(0, generation - pkg1::KeyGeneration_4_0_0);
|
||||
const int index = std::max(0, generation - pkg1::KeyGeneration_4_0_0);
|
||||
se::SetEncryptedAesKey128(slot, pkg1::AesKeySlot_RandomForKeyStorageWrap, GetDeviceMasterKeyStorage(index), se::AesBlockSize);
|
||||
}
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ namespace ams::secmon {
|
|||
}
|
||||
|
||||
uintptr_t MapSmcUserPage(uintptr_t address) {
|
||||
if (g_smc_user_page_physical_address != 0) {
|
||||
if (g_smc_user_page_physical_address == 0) {
|
||||
if (!(MemoryRegionDram.GetAddress() <= address && address <= MemoryRegionDramHigh.GetEndAddress() - MemoryRegionVirtualSmcUserPage.GetSize())) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace ams::secmon::smc {
|
|||
namespace {
|
||||
|
||||
constexpr inline auto AesKeySize = se::AesBlockSize;
|
||||
constexpr inline size_t CmacSizeMax = 4_KB;
|
||||
constexpr inline size_t CmacSizeMax = 1_KB;
|
||||
|
||||
enum SealKey {
|
||||
SealKey_LoadAesKey = 0,
|
||||
|
|
|
@ -231,9 +231,48 @@ namespace ams::secmon::smc {
|
|||
return info.handler(args);
|
||||
}
|
||||
|
||||
constinit std::atomic<int> g_logged = 0;
|
||||
|
||||
constexpr int LogMin = 0x100;
|
||||
constexpr int LogMax = 0x120;
|
||||
|
||||
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 HandleSmc(int type, SmcArguments &args) {
|
||||
if (type == HandlerType_User) {
|
||||
DebugLog(args);
|
||||
}
|
||||
|
||||
/* Get the table. */
|
||||
const auto &table = GetHandlerTable(static_cast<HandlerType>(type), args.r[0]);
|
||||
|
||||
|
@ -243,6 +282,10 @@ namespace ams::secmon::smc {
|
|||
/* Set the invocation result. */
|
||||
args.r[0] = static_cast<u64>(InvokeSmcHandler(info, args));
|
||||
|
||||
if (type == HandlerType_User) {
|
||||
DebugLog(args);
|
||||
}
|
||||
|
||||
/* TODO: For debugging. Remove this when exo2 is complete. */
|
||||
#if 1
|
||||
if (args.r[0] == static_cast<u64>(SmcResult::NotImplemented)) {
|
||||
|
|
Loading…
Reference in a new issue