From 5c10b231c892150927f37788b7e7ddf5290c74e4 Mon Sep 17 00:00:00 2001
From: Mohit Dhingra <mohitdhingras@gmail.com>
Date: Sat, 13 Apr 2013 23:43:23 +0530
Subject: [PATCH 1/3] Unit test for checking VMX capabilities

---
 x86/vmx_test.c |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)
 create mode 100644 x86/vmx_test.c

diff --git a/x86/vmx_test.c b/x86/vmx_test.c
new file mode 100644
index 0000000..ee7706e
--- /dev/null
+++ b/x86/vmx_test.c
@@ -0,0 +1,58 @@
+
+#include "../lib/libcflat.h"
+#include "../lib/x86/processor.h"
+#include "../lib/x86/msr.h"
+
+
+
+int main(int ac, char **av)
+{
+
+  int eax_initialize = 1; 
+  uint32_t test_vmx_capabilities = 0;
+
+
+
+  int code = 0;
+
+  union {
+  uint32_t where[4];
+  char vendor[17];
+  }s;
+
+
+  
+  asm volatile ("mov %1, %%eax\n\t"  		// mov source destination
+		"cpuid\n\t"			// When eax = 1, cpuid puts Feature Flags in ecx and edx registers. Bit 5 in ecx tells whether VMX is supported or not.
+//		"and $0x20, %%ecx\n\t"  	// ANDing ecx with 0x20 (00100000), if it results in non-zero, then VMX capabilities are present.
+		"mov %%ecx, %0"			// Storing the result into test_vmx_capabilities
+
+		:"=r"(test_vmx_capabilities)	// Ouputs : test_vmx_capabilities
+		:"r"(eax_initialize)		// Inputs : eax_initialize
+		:"eax","ecx");
+
+
+  printf("Feauture Flag returned in ecx : 0x%x ", test_vmx_capabilities);
+
+  if ( test_vmx_capabilities & 0x20 )
+	printf ("VMX capabilities present ! \n");
+  else
+	printf ("VMX capabilities not present ! \n");
+
+
+
+  // Prints vendor ID 
+
+  asm volatile("cpuid":"=a"(*s.where),"=b"(*(s.where+1)),
+               "=c"(*(s.where+3)),"=d"(*(s.where+2)):"a"(code));
+
+  s.vendor[17] = '\0';
+ 
+  printf("Vendor ID (returned by CPUID) : %s\n", (s.vendor+4)); 
+
+
+
+ 
+
+ return 1;
+}
-- 
1.7.3.4


From 8f1f5ca9505352d3139f648c7a359ecfaaf9088a Mon Sep 17 00:00:00 2001
From: Mohit Dhingra <mohitdhingras@gmail.com>
Date: Sat, 13 Apr 2013 23:43:54 +0530
Subject: [PATCH 2/3] Unit test for checking VMX capabilities

---
 config-x86-common.mak |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/config-x86-common.mak b/config-x86-common.mak
index 1f0f1ba..df2a42e 100644
--- a/config-x86-common.mak
+++ b/config-x86-common.mak
@@ -31,7 +31,7 @@ FLATLIBS = lib/libcflat.a $(libgcc)
 
 tests-common = $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \
                $(TEST_DIR)/smptest.flat  $(TEST_DIR)/port80.flat \
-               $(TEST_DIR)/realmode.flat $(TEST_DIR)/msr.flat \
+               $(TEST_DIR)/realmode.flat $(TEST_DIR)/msr.flat $(TEST_DIR)/vmx_test.flat \
                $(TEST_DIR)/hypercall.flat $(TEST_DIR)/sieve.flat \
                $(TEST_DIR)/kvmclock_test.flat  $(TEST_DIR)/eventinj.flat \
                $(TEST_DIR)/s3.flat $(TEST_DIR)/pmu.flat \
@@ -79,6 +79,8 @@ $(TEST_DIR)/realmode.o: bits = 32
 
 $(TEST_DIR)/msr.elf: $(cstart.o) $(TEST_DIR)/msr.o
 
+$(TEST_DIR)/vmx_test.elf: $(cstart.o) $(TEST_DIR)/vmx_test.o
+
 $(TEST_DIR)/idt_test.elf: $(cstart.o) $(TEST_DIR)/idt_test.o
 
 $(TEST_DIR)/xsave.elf: $(cstart.o) $(TEST_DIR)/xsave.o
-- 
1.7.3.4


From 4fb354449e5a718fbf1c0124b37ef51ad32119f8 Mon Sep 17 00:00:00 2001
From: Mohit Dhingra <mohitdhingras@gmail.com>
Date: Sat, 13 Apr 2013 23:44:20 +0530
Subject: [PATCH 3/3] Unit test for checking VMX capabilities

---
 x86/unittests.cfg |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/x86/unittests.cfg b/x86/unittests.cfg
index 5e08c55..6230acf 100644
--- a/x86/unittests.cfg
+++ b/x86/unittests.cfg
@@ -66,6 +66,29 @@ file = idt_test.flat
 [msr]
 file = msr.flat
 
+[vmx_test]
+file = vmx_test.flat
+
+[port80]
+file = port80.flat
+
+[realmode]
+file = realmode.flat
+
+[sieve]
+file = sieve.flat
+
+[tsc]
+file = tsc.flat
+
+[xsave]
+file = xsave.flat
+
+[rmap_chain]
+file = rmap_chain.flat
+
+[svm]
+file = svm.flat
 [port80]
 file = port80.flat
 
@@ -101,4 +124,4 @@ extra_params = --append "10000000 `date +%s`"
 
 [pcid]
 file = pcid.flat
-extra_params = -cpu qemu64,+pcid
\ No newline at end of file
+extra_params = -cpu qemu64,+pcid
-- 
1.7.3.4

