Skip to content

Conversation

@bubblepipe
Copy link
Contributor

The original code used usize::MAX << arch::VIRT_ADDR_BITS to calculate the base of the kernel address space. This works by coincidence for RISC-V but fails for x86_64:

For RISC-V (38-bit virtual addresses):

riscv64::KERNEL_ASPACE_BASE = 0xffffffc000000000
riscv64::VIRT_ADDR_BITS = 38
usize::MAX << riscv64::VIRT_ADDR_BITS = 0xffffffc000000000 // same as KERNEL_ASPACE_BASE

For x86_64 (48-bit virtual addresses):

x86_64::KERNEL_ASPACE_BASE = 0xffffffc000000000
x86_64::VIRT_ADDR_BITS = 48
usize::MAX << x86_64::VIRT_ADDR_BITS = 0xffff000000000000 // different with KERNEL_ASPACE_BASE

@JonasKruckenberg
Copy link
Owner

Ahh hehe, this one is on me. You must set VIRT_ADDR_BITS to one less than the "address bitness" for the math to work out. Maybe VIRT_ADDR_BITS is a bad name, but it essentially means "the highest usable bit of an address". So for RISCV Sv39 which is a 39 bit addressing system we set VIRT_ADDR_BITS = 38 and for standard x86 you should set VIRT_ADDR_BITS = 47.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants