Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DCE21C25B0E for ; Tue, 16 Aug 2022 16:17:48 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 88D80848F0; Tue, 16 Aug 2022 18:17:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 9B77D84911; Tue, 16 Aug 2022 18:17:44 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 7DC5C848FF for ; Tue, 16 Aug 2022 18:17:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andre.przywara@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4E789106F; Tue, 16 Aug 2022 09:17:41 -0700 (PDT) Received: from donnerap.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4401C3F67D; Tue, 16 Aug 2022 09:17:39 -0700 (PDT) Date: Tue, 16 Aug 2022 17:17:36 +0100 From: Andre Przywara To: Sergei Antonov Cc: u-boot@lists.denx.de, Samuel Holland , Ye Li , Simon Glass , Marek Vasut , Sean Anderson , Tom Rini , Wolfgang Denk Subject: Re: [PATCH] arm: ARMv4 assembly compatibility Message-ID: <20220816171736.5c7a78cc@donnerap.cambridge.arm.com> In-Reply-To: <20220810090446.1469742-1-saproj@gmail.com> References: <20220810090446.1469742-1-saproj@gmail.com> Organization: ARM X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.32; aarch64-unknown-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On Wed, 10 Aug 2022 12:04:46 +0300 Sergei Antonov wrote: Hi, > There is currently a problem that U-Boot can not work on ARMv4 > because assembly imlementations of memcpy() and some other functions > use "bx lr" instruction that is not available on ARMv4 ("mov pc, lr" > should be used instead). So there is a comment in the current code, right above what's shown here in the first hunk, which says: /* * We only support cores that support at least Thumb-1 and thus we use * 'bx lr' */ This was added by Tom in commit 431afb4ef9fe, when he removed some code very close to what you are adding back now. So what is the story here? This commit seems to suggest U-Boot doesn't support even ARMv5 without "T", has this changed? There are probably other code places which would need adjustment to run on ARMv4? Tom, can you say why support for Thumb-less code / older architectures was dropped? No users, I guess? Sergei, can you say what is this for? Are you adding support for a SoC with an ARM810 core from 1996? Cheers, Andre > > A working preprocessor-based solution to this problem is found in > arch/arm/lib/relocate.S. Move it to the "ret" macro in > arch/arm/include/asm/assembler.h and change all "bx lr" code > to "ret lr" in functions that may run on ARMv4. Linux source code > deals with this problem in the same manner. > > Signed-off-by: Sergei Antonov > CC: Samuel Holland > CC: Ye Li > CC: Simon Glass > CC: Andre Przywara > CC: Marek Vasut > CC: Sean Anderson > CC: Tom Rini > CC: Wolfgang Denk > --- > arch/arm/include/asm/assembler.h | 6 ++++++ > arch/arm/lib/lib1funcs.S | 8 ++++---- > arch/arm/lib/memcpy.S | 6 +++--- > arch/arm/lib/relocate.S | 10 ++-------- > arch/arm/lib/setjmp.S | 4 ++-- > 5 files changed, 17 insertions(+), 17 deletions(-) > > diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h > index b146918586..911f7a1b49 100644 > --- a/arch/arm/include/asm/assembler.h > +++ b/arch/arm/include/asm/assembler.h > @@ -63,11 +63,17 @@ > */ > .irp c,,eq,ne,cs,cc,mi,pl,vs,vc,hi,ls,ge,lt,gt,le,hs,lo > .macro ret\c, reg > + > + /* ARMv4- don't know bx lr but the assembler fails to see that */ > +#ifdef __ARM_ARCH_4__ > + mov\c pc, \reg > +#else > .ifeqs "\reg", "lr" > bx\c \reg > .else > mov\c pc, \reg > .endif > +#endif > .endm > .endr > > diff --git a/arch/arm/lib/lib1funcs.S b/arch/arm/lib/lib1funcs.S > index 700eee5fbb..7ff4446dd6 100644 > --- a/arch/arm/lib/lib1funcs.S > +++ b/arch/arm/lib/lib1funcs.S > @@ -377,7 +377,7 @@ ENTRY(__gnu_thumb1_case_sqi) > lsls r1, r1, #1 > add lr, lr, r1 > pop {r1} > - bx lr > + ret lr > ENDPROC(__gnu_thumb1_case_sqi) > .popsection > > @@ -391,7 +391,7 @@ ENTRY(__gnu_thumb1_case_uqi) > lsls r1, r1, #1 > add lr, lr, r1 > pop {r1} > - bx lr > + ret lr > ENDPROC(__gnu_thumb1_case_uqi) > .popsection > > @@ -406,7 +406,7 @@ ENTRY(__gnu_thumb1_case_shi) > lsls r1, r1, #1 > add lr, lr, r1 > pop {r0, r1} > - bx lr > + ret lr > ENDPROC(__gnu_thumb1_case_shi) > .popsection > > @@ -421,7 +421,7 @@ ENTRY(__gnu_thumb1_case_uhi) > lsls r1, r1, #1 > add lr, lr, r1 > pop {r0, r1} > - bx lr > + ret lr > ENDPROC(__gnu_thumb1_case_uhi) > .popsection > #endif > diff --git a/arch/arm/lib/memcpy.S b/arch/arm/lib/memcpy.S > index eee7a219ce..a1c996f94e 100644 > --- a/arch/arm/lib/memcpy.S > +++ b/arch/arm/lib/memcpy.S > @@ -59,7 +59,7 @@ > #endif > ENTRY(memcpy) > cmp r0, r1 > - bxeq lr > + reteq lr > > enter r4, lr > > @@ -148,7 +148,7 @@ ENTRY(memcpy) > str1b r0, ip, cs, abort=21f > > exit r4, lr > - bx lr > + ret lr > > 9: rsb ip, ip, #4 > cmp ip, #2 > @@ -258,7 +258,7 @@ ENTRY(memcpy) > > .macro copy_abort_end > ldmfd sp!, {r4, lr} > - bx lr > + ret lr > .endm > > ENDPROC(memcpy) > diff --git a/arch/arm/lib/relocate.S b/arch/arm/lib/relocate.S > index 5102bfabde..dd6f2e3bd5 100644 > --- a/arch/arm/lib/relocate.S > +++ b/arch/arm/lib/relocate.S > @@ -61,7 +61,7 @@ ENTRY(relocate_vectors) > stmia r1!, {r2-r8,r10} > #endif > #endif > - bx lr > + ret lr > > ENDPROC(relocate_vectors) > > @@ -127,13 +127,7 @@ relocate_done: > mcr p15, 0, r0, c7, c10, 4 /* drain write buffer */ > #endif > > - /* ARMv4- don't know bx lr but the assembler fails to see that */ > - > -#ifdef __ARM_ARCH_4__ > - mov pc, lr > -#else > - bx lr > -#endif > + ret lr > > ENDPROC(relocate_code) > > diff --git a/arch/arm/lib/setjmp.S b/arch/arm/lib/setjmp.S > index 176a1d5315..2f041aeef0 100644 > --- a/arch/arm/lib/setjmp.S > +++ b/arch/arm/lib/setjmp.S > @@ -17,7 +17,7 @@ ENTRY(setjmp) > mov ip, sp > stm a1, {v1-v8, ip, lr} > mov a1, #0 > - bx lr > + ret lr > ENDPROC(setjmp) > .popsection > > @@ -31,6 +31,6 @@ ENTRY(longjmp) > bne 1f > mov a1, #1 > 1: > - bx lr > + ret lr > ENDPROC(longjmp) > .popsection