From 7fef83885f7e233c647429bf5955bbe499856e65 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 26 Apr 2019 07:25:38 -0700 Subject: [PATCH] ams: improve fatal error context --- fusee/fusee-primary/src/panic.c | 5 ++++- fusee/fusee-primary/src/panic.h | 14 ++++++++++++-- .../source/bpc_mitm/bpcmitm_reboot_manager.cpp | 10 +++++----- stratosphere/libstratosphere | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/fusee/fusee-primary/src/panic.c b/fusee/fusee-primary/src/panic.c index 706955ced..be7b8d35d 100644 --- a/fusee/fusee-primary/src/panic.c +++ b/fusee/fusee-primary/src/panic.c @@ -41,6 +41,8 @@ static const char *get_error_desc_str(uint32_t error_desc) { return "SError"; case 0x301: return "Bad SVC"; + case 0xFFE: + return "std::abort() called"; default: return "Unknown"; } @@ -48,7 +50,8 @@ static const char *get_error_desc_str(uint32_t error_desc) { static void _check_and_display_atmosphere_fatal_error(void) { /* Check for valid magic. */ - if (ATMOSPHERE_FATAL_ERROR_CONTEXT->magic != ATMOSPHERE_REBOOT_TO_FATAL_MAGIC) { + if (ATMOSPHERE_FATAL_ERROR_CONTEXT->magic != ATMOSPHERE_REBOOT_TO_FATAL_MAGIC && + ATMOSPHERE_FATAL_ERROR_CONTEXT->magic != ATMOSPHERE_REBOOT_TO_FATAL_MAGIC_0) { return; } diff --git a/fusee/fusee-primary/src/panic.h b/fusee/fusee-primary/src/panic.h index 27d1f4982..1f6654f30 100644 --- a/fusee/fusee-primary/src/panic.h +++ b/fusee/fusee-primary/src/panic.h @@ -28,6 +28,10 @@ #define PANIC_CODE_SAFEMODE 0x00000020 + +#define AMS_FATAL_ERROR_MAX_STACKTRACE 0x20 +#define AMS_FATAL_ERROR_MAX_STACKDUMP 0x100 + /* Atmosphere reboot-to-fatal-error. */ typedef struct { uint32_t magic; @@ -43,17 +47,23 @@ typedef struct { }; }; uint64_t pc; - uint64_t padding; + uint64_t module_base; uint32_t pstate; uint32_t afsr0; uint32_t afsr1; uint32_t esr; uint64_t far; uint64_t report_identifier; /* Normally just system tick. */ + uint64_t stack_trace_size; + uint64_t stack_dump_size; + uint64_t stack_trace[AMS_FATAL_ERROR_MAX_STACKTRACE]; + uint8_t stack_dump[AMS_FATAL_ERROR_MAX_STACKDUMP]; } atmosphere_fatal_error_ctx; +/* "AFE1" */ +#define ATMOSPHERE_REBOOT_TO_FATAL_MAGIC 0x31454641 /* "AFE0" */ -#define ATMOSPHERE_REBOOT_TO_FATAL_MAGIC 0x30454641 +#define ATMOSPHERE_REBOOT_TO_FATAL_MAGIC_0 0x30454641 #define ATMOSPHERE_FATAL_ERROR_CONTEXT ((volatile atmosphere_fatal_error_ctx *)(0x4003E000)) diff --git a/stratosphere/ams_mitm/source/bpc_mitm/bpcmitm_reboot_manager.cpp b/stratosphere/ams_mitm/source/bpc_mitm/bpcmitm_reboot_manager.cpp index 4c6c71d66..98f37bcf1 100644 --- a/stratosphere/ams_mitm/source/bpc_mitm/bpcmitm_reboot_manager.cpp +++ b/stratosphere/ams_mitm/source/bpc_mitm/bpcmitm_reboot_manager.cpp @@ -101,11 +101,6 @@ Result BpcRebootManager::PerformReboot() { } void BpcRebootManager::RebootForFatalError(AtmosphereFatalErrorContext *ctx) { - /* If we don't actually have a payload loaded, just go to RCM. */ - if (!g_payload_loaded) { - RebootToRcm(); - } - /* Ensure clean IRAM state. */ ClearIram(); @@ -118,5 +113,10 @@ void BpcRebootManager::RebootForFatalError(AtmosphereFatalErrorContext *ctx) { memcpy(g_work_page, ctx, sizeof(*ctx)); CopyToIram(IRAM_PAYLOAD_BASE + IRAM_PAYLOAD_MAX_SIZE, g_work_page, sizeof(g_work_page)); + /* If we don't actually have a payload loaded, just go to RCM. */ + if (!g_payload_loaded) { + RebootToRcm(); + } + RebootToIramPayload(); } \ No newline at end of file diff --git a/stratosphere/libstratosphere b/stratosphere/libstratosphere index 63fc847f8..9dfe7709d 160000 --- a/stratosphere/libstratosphere +++ b/stratosphere/libstratosphere @@ -1 +1 @@ -Subproject commit 63fc847f8ae43b173a9031071eebb76a1961c41c +Subproject commit 9dfe7709d950ef440548b123e43ea69ce52684b4