xref: /optee_os/core/arch/riscv/riscv.mk (revision 00eea9243ce73ce7a191f087b0bab460b70be0d3)
1# Setup compiler for the core module
2ifeq ($(CFG_RV64_core),y)
3arch-bits-core := 64
4else
5arch-bits-core := 32
6endif
7CROSS_COMPILE_core := $(CROSS_COMPILE$(arch-bits-core))
8COMPILER_core := $(COMPILER)
9
10include mk/$(COMPILER_core).mk
11
12# Defines the cc-option macro using the compiler set for the core module
13include mk/cc-option.mk
14
15CFG_MMAP_REGIONS ?= 13
16CFG_RESERVED_VASPACE_SIZE ?= (1024 * 1024 * 10)
17CFG_NEX_DYN_VASPACE_SIZE ?= (1024 * 1024)
18CFG_TEE_DYN_VASPACE_SIZE ?= (1024 * 1024)
19
20ifeq ($(CFG_RV64_core),y)
21CFG_KERN_LINKER_FORMAT ?= elf64-littleriscv
22CFG_KERN_LINKER_ARCH ?= riscv
23else
24ifeq ($(CFG_RV32_core),y)
25CFG_KERN_LINKER_FORMAT ?= elf32-littleriscv
26CFG_KERN_LINKER_ARCH ?= riscv
27else
28$(error Error: CFG_RV64_core or CFG_RV32_core should be defined)
29endif
30endif
31
32CFG_CORE_RWDATA_NOEXEC ?= y
33CFG_CORE_RODATA_NOEXEC ?= n
34ifeq ($(CFG_CORE_RODATA_NOEXEC),y)
35$(call force,CFG_CORE_RWDATA_NOEXEC,y)
36endif
37
38CFG_MAX_CACHE_LINE_SHIFT ?= 6
39
40# CFG_WITH_LPAE is ARM-related flag, however, it is used by core code.
41# In order to maintain the code logic, we set it when CFG_CORE_LARGE_PHYS_ADDR is set.
42# Platform configuration should accordingly set CFG_CORE_LARGE_PHYS_ADDR or not.
43ifeq ($(CFG_CORE_LARGE_PHYS_ADDR),y)
44$(call force,CFG_WITH_LPAE,y)
45endif
46
47# Paged virtual-memory schemes (SvXX)
48# For RV32, the acceptable value is 32.
49# For RV64, the acceptable values are 39, 48, 57.
50CFG_RISCV_MMU_MODE ?= 39
51ifeq ($(CFG_RV64_core),y)
52$(call cfg-check-value,RISCV_MMU_MODE,39 48 57)
53else
54ifeq ($(CFG_RV32_core),y)
55$(call cfg-check-value,RISCV_MMU_MODE,32)
56endif
57endif
58
59CFG_RISCV_SBI	 ?= n
60CFG_RISCV_M_MODE ?= y
61ifeq ($(CFG_RISCV_M_MODE),y)
62ifeq ($(CFG_RISCV_S_MODE),y)
63$(error CFG_RISCV_M_MODE and CFG_RISCV_S_MODE cannot be both 'y')
64else
65$(call force,CFG_RISCV_S_MODE,n)
66$(call force,CFG_RISCV_SBI,n)
67endif
68endif
69ifeq ($(CFG_RISCV_S_MODE),y)
70$(call force,CFG_RISCV_M_MODE,n)
71endif
72ifneq (y,$(call cfg-one-enabled,CFG_RISCV_M_MODE M CFG_RISCV_S_MODE))
73$(error Either CFG_RISCV_M_MODE or CFG_RISCV_S_MODE must be 'y')
74endif
75
76ifeq ($(CFG_RISCV_SBI_CONSOLE),y)
77$(call force,CFG_RISCV_SBI,y)
78endif
79
80ifeq ($(CFG_RISCV_SBI_MPXY),y)
81$(call force,CFG_RISCV_SBI,y)
82endif
83
84# 'y' to let M-mode secure monitor handle the communication between OP-TEE OS
85# and untrusted domain.
86CFG_RISCV_WITH_M_MODE_SM ?= n
87ifeq ($(CFG_RISCV_WITH_M_MODE_SM),y)
88$(call force,CFG_RISCV_SBI,y)
89endif
90
91# Disable unsupported and other arch-specific flags
92$(call force,CFG_CORE_FFA,n)
93$(call force,CFG_SECURE_PARTITION,n)
94$(call force,CFG_PAGED_USER_TA,n)
95$(call force,CFG_WITH_PAGER,n)
96$(call force,CFG_GIC,n)
97$(call force,CFG_ARM_GICV3,n)
98$(call force,CFG_WITH_VFP,n)
99$(call force,CFG_WITH_STMM_SP,n)
100$(call force,CFG_TA_BTI,n)
101
102# Enable generic timer
103$(call force,CFG_CORE_HAS_GENERIC_TIMER,y)
104
105core-platform-cppflags	+= -I$(arch-dir)/include
106core-platform-subdirs += \
107	$(addprefix $(arch-dir)/, kernel mm tee) $(platform-dir)
108
109# Default values for "-mcmodel" compiler flag
110riscv-platform-mcmodel ?= medany
111
112ifeq ($(CFG_RV64_core),y)
113ISA_BASE = rv64ima
114ABI_BASE = lp64
115else
116ISA_BASE = rv32ima
117ABI_BASE = ilp32
118endif
119ifeq ($(CFG_RISCV_FPU),y)
120ISA_D = fd
121ABI_D = d
122endif
123ifeq ($(CFG_RISCV_ISA_C),y)
124ISA_C = c
125endif
126ifeq ($(CFG_RISCV_ISA_ZBB),y)
127ISA_ZBB = _zbb
128endif
129
130riscv-isa = $(ISA_BASE)$(ISA_D)$(ISA_C)$(ISA_ZBB)_zicsr_zifencei
131riscv-abi = $(ABI_BASE)$(ABI_D)
132
133rv64-platform-cflags += -mcmodel=$(riscv-platform-mcmodel)
134rv64-platform-cflags += -march=$(riscv-isa) -mabi=$(riscv-abi)
135rv64-platform-cflags += -Wno-missing-include-dirs
136rv32-platform-cflags += -mcmodel=$(riscv-platform-mcmodel)
137rv32-platform-cflags += -march=$(riscv-isa) -mabi=$(riscv-abi)
138
139rv64-platform-cppflags += -DRV64=1 -D__LP64__=1
140rv32-platform-cppflags += -DRV32=1 -D__ILP32__=1
141
142platform-cflags-generic ?= -ffunction-sections -fdata-sections -pipe
143platform-aflags-generic ?= -pipe -march=$(riscv-isa) -mabi=$(riscv-abi)
144
145rv64-platform-cflags-generic := -mstrict-align $(call cc-option,)
146
147# Optimize for size by default, usually gives good performance too
148CFG_CC_OPT_LEVEL ?= 0
149platform-cflags-optimization ?= -O$(CFG_CC_OPT_LEVEL)
150
151CFG_DEBUG_INFO ?= y
152ifeq ($(CFG_DEBUG_INFO),y)
153platform-cflags-debug-info ?= -g3
154platform-aflags-debug-info ?= -g
155endif
156
157core-platform-cflags += $(platform-cflags-optimization)
158core-platform-cflags += $(platform-cflags-generic)
159core-platform-cflags += $(platform-cflags-debug-info)
160
161core-platform-aflags += $(platform-aflags-generic)
162core-platform-aflags += $(platform-aflags-debug-info)
163
164ifeq ($(CFG_CORE_ASLR),y)
165core-platform-cflags += -fpie
166endif
167
168ifeq ($(CFG_UNWIND),y)
169core-platform-cppflags += -fno-omit-frame-pointer
170core-platform-cflags += -fno-omit-frame-pointer
171endif
172
173ifeq ($(CFG_RV64_core),y)
174core-platform-cppflags += $(rv64-platform-cppflags)
175core-platform-cflags += $(rv64-platform-cflags)
176core-platform-cflags += $(rv64-platform-cflags-generic)
177core-platform-cflags += $(rv64-platform-cflags-no-hard-float)
178core-platform-aflags += $(rv64-platform-aflags)
179else
180core-platform-cppflags += $(rv32-platform-cppflags)
181core-platform-cflags += $(rv32-platform-cflags)
182core-platform-cflags += $(rv32-platform-cflags-no-hard-float)
183ifeq ($(CFG_UNWIND),y)
184core-platform-cflags += -funwind-tables
185endif
186core-platform-aflags += $(core_rv32-platform-aflags)
187core-platform-aflags += $(rv32-platform-aflags)
188endif
189
190# Provide default supported-ta-targets if not set by the platform config
191ifeq (,$(supported-ta-targets))
192supported-ta-targets = ta_rv32
193ifeq ($(CFG_RV64_core),y)
194supported-ta-targets += ta_rv64
195endif
196endif
197
198ta-targets := $(if $(CFG_USER_TA_TARGETS),$(filter $(supported-ta-targets),$(CFG_USER_TA_TARGETS)),$(supported-ta-targets))
199unsup-targets := $(filter-out $(ta-targets),$(CFG_USER_TA_TARGETS))
200ifneq (,$(unsup-targets))
201$(error CFG_USER_TA_TARGETS contains unsupported value(s): $(unsup-targets). Valid values: $(supported-ta-targets))
202endif
203
204ifneq ($(filter ta_rv32,$(ta-targets)),)
205# Variables for ta-target/sm "ta_rv32"
206CFG_RV32_ta_rv32 := y
207arch-bits-ta_rv32 := 32
208ta_rv32-platform-cppflags += $(rv32-platform-cppflags)
209ta_rv32-platform-cflags += $(rv32-platform-cflags)
210ta_rv32-platform-cflags += $(platform-cflags-optimization)
211ta_rv32-platform-cflags += $(platform-cflags-debug-info)
212ta_rv32-platform-cflags += -fpic
213
214ifeq ($(CFG_UNWIND),y)
215ta_rv32-platform-cflags += -fno-omit-frame-pointer
216ta_rv32-platform-cflags += -funwind-tables
217endif
218ta_rv32-platform-aflags += $(platform-aflags-generic)
219ta_rv32-platform-aflags += $(platform-aflags-debug-info)
220ta_rv32-platform-aflags += $(rv32-platform-aflags)
221
222ta_rv32-platform-cxxflags += -fpic
223ta_rv32-platform-cxxflags += $(rv32-platform-cxxflags)
224ta_rv32-platform-cxxflags += $(platform-cflags-optimization)
225ta_rv32-platform-cxxflags += $(platform-cflags-debug-info)
226
227ta-mk-file-export-vars-ta_rv32 += CFG_RV32_ta_rv32
228ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-cppflags
229ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-cflags
230ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-aflags
231ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-cxxflags
232
233ta-mk-file-export-add-ta_rv32 += CROSS_COMPILE ?= riscv32-unknown-linux-gnu-_nl_
234ta-mk-file-export-add-ta_rv32 += CROSS_COMPILE32 ?= $$(CROSS_COMPILE)_nl_
235ta-mk-file-export-add-ta_rv32 += CROSS_COMPILE_ta_rv32 ?= $$(CROSS_COMPILE32)_nl_
236ta-mk-file-export-add-ta_rv32 += COMPILER ?= gcc_nl_
237ta-mk-file-export-add-ta_rv32 += COMPILER_ta_rv32 ?= $$(COMPILER)_nl_
238ta-mk-file-export-add-ta_rv32 += PYTHON3 ?= python3_nl_
239endif
240
241ifneq ($(filter ta_rv64,$(ta-targets)),)
242# Variables for ta-target/sm "ta_rv64"
243CFG_RV64_ta_rv64 := y
244arch-bits-ta_rv64 := 64
245ta_rv64-platform-cppflags += $(rv64-platform-cppflags)
246ta_rv64-platform-cflags += $(rv64-platform-cflags)
247ta_rv64-platform-cflags += $(platform-cflags-optimization)
248ta_rv64-platform-cflags += $(platform-cflags-debug-info)
249ta_rv64-platform-cflags += -fpic
250ta_rv64-platform-cflags += $(rv64-platform-cflags-generic)
251ifeq ($(CFG_UNWIND),y)
252ta_rv64-platform-cflags += -fno-omit-frame-pointer
253endif
254ifeq ($(rv64-platform-hard-float-enabled),y)
255ta_rv64-platform-cflags += $(rv64-platform-cflags-hard-float)
256else
257ta_rv64-platform-cflags += $(rv64-platform-cflags-no-hard-float)
258endif
259ta_rv64-platform-aflags += $(platform-aflags-generic)
260ta_rv64-platform-aflags += $(platform-aflags-debug-info)
261ta_rv64-platform-aflags += $(rv64-platform-aflags)
262
263ta_rv64-platform-cxxflags += -fpic
264ta_rv64-platform-cxxflags += $(platform-cflags-optimization)
265ta_rv64-platform-cxxflags += $(platform-cflags-debug-info)
266
267ta-mk-file-export-vars-ta_rv64 += CFG_RV64_ta_rv64
268ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-cppflags
269ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-cflags
270ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-aflags
271ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-cxxflags
272
273ta-mk-file-export-add-ta_rv64 += CROSS_COMPILE64 ?= $$(CROSS_COMPILE)_nl_
274ta-mk-file-export-add-ta_rv64 += CROSS_COMPILE_ta_rv64 ?= $$(CROSS_COMPILE64)_nl_
275ta-mk-file-export-add-ta_rv64 += COMPILER ?= gcc_nl_
276ta-mk-file-export-add-ta_rv64 += COMPILER_ta_rv64 ?= $$(COMPILER)_nl_
277ta-mk-file-export-add-ta_rv64 += PYTHON3 ?= python3_nl_
278endif
279
280# Set cross compiler prefix for each TA target
281$(foreach sm, $(ta-targets), $(eval CROSS_COMPILE_$(sm) ?= $(CROSS_COMPILE$(arch-bits-$(sm)))))
282