IgrOS-Kernel 0.1.34.545
Simple C++20 Kernel for i386/x86_64
Loading...
Searching...
No Matches
features.cpp
Go to the documentation of this file.
1
11
12
13// IgrOS-Kernel arch x86
14#include <arch/x86/features.hpp>
15
16#if defined(IGROS_ARCH_x86_64)
17
18// IgrOS-Kernel arch x86_64
19#include <arch/x86_64/cpuid.hpp>
20#include <arch/x86_64/msr.hpp>
21// IgrOS-Kernel library
22#include <klib/kFlags.hpp>
23
24#endif
25
26
27#ifdef __cplusplus
28
29extern "C" {
30
31#endif // __cplusplus
32
33
34 // Enable no-execute page protection if CPU supports it
35 [[nodiscard]]
36 auto cpuEnableNoExecute() noexcept -> bool {
37
38#if defined(IGROS_ARCH_x86_64)
39
40 using namespace igros;
41 using namespace igros::x86_64;
42
43 // CPUID.80000001h:EDX.NX
45 return false;
46 }
47 // Set EFER.NXE: NX bit in page tables is reserved (faults) until then
49 return true;
50
51#else
52
53 // No PAE page tables on i386 - no NX bit
54 return false;
55
56#endif
57 }
58
59
60#ifdef __cplusplus
61
62} // extern "C"
63
64#endif // __cplusplus
65
static constexpr auto from(const U value) noexcept -> kFlags
From raw value (hardware register, table entry).
Definition kFlags.hpp:55
CPUID detection.
auto cpuEnableNoExecute() noexcept -> bool
Enable no-execute page protection (EFER.NXE) if CPU supports it.
Definition features.cpp:36
CPU feature control.
Bit flags template datatype.
MSR registers operations.
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
@ NX
No-execute page protection.
Definition cpuid.hpp:37
auto cpuid(const CPUID leaf, const igros_dword_t subleaf=0_u32) noexcept -> cpuidRegs_t
Execute CPUID (CPUID is always available in long mode; caller checks leaf is supported).
Definition cpuid.hpp:56
auto readMSR(const MSR reg) noexcept -> igros_quad_t
Read MSR register (RDMSR returns EDX:EAX).
Definition msr.hpp:49
@ NXE
No-execute enable.
Definition msr.hpp:41
@ EXTENDED_INFO
Extended feature flags (long mode, NX, 1 GB pages).
Definition cpuid.hpp:31
@ EFER
Extended feature enable.
Definition msr.hpp:27
auto cpuidHasLeaf(const CPUID leaf) noexcept -> bool
Check CPUID leaf is supported (basic and extended ranges are checked separately).
Definition cpuid.hpp:70
IgrOS kernel: common types and literals.