1#-------------------------------------------------------------------------------
2# Copyright (c) 2022-2023, Arm Limited. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
8########################## FPU and MVE #########################################
9
10tfm_invalid_config(NOT CMAKE_C_COMPILER_ID STREQUAL "GNU" AND (CONFIG_TFM_ENABLE_MVE OR CONFIG_TFM_ENABLE_MVE_FP))
11tfm_invalid_config((NOT CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_C_COMPILER_ID STREQUAL "ARMClang") AND CONFIG_TFM_ENABLE_FP)
12tfm_invalid_config((NOT CONFIG_TFM_FP_ARCH) AND (CONFIG_TFM_ENABLE_FP OR CONFIG_TFM_ENABLE_MVE_FP))
13tfm_invalid_config((CMAKE_C_COMPILER_ID STREQUAL "ARMClang") AND (NOT CONFIG_TFM_FP_ARCH_ASM) AND CONFIG_TFM_ENABLE_FP)
14tfm_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)
15tfm_invalid_config((CONFIG_TFM_ENABLE_FP OR CONFIG_TFM_ENABLE_MVE OR CONFIG_TFM_ENABLE_MVE_FP) AND NOT CONFIG_TFM_ENABLE_CP10CP11)
16
17###################### Check compiler for FP vulnerability #####################
18
19# Check compiler with mitigation for the VLLDM instruction security vulnerability or not.
20# For more information, please check https://developer.arm.com/support/arm-security-updates/vlldm-instruction-security-vulnerability.
21if (CONFIG_TFM_FLOAT_ABI STREQUAL "hard")
22    # Create test C file.
23    file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cvetest.c "int x;")
24    # Compile with mitigation -mfix-cmse-cve-2021-35465.
25    if (CMAKE_C_COMPILER_ID STREQUAL "ARMClang")
26        execute_process (
27            COMMAND ${CMAKE_C_COMPILER} --target=${CROSS_COMPILE} ${CMAKE_C_FLAGS} -mcmse -mfix-cmse-cve-2021-35465 -S ${CMAKE_CURRENT_BINARY_DIR}/cvetest.c -o ${CMAKE_CURRENT_BINARY_DIR}/cvetest.s
28            RESULT_VARIABLE ret
29            ERROR_VARIABLE err
30        )
31    else()
32        execute_process (
33            COMMAND ${CMAKE_C_COMPILER} -mfix-cmse-cve-2021-35465 -S ${CMAKE_CURRENT_BINARY_DIR}/cvetest.c -o ${CMAKE_CURRENT_BINARY_DIR}/cvetest.s
34            RESULT_VARIABLE ret
35            ERROR_VARIABLE err
36        )
37    endif()
38    file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/cvetest.c)
39    # Check result
40    if(NOT ret EQUAL 0)
41        message(FATAL_ERROR "To enable FPU usage in SPE and NSPE both, please use the compiler with '-mfix-cmse-cve-2021-35465' support")
42    else()
43        file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/cvetest.s)
44    endif()
45endif()
46