[U-Boot] [PATCH 3/6] mpc83xx: Add link vs. load address calculation

Joakim Tjernlund Joakim.Tjernlund at transmode.se
Tue Nov 23 19:48:48 CET 2010


link_off calculates the difference between link address and
actila load address. This is a must for true PIC u-boot.
---
 arch/powerpc/cpu/mpc83xx/start.S |   25 +++++++++++++++++++++++++
 include/common.h                 |    5 +++++
 2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/cpu/mpc83xx/start.S b/arch/powerpc/cpu/mpc83xx/start.S
index 3cac147..ec65f40 100644
--- a/arch/powerpc/cpu/mpc83xx/start.S
+++ b/arch/powerpc/cpu/mpc83xx/start.S
@@ -427,6 +427,31 @@ _end_of_vectors:
 
 	. = 0x3000
 
+	.globl	link_off /* const void * link_off(const void * ptr) */
+	.type	link_off, @function
+	/*
+	 * Calculates the offset between link address and load address
+	 * and subtracs the offset to from its argument(r3)
+	 * This function must be where _GOT2_TABLE_ is defined
+	 */
+link_off:
+	/* GOT hand coded as we cannot clobber r12 */
+	mflr	r4
+	bl	1f
+	.text	2
+0:	.long	.LCTOC1-1f
+	.text
+1:	mflr	r6
+	lwz	r0,0b-1b(r6)
+	add	r6,r0,r6
+	mtlr	r4
+	la	r4,.L__GOT2_TABLE_(r6) /* addi	r4,r6,.L__GOT2_TABLE_ */
+	lwz	r5,.L__GOT2_TABLE_(r6)
+	sub	r4,r5,r4 /* r4 - r5 */
+	sub	r3,r3,r4 /* r4 - r3 */
+	blr
+	.size	link_off, .-link_off
+
 /*
  * This code finishes saving the registers to the exception frame
  * and jumps to the appropriate handler for the exception.
diff --git a/include/common.h b/include/common.h
index 8bca04f..f257ea4 100644
--- a/include/common.h
+++ b/include/common.h
@@ -94,6 +94,9 @@ typedef volatile unsigned char	vu_char;
 #ifdef CONFIG_MPC83xx
 #include <mpc83xx.h>
 #include <asm/immap_83xx.h>
+const void * link_off(const void *);
+#else
+#define link_off(x) ((const void *)(x))
 #endif
 #ifdef	CONFIG_4xx
 #include <ppc4xx.h>
@@ -111,6 +114,8 @@ typedef volatile unsigned char	vu_char;
 #include <asm/arch/hardware.h>
 #endif
 
+#define LINK_OFF(x) ((__typeof__(x))link_off(x))
+
 #include <part.h>
 #include <flash.h>
 #include <image.h>
-- 
1.7.2.2



More information about the U-Boot mailing list