IgrOS-Kernel 0.1.34.545
Simple C++20 Kernel for i386/x86_64
Loading...
Searching...
No Matches
cpu.hpp
Go to the documentation of this file.
1
11
12
13#pragma once
14
15
16// IgrOS-Kernel arch
17#include <arch/register.hpp>
18#include <arch/types.hpp>
19// IgrOS-Kernel library
20#include <klib/kPrint.hpp>
21
22
23#ifdef __cplusplus
24
25extern "C" {
26
27#endif // __cplusplus
28
29
31 [[noreturn]]
32 void cpuHalt() noexcept;
33
34
35#ifdef __cplusplus
36
37} // extern "C"
38
39#endif // __cplusplus
40
41
42// x86_64 namespace
43namespace igros::x86_64 {
44
45
47 class cpu final {
48
49 public:
50
52 cpu() noexcept = default;
54 ~cpu() noexcept = default;
55
57 cpu(const cpu &other) = delete;
59 auto operator=(const cpu &other) -> cpu & = delete;
61 cpu(cpu &&other) = delete;
63 auto operator=(cpu &&other) -> cpu & = delete;
64
66 [[noreturn]]
67 static void halt() noexcept;
68
71 static void dumpRegisters(const register_t* const regs) noexcept;
72 };
73
74
76 [[noreturn]]
77 inline void cpu::halt() noexcept {
78 ::cpuHalt();
79 }
80
81
83 inline void cpu::dumpRegisters(const register_t* const regs) noexcept {
84 // 64-bit register value as format "%llx" argument
85 constexpr auto r = [](const igros_quad_t value) constexpr noexcept {
86 return static_cast<unsigned long long>(value);
87 };
88 // Print regs
89 klib::kprintf(R"registers(
90Registers dump:
91RAX=[%016llx] RBX=[%016llx] RCX=[%016llx] RDX=[%016llx]
92R8 =[%016llx] R9 =[%016llx] R10=[%016llx] R11=[%016llx]
93R12=[%016llx] R13=[%016llx] R14=[%016llx] R15=[%016llx]
94RSI=[%016llx] RDI=[%016llx]
95RSP=[%016llx] RBP=[%016llx]
96RIP=[%016llx]
97RFLAGS=[%016llx]
98Segments:
99CS=[%016llx]
100DS=[%016llx]
101SS=[%016llx]
102ES=[%016llx]
103FS=[%016llx]
104GS=[%016llx]
105)registers",
106 r(regs->rax),
107 r(regs->rbx),
108 r(regs->rcx),
109 r(regs->rdx),
110 r(regs->r8),
111 r(regs->r9),
112 r(regs->r10),
113 r(regs->r11),
114 r(regs->r12),
115 r(regs->r13),
116 r(regs->r14),
117 r(regs->r15),
118 r(regs->rsi),
119 r(regs->rdi),
120 r(regs->userRsp),
121 r(regs->rbp),
122 r(regs->rip),
123 r(regs->rflags),
124 r(regs->cs),
125 r(0_u64), //r(regs->ds),
126 r(regs->ss),
127 r(0_u64), //r(regs->es),
128 r(0_u64), //r(regs->fs),
129 r(0_u64) //r(regs->gs)
130 );
131 }
132
133
134} // namespace igros::x86_64
135
cpu() noexcept=default
Default c-tor.
static void dumpRegisters(const register_t *const regs) noexcept
Dump CPU registers.
Definition cpu.hpp:83
static void halt() noexcept
Halt CPU.
Definition cpu.hpp:77
std::uint64_t igros_quad_t
64-bit unsigned integer
Definition types.hpp:44
void cpuHalt() noexcept
Halt CPU.
Kernel text print functions.
void kprintf(const char *const format,...) noexcept
Kernel printf function (arguments are checked against format at compile time).
Definition kPrint.cpp:358
x86_64 (long mode): GDT, IDT, TSS, CPUID, MSR, CPU registers
Architecture register type deduction.
x86_64 task switch registers save
Definition register.hpp:32
Common C++ types redefinition.