mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 12:21:18 +00:00
exo: reserve a portion of iram for secure monitor debug (including code)
This commit is contained in:
parent
43ef260c66
commit
72f83ea43e
5 changed files with 34 additions and 11 deletions
|
@ -196,6 +196,11 @@ namespace ams::secmon {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Validate that the page isn't a secure monitor debug page. */
|
||||||
|
if (MemoryRegionPhysicalIramSecureMonitorDebug.Contains(address, 1)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Validate that the page is aligned. */
|
/* Validate that the page is aligned. */
|
||||||
if (!util::IsAligned(address, 4_KB)) {
|
if (!util::IsAligned(address, 4_KB)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -89,8 +89,10 @@ namespace ams::secmon {
|
||||||
|
|
||||||
constexpr inline const MemoryRegion MemoryRegionPhysicalIram = MemoryRegion(UINT64_C(0x40000000), 0x40000);
|
constexpr inline const MemoryRegion MemoryRegionPhysicalIram = MemoryRegion(UINT64_C(0x40000000), 0x40000);
|
||||||
constexpr inline const MemoryRegion MemoryRegionPhysicalTzram = MemoryRegion(UINT64_C(0x7C010000), 0x10000);
|
constexpr inline const MemoryRegion MemoryRegionPhysicalTzram = MemoryRegion(UINT64_C(0x7C010000), 0x10000);
|
||||||
|
constexpr inline const MemoryRegion MemoryRegionPhysicalTzramMariko = MemoryRegion(UINT64_C(0x7C010000), 0x40000);
|
||||||
static_assert(MemoryRegionPhysical.Contains(MemoryRegionPhysicalIram));
|
static_assert(MemoryRegionPhysical.Contains(MemoryRegionPhysicalIram));
|
||||||
static_assert(MemoryRegionPhysical.Contains(MemoryRegionPhysicalTzram));
|
static_assert(MemoryRegionPhysical.Contains(MemoryRegionPhysicalTzram));
|
||||||
|
static_assert(MemoryRegionPhysicalTzramMariko.Contains(MemoryRegionPhysicalTzram));
|
||||||
|
|
||||||
constexpr inline const MemoryRegion MemoryRegionPhysicalTzramVolatile(UINT64_C(0x7C010000), 0x2000);
|
constexpr inline const MemoryRegion MemoryRegionPhysicalTzramVolatile(UINT64_C(0x7C010000), 0x2000);
|
||||||
static_assert(MemoryRegionPhysicalTzram.Contains(MemoryRegionPhysicalTzramVolatile));
|
static_assert(MemoryRegionPhysicalTzram.Contains(MemoryRegionPhysicalTzramVolatile));
|
||||||
|
@ -193,6 +195,10 @@ namespace ams::secmon {
|
||||||
constexpr inline const MemoryRegion MemoryRegionVirtualTzramProgramExceptionVectors(UINT64_C(0x1F00C0000), 0x800);
|
constexpr inline const MemoryRegion MemoryRegionVirtualTzramProgramExceptionVectors(UINT64_C(0x1F00C0000), 0x800);
|
||||||
static_assert(MemoryRegionVirtualTzramProgram.Contains(MemoryRegionVirtualTzramProgramExceptionVectors));
|
static_assert(MemoryRegionVirtualTzramProgram.Contains(MemoryRegionVirtualTzramProgramExceptionVectors));
|
||||||
|
|
||||||
|
constexpr inline const MemoryRegion MemoryRegionVirtualTzramMarikoProgram(UINT64_C(0x1F00D0000), 0x20000);
|
||||||
|
constexpr inline const MemoryRegion MemoryRegionPhysicalTzramMarikoProgram(UINT64_C(0x7C020000), 0x20000);
|
||||||
|
static_assert(MemoryRegionPhysicalTzramMariko.Contains(MemoryRegionVirtualTzramMarikoProgram));
|
||||||
|
|
||||||
constexpr inline const MemoryRegion MemoryRegionVirtualTzramProgramMain(UINT64_C(0x1F00C0800), 0xB800);
|
constexpr inline const MemoryRegion MemoryRegionVirtualTzramProgramMain(UINT64_C(0x1F00C0800), 0xB800);
|
||||||
static_assert(MemoryRegionVirtualTzramProgram.Contains(MemoryRegionVirtualTzramProgramMain));
|
static_assert(MemoryRegionVirtualTzramProgram.Contains(MemoryRegionVirtualTzramProgramMain));
|
||||||
|
|
||||||
|
@ -218,6 +224,13 @@ namespace ams::secmon {
|
||||||
static_assert(MemoryRegionVirtual.Contains(MemoryRegionVirtualIramSc7Firmware));
|
static_assert(MemoryRegionVirtual.Contains(MemoryRegionVirtualIramSc7Firmware));
|
||||||
static_assert(MemoryRegionPhysicalIram.Contains(MemoryRegionPhysicalIramSc7Firmware));
|
static_assert(MemoryRegionPhysicalIram.Contains(MemoryRegionPhysicalIramSc7Firmware));
|
||||||
|
|
||||||
|
constexpr inline const MemoryRegion MemoryRegionPhysicalIramSecureMonitorDebug(UINT64_C(0x40030000), 0x8000);
|
||||||
|
static_assert(MemoryRegionPhysicalIram.Contains(MemoryRegionPhysicalIramSecureMonitorDebug));
|
||||||
|
|
||||||
|
constexpr inline const MemoryRegion MemoryRegionVirtualDebugCode = MemoryRegion(UINT64_C(0x1F0150000), 0x4000);
|
||||||
|
constexpr inline const MemoryRegion MemoryRegionPhysicalDebugCode = MemoryRegion(UINT64_C(0x40034000), 0x4000);
|
||||||
|
static_assert(MemoryRegionPhysicalIramSecureMonitorDebug.Contains(MemoryRegionPhysicalDebugCode));
|
||||||
|
|
||||||
constexpr inline const MemoryRegion MemoryRegionVirtualDebug = MemoryRegion(UINT64_C(0x1F0160000), 0x10000);
|
constexpr inline const MemoryRegion MemoryRegionVirtualDebug = MemoryRegion(UINT64_C(0x1F0160000), 0x10000);
|
||||||
static_assert(MemoryRegionVirtual.Contains(MemoryRegionVirtualDebug));
|
static_assert(MemoryRegionVirtual.Contains(MemoryRegionVirtualDebug));
|
||||||
|
|
||||||
|
@ -233,6 +246,11 @@ namespace ams::secmon {
|
||||||
static_assert(MemoryRegionVirtual.Contains(MemoryRegionVirtualDramSecureDataStore));
|
static_assert(MemoryRegionVirtual.Contains(MemoryRegionVirtualDramSecureDataStore));
|
||||||
static_assert(MemoryRegionDram.Contains(MemoryRegionPhysicalDramSecureDataStore));
|
static_assert(MemoryRegionDram.Contains(MemoryRegionPhysicalDramSecureDataStore));
|
||||||
|
|
||||||
|
constexpr inline const MemoryRegion MemoryRegionVirtualDramDebugDataStore = MemoryRegion(UINT64_C(0x1F0110000), 0x4000);
|
||||||
|
constexpr inline const MemoryRegion MemoryRegionPhysicalDramDebugDataStore = MemoryRegion( UINT64_C(0x8000C000), 0x4000);
|
||||||
|
static_assert(MemoryRegionVirtual.Contains(MemoryRegionVirtualDramSecureDataStore));
|
||||||
|
static_assert(MemoryRegionDram.Contains(MemoryRegionPhysicalDramSecureDataStore));
|
||||||
|
|
||||||
constexpr inline const MemoryRegion MemoryRegionVirtualDramSecureDataStoreTzram = MemoryRegion(UINT64_C(0x1F0100000), 0xE000);
|
constexpr inline const MemoryRegion MemoryRegionVirtualDramSecureDataStoreTzram = MemoryRegion(UINT64_C(0x1F0100000), 0xE000);
|
||||||
constexpr inline const MemoryRegion MemoryRegionVirtualDramSecureDataStoreWarmbootFirmware = MemoryRegion(UINT64_C(0x1F010E000), 0x17C0);
|
constexpr inline const MemoryRegion MemoryRegionVirtualDramSecureDataStoreWarmbootFirmware = MemoryRegion(UINT64_C(0x1F010E000), 0x17C0);
|
||||||
constexpr inline const MemoryRegion MemoryRegionVirtualDramSecureDataStoreSecurityEngineState = MemoryRegion(UINT64_C(0x1F010F7C0), 0x0840);
|
constexpr inline const MemoryRegion MemoryRegionVirtualDramSecureDataStoreSecurityEngineState = MemoryRegion(UINT64_C(0x1F010F7C0), 0x0840);
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace ams::mitm::bpc {
|
||||||
constexpr uintptr_t IramBase = 0x40000000ull;
|
constexpr uintptr_t IramBase = 0x40000000ull;
|
||||||
constexpr uintptr_t IramPayloadBase = 0x40010000ull;
|
constexpr uintptr_t IramPayloadBase = 0x40010000ull;
|
||||||
constexpr size_t IramSize = 0x40000;
|
constexpr size_t IramSize = 0x40000;
|
||||||
constexpr size_t IramPayloadMaxSize = 0x2E000;
|
constexpr size_t IramPayloadMaxSize = 0x20000;
|
||||||
|
|
||||||
/* Helper enum. */
|
/* Helper enum. */
|
||||||
enum class RebootType : u32 {
|
enum class RebootType : u32 {
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace ams::boot {
|
||||||
constexpr uintptr_t IramBase = 0x40000000ull;
|
constexpr uintptr_t IramBase = 0x40000000ull;
|
||||||
constexpr uintptr_t IramPayloadBase = 0x40010000ull;
|
constexpr uintptr_t IramPayloadBase = 0x40010000ull;
|
||||||
constexpr size_t IramSize = 0x40000;
|
constexpr size_t IramSize = 0x40000;
|
||||||
constexpr size_t IramPayloadMaxSize = 0x2E000;
|
constexpr size_t IramPayloadMaxSize = 0x20000;
|
||||||
|
|
||||||
/* Globals. */
|
/* Globals. */
|
||||||
alignas(os::MemoryPageSize) u8 g_work_page[os::MemoryPageSize];
|
alignas(os::MemoryPageSize) u8 g_work_page[os::MemoryPageSize];
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
|
||||||
#define IRAM_PAYLOAD_MAX_SIZE 0x2F000
|
#define IRAM_PAYLOAD_MAX_SIZE 0x20000
|
||||||
#define IRAM_PAYLOAD_BASE 0x40010000
|
#define IRAM_PAYLOAD_BASE 0x40010000
|
||||||
|
|
||||||
static alignas(0x1000) u8 g_reboot_payload[IRAM_PAYLOAD_MAX_SIZE];
|
static alignas(0x1000) u8 g_reboot_payload[IRAM_PAYLOAD_MAX_SIZE];
|
||||||
|
@ -13,7 +13,7 @@ static alignas(0x1000) u8 g_work_page[0x1000];
|
||||||
|
|
||||||
void do_iram_dram_copy(void *buf, uintptr_t iram_addr, size_t size, int option) {
|
void do_iram_dram_copy(void *buf, uintptr_t iram_addr, size_t size, int option) {
|
||||||
memcpy(g_work_page, buf, size);
|
memcpy(g_work_page, buf, size);
|
||||||
|
|
||||||
SecmonArgs args = {0};
|
SecmonArgs args = {0};
|
||||||
args.X[0] = 0xF0000201; /* smcAmsIramCopy */
|
args.X[0] = 0xF0000201; /* smcAmsIramCopy */
|
||||||
args.X[1] = (uintptr_t)g_work_page; /* DRAM Address */
|
args.X[1] = (uintptr_t)g_work_page; /* DRAM Address */
|
||||||
|
@ -21,7 +21,7 @@ void do_iram_dram_copy(void *buf, uintptr_t iram_addr, size_t size, int option)
|
||||||
args.X[3] = size; /* Copy size */
|
args.X[3] = size; /* Copy size */
|
||||||
args.X[4] = option; /* 0 = Read, 1 = Write */
|
args.X[4] = option; /* 0 = Read, 1 = Write */
|
||||||
svcCallSecureMonitor(&args);
|
svcCallSecureMonitor(&args);
|
||||||
|
|
||||||
memcpy(buf, g_work_page, size);
|
memcpy(buf, g_work_page, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,18 +42,18 @@ static void clear_iram(void) {
|
||||||
|
|
||||||
static void reboot_to_payload(void) {
|
static void reboot_to_payload(void) {
|
||||||
clear_iram();
|
clear_iram();
|
||||||
|
|
||||||
for (size_t i = 0; i < IRAM_PAYLOAD_MAX_SIZE; i += 0x1000) {
|
for (size_t i = 0; i < IRAM_PAYLOAD_MAX_SIZE; i += 0x1000) {
|
||||||
copy_to_iram(IRAM_PAYLOAD_BASE + i, &g_reboot_payload[i], 0x1000);
|
copy_to_iram(IRAM_PAYLOAD_BASE + i, &g_reboot_payload[i], 0x1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
splSetConfig((SplConfigItem)65001, 2);
|
splSetConfig((SplConfigItem)65001, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
consoleInit(NULL);
|
consoleInit(NULL);
|
||||||
|
|
||||||
bool can_reboot = true;
|
bool can_reboot = true;
|
||||||
Result rc = splInitialize();
|
Result rc = splInitialize();
|
||||||
if (R_FAILED(rc)) {
|
if (R_FAILED(rc)) {
|
||||||
|
@ -70,7 +70,7 @@ int main(int argc, char **argv)
|
||||||
printf("Press [-] to reboot to payload\n");
|
printf("Press [-] to reboot to payload\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Press [L] to exit\n");
|
printf("Press [L] to exit\n");
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
|
@ -89,7 +89,7 @@ int main(int argc, char **argv)
|
||||||
if (can_reboot && kDown & KEY_MINUS) {
|
if (can_reboot && kDown & KEY_MINUS) {
|
||||||
reboot_to_payload();
|
reboot_to_payload();
|
||||||
}
|
}
|
||||||
if (kDown & KEY_L) { break; } // break in order to return to hbmenu
|
if (kDown & KEY_L) { break; } // break in order to return to hbmenu
|
||||||
|
|
||||||
consoleUpdate(NULL);
|
consoleUpdate(NULL);
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ int main(int argc, char **argv)
|
||||||
if (can_reboot) {
|
if (can_reboot) {
|
||||||
splExit();
|
splExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
consoleExit(NULL);
|
consoleExit(NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue