public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Aneesh V <aneesh@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH 2/4] OMAP3+: fix issues with Thumb build
Date: Mon,  6 Feb 2012 17:07:26 +0530	[thread overview]
Message-ID: <1328528248-20872-3-git-send-email-aneesh@ti.com> (raw)
In-Reply-To: <1328528248-20872-1-git-send-email-aneesh@ti.com>

When U-Boot/SPL is built using the Thumb instruction set the
toolchain has a  potential issue with weakly linked symbols.
If a function has a weakly linked default implementation in C
and a real implementation in assembly GCC is confused about the
instruction set of the assembly implementation. As a result
the assembly function that is built in ARM is executed as
if it is Thumb. This results in a crash.

We need to investigate further to see if this is a toolchain
issue or an issue with our usage of it. In the meanwhile, we
can workaround the issue by having both the weakly linked alias
and the real implementation in C.

Signed-off-by: Aneesh V <aneesh@ti.com>
---
 arch/arm/cpu/armv7/cpu.c                       |    4 ++-
 arch/arm/cpu/armv7/omap-common/hwinit-common.c |   25 ++++++++++++++++++++++++
 arch/arm/cpu/armv7/omap-common/lowlevel_init.S |    4 +-
 3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/arch/arm/cpu/armv7/cpu.c b/arch/arm/cpu/armv7/cpu.c
index 662c496..3844556 100644
--- a/arch/arm/cpu/armv7/cpu.c
+++ b/arch/arm/cpu/armv7/cpu.c
@@ -37,8 +37,10 @@
 #include <asm/cache.h>
 #include <asm/armv7.h>
 
-void save_boot_params_default(u32 r0, u32 r1, u32 r2, u32 r3)
+void __attribute__((naked)) save_boot_params_default(u32 r0, u32 r1,
+		u32 r2, u32 r3)
 {
+	asm volatile ("blx lr");
 }
 
 void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3)
diff --git a/arch/arm/cpu/armv7/omap-common/hwinit-common.c b/arch/arm/cpu/armv7/omap-common/hwinit-common.c
index ab46bff..16dfbed 100644
--- a/arch/arm/cpu/armv7/omap-common/hwinit-common.c
+++ b/arch/arm/cpu/armv7/omap-common/hwinit-common.c
@@ -237,3 +237,28 @@ void enable_caches(void)
 	dcache_enable();
 }
 #endif
+
+/*
+ * This function is a wrapper to do_save_boot_params that does the
+ * real implementation of the functionality. 'do_save_boot_params()' is
+ * implemented in assembly because this is called very early in the boot
+ * when stack is not available. We had to wrap it around in this 'naked'
+ * C function because of a potential issue with the tool-chain.
+ *
+ * When U-Boot/SPL is built using the Thumb instruction set compiler
+ * potential issue with weakly linked symbols. If a function has a weakly
+ * linked default implementation in C and a real implementation in assembly
+ * GCC is confused about the instruction set of the assembly implementation
+ * As a result the assembly function that is built in ARM is executed as
+ * if it is Thumb. This results in a crash. The solution (or workaround)
+ * is to have both the weakly linked alias and the real implementation
+ * in C.
+ *
+ * This function runs without a valid stack. So, never try to use a stack
+ * or any other fancy stuff.
+ */
+void __attribute__((naked)) save_boot_params(u32 r0, u32 r1, u32 r2, u32 r4)
+{
+	asm volatile ("ldr r12, =do_save_boot_params");
+	asm volatile ("bx r12");
+}
diff --git a/arch/arm/cpu/armv7/omap-common/lowlevel_init.S b/arch/arm/cpu/armv7/omap-common/lowlevel_init.S
index 35f38ac..38ca054 100644
--- a/arch/arm/cpu/armv7/omap-common/lowlevel_init.S
+++ b/arch/arm/cpu/armv7/omap-common/lowlevel_init.S
@@ -28,8 +28,8 @@
 
 #include <asm/arch/omap.h>
 
-.global save_boot_params
-save_boot_params:
+.global do_save_boot_params
+do_save_boot_params:
 	/*
 	 * See if the rom code passed pointer is valid:
 	 * It is not valid if it is not in non-secure SRAM
-- 
1.7.1

  parent reply	other threads:[~2012-02-06 11:37 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-06 11:37 [U-Boot] [RFC PATCH 0/4] Enable Thumb build for ARM platforms Aneesh V
2012-02-06 11:37 ` [U-Boot] [RFC PATCH 1/4] ARM: enable Thumb build Aneesh V
2012-02-06 18:45   ` Tom Rini
2012-02-07  7:43     ` Aneesh V
2012-02-06 11:37 ` Aneesh V [this message]
2012-02-06 21:06   ` [U-Boot] [RFC PATCH 2/4] OMAP3+: fix issues with " Albert ARIBAUD
2012-02-07  7:49     ` Aneesh V
2012-02-09  8:58     ` Aneesh V
2012-02-06 11:37 ` [U-Boot] [RFC PATCH 3/4] OMAP3+: Use -march=armv7-a and thereby enable Thumb-2 Aneesh V
2012-02-06 11:37 ` [U-Boot] [RFC PATCH 4/4] OMAP4: enable Thumb build Aneesh V
2012-02-06 12:26 ` [U-Boot] [RFC PATCH 0/4] Enable Thumb build for ARM platforms Aneesh V
2012-02-06 13:22   ` Aneesh V
2012-02-15 13:57 ` [U-Boot] [PATCH " Aneesh V
2012-02-15 13:57 ` [U-Boot] [PATCH 1/4] ARM: enable Thumb build Aneesh V
2012-02-15 13:57 ` [U-Boot] [PATCH 2/4] arm: add %function attribute to assembly functions Aneesh V
2012-02-17 11:09   ` Aneesh V
2012-02-18 10:13     ` Albert ARIBAUD
2012-02-18 13:24       ` Aneesh V
2012-02-18 15:04         ` Albert ARIBAUD
2012-02-18 16:34         ` Aneesh V
2012-02-18 16:48           ` Albert ARIBAUD
2012-02-20 16:08             ` Aneesh V
2012-02-23 11:06               ` Aneesh V
2012-02-17 17:13   ` Mike Frysinger
2012-02-18 11:12     ` Aneesh V
2012-02-18 11:34       ` Albert ARIBAUD
2012-02-18 22:03   ` Simon Glass
2012-02-19  7:15     ` Mike Frysinger
2012-02-20 20:07       ` Tom Rini
2012-02-20 21:53         ` Simon Glass
2012-02-21  4:19           ` Mike Frysinger
2012-02-21  4:44             ` Simon Glass
2012-02-21 14:33             ` Tom Rini
2012-02-21 15:42               ` Mike Frysinger
2012-02-21 18:03                 ` Aneesh V
2012-02-21 19:28                   ` Mike Frysinger
2012-02-21 20:01                     ` Aneesh V
2012-02-21  4:18         ` Mike Frysinger
2012-02-15 13:57 ` [U-Boot] [PATCH 3/4] armv7: Use -march=armv7-a and thereby enable Thumb-2 Aneesh V
2012-02-15 13:57 ` [U-Boot] [PATCH 4/4] OMAP4: enable Thumb build Aneesh V
2012-02-23 13:39 ` [U-Boot] [PATCH v2 1/5] arm: adapt asm/linkage.h from Linux Aneesh V
2012-02-23 14:01   ` Aneesh V
2012-02-23 13:39 ` [U-Boot] [PATCH v2 2/5] armv7: add appropriate headers for assembly functions Aneesh V
2012-02-23 13:39 ` [U-Boot] [PATCH v2 3/5] ARM: enable Thumb build Aneesh V
2012-02-23 14:57   ` Mike Frysinger
2012-02-23 17:28     ` Aneesh V
2012-02-23 17:34       ` Tom Rini
2012-02-23 17:49         ` Aneesh V
2012-02-23 17:51           ` Tom Rini
2012-02-23 18:09             ` Aneesh V
2012-02-23 18:13               ` Aneesh V
2012-02-23 18:05           ` Mike Frysinger
2012-02-23 18:04       ` Mike Frysinger
2012-02-23 18:12         ` Aneesh V
2012-02-23 13:39 ` [U-Boot] [PATCH v2 4/5] armv7: Use -march=armv7-a and thereby enable Thumb-2 Aneesh V
2012-02-23 13:39 ` [U-Boot] [PATCH v2 5/5] OMAP4: enable Thumb build Aneesh V
2012-02-23 14:06 ` [U-Boot] [PATCH v3 1/6] arm: adapt asm/linkage.h from Linux Aneesh V
2012-02-23 14:59   ` Mike Frysinger
2012-02-23 15:24     ` Tom Rini
2012-02-23 16:57       ` Mike Frysinger
2012-02-23 17:40     ` Aneesh V
2012-02-23 23:52       ` Mike Frysinger
2012-02-24 10:30         ` Aneesh V
2012-02-23 14:06 ` [U-Boot] [PATCH v3 2/6] armv7: add appropriate headers for assembly functions Aneesh V
2012-02-23 14:59   ` Mike Frysinger
2012-02-23 14:06 ` [U-Boot] [PATCH v3 3/6] ARM: enable Thumb build Aneesh V
2012-02-23 14:06 ` [U-Boot] [PATCH v3 4/6] armv7: Use -march=armv7-a and thereby enable Thumb-2 Aneesh V
2012-02-23 15:05   ` Mike Frysinger
2012-02-23 17:50     ` Aneesh V
2012-02-23 14:06 ` [U-Boot] [PATCH v3 5/6] omap4+: Avoid using __attribute__ ((__packed__)) Aneesh V
2012-02-23 14:21   ` Tom Rini
2012-02-23 14:56     ` Aneesh V
2012-02-23 15:03       ` Mike Frysinger
2012-02-23 15:03     ` Mike Frysinger
2012-02-23 15:42       ` Aneesh V
2012-02-23 14:06 ` [U-Boot] [PATCH v3 6/6] OMAP4: enable Thumb build Aneesh V
2012-03-08 17:10 ` [U-Boot] [PATCH 1/6] arm: adapt asm/linkage.h from Linux Aneesh V
2012-03-08 17:14   ` Aneesh V
2012-03-08 17:10 ` [U-Boot] [PATCH 2/6] armv7: add appropriate headers for assembly functions Aneesh V
2012-03-08 17:10 ` [U-Boot] [PATCH 3/6] ARM: enable Thumb build Aneesh V
2012-03-08 17:10 ` [U-Boot] [PATCH 4/6] armv7: Use -march=armv7-a and thereby enable Thumb-2 Aneesh V
2012-03-08 17:10 ` [U-Boot] [PATCH 5/6] omap4+: Avoid using __attribute__ ((__packed__)) Aneesh V
2012-03-08 17:10 ` [U-Boot] [PATCH 6/6] OMAP4: enable Thumb build Aneesh V

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1328528248-20872-3-git-send-email-aneesh@ti.com \
    --to=aneesh@ti.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox