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