diff options
| author | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-10-28 13:32:09 +0000 |
|---|---|---|
| committer | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-10-28 13:32:09 +0000 |
| commit | e5925df93411429340d2887594004aaa690d2ef5 (patch) | |
| tree | a24bc2f7aaf897fead13e151a5c155b597664f16 /arch/x86_64/src/memory/paging | |
| parent | efcb913196ccf0386a557e8c1053c430e5896179 (diff) | |
| download | teachos-e5925df93411429340d2887594004aaa690d2ef5.tar.xz teachos-e5925df93411429340d2887594004aaa690d2ef5.zip | |
Adjust constant and make all possible variables const
Diffstat (limited to 'arch/x86_64/src/memory/paging')
| -rw-r--r-- | arch/x86_64/src/memory/paging/page_entry.cpp | 2 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/paging/page_mapper.cpp | 26 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/paging/page_table.cpp | 22 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/paging/virtual_page.cpp | 2 |
4 files changed, 28 insertions, 24 deletions
diff --git a/arch/x86_64/src/memory/paging/page_entry.cpp b/arch/x86_64/src/memory/paging/page_entry.cpp index dbf23e2..8923fea 100644 --- a/arch/x86_64/src/memory/paging/page_entry.cpp +++ b/arch/x86_64/src/memory/paging/page_entry.cpp @@ -6,7 +6,7 @@ namespace teachos::arch::memory::paging { namespace { - constexpr std::size_t PHYSICAL_ADDRESS_MASK = 0x000fffff'fffff000; + std::size_t constexpr PHYSICAL_ADDRESS_MASK = 0x000fffff'fffff000; } entry::entry(uint64_t flags) diff --git a/arch/x86_64/src/memory/paging/page_mapper.cpp b/arch/x86_64/src/memory/paging/page_mapper.cpp index fb9ea39..3baf6ae 100644 --- a/arch/x86_64/src/memory/paging/page_mapper.cpp +++ b/arch/x86_64/src/memory/paging/page_mapper.cpp @@ -4,11 +4,15 @@ namespace teachos::arch::memory::paging { + namespace + { + std::size_t constexpr PAGE_TABLE_LEVEL_4_ADDRESS = 0xffffffff'fffff000; + } // namespace auto create_or_get() -> page_table_handle { static auto initialized = false; - static page_table_handle active_handle{reinterpret_cast<page_table *>(0xffffffff'fffff000), + static page_table_handle active_handle{reinterpret_cast<page_table *>(PAGE_TABLE_LEVEL_4_ADDRESS), page_table_handle::LEVEL4}; if (!initialized) @@ -22,9 +26,9 @@ namespace teachos::arch::memory::paging auto translate_address(virtual_address address) -> std::optional<allocator::physical_address> { - auto offset = address % allocator::PAGE_FRAME_SIZE; - auto page = virtual_page::containing_address(address); - auto frame = translate_page(page); + auto const offset = address % allocator::PAGE_FRAME_SIZE; + auto const page = virtual_page::containing_address(address); + auto const frame = translate_page(page); if (frame.has_value()) { @@ -40,7 +44,7 @@ namespace teachos::arch::memory::paging for (auto level = page_table_handle::LEVEL4; level != page_table_handle::LEVEL1; --level) { - auto next_handle = current_handle.next_table(page.get_level_index(level)); + auto const next_handle = current_handle.next_table(page.get_level_index(level)); // If the next table method failed then it is highly likely that it was a huge page and we therefore have to // parse the table differently. Therefore, we attempt to parse it using the method required by huge pages. if (!next_handle.has_value()) @@ -50,8 +54,8 @@ namespace teachos::arch::memory::paging current_handle = next_handle.value(); } - auto level1_index = page.get_level_index(page_table_handle::LEVEL1); - auto level1_frame = current_handle[level1_index].calculate_pointed_to_frame(); + auto const level1_index = page.get_level_index(page_table_handle::LEVEL1); + auto const level1_frame = current_handle[level1_index].calculate_pointed_to_frame(); return level1_frame; } @@ -65,8 +69,8 @@ namespace teachos::arch::memory::paging return std::nullopt; } - auto level3_entry = level3_handle.value()[page.get_level_index(page_table_handle::LEVEL3)]; - auto level3_frame = level3_entry.calculate_pointed_to_frame(); + auto const level3_entry = level3_handle.value()[page.get_level_index(page_table_handle::LEVEL3)]; + auto const level3_frame = level3_entry.calculate_pointed_to_frame(); if (level3_frame.has_value() && level3_entry.contains_flags(entry::HUGE_PAGE)) { exception_handling::assert( @@ -80,8 +84,8 @@ namespace teachos::arch::memory::paging auto level2_handle = level3_handle.value().next_table(page.get_level_index(page_table_handle::LEVEL3)); if (level2_handle.has_value()) { - auto level2_entry = level2_handle.value()[page.get_level_index(page_table_handle::LEVEL2)]; - auto level2_frame = level2_entry.calculate_pointed_to_frame(); + auto const level2_entry = level2_handle.value()[page.get_level_index(page_table_handle::LEVEL2)]; + auto const level2_frame = level2_entry.calculate_pointed_to_frame(); if (level2_frame.has_value() && level2_entry.contains_flags(entry::HUGE_PAGE)) { exception_handling::assert(level2_frame.value().frame_number % PAGE_TABLE_ENTRY_COUNT == 0U, diff --git a/arch/x86_64/src/memory/paging/page_table.cpp b/arch/x86_64/src/memory/paging/page_table.cpp index e919a1e..a01c431 100644 --- a/arch/x86_64/src/memory/paging/page_table.cpp +++ b/arch/x86_64/src/memory/paging/page_table.cpp @@ -60,9 +60,9 @@ namespace teachos::arch::memory::paging auto page_table::zero_entries() -> void { - constexpr size_t entry_amount = sizeof(entries) / sizeof(entries[0]); + std::size_t constexpr entry_amount = sizeof(entries) / sizeof(entries[0]); static_assert(entry_amount == PAGE_TABLE_ENTRY_COUNT); - for (size_t i = 0; i < entry_amount; ++i) + for (std::size_t i = 0; i < entry_amount; ++i) { auto entry = this->operator[](i); entry.set_unused(); @@ -71,7 +71,7 @@ namespace teachos::arch::memory::paging auto page_table::next_table(std::size_t table_index) -> std::optional<page_table *> { - auto address = next_table_address(table_index); + auto const address = next_table_address(table_index); if (address.has_value()) { return reinterpret_cast<page_table *>(address.value()); @@ -89,11 +89,11 @@ namespace teachos::arch::memory::paging auto page_table::next_table_address(std::size_t table_index) -> std::optional<std::size_t> { - auto entry = this->operator[](table_index); + auto const entry = this->operator[](table_index); if (entry.contains_flags(entry::PRESENT) && !entry.contains_flags(entry::HUGE_PAGE)) { - std::size_t const table_address = reinterpret_cast<std::size_t>(this); + auto const table_address = reinterpret_cast<std::size_t>(this); return ((table_address << 9) | (table_index << 12)); } return std::nullopt; @@ -113,17 +113,17 @@ namespace teachos::arch::memory::paging exception_handling::assert(handle_level == page_table_handle::LEVEL4, "[Page Table] Attempted to initialize a page table of level 3 or lower"); auto level3_page_table = std::construct_at(reinterpret_cast<page_table *>(&_end_of_image)); - for (size_t n = 1; n <= PAGE_TABLE_ENTRY_COUNT; ++n) + for (std::size_t n = 1; n <= PAGE_TABLE_ENTRY_COUNT; ++n) { - size_t offset = sizeof(page_table) * n; + std::size_t offset = sizeof(page_table) * n; std::construct_at(reinterpret_cast<page_table *>(&_end_of_image + offset)); - for (size_t m = 1; m <= PAGE_TABLE_ENTRY_COUNT; ++m) + for (std::size_t m = 1; m <= PAGE_TABLE_ENTRY_COUNT; ++m) { - size_t offset = sizeof(page_table) * ((PAGE_TABLE_ENTRY_COUNT * n) + m); + std::size_t offset = sizeof(page_table) * ((PAGE_TABLE_ENTRY_COUNT * n) + m); std::construct_at(reinterpret_cast<page_table *>(&_end_of_image + offset)); } } - size_t const flags = reinterpret_cast<size_t>(level3_page_table); + std::size_t const flags = reinterpret_cast<std::size_t>(level3_page_table); this->operator[](0U) = entry{flags}; */ } @@ -134,7 +134,7 @@ namespace teachos::arch::memory::paging { exception_handling::assert(handle_level != page_table_handle::LEVEL1, "[Page Table] Attempted to call next_table on level 1 page table"); - auto next_table = handle->next_table(table_index); + auto const next_table = handle->next_table(table_index); if (next_table.has_value()) { return page_table_handle{next_table.value(), --handle_level}; diff --git a/arch/x86_64/src/memory/paging/virtual_page.cpp b/arch/x86_64/src/memory/paging/virtual_page.cpp index d39bb7f..4221335 100644 --- a/arch/x86_64/src/memory/paging/virtual_page.cpp +++ b/arch/x86_64/src/memory/paging/virtual_page.cpp @@ -12,7 +12,7 @@ namespace teachos::arch::memory::paging auto virtual_page::containing_address(virtual_address address) -> virtual_page { - exception_handling::assert(address < 0x0000800000000000 || address >= 0xffff800000000000, + exception_handling::assert(address < 0x00008000'00000000 || address >= 0xffff8000'00000000, "[Virtual Page] Attempted to create virtual page from invalid address"); return virtual_page{address / allocator::PAGE_FRAME_SIZE}; } |
