diff options
| author | Fabian Imhof <fabian.imhof@ost.ch> | 2024-10-26 07:47:33 +0000 |
|---|---|---|
| committer | Fabian Imhof <fabian.imhof@ost.ch> | 2024-10-26 07:47:33 +0000 |
| commit | 886c5e5ce7d1e6dd80d3782d5cf66bf474a6cddb (patch) | |
| tree | 82b801a473b67880cfaba2709f90a2faff33e0a9 /arch | |
| parent | b00ec1f863e330d2c4ae1d1ef4d352ab73861f17 (diff) | |
| parent | e44a16e45a309aa96375a2215d0d2405cf467dae (diff) | |
| download | teachos-886c5e5ce7d1e6dd80d3782d5cf66bf474a6cddb.tar.xz teachos-886c5e5ce7d1e6dd80d3782d5cf66bf474a6cddb.zip | |
Merge branch 'feat_memory_manager' of ssh://gitlab.ost.ch:45022/teachos/kernel into feat_memory_manager
Diffstat (limited to 'arch')
| -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; } |
