aboutsummaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorFabian Imhof <fabian.imhof@ost.ch>2024-10-08 09:52:17 +0000
committerFabian Imhof <fabian.imhof@ost.ch>2024-10-08 09:52:17 +0000
commitbb2089599007fb5e25e613e67088a05731df4347 (patch)
tree77deff9406e9ace63476c8909fde2b04d7364476 /arch
parent8773024d1b4e756fe5d3494479247c64c7ad8491 (diff)
parenta6018f84cc8971859d90109740fbada8d77ff5a9 (diff)
downloadteachos-bb2089599007fb5e25e613e67088a05731df4347.tar.xz
teachos-bb2089599007fb5e25e613e67088a05731df4347.zip
Merge branch 'feat_memory_manager' of ssh://gitlab.ost.ch:45022/teachos/kernel into feat_memory_manager
Diffstat (limited to 'arch')
-rw-r--r--arch/x86_64/include/arch/memory/multiboot.hpp46
-rw-r--r--arch/x86_64/src/kernel/main.cpp19
2 files changed, 49 insertions, 16 deletions
diff --git a/arch/x86_64/include/arch/memory/multiboot.hpp b/arch/x86_64/include/arch/memory/multiboot.hpp
index 37b10f0..f6ff480 100644
--- a/arch/x86_64/include/arch/memory/multiboot.hpp
+++ b/arch/x86_64/include/arch/memory/multiboot.hpp
@@ -124,40 +124,43 @@ namespace teachos::arch::memory
// Nothing to do
}
- auto writeable() -> bool { return is_bit_set(0); }
+ auto writeable() const -> bool { return is_bit_set(0); }
- auto occupies_memory() -> bool { return is_bit_set(1); }
+ auto occupies_memory() const -> bool { return is_bit_set(1); }
- auto is_executable() -> bool { return is_bit_set(2); }
+ auto is_executable() const -> bool { return is_bit_set(2); }
- auto contains_duplicate_data() -> bool { return is_bit_set(4); }
+ auto contains_duplicate_data() const -> bool { return is_bit_set(4); }
- auto contains_strings() -> bool { return is_bit_set(5); }
+ auto contains_strings() const -> bool { return is_bit_set(5); }
- auto section_header_info_is_section_header_table_index() -> bool { return is_bit_set(6); }
+ auto section_header_info_is_section_header_table_index() const -> bool { return is_bit_set(6); }
- auto preserve_ordering_after_combination() -> bool { return is_bit_set(7); }
+ auto preserve_ordering_after_combination() const -> bool { return is_bit_set(7); }
- auto requires_special_os_processing() -> bool { return is_bit_set(8); }
+ auto requires_special_os_processing() const -> bool { return is_bit_set(8); }
- auto is_section_group_member() -> bool { return is_bit_set(9); }
+ auto is_section_group_member() const -> bool { return is_bit_set(9); }
- auto holds_thread_local_data() -> bool { return is_bit_set(10); }
+ auto holds_thread_local_data() const -> bool { return is_bit_set(10); }
- auto is_compressed() -> bool { return is_bit_set(11); }
+ auto is_compressed() const -> bool { return is_bit_set(11); }
- auto has_special_ordering_requirements() -> bool { return is_bit_set(30); }
+ auto has_special_ordering_requirements() const -> bool { return is_bit_set(30); }
- auto is_excluded_unless_referenced_or_allocated() -> bool { return is_bit_set(31); }
+ auto is_excluded_unless_referenced_or_allocated() const -> bool { return is_bit_set(31); }
+
+ auto operator==(elf_section_flags const & other) const -> bool { return flags == other.flags; }
private:
- auto is_bit_set(uint8_t index) -> bool { return flags[index] == 1; }
+ auto is_bit_set(uint8_t index) const -> bool { return flags[index] == 1; }
std::bitset<64U> flags;
};
/**
- * https://docs.oracle.com/cd/E19455-01/806-3773/elf-2/index.html
+ * @brief Defines the data included in a section header, where each section has exactly one section header.
+ * See https://refspecs.linuxbase.org/elf/gabi4+/ch4.sheader.html for more information
*/
struct elf_section_header
{
@@ -171,6 +174,19 @@ namespace teachos::arch::memory
uint32_t additional_information;
uint64_t address_alignment;
uint64_t fixed_table_entry_size;
+
+ /**
+ * @brief Detect whether e section header is inactive or not, should always be the case for the first entry in the
+ * sections table
+ * @return Whether the current section header is actually null or not, requires all fields besides section_size and
+ * other_section to actually contain 0
+ */
+ auto is_null() const -> bool
+ {
+ return name_table_index == 0U && type == elf_section_type::UNSPECIFIED && flags == 0U && virtual_address == 0U &&
+ file_offset == 0U && additional_information == 0U && address_alignment == 0U &&
+ fixed_table_entry_size == 0U;
+ }
};
/**
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);