11#pragma once
22#include " types.hpp"
3+ #include " assert.hpp"
34
45struct Msr {
56 constexpr explicit Msr (u32 offset) : offset {offset} {}
@@ -22,9 +23,25 @@ struct Msr {
2223
2324namespace msrs {
2425 constexpr Msr IA32_APIC_BASE {0x1B };
26+ constexpr Msr IA32_FEATURE_CONTROL {0x3A };
2527 constexpr Msr IA32_MTRRCAP {0xFE };
2628 constexpr Msr IA32_PAT {0x277 };
2729 constexpr Msr IA32_MTRRDEFTYPE {0x2FF };
30+ constexpr Msr IA32_VMX_BASIC {0x480 };
31+ constexpr Msr IA32_VMX_PINBASED_CTLS {0x481 };
32+ constexpr Msr IA32_VMX_PROCBASED_CTLS {0x482 };
33+ constexpr Msr IA32_VMX_EXIT_CTLS {0x483 };
34+ constexpr Msr IA32_VMX_ENTRY_CTLS {0x484 };
35+ constexpr Msr IA32_VMX_MISC {0x485 };
36+ constexpr Msr IA32_VMX_CR0_FIXED0 {0x486 };
37+ constexpr Msr IA32_VMX_CR0_FIXED1 {0x487 };
38+ constexpr Msr IA32_VMX_CR4_FIXED0 {0x488 };
39+ constexpr Msr IA32_VMX_CR4_FIXED1 {0x489 };
40+ constexpr Msr IA32_VMX_PROCBASED_CTLS2 {0x48B };
41+ constexpr Msr IA32_VMX_TRUE_PINBASED_CTLS {0x48D };
42+ constexpr Msr IA32_VMX_TRUE_PROCBASED_CTLS {0x48E };
43+ constexpr Msr IA32_VMX_PROCBASED_CTLS3 {0x492 };
44+ constexpr Msr IA32_VMX_EXIT_CTLS2 {0x493 };
2845 constexpr Msr IA32_EFER {0xC0000080 };
2946 constexpr Msr IA32_STAR {0xC0000081 };
3047 constexpr Msr IA32_LSTAR {0xC0000082 };
@@ -55,6 +72,20 @@ inline void wrxcr(u32 index, u64 value) {
5572 asm volatile (" xsetbv" : : " c" (index), " a" (low), " d" (high) : " memory" );
5673}
5774
75+ inline u64 rdxcr (u32 index) {
76+ u32 low;
77+ u32 high;
78+ asm volatile (" xgetbv" : " =a" (low), " =d" (high) : " c" (index) : " memory" );
79+ return static_cast <u64 >(high) << 32 | low;
80+ }
81+
82+ static inline u64 rdtsc () {
83+ u32 low;
84+ u32 high;
85+ asm volatile (" rdtsc" : " =a" (low), " =d" (high));
86+ return static_cast <u64 >(high) << 32 | low;
87+ }
88+
5889struct CpuFeatures {
5990 usize xsave_area_size;
6091 bool rdrnd;
@@ -65,6 +96,7 @@ struct CpuFeatures {
6596 bool smep;
6697 bool smap;
6798 bool rdseed;
99+ bool vmx;
68100};
69101static_assert (offsetof(CpuFeatures, smap) == 14 );
70102
0 commit comments