visor/include/x86/msr.h

55 lines
1.2 KiB
C

#ifndef _VISOR_MSR_H_
#define _VISOR_MSR_H_
#include <stdint.h>
#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_VMCS_ENUM 0x48A
#define IA32_EFER 0xC0000080
#define IA32_FS_BASE 0xC0000100
#define IA32_GS_BASE 0xC0000101
static inline uint32_t
readmsr32(uint32_t msr)
{
uint32_t value;
__asm__ ("rdmsr\n\t" : "=a"(value) : "c"(msr) : "edx");
return value;
}
static inline uint64_t
readmsr64(uint32_t msr)
{
uint64_t value;
__asm__ ("rdmsr\n\t" : "=A"(value) : "c"(msr));
return value;
}
static inline void
writemsr32(uint32_t msr, uint32_t value)
{
uint32_t high = 0;
__asm__ ("wrmsr\n\t" :: "c"(msr), "a"(value), "d"(high));
}
static inline void
writemsr64(uint32_t msr, uint64_t value)
{
__asm__ ("wrmsr\n\t" :: "c"(msr), "A"(value));
}
#endif