]> xenbits.xensource.com Git - people/dariof/xen.git/commitdiff
x86/ioemul: Misc improvements to ioport_emulate.c
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 11 Jan 2018 12:42:59 +0000 (12:42 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 1 Feb 2018 10:54:10 +0000 (10:54 +0000)
Put the opcode into an array and use memcpy.  This allows the compiled code to
be written with two movs, rather than 10 mov $imm8's.  Also, drop trailing
whitespace in the file.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/ioport_emulate.c

index e80993acc944ab9f158dc09924d8c23c813d7a08..c2aded7668d3bbdd912ca2dc1b921f4b1e0be257 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************************
  * ioport_emulate.c
- * 
+ *
  * Handle I/O port access quirks of various platforms.
  */
 
 static bool ioemul_handle_proliant_quirk(
     u8 opcode, char *io_emul_stub, struct cpu_user_regs *regs)
 {
+    static const char stub[] = {
+        0x9c,       /*    pushf           */
+        0xfa,       /*    cli             */
+        0xee,       /*    out %al, %dx    */
+        0xec,       /* 1: in %dx, %al     */
+        0xa8, 0x80, /*    test $0x80, %al */
+        0x75, 0xfb, /*    jnz 1b          */
+        0x9d,       /*    popf            */
+        0xc3,       /*    ret             */
+    };
     uint16_t port = regs->dx;
     uint8_t value = regs->al;
 
     if ( (opcode != 0xee) || (port != 0xcd4) || !(value & 0x80) )
         return false;
 
-    /*    pushf */
-    io_emul_stub[0] = 0x9c;
-    /*    cli */
-    io_emul_stub[1] = 0xfa;
-    /*    out %al,%dx */
-    io_emul_stub[2] = 0xee;
-    /* 1: in %dx,%al */
-    io_emul_stub[3] = 0xec;
-    /*    test $0x80,%al */
-    io_emul_stub[4] = 0xa8;
-    io_emul_stub[5] = 0x80;
-    /*    jnz 1b */
-    io_emul_stub[6] = 0x75;
-    io_emul_stub[7] = 0xfb;
-    /*    popf */
-    io_emul_stub[8] = 0x9d;
-    /*    ret */
-    io_emul_stub[9] = 0xc3;
-
-    BUILD_BUG_ON(IOEMUL_QUIRK_STUB_BYTES < 10);
+    memcpy(io_emul_stub, stub, sizeof(stub));
+    BUILD_BUG_ON(IOEMUL_QUIRK_STUB_BYTES < sizeof(stub));
 
     return true;
 }