summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammed Gamal <m.gamal005@gmail.com>2010-07-28 12:39:01 +0300
committerMarcelo Tosatti <mtosatti@redhat.com>2010-07-29 12:50:28 -0300
commit3220650f0b47073f16a313d52c167b3d5942d359 (patch)
tree39b32af49926d223427040bf067e64ee6be29e00
parentd41402af66ad6fa5262ecbc2c22e7812d5cc055b (diff)
test: Add emulator test for iret instruction
This adds a unit test for real mode emulation of the iret instruction Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
-rw-r--r--kvm/test/x86/realmode.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/kvm/test/x86/realmode.c b/kvm/test/x86/realmode.c
index 587f33122..bb161ac48 100644
--- a/kvm/test/x86/realmode.c
+++ b/kvm/test/x86/realmode.c
@@ -869,6 +869,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();
@@ -890,6 +968,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);
}