aboutsummaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-06 12:40:33 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-06 12:40:33 +0000
commitb9c5aea495653bb9fc347fa6ba5976b42510af53 (patch)
tree139f3c8d4959d91f380e903f5dd05220cbc3e765 /arch
parent241c17a52e3954a6c1cf8d38f402d240070a5818 (diff)
downloadteachos-b9c5aea495653bb9fc347fa6ba5976b42510af53.tar.xz
teachos-b9c5aea495653bb9fc347fa6ba5976b42510af53.zip
Added elf section type enum
Diffstat (limited to 'arch')
-rw-r--r--arch/x86_64/include/arch/memory/multiboot.hpp70
-rw-r--r--arch/x86_64/src/kernel/main.cpp8
2 files changed, 43 insertions, 35 deletions
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 <bitset>
#include <cstdint>
namespace teachos::arch::memory
@@ -90,48 +91,51 @@ namespace teachos::arch::memory
struct memory_area entries;
};
- /* ELF standard typedefs (yet more proof that <stdint.h> 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)