From 5b7dd8163d517c8f52971bc16fe92f831553d2bb Mon Sep 17 00:00:00 2001 From: Gabor Juhos Date: Thu, 24 Jan 2013 06:27:51 +0000 Subject: MIPS: start.S: fix boundary check in relocate_code The loop code copies more data with one than necessary due to the 'ble' instuction. Use the 'blt' instruction instead to fix that. Due to the lack of suitable hardware the Xburst specific code is compile tested only. However the change is quite obvious. Signed-off-by: Gabor Juhos Cc: Daniel Schwierzeck --- arch/mips/cpu/xburst/start.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/mips/cpu/xburst/start.S') diff --git a/arch/mips/cpu/xburst/start.S b/arch/mips/cpu/xburst/start.S index 3a8280cb0a..194d7452e1 100644 --- a/arch/mips/cpu/xburst/start.S +++ b/arch/mips/cpu/xburst/start.S @@ -87,7 +87,7 @@ relocate_code: lw t3, 0(t0) sw t3, 0(t1) addu t0, 4 - ble t0, t2, 1b + blt t0, t2, 1b addu t1, 4 /* If caches were enabled, we would have to flush them here. */ -- cgit From 025f2b338072781cd747bf7365cf43fcf9f40f1a Mon Sep 17 00:00:00 2001 From: Gabor Juhos Date: Wed, 30 Jan 2013 04:56:37 +0000 Subject: MIPS: simplify relocated _G_O_T_ address calculation The difference between the address of the original and the relocated _GLOBAL_OFFSET_TABLE_ is always the same as the relocation offset. The relocation offset is already computed and it is available in the 's1/t6' register. Use that to adjust the relocated _G_O_T_ address, instead of calculating the offset again from the _gp value. Signed-off-by: Gabor Juhos Cc: Daniel Schwierzeck Cc: Xiangfu Liu --- arch/mips/cpu/xburst/start.S | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'arch/mips/cpu/xburst/start.S') diff --git a/arch/mips/cpu/xburst/start.S b/arch/mips/cpu/xburst/start.S index 194d7452e1..9e637dfe99 100644 --- a/arch/mips/cpu/xburst/start.S +++ b/arch/mips/cpu/xburst/start.S @@ -122,7 +122,6 @@ relocate_code: jr t0 nop - .word _gp .word _GLOBAL_OFFSET_TABLE_ .word uboot_end_data .word uboot_end @@ -137,9 +136,7 @@ in_ram: */ lw t3, -4(t0) # t3 <-- num_got_entries lw t4, -16(t0) # t4 <-- _GLOBAL_OFFSET_TABLE_ - lw t5, -20(t0) # t5 <-- _gp - sub t4, t5 # compute offset - add t4, t4, gp # t4 now holds relocated _G_O_T_ + add t4, t6 # t4 now holds relocated _G_O_T_ addi t4, t4, 8 # skipping first two entries li t2, 2 1: -- cgit From 6d8622788020265a9e98e8345c6435c8680c992c Mon Sep 17 00:00:00 2001 From: Gabor Juhos Date: Wed, 30 Jan 2013 04:51:06 +0000 Subject: MIPS: xburst: simplify relocation offset calculation The current code uses four instructions and a temporary register to calculate the relocation offset and to adjust the gp register. The relocation offset can be calculated directly from the CONFIG_SYS_MONITOR_BASE constant and from the destination address. The resulting offset can be used to adjust the gp pointer. This approach makes the code a bit simpler because it needs two instructions only. Signed-off-by: Gabor Juhos Cc: Daniel Schwierzeck Cc: Xiangfu Liu --- arch/mips/cpu/xburst/start.S | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'arch/mips/cpu/xburst/start.S') diff --git a/arch/mips/cpu/xburst/start.S b/arch/mips/cpu/xburst/start.S index 9e637dfe99..50b7fb1021 100644 --- a/arch/mips/cpu/xburst/start.S +++ b/arch/mips/cpu/xburst/start.S @@ -64,19 +64,13 @@ relocate_code: move sp, a0 # set new stack pointer li t0, CONFIG_SYS_MONITOR_BASE + sub t6, a2, t0 # t6 <-- relocation offset + la t3, in_ram lw t2, -12(t3) # t2 <-- uboot_end_data move t1, a2 - /* - * Fix $gp: - * - * New $gp = (Old $gp - CONFIG_SYS_MONITOR_BASE) + Destination Address - */ - move t6, gp - sub gp, CONFIG_SYS_MONITOR_BASE - add gp, a2 # gp now adjusted - sub t6, gp, t6 # t6 <-- relocation offset + add gp, t6 # adjust gp /* * t0 = source address -- cgit From 696a3b2a5368360c149335e2a35b8900a78f47fa Mon Sep 17 00:00:00 2001 From: Daniel Schwierzeck Date: Tue, 12 Feb 2013 22:22:13 +0100 Subject: MIPS: start.S: optimize BSS initialization Get the start and end address for clearing BSS from the newly introduced symbols __bss_start and __bss_end. After GOT is relocated, those symbols are already pointing to the correct addresses. Also optimize the loop by moving the address incrementation to the delay slot to avoid the initial sub instruction. Signed-off-by: Daniel Schwierzeck --- arch/mips/cpu/xburst/start.S | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'arch/mips/cpu/xburst/start.S') diff --git a/arch/mips/cpu/xburst/start.S b/arch/mips/cpu/xburst/start.S index 50b7fb1021..bd9390ae5e 100644 --- a/arch/mips/cpu/xburst/start.S +++ b/arch/mips/cpu/xburst/start.S @@ -143,16 +143,19 @@ in_ram: blt t2, t3, 1b addi t4, 4 - /* Clear BSS */ - lw t1, -12(t0) # t1 <-- uboot_end_data - lw t2, -8(t0) # t2 <-- uboot_end - add t1, t6 # adjust pointers - add t2, t6 - - sub t1, 4 -1: addi t1, 4 - bltl t1, t2, 1b - sw zero, 0(t1) + /* + * Clear BSS + * + * GOT is now relocated. Thus __bss_start and __bss_end can be + * accessed directly via $gp. + */ + la t1, __bss_start # t1 <-- __bss_start + la t2, __bss_end # t2 <-- __bss_end + +1: + sw zero, 0(t1) + blt t1, t2, 1b + addi t1, 4 move a0, a1 # a0 <-- gd la t9, board_init_r -- cgit From 28875e2c4731296ee7ed645d07f1c28c0301f1c4 Mon Sep 17 00:00:00 2001 From: Daniel Schwierzeck Date: Tue, 12 Feb 2013 22:22:13 +0100 Subject: MIPS: start.S: use symbol __image_copy_end for U-Boot image relocation Use the newly introduced symbol __image_copy_end as end address for relocation of U-Boot image. This is needed for dynamic relocation added in later patches. This patch obsoletes the symbols uboot_end and uboot_end_data which are removed. Signed-off-by: Daniel Schwierzeck --- arch/mips/cpu/xburst/start.S | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'arch/mips/cpu/xburst/start.S') diff --git a/arch/mips/cpu/xburst/start.S b/arch/mips/cpu/xburst/start.S index bd9390ae5e..6b30d3ee8a 100644 --- a/arch/mips/cpu/xburst/start.S +++ b/arch/mips/cpu/xburst/start.S @@ -67,7 +67,7 @@ relocate_code: sub t6, a2, t0 # t6 <-- relocation offset la t3, in_ram - lw t2, -12(t3) # t2 <-- uboot_end_data + lw t2, -12(t3) # t2 <-- __image_copy_end move t1, a2 add gp, t6 # adjust gp @@ -116,9 +116,8 @@ relocate_code: jr t0 nop + .word __image_copy_end .word _GLOBAL_OFFSET_TABLE_ - .word uboot_end_data - .word uboot_end .word num_got_entries in_ram: @@ -129,7 +128,7 @@ in_ram: * generated by GNU ld. Skip these reserved entries from relocation. */ lw t3, -4(t0) # t3 <-- num_got_entries - lw t4, -16(t0) # t4 <-- _GLOBAL_OFFSET_TABLE_ + lw t4, -8(t0) # t4 <-- _GLOBAL_OFFSET_TABLE_ add t4, t6 # t4 now holds relocated _G_O_T_ addi t4, t4, 8 # skipping first two entries li t2, 2 -- cgit From 04380c651a2ff0d1495822321d2b7668dcd02537 Mon Sep 17 00:00:00 2001 From: Gabor Juhos Date: Tue, 12 Feb 2013 22:22:13 +0100 Subject: MIPS: add dynamic relocation support The code handles relocation entries with the following relocation types only: mips32: R_MIPS_REL32 mips64: R_MIPS_REL+R_MIPS_64 xburst: R_MIPS_REL32 Other relocation entries are skipped without processing. The code must be extended if other relocation types must be supported. Add -pie to LDFLAGS_FINAL to generate the .rel.dyn fixup table, which will be applied to the relocated image before transferring control to it. The CONFIG_NEEDS_MANUAL_RELOC is not needed after the patch, so remove that as well. Signed-off-by: Gabor Juhos Signed-off-by: Daniel Schwierzeck --- arch/mips/cpu/xburst/start.S | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'arch/mips/cpu/xburst/start.S') diff --git a/arch/mips/cpu/xburst/start.S b/arch/mips/cpu/xburst/start.S index 6b30d3ee8a..d2c064b017 100644 --- a/arch/mips/cpu/xburst/start.S +++ b/arch/mips/cpu/xburst/start.S @@ -116,6 +116,8 @@ relocate_code: jr t0 nop + .word __rel_dyn_end + .word __rel_dyn_start .word __image_copy_end .word _GLOBAL_OFFSET_TABLE_ .word num_got_entries @@ -142,6 +144,32 @@ in_ram: blt t2, t3, 1b addi t4, 4 + /* Update dynamic relocations */ + lw t1, -16(t0) # t1 <-- __rel_dyn_start + lw t2, -20(t0) # t2 <-- __rel_dyn_end + + b 2f # skip first reserved entry + addi t1, 8 + +1: + lw t3, -4(t1) # t3 <-- relocation info + + sub t3, 3 + bnez t3, 2f # skip non R_MIPS_REL32 entries + nop + + lw t3, -8(t1) # t3 <-- location to fix up in FLASH + + lw t4, 0(t3) # t4 <-- original pointer + add t4, t6 # t4 <-- adjusted pointer + + add t3, t6 # t3 <-- location to fix up in RAM + sw t4, 0(t3) + +2: + blt t1, t2, 1b + addi t1, 8 # each rel.dyn entry is 8 bytes + /* * Clear BSS * -- cgit