xref: /optee_os/core/arch/riscv/riscv.mk (revision 8e17e072793b1d3c3a89eb7c43ce8288a17ba945)
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
84ifeq ($(CFG_RISCV_SBI_MPXY_RPMI),y)
85$(call force,CFG_RISCV_SBI_MPXY,y)
86endif
87
88# 'y' to let M-mode secure monitor handle the communication between OP-TEE OS
89# and untrusted domain.
90CFG_RISCV_WITH_M_MODE_SM ?= n
91ifeq ($(CFG_RISCV_WITH_M_MODE_SM),y)
92$(call force,CFG_RISCV_SBI,y)
93endif
94
95# Disable unsupported and other arch-specific flags
96$(call force,CFG_CORE_FFA,n)
97$(call force,CFG_SECURE_PARTITION,n)
98$(call force,CFG_PAGED_USER_TA,n)
99$(call force,CFG_WITH_PAGER,n)
100$(call force,CFG_GIC,n)
101$(call force,CFG_ARM_GICV3,n)
102$(call force,CFG_WITH_VFP,n)
103$(call force,CFG_WITH_STMM_SP,n)
104$(call force,CFG_TA_BTI,n)
105
106# Enable generic timer
107$(call force,CFG_CORE_HAS_GENERIC_TIMER,y)
108
109core-platform-cppflags	+= -I$(arch-dir)/include
110core-platform-subdirs += \
111	$(addprefix $(arch-dir)/, kernel mm tee) $(platform-dir)
112
113# Default values for "-mcmodel" compiler flag
114riscv-platform-mcmodel ?= medany
115
116ifeq ($(CFG_RV64_core),y)
117ISA_BASE = rv64ima
118ABI_BASE = lp64
119else
120ISA_BASE = rv32ima
121ABI_BASE = ilp32
122endif
123ifeq ($(CFG_RISCV_FPU),y)
124ISA_D = fd
125ABI_D = d
126endif
127ifeq ($(CFG_RISCV_ISA_C),y)
128ISA_C = c
129endif
130ifeq ($(CFG_RISCV_ISA_ZBB),y)
131ISA_ZBB = _zbb
132endif
133
134riscv-isa = $(ISA_BASE)$(ISA_D)$(ISA_C)$(ISA_ZBB)_zicsr_zifencei
135riscv-abi = $(ABI_BASE)$(ABI_D)
136
137rv64-platform-cflags += -mcmodel=$(riscv-platform-mcmodel)
138rv64-platform-cflags += -march=$(riscv-isa) -mabi=$(riscv-abi)
139rv64-platform-cflags += -Wno-missing-include-dirs
140rv32-platform-cflags += -mcmodel=$(riscv-platform-mcmodel)
141rv32-platform-cflags += -march=$(riscv-isa) -mabi=$(riscv-abi)
142
143rv64-platform-cppflags += -DRV64=1 -D__LP64__=1
144rv32-platform-cppflags += -DRV32=1 -D__ILP32__=1
145
146platform-cflags-generic ?= -ffunction-sections -fdata-sections -pipe
147platform-aflags-generic ?= -pipe -march=$(riscv-isa) -mabi=$(riscv-abi)
148
149rv64-platform-cflags-generic := -mstrict-align $(call cc-option,)
150
151# Optimize for size by default, usually gives good performance too
152CFG_CC_OPT_LEVEL ?= 0
153platform-cflags-optimization ?= -O$(CFG_CC_OPT_LEVEL)
154
155CFG_DEBUG_INFO ?= y
156ifeq ($(CFG_DEBUG_INFO),y)
157platform-cflags-debug-info ?= -g3
158platform-aflags-debug-info ?= -g
159endif
160
161core-platform-cflags += $(platform-cflags-optimization)
162core-platform-cflags += $(platform-cflags-generic)
163core-platform-cflags += $(platform-cflags-debug-info)
164
165core-platform-aflags += $(platform-aflags-generic)
166core-platform-aflags += $(platform-aflags-debug-info)
167
168ifeq ($(CFG_CORE_ASLR),y)
169core-platform-cflags += -fpie
170endif
171
172ifeq ($(CFG_UNWIND),y)
173core-platform-cppflags += -fno-omit-frame-pointer
174core-platform-cflags += -fno-omit-frame-pointer
175endif
176
177ifeq ($(CFG_RV64_core),y)
178core-platform-cppflags += $(rv64-platform-cppflags)
179core-platform-cflags += $(rv64-platform-cflags)
180core-platform-cflags += $(rv64-platform-cflags-generic)
181core-platform-cflags += $(rv64-platform-cflags-no-hard-float)
182core-platform-aflags += $(rv64-platform-aflags)
183else
184core-platform-cppflags += $(rv32-platform-cppflags)
185core-platform-cflags += $(rv32-platform-cflags)
186core-platform-cflags += $(rv32-platform-cflags-no-hard-float)
187ifeq ($(CFG_UNWIND),y)
188core-platform-cflags += -funwind-tables
189endif
190core-platform-aflags += $(core_rv32-platform-aflags)
191core-platform-aflags += $(rv32-platform-aflags)
192endif
193
194# Provide default supported-ta-targets if not set by the platform config
195ifeq (,$(supported-ta-targets))
196supported-ta-targets = ta_rv32
197ifeq ($(CFG_RV64_core),y)
198supported-ta-targets += ta_rv64
199endif
200endif
201
202ta-targets := $(if $(CFG_USER_TA_TARGETS),$(filter $(supported-ta-targets),$(CFG_USER_TA_TARGETS)),$(supported-ta-targets))
203unsup-targets := $(filter-out $(ta-targets),$(CFG_USER_TA_TARGETS))
204ifneq (,$(unsup-targets))
205$(error CFG_USER_TA_TARGETS contains unsupported value(s): $(unsup-targets). Valid values: $(supported-ta-targets))
206endif
207
208ifneq ($(filter ta_rv32,$(ta-targets)),)
209# Variables for ta-target/sm "ta_rv32"
210CFG_RV32_ta_rv32 := y
211arch-bits-ta_rv32 := 32
212ta_rv32-platform-cppflags += $(rv32-platform-cppflags)
213ta_rv32-platform-cflags += $(rv32-platform-cflags)
214ta_rv32-platform-cflags += $(platform-cflags-optimization)
215ta_rv32-platform-cflags += $(platform-cflags-debug-info)
216ta_rv32-platform-cflags += -fpic
217
218ifeq ($(CFG_UNWIND),y)
219ta_rv32-platform-cflags += -fno-omit-frame-pointer
220ta_rv32-platform-cflags += -funwind-tables
221endif
222ta_rv32-platform-aflags += $(platform-aflags-generic)
223ta_rv32-platform-aflags += $(platform-aflags-debug-info)
224ta_rv32-platform-aflags += $(rv32-platform-aflags)
225
226ta_rv32-platform-cxxflags += -fpic
227ta_rv32-platform-cxxflags += $(rv32-platform-cxxflags)
228ta_rv32-platform-cxxflags += $(platform-cflags-optimization)
229ta_rv32-platform-cxxflags += $(platform-cflags-debug-info)
230
231ta-mk-file-export-vars-ta_rv32 += CFG_RV32_ta_rv32
232ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-cppflags
233ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-cflags
234ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-aflags
235ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-cxxflags
236
237ta-mk-file-export-add-ta_rv32 += CROSS_COMPILE ?= riscv32-unknown-linux-gnu-_nl_
238ta-mk-file-export-add-ta_rv32 += CROSS_COMPILE32 ?= $$(CROSS_COMPILE)_nl_
239ta-mk-file-export-add-ta_rv32 += CROSS_COMPILE_ta_rv32 ?= $$(CROSS_COMPILE32)_nl_
240ta-mk-file-export-add-ta_rv32 += COMPILER ?= gcc_nl_
241ta-mk-file-export-add-ta_rv32 += COMPILER_ta_rv32 ?= $$(COMPILER)_nl_
242ta-mk-file-export-add-ta_rv32 += PYTHON3 ?= python3_nl_
243endif
244
245ifneq ($(filter ta_rv64,$(ta-targets)),)
246# Variables for ta-target/sm "ta_rv64"
247CFG_RV64_ta_rv64 := y
248arch-bits-ta_rv64 := 64
249ta_rv64-platform-cppflags += $(rv64-platform-cppflags)
250ta_rv64-platform-cflags += $(rv64-platform-cflags)
251ta_rv64-platform-cflags += $(platform-cflags-optimization)
252ta_rv64-platform-cflags += $(platform-cflags-debug-info)
253ta_rv64-platform-cflags += -fpic
254ta_rv64-platform-cflags += $(rv64-platform-cflags-generic)
255ifeq ($(CFG_UNWIND),y)
256ta_rv64-platform-cflags += -fno-omit-frame-pointer
257endif
258ifeq ($(rv64-platform-hard-float-enabled),y)
259ta_rv64-platform-cflags += $(rv64-platform-cflags-hard-float)
260else
261ta_rv64-platform-cflags += $(rv64-platform-cflags-no-hard-float)
262endif
263ta_rv64-platform-aflags += $(platform-aflags-generic)
264ta_rv64-platform-aflags += $(platform-aflags-debug-info)
265ta_rv64-platform-aflags += $(rv64-platform-aflags)
266
267ta_rv64-platform-cxxflags += -fpic
268ta_rv64-platform-cxxflags += $(platform-cflags-optimization)
269ta_rv64-platform-cxxflags += $(platform-cflags-debug-info)
270
271ta-mk-file-export-vars-ta_rv64 += CFG_RV64_ta_rv64
272ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-cppflags
273ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-cflags
274ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-aflags
275ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-cxxflags
276
277ta-mk-file-export-add-ta_rv64 += CROSS_COMPILE64 ?= $$(CROSS_COMPILE)_nl_
278ta-mk-file-export-add-ta_rv64 += CROSS_COMPILE_ta_rv64 ?= $$(CROSS_COMPILE64)_nl_
279ta-mk-file-export-add-ta_rv64 += COMPILER ?= gcc_nl_
280ta-mk-file-export-add-ta_rv64 += COMPILER_ta_rv64 ?= $$(COMPILER)_nl_
281ta-mk-file-export-add-ta_rv64 += PYTHON3 ?= python3_nl_
282endif
283
284# Set cross compiler prefix for each TA target
285$(foreach sm, $(ta-targets), $(eval CROSS_COMPILE_$(sm) ?= $(CROSS_COMPILE$(arch-bits-$(sm)))))
286