From 7fc99d55ffff20b49dc4088efc95b68b3d33a45b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 14 Oct 2024 09:47:49 +0000 Subject: Use scoped switch statements to extract calculations to variables --- arch/x86_64/src/kernel/main.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'arch/x86_64/src') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 1289eb6..1c6aa55 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -9,8 +9,13 @@ namespace teachos::arch::kernel { auto assert(bool condition) -> void { + if (condition) + { + return; + } + video::vga::text::write("Assert failed", video::vga::text::common_attributes::green_on_black); - while (!condition) + for (;;) { // Trick the compiler into thinking the variable is changes at run time, // to prevent the while loop being optimized away @@ -39,7 +44,6 @@ namespace teachos::arch::kernel auto process_elf_sections(arch::memory::elf_symbols_section * symbol, uint64_t & kernel_start, uint64_t & kernel_end) -> void { - // Validate ELF sections auto expected_entry_size = symbol->entry_size; constexpr auto actual_entry_size = sizeof(arch::memory::elf_section_header); assert(expected_entry_size == actual_entry_size); @@ -61,17 +65,18 @@ namespace teachos::arch::kernel { switch (section->type) { - case arch::memory::elf_section_type::PROGRAMM: + case arch::memory::elf_section_type::PROGRAMM: { if (section->virtual_address < kernel_start) { kernel_start = section->virtual_address; } - - if (section->virtual_address + section->section_size > kernel_end) + auto virtual_address_end = section->virtual_address + section->section_size; + if (virtual_address_end > kernel_end) { - kernel_end = section->virtual_address + section->section_size; + kernel_end = virtual_address_end; } break; + } case arch::memory::elf_section_type::DYNAMIC_SYMBOL_TABLE: case arch::memory::elf_section_type::SYMBOL_TABLE: symbol_table_section_count++; @@ -121,13 +126,16 @@ namespace teachos::arch::kernel { switch (tag->type) { - case arch::memory::multi_boot_tag_type::ELF_SECTIONS: - process_elf_sections(reinterpret_cast(tag), kernel_start, - kernel_end); + case arch::memory::multi_boot_tag_type::ELF_SECTIONS: { + auto symbol = reinterpret_cast(tag); + process_elf_sections(symbol, kernel_start, kernel_end); break; - case arch::memory::multi_boot_tag_type::MEMORY_MAP: - process_memory_map(reinterpret_cast(tag), memory_areas, area_count); + } + case arch::memory::multi_boot_tag_type::MEMORY_MAP: { + auto mminfo = reinterpret_cast(tag); + process_memory_map(mminfo, memory_areas, area_count); break; + } default: // All other cases are not important and can be ignored break; -- cgit v1.2.3