aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/memory/multiboot
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/src/memory/multiboot')
-rw-r--r--arch/x86_64/src/memory/multiboot/reader.cpp42
1 files changed, 20 insertions, 22 deletions
diff --git a/arch/x86_64/src/memory/multiboot/reader.cpp b/arch/x86_64/src/memory/multiboot/reader.cpp
index e35baf3..7bdf48f 100644
--- a/arch/x86_64/src/memory/multiboot/reader.cpp
+++ b/arch/x86_64/src/memory/multiboot/reader.cpp
@@ -18,8 +18,7 @@ namespace teachos::arch::memory::multiboot
return reinterpret_cast<T>(reinterpret_cast<uint8_t *>(ptr) + ((size + 7) & ~7));
}
- auto process_memory_map(memory_map_header * mminfo, memory_area_container::iterator & begin_area,
- memory_area_container::iterator & end_area) -> void
+ auto process_memory_map(memory_map_header * mminfo) -> memory_area_container
{
auto const expected_entry_size = mminfo->entry_size;
auto constexpr actual_entry_size = sizeof(memory_area);
@@ -30,13 +29,13 @@ namespace teachos::arch::memory::multiboot
auto const total_entries_size = total_size - sizeof(memory_map_header) + actual_entry_size;
auto const number_of_entries = total_entries_size / actual_entry_size;
- begin_area = memory_area_container::iterator{&mminfo->entries};
- end_area = begin_area + number_of_entries;
+ auto const begin = memory_area_container::iterator{&mminfo->entries};
+ auto const end = begin + number_of_entries;
+ return memory_area_container{begin, end};
}
- auto process_elf_sections(elf_symbols_section_header * symbol, std::size_t & kernel_start, std::size_t & kernel_end,
- elf_section_header_container::iterator & begin_kernel,
- elf_section_header_container::iterator & end_kernel) -> void
+ auto process_elf_sections(elf_symbols_section_header * symbol, std::size_t & kernel_start,
+ std::size_t & kernel_end) -> elf_section_header_container
{
auto const expected_entry_size = symbol->entry_size;
auto constexpr actual_entry_size = sizeof(elf_section_header);
@@ -50,30 +49,30 @@ namespace teachos::arch::memory::multiboot
exception_handling::assert(expected_total_size == actual_total_size,
"[Multiboot Reader] Unexpected elf symbols section header total size");
- begin_kernel = elf_section_header_container::iterator{reinterpret_cast<elf_section_header *>(&symbol->end)};
- end_kernel = begin_kernel + symbol->number_of_sections;
- exception_handling::assert(begin_kernel->is_null(),
+ auto const begin = elf_section_header_container::iterator{reinterpret_cast<elf_section_header *>(&symbol->end)};
+ auto const end = begin + symbol->number_of_sections;
+ exception_handling::assert(begin->is_null(),
"[Multiboot Reader] Elf symbols section not starting with SHT_NULL section");
- elf_section_header_container container{begin_kernel, end_kernel};
+ elf_section_header_container sections{begin, end};
auto const elf_section_with_lowest_virtual_address =
- std::ranges::min_element(container, [](elf_section_header const & a, elf_section_header const & b) {
+ std::ranges::min_element(sections, [](elf_section_header const & a, elf_section_header const & b) {
return a.virtual_address < b.virtual_address;
});
auto const elf_section_with_highest_virtual_address =
- std::ranges::max_element(container, [](elf_section_header const & a, elf_section_header const & b) {
+ std::ranges::max_element(sections, [](elf_section_header const & a, elf_section_header const & b) {
auto a_virtual_address_end = a.virtual_address + a.section_size;
auto b_virtual_address_end = b.virtual_address + b.section_size;
return a_virtual_address_end < b_virtual_address_end;
});
- auto const symbol_table_section_count = std::ranges::count_if(container, [](elf_section_header const & section) {
+ auto const symbol_table_section_count = std::ranges::count_if(sections, [](elf_section_header const & section) {
return section.type == elf_section_type::DYNAMIC_SYMBOL_TABLE || section.type == elf_section_type::SYMBOL_TABLE;
});
auto const dynamic_section_count = std::ranges::count_if(
- container, [](elf_section_header const & section) { return section.type == elf_section_type::DYNAMIC; });
+ sections, [](elf_section_header const & section) { return section.type == elf_section_type::DYNAMIC; });
exception_handling::assert(
symbol_table_section_count == 1U,
@@ -87,6 +86,8 @@ namespace teachos::arch::memory::multiboot
auto const highest_elf_section = *elf_section_with_highest_virtual_address;
kernel_end = highest_elf_section.virtual_address + highest_elf_section.section_size;
+
+ return sections;
}
} // namespace
@@ -94,12 +95,10 @@ namespace teachos::arch::memory::multiboot
{
memory_information mem_info{UINT64_MAX,
0U,
- elf_section_header_container::iterator{},
- elf_section_header_container::iterator{},
+ elf_section_header_container{},
boot::multiboot_information_pointer,
0U,
- memory_area_container::iterator{},
- memory_area_container::iterator{}};
+ memory_area_container{}};
auto const multiboot_information_pointer = reinterpret_cast<info_header *>(boot::multiboot_information_pointer);
auto const multiboot_tag = &multiboot_information_pointer->tags;
@@ -111,13 +110,12 @@ namespace teachos::arch::memory::multiboot
{
case tag_type::ELF_SECTIONS: {
auto const symbol = reinterpret_cast<elf_symbols_section_header *>(tag);
- process_elf_sections(symbol, mem_info.kernel_start, mem_info.kernel_end, mem_info.begin_kernel,
- mem_info.end_kernel);
+ mem_info.sections = process_elf_sections(symbol, mem_info.kernel_start, mem_info.kernel_end);
break;
}
case tag_type::MEMORY_MAP: {
auto const mminfo = reinterpret_cast<memory_map_header *>(tag);
- process_memory_map(mminfo, mem_info.begin_area, mem_info.end_area);
+ mem_info.areas = process_memory_map(mminfo);
break;
}
default: