aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/kernel/main.cpp
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-08 07:58:53 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-08 07:58:53 +0000
commita6018f84cc8971859d90109740fbada8d77ff5a9 (patch)
tree5e56b194730e4cb9579c8679f9a763672b8136ff /arch/x86_64/src/kernel/main.cpp
parent78153377d8a964d6b7290d966e5c1d30369abc2c (diff)
downloadteachos-a6018f84cc8971859d90109740fbada8d77ff5a9.tar.xz
teachos-a6018f84cc8971859d90109740fbada8d77ff5a9.zip
Add more asserts for elf sections
Diffstat (limited to 'arch/x86_64/src/kernel/main.cpp')
-rw-r--r--arch/x86_64/src/kernel/main.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp
index 636ddf2..2ba4fe2 100644
--- a/arch/x86_64/src/kernel/main.cpp
+++ b/arch/x86_64/src/kernel/main.cpp
@@ -11,7 +11,12 @@ namespace teachos::arch::kernel
video::vga::text::write("Assert failed", video::vga::text::common_attributes::green_on_black);
while (!condition)
{
- ;
+ // Trick the compiler into thinking the variable is changes at run time,
+ // to prevent the while loop being optimized away
+ // See
+ // https://stackoverflow.com/questions/9495856/how-to-prevent-g-from-optimizing-out-a-loop-controlled-by-a-variable-that-can
+ // for mroe information.
+ asm volatile("" : "+g"(condition));
}
}
@@ -44,8 +49,20 @@ namespace teachos::arch::kernel
constexpr auto actual_entry_size = sizeof(arch::memory::elf_section_header);
assert(expected_entry_size == actual_entry_size);
+ auto expected_total_size = symbol->tag.size;
+ auto actual_total_entry_size = actual_entry_size * symbol->number_of_sections;
+ constexpr auto actual_total_section_size =
+ sizeof(arch::memory::elf_symbols_section) - actual_entry_size - sizeof(uint32_t);
+ auto actual_total_size = actual_total_entry_size + actual_total_section_size;
+ assert(expected_total_size == actual_total_size);
+
auto begin = &symbol->sections;
auto end = begin + symbol->number_of_sections;
+ // TODO: Last value is completly wrong, should show 0 but shows huge value for size of entries in the table of the
+ // SHT_NULL elf section entry. Memory around value also make no sense and look even worse? But according to api
+ // value should be zero :(
+ // assert(begin->is_null());
+
for (auto section = begin; section != end; ++section)
{
video::vga::text::write("Looping Code section", video::vga::text::common_attributes::green_on_black);