diff options
| author | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-11-04 12:13:44 +0000 |
|---|---|---|
| committer | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-11-04 12:13:44 +0000 |
| commit | 162bea11c7a4f1854cde53920b4c14b4eadf539d (patch) | |
| tree | 602177115d3e88991882edf39564e844a20bb19a /arch/x86_64/src | |
| parent | 95d8c279bf945c99ef207c12de3ab6a2bc14f380 (diff) | |
| download | teachos-162bea11c7a4f1854cde53920b4c14b4eadf539d.tar.xz teachos-162bea11c7a4f1854cde53920b4c14b4eadf539d.zip | |
WIP attempt to fix crashes
Diffstat (limited to 'arch/x86_64/src')
| -rw-r--r-- | arch/x86_64/src/memory/allocator/area_frame_allocator.cpp | 12 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/allocator/physical_frame.cpp | 113 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/multiboot/reader.cpp | 25 |
3 files changed, 32 insertions, 118 deletions
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 da4a919..42aff68 100644 --- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp @@ -23,19 +23,17 @@ namespace teachos::arch::memory::allocator auto area_frame_allocator::choose_next_area() -> void { current_area = std::nullopt; - auto next_area_with_free_frames = memory_areas | std::views::filter([this](multiboot::memory_area const & area) { - auto address = area.base_address + area.area_length - 1; + auto next_area_with_free_frames = memory_areas | std::views::filter([this](auto const & area) { + 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, [](multiboot::memory_area a, multiboot::memory_area b) { - return a.base_address < b.base_address; - }); + 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; }); 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 227745a..63d84ec 100644 --- a/arch/x86_64/src/memory/allocator/physical_frame.cpp +++ b/arch/x86_64/src/memory/allocator/physical_frame.cpp @@ -9,126 +9,43 @@ namespace teachos::arch::memory::allocator auto physical_frame::start_address() const -> physical_address { return frame_number * PAGE_FRAME_SIZE; } - /** - * @brief Constructor. - * - * @param value Underlying value the iterator should point too - */ - physical_frame_iterator::physical_frame_iterator(physical_frame_iterator::value_type value) - : value(value) + auto physical_frame::operator++(int) -> physical_frame { - // Nothing to do - } - - /** - * @brief Dereferences the initally given pointer to its value. - * - * @return Reference to the value. - */ - auto physical_frame_iterator::operator*() -> physical_frame_iterator::value_type & { return value; } - - /** - * @brief Get underlying value, which is the intially passed pointer. - * - * @return Underlying value passed intially. - */ - auto physical_frame_iterator::operator->() -> physical_frame_iterator::value_type * { return &value; } - - /** - * @brief Post increment operator. Returns a copy of the value. - * - * @return Copy of the incremented underlying address. - */ - auto physical_frame_iterator::operator++(int) -> physical_frame_iterator - { - physical_frame_iterator const old_value = *this; - ++value.frame_number; + physical_frame const old_value = *this; + ++frame_number; return old_value; } - /** - * @brief Pre increment operator. Returns a reference to the changed value. - * - * @return Reference to the incremented underlying address. - */ - auto physical_frame_iterator::operator++() -> physical_frame_iterator & + auto physical_frame::operator++() -> physical_frame & { - ++value.frame_number; + ++frame_number; return *this; } - /** - * @brief Addition assignment operator. Returns a reference to the changed value. - * - * @param operand Value we want to add to the underlying address. - * @return Reference to the changed underlying address. - */ - auto - physical_frame_iterator::operator+=(physical_frame_iterator::difference_type operand) -> physical_frame_iterator & + auto physical_frame::operator+=(std::size_t operand) -> physical_frame & { - value.frame_number += operand; + frame_number += operand; return *this; } - /** - * @brief Subtraction assignment operator. Returns a reference to the changed value. - * - * @param operand Value we want to subtract from the underlying address. - * @return Reference to the changed underlying address. - */ - auto - physical_frame_iterator::operator-=(physical_frame_iterator::difference_type operand) -> physical_frame_iterator & + auto physical_frame::operator-=(std::size_t operand) -> physical_frame & { - value.frame_number -= operand; + frame_number -= operand; return *this; } - /** - * @brief Addition operator. Returns the changed value. - * - * @param operand Value we want to add to a copy of the underlying address. - * @return Copy of underlying address incremented by the given value. - */ - auto - physical_frame_iterator::operator+(physical_frame_iterator::difference_type operand) const -> physical_frame_iterator - { - return physical_frame_iterator{physical_frame_iterator::value_type{value.frame_number + operand}}; - } - - /** - * @brief Subtraction operator. Returns the changed value. - * - * @param operand Value we want to subtrcat from a copy of the underlying address. - * @return Copy of underlying address decremented by the given value. - */ - auto - physical_frame_iterator::operator-(physical_frame_iterator::difference_type operand) const -> physical_frame_iterator + auto physical_frame::operator+(std::size_t operand) const -> physical_frame { - return physical_frame_iterator{physical_frame_iterator::value_type{value.frame_number - operand}}; + return physical_frame{frame_number + operand}; } - /** - * @brief Subtraction operator. Returns the size difference between two iterators. - * - * @param other Other iterator we want to substract the underlying address with ours. - * @return Size difference between the underlying address of this instance and the given iterator. - */ - auto physical_frame_iterator::operator-(const physical_frame_iterator & other) const - -> physical_frame_iterator::difference_type + auto physical_frame::operator-(std::size_t operand) const -> physical_frame { - return value.frame_number - other.value.frame_number; + return physical_frame{frame_number - operand}; } - /** - * @brief Index operator overload. Returns a reference to the value at the given index. Simply returns the - * dereferenced underlying pointer incremented by the given index. - * - * @param index Index we want to access and get the value from. - * @return Reference to the value at the given index. - */ - auto physical_frame_iterator::operator[](physical_frame_iterator::difference_type index) const - -> physical_frame_iterator::value_type + auto physical_frame::operator-(const physical_frame & other) const -> std::size_t { - return physical_frame_iterator::value_type{value.frame_number + index}; + 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 4576085..178cc45 100644 --- a/arch/x86_64/src/memory/multiboot/reader.cpp +++ b/arch/x86_64/src/memory/multiboot/reader.cpp @@ -51,28 +51,27 @@ namespace teachos::arch::memory::multiboot auto const begin = elf_section_header_container::iterator{reinterpret_cast<elf_section_header *>(&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, [](elf_section_header const & a, elf_section_header const & b) { - return a.physical_address < b.physical_address; - }); + 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; }); auto const elf_section_with_highest_physical_address = - std::ranges::max_element(sections, [](elf_section_header const & a, elf_section_header const & b) { - auto a_physical_address_end = a.physical_address + a.section_size; - auto b_physical_address_end = b.physical_address + b.section_size; + 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; return a_physical_address_end < b_physical_address_end; }); - auto const symbol_table_section_count = std::ranges::count_if(sections, [](elf_section_header const & section) { - return section.type == elf_section_type::DYNAMIC_SYMBOL_TABLE || section.type == elf_section_type::SYMBOL_TABLE; + 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; }); auto const dynamic_section_count = std::ranges::count_if( - sections, [](elf_section_header 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, @@ -82,10 +81,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; } |
