aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch/x86_64/include/arch/memory/allocator/physical_frame.hpp4
-rw-r--r--arch/x86_64/include/arch/memory/paging/virtual_page.hpp23
-rw-r--r--arch/x86_64/src/memory/main.cpp16
-rw-r--r--arch/x86_64/src/memory/paging/virtual_page.cpp13
4 files changed, 47 insertions, 9 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 a39517a..d5e2f4c 100644
--- a/arch/x86_64/include/arch/memory/allocator/physical_frame.hpp
+++ b/arch/x86_64/include/arch/memory/allocator/physical_frame.hpp
@@ -54,14 +54,14 @@ namespace teachos::arch::memory::allocator
/**
* @brief Post increment operator. Returns a copy of the value.
*
- * @return Copy of the incremented underlying address.
+ * @return Copy of the incremented underlying frame number.
*/
auto operator++(int) -> physical_frame;
/**
* @brief Pre increment operator. Returns a reference to the changed value.
*
- * @return Reference to the incremented underlying address.
+ * @return Reference to the incremented underlying frame number.
*/
auto operator++() -> physical_frame &;
diff --git a/arch/x86_64/include/arch/memory/paging/virtual_page.hpp b/arch/x86_64/include/arch/memory/paging/virtual_page.hpp
index c319af2..0ee9cbd 100644
--- a/arch/x86_64/include/arch/memory/paging/virtual_page.hpp
+++ b/arch/x86_64/include/arch/memory/paging/virtual_page.hpp
@@ -18,6 +18,11 @@ namespace teachos::arch::memory::paging
struct virtual_page
{
/**
+ * @brief Defaulted constructor.
+ */
+ constexpr virtual_page() = default;
+
+ /**
* @brief Constructor.
*
* @param page_number Index number of the current virtual page, used to distinguish it from other pages.
@@ -52,6 +57,20 @@ namespace teachos::arch::memory::paging
auto get_level_index(page_table_handle::level level) const -> size_t;
/**
+ * @brief Post increment operator. Returns a copy of the value.
+ *
+ * @return Copy of the incremented underlying page number.
+ */
+ auto operator++(int) -> virtual_page;
+
+ /**
+ * @brief Pre increment operator. Returns a reference to the changed value.
+ *
+ * @return Reference to the incremented underlying page number.
+ */
+ auto operator++() -> virtual_page &;
+
+ /**
* @brief Defaulted equals operator.
*/
auto operator==(const virtual_page & other) const -> bool = default;
@@ -61,9 +80,11 @@ namespace teachos::arch::memory::paging
*/
auto operator<=>(const virtual_page & other) const -> std::partial_ordering = default;
- std::size_t page_number; ///< Index number of the current virtual page, used to distinguish it from other pages.
+ std::size_t page_number =
+ {}; ///< Index number of the current virtual page, used to distinguish it from other pages.
};
+ typedef shared::container<shared::forward_value_iterator<virtual_page>> page_container;
} // namespace teachos::arch::memory::paging
#endif // TEACHOS_ARCH_X86_64_MEMORY_PAGING_VIRTUAL_PAGE_HPP
diff --git a/arch/x86_64/src/memory/main.cpp b/arch/x86_64/src/memory/main.cpp
index ce07115..80242cc 100644
--- a/arch/x86_64/src/memory/main.cpp
+++ b/arch/x86_64/src/memory/main.cpp
@@ -14,13 +14,16 @@ namespace teachos::arch::memory
{
auto remap_heap(allocator::area_frame_allocator allocator, paging::active_page_table & active_table) -> void
{
- auto heap_start_page = paging::virtual_page::containing_address(memory::heap::HEAP_START);
- auto heap_end_page =
- paging::virtual_page::containing_address(memory::heap::HEAP_START + memory::heap::HEAP_SIZE - 1);
-
- for (auto i = heap_start_page.page_number; i <= heap_end_page.page_number; i++)
+ auto const start_page = paging::virtual_page::containing_address(memory::heap::HEAP_START);
+ auto const end_page =
+ ++(paging::virtual_page::containing_address(memory::heap::HEAP_START + memory::heap::HEAP_SIZE - 1));
+ paging::page_container::iterator const begin{start_page};
+ paging::page_container::iterator const end{end_page};
+ paging::page_container const pages{begin, end};
+
+ for (auto const & page : pages)
{
- active_table.map_page_to_next_free_frame(allocator, paging::virtual_page{i}, paging::entry::WRITABLE);
+ active_table.map_page_to_next_free_frame(allocator, page, paging::entry::WRITABLE);
}
}
} // namespace
@@ -43,5 +46,6 @@ namespace teachos::arch::memory
video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black);
remap_heap(allocator, active_table);
+ video::vga::text::write("Heap remapping successfull", video::vga::text::common_attributes::green_on_black);
}
} // namespace teachos::arch::memory \ No newline at end of file
diff --git a/arch/x86_64/src/memory/paging/virtual_page.cpp b/arch/x86_64/src/memory/paging/virtual_page.cpp
index f798709..d374156 100644
--- a/arch/x86_64/src/memory/paging/virtual_page.cpp
+++ b/arch/x86_64/src/memory/paging/virtual_page.cpp
@@ -17,4 +17,17 @@ namespace teachos::arch::memory::paging
{
return (page_number >> (level * 9U)) & 0x1FF;
}
+
+ auto virtual_page::operator++(int) -> virtual_page
+ {
+ virtual_page const old_value = *this;
+ ++page_number;
+ return old_value;
+ }
+
+ auto virtual_page::operator++() -> virtual_page &
+ {
+ ++page_number;
+ return *this;
+ }
} // namespace teachos::arch::memory::paging