Commit 99ee878c authored by Nadav Amit's avatar Nadav Amit Committed by Paolo Bonzini
Browse files

x86: realmode: test smsw behavior with register operand

The smsw instruction has an undocumented behavior, in which the high-order
16-bits of CR0 are also saved in a 32-bit destination register.  This is
similar to the way smsw behaves in long-mode. However, it is hard to test the
long-mode case, since we need to cause an "invalid guest state" in long-mode.

The test works as follows: it sets CR0.CD (bit 30), so any of the high 16-bits
would be set.  It then executes smsw to register destination and compares the
register value with that of CR0.  CR0 value is restored when the test is done.

This test is expected to fail only when unrestricted mode is disabled or

Signed-off-by: default avatarNadav Amit <>
Signed-off-by: default avatarPaolo Bonzini <>
parent 4003963d
......@@ -1650,6 +1650,20 @@ void test_dr_mod(void)
report("mov dr with mod bits", R_AX | R_BX, outregs.eax == 0xaced);
void test_smsw(void)
MK_INSN(smsw, "movl %cr0, %ebx\n\t"
"movl %ebx, %ecx\n\t"
"or $0x40000000, %ebx\n\t"
"movl %ebx, %cr0\n\t"
"smswl %eax\n\t"
"movl %ecx, %cr0\n\t");
inregs.eax = 0x12345678;
report("smsw", R_AX | R_BX | R_CX, outregs.eax == outregs.ebx);
void realmode_start(void)
......@@ -1696,6 +1710,7 @@ void realmode_start(void)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment