Skip to content

Commit c16f233

Browse files
committed
cmake: arcmwdt: riscv: derive ccac flags from Kconfig
- Add arcmwdt RISC-V core/ISA mapping in target_riscv.cmake * Select series core flag from SoC Kconfig: -av5rmx/-av5rhx * Map RISC-V Kconfig to ccac -Z flags (M/A/C/Zicsr/Zifencei/Zicntr) * Handle compressed logic correctly: -Zc or individual Zc* sub-extensions * Add F/D and compressed FPU (-Zf/-Zd, -Zcf/-Zcd) * Add -Zmmul when M is not selected and ZMMUL is enabled - Keep early compiler checks stable by not pushing -Z into CMAKE_REQUIRED_F CMAKE_REQUIRED_FLAGS - Leave non-RISC-V handling unchanged; include target_riscv.cmake from arcm arcmwdt target Signed-off-by: Afonso Oliveira <[email protected]>
1 parent a03159e commit c16f233

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

cmake/compiler/arcmwdt/target.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,8 @@ endif()
6363
# The MWDT compiler doesn't need to pass any properties to the linker as for now
6464
function(compiler_set_linker_properties)
6565
endfunction()
66+
67+
# Include architecture-specific settings
68+
if("${ARCH}" STREQUAL "riscv")
69+
include(${CMAKE_CURRENT_LIST_DIR}/target_riscv.cmake)
70+
endif()
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
# CCAC/MetaWare (MWDT) RISC-V target configuration
4+
5+
# Derive core (e.g. -av5rmx) and ISA feature flags (-Z*)
6+
# Strictly from SoC Kconfig booleans (no board heuristics).
7+
if(CONFIG_SOC_SERIES_RMX)
8+
set(ARCMWDT_RISCV_CORE -av5rmx)
9+
elseif(CONFIG_SOC_SERIES_RHX)
10+
set(ARCMWDT_RISCV_CORE -av5rhx)
11+
endif()
12+
13+
if(NOT ARCMWDT_RISCV_CORE)
14+
message(FATAL_ERROR "MWDT: Unable to determine ARC-V series from SoC Kconfig (expect CONFIG_SOC_SERIES_RMX or CONFIG_SOC_SERIES_RHX, etc.).")
15+
endif()
16+
17+
# Translate Zephyr RISC-V ISA Kconfig options to MWDT (ccac) flags
18+
set(ARCMWDT_RISCV_ISA_FLAGS)
19+
20+
# Base ISA extensions
21+
if(CONFIG_RISCV_ISA_EXT_M)
22+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zm)
23+
endif()
24+
25+
if(CONFIG_RISCV_ISA_EXT_A)
26+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Za)
27+
endif()
28+
29+
# System and fence extensions
30+
if(CONFIG_RISCV_ISA_EXT_ZICSR)
31+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zicsr)
32+
endif()
33+
34+
if(CONFIG_RISCV_ISA_EXT_ZIFENCEI)
35+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zifencei)
36+
endif()
37+
38+
# Base counters/timers
39+
if(CONFIG_RISCV_ISA_EXT_ZICNTR)
40+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zicntr)
41+
endif()
42+
43+
# Floating point
44+
if(CONFIG_RISCV_ISA_EXT_F)
45+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zf)
46+
endif()
47+
48+
if(CONFIG_RISCV_ISA_EXT_D)
49+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zd)
50+
endif()
51+
52+
# Bitmanip extensions
53+
if(CONFIG_RISCV_ISA_EXT_ZBA)
54+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zba)
55+
endif()
56+
57+
if(CONFIG_RISCV_ISA_EXT_ZBB)
58+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zbb)
59+
endif()
60+
61+
if(CONFIG_RISCV_ISA_EXT_ZBC)
62+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zbc)
63+
endif()
64+
65+
if(CONFIG_RISCV_ISA_EXT_ZBS)
66+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zbs)
67+
endif()
68+
69+
# Compressed ISA and sub-extensions
70+
# If full C is selected, use -Zc and add compressed FPU sub-exts as selected.
71+
if(CONFIG_RISCV_ISA_EXT_C)
72+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zc)
73+
if(CONFIG_RISCV_ISA_EXT_ZCF)
74+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zcf)
75+
endif()
76+
if(CONFIG_RISCV_ISA_EXT_ZCD)
77+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zcd)
78+
endif()
79+
else()
80+
if(CONFIG_RISCV_ISA_EXT_ZCA)
81+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zca)
82+
endif()
83+
if(CONFIG_RISCV_ISA_EXT_ZCB)
84+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zcb)
85+
endif()
86+
if(CONFIG_RISCV_ISA_EXT_ZCD)
87+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zcd)
88+
endif()
89+
if(CONFIG_RISCV_ISA_EXT_ZCF)
90+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zcf)
91+
endif()
92+
if(CONFIG_RISCV_ISA_EXT_ZCMP)
93+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zcmp)
94+
endif()
95+
if(CONFIG_RISCV_ISA_EXT_ZCMT)
96+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zcmt)
97+
endif()
98+
endif()
99+
100+
# Multiply-only (when M is not selected)
101+
if(NOT CONFIG_RISCV_ISA_EXT_M AND CONFIG_RISCV_ISA_EXT_ZMMUL)
102+
list(APPEND ARCMWDT_RISCV_ISA_FLAGS -Zmmul)
103+
endif()
104+
105+
# Apply derived flags
106+
if(ARCMWDT_RISCV_CORE)
107+
list(APPEND TOOLCHAIN_C_FLAGS ${ARCMWDT_RISCV_CORE})
108+
list(APPEND TOOLCHAIN_LD_FLAGS ${ARCMWDT_RISCV_CORE})
109+
endif()
110+
111+
if(ARCMWDT_RISCV_ISA_FLAGS)
112+
list(APPEND TOOLCHAIN_C_FLAGS ${ARCMWDT_RISCV_ISA_FLAGS})
113+
list(APPEND TOOLCHAIN_LD_FLAGS ${ARCMWDT_RISCV_ISA_FLAGS})
114+
endif()

0 commit comments

Comments
 (0)