blob: e797b22efb04663fb92db77aa5c45a2d9d980380 (
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#include "x86_64/memory/page_table.hpp"
#include <algorithm>
#include <utility>
namespace teachos::memory::x86_64
{
auto page_table::entry::clear() -> void
{
m_raw = 0;
}
auto page_table::entry::present() const -> bool
{
return (all_flags() & flags::present) != flags::empty;
}
auto page_table::entry::huge() const -> bool
{
return (all_flags() & flags::huge_page) != flags::empty;
}
auto page_table::entry::all_flags() const -> flags
{
return std::bit_cast<flags>(m_raw & ~frame_number_mask);
}
auto page_table::entry::all_flags(flags flags) -> void
{
m_raw = (m_raw & ~frame_number_mask) | std::to_underlying(flags);
}
auto page_table::entry::operator|=(flags rhs) -> page_table::entry &
{
auto raw_flags = std::to_underlying(rhs) & ~frame_number_mask;
m_raw |= raw_flags;
return *this;
}
auto page_table::entry::frame() const -> std::optional<struct frame>
{
if (present())
{
return frame::containing(physical_address{m_raw & frame_number_mask});
}
return std::nullopt;
}
auto page_table::entry::frame(struct frame frame, flags flags) -> void
{
m_raw = (frame.start_address().raw() | static_cast<std::uint64_t>(flags));
};
auto page_table::operator[](std::size_t index) -> entry &
{
return m_entries.at(index);
}
auto page_table::operator[](std::size_t index) const -> entry const &
{
return m_entries.at(index);
}
auto page_table::clear() -> void
{
std::ranges::for_each(m_entries, &page_table::entry::clear);
}
auto page_table::empty() const noexcept -> bool
{
return std::ranges::all_of(m_entries,
[](auto const & entry) -> auto { return entry.all_flags() == entry::flags::empty; });
}
} // namespace teachos::memory::x86_64
|