aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/memory/paging
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-20 12:02:20 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-20 12:02:20 +0000
commitda2341ec12128d3b4983a67d39aeaf76b1781fa8 (patch)
treeeab408f61804267fabb7151edce4410b0f05ddc2 /arch/x86_64/src/memory/paging
parent0d42fed17834a21d29032dd2d8e56e11596056bc (diff)
downloadteachos-da2341ec12128d3b4983a67d39aeaf76b1781fa8.tar.xz
teachos-da2341ec12128d3b4983a67d39aeaf76b1781fa8.zip
Add printf like behaviour to assert
Diffstat (limited to 'arch/x86_64/src/memory/paging')
-rw-r--r--arch/x86_64/src/memory/paging/page_entry.cpp2
-rw-r--r--arch/x86_64/src/memory/paging/page_mapper.cpp24
-rw-r--r--arch/x86_64/src/memory/paging/page_table.cpp2
3 files changed, 13 insertions, 15 deletions
diff --git a/arch/x86_64/src/memory/paging/page_entry.cpp b/arch/x86_64/src/memory/paging/page_entry.cpp
index 0dbbae1..30a8961 100644
--- a/arch/x86_64/src/memory/paging/page_entry.cpp
+++ b/arch/x86_64/src/memory/paging/page_entry.cpp
@@ -36,7 +36,7 @@ namespace teachos::arch::memory::paging
auto entry::set_entry(allocator::physical_frame frame, std::bitset<64U> additional_flags) -> void
{
exception_handling::assert((frame.start_address() & ~0x000fffff'fffff000) == 0,
- "Start address is not aligned with Page");
+ "[Paging Entry] Start address is not aligned with page");
flags = std::bitset<64U>(frame.start_address()) | additional_flags;
}
} // namespace teachos::arch::memory::paging
diff --git a/arch/x86_64/src/memory/paging/page_mapper.cpp b/arch/x86_64/src/memory/paging/page_mapper.cpp
index eb1e18c..8c64f22 100644
--- a/arch/x86_64/src/memory/paging/page_mapper.cpp
+++ b/arch/x86_64/src/memory/paging/page_mapper.cpp
@@ -81,28 +81,26 @@ namespace teachos::arch::memory::paging
allocator::physical_frame const & frame, entry::bitset flags) -> void
{
page_table page_table{};
- bool is_valid = false;
+ bool table_exists = false;
for (auto level = page_table::LEVEL4; level != page_table::LEVEL1; level--)
{
std::size_t level_index = page.get_level_index(level);
- is_valid = page_table.next_table(level_index);
+ table_exists = page_table.next_table(level_index);
- if (!is_valid)
+ if (!table_exists)
{
- break;
+ auto allocated_frame = allocator.allocate_frame();
+ exception_handling::assert(!allocated_frame.has_value(), "[Page mapper]: Unable to allocate frame");
+ page_table[level_index].set_entry(allocated_frame.value(), entry::PRESENT | entry::WRITABLE);
+ page_table.zero_entries();
}
-
- auto allocated_frame = allocator.allocate_frame();
- exception_handling::assert(!allocated_frame.has_value(), "[Page mapper]: Unable to allocate frame");
- page_table[level_index].set_entry(allocated_frame.value(), entry::PRESENT | entry::WRITABLE);
- page_table.zero_entries();
}
- entry page_table_entry = page_table[page.get_level_index(page_table::LEVEL1)];
- arch::exception_handling::assert(!page_table_entry.contains_flags(entry::HUGE_PAGE),
+ auto level1_entry = page_table[page.get_level_index(page_table::LEVEL1)];
+ arch::exception_handling::assert(!level1_entry.contains_flags(entry::HUGE_PAGE),
"[Page Mapper]: Unable to map huge pages");
- arch::exception_handling::assert(!page_table_entry.is_unused(), "[Page Mapper]: Page table entry is already used");
- page_table_entry.set_entry(frame, flags | entry::PRESENT);
+ arch::exception_handling::assert(!level1_entry.is_unused(), "[Page Mapper]: Page table entry is already used");
+ level1_entry.set_entry(frame, flags | entry::PRESENT);
}
} // namespace teachos::arch::memory::paging \ No newline at end of file
diff --git a/arch/x86_64/src/memory/paging/page_table.cpp b/arch/x86_64/src/memory/paging/page_table.cpp
index 02ababe..ea2e9c2 100644
--- a/arch/x86_64/src/memory/paging/page_table.cpp
+++ b/arch/x86_64/src/memory/paging/page_table.cpp
@@ -39,7 +39,7 @@ namespace teachos::arch::memory::paging
{
// 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");
+ exception_handling::assert(index < PAGE_TABLE_ENTRY_COUNT, "[Page Table] Index out of bounds");
return current_table->entries[index];
}