Skip to content

BACKPORT: arch: arm: cortex_m: add ARMV8_M_CDE_CP0 option - #260

Open
venkatesan-krishnamoorthy wants to merge 3 commits into
TexasInstruments:v4.4.0-ti-nextfrom
venkatesan-krishnamoorthy:backport_cde_cp0
Open

venkatesan-krishnamoorthy wants to merge 3 commits into
TexasInstruments:v4.4.0-ti-nextfrom
venkatesan-krishnamoorthy:backport_cde_cp0

Conversation

@venkatesan-krishnamoorthy

Copy link
Copy Markdown

Backport of zephyrproject-rtos#125401, merged upstream on 2026-12-01.

Adds the ARMV8_M_CDE_CP0 option for SoCs with an Arm Custom Datapath Extension coprocessor on CP0, selects it for AM13, and adds a build-only test.

Upstream commits (cherry-picked unchanged, only the UPSTREAM: tag and the commit <sha> upstream. line added):

  • a96482e arch: arm: cortex_m: add ARMV8_M_CDE_CP0 option
  • 59510f9 soc: ti: am13: select ARMV8_M_CDE_CP0
  • e040823 tests: arch: arm: add build-only test for ARMV8_M_CDE_CP0

Note: the test keeps the upstream file name tests.yaml; twister on this base reads testcase.yaml.

commit a96482e upstream.

Add a Kconfig option for SoCs that implement an Arm Custom Datapath
Extension coprocessor on CP0.

GCC rejects +cdecp0 on -mcpu, so when the option is set build with
-march=armv8[.1]-m.main[+dsp|+mve|+mve.fp]+cdecp0 and -mtune set to the
CPU, via the new GCC_M_ARCH and GCC_M_TUNE variables. This applies to
any ARMv8-M Mainline CPU rather than Cortex-M33 only. Clang takes
+cdecp0 on -mcpu.

The option is not selected by any SoC yet, so there is no change in
behavior for existing targets.

Signed-off-by: Venkatesan Krishnamoorthy <v-krishnamoorthy@ti.com>
commit 59510f9 upstream.

Select ARMV8_M_CDE_CP0 so the build enables the CDE coprocessor on CP0
for this SoC.

Signed-off-by: Venkatesan Krishnamoorthy <v-krishnamoorthy@ti.com>
commit e040823 upstream.

Add a build-only test that enables ARMV8_M_CDE_CP0 through a test-local
Kconfig symbol and uses the CDE intrinsics from arm_cde.h on
coprocessor 0. The test checks __ARM_FEATURE_CDE and the coprocessor
mask at compile time, so a missing +cdecp0 in the compiler flags fails
the build.

The code is never run: whether CP0 is implemented and enabled depends
on the SoC. Built with GCC and Clang, and confirmed that the build
fails with the option disabled.

Signed-off-by: Venkatesan Krishnamoorthy <v-krishnamoorthy@ti.com>
@venkatesan-krishnamoorthy
venkatesan-krishnamoorthy requested a review from a team December 3, 2026 08:57
@qodo-code-review

qodo-code-review Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

BACKPORT: arch: arm: cortex_m: add ARMV8_M_CDE_CP0 option

✨ Enhancement ⚙️ Configuration changes 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Adds ARMV8_M_CDE_CP0 option; GCC gets -march/-mtune with +cdecp0, Clang gets -mcpu+cdecp0.
• Selects the option for the TI AM13 SoC, enabling the CDE coprocessor on CP0.
• Adds a build-only test checking CDE macros; it uses tests.yaml, which twister here ignores.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed Kconfig symbol, GCC/Clang flag paths, and AM13E selection all implement one bounded behavior: compiling ARMv8-M firmware with CDE CP0 enabled.
  • The build-only test validates this same compiler contract and does not constitute a separate production capability.
Sources

cmake/compiler/clang/target_arm.cmake[5-10]

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()

cmake/compiler/gcc/target_arm.cmake[5-13]

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()

arch/arm/core/cortex_m/Kconfig[293-301]

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.
Behavioral complexity 🟡 Medium 🧩 Compatibility cases

  • Before: ARM builds always selected -mcpu=${GCC_M_CPU}.
  • After: the CDE gate selects compiler-specific forms, preserves DSP/MVE architecture features, and separates GCC architecture selection from CPU tuning.
  • New correctness condition: each supported ARMv8-M feature combination and compiler must accept cdecp0 without losing the configured CPU or MVE/DSP features.
  • The test adds only build validation; no new runtime state or ordering protocol is introduced.
Sources

cmake/compiler/gcc/target_arm.cmake[5-13]

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()

cmake/compiler/clang/target_arm.cmake[5-10]

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()

arch/arm/core/cortex_m/Kconfig[293-301]

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.
Potential damage 🟡 Medium 🩹 Temporary loss

  • If the new compiler configuration is incorrect, CDE-using firmware can fail to compile or lose the intended CDE compiler capability.
  • Reverting the build changes restores the previous compilation behavior; no persistent state or external effect is introduced by these files.
  • Existing production code currently has no discovered CDE intrinsic caller, so this assessment does not claim a current runtime fault.
  • Rebuild after reverting or correcting the compiler configuration.
  • If a future firmware image had already been deployed with an invalid CDE execution path, firmware replacement would be required; source evidence does not show such a path in this PR.
Sources

arch/arm/core/cortex_m/Kconfig[293-301]

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.

tests/arch/arm/arm_cde_cp0/tests.yaml[1-7]

tests:
  arch.arm.cde_cp0:
    tags:
      - arm
    build_only: true
    arch_allow:
      - arm
Assessed commit 77a400d
Diagram

graph TD
A["AM13 SoC Kconfig"] --> B["ARMV8_M_CDE_CP0"] --> C["gcc-m-cpu.cmake"] --> D["GCC target flags"] --> E["Compiler CDE on CP0"]
B --> F["Clang target flags"] --> E
E --> G["Build-only test main.c"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Per-SoC compiler flags in the SoC or board CMake
  • ➕ Keeps the generic cmake code untouched
  • ➕ Scopes the change to the one SoC that needs it
  • ➖ Duplicates the arch/tune derivation for every SoC that adds CDE
  • ➖ Bypasses the Kconfig-driven selection that other options use
2. Set +cdecp0 on -mcpu for GCC as well
  • ➕ Single flag form across both toolchains
  • ➕ Simpler cmake logic
  • ➖ GCC rejects this form, so the build would fail

Recommendation: The PR's approach is sound. GCC cannot take +cdecp0 on -mcpu, so the explicit -march plus -mtune split in gcc-m-cpu.cmake is required, not optional. Keeping the option generic to ARMv8-M Mainline avoids per-SoC toolchain logic. One follow-up is worth raising: the test file is named tests.yaml, but twister on this base reads testcase.yaml, so the test may never be discovered and would silently not run.

Files changed (10) +110 / -2

Enhancement (4) +44 / -2
KconfigAdd ARMV8_M_CDE_CP0 Kconfig option +10/-0

Add ARMV8_M_CDE_CP0 Kconfig option

• Adds a hidden bool option that depends on ARMV8_M_MAINLINE. Its help text states that the SoC must enable CPACR access before using CP0.

arch/arm/core/cortex_m/Kconfig

target_arm.cmakePass +cdecp0 on -mcpu for Clang +6/-1

Pass +cdecp0 on -mcpu for Clang

• When the option is set, appends +cdecp0 to the -mcpu flag. Clang accepts the feature on -mcpu, so no other change is needed.

cmake/compiler/clang/target_arm.cmake

target_arm.cmakeUse -march and -mtune when GCC_M_ARCH is set +9/-1

Use -march and -mtune when GCC_M_ARCH is set

• Emits -march=GCC_M_ARCH and optional -mtune=GCC_M_TUNE instead of -mcpu when GCC_M_ARCH is defined. Otherwise the existing -mcpu behavior is unchanged.

cmake/compiler/gcc/target_arm.cmake

gcc-m-cpu.cmakeDerive GCC arch and tune for CDE on CP0 +19/-0

Derive GCC arch and tune for CDE on CP0

• Builds GCC_M_ARCH from the Mainline version and the MVE, DSP, or none extension, then appends +cdecp0. Sets GCC_M_TUNE to the CPU name with any +suffix stripped.

cmake/gcc-m-cpu.cmake

Tests (5) +65 / -0
CMakeLists.txtAdd CMake project for CDE CP0 build test +8/-0

Add CMake project for CDE CP0 build test

• Adds a minimal Zephyr CMake project for the test with one source file, src/main.c.

tests/arch/arm/arm_cde_cp0/CMakeLists.txt

KconfigAdd test-local Kconfig selecting ARMV8_M_CDE_CP0 +12/-0

Add test-local Kconfig selecting ARMV8_M_CDE_CP0

• Defines TEST_ARM_CDE_CP0, default y, dependent on ARMV8_M_MAINLINE, which selects ARMV8_M_CDE_CP0 so the option is exercised on any Mainline target.

tests/arch/arm/arm_cde_cp0/Kconfig

prj.confAdd empty project configuration for CDE test +1/-0

Add empty project configuration for CDE test

• Adds a prj.conf containing only the SPDX header. The test relies on the Kconfig default and needs no extra options.

tests/arch/arm/arm_cde_cp0/prj.conf

main.cAdd compile-time CDE feature checks and intrinsic calls +31/-0

Add compile-time CDE feature checks and intrinsic calls

• Uses #error guards to check __ARM_FEATURE_CDE and the CP0 bit in __ARM_FEATURE_CDE_COPROC. Calls __arm_cx1 and __arm_cx2 on coprocessor 0; the code is never run.

tests/arch/arm/arm_cde_cp0/src/main.c

tests.yamlAdd build-only test metadata, under a non-discovered filename +13/-0

Add build-only test metadata, under a non-discovered filename

• Declares build_only for arm targets on several platforms, including lp_am13e230. The file is named tests.yaml, but twister on this base reads testcase.yaml, so the test may not be discovered. Renaming it is needed to make the test run.

tests/arch/arm/arm_cde_cp0/tests.yaml

Other (1) +1 / -0
KconfigSelect ARMV8_M_CDE_CP0 for AM13E23019 +1/-0

Select ARMV8_M_CDE_CP0 for AM13E23019

• Adds a select of ARMV8_M_CDE_CP0 to the AM13E23019 SoC symbol, so the build enables CDE on CP0 for this part.

soc/ti/am13/am13e/Kconfig

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo


Action required

1. The CDE build test never enters Twister 🐞
Description
The new test manifest is named tests.yaml, whereas this branch's Twister discovery recognizes
testcase.yaml for tests. Its directory is skipped during test discovery, so neither the build nor
its compiler-feature checks run.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Twister cannot discover the new build-only test because its manifest has the wrong filename for this branch.

## Fix Focus Areas
- tests/arch/arm/arm_cde_cp0/tests.yaml[1-13]

## Recommended Fix
Rename `tests.yaml` to `testcase.yaml`, retaining its contents, and verify that Twister discovers the CDE scenario.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

2. CDE applications fault on AM13 🐞
Description
SOC_AM13E23019 selects ARMV8_M_CDE_CP0, but AM13 startup does not enable CP0 access in the
coprocessor access control register. After reset, an application that uses the newly enabled CDE
intrinsics can execute a CP0 instruction while access remains disabled.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
AM13 advertises CDE CP0 to the compiler without enabling access to CP0 before applications can use it.

## Fix Focus Areas
- soc/ti/am13/am13e/Kconfig[7-13]
- soc/ti/am13/am13e/soc.c[8-36]

## Recommended Fix
Enable the appropriate CP0 access in AM13's early startup path before CDE instructions can execute. Verify the access setting for the intended execution contexts, or defer selecting the option until startup provides that guarantee.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


View medium (1)
Remediation recommended
3. Other Arm toolchains leave CDE disabled 🐞
Description
The new compiler-feature handling covers GCC and Clang but leaves armclang and IAR generating their
existing CPU flags without enabling CP0 CDE. Builds selecting ARMV8_M_CDE_CP0 through either
toolchain therefore do not receive the promised compiler feature, and CDE-dependent source cannot
use it as configured.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Selecting the new CDE option does not enable the compiler feature when building with armclang or IAR.

## Fix Focus Areas
- cmake/compiler/armclang/target.cmake[17-29]
- cmake/compiler/iar/target.cmake[75-82]
- arch/arm/core/cortex_m/Kconfig[293-301]

## Recommended Fix
Add each toolchain's supported CDE CP0 configuration flags where available; otherwise explicitly reject the option for that toolchain rather than silently leaving the requested feature disabled.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Comment thread soc/ti/am13/am13e/Kconfig
config SOC_AM13E23019
select ARM
select ARMV8_M_DSP
select ARMV8_M_CDE_CP0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

2. Cde applications fault on am13 🐞 Bug ≡ Correctness

SOC_AM13E23019 selects ARMV8_M_CDE_CP0, but AM13 startup does not enable CP0 access in the
coprocessor access control register. After reset, an application that uses the newly enabled CDE
intrinsics can execute a CP0 instruction while access remains disabled.
Agent Prompt
## Issue description
AM13 advertises CDE CP0 to the compiler without enabling access to CP0 before applications can use it.

## Fix Focus Areas
- soc/ti/am13/am13e/Kconfig[7-13]
- soc/ti/am13/am13e/soc.c[8-36]

## Recommended Fix
Enable the appropriate CP0 access in AM13's early startup path before CDE instructions can execute. Verify the access setting for the intended execution contexts, or defer selecting the option until startup provides that guarantee.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Comment on lines +1 to +2
tests:
arch.arm.cde_cp0:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. The cde build test never enters twister 🐞 Bug ≡ Correctness

The new test manifest is named tests.yaml, whereas this branch's Twister discovery recognizes
testcase.yaml for tests. Its directory is skipped during test discovery, so neither the build nor
its compiler-feature checks run.
Agent Prompt
## Issue description
Twister cannot discover the new build-only test because its manifest has the wrong filename for this branch.

## Fix Focus Areas
- tests/arch/arm/arm_cde_cp0/tests.yaml[1-13]

## Recommended Fix
Rename `tests.yaml` to `testcase.yaml`, retaining its contents, and verify that Twister discovers the CDE scenario.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Comment on lines +293 to +296
config ARMV8_M_CDE_CP0
bool
depends on ARMV8_M_MAINLINE
help

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

3. Other arm toolchains leave cde disabled 🐞 Bug ≡ Correctness

The new compiler-feature handling covers GCC and Clang but leaves armclang and IAR generating their
existing CPU flags without enabling CP0 CDE. Builds selecting ARMV8_M_CDE_CP0 through either
toolchain therefore do not receive the promised compiler feature, and CDE-dependent source cannot
use it as configured.
Agent Prompt
## Issue description
Selecting the new CDE option does not enable the compiler feature when building with armclang or IAR.

## Fix Focus Areas
- cmake/compiler/armclang/target.cmake[17-29]
- cmake/compiler/iar/target.cmake[75-82]
- arch/arm/core/cortex_m/Kconfig[293-301]

## Recommended Fix
Add each toolchain's supported CDE CP0 configuration flags where available; otherwise explicitly reject the option for that toolchain rather than silently leaving the requested feature disabled.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant