IgrOS-Kernel 0.1.34.545
Simple C++20 Kernel for i386/x86_64
Loading...
Searching...
No Matches
msr.hpp
Go to the documentation of this file.
1
11
12
13#pragma once
14
15
16// IgrOS-Kernel arch
17#include <arch/types.hpp>
18
19
20// x86_64 namespace
21namespace igros::x86_64 {
22
23
25 enum class MSR : igros_dword_t {
26 APIC_BASE = 0x0000001B_u32,
27 EFER = 0xC0000080_u32,
28 STAR = 0xC0000081_u32,
29 LSTAR = 0xC0000082_u32,
30 FMASK = 0xC0000084_u32,
31 FS_BASE = 0xC0000100_u32,
32 GS_BASE = 0xC0000101_u32,
33 KERNEL_GS_BASE = 0xC0000102_u32,
34 };
35
37 enum class EFER : igros_quad_t {
38 SCE = 0x0000000000000001_u64,
39 LME = 0x0000000000000100_u64,
40 LMA = 0x0000000000000400_u64,
41 NXE = 0x0000000000000800_u64,
42 };
43
44
48 [[nodiscard]]
49 inline auto readMSR(const MSR reg) noexcept -> igros_quad_t {
50 auto low {igros_dword_t {}}; // NOLINT(misc-const-correctness): written by RDMSR
51 auto high {igros_dword_t {}}; // NOLINT(misc-const-correctness): written by RDMSR
52 asm volatile("rdmsr" : "=a"(low), "=d"(high) : "c"(static_cast<igros_dword_t>(reg)));
53 return (static_cast<igros_quad_t>(high) << 32) | low;
54 }
55
59 inline void writeMSR(const MSR reg, const igros_quad_t value) noexcept {
60 asm volatile(
61 "wrmsr"
62 :
63 : "c"(static_cast<igros_dword_t>(reg)),
64 "a"(static_cast<igros_dword_t>(value)),
65 "d"(static_cast<igros_dword_t>(value >> 32))
66 : "memory"
67 );
68 }
69
70
71} // namespace igros::x86_64
72
std::uint32_t igros_dword_t
32-bit unsigned integer
Definition types.hpp:43
std::uint64_t igros_quad_t
64-bit unsigned integer
Definition types.hpp:44
x86_64 (long mode): GDT, IDT, TSS, CPUID, MSR, CPU registers
void writeMSR(const MSR reg, const igros_quad_t value) noexcept
Write MSR register (WRMSR takes EDX:EAX).
Definition msr.hpp:59
auto readMSR(const MSR reg) noexcept -> igros_quad_t
Read MSR register (RDMSR returns EDX:EAX).
Definition msr.hpp:49
EFER
EFER register bits.
Definition msr.hpp:37
@ SCE
SYSCALL enable.
Definition msr.hpp:38
@ NXE
No-execute enable.
Definition msr.hpp:41
@ LMA
Long mode active.
Definition msr.hpp:40
@ LME
Long mode enable.
Definition msr.hpp:39
MSR
Model specific registers.
Definition msr.hpp:25
@ KERNEL_GS_BASE
SWAPGS target.
Definition msr.hpp:33
@ LSTAR
SYSCALL 64-bit entry.
Definition msr.hpp:29
@ APIC_BASE
Local APIC base.
Definition msr.hpp:26
@ FS_BASE
FS segment base.
Definition msr.hpp:31
@ FMASK
SYSCALL RFLAGS mask.
Definition msr.hpp:30
@ STAR
SYSCALL segments.
Definition msr.hpp:28
@ GS_BASE
GS segment base.
Definition msr.hpp:32
Common C++ types redefinition.