From edc11135d83ef1f8fcbc1575a290b31ccbdb7e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 10 Nov 2024 09:34:21 +0000 Subject: Identity map memory map and vga text buffer,w hen setting up kernel --- .../include/arch/memory/paging/kernel_mapper.hpp | 23 +++++++++++++++++++--- .../include/arch/memory/paging/page_entry.hpp | 2 +- arch/x86_64/include/arch/video/vga/text.hpp | 2 ++ arch/x86_64/src/memory/paging/page_entry.cpp | 2 +- arch/x86_64/src/video/vga/text.cpp | 21 ++++++++++---------- 5 files changed, 34 insertions(+), 16 deletions(-) (limited to 'arch') 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 c91c5f0..d1b9325 100644 --- a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp +++ b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp @@ -5,6 +5,7 @@ #include "arch/memory/paging/active_page_table.hpp" #include "arch/memory/paging/inactive_page_table.hpp" #include "arch/memory/paging/temporary_page.hpp" +#include "arch/video/vga/text.hpp" namespace teachos::arch::memory::paging { @@ -124,19 +125,35 @@ namespace teachos::arch::memory::paging // End address is exclusive, so that it is not part of the section anymore (one past the last frame of this // section). But end frame would now point to the actual last frame and not one past the last frame, therefore // we increment by one to get one past the last frame of this section. - auto end_frame = + auto const end_frame = ++(allocator::physical_frame::containing_address(section.physical_address + section.section_size - 1)); allocator::frame_container::iterator const begin{start_frame}; allocator::frame_container::iterator const end{end_frame}; - allocator::frame_container frames{begin, end}; - entry entry{section.flags}; + allocator::frame_container const frames{begin, end}; + entry const entry{section.flags}; for (auto const & frame : frames) { active_table.identity_map(allocator, frame, entry.get_flags()); } } + + auto const vga_buffer_frame = + allocator::physical_frame::containing_address(video::vga::text::DEFAULT_VGA_TEXT_BUFFER_ADDRESS); + active_table.identity_map(allocator, vga_buffer_frame, entry::WRITABLE); + + auto const multiboot_start_frame = allocator::physical_frame::containing_address(mem_info.multiboot_start); + auto const multiboot_end_frame = ++allocator::physical_frame::containing_address(mem_info.multiboot_end - 1); + + allocator::frame_container::iterator const multiboot_begin{multiboot_start_frame}; + allocator::frame_container::iterator const multiboot_end{multiboot_end_frame}; + allocator::frame_container const multiboot_frames{multiboot_begin, multiboot_end}; + + for (auto const & frame : multiboot_frames) + { + active_table.identity_map(allocator, frame, entry::PRESENT); + } } T & allocator; diff --git a/arch/x86_64/include/arch/memory/paging/page_entry.hpp b/arch/x86_64/include/arch/memory/paging/page_entry.hpp index ab9659d..a7ba262 100644 --- a/arch/x86_64/include/arch/memory/paging/page_entry.hpp +++ b/arch/x86_64/include/arch/memory/paging/page_entry.hpp @@ -104,7 +104,7 @@ namespace teachos::arch::memory::paging * * @return Extracted entry flags, without the physical address. */ - auto get_flags() -> std::bitset<64U>; + auto get_flags() const -> std::bitset<64U>; private: std::bitset<64U> flags; ///< Underlying bitset used to read the flags from. Bits 9 - 11 and 52 - 62 can be diff --git a/arch/x86_64/include/arch/video/vga/text.hpp b/arch/x86_64/include/arch/video/vga/text.hpp index f200da4..665dc1c 100644 --- a/arch/x86_64/include/arch/video/vga/text.hpp +++ b/arch/x86_64/include/arch/video/vga/text.hpp @@ -7,6 +7,8 @@ namespace teachos::arch::video::vga::text { + auto constexpr DEFAULT_VGA_TEXT_BUFFER_ADDRESS = 0xB8000; + /** * @brief The colors available in the standard VGA text mode. */ diff --git a/arch/x86_64/src/memory/paging/page_entry.cpp b/arch/x86_64/src/memory/paging/page_entry.cpp index f13e645..aae5013 100644 --- a/arch/x86_64/src/memory/paging/page_entry.cpp +++ b/arch/x86_64/src/memory/paging/page_entry.cpp @@ -55,5 +55,5 @@ namespace teachos::arch::memory::paging flags = frame.start_address() | additional_flags.to_ulong(); } - auto entry::get_flags() -> std::bitset<64U> { return flags.to_ulong() & ~PHYSICAL_ADDRESS_MASK; } + auto entry::get_flags() const -> std::bitset<64U> { return flags.to_ulong() & ~PHYSICAL_ADDRESS_MASK; } } // namespace teachos::arch::memory::paging diff --git a/arch/x86_64/src/video/vga/text.cpp b/arch/x86_64/src/video/vga/text.cpp index 9eef288..0137ddb 100644 --- a/arch/x86_64/src/video/vga/text.cpp +++ b/arch/x86_64/src/video/vga/text.cpp @@ -11,9 +11,8 @@ namespace teachos::arch::video::vga::text { namespace { - auto constexpr default_text_buffer_address = 0xb8000; - auto constexpr default_text_buffer_width = 80; - auto constexpr default_text_buffer_height = 25; + auto constexpr DEFAULT_TEXT_BUFFER_WIDTH = 80U; + auto constexpr DEFAULT_TEXT_BUFFER_HEIGHT = 25U; extern "C" std::pair * vga_buffer_pointer; auto constinit text_buffer = teachos::memory::asm_pointer{vga_buffer_pointer}; @@ -21,7 +20,7 @@ namespace teachos::arch::video::vga::text auto clear(attribute attribute) -> void { - *text_buffer = reinterpret_cast(default_text_buffer_address); + *text_buffer = reinterpret_cast(DEFAULT_VGA_TEXT_BUFFER_ADDRESS); std::ranges::fill_n(*text_buffer, 2000, std::pair{' ', attribute}); } @@ -35,21 +34,21 @@ namespace teachos::arch::video::vga::text auto newline() -> void { - auto base = reinterpret_cast(default_text_buffer_address); + auto base = reinterpret_cast(DEFAULT_VGA_TEXT_BUFFER_ADDRESS); auto & raw_buffer = *text_buffer; - auto current_line = (raw_buffer - base) / default_text_buffer_width; + auto current_line = (raw_buffer - base) / DEFAULT_TEXT_BUFFER_WIDTH; auto next_line = current_line + 1; - if (next_line >= default_text_buffer_height) + if (next_line >= DEFAULT_TEXT_BUFFER_HEIGHT) { - auto begin = base + default_text_buffer_width; - auto end = base + default_text_buffer_width * default_text_buffer_height; + auto begin = base + DEFAULT_TEXT_BUFFER_WIDTH; + auto end = base + DEFAULT_TEXT_BUFFER_WIDTH * DEFAULT_TEXT_BUFFER_HEIGHT; std::ranges::move(begin, end, base); - raw_buffer = base + current_line * default_text_buffer_width; + raw_buffer = base + current_line * DEFAULT_TEXT_BUFFER_WIDTH; } else { - raw_buffer = base + next_line * default_text_buffer_width; + raw_buffer = base + next_line * DEFAULT_TEXT_BUFFER_WIDTH; } } -- cgit v1.2.3