Module kernel_config::memory
source · Expand description
The basic virtual address ranges (virtual memory map) defined by Theseus.
Current P4 (top-level page table) mappings:
- 511: kernel text sections.
- 510: recursive mapping for accessing the current P4 root page table frame.
- 509: kernel heap.
- 508: recursive mapping for accessing the P4 root page table frame of an upcoming new page table.
- 507 down to 0: available for general usage.
Constants
- Value: 512 GiB.
- 64-bit architecture results in 8 bytes per address.
- Value: 512.
- The kernel heap is allowed to grow to fill the entirety of its P4 entry.
- Value: 509. The 509th entry is used for the kernel heap.
- The higher-half heap gets the 512GB address range starting at the 509th P4 entry, which is the slot right below the recursive P4 entry (510). Actual value: 0o177777_775_000_000_000_0000, or 0xFFFF_FE80_0000_0000
- The virtual address where the initial kernel (the nano_core) is mapped to. Actual value: 0xFFFFFFFF80000000 on x86_64. i.e., the linear offset between physical memory and kernel memory. So, for example, the VGA buffer will be mapped from 0xb8000 to 0xFFFFFFFF800b8000 (on x86_64). This is -2GiB from the end of the 64-bit address space.
- Value: 511. The 511th entry is used (in part) for kernel text sections.
- The kernel text region is where we load kernel modules. It starts at the 511th P4 entry and goes up until the KERNEL_OFFSET, which is where the nano_core itself starts. Actual value on x86_64: 0o177777_777_000_000_000_0000, or 0xFFFF_FF80_0000_0000
- Value: 0. Shift the Page number (not the address!) by this to get the P1 index.
- Value: 9. Shift the Page number (not the address!) by this to get the P2 index.
- Value: 18. Shift the Page number (not the address!) by this to get the P3 index.
- Value: 27. Shift the Page number (not the address!) by this to get the P4 index.
- The lower 12 bits of a virtual address correspond to the P1 page frame offset.
- Page size is 4096 bytes, 4KiB pages.
- Value: 510. The 510th entry is used to recursively map the current P4 root page table frame such that it can be accessed and modified just like any other level of page table.
- The start of the virtual address range covered by the 510th P4 entry, i.e.,
RECURSIVE_P4_INDEX
; - Value: 508. The 508th entry is used to temporarily recursively map the P4 root page table frame of an upcoming (new) page table such that it can be accessed and modified.
- The start of the virtual address range covered by the 508th P4 entry, i.e.,
UPCOMING_PAGE_TABLE_RECURSIVE_P4_INDEX
;