IgrOS-Kernel 0.1.34.545
Simple C++20 Kernel for i386/x86_64
Loading...
Searching...
No Matches
driver.hpp
Go to the documentation of this file.
1
11
12
13#pragma once
14
15
16// C++
17#include <array>
18#include <type_traits>
19// IgrOS-Kernel arch
20#include <arch/types.hpp>
21// IgrOS-Kernel library
22#include <klib/kPrint.hpp>
23
24
25// Kernel drivers
26namespace igros::drivers {
27
28
30 using driverInit_t = std::add_pointer_t<auto() noexcept -> bool>;
31
32
34 struct driver_t {
35
36 const char* name;
38 };
39
40
45 template<igros_usize_t N>
46 auto init(const std::array<drivers::driver_t, N> &drivers) noexcept -> igros_usize_t {
47 // Failed drivers count
48 auto failed {0_usize};
49 // Init drivers one by one (failed driver doesn't stop the rest)
50 for (const auto &driver : drivers) {
51 const auto ok {driver.init()};
53 "Driver %s:\t%s",
54 driver.name,
55 ok ? "OK" : "ERROR"
56 );
57 failed += ok ? 0_usize : 1_usize;
58 }
59 // Failed drivers count
60 return failed;
61 }
62
63
64} // namespace igros::drivers
65
std::size_t igros_usize_t
Unsigned size.
Definition types.hpp:51
Kernel text print functions.
Driver table and initialization.
std::add_pointer_t< auto() noexcept -> bool > driverInit_t
Driver init function (returns true on success).
Definition driver.hpp:30
auto init(const std::array< drivers::driver_t, N > &drivers) noexcept -> igros_usize_t
Initialize drivers in order and print status of each, returns failed drivers count.
Definition driver.hpp:46
void kprintf(const char *const format,...) noexcept
Kernel printf function (arguments are checked against format at compile time).
Definition kPrint.cpp:358
Kernel driver description.
Definition driver.hpp:34
driverInit_t init
Driver init function.
Definition driver.hpp:37
const char * name
Driver name.
Definition driver.hpp:36
Common C++ types redefinition.