diff options
Diffstat (limited to 'kernel/kapi')
| -rw-r--r-- | kernel/kapi/boot_module/bus.cpp | 2 | ||||
| -rw-r--r-- | kernel/kapi/boot_module/registry.cpp | 131 | ||||
| -rw-r--r-- | kernel/kapi/boot_modules.cpp | 41 |
3 files changed, 132 insertions, 42 deletions
diff --git a/kernel/kapi/boot_module/bus.cpp b/kernel/kapi/boot_module/bus.cpp index aab1403b..88f2cda3 100644 --- a/kernel/kapi/boot_module/bus.cpp +++ b/kernel/kapi/boot_module/bus.cpp @@ -53,7 +53,7 @@ namespace kapi::boot_modules return kapi::devices::device::query_interface(interface); } - boot_module_bus::boot_module_bus(boot_module_registry const * registry) + boot_module_bus::boot_module_bus(registry const * registry) : kapi::devices::bus{"boot_modules"} , m_registry(registry) {} diff --git a/kernel/kapi/boot_module/registry.cpp b/kernel/kapi/boot_module/registry.cpp new file mode 100644 index 00000000..80c76129 --- /dev/null +++ b/kernel/kapi/boot_module/registry.cpp @@ -0,0 +1,131 @@ +#include <kapi/boot_modules/registry.hpp> + +#include <kapi/boot_modules.hpp> +#include <kapi/system.hpp> +#include <kapi/test_support/boot_modules.hpp> + +#include <cstddef> +#include <optional> +#include <utility> + +namespace kapi::boot_modules +{ + + namespace + { + constinit auto instance = std::optional<registry>{}; + } + + auto registry::init() -> void + { + if (instance) + { + system::panic("[OS] Boot module registry has already been initialized."); + } + + instance.emplace(); + } + + auto registry::get() -> registry & + { + if (!instance) + { + system::panic("[OS] Boot module registry has not been initialized."); + } + + return *instance; + } + + auto registry::begin() const noexcept -> const_iterator + { + return m_modules.begin(); + } + + auto registry::end() const noexcept -> const_iterator + { + return m_modules.end(); + } + + auto registry::cbegin() const noexcept -> const_iterator + { + return m_modules.cbegin(); + } + + auto registry::cend() const noexcept -> const_iterator + { + return m_modules.cend(); + } + + auto registry::rbegin() const noexcept -> const_reverse_iterator + { + return m_modules.rbegin(); + } + + auto registry::rend() const noexcept -> const_reverse_iterator + { + return m_modules.rend(); + } + + auto registry::crbegin() const noexcept -> const_reverse_iterator + { + return m_modules.crbegin(); + } + + auto registry::crend() const noexcept -> const_reverse_iterator + { + return m_modules.crend(); + } + + auto registry::front() const noexcept -> const_reference + { + return m_modules.front(); + } + + auto registry::back() const noexcept -> const_reference + { + return m_modules.back(); + } + + auto registry::size() const noexcept -> std::size_t + { + return m_modules.size(); + } + + auto registry::empty() const noexcept -> bool + { + return m_modules.empty(); + } + + auto registry::at(std::size_t index) const -> const_reference + { + return m_modules.at(index); + } + + auto registry::operator[](std::size_t index) const noexcept -> const_reference + { + return m_modules[index]; + } + + auto registry::add(boot_module module) -> void + { + m_modules.push_back(module); + } + +} // namespace kapi::boot_modules + +namespace kapi::test_support::boot_modules +{ + + auto deinit_registry() -> void + { + kapi::boot_modules::instance.reset(); + } + + auto inject_registry(kapi::boot_modules::registry && registry) -> std::optional<kapi::boot_modules::registry> + { + auto old = std::move(kapi::boot_modules::instance); + kapi::boot_modules::instance.emplace(std::move(registry)); + return old; + } + +} // namespace kapi::test_support::boot_modules diff --git a/kernel/kapi/boot_modules.cpp b/kernel/kapi/boot_modules.cpp deleted file mode 100644 index 5629b77f..00000000 --- a/kernel/kapi/boot_modules.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include <kapi/boot_modules.hpp> - -#include <kapi/system.hpp> - -#include <optional> - -namespace -{ - constinit auto static registry = std::optional<kapi::boot_modules::boot_module_registry>{}; -} // namespace - -namespace kapi::boot_modules -{ - auto set_boot_module_registry(boot_module_registry & new_registry) -> void - { - if (registry) - { - system::panic("[x86_64] Boot module registry has already been set."); - } - - registry = new_registry; - } - - auto get_boot_module_registry() -> boot_module_registry const & - { - if (!registry) - { - system::panic("[x86_64] Boot module registry has not been initialized."); - } - - return *registry; - } -} // namespace kapi::boot_modules - -namespace kernel::tests::boot_modules -{ - auto deinit() -> void - { - registry.reset(); - } -} // namespace kernel::tests::boot_modules |
