IgrOS-Kernel 0.1.34.545
Simple C++20 Kernel for i386/x86_64
Loading...
Searching...
No Matches
platform-x86.cpp
Go to the documentation of this file.
1
11
12
13// C++
14#include <array>
15#include <source_location>
16// IgrOS-Kernel arch x86
18#include <arch/x86/irq.hpp>
19#include <arch/x86/native.hpp>
20#include <arch/x86/paging.hpp>
21
22#if defined(IGROS_ARCH_i386)
23
24// IgrOS-Kernel arch i386
25#include <arch/i386/gdt.hpp>
26#include <arch/i386/idt.hpp>
27
28#elif defined(IGROS_ARCH_x86_64)
29
30// IgrOS-Kernel arch x86_64
31#include <arch/x86_64/gdt.hpp>
32#include <arch/x86_64/idt.hpp>
33
34#endif
35
36// IgrOS-Kernel drivers
37#include <drivers/clock/pit.hpp>
38#include <drivers/clock/rtc.hpp>
39#include <drivers/driver.hpp>
42#include <drivers/vga/vmem.hpp>
43// IgrOS-Kernel library
44#include <klib/kPrint.hpp>
45// IgrOS-Kernel platform
46#include <platform/platform.hpp>
47
48
49// x86 namespace
50namespace igros::x86 {
51
52
54 static void platformInit() noexcept {
55
56 // Setup Global Descriptors Table and task state segment (IDT refers to it)
57 native::gdt::init();
58 // Setup Interrupts Descriptor Table
59 native::idt::init();
60 // Init exceptions
62
63 // Init interrupts
64 irq::init();
65 // Enable interrupts
67
68 // Platform drivers (in init order)
69 constexpr auto DRIVERS = std::to_array<drivers::driver_t>({
70 {.name = "VGA", .init = arch::vmemInit},
71 {.name = "UART", .init = arch::serialSetup},
72 {.name = "Keyboard", .init = arch::keyboardSetup},
73 {.name = "RTC", .init = arch::rtcSetup},
74 // PIT prints time every second, enable when needed
75 //{.name = "PIT", .init = arch::pitSetup},
76 });
77 // Setup drivers
78 drivers::init(DRIVERS);
79
80 // Setup paging (kernel page tables, needs physical memory allocator)
82
83 // Debug print
85 "[%s]\n",
86 std::source_location::current().function_name()
87 );
88 }
89
91 static void platformFinalize() noexcept {
92 // Debug print
94 "[%s]\n",
95 std::source_location::current().function_name()
96 );
97 }
98
100 static void platformShutdown() noexcept {
101 // Debug print
103 "[%s]\n",
104 std::source_location::current().function_name()
105 );
106 }
107
109 static void platformReboot() noexcept {
110 // Debug print
112 "[%s]\n",
113 std::source_location::current().function_name()
114 );
115 }
116
118 static void platformSuspend() noexcept {
119 // Debug print
121 "[%s]\n",
122 std::source_location::current().function_name()
123 );
124 }
125
127 static void platformWakeup() noexcept {
128 // Debug print
130 "[%s]\n",
131 std::source_location::current().function_name()
132 );
133 }
134
135
136} // namespace igros::x86
137
138
139// OS platform
140namespace igros::platform {
141
142
143 // Get kernel current platform
144 [[nodiscard]]
145 auto Platform::current() noexcept -> const Platform & {
146 // Current x86 platform (constant-initialized, no runtime init)
147 constinit static const Platform platform {
155 };
156 // Current x86 platform reference
157 return platform;
158 }
159
160
161} // namespace igros::platform
162
constexpr Platform() noexcept=default
Default c-tor.
static auto current() noexcept -> const Platform &
Get kernel current platform (implemented in corresponding platform file).
static void init() noexcept
Init exceptions.
static void enable() noexcept
Enable interrupts.
Definition irq.cpp:65
static void init() noexcept
Init IRQ.
Definition irq.cpp:46
static void init() noexcept
Build kernel page tables and switch to them:
Definition paging.cpp:260
Kernel driver interface.
Exceptions low-level operations.
Global descriptor table low-level operations.
Interrupt descriptor table low-level operations.
Kernel text print functions.
Keyboard generic handling.
auto serialSetup() noexcept -> bool
Setup COM1 (115200 8N1) with receive interrupt.
Definition serial.cpp:298
auto vmemInit() noexcept -> bool
Init VGA console.
Definition vmem.cpp:215
auto keyboardSetup() noexcept -> bool
Setup keyboard function.
Definition keyboard.cpp:65
auto rtcSetup() noexcept -> bool
Setup RTC function.
Definition rtc.cpp:190
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
Platform description and initialization.
Code shared by i386 and x86_64: ports, interrupts, exceptions, paging.
static void platformInit() noexcept
Initialize x86.
static void platformSuspend() noexcept
Suspend x86.
static void platformWakeup() noexcept
Wakeup x86.
static void platformReboot() noexcept
Reboot x86.
static void platformFinalize() noexcept
Finalize x86.
constexpr auto ARCH_NAME
Current architecture.
Definition native.hpp:51
static void platformShutdown() noexcept
Shutdown x86.
x86 family current (native) architecture selection
Paging (i386 2-level and x86_64 4-level page tables).
Programmable interrupt timer.
IgrOS platform description.
RTC clock driver.
UART driver.
VGA memory low-level operations.
Interrupts low-level operations.
Global descriptor table low-level operations.
Interrupt descriptor table low-level operations.