diff --git a/arch/arm/core/cortex_m/Kconfig b/arch/arm/core/cortex_m/Kconfig index 2da72c2049406..63c121eb85c1d 100644 --- a/arch/arm/core/cortex_m/Kconfig +++ b/arch/arm/core/cortex_m/Kconfig @@ -290,6 +290,16 @@ config ARMV8_M_DSP This option signifies the use of an ARMv8-M processor implementation supporting the DSP Extension. +config ARMV8_M_CDE_CP0 + bool + depends on ARMV8_M_MAINLINE + help + This option signifies the use of an ARMv8-M processor implementation + with an Arm Custom Datapath Extension (CDE) coprocessor on CP0. The + compiler is told to enable the cdecp0 feature so the CDE intrinsics + from arm_cde.h can be used. The SoC is responsible for enabling access + to the coprocessor (CPACR) before it is used. + config ARMV8_1_M_MVEI bool depends on ARMV8_1_M_MAINLINE diff --git a/cmake/compiler/clang/target_arm.cmake b/cmake/compiler/clang/target_arm.cmake index d1d51cb4d61e2..e58f993f152eb 100644 --- a/cmake/compiler/clang/target_arm.cmake +++ b/cmake/compiler/clang/target_arm.cmake @@ -2,7 +2,12 @@ set(ARM_C_FLAGS) -list(APPEND ARM_C_FLAGS -mcpu=${GCC_M_CPU}) +if(CONFIG_ARMV8_M_CDE_CP0) + # Clang takes the CDE feature on -mcpu rather than -march + list(APPEND ARM_C_FLAGS -mcpu=${GCC_M_CPU}+cdecp0) +else() + list(APPEND ARM_C_FLAGS -mcpu=${GCC_M_CPU}) +endif() if(CONFIG_COMPILER_ISA_THUMB2) list(APPEND ARM_C_FLAGS -mthumb) diff --git a/cmake/compiler/gcc/target_arm.cmake b/cmake/compiler/gcc/target_arm.cmake index 4e4523c43c579..c9971dd7c907c 100644 --- a/cmake/compiler/gcc/target_arm.cmake +++ b/cmake/compiler/gcc/target_arm.cmake @@ -2,7 +2,15 @@ set(ARM_C_FLAGS) -list(APPEND ARM_C_FLAGS -mcpu=${GCC_M_CPU}) +if(DEFINED GCC_M_ARCH) + # The CPU alone cannot express the requested architecture features + list(APPEND ARM_C_FLAGS -march=${GCC_M_ARCH}) + if(DEFINED GCC_M_TUNE) + list(APPEND ARM_C_FLAGS -mtune=${GCC_M_TUNE}) + endif() +else() + list(APPEND ARM_C_FLAGS -mcpu=${GCC_M_CPU}) +endif() if(CONFIG_COMPILER_ISA_THUMB2) list(APPEND ARM_C_FLAGS -mthumb) diff --git a/cmake/gcc-m-cpu.cmake b/cmake/gcc-m-cpu.cmake index f5117b1d4356a..e9a74bb82e64d 100644 --- a/cmake/gcc-m-cpu.cmake +++ b/cmake/gcc-m-cpu.cmake @@ -107,6 +107,25 @@ if("${ARCH}" STREQUAL "arm") else() message(FATAL_ERROR "Expected CONFIG_CPU_CORTEX_x to be defined") endif() + + if(CONFIG_ARMV8_M_CDE_CP0) + # GCC does not accept the cdecp0 feature on -mcpu, so select the + # architecture explicitly and keep the CPU for tuning. + if(CONFIG_ARMV8_1_M_MAINLINE) + set(GCC_M_ARCH armv8.1-m.main) + else() + set(GCC_M_ARCH armv8-m.main) + endif() + if(CONFIG_ARMV8_1_M_MVEF) + string(APPEND GCC_M_ARCH +mve.fp) + elseif(CONFIG_ARMV8_1_M_MVEI) + string(APPEND GCC_M_ARCH +mve) + elseif(CONFIG_ARMV8_M_DSP) + string(APPEND GCC_M_ARCH +dsp) + endif() + string(APPEND GCC_M_ARCH +cdecp0) + string(REGEX REPLACE "\\+.*" "" GCC_M_TUNE ${GCC_M_CPU}) + endif() elseif("${ARCH}" STREQUAL "arm64") if(CONFIG_CPU_CORTEX_A53) set(GCC_M_CPU cortex-a53) diff --git a/soc/ti/am13/am13e/Kconfig b/soc/ti/am13/am13e/Kconfig index d8ff981776dbd..1244641032458 100644 --- a/soc/ti/am13/am13e/Kconfig +++ b/soc/ti/am13/am13e/Kconfig @@ -7,6 +7,7 @@ config SOC_AM13E23019 select ARM select ARMV8_M_DSP + select ARMV8_M_CDE_CP0 select BUILD_OUTPUT_BIN select BUILD_OUTPUT_HEX select CPU_CORTEX_M33 diff --git a/tests/arch/arm/arm_cde_cp0/CMakeLists.txt b/tests/arch/arm/arm_cde_cp0/CMakeLists.txt new file mode 100644 index 0000000000000..5a20d22c895dd --- /dev/null +++ b/tests/arch/arm/arm_cde_cp0/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.28.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(arm_cde_cp0) + +target_sources(app PRIVATE src/main.c) diff --git a/tests/arch/arm/arm_cde_cp0/Kconfig b/tests/arch/arm/arm_cde_cp0/Kconfig new file mode 100644 index 0000000000000..d5513143aa6ca --- /dev/null +++ b/tests/arch/arm/arm_cde_cp0/Kconfig @@ -0,0 +1,12 @@ +# Copyright (c) 2026 Texas Instruments Incorporated +# SPDX-License-Identifier: Apache-2.0 + +# ARMV8_M_CDE_CP0 is normally selected by the SoC. Select it here so that the +# option can be exercised on any Armv8-M Mainline target. +config TEST_ARM_CDE_CP0 + bool "Build with the CDE coprocessor on CP0 enabled" + default y + depends on ARMV8_M_MAINLINE + select ARMV8_M_CDE_CP0 + +source "Kconfig.zephyr" diff --git a/tests/arch/arm/arm_cde_cp0/prj.conf b/tests/arch/arm/arm_cde_cp0/prj.conf new file mode 100644 index 0000000000000..9881313609aae --- /dev/null +++ b/tests/arch/arm/arm_cde_cp0/prj.conf @@ -0,0 +1 @@ +# SPDX-License-Identifier: Apache-2.0 diff --git a/tests/arch/arm/arm_cde_cp0/src/main.c b/tests/arch/arm/arm_cde_cp0/src/main.c new file mode 100644 index 0000000000000..87d751f50d235 --- /dev/null +++ b/tests/arch/arm/arm_cde_cp0/src/main.c @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2026 Texas Instruments Incorporated + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/* + * Build-only check that CONFIG_ARMV8_M_CDE_CP0 makes the compiler accept CDE + * instructions on coprocessor 0. The code is never run, since whether CP0 is + * implemented and enabled depends on the SoC. + */ + +#ifndef __ARM_FEATURE_CDE +#error "CDE is not enabled by the compiler flags" +#endif + +#if !(__ARM_FEATURE_CDE_COPROC & BIT(0)) +#error "CDE coprocessor 0 is not enabled by the compiler flags" +#endif + +int main(void) +{ + uint32_t val = __arm_cx1(0, 0); + + val = __arm_cx2(0, val, 0); + + return (int)val; +} diff --git a/tests/arch/arm/arm_cde_cp0/tests.yaml b/tests/arch/arm/arm_cde_cp0/tests.yaml new file mode 100644 index 0000000000000..a1fdc155caebe --- /dev/null +++ b/tests/arch/arm/arm_cde_cp0/tests.yaml @@ -0,0 +1,13 @@ +tests: + arch.arm.cde_cp0: + tags: + - arm + build_only: true + arch_allow: + - arm + platform_allow: + - mps2/an521/cpu0 + - mps2/an521/cpu0/ns + - mps3/corstone300/an547 + - mps4/corstone315/fvp + - lp_am13e230