From 1b03bcecac1276b486e17daf0384de7fa203d974 Mon Sep 17 00:00:00 2001 From: Fabian Imhof Date: Sun, 20 Oct 2024 12:57:21 +0000 Subject: create active_page_table --- .../arch/memory/paging/active_page_table.hpp | 31 ++++++++++++++++++++++ .../include/arch/memory/paging/page_mapper.hpp | 1 - .../x86_64/src/memory/paging/active_page_table.cpp | 31 ++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 arch/x86_64/include/arch/memory/paging/active_page_table.hpp create mode 100644 arch/x86_64/src/memory/paging/active_page_table.cpp (limited to 'arch/x86_64') diff --git a/arch/x86_64/include/arch/memory/paging/active_page_table.hpp b/arch/x86_64/include/arch/memory/paging/active_page_table.hpp new file mode 100644 index 0000000..4a94b40 --- /dev/null +++ b/arch/x86_64/include/arch/memory/paging/active_page_table.hpp @@ -0,0 +1,31 @@ +#ifndef TEACHOS_ARCH_X86_64_MEMORY_PAGING_VIRTUAL_PAGE_HPP +#define TEACHOS_ARCH_X86_64_MEMORY_PAGING_VIRTUAL_PAGE_HPP + +#include "arch/memory/paging/page_table.hpp" + +namespace teachos::arch::memory::paging +{ + + struct active_page_table + { + /** + * @brief Ensures only one instance of active_page_table exists. + * + * @param level4_page_table A pointer to the level 4 page table. + * @return The only instance of active_page_table. + */ + auto create(page_table * level4_page_table) -> active_page_table *; + + private: + /** + * @brief Construct a new active page table object. + * + * @param level4_page_table A pointer to the level 4 page table. + */ + active_page_table(page_table * level4_page_table); + + bool instantiated = false; ///< Indicates wether an instance already exists. + page_table * level4_page_table; ///< The active level4 page table. + }; +} // namespace teachos::arch::memory::paging +#endif \ No newline at end of file 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 5bdd82a..ae3502e 100644 --- a/arch/x86_64/include/arch/memory/paging/page_mapper.hpp +++ b/arch/x86_64/include/arch/memory/paging/page_mapper.hpp @@ -48,7 +48,6 @@ namespace teachos::arch::memory::paging template auto map_page_to_frame(T & allocator, virtual_page page, allocator::physical_frame frame, std::bitset<64U> flags) -> void - { page_table page_table{}; bool table_exists = false; diff --git a/arch/x86_64/src/memory/paging/active_page_table.cpp b/arch/x86_64/src/memory/paging/active_page_table.cpp new file mode 100644 index 0000000..eb85c34 --- /dev/null +++ b/arch/x86_64/src/memory/paging/active_page_table.cpp @@ -0,0 +1,31 @@ +#include "arch/memory/paging/active_page_table.hpp" + +namespace teachos::arch::memory::paging +{ + struct active_page_table + { + auto create(page_table * level4_page_table) -> active_page_table * + { + if (instantiated) + { + return this; + } + + instantiated = true; + return &active_page_table(level4_page_table); + } + + active_page_table(const active_page_table &) = delete; + active_page_table & operator=(const active_page_table &) = delete; + + private: + active_page_table(page_table * level4_page_table) + : level4_page_table(level4_page_table) + { + // Nothing to do + } + + bool instantiated = false; + page_table * level4_page_table; + }; +} // namespace teachos::arch::memory::paging \ No newline at end of file -- cgit v1.2.3