summaryrefslogtreecommitdiff
path: root/kernel/drivers/driver_registry.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/drivers/driver_registry.cpp')
-rw-r--r--kernel/drivers/driver_registry.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/kernel/drivers/driver_registry.cpp b/kernel/drivers/driver_registry.cpp
new file mode 100644
index 0000000..43b2b5a
--- /dev/null
+++ b/kernel/drivers/driver_registry.cpp
@@ -0,0 +1,55 @@
+// ============================================================================
+// drivers/driver_registry.cpp — Driver/device registry globals
+//
+// Provides storage for per-category driver lists, the active console
+// pointer, and the platform bus singleton. Always compiled.
+// ============================================================================
+
+#include <kernel/console_driver.h>
+#include <kernel/platform_bus.h>
+
+// ── ConsoleDriver default write implementation ────────────────────────────
+
+void ConsoleDriver::write(const char* s, size_t len) {
+ for (size_t i = 0; i < len; ++i) {
+ putchar(s[i]);
+ }
+}
+
+// ── Console registry ──────────────────────────────────────────────────────
+
+static DriverList<ConsoleDriver> g_console_drivers;
+static ConsoleDriver* g_active_console = nullptr;
+
+namespace console {
+
+void register_driver(ConsoleDriver* driver) {
+ g_console_drivers.add(driver);
+}
+
+void set_active(ConsoleDriver* driver) {
+ g_active_console = driver;
+}
+
+ConsoleDriver* active() {
+ return g_active_console;
+}
+
+DriverList<ConsoleDriver>& drivers() {
+ return g_console_drivers;
+}
+
+} // namespace console
+
+// ── Platform bus (lazy singleton) ─────────────────────────────────────────
+
+namespace platform {
+
+Bus& bus() {
+ if (!PlatformBus::instance()) {
+ PlatformBus::create();
+ }
+ return *PlatformBus::instance();
+}
+
+} // namespace platform