aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/include
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/include')
-rw-r--r--arch/x86_64/include/arch/memory/paging/page_mapper.hpp4
-rw-r--r--arch/x86_64/include/arch/memory/paging/page_table.hpp77
-rw-r--r--arch/x86_64/include/arch/memory/paging/virtual_page.hpp2
3 files changed, 22 insertions, 61 deletions
diff --git a/arch/x86_64/include/arch/memory/paging/page_mapper.hpp b/arch/x86_64/include/arch/memory/paging/page_mapper.hpp
index a874f75..0806f58 100644
--- a/arch/x86_64/include/arch/memory/paging/page_mapper.hpp
+++ b/arch/x86_64/include/arch/memory/paging/page_mapper.hpp
@@ -60,7 +60,7 @@ namespace teachos::arch::memory::paging
{
auto current_handle = create_or_get();
- for (auto level = page_table::LEVEL4; level != page_table::LEVEL1; level--)
+ for (auto level = page_table_handle::LEVEL4; level != page_table_handle::LEVEL1; level--)
{
auto level_index = page.get_level_index(level);
auto next_handle = current_handle.next_table(level_index);
@@ -82,7 +82,7 @@ namespace teachos::arch::memory::paging
current_handle = next_handle.value();
}
- auto level1_entry = current_handle[page.get_level_index(page_table::LEVEL1)];
+ auto level1_entry = current_handle[page.get_level_index(page_table_handle::LEVEL1)];
arch::exception_handling::assert(!level1_entry.contains_flags(entry::HUGE_PAGE),
"[Page Mapper] Unable to map huge pages");
arch::exception_handling::assert(!level1_entry.is_unused(), "[Page Mapper] Page table entry is already used");
diff --git a/arch/x86_64/include/arch/memory/paging/page_table.hpp b/arch/x86_64/include/arch/memory/paging/page_table.hpp
index a1c8abe..91ce81c 100644
--- a/arch/x86_64/include/arch/memory/paging/page_table.hpp
+++ b/arch/x86_64/include/arch/memory/paging/page_table.hpp
@@ -11,12 +11,20 @@ namespace teachos::arch::memory::paging
}
/**
- * @brief A Page table containing 512 entries.
+ * @brief Forward delcaration of the page_table, because it should only be accessible over the handle, the actual
+ * methods or constructor are not defined meaning they are not callable from outside. Instead the struct is only fully
+ * defined in the implementation (.cpp) file of the page table, and therefore also only accesible in that file.
*/
- struct page_table
+ struct page_table;
+
+ /**
+ * @brief Handle that ensures accessing the page table is safe because it adds additional checks to the next_table
+ * method and ensures it can only be called if the table level is not LEVEL1.
+ */
+ struct page_table_handle
{
/**
- * @brief Level of the page table, level 1 should not be able to call next_table anymore, because it would result in
+ * @brief Level of the page table, level 1 will not be able to call next_table anymore, because it would result in
* attempting to access memory that it should not.
*/
enum level : uint8_t
@@ -28,61 +36,12 @@ namespace teachos::arch::memory::paging
};
/**
- * @brief Deleted constructor. Object can only be created by casting from the fixed Level 4
- * page table address `reinterpret_cast<page_table *>(0xfffffffffffff000)`.
- */
- page_table() = delete;
-
- /**
- * @brief Set every entry of the page to unused.
- */
- auto zero_entries() -> void;
-
- /**
- * @brief Returns the next page table level from the given page table index. Meaning we
- * use an index into a Level 4 page table to get the according Level 3 page table. This method should not be called
- * on a Level 1 page table, because there is no furthere page table and mangeling up and returning the physical
- * address would cause hard to debug issues.
- *
- * @param table_index Index of this page table in the page table one level lower.
- */
- auto next_table(std::size_t table_index) const -> std::optional<page_table *>;
-
- /**
- * @brief Index operator overload to access specific entries directy.
- *
- * @param index Index of the entry we want to access and read or write too.
- * @return Entry at the given table index.
- */
- auto operator[](std::size_t index) const -> entry;
-
- private:
- /**
- * @brief Calculates the address of the next page table level for the given table index. The next page table address
- * is only valid if the corresponding entry is present and not a huge page. Meaning we use an index into a
- * Level 4 page table to get the according Level 3 page table address.
- *
- * @param table_index Index of this page table in the page table one level higher.
- * @return An optional of the address of the next page table or null.
- */
- auto next_table_address(std::size_t table_index) const -> std::optional<std::size_t>;
-
- entry entries[PAGE_TABLE_ENTRY_COUNT]; ///< Entries containing addresses to page tables of a level below or actual
- ///< virtual addresses for the level 1 page table.
- };
-
- auto operator--(page_table::level & level, int) -> page_table::level;
-
- /**
- * @brief Handle that ensures accessing the page table is safe because it adds additional checks to the next_table
- * method and ensures it can only be called if the table level is not LEVEL1.
- */
- struct page_table_handle
- {
- /**
* @brief Constructor.
+ *
+ * @param handle Underlying page table the handle should point to.
+ * @param handle_level Level the underlying page table is on, used to ensure safety.
*/
- page_table_handle(page_table * handle, page_table::level handle_level);
+ page_table_handle(page_table * handle, level handle_level);
/**
* @brief Set every entry of the page to unused.
@@ -109,9 +68,11 @@ namespace teachos::arch::memory::paging
private:
page_table * handle; ///< Handle to underlying page table, can never be null (invariant ensured by constructor)
- page_table::level handle_level; ///< Level page table is currently on, depends on how often next_level was
- ///< called successfully.
+ level handle_level; ///< Level page table is currently on, depends on how often next_level was
+ ///< called successfully.
};
+
+ auto operator--(page_table_handle::level & level, int) -> page_table_handle::level;
} // namespace teachos::arch::memory::paging
#endif // TEACHOS_ARCH_X86_64_MEMORY_PAGING_PAGE_TABLE_HPP
diff --git a/arch/x86_64/include/arch/memory/paging/virtual_page.hpp b/arch/x86_64/include/arch/memory/paging/virtual_page.hpp
index f8dfbf0..ca11b3c 100644
--- a/arch/x86_64/include/arch/memory/paging/virtual_page.hpp
+++ b/arch/x86_64/include/arch/memory/paging/virtual_page.hpp
@@ -43,7 +43,7 @@ namespace teachos::arch::memory::paging
* @param level Level of the page table we want to calculate the index for.
* @return Index into the page table with the given level.
*/
- auto get_level_index(page_table::level level) const -> uint64_t;
+ auto get_level_index(page_table_handle::level level) const -> uint64_t;
/**
* @brief Defaulted equals operator.