#define VMI_CALL_CPUID 0 #define VMI_CALL_WRMSR 1 #define VMI_CALL_RDMSR 2 #define VMI_CALL_SetGDT 3 #define VMI_CALL_SetLDT 4 #define VMI_CALL_SetIDT 5 #define VMI_CALL_SetTR 6 #define VMI_CALL_GetGDT 7 #define VMI_CALL_GetLDT 8 #define VMI_CALL_GetIDT 9 #define VMI_CALL_GetTR 10 #define VMI_CALL_WriteGDTEntry 11 #define VMI_CALL_WriteLDTEntry 12 #define VMI_CALL_WriteIDTEntry 13 #define VMI_CALL_UpdateKernelStack 14 #define VMI_CALL_SetCR0 15 #define VMI_CALL_SetCR2 16 #define VMI_CALL_SetCR3 17 #define VMI_CALL_SetCR4 18 #define VMI_CALL_GetCR0 19 #define VMI_CALL_GetCR2 20 #define VMI_CALL_GetCR3 21 #define VMI_CALL_GetCR4 22 #define VMI_CALL_WBINVD 23 #define VMI_CALL_SetDR 24 #define VMI_CALL_GetDR 25 #define VMI_CALL_RDPMC 26 #define VMI_CALL_RDTSC 27 #define VMI_CALL_CLTS 28 #define VMI_CALL_EnableInterrupts 29 #define VMI_CALL_DisableInterrupts 30 #define VMI_CALL_GetInterruptMask 31 #define VMI_CALL_SetInterruptMask 32 #define VMI_CALL_IRET 33 #define VMI_CALL_SYSEXIT 34 #define VMI_CALL_Halt 35 #define VMI_CALL_Reboot 36 #define VMI_CALL_Shutdown 37 #define VMI_CALL_SetPxE 38 #define VMI_CALL_SetPxELong 39 #define VMI_CALL_UpdatePxE 40 #define VMI_CALL_UpdatePxELong 41 #define VMI_CALL_MachineToPhysical 42 #define VMI_CALL_PhysicalToMachine 43 #define VMI_CALL_AllocatePage 44 #define VMI_CALL_ReleasePage 45 #define VMI_CALL_InvalPage 46 #define VMI_CALL_FlushTLB 47 #define VMI_CALL_SetLinearMapping 48 #define VMI_CALL_SetIOPLMask 61 #define VMI_CALL_SetInitialAPState 62 #define VMI_CALL_APICWrite 63 #define VMI_CALL_APICRead 64 #define VMI_CALL_SetLazyMode 73 typedef unsigned long long uint64_t; /* VMI Relocation types */ #define VMI_RELOCATION_NONE 0 #define VMI_RELOCATION_CALL_REL 1 #define VMI_RELOCATION_JUMP_REL 2 #define VMI_RELOCATION_NOP 3 struct vmi_relocation_info { unsigned char *eip; unsigned char type; unsigned char reserved[3]; }; static void putc(char value) { asm volatile("outb %b0, %w1": :"a" (value), "Nd" (0x410)); } static void puts(const char *string) { for (; *string; string++) putc(*string); } static void putint(int value) { asm volatile("outl %0, %w1": :"a" (value), "Nd" (0x414)); } static void __attribute__((regparm(3))) vmiSysExit(void) { puts("foo\n"); asm volatile("sti; sysexit"); } static void __attribute__((regparm(3))) vmiIRET(void) { puts("foo\n"); asm volatile("iret"); } uint64_t __attribute__((regparm(2))) vmi_get_relocation_info(int call) { struct vmi_relocation_info reloc; if (call == VMI_CALL_SYSEXIT) { puts("relocation("); putint(call); puts(") - "); putint((unsigned long)vmiSysExit); puts("\n"); reloc.eip = (void *)vmiSysExit; reloc.type = VMI_RELOCATION_JUMP_REL; } else if (call == VMI_CALL_IRET) { reloc.eip = (void *)vmiIRET; reloc.type = VMI_RELOCATION_JUMP_REL; } else { reloc.eip = 0; reloc.type = 0; } return *(uint64_t *)&reloc; }