From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jan Beulich" Subject: [PATCH] x86 emulation: fix bswap Date: Thu, 15 Feb 2007 10:22:38 +0000 Message-ID: <45D4427E.76E4.0078.0@novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org 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 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; }