xref: /optee_os/core/arch/riscv/riscv.mk (revision f303c856ba0c3962d0cfb054287933952c79bc51)
17f43e5c3SMarouene Boubakri# Setup compiler for the core module
27f43e5c3SMarouene Boubakriifeq ($(CFG_RV64_core),y)
37f43e5c3SMarouene Boubakriarch-bits-core := 64
47f43e5c3SMarouene Boubakrielse
57f43e5c3SMarouene Boubakriarch-bits-core := 32
67f43e5c3SMarouene Boubakriendif
77f43e5c3SMarouene BoubakriCROSS_COMPILE_core := $(CROSS_COMPILE$(arch-bits-core))
87f43e5c3SMarouene BoubakriCOMPILER_core := $(COMPILER)
97f43e5c3SMarouene Boubakri
107f43e5c3SMarouene Boubakriinclude mk/$(COMPILER_core).mk
117f43e5c3SMarouene Boubakri
127f43e5c3SMarouene Boubakri# Defines the cc-option macro using the compiler set for the core module
137f43e5c3SMarouene Boubakriinclude mk/cc-option.mk
147f43e5c3SMarouene Boubakri
157f43e5c3SMarouene BoubakriCFG_MMAP_REGIONS ?= 13
167f43e5c3SMarouene BoubakriCFG_RESERVED_VASPACE_SIZE ?= (1024 * 1024 * 10)
177f43e5c3SMarouene Boubakri
187f43e5c3SMarouene Boubakriifeq ($(CFG_RV64_core),y)
197f43e5c3SMarouene BoubakriCFG_KERN_LINKER_FORMAT ?= elf64-littleriscv
207f43e5c3SMarouene BoubakriCFG_KERN_LINKER_ARCH ?= riscv
217f43e5c3SMarouene Boubakrielse
227f43e5c3SMarouene Boubakriifeq ($(CFG_RV32_core),y)
237f43e5c3SMarouene BoubakriCFG_KERN_LINKER_FORMAT ?= elf32-littleriscv
247f43e5c3SMarouene BoubakriCFG_KERN_LINKER_ARCH ?= riscv
257f43e5c3SMarouene Boubakrielse
267f43e5c3SMarouene Boubakri$(error Error: CFG_RV64_core or CFG_RV32_core should be defined)
277f43e5c3SMarouene Boubakriendif
287f43e5c3SMarouene Boubakriendif
297f43e5c3SMarouene Boubakri
307f43e5c3SMarouene BoubakriCFG_CORE_RWDATA_NOEXEC ?= y
317f43e5c3SMarouene BoubakriCFG_CORE_RODATA_NOEXEC ?= n
327f43e5c3SMarouene Boubakriifeq ($(CFG_CORE_RODATA_NOEXEC),y)
337f43e5c3SMarouene Boubakri$(call force,CFG_CORE_RWDATA_NOEXEC,y)
347f43e5c3SMarouene Boubakriendif
357f43e5c3SMarouene Boubakri
365f7b832aSMarouene BoubakriCFG_MAX_CACHE_LINE_SHIFT ?= 6
375f7b832aSMarouene Boubakri
383cdf0b24SMarouene BoubakriCFG_RISCV_SBI	 ?= n
397c14296eSMarouene BoubakriCFG_RISCV_M_MODE ?= y
407c14296eSMarouene Boubakriifeq ($(CFG_RISCV_M_MODE),y)
417c14296eSMarouene Boubakriifeq ($(CFG_RISCV_S_MODE),y)
427c14296eSMarouene Boubakri$(error CFG_RISCV_M_MODE and CFG_RISCV_S_MODE cannot be both 'y')
437c14296eSMarouene Boubakrielse
447c14296eSMarouene Boubakri$(call force,CFG_RISCV_S_MODE,n)
453cdf0b24SMarouene Boubakri$(call force,CFG_RISCV_SBI,n)
467c14296eSMarouene Boubakriendif
477c14296eSMarouene Boubakriendif
487c14296eSMarouene Boubakriifeq ($(CFG_RISCV_S_MODE),y)
497c14296eSMarouene Boubakri$(call force,CFG_RISCV_M_MODE,n)
507c14296eSMarouene Boubakriendif
517c14296eSMarouene Boubakriifneq (y,$(call cfg-one-enabled,CFG_RISCV_M_MODE M CFG_RISCV_S_MODE))
527c14296eSMarouene Boubakri$(error Either CFG_RISCV_M_MODE or CFG_RISCV_S_MODE must be 'y')
537c14296eSMarouene Boubakriendif
547c14296eSMarouene Boubakri
559afe87e0SMarouene Boubakriifeq ($(CFG_RISCV_SBI_CONSOLE),y)
569afe87e0SMarouene Boubakri$(call force,CFG_RISCV_SBI,y)
579afe87e0SMarouene Boubakriendif
589afe87e0SMarouene Boubakri
597f43e5c3SMarouene Boubakricore-platform-cppflags	+= -I$(arch-dir)/include
607f43e5c3SMarouene Boubakricore-platform-subdirs += \
61*f303c856SMarouene Boubakri	$(addprefix $(arch-dir)/, kernel mm tee) $(platform-dir)
627f43e5c3SMarouene Boubakri
637f43e5c3SMarouene Boubakri# more convenient to move it to platform instead
647f43e5c3SMarouene Boubakrirv64-platform-cppflags += -mcmodel=medany -march=rv64imafd -mabi=lp64d
657f43e5c3SMarouene Boubakrirv64-platform-cppflags += -Wno-missing-include-dirs
667f43e5c3SMarouene Boubakri
677f43e5c3SMarouene Boubakrirv64-platform-cppflags += -DRV64=1 -D__LP64__=1
687f43e5c3SMarouene Boubakrirv32-platform-cppflags += -DRV32=1 -D__ILP32__=1
697f43e5c3SMarouene Boubakri
707f43e5c3SMarouene Boubakriplatform-cflags-generic ?= -ffunction-sections -fdata-sections -pipe
717f43e5c3SMarouene Boubakriplatform-aflags-generic ?= -pipe
727f43e5c3SMarouene Boubakri
737f43e5c3SMarouene Boubakrirv64-platform-cflags-generic := -mstrict-align $(call cc-option,)
747f43e5c3SMarouene Boubakri
757f43e5c3SMarouene Boubakri# Optimize for size by default, usually gives good performance too
767f43e5c3SMarouene BoubakriCFG_CC_OPT_LEVEL ?= 0
777f43e5c3SMarouene Boubakriplatform-cflags-optimization ?= -O$(CFG_CC_OPT_LEVEL)
787f43e5c3SMarouene Boubakri
797f43e5c3SMarouene BoubakriCFG_DEBUG_INFO ?= y
807f43e5c3SMarouene Boubakriifeq ($(CFG_DEBUG_INFO),y)
817f43e5c3SMarouene Boubakriplatform-cflags-debug-info ?= -g3
827f43e5c3SMarouene Boubakriplatform-aflags-debug-info ?= -g
837f43e5c3SMarouene Boubakriendif
847f43e5c3SMarouene Boubakri
857f43e5c3SMarouene Boubakricore-platform-cflags += $(platform-cflags-optimization)
867f43e5c3SMarouene Boubakricore-platform-cflags += $(platform-cflags-generic)
877f43e5c3SMarouene Boubakricore-platform-cflags += $(platform-cflags-debug-info)
887f43e5c3SMarouene Boubakri
897f43e5c3SMarouene Boubakricore-platform-aflags += $(platform-aflags-generic)
907f43e5c3SMarouene Boubakricore-platform-aflags += $(platform-aflags-debug-info)
917f43e5c3SMarouene Boubakri
927f43e5c3SMarouene Boubakriifeq ($(CFG_CORE_ASLR),y)
937f43e5c3SMarouene Boubakricore-platform-cflags += -fpie
947f43e5c3SMarouene Boubakriendif
957f43e5c3SMarouene Boubakri
967f43e5c3SMarouene Boubakriifeq ($(CFG_RV64_core),y)
977f43e5c3SMarouene Boubakricore-platform-cppflags += $(rv64-platform-cppflags)
987f43e5c3SMarouene Boubakricore-platform-cflags += $(rv64-platform-cflags)
997f43e5c3SMarouene Boubakricore-platform-cflags += $(rv64-platform-cflags-generic)
1007f43e5c3SMarouene Boubakricore-platform-cflags += $(rv64-platform-cflags-no-hard-float)
1017f43e5c3SMarouene Boubakricore-platform-aflags += $(rv64-platform-aflags)
1027f43e5c3SMarouene Boubakrielse
1037f43e5c3SMarouene Boubakricore-platform-cppflags += $(rv32-platform-cppflags)
1047f43e5c3SMarouene Boubakricore-platform-cflags += $(rv32-platform-cflags)
1057f43e5c3SMarouene Boubakricore-platform-cflags += $(rv32-platform-cflags-no-hard-float)
1067f43e5c3SMarouene Boubakriifeq ($(CFG_UNWIND),y)
1077f43e5c3SMarouene Boubakricore-platform-cflags += -funwind-tables
1087f43e5c3SMarouene Boubakriendif
1097f43e5c3SMarouene Boubakricore-platform-aflags += $(core_rv32-platform-aflags)
1107f43e5c3SMarouene Boubakricore-platform-aflags += $(rv32-platform-aflags)
1117f43e5c3SMarouene Boubakriendif
1127f43e5c3SMarouene Boubakri
1137f43e5c3SMarouene Boubakri# Provide default supported-ta-targets if not set by the platform config
1147f43e5c3SMarouene Boubakriifeq (,$(supported-ta-targets))
1157f43e5c3SMarouene Boubakrisupported-ta-targets = ta_rv32
1167f43e5c3SMarouene Boubakriifeq ($(CFG_RV64_core),y)
1177f43e5c3SMarouene Boubakrisupported-ta-targets += ta_rv64
1187f43e5c3SMarouene Boubakriendif
1197f43e5c3SMarouene Boubakriendif
1207f43e5c3SMarouene Boubakri
1217f43e5c3SMarouene Boubakrita-targets := $(if $(CFG_USER_TA_TARGETS),$(filter $(supported-ta-targets),$(CFG_USER_TA_TARGETS)),$(supported-ta-targets))
1227f43e5c3SMarouene Boubakriunsup-targets := $(filter-out $(ta-targets),$(CFG_USER_TA_TARGETS))
1237f43e5c3SMarouene Boubakriifneq (,$(unsup-targets))
1247f43e5c3SMarouene Boubakri$(error CFG_USER_TA_TARGETS contains unsupported value(s): $(unsup-targets). Valid values: $(supported-ta-targets))
1257f43e5c3SMarouene Boubakriendif
1267f43e5c3SMarouene Boubakri
1277f43e5c3SMarouene Boubakriifneq ($(filter ta_rv32,$(ta-targets)),)
1287f43e5c3SMarouene Boubakri# Variables for ta-target/sm "ta_rv32"
1297f43e5c3SMarouene BoubakriCFG_RV32_ta_rv32 := y
1307f43e5c3SMarouene Boubakriarch-bits-ta_rv32 := 32
1317f43e5c3SMarouene Boubakrita_rv32-platform-cppflags += $(rv32-platform-cppflags)
1327f43e5c3SMarouene Boubakrita_rv32-platform-cflags += $(rv32-platform-cflags)
1337f43e5c3SMarouene Boubakrita_rv32-platform-cflags += $(platform-cflags-optimization)
1347f43e5c3SMarouene Boubakrita_rv32-platform-cflags += $(platform-cflags-debug-info)
1357f43e5c3SMarouene Boubakrita_rv32-platform-cflags += -fpic
1367f43e5c3SMarouene Boubakri
1377f43e5c3SMarouene Boubakriifeq ($(CFG_UNWIND),y)
1387f43e5c3SMarouene Boubakrita_rv32-platform-cflags += -funwind-tables
1397f43e5c3SMarouene Boubakriendif
1407f43e5c3SMarouene Boubakrita_rv32-platform-aflags += $(platform-aflags-generic)
1417f43e5c3SMarouene Boubakrita_rv32-platform-aflags += $(platform-aflags-debug-info)
1427f43e5c3SMarouene Boubakrita_rv32-platform-aflags += $(rv32-platform-aflags)
1437f43e5c3SMarouene Boubakri
1447f43e5c3SMarouene Boubakrita_rv32-platform-cxxflags += -fpic
1457f43e5c3SMarouene Boubakrita_rv32-platform-cxxflags += $(rv32-platform-cxxflags)
1467f43e5c3SMarouene Boubakrita_rv32-platform-cxxflags += $(platform-cflags-optimization)
1477f43e5c3SMarouene Boubakrita_rv32-platform-cxxflags += $(platform-cflags-debug-info)
1487f43e5c3SMarouene Boubakri
1497f43e5c3SMarouene Boubakrita-mk-file-export-vars-ta_rv32 += CFG_RV32_ta_rv32
1507f43e5c3SMarouene Boubakrita-mk-file-export-vars-ta_rv32 += ta_rv32-platform-cppflags
1517f43e5c3SMarouene Boubakrita-mk-file-export-vars-ta_rv32 += ta_rv32-platform-cflags
1527f43e5c3SMarouene Boubakrita-mk-file-export-vars-ta_rv32 += ta_rv32-platform-aflags
1537f43e5c3SMarouene Boubakrita-mk-file-export-vars-ta_rv32 += ta_rv32-platform-cxxflags
1547f43e5c3SMarouene Boubakri
1557f43e5c3SMarouene Boubakrita-mk-file-export-add-ta_rv32 += CROSS_COMPILE ?= riscv32-unknown-linux-gnu-_nl_
1567f43e5c3SMarouene Boubakrita-mk-file-export-add-ta_rv32 += CROSS_COMPILE32 ?= $$(CROSS_COMPILE)_nl_
1577f43e5c3SMarouene Boubakrita-mk-file-export-add-ta_rv32 += CROSS_COMPILE_ta_rv32 ?= $$(CROSS_COMPILE32)_nl_
1587f43e5c3SMarouene Boubakrita-mk-file-export-add-ta_rv32 += COMPILER ?= gcc_nl_
1597f43e5c3SMarouene Boubakrita-mk-file-export-add-ta_rv32 += COMPILER_ta_rv32 ?= $$(COMPILER)_nl_
1607f43e5c3SMarouene Boubakrita-mk-file-export-add-ta_rv32 += PYTHON3 ?= python3_nl_
1617f43e5c3SMarouene Boubakriendif
1627f43e5c3SMarouene Boubakri
1637f43e5c3SMarouene Boubakriifneq ($(filter ta_rv64,$(ta-targets)),)
1647f43e5c3SMarouene Boubakri# Variables for ta-target/sm "ta_rv64"
1657f43e5c3SMarouene BoubakriCFG_RV64_ta_rv64 := y
1667f43e5c3SMarouene Boubakriarch-bits-ta_rv64 := 64
1677f43e5c3SMarouene Boubakrita_rv64-platform-cppflags += $(rv64-platform-cppflags)
1687f43e5c3SMarouene Boubakrita_rv64-platform-cflags += $(rv64-platform-cflags)
1697f43e5c3SMarouene Boubakrita_rv64-platform-cflags += $(platform-cflags-optimization)
1707f43e5c3SMarouene Boubakrita_rv64-platform-cflags += $(platform-cflags-debug-info)
1717f43e5c3SMarouene Boubakrita_rv64-platform-cflags += -fpic
1727f43e5c3SMarouene Boubakrita_rv64-platform-cflags += $(rv64-platform-cflags-generic)
1737f43e5c3SMarouene Boubakriifeq ($(rv64-platform-hard-float-enabled),y)
1747f43e5c3SMarouene Boubakrita_rv64-platform-cflags += $(rv64-platform-cflags-hard-float)
1757f43e5c3SMarouene Boubakrielse
1767f43e5c3SMarouene Boubakrita_rv64-platform-cflags += $(rv64-platform-cflags-no-hard-float)
1777f43e5c3SMarouene Boubakriendif
1787f43e5c3SMarouene Boubakrita_rv64-platform-aflags += $(platform-aflags-generic)
1797f43e5c3SMarouene Boubakrita_rv64-platform-aflags += $(platform-aflags-debug-info)
1807f43e5c3SMarouene Boubakrita_rv64-platform-aflags += $(rv64-platform-aflags)
1817f43e5c3SMarouene Boubakri
1827f43e5c3SMarouene Boubakrita_rv64-platform-cxxflags += -fpic
1837f43e5c3SMarouene Boubakrita_rv64-platform-cxxflags += $(platform-cflags-optimization)
1847f43e5c3SMarouene Boubakrita_rv64-platform-cxxflags += $(platform-cflags-debug-info)
1857f43e5c3SMarouene Boubakri
1867f43e5c3SMarouene Boubakrita-mk-file-export-vars-ta_rv64 += CFG_RV64_ta_rv64
1877f43e5c3SMarouene Boubakrita-mk-file-export-vars-ta_rv64 += ta_rv64-platform-cppflags
1887f43e5c3SMarouene Boubakrita-mk-file-export-vars-ta_rv64 += ta_rv64-platform-cflags
1897f43e5c3SMarouene Boubakrita-mk-file-export-vars-ta_rv64 += ta_rv64-platform-aflags
1907f43e5c3SMarouene Boubakrita-mk-file-export-vars-ta_rv64 += ta_rv64-platform-cxxflags
1917f43e5c3SMarouene Boubakri
1927f43e5c3SMarouene Boubakrita-mk-file-export-add-ta_rv64 += CROSS_COMPILE64 ?= $$(CROSS_COMPILE)_nl_
1937f43e5c3SMarouene Boubakrita-mk-file-export-add-ta_rv64 += CROSS_COMPILE_ta_rv64 ?= $$(CROSS_COMPILE64)_nl_
1947f43e5c3SMarouene Boubakrita-mk-file-export-add-ta_rv64 += COMPILER ?= gcc_nl_
1957f43e5c3SMarouene Boubakrita-mk-file-export-add-ta_rv64 += COMPILER_ta_rv64 ?= $$(COMPILER)_nl_
1967f43e5c3SMarouene Boubakrita-mk-file-export-add-ta_rv64 += PYTHON3 ?= python3_nl_
1977f43e5c3SMarouene Boubakriendif
1987f43e5c3SMarouene Boubakri
1997f43e5c3SMarouene Boubakri# Set cross compiler prefix for each TA target
2007f43e5c3SMarouene Boubakri$(foreach sm, $(ta-targets), $(eval CROSS_COMPILE_$(sm) ?= $(CROSS_COMPILE$(arch-bits-$(sm)))))
201