[U-Boot] [PATCH 1/4] ppc: Add const void *link_off(const void *addr)

Joakim Tjernlund Joakim.Tjernlund at transmode.se
Mon Nov 2 19:01:17 CET 2009


Calculates the offset between global data link address
and where the data is actually loaded. Add this offset
to 'addr' arg and return the result.
Useful for true PIC and when relocating code to RAM.
---
 include/common.h |    7 +++++++
 lib_ppc/reloc.S  |   21 +++++++++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/include/common.h b/include/common.h
index 7df9afa..b37cb1d 100644
--- a/include/common.h
+++ b/include/common.h
@@ -108,6 +108,13 @@ typedef volatile unsigned char	vu_char;
 #include <asm/blackfin.h>
 #endif
 
+#ifdef CONFIG_LINK_OFF
+const void * link_off(const void * addr);
+#else
+#define link_off(addr) ((const void *) (addr))
+#endif
+#define LINK_OFF(x) ((__typeof__(&(x)[0]))link_off(x))
+
 #include <part.h>
 #include <flash.h>
 #include <image.h>
diff --git a/lib_ppc/reloc.S b/lib_ppc/reloc.S
index 50f9a83..3ec26cc 100644
--- a/lib_ppc/reloc.S
+++ b/lib_ppc/reloc.S
@@ -47,3 +47,24 @@ trap_reloc:
 	blr
 	.size	trap_reloc, .-trap_reloc
 #endif
+
+#ifdef CONFIG_LINK_OFF
+	/* Calculate the offset between global data link address
+	 * and where the data is actually loaded. Add this offset
+	 * to 'addr' arg and return the result.
+	 * Useful for true PIC and when relocating code to RAM */
+	.globl	link_off
+	.type	link_off, @function
+link_off: /* const void * link_off(const void * addr) */
+	/* In asm as we cannot use the stack */
+	mflr	r5
+	bl	_GLOBAL_OFFSET_TABLE_ at local-4
+	mflr	r4
+	mtlr	r5
+	addi	r4,r4,12 /* find first .got2 entry */
+	lwz	r5,0(r4) /* get link address */
+	subf	r4,r5,r4 /* r4 = r4 - r5 */
+	add	r3,r3,r4 /* r3 = r4 + r3 */
+	blr
+	.size	link_off, .-link_off
+#endif
-- 
1.6.4.4



More information about the U-Boot mailing list