From 5a2892f65abe13c32bb07de697826f374c1d2b1d Mon Sep 17 00:00:00 2001 From: Fabian Imhof Date: Tue, 22 Oct 2024 07:40:35 +0000 Subject: change table level 4 address --- arch/x86_64/include/arch/memory/paging/page_mapper.hpp | 5 ++--- arch/x86_64/src/memory/paging/page_mapper.cpp | 15 ++++----------- 2 files changed, 6 insertions(+), 14 deletions(-) (limited to 'arch/x86_64') 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 a8cca4c..24d8cde 100644 --- a/arch/x86_64/include/arch/memory/paging/page_mapper.hpp +++ b/arch/x86_64/include/arch/memory/paging/page_mapper.hpp @@ -73,12 +73,11 @@ namespace teachos::arch::memory::paging if (!next_handle) { auto allocated_frame = allocator.allocate_frame(); - exception_handling::assert(!allocated_frame.has_value(), "[Page mapper] Unable to allocate frame"); + exception_handling::assert(allocated_frame.has_value(), "[Page mapper] Unable to allocate frame"); current_handle[level_index].set_entry(allocated_frame.value(), entry::PRESENT | entry::WRITABLE); // There should now be an entry at the previously not existent index, therefore we can simply access it again. next_handle = current_handle.next_table(page.get_level_index(level)); - exception_handling::assert(!next_handle.has_value(), - "[Page mapper] Unable to create new entry into page table"); + exception_handling::assert(next_handle.has_value(), "[Page mapper] Unable to create new entry into page table"); next_handle.value().zero_entries(); } current_handle = next_handle.value(); diff --git a/arch/x86_64/src/memory/paging/page_mapper.cpp b/arch/x86_64/src/memory/paging/page_mapper.cpp index 75b17ff..1371868 100644 --- a/arch/x86_64/src/memory/paging/page_mapper.cpp +++ b/arch/x86_64/src/memory/paging/page_mapper.cpp @@ -4,8 +4,9 @@ namespace teachos::arch::memory::paging { namespace { - constexpr size_t PAGE_TABLE_LEVEL_4_ADDRESS = 0xfffffffffffff000; - } + // TODO: Set the address to a sensible location, this is merely a placeholder + constexpr size_t PAGE_TABLE_LEVEL_4_ADDRESS = 0x27AC40; + } // namespace auto create_or_get() -> page_table_handle { @@ -14,19 +15,11 @@ namespace teachos::arch::memory::paging return page_table_handle{active_page, page_table_handle::LEVEL4}; } - auto subtract_level(page_table_handle::level level) -> page_table_handle::level - { - exception_handling::assert(level != page_table_handle::LEVEL1, - "[Page table] Attemptd to decrement enum to value outside of range"); - auto value = static_cast::type>(level); - return static_cast(--value); - } - auto translate_page(virtual_page page) -> std::optional { auto current_handle = create_or_get(); - for (auto level = page_table_handle::LEVEL4; level != page_table_handle::LEVEL1; level = subtract_level(level)) + for (auto level = page_table_handle::LEVEL4; level != page_table_handle::LEVEL1; level--) { auto next_handle = current_handle.next_table(page.get_level_index(level)); // If the next table method failed then it is highly likely that it was a huge page and we therefore have to -- cgit v1.2.3