link_off calculates the difference between link address and
actual load address. This is a must for true PIC u-boot.

Signed-off-by: Joakim Tjernlund <joakim.tjernl...@transmode.se>
---
 arch/powerpc/cpu/mpc83xx/start.S |   26 ++++++++++++++++++++++++++
 include/common.h                 |    7 +++++++
 2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/cpu/mpc83xx/start.S b/arch/powerpc/cpu/mpc83xx/start.S
index 1ab8c88..16aed0a 100644
--- a/arch/powerpc/cpu/mpc83xx/start.S
+++ b/arch/powerpc/cpu/mpc83xx/start.S
@@ -419,6 +419,32 @@ ProgramCheck:
 _end_of_vectors:
 
        . = 0x3000
+#ifdef CONFIG_SYS_TRUE_PIC
+       .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
+#endif
 
 /*
  * This code finishes saving the registers to the exception frame
diff --git a/include/common.h b/include/common.h
index 189ad81..a04bd27 100644
--- a/include/common.h
+++ b/include/common.h
@@ -112,6 +112,13 @@ typedef volatile unsigned char     vu_char;
 #include <asm/arch/hardware.h>
 #endif
 
+#ifdef CONFIG_SYS_TRUE_PIC
+const void * link_off(const void *);
+#else
+#define link_off(x) ((const void *)(x))
+#endif
+#define LINK_OFF(x) ((__typeof__(x))link_off(x))
+
 #include <part.h>
 #include <flash.h>
 #include <image.h>
-- 
1.7.2.2

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to