ia64/xen-unstable

changeset 14035:e7994a122aab

x86 emulation: fix bswap

REX.R needs to be decoded. Since it is simple to do, faster, and
smaller, let hardware do 32- and 64-bit BSWAP. 16-bite BSWAP is
undefined: emulate with observed behaviour (write zero).

Signed-off-by: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Tue Feb 20 17:05:50 2007 +0000 (2007-02-20)
parents 4719e34ed7a7
children 315c348e5f9e 4314691c70a2
files xen/arch/x86/x86_emulate.c
line diff
     1.1 --- a/xen/arch/x86/x86_emulate.c	Tue Feb 20 16:57:50 2007 +0000
     1.2 +++ b/xen/arch/x86/x86_emulate.c	Tue Feb 20 17:05:50 2007 +0000
     1.3 @@ -2350,33 +2350,23 @@ x86_emulate(
     1.4  #endif
     1.5  
     1.6      case 0xc8 ... 0xcf: /* bswap */
     1.7 -        dst.type  = OP_REG;
     1.8 -        dst.reg   = decode_register(b & 7, &_regs, 0);
     1.9 -        dst.val = *dst.reg;
    1.10 +        dst.type = OP_REG;
    1.11 +        dst.reg  = decode_register(
    1.12 +            (b & 7) | ((rex_prefix & 1) << 3), &_regs, 0);
    1.13          switch ( dst.bytes = op_bytes )
    1.14          {
    1.15 -        case 2:
    1.16 -            dst.val = (((dst.val & 0x00FFUL) << 8) |
    1.17 -                       ((dst.val & 0xFF00UL) >> 8));
    1.18 +        default: /* case 2: */
    1.19 +            /* Undefined behaviour. Writes zero on all tested CPUs. */
    1.20 +            dst.val = 0;
    1.21              break;
    1.22          case 4:
    1.23 -            dst.val = (((dst.val & 0x000000FFUL) << 24) |
    1.24 -                       ((dst.val & 0x0000FF00UL) <<  8) |
    1.25 -                       ((dst.val & 0x00FF0000UL) >>  8) |
    1.26 -                       ((dst.val & 0xFF000000UL) >> 24));
    1.27 +#ifdef __x86_64__
    1.28 +            __asm__ ( "bswap %k0" : "=r" (dst.val) : "0" (*dst.reg) );
    1.29              break;
    1.30 -#ifdef __x86_64__
    1.31          case 8:
    1.32 -            dst.val = (((dst.val & 0x00000000000000FFUL) << 56) |
    1.33 -                       ((dst.val & 0x000000000000FF00UL) << 40) |
    1.34 -                       ((dst.val & 0x0000000000FF0000UL) << 24) |
    1.35 -                       ((dst.val & 0x00000000FF000000UL) <<  8) |
    1.36 -                       ((dst.val & 0x000000FF00000000UL) >>  8) |
    1.37 -                       ((dst.val & 0x0000FF0000000000UL) >> 24) |
    1.38 -                       ((dst.val & 0x00FF000000000000UL) >> 40) |
    1.39 -                       ((dst.val & 0xFF00000000000000UL) >> 56));
    1.40 +#endif
    1.41 +            __asm__ ( "bswap %0" : "=r" (dst.val) : "0" (*dst.reg) );
    1.42              break;
    1.43 -#endif
    1.44          }
    1.45          break;
    1.46      }