VirtualBox

Changeset 59527 in vbox for trunk/include/iprt


Ignore:
Timestamp:
Jan 31, 2016 11:54:20 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
105318
Message:

iprt/asm.h: Experimented with alternative serializating instructions (ASMSerializeInstruction), cpuid(0) is very reasonable compared to iret (rdtscp would be preferable).

Location:
trunk/include/iprt
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/asm-watcom-x86-16.h

    r59480 r59527  
    150150/* ASMAtomicCmpXchgExU64: External assembly implementation, too few registers for parameters.  */
    151151
    152 #undef      ASMSerializeInstruction
    153 #if 1
    154 # pragma aux ASMSerializeInstruction = \
     152#undef      ASMSerializeInstructionCpuId
     153#pragma aux ASMSerializeInstructionCpuId = \
     154    ".586" \
     155    "xor eax, eax" \
     156    "cpuid" \
     157    parm [] \
     158    modify exact [ax bx cx dx];
     159
     160#undef ASMSerializeInstructionIRet
     161#pragma aux ASMSerializeInstructionIRet = \
    155162    "pushf" \
    156163    "push cs" \
     
    158165    "jmp  done" \
    159166    "foo:" \
    160     "iret" /* serializing */ \
     167    "iret" \
    161168    "done:" \
    162169    parm [] \
    163     modify exact [ax];
    164 #else
    165 # pragma aux ASMSerializeInstruction = \
    166     ".586" \
    167     "xor eax, eax" \
    168     "cpuid" \
     170    modify exact [];
     171
     172#undef      ASMSerializeInstructionRdTscp
     173#pragma aux ASMSerializeInstructionRdTscp = \
     174    0x0f 0x01 0xf9 \
    169175    parm [] \
    170     modify exact [ax bx cx dx];
    171 #endif
     176    modify exact [ax dx cx];
    172177
    173178#undef      ASMAtomicReadU64
  • trunk/include/iprt/asm-watcom-x86-32.h

    r58788 r59527  
    151151    modify exact [eax edx];
    152152
    153 #undef      ASMSerializeInstruction
    154 #pragma aux ASMSerializeInstruction = \
     153#undef      ASMSerializeInstructionCpuId
     154#pragma aux ASMSerializeInstructionCpuId = \
    155155    ".586" \
    156156    "xor eax, eax" \
     
    158158    parm [] \
    159159    modify exact [eax ebx ecx edx];
     160
     161#undef ASMSerializeInstructionIRet
     162#pragma aux ASMSerializeInstructionIRet = \
     163    "pushf" \
     164    "push cs" \
     165    "call foo" /* 'push offset done' doesn't work */ \
     166    "jmp  done" \
     167    "foo:" \
     168    "iret" \
     169    "done:" \
     170    parm [] \
     171    modify exact [];
     172
     173#undef      ASMSerializeInstructionRdTscp
     174#pragma aux ASMSerializeInstructionRdTscp = \
     175    0x0f 0x01 0xf9 \
     176    parm [] \
     177    modify exact [eax edx ecx];
    160178
    161179#undef      ASMAtomicReadU64
  • trunk/include/iprt/asm.h

    r59480 r59527  
    13731373
    13741374/**
    1375  * Serialize Instruction.
     1375 * Virtualization unfriendly serializing instruction, always exits.
    13761376 */
    13771377#if RT_INLINE_ASM_EXTERNAL && !RT_INLINE_ASM_USES_INTRIN
    1378 DECLASM(void) ASMSerializeInstruction(void);
    1379 #else
    1380 DECLINLINE(void) ASMSerializeInstruction(void)
     1378DECLASM(void) ASMSerializeInstructionCpuId(void);
     1379#else
     1380DECLINLINE(void) ASMSerializeInstructionCpuId(void)
    13811381{
    13821382# if RT_INLINE_ASM_GNU_STYLE
    13831383    RTCCUINTREG xAX = 0;
    13841384#  ifdef RT_ARCH_AMD64
    1385     __asm__ ("cpuid"
    1386              : "=a" (xAX)
    1387              : "0" (xAX)
    1388              : "rbx", "rcx", "rdx");
     1385    __asm__ __volatile__ ("cpuid"
     1386                          : "=a" (xAX)
     1387                          : "0" (xAX)
     1388                          : "rbx", "rcx", "rdx");
    13891389#  elif (defined(PIC) || defined(__PIC__)) && defined(__i386__)
    1390     __asm__ ("push  %%ebx\n\t"
    1391              "cpuid\n\t"
    1392              "pop   %%ebx\n\t"
    1393              : "=a" (xAX)
    1394              : "0" (xAX)
    1395              : "ecx", "edx");
    1396 #  else
    1397     __asm__ ("cpuid"
    1398              : "=a" (xAX)
    1399              : "0" (xAX)
    1400              : "ebx", "ecx", "edx");
     1390    __asm__ __volatile__ ("push  %%ebx\n\t"
     1391                          "cpuid\n\t"
     1392                          "pop   %%ebx\n\t"
     1393                          : "=a" (xAX)
     1394                          : "0" (xAX)
     1395                          : "ecx", "edx");
     1396#  else
     1397    __asm__ __volatile__ ("cpuid"
     1398                          : "=a" (xAX)
     1399                          : "0" (xAX)
     1400                          : "ebx", "ecx", "edx");
    14011401#  endif
    14021402
     
    14151415# endif
    14161416}
     1417#endif
     1418
     1419/**
     1420 * Virtualization friendly serializing instruction, though more expensive.
     1421 */
     1422#if RT_INLINE_ASM_EXTERNAL
     1423DECLASM(void) ASMSerializeInstructionIRet(void);
     1424#else
     1425DECLINLINE(void) ASMSerializeInstructionIRet(void)
     1426{
     1427# if RT_INLINE_ASM_GNU_STYLE
     1428#  ifdef RT_ARCH_AMD64
     1429    __asm__ __volatile__ ("movq  %%rsp,%%r10\n\t"
     1430                          "subq  $128, %%rsp\n\t" /*redzone*/
     1431                          "mov   %%ss, %%eax\n\t"
     1432                          "pushq %%rax\n\t"
     1433                          "pushq %%r10\n\t"
     1434                          "pushfq\n\t"
     1435                          "movl  %%cs, %%eax\n\t"
     1436                          "pushq %%rax\n\t"
     1437                          "leaq  1f(%%rip), %%rax\n\t"
     1438                          "pushq %%rax\n\t"
     1439                          "iretq\n\t"
     1440                          "1:\n\t"
     1441                          ::: "rax", "r10");
     1442#  else
     1443    __asm__ __volatile__ ("pushfl\n\t"
     1444                          "pushl %%cs\n\t"
     1445                          "pushl $1f\n\t"
     1446                          "iretl\n\t"
     1447                          "1:\n\t"
     1448                          :::);
     1449#  endif
     1450
     1451# else
     1452    __asm
     1453    {
     1454        pushfd
     1455        push    cs
     1456        push    la_ret
     1457        retd
     1458    la_ret:
     1459    }
     1460# endif
     1461}
     1462#endif
     1463
     1464/**
     1465 * Virtualization friendlier serializing instruction, may still cause exits.
     1466 */
     1467#if RT_INLINE_ASM_EXTERNAL && RT_INLINE_ASM_USES_INTRIN < 15
     1468DECLASM(void) ASMSerializeInstructionRdTscp(void);
     1469#else
     1470DECLINLINE(void) ASMSerializeInstructionRdTscp(void)
     1471{
     1472# if RT_INLINE_ASM_GNU_STYLE
     1473    /* rdtscp is not supported by ancient linux build VM of course :-( */
     1474#  ifdef RT_ARCH_AMD64
     1475    /*__asm__ __volatile__("rdtscp\n\t" ::: "rax", "rdx, "rcx"); */
     1476    __asm__ __volatile__(".byte 0x0f,0x01,0xf9\n\t" ::: "rax", "rdx", "rcx");
     1477#  else
     1478    /*__asm__ __volatile__("rdtscp\n\t" ::: "eax", "edx, "ecx"); */
     1479    __asm__ __volatile__(".byte 0x0f,0x01,0xf9\n\t" ::: "eax", "edx", "ecx");
     1480#  endif
     1481# else
     1482#  if RT_INLINE_ASM_USES_INTRIN >= 15
     1483    uint32_t uIgnore;
     1484    (void)__rdtscp(&uIgnore);
     1485    (void)uIgnore;
     1486#  else
     1487    __asm
     1488    {
     1489        rdtscp
     1490    }
     1491#  endif
     1492# endif
     1493}
     1494#endif
     1495
     1496
     1497/**
     1498 * Serialize Instruction.
     1499 */
     1500#if (defined(RT_ARCH_X86) && ARCH_BITS == 16) || defined(IN_GUEST)
     1501# define ASMSerializeInstruction() ASMSerializeInstructionIRet()
     1502#else
     1503# define ASMSerializeInstruction() ASMSerializeInstructionCpuId()
    14171504#endif
    14181505
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette