Skip to contentSkip to conversation

test: add test for xchg instruction

PATCH Applied Wei Yongjun 2 participants 2 messages Jul 15, 2010 – Jul 16, 2010 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test: add test for xchg instruction

This patch add test for xchg instruction.

---
 kvm/test/x86/emulator.c |   52 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)
kvm/test/x86/emulator.c +52 -0
index 6db1305..2af3d96 100644
@@ -270,6 +270,56 @@ void test_lmsw(void)
 	asm("lmsw %0" : : "r"(msw));
 }
 
+void test_xchg(void *mem)
+{
+	unsigned long *memq = mem;
+	unsigned long rax;
+
+	asm volatile("mov $0x123456789abcdef, %%rax\n\t"
+		     "mov %%rax, (%[memq])\n\t"
+		     "mov $0xfedcba9876543210, %%rax\n\t"
+		     "xchg %%al, (%[memq])\n\t"
+		     "mov %%rax, %[rax]\n\t"
+		     : [rax]"=r"(rax)
+		     : [memq]"r"(memq)
+		     : "memory");
+	report("xchg reg, r/m (1)",
+	       rax == 0xfedcba98765432ef && *memq == 0x123456789abcd10);
+
+	asm volatile("mov $0x123456789abcdef, %%rax\n\t"
+		     "mov %%rax, (%[memq])\n\t"
+		     "mov $0xfedcba9876543210, %%rax\n\t"
+		     "xchg %%ax, (%[memq])\n\t"
+		     "mov %%rax, %[rax]\n\t"
+		     : [rax]"=r"(rax)
+		     : [memq]"r"(memq)
+		     : "memory");
+	report("xchg reg, r/m (2)",
+	       rax == 0xfedcba987654cdef && *memq == 0x123456789ab3210);
+
+	asm volatile("mov $0x123456789abcdef, %%rax\n\t"
+		     "mov %%rax, (%[memq])\n\t"
+		     "mov $0xfedcba9876543210, %%rax\n\t"
+		     "xchg %%eax, (%[memq])\n\t"
+		     "mov %%rax, %[rax]\n\t"
+		     : [rax]"=r"(rax)
+		     : [memq]"r"(memq)
+		     : "memory");
+	report("xchg reg, r/m (3)",
+	       rax == 0x89abcdef && *memq == 0x123456776543210);
+
+	asm volatile("mov $0x123456789abcdef, %%rax\n\t"
+		     "mov %%rax, (%[memq])\n\t"
+		     "mov $0xfedcba9876543210, %%rax\n\t"
+		     "xchg %%rax, (%[memq])\n\t"
+		     "mov %%rax, %[rax]\n\t"
+		     : [rax]"=r"(rax)
+		     : [memq]"r"(memq)
+		     : "memory");
+	report("xchg reg, r/m (4)",
+	       rax == 0x123456789abcdef && *memq == 0xfedcba9876543210);
+}
+
 int main()
 {
 	void *mem;
@@ -292,6 +342,8 @@ int main()
 	test_push(mem);
 	test_pop(mem);
 
+	test_xchg(mem);
+
 	test_cr8();
 
 	test_smsw();
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 6 lines · Wei Yongjun

This patch add test for xchg instruction.

---
 kvm/test/x86/emulator.c |   52 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)

Applied, thanks.