WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] x86 emulation: fix bswap

To: <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH] x86 emulation: fix bswap
From: "Jan Beulich" <jbeulich@xxxxxxxxxx>
Date: Thu, 15 Feb 2007 10:22:38 +0000
Delivery-date: Thu, 15 Feb 2007 02:20:39 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
REX.R needs to be decoded and since bswap on a 16-bit operand is undefined,
it is best to have hardware execute this so the emulation result matches
hardware behavior. Since it is simple to do, faster, and smaller, also let 
hardware
do 32- and 64-bit ones.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxxxx>

Index: 2007-02-07/xen/arch/x86/x86_emulate.c
===================================================================
--- 2007-02-07.orig/xen/arch/x86/x86_emulate.c  2007-02-08 08:46:39.000000000 
+0100
+++ 2007-02-07/xen/arch/x86/x86_emulate.c       2007-02-08 09:32:00.000000000 
+0100
@@ -2326,32 +2326,22 @@ x86_emulate(
 
     case 0xc8 ... 0xcf: /* bswap */
         dst.type  = OP_REG;
-        dst.reg   = decode_register(b & 7, &_regs, 0);
+        dst.reg   = decode_register(
+            (b & 7) | ((rex_prefix & 1) << 3), &_regs, 0);
         dst.val = *dst.reg;
         switch ( dst.bytes = op_bytes )
         {
         case 2:
-            dst.val = (((dst.val & 0x00FFUL) << 8) |
-                       ((dst.val & 0xFF00UL) >> 8));
+            __asm__("data16 bswap %k0" : "+r" (dst.val));
             break;
         case 4:
-            dst.val = (((dst.val & 0x000000FFUL) << 24) |
-                       ((dst.val & 0x0000FF00UL) <<  8) |
-                       ((dst.val & 0x00FF0000UL) >>  8) |
-                       ((dst.val & 0xFF000000UL) >> 24));
-            break;
 #ifdef __x86_64__
-        case 8:
-            dst.val = (((dst.val & 0x00000000000000FFUL) << 56) |
-                       ((dst.val & 0x000000000000FF00UL) << 40) |
-                       ((dst.val & 0x0000000000FF0000UL) << 24) |
-                       ((dst.val & 0x00000000FF000000UL) <<  8) |
-                       ((dst.val & 0x000000FF00000000UL) >>  8) |
-                       ((dst.val & 0x0000FF0000000000UL) >> 24) |
-                       ((dst.val & 0x00FF000000000000UL) >> 40) |
-                       ((dst.val & 0xFF00000000000000UL) >> 56));
+            __asm__("bswap %k0" : "+r" (dst.val));
             break;
+        case 8:
 #endif
+            __asm__("bswap %0" : "+r" (dst.val));
+            break;
         }
         break;
     }


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel