aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-07-24 23:12:23 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-07-24 23:12:23 +0200
commit8ac3b7c5dfd6917eac1ffb117ee48231032ce754 (patch)
treecd1203a908b6f449db2e321207b6e0e77962fa57 /kernel
parenta1f1ddabf24fb6dfb1bcfc6257c44b6a2bfba8ab (diff)
downloadkernel-8ac3b7c5dfd6917eac1ffb117ee48231032ce754.tar.xz
kernel-8ac3b7c5dfd6917eac1ffb117ee48231032ce754.zip
kernel: remove boot modules registry
Diffstat (limited to 'kernel')
-rw-r--r--kernel/CMakeLists.txt7
-rw-r--r--kernel/kapi/boot_module/bus.cpp97
-rw-r--r--kernel/kapi/boot_module/registry.cpp131
-rw-r--r--kernel/kapi/boot_modules/device.cpp39
-rw-r--r--kernel/kernel/bus/boot_modules.cpp60
-rw-r--r--kernel/kernel/bus/boot_modules.hpp28
-rw-r--r--kernel/kernel/devices/storage.cpp9
-rw-r--r--kernel/kernel/devices/storage.hpp2
-rw-r--r--kernel/kernel/devices/storage.tests.cpp31
-rw-r--r--kernel/kernel/drivers/storage/ram_disk.cpp8
-rw-r--r--kernel/kernel/drivers/storage/ram_disk.hpp4
-rw-r--r--kernel/kernel/main.cpp8
-rw-r--r--kernel/kernel/test_support/filesystem/storage_boot_module_fixture.cpp42
-rw-r--r--kernel/kernel/test_support/filesystem/storage_boot_module_fixture.hpp8
-rw-r--r--kernel/kernel/test_support/kapi/boot_modules.cpp6
-rw-r--r--kernel/kernel/test_support/state_reset_listener.cpp6
16 files changed, 188 insertions, 298 deletions
diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt
index 5a0b42a8..0d6c4ba9 100644
--- a/kernel/CMakeLists.txt
+++ b/kernel/CMakeLists.txt
@@ -8,8 +8,7 @@ add_library("kernel::lib" ALIAS "kernel_lib")
target_sources("kernel_lib" PRIVATE
# Kernel-defined KAPI Implementation
"kapi/acpi.cpp"
- "kapi/boot_module/bus.cpp"
- "kapi/boot_module/registry.cpp"
+ "kapi/boot_modules/device.cpp"
"kapi/cio.cpp"
"kapi/cpu.cpp"
"kapi/devices.cpp"
@@ -43,6 +42,9 @@ target_sources("kernel_lib" PRIVATE
"kernel/devices/block_device_utils.cpp"
"kernel/devices/root_bus.cpp"
+ # Bus Sumbsystem
+ "kernel/bus/boot_modules.cpp"
+
# Driver Subsystem
"kernel/drivers/storage/ram_disk.cpp"
"kernel/drivers/init.cpp"
@@ -154,6 +156,7 @@ if(BUILD_TESTING)
teachos_add_tests("kernel")
target_sources("kernel_tests" PRIVATE
+ "kernel/test_support/kapi/boot_modules.cpp"
"kernel/test_support/kapi/cpu.cpp"
"kernel/test_support/kapi/cio.cpp"
"kernel/test_support/kapi/interrupts.cpp"
diff --git a/kernel/kapi/boot_module/bus.cpp b/kernel/kapi/boot_module/bus.cpp
deleted file mode 100644
index 17052629..00000000
--- a/kernel/kapi/boot_module/bus.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-#include <kapi/boot_modules/bus.hpp>
-
-#include <kapi/boot_modules.hpp>
-#include <kapi/devices.hpp>
-
-#include <kstd/format.hpp>
-#include <kstd/memory.hpp>
-#include <kstd/result.hpp>
-#include <kstd/string.hpp>
-
-#include <cstddef>
-#include <ranges>
-#include <string_view>
-
-namespace kapi::boot_modules
-{
- auto has_parameter(std::string_view cmdline, std::string_view key, std::string_view value) -> bool
- {
- for (auto token : std::views::split(cmdline, ' '))
- {
- auto const text = std::string_view{token};
- auto const equals = text.find('=');
- if (equals != std::string_view::npos && text.substr(0, equals) == key && text.substr(equals + 1) == value)
- {
- return true;
- }
- }
- return false;
- }
-
- boot_module_device::boot_module_device(std::size_t index, struct module const & module)
- : kapi::devices::device{kstd::format("boot_module{}", index)}
- , m_module(module)
- {}
-
- auto boot_module_device::command_line() const -> std::string_view
- {
- return m_module.name;
- }
-
- auto boot_module_device::module() const -> boot_modules::module const &
- {
- return m_module;
- }
-
- auto boot_module_device::query_interface(kapi::devices::interface_id interface) -> void *
- {
- if (interface == boot_module_identification::id)
- {
- return static_cast<boot_module_identification *>(this);
- }
-
- return kapi::devices::device::query_interface(interface);
- }
-
- boot_module_bus::boot_module_bus(registry const * registry)
- : kapi::devices::bus{"boot_modules"}
- , m_registry(registry)
- {}
-
- auto boot_module_bus::enumerate(kapi::devices::bus & self) -> void
- {
- std::size_t index = 0;
-
- for (auto const & module : *m_registry)
- {
- self.add_child(kstd::make_shared<boot_module_device>(index++, module));
- }
- }
-
- auto boot_module_bus::match(kapi::devices::device const & dev, kapi::devices::driver const & drv) const
- -> kstd::result<unsigned>
- {
- auto const * ident = dev.as<boot_module_identification>();
- auto const * claims = drv.as<boot_module_driver_identification>();
-
- if (!ident || !claims)
- {
- return kstd::failure(kapi::devices::driver_match_errc::no_match);
- }
-
- auto const [key, value] = claims->claimed_parameter();
-
- if (!has_parameter(ident->command_line(), key, value))
- {
- return kstd::failure(kapi::devices::driver_match_errc::no_match);
- }
-
- return 0u;
- }
-
- auto boot_module_bus::protocol() -> kapi::devices::bus_protocol *
- {
- return this;
- }
-
-} // namespace kapi::boot_modules
diff --git a/kernel/kapi/boot_module/registry.cpp b/kernel/kapi/boot_module/registry.cpp
deleted file mode 100644
index 9876866b..00000000
--- a/kernel/kapi/boot_module/registry.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-#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(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/device.cpp b/kernel/kapi/boot_modules/device.cpp
new file mode 100644
index 00000000..84a43c1c
--- /dev/null
+++ b/kernel/kapi/boot_modules/device.cpp
@@ -0,0 +1,39 @@
+#include <kapi/boot_modules/device.hpp>
+
+#include <kapi/boot_modules/module.hpp>
+#include <kapi/devices.hpp>
+
+#include <kstd/format.hpp>
+
+#include <cstddef>
+#include <string_view>
+
+namespace kapi::boot_modules
+{
+
+ device::device(std::size_t index, kapi::boot_modules::module const & module)
+ : kapi::devices::device{kstd::format("device{}", index)}
+ , m_module(module)
+ {}
+
+ auto device::command_line() const -> std::string_view
+ {
+ return m_module.name;
+ }
+
+ auto device::module() const -> boot_modules::module const &
+ {
+ return m_module;
+ }
+
+ auto device::query_interface(kapi::devices::interface_id interface) -> void *
+ {
+ if (interface == boot_module_signature::id)
+ {
+ return static_cast<boot_module_signature *>(this);
+ }
+
+ return kapi::devices::device::query_interface(interface);
+ }
+
+} // namespace kapi::boot_modules \ No newline at end of file
diff --git a/kernel/kernel/bus/boot_modules.cpp b/kernel/kernel/bus/boot_modules.cpp
new file mode 100644
index 00000000..ac5a2068
--- /dev/null
+++ b/kernel/kernel/bus/boot_modules.cpp
@@ -0,0 +1,60 @@
+#include <kernel/bus/boot_modules.hpp>
+
+#include <kapi/boot_modules.hpp>
+#include <kapi/devices.hpp>
+
+#include <kstd/result.hpp>
+#include <kstd/string.hpp>
+
+#include <ranges>
+#include <string_view>
+
+namespace kernel::bus
+{
+ auto has_parameter(std::string_view cmdline, std::string_view key, std::string_view value) -> bool
+ {
+ for (auto token : std::views::split(cmdline, ' '))
+ {
+ auto const text = std::string_view{token};
+ auto const equals = text.find('=');
+ if (equals != std::string_view::npos && text.substr(0, equals) == key && text.substr(equals + 1) == value)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ boot_modules::boot_modules()
+ : kapi::devices::bus{"boot_modules"}
+ {}
+
+ auto boot_modules::enumerate(kapi::devices::bus &) -> void {}
+
+ auto boot_modules::match(kapi::devices::device const & dev, kapi::devices::driver const & drv) const
+ -> kstd::result<unsigned>
+ {
+ auto signature = dev.as<kapi::boot_modules::boot_module_signature>();
+ auto claim = drv.as<kapi::boot_modules::boot_module_claim>();
+
+ if (!signature || !claim)
+ {
+ return kstd::failure(kapi::devices::driver_match_errc::no_match);
+ }
+
+ auto const [key, value] = claim->parameter();
+
+ if (!has_parameter(signature->command_line(), key, value))
+ {
+ return kstd::failure(kapi::devices::driver_match_errc::no_match);
+ }
+
+ return 0u;
+ }
+
+ auto boot_modules::protocol() -> kapi::devices::bus_protocol *
+ {
+ return this;
+ }
+
+} // namespace kernel::bus
diff --git a/kernel/kernel/bus/boot_modules.hpp b/kernel/kernel/bus/boot_modules.hpp
new file mode 100644
index 00000000..147cfdf2
--- /dev/null
+++ b/kernel/kernel/bus/boot_modules.hpp
@@ -0,0 +1,28 @@
+#ifndef TEACHOS_KERNEL_BUS_BOOT_MODULES_HPP
+#define TEACHOS_KERNEL_BUS_BOOT_MODULES_HPP
+
+#include <kapi/devices.hpp>
+
+#include <kstd/result.hpp>
+
+namespace kernel::bus
+{
+
+ //! The boot modules bus.
+ //!
+ //! Boot modules used to back devices may be attached to this bus.
+ struct boot_modules final : kapi::devices::bus, kapi::devices::bus_protocol
+ {
+ boot_modules();
+
+ auto enumerate(kapi::devices::bus & self) -> void override;
+
+ [[nodiscard]] auto match(kapi::devices::device const & dev, kapi::devices::driver const & drv) const
+ -> kstd::result<unsigned> override;
+
+ [[nodiscard]] auto protocol() -> kapi::devices::bus_protocol * override;
+ };
+
+} // namespace kernel::bus
+
+#endif \ No newline at end of file
diff --git a/kernel/kernel/devices/storage.cpp b/kernel/kernel/devices/storage.cpp
index cbd350ce..a95b1840 100644
--- a/kernel/kernel/devices/storage.cpp
+++ b/kernel/kernel/devices/storage.cpp
@@ -1,17 +1,18 @@
#include <kernel/devices/storage.hpp>
-#include <kapi/boot_modules.hpp>
+#include <kernel/bus/boot_modules.hpp>
+
#include <kapi/devices.hpp>
#include <kstd/memory.hpp>
namespace kernel::devices::storage
{
- auto init() -> void
+ auto init() -> kstd::shared_ptr<kapi::devices::bus>
{
- auto modules_bus = kstd::make_shared<kapi::boot_modules::boot_module_bus>(&kapi::boot_modules::registry::get());
+ auto modules_bus = kstd::make_shared<kernel::bus::boot_modules>();
kapi::devices::get_root_bus()->add_child(modules_bus);
- modules_bus->enumerate(*modules_bus);
+ return modules_bus;
}
auto determine_boot_device() -> kstd::shared_ptr<kapi::devices::device>
diff --git a/kernel/kernel/devices/storage.hpp b/kernel/kernel/devices/storage.hpp
index 1d0362a3..bbbe8e6f 100644
--- a/kernel/kernel/devices/storage.hpp
+++ b/kernel/kernel/devices/storage.hpp
@@ -10,7 +10,7 @@ namespace kernel::devices::storage
{
//! Attach the boot-time storage controllers to the system device tree.
- auto init() -> void;
+ [[nodiscard]] auto init() -> kstd::shared_ptr<kapi::devices::bus>;
//! @brief Determine the boot device.
//!
diff --git a/kernel/kernel/devices/storage.tests.cpp b/kernel/kernel/devices/storage.tests.cpp
index 30cafe4a..2a06149a 100644
--- a/kernel/kernel/devices/storage.tests.cpp
+++ b/kernel/kernel/devices/storage.tests.cpp
@@ -1,9 +1,12 @@
#include <kernel/devices/storage.hpp>
#include <kapi/boot_modules.hpp>
+#include <kapi/boot_modules/device.hpp>
+#include <kapi/boot_modules/module.hpp>
#include <kapi/devices.hpp>
#include <kapi/memory.hpp>
-#include <kapi/test_support/boot_modules.hpp>
+
+#include <kstd/memory.hpp>
#include <catch2/catch_test_macros.hpp>
@@ -13,38 +16,24 @@
TEST_CASE("Storage devices attached with init() are reachable from the root bus", "[devices][storage]")
{
auto storage = std::vector<std::byte>{4096, std::byte{}};
- auto registry = kapi::boot_modules::registry{};
-
- registry.add({
+ auto module = kapi::boot_modules::module{
.name = "test_module type=ramdisk",
.start_address = kapi::memory::linear_address{storage.data()},
.size = storage.size(),
- });
+ };
+ auto device = kstd::make_shared<kapi::boot_modules::device>(0, module);
- kapi::test_support::boot_modules::inject_registry(std::move(registry));
+ auto bus = static_pointer_cast<kapi::devices::bus>(kapi::devices::device_registry::get().find("boot_modules"));
+ REQUIRE(bus);
- kernel::devices::storage::init();
+ bus->add_child(device);
auto block_devices = kapi::devices::interface_registry::get().all(kapi::devices::block_device::id);
REQUIRE(block_devices.size() == 1);
CHECK(block_devices[0].name() == "ram0");
- auto root = kapi::devices::get_root_bus();
- auto boot_modules_bus_found = false;
-
- for (auto const & child : root->children())
- {
- if (child->name() == "boot_modules")
- {
- boot_modules_bus_found = true;
- }
- }
- CHECK(boot_modules_bus_found);
-
auto boot_device = kernel::devices::storage::determine_boot_device();
REQUIRE(boot_device);
CHECK(boot_device->state() == kapi::devices::state::bound);
CHECK(boot_device->bound_driver() != nullptr);
-
- kapi::test_support::boot_modules::deinit_registry();
} \ No newline at end of file
diff --git a/kernel/kernel/drivers/storage/ram_disk.cpp b/kernel/kernel/drivers/storage/ram_disk.cpp
index f4223c19..8bf06b66 100644
--- a/kernel/kernel/drivers/storage/ram_disk.cpp
+++ b/kernel/kernel/drivers/storage/ram_disk.cpp
@@ -95,7 +95,7 @@ namespace kernel::drivers::storage
auto ram_disk::probe(kapi::devices::device & device) -> kstd::result<void>
{
- auto interface = device.as<kapi::boot_modules::boot_module_identification>();
+ auto interface = device.as<kapi::boot_modules::boot_module_signature>();
if (!interface)
{
return kstd::failure(make_error_code(kstd::errc::invalid_argument));
@@ -134,7 +134,7 @@ namespace kernel::drivers::storage
device.set_driver_data(nullptr);
}
- auto ram_disk::claimed_parameter() const -> std::pair<std::string_view, std::string_view>
+ auto ram_disk::parameter() const -> std::pair<std::string_view, std::string_view>
{
return {"type", "ramdisk"};
}
@@ -146,9 +146,9 @@ namespace kernel::drivers::storage
auto ram_disk::query_interface(kapi::devices::interface_id interface) -> void *
{
- if (interface == kapi::boot_modules::boot_module_driver_identification::id)
+ if (interface == kapi::boot_modules::boot_module_claim::id)
{
- return static_cast<kapi::boot_modules::boot_module_driver_identification *>(this);
+ return static_cast<kapi::boot_modules::boot_module_claim *>(this);
}
return kapi::devices::driver::query_interface(interface);
diff --git a/kernel/kernel/drivers/storage/ram_disk.hpp b/kernel/kernel/drivers/storage/ram_disk.hpp
index ab4c5a1b..ac8d2879 100644
--- a/kernel/kernel/drivers/storage/ram_disk.hpp
+++ b/kernel/kernel/drivers/storage/ram_disk.hpp
@@ -14,13 +14,13 @@
namespace kernel::drivers::storage
{
- struct ram_disk final : kapi::devices::driver, kapi::boot_modules::boot_module_driver_identification
+ struct ram_disk final : kapi::devices::driver, kapi::boot_modules::boot_module_claim
{
[[nodiscard]] auto probe(kapi::devices::device & device) -> kstd::result<void> override;
auto unbind(kapi::devices::device & device) -> void override;
- [[nodiscard]] auto claimed_parameter() const -> std::pair<std::string_view, std::string_view> override;
+ [[nodiscard]] auto parameter() const -> std::pair<std::string_view, std::string_view> override;
[[nodiscard]] auto claimed_major() const -> std::optional<std::uint8_t> override;
diff --git a/kernel/kernel/main.cpp b/kernel/kernel/main.cpp
index aa12df1a..9d841f79 100644
--- a/kernel/kernel/main.cpp
+++ b/kernel/kernel/main.cpp
@@ -167,12 +167,12 @@ auto main() -> int
kapi::interrupts::enable();
kstd::println("[OS] Interrupts enabled.");
- kapi::boot_modules::init();
- kstd::println("[OS] Boot module registry initialized.");
-
- kernel::devices::storage::init();
+ auto modules_bus = kernel::devices::storage::init();
kstd::println("[OS] Storage subsystem initialized.");
+ kapi::boot_modules::init(*modules_bus);
+ kstd::println("[OS] Boot modules attached.");
+
kernel::filesystem::open_file_table::init();
kstd::println("[OS] Global open file table initialized.");
diff --git a/kernel/kernel/test_support/filesystem/storage_boot_module_fixture.cpp b/kernel/kernel/test_support/filesystem/storage_boot_module_fixture.cpp
index 75b25011..644e38fe 100644
--- a/kernel/kernel/test_support/filesystem/storage_boot_module_fixture.cpp
+++ b/kernel/kernel/test_support/filesystem/storage_boot_module_fixture.cpp
@@ -1,11 +1,12 @@
#include <kernel/test_support/filesystem/storage_boot_module_fixture.hpp>
+#include <kernel/bus/boot_modules.hpp>
#include <kernel/devices/storage.hpp>
#include <kapi/boot_modules.hpp>
+#include <kapi/boot_modules/device.hpp>
#include <kapi/devices.hpp>
#include <kapi/memory.hpp>
-#include <kapi/test_support/boot_modules.hpp>
#include <kstd/memory.hpp>
@@ -76,16 +77,14 @@ namespace kernel::tests::filesystem
return *this;
}
- storage_boot_module_fixture::~storage_boot_module_fixture()
- {
- kapi::test_support::boot_modules::deinit_registry();
- }
+ storage_boot_module_fixture::~storage_boot_module_fixture() {}
auto storage_boot_module_fixture::setup_modules(std::size_t module_count, std::size_t module_size) -> void
{
m_module_names.clear();
m_module_data.clear();
- m_registry = {};
+
+ m_boot_module_bus = kstd::make_shared<kernel::bus::boot_modules>();
m_module_names.reserve(module_count);
m_module_data.reserve(module_count);
@@ -94,22 +93,15 @@ namespace kernel::tests::filesystem
{
m_module_names.push_back(std::format("test_mod{} type=ramdisk", i));
m_module_data.emplace_back(module_size, std::byte{static_cast<unsigned char>(0x40 + (i % 16))});
- }
- for (std::size_t i = 0; i < module_count; ++i)
- {
- m_registry.add({
+ auto module = kapi::boot_modules::module{
.name = m_module_names[i].c_str(),
.start_address = kapi::memory::linear_address{m_module_data[i].data()},
.size = m_module_data[i].size(),
- });
+ };
+ m_boot_module_bus->add_child(kstd::make_shared<kapi::boot_modules::device>(i, module));
}
- kapi::test_support::boot_modules::inject_registry(std::move(m_registry));
-
- m_boot_module_bus = kstd::make_shared<kapi::boot_modules::boot_module_bus>(&kapi::boot_modules::registry::get());
- m_boot_module_bus->enumerate(*m_boot_module_bus);
-
if (module_count > 0 && kapi::devices::interface_registry::get().all(kapi::devices::block_device::id).empty())
{
throw std::runtime_error{"No RAM disk driver bound to any of the test fixture's boot modules."};
@@ -121,7 +113,8 @@ namespace kernel::tests::filesystem
{
m_module_names.clear();
m_module_data.clear();
- m_registry = {};
+
+ m_boot_module_bus = kstd::make_shared<kernel::bus::boot_modules>();
if (module_names.size() != img_paths.size())
{
@@ -130,30 +123,27 @@ namespace kernel::tests::filesystem
for (size_t i = 0; i < module_names.size(); ++i)
{
- setup_module_from_img(module_names[i], img_paths[i]);
+ setup_module_from_img(i, module_names[i], img_paths[i]);
}
- kapi::test_support::boot_modules::inject_registry(std::move(m_registry));
-
- m_boot_module_bus = kstd::make_shared<kapi::boot_modules::boot_module_bus>(&kapi::boot_modules::registry::get());
- m_boot_module_bus->enumerate(*m_boot_module_bus);
-
if (!module_names.empty() && kapi::devices::interface_registry::get().all(kapi::devices::block_device::id).empty())
{
throw std::runtime_error{"No RAM disk driver bound to any of the test fixture's boot modules."};
}
}
- auto storage_boot_module_fixture::setup_module_from_img(std::string const & module_name,
+ auto storage_boot_module_fixture::setup_module_from_img(std::size_t index, std::string const & module_name,
std::filesystem::path const & img_path) -> void
{
m_module_names.push_back(module_name + " type=ramdisk");
auto & mapped_image = m_mapped_images.emplace_back(img_path);
- m_registry.add({
+ auto module = kapi::boot_modules::module{
.name = m_module_names.back().c_str(),
.start_address = kapi::memory::linear_address{mapped_image.mapping},
.size = mapped_image.size,
- });
+ };
+
+ m_boot_module_bus->add_child(kstd::make_shared<kapi::boot_modules::device>(index, module));
}
} // namespace kernel::tests::filesystem \ No newline at end of file
diff --git a/kernel/kernel/test_support/filesystem/storage_boot_module_fixture.hpp b/kernel/kernel/test_support/filesystem/storage_boot_module_fixture.hpp
index fdb50037..990d640a 100644
--- a/kernel/kernel/test_support/filesystem/storage_boot_module_fixture.hpp
+++ b/kernel/kernel/test_support/filesystem/storage_boot_module_fixture.hpp
@@ -2,6 +2,7 @@
#define TEACHOS_KERNEL_TEST_SUPPORT_FILESYSTEM_STORAGE_BOOT_MODULE_FIXTURE_HPP
#include <kapi/boot_modules.hpp>
+#include <kapi/devices.hpp>
#include <kstd/memory.hpp>
@@ -37,15 +38,14 @@ namespace kernel::tests::filesystem
std::size_t size;
};
- kapi::boot_modules::registry m_registry{};
std::vector<std::string> m_module_names{};
std::vector<std::vector<std::byte>> m_module_data{};
std::vector<mapped_image> m_mapped_images{};
-
- kstd::shared_ptr<kapi::boot_modules::boot_module_bus> m_boot_module_bus{};
+ kstd::shared_ptr<kapi::devices::bus> m_boot_module_bus{};
private:
- auto setup_module_from_img(std::string const & module_name, std::filesystem::path const & img_path) -> void;
+ auto setup_module_from_img(std::size_t index, std::string const & module_name,
+ std::filesystem::path const & img_path) -> void;
};
} // namespace kernel::tests::filesystem
diff --git a/kernel/kernel/test_support/kapi/boot_modules.cpp b/kernel/kernel/test_support/kapi/boot_modules.cpp
new file mode 100644
index 00000000..a064139f
--- /dev/null
+++ b/kernel/kernel/test_support/kapi/boot_modules.cpp
@@ -0,0 +1,6 @@
+#include <kapi/devices.hpp>
+
+namespace kapi::boot_modules
+{
+ auto init(kapi::devices::bus &) -> void {}
+} // namespace kapi::boot_modules
diff --git a/kernel/kernel/test_support/state_reset_listener.cpp b/kernel/kernel/test_support/state_reset_listener.cpp
index 45e8f5cb..13561644 100644
--- a/kernel/kernel/test_support/state_reset_listener.cpp
+++ b/kernel/kernel/test_support/state_reset_listener.cpp
@@ -1,3 +1,4 @@
+#include <kernel/devices/storage.hpp>
#include <kernel/drivers/storage/ram_disk.hpp>
#include <kernel/filesystem/open_file_table.hpp>
#include <kernel/filesystem/type_registry.hpp>
@@ -15,7 +16,6 @@
#include <kapi/devices.hpp>
#include <kapi/devices/driver_registry.hpp>
#include <kapi/memory.hpp>
-#include <kapi/test_support/boot_modules.hpp>
#include <kapi/test_support/devices.hpp>
#include <kstd/memory.hpp>
@@ -25,6 +25,8 @@
#include <catch2/reporters/catch_reporter_event_listener.hpp>
#include <catch2/reporters/catch_reporter_registrars.hpp>
+#include <tuple>
+
struct state_reset_listener : Catch::EventListenerBase
{
using EventListenerBase::EventListenerBase;
@@ -36,6 +38,7 @@ struct state_reset_listener : Catch::EventListenerBase
kapi::memory::init();
kapi::devices::init();
+ std::ignore = kernel::devices::storage::init();
kernel::filesystem::open_file_table::init();
kapi::devices::driver_registry::get().add(kstd::make_shared<kernel::drivers::storage::ram_disk>());
@@ -48,7 +51,6 @@ struct state_reset_listener : Catch::EventListenerBase
kernel::tests::filesystem::type_registry::deinit();
kernel::tests::filesystem::open_file_table::deinit();
- kapi::test_support::boot_modules::deinit_registry();
kapi::test_support::devices::deinit();
kernel::tests::memory::deinit();
kernel::tests::cpu::deinit();