diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2025-11-28 16:06:15 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2025-11-28 16:06:15 +0100 |
| commit | 1db039ca1c67e8daba8b5ec6d5158cb2110e1410 (patch) | |
| tree | 0e90979d364a29bd21f46642e1a7eac9fbe19caa /kapi | |
| parent | 75dccce516db9ee4a43108015f78a9e99b21144f (diff) | |
| download | teachos-1db039ca1c67e8daba8b5ec6d5158cb2110e1410.tar.xz teachos-1db039ca1c67e8daba8b5ec6d5158cb2110e1410.zip | |
x86_64: port basic page and page table abstractions
Diffstat (limited to 'kapi')
| -rw-r--r-- | kapi/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | kapi/include/kapi/memory.hpp | 1 | ||||
| -rw-r--r-- | kapi/include/kapi/memory/page.hpp | 59 |
3 files changed, 64 insertions, 0 deletions
diff --git a/kapi/CMakeLists.txt b/kapi/CMakeLists.txt index 553b9ba..ca26615 100644 --- a/kapi/CMakeLists.txt +++ b/kapi/CMakeLists.txt @@ -8,6 +8,10 @@ target_sources("kapi" PUBLIC "include/kapi/boot.hpp" "include/kapi/cio.hpp" "include/kapi/memory.hpp" + "include/kapi/memory/address.hpp" + "include/kapi/memory/frame_allocator.hpp" + "include/kapi/memory/frame.hpp" + "include/kapi/memory/page.hpp" "include/kapi/system.hpp" ) 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 |
