From 7e8a818d95e820f8e9c63233d670f5b843820081 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Thu, 14 Nov 2024 12:06:27 +0000 Subject: [PATCH] arm: add ARM architecture profile detection Add some logic to detect classic and M-profile cores, and make this info available to the build system. All existing targets are classic profile. Change-Id: I07bfcd418bcaa6297b9bbf889fc189f167147428 --- firmware/export/config.h | 8 +++++- tools/configure | 53 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/firmware/export/config.h b/firmware/export/config.h index 4a33ae26cf..b7ba0dc86f 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h @@ -696,7 +696,13 @@ Lyre prototype 1 */ /* define for all cpus from ARM family */ #if ARCH == ARCH_ARM #define CPU_ARM -#define ARM_ARCH ARCH_VERSION /* ARMv{4,5,6,7} */ +#define ARM_ARCH ARCH_VERSION /* ARMv{4,5,6,7} */ +#define ARM_PROFILE ARCH_PROFILE /* Classic, Microcontroller */ +# if ARM_PROFILE == ARM_PROFILE_MICRO +# define CPU_ARM_MICRO +# elif ARM_PROFILE == ARM_PROFILE_CLASSIC +# define CPU_ARM_CLASSIC +# endif #endif #if ARCH == ARCH_MIPS diff --git a/tools/configure b/tools/configure index 629e29465f..4da644fe5f 100755 --- a/tools/configure +++ b/tools/configure @@ -4634,10 +4634,41 @@ if [ -z "$arch" ]; then arch="arm" # cpp defines like "#define __ARM_ARCH_4TE__ 1" (where we want to extract the 4) arch_version="$(echo $cpp_defines | tr ' ' '\012' | grep __ARM_ARCH | sed -e 's,.*\([0-9]\).*,\1,' | grep -v __ARM_ARCH | head -1)" + arch_profile="$(echo "$cpp_defines" | grep 'define __ARM_ARCH_PROFILE' | sed -e 's,.* \([0-9]\+\)$,\1,')" if test "$gccnum" -ge "800"; then # GCC8+ can natively emit unified asm syntax GCCOPTS="$GCCOPTS -masm-syntax-unified" fi + case "$arch_profile" in + 77) + arch_profile=micro + + # We have a lot of assembly written for ARM32, which won't + # successfully assemble on a Thumb-only core due to missing + # IT blocks. The recommended practice for portable assembly + # is to add explicit IT blocks nowadays. + # + # This option instructs the assembler to add IT blocks + # automatically as needed, which allows the old assembly to + # compile unchanged (although it might be sub-optimal). + GCCOPTS="$GCCOPTS -Wa,-mimplicit-it=thumb" + + # Disable this option -- it only makes sense for cores that + # support both ARM and Thumb instruction sets. + if [ "$ARG_ARM_THUMB" = "1" ]; then + echo "Warning: --thumb option has no effect on ARM M profile cores" + ARG_ARM_THUMB=0 + fi + ;; + *) + # On classic ARM we expect an empty string, so only warn if it's nonempty + if [ -n "$arch_profile" ]; then + echo "Warning: Cannot determine target ARM profile, assuming classic" + fi + + arch_profile=classic + ;; + esac elif [ -n "$(echo $cpp_defines | grep -w __mips__)" ]; then arch="mips" arch_version="$(echo $cpp_defines | tr ' ' '\012' | grep _MIPS_ARCH_MIPS | sed -e 's,.*\([0-9][0-9]\).*,\1,' | grep -v _MIPS_ARCH_MIPS)" @@ -4651,7 +4682,11 @@ if [ -z "$arch" ]; then fi if [ "$arch" != "none" ]; then if [ -n "$arch_version" ]; then - echo "Automatically selected arch: $arch (ver $arch_version)" + if [ -n "$arch_profile" ]; then + echo "Automatically selected arch: $arch (ver $arch_version, profile $arch_profile)" + else + echo "Automatically selected arch: $arch (ver $arch_version)" + fi else echo "Automatically selected arch: $arch" fi @@ -4664,10 +4699,13 @@ else fi fi -arch="arch_$arch" +Darch="#define ARCH arch_$arch" if [ -n "$arch_version" ]; then Darch_version="#define ARCH_VERSION $arch_version" fi +if [ -n "$arch_profile" ]; then + Darch_profile="#define ARCH_PROFILE $(echo ${arch}_PROFILE_${arch_profile} | tr [a-z] [A-Z])" +fi if test -n "$ccache"; then CC="$ccache $CC" @@ -4722,10 +4760,14 @@ cat > autoconf.h.new <