aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/memory/multiboot
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-28 13:32:09 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-28 13:32:09 +0000
commite5925df93411429340d2887594004aaa690d2ef5 (patch)
treea24bc2f7aaf897fead13e151a5c155b597664f16 /arch/x86_64/src/memory/multiboot
parentefcb913196ccf0386a557e8c1053c430e5896179 (diff)
downloadteachos-e5925df93411429340d2887594004aaa690d2ef5.tar.xz
teachos-e5925df93411429340d2887594004aaa690d2ef5.zip
Adjust constant and make all possible variables const
Diffstat (limited to 'arch/x86_64/src/memory/multiboot')
-rw-r--r--arch/x86_64/src/memory/multiboot/reader.cpp47
1 files changed, 23 insertions, 24 deletions
diff --git a/arch/x86_64/src/memory/multiboot/reader.cpp b/arch/x86_64/src/memory/multiboot/reader.cpp
index 228aa09..c3a78df 100644
--- a/arch/x86_64/src/memory/multiboot/reader.cpp
+++ b/arch/x86_64/src/memory/multiboot/reader.cpp
@@ -21,14 +21,14 @@ namespace teachos::arch::memory::multiboot
auto process_memory_map(memory_map_header * mminfo, memory_area_container::iterator & begin_area,
memory_area_container::iterator & end_area) -> void
{
- auto expected_entry_size = mminfo->entry_size;
- constexpr auto actual_entry_size = sizeof(memory_area);
+ auto const expected_entry_size = mminfo->entry_size;
+ auto constexpr actual_entry_size = sizeof(memory_area);
exception_handling::assert(expected_entry_size == actual_entry_size,
"[Multiboot Reader] Unexpected memory area entry size");
- auto total_size = mminfo->info.size;
- auto total_entries_size = total_size - sizeof(memory_map_header) + actual_entry_size;
- auto number_of_entries = total_entries_size / actual_entry_size;
+ auto const total_size = mminfo->info.size;
+ 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;
@@ -37,41 +37,41 @@ namespace teachos::arch::memory::multiboot
auto process_elf_sections(elf_symbols_section_header * symbol, uint64_t & kernel_start,
uint64_t & kernel_end) -> void
{
- auto expected_entry_size = symbol->entry_size;
- constexpr auto actual_entry_size = sizeof(elf_section_header);
+ auto const expected_entry_size = symbol->entry_size;
+ auto constexpr actual_entry_size = sizeof(elf_section_header);
exception_handling::assert(expected_entry_size == actual_entry_size,
"[Multiboot Reader] Unexpected elf section header entry size");
- auto expected_total_size = symbol->info.size;
- auto actual_total_entry_size = actual_entry_size * symbol->number_of_sections;
- constexpr auto actual_total_section_size = sizeof(elf_symbols_section_header) - sizeof(uint32_t);
- auto actual_total_size = actual_total_entry_size + actual_total_section_size;
+ auto const expected_total_size = symbol->info.size;
+ auto const actual_total_entry_size = actual_entry_size * symbol->number_of_sections;
+ auto constexpr actual_total_section_size = sizeof(elf_symbols_section_header) - sizeof(uint32_t);
+ auto const actual_total_size = actual_total_entry_size + actual_total_section_size;
exception_handling::assert(expected_total_size == actual_total_size,
"[Multiboot Reader] Unexpected elf symbols section header total size");
- auto begin = elf_section_header_container::iterator{reinterpret_cast<elf_section_header *>(&symbol->end)};
- auto end = begin + symbol->number_of_sections;
+ 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, end};
- auto elf_section_with_lowest_virtual_address =
+ auto const elf_section_with_lowest_virtual_address =
std::ranges::min_element(container, [](elf_section_header const & a, elf_section_header const & b) {
return a.virtual_address < b.virtual_address;
});
- auto elf_section_with_highest_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) {
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 symbol_table_section_count = std::ranges::count_if(container, [](elf_section_header const & section) {
+ auto const symbol_table_section_count = std::ranges::count_if(container, [](elf_section_header const & section) {
return section.type == elf_section_type::DYNAMIC_SYMBOL_TABLE || section.type == elf_section_type::SYMBOL_TABLE;
});
- auto dynamic_section_count = std::ranges::count_if(
+ auto const dynamic_section_count = std::ranges::count_if(
container, [](elf_section_header const & section) { return section.type == elf_section_type::DYNAMIC; });
exception_handling::assert(
@@ -81,10 +81,10 @@ namespace teachos::arch::memory::multiboot
dynamic_section_count <= 1U,
"[Multiboot Reader] ELF Specifications allows only (1) or less dynamic sections, but got more");
- auto lowest_elf_section = *elf_section_with_lowest_virtual_address;
+ auto const lowest_elf_section = *elf_section_with_lowest_virtual_address;
kernel_start = lowest_elf_section.virtual_address;
- auto highest_elf_section = *elf_section_with_highest_virtual_address;
+ auto const highest_elf_section = *elf_section_with_highest_virtual_address;
kernel_end = highest_elf_section.virtual_address + highest_elf_section.section_size;
}
} // namespace
@@ -98,8 +98,8 @@ namespace teachos::arch::memory::multiboot
memory_area_container::iterator{},
memory_area_container::iterator{}};
- auto multiboot_information_pointer = reinterpret_cast<info_header *>(boot::multiboot_information_pointer);
- auto multiboot_tag = &multiboot_information_pointer->tags;
+ auto const multiboot_information_pointer = reinterpret_cast<info_header *>(boot::multiboot_information_pointer);
+ auto const multiboot_tag = &multiboot_information_pointer->tags;
mem_info.multiboot_end = mem_info.multiboot_start + multiboot_information_pointer->total_size;
for (auto tag = multiboot_tag; tag->type != tag_type::END; tag = align_to_8_byte_boundary(tag, tag->size))
@@ -107,12 +107,12 @@ namespace teachos::arch::memory::multiboot
switch (tag->type)
{
case tag_type::ELF_SECTIONS: {
- auto symbol = reinterpret_cast<elf_symbols_section_header *>(tag);
+ auto const symbol = reinterpret_cast<elf_symbols_section_header *>(tag);
process_elf_sections(symbol, mem_info.kernel_start, mem_info.kernel_end);
break;
}
case tag_type::MEMORY_MAP: {
- auto mminfo = reinterpret_cast<memory_map_header *>(tag);
+ auto const mminfo = reinterpret_cast<memory_map_header *>(tag);
process_memory_map(mminfo, mem_info.begin_area, mem_info.end_area);
break;
}
@@ -121,7 +121,6 @@ namespace teachos::arch::memory::multiboot
break;
}
}
-
return mem_info;
}
} // namespace teachos::arch::memory::multiboot