Skip to content

Commit 04a6a8e

Browse files
Song Shuaipalmer-dabbelt
authored andcommitted
riscv: kexec: Cleanup riscv_kexec_relocate
For readability and simplicity, cleanup the riscv_kexec_relocate code: - Re-sort the first 4 `mv` instructions against `riscv_kexec_method()` - Eliminate registers for debugging (s9,s10,s11) and storing const-value (s5,s6) - Replace `jalr` with `jr` for no-link jump I tested this on Qemu virt machine and works as it was. Signed-off-by: Song Shuai <songshuaishuai@tinylab.org> Link: https://lore.kernel.org/r/20230907103304.590739-2-songshuaishuai@tinylab.org Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 06c2afb commit 04a6a8e

1 file changed

Lines changed: 23 additions & 29 deletions

File tree

arch/riscv/kernel/kexec_relocate.S

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,17 @@ SYM_CODE_START(riscv_kexec_relocate)
1717
* s1: (const) Phys address to jump to after relocation
1818
* s2: (const) Phys address of the FDT image
1919
* s3: (const) The hartid of the current hart
20-
* s4: Pointer to the destination address for the relocation
21-
* s5: (const) Number of words per page
22-
* s6: (const) 1, used for subtraction
23-
* s7: (const) kernel_map.va_pa_offset, used when switching MMU off
24-
* s8: (const) Physical address of the main loop
25-
* s9: (debug) indirection page counter
26-
* s10: (debug) entry counter
27-
* s11: (debug) copied words counter
20+
* s4: (const) kernel_map.va_pa_offset, used when switching MMU off
21+
* s5: Pointer to the destination address for the relocation
22+
* s6: (const) Physical address of the main loop
2823
*/
2924
mv s0, a0
3025
mv s1, a1
3126
mv s2, a2
3227
mv s3, a3
33-
mv s4, zero
34-
li s5, (PAGE_SIZE / RISCV_SZPTR)
35-
li s6, 1
36-
mv s7, a4
37-
mv s8, zero
38-
mv s9, zero
39-
mv s10, zero
40-
mv s11, zero
28+
mv s4, a4
29+
mv s5, zero
30+
mv s6, zero
4131

4232
/* Disable / cleanup interrupts */
4333
csrw CSR_SIE, zero
@@ -52,31 +42,36 @@ SYM_CODE_START(riscv_kexec_relocate)
5242
* the start of the loop below so that we jump there in
5343
* any case.
5444
*/
55-
la s8, 1f
56-
sub s8, s8, s7
57-
csrw CSR_STVEC, s8
45+
la s6, 1f
46+
sub s6, s6, s4
47+
csrw CSR_STVEC, s6
48+
49+
/*
50+
* With C-extension, here we get 42 Bytes and the next
51+
* .align directive would pad zeros here up to 44 Bytes.
52+
* So manually put a nop here to avoid zeros padding.
53+
*/
54+
nop
5855

5956
/* Process entries in a loop */
6057
.align 2
6158
1:
62-
addi s10, s10, 1
6359
REG_L t0, 0(s0) /* t0 = *image->entry */
6460
addi s0, s0, RISCV_SZPTR /* image->entry++ */
6561

6662
/* IND_DESTINATION entry ? -> save destination address */
6763
andi t1, t0, 0x1
6864
beqz t1, 2f
69-
andi s4, t0, ~0x1
65+
andi s5, t0, ~0x1
7066
j 1b
7167

7268
2:
7369
/* IND_INDIRECTION entry ? -> update next entry ptr (PA) */
7470
andi t1, t0, 0x2
7571
beqz t1, 2f
7672
andi s0, t0, ~0x2
77-
addi s9, s9, 1
7873
csrw CSR_SATP, zero
79-
jalr zero, s8, 0
74+
jr s6
8075

8176
2:
8277
/* IND_DONE entry ? -> jump to done label */
@@ -92,14 +87,13 @@ SYM_CODE_START(riscv_kexec_relocate)
9287
andi t1, t0, 0x8
9388
beqz t1, 1b /* Unknown entry type, ignore it */
9489
andi t0, t0, ~0x8
95-
mv t3, s5 /* i = num words per page */
90+
li t3, (PAGE_SIZE / RISCV_SZPTR) /* i = num words per page */
9691
3: /* copy loop */
9792
REG_L t1, (t0) /* t1 = *src_ptr */
98-
REG_S t1, (s4) /* *dst_ptr = *src_ptr */
93+
REG_S t1, (s5) /* *dst_ptr = *src_ptr */
9994
addi t0, t0, RISCV_SZPTR /* stc_ptr++ */
100-
addi s4, s4, RISCV_SZPTR /* dst_ptr++ */
101-
sub t3, t3, s6 /* i-- */
102-
addi s11, s11, 1 /* c++ */
95+
addi s5, s5, RISCV_SZPTR /* dst_ptr++ */
96+
addi t3, t3, -0x1 /* i-- */
10397
beqz t3, 1b /* copy done ? */
10498
j 3b
10599

@@ -146,7 +140,7 @@ SYM_CODE_START(riscv_kexec_relocate)
146140
*/
147141
fence.i
148142

149-
jalr zero, a2, 0
143+
jr a2
150144

151145
SYM_CODE_END(riscv_kexec_relocate)
152146
riscv_kexec_relocate_end:

0 commit comments

Comments
 (0)