aboutsummaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorFabian Imhof <fabian.imhof@ost.ch>2024-10-20 12:57:21 +0000
committerFabian Imhof <fabian.imhof@ost.ch>2024-10-20 12:57:21 +0000
commit1b03bcecac1276b486e17daf0384de7fa203d974 (patch)
tree53496ddf705f876ec06654acbd6b723310847c30 /arch
parentbb8b3f9c0734220702e3e930e7acb4906aa13db6 (diff)
downloadteachos-1b03bcecac1276b486e17daf0384de7fa203d974.tar.xz
teachos-1b03bcecac1276b486e17daf0384de7fa203d974.zip
create active_page_table
Diffstat (limited to 'arch')
-rw-r--r--arch/x86_64/include/arch/memory/paging/active_page_table.hpp31
-rw-r--r--arch/x86_64/include/arch/memory/paging/page_mapper.hpp1
-rw-r--r--arch/x86_64/src/memory/paging/active_page_table.cpp31
3 files changed, 62 insertions, 1 deletions
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<allocator::FrameAllocator T>
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