IgrOS-Kernel 0.1.34.545
Simple C++20 Kernel for i386/x86_64
Loading...
Searching...
No Matches
phys.hpp
Go to the documentation of this file.
1
11
12
13#pragma once
14
15
16// IgrOS-Kernel arch
17#include <arch/types.hpp>
18
19
20// Multiboot code zone
21namespace igros::multiboot {
22
23
25 struct info_t;
26
27
28} // namespace igros::multiboot
29
30
31// Memory code zone
32namespace igros::mem {
33
34
37
38 // Physical page size
39 constexpr auto PAGE_SHIFT {12_usize};
40 constexpr auto PAGE_SIZE {1_usize << PAGE_SHIFT};
41
43 constexpr auto LOW_MEMORY_LIMIT {0x400000_u64};
45 constexpr auto LOW_MEMORY_RESERVED {0x100000_u64};
46
47
52 class phys final {
53
54 public:
55
57 ~phys() noexcept = default;
58
60 phys(const phys &other) = delete;
62 auto operator=(const phys &other) -> phys & = delete;
63
65 constexpr static auto MEMORY_LIMIT {0x100000000_u64};
66
69 static void init(const multiboot::info_t &info) noexcept;
70
74 [[nodiscard]]
75 static auto alloc(const phys_t limit = MEMORY_LIMIT) noexcept -> phys_t;
78 static void free(const phys_t page) noexcept;
79
82 [[nodiscard]]
83 static auto freePages() noexcept -> igros_usize_t;
86 [[nodiscard]]
87 static auto top() noexcept -> phys_t;
88
92 static void markFree(const phys_t start, const phys_t end) noexcept;
96 static void markUsed(const phys_t start, const phys_t end) noexcept;
97 };
98
99
100} // namespace igros::mem
101
static void markUsed(const phys_t start, const phys_t end) noexcept
Mark physical memory range [start, end) as used (every touched page).
Definition phys.cpp:234
static void free(const phys_t page) noexcept
Free physical page.
Definition phys.cpp:185
static constexpr auto MEMORY_LIMIT
Physical memory tracked by allocator (bitmap of 128 KB).
Definition phys.hpp:65
phys(const phys &other)=delete
Copy c-tor.
static auto freePages() noexcept -> igros_usize_t
Number of free pages.
Definition phys.cpp:202
static auto alloc(const phys_t limit=MEMORY_LIMIT) noexcept -> phys_t
Allocate physical page below limit (0 if no memory left).
Definition phys.cpp:162
static void init(const multiboot::info_t &info) noexcept
Initialize from bootloader memory map (reserves kernel and boot data).
Definition phys.cpp:116
~phys() noexcept=default
D-tor.
static auto top() noexcept -> phys_t
End of highest memory ever marked free (top of usable RAM, clamped to MEMORY_LIMIT).
Definition phys.cpp:209
static void markFree(const phys_t start, const phys_t end) noexcept
Mark physical memory range [start, end) as free (only whole pages).
Definition phys.cpp:215
std::size_t igros_usize_t
Unsigned size.
Definition types.hpp:51
std::uint64_t igros_quad_t
64-bit unsigned integer
Definition types.hpp:44
Memory management: physical page allocator, direct map, virtual addresses.
constexpr auto PAGE_SHIFT
Page size bits.
Definition phys.hpp:39
constexpr auto LOW_MEMORY_RESERVED
Physical memory never given out (BIOS, video memory, ROMs).
Definition phys.hpp:45
constexpr auto LOW_MEMORY_LIMIT
Physical memory mapped by boot code at kernel virtual offset (see boot.s).
Definition phys.hpp:43
igros_quad_t phys_t
Physical address (64-bit: physical memory may lie above 4 GB).
Definition phys.hpp:36
constexpr auto PAGE_SIZE
Page size in bytes.
Definition phys.hpp:40
Multiboot 1 information passed by the bootloader.
Multiboot 1 information from bootloader.
Definition multiboot.hpp:97
Common C++ types redefinition.