aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/memory/allocator
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/src/memory/allocator')
-rw-r--r--arch/x86_64/src/memory/allocator/area_frame_allocator.cpp12
-rw-r--r--arch/x86_64/src/memory/allocator/physical_frame.cpp113
2 files changed, 20 insertions, 105 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