diff options
Diffstat (limited to 'arch/x86_64/src/memory')
| -rw-r--r-- | arch/x86_64/src/memory/paging/page_mapper.cpp | 11 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/paging/page_table.cpp | 15 |
2 files changed, 13 insertions, 13 deletions
diff --git a/arch/x86_64/src/memory/paging/page_mapper.cpp b/arch/x86_64/src/memory/paging/page_mapper.cpp index 687bffd..cd77366 100644 --- a/arch/x86_64/src/memory/paging/page_mapper.cpp +++ b/arch/x86_64/src/memory/paging/page_mapper.cpp @@ -4,17 +4,10 @@ namespace teachos::arch::memory::paging { - namespace - { - constexpr size_t PAGE_TABLE_LEVEL_4_ADDRESS = 0xfffffffffffff000; - } // namespace - auto create_or_get() -> page_table_handle { - // Perhaps we need to access boot::page_map_level_4; so we do not crash when returning entry? - 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}; + // 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}; } 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 1d7b8a0..2f97a80 100644 --- a/arch/x86_64/src/memory/paging/page_table.cpp +++ b/arch/x86_64/src/memory/paging/page_table.cpp @@ -1,6 +1,7 @@ #include "arch/memory/paging/page_table.hpp" #include <array> +#include <memory> namespace teachos::arch::memory::paging { @@ -10,6 +11,11 @@ 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; @@ -46,9 +52,9 @@ namespace teachos::arch::memory::paging */ auto next_table_address(std::size_t table_index) -> std::optional<std::size_t>; - std::array<entry, PAGE_TABLE_ENTRY_COUNT> - entries{}; ///< Entries containing addresses to page tables of a level below or - ///< actual virtual addresses for the level 1 page table. + std::array<entry, PAGE_TABLE_ENTRY_COUNT> entries = + {}; ///< Entries containing addresses to page tables of a level below or + ///< actual virtual addresses for the level 1 page table. }; auto page_table::zero_entries() -> void @@ -67,7 +73,8 @@ namespace teachos::arch::memory::paging auto address = next_table_address(table_index); if (address) { - return reinterpret_cast<page_table *>(address.value()); + // TODO: Probably erases the data even if the page table already existed previously and had values. + return std::construct_at(reinterpret_cast<page_table *>(address.value())); } return std::nullopt; } |
