Build: Fix IAR build when TFM_EXCEPTION_INFO_DUMP=ON
IAR build fails if TFM_EXCEPTION_INFO_DUMP=ON is
defined. Added the missing IAR specific pragma
which solved the issue.
Signed-off-by: Dávid Házi <david.hazi@arm.com>
Change-Id: I1e92f05d6e9d7fecaedcb2b762ead09eb9a4ef99
diff --git a/platform/ext/common/exception_info.c b/platform/ext/common/exception_info.c
index 25e7e7c..f4fc17c 100644
--- a/platform/ext/common/exception_info.c
+++ b/platform/ext/common/exception_info.c
@@ -6,8 +6,9 @@
#include <string.h>
#include "tfm_arch.h"
-#include "exception_info.h"
#include "tfm_spm_log.h"
+/* "exception_info.h" must be the last include because of the IAR pragma */
+#include "exception_info.h"
struct exception_info_t {
uint32_t EXC_RETURN; /* EXC_RETURN value in LR. */
diff --git a/platform/ext/common/faults.c b/platform/ext/common/faults.c
index d9f1595..148b302 100644
--- a/platform/ext/common/faults.c
+++ b/platform/ext/common/faults.c
@@ -5,8 +5,9 @@
*
*/
#include "cmsis.h"
-#include "exception_info.h"
#include "utilities.h"
+/* "exception_info.h" must be the last include because of the IAR pragma */
+#include "exception_info.h"
void C_HardFault_Handler(void)
{
diff --git a/platform/ext/common/mpc_ppc_faults.c b/platform/ext/common/mpc_ppc_faults.c
index e1cd118..95c7d78 100644
--- a/platform/ext/common/mpc_ppc_faults.c
+++ b/platform/ext/common/mpc_ppc_faults.c
@@ -8,6 +8,7 @@
#include "cmsis.h"
#include "common_target_cfg.h"
#include "utilities.h"
+/* "exception_info.h" must be the last include because of the IAR pragma */
#include "exception_info.h"
void C_MPC_Handler(void)
diff --git a/platform/ext/target/arm/mps2/an519/faults.c b/platform/ext/target/arm/mps2/an519/faults.c
index f148e21..3f663d1 100644
--- a/platform/ext/target/arm/mps2/an519/faults.c
+++ b/platform/ext/target/arm/mps2/an519/faults.c
@@ -9,6 +9,7 @@
#include "target_cfg.h"
#include "Driver_MPC.h"
#include "utilities.h"
+/* "exception_info.h" must be the last include because of the IAR pragma */
#include "exception_info.h"
/* Import MPC driver */
diff --git a/platform/ext/target/arm/mps2/an521/faults.c b/platform/ext/target/arm/mps2/an521/faults.c
index f148e21..3f663d1 100644
--- a/platform/ext/target/arm/mps2/an521/faults.c
+++ b/platform/ext/target/arm/mps2/an521/faults.c
@@ -9,6 +9,7 @@
#include "target_cfg.h"
#include "Driver_MPC.h"
#include "utilities.h"
+/* "exception_info.h" must be the last include because of the IAR pragma */
#include "exception_info.h"
/* Import MPC driver */
diff --git a/platform/ext/target/arm/musca_b1/faults.c b/platform/ext/target/arm/musca_b1/faults.c
index a0daad4..8f5e5d1 100644
--- a/platform/ext/target/arm/musca_b1/faults.c
+++ b/platform/ext/target/arm/musca_b1/faults.c
@@ -9,8 +9,9 @@
#include "target_cfg.h"
#include "Driver_MPC.h"
#include "utilities.h"
-#include "exception_info.h"
#include "tfm_hal_platform.h"
+/* "exception_info.h" must be the last include because of the IAR pragma */
+#include "exception_info.h"
/* Import MPC driver */
extern ARM_DRIVER_MPC Driver_EFLASH0_MPC;
diff --git a/platform/ext/target/arm/musca_s1/faults.c b/platform/ext/target/arm/musca_s1/faults.c
index 40f3a15..f2658e6 100644
--- a/platform/ext/target/arm/musca_s1/faults.c
+++ b/platform/ext/target/arm/musca_s1/faults.c
@@ -9,6 +9,7 @@
#include "target_cfg.h"
#include "Driver_MPC.h"
#include "utilities.h"
+/* "exception_info.h" must be the last include because of the IAR pragma */
#include "exception_info.h"
/* Import MPC driver */
diff --git a/platform/ext/target/arm/rss/common/faults.c b/platform/ext/target/arm/rss/common/faults.c
index 6f01795..17ba26a 100644
--- a/platform/ext/target/arm/rss/common/faults.c
+++ b/platform/ext/target/arm/rss/common/faults.c
@@ -8,6 +8,7 @@
#include "cmsis.h"
#include "target_cfg.h"
#include "utilities.h"
+/* "exception_info.h" must be the last include because of the IAR pragma */
#include "exception_info.h"
void C_MPC_Handler(void)
diff --git a/platform/ext/target/nordic_nrf/common/core/faults.c b/platform/ext/target/nordic_nrf/common/core/faults.c
index 593cf68..37ff846 100644
--- a/platform/ext/target/nordic_nrf/common/core/faults.c
+++ b/platform/ext/target/nordic_nrf/common/core/faults.c
@@ -10,8 +10,9 @@
#include "cmsis.h"
#include "tfm_spm_log.h"
#include "spu.h"
-#include "exception_info.h"
#include "utilities.h"
+/* "exception_info.h" must be the last include because of the IAR pragma */
+#include "exception_info.h"
static void spu_dump_context(void)
{
diff --git a/platform/ext/target/nuvoton/common/faults.c b/platform/ext/target/nuvoton/common/faults.c
index 759e4ad..d243e55 100644
--- a/platform/ext/target/nuvoton/common/faults.c
+++ b/platform/ext/target/nuvoton/common/faults.c
@@ -9,6 +9,7 @@
#include "cmsis.h"
#include "target_cfg.h"
#include "utilities.h"
+/* "exception_info.h" must be the last include because of the IAR pragma */
#include "exception_info.h"
void C_SCU_Handler(void)
diff --git a/platform/ext/target/nxp/common/mpc_ppc_faults.c b/platform/ext/target/nxp/common/mpc_ppc_faults.c
index 5dbc409..e118f8f 100644
--- a/platform/ext/target/nxp/common/mpc_ppc_faults.c
+++ b/platform/ext/target/nxp/common/mpc_ppc_faults.c
@@ -8,8 +8,9 @@
#include "cmsis.h"
#include "utilities.h"
-#include "exception_info.h"
#include "target_cfg.h"
+/* "exception_info.h" must be the last include because of the IAR pragma */
+#include "exception_info.h"
void C_SEC_VIO_IRQHandler(void)
{
diff --git a/platform/include/exception_info.h b/platform/include/exception_info.h
index fb5e437..028120d 100644
--- a/platform/include/exception_info.h
+++ b/platform/include/exception_info.h
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2021, Nordic Semiconductor ASA. All rights reserved.
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -29,7 +30,7 @@
/* This level of indirection is needed to fully resolve exception info when it's
* a macro
*/
-#define _STRINGIFY(exception_info) #exception_info
+#define __STRINGIFY(exception_info) #exception_info
/* Store context for an exception, and print an error message with the context.
*
@@ -37,22 +38,29 @@
* other value will result in printing "Unknown".
*/
#ifdef TFM_EXCEPTION_INFO_DUMP
-#define EXCEPTION_INFO(exception_type) \
- __ASM volatile( \
- "MOV r0, lr\n" \
- "MRS r1, MSP\n" \
- "MRS r2, PSP\n" \
- "MOVS r3, #" _STRINGIFY(exception_type) "\n" \
- "BL store_and_dump_context\n" \
- )
/* Store context for an exception, then print the info.
* Call EXCEPTION_INFO() instead of calling this directly.
*/
void store_and_dump_context(uint32_t LR_in, uint32_t MSP_in, uint32_t PSP_in,
uint32_t exception_type);
-#else
-#define EXCEPTION_INFO(exception_type)
+
+/* IAR Specific */
+#if defined(__ICCARM__)
+#pragma required = store_and_dump_context
#endif
+#define EXCEPTION_INFO(exception_type) \
+ __ASM volatile( \
+ "MOV r0, lr\n" \
+ "MRS r1, MSP\n" \
+ "MRS r2, PSP\n" \
+ "MOVS r3, #" __STRINGIFY(exception_type) "\n"\
+ "BL store_and_dump_context\n" \
+ )
+
+#else /* TFM_EXCEPTION_INFO_DUMP */
+#define EXCEPTION_INFO(exception_type)
+#endif /* TFM_EXCEPTION_INFO_DUMP */
+
#endif /* __EXCEPTION_INFO_H__ */