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