visor/include/x86/msr.h

57 lines
1.3 KiB
C
Raw Normal View History

2025-03-10 19:19:53 +01:00
#ifndef _VISOR_MSR_H_
#define _VISOR_MSR_H_
#include <stdint.h>
2025-03-11 01:40:28 +01:00
#define IA32_FEATURE_CONTROL 0x03A
#define IA32_DEBUGCTL 0x1D9
#define IA32_PAT 0x277
2025-03-10 19:19:53 +01:00
#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_VMCS_ENUM 0x48A
2025-03-11 02:06:12 +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
{
uint64_t value;
__asm__ ("rdmsr\n\t" : "=A"(value) : "c"(msr));
return value;
}
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
{
uint32_t high = 0;
__asm__ ("wrmsr\n\t" :: "c"(msr), "a"(value), "d"(high));
}
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
{
__asm__ ("wrmsr\n\t" :: "c"(msr), "A"(value));
}
#endif