From 40804526a58ddf2cc0df0750550c8dcfa7b7c57c Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 15 Dec 2025 11:34:30 +0100 Subject: x86_64/boot: use high-mem address of MBI --- arch/x86_64/include/x86_64/boot/boot.hpp | 3 +++ arch/x86_64/src/boot/entry64.s | 1 + arch/x86_64/src/kapi/memory.cpp | 6 ++---- arch/x86_64/src/memory/recursive_page_mapper.cpp | 3 +-- 4 files changed, 7 insertions(+), 6 deletions(-) (limited to 'arch') diff --git a/arch/x86_64/include/x86_64/boot/boot.hpp b/arch/x86_64/include/x86_64/boot/boot.hpp index 6dcd2de..2c44659 100644 --- a/arch/x86_64/include/x86_64/boot/boot.hpp +++ b/arch/x86_64/include/x86_64/boot/boot.hpp @@ -56,7 +56,10 @@ namespace teachos::boot struct information { + //! A pointer to the loader provided Multiboot2 Information structure. multiboot2::information_view const * mbi; + + //! The index of the next character to be written in the VGA text buffer after handoff. std::size_t vga_buffer_index; }; diff --git a/arch/x86_64/src/boot/entry64.s b/arch/x86_64/src/boot/entry64.s index 2932354..657b0a8 100644 --- a/arch/x86_64/src/boot/entry64.s +++ b/arch/x86_64/src/boot/entry64.s @@ -33,6 +33,7 @@ _entry64: mov %rsp, %rbp mov multiboot_information_pointer, %rax + or $TEACHOS_VMA, %rax mov vga_buffer_pointer, %rdx sub $0xb8000, %rdx mov %rax, (bootstrap_information) diff --git a/arch/x86_64/src/kapi/memory.cpp b/arch/x86_64/src/kapi/memory.cpp index ae0401e..748893a 100644 --- a/arch/x86_64/src/kapi/memory.cpp +++ b/arch/x86_64/src/kapi/memory.cpp @@ -138,8 +138,8 @@ namespace teachos::memory { auto mbi_base = std::bit_cast(boot::bootstrap_information.mbi); auto mbi_size = boot::bootstrap_information.mbi->size_bytes(); - auto mbi_physical_start = physical_address{mbi_base}; - auto mbi_virtual_start = linear_address{mbi_base + std::bit_cast(&boot::x86_64::TEACHOS_VMA)}; + auto mbi_physical_start = physical_address{mbi_base & ~std::bit_cast(&boot::x86_64::TEACHOS_VMA)}; + auto mbi_virtual_start = linear_address{mbi_base}; auto mbi_block_count = (mbi_size + PLATFORM_FRAME_SIZE - 1) / PLATFORM_FRAME_SIZE; for (auto i = 0uz; i < mbi_block_count; ++i) @@ -148,8 +148,6 @@ namespace teachos::memory auto frame = frame::containing(mbi_physical_start) + 1; mapper.map(page, frame, page_mapper::flags::empty); } - - boot::bootstrap_information.mbi = std::bit_cast(mbi_virtual_start.raw()); } } // namespace diff --git a/arch/x86_64/src/memory/recursive_page_mapper.cpp b/arch/x86_64/src/memory/recursive_page_mapper.cpp index 798233a..ef234ad 100644 --- a/arch/x86_64/src/memory/recursive_page_mapper.cpp +++ b/arch/x86_64/src/memory/recursive_page_mapper.cpp @@ -14,8 +14,7 @@ namespace teachos::memory::x86_64 //! On any level above PML1, the entries need to not be no_execute, because the image is densely packed. The entries //! also need to be writable, since the mapping is being performed through the recursive page map hierarchy. When //! setting the final entry in the PML1, the actually desired flags are set as is, with the present bit - //! added, thus - //! still enforcing non-writability and non-execution of the affected page. + //! added, thus still enforcing non-writability and non-execution of the affected page. template requires(Level > 1uz && Level <= PLATFORM_PAGING_LEVELS) auto do_map(recursive_page_table * pml, page page, frame_allocator & allocator, page_mapper::flags flags) -- cgit v1.2.3