aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/memory/paging
diff options
context:
space:
mode:
authorFabian Imhof <fabian.imhof@ost.ch>2024-10-22 08:58:48 +0000
committerFabian Imhof <fabian.imhof@ost.ch>2024-10-22 08:58:48 +0000
commitc29d8c3b65f63bfd54031412d9c2975ef7571460 (patch)
treec43af699c5f0ccb0e448f6101c6d702be372e1a9 /arch/x86_64/src/memory/paging
parent9a1f3e66b6c860fdca689241e78f85bdbb5b4da5 (diff)
downloadteachos-c29d8c3b65f63bfd54031412d9c2975ef7571460.tar.xz
teachos-c29d8c3b65f63bfd54031412d9c2975ef7571460.zip
use actual page_table address
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_mapper.cpp9
-rw-r--r--arch/x86_64/src/memory/paging/page_table.cpp14
3 files changed, 13 insertions, 14 deletions
diff --git a/arch/x86_64/src/memory/paging/page_entry.cpp b/arch/x86_64/src/memory/paging/page_entry.cpp
index a172ca8..5d597ab 100644
--- a/arch/x86_64/src/memory/paging/page_entry.cpp
+++ b/arch/x86_64/src/memory/paging/page_entry.cpp
@@ -33,10 +33,10 @@ namespace teachos::arch::memory::paging
auto entry::contains_flags(std::bitset<64U> other) const -> bool { return (flags & other) == other; }
- auto entry::set_entry(allocator::physical_frame frame, std::bitset<64U> flags) -> void
+ auto entry::set_entry(allocator::physical_frame frame, std::bitset<64U> additional_flags) -> void
{
exception_handling::assert((frame.start_address() & ~0x000fffff'fffff000) == 0,
"[Paging Entry] Start address is not aligned with page");
- flags = std::bitset<64U>{frame.start_address()} | flags;
+ 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 03f9f10..1fe72e3 100644
--- a/arch/x86_64/src/memory/paging/page_mapper.cpp
+++ b/arch/x86_64/src/memory/paging/page_mapper.cpp
@@ -1,19 +1,18 @@
#include "arch/memory/paging/page_mapper.hpp"
+#include "arch/boot/pointers.hpp"
+
namespace teachos::arch::memory::paging
{
namespace
{
- // TODO: Set the address to a sensible location, this is merely a placeholder
- // constexpr size_t PAGE_TABLE_LEVEL_4_ADDRESS = 0xfffffffffffff000;
- constexpr size_t PAGE_TABLE_LEVEL_4_ADDRESS = 0x27AC40;
+ page_table * PAGE_TABLE_LEVEL_4_ADDRESS = boot::page_map_level_4;
} // namespace
auto create_or_get() -> page_table_handle
{
- static page_table * const active_page{reinterpret_cast<page_table *>(PAGE_TABLE_LEVEL_4_ADDRESS)};
// We can not save page_table_handle as a static variable directly, if we do the program will fail to link.
- return page_table_handle{active_page, page_table_handle::LEVEL4};
+ return page_table_handle{PAGE_TABLE_LEVEL_4_ADDRESS, page_table_handle::LEVEL4};
}
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 b229ff7..8971209 100644
--- a/arch/x86_64/src/memory/paging/page_table.cpp
+++ b/arch/x86_64/src/memory/paging/page_table.cpp
@@ -24,7 +24,7 @@ namespace teachos::arch::memory::paging
*
* @param table_index Index of this page table in the page table one level lower.
*/
- auto next_table(std::size_t table_index) const -> std::optional<page_table *>;
+ auto next_table(std::size_t table_index) -> std::optional<page_table *>;
/**
* @brief Index operator overload to access specific entries directy.
@@ -32,7 +32,7 @@ namespace teachos::arch::memory::paging
* @param index Index of the entry we want to access and read or write too.
* @return Entry at the given table index.
*/
- auto operator[](std::size_t index) const -> entry;
+ auto operator[](std::size_t index) -> entry &;
private:
/**
@@ -44,7 +44,7 @@ namespace teachos::arch::memory::paging
* @param table_index Index of this page table in the page table one level higher.
* @return An optional of the address of the next page table or null.
*/
- auto next_table_address(std::size_t table_index) const -> std::optional<std::size_t>;
+ auto next_table_address(std::size_t table_index) -> std::optional<std::size_t>;
entry entries[PAGE_TABLE_ENTRY_COUNT]; ///< Entries containing addresses to page tables of a level below or
///< actual virtual addresses for the level 1 page table.
@@ -60,7 +60,7 @@ namespace teachos::arch::memory::paging
}
}
- auto page_table::next_table(std::size_t table_index) const -> std::optional<page_table *>
+ auto page_table::next_table(std::size_t table_index) -> std::optional<page_table *>
{
auto address = next_table_address(table_index);
if (address)
@@ -70,7 +70,7 @@ namespace teachos::arch::memory::paging
return std::nullopt;
}
- auto page_table::operator[](std::size_t index) const -> entry
+ auto page_table::operator[](std::size_t index) -> entry &
{
// 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.
@@ -78,7 +78,7 @@ namespace teachos::arch::memory::paging
return entries[index];
}
- auto page_table::next_table_address(std::size_t table_index) const -> std::optional<std::size_t>
+ auto page_table::next_table_address(std::size_t table_index) -> std::optional<std::size_t>
{
auto entry = this->operator[](table_index);
@@ -112,7 +112,7 @@ namespace teachos::arch::memory::paging
return std::nullopt;
}
- auto page_table_handle::operator[](std::size_t index) const -> entry { return handle->operator[](index); }
+ auto page_table_handle::operator[](std::size_t index) -> entry & { return handle->operator[](index); }
auto operator--(page_table_handle::level & value, int) -> page_table_handle::level
{