2025-03-10 19:19:53 +01:00
|
|
|
#ifndef _VISOR_VMX_H_
|
|
|
|
|
#define _VISOR_VMX_H_
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2025-03-10 20:24:32 +01:00
|
|
|
struct VMXON {
|
2025-03-10 19:19:53 +01:00
|
|
|
uint32_t revisionID;
|
|
|
|
|
uint32_t abortIndicator;
|
2025-03-10 20:24:32 +01:00
|
|
|
char vmcsData[];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct VMCS {
|
2025-03-10 20:41:09 +01:00
|
|
|
uint32_t revisionID;
|
2025-03-10 19:19:53 +01:00
|
|
|
/* Guest-state area */
|
|
|
|
|
/* Host-state area */
|
|
|
|
|
/* VM-execution control fields */
|
|
|
|
|
/* VM-exit control fields */
|
|
|
|
|
/* VM-entry control fields */
|
|
|
|
|
/* VM-exit information fields */
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-10 20:24:32 +01:00
|
|
|
static inline uint64_t
|
2025-03-10 19:19:53 +01:00
|
|
|
vmxon(void *region)
|
|
|
|
|
{
|
2025-03-10 20:24:32 +01:00
|
|
|
uint64_t regionpa = (uint64_t)region;
|
|
|
|
|
uint64_t flags;
|
|
|
|
|
__asm__ volatile (
|
2025-03-10 20:41:09 +01:00
|
|
|
"vmxon %1\n\t"
|
|
|
|
|
"pushf \n\t"
|
|
|
|
|
"pop %0\n\t"
|
2025-03-10 20:24:32 +01:00
|
|
|
: "=r"(flags) : "m"(regionpa));
|
|
|
|
|
return flags;
|
2025-03-10 19:19:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
vmxoff(void)
|
|
|
|
|
{
|
|
|
|
|
__asm__ volatile ("vmxoff\n\t" ::);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-10 20:41:09 +01:00
|
|
|
static inline uint64_t
|
2025-03-10 19:19:53 +01:00
|
|
|
vmptrld(void *region)
|
|
|
|
|
{
|
2025-03-10 20:41:09 +01:00
|
|
|
uint64_t regionpa = (uint64_t)region;
|
|
|
|
|
uint64_t flags;
|
|
|
|
|
__asm__ volatile (
|
|
|
|
|
"vmptrld %1\n\t"
|
|
|
|
|
"pushf \n\t"
|
|
|
|
|
"pop %0\n\t"
|
|
|
|
|
: "=r"(flags) : "m"(regionpa));
|
|
|
|
|
return flags;
|
2025-03-10 19:19:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
vmptrst(void *arg)
|
|
|
|
|
{
|
|
|
|
|
__asm__ volatile ("vmptrst\n\t" ::);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-10 20:41:09 +01:00
|
|
|
static inline uint64_t
|
2025-03-10 19:19:53 +01:00
|
|
|
vmclear(void *region)
|
|
|
|
|
{
|
2025-03-10 20:41:09 +01:00
|
|
|
uint64_t regionpa = (uint64_t)region;
|
|
|
|
|
uint64_t flags;
|
|
|
|
|
__asm__ volatile (
|
|
|
|
|
"vmclear %1\n\t"
|
|
|
|
|
"pushf \n\t"
|
|
|
|
|
"pop %0\n\t"
|
|
|
|
|
: "=r"(flags) : "m"(regionpa));
|
|
|
|
|
return flags;
|
2025-03-10 19:19:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
vmlaunch(void)
|
|
|
|
|
{
|
|
|
|
|
__asm__ volatile ("vmlaunch\n\t" ::);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
vmresume(void)
|
|
|
|
|
{
|
|
|
|
|
__asm__ volatile ("vmresume\n\t" ::);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
vmread()
|
|
|
|
|
{
|
|
|
|
|
__asm__ volatile ("vmread\n\t" ::);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
vmwrite()
|
|
|
|
|
{
|
|
|
|
|
__asm__ volatile ("vmwrite\n\t" ::);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
vmcall()
|
|
|
|
|
{
|
|
|
|
|
__asm__ volatile ("vmcall\n\t" ::);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|