diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-07-24 19:27:20 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-07-24 19:27:20 +0200 |
| commit | 3d09b0bd2c35740b34b87c1400e0a3d93647a5d2 (patch) | |
| tree | 3722c12441ef14e824fa192055cc86c785667ee6 /kapi | |
| parent | 65ba51c7fdcf09dce6b1d690fe059e71d026d1a6 (diff) | |
| download | kernel-3d09b0bd2c35740b34b87c1400e0a3d93647a5d2.tar.xz kernel-3d09b0bd2c35740b34b87c1400e0a3d93647a5d2.zip | |
kapi: extract real boot module registry singleton
Diffstat (limited to 'kapi')
| -rw-r--r-- | kapi/kapi/boot_modules.hpp | 18 | ||||
| -rw-r--r-- | kapi/kapi/boot_modules/boot_module_registry.hpp | 109 | ||||
| -rw-r--r-- | kapi/kapi/boot_modules/bus.hpp | 6 | ||||
| -rw-r--r-- | kapi/kapi/boot_modules/registry.hpp | 76 | ||||
| -rw-r--r-- | kapi/kapi/test_support/boot_modules.hpp | 17 |
5 files changed, 99 insertions, 127 deletions
diff --git a/kapi/kapi/boot_modules.hpp b/kapi/kapi/boot_modules.hpp index 18995303..49a83ef5 100644 --- a/kapi/kapi/boot_modules.hpp +++ b/kapi/kapi/boot_modules.hpp @@ -1,9 +1,9 @@ #ifndef TEACHOS_KAPI_BOOT_MODULES_HPP #define TEACHOS_KAPI_BOOT_MODULES_HPP -#include <kapi/boot_modules/boot_module.hpp> // IWYU pragma: export -#include <kapi/boot_modules/boot_module_registry.hpp> // IWYU pragma: export -#include <kapi/boot_modules/bus.hpp> // IWYU pragma: export +#include <kapi/boot_modules/boot_module.hpp> // IWYU pragma: export +#include <kapi/boot_modules/bus.hpp> // IWYU pragma: export +#include <kapi/boot_modules/registry.hpp> // IWYU pragma: export namespace kapi::boot_modules { @@ -17,17 +17,5 @@ namespace kapi::boot_modules //! 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; - - //! @qualifier kernel-defined - //! Get the boot module registry. - //! - //! @returns The boot module registry. - auto get_boot_module_registry() -> boot_module_registry const &; - } // namespace kapi::boot_modules #endif
\ No newline at end of file diff --git a/kapi/kapi/boot_modules/boot_module_registry.hpp b/kapi/kapi/boot_modules/boot_module_registry.hpp deleted file mode 100644 index 7f490ae3..00000000 --- a/kapi/kapi/boot_modules/boot_module_registry.hpp +++ /dev/null @@ -1,109 +0,0 @@ -#ifndef TEACHOS_KAPI_BOOT_MODULES_BOOT_MODULE_REGISTRY_HPP -#define TEACHOS_KAPI_BOOT_MODULES_BOOT_MODULE_REGISTRY_HPP - -// IWYU pragma: private, include <kapi/boot_modules.hpp> - -#include <kapi/boot_modules/boot_module.hpp> - -#include <kstd/vector.hpp> - -#include <cstddef> - -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 = kstd::vector<boot_module>; - 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; - - [[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.push_back(module); - } - - private: - range_type m_modules{}; - }; -} // namespace kapi::boot_modules - -#endif
\ No newline at end of file diff --git a/kapi/kapi/boot_modules/bus.hpp b/kapi/kapi/boot_modules/bus.hpp index 9cab7edb..7e3c773c 100644 --- a/kapi/kapi/boot_modules/bus.hpp +++ b/kapi/kapi/boot_modules/bus.hpp @@ -4,7 +4,7 @@ // IWYU pragma: private, include <kapi/boot_modules.hpp> #include <kapi/boot_modules/boot_module.hpp> -#include <kapi/boot_modules/boot_module_registry.hpp> +#include <kapi/boot_modules/registry.hpp> #include <kapi/devices.hpp> #include <kstd/result.hpp> @@ -53,7 +53,7 @@ namespace kapi::boot_modules struct boot_module_bus final : kapi::devices::bus, kapi::devices::bus_protocol { - explicit boot_module_bus(boot_module_registry const * registry); + explicit boot_module_bus(registry const * registry); auto enumerate(kapi::devices::bus & self) -> void override; @@ -63,7 +63,7 @@ namespace kapi::boot_modules [[nodiscard]] auto protocol() -> kapi::devices::bus_protocol * override; private: - boot_module_registry const * m_registry; + registry const * m_registry; }; } // namespace kapi::boot_modules diff --git a/kapi/kapi/boot_modules/registry.hpp b/kapi/kapi/boot_modules/registry.hpp new file mode 100644 index 00000000..4c659fa4 --- /dev/null +++ b/kapi/kapi/boot_modules/registry.hpp @@ -0,0 +1,76 @@ +#ifndef TEACHOS_KAPI_BOOT_MODULES_REGISTRY_HPP +#define TEACHOS_KAPI_BOOT_MODULES_REGISTRY_HPP + +// IWYU pragma: private, include <kapi/boot_modules.hpp> + +#include <kapi/boot_modules/boot_module.hpp> + +#include <kstd/vector.hpp> + +#include <cstddef> + +namespace kapi::boot_modules +{ + + //! @addtogroup kapi-boot_modules-kernel-defined + //! @{ + + //! 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 registry + { + using container = kstd::vector<boot_module>; + using value_type = container::value_type; + using const_reference = container::const_reference; + + using const_iterator = container::const_iterator; + using const_reverse_iterator = container::const_reverse_iterator; + using size_type = container::size_type; + + auto static init() -> void; + + auto static get() -> registry &; + + registry() = default; + + [[nodiscard]] auto begin() const noexcept -> const_iterator; + + [[nodiscard]] auto end() const noexcept -> const_iterator; + + [[nodiscard]] auto cbegin() const noexcept -> const_iterator; + + [[nodiscard]] auto cend() const noexcept -> const_iterator; + + [[nodiscard]] auto rbegin() const noexcept -> const_reverse_iterator; + + [[nodiscard]] auto rend() const noexcept -> const_reverse_iterator; + + [[nodiscard]] auto crbegin() const noexcept -> const_reverse_iterator; + + [[nodiscard]] auto crend() const noexcept -> const_reverse_iterator; + + [[nodiscard]] auto front() const noexcept -> const_reference; + + [[nodiscard]] auto back() const noexcept -> const_reference; + + [[nodiscard]] auto size() const noexcept -> std::size_t; + + [[nodiscard]] auto empty() const noexcept -> bool; + + [[nodiscard]] auto at(std::size_t index) const -> const_reference; + + [[nodiscard]] auto operator[](std::size_t index) const noexcept -> const_reference; + + auto add(boot_module module) -> void; + + private: + container m_modules{}; + }; + + //! @} + +} // namespace kapi::boot_modules + +#endif
\ No newline at end of file diff --git a/kapi/kapi/test_support/boot_modules.hpp b/kapi/kapi/test_support/boot_modules.hpp new file mode 100644 index 00000000..86a81307 --- /dev/null +++ b/kapi/kapi/test_support/boot_modules.hpp @@ -0,0 +1,17 @@ +#ifndef KAPI_TEST_SUPPORT_BOOT_MODULES_HPP +#define KAPI_TEST_SUPPORT_BOOT_MODULES_HPP + +#include <kapi/boot_modules.hpp> + +#include <optional> + +namespace kapi::test_support::boot_modules +{ + + auto deinit_registry() -> void; + + auto inject_registry(kapi::boot_modules::registry && registry) -> std::optional<kapi::boot_modules::registry>; + +} // namespace kapi::test_support::boot_modules + +#endif |
