From 951b314b655781dc59aee24cf952d03bf3b3ee83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 6 Oct 2024 13:32:14 +0000 Subject: Interpret files as bitset wrapper --- arch/x86_64/include/arch/memory/multiboot.hpp | 64 ++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 10 deletions(-) (limited to 'arch/x86_64/include') diff --git a/arch/x86_64/include/arch/memory/multiboot.hpp b/arch/x86_64/include/arch/memory/multiboot.hpp index c808213..f1f0613 100644 --- a/arch/x86_64/include/arch/memory/multiboot.hpp +++ b/arch/x86_64/include/arch/memory/multiboot.hpp @@ -113,18 +113,62 @@ namespace teachos::arch::memory PRE_INITALIZATION_FUNCTION_ARRAY }; + /** + * https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-94076/index.html + */ + class elf_section_flags + { + public: + elf_section_flags(uint64_t flags) + : flags(flags) + { + // Nothing to do + } + + auto writeable() -> bool { return is_bit_set(0); } + + auto occupies_memory() -> bool { return is_bit_set(1); } + + auto is_executable() -> bool { return is_bit_set(2); } + + auto contains_duplicate_data() -> bool { return is_bit_set(4); } + + auto contains_strings() -> bool { return is_bit_set(5); } + + auto section_header_info_is_section_header_table_index() -> bool { return is_bit_set(6); } + + auto preserve_ordering_after_combination() -> bool { return is_bit_set(7); } + + auto requires_special_os_processing() -> bool { return is_bit_set(8); } + + auto is_section_group_member() -> bool { return is_bit_set(9); } + + auto holds_thread_local_data() -> bool { return is_bit_set(10); } + + auto is_compressed() -> bool { return is_bit_set(11); } + + auto has_special_ordering_requirements() -> bool { return is_bit_set(30); } + + auto is_excluded_unless_referenced_or_allocated() -> bool { return is_bit_set(31); } + + private: + auto is_bit_set(uint8_t index) -> bool { return flags[index] == 1; } + + std::bitset<64U> flags; + }; + struct elf_section_header { - 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 */ + uint32_t sh_name; /* Section name (string tbl index) */ + elf_section_type sh_type; /* Section type */ + elf_section_flags 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 */ }; /** -- cgit v1.2.3