From 035c8d6e38fd901e6769a81f67b8d9e1e3fcea20 Mon Sep 17 00:00:00 2001 From: Lukas Oesch Date: Thu, 26 Feb 2026 11:24:27 +0100 Subject: implemented boot_modules and boot_module_registry, init boot_modules in kernel main --- kapi/CMakeLists.txt | 3 + kapi/include/kapi/boot_module/boot_module.hpp | 21 ++++ .../kapi/boot_module/boot_module_registry.hpp | 108 +++++++++++++++++++++ kapi/include/kapi/boot_modules.hpp | 25 +++++ 4 files changed, 157 insertions(+) create mode 100644 kapi/include/kapi/boot_module/boot_module.hpp create mode 100644 kapi/include/kapi/boot_module/boot_module_registry.hpp create mode 100644 kapi/include/kapi/boot_modules.hpp (limited to 'kapi') diff --git a/kapi/CMakeLists.txt b/kapi/CMakeLists.txt index 5e914bb..028cdbb 100644 --- a/kapi/CMakeLists.txt +++ b/kapi/CMakeLists.txt @@ -5,8 +5,11 @@ target_sources("kapi" PUBLIC FILE_SET HEADERS BASE_DIRS "include" FILES + "include/kapi/boot_modules.hpp" "include/kapi/boot.hpp" "include/kapi/cio.hpp" + "include/kapi/boot_module/boot_module.hpp" + "include/kapi/boot_module/boot_module_registry.hpp" "include/kapi/memory.hpp" "include/kapi/memory/address.hpp" "include/kapi/memory/frame_allocator.hpp" diff --git a/kapi/include/kapi/boot_module/boot_module.hpp b/kapi/include/kapi/boot_module/boot_module.hpp new file mode 100644 index 0000000..f2d97ae --- /dev/null +++ b/kapi/include/kapi/boot_module/boot_module.hpp @@ -0,0 +1,21 @@ +#ifndef TEACHOS_KAPI_BOOT_MODULE_BOOT_MODULE_HPP +#define TEACHOS_KAPI_BOOT_MODULE_BOOT_MODULE_HPP + +#include +#include + +namespace kapi::boot_modules +{ + // ! The boot module struct + // ! + // ! The boot module struct represents a module loaded by the bootloader, and contains information about it, such as + // ! its name, virtual start address, and size. + struct boot_module + { + std::string_view name; + size_t start_address; + size_t size; + }; +} // namespace kapi::boot_modules + +#endif \ No newline at end of file diff --git a/kapi/include/kapi/boot_module/boot_module_registry.hpp b/kapi/include/kapi/boot_module/boot_module_registry.hpp new file mode 100644 index 0000000..3732a5f --- /dev/null +++ b/kapi/include/kapi/boot_module/boot_module_registry.hpp @@ -0,0 +1,108 @@ +#ifndef TEACHOS_KAPI_BOOT_MODULE_BOOT_MODULE_REGISTRY_HPP +#define TEACHOS_KAPI_BOOT_MODULE_BOOT_MODULE_REGISTRY_HPP + +#include "kapi/boot_module/boot_module.hpp" + +#include +#include + +namespace kapi::boot_modules +{ + + // ! The interface of the boot module registry + // ! + // ! The boot module registry is responsible for keeping track of the modules loaded by the bootloader, and + // ! providing access to them for the rest of the kernel. + struct boot_module_registry + { + using range_type = std::array; // TODO BA-FS26 use kstd::vector when available + + using value_type = range_type::value_type; + using const_reference = range_type::const_reference; + + using const_iterator = range_type::const_iterator; + using const_reverse_iterator = range_type::const_reverse_iterator; + using size_type = range_type::size_type; + using difference_type = range_type::difference_type; + + [[nodiscard]] auto begin() const noexcept -> const_iterator + { + return m_modules.begin(); + } + + [[nodiscard]] auto end() const noexcept -> const_iterator + { + return m_modules.end(); + } + + [[nodiscard]] auto cbegin() const noexcept -> const_iterator + { + return begin(); + } + + [[nodiscard]] auto cend() const noexcept -> const_iterator + { + return end(); + } + + [[nodiscard]] auto rbegin() const noexcept -> const_reverse_iterator + { + return m_modules.rbegin(); + } + + [[nodiscard]] auto rend() const noexcept -> const_reverse_iterator + { + return m_modules.rend(); + } + + [[nodiscard]] auto crbegin() const noexcept -> const_reverse_iterator + { + return rbegin(); + } + + [[nodiscard]] auto crend() const noexcept -> const_reverse_iterator + { + return rend(); + } + + [[nodiscard]] auto front() const noexcept -> const_reference + { + return m_modules.front(); + } + + [[nodiscard]] auto back() const noexcept -> const_reference + { + return m_modules.back(); + } + + [[nodiscard]] auto size() const noexcept -> std::size_t + { + return m_modules.size(); + } + + [[nodiscard]] auto empty() const noexcept -> bool + { + return m_modules.empty(); + } + + [[nodiscard]] auto at(std::size_t index) const -> const_reference + { + return m_modules.at(index); + } + + [[nodiscard]] auto operator[](std::size_t index) const noexcept -> const_reference + { + return m_modules[index]; + } + + auto add_boot_module(boot_module module) -> void + { + m_modules.at(0) = module; // TODO BA-FS26 push back when kstd::vector is available + } + + private: + range_type m_modules{}; + }; +} // namespace kapi::boot_modules + +#endif \ No newline at end of file diff --git a/kapi/include/kapi/boot_modules.hpp b/kapi/include/kapi/boot_modules.hpp new file mode 100644 index 0000000..752b070 --- /dev/null +++ b/kapi/include/kapi/boot_modules.hpp @@ -0,0 +1,25 @@ +#ifndef TEACHOS_KAPI_BOOT_MODULES_HPP +#define TEACHOS_KAPI_BOOT_MODULES_HPP + +#include "kapi/boot_module/boot_module_registry.hpp" // IWYU pragma: export + +namespace kapi::boot_modules +{ + + //! @qualifier platform-defined + //! Initialize the boot module registry. + //! + //! @note This function must be implemented by the target platform. + //! + //! This function initializes the boot module registry, which is responsible for keeping track of the modules loaded + //! by the bootloader, and providing access to them for the rest of the kernel. + auto init() -> void; + + //! @qualifier kernel-defined + //! Set the boot module registry + //! + //! @param registry A new boot module registry. + auto set_boot_module_registry(boot_module_registry & registry) -> void; + +} // namespace kapi::boot_modules +#endif \ No newline at end of file -- cgit v1.2.3