62#if defined(IGROS_ARCH_x86_64)
74#if defined(IGROS_ARCH_i386)
77 constexpr static auto LEVELS {2_usize};
84#elif defined(IGROS_ARCH_x86_64)
87 constexpr static auto LEVELS {4_usize};
113 static void init() noexcept;
121 static auto
map(const
mem::phys_t phys, const
mem::virt_t virt, const
klib::kFlags<
FLAGS> flags) noexcept ->
bool;
124 static
void unmap(const
mem::virt_t virt) noexcept;
135 static auto
root() noexcept ->
mem::phys_t;
149 static
void exHandler(const register_t* regs) noexcept;
188 static auto
entry(const
mem::phys_t top, const
mem::virt_t virt, const
bool create, const
bool user, const
igros_usize_t level = 0_usize) noexcept ->
entry_t*;
202 static auto
map(const
mem::phys_t top, const
mem::phys_t phys, const
mem::virt_t virt, const
klib::kFlags<
FLAGS> flags) noexcept ->
bool;
210 static auto
mapLarge(const
mem::phys_t top, const
mem::phys_t phys, const
mem::virt_t virt, const
klib::kFlags<
FLAGS> flags) noexcept ->
bool;
220 static auto
selfTest() noexcept ->
bool;
static void unmap(const mem::virt_t virt) noexcept
Unmap 4 KB page.
igros_usize_t entry_t
Page table entry (register-wide).
static auto table(const mem::phys_t phys) noexcept -> entry_t *
Table at physical address (through direct map).
static auto selfTest() noexcept -> bool
Check mapping on a scratch page.
static auto root() noexcept -> mem::phys_t
Current top level table physical address.
static auto allocTable() noexcept -> mem::phys_t
Allocate empty table (reachable through direct map, 0 if no memory).
static auto directMapEnd() noexcept -> mem::phys_t
End of physical memory reachable through direct map.
static auto kernelFlags(const mem::phys_t phys) noexcept -> klib::kFlags< FLAGS >
Rights of kernel offset mapping of low memory physical page (kernel sections).
static auto entry(const mem::phys_t top, const mem::virt_t virt, const bool create, const bool user, const igros_usize_t level=0_usize) noexcept -> entry_t *
Entry of virtual address at given level (0 - page table) of given hierarchy.
FAULT
Page fault error code flags.
@ PROTECTED
Protection violation (else page not present).
@ FETCH
Instruction fetch.
@ RESERVED
Reserved bit set in entry.
@ WRITE
Write access (else read).
static constexpr auto ENTRIES
Entries per table.
static auto map(const mem::phys_t phys, const mem::virt_t virt, const klib::kFlags< FLAGS > flags) noexcept -> bool
Map 4 KB page (false if structures can't be allocated or address is in a large page).
static constexpr auto LEVELS
Table levels.
static void exHandler(const register_t *regs) noexcept
Page fault handler.
static constexpr auto LARGE_PAGE_SIZE
Large page size (4 MB on i386, 2 MB on x86_64).
~paging() noexcept=default
D-tor.
static constexpr auto PAGE_SIZE
Page size in bytes.
static auto makeEntry(const mem::phys_t phys, const klib::kFlags< FLAGS > flags) noexcept -> entry_t
Entry value for physical address with flags (drops NX if not enabled).
static auto dynamicStart() noexcept -> igros_byte_t *
Start of kernel dynamic mappings (right above direct map).
static void init() noexcept
Build kernel page tables and switch to them:
paging(const paging &other)=delete
Copy c-tor.
static auto index(const mem::virt_t virt, const igros_usize_t level) noexcept -> igros_usize_t
Index of virtual address in table of given level (0 - page table).
static constexpr auto INVALID
Address isn't mapped.
static constexpr auto INDEX_BITS
static constexpr auto DIRECT_MAP_LIMIT
Physical memory mapped at kernel offset (-2 GB .. -1 GB), rest is for dynamic mappings.
static constexpr auto ADDRESS_MASK
Physical address bits of entry (52-bit physical addresses).
static constexpr auto PAGE_SHIFT
Page size bits.
FLAGS
Page table entry flags.
@ NO_EXECUTE
Instruction fetch not allowed (EFER.NXE).
@ WRITE_THROUGH
Write-through caching.
@ DIRTY
Set by CPU on write (pages).
@ GLOBAL
Not flushed on CR3 change.
@ ACCESSED
Set by CPU on access.
@ HUGE
Large page (directory levels).
@ NON_CACHED
Caching disabled.
static auto translate(const mem::virt_t virt) noexcept -> mem::phys_t
Physical address of virtual address (INVALID if not mapped).
static auto mapLarge(const mem::phys_t top, const mem::phys_t phys, const mem::virt_t virt, const klib::kFlags< FLAGS > flags) noexcept -> bool
Map large page in given hierarchy (fresh directory entry only).
std::size_t igros_usize_t
Unsigned size.
std::uint8_t igros_byte_t
8-bit unsigned integer
Bit flags template datatype.
Freestanding kernel library: printing, math, alignment, flags, strings.
Memory management: physical page allocator, direct map, virtual addresses.
constexpr auto PAGE_SHIFT
Page size bits.
igros_quad_t phys_t
Physical address (64-bit: physical memory may lie above 4 GB).
constexpr auto PAGE_SIZE
Page size in bytes.
Code shared by i386 and x86_64: ports, interrupts, exceptions, paging.
x86 family current (native) architecture selection
Physical memory allocator.
Common C++ types redefinition.