aboutsummaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorFabian Imhof <fabian.imhof@ost.ch>2024-10-27 13:27:33 +0000
committerFabian Imhof <fabian.imhof@ost.ch>2024-10-27 13:27:33 +0000
commit1518177efac38961a36db0bc40152d00c38e6281 (patch)
tree8c4ce4f8c5b967533a0a4b14aa1460cee9508405 /arch
parentca17ed52ea768f1e1c837207f7d27afa6ed99cc2 (diff)
downloadteachos-1518177efac38961a36db0bc40152d00c38e6281.tar.xz
teachos-1518177efac38961a36db0bc40152d00c38e6281.zip
add correct optional handling
Diffstat (limited to 'arch')
-rw-r--r--arch/x86_64/include/arch/memory/paging/page_table.hpp2
-rw-r--r--arch/x86_64/src/memory/allocator/area_frame_allocator.cpp17
-rw-r--r--arch/x86_64/src/memory/paging/page_mapper.cpp12
-rw-r--r--arch/x86_64/src/memory/paging/page_table.cpp4
4 files changed, 20 insertions, 15 deletions
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 291ea8d..8fcde9f 100644
--- a/arch/x86_64/include/arch/memory/paging/page_table.hpp
+++ b/arch/x86_64/include/arch/memory/paging/page_table.hpp
@@ -83,7 +83,7 @@ namespace teachos::arch::memory::paging
// been created itself. So we have to do that before we are able to allocate the wanted frame. This has to be done
// for every level, meaning we potenitally create a level 4, level 3 and level 2 page entry, each pointing to a
// page table one level below.
- if (!next_handle)
+ if (!next_handle.has_value())
{
auto allocated_frame = allocator.allocate_frame();
exception_handling::assert(allocated_frame.has_value(), "[Page mapper] Unable to allocate frame");
diff --git a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp
index c2cafce..05b828c 100644
--- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp
+++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp
@@ -29,14 +29,14 @@ namespace teachos::arch::memory::allocator
if (physical_frame::containing_address(address) >= next_free_frame)
{
// The `next_free_frame` address is smaller than the last address of the current area
- if (!current_area || area.base_address < current_area->base_address)
+ if (!current_area.has_value() || area.base_address < current_area.value().base_address)
{
- current_area = area;
+ current_area.emplace(area);
}
}
}
- if (current_area)
+ if (current_area.has_value())
{
// Update the `next_free_frame` according to the new memory area
physical_frame start_frame = physical_frame::containing_address(current_area->base_address);
@@ -53,7 +53,7 @@ namespace teachos::arch::memory::allocator
* Only try to allocate memory if current_area is not null, because
* the current_area is null if there is no more available memory.
*/
- if (current_area)
+ if (current_area.has_value())
{
physical_frame physical_frame{next_free_frame.frame_number};
@@ -65,11 +65,16 @@ namespace teachos::arch::memory::allocator
// All frames of current area are used, switch to next area
choose_next_area();
}
- else if (physical_frame >= multiboot_start && physical_frame <= kernel_end)
+ else if (physical_frame >= kernel_start && physical_frame <= kernel_end)
{
- // `physical_frame` is used by the kernel or multiboot information structure
+ // `physical_frame` is used by the kernel
next_free_frame = allocator::physical_frame{kernel_end.frame_number + 1};
}
+ else if (physical_frame >= multiboot_start && physical_frame <= multiboot_end)
+ {
+ // `physical_frame` is used by the multiboot information structure
+ next_free_frame = allocator::physical_frame{multiboot_end.frame_number + 1};
+ }
else
{
// Frame is unused, increment `next_free_frame` and return it
diff --git a/arch/x86_64/src/memory/paging/page_mapper.cpp b/arch/x86_64/src/memory/paging/page_mapper.cpp
index 75d6759..bc0c0d9 100644
--- a/arch/x86_64/src/memory/paging/page_mapper.cpp
+++ b/arch/x86_64/src/memory/paging/page_mapper.cpp
@@ -28,7 +28,7 @@ namespace teachos::arch::memory::paging
auto 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)
+ if (!next_handle.has_value())
{
return translate_huge_page(page);
}
@@ -45,14 +45,14 @@ namespace teachos::arch::memory::paging
auto current_handle = create_or_get();
auto level3_handle = current_handle.next_table(page.get_level_index(page_table_handle::LEVEL4));
- if (!level3_handle)
+ if (!level3_handle.has_value())
{
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();
- if (level3_frame && level3_entry.contains_flags(entry::HUGE_PAGE))
+ if (level3_frame.has_value() && level3_entry.contains_flags(entry::HUGE_PAGE))
{
exception_handling::assert(
level3_frame.value().frame_number % (PAGE_TABLE_ENTRY_COUNT * PAGE_TABLE_ENTRY_COUNT) == 0U,
@@ -63,11 +63,11 @@ namespace teachos::arch::memory::paging
}
auto level2_handle = level3_handle.value().next_table(page.get_level_index(page_table_handle::LEVEL3));
- if (level2_handle)
+ 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();
- if (level2_frame && level2_entry.contains_flags(entry::HUGE_PAGE))
+ 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,
"[Page Mapper] Physical address must be 2 MiB aligned");
@@ -84,7 +84,7 @@ namespace teachos::arch::memory::paging
virtual_page page = virtual_page::containing_address(virtual_address);
std::optional<allocator::physical_frame> frame = translate_page(page);
- if (frame)
+ if (frame.has_value())
{
return frame.value().frame_number * allocator::PAGE_FRAME_SIZE + offset;
}
diff --git a/arch/x86_64/src/memory/paging/page_table.cpp b/arch/x86_64/src/memory/paging/page_table.cpp
index 868cf86..f1df31d 100644
--- a/arch/x86_64/src/memory/paging/page_table.cpp
+++ b/arch/x86_64/src/memory/paging/page_table.cpp
@@ -72,7 +72,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);
- if (address)
+ if (address.has_value())
{
return reinterpret_cast<page_table *>(address.value());
}
@@ -136,7 +136,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);
- if (next_table)
+ if (next_table.has_value())
{
return page_table_handle{next_table.value(), --handle_level};
}