aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src
diff options
context:
space:
mode:
authorFabian Imhof <fabian.imhof@ost.ch>2024-10-26 08:47:26 +0000
committerFabian Imhof <fabian.imhof@ost.ch>2024-10-26 08:47:26 +0000
commitbca36b0c10fcae447c90e211e83987fea28eecdc (patch)
tree3fa0395bbe35bcba5462a94d8ff63e3abd8d8246 /arch/x86_64/src
parent886c5e5ce7d1e6dd80d3782d5cf66bf474a6cddb (diff)
downloadteachos-bca36b0c10fcae447c90e211e83987fea28eecdc.tar.xz
teachos-bca36b0c10fcae447c90e211e83987fea28eecdc.zip
wip
Diffstat (limited to 'arch/x86_64/src')
-rw-r--r--arch/x86_64/src/boot/boot.s16
-rw-r--r--arch/x86_64/src/memory/paging/page_mapper.cpp12
-rw-r--r--arch/x86_64/src/memory/paging/page_table.cpp15
3 files changed, 28 insertions, 15 deletions
diff --git a/arch/x86_64/src/boot/boot.s b/arch/x86_64/src/boot/boot.s
index 7d6b322..6ed1e0a 100644
--- a/arch/x86_64/src/boot/boot.s
+++ b/arch/x86_64/src/boot/boot.s
@@ -24,11 +24,11 @@
.global page_map_level_4
page_map_level_4: .skip 512 * 8
-.global page_map_level_3_low
-page_map_level_3_low: .skip 512 * 8
+.global page_map_level_3
+page_map_level_3: .skip 512 * 8
-.global page_map_level_2_low
-page_map_level_2_low: .skip 512 * 8
+.global page_map_level_2
+page_map_level_2: .skip 512 * 8
/**
* Reserve some space for the Multiboot 2 information pointer.
@@ -318,14 +318,14 @@ enable_sse:
*/
prepare_page_maps:
/* Add an entry to the PML4, pointing to the low PML3 */
- mov $page_map_level_3_low, %eax
+ mov $page_map_level_3, %eax
or $0x3, %eax
mov %eax, (page_map_level_4 + ((0x0000000000100000 >> 39) & 0x1ff) * 8)
/* Add an entry to the low PML3, pointing to the low PML2 */
- mov $page_map_level_2_low, %eax
+ mov $page_map_level_2, %eax
or $0x3, %eax
- mov %eax, (page_map_level_3_low + ((0x0000000000100000 >> 30) & 0x1ff) * 8)
+ mov %eax, (page_map_level_3 + ((0x0000000000100000 >> 30) & 0x1ff) * 8)
xor %ecx, %ecx
@@ -337,7 +337,7 @@ prepare_page_maps:
mov $(1 << 21), %eax
mul %ecx
or $((1 << 0) | (1 << 1) | (1 << 7)), %eax
- mov %eax, page_map_level_2_low(,%ecx,8)
+ mov %eax, page_map_level_2(,%ecx,8)
inc %ecx
cmp %esi, %ecx
diff --git a/arch/x86_64/src/memory/paging/page_mapper.cpp b/arch/x86_64/src/memory/paging/page_mapper.cpp
index cd77366..dff9ae4 100644
--- a/arch/x86_64/src/memory/paging/page_mapper.cpp
+++ b/arch/x86_64/src/memory/paging/page_mapper.cpp
@@ -4,10 +4,20 @@
namespace teachos::arch::memory::paging
{
+
auto create_or_get() -> page_table_handle
{
+ static auto initialized = false;
// TODO: As soon as linker error is fixed in toolchain make handle static and return that.
- return page_table_handle{arch::boot::page_map_level_4, page_table_handle::LEVEL4};
+ page_table_handle active_handle{boot::page_map_level_4, page_table_handle::LEVEL4};
+
+ if (!initialized)
+ {
+ active_handle.initialize_page_tables();
+ initialized = true;
+ }
+
+ return active_handle;
}
auto translate_page(virtual_page page) -> std::optional<allocator::physical_frame>
diff --git a/arch/x86_64/src/memory/paging/page_table.cpp b/arch/x86_64/src/memory/paging/page_table.cpp
index 2f97a80..b5315a0 100644
--- a/arch/x86_64/src/memory/paging/page_table.cpp
+++ b/arch/x86_64/src/memory/paging/page_table.cpp
@@ -11,11 +11,6 @@ namespace teachos::arch::memory::paging
struct page_table
{
/**
- * @brief Defaulted constructor.
- */
- page_table() = default;
-
- /**
* @brief Set every entry of the page to unused.
*/
auto zero_entries() -> void;
@@ -105,7 +100,15 @@ namespace teachos::arch::memory::paging
: handle(handle)
, handle_level(handle_level)
{
- exception_handling::assert(handle, "[Page table] Attempted to pass nullptr as handle to page table handle method");
+ exception_handling::assert(handle, "[Page Table] Attempted to pass nullptr as handle to page table handle method");
+ }
+
+ auto page_table_handle::initialize_page_table() -> void
+ {
+ exception_handling::assert(handle_level == page_table_handle::LEVEL4,
+ "[Page Table] Attempted to initialize a page table of level 3 or lower");
+
+ auto level_3_page_table = boot::page_map_level_3;
}
auto page_table_handle::zero_entries() -> void { handle->zero_entries(); }