aboutsummaryrefslogtreecommitdiff
path: root/pw_cpu_exception_cortex_m/util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'pw_cpu_exception_cortex_m/util.cc')
-rw-r--r--pw_cpu_exception_cortex_m/util.cc31
1 files changed, 28 insertions, 3 deletions
diff --git a/pw_cpu_exception_cortex_m/util.cc b/pw_cpu_exception_cortex_m/util.cc
index ff817b34f..fc2925288 100644
--- a/pw_cpu_exception_cortex_m/util.cc
+++ b/pw_cpu_exception_cortex_m/util.cc
@@ -115,10 +115,10 @@ void LogExceptionAnalysis(const pw_cpu_exception_State& cpu_state) {
}
#if _PW_ARCH_ARM_V8M_MAINLINE
if (cpu_state.extended.cfsr & kCfsrStkofMask) {
- if (cpu_state.extended.exc_return & kExcReturnStackMask) {
- PW_LOG_CRITICAL("Encountered stack overflow in thread mode");
+ if (ProcessStackActive(cpu_state)) {
+ PW_LOG_CRITICAL("Encountered process stack overflow (psp)");
} else {
- PW_LOG_CRITICAL("Encountered main (interrupt handler) stack overflow");
+ PW_LOG_CRITICAL("Encountered main stack overflow (msp)");
}
}
#endif // _PW_ARCH_ARM_V8M_MAINLINE
@@ -150,4 +150,29 @@ void LogExceptionAnalysis(const pw_cpu_exception_State& cpu_state) {
#endif // PW_CPU_EXCEPTION_CORTEX_M_EXTENDED_CFSR_DUMP
}
+ProcessorMode ActiveProcessorMode(const pw_cpu_exception_State& cpu_state) {
+ // See ARMv7-M Architecture Reference Manual Section B1.5.8 for the exception
+ // return values, in particular bits 0:3.
+ // Bits 0:3 of EXC_RETURN:
+ // 0b0001 - 0x1 Handler mode Main
+ // 0b1001 - 0x9 Thread mode Main
+ // 0b1101 - 0xD Thread mode Process
+ // ^
+ if (cpu_state.extended.exc_return & kExcReturnModeMask) {
+ return ProcessorMode::kThreadMode;
+ }
+ return ProcessorMode::kHandlerMode;
+}
+
+bool MainStackActive(const pw_cpu_exception_State& cpu_state) {
+ // See ARMv7-M Architecture Reference Manual Section B1.5.8 for the exception
+ // return values, in particular bits 0:3.
+ // Bits 0:3 of EXC_RETURN:
+ // 0b0001 - 0x1 Handler mode Main
+ // 0b1001 - 0x9 Thread mode Main
+ // 0b1101 - 0xD Thread mode Process
+ // ^
+ return (cpu_state.extended.exc_return & kExcReturnStackMask) == 0;
+}
+
} // namespace pw::cpu_exception::cortex_m