iar: Fix v8.1m arch check
IAR has a different architecture defines than GCC and Armclang.
CMSIS headers have these definitions, but you always have to
include the cmsis_compilers.h file to activate it, but nothing forces it.
To have these definitions in all cases, I've added the global
defines for every supported architectures.
The CMSIS patch is upstreamed to the CMSIS6 repo as a PR.
Signed-off-by: Dávid Házi <david.hazi@arm.com>
Change-Id: Iaaee265f77f23507168df9b46884d0b7d3818bea
diff --git a/lib/ext/cmsis/0001-iar-Add-missing-v8.1m-check.patch b/lib/ext/cmsis/0001-iar-Add-missing-v8.1m-check.patch
new file mode 100644
index 0000000..5b69e31
--- /dev/null
+++ b/lib/ext/cmsis/0001-iar-Add-missing-v8.1m-check.patch
@@ -0,0 +1,29 @@
+From 7aa79a3f45bcf1ef34181b96245a9cb1fc5ae95e Mon Sep 17 00:00:00 2001
+From: Dávid Házi <david.hazi@arm.com>
+Date: Thu, 25 Apr 2024 09:53:10 +0200
+Subject: [PATCH] iar: Add missing v8.1m check
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Signed-off-by: Dávid Házi <david.hazi@arm.com>
+---
+ CMSIS/Core/Include/m-profile/cmsis_iccarm_m.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/CMSIS/Core/Include/m-profile/cmsis_iccarm_m.h b/CMSIS/Core/Include/m-profile/cmsis_iccarm_m.h
+index 4fe09f20..c726cecf 100644
+--- a/CMSIS/Core/Include/m-profile/cmsis_iccarm_m.h
++++ b/CMSIS/Core/Include/m-profile/cmsis_iccarm_m.h
+@@ -77,7 +77,7 @@
+
+ /* Alternativ core deduction for older ICCARM's */
+ #if !defined(__ARM_ARCH_6M__) && !defined(__ARM_ARCH_7M__) && !defined(__ARM_ARCH_7EM__) && \
+- !defined(__ARM_ARCH_8M_BASE__) && !defined(__ARM_ARCH_8M_MAIN__)
++ !defined(__ARM_ARCH_8M_BASE__) && !defined(__ARM_ARCH_8M_MAIN__) && !defined(__ARM_ARCH_8_1M_MAIN__)
+ #if defined(__ARM6M__) && (__CORE__ == __ARM6M__)
+ #define __ARM_ARCH_6M__ 1
+ #elif defined(__ARM7M__) && (__CORE__ == __ARM7M__)
+--
+2.40.1
+
diff --git a/platform/ns/toolchain_ns_IARARM.cmake b/platform/ns/toolchain_ns_IARARM.cmake
index f8d0385..53ccde3 100644
--- a/platform/ns/toolchain_ns_IARARM.cmake
+++ b/platform/ns/toolchain_ns_IARARM.cmake
@@ -120,6 +120,14 @@
string(APPEND CMAKE_C_LINK_FLAGS " " ${LINKER_CP_OPTION})
string(APPEND CMAKE_ASM_LINK_FLAGS " " ${LINKER_CP_OPTION})
+ add_compile_definitions(
+ $<$<STREQUAL:${TFM_SYSTEM_ARCHITECTURE},armv6-m>:__ARM_ARCH_6M__=1>
+ $<$<STREQUAL:${TFM_SYSTEM_ARCHITECTURE},armv7-m>:__ARM_ARCH_7M__=1>
+ $<$<AND:$<STREQUAL:${TFM_SYSTEM_ARCHITECTURE},armv7-m>,$<BOOL:__ARM_FEATURE_DSP>>:__ARM_ARCH_7EM__=1>
+ $<$<STREQUAL:${TFM_SYSTEM_ARCHITECTURE},armv8-m.base>:__ARM_ARCH_8M_BASE__=1>
+ $<$<STREQUAL:${TFM_SYSTEM_ARCHITECTURE},armv8-m.main>:__ARM_ARCH_8M_MAIN__=1>
+ $<$<STREQUAL:${TFM_SYSTEM_ARCHITECTURE},armv8.1-m.main>:__ARM_ARCH_8_1M_MAIN__=1>
+ )
endmacro()
# Configure environment for the compiler setup run by cmake at the first
diff --git a/secure_fw/spm/core/arch/tfm_arch_v8m_main.c b/secure_fw/spm/core/arch/tfm_arch_v8m_main.c
index 1ed2233..0dc4c8c 100644
--- a/secure_fw/spm/core/arch/tfm_arch_v8m_main.c
+++ b/secure_fw/spm/core/arch/tfm_arch_v8m_main.c
@@ -342,7 +342,15 @@
"eor r0, r0, r0 \n"
"vmsr fpscr, r0 \n"
#if (defined(__ARM_ARCH_8_1M_MAIN__))
+/* IAR throws an error if the S0-S31 syntax is used.
+ * Splitting the command into two parts solved the issue.
+ */
+#if defined(__ICCARM__)
+ "vscclrm {s0-s30,vpr} \n"
+ "vscclrm {s31,vpr} \n"
+#else
"vscclrm {s0-s31,vpr} \n"
+#endif
#else
"vmov s0, r0 \n"
"vmov s1, r0 \n"
diff --git a/toolchain_IARARM.cmake b/toolchain_IARARM.cmake
index ba14c16..d8daffd 100644
--- a/toolchain_IARARM.cmake
+++ b/toolchain_IARARM.cmake
@@ -142,6 +142,15 @@
)
set(LINKER_CP_OPTION --fpu=none)
endif()
+
+ add_compile_definitions(
+ $<$<STREQUAL:${TFM_SYSTEM_ARCHITECTURE},armv6-m>:__ARM_ARCH_6M__=1>
+ $<$<STREQUAL:${TFM_SYSTEM_ARCHITECTURE},armv7-m>:__ARM_ARCH_7M__=1>
+ $<$<AND:$<STREQUAL:${TFM_SYSTEM_ARCHITECTURE},armv7-m>,$<BOOL:__ARM_FEATURE_DSP>>:__ARM_ARCH_7EM__=1>
+ $<$<STREQUAL:${TFM_SYSTEM_ARCHITECTURE},armv8-m.base>:__ARM_ARCH_8M_BASE__=1>
+ $<$<STREQUAL:${TFM_SYSTEM_ARCHITECTURE},armv8-m.main>:__ARM_ARCH_8M_MAIN__=1>
+ $<$<STREQUAL:${TFM_SYSTEM_ARCHITECTURE},armv8.1-m.main>:__ARM_ARCH_8_1M_MAIN__=1>
+ )
endmacro()
# Configure environment for the compiler setup run by cmake at the first