VirtualBox

Changeset 8264

Show
Ignore:
Timestamp:
04/22/08 09:13:25 (9 months ago)
Author:
vboxsync
Message:

volatile applies to rdmsr as well

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/iprt/asm.h

    r8253 r8264  
    3838 * Defined as 1 if we're using a _MSC_VER 1400. 
    3939 * Otherwise defined as 0. 
     40 */ 
     41 
     42/** @note 
     43 * 
     44 * Some remarks about __volatile__: Without this keyword gcc is allowed to reorder 
     45 * or even optimize assembler instructions away. For instance, in the following code 
     46 * the second rdmsr instruction is optimized away because gcc treats that instruction 
     47 * as deterministic: 
     48 * 
     49 *   @code 
     50 *   static inline uint64_t rdmsr_low(idx) 
     51 *   { 
     52 *     uint32_t low; 
     53 *     __asm__ ("rdmsr" : "=a"(low) : "c"(idx) : "edx"); 
     54 *   } 
     55 *   ... 
     56 *   uint32_t msr1 = rdmsr(1); 
     57 *   foo(msr1); 
     58 *   msr1 = rdmsr(1); 
     59 *   bar(msr1); 
     60 *   @endcode 
     61 * 
     62 * The input parameter of rdmsr_low is the same for both calls and therefore gcc will 
     63 * use the result of the first call as input parameter for bar() as well. For rdmsr this 
     64 * is not acceptable as this instruction is _not_ deterministic. This applies to reading 
     65 * machine status information in general. 
    4066 */ 
    4167 
     
    13621388    RTUINT64U u; 
    13631389# if RT_INLINE_ASM_GNU_STYLE 
    1364     __asm__ ("rdmsr\n\t" 
     1390    __asm__ __volatile__ ("rdmsr\n\t" 
    13651391             : "=a" (u.s.Lo), 
    13661392               "=d" (u.s.Hi) 
     
    14351461    uint32_t u32; 
    14361462# if RT_INLINE_ASM_GNU_STYLE 
    1437     __asm__ ("rdmsr\n\t" 
     1463    __asm__ __volatile__("rdmsr\n\t" 
    14381464             : "=a" (u32) 
    14391465             : "c" (uRegister) 
     
    14701496    uint32_t    u32; 
    14711497# if RT_INLINE_ASM_GNU_STYLE 
    1472     __asm__ ("rdmsr\n\t" 
     1498    __asm__ __volatile__("rdmsr\n\t" 
    14731499             : "=d" (u32) 
    14741500             : "c" (uRegister) 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy