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 | |
| parent | 95d8c279bf945c99ef207c12de3ab6a2bc14f380 (diff) | |
| download | teachos-162bea11c7a4f1854cde53920b4c14b4eadf539d.tar.xz teachos-162bea11c7a4f1854cde53920b4c14b4eadf539d.zip | |
WIP attempt to fix crashes
Diffstat (limited to 'arch/x86_64')
9 files changed, 166 insertions, 265 deletions
diff --git a/arch/x86_64/include/arch/memory/allocator/physical_frame.hpp b/arch/x86_64/include/arch/memory/allocator/physical_frame.hpp index 89e3cf8..43a22a2 100644 --- a/arch/x86_64/include/arch/memory/allocator/physical_frame.hpp +++ b/arch/x86_64/include/arch/memory/allocator/physical_frame.hpp @@ -1,6 +1,9 @@ #ifndef TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_PHYSICAL_FRAME_HPP #define TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_PHYSICAL_FRAME_HPP +#include "arch/shared/container.hpp" +#include "arch/shared/random_access_iterator.hpp" + #include <compare> #include <cstdint> #include <iterator> @@ -49,67 +52,18 @@ namespace teachos::arch::memory::allocator auto start_address() const -> physical_address; /** - * @brief Defaulted equals operator. - */ - auto operator==(const physical_frame & other) const -> bool = default; - - /** - * @brief Defaulted three-way comparsion operator. - */ - auto operator<=>(const physical_frame & other) const -> std::partial_ordering = default; - - std::size_t frame_number = - {}; ///< Index number of the current physical frame, used to distinguish it from other frames. - }; - - /** - * @brief Iterator for the frame number - */ - struct physical_frame_iterator - { - using iterator_category = std::random_access_iterator_tag; ///< Iterator category of this type. - using difference_type = std::ptrdiff_t; ///< Type when diving one instance of this iterator by another. - using value_type = physical_frame; ///< Underlying value pointed to by this iterator. - - /** - * @brief Defaulted constructor. - */ - physical_frame_iterator() = default; - - /** - * @brief Constructor. - * - * @param value Underlying value the iterator should point too - */ - explicit physical_frame_iterator(value_type value); - - /** - * @brief Dereferences the initally given pointer to its value. - * - * @return Reference to the value. - */ - auto operator*() -> value_type &; - - /** - * @brief Get underlying value, which is the intially passed pointer. - * - * @return Underlying value passed intially. - */ - auto operator->() -> value_type *; - - /** * @brief Post increment operator. Returns a copy of the value. * * @return Copy of the incremented underlying address. */ - auto operator++(int) -> physical_frame_iterator; + auto operator++(int) -> physical_frame; /** * @brief Pre increment operator. Returns a reference to the changed value. * * @return Reference to the incremented underlying address. */ - auto operator++() -> physical_frame_iterator &; + auto operator++() -> physical_frame &; /** * @brief Addition assignment operator. Returns a reference to the changed value. @@ -117,7 +71,7 @@ namespace teachos::arch::memory::allocator * @param operand Value we want to add to the underlying address. * @return Reference to the changed underlying address. */ - auto operator+=(difference_type operand) -> physical_frame_iterator &; + auto operator+=(std::size_t operand) -> physical_frame &; /** * @brief Subtraction assignment operator. Returns a reference to the changed value. @@ -125,23 +79,21 @@ namespace teachos::arch::memory::allocator * @param operand Value we want to subtract from the underlying address. * @return Reference to the changed underlying address. */ - auto operator-=(difference_type operand) -> physical_frame_iterator &; + auto operator-=(std::size_t operand) -> physical_frame &; /** - * @brief Addition operator. Returns the changed value. + * @brief Post increment operator. Returns a copy of the 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. + * @return Copy of the incremented underlying address. */ - auto operator+(difference_type operand) const -> physical_frame_iterator; + auto operator+(std::size_t operand) const -> physical_frame; /** - * @brief Subtraction operator. Returns the changed value. + * @brief Pre increment operator. Returns a reference to 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. + * @return Reference to the incremented underlying address. */ - auto operator-(difference_type operand) const -> physical_frame_iterator; + auto operator-(std::size_t operand) const -> physical_frame; /** * @brief Subtraction operator. Returns the size difference between two iterators. @@ -149,36 +101,23 @@ namespace teachos::arch::memory::allocator * @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 operator-(const physical_frame_iterator & other) const -> difference_type; - - /** - * @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 operator[](difference_type index) const -> value_type; + auto operator-(physical_frame const & other) const -> std::size_t; /** - * @brief Defaulted comparsion operator. Simply compares the memory address of both iterators. - * - * @param other Other iterator to compare to. - * @return Whether both iterators point to the same underlying address in memory. + * @brief Defaulted equals operator. */ - auto operator==(physical_frame_iterator const & other) const -> bool = default; + auto operator==(physical_frame const & other) const -> bool = default; /** - * @brief Defaulted threeway comparsion operator. Simply compares the memory address of both iterators. - * - * @param other Other iterator to compare to. - * @return Whether the given iterator is smaller or larger than this iterator. + * @brief Defaulted three-way comparsion operator. */ - auto operator<=>(physical_frame_iterator const & other) const -> std::strong_ordering = default; + auto operator<=>(physical_frame const & other) const -> std::partial_ordering = default; - private: - value_type value = {}; ///< Underlying address the iterator is currently pointing too. + std::size_t frame_number = + {}; ///< Index number of the current physical frame, used to distinguish it from other frames. }; + + typedef shared::container<shared::random_access_iterator<physical_frame>> frame_container; } // namespace teachos::arch::memory::allocator #endif // TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_PHYSICAL_FRAME_HPP diff --git a/arch/x86_64/include/arch/memory/multiboot/elf_symbols_section.hpp b/arch/x86_64/include/arch/memory/multiboot/elf_symbols_section.hpp index e29590d..6227fc9 100644 --- a/arch/x86_64/include/arch/memory/multiboot/elf_symbols_section.hpp +++ b/arch/x86_64/include/arch/memory/multiboot/elf_symbols_section.hpp @@ -122,8 +122,8 @@ namespace teachos::arch::memory::multiboot elf_section_flags flags; ///< 1-bit flgas that describe section attributes. uint64_t physical_address; ///< If section appears in memory image of a process, gives address at which the ///< sections first byte should reside, otherwise 0. - uint64_t file_offset; ///< Offset from the beginning of the file to the first byte in the section. SHT_NOBITS - ///< contains the conceptual placement instead (because it occupies no space in the file). + uint64_t file_offset; ///< Offset from the beginning of the file to the first byte in the section. SHT_NOBITS + ///< contains the conceptual placement instead (because it occupies no space in the file). uint64_t section_size; ///< Complete section size in bytes, SHT_NOBITS may have non-zero value but will always ///< occupy no space in the file. uint32_t other_section; ///< Section header table index link, behaviour varies on type @@ -162,7 +162,7 @@ namespace teachos::arch::memory::multiboot ///< contained in the section, to ensure byte alignment is actually 4 byte. }; - typedef shared::container<shared::random_access_iterator<elf_section_header>> elf_section_header_container; + typedef shared::container<shared::random_access_iterator<elf_section_header *>> elf_section_header_container; } // namespace teachos::arch::memory::multiboot #endif // TEACHOS_ARCH_X86_64_MEMORY_MULTIBOOT_ELF_SYBOLS_SECTION_HPP diff --git a/arch/x86_64/include/arch/memory/multiboot/memory_map.hpp b/arch/x86_64/include/arch/memory/multiboot/memory_map.hpp index 910eecb..ccd5cf0 100644 --- a/arch/x86_64/include/arch/memory/multiboot/memory_map.hpp +++ b/arch/x86_64/include/arch/memory/multiboot/memory_map.hpp @@ -46,7 +46,7 @@ namespace teachos::arch::memory::multiboot struct memory_area entries; ///< Specific memory regions. }; - typedef shared::container<shared::random_access_iterator<memory_area>> memory_area_container; + typedef shared::container<shared::random_access_iterator<memory_area *>> memory_area_container; } // namespace teachos::arch::memory::multiboot #endif // TEACHOS_ARCH_X86_64_MEMORY_MULTIBOOT_MEMORY_MAP_HPP 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 2dd0387..d301c91 100644 --- a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp +++ b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp @@ -9,11 +9,9 @@ namespace teachos::arch::memory::paging { namespace { - virtual_page UNUSED_VIRTUAL_PAGE = virtual_page::containing_address(0xCAFEBABE); + virtual_page constexpr UNUSED_VIRTUAL_PAGE(0xCAFEBABE); } // namespace - typedef shared::container<allocator::physical_frame_iterator> frame_container; - /** * @brief Kernel mapper that allows to remap the kernel elf sections in C++. * @@ -103,20 +101,23 @@ namespace teachos::arch::memory::paging exception_handling::assert(!mem_info.sections.empty(), "[Kernel Mapper] Kernel elf sections empty"); for (auto const & section : mem_info.sections) { - if (!section.flags.contains_flags(multiboot::elf_section_flags::OCCUPIES_MEMORY)) + if (!section->flags.contains_flags(multiboot::elf_section_flags::OCCUPIES_MEMORY)) { continue; } - exception_handling::assert(section.physical_address % allocator::PAGE_FRAME_SIZE == 0U, + exception_handling::assert(section->physical_address % allocator::PAGE_FRAME_SIZE == 0U, "[Kernel Mapper] Section must be page aligned"); - auto const start_frame = allocator::physical_frame::containing_address(section.physical_address); - auto const end_frame = - allocator::physical_frame::containing_address(section.physical_address + section.section_size); + auto const start_frame = allocator::physical_frame::containing_address(section->physical_address); + // 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 = + ++(allocator::physical_frame::containing_address(section->physical_address + section->section_size - 1)); - allocator::physical_frame_iterator const begin{start_frame}; - allocator::physical_frame_iterator const end{end_frame}; - frame_container frames{begin, end}; - entry entry{section.flags}; + 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}; for (auto const & frame : frames) { diff --git a/arch/x86_64/include/arch/shared/container.hpp b/arch/x86_64/include/arch/shared/container.hpp index bc2a5f6..9b4192e 100644 --- a/arch/x86_64/include/arch/shared/container.hpp +++ b/arch/x86_64/include/arch/shared/container.hpp @@ -1,12 +1,13 @@ #ifndef TEACHOS_ARCH_X86_64_SHARED_CONTAINER_HPP #define TEACHOS_ARCH_X86_64_SHARED_CONTAINER_HPP -#include "arch/exception_handling/assert.hpp" - #include <iterator> namespace teachos::arch::shared { + template<typename T> + concept Iterator = std::contiguous_iterator<T>; + /** * @brief Read-only container for given template type, that allow to easily use this container instance in C++20 * ranges calls. diff --git a/arch/x86_64/include/arch/shared/random_access_iterator.hpp b/arch/x86_64/include/arch/shared/random_access_iterator.hpp index b1a800c..69617f3 100644 --- a/arch/x86_64/include/arch/shared/random_access_iterator.hpp +++ b/arch/x86_64/include/arch/shared/random_access_iterator.hpp @@ -5,18 +5,25 @@ namespace teachos::arch::shared { + template<typename T> + concept Iterable = std::incrementable<T> && std::three_way_comparable<T> && std::indirectly_readable<T>; + /** - * @brief Generic random access iterator for given template type. Can be a nullptr, ensure to check when using this - * iterator. Allows to easily use this iterator instance in algorithm calls. + * @brief Generic random access iterator for given template type. Allows any value that Allows to easily use this + * iterator instance in algorithm calls. * * @tparam T Value the iterator points too. */ - template<typename T> + template<Iterable T> struct random_access_iterator { - using iterator_category = std::random_access_iterator_tag; ///< Iterator category of this type. - using difference_type = std::ptrdiff_t; ///< Type when diving one instance of this iterator by another. - using value_type = T; ///< Underlying value pointed to by this iterator. + using iterator_category = std::contiguous_iterator_tag; ///< Iterator category of this type. + using difference_type = std::ptrdiff_t; ///< Type when diving one instance of this iterator by another. + using value_type = T; ///< Underlying value pointed to by this iterator. + using reference_type = value_type &; ///< Reference to value returned by dereference * operation. + using pointer_type = value_type *; ///< Pointer to value returned by arrow -> operation. + using const_reference_type = value_type const &; ///< Reference to value returned by const dereference * operation. + using const_pointer_type = value_type const *; ///< Pointer to value returned by const arrow -> operation. /** * @brief Defaulted constructor. @@ -26,124 +33,162 @@ namespace teachos::arch::shared /** * @brief Constructor. * - * @param p Underlying address the iterator should point too. + * @param value Underlying value the iterator should point too and increment or decrement. */ - explicit random_access_iterator(value_type * p) - : ptr(p) + explicit random_access_iterator(value_type value) + : value(value) { // Nothing to do } /** - * @brief Dereferences the initally given pointer to its value. + * @brief Gets a reference to the underlying value. * * @return Reference to the value. */ - auto operator*() const -> value_type & { return *ptr; } + auto operator*() -> reference_type { return value; } /** - * @brief Get underlying value, which is the intially passed pointer. + * @brief Gets a pointer to the underlying value. * * @return Underlying value passed intially. */ - auto operator->() const -> value_type * { return ptr; } + auto operator->() -> pointer_type { return &value; } /** - * @brief Post increment operator. Returns a copy of the value. + * @brief Gets a const reference to the underlying value. * - * @return Copy of the incremented underlying address. + * @return Reference to the value. */ - auto operator++(int) -> random_access_iterator + auto operator*() const -> const_reference_type { return value; } + + /** + * @brief Gets a const pointer to the underlying value. + * + * @return Underlying value passed intially. + */ + auto operator->() const -> const_pointer_type { return &value; } + + /** + * @brief Pre decrement operator. Returns a reference to the changed value. + * + * @return Reference to the decrement underlying value. + */ + auto operator--() -> random_access_iterator & { - random_access_iterator const old_value = *this; - ++ptr; - return old_value; + --value; + return *this; } /** * @brief Pre increment operator. Returns a reference to the changed value. * - * @return Reference to the incremented underlying address. + * @return Reference to the incremented underlying value. */ auto operator++() -> random_access_iterator & { - ++ptr; + ++value; return *this; } /** + * @brief Post decrement operator. Returns a copy of the value. + * + * @return Copy of the decremented underlying value. + */ + auto operator--(int) -> random_access_iterator + { + auto const old_value = *this; + --value; + return old_value; + } + + /** + * @brief Post increment operator. Returns a copy of the value. + * + * @return Copy of the incremented underlying value. + */ + auto operator++(int) -> random_access_iterator + { + auto const old_value = *this; + ++value; + return old_value; + } + + /** * @brief Addition assignment operator. Returns a reference to the changed value. * - * @param value Value we want to add to the underlying address. - * @return Reference to the changed underlying address. + * @param operand Value we want to add to the underlying value the iterator is pointing too. + * @return Reference to the changed underlying value. */ - auto operator+=(difference_type value) -> random_access_iterator & + auto operator+=(difference_type operand) -> random_access_iterator & { - ptr += value; + value += operand; return *this; } /** * @brief Subtraction assignment operator. Returns a reference to the changed value. * - * @param value Value we want to subtract from the underlying address. - * @return Reference to the changed underlying address. + * @param operand Value we want to subtract from the underlying value the iterator is pointing too. + * @return Reference to the changed underlying value. */ - auto operator-=(difference_type value) -> random_access_iterator & + auto operator-=(difference_type operand) -> random_access_iterator & { - ptr -= value; + value -= operand; return *this; } /** * @brief Addition operator. Returns the changed value. * - * @param value Value we want to add to a copy of the underlying address. - * @return Copy of underlying address incremented by the given value. + * @param operand Value we want to add to a copy of the underlying value the iterator is pointing too. + * @return Copy of underlying value incremented by the given value. */ - auto operator+(difference_type value) const -> random_access_iterator + auto operator+(difference_type operand) const -> random_access_iterator { - return random_access_iterator{ptr + value}; + return random_access_iterator{value + operand}; } /** * @brief Subtraction operator. Returns the changed value. * - * @param value Value we want to subtrcat from a copy of the underlying address. - * @return Copy of underlying address decremented by the given value. + * @param operand Value we want to subtract from a copy of the underlying value the iterator is pointing too. + * @return Copy of underlying value decremented by the given value. */ - auto operator-(difference_type value) const -> random_access_iterator + auto operator-(difference_type operand) const -> random_access_iterator { - return random_access_iterator{ptr - value}; + return random_access_iterator{value - 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. + * @param other Other iterator we want to substract the underlying value with ours. + * @return Size difference between the underlying value of this instance and the given iterator. */ - auto operator-(const random_access_iterator & other) const -> difference_type { return ptr - other.ptr; } + auto operator-(random_access_iterator const & other) const -> difference_type { return value - other.value; } /** * @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. + * underlying value the iterator is pointing too 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 operator[](difference_type index) const -> value_type & { return *(ptr + index); } + auto operator[](difference_type index) const -> value_type const & { return value + index; } /** - * @brief Defaulted comparsion operator. Simply compares the memory address of both iterators. + * @brief Defaulted comparsion operator. Forwards to the comparsion operator of the given template type. * * @param other Other iterator to compare to. - * @return Whether both iterators point to the same underlying address in memory. + * @return Whether both iterators point to the same underlying value in memory. */ auto operator==(random_access_iterator const & other) const -> bool = default; /** - * @brief Defaulted threeway comparsion operator. Simply compares the memory address of both iterators. + * @brief Defaulted threeway comparsion operator. Forwards to the threeway comparsion operator of the given + * template type. * * @param other Other iterator to compare to. * @return Whether the given iterator is smaller or larger than this iterator. @@ -151,7 +196,8 @@ namespace teachos::arch::shared auto operator<=>(random_access_iterator const & other) const -> std::strong_ordering = default; private: - value_type * ptr = {}; ///< Underlying address the iterator is currently pointing too. + value_type value = + {}; ///< Underlying value the iterator is currently pointing too and should increment or decrement. }; } // namespace teachos::arch::shared 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; } |
