Changeset 30801 in vbox
- Timestamp:
- Jul 13, 2010 10:10:29 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/asm-amd64-x86.h
r29270 r30801 622 622 623 623 /** 624 * Performs the cpuid instruction returning eax. 625 * 626 * @param uOperator CPUID operation (eax). 627 * @returns EAX after cpuid operation. 628 */ 629 #if RT_INLINE_ASM_EXTERNAL && !RT_INLINE_ASM_USES_INTRIN 630 DECLASM(uint32_t) ASMCpuId_EAX(uint32_t uOperator); 631 #else 632 DECLINLINE(uint32_t) ASMCpuId_EAX(uint32_t uOperator) 633 { 634 RTCCUINTREG xAX; 635 # if RT_INLINE_ASM_GNU_STYLE 636 # ifdef RT_ARCH_AMD64 637 __asm__ ("cpuid" 638 : "=a" (xAX) 639 : "0" (uOperator) 640 : "rbx", "rcx", "rdx"); 641 # elif (defined(PIC) || defined(__PIC__)) && defined(__i386__) 642 __asm__ ("push %%ebx\n\t" 643 "cpuid\n\t" 644 "pop %%ebx\n\t" 645 : "=a" (xAX) 646 : "0" (uOperator) 647 : "ecx", "edx"); 648 # else 649 __asm__ ("cpuid" 650 : "=a" (xAX) 651 : "0" (uOperator) 652 : "edx", "ecx", "ebx"); 653 # endif 654 655 # elif RT_INLINE_ASM_USES_INTRIN 656 int aInfo[4]; 657 __cpuid(aInfo, uOperator); 658 xDX = aInfo[0]; 659 660 # else 661 __asm 662 { 663 push ebx 664 mov eax, [uOperator] 665 cpuid 666 mov [xAX], eax 667 pop ebx 668 } 669 # endif 670 return (uint32_t)xAX; 671 } 672 #endif 673 674 675 /** 676 * Performs the cpuid instruction returning ebx. 677 * 678 * @param uOperator CPUID operation (eax). 679 * @returns EBX after cpuid operation. 680 */ 681 #if RT_INLINE_ASM_EXTERNAL && !RT_INLINE_ASM_USES_INTRIN 682 DECLASM(uint32_t) ASMCpuId_EBX(uint32_t uOperator); 683 #else 684 DECLINLINE(uint32_t) ASMCpuId_EBX(uint32_t uOperator) 685 { 686 RTCCUINTREG xBX; 687 # if RT_INLINE_ASM_GNU_STYLE 688 # ifdef RT_ARCH_AMD64 689 RTCCUINTREG uSpill; 690 __asm__ ("cpuid" 691 : "=a" (uSpill), 692 "=b" (xBX) 693 : "0" (uOperator) 694 : "rdx", "rcx"); 695 # elif (defined(PIC) || defined(__PIC__)) && defined(__i386__) 696 __asm__ ("push %%ebx\n\t" 697 "cpuid\n\t" 698 "mov %%ebx, %%edx\n\t" 699 "pop %%ebx\n\t" 700 : "=a" (uOperator), 701 "=d" (xBX) 702 : "0" (uOperator) 703 : "ecx"); 704 # else 705 __asm__ ("cpuid" 706 : "=a" (uOperator), 707 "=b" (xBX) 708 : "0" (uOperator) 709 : "edx", "ecx"); 710 # endif 711 712 # elif RT_INLINE_ASM_USES_INTRIN 713 int aInfo[4]; 714 __cpuid(aInfo, uOperator); 715 xDX = aInfo[1]; 716 717 # else 718 __asm 719 { 720 push ebx 721 mov eax, [uOperator] 722 cpuid 723 mov [xBX], ebx 724 pop ebx 725 } 726 # endif 727 return (uint32_t)xBX; 728 } 729 #endif 730 731 732 /** 733 * Performs the cpuid instruction returning ecx. 734 * 735 * @param uOperator CPUID operation (eax). 736 * @returns ECX after cpuid operation. 737 */ 738 #if RT_INLINE_ASM_EXTERNAL && !RT_INLINE_ASM_USES_INTRIN 739 DECLASM(uint32_t) ASMCpuId_ECX(uint32_t uOperator); 740 #else 741 DECLINLINE(uint32_t) ASMCpuId_ECX(uint32_t uOperator) 742 { 743 RTCCUINTREG xCX; 744 # if RT_INLINE_ASM_GNU_STYLE 745 # ifdef RT_ARCH_AMD64 746 RTCCUINTREG uSpill; 747 __asm__ ("cpuid" 748 : "=a" (uSpill), 749 "=c" (xCX) 750 : "0" (uOperator) 751 : "rbx", "rdx"); 752 # elif (defined(PIC) || defined(__PIC__)) && defined(__i386__) 753 __asm__ ("push %%ebx\n\t" 754 "cpuid\n\t" 755 "pop %%ebx\n\t" 756 : "=a" (uOperator), 757 "=c" (xCX) 758 : "0" (uOperator) 759 : "edx"); 760 # else 761 __asm__ ("cpuid" 762 : "=a" (uOperator), 763 "=c" (xCX) 764 : "0" (uOperator) 765 : "ebx", "edx"); 766 767 # endif 768 769 # elif RT_INLINE_ASM_USES_INTRIN 770 int aInfo[4]; 771 __cpuid(aInfo, uOperator); 772 xCX = aInfo[2]; 773 774 # else 775 __asm 776 { 777 push ebx 778 mov eax, [uOperator] 779 cpuid 780 mov [xCX], ecx 781 pop ebx 782 } 783 # endif 784 return (uint32_t)xCX; 785 } 786 #endif 787 788 789 /** 624 790 * Performs the cpuid instruction returning edx. 625 791 * … … 673 839 # endif 674 840 return (uint32_t)xDX; 675 }676 #endif677 678 679 /**680 * Performs the cpuid instruction returning ecx.681 *682 * @param uOperator CPUID operation (eax).683 * @returns ECX after cpuid operation.684 */685 #if RT_INLINE_ASM_EXTERNAL && !RT_INLINE_ASM_USES_INTRIN686 DECLASM(uint32_t) ASMCpuId_ECX(uint32_t uOperator);687 #else688 DECLINLINE(uint32_t) ASMCpuId_ECX(uint32_t uOperator)689 {690 RTCCUINTREG xCX;691 # if RT_INLINE_ASM_GNU_STYLE692 # ifdef RT_ARCH_AMD64693 RTCCUINTREG uSpill;694 __asm__ ("cpuid"695 : "=a" (uSpill),696 "=c" (xCX)697 : "0" (uOperator)698 : "rbx", "rdx");699 # elif (defined(PIC) || defined(__PIC__)) && defined(__i386__)700 __asm__ ("push %%ebx\n\t"701 "cpuid\n\t"702 "pop %%ebx\n\t"703 : "=a" (uOperator),704 "=c" (xCX)705 : "0" (uOperator)706 : "edx");707 # else708 __asm__ ("cpuid"709 : "=a" (uOperator),710 "=c" (xCX)711 : "0" (uOperator)712 : "ebx", "edx");713 714 # endif715 716 # elif RT_INLINE_ASM_USES_INTRIN717 int aInfo[4];718 __cpuid(aInfo, uOperator);719 xCX = aInfo[2];720 721 # else722 __asm723 {724 push ebx725 mov eax, [uOperator]726 cpuid727 mov [xCX], ecx728 pop ebx729 }730 # endif731 return (uint32_t)xCX;732 841 } 733 842 #endif -
trunk/src/VBox/Runtime/testcase/tstInlineAsm.cpp
r30797 r30801 136 136 ASMCpuId(0, &s.uEAX, &s.uEBX, &s.uECX, &s.uEDX); 137 137 138 uint32_t u32 = ASMCpuId_ECX(0); 138 uint32_t u32; 139 140 u32 = ASMCpuId_EAX(0); 141 CHECKVAL(u32, s.uEAX, "%x"); 142 u32 = ASMCpuId_EBX(0); 143 CHECKVAL(u32, s.uEBX, "%x"); 144 u32 = ASMCpuId_ECX(0); 139 145 CHECKVAL(u32, s.uECX, "%x"); 140 141 146 u32 = ASMCpuId_EDX(0); 142 147 CHECKVAL(u32, s.uEDX, "%x"); … … 145 150 uint32_t uEDX2 = s.uEDX - 1; 146 151 ASMCpuId_ECX_EDX(0, &uECX2, &uEDX2); 147 148 152 CHECKVAL(uECX2, s.uECX, "%x"); 149 153 CHECKVAL(uEDX2, s.uEDX, "%x"); … … 165 169 RTPrintf("%08x %08x %08x %08x %08x%s\n", 166 170 iStd, s.uEAX, s.uEBX, s.uECX, s.uEDX, iStd <= cFunctions ? "" : "*"); 171 172 u32 = ASMCpuId_EAX(iStd); 173 CHECKVAL(u32, s.uEAX, "%x"); 174 u32 = ASMCpuId_EBX(iStd); 175 CHECKVAL(u32, s.uEBX, "%x"); 176 u32 = ASMCpuId_ECX(iStd); 177 CHECKVAL(u32, s.uECX, "%x"); 178 u32 = ASMCpuId_EDX(iStd); 179 CHECKVAL(u32, s.uEDX, "%x"); 180 181 uECX2 = s.uECX - 1; 182 uEDX2 = s.uEDX - 1; 183 ASMCpuId_ECX_EDX(iStd, &uECX2, &uEDX2); 184 CHECKVAL(uECX2, s.uECX, "%x"); 185 CHECKVAL(uEDX2, s.uEDX, "%x"); 167 186 } 168 187 … … 270 289 RTPrintf("%08x %08x %08x %08x %08x%s\n", 271 290 iExt, s.uEAX, s.uEBX, s.uECX, s.uEDX, iExt <= cExtFunctions ? "" : "*"); 291 292 u32 = ASMCpuId_EAX(iExt); 293 CHECKVAL(u32, s.uEAX, "%x"); 294 u32 = ASMCpuId_EBX(iExt); 295 CHECKVAL(u32, s.uEBX, "%x"); 296 u32 = ASMCpuId_ECX(iExt); 297 CHECKVAL(u32, s.uECX, "%x"); 298 u32 = ASMCpuId_EDX(iExt); 299 CHECKVAL(u32, s.uEDX, "%x"); 300 301 uECX2 = s.uECX - 1; 302 uEDX2 = s.uEDX - 1; 303 ASMCpuId_ECX_EDX(iExt, &uECX2, &uEDX2); 304 CHECKVAL(uECX2, s.uECX, "%x"); 305 CHECKVAL(uEDX2, s.uEDX, "%x"); 272 306 } 273 307
Note:
See TracChangeset
for help on using the changeset viewer.