From patchwork Thu Jul 15 00:58:47 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yongjun X-Patchwork-Id: 112122 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o6F11Lo1021462 for ; Thu, 15 Jul 2010 01:01:21 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758019Ab0GOBBT (ORCPT ); Wed, 14 Jul 2010 21:01:19 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:61214 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1757878Ab0GOBBT (ORCPT ); Wed, 14 Jul 2010 21:01:19 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 7828A17012D; Thu, 15 Jul 2010 09:01:17 +0800 (CST) Received: from fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id o6F0wUNT028631; Thu, 15 Jul 2010 08:58:31 +0800 Received: from [10.167.141.76] (unknown [10.167.141.76]) by fnst.cn.fujitsu.com (Postfix) with ESMTPA id 95AC71CC1FA; Thu, 15 Jul 2010 09:01:39 +0800 (CST) Message-ID: <4C3E5D47.2030507@cn.fujitsu.com> Date: Thu, 15 Jul 2010 08:58:47 +0800 From: Wei Yongjun User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.10) Gecko/20100528 Thunderbird/3.0.5 MIME-Version: 1.0 To: Marcelo Tosatti , Avi Kivity CC: kvm@vger.kernel.org Subject: [PATCH] test: add test for xchg instruction Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 15 Jul 2010 01:01:22 +0000 (UTC) diff --git a/kvm/test/x86/emulator.c b/kvm/test/x86/emulator.c index 6db1305..2af3d96 100644 --- a/kvm/test/x86/emulator.c +++ b/kvm/test/x86/emulator.c @@ -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();