xref: /rk3399_ARM-atf/make_helpers/march.mk (revision 8ff87a3110abee5b9b7ed1c99cb34c25083fbd7a)
17794d6c8SGovindraj Raja#
20772fc7eSBoyan Karatotev# Copyright (c) 2023-2025, Arm Limited. All rights reserved.
37794d6c8SGovindraj Raja#
47794d6c8SGovindraj Raja# SPDX-License-Identifier: BSD-3-Clause
57794d6c8SGovindraj Raja#
67794d6c8SGovindraj Raja
77794d6c8SGovindraj Raja# This build helper makefile is used to determine a suitable march build
87794d6c8SGovindraj Raja# option to be used, based on platform provided ARM_ARCH_MAJOR/MINOR
97794d6c8SGovindraj Raja# data and compiler supported march version.
107794d6c8SGovindraj Raja
117794d6c8SGovindraj Raja# Set the compiler's target architecture profile based on
127794d6c8SGovindraj Raja# ARM_ARCH_MAJOR and ARM_ARCH_MINOR options.
137794d6c8SGovindraj Raja
147794d6c8SGovindraj Raja
157794d6c8SGovindraj Raja# This is used to collect available march values from compiler.
167794d6c8SGovindraj Raja# Example on a gcc-12.2 arm64 toolchain it will look like:
177794d6c8SGovindraj Raja# [...]
187794d6c8SGovindraj Raja#./aarch64-none-elf-gcc --target-help -march=foo
197794d6c8SGovindraj Raja# cc1: error: unknown value 'foo' for '-march'
207794d6c8SGovindraj Raja# cc1: note: valid arguments are: armv8-a armv8.1-a armv8.2-a armv8.3-a armv8.4-a armv8.5-a
217794d6c8SGovindraj Raja# armv8.6-a armv8.7-a armv8.8-a armv8-r armv9-a
227794d6c8SGovindraj Raja# [...]
237794d6c8SGovindraj Raja#
24291e7182SChris KayGCC_MARCH_OUTPUT := $(if $($(ARCH)-cc),$(shell $($(ARCH)-cc) -march=foo -Q --help=target -v 2>&1))
257794d6c8SGovindraj Raja
267794d6c8SGovindraj Raja# This function is used to find the best march value supported by the given compiler.
277794d6c8SGovindraj Raja# We try to use `GCC_MARCH_OUTPUT` which has verbose message with supported march values we filter that
287794d6c8SGovindraj Raja# to find armvX.Y-a or armvX-a values, then filter the best supported arch based on ARM_ARCH_MAJOR.
297794d6c8SGovindraj Raja#
307794d6c8SGovindraj Raja# Example on a gcc-12.2 arm64 toolchain this will return armv9-a if platform requested for armv9.2-a
317794d6c8SGovindraj Raja# Similarly on gcc 11.3 it would return armv8.6-a if platform requested armv8.8-a
327794d6c8SGovindraj Rajadefine major_best_avail_march
337794d6c8SGovindraj Raja$(1) := $(lastword $(filter armv$(ARM_ARCH_MAJOR)% ,$(filter armv%-a, $(GCC_MARCH_OUTPUT))))
347794d6c8SGovindraj Rajaendef
357794d6c8SGovindraj Raja
367794d6c8SGovindraj Raja# This function is used to just return latest march value supported by the given compiler.
377794d6c8SGovindraj Raja#
387794d6c8SGovindraj Raja# Example: this would return armv8.6-a on a gcc-11.3 when platform requested for armv9.0-a
397794d6c8SGovindraj Raja#
407794d6c8SGovindraj Raja# Thus this function should be used in conjunction with major_best_avail_march, when best match
417794d6c8SGovindraj Raja# is not found it should be ok to try with lastest known supported march value from the
427794d6c8SGovindraj Raja# compiler.
437794d6c8SGovindraj Rajadefine latest_match_march
447794d6c8SGovindraj Raja$(1) := $(lastword $(filter armv%-a, $(GCC_MARCH_OUTPUT)))
457794d6c8SGovindraj Rajaendef
467794d6c8SGovindraj Raja
477794d6c8SGovindraj Rajaifdef MARCH_DIRECTIVE
487794d6c8SGovindraj Raja    march-directive		:= $(MARCH_DIRECTIVE)
497794d6c8SGovindraj Rajaelse
507794d6c8SGovindraj Raja
517794d6c8SGovindraj Rajaifeq (${ARM_ARCH_MINOR},0)
527794d6c8SGovindraj Raja    provided-march = armv${ARM_ARCH_MAJOR}-a
537794d6c8SGovindraj Rajaelse
547794d6c8SGovindraj Raja    provided-march = armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
557794d6c8SGovindraj Rajaendif
567794d6c8SGovindraj Raja
578620bd0bSChris Kayifeq ($(filter %-clang,$($(ARCH)-cc-id)),)
587794d6c8SGovindraj Raja
597794d6c8SGovindraj Raja# We expect from Platform to provide a correct Major/Minor value but expecting something
607794d6c8SGovindraj Raja# from compiler with unsupported march means we shouldn't fail without trying anything,
617794d6c8SGovindraj Raja# so here we try to find best supported march value and use that for compilation.
627794d6c8SGovindraj Raja# If we don't support current march version from gcc compiler, try with lower arch based on
637794d6c8SGovindraj Raja# availability. In TF-A there is no hard rule for need of higher version march for basic
647794d6c8SGovindraj Raja# functionality, denying a build on only this fact doesn't look correct, so try with best
657794d6c8SGovindraj Raja# or latest march values from whats available from compiler.
667794d6c8SGovindraj Rajaifeq (,$(findstring $(provided-march), $(GCC_MARCH_OUTPUT)))
677794d6c8SGovindraj Raja    $(eval $(call major_best_avail_march, available-march))
687794d6c8SGovindraj Raja
697794d6c8SGovindraj Rajaifeq (, $(available-march))
707794d6c8SGovindraj Raja    $(eval $(call latest_match_march, available-march))
717794d6c8SGovindraj Rajaendif
727794d6c8SGovindraj Raja
737794d6c8SGovindraj Raja# If we fail to come up with any available-march value so far, don't update
747794d6c8SGovindraj Raja# provided-march and thus allow the build to fail using the provided-march
757794d6c8SGovindraj Raja# which is derived based on arch_major and arch_minor values.
767794d6c8SGovindraj Rajaifneq (,$(available-march))
777794d6c8SGovindraj Raja    provided-march := ${available-march}
787794d6c8SGovindraj Rajaendif
797794d6c8SGovindraj Raja
807794d6c8SGovindraj Rajaendif # provided-march supported
817794d6c8SGovindraj Rajaendif # not clang
827794d6c8SGovindraj Raja
837794d6c8SGovindraj Rajamarch-directive := -march=${provided-march}
847794d6c8SGovindraj Raja
850772fc7eSBoyan Karatotev################################################################################
860772fc7eSBoyan Karatotev# Get Architecture Feature Modifiers
870772fc7eSBoyan Karatotev################################################################################
880772fc7eSBoyan Karatotevarch-features		=	${ARM_ARCH_FEATURE}
890772fc7eSBoyan Karatotev
90*3325415bSJohn Powell# This section is where we place modifiers for optional arch features. If they
91*3325415bSJohn Powell# are enabled with build flags, then we need to explicitly enable them in the
92*3325415bSJohn Powell# compiler as well since they are not enabled by default.
93*3325415bSJohn Powellifneq ($(ENABLE_FEAT_PAUTH_LR), 0)
94*3325415bSJohn Powell    # Currently, FEAT_PAUTH_LR is only supported by arm/clang compilers
95*3325415bSJohn Powell    # TODO implement for GCC when support is added
96*3325415bSJohn Powell    ifeq ($($(ARCH)-cc-id),arm-clang)
97*3325415bSJohn Powell            arch-features	:= $(arch-features)+pauth-lr
98*3325415bSJohn Powell    else
99*3325415bSJohn Powell            $(error Error: ENABLE_FEAT_PAUTH_LR not supported for GCC compiler)
100*3325415bSJohn Powell    endif
101*3325415bSJohn Powellendif
102*3325415bSJohn Powell
1037275ac2aSGovindraj Raja# Set the compiler's architecture feature modifiers
1047275ac2aSGovindraj Rajaifneq ($(arch-features), none)
1057275ac2aSGovindraj Raja	# Strip "none+" from arch-features
1067275ac2aSGovindraj Raja	arch-features	:=	$(subst none+,,$(arch-features))
1077275ac2aSGovindraj Raja	march-directive	:=	$(march-directive)+$(arch-features)
1087275ac2aSGovindraj Raja# Print features
1097275ac2aSGovindraj Raja        $(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
1107275ac2aSGovindraj Rajaendif #(arch-features)
1117275ac2aSGovindraj Raja
1127794d6c8SGovindraj Rajaendif # MARCH_DIRECTIVE
113