blob: 068e8249580d9dd50f96269056ddb0900c5f1109 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#ifndef TEACHOS_X86_64_PAGE_UTILITIES_HPP
#define TEACHOS_X86_64_PAGE_UTILITIES_HPP
#include <kapi/memory.hpp>
#include <cstddef>
namespace arch::memory
{
constexpr auto inline pml_index(std::size_t index, kapi::memory::page page) noexcept -> std::size_t
{
constexpr auto bits_per_level = 9;
auto shift_width = (index - 1) * bits_per_level;
constexpr auto index_mask = 0x1ffuz;
return page.number() >> shift_width & index_mask;
}
template<typename ValueType = void>
[[nodiscard]] constexpr auto to_higher_half_pointer(kapi::memory::physical_address address) -> ValueType *
{
using namespace kapi::memory;
auto const higher_half_address = higher_half_direct_map_base + address.raw();
return static_cast<ValueType *>(higher_half_address);
}
} // namespace arch::memory
#endif
|