From 6592744b3bd75515957e9df03e6d3e69275b5ecf Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 7 Mar 2018 04:00:19 -0800 Subject: [PATCH] Add debug region to mapped memory --- exosphere/src/memory_map.h | 4 +++- exosphere/src/panic_color.h | 2 ++ exosphere/src/smc_api.c | 9 +++++++++ exosphere/src/utils.c | 4 ++++ exosphere/src/utils.h | 2 ++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/exosphere/src/memory_map.h b/exosphere/src/memory_map.h index dbc7287d3..82f7a504f 100644 --- a/exosphere/src/memory_map.h +++ b/exosphere/src/memory_map.h @@ -31,6 +31,7 @@ #define _MMAPDEV15 ( 0x6000D000ull, 0x1000ull, true ) /* GPIO-1 - GPIO-8 */ #define _MMAPDEV16 ( 0x7000C000ull, 0x1000ull, true ) /* I2C-I2C4 */ #define _MMAPDEV17 ( 0x6000F000ull, 0x1000ull, true ) /* Exception vectors */ +#define _MMAPDEV18 ( 0x40038000ull, 0x8000ull, true ) /* DEBUG: IRAM */ /* LP0 entry ram segments (addr, size, additional attributes) */ #define _MMAPLP0ES0 ( 0x40020000ull, 0x10000ull, MMU_PTE_BLOCK_NS | ATTRIB_MEMTYPE_DEVICE ) /* Encrypted TZRAM */ @@ -79,7 +80,8 @@ #define MMIO_DEVID_GPIO 15 #define MMIO_DEVID_DTV_I2C234 16 #define MMIO_DEVID_EXCEPTION_VECTORS 17 -#define MMIO_DEVID_MAX 18 +#define MMIO_DEVID_DEBUG_IRAM 18 +#define MMIO_DEVID_MAX 19 #define LP0_ENTRY_RAM_SEGMENT_ID_ENCRYPTED_TZRAM 0 #define LP0_ENTRY_RAM_SEGMENT_ID_LP0_ENTRY_CODE 1 diff --git a/exosphere/src/panic_color.h b/exosphere/src/panic_color.h index ba42f8713..a310b139b 100644 --- a/exosphere/src/panic_color.h +++ b/exosphere/src/panic_color.h @@ -18,4 +18,6 @@ #define COLOR_E 0x03000003 #define COLOR_F 0xB6000003 +#define PANIC_REBOOT 0x20 + #endif \ No newline at end of file diff --git a/exosphere/src/smc_api.c b/exosphere/src/smc_api.c index be235010e..1f3c16b50 100644 --- a/exosphere/src/smc_api.c +++ b/exosphere/src/smc_api.c @@ -150,6 +150,8 @@ void clear_priv_smc_in_progress(void) { uint32_t (*g_smc_callback)(void *, uint64_t) = NULL; uint64_t g_smc_callback_key = 0; +static _Atomic(int) g_num_smcs_called = 0; + uint64_t try_set_smc_callback(uint32_t (*callback)(void *, uint64_t)) { uint64_t key; if (g_smc_callback_key) { @@ -198,6 +200,13 @@ void call_smc_handler(uint32_t handler_id, smc_args_t *args) { if ((smc_handler = g_smc_tables[handler_id].handlers[smc_id].handler) == NULL) { generic_panic(); } + + int num_called = atomic_fetch_add(&g_num_smcs_called, 1); + + /* DEBUG: use num_called to determine panic behavior. */ + if (num_called == 0x30) { + /* panic(COLOR_F); */ + } /* Call function. */ args->X[0] = smc_handler(args); diff --git a/exosphere/src/utils.c b/exosphere/src/utils.c index 9a59d579d..c3d43cfcc 100644 --- a/exosphere/src/utils.c +++ b/exosphere/src/utils.c @@ -36,3 +36,7 @@ __attribute__((noinline)) bool overlaps(uint64_t as, uint64_t ae, uint64_t bs, u return true; return false; } + +uintptr_t get_iram_address_for_debug(void) { + return MMIO_GET_DEVICE_ADDRESS(MMIO_DEVID_DEBUG_IRAM); +} diff --git a/exosphere/src/utils.h b/exosphere/src/utils.h index ff494351b..c0a9f7fe8 100644 --- a/exosphere/src/utils.h +++ b/exosphere/src/utils.h @@ -57,6 +57,8 @@ __attribute__ ((noreturn)) void generic_panic(void); __attribute__ ((noreturn)) void panic_predefined(uint32_t which); bool overlaps(uint64_t as, uint64_t ae, uint64_t bs, uint64_t be); +uintptr_t get_iram_address_for_debug(void); + static inline uintptr_t get_physical_address(const void *vaddr) { uintptr_t PAR; __asm__ __volatile__ ("at s1e3r, %0" :: "r"(vaddr));