From 30466aeb3da181c21bd451f32c1ff97e53a55dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 4 Nov 2024 13:29:03 +0000 Subject: Use more concepts and seperate iterator implementations --- .../src/memory/allocator/area_frame_allocator.cpp | 6 ++--- .../x86_64/src/memory/allocator/physical_frame.cpp | 27 ---------------------- arch/x86_64/src/memory/multiboot/reader.cpp | 17 +++++++------- 3 files changed, 11 insertions(+), 39 deletions(-) (limited to 'arch/x86_64/src') diff --git a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp index 42aff68..3bc9676 100644 --- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp @@ -24,16 +24,16 @@ namespace teachos::arch::memory::allocator { current_area = std::nullopt; auto next_area_with_free_frames = memory_areas | std::views::filter([this](auto const & area) { - auto address = area->base_address + area->area_length - 1; + auto address = area.base_address + area.area_length - 1; return physical_frame::containing_address(address) >= next_free_frame; }); auto const lowest_area_with_free_frames = std::ranges::min_element( - next_area_with_free_frames, [](auto const & a, auto const & b) { return a->base_address < b->base_address; }); + next_area_with_free_frames, [](auto const & a, auto const & b) { return a.base_address < b.base_address; }); if (lowest_area_with_free_frames != next_area_with_free_frames.end()) { - current_area = **lowest_area_with_free_frames; + current_area = *lowest_area_with_free_frames; // Update the `next_free_frame` according to the new memory area auto const start_frame = physical_frame::containing_address(current_area.value().base_address); if (next_free_frame < start_frame) diff --git a/arch/x86_64/src/memory/allocator/physical_frame.cpp b/arch/x86_64/src/memory/allocator/physical_frame.cpp index 63d84ec..ec387a1 100644 --- a/arch/x86_64/src/memory/allocator/physical_frame.cpp +++ b/arch/x86_64/src/memory/allocator/physical_frame.cpp @@ -21,31 +21,4 @@ namespace teachos::arch::memory::allocator ++frame_number; return *this; } - - auto physical_frame::operator+=(std::size_t operand) -> physical_frame & - { - frame_number += operand; - return *this; - } - - auto physical_frame::operator-=(std::size_t operand) -> physical_frame & - { - frame_number -= operand; - return *this; - } - - auto physical_frame::operator+(std::size_t operand) const -> physical_frame - { - return physical_frame{frame_number + operand}; - } - - auto physical_frame::operator-(std::size_t operand) const -> physical_frame - { - return physical_frame{frame_number - operand}; - } - - auto physical_frame::operator-(const physical_frame & other) const -> std::size_t - { - return frame_number - other.frame_number; - } } // namespace teachos::arch::memory::allocator diff --git a/arch/x86_64/src/memory/multiboot/reader.cpp b/arch/x86_64/src/memory/multiboot/reader.cpp index 178cc45..1dd18ff 100644 --- a/arch/x86_64/src/memory/multiboot/reader.cpp +++ b/arch/x86_64/src/memory/multiboot/reader.cpp @@ -51,27 +51,26 @@ namespace teachos::arch::memory::multiboot auto const begin = elf_section_header_container::iterator{reinterpret_cast(&symbol->end)}; auto const end = begin + symbol->number_of_sections; - exception_handling::assert((*begin)->is_null(), + exception_handling::assert(begin->is_null(), "[Multiboot Reader] Elf symbols section not starting with SHT_NULL section"); elf_section_header_container sections{begin, end}; 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; }); + 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) { - auto a_physical_address_end = a->physical_address + a->section_size; - auto b_physical_address_end = b->physical_address + b->section_size; + 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, [](auto const & section) { - return section->type == elf_section_type::DYNAMIC_SYMBOL_TABLE || - section->type == elf_section_type::SYMBOL_TABLE; + return section.type == elf_section_type::DYNAMIC_SYMBOL_TABLE || section.type == elf_section_type::SYMBOL_TABLE; }); auto const dynamic_section_count = std::ranges::count_if( - sections, [](auto const & section) { return section->type == elf_section_type::DYNAMIC; }); + sections, [](auto const & section) { return section.type == elf_section_type::DYNAMIC; }); exception_handling::assert( symbol_table_section_count == 1U, @@ -81,10 +80,10 @@ namespace teachos::arch::memory::multiboot "[Multiboot Reader] ELF Specifications allows only (1) or less dynamic sections, but got more"); auto const lowest_elf_section = *elf_section_with_lowest_physical_address; - kernel_start = lowest_elf_section->physical_address; + kernel_start = lowest_elf_section.physical_address; auto const highest_elf_section = *elf_section_with_highest_physical_address; - kernel_end = highest_elf_section->physical_address + highest_elf_section->section_size; + kernel_end = highest_elf_section.physical_address + highest_elf_section.section_size; return sections; } -- cgit v1.2.3