From ee07eba5696c2796de97257f84d7ccf89d0f6a81 Mon Sep 17 00:00:00 2001 From: Filip Kokosinski Date: Wed, 15 Jan 2025 11:44:10 +0100 Subject: [PATCH] arch/riscv: add Zaamo and Zlrsc extension subsets The Zaamo and Zalrsc Extension (Version v1.0.0, 2024-04-25; Ratified) split the standard A extension into two subextensions. As of date, the `_zaamo` and `_zlrsc` extension specifications are accepted by the upstream in-development GCC through the `march` argument. This means that those subextensions are not yet supported by GCC shipped with Zephyr SDK. Signed-off-by: Filip Kokosinski --- arch/riscv/Kconfig.isa | 16 ++++++++++++++++ cmake/compiler/gcc/target_riscv.cmake | 14 +++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/arch/riscv/Kconfig.isa b/arch/riscv/Kconfig.isa index 70599843c48..7ac915865d1 100644 --- a/arch/riscv/Kconfig.isa +++ b/arch/riscv/Kconfig.isa @@ -33,6 +33,8 @@ config RISCV_ISA_EXT_M config RISCV_ISA_EXT_A bool + imply RISCV_ISA_EXT_ZAAMO + imply RISCV_ISA_EXT_ZLRSC help (A) - Standard Extension for Atomic Instructions @@ -111,6 +113,20 @@ config RISCV_ISA_EXT_ZIFENCEI provides explicit synchronization between writes to instruction memory and instruction fetches on the same hart. +config RISCV_ISA_EXT_ZAAMO + bool + help + (Zaamo) - Atomic memory operation subset of the A extension + + The Zaamo extension enables support for AMO*.W/D-style instructions. + +config RISCV_ISA_EXT_ZLRSC + bool + help + (Zlrsc) - Load-Reserved/Store-Conditional subset of the A extension + + The Zlrsc extension enables support for LR.W/D and SC.W/D-style instructions. + config RISCV_ISA_EXT_ZBA bool help diff --git a/cmake/compiler/gcc/target_riscv.cmake b/cmake/compiler/gcc/target_riscv.cmake index a297a772886..74d12d04c79 100644 --- a/cmake/compiler/gcc/target_riscv.cmake +++ b/cmake/compiler/gcc/target_riscv.cmake @@ -53,6 +53,18 @@ if(CONFIG_RISCV_ISA_EXT_ZIFENCEI) string(CONCAT riscv_march ${riscv_march} "_zifencei") endif() +# Check whether we already imply Zaamo/Zlrsc by selecting the A extension; if not - check them +# individually and enable them as needed +if(NOT CONFIG_RISCV_ISA_EXT_A) + if(CONFIG_RISCV_ISA_EXT_ZAAMO) + string(CONCAT riscv_march ${riscv_march} "_zaamo") + endif() + + if(CONFIG_RISCV_ISA_EXT_ZLRSC) + string(CONCAT riscv_march ${riscv_march} "_zlrsc") + endif() +endif() + if(CONFIG_RISCV_ISA_EXT_ZBA) string(CONCAT riscv_march ${riscv_march} "_zba") endif() @@ -90,4 +102,4 @@ set(LLEXT_APPEND_FLAGS -mabi=${riscv_mabi} -march=${riscv_march} -mno-relax -) \ No newline at end of file +)