diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2025-10-30 15:59:48 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2025-10-30 15:59:48 +0100 |
| commit | 78f0df1cf849af8b0ade40a8ebcffd7fb53635cb (patch) | |
| tree | 1ceab6b4f2f518a32da5c12d0939637c7fbdd7e7 | |
| parent | 5e9b7dd3dbc194ffa583e9efaab1aef1b6792d97 (diff) | |
| download | teachos-78f0df1cf849af8b0ade40a8ebcffd7fb53635cb.tar.xz teachos-78f0df1cf849af8b0ade40a8ebcffd7fb53635cb.zip | |
libs: begin ELF support implementation
| -rw-r--r-- | .clang-format | 10 | ||||
| -rw-r--r-- | cmake/Platforms/x86_64.cmake | 2 | ||||
| -rw-r--r-- | libs/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | libs/elf/CMakeLists.txt | 19 | ||||
| -rw-r--r-- | libs/elf/include/elf/format.hpp | 15 | ||||
| -rw-r--r-- | libs/elf/include/elf/section_header.hpp | 23 | ||||
| -rw-r--r-- | libs/multiboot2/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | libs/multiboot2/include/multiboot2/information.hpp | 25 |
8 files changed, 89 insertions, 14 deletions
diff --git a/.clang-format b/.clang-format index 6d3fa9d..a47e396 100644 --- a/.clang-format +++ b/.clang-format @@ -55,13 +55,15 @@ DerivePointerAlignment: "false" FixNamespaceComments: "true" IncludeBlocks: Regroup IncludeCategories: - - Regex: kapi/[[:alnum:]._\/]+\.hpp + - Regex: 'kapi/[[:alnum:]._\/]+\.hpp' Priority: 100 - - Regex: x86_64/[[:alnum:]._\/]+\.hpp + - Regex: 'x86_64/[[:alnum:]._\/]+\.hpp' Priority: 110 - - Regex: "[[:alnum:]._\\/]+\\.hpp" + - Regex: '"[[:alnum:]._\/]+\.hpp"' Priority: 300 - - Regex: <[[:alnum:]._]+(?!\.(h|hpp))> + - Regex: '<[[:alnum:]._\/]+\.hpp>' + Priority: 600 + - Regex: '<[[:alnum:]._]+(?!\.(h|hpp))>' Priority: 900 IndentCaseLabels: "true" IndentPPDirectives: None diff --git a/cmake/Platforms/x86_64.cmake b/cmake/Platforms/x86_64.cmake index 23287de..b17fec8 100644 --- a/cmake/Platforms/x86_64.cmake +++ b/cmake/Platforms/x86_64.cmake @@ -10,7 +10,7 @@ set(CMAKE_SYSTEM_PROCESSOR "x86_64") set(CMAKE_ASM_COMPILER_TARGET "${PLATFORM_TARGET}") set(CMAKE_CXX_COMPILER_TARGET "${PLATFORM_TARGET}") -find_program(CMAKE_ASM_COMPILER "${CMAKE_ASM_COMPILER_TARGET}-gcc" REQUIRED) +find_program(CMAKE_ASM_COMPILER "${CMAKE_ASM_COMPILER_TARGET}-g++" REQUIRED) find_program(CMAKE_CXX_COMPILER "${CMAKE_CXX_COMPILER_TARGET}-g++" REQUIRED) set(CMAKE_CXX_FLAGS_INIT diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index b2dbf86..58d9796 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -1,2 +1,3 @@ +add_subdirectory("elf" EXCLUDE_FROM_ALL SYSTEM) add_subdirectory("kstd" EXCLUDE_FROM_ALL SYSTEM) add_subdirectory("multiboot2" EXCLUDE_FROM_ALL SYSTEM)
\ No newline at end of file diff --git a/libs/elf/CMakeLists.txt b/libs/elf/CMakeLists.txt new file mode 100644 index 0000000..66e59ee --- /dev/null +++ b/libs/elf/CMakeLists.txt @@ -0,0 +1,19 @@ +add_library("elf" INTERFACE) +add_library("libs::elf" ALIAS "elf") + +target_sources("elf" INTERFACE + FILE_SET HEADERS + BASE_DIRS "include" + FILES + "include/elf/format.hpp" + "include/elf/section_header.hpp" + +) + +target_include_directories("elf" INTERFACE + "include" +) + +set_target_properties("elf" PROPERTIES + VERIFY_INTERFACE_HEADER_SETS YES +)
\ No newline at end of file diff --git a/libs/elf/include/elf/format.hpp b/libs/elf/include/elf/format.hpp new file mode 100644 index 0000000..b3220f5 --- /dev/null +++ b/libs/elf/include/elf/format.hpp @@ -0,0 +1,15 @@ +#ifndef ELF_FORMAT_HPP +#define ELF_FORMAT_HPP + +namespace elf +{ + + enum struct format + { + elf32, + elf64, + }; + +} // namespace elf + +#endif
\ No newline at end of file diff --git a/libs/elf/include/elf/section_header.hpp b/libs/elf/include/elf/section_header.hpp new file mode 100644 index 0000000..0ff5e4b --- /dev/null +++ b/libs/elf/include/elf/section_header.hpp @@ -0,0 +1,23 @@ +#ifndef ELF_SECTION_HEADER_HPP +#define ELF_SECTION_HEADER_HPP + +#include "format.hpp" + +#include <cstdint> + +namespace elf +{ + + enum struct section_header_type : std::uint32_t + { + }; + + template<format Format> + struct section_header + { + std::uint32_t name_offset; + section_header_type type; + }; +} // namespace elf + +#endif
\ No newline at end of file diff --git a/libs/multiboot2/CMakeLists.txt b/libs/multiboot2/CMakeLists.txt index 7b9e58a..350a996 100644 --- a/libs/multiboot2/CMakeLists.txt +++ b/libs/multiboot2/CMakeLists.txt @@ -17,3 +17,11 @@ target_sources("multiboot2" INTERFACE target_include_directories("multiboot2" INTERFACE "include" ) + +target_link_libraries("multiboot2" INTERFACE + "libs::elf" +) + +set_target_properties("multiboot2" PROPERTIES + VERIFY_INTERFACE_HEADER_SETS YES +)
\ No newline at end of file diff --git a/libs/multiboot2/include/multiboot2/information.hpp b/libs/multiboot2/include/multiboot2/information.hpp index ac03069..d2b4c98 100644 --- a/libs/multiboot2/include/multiboot2/information.hpp +++ b/libs/multiboot2/include/multiboot2/information.hpp @@ -5,6 +5,9 @@ #include "impl/iterator.hpp" #include "impl/tag.hpp" +#include <elf/format.hpp> +#include <elf/section_header.hpp> + #include <algorithm> #include <cstddef> #include <cstdint> @@ -50,15 +53,17 @@ namespace multiboot2 /** * @copydoc multiboot2::impl::elf_symbols_data */ - struct elf_symbols : impl::vla_tag<impl::elf_symbols_data, std::byte const, std::span> + template<elf::format Format> + struct elf_symbols : impl::vla_tag<impl::elf_symbols_data, elf::section_header<Format> const, std::span> { - using vla_tag::vla_tag; + using base = impl::vla_tag<impl::elf_symbols_data, elf::section_header<Format> const, std::span>; + using base::base; - using iterator = range_type::iterator; + using iterator = base::range_type::iterator; - auto data() const noexcept -> range_type + auto data() const noexcept -> base::range_type { - return m_vla; + return this->m_vla; } }; @@ -168,14 +173,16 @@ namespace multiboot2 return maybe_command_line().value(); } - auto maybe_elf_symbols() const noexcept -> std::optional<elf_symbols> + template<elf::format Format> + auto maybe_elf_symbols() const noexcept -> std::optional<elf_symbols<Format>> { - return get<multiboot2::elf_symbols>(); + return get<multiboot2::elf_symbols<Format>>(); } - auto elf_symbols() const -> elf_symbols + template<elf::format Format> + auto elf_symbols() const -> elf_symbols<Format> { - return maybe_elf_symbols().value(); + return maybe_elf_symbols<Format>().value(); } auto maybe_loader_name() const noexcept -> std::optional<loader_name> |
