platform: Change exception handler to use system registers
Change exception handler to use system registers instead of handler
provided information to provide active exception information to the
exception information handler.
This frees up one register argument to the store and dump function.
Change-Id: I70a29438fd5ac0bad6945588c5ae7431cd66d060
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
diff --git a/platform/ext/common/exception_info.c b/platform/ext/common/exception_info.c
index 71f7ab7..11180be 100644
--- a/platform/ext/common/exception_info.c
+++ b/platform/ext/common/exception_info.c
@@ -77,7 +77,7 @@
}
static void dump_exception_info(bool stack_error,
- struct exception_info_t *ctx)
+ const struct exception_info_t *ctx)
{
SPMLOG_DBGMSG("Here is some context for the exception:\r\n");
SPMLOG_DBGMSGVAL(" EXC_RETURN (LR): ", ctx->EXC_RETURN);
@@ -148,19 +148,17 @@
#endif
}
-static void dump_error(uint32_t error_type)
+static void dump_error(const struct exception_info_t *ctx)
{
bool stack_error = false;
SPMLOG_ERRMSG("FATAL ERROR: ");
- switch (error_type) {
- case EXCEPTION_TYPE_SECUREFAULT:
- SPMLOG_ERRMSG("SecureFault\r\n");
- break;
+ switch (ctx->VECTACTIVE) {
case EXCEPTION_TYPE_HARDFAULT:
SPMLOG_ERRMSG("HardFault\r\n");
break;
- case EXCEPTION_TYPE_MEMFAULT:
+#ifdef FAULT_STATUS_PRESENT
+ case EXCEPTION_TYPE_MEMMANAGEFAULT:
SPMLOG_ERRMSG("MemManage fault\r\n");
stack_error = true;
break;
@@ -172,17 +170,25 @@
SPMLOG_ERRMSG("UsageFault\r\n");
stack_error = true;
break;
- case EXCEPTION_TYPE_PLATFORM:
- SPMLOG_ERRMSG("Platform Exception\r\n");
+#ifdef TRUSTZONE_PRESENT
+ case EXCEPTION_TYPE_SECUREFAULT:
+ SPMLOG_ERRMSG("SecureFault\r\n");
+ break;
+#endif
+#endif
+ /* Platform specific external interrupt secure handler. */
+ default:
+ if (ctx->VECTACTIVE < 16) {
+ SPMLOG_ERRMSGVAL("Reserved Exception ", ctx->VECTACTIVE);
+ } else {
+ SPMLOG_ERRMSGVAL("Platform external interrupt (IRQn): ", ctx->VECTACTIVE - 16);
+ }
/* Depends on the platform, assume it may cause stack error */
stack_error = true;
break;
- default:
- SPMLOG_ERRMSG("Unknown\r\n");
- break;
}
- dump_exception_info(stack_error, &exception_info);
+ dump_exception_info(stack_error, ctx);
}
void tfm_exception_info_get_context(struct exception_info_t *ctx)
@@ -190,11 +196,11 @@
memcpy(ctx, &exception_info, sizeof(exception_info));
}
-void store_and_dump_context(uint32_t LR_in, uint32_t MSP_in, uint32_t PSP_in,
- uint32_t exception_type)
+void store_and_dump_context(uint32_t LR_in, uint32_t MSP_in, uint32_t PSP_in)
{
struct exception_info_t *ctx = &exception_info;
+ ctx->VECTACTIVE = SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk;
ctx->xPSR = __get_xPSR();
ctx->EXC_RETURN = LR_in;
ctx->MSP = MSP_in;
@@ -219,5 +225,5 @@
#endif
#endif
- dump_error(exception_type);
+ dump_error(ctx);
}
diff --git a/platform/ext/common/faults.c b/platform/ext/common/faults.c
index 148b302..817bbce 100644
--- a/platform/ext/common/faults.c
+++ b/platform/ext/common/faults.c
@@ -21,7 +21,7 @@
__attribute__((naked)) void HardFault_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_HARDFAULT);
+ EXCEPTION_INFO();
__ASM volatile(
"bl C_HardFault_Handler \n"
@@ -41,7 +41,7 @@
__attribute__((naked)) void MemManage_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_MEMFAULT);
+ EXCEPTION_INFO();
__ASM volatile(
"bl C_MemManage_Handler \n"
@@ -61,7 +61,7 @@
__attribute__((naked)) void BusFault_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_BUSFAULT);
+ EXCEPTION_INFO();
__ASM volatile(
"bl C_BusFault_Handler \n"
@@ -81,7 +81,7 @@
__attribute__((naked)) void SecureFault_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_SECUREFAULT);
+ EXCEPTION_INFO();
__ASM volatile(
"bl C_SecureFault_Handler \n"
@@ -96,7 +96,7 @@
__attribute__((naked)) void UsageFault_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_USAGEFAULT);
+ EXCEPTION_INFO();
__ASM volatile(
"bl C_UsageFault_Handler \n"
diff --git a/platform/ext/common/mpc_ppc_faults.c b/platform/ext/common/mpc_ppc_faults.c
index 95c7d78..f0e7880 100644
--- a/platform/ext/common/mpc_ppc_faults.c
+++ b/platform/ext/common/mpc_ppc_faults.c
@@ -25,7 +25,7 @@
__attribute__((naked)) void MPC_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL C_MPC_Handler \n"
@@ -47,7 +47,7 @@
__attribute__((naked)) void PPC_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL C_PPC_Handler \n"
diff --git a/platform/ext/target/arm/mps2/an519/faults.c b/platform/ext/target/arm/mps2/an519/faults.c
index 3f663d1..fd680c5 100644
--- a/platform/ext/target/arm/mps2/an519/faults.c
+++ b/platform/ext/target/arm/mps2/an519/faults.c
@@ -29,7 +29,7 @@
__attribute__((naked)) void MPC_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL C_MPC_Handler \n"
@@ -57,7 +57,7 @@
__attribute__((naked)) void PPC_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL C_PPC_Handler \n"
diff --git a/platform/ext/target/arm/mps2/an521/faults.c b/platform/ext/target/arm/mps2/an521/faults.c
index 3f663d1..fd680c5 100644
--- a/platform/ext/target/arm/mps2/an521/faults.c
+++ b/platform/ext/target/arm/mps2/an521/faults.c
@@ -29,7 +29,7 @@
__attribute__((naked)) void MPC_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL C_MPC_Handler \n"
@@ -57,7 +57,7 @@
__attribute__((naked)) void PPC_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL C_PPC_Handler \n"
diff --git a/platform/ext/target/arm/musca_b1/faults.c b/platform/ext/target/arm/musca_b1/faults.c
index 8f5e5d1..5b658bf 100644
--- a/platform/ext/target/arm/musca_b1/faults.c
+++ b/platform/ext/target/arm/musca_b1/faults.c
@@ -32,7 +32,7 @@
__attribute__((naked)) void MPC_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL C_MPC_Handler \n"
@@ -60,7 +60,7 @@
__attribute__((naked)) void PPC_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL C_PPC_Handler \n"
@@ -84,7 +84,7 @@
__attribute__((naked)) void NMI_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL C_NMI_Handler \n"
diff --git a/platform/ext/target/arm/musca_s1/faults.c b/platform/ext/target/arm/musca_s1/faults.c
index f2658e6..a248c40 100644
--- a/platform/ext/target/arm/musca_s1/faults.c
+++ b/platform/ext/target/arm/musca_s1/faults.c
@@ -29,7 +29,7 @@
__attribute__((naked)) void MPC_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL C_MPC_Handler \n"
@@ -57,7 +57,7 @@
__attribute__((naked)) void PPC_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL C_PPC_Handler \n"
diff --git a/platform/ext/target/arm/rss/common/faults.c b/platform/ext/target/arm/rss/common/faults.c
index 95c7d78..f0e7880 100644
--- a/platform/ext/target/arm/rss/common/faults.c
+++ b/platform/ext/target/arm/rss/common/faults.c
@@ -25,7 +25,7 @@
__attribute__((naked)) void MPC_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL C_MPC_Handler \n"
@@ -47,7 +47,7 @@
__attribute__((naked)) void PPC_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL C_PPC_Handler \n"
diff --git a/platform/ext/target/nordic_nrf/common/core/faults.c b/platform/ext/target/nordic_nrf/common/core/faults.c
index 37ff846..5d3a554 100644
--- a/platform/ext/target/nordic_nrf/common/core/faults.c
+++ b/platform/ext/target/nordic_nrf/common/core/faults.c
@@ -47,7 +47,7 @@
__attribute__((naked)) void SPU_IRQHandler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL SPU_Handler \n"
diff --git a/platform/ext/target/nordic_nrf/common/nrf5340/gcc/startup_nrf5340.c b/platform/ext/target/nordic_nrf/common/nrf5340/gcc/startup_nrf5340.c
index c164a59..ed60466 100644
--- a/platform/ext/target/nordic_nrf/common/nrf5340/gcc/startup_nrf5340.c
+++ b/platform/ext/target/nordic_nrf/common/nrf5340/gcc/startup_nrf5340.c
@@ -26,7 +26,7 @@
#include "exception_info.h"
__NO_RETURN __attribute__((naked)) void default_tfm_IRQHandler(void) {
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL default_irq_handler \n"
diff --git a/platform/ext/target/nordic_nrf/common/nrf91/gcc/startup_nrf91.c b/platform/ext/target/nordic_nrf/common/nrf91/gcc/startup_nrf91.c
index a171249..d82f6a6 100644
--- a/platform/ext/target/nordic_nrf/common/nrf91/gcc/startup_nrf91.c
+++ b/platform/ext/target/nordic_nrf/common/nrf91/gcc/startup_nrf91.c
@@ -26,7 +26,7 @@
#include "exception_info.h"
__NO_RETURN __attribute__((naked)) void default_tfm_IRQHandler(void) {
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL default_irq_handler \n"
diff --git a/platform/ext/target/nuvoton/common/faults.c b/platform/ext/target/nuvoton/common/faults.c
index d243e55..a051334 100644
--- a/platform/ext/target/nuvoton/common/faults.c
+++ b/platform/ext/target/nuvoton/common/faults.c
@@ -21,7 +21,7 @@
__attribute__((naked)) void SCU_IRQHandler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL C_SCU_Handler \n"
@@ -39,7 +39,7 @@
__attribute__((naked)) void MPC_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL C_MPC_Handler \n"
@@ -57,7 +57,7 @@
__attribute__((naked)) void PPC_Handler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL C_PPC_Handler \n"
diff --git a/platform/ext/target/nxp/common/mpc_ppc_faults.c b/platform/ext/target/nxp/common/mpc_ppc_faults.c
index e118f8f..a14ea86 100644
--- a/platform/ext/target/nxp/common/mpc_ppc_faults.c
+++ b/platform/ext/target/nxp/common/mpc_ppc_faults.c
@@ -25,7 +25,7 @@
__attribute__((naked)) void SEC_VIO_IRQHandler(void)
{
- EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);
+ EXCEPTION_INFO();
__ASM volatile(
"BL C_SEC_VIO_IRQHandler \n"