aboutsummaryrefslogtreecommitdiff
path: root/kapi/include
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2025-11-28 16:06:15 +0100
committerFelix Morgner <felix.morgner@ost.ch>2025-11-28 16:06:15 +0100
commit1db039ca1c67e8daba8b5ec6d5158cb2110e1410 (patch)
tree0e90979d364a29bd21f46642e1a7eac9fbe19caa /kapi/include
parent75dccce516db9ee4a43108015f78a9e99b21144f (diff)
downloadteachos-1db039ca1c67e8daba8b5ec6d5158cb2110e1410.tar.xz
teachos-1db039ca1c67e8daba8b5ec6d5158cb2110e1410.zip
x86_64: port basic page and page table abstractions
Diffstat (limited to 'kapi/include')
-rw-r--r--kapi/include/kapi/memory.hpp1
-rw-r--r--kapi/include/kapi/memory/page.hpp59
2 files changed, 60 insertions, 0 deletions
diff --git a/kapi/include/kapi/memory.hpp b/kapi/include/kapi/memory.hpp
index 3daaa86..4279274 100644
--- a/kapi/include/kapi/memory.hpp
+++ b/kapi/include/kapi/memory.hpp
@@ -4,6 +4,7 @@
#include "kapi/memory/address.hpp" // IWYU pragma: export
#include "kapi/memory/frame.hpp" // IWYU pragma: export
#include "kapi/memory/frame_allocator.hpp" // IWYU pragma: export
+#include "kapi/memory/page.hpp" // IWYU pragma: export
namespace teachos::memory
{
diff --git a/kapi/include/kapi/memory/page.hpp b/kapi/include/kapi/memory/page.hpp
new file mode 100644
index 0000000..2b8e52a
--- /dev/null
+++ b/kapi/include/kapi/memory/page.hpp
@@ -0,0 +1,59 @@
+#ifndef TEACHOS_KAPI_MEMORY_PAGE_HPP
+#define TEACHOS_KAPI_MEMORY_PAGE_HPP
+
+#include "kapi/memory/address.hpp"
+
+#include <compare>
+#include <cstddef>
+
+namespace teachos::memory
+{
+
+ extern std::size_t const PLATFORM_PAGE_SIZE;
+
+ struct page
+ {
+ constexpr page() = default;
+
+ explicit constexpr page(std::size_t number)
+ : m_number{number}
+ {}
+
+ /**
+ * @brief Returns the virtual page the given address is contained in.
+ *
+ * @param address Linear address we want to get the corresponding virtual page for.
+ * @return Page the given address is contained in.
+ */
+ constexpr auto static containing(linear_address address) noexcept -> page
+ {
+ return page{address.raw() / PLATFORM_PAGE_SIZE};
+ }
+
+ /**
+ * @brief Get the start address of this virtual page.
+ *
+ * @return Start address of the virtual page.
+ */
+ [[nodiscard]] constexpr auto start_address() const noexcept -> linear_address
+ {
+ return linear_address{m_number * PLATFORM_PAGE_SIZE};
+ }
+
+ /**
+ * @brief Check if this page refers to the same page as @p other.
+ */
+ constexpr auto operator==(page const & other) const noexcept -> bool = default;
+
+ /**
+ * @brief Lexicographically compare this page to @p other.
+ */
+ constexpr auto operator<=>(page const & other) const noexcept -> std::strong_ordering = default;
+
+ private:
+ std::size_t m_number{};
+ };
+
+} // namespace teachos::memory
+
+#endif \ No newline at end of file