/* Check if AMD CPU supports SVM virtualization (aka AMDV) */
#include <signal.h>
#include <setjmp.h>
#include <stdio.h>

sigjmp_buf recover;

static inline unsigned int cpuid_eax(unsigned int op)
{
        unsigned int eax;
        asm("cpuid" : "=a" (eax) : "0" (op) : "bx", "cx", "dx");
        return eax;
}

void nosvm(int s)
{
        siglongjmp(recover, 1);
}

int has_svm(void)
{
        unsigned eax;
        signal(SIGILL,nosvm);
        if (sigsetjmp(recover, 1) == 0)
                eax = cpuid_eax(0x8000000a);
        else
                eax = 0;
        signal(SIGILL, SIG_DFL);
        return (eax & 0x7f) > 0;
}

int main(void)
{
	printf("%s have SVM.\n", has_svm() ? "Does" : "Doesn't");
	return 0;
}


