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 55core-platform-cppflags += -I$(arch-dir)/include 56core-platform-subdirs += \ 57 $(addprefix $(arch-dir)/, kernel) $(platform-dir) 58 59# more convenient to move it to platform instead 60rv64-platform-cppflags += -mcmodel=medany -march=rv64imafd -mabi=lp64d 61rv64-platform-cppflags += -Wno-missing-include-dirs 62 63rv64-platform-cppflags += -DRV64=1 -D__LP64__=1 64rv32-platform-cppflags += -DRV32=1 -D__ILP32__=1 65 66platform-cflags-generic ?= -ffunction-sections -fdata-sections -pipe 67platform-aflags-generic ?= -pipe 68 69rv64-platform-cflags-generic := -mstrict-align $(call cc-option,) 70 71# Optimize for size by default, usually gives good performance too 72CFG_CC_OPT_LEVEL ?= 0 73platform-cflags-optimization ?= -O$(CFG_CC_OPT_LEVEL) 74 75CFG_DEBUG_INFO ?= y 76ifeq ($(CFG_DEBUG_INFO),y) 77platform-cflags-debug-info ?= -g3 78platform-aflags-debug-info ?= -g 79endif 80 81core-platform-cflags += $(platform-cflags-optimization) 82core-platform-cflags += $(platform-cflags-generic) 83core-platform-cflags += $(platform-cflags-debug-info) 84 85core-platform-aflags += $(platform-aflags-generic) 86core-platform-aflags += $(platform-aflags-debug-info) 87 88ifeq ($(CFG_CORE_ASLR),y) 89core-platform-cflags += -fpie 90endif 91 92ifeq ($(CFG_RV64_core),y) 93core-platform-cppflags += $(rv64-platform-cppflags) 94core-platform-cflags += $(rv64-platform-cflags) 95core-platform-cflags += $(rv64-platform-cflags-generic) 96core-platform-cflags += $(rv64-platform-cflags-no-hard-float) 97core-platform-aflags += $(rv64-platform-aflags) 98else 99core-platform-cppflags += $(rv32-platform-cppflags) 100core-platform-cflags += $(rv32-platform-cflags) 101core-platform-cflags += $(rv32-platform-cflags-no-hard-float) 102ifeq ($(CFG_UNWIND),y) 103core-platform-cflags += -funwind-tables 104endif 105core-platform-aflags += $(core_rv32-platform-aflags) 106core-platform-aflags += $(rv32-platform-aflags) 107endif 108 109# Provide default supported-ta-targets if not set by the platform config 110ifeq (,$(supported-ta-targets)) 111supported-ta-targets = ta_rv32 112ifeq ($(CFG_RV64_core),y) 113supported-ta-targets += ta_rv64 114endif 115endif 116 117ta-targets := $(if $(CFG_USER_TA_TARGETS),$(filter $(supported-ta-targets),$(CFG_USER_TA_TARGETS)),$(supported-ta-targets)) 118unsup-targets := $(filter-out $(ta-targets),$(CFG_USER_TA_TARGETS)) 119ifneq (,$(unsup-targets)) 120$(error CFG_USER_TA_TARGETS contains unsupported value(s): $(unsup-targets). Valid values: $(supported-ta-targets)) 121endif 122 123ifneq ($(filter ta_rv32,$(ta-targets)),) 124# Variables for ta-target/sm "ta_rv32" 125CFG_RV32_ta_rv32 := y 126arch-bits-ta_rv32 := 32 127ta_rv32-platform-cppflags += $(rv32-platform-cppflags) 128ta_rv32-platform-cflags += $(rv32-platform-cflags) 129ta_rv32-platform-cflags += $(platform-cflags-optimization) 130ta_rv32-platform-cflags += $(platform-cflags-debug-info) 131ta_rv32-platform-cflags += -fpic 132 133ifeq ($(CFG_UNWIND),y) 134ta_rv32-platform-cflags += -funwind-tables 135endif 136ta_rv32-platform-aflags += $(platform-aflags-generic) 137ta_rv32-platform-aflags += $(platform-aflags-debug-info) 138ta_rv32-platform-aflags += $(rv32-platform-aflags) 139 140ta_rv32-platform-cxxflags += -fpic 141ta_rv32-platform-cxxflags += $(rv32-platform-cxxflags) 142ta_rv32-platform-cxxflags += $(platform-cflags-optimization) 143ta_rv32-platform-cxxflags += $(platform-cflags-debug-info) 144 145ta-mk-file-export-vars-ta_rv32 += CFG_RV32_ta_rv32 146ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-cppflags 147ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-cflags 148ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-aflags 149ta-mk-file-export-vars-ta_rv32 += ta_rv32-platform-cxxflags 150 151ta-mk-file-export-add-ta_rv32 += CROSS_COMPILE ?= riscv32-unknown-linux-gnu-_nl_ 152ta-mk-file-export-add-ta_rv32 += CROSS_COMPILE32 ?= $$(CROSS_COMPILE)_nl_ 153ta-mk-file-export-add-ta_rv32 += CROSS_COMPILE_ta_rv32 ?= $$(CROSS_COMPILE32)_nl_ 154ta-mk-file-export-add-ta_rv32 += COMPILER ?= gcc_nl_ 155ta-mk-file-export-add-ta_rv32 += COMPILER_ta_rv32 ?= $$(COMPILER)_nl_ 156ta-mk-file-export-add-ta_rv32 += PYTHON3 ?= python3_nl_ 157endif 158 159ifneq ($(filter ta_rv64,$(ta-targets)),) 160# Variables for ta-target/sm "ta_rv64" 161CFG_RV64_ta_rv64 := y 162arch-bits-ta_rv64 := 64 163ta_rv64-platform-cppflags += $(rv64-platform-cppflags) 164ta_rv64-platform-cflags += $(rv64-platform-cflags) 165ta_rv64-platform-cflags += $(platform-cflags-optimization) 166ta_rv64-platform-cflags += $(platform-cflags-debug-info) 167ta_rv64-platform-cflags += -fpic 168ta_rv64-platform-cflags += $(rv64-platform-cflags-generic) 169ifeq ($(rv64-platform-hard-float-enabled),y) 170ta_rv64-platform-cflags += $(rv64-platform-cflags-hard-float) 171else 172ta_rv64-platform-cflags += $(rv64-platform-cflags-no-hard-float) 173endif 174ta_rv64-platform-aflags += $(platform-aflags-generic) 175ta_rv64-platform-aflags += $(platform-aflags-debug-info) 176ta_rv64-platform-aflags += $(rv64-platform-aflags) 177 178ta_rv64-platform-cxxflags += -fpic 179ta_rv64-platform-cxxflags += $(platform-cflags-optimization) 180ta_rv64-platform-cxxflags += $(platform-cflags-debug-info) 181 182ta-mk-file-export-vars-ta_rv64 += CFG_RV64_ta_rv64 183ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-cppflags 184ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-cflags 185ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-aflags 186ta-mk-file-export-vars-ta_rv64 += ta_rv64-platform-cxxflags 187 188ta-mk-file-export-add-ta_rv64 += CROSS_COMPILE64 ?= $$(CROSS_COMPILE)_nl_ 189ta-mk-file-export-add-ta_rv64 += CROSS_COMPILE_ta_rv64 ?= $$(CROSS_COMPILE64)_nl_ 190ta-mk-file-export-add-ta_rv64 += COMPILER ?= gcc_nl_ 191ta-mk-file-export-add-ta_rv64 += COMPILER_ta_rv64 ?= $$(COMPILER)_nl_ 192ta-mk-file-export-add-ta_rv64 += PYTHON3 ?= python3_nl_ 193endif 194 195# Set cross compiler prefix for each TA target 196$(foreach sm, $(ta-targets), $(eval CROSS_COMPILE_$(sm) ?= $(CROSS_COMPILE$(arch-bits-$(sm))))) 197