2025-03-10 19:19:53 +01:00
|
|
|
#ifndef _VISOR_MSR_H_
|
|
|
|
|
#define _VISOR_MSR_H_
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2025-03-11 20:59:39 +01:00
|
|
|
#define IA32_FEATURE_CONTROL 0x03A
|
|
|
|
|
#define IA32_DEBUGCTL 0x1D9
|
|
|
|
|
#define IA32_PAT 0x277
|
|
|
|
|
|
|
|
|
|
#define IA32_VMX_BASIC 0x480
|
|
|
|
|
#define IA32_VMX_PINBASED_CTLS 0x481
|
|
|
|
|
#define IA32_VMX_PROCBASED_CTLS 0x482
|
|
|
|
|
#define IA32_VMX_EXIT_CTLS 0x483
|
|
|
|
|
#define IA32_VMX_ENTRY_CTLS 0x484
|
|
|
|
|
#define IA32_VMX_MISC 0x485
|
|
|
|
|
#define IA32_VMX_CR0_FIXED0 0x486
|
|
|
|
|
#define IA32_VMX_CR0_FIXED1 0x487
|
|
|
|
|
#define IA32_VMX_CR4_FIXED0 0x488
|
|
|
|
|
#define IA32_VMX_CR4_FIXED1 0x489
|
|
|
|
|
#define IA32_VMX_TRUE_ENTRY_CTLS 0x490
|
|
|
|
|
#define IA32_VMX_VMCS_ENUM 0x48A
|
2025-03-12 17:20:39 +01:00
|
|
|
#define IA32_VMX_PROCBASED_CTLS2 0x48B
|
2025-03-12 03:25:50 +01:00
|
|
|
#define IA32_VMX_TRUE_PINBASED_CTLS 0x48D
|
|
|
|
|
#define IA32_VMX_TRUE_PROCBASED_CTLS 0x48E
|
2025-03-12 17:20:39 +01:00
|
|
|
#define IA32_VMX_TRUE_EXIT_CTLS 0x48F
|
2025-03-11 20:59:39 +01:00
|
|
|
|
|
|
|
|
#define IA32_EFER 0xC0000080
|
|
|
|
|
#define IA32_FS_BASE 0xC0000100
|
|
|
|
|
#define IA32_GS_BASE 0xC0000101
|
|
|
|
|
#define IA32_KERNEL_GS_BASE 0xC0000102
|
2025-03-11 01:40:28 +01:00
|
|
|
|
2025-03-10 19:19:53 +01:00
|
|
|
static inline uint32_t
|
2025-03-11 01:40:28 +01:00
|
|
|
readmsr32(uint32_t msr)
|
2025-03-10 19:19:53 +01:00
|
|
|
{
|
|
|
|
|
uint32_t value;
|
2025-03-10 20:24:32 +01:00
|
|
|
__asm__ ("rdmsr\n\t" : "=a"(value) : "c"(msr) : "edx");
|
2025-03-10 19:19:53 +01:00
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline uint64_t
|
2025-03-11 01:40:28 +01:00
|
|
|
readmsr64(uint32_t msr)
|
2025-03-10 19:19:53 +01:00
|
|
|
{
|
2025-03-11 20:59:39 +01:00
|
|
|
uint32_t lo, hi;
|
|
|
|
|
__asm__ ("rdmsr\n\t" : "=a"(lo), "=d"(hi) : "c"(msr));
|
|
|
|
|
return lo | ((uint64_t)hi << 32);
|
2025-03-10 19:19:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
2025-03-11 01:40:28 +01:00
|
|
|
writemsr32(uint32_t msr, uint32_t value)
|
2025-03-10 19:19:53 +01:00
|
|
|
{
|
2025-03-11 20:59:39 +01:00
|
|
|
uint32_t hi = 0;
|
|
|
|
|
__asm__ ("wrmsr\n\t" :: "c"(msr), "a"(value), "d"(hi));
|
2025-03-10 19:19:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
2025-03-11 01:40:28 +01:00
|
|
|
writemsr64(uint32_t msr, uint64_t value)
|
2025-03-10 19:19:53 +01:00
|
|
|
{
|
2025-03-11 20:59:39 +01:00
|
|
|
uint32_t lo = value, hi = value >> 32;
|
|
|
|
|
__asm__ ("wrmsr\n\t" :: "c"(msr), "a"(lo), "d"(hi));
|
2025-03-10 19:19:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|