aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/memory/paging.cpp
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-14 14:03:27 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-14 14:03:27 +0000
commit38e0b13ab9a4997fdf9f311fd125825919d2e6c7 (patch)
tree199989f891136e6502c60a8ad2a07512d6cae022 /arch/x86_64/src/memory/paging.cpp
parent563a3dcbc1f2d26adcd6761358c45d635738f3c5 (diff)
downloadteachos-38e0b13ab9a4997fdf9f311fd125825919d2e6c7.tar.xz
teachos-38e0b13ab9a4997fdf9f311fd125825919d2e6c7.zip
Start developing paging
Diffstat (limited to 'arch/x86_64/src/memory/paging.cpp')
-rw-r--r--arch/x86_64/src/memory/paging.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/arch/x86_64/src/memory/paging.cpp b/arch/x86_64/src/memory/paging.cpp
new file mode 100644
index 0000000..555357c
--- /dev/null
+++ b/arch/x86_64/src/memory/paging.cpp
@@ -0,0 +1,53 @@
+#include "arch/memory/paging.hpp"
+
+namespace teachos::arch::memory
+{
+ auto entry::is_unused() const -> bool { return flags == 0U; }
+
+ auto entry::set_unused() -> void { flags = 0U; }
+
+ auto entry::present() const -> bool { return is_bit_set(0U); }
+
+ auto entry::writable() const -> bool { return is_bit_set(1U); }
+
+ auto entry::user_accessible() const -> bool { return is_bit_set(2U); }
+
+ auto entry::write_through_caching() const -> bool { return is_bit_set(3U); }
+
+ auto entry::disabled_caching() const -> bool { return is_bit_set(4U); }
+
+ auto entry::is_accessing() const -> bool { return is_bit_set(5U); }
+
+ auto entry::is_diry() const -> bool { return is_bit_set(6U); }
+
+ auto entry::is_huge_page() const -> bool { return is_bit_set(7U); }
+
+ auto entry::is_global() const -> bool { return is_bit_set(8U); }
+
+ auto entry::executing_code_forbidden() const -> bool { return is_bit_set(63U); }
+
+ auto entry::calculate_pointed_to_frame() const -> std::optional<physical_frame>
+ {
+ if (present())
+ {
+ auto physical_address = calculate_physical_address();
+ return physical_frame::containing_address(physical_address);
+ }
+ return std::nullopt;
+ }
+
+ auto entry::calculate_physical_address() const -> std::size_t
+ {
+ constexpr std::size_t start_bit = 12U;
+ constexpr std::size_t end_bit = 51U;
+ size_t value = 0U;
+
+ for (auto i = start_bit; i < end_bit; i++)
+ {
+ value |= (flags[i] ? (1 << (i - start_bit)) : 0);
+ }
+ return value;
+ }
+
+ auto entry::is_bit_set(uint8_t index) const -> bool { return flags[index] == 1U; }
+} // namespace teachos::arch::memory