![]() |
Max OS 0.3
|
Defines a PhysicalMemoryManager class for managing physical memory allocation and deallocation of pages. More...
#include <cstdint>#include <cstddef>#include <common/macros.h>#include <system/multiboot.h>#include <common/spinlock.h>Go to the source code of this file.
Classes | |
| struct | MaxOS::memory::PageTableEntry |
| Struct for a page table entry. More... | |
| struct | MaxOS::memory::PageMapLevel |
| Struct for a page map level (PML4, PDPT, PD, PT) More... | |
| class | MaxOS::memory::PhysicalMemoryManager |
| Manages the physical memory of the system such as what pages are allocated/free and mapping of virtual to physical addresses. More... | |
Macros | |
| #define | ENTRIES_TO_ADDRESS(pml4, pdpr, pd, pt) ((pml4 << 39) | (pdpr << 30) | (pd << 21) | (pt << 12)) |
| Convert page map level indices to a virtual address. | |
| #define | PMLX_GET_INDEX(ADDR, LEVEL) (((uint64_t)ADDR & ((uint64_t)0x1ff << (12 + LEVEL * 9))) >> (12 + LEVEL * 9)) |
| Get the index for a given page map level from a virtual address. | |
| #define | PML4_GET_INDEX(ADDR) PMLX_GET_INDEX(ADDR, 3) |
| Get the PML4 index from a virtual address. | |
| #define | PML3_GET_INDEX(ADDR) PMLX_GET_INDEX(ADDR, 2) |
| Get the PDPT index from a virtual address. | |
| #define | PML2_GET_INDEX(ADDR) PMLX_GET_INDEX(ADDR, 1) |
| Get the PDP index from a virtual address. | |
| #define | PML1_GET_INDEX(ADDR) PMLX_GET_INDEX(ADDR, 0) |
| Get the PT index from a virtual address. | |
Typedefs | |
| typedef void | MaxOS::memory::virtual_address_t |
| A type representing a virtual address (used for readability) | |
| typedef void | MaxOS::memory::physical_address_t |
| A type representing a physical address (used for readability) | |
| typedef enum MaxOS::memory::PageFlags | MaxOS::memory::page_flags_t |
| Alias for PageFlags enum. | |
| typedef struct PACKED MaxOS::memory::PageTableEntry | MaxOS::memory::pte_t |
| Alias for PageTableEntry struct. | |
| typedef struct PACKED MaxOS::memory::PageMapLevel | MaxOS::memory::pml_t |
| Alias for PageMapLevel struct. | |
Enumerations | |
| enum | MaxOS::memory::PageFlags { MaxOS::memory::NONE = 0 , MaxOS::memory::PRESENT = (1 << 0) , MaxOS::memory::WRITE = (1 << 1) , MaxOS::memory::USER = (1 << 2) , MaxOS::memory::WRITE_THROUGH = (1 << 3) , MaxOS::memory::CACHE_DISABLED = (1 << 4) , MaxOS::memory::ACCESSED = (1 << 5) , MaxOS::memory::DIRTY = (1 << 6) , MaxOS::memory::HUGE_PAGE = (1 << 7) , MaxOS::memory::GLOBAL = (1 << 8) , MaxOS::memory::NO_EXECUTE = (1ULL << 63) } |
| Flags for page table entries. More... | |
Variables | |
| constexpr uint64_t | MaxOS::memory::PAGE_SIZE = 0x1000 |
| The size of a page (4KB) | |
| constexpr uint8_t | MaxOS::memory::ROW_BITS = 64 |
| The number of bits in the bitmap row. | |
| constexpr uint64_t | MaxOS::memory::HIGHER_HALF_KERNEL_OFFSET = 0xFFFFFFFF80000000 |
| Where the kernel is mapped in higher half memory. | |
| constexpr uint64_t | MaxOS::memory::HIGHER_HALF_MEM_OFFSET = 0xFFFF800000000000 |
| Where higher half memory starts. | |
| constexpr uint64_t | MaxOS::memory::HIGHER_HALF_MEM_RESERVED = 0x280000000 |
| Reserved higher half memory for kernel use (10GB) | |
| constexpr uint64_t | MaxOS::memory::HIGHER_HALF_OFFSET |
| Where higher half memory usable space starts. | |
| constexpr uint64_t | MaxOS::memory::HIGHER_HALF_DIRECT_MAP |
| Where the map of physical memory to higher half starts. | |
Defines a PhysicalMemoryManager class for managing physical memory allocation and deallocation of pages.
Definition in file physical.h.
| #define ENTRIES_TO_ADDRESS | ( | pml4, | |
| pdpr, | |||
| pd, | |||
| pt | |||
| ) | ((pml4 << 39) | (pdpr << 30) | (pd << 21) | (pt << 12)) |
Convert page map level indices to a virtual address.
Definition at line 19 of file physical.h.
| #define PML1_GET_INDEX | ( | ADDR | ) | PMLX_GET_INDEX(ADDR, 0) |
Get the PT index from a virtual address.
Definition at line 25 of file physical.h.
| #define PML2_GET_INDEX | ( | ADDR | ) | PMLX_GET_INDEX(ADDR, 1) |
Get the PDP index from a virtual address.
Definition at line 24 of file physical.h.
| #define PML3_GET_INDEX | ( | ADDR | ) | PMLX_GET_INDEX(ADDR, 2) |
Get the PDPT index from a virtual address.
Definition at line 23 of file physical.h.
| #define PML4_GET_INDEX | ( | ADDR | ) | PMLX_GET_INDEX(ADDR, 3) |
Get the PML4 index from a virtual address.
Definition at line 22 of file physical.h.
| #define PMLX_GET_INDEX | ( | ADDR, | |
| LEVEL | |||
| ) | (((uint64_t)ADDR & ((uint64_t)0x1ff << (12 + LEVEL * 9))) >> (12 + LEVEL * 9)) |
Get the index for a given page map level from a virtual address.
Definition at line 20 of file physical.h.
Alias for PageFlags enum.
| typedef void MaxOS::memory::physical_address_t |
A type representing a physical address (used for readability)
Definition at line 30 of file physical.h.
| typedef void MaxOS::memory::virtual_address_t |
A type representing a virtual address (used for readability)
Definition at line 29 of file physical.h.
Flags for page table entries.
Definition at line 41 of file physical.h.
|
constexpr |
Where the map of physical memory to higher half starts.
Definition at line 99 of file physical.h.
Referenced by MaxOS::memory::PhysicalMemoryManager::from_dm_region(), MaxOS::memory::PhysicalMemoryManager::PhysicalMemoryManager(), MaxOS::memory::PhysicalMemoryManager::to_dm_region(), and MaxOS::memory::VirtualMemoryManager::VirtualMemoryManager().
|
constexpr |
Where the kernel is mapped in higher half memory.
Definition at line 94 of file physical.h.
Referenced by MaxOS::system::Multiboot::start_tag(), MaxOS::memory::PhysicalMemoryManager::to_higher_region(), and MaxOS::memory::PhysicalMemoryManager::to_lower_region().
|
constexpr |
Where higher half memory starts.
Definition at line 95 of file physical.h.
Referenced by MaxOS::memory::PhysicalMemoryManager::to_io_region().
|
constexpr |
Reserved higher half memory for kernel use (10GB)
Definition at line 96 of file physical.h.
|
constexpr |
Where higher half memory usable space starts.
Definition at line 97 of file physical.h.
Referenced by MaxOS::memory::PhysicalMemoryManager::to_dm_region().
|
constexpr |
The size of a page (4KB)
Definition at line 91 of file physical.h.
Referenced by MaxOS::memory::PhysicalMemoryManager::align_direct_to_page(), MaxOS::memory::PhysicalMemoryManager::align_to_page(), MaxOS::memory::VirtualMemoryManager::allocate(), MaxOS::memory::PhysicalMemoryManager::allocate_area(), MaxOS::memory::PhysicalMemoryManager::allocate_frame(), MaxOS::memory::PhysicalMemoryManager::check_aligned(), MaxOS::memory::PhysicalMemoryManager::free_area(), MaxOS::memory::PhysicalMemoryManager::free_frame(), MaxOS::memory::VirtualMemoryManager::load_physical_into_address_space(), MaxOS::memory::PhysicalMemoryManager::map_area(), MaxOS::memory::PhysicalMemoryManager::map_area(), MaxOS::memory::PhysicalMemoryManager::memory_used(), MaxOS::memory::MemoryManager::MemoryManager(), MaxOS::memory::PhysicalMemoryManager::PhysicalMemoryManager(), MaxOS::memory::PhysicalMemoryManager::reserve(), MaxOS::memory::PhysicalMemoryManager::reserve(), MaxOS::memory::PhysicalMemoryManager::reserve_kernel_regions(), MaxOS::memory::PhysicalMemoryManager::size_to_frames(), MaxOS::memory::PhysicalMemoryManager::unmap_area(), MaxOS::memory::VirtualMemoryManager::VirtualMemoryManager(), and MaxOS::memory::VirtualMemoryManager::~VirtualMemoryManager().
|
constexpr |
The number of bits in the bitmap row.
Definition at line 92 of file physical.h.
Referenced by MaxOS::memory::PhysicalMemoryManager::allocate_area(), MaxOS::memory::PhysicalMemoryManager::allocate_frame(), MaxOS::memory::PhysicalMemoryManager::free_area(), MaxOS::memory::PhysicalMemoryManager::free_frame(), MaxOS::memory::PhysicalMemoryManager::PhysicalMemoryManager(), and MaxOS::memory::PhysicalMemoryManager::reserve().