aboutsummaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2024-11-11 14:16:18 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2024-11-11 14:16:18 +0000
commit0ca0c40c197c214288ad2ed1179ae9ae28c50194 (patch)
treedf2127d7e6a39de96c70c2458140dee75ae3c49e /arch
parent0f3c5c2bc02d7aa48f8edbe42a67dd91821032b7 (diff)
downloadteachos-0ca0c40c197c214288ad2ed1179ae9ae28c50194.tar.xz
teachos-0ca0c40c197c214288ad2ed1179ae9ae28c50194.zip
Improve calculation of kernel end and start address.
Diffstat (limited to 'arch')
-rw-r--r--arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp3
-rw-r--r--arch/x86_64/src/kernel/main.cpp4
-rw-r--r--arch/x86_64/src/memory/multiboot/reader.cpp9
3 files changed, 12 insertions, 4 deletions
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 10fad0c..f01bd37 100644
--- a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
+++ b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
@@ -38,7 +38,7 @@ namespace teachos::arch::memory::paging
* inactive page table, that is not used by the CPU to ensure we are not changign memory that we are using. Because
* remapping active kernel memory in the kernel wouldn't work.
*/
- auto remap_kernel() -> void
+ auto remap_kernel() -> active_page_table &
{
temporary_page temporary_page{virtual_page{0xCAFEBABE}, allocator};
auto & active_table = active_page_table::create_or_get();
@@ -51,6 +51,7 @@ namespace teachos::arch::memory::paging
auto const old_level_4_page =
virtual_page::containing_address(old_table.page_table_level_4_frame.start_address());
active_table.unmap_page(allocator, old_level_4_page);
+ return active_table;
}
private:
diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp
index ea1a157..f9b252d 100644
--- a/arch/x86_64/src/kernel/main.cpp
+++ b/arch/x86_64/src/kernel/main.cpp
@@ -25,9 +25,11 @@ namespace teachos::arch::kernel
memory::cpu::set_efer_bit(memory::cpu::efer_flags::NXE);
memory::paging::kernel_mapper kernel(allocator, memory_information);
- kernel.remap_kernel();
+ auto & active_table = kernel.remap_kernel();
video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black);
+ // TODO: Map heap virtual pages with active table
+
/*
size_t address = 42 * memory::paging::PAGE_TABLE_ENTRY_COUNT * memory::paging::PAGE_TABLE_ENTRY_COUNT *
memory::allocator::PAGE_FRAME_SIZE; // 42th P3 entry
diff --git a/arch/x86_64/src/memory/multiboot/reader.cpp b/arch/x86_64/src/memory/multiboot/reader.cpp
index 1dd18ff..2bf5b25 100644
--- a/arch/x86_64/src/memory/multiboot/reader.cpp
+++ b/arch/x86_64/src/memory/multiboot/reader.cpp
@@ -6,6 +6,7 @@
#include "arch/memory/multiboot/info.hpp"
#include <algorithm>
+#include <ranges>
namespace teachos::arch::memory::multiboot
{
@@ -56,11 +57,15 @@ namespace teachos::arch::memory::multiboot
elf_section_header_container sections{begin, end};
+ auto allocated_sections = sections | std::views::filter([](auto const & section) {
+ return section.flags.contains_flags(elf_section_flags::OCCUPIES_MEMORY);
+ });
+
auto const elf_section_with_lowest_physical_address = std::ranges::min_element(
- sections, [](auto const & a, auto const & b) { return a.physical_address < b.physical_address; });
+ allocated_sections, [](auto const & a, auto const & b) { return a.physical_address < b.physical_address; });
auto const elf_section_with_highest_physical_address =
- std::ranges::max_element(sections, [](auto const & a, auto const & b) {
+ std::ranges::max_element(allocated_sections, [](auto const & a, auto const & b) {
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;