[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] x86/emul: Make POPF emulation easier to follow



Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Wei Liu <wei.liu2@xxxxxxxxxx>
CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>

It's taken me nearly an hour with the vendor manuals to convince myself that
the emulation is correct.  The code is definitely too complicated to follow
without some comments.
---
 xen/arch/x86/x86_emulate/x86_emulate.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c 
b/xen/arch/x86/x86_emulate/x86_emulate.c
index 6523d65..de8dae8 100644
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -4193,6 +4193,10 @@ x86_emulate(
         goto push;
 
     case 0x9d: /* popf */ {
+        /*
+         * Bits which may not be modified by this POP instruction. RF is
+         * handled uniformly during instruction retirement.
+         */
         uint32_t mask = X86_EFLAGS_VIP | X86_EFLAGS_VIF | X86_EFLAGS_VM;
 
         cr4 = 0;
@@ -4206,10 +4210,15 @@ x86_emulate(
                     if ( rc != X86EMUL_OKAY )
                         goto done;
                 }
+                /* All IOPL != 3 POPs fail, except a 16-bit POP in vm86 mode. 
*/
                 generate_exception_if(!(cr4 & X86_CR4_VME) &&
                                       MASK_EXTR(_regs.eflags, X86_EFLAGS_IOPL) 
!= 3,
                                       EXC_GP, 0);
             }
+            /*
+             * IOPL cannot be modified outside of CPL 0.  IF cannot be
+             * modified if IOPL < CPL.
+             */
             mask |= X86_EFLAGS_IOPL;
             if ( !mode_iopl() )
                 mask |= X86_EFLAGS_IF;
@@ -4222,7 +4231,9 @@ x86_emulate(
             goto done;
         if ( op_bytes == 2 )
         {
+            /* 16-bit POP preserves the upper 16 bits of EFLAGS. */
             dst.val = (uint16_t)dst.val | (_regs.eflags & 0xffff0000u);
+            /* VME processing only applies at IOPL != 3. */
             if ( (cr4 & X86_CR4_VME) &&
                  MASK_EXTR(_regs.eflags, X86_EFLAGS_IOPL) != 3 )
             {
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.