diff options
| author | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-11-03 10:47:33 +0000 |
|---|---|---|
| committer | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-11-03 10:47:33 +0000 |
| commit | d4b1b8a85212f07df47217fe13d86956c7eb064f (patch) | |
| tree | 2ad44bbe5795f6ca8e5796e6cb7d3e0e124ef330 /arch | |
| parent | 4d76f412b071a05f0aae1d1307f2b58cb2778569 (diff) | |
| download | teachos-d4b1b8a85212f07df47217fe13d86956c7eb064f.tar.xz teachos-d4b1b8a85212f07df47217fe13d86956c7eb064f.zip | |
Use passed allocator in inactive page instead of tiny.
Diffstat (limited to 'arch')
5 files changed, 25 insertions, 22 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 diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 5cfd9b3..c111f22 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -20,8 +20,8 @@ namespace teachos::arch::kernel auto const memory_information = memory::multiboot::read_multiboot2(); memory::allocator::area_frame_allocator allocator(memory_information); - memory::paging::kernel_mapper kernel(memory_information); - kernel.remap_kernel(allocator); + memory::paging::kernel_mapper kernel(allocator, memory_information); + kernel.remap_kernel(); video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); /* diff --git a/arch/x86_64/src/memory/paging/inactive_page_table.cpp b/arch/x86_64/src/memory/paging/inactive_page_table.cpp index 0b141e2..f6ecb8b 100644 --- a/arch/x86_64/src/memory/paging/inactive_page_table.cpp +++ b/arch/x86_64/src/memory/paging/inactive_page_table.cpp @@ -9,6 +9,6 @@ namespace teachos::arch::memory::paging auto table = temporary_page.map_table_frame(page_table_level_4_frame, active_page_table); table.zero_entries(); table[511].set_entry(page_table_level_4_frame, entry::PRESENT | entry::WRITABLE); - temporary_page.unmap(active_page_table); + temporary_page.unmap_page(active_page_table); } } // namespace teachos::arch::memory::paging diff --git a/arch/x86_64/src/memory/paging/temporary_page.cpp b/arch/x86_64/src/memory/paging/temporary_page.cpp index 180b4a8..7b065ab 100644 --- a/arch/x86_64/src/memory/paging/temporary_page.cpp +++ b/arch/x86_64/src/memory/paging/temporary_page.cpp @@ -14,7 +14,10 @@ namespace teachos::arch::memory::paging return page.start_address(); } - auto temporary_page::unmap(active_page_table & active_table) -> void { active_table.unmap_page(allocator, page); } + auto temporary_page::unmap_page(active_page_table & active_table) -> void + { + active_table.unmap_page(allocator, page); + } auto temporary_page::map_table_frame(allocator::physical_frame frame, active_page_table & active_table) -> page_table_handle @@ -33,6 +36,6 @@ namespace teachos::arch::memory::paging handle.zero_entries(); handle[511].set_entry(frame.value(), entry::PRESENT | entry::WRITABLE); - unmap(active_table); + unmap_page(active_table); } } // namespace teachos::arch::memory::paging |
