diff options
Diffstat (limited to 'arch/x86_64/src/kapi/memory.cpp')
| -rw-r--r-- | arch/x86_64/src/kapi/memory.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/arch/x86_64/src/kapi/memory.cpp b/arch/x86_64/src/kapi/memory.cpp index 703b3e1..0e4b78e 100644 --- a/arch/x86_64/src/kapi/memory.cpp +++ b/arch/x86_64/src/kapi/memory.cpp @@ -8,6 +8,7 @@ #include "x86_64/memory/buffered_allocator.hpp" #include "x86_64/memory/mmu.hpp" #include "x86_64/memory/page_table.hpp" +#include "x86_64/memory/page_utilities.hpp" #include "x86_64/memory/paging_root.hpp" #include "x86_64/memory/region_allocator.hpp" #include "x86_64/memory/scoped_mapping.hpp" @@ -63,15 +64,46 @@ namespace teachos::memory using namespace x86_64; using entry_flags = page_table::entry::flags; - auto temporary_mapper = scoped_mapping{page::containing(unused_page_address), allocator}; + auto page = page::containing(unused_page_address); + + auto temporary_mapper = scoped_mapping{page, allocator}; auto new_pml4_frame = allocator.allocate(); auto pml4 = std::construct_at(temporary_mapper.map_as<page_table>(*new_pml4_frame, entry_flags::writable)); (*pml4)[recursive_page_map_index].frame(new_pml4_frame.value(), entry_flags::present | entry_flags::writable); + + auto pml4_index = pml_index<4>(page); + auto & old_pml4 = paging_root::get(); + auto pml4_entry = old_pml4[pml4_index]; + + auto pml3_index = pml_index<3>(page); + auto old_pml3 = old_pml4.next(pml4_index); + auto pml3_entry = (**old_pml3)[pml3_index]; + + auto pml2_index = pml_index<2>(page); + auto old_pml2 = (**old_pml3).next(pml3_index); + auto pml2_entry = (**old_pml2)[pml2_index]; + + auto pml1_index = pml_index<1>(page); + auto old_pml1 = (**old_pml2).next(pml2_index); + auto pml1_entry = (**old_pml1)[pml1_index]; + paging_root::get()[recursive_page_map_index].frame(new_pml4_frame.value(), entry_flags::present | entry_flags::writable); tlb_flush_all(); + + auto & new_pml4 = paging_root::get(); + new_pml4[pml4_index] = pml4_entry; + + auto new_pml3 = new_pml4.next(pml4_index); + (**new_pml3)[pml3_index] = pml3_entry; + + auto new_pml2 = (**new_pml3).next(pml3_index); + (**new_pml2)[pml2_index] = pml2_entry; + + auto new_pml1 = (**new_pml2).next(pml2_index); + (**new_pml1)[pml1_index] = pml1_entry; } } // namespace |
