diff options
Diffstat (limited to 'arch/x86_64/include')
| -rw-r--r-- | arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp | 25 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/memory/paging/temporary_page.hpp | 9 |
2 files changed, 17 insertions, 17 deletions
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 a7ae3aa..d7365a0 100644 --- a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp +++ b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp @@ -16,16 +16,21 @@ namespace teachos::arch::memory::paging /** * @brief Kernel mapper that allows to remap the kernel elf sections in C++. + * + * @tparam T Contract the allocator that should be used to allocate frames for the remapping process has to fulfill. */ + template<allocator::FrameAllocator T> struct kernel_mapper { /** * @brief Constructor. * + * @param allocator Allocator that should be used to allocate frames for the remapping process. * @param mem_info Information about elf kernel sections required for remapping process. */ - kernel_mapper(multiboot::memory_information const & mem_info) - : mem_info(mem_info) + kernel_mapper(T & allocator, multiboot::memory_information const & mem_info) + : allocator(allocator) + , mem_info(mem_info) { // Nothing to do } @@ -37,13 +42,8 @@ namespace teachos::arch::memory::paging * @note We have to use a workaround with an * inactive page table, that is not used by the CPU to ensure we are not changign memory that we are using. Because * remapping active kernel memory in the kernel wouldn't work. - * - * @tparam T Contract the allocator that should be used to allocate frames for the remapping process has to fulfill. - * - * @param allocator Allocator that should be used to allocate frames for the remapping process. */ - template<allocator::FrameAllocator T> - auto remap_kernel(T & allocator) -> void + auto remap_kernel() -> void { virtual_page temporary_address{UNUSED_VIRTUAL_ADDRESS}; temporary_page temporary_page{temporary_address, allocator}; @@ -80,11 +80,11 @@ namespace teachos::arch::memory::paging active_table.active_handle[511].set_entry(inactive_table.page_table_level_4_frame, entry::PRESENT | entry::WRITABLE); tlb_flush_all(); - map_elf_kernel_sections(temporary_page, active_table); + map_elf_kernel_sections(active_table); page_table_level4[511].set_entry(backup, entry::PRESENT | entry::WRITABLE); tlb_flush_all(); - temporary_page.unmap(active_table); + temporary_page.unmap_page(active_table); } /** @@ -94,7 +94,7 @@ namespace teachos::arch::memory::paging * @param active_table Active level 4 page table that should be used to map the required elf sections into entries. * Has had its recursive mapping temporarily replaced and points to unmapped place in memory. */ - auto map_elf_kernel_sections(temporary_page & temporary_page, active_page_table & active_table) -> void + auto map_elf_kernel_sections(active_page_table & active_table) -> void { for (auto const & section : mem_info.sections) { @@ -115,11 +115,12 @@ namespace teachos::arch::memory::paging for (auto const & frame : frames) { // TODO: Use actual elf section flags, convert from one to the other flag type. - active_table.identity_map(temporary_page.allocator, frame, entry::WRITABLE); + active_table.identity_map(allocator, frame, entry::WRITABLE); } } } + T & allocator; multiboot::memory_information const & mem_info; ///< Information about elf kernel sections required for remapping process. }; diff --git a/arch/x86_64/include/arch/memory/paging/temporary_page.hpp b/arch/x86_64/include/arch/memory/paging/temporary_page.hpp index 6b3bcb6..8b49894 100644 --- a/arch/x86_64/include/arch/memory/paging/temporary_page.hpp +++ b/arch/x86_64/include/arch/memory/paging/temporary_page.hpp @@ -40,7 +40,7 @@ namespace teachos::arch::memory::paging * * @param active_table The current active page table. */ - auto unmap(active_page_table & active_table) -> void; + auto unmap_page(active_page_table & active_table) -> void; /** * @brief Map the temporary page to a frame. @@ -51,10 +51,6 @@ namespace teachos::arch::memory::paging */ auto map_table_frame(allocator::physical_frame frame, active_page_table & active_table) -> page_table_handle; - // TODO: Better way to do this? - virtual_page page; - allocator::tiny_frame_allocator allocator; - private: /** * @brief Map the temporary page to a frame. @@ -64,6 +60,9 @@ namespace teachos::arch::memory::paging * @return The virtual address of the page. */ auto map_to_frame(allocator::physical_frame frame, active_page_table & active_table) -> virtual_address; + + virtual_page page; ///< Underlying virtual page we want to temporarily map a level 4 page table into. + allocator::tiny_frame_allocator allocator; ///< Allocator that should be used to map the temporary page. }; } // namespace teachos::arch::memory::paging |
