firmware: Optimize loading relocation type
PATCH 1/2 firmware: Optimize loading relocation type
't5' already contains relocation type so don't bother reloading it.
---
firmware/fw_base.S | 1 - 1 file changed, 1 deletion(-)
firmware/fw_base.S +0 -1
@@ -95,7 +95,6 @@ _try_lottery: lla t4, __dyn_sym_start 4: - REG_L t5, -(REGBYTES*2)(t0) /* t5 <-- relocation info:type */ srli t6, t5, SYM_INDEX /* t6 <--- sym table index */ andi t5, t5, 0xFF /* t5 <--- relocation type */ li t3, RELOC_TYPE
Signature · 1 line
2.25.1
PATCH 2/2 firmware: Change to use positive offset to access relocation entries
The codes currently skip the very first relocation entry, but later reference the elements in the relocation entry using minus offsets.
Change to use positive offsets so that there is no need to skip the first relocation entry.
---
firmware/fw_base.S | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
firmware/fw_base.S +7 -8
@@ -79,13 +79,12 @@ _try_lottery: lla t0, __rel_dyn_start lla t1, __rel_dyn_end beq t0, t1, _relocate_done - j 5f 2: - REG_L t5, -(REGBYTES*2)(t0) /* t5 <-- relocation info:type */ + REG_L t5, REGBYTES(t0) /* t5 <-- relocation info:type */ li t3, R_RISCV_RELATIVE /* reloc type R_RISCV_RELATIVE */ bne t5, t3, 3f - REG_L t3, -(REGBYTES*3)(t0) - REG_L t5, -(REGBYTES)(t0) /* t5 <-- addend */ + REG_L t3, 0(t0) + REG_L t5, (REGBYTES * 2)(t0) /* t5 <-- addend */ add t5, t5, t2 add t3, t3, t2 REG_S t5, 0(t3) /* store runtime address to the GOT entry */
@@ -101,11 +100,11 @@ _try_lottery: bne t5, t3, 5f /* address R_RISCV_64 or R_RISCV_32 cases*/ - REG_L t3, -(REGBYTES*3)(t0) + REG_L t3, 0(t0) li t5, SYM_SIZE mul t6, t6, t5 add s5, t4, t6 - REG_L t6, -(REGBYTES)(t0) /* t0 <-- addend */ + REG_L t6, (REGBYTES * 2)(t0) /* t0 <-- addend */ REG_L t5, REGBYTES(s5) add t5, t5, t6 add t5, t5, t2 /* t5 <-- location to fix up in RAM */
@@ -113,8 +112,8 @@ _try_lottery: REG_S t5, 0(t3) /* store runtime address to the variable */ 5: - addi t0, t0, (REGBYTES*3) - ble t0, t1, 2b + addi t0, t0, (REGBYTES * 3) + blt t0, t1, 2b j _relocate_done _wait_relocate_copy_done: j _wait_for_boot_hart
Signature · 1 line
2.25.1
PATCH 2/2 firmware: Change to use positive offset to access relocation entries
Quoted 8 lines · On Tue, Apr 4, 2023 at 10:17?AM Bin Meng <[email protected]> wrote:
The codes currently skip the very first relocation entry, but later reference the elements in the relocation entry using minus offsets.
Change to use positive offsets so that there is no need to skip the first relocation entry.
Signed-off-by Bin Meng <[email protected]>
Looks good to me.
Regards,
Anup
Quoted 54 lines
---
firmware/fw_base.S | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)firmware/fw_base.S +7
-9@@ -79,13 +79,12 @@ _try_lottery: lla t0, __rel_dyn_start lla t1, __rel_dyn_end beq t0, t1, _relocate_done - j 5f 2: - REG_L t5, -(REGBYTES*2)(t0) /* t5 <-- relocation info:type */ + REG_L t5, REGBYTES(t0) /* t5 <-- relocation info:type */ li t3, R_RISCV_RELATIVE /* reloc type R_RISCV_RELATIVE */ bne t5, t3, 3f - REG_L t3, -(REGBYTES*3)(t0) - REG_L t5, -(REGBYTES)(t0) /* t5 <-- addend */ + REG_L t3, 0(t0) + REG_L t5, (REGBYTES * 2)(t0) /* t5 <-- addend */ add t5, t5, t2 add t3, t3, t2 REG_S t5, 0(t3) /* store runtime address to the GOT entry */@@ -101,11 +100,11 @@ _try_lottery: bne t5, t3, 5f /* address R_RISCV_64 or R_RISCV_32 cases*/ - REG_L t3, -(REGBYTES*3)(t0) + REG_L t3, 0(t0) li t5, SYM_SIZE mul t6, t6, t5 add s5, t4, t6 - REG_L t6, -(REGBYTES)(t0) /* t0 <-- addend */ + REG_L t6, (REGBYTES * 2)(t0) /* t0 <-- addend */ REG_L t5, REGBYTES(s5) add t5, t5, t6 add t5, t5, t2 /* t5 <-- location to fix up in RAM */@@ -113,8 +112,8 @@ _try_lottery: REG_S t5, 0(t3) /* store runtime address to the variable */ 5: - addi t0, t0, (REGBYTES*3) - ble t0, t1, 2b + addi t0, t0, (REGBYTES * 3) + blt t0, t1, 2b j _relocate_done _wait_relocate_copy_done: j _wait_for_boot_hart --2.25.1
PATCH 2/2 firmware: Change to use positive offset to access relocation entries
In reply to Bin Meng? 2023-04-04???? 12:46 +0800?Bin Meng???
Quoted 7 lines
The codes currently skip the very first relocation entry, but later reference the elements in the relocation entry using minus offsets.
Change to use positive offsets so that there is no need to skip the first relocation entry.
Signed-off-by Bin Meng <[email protected]>
LGTM
Quoted 55 lines
---
?firmware/fw_base.S | 15 +++++++--------
?1 file changed, 7 insertions(+), 8 deletions(-)firmware/fw_base.S +0
-0@@ -79,13 +79,12 @@ _try_lottery:????????lla?????t0,
__rel_dyn_start
????????lla?????t1,__rel_dyn_end
????????beq?????t0, t1,_relocate_done
-???????j???????5f
?2:
-???????REG_L???t5, -(REGBYTES*2)(t0)???/* t5 <-- relocation info:type */ +???????REG_L???t5, REGBYTES(t0)????????/* t5 <-- relocation info:type */ ????????li??????t3, R_RISCV_RELATIVE????/* reloc typeR_RISCV_RELATIVE*/ ????????bne?????t5, t3, 3f
-???????REG_L???t3, -(REGBYTES*3)(t0)
-???????REG_L???t5, -(REGBYTES)(t0)?????/* t5 <-- addend */ +???????REG_L???t3, 0(t0)
+???????REG_L???t5, (REGBYTES * 2)(t0)??/* t5 <-- addend */ ????????add?????t5, t5, t2
????????add?????t3, t3, t2
????????REG_S???t5, 0(t3)???????????????/* store runtime address to the GOT entry */firmware/fw_base.S +0
-0@@ -101,11 +100,11 @@ _try_lottery:????????bne?????t5, t3, 5f
?
????????/* addressR_RISCV_64orR_RISCV_32cases*/ -???????REG_L???t3, -(REGBYTES*3)(t0)
+???????REG_L???t3, 0(t0)
????????li??????t5,SYM_SIZE
????????mul?????t6, t6, t5
????????add?????s5, t4, t6
-???????REG_L???t6, -(REGBYTES)(t0)?????/* t0 <-- addend */ +???????REG_L???t6, (REGBYTES * 2)(t0)??/* t0 <-- addend */ ????????REG_L???t5, REGBYTES(s5)
????????add?????t5, t5, t6
????????add?????t5, t5, t2??????????????/* t5 <-- location to fix up in RAM */firmware/fw_base.S +0
-0@@ -113,8 +112,8 @@ _try_lottery:????????REG_S???t5, 0(t3)???????????????/* store runtime address to the variable */ ?
?5:
-???????addi????t0, t0, (REGBYTES*3)
-???????ble?????t0, t1, 2b
+???????addi????t0, t0, (REGBYTES * 3)
+???????blt?????t0, t1, 2b
????????j???????_relocate_done
?_wait_relocate_copy_done:
????????j???????_wait_for_boot_hartSignature · 1 line
2.25.1
Anup Patel
AppliedPATCH 2/2 firmware: Change to use positive offset to access relocation entries
In reply to Bin MengQuoted 8 lines · On Tue, Apr 4, 2023 at 10:17?AM Bin Meng <[email protected]> wrote:
The codes currently skip the very first relocation entry, but later reference the elements in the relocation entry using minus offsets.
Change to use positive offsets so that there is no need to skip the first relocation entry.
Signed-off-by Bin Meng <[email protected]>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 54 lines
---
firmware/fw_base.S | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)firmware/fw_base.S +7
-9@@ -79,13 +79,12 @@ _try_lottery: lla t0, __rel_dyn_start lla t1, __rel_dyn_end beq t0, t1, _relocate_done - j 5f 2: - REG_L t5, -(REGBYTES*2)(t0) /* t5 <-- relocation info:type */ + REG_L t5, REGBYTES(t0) /* t5 <-- relocation info:type */ li t3, R_RISCV_RELATIVE /* reloc type R_RISCV_RELATIVE */ bne t5, t3, 3f - REG_L t3, -(REGBYTES*3)(t0) - REG_L t5, -(REGBYTES)(t0) /* t5 <-- addend */ + REG_L t3, 0(t0) + REG_L t5, (REGBYTES * 2)(t0) /* t5 <-- addend */ add t5, t5, t2 add t3, t3, t2 REG_S t5, 0(t3) /* store runtime address to the GOT entry */@@ -101,11 +100,11 @@ _try_lottery: bne t5, t3, 5f /* address R_RISCV_64 or R_RISCV_32 cases*/ - REG_L t3, -(REGBYTES*3)(t0) + REG_L t3, 0(t0) li t5, SYM_SIZE mul t6, t6, t5 add s5, t4, t6 - REG_L t6, -(REGBYTES)(t0) /* t0 <-- addend */ + REG_L t6, (REGBYTES * 2)(t0) /* t0 <-- addend */ REG_L t5, REGBYTES(s5) add t5, t5, t6 add t5, t5, t2 /* t5 <-- location to fix up in RAM */@@ -113,8 +112,8 @@ _try_lottery: REG_S t5, 0(t3) /* store runtime address to the variable */ 5: - addi t0, t0, (REGBYTES*3) - ble t0, t1, 2b + addi t0, t0, (REGBYTES * 3) + blt t0, t1, 2b j _relocate_done _wait_relocate_copy_done: j _wait_for_boot_hart --2.25.1
PATCH 1/2 firmware: Optimize loading relocation type
In reply to Bin MengQuoted 4 lines · On Tue, Apr 4, 2023 at 10:16?AM Bin Meng <[email protected]> wrote:
't5' already contains relocation type so don't bother reloading it.
Signed-off-by Bin Meng <[email protected]>
Looks good to me.
Regards,
Anup
Quoted 20 lines
---
firmware/fw_base.S | 1 - 1 file changed, 1 deletion(-)firmware/fw_base.S +0
-2@@ -95,7 +95,6 @@ _try_lottery: lla t4, __dyn_sym_start 4: - REG_L t5, -(REGBYTES*2)(t0) /* t5 <-- relocation info:type */ srli t6, t5, SYM_INDEX /* t6 <--- sym table index */ andi t5, t5, 0xFF /* t5 <--- relocation type */ li t3, RELOC_TYPE --2.25.1
PATCH 1/2 firmware: Optimize loading relocation type
In reply to Bin Meng? 2023-04-04???? 12:46 +0800?Bin Meng???
Quoted 3 lines
't5' already contains relocation type so don't bother reloading it.
Signed-off-by Bin Meng <[email protected]>
LGTM
Quoted 21 lines
---
?firmware/fw_base.S | 1 -
?1 file changed, 1 deletion(-)firmware/fw_base.S +0
-0@@ -95,7 +95,6 @@ _try_lottery:????????lla?????t4,
__dyn_sym_start
?
?4:
-???????REG_L???t5, -(REGBYTES*2)(t0)???/* t5 <-- relocation info:type */ ????????srli????t6, t5, SYM_INDEX???????/* t6 <--- sym table index */ ????????andi????t5, t5, 0xFF????????????/* t5 <--- relocation type */ ????????li??????t3,RELOC_TYPESignature · 1 line
2.25.1
Anup Patel
AppliedPATCH 1/2 firmware: Optimize loading relocation type
In reply to Bin MengQuoted 4 lines · On Tue, Apr 4, 2023 at 10:16?AM Bin Meng <[email protected]> wrote:
't5' already contains relocation type so don't bother reloading it.
Signed-off-by Bin Meng <[email protected]>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 20 lines
---
firmware/fw_base.S | 1 - 1 file changed, 1 deletion(-)firmware/fw_base.S +0
-2@@ -95,7 +95,6 @@ _try_lottery: lla t4, __dyn_sym_start 4: - REG_L t5, -(REGBYTES*2)(t0) /* t5 <-- relocation info:type */ srli t6, t5, SYM_INDEX /* t6 <--- sym table index */ andi t5, t5, 0xFF /* t5 <--- relocation type */ li t3, RELOC_TYPE --2.25.1