From 553f3a824511bb8107982b2b2737f5b1dff59855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 13 Oct 2024 08:28:30 +0000 Subject: Add missing cpp files to cmake and fix elf alignment issues --- arch/x86_64/src/memory/frame_allocator.cpp | 66 ++++++++++++++++-------------- arch/x86_64/src/memory/multiboot.cpp | 4 +- 2 files changed, 37 insertions(+), 33 deletions(-) (limited to 'arch/x86_64/src/memory') diff --git a/arch/x86_64/src/memory/frame_allocator.cpp b/arch/x86_64/src/memory/frame_allocator.cpp index b8f53be..3793ac6 100644 --- a/arch/x86_64/src/memory/frame_allocator.cpp +++ b/arch/x86_64/src/memory/frame_allocator.cpp @@ -2,6 +2,37 @@ namespace teachos::arch::memory { + auto area_frame_allocator::choose_next_area() -> void + { + current_area = std::nullopt; + auto begin = areas; + auto end = areas + 5; + + // TODO: Fix this loop as soon as you've created an area iterator + for (auto area = begin; area != end; ++area) + { + std::size_t address = area->base_address + area->area_length - 1; + if (frame::containing_address(address) >= next_free_frame) + { + // The `next_free_frame` address is smaller than the last address of the current area + if (!current_area || area->base_address < current_area->base_address) + { + current_area = *area; + } + } + } + + if (current_area) + { + // Update the `next_free_frame` according to the new memory area + frame start_frame = frame::containing_address(current_area->base_address); + if (next_free_frame < start_frame) + { + next_free_frame = start_frame; + } + } + } + auto area_frame_allocator::allocate_frame() -> std::optional { /* @@ -40,38 +71,11 @@ namespace teachos::arch::memory return std::nullopt; } - auto area_frame_allocator::deallocate_frame(frame frame) -> void {} - - namespace + auto area_frame_allocator::deallocate_frame(frame frame) -> void { - auto area_frame_allocator::choose_next_area() -> void + // TODO: Fix, simply done because compiler will complain if frame is unused and not compile + if (frame.frame_number == 3) { - current_area = std::nullopt; - - // TODO: Fix this loop as soon as you've created an area iterator - for (const auto & area : areas) - { - std::size_t address = area.base_addr + area.length - 1; - if (frame::containing_address(address) >= next_free_frame) - { - // The `next_free_frame` address is smaller than the last address of the current area - if (!current_area || area.base_addr < current_area->base_address) - { - current_area = area; - } - } - } - - if (current_area) - { - // Update the `next_free_frame` according to the new memory area - frame start_frame = frame::containing_address(current_area->base_address); - if (next_free_frame < start_frame) - { - next_free_frame = start_frame; - } - } } - - } // namespace + } } // namespace teachos::arch::memory diff --git a/arch/x86_64/src/memory/multiboot.cpp b/arch/x86_64/src/memory/multiboot.cpp index 91e7550..3f6248d 100644 --- a/arch/x86_64/src/memory/multiboot.cpp +++ b/arch/x86_64/src/memory/multiboot.cpp @@ -1,4 +1,4 @@ -#include "multiboot.hpp" +#include "arch/memory/multiboot.hpp" namespace teachos::arch::memory { @@ -34,7 +34,7 @@ namespace teachos::arch::memory auto elf_section_header::is_null() const -> bool { - return name_table_index == 0U && type == elf_section_type::UNSPECIFIED && + return name_table_index == 0U && type == elf_section_type::INACTIVE && flags == teachos::arch::memory::elf_section_flags{0U} && virtual_address == 0U && file_offset == 0U && additional_information == 0U && address_alignment == 0U && fixed_table_entry_size == 0U; } -- cgit v1.2.3