xref: /optee_os/core/arch/riscv/riscv.mk (revision fab37ad7dc719c507661870039f7bcf91f5a6029)
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)
17
18ifeq ($(CFG_RV64_core),y)
19CFG_KERN_LINKER_FORMAT ?= elf64-littleriscv
20CFG_KERN_LINKER_ARCH ?= riscv
21else
22ifeq ($(CFG_RV32_core),y)
23CFG_KERN_LINKER_FORMAT ?= elf32-littleriscv
24CFG_KERN_LINKER_ARCH ?= riscv
25else
26$(error Error: CFG_RV64_core or CFG_RV32_core should be defined)
27endif
28endif
29
30CFG_CORE_RWDATA_NOEXEC ?= y
31CFG_CORE_RODATA_NOEXEC ?= n
32ifeq ($(CFG_CORE_RODATA_NOEXEC),y)
33$(call force,CFG_CORE_RWDATA_NOEXEC,y)
34endif
35
36CFG_MAX_CACHE_LINE_SHIFT ?= 6
37
38# CFG_WITH_LPAE is ARM-related flag, however, it is used by core code.
39# In order to maintain the code logic, we set it when CFG_CORE_LARGE_PHYS_ADDR is set.
40# Platform configuration should accordingly set CFG_CORE_LARGE_PHYS_ADDR or not.
41ifeq ($(CFG_CORE_LARGE_PHYS_ADDR),y)
42$(call force,CFG_WITH_LPAE,y)
43endif
44
45CFG_RISCV_SBI	 ?= n
46CFG_RISCV_M_MODE ?= y
47ifeq ($(CFG_RISCV_M_MODE),y)
48ifeq ($(CFG_RISCV_S_MODE),y)
49$(error CFG_RISCV_M_MODE and CFG_RISCV_S_MODE cannot be both 'y')
50else
51$(call force,CFG_RISCV_S_MODE,n)
52$(call force,CFG_RISCV_SBI,n)
53endif
54endif
55ifeq ($(CFG_RISCV_S_MODE),y)
56$(call force,CFG_RISCV_M_MODE,n)
57endif
58ifneq (y,$(call cfg-one-enabled,CFG_RISCV_M_MODE M CFG_RISCV_S_MODE))
59$(error Either CFG_RISCV_M_MODE or CFG_RISCV_S_MODE must be 'y')
60endif
61
62ifeq ($(CFG_RISCV_SBI_CONSOLE),y)
63$(call force,CFG_RISCV_SBI,y)
64endif
65
66# Disable unsupported and other arch-specific flags
67$(call force,CFG_CORE_FFA,n)
68$(call force,CFG_SECURE_PARTITION,n)
69$(call force,CFG_PAGED_USER_TA,n)
70$(call force,CFG_WITH_PAGER,n)
71$(call force,CFG_GIC,n)
72$(call force,CFG_ARM_GICV3,n)
73$(call force,CFG_WITH_VFP,n)
74$(call force,CFG_WITH_STMM_SP,n)
75$(call force,CFG_TA_BTI,n)
76
77# Enable generic timer
78$(call force,CFG_CORE_HAS_GENERIC_TIMER,y)
79
80core-platform-cppflags	+= -I$(arch-dir)/include
81core-platform-subdirs += \
82	$(addprefix $(arch-dir)/, kernel mm tee) $(platform-dir)
83
84# Default values for "-mcmodel", "-march", and "-abi" compiler flags.
85# Platform-specific overrides are in core/arch/riscv/plat-*/conf.mk.
86riscv-platform-mcmodel ?= medany
87rv64-platform-isa ?= rv64imafd
88rv64-platform-abi ?= lp64d
89rv32-platform-isa ?= rv32imafd
90rv32-platform-abi ?= ilp32d
91
92rv64-platform-cflags += -mcmodel=$(riscv-platform-mcmodel)
93rv64-platform-cflags += -march=$(rv64-platform-isa) -mabi=$(rv64-platform-abi)
94rv64-platform-cflags += -Wno-missing-include-dirs
95rv32-platform-cflags += -mcmodel=$(riscv-platform-mcmodel)
96rv32-platform-cflags += -march=$(rv32-platform-isa) -mabi=$(rv32-platform-abi)
97
98rv64-platform-cppflags += -DRV64=1 -D__LP64__=1
99rv32-platform-cppflags += -DRV32=1 -D__ILP32__=1
100
101platform-cflags-generic ?= -ffunction-sections -fdata-sections -pipe
102platform-aflags-generic ?= -pipe
103
104rv64-platform-cflags-generic := -mstrict-align $(call cc-option,)
105
106# Optimize for size by default, usually gives good performance too
107CFG_CC_OPT_LEVEL ?= 0
108platform-cflags-optimization ?= -O$(CFG_CC_OPT_LEVEL)
109
110CFG_DEBUG_INFO ?= y
111ifeq ($(CFG_DEBUG_INFO),y)
112platform-cflags-debug-info ?= -g3
113platform-aflags-debug-info ?= -g
114endif
115
116core-platform-cflags += $(platform-cflags-optimization)
117core-platform-cflags += $(platform-cflags-generic)
118core-platform-cflags += $(platform-cflags-debug-info)
119
120core-platform-aflags += $(platform-aflags-generic)
121core-platform-aflags += $(platform-aflags-debug-info)
122
123ifeq ($(CFG_CORE_ASLR),y)
124core-platform-cflags += -fpie
125endif
126
127ifeq ($(CFG_UNWIND),y)
128core-platform-cppflags += -fno-omit-frame-pointer
129core-platform-cflags += -fno-omit-frame-pointer
130endif
131
132ifeq ($(CFG_RV64_core),y)
133core-platform-cppflags += $(rv64-platform-cppflags)
134core-platform-cflags += $(rv64-platform-cflags)
135core-platform-cflags += $(rv64-platform-cflags-generic)
136core-platform-cflags += $(rv64-platform-cflags-no-hard-float)
137core-platform-aflags += $(rv64-platform-aflags)
138else
139core-platform-cppflags += $(rv32-platform-cppflags)
140core-platform-cflags += $(rv32-platform-cflags)
141core-platform-cflags += $(rv32-platform-cflags-no-hard-float)
142ifeq ($(CFG_UNWIND),y)
143core-platform-cflags += -funwind-tables
144endif
145core-platform-aflags += $(core_rv32-platform-aflags)
146core-platform-aflags += $(rv32-platform-aflags)
147endif
148
149# Provide default supported-ta-targets if not set by the platform config
150ifeq (,$(supported-ta-targets))
151supported-ta-targets = ta_rv32
152ifeq ($(CFG_RV64_core),y)
153supported-ta-targets += ta_rv64
154endif
155endif
156
157ta-targets := $(if $(CFG_USER_TA_TARGETS),$(filter $(supported-ta-targets),$(CFG_USER_TA_TARGETS)),$(supported-ta-targets))
158unsup-targets := $(filter-out $(ta-targets),$(CFG_USER_TA_TARGETS))
159ifneq (,$(unsup-targets))
160$(error CFG_USER_TA_TARGETS contains unsupported value(s): $(unsup-targets). Valid values: $(supported-ta-targets))
161endif
162
163ifneq ($(filter ta_rv32,$(ta-targets)),)
164# Variables for ta-target/sm "ta_rv32"
165CFG_RV32_ta_rv32 := y
166arch-bits-ta_rv32 := 32
167ta_rv32-platform-cppflags += $(rv32-platform-cppflags)
168ta_rv32-platform-cflags += $(rv32-platform-cflags)
169ta_rv32-platform-cflags += $(platform-cflags-optimization)
170ta_rv32-platform-cflags += $(platform-cflags-debug-info)
171ta_rv32-platform-cflags += -fpic
172
173ifeq ($(CFG_UNWIND),y)
174ta_rv32-platform-cflags += -fno-omit-frame-pointer
175ta_rv32-platform-cflags += -funwind-tables
176endif
177ta_rv32-platform-aflags += $(platform-aflags-generic)
178ta_rv32-platform-aflags += $(platform-aflags-debug-info)
179ta_rv32-platform-aflags += $(rv32-platform-aflags)
180
181ta_rv32-platform-cxxflags += -fpic
182ta_rv32-platform-cxxflags += $(rv32-platform-cxxflags)
183ta_rv32-platform-cxxflags += $(platform-cflags-optimization)
184ta_rv32-platform-cxxflags += $(platform-cflags-debug-info)
185
186ta-mk-file-export-vars-ta_rv32 += CFG_RV32_ta_rv32
187ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-cppflags
188ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-cflags
189ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-aflags
190ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-cxxflags
191
192ta-mk-file-export-add-ta_rv32 += CROSS_COMPILE ?= riscv32-unknown-linux-gnu-_nl_
193ta-mk-file-export-add-ta_rv32 += CROSS_COMPILE32 ?= $$(CROSS_COMPILE)_nl_
194ta-mk-file-export-add-ta_rv32 += CROSS_COMPILE_ta_rv32 ?= $$(CROSS_COMPILE32)_nl_
195ta-mk-file-export-add-ta_rv32 += COMPILER ?= gcc_nl_
196ta-mk-file-export-add-ta_rv32 += COMPILER_ta_rv32 ?= $$(COMPILER)_nl_
197ta-mk-file-export-add-ta_rv32 += PYTHON3 ?= python3_nl_
198endif
199
200ifneq ($(filter ta_rv64,$(ta-targets)),)
201# Variables for ta-target/sm "ta_rv64"
202CFG_RV64_ta_rv64 := y
203arch-bits-ta_rv64 := 64
204ta_rv64-platform-cppflags += $(rv64-platform-cppflags)
205ta_rv64-platform-cflags += $(rv64-platform-cflags)
206ta_rv64-platform-cflags += $(platform-cflags-optimization)
207ta_rv64-platform-cflags += $(platform-cflags-debug-info)
208ta_rv64-platform-cflags += -fpic
209ta_rv64-platform-cflags += $(rv64-platform-cflags-generic)
210ifeq ($(CFG_UNWIND),y)
211ta_rv64-platform-cflags += -fno-omit-frame-pointer
212endif
213ifeq ($(rv64-platform-hard-float-enabled),y)
214ta_rv64-platform-cflags += $(rv64-platform-cflags-hard-float)
215else
216ta_rv64-platform-cflags += $(rv64-platform-cflags-no-hard-float)
217endif
218ta_rv64-platform-aflags += $(platform-aflags-generic)
219ta_rv64-platform-aflags += $(platform-aflags-debug-info)
220ta_rv64-platform-aflags += $(rv64-platform-aflags)
221
222ta_rv64-platform-cxxflags += -fpic
223ta_rv64-platform-cxxflags += $(platform-cflags-optimization)
224ta_rv64-platform-cxxflags += $(platform-cflags-debug-info)
225
226ta-mk-file-export-vars-ta_rv64 += CFG_RV64_ta_rv64
227ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-cppflags
228ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-cflags
229ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-aflags
230ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-cxxflags
231
232ta-mk-file-export-add-ta_rv64 += CROSS_COMPILE64 ?= $$(CROSS_COMPILE)_nl_
233ta-mk-file-export-add-ta_rv64 += CROSS_COMPILE_ta_rv64 ?= $$(CROSS_COMPILE64)_nl_
234ta-mk-file-export-add-ta_rv64 += COMPILER ?= gcc_nl_
235ta-mk-file-export-add-ta_rv64 += COMPILER_ta_rv64 ?= $$(COMPILER)_nl_
236ta-mk-file-export-add-ta_rv64 += PYTHON3 ?= python3_nl_
237endif
238
239# Set cross compiler prefix for each TA target
240$(foreach sm, $(ta-targets), $(eval CROSS_COMPILE_$(sm) ?= $(CROSS_COMPILE$(arch-bits-$(sm)))))
241