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