Skip to content

Commit 01f1d2d

Browse files
spholzADKaster
authored andcommitted
Kernel/riscv64: Don't clobber the boot info argument in enable_paging
"register asm" variables don't preserve the register value, so the call to calculate_physical_to_link_time_address_offset in the asm input operands is allowed to clobber a0.
1 parent 1127fa1 commit 01f1d2d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Kernel/Arch/riscv64/MMU.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,9 @@ static UNMAP_AFTER_INIT void setup_kernel_page_directory(u64* root_table)
177177
// This function has to fit into one page as it will be identity mapped.
178178
[[gnu::aligned(PAGE_SIZE)]] [[noreturn]] UNMAP_AFTER_INIT static void enable_paging(BootInfo const& info, FlatPtr satp, u64* enable_paging_pte)
179179
{
180-
// Switch current root page table to argument 0. This will immediately take effect, but we won't not crash as this function is identity mapped.
180+
// Switch current root page table to argument 1. This will immediately take effect, but we won't not crash as this function is identity mapped.
181181
// Also, set up a temporary trap handler to catch any traps while switching page tables.
182+
auto offset = calculate_physical_to_link_time_address_offset();
182183
register FlatPtr a0 asm("a0") = bit_cast<FlatPtr>(&info);
183184
asm volatile(
184185
" lla t0, 1f \n"
@@ -213,7 +214,7 @@ static UNMAP_AFTER_INIT void setup_kernel_page_directory(u64* root_table)
213214
" wfi \n"
214215
" j 1b \n"
215216
:
216-
: "r"(a0), [satp] "r"(satp), [offset] "r"(calculate_physical_to_link_time_address_offset()), [enable_paging_pte] "r"(enable_paging_pte)
217+
: "r"(a0), [satp] "r"(satp), [offset] "r"(offset), [enable_paging_pte] "r"(enable_paging_pte)
217218
: "t0");
218219

219220
VERIFY_NOT_REACHED();

0 commit comments

Comments
 (0)