From b9c5aea495653bb9fc347fa6ba5976b42510af53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 6 Oct 2024 12:40:33 +0000 Subject: Added elf section type enum --- arch/x86_64/include/arch/memory/multiboot.hpp | 70 ++++++++++++++------------- arch/x86_64/src/kernel/main.cpp | 8 ++- 2 files changed, 43 insertions(+), 35 deletions(-) (limited to 'arch/x86_64') diff --git a/arch/x86_64/include/arch/memory/multiboot.hpp b/arch/x86_64/include/arch/memory/multiboot.hpp index a2d6e9d..c808213 100644 --- a/arch/x86_64/include/arch/memory/multiboot.hpp +++ b/arch/x86_64/include/arch/memory/multiboot.hpp @@ -1,6 +1,7 @@ #ifndef TEACHOS_ARCH_X86_64_MEMORY_MULTIBOOT_HPP #define TEACHOS_ARCH_X86_64_MEMORY_MULTIBOOT_HPP +#include #include namespace teachos::arch::memory @@ -90,48 +91,51 @@ namespace teachos::arch::memory struct memory_area entries; }; - /* ELF standard typedefs (yet more proof that was way overdue) */ - typedef uint16_t Elf64_Half; - typedef int16_t Elf64_SHalf; - typedef uint32_t Elf64_Word; - typedef int32_t Elf64_Sword; - typedef uint64_t Elf64_Xword; - typedef int64_t Elf64_Sxword; - - typedef uint64_t Elf64_Off; - typedef uint64_t Elf64_Addr; - typedef uint16_t Elf64_Section; - - struct elf_section_header + /** + * https://refspecs.linuxfoundation.org/LSB_2.1.0/LSB-Core-generic/LSB-Core-generic/elftypes.html + */ + enum class elf_section_type : uint32_t { - Elf64_Word sh_name; /* Section name (string tbl index) */ - Elf64_Word sh_type; /* Section type */ - Elf64_Xword sh_flags; /* Section flags */ - Elf64_Addr sh_addr; /* Section virtual addr at execution */ - Elf64_Off sh_offset; /* Section file offset */ - Elf64_Xword sh_size; /* Section size in bytes */ - Elf64_Word sh_link; /* Link to another section */ - Elf64_Word sh_info; /* Additional section information */ - Elf64_Xword sh_addralign; /* Section alignment */ - Elf64_Xword sh_entsize; /* Entry size if section holds table */ + INACTIVE, + PROGRAMM, + SYMBOL_TABLE, + STRING_TABLE, + RELOCATION_ENTRY_WITH_EXPLICIT_ADDENDS, + SYMBOL_HASH_TABLE, + DYNAMIC, + NOTE, + EMPTY, + RELOCATION_ENTRY_WITHOUT_EXPLICIT_ADDENDS, + UNSPECIFIED, + DYNAMIC_SYMBOL, + INITALIZATION_FUNCTION_ARRAY = 14, + TERMINATION_FUNCTION_ARRAY, + PRE_INITALIZATION_FUNCTION_ARRAY }; - struct elf_symbol + struct elf_section_header { - Elf64_Word st_name; /* Symbol name (string tbl index) */ - unsigned char st_info; /* Symbol type and binding */ - unsigned char st_other; /* Symbol visibility */ - Elf64_Section st_shndx; /* Section index */ - Elf64_Addr st_value; /* Symbol value */ - Elf64_Xword st_size; /* Symbol size */ + uint32_t sh_name; /* Section name (string tbl index) */ + elf_section_type sh_type; /* Section type */ + std::bitset<64U> sh_flags; /* Section flags */ + uint64_t sh_addr; /* Section virtual addr at execution */ + uint64_t sh_offset; /* Section file offset */ + uint64_t sh_size; /* Section size in bytes */ + uint32_t sh_link; /* Link to another section */ + uint32_t sh_info; /* Additional section information */ + uint64_t sh_addralign; /* Section alignment */ + uint64_t sh_entsize; /* Entry size if section holds table */ }; + /** + * https://gist.github.com/x0nu11byt3/bcb35c3de461e5fb66173071a2379779 + */ struct elf_symbols_section { multi_boot_tag tag; - uint16_t num; - uint16_t entsize; - uint16_t shndx; + uint32_t num; + uint32_t entsize; + uint32_t shndx; alignas(8) struct elf_section_header sections; }; } // namespace teachos::arch::memory diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index fa1e464..481264c 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -24,8 +24,8 @@ namespace teachos::arch::kernel auto print_memory_map(arch::memory::memory_map * mminfo) -> void { auto expected_entry_size = mminfo->entry_size; - constexpr auto actual_size = sizeof(arch::memory::memory_area); - assert(expected_entry_size == actual_size); + constexpr auto actual_entry_size = sizeof(arch::memory::memory_area); + assert(expected_entry_size == actual_entry_size); auto remaining_size = mminfo->tag.size - (4 * sizeof(uint32_t)); auto entry_amount = remaining_size / mminfo->entry_size; @@ -40,6 +40,10 @@ namespace teachos::arch::kernel auto print_elf_sections(arch::memory::elf_symbols_section * symbol) -> void { + auto expected_entry_size = symbol->entsize; + constexpr auto actual_entry_size = sizeof(arch::memory::elf_section_header); + assert(expected_entry_size == actual_entry_size); + auto begin = &symbol->sections; auto end = begin + symbol->num; for (auto section = begin; section != end; ++section) -- cgit v1.2.3