17#include <initializer_list>
93 if (!info.hasInfoModules()) {
100 if (
nullptr == modules) [[unlikely]] {
103 for (
const auto &bootModule : std::span {modules, info.modulesCount}) {
105 if (0_u32 != bootModule.name) {
121 searchHint = freeMap.size();
125 auto hasAvailable {
false};
126 for (
const auto &entry : info.memoryMap()) {
133 if (!hasAvailable && info.hasInfoMemory()) {
145 if (info.hasInfoMemoryMap()) {
149 if (info.hasInfoCommandLine()) {
150 markUsedString(info.cmdLine);
152 if (info.hasInfoBootloaderName()) {
153 markUsedString(info.bootloaderName);
156 markUsedModules(info);
165 const auto limitWords {(limitPages + WORD_BITS - 1_usize) / WORD_BITS};
167 for (
auto word {searchHint}; word < limitWords; ++word) {
168 if (0_u32 != freeMap[word]) {
169 const auto page {(word * WORD_BITS) +
static_cast<igros_usize_t>(std::countr_zero(freeMap[word]))};
171 if (page >= limitPages) [[unlikely]] {
192 if (isFree(index)) [[unlikely]] {
226 for (
auto page {first}; page < last; ++page) {
241 for (
auto page {first}; page < last; ++page) {
static constexpr auto check(const T value) noexcept -> bool
Check alignment.
static constexpr auto up(const T value) noexcept -> T
Align up.
static auto physOf(const T *const object) noexcept -> phys_t
Physical address of directly mapped object.
static auto string(const phys_t phys) noexcept -> const char *
String at physical memory (nullptr if not directly mapped up to null terminator).
static auto pointer(const phys_t phys, const phys_t size=sizeof(T)) noexcept -> T *
Pointer to physical memory (nullptr if range is not directly mapped).
static void markUsed(const phys_t start, const phys_t end) noexcept
Mark physical memory range [start, end) as used (every touched page).
static void free(const phys_t page) noexcept
Free physical page.
static constexpr auto MEMORY_LIMIT
Physical memory tracked by allocator (bitmap of 128 KB).
static auto freePages() noexcept -> igros_usize_t
Number of free pages.
static auto alloc(const phys_t limit=MEMORY_LIMIT) noexcept -> phys_t
Allocate physical page below limit (0 if no memory left).
static void init(const multiboot::info_t &info) noexcept
Initialize from bootloader memory map (reserves kernel and boot data).
static auto top() noexcept -> phys_t
End of highest memory ever marked free (top of usable RAM, clamped to MEMORY_LIMIT).
static void markFree(const phys_t start, const phys_t end) noexcept
Mark physical memory range [start, end) as free (only whole pages).
Direct map of physical memory.
std::size_t igros_usize_t
Unsigned size.
std::uint32_t igros_dword_t
32-bit unsigned integer
Kernel alignment functions definitions.
constexpr auto kstrview(const char *const src) noexcept -> std::string_view
View of null-terminated string (null pointer is empty string).
void setFree(const igros_usize_t page) noexcept
Mark page as free.
igros_dword_t word_t
Bitmap word.
constinit igros_usize_t searchHint
No free pages in words below this one.
constinit std::array< word_t, PAGES/WORD_BITS > freeMap
Free pages bitmap (bit set - page is free).
void setUsed(const igros_usize_t page) noexcept
Mark page as used.
constexpr auto PAGES
Number of tracked pages.
auto isFree(const igros_usize_t page) noexcept -> bool
Check if page is free.
constinit phys_t memoryTop
End of highest memory marked free.
constinit igros_usize_t freeCount
Number of free pages.
constexpr auto WORD_BITS
Pages per bitmap word.
void markUsedString(const phys_t address) noexcept
Mark boot string as used (only first byte if string is not directly mapped).
void markUsedModules(const multiboot::info_t &info) noexcept
Mark modules list, modules and their names as used.
Memory management: physical page allocator, direct map, virtual addresses.
constexpr auto PAGE_SHIFT
Page size bits.
constexpr auto LOW_MEMORY_RESERVED
Physical memory never given out (BIOS, video memory, ROMs).
igros_quad_t phys_t
Physical address (64-bit: physical memory may lie above 4 GB).
constexpr auto address(const virt_t virt) noexcept -> igros_usize_t
Numeric value of virtual address.
@ AVAILABLE
Memory available.
Physical memory allocator.
Multiboot 1 information from bootloader.
Multiboot 1 module entry.