aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64')
-rw-r--r--arch/x86_64/include/arch/memory/paging/page_mapper.hpp2
-rw-r--r--arch/x86_64/include/arch/memory/paging/page_table.hpp15
-rw-r--r--arch/x86_64/src/memory/allocator/area_frame_allocator.cpp9
-rw-r--r--arch/x86_64/src/memory/paging/page_table.cpp55
4 files changed, 41 insertions, 40 deletions
diff --git a/arch/x86_64/include/arch/memory/paging/page_mapper.hpp b/arch/x86_64/include/arch/memory/paging/page_mapper.hpp
index d852fbc..6a0c989 100644
--- a/arch/x86_64/include/arch/memory/paging/page_mapper.hpp
+++ b/arch/x86_64/include/arch/memory/paging/page_mapper.hpp
@@ -146,10 +146,10 @@ namespace teachos::arch::memory::paging
exception_handling::assert(level1_frame.has_value(),
"[Page Mapper] Attempted to unmap page, which has not been mapped previously");
level1_entry.set_unused();
- invalidate_page_cache(&level1_entry);
// TODO: Deallocate and unmap level 1, 2, 3 page table entry if this was the last page in them.
// TODO: Fix deallocate because it is not yet implemented.
allocator.deallocate_frame(level1_frame.value());
+ invalidate_page_cache(&level1_entry);
}
} // namespace teachos::arch::memory::paging
diff --git a/arch/x86_64/include/arch/memory/paging/page_table.hpp b/arch/x86_64/include/arch/memory/paging/page_table.hpp
index e4847e3..07e7e22 100644
--- a/arch/x86_64/include/arch/memory/paging/page_table.hpp
+++ b/arch/x86_64/include/arch/memory/paging/page_table.hpp
@@ -57,6 +57,11 @@ namespace teachos::arch::memory::paging
auto zero_entries() -> void;
/**
+ * @brief Checks if all entries of this page are unused.
+ */
+ auto is_empty() const -> bool;
+
+ /**
* @brief Returns the next page table level from the given page table index. Meaning we
* use an index into a Level 4 page table to get the according Level 3 page table.
*
@@ -97,7 +102,7 @@ namespace teachos::arch::memory::paging
}
/**
- * @brief Index operator overload to access specific immutable entry directy.
+ * @brief Index operator overload to access specific mutable entry directy.
*
* @param index Index of the entry we want to access and only read.
* @return Entry at the given table index.
@@ -105,6 +110,14 @@ namespace teachos::arch::memory::paging
auto operator[](std::size_t index) -> entry &;
/**
+ * @brief Index operator overload to access specific immutable entry directy.
+ *
+ * @param index Index of the entry we want to access and read or write.
+ * @return Entry at the given table index.
+ */
+ auto operator[](std::size_t index) const -> entry const &;
+
+ /**
* @brief Decrements the page table handle level enum by one, is defined so we can use it as a replacement for an
* int index in a range based for loop.
*
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 fecc6cd..e79cd8b 100644
--- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp
+++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp
@@ -85,11 +85,8 @@ namespace teachos::arch::memory::allocator
auto area_frame_allocator::deallocate_frame(physical_frame physical_frame) -> void
{
- // TODO: Implement deallocation to make unmap actually work.
- if (physical_frame.frame_number == 0)
- {
- }
- /*exception_handling::assert(false && physical_frame.frame_number == 0,
- "[deallocate_frame] Not implemented Exception");*/
+ // TODO: Fix create acutal deallocation of frames if it is even possible. Can the area frame allocator even
+ // deallocate in the first place?
+ next_free_frame = physical_frame;
}
} // namespace teachos::arch::memory::allocator
diff --git a/arch/x86_64/src/memory/paging/page_table.cpp b/arch/x86_64/src/memory/paging/page_table.cpp
index a01c431..64a4fd9 100644
--- a/arch/x86_64/src/memory/paging/page_table.cpp
+++ b/arch/x86_64/src/memory/paging/page_table.cpp
@@ -1,5 +1,6 @@
#include "arch/memory/paging/page_table.hpp"
+#include <algorithm>
#include <array>
#include <memory>
@@ -16,31 +17,16 @@ namespace teachos::arch::memory::paging
*/
struct page_table
{
- /**
- * @brief Set every entry of the page to unused.
- */
auto zero_entries() -> void;
- /**
- * @brief Returns the next page table level from the given page table index. Meaning we use an index into a Level 4
- * page table to get the according Level 3 page table.
- *
- * @note This method
- * should not be called on a Level 1 page table, because there is no furthere page table and mangeling up and
- * returning the physical address would cause hard to debug issues.
- *
- * @param table_index Index of this page table in the page table one level lower.
- */
- auto next_table(std::size_t table_index) -> std::optional<page_table *>;
+ auto is_empty() const -> bool;
+
+ auto next_table(std::size_t table_index) const -> std::optional<page_table *>;
- /**
- * @brief Index operator overload to access specific entries directy.
- *
- * @param index Index of the entry we want to access and read or write too.
- * @return Entry at the given table index.
- */
auto operator[](std::size_t index) -> entry &;
+ auto operator[](std::size_t index) const -> entry const &;
+
private:
/**
* @brief Calculates the address of the next page table level for the given table index.
@@ -51,7 +37,7 @@ namespace teachos::arch::memory::paging
* @param table_index Index of this page table in the page table one level higher.
* @return An optional of the address of the next page table or null.
*/
- auto next_table_address(std::size_t table_index) -> std::optional<std::size_t>;
+ auto next_table_address(std::size_t table_index) const -> std::optional<std::size_t>;
std::array<entry, PAGE_TABLE_ENTRY_COUNT> entries =
{}; ///< Entries containing addresses to page tables of a level below or
@@ -60,16 +46,15 @@ namespace teachos::arch::memory::paging
auto page_table::zero_entries() -> void
{
- std::size_t constexpr entry_amount = sizeof(entries) / sizeof(entries[0]);
- static_assert(entry_amount == PAGE_TABLE_ENTRY_COUNT);
- for (std::size_t i = 0; i < entry_amount; ++i)
- {
- auto entry = this->operator[](i);
- entry.set_unused();
- }
+ std::ranges::for_each(entries, [](entry & entry) { entry.set_unused(); });
+ }
+
+ auto page_table::is_empty() const -> bool
+ {
+ return std::all_of(entries.begin(), entries.end(), [](entry const & entry) { return entry.is_unused(); });
}
- auto page_table::next_table(std::size_t table_index) -> std::optional<page_table *>
+ auto page_table::next_table(std::size_t table_index) const -> std::optional<page_table *>
{
auto const address = next_table_address(table_index);
if (address.has_value())
@@ -81,13 +66,17 @@ namespace teachos::arch::memory::paging
auto page_table::operator[](std::size_t index) -> entry &
{
- // C array is not bounds checked, therefore we have to check ourselves, to ensure no out of bounds reads, which
- // could be incredibly hard to debug later.
exception_handling::assert(index < PAGE_TABLE_ENTRY_COUNT, "[Page Table] Index out of bounds");
return entries[index];
}
- auto page_table::next_table_address(std::size_t table_index) -> std::optional<std::size_t>
+ auto page_table::operator[](std::size_t index) const -> entry const &
+ {
+ exception_handling::assert(index < PAGE_TABLE_ENTRY_COUNT, "[Page Table] Index out of bounds");
+ return entries[index];
+ }
+
+ auto page_table::next_table_address(std::size_t table_index) const -> std::optional<std::size_t>
{
auto const entry = this->operator[](table_index);
@@ -130,6 +119,8 @@ namespace teachos::arch::memory::paging
auto page_table_handle::zero_entries() -> void { handle->zero_entries(); }
+ auto page_table_handle::is_empty() const -> bool { return handle->is_empty(); }
+
auto page_table_handle::next_table(std::size_t table_index) -> std::optional<page_table_handle>
{
exception_handling::assert(handle_level != page_table_handle::LEVEL1,