diff options
Diffstat (limited to 'libs/multiboot2')
| -rw-r--r-- | libs/multiboot2/CMakeLists.txt | 37 | ||||
| -rw-r--r-- | libs/multiboot2/multiboot2/constants.hpp (renamed from libs/multiboot2/include/multiboot2/constants.hpp) | 2 | ||||
| -rw-r--r-- | libs/multiboot2/multiboot2/constants/architecture_id.hpp (renamed from libs/multiboot2/include/multiboot2/constants/architecture_id.hpp) | 0 | ||||
| -rw-r--r-- | libs/multiboot2/multiboot2/constants/information_id.hpp (renamed from libs/multiboot2/include/multiboot2/constants/information_id.hpp) | 8 | ||||
| -rw-r--r-- | libs/multiboot2/multiboot2/constants/memory_type.hpp (renamed from libs/multiboot2/include/multiboot2/constants/memory_type.hpp) | 0 | ||||
| -rw-r--r-- | libs/multiboot2/multiboot2/constants/tag_id.hpp (renamed from libs/multiboot2/include/multiboot2/constants/tag_id.hpp) | 0 | ||||
| -rw-r--r-- | libs/multiboot2/multiboot2/information.hpp (renamed from libs/multiboot2/include/multiboot2/information.hpp) | 92 | ||||
| -rw-r--r-- | libs/multiboot2/multiboot2/information/data.hpp (renamed from libs/multiboot2/include/multiboot2/information/data.hpp) | 60 | ||||
| -rw-r--r-- | libs/multiboot2/multiboot2/information/iterator.hpp (renamed from libs/multiboot2/include/multiboot2/information/iterator.hpp) | 4 | ||||
| -rw-r--r-- | libs/multiboot2/multiboot2/information/tag.hpp (renamed from libs/multiboot2/include/multiboot2/information/tag.hpp) | 6 | ||||
| -rw-r--r-- | libs/multiboot2/test_data/mbi.bin | 3 |
11 files changed, 178 insertions, 34 deletions
diff --git a/libs/multiboot2/CMakeLists.txt b/libs/multiboot2/CMakeLists.txt index 350a996..5ab56db 100644 --- a/libs/multiboot2/CMakeLists.txt +++ b/libs/multiboot2/CMakeLists.txt @@ -1,27 +1,42 @@ +cmake_minimum_required(VERSION "3.27.0") + +project("multiboot2" + DESCRIPTION "Multiboot2 bootloader specification library" + VERSION "0.0.1" + LANGUAGES CXX +) + +include("CTest") + +#[============================================================================[ +# Library +#]============================================================================] + add_library("multiboot2" INTERFACE) -add_library("libs::multiboot2" ALIAS "multiboot2") +add_library("multiboot2::lib" ALIAS "multiboot2") + +file(GLOB_RECURSE MULTIBOOT2_HEADERS + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + CONFIGURE_DEPENDS + "include/**.hpp" +) target_sources("multiboot2" INTERFACE FILE_SET HEADERS BASE_DIRS "include" FILES - "include/multiboot2/constants.hpp" - "include/multiboot2/information.hpp" - - "include/multiboot2/impl/data.hpp" - "include/multiboot2/impl/ids.hpp" - "include/multiboot2/impl/iterator.hpp" - "include/multiboot2/impl/tag.hpp" + ${MULTIBOOT2_HEADERS} ) target_include_directories("multiboot2" INTERFACE - "include" + "${CMAKE_CURRENT_SOURCE_DIR}" ) target_link_libraries("multiboot2" INTERFACE - "libs::elf" + "elf::lib" + "kstd::lib" ) set_target_properties("multiboot2" PROPERTIES VERIFY_INTERFACE_HEADER_SETS YES -)
\ No newline at end of file +) diff --git a/libs/multiboot2/include/multiboot2/constants.hpp b/libs/multiboot2/multiboot2/constants.hpp index 2198210..57fa940 100644 --- a/libs/multiboot2/include/multiboot2/constants.hpp +++ b/libs/multiboot2/multiboot2/constants.hpp @@ -1,7 +1,7 @@ #ifndef MULTIBOOT2_CONSTANTS_HPP #define MULTIBOOT2_CONSTANTS_HPP -#include "constants/architecture_id.hpp" // IWYU pragma: export +#include <multiboot2/constants/architecture_id.hpp> // IWYU pragma: export #include <cstdint> diff --git a/libs/multiboot2/include/multiboot2/constants/architecture_id.hpp b/libs/multiboot2/multiboot2/constants/architecture_id.hpp index e13c471..e13c471 100644 --- a/libs/multiboot2/include/multiboot2/constants/architecture_id.hpp +++ b/libs/multiboot2/multiboot2/constants/architecture_id.hpp diff --git a/libs/multiboot2/include/multiboot2/constants/information_id.hpp b/libs/multiboot2/multiboot2/constants/information_id.hpp index be492eb..27c5300 100644 --- a/libs/multiboot2/include/multiboot2/constants/information_id.hpp +++ b/libs/multiboot2/multiboot2/constants/information_id.hpp @@ -57,10 +57,10 @@ namespace multiboot2 smbios_tables, //! A copy of RSDP as defined per ACPI 1.0 specification. - acpi_old_rsdp, + acpi_rsdp, - //! A copy of RSDP as defined per ACPI 2.0 or later specification. - acpi_new_rsdp, + //! A copy of XSDP as defined per ACPI 2.0 or later specification. + acpi_xsdp, //! The network information specified specified as per DHCP. networking_information, @@ -83,4 +83,4 @@ namespace multiboot2 } // namespace multiboot2 -#endif
\ No newline at end of file +#endif diff --git a/libs/multiboot2/include/multiboot2/constants/memory_type.hpp b/libs/multiboot2/multiboot2/constants/memory_type.hpp index 6be94bd..6be94bd 100644 --- a/libs/multiboot2/include/multiboot2/constants/memory_type.hpp +++ b/libs/multiboot2/multiboot2/constants/memory_type.hpp diff --git a/libs/multiboot2/include/multiboot2/constants/tag_id.hpp b/libs/multiboot2/multiboot2/constants/tag_id.hpp index 23d39cc..23d39cc 100644 --- a/libs/multiboot2/include/multiboot2/constants/tag_id.hpp +++ b/libs/multiboot2/multiboot2/constants/tag_id.hpp diff --git a/libs/multiboot2/include/multiboot2/information.hpp b/libs/multiboot2/multiboot2/information.hpp index 0f48835..f688fe5 100644 --- a/libs/multiboot2/include/multiboot2/information.hpp +++ b/libs/multiboot2/multiboot2/information.hpp @@ -1,18 +1,21 @@ #ifndef MULTIBOOT2_INFORMATION_HPP #define MULTIBOOT2_INFORMATION_HPP -#include "information/data.hpp" // IWYU pragma: export -#include "information/iterator.hpp" // IWYU pragma: export -#include "information/tag.hpp" // IWYU pragma: export - #include <elf/format.hpp> #include <elf/section_header.hpp> +#include <kstd/units> + +#include <multiboot2/information/data.hpp> // IWYU pragma: export +#include <multiboot2/information/iterator.hpp> // IWYU pragma: export +#include <multiboot2/information/tag.hpp> // IWYU pragma: export + #include <algorithm> #include <cstddef> #include <cstdint> #include <cstdlib> #include <optional> +#include <ranges> #include <span> #include <string_view> @@ -106,6 +109,47 @@ namespace multiboot2 } }; + /** + * @copydoc multiboot2::data::module + */ + struct module : vla_tag<data::module, char, std::basic_string_view> + { + using vla_tag::vla_tag; + + /** + * @brief The module command line or name. + */ + [[nodiscard]] auto string() const noexcept -> std::string_view + { + return {data(), vla_tag::size()}; + } + + [[nodiscard]] constexpr auto size() const noexcept -> kstd::units::bytes + { + return kstd::units::bytes{end_address - start_address}; + } + }; + + struct acpi_rsdp : vla_tag<data::acpi_rsdp, std::byte, std::span> + { + using vla_tag::vla_tag; + + [[nodiscard]] auto pointer() const noexcept -> range_type + { + return {data(), size()}; + } + }; + + struct acpi_xsdp : vla_tag<data::acpi_xsdp, std::byte, std::span> + { + using vla_tag::vla_tag; + + [[nodiscard]] auto pointer() const noexcept -> range_type + { + return {data(), size()}; + } + }; + struct information_view { using iterator = iterator; @@ -113,9 +157,9 @@ namespace multiboot2 using pointer = iterator::pointer; using reference = iterator::reference; - [[nodiscard]] auto size_bytes() const noexcept -> std::size_t + [[nodiscard]] auto size() const noexcept -> kstd::units::bytes { - return m_size; + return kstd::units::bytes{m_size}; } // Range access @@ -173,7 +217,7 @@ namespace multiboot2 { return get<multiboot2::elf_symbols<Format>>().and_then( [](auto x) -> std::optional<multiboot2::elf_symbols<Format>> { - if (x.entry_size == elf::section_header_size<Format>) + if (x.entry_size_in_B == elf::section_header_size<Format>) { return std::optional{x}; } @@ -210,6 +254,38 @@ namespace multiboot2 return maybe_memory_map().value(); } + [[nodiscard]] auto modules() const noexcept + { + auto filter_modules = [](auto const & tag) { + return tag.information_id() == module::id; + }; + auto transform_module = [](auto const & tag) { + return module{&tag}; + }; + return std::ranges::subrange(begin(), end()) | std::views::filter(filter_modules) | + std::views::transform(transform_module); + } + + [[nodiscard]] auto maybe_acpi_rsdp() const noexcept -> std::optional<acpi_rsdp> + { + return get<multiboot2::acpi_rsdp>(); + } + + [[nodiscard]] auto acpi_rsdp() const noexcept -> acpi_rsdp + { + return maybe_acpi_rsdp().value(); + } + + [[nodiscard]] auto maybe_acpi_xsdp() const noexcept -> std::optional<acpi_xsdp> + { + return get<multiboot2::acpi_xsdp>(); + } + + [[nodiscard]] auto acpi_xsdp() const noexcept -> acpi_xsdp + { + return maybe_acpi_xsdp().value(); + } + private: template<typename Tag> [[nodiscard]] constexpr auto get() const noexcept -> std::optional<Tag> @@ -229,4 +305,4 @@ namespace multiboot2 } // namespace multiboot2 -#endif
\ No newline at end of file +#endif diff --git a/libs/multiboot2/include/multiboot2/information/data.hpp b/libs/multiboot2/multiboot2/information/data.hpp index ccd8fbb..f39a6cb 100644 --- a/libs/multiboot2/include/multiboot2/information/data.hpp +++ b/libs/multiboot2/multiboot2/information/data.hpp @@ -3,8 +3,10 @@ // IWYU pragma: private, include <multiboot2/information.hpp> -#include "multiboot2/constants/information_id.hpp" -#include "multiboot2/constants/memory_type.hpp" +#include <kstd/units> + +#include <multiboot2/constants/information_id.hpp> +#include <multiboot2/constants/memory_type.hpp> #include <cstdint> @@ -27,6 +29,16 @@ namespace multiboot2 //! loader. struct basic_memory : tag_data<information_id::basic_memory_information> { + [[nodiscard]] constexpr auto lower() const noexcept -> kstd::units::bytes + { + return kstd::units::bytes{lower_KiB * 1024}; + } + + [[nodiscard]] constexpr auto upper() const noexcept -> kstd::units::bytes + { + return kstd::units::bytes{upper_KiB * 1024}; + } + //! The amount of lower memory available to the system. //! //! Any memory below the 1 MiB address boundary is considered to be lower memory. The maximum possible value for @@ -72,11 +84,16 @@ namespace multiboot2 //! time. The array begins after the last member of this structure. struct elf_symbols : tag_data<information_id::elf_sections> { + [[nodiscard]] constexpr auto entry_size() const noexcept -> kstd::units::bytes + { + return kstd::units::bytes{entry_size_in_B}; + } + //! The number of section header table entries. std::uint32_t count; //! The size of each section header table entry. - std::uint32_t entry_size; + std::uint32_t entry_size_in_B; //! The section number of the string table containing the section names. std::uint32_t string_table_index; @@ -102,6 +119,11 @@ namespace multiboot2 return type == memory_type::available; } + [[nodiscard]] constexpr auto size() const noexcept -> kstd::units::bytes + { + return kstd::units::bytes{size_in_B}; + } + //! The physical start address of this region std::uint64_t base; @@ -117,18 +139,46 @@ namespace multiboot2 std::uint32_t : 0; }; + [[nodiscard]] constexpr auto entry_size() const noexcept -> kstd::units::bytes + { + return kstd::units::bytes{entry_size_in_B}; + } + //! The size of each entry present in the map. //! //! This field is present to allow for future extension of the entry format. Each entry's size is guaranteed to //! always be an integer multiple of 8. - std::uint32_t entry_size; + std::uint32_t entry_size_in_B; //! The version of each entry present in the map std::uint32_t entry_version; }; + //! A module loaded by the bootloader. + //! + //! @note the command line associated with this module is not part of this structure, since it is of variable size + //! and the contained information starts at the end of this structure. + struct module : tag_data<information_id::module> + { + //! The physical start address of this module. + std::uint32_t start_address; + + //! The physical end address of this module. + std::uint32_t end_address; + }; + + //! A copy of the ACPI RSDP + struct acpi_rsdp : tag_data<information_id::acpi_rsdp> + { + }; + + //! A copy of the ACPI XSDP + struct acpi_xsdp : tag_data<information_id::acpi_xsdp> + { + }; + } // namespace data } // namespace multiboot2 -#endif
\ No newline at end of file +#endif diff --git a/libs/multiboot2/include/multiboot2/information/iterator.hpp b/libs/multiboot2/multiboot2/information/iterator.hpp index 62c267d..bded43e 100644 --- a/libs/multiboot2/include/multiboot2/information/iterator.hpp +++ b/libs/multiboot2/multiboot2/information/iterator.hpp @@ -3,8 +3,8 @@ // IWYU pragma: private, include <multiboot2/information.hpp> -#include "multiboot2/constants/information_id.hpp" -#include "tag.hpp" +#include <multiboot2/constants/information_id.hpp> +#include <multiboot2/information/tag.hpp> #include <cstddef> #include <iterator> diff --git a/libs/multiboot2/include/multiboot2/information/tag.hpp b/libs/multiboot2/multiboot2/information/tag.hpp index cd1fc0e..0c29299 100644 --- a/libs/multiboot2/include/multiboot2/information/tag.hpp +++ b/libs/multiboot2/multiboot2/information/tag.hpp @@ -3,7 +3,7 @@ // IWYU pragma: private, include <multiboot2/information.hpp> -#include "multiboot2/constants/information_id.hpp" +#include <multiboot2/constants/information_id.hpp> #include <bit> #include <cstddef> @@ -172,9 +172,9 @@ namespace multiboot2 return m_vla.data(); } - [[nodiscard]] auto at() const -> const_reference + [[nodiscard]] auto at(std::size_t index) const -> const_reference { - return m_vla.at(); + return m_vla.at(index); } [[nodiscard]] auto operator[](std::size_t index) const noexcept -> const_reference diff --git a/libs/multiboot2/test_data/mbi.bin b/libs/multiboot2/test_data/mbi.bin new file mode 100644 index 0000000..4985526 --- /dev/null +++ b/libs/multiboot2/test_data/mbi.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3b67ca95183fde8e7dc8dac2d20af9331122128127926ebe6f8bd80ca9fed7c3 +size 1176 |
