summaryrefslogtreecommitdiff
path: root/kernel/drivers/driver_registry.cpp
blob: 43b2b5a4583557679e8e259762d6c1b46cd2b916 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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