aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/memory/paging
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/src/memory/paging')
-rw-r--r--arch/x86_64/src/memory/paging/page_entry.cpp4
-rw-r--r--arch/x86_64/src/memory/paging/page_table.cpp6
-rw-r--r--arch/x86_64/src/memory/paging/virtual_page.cpp22
3 files changed, 27 insertions, 5 deletions
diff --git a/arch/x86_64/src/memory/paging/page_entry.cpp b/arch/x86_64/src/memory/paging/page_entry.cpp
index 43c0b71..692f8ae 100644
--- a/arch/x86_64/src/memory/paging/page_entry.cpp
+++ b/arch/x86_64/src/memory/paging/page_entry.cpp
@@ -35,8 +35,8 @@ namespace teachos::arch::memory::paging
auto entry::set_address(allocator::physical_frame frame) -> void
{
- arch::exception_handling::assert((frame.start_address() & ~0x000fffff'fffff000) == 0,
- "Start address is not aligned with Page");
+ exception_handling::assert((frame.start_address() & ~0x000fffff'fffff000) == 0,
+ "Start address is not aligned with Page");
flags = std::bitset<64U>(frame.start_address()) | flags;
}
} // namespace teachos::arch::memory::paging
diff --git a/arch/x86_64/src/memory/paging/page_table.cpp b/arch/x86_64/src/memory/paging/page_table.cpp
index 786ff69..8345161 100644
--- a/arch/x86_64/src/memory/paging/page_table.cpp
+++ b/arch/x86_64/src/memory/paging/page_table.cpp
@@ -23,8 +23,8 @@ namespace teachos::arch::memory::paging
auto page_table::next_table(std::size_t table_index) -> void
{
- arch::exception_handling::assert(current_level != LEVEL1,
- "[Page Table] Attempted to call next_table on level 1 page table");
+ exception_handling::assert(current_level != LEVEL1,
+ "[Page Table] Attempted to call next_table on level 1 page table");
auto address = next_table_address(table_index);
if (address.has_value())
@@ -38,7 +38,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.
- arch::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];
}
diff --git a/arch/x86_64/src/memory/paging/virtual_page.cpp b/arch/x86_64/src/memory/paging/virtual_page.cpp
new file mode 100644
index 0000000..3fb6caf
--- /dev/null
+++ b/arch/x86_64/src/memory/paging/virtual_page.cpp
@@ -0,0 +1,22 @@
+#include "arch/memory/paging/virtual_page.hpp"
+
+#include "arch/exception_handling/assert.hpp"
+#include "arch/memory/allocator/physical_frame.hpp"
+
+namespace teachos::arch::memory::paging
+{
+ virtual_page::virtual_page(std::size_t page_number)
+ : page_number(page_number)
+ {
+ // Nothing to do
+ }
+
+ auto virtual_page::containing_address(std::size_t virtual_address) -> virtual_page
+ {
+ exception_handling::assert(virtual_address < 0x0000800000000000 || virtual_address >= 0xffff800000000000,
+ "[Virtual Page] Attempted to create virtual page from invalid address");
+ return virtual_page{virtual_address / allocator::PAGE_FRAME_SIZE};
+ }
+
+ auto virtual_page::start_address() const -> uint64_t { return page_number * allocator::PAGE_FRAME_SIZE; }
+} // namespace teachos::arch::memory::paging