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