diff options
| author | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-10-14 09:47:49 +0000 |
|---|---|---|
| committer | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-10-14 09:47:49 +0000 |
| commit | 7fc99d55ffff20b49dc4088efc95b68b3d33a45b (patch) | |
| tree | 329f969f2ed11f24982b169ffcb3a4ef375eb6ce /arch/x86_64/src | |
| parent | 8beb8b758c33cf1ac5357b31296927e7df8cf971 (diff) | |
| download | teachos-7fc99d55ffff20b49dc4088efc95b68b3d33a45b.tar.xz teachos-7fc99d55ffff20b49dc4088efc95b68b3d33a45b.zip | |
Use scoped switch statements to extract calculations to variables
Diffstat (limited to 'arch/x86_64/src')
| -rw-r--r-- | arch/x86_64/src/kernel/main.cpp | 30 |
1 files changed, 19 insertions, 11 deletions
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<teachos::arch::memory::elf_symbols_section *>(tag), kernel_start, - kernel_end); + case arch::memory::multi_boot_tag_type::ELF_SECTIONS: { + auto symbol = reinterpret_cast<teachos::arch::memory::elf_symbols_section *>(tag); + process_elf_sections(symbol, kernel_start, kernel_end); break; - case arch::memory::multi_boot_tag_type::MEMORY_MAP: - process_memory_map(reinterpret_cast<teachos::arch::memory::memory_map *>(tag), memory_areas, area_count); + } + case arch::memory::multi_boot_tag_type::MEMORY_MAP: { + auto mminfo = reinterpret_cast<teachos::arch::memory::memory_map *>(tag); + process_memory_map(mminfo, memory_areas, area_count); break; + } default: // All other cases are not important and can be ignored break; |
