From 3dfc88158c3b35c0a089b0b0ff49198cf16141df Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 12 May 2025 13:57:53 +0100 Subject: [PATCH] [riscv] Construct page tables based on link-time virtual addresses Always construct the page tables based on the link-time address values even if relocations have already been applied, on the assumption that relocations will be reapplied after paging has been enabled. Signed-off-by: Michael Brown --- src/arch/riscv/prefix/libprefix.S | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/arch/riscv/prefix/libprefix.S b/src/arch/riscv/prefix/libprefix.S index 9a706af50..a24b34fa4 100644 --- a/src/arch/riscv/prefix/libprefix.S +++ b/src/arch/riscv/prefix/libprefix.S @@ -32,6 +32,16 @@ .section ".note.GNU-stack", "", @progbits .text + /* Link-time base address of _prefix + * + * This will be not be updated if runtime relocations are applied. + */ + .section ".rodata.prefix_link", "a", @progbits + .balign ( __riscv_xlen / 8 ) +prefix_link: + .dword _base + .size prefix_link, . - prefix_link + /* Virtual address of _prefix * * This will be updated if runtime relocations are applied. @@ -531,7 +541,7 @@ enable_paging_64: li a1, SATP_MODE_SV57 /* Calculate virtual address offset */ - LOADN t0, prefix_virt + LOADN t0, prefix_link la t1, _prefix sub tp, t1, t0 @@ -582,7 +592,7 @@ enable_paging_64_loop: STOREN t0, -PTE_SIZE(a3) /* Calculate PTE[x] address for iPXE virtual address map */ - LOADN t0, prefix_virt + LOADN t0, prefix_link srli t0, t0, VPN1_LSB andi t0, t0, ( PTE_COUNT - 1 ) slli t0, t0, PTE_SIZE_LOG2 @@ -729,7 +739,7 @@ enable_paging_32: progress " paging:" /* Calculate virtual address offset */ - LOADN t0, prefix_virt + LOADN t0, prefix_link la t1, _prefix sub tp, t1, t0