build: Add IAR FPU support
Signed-off-by: Dávid Házi <david.hazi@arm.com>
Change-Id: I395609b9f02d928fcf547f3b9072264b2527b57a
diff --git a/config/cp_check.cmake b/config/cp_check.cmake
index a36be20..17ad4bc 100644
--- a/config/cp_check.cmake
+++ b/config/cp_check.cmake
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2022-2023, Arm Limited. All rights reserved.
+# Copyright (c) 2022-2024, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -26,7 +26,6 @@
########################## FPU and MVE #########################################
tfm_invalid_config(NOT CMAKE_C_COMPILER_ID STREQUAL "GNU" AND (CONFIG_TFM_ENABLE_MVE OR CONFIG_TFM_ENABLE_MVE_FP))
-tfm_invalid_config((NOT CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_C_COMPILER_ID STREQUAL "ARMClang") AND CONFIG_TFM_ENABLE_FP)
tfm_invalid_config((NOT CONFIG_TFM_FP_ARCH) AND (CONFIG_TFM_ENABLE_FP OR CONFIG_TFM_ENABLE_MVE_FP))
tfm_invalid_config((CMAKE_C_COMPILER_ID STREQUAL "ARMClang") AND (NOT CONFIG_TFM_FP_ARCH_ASM) AND CONFIG_TFM_ENABLE_FP)
tfm_invalid_config((NOT CONFIG_TFM_ENABLE_FP AND NOT CONFIG_TFM_ENABLE_MVE AND NOT CONFIG_TFM_ENABLE_MVE_FP) AND CONFIG_TFM_LAZY_STACKING)
@@ -54,12 +53,20 @@
RESULT_VARIABLE ret
ERROR_VARIABLE err
)
- else()
+ elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
execute_process (
COMMAND ${CMAKE_C_COMPILER} -mfix-cmse-cve-2021-35465 -S ${CMAKE_CURRENT_BINARY_DIR}/cvetest.c -o ${CMAKE_CURRENT_BINARY_DIR}/cvetest.s
RESULT_VARIABLE ret
ERROR_VARIABLE err
)
+ elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
+ execute_process (
+ COMMAND ${CMAKE_C_COMPILER} --enable_hardware_workaround fix-cmse-cve-2021-35465 ${CMAKE_CURRENT_BINARY_DIR}/cvetest.c -o ${CMAKE_CURRENT_BINARY_DIR}/cvetest.s
+ RESULT_VARIABLE ret
+ ERROR_VARIABLE err
+ )
+ else()
+ message(FATAL_ERROR "Unsupported compiler.")
endif()
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/cvetest.c)
# Check result
diff --git a/platform/ext/common/test_interrupt.c b/platform/ext/common/test_interrupt.c
index 5a49f9c..c0b7fa6 100644
--- a/platform/ext/common/test_interrupt.c
+++ b/platform/ext/common/test_interrupt.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, Arm Limited. All rights reserved.
+ * Copyright (c) 2022-2024, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -97,7 +97,7 @@
* If LR.BIT[6] equals 1, the interrupt is triggerred by secure thread.
*/
"ands r0, lr, #0x40 \n"
- "cmp r0, 0x40 \n"
+ "cmp r0, #0x40 \n"
"bne change_regs \n"
"push {r7, lr} \n"
"vpush {s0-s15} \n"
@@ -109,7 +109,7 @@
"vpop {s0-s15} \n"
"pop {r7, lr} \n"
"cmp r0, #0 \n"
- "bne panic \n"
+ "bne.w panic \n"
"change_regs: \n"
"mov r0, #0x000000E0 \n"
"vmov s0, r0 \n"
diff --git a/platform/ns/toolchain_ns_IARARM.cmake b/platform/ns/toolchain_ns_IARARM.cmake
index 9c99f67..f8d0385 100644
--- a/platform/ns/toolchain_ns_IARARM.cmake
+++ b/platform/ns/toolchain_ns_IARARM.cmake
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2023, Arm Limited. All rights reserved.
+# Copyright (c) 2023-2024, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -42,7 +42,6 @@
$<$<COMPILE_LANGUAGE:C,CXX>:-D_NO_DEFINITIONS_IN_HEADER_FILES>
$<$<COMPILE_LANGUAGE:C,CXX>:--diag_suppress=Pe546,Pe940,Pa082,Pa084>
$<$<COMPILE_LANGUAGE:C,CXX>:--no_path_in_file_macros>
- "$<$<COMPILE_LANGUAGE:C,CXX,ASM>:SHELL:--fpu none>"
$<$<AND:$<COMPILE_LANGUAGE:C,CXX,ASM>,$<BOOL:${TFM_DEBUG_SYMBOLS}>,$<CONFIG:Release,MinSizeRel>>:-r>
)
endmacro()
@@ -55,7 +54,6 @@
--semihosting
--redirect __write=__write_buffered
--diag_suppress=lp005
- "SHELL:--fpu none"
)
endmacro()
@@ -102,6 +100,26 @@
" cores with IAR version between 9.20 and 9.32.1")
endif()
+ if (CONFIG_TFM_FLOAT_ABI STREQUAL "hard")
+ if (CONFIG_TFM_ENABLE_FP)
+ set(COMPILER_CP_C_FLAG "--fpu=${CONFIG_TFM_FP_ARCH_ASM}")
+ set(COMPILER_CP_ASM_FLAG "--fpu=${CONFIG_TFM_FP_ARCH_ASM}")
+ # armasm and armlink have the same option "--fpu" and are both used to
+ # specify the target FPU architecture. So the supported FPU architecture
+ # names can be shared by armasm and armlink.
+ set(LINKER_CP_OPTION "--fpu=${CONFIG_TFM_FP_ARCH_ASM}")
+ endif()
+ else()
+ set(COMPILER_CP_C_FLAG "--fpu=none")
+ set(COMPILER_CP_ASM_FLAG "--fpu=none")
+ set(LINKER_CP_OPTION "--fpu=none")
+ endif()
+
+ string(APPEND CMAKE_C_FLAGS " " ${COMPILER_CP_C_FLAG})
+ string(APPEND CMAKE_ASM_FLAGS " " ${COMPILER_CP_ASM_FLAG})
+ string(APPEND CMAKE_C_LINK_FLAGS " " ${LINKER_CP_OPTION})
+ string(APPEND CMAKE_ASM_LINK_FLAGS " " ${LINKER_CP_OPTION})
+
endmacro()
# Configure environment for the compiler setup run by cmake at the first
diff --git a/secure_fw/partitions/ns_agent_tz/ns_agent_tz.c b/secure_fw/partitions/ns_agent_tz/ns_agent_tz.c
index 70730b9..5ff9881 100644
--- a/secure_fw/partitions/ns_agent_tz/ns_agent_tz.c
+++ b/secure_fw/partitions/ns_agent_tz/ns_agent_tz.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021-2023, Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2024, Arm Limited. All rights reserved.
* Copyright (c) 2023 Cypress Semiconductor Corporation (an Infineon
* company) or an affiliate of Cypress Semiconductor Corporation. All rights
* reserved.
@@ -23,7 +23,15 @@
" cmp r2, r3 \n"
" bne ns_agent_nspe_jump_panic \n"
#if (CONFIG_TFM_FLOAT_ABI > 0)
- " vscclrm {s0-s31, vpr} \n"
+/* 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
" mov r1, #0 \n"
" vmsr fpscr_nzcvqc, r1 \n"
" mrs r1, control \n"
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 5bde22d..2763d81 100644
--- a/secure_fw/spm/core/arch/tfm_arch_v8m_main.c
+++ b/secure_fw/spm/core/arch/tfm_arch_v8m_main.c
@@ -322,11 +322,7 @@
| FPU_FPCCR_LSPENS_Msk;
/* Prevent non-secure from modifying FPU’s power setting. */
-#if defined(__ARM_ARCH_8_1M_MAIN__) && defined(ICB)
ICB->CPPWR |= SCnSCB_CPPWR_SUS11_Msk | SCnSCB_CPPWR_SUS10_Msk;
-#else
- SCnSCB->CPPWR |= SCnSCB_CPPWR_SUS11_Msk | SCnSCB_CPPWR_SUS10_Msk;
-#endif
#endif /* CONFIG_TFM_FLOAT_ABI >= 1 */
#if defined(__ARM_ARCH_8_1M_MAIN__)
diff --git a/toolchain_IARARM.cmake b/toolchain_IARARM.cmake
index 7c711a6..ba14c16 100644
--- a/toolchain_IARARM.cmake
+++ b/toolchain_IARARM.cmake
@@ -46,7 +46,6 @@
$<$<COMPILE_LANGUAGE:C,CXX>:-D_NO_DEFINITIONS_IN_HEADER_FILES>
$<$<COMPILE_LANGUAGE:C,CXX>:--diag_suppress=Pe546,Pe940,Pa082,Pa084>
$<$<COMPILE_LANGUAGE:C,CXX>:--no_path_in_file_macros>
- "$<$<COMPILE_LANGUAGE:C,CXX,ASM>:SHELL:--fpu none>"
$<$<AND:$<COMPILE_LANGUAGE:C,CXX,ASM>,$<BOOL:${TFM_DEBUG_SYMBOLS}>,$<CONFIG:Release,MinSizeRel>>:-r>
)
endmacro()
@@ -59,7 +58,6 @@
--semihosting
--redirect __write=__write_buffered
--diag_suppress=lp005,Lp023
- "SHELL:--fpu none"
)
endmacro()
@@ -121,6 +119,29 @@
$<$<COMPILE_LANGUAGE:ASM>:--fpu=none>
)
set(BL1_LINKER_CP_OPTION --fpu=none)
+
+ if (CONFIG_TFM_FLOAT_ABI STREQUAL "hard")
+ set(COMPILER_CP_FLAG
+ $<$<COMPILE_LANGUAGE:C>:-mfloat-abi=hard>
+ )
+
+ if (CONFIG_TFM_ENABLE_FP)
+ set(COMPILER_CP_FLAG
+ $<$<COMPILE_LANGUAGE:C>:--fpu=${CONFIG_TFM_FP_ARCH_ASM}>
+ $<$<COMPILE_LANGUAGE:ASM>:--fpu=${CONFIG_TFM_FP_ARCH_ASM}>
+ )
+ # armasm and armlink have the same option "--fpu" and are both used to
+ # specify the target FPU architecture. So the supported FPU architecture
+ # names can be shared by armasm and armlink.
+ set(LINKER_CP_OPTION --fpu=${CONFIG_TFM_FP_ARCH_ASM})
+ endif()
+ else()
+ set(COMPILER_CP_FLAG
+ $<$<COMPILE_LANGUAGE:C>:--fpu=none>
+ $<$<COMPILE_LANGUAGE:ASM>:--fpu=none>
+ )
+ set(LINKER_CP_OPTION --fpu=none)
+ endif()
endmacro()
# Configure environment for the compiler setup run by cmake at the first