Expand description
This module contains constants that define how the kernel address space is laid out on RISC-V
using the Sv48 paging model. It is very similar to the layout on x86_64
, as the structure of
the page tables are almost identical on the two architectures.
The 511th P4 entry (virtual addresses 0xffff_ff80_0000_0000
through 0xffff_ffff_ffff_ffff
)
is always mapped to the kernel P3. The rest of the virtual address space (virtual addresses
0x0000_0000_0000_0000
through 0xffff_ff7f_ffff_ffff
) are free for userspace to use.
This gives us 512 GiB of kernel space. The kernel itself lies within the top 2GiB of the address space (the top two entries of the kernel P3). The remaining 510 GiB of the kernel P3 is used to map the entirety of physical memory into the kernel address space, and for task kernel stacks.
Directly below the base of the kernel, we reserve 128GiB for task kernel stacks, which gives us a maximum of 65536 tasks if each one has the default stack size.
This leaves us 382GiB for the physical memory map, which should be sufficient for any system I can imagine us running on (famous last words).
Constants§
- KERNEL_
ADDRESS_ SPACE_ START - KERNEL_
BASE - The kernel starts at -2GiB. The kernel image is loaded directly at this address, and the following space until the top of memory is managed dynamically and contains the boot info structures, memory map, and kernel heap.
- KERNEL_
P4_ ENTRY - KERNEL_
STACKS_ BASE - MAX_
TASKS - PHYSICAL_
MAP_ BASE - STACK_
SLOT_ SIZE
Functions§
- physical_
to_ virtual - Access a given physical address through the physical mapping. This cannot be used until the kernel page tables have been switched to.