From 67be3c58bef94fece14d4e3a79f3559649e9a74c Mon Sep 17 00:00:00 2001 From: Fabian Imhof Date: Sun, 3 Nov 2024 12:12:41 +0000 Subject: rename member and use correct address --- .../arch/memory/multiboot/elf_symbols_section.hpp | 8 ++++---- .../include/arch/memory/paging/kernel_mapper.hpp | 17 ++++++++++++----- arch/x86_64/include/arch/memory/paging/tlb.hpp | 2 +- .../src/memory/multiboot/elf_symbols_section.cpp | 2 +- arch/x86_64/src/memory/multiboot/reader.cpp | 20 ++++++++++---------- 5 files changed, 28 insertions(+), 21 deletions(-) (limited to 'arch') diff --git a/arch/x86_64/include/arch/memory/multiboot/elf_symbols_section.hpp b/arch/x86_64/include/arch/memory/multiboot/elf_symbols_section.hpp index c9989ae..e29590d 100644 --- a/arch/x86_64/include/arch/memory/multiboot/elf_symbols_section.hpp +++ b/arch/x86_64/include/arch/memory/multiboot/elf_symbols_section.hpp @@ -120,10 +120,10 @@ namespace teachos::arch::memory::multiboot uint32_t name_table_index; ///< Index into the section header string table, specifies the name of the section. elf_section_type type; ///< Categorizes the sections content and semantics. elf_section_flags flags; ///< 1-bit flgas that describe section attributes. - uint64_t virtual_address; ///< If section appears in memory image of a process, gives address at which the sections - ///< first byte should reside, otherwise 0. - uint64_t file_offset; ///< Offset from the beginning of the file to the first byte in the section. SHT_NOBITS - ///< contains the conceptual placement instead (because it occupies no space in the file). + uint64_t physical_address; ///< If section appears in memory image of a process, gives address at which the + ///< sections first byte should reside, otherwise 0. + uint64_t file_offset; ///< Offset from the beginning of the file to the first byte in the section. SHT_NOBITS + ///< contains the conceptual placement instead (because it occupies no space in the file). uint64_t section_size; ///< Complete section size in bytes, SHT_NOBITS may have non-zero value but will always ///< occupy no space in the file. uint32_t other_section; ///< Section header table index link, behaviour varies on type 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 d7365a0..84f0471 100644 --- a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp +++ b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp @@ -57,7 +57,9 @@ namespace teachos::arch::memory::paging private: /** - * @brief Remaps the kernel elf sections. This is done with switching the current level 4 page table recursive + * @brief Remaps the kernel elf sections. + * + * This is done with switching the current level 4 page table recursive * mapping to any unmapped address in memory and then actually mapping the level 4 page table on that address. * Once the remapping process is done we can restore the original recursive mapping with the complete remapped * kernel. @@ -74,11 +76,16 @@ namespace teachos::arch::memory::paging auto remap_elf_kernel_sections(inactive_page_table inactive_table, temporary_page & temporary_page, active_page_table & active_table) -> void { - auto const backup = allocator::physical_frame::containing_address(PAGE_TABLE_LEVEL_4_ADDRESS); + auto physical_address = active_table.translate_address(PAGE_TABLE_LEVEL_4_ADDRESS); + exception_handling::assert(!physical_address.has_value(), + "[Kernel Mapper] Physical address for active table not mapped"); + + auto const backup = allocator::physical_frame::containing_address(physical_address.value()); auto page_table_level4 = temporary_page.map_table_frame(backup, active_table); 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(active_table); @@ -102,11 +109,11 @@ namespace teachos::arch::memory::paging { continue; } - exception_handling::assert(section.virtual_address % allocator::PAGE_FRAME_SIZE == 0U, + exception_handling::assert(section.physical_address % allocator::PAGE_FRAME_SIZE == 0U, "[Kernel Mapper] Section must be page aligned"); - auto const start_frame = allocator::physical_frame::containing_address(section.virtual_address); + auto const start_frame = allocator::physical_frame::containing_address(section.physical_address); auto const end_frame = - allocator::physical_frame::containing_address(section.virtual_address + section.section_size); + allocator::physical_frame::containing_address(section.physical_address + section.section_size); allocator::physical_frame_iterator const begin{start_frame}; allocator::physical_frame_iterator const end{end_frame}; diff --git a/arch/x86_64/include/arch/memory/paging/tlb.hpp b/arch/x86_64/include/arch/memory/paging/tlb.hpp index 1194720..85c4152 100644 --- a/arch/x86_64/include/arch/memory/paging/tlb.hpp +++ b/arch/x86_64/include/arch/memory/paging/tlb.hpp @@ -5,7 +5,7 @@ namespace teachos::arch::memory::paging { - std::size_t constexpr PAGE_TABLE_LEVEL_4_ADDRESS = 0xffffffff'fffff000; + virtual_address constexpr PAGE_TABLE_LEVEL_4_ADDRESS = 0xffffffff'fffff000; /** * @brief Invalidates any translation lookaside buffer (TLB) entry for the page table the given address is cotained diff --git a/arch/x86_64/src/memory/multiboot/elf_symbols_section.cpp b/arch/x86_64/src/memory/multiboot/elf_symbols_section.cpp index 953a57d..f5d126b 100644 --- a/arch/x86_64/src/memory/multiboot/elf_symbols_section.cpp +++ b/arch/x86_64/src/memory/multiboot/elf_symbols_section.cpp @@ -7,7 +7,7 @@ namespace teachos::arch::memory::multiboot auto elf_section_header::is_null() const -> bool { return name_table_index == 0U && type == elf_section_type::INACTIVE && flags == elf_section_flags(0U) && - virtual_address == 0U && file_offset == 0U && additional_information == 0U && address_alignment == 0U && + physical_address == 0U && file_offset == 0U && additional_information == 0U && address_alignment == 0U && fixed_table_entry_size == 0U; } } // namespace teachos::arch::memory::multiboot diff --git a/arch/x86_64/src/memory/multiboot/reader.cpp b/arch/x86_64/src/memory/multiboot/reader.cpp index 7bdf48f..4576085 100644 --- a/arch/x86_64/src/memory/multiboot/reader.cpp +++ b/arch/x86_64/src/memory/multiboot/reader.cpp @@ -56,16 +56,16 @@ namespace teachos::arch::memory::multiboot elf_section_header_container sections{begin, end}; - auto const elf_section_with_lowest_virtual_address = + auto const elf_section_with_lowest_physical_address = std::ranges::min_element(sections, [](elf_section_header const & a, elf_section_header const & b) { - return a.virtual_address < b.virtual_address; + return a.physical_address < b.physical_address; }); - auto const elf_section_with_highest_virtual_address = + auto const elf_section_with_highest_physical_address = std::ranges::max_element(sections, [](elf_section_header const & a, elf_section_header const & b) { - auto a_virtual_address_end = a.virtual_address + a.section_size; - auto b_virtual_address_end = b.virtual_address + b.section_size; - return a_virtual_address_end < b_virtual_address_end; + auto a_physical_address_end = a.physical_address + a.section_size; + auto b_physical_address_end = b.physical_address + b.section_size; + return a_physical_address_end < b_physical_address_end; }); auto const symbol_table_section_count = std::ranges::count_if(sections, [](elf_section_header const & section) { @@ -81,11 +81,11 @@ namespace teachos::arch::memory::multiboot dynamic_section_count <= 1U, "[Multiboot Reader] ELF Specifications allows only (1) or less dynamic sections, but got more"); - auto const lowest_elf_section = *elf_section_with_lowest_virtual_address; - kernel_start = lowest_elf_section.virtual_address; + auto const lowest_elf_section = *elf_section_with_lowest_physical_address; + kernel_start = lowest_elf_section.physical_address; - auto const highest_elf_section = *elf_section_with_highest_virtual_address; - kernel_end = highest_elf_section.virtual_address + highest_elf_section.section_size; + auto const highest_elf_section = *elf_section_with_highest_physical_address; + kernel_end = highest_elf_section.physical_address + highest_elf_section.section_size; return sections; } -- cgit v1.2.3