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