aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/memory
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/src/memory')
-rw-r--r--arch/x86_64/src/memory/paging/page_table.cpp24
-rw-r--r--arch/x86_64/src/memory/paging/temporary_page.cpp35
2 files changed, 47 insertions, 12 deletions
diff --git a/arch/x86_64/src/memory/paging/page_table.cpp b/arch/x86_64/src/memory/paging/page_table.cpp
index 3ad1d54..3c9942a 100644
--- a/arch/x86_64/src/memory/paging/page_table.cpp
+++ b/arch/x86_64/src/memory/paging/page_table.cpp
@@ -88,33 +88,33 @@ namespace teachos::arch::memory::paging
return std::nullopt;
}
- page_table_handle::page_table_handle(page_table * handle, page_table_handle::level handle_level)
- : handle(handle)
- , handle_level(handle_level)
+ page_table_handle::page_table_handle(page_table * table, page_table_handle::level table_level)
+ : table(table)
+ , table_level(table_level)
{
- exception_handling::assert(handle != nullptr,
- "[Page Table] Attempted to pass nullptr as handle to page table handle method");
+ exception_handling::assert(table != nullptr,
+ "[Page Table] Attempted to pass nullptr as table to page table table method");
}
- auto page_table_handle::zero_entries() -> void { handle->zero_entries(); }
+ auto page_table_handle::zero_entries() -> void { table->zero_entries(); }
- auto page_table_handle::is_empty() const -> bool { return handle->is_empty(); }
+ auto page_table_handle::is_empty() const -> bool { return table->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,
+ exception_handling::assert(table_level != page_table_handle::LEVEL1,
"[Page Table] Attempted to call next_table on level 1 page table");
- auto const next_table = handle->next_table(table_index);
+ auto const next_table = table->next_table(table_index);
if (next_table.has_value())
{
- return page_table_handle{next_table.value(), --handle_level};
+ return page_table_handle{next_table.value(), --table_level};
}
return std::nullopt;
}
- auto page_table_handle::get_level() const -> page_table_handle::level { return handle_level; }
+ auto page_table_handle::get_level() const -> page_table_handle::level { return table_level; }
- auto page_table_handle::operator[](std::size_t index) -> entry & { return handle->operator[](index); }
+ auto page_table_handle::operator[](std::size_t index) -> entry & { return table->operator[](index); }
auto operator--(page_table_handle::level & value) -> page_table_handle::level &
{
diff --git a/arch/x86_64/src/memory/paging/temporary_page.cpp b/arch/x86_64/src/memory/paging/temporary_page.cpp
new file mode 100644
index 0000000..433f0ce
--- /dev/null
+++ b/arch/x86_64/src/memory/paging/temporary_page.cpp
@@ -0,0 +1,35 @@
+#include "arch/memory/paging/temporary_page.hpp"
+
+#include "arch/memory/paging/page_entry.hpp"
+#include "arch/memory/paging/page_mapper.hpp"
+
+namespace teachos::arch::memory::paging
+{
+ auto temporary_page::map_to_frame(allocator::physical_frame frame) -> virtual_address
+ {
+ exception_handling::assert(!translate_page(page).has_value(), "[Temporary page] Page is already mapped");
+
+ map_page_to_frame(allocator, page, frame, entry::WRITABLE);
+ return page.start_address();
+ }
+
+ auto temporary_page::unmap() -> void { unmap_page(allocator, page); }
+
+ auto temporary_page::map_table_frame(allocator::physical_frame frame) -> page_table_handle
+ {
+ page_table_handle handle{reinterpret_cast<page_table *>(map_to_frame(frame)), page_table_handle::LEVEL1};
+ return handle;
+ }
+
+ auto temporary_page::zero_entries() -> void
+ {
+ auto frame = allocator.allocate_frame();
+ exception_handling::assert(!frame.has_value(), "[Temporary Page] Tiny allocator could not allocate a frame");
+
+ page_table_handle handle = map_table_frame(frame.value());
+ handle.zero_entries();
+ handle[511].set_entry(frame.value(), entry::PRESENT | entry::WRITABLE);
+
+ unmap();
+ }
+} // namespace teachos::arch::memory::paging \ No newline at end of file