|
IgrOS-Kernel 0.1.34.545
Simple C++20 Kernel for i386/x86_64
|
Paging. More...
#include <arch/x86/paging.hpp>
Public Types | |
| enum class | FLAGS : entry_t { PRESENT = 0x001 , WRITABLE = 0x002 , USER = 0x004 , WRITE_THROUGH = 0x008 , NON_CACHED = 0x010 , ACCESSED = 0x020 , DIRTY = 0x040 , HUGE = 0x080 , NO_EXECUTE = 0x8000000000000000 , GLOBAL = 0x100 } |
| Page table entry flags. More... | |
| using | entry_t = igros_usize_t |
| Page table entry (register-wide). | |
Public Member Functions | |
| ~paging () noexcept=default | |
| D-tor. | |
| paging (const paging &other)=delete | |
| Copy c-tor. | |
| auto | operator= (const paging &other) -> paging &=delete |
| Copy assignment. | |
Static Public Member Functions | |
| static void | init () noexcept |
| Build kernel page tables and switch to them: | |
| 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 void | unmap (const mem::virt_t virt) noexcept |
| Unmap 4 KB page. | |
| static auto | translate (const mem::virt_t virt) noexcept -> mem::phys_t |
| Physical address of virtual address (INVALID if not mapped). | |
| static auto | root () noexcept -> mem::phys_t |
| Current top level table physical address. | |
| static auto | directMapEnd () noexcept -> mem::phys_t |
| End of physical memory reachable through direct map. | |
| static auto | dynamicStart () noexcept -> igros_byte_t * |
| Start of kernel dynamic mappings (right above direct map). | |
| static void | exHandler (const register_t *regs) noexcept |
| Page fault handler. | |
Static Public Attributes | |
| static constexpr auto | PAGE_SHIFT {mem::PAGE_SHIFT} |
| Page size bits. | |
| static constexpr auto | PAGE_SIZE {mem::PAGE_SIZE} |
| Page size in bytes. | |
| static constexpr auto | LEVELS {4_usize} |
| Table levels. | |
| static constexpr auto | INDEX_BITS {9_usize} |
| static constexpr auto | ADDRESS_MASK {entry_t {0x000FFFFFFFFFF000}} |
| Physical address bits of entry (52-bit physical addresses). | |
| static constexpr auto | DIRECT_MAP_LIMIT {mem::phys_t {0x40000000}} |
| Physical memory mapped at kernel offset (-2 GB .. -1 GB), rest is for dynamic mappings. | |
| static constexpr auto | ENTRIES {1_usize << INDEX_BITS} |
| Entries per table. | |
| static constexpr auto | LARGE_PAGE_SIZE {PAGE_SIZE << INDEX_BITS} |
| Large page size (4 MB on i386, 2 MB on x86_64). | |
| static constexpr auto | INVALID {~mem::phys_t {0}} |
| Address isn't mapped. | |
Private Types | |
| enum class | FAULT : igros_usize_t { PROTECTED = 0x01 , WRITE = 0x02 , USER = 0x04 , RESERVED = 0x08 , FETCH = 0x10 } |
| Page fault error code flags. More... | |
Static Private Member Functions | |
| static auto | table (const mem::phys_t phys) noexcept -> entry_t * |
| Table at physical address (through direct map). | |
| static auto | allocTable () noexcept -> mem::phys_t |
| Allocate empty table (reachable through direct map, 0 if no memory). | |
| 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 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. | |
| 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 | map (const mem::phys_t top, const mem::phys_t phys, const mem::virt_t virt, const klib::kFlags< FLAGS > flags) noexcept -> bool |
| Map 4 KB page in given hierarchy. | |
| 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). | |
| 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 | selfTest () noexcept -> bool |
| Check mapping on a scratch page. | |
Paging.
Physical memory is mapped at kernel virtual offset (direct map): first 4 MB by boot code, up to top of RAM (DIRECT_MAP_LIMIT at most) once init built kernel page tables. Page tables are accessed through the direct map; table entries hold physical addresses.
Definition at line 37 of file paging.hpp.
Page table entry (register-wide).
Definition at line 50 of file paging.hpp.
|
strongprivate |
Page fault error code flags.
| Enumerator | |
|---|---|
| PROTECTED | Protection violation (else page not present). |
| WRITE | Write access (else read). |
| USER | User mode access (else kernel). |
| RESERVED | Reserved bit set in entry. |
| FETCH | Instruction fetch. |
Definition at line 155 of file paging.hpp.
|
strong |
Page table entry flags.
Definition at line 53 of file paging.hpp.
|
staticnodiscardprivatenoexcept |
Allocate empty table (reachable through direct map, 0 if no memory).
Definition at line 83 of file paging.cpp.
|
staticnodiscardnoexcept |
End of physical memory reachable through direct map.
Definition at line 230 of file paging.cpp.
|
staticnodiscardnoexcept |
Start of kernel dynamic mappings (right above direct map).
Definition at line 236 of file paging.cpp.
|
staticnodiscardprivatenoexcept |
Entry of virtual address at given level (0 - page table) of given hierarchy.
(create - allocate missing tables)
| top | Top level table physical address |
| virt | Virtual address |
| create | Allocate missing tables |
| user | Allow user access on upper levels |
| level | Table level of the entry |
Definition at line 100 of file paging.cpp.
|
staticnoexcept |
Page fault handler.
| regs | Registers saved on page fault |
Definition at line 357 of file paging.cpp.
|
staticnodiscardprivatenoexcept |
Index of virtual address in table of given level (0 - page table).
| virt | Virtual address |
| level | Table level |
Definition at line 93 of file paging.cpp.
|
staticnoexcept |
Build kernel page tables and switch to them:
Definition at line 260 of file paging.cpp.
|
staticnodiscardprivatenoexcept |
Rights of kernel offset mapping of low memory physical page (kernel sections).
| phys | Physical page address |
Definition at line 243 of file paging.cpp.
|
staticnodiscardprivatenoexcept |
Entry value for physical address with flags (drops NX if not enabled).
| phys | Physical address |
| flags | Entry flags |
Definition at line 134 of file paging.cpp.
|
staticnodiscardnoexcept |
Map 4 KB page (false if structures can't be allocated or address is in a large page).
| phys | Physical page address |
| virt | Virtual page address |
| flags | Entry flags |
Definition at line 182 of file paging.cpp.
|
staticnodiscardprivatenoexcept |
Map 4 KB page in given hierarchy.
| top | Top level table physical address |
| phys | Physical page address |
| virt | Virtual page address |
| flags | Entry flags |
Definition at line 142 of file paging.cpp.
|
staticnodiscardprivatenoexcept |
Map large page in given hierarchy (fresh directory entry only).
| top | Top level table physical address |
| phys | Physical large page address |
| virt | Virtual large page address |
| flags | Entry flags |
Definition at line 163 of file paging.cpp.
|
staticnodiscardnoexcept |
Current top level table physical address.
Definition at line 223 of file paging.cpp.
|
staticnodiscardprivatenoexcept |
Check mapping on a scratch page.
Definition at line 322 of file paging.cpp.
|
staticnodiscardprivatenoexcept |
Table at physical address (through direct map).
| phys | Table physical address |
Definition at line 76 of file paging.cpp.
|
staticnodiscardnoexcept |
Physical address of virtual address (INVALID if not mapped).
| virt | Virtual address |
Definition at line 198 of file paging.cpp.
|
staticnoexcept |
|
staticconstexpr |
Physical address bits of entry (52-bit physical addresses).
Definition at line 90 of file paging.hpp.
|
staticconstexpr |
Physical memory mapped at kernel offset (-2 GB .. -1 GB), rest is for dynamic mappings.
Definition at line 92 of file paging.hpp.
|
staticconstexpr |
Entries per table.
Definition at line 97 of file paging.hpp.
|
staticconstexpr |
Index bits per level
Definition at line 88 of file paging.hpp.
|
staticconstexpr |
Address isn't mapped.
Definition at line 102 of file paging.hpp.
|
staticconstexpr |
Large page size (4 MB on i386, 2 MB on x86_64).
Definition at line 99 of file paging.hpp.
|
staticconstexpr |
Table levels.
Definition at line 87 of file paging.hpp.
|
staticconstexpr |
Page size bits.
Definition at line 71 of file paging.hpp.
|
staticconstexpr |
Page size in bytes.
Definition at line 72 of file paging.hpp.