aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2024-11-01 12:56:22 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2024-11-01 12:56:22 +0000
commitdefb727b2d0ac902e10e9736440779495b8b51a9 (patch)
tree9a3e0992a227eaa6624e69c858a0c18421dae32d /arch/x86_64/src
parent1154d641797e8bb51814fad2a618e9e30c3d0685 (diff)
downloadteachos-defb727b2d0ac902e10e9736440779495b8b51a9.tar.xz
teachos-defb727b2d0ac902e10e9736440779495b8b51a9.zip
Move methods into seperate class.
Diffstat (limited to 'arch/x86_64/src')
-rw-r--r--arch/x86_64/src/memory/paging/page_mapper.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/arch/x86_64/src/memory/paging/page_mapper.cpp b/arch/x86_64/src/memory/paging/page_mapper.cpp
index 2f2ee6a..30055e8 100644
--- a/arch/x86_64/src/memory/paging/page_mapper.cpp
+++ b/arch/x86_64/src/memory/paging/page_mapper.cpp
@@ -7,14 +7,15 @@ namespace teachos::arch::memory::paging
std::size_t constexpr PAGE_TABLE_LEVEL_4_ADDRESS = 0xffffffff'fffff000;
} // namespace
- auto create_or_get() -> page_table_handle
+ auto active_page_table::create_or_get() -> active_page_table &
{
static page_table_handle active_handle{reinterpret_cast<page_table *>(PAGE_TABLE_LEVEL_4_ADDRESS),
page_table_handle::LEVEL4};
- return active_handle;
+ static active_page_table active_page{active_handle};
+ return active_page;
}
- auto translate_address(virtual_address address) -> std::optional<allocator::physical_address>
+ auto active_page_table::translate_address(virtual_address address) -> std::optional<allocator::physical_address>
{
auto const offset = address % allocator::PAGE_FRAME_SIZE;
auto const page = virtual_page::containing_address(address);
@@ -28,9 +29,9 @@ namespace teachos::arch::memory::paging
return std::nullopt;
}
- auto translate_page(virtual_page page) -> std::optional<allocator::physical_frame>
+ auto active_page_table::translate_page(virtual_page page) -> std::optional<allocator::physical_frame>
{
- auto current_handle = create_or_get();
+ auto current_handle = active_handle;
for (auto level = page_table_handle::LEVEL4; level != page_table_handle::LEVEL1; --level)
{
@@ -49,9 +50,9 @@ namespace teachos::arch::memory::paging
return level1_entry.calculate_pointed_to_frame();
}
- auto translate_huge_page(virtual_page page) -> std::optional<allocator::physical_frame>
+ auto active_page_table::translate_huge_page(virtual_page page) -> std::optional<allocator::physical_frame>
{
- auto current_handle = create_or_get();
+ auto current_handle = active_handle;
auto level3_handle = current_handle.next_table(page.get_level_index(page_table_handle::LEVEL4));
if (!level3_handle.has_value())
@@ -86,4 +87,10 @@ namespace teachos::arch::memory::paging
}
return std::nullopt;
}
+
+ active_page_table::active_page_table(page_table_handle active_handle)
+ : active_handle(active_handle)
+ {
+ // Nothing to do
+ }
} // namespace teachos::arch::memory::paging