Skip to contentSkip to conversation

test: Add emulator test for iret instruction

PATCH In review Mohammed Gamal 2 participants 3 messages Jul 27, 2010 – Jul 28, 2010 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test: Add emulator test for iret instruction

This adds a unit test for real mode emulation of the iret instruction

---
 kvm/test/x86/realmode.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
kvm/test/x86/realmode.c +23 -0
index bd79348..16716cc 100644
@@ -865,6 +865,28 @@ void test_pusha_popa()
 		print_serial("Pusha/Popa Test2: PASS\n");
 }
 
+void test_iret()
+{
+	struct regs inregs = { 0 }, outregs;
+
+	MK_INSN(iret, "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"
+		     );
+
+	exec_in_big_real_mode(&inregs, &outregs,
+			      insn_iret,
+			      insn_iret_end - insn_iret);
+
+	if (!regs_equal(&inregs, &outregs, 0))
+		print_serial("iret Test 1: FAIL\n");
+	else
+		print_serial("iret Test 1: PASS\n");
+}
+
 void realmode_start(void)
 {
 	test_null();
@@ -886,6 +908,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);
 }
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 27 lines · Mohammed Gamal

This adds a unit test for real mode emulation of the iret instruction

---
  kvm/test/x86/realmode.c |   23 +++++++++++++++++++++++
  1 files changed, 23 insertions(+), 0 deletions(-)
kvm/test/x86/realmode.c +12 -0
index bd79348..16716cc 100644
@@ -865,6 +865,28 @@ void test_pusha_popa()
  		print_serial("Pusha/Popa Test2: PASS\n");
  }
 
+void test_iret()
+{
+	struct regs inregs = { 0 }, outregs;
+
+	MK_INSN(iret, "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"
+		     );
+

kvm/test/x86/realmode.c void test_pusha_popa() · line 889

Quoted 10 lines
kvm/test/x86/realmode.c +10 -0
+	exec_in_big_real_mode(&inregs,&outregs,
+			      insn_iret,
+			      insn_iret_end - insn_iret);
+
+	if (!regs_equal(&inregs,&outregs, 0))
+		print_serial("iret Test 1: FAIL\n");
+	else
+		print_serial("iret Test 1: PASS\n");
+}
+

This tests 32-bit iret, please test 16-bit iret as well (pushfw, pushw cs, callw, iretw).

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#2 lore raw
Quoted 33 lines · Avi Kivity
Quoted 32 lines · Mohammed Gamal

This adds a unit test for real mode emulation of the iret instruction

---
  kvm/test/x86/realmode.c |   23 +++++++++++++++++++++++
  1 files changed, 23 insertions(+), 0 deletions(-)
kvm/test/x86/realmode.c +7 -0
index bd79348..16716cc 100644
@@ -865,6 +865,28 @@ void test_pusha_popa()
          print_serial("Pusha/Popa Test2: PASS\n");
  }
 
+void test_iret()
+{
+    struct regs inregs = { 0 }, outregs;
+
+    MK_INSN(iret, "pushf\n\t"
+              "pushl %cs\n\t"
+              "call 1f\n\t" /* a near call will push eip onto the 

stack */

kvm/test/x86/realmode.c +9 -0
+              "jmp 2f\n\t"
+              "1:iret\n\t"
+              "2:\n\t"
+             );
+
+    exec_in_big_real_mode(&inregs,&outregs,
+                  insn_iret,
+                  insn_iret_end - insn_iret);
+
Quoted 9 lines

kvm/test/x86/realmode.c void test_pusha_popa() · line 889

Quoted 6 lines
kvm/test/x86/realmode.c +6 -0
+    if (!regs_equal(&inregs,&outregs, 0))
+        print_serial("iret Test 1: FAIL\n");
+    else
+        print_serial("iret Test 1: PASS\n");
+}
+

This tests 32-bit iret, please test 16-bit iret as well (pushfw, pushw cs, callw, iretw).

Also add tests that set bits that must be zero (and checks that IRET clears them in eflags) or clears bit 1 and sees that IRET sets it.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.