From patchwork Wed Jul 28 09:39:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mohammed Gamal X-Patchwork-Id: 114718 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 o6S9dHNt021177 for ; Wed, 28 Jul 2010 09:39:17 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753806Ab0G1JjP (ORCPT ); Wed, 28 Jul 2010 05:39:15 -0400 Received: from mail-ww0-f42.google.com ([74.125.82.42]:43786 "EHLO mail-ww0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751961Ab0G1JjO (ORCPT ); Wed, 28 Jul 2010 05:39:14 -0400 Received: by wwf26 with SMTP id 26so4823928wwf.1 for ; Wed, 28 Jul 2010 02:39:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer; bh=SvW91fkwRBa9fqeCB4N/dJ/VAJQusnRUrtRSDvztWO8=; b=xIP/mkqlC7/aObQYhrrV4LYP8Ka9K28kmUjC4cGxms6dPiiVO9H4Musaba1aMoF24g OTN4V6yW87tGQM6U/rLn7G+xe1bYOGRnmtfkK3hpYg7rILwmCcRCGbryaplMcc8sLbI1 CRsOQTZjZBMt24JpeMKkOXCl0hvt2W6uSnACU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=lUhu4WEQ14RMI4FNCrdj33vr98vNQFtVNQzW1VdOLV1MDV8o6gPMniURGtBvgY0SxP rSpRHdThASqRHzO5Hue2B92VEy+2fhKjqBgwGweRSWmMiAtRJ/W245LWgqmF4S7hJnZ9 2gWu/xvj2iyQBGac+JRI8WMZOi7NkiNexPpeE= Received: by 10.227.156.21 with SMTP id u21mr10299498wbw.56.1280309953343; Wed, 28 Jul 2010 02:39:13 -0700 (PDT) Received: from localhost.localdomain ([41.238.104.174]) by mx.google.com with ESMTPS id h3sm1529675wbb.9.2010.07.28.02.39.11 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 28 Jul 2010 02:39:12 -0700 (PDT) From: Mohammed Gamal To: avi@redhat.com Cc: mtosatti@redhat.com, kvm@vger.kernel.org, Mohammed Gamal Subject: [PATCH] test: Add emulator test for iret instruction Date: Wed, 28 Jul 2010 12:39:01 +0300 Message-Id: <1280309941-13571-1-git-send-email-m.gamal005@gmail.com> X-Mailer: git-send-email 1.7.0.4 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]); Wed, 28 Jul 2010 09:39:17 +0000 (UTC) diff --git a/kvm/test/x86/realmode.c b/kvm/test/x86/realmode.c index bd79348..74456c3 100644 --- a/kvm/test/x86/realmode.c +++ b/kvm/test/x86/realmode.c @@ -865,6 +865,84 @@ void test_pusha_popa() print_serial("Pusha/Popa Test2: PASS\n"); } +void test_iret() +{ + struct regs inregs = { 0 }, outregs; + + MK_INSN(iret32, "pushf\n\t" + "pushl %cs\n\t" + "call 1f\n\t" /* a near call will push eip onto the stack */ + "jmp 2f\n\t" + "1: iret\n\t" + "2:\n\t" + ); + + MK_INSN(iret16, "pushfw\n\t" + "pushw %cs\n\t" + "callw 1f\n\t" + "jmp 2f\n\t" + "1: iretw\n\t" + "2:\n\t"); + + MK_INSN(iret_flags32, "pushfl\n\t" + "popl %eax\n\t" + "andl $~0x2, %eax\n\t" + "orl $0xffc08028, %eax\n\t" + "pushl %eax\n\t" + "pushl %cs\n\t" + "call 1f\n\t" + "jmp 2f\n\t" + "1: iret\n\t" + "2:\n\t"); + + MK_INSN(iret_flags16, "pushfw\n\t" + "popw %ax\n\t" + "and $~0x2, %ax\n\t" + "or $0x8028, %ax\n\t" + "pushw %ax\n\t" + "pushw %cs\n\t" + "callw 1f\n\t" + "jmp 2f\n\t" + "1: iretw\n\t" + "2:\n\t"); + + exec_in_big_real_mode(&inregs, &outregs, + insn_iret32, + insn_iret32_end - insn_iret32); + + if (!regs_equal(&inregs, &outregs, 0)) + print_serial("iret Test 1: FAIL\n"); + else + print_serial("iret Test 1: PASS\n"); + + exec_in_big_real_mode(&inregs, &outregs, + insn_iret16, + insn_iret16_end - insn_iret16); + + if (!regs_equal(&inregs, &outregs, 0)) + print_serial("iret Test 2: FAIL\n"); + else + print_serial("iret Test 2: PASS\n"); + + exec_in_big_real_mode(&inregs, &outregs, + insn_iret_flags32, + insn_iret_flags32_end - insn_iret_flags32); + + if (!regs_equal(&inregs, &outregs, R_AX)) + print_serial("iret Test 3: FAIL\n"); + else + print_serial("iret Test 3: PASS\n"); + + exec_in_big_real_mode(&inregs, &outregs, + insn_iret_flags16, + insn_iret_flags16_end - insn_iret_flags16); + + if (!regs_equal(&inregs, &outregs, R_AX)) + print_serial("iret Test 4: FAIL\n"); + else + print_serial("iret Test 4: PASS\n"); +} + void realmode_start(void) { test_null(); @@ -886,6 +964,7 @@ void realmode_start(void) /* long jmp test uses call near so test it after testing call */ test_long_jmp(); test_xchg(); + test_iret(); exit(0); }