xref: /optee_os/core/arch/riscv/riscv.mk (revision 039e02df2716a0ed886b56e1e07b7ac1d8597228)
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
36core-platform-cppflags	+= -I$(arch-dir)/include
37core-platform-subdirs += \
38	$(addprefix $(arch-dir)/, kernel) $(platform-dir)
39
40# more convenient to move it to platform instead
41rv64-platform-cppflags += -mcmodel=medany -march=rv64imafd -mabi=lp64d
42rv64-platform-cppflags += -Wno-missing-include-dirs
43
44rv64-platform-cppflags += -DRV64=1 -D__LP64__=1
45rv32-platform-cppflags += -DRV32=1 -D__ILP32__=1
46
47platform-cflags-generic ?= -ffunction-sections -fdata-sections -pipe
48platform-aflags-generic ?= -pipe
49
50rv64-platform-cflags-generic := -mstrict-align $(call cc-option,)
51
52# Optimize for size by default, usually gives good performance too
53CFG_CC_OPT_LEVEL ?= 0
54platform-cflags-optimization ?= -O$(CFG_CC_OPT_LEVEL)
55
56CFG_DEBUG_INFO ?= y
57ifeq ($(CFG_DEBUG_INFO),y)
58platform-cflags-debug-info ?= -g3
59platform-aflags-debug-info ?= -g
60endif
61
62core-platform-cflags += $(platform-cflags-optimization)
63core-platform-cflags += $(platform-cflags-generic)
64core-platform-cflags += $(platform-cflags-debug-info)
65
66core-platform-aflags += $(platform-aflags-generic)
67core-platform-aflags += $(platform-aflags-debug-info)
68
69ifeq ($(CFG_CORE_ASLR),y)
70core-platform-cflags += -fpie
71endif
72
73ifeq ($(CFG_RV64_core),y)
74core-platform-cppflags += $(rv64-platform-cppflags)
75core-platform-cflags += $(rv64-platform-cflags)
76core-platform-cflags += $(rv64-platform-cflags-generic)
77core-platform-cflags += $(rv64-platform-cflags-no-hard-float)
78core-platform-aflags += $(rv64-platform-aflags)
79else
80core-platform-cppflags += $(rv32-platform-cppflags)
81core-platform-cflags += $(rv32-platform-cflags)
82core-platform-cflags += $(rv32-platform-cflags-no-hard-float)
83ifeq ($(CFG_UNWIND),y)
84core-platform-cflags += -funwind-tables
85endif
86core-platform-aflags += $(core_rv32-platform-aflags)
87core-platform-aflags += $(rv32-platform-aflags)
88endif
89
90# Provide default supported-ta-targets if not set by the platform config
91ifeq (,$(supported-ta-targets))
92supported-ta-targets = ta_rv32
93ifeq ($(CFG_RV64_core),y)
94supported-ta-targets += ta_rv64
95endif
96endif
97
98ta-targets := $(if $(CFG_USER_TA_TARGETS),$(filter $(supported-ta-targets),$(CFG_USER_TA_TARGETS)),$(supported-ta-targets))
99unsup-targets := $(filter-out $(ta-targets),$(CFG_USER_TA_TARGETS))
100ifneq (,$(unsup-targets))
101$(error CFG_USER_TA_TARGETS contains unsupported value(s): $(unsup-targets). Valid values: $(supported-ta-targets))
102endif
103
104ifneq ($(filter ta_rv32,$(ta-targets)),)
105# Variables for ta-target/sm "ta_rv32"
106CFG_RV32_ta_rv32 := y
107arch-bits-ta_rv32 := 32
108ta_rv32-platform-cppflags += $(rv32-platform-cppflags)
109ta_rv32-platform-cflags += $(rv32-platform-cflags)
110ta_rv32-platform-cflags += $(platform-cflags-optimization)
111ta_rv32-platform-cflags += $(platform-cflags-debug-info)
112ta_rv32-platform-cflags += -fpic
113
114ifeq ($(CFG_UNWIND),y)
115ta_rv32-platform-cflags += -funwind-tables
116endif
117ta_rv32-platform-aflags += $(platform-aflags-generic)
118ta_rv32-platform-aflags += $(platform-aflags-debug-info)
119ta_rv32-platform-aflags += $(rv32-platform-aflags)
120
121ta_rv32-platform-cxxflags += -fpic
122ta_rv32-platform-cxxflags += $(rv32-platform-cxxflags)
123ta_rv32-platform-cxxflags += $(platform-cflags-optimization)
124ta_rv32-platform-cxxflags += $(platform-cflags-debug-info)
125
126ta-mk-file-export-vars-ta_rv32 += CFG_RV32_ta_rv32
127ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-cppflags
128ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-cflags
129ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-aflags
130ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-cxxflags
131
132ta-mk-file-export-add-ta_rv32 += CROSS_COMPILE ?= riscv32-unknown-linux-gnu-_nl_
133ta-mk-file-export-add-ta_rv32 += CROSS_COMPILE32 ?= $$(CROSS_COMPILE)_nl_
134ta-mk-file-export-add-ta_rv32 += CROSS_COMPILE_ta_rv32 ?= $$(CROSS_COMPILE32)_nl_
135ta-mk-file-export-add-ta_rv32 += COMPILER ?= gcc_nl_
136ta-mk-file-export-add-ta_rv32 += COMPILER_ta_rv32 ?= $$(COMPILER)_nl_
137ta-mk-file-export-add-ta_rv32 += PYTHON3 ?= python3_nl_
138endif
139
140ifneq ($(filter ta_rv64,$(ta-targets)),)
141# Variables for ta-target/sm "ta_rv64"
142CFG_RV64_ta_rv64 := y
143arch-bits-ta_rv64 := 64
144ta_rv64-platform-cppflags += $(rv64-platform-cppflags)
145ta_rv64-platform-cflags += $(rv64-platform-cflags)
146ta_rv64-platform-cflags += $(platform-cflags-optimization)
147ta_rv64-platform-cflags += $(platform-cflags-debug-info)
148ta_rv64-platform-cflags += -fpic
149ta_rv64-platform-cflags += $(rv64-platform-cflags-generic)
150ifeq ($(rv64-platform-hard-float-enabled),y)
151ta_rv64-platform-cflags += $(rv64-platform-cflags-hard-float)
152else
153ta_rv64-platform-cflags += $(rv64-platform-cflags-no-hard-float)
154endif
155ta_rv64-platform-aflags += $(platform-aflags-generic)
156ta_rv64-platform-aflags += $(platform-aflags-debug-info)
157ta_rv64-platform-aflags += $(rv64-platform-aflags)
158
159ta_rv64-platform-cxxflags += -fpic
160ta_rv64-platform-cxxflags += $(platform-cflags-optimization)
161ta_rv64-platform-cxxflags += $(platform-cflags-debug-info)
162
163ta-mk-file-export-vars-ta_rv64 += CFG_RV64_ta_rv64
164ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-cppflags
165ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-cflags
166ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-aflags
167ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-cxxflags
168
169ta-mk-file-export-add-ta_rv64 += CROSS_COMPILE64 ?= $$(CROSS_COMPILE)_nl_
170ta-mk-file-export-add-ta_rv64 += CROSS_COMPILE_ta_rv64 ?= $$(CROSS_COMPILE64)_nl_
171ta-mk-file-export-add-ta_rv64 += COMPILER ?= gcc_nl_
172ta-mk-file-export-add-ta_rv64 += COMPILER_ta_rv64 ?= $$(COMPILER)_nl_
173ta-mk-file-export-add-ta_rv64 += PYTHON3 ?= python3_nl_
174endif
175
176# Set cross compiler prefix for each TA target
177$(foreach sm, $(ta-targets), $(eval CROSS_COMPILE_$(sm) ?= $(CROSS_COMPILE$(arch-bits-$(sm)))))
178