From 86f19267c7ca4e14ac6169f758130b3c27e62cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Fri, 1 Nov 2024 15:10:30 +0000 Subject: Resolve compilation issues --- .../arch/memory/paging/active_page_table.hpp | 27 +++++++++++----------- .../include/arch/memory/paging/kernel_mapper.hpp | 12 ++++++++-- .../x86_64/src/memory/paging/active_page_table.cpp | 5 ---- arch/x86_64/src/memory/paging/kernel_mapper.cpp | 17 ++++++++++---- 4 files changed, 36 insertions(+), 25 deletions(-) (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 index e876798..e2c205b 100644 --- a/arch/x86_64/include/arch/memory/paging/active_page_table.hpp +++ b/arch/x86_64/include/arch/memory/paging/active_page_table.hpp @@ -10,6 +10,7 @@ namespace teachos::arch::memory::paging { + std::size_t constexpr PAGE_TABLE_LEVEL_4_ADDRESS = 0xffffffff'fffff000; /** * @brief Currently active level 4 page table, is used to ensure there is only ever one valid instance and it cannot @@ -17,7 +18,7 @@ namespace teachos::arch::memory::paging */ struct active_page_table { - typedef void (*function)(active_page_table * active_page_table); + typedef void (*function)(active_page_table & active_page_table); /** * @brief Creates a single instance of an active level 4 page table table and returns the created instance or @@ -53,6 +54,18 @@ namespace teachos::arch::memory::paging */ auto translate_huge_page(virtual_page page) -> std::optional; + /** + * @brief Invalidates any translation lookaside buffer (TLB) entry for the page table the given address is cotained + * in. See https://www.felixcloutier.com/x86/invlpg for more information on the used x86 instruction. + * + * @param address Memory address, which will be used to determine the contained page and flush the TLB entry for + * that page. + */ + static auto invalidate_page_cache(virtual_address address) -> void + { + asm volatile("invlpg (%0)" ::"r"(address) : "memory"); + } + /** * @brief Maps a virtual page to a physical frame in the page table with the specified flags. * @@ -180,18 +193,6 @@ namespace teachos::arch::memory::paging */ active_page_table & operator=(active_page_table const &) = delete; - /** - * @brief Invalidates any translation lookaside buffer (TLB) entry for the page table the given address is cotained - * in. See https://www.felixcloutier.com/x86/invlpg for more information on the used x86 instruction. - * - * @param address Memory address, which will be used to determine the contained page and flush the TLB entry for - * that page. - */ - static auto invalidate_page_cache(virtual_address address) -> void - { - asm volatile("invlpg (%0)" ::"r"(address) : "memory"); - } - /** * @brief Unmaps specific page at the current internal handle level. * diff --git a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp index 085344a..0583692 100644 --- a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp +++ b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp @@ -7,8 +7,16 @@ namespace teachos::arch::memory::paging { - auto with(inactive_page_table inactive_page_table, temporary_page temporary_page, active_page_table::function f, - active_page_table & active_page_table) -> void; + struct kernel_mapper + { + kernel_mapper(active_page_table & active_table); + + auto with(inactive_page_table inactive_page_table, temporary_page temporary_page, + active_page_table::function f) -> void; + + private: + active_page_table & active_table; + }; } // namespace teachos::arch::memory::paging #endif // TEACHOS_ARCH_X86_64_MEMORY_PAGING_KERNEL_MAPPER_HPP diff --git a/arch/x86_64/src/memory/paging/active_page_table.cpp b/arch/x86_64/src/memory/paging/active_page_table.cpp index 38696f8..844ae37 100644 --- a/arch/x86_64/src/memory/paging/active_page_table.cpp +++ b/arch/x86_64/src/memory/paging/active_page_table.cpp @@ -2,11 +2,6 @@ namespace teachos::arch::memory::paging { - namespace - { - std::size_t constexpr PAGE_TABLE_LEVEL_4_ADDRESS = 0xffffffff'fffff000; - } // namespace - auto active_page_table::create_or_get() -> active_page_table & { static page_table_handle active_handle{reinterpret_cast(PAGE_TABLE_LEVEL_4_ADDRESS), diff --git a/arch/x86_64/src/memory/paging/kernel_mapper.cpp b/arch/x86_64/src/memory/paging/kernel_mapper.cpp index 9dfc5ad..59930fc 100644 --- a/arch/x86_64/src/memory/paging/kernel_mapper.cpp +++ b/arch/x86_64/src/memory/paging/kernel_mapper.cpp @@ -2,12 +2,19 @@ namespace teachos::arch::memory::paging { - auto with(inactive_page_table inactive_page_table, temporary_page temporary_page, - active_page_table::function f) -> void + kernel_mapper::kernel_mapper(active_page_table & active_table) + : active_table(active_table) { - /*active_handle[511].set_entry(inactive_page_table.page_table_level_4_frame, entry::PRESENT | entry::WRITABLE); - invalidate_page_cache(PAGE_TABLE_LEVEL_4_ADDRESS); + // Nothing to do + } + + auto kernel_mapper::with(inactive_page_table inactive_page_table, temporary_page temporary_page, + active_page_table::function f) -> void + { + active_table.active_handle[511].set_entry(inactive_page_table.page_table_level_4_frame, + entry::PRESENT | entry::WRITABLE); + active_page_table::invalidate_page_cache(PAGE_TABLE_LEVEL_4_ADDRESS); - f(*this);*/ + f(active_table); } } // namespace teachos::arch::memory::paging -- cgit v1.2.3