aboutsummaryrefslogtreecommitdiff
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
parent9a1f3e66b6c860fdca689241e78f85bdbb5b4da5 (diff)
downloadteachos-c29d8c3b65f63bfd54031412d9c2975ef7571460.tar.xz
teachos-c29d8c3b65f63bfd54031412d9c2975ef7571460.zip
use actual page_table address
-rw-r--r--arch/x86_64/include/arch/boot/pointers.hpp3
-rw-r--r--arch/x86_64/include/arch/memory/paging/page_entry.hpp4
-rw-r--r--arch/x86_64/include/arch/memory/paging/page_mapper.hpp2
-rw-r--r--arch/x86_64/include/arch/memory/paging/page_table.hpp2
-rw-r--r--arch/x86_64/src/boot/boot.s2
-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
8 files changed, 21 insertions, 19 deletions
diff --git a/arch/x86_64/include/arch/boot/pointers.hpp b/arch/x86_64/include/arch/boot/pointers.hpp
index 25800f4..37840b6 100644
--- a/arch/x86_64/include/arch/boot/pointers.hpp
+++ b/arch/x86_64/include/arch/boot/pointers.hpp
@@ -1,11 +1,14 @@
#ifndef TEACHOS_ARCH_X86_64_BOOT_POINTERS_HPP
#define TEACHOS_ARCH_X86_64_BOOT_POINTERS_HPP
+#include "arch/memory/paging/page_table.hpp"
+
#include <cstddef>
namespace teachos::arch::boot
{
extern "C" size_t const multiboot_information_pointer;
+ extern "C" memory::paging::page_table * page_map_level_4;
} // namespace teachos::arch::boot
#endif
diff --git a/arch/x86_64/include/arch/memory/paging/page_entry.hpp b/arch/x86_64/include/arch/memory/paging/page_entry.hpp
index 2b3b3f3..33126f0 100644
--- a/arch/x86_64/include/arch/memory/paging/page_entry.hpp
+++ b/arch/x86_64/include/arch/memory/paging/page_entry.hpp
@@ -59,9 +59,9 @@ namespace teachos::arch::memory::paging
* to calculate_physical_address() will return the new address and flags instead of the old one.
*
* @param frame Physical frame that contains the address we want to copy into our underlying std::bitset.
- * @param flags Entry flags which will be copied into our underlying std::bitset.
+ * @param additional_flags Entry flags which will be copied into our underlying std::bitset.
*/
- auto set_entry(allocator::physical_frame frame, std::bitset<64U> flags) -> void;
+ auto set_entry(allocator::physical_frame frame, std::bitset<64U> additional_flags) -> void;
/**
* @brief Checks if the given std::bitset is a subset or equivalent to the underlying std::bitset.
diff --git a/arch/x86_64/include/arch/memory/paging/page_mapper.hpp b/arch/x86_64/include/arch/memory/paging/page_mapper.hpp
index 173db9b..358b90c 100644
--- a/arch/x86_64/include/arch/memory/paging/page_mapper.hpp
+++ b/arch/x86_64/include/arch/memory/paging/page_mapper.hpp
@@ -77,7 +77,7 @@ namespace teachos::arch::memory::paging
exception_handling::assert(allocated_frame.has_value(), "[Page mapper] Unable to allocate frame");
current_handle[level_index].set_entry(allocated_frame.value(), entry::PRESENT | entry::WRITABLE);
// There should now be an entry at the previously not existent index, therefore we can simply access it again.
- next_handle = current_handle.next_table(page.get_level_index(level));
+ next_handle = current_handle.next_table(level_index);
exception_handling::assert(next_handle.has_value(), "[Page mapper] Unable to create new entry into page table");
next_handle.value().zero_entries();
}
diff --git a/arch/x86_64/include/arch/memory/paging/page_table.hpp b/arch/x86_64/include/arch/memory/paging/page_table.hpp
index e6542a2..ad5c794 100644
--- a/arch/x86_64/include/arch/memory/paging/page_table.hpp
+++ b/arch/x86_64/include/arch/memory/paging/page_table.hpp
@@ -66,7 +66,7 @@ namespace teachos::arch::memory::paging
* @param index Index of the entry we want to access and only read.
* @return Entry at the given table index.
*/
- auto operator[](std::size_t index) const -> entry;
+ auto operator[](std::size_t index) -> entry &;
/**
* @brief Decrements the page table handle level enum by one, is defined so we can use it as a replacement for an
diff --git a/arch/x86_64/src/boot/boot.s b/arch/x86_64/src/boot/boot.s
index 710d4ce..7d6b322 100644
--- a/arch/x86_64/src/boot/boot.s
+++ b/arch/x86_64/src/boot/boot.s
@@ -10,7 +10,7 @@
.align 4096
/**
- * Reserve space for the page maps we are going to used during startup.
+ * Reserve space for the page maps we are going to use during startup.
*
* Note: We are going to use large pages to make the initial mapping code
* simpler.
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
{