VirtualBox

Changeset 8889

Show
Ignore:
Timestamp:
05/16/08 14:36:58 (4 months ago)
Author:
vboxsync
Message:

Added ASMGetCpuModuleIntel/Amd and ASMIsIntelCpu and ASMIsIntelCpuEx because intel idffers sligtly in the way they calulate the module number.

Files:

Legend:

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

    r8882 r8889  
    944944 
    945945/** 
     946 * Tests if it an genuin Intel CPU based on the ASMCpuId(0) output. 
     947 * 
     948 * @returns true/false. 
     949 * @param   uEBX    EBX return from ASMCpuId(0) 
     950 * @param   uECX    ECX return from ASMCpuId(0) 
     951 * @param   uEDX    EDX return from ASMCpuId(0) 
     952 */ 
     953DECLINLINE(bool) ASMIsIntelCpuEx(uint32_t uEBX, uint32_t uECX, uint32_t uEDX) 
     954{ 
     955    return uEBX == 0x756e6547 
     956        || uECX == 0x6c65746e 
     957        || uEDX == 0x49656e69; 
     958} 
     959 
     960 
     961/** 
     962 * Tests if this is an genuin Intel CPU. 
     963 * 
     964 * @returns true/false. 
     965 */ 
     966DECLINLINE(bool) ASMIsIntelCpu(void) 
     967{ 
     968    uint32_t uEAX, uEBX, uECX, uEDX; 
     969    ASMCpuId(1, &uEAX, &uEBX, &uECX, &uEDX); 
     970    return ASMIsIntelCpuEx(uEBX, uECX, uEDX); 
     971} 
     972 
     973 
     974/** 
    946975 * Extracts the CPU family from ASMCpuId(1) or ASMCpuId(0x80000001) 
    947976 * 
     
    958987 
    959988/** 
    960  * Extracts the CPU model from ASMCpuId(1) or ASMCpuId(0x80000001) 
     989 * Extracts the CPU model from ASMCpuId(1) or ASMCpuId(0x80000001), Intel variant. 
    961990 * 
    962991 * @returns Model. 
    963992 * @param   uEAX    EAX from ASMCpuId(1) or ASMCpuId(0x80000001). 
    964  */ 
    965 DECLINLINE(uint32_t) ASMGetCpuModel(uint32_t uEAX) 
    966 
    967     return ((uEAX >> 8) & 0xf) == 0xf /* family! */ 
     993 * @param   fIntel  Whether it's an intel CPU. 
     994 */ 
     995DECLINLINE(uint32_t) ASMGetCpuModelIntel(uint32_t uEAX) 
     996
     997    return ((uEAX >> 8) & 0xf) == 0xf || (((uEAX >> 8) & 0xf) == 0x6) /* family! */ 
     998         ? ((uEAX >> 4) & 0xf) | ((uEAX >> 12) & 0xf0) 
     999         : ((uEAX >> 4) & 0xf); 
     1000
     1001 
     1002 
     1003/** 
     1004 * Extracts the CPU model from ASMCpuId(1) or ASMCpuId(0x80000001), AMD variant. 
     1005 * 
     1006 * @returns Model. 
     1007 * @param   uEAX    EAX from ASMCpuId(1) or ASMCpuId(0x80000001). 
     1008 * @param   fIntel  Whether it's an intel CPU. 
     1009 */ 
     1010DECLINLINE(uint32_t) ASMGetCpuModelAMD(uint32_t uEAX) 
     1011
     1012    return ((uEAX >> 8) & 0xf) == 0xf 
     1013         ? ((uEAX >> 4) & 0xf) | ((uEAX >> 12) & 0xf0) 
     1014         : ((uEAX >> 4) & 0xf); 
     1015
     1016 
     1017 
     1018/** 
     1019 * Extracts the CPU model from ASMCpuId(1) or ASMCpuId(0x80000001) 
     1020 * 
     1021 * @returns Model. 
     1022 * @param   uEAX    EAX from ASMCpuId(1) or ASMCpuId(0x80000001). 
     1023 * @param   fIntel  Whether it's an intel CPU. Use ASMIsIntelCpuEx() or ASMIsIntelCpu(). 
     1024 */ 
     1025DECLINLINE(uint32_t) ASMGetCpuModel(uint32_t uEAX, bool fIntel) 
     1026
     1027    return ((uEAX >> 8) & 0xf) == 0xf || (((uEAX >> 8) & 0xf) == 0x6 && fIntel) /* family! */ 
    9681028         ? ((uEAX >> 4) & 0xf) | ((uEAX >> 12) & 0xf0) 
    9691029         : ((uEAX >> 4) & 0xf); 
  • trunk/src/VBox/Runtime/testcase/tstInlineAsm.cpp

    r8882 r8889  
    175175             "Support:                         0-%u\n", 
    176176             &s.uEBX, &s.uEDX, &s.uECX, s.uEAX); 
     177    bool const fIntel = ASMIsIntelCpuEx(s.uEBX, s.uECX, s.uEDX); 
    177178 
    178179    /* 
     
    190191                 "Brand ID:                        %#04x\n", 
    191192                 (s.uEAX >> 8) & 0xf, (s.uEAX >> 20) & 0x7f, ASMGetCpuFamily(s.uEAX), 
    192                  (s.uEAX >> 4) & 0xf, (s.uEAX >> 16) & 0x0f, ASMGetCpuModel(s.uEAX), 
     193                 (s.uEAX >> 4) & 0xf, (s.uEAX >> 16) & 0x0f, ASMGetCpuModel(s.uEAX, fIntel), 
    193194                 ASMGetCpuStepping(s.uEAX), 
    194195                 (s.uEBX >> 24) & 0xff, 
     
    285286                 "Brand ID:                        %#05x\n", 
    286287                 (s.uEAX >> 8) & 0xf, (s.uEAX >> 20) & 0x7f, ASMGetCpuFamily(s.uEAX), 
    287                  (s.uEAX >> 4) & 0xf, (s.uEAX >> 16) & 0x0f, ASMGetCpuModel(s.uEAX), 
     288                 (s.uEAX >> 4) & 0xf, (s.uEAX >> 16) & 0x0f, ASMGetCpuModel(s.uEAX, fIntel), 
    288289                 ASMGetCpuStepping(s.uEAX), 
    289290                 s.uEBX & 0xfff); 
  • trunk/src/VBox/VMM/CPUM.cpp

    r8885 r8889  
    10451045        case 4:  return "4 way "; 
    10461046        case 5:  return "res5  "; 
    1047         case 6:  return "8 way "; 
    1048         case 7:  return "res7  "; 
     1047        case 6:  return "8 way ";                                    case 7:  return "res7  "; 
    10491048        case 8:  return "16 way"; 
    10501049        case 9:  return "res9  "; 
     
    10931092                    "         RAW Standard CPUIDs\n" 
    10941093                    "     Function  eax      ebx      ecx      edx\n"); 
    1095     for (unsigned i = 0; i < ELEMENTS(pVM->cpum.s.aGuestCpuIdStd); i++) 
     1094    for (unsigned i = 0; i < RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdStd); i++) 
    10961095    { 
    10971096        Guest = pVM->cpum.s.aGuestCpuIdStd[i]; 
     
    11211120     * Get Features. 
    11221121     */ 
     1122    bool const fIntel = ASMIsIntelCpuEx(pVM->cpum.s.aGuestCpuIdStd[0].ebx, 
     1123                                        pVM->cpum.s.aGuestCpuIdStd[0].ecx, 
     1124                                        pVM->cpum.s.aGuestCpuIdStd[0].edx); 
    11231125    if (cStdMax >= 1 && iVerbosity) 
    11241126    { 
     
    11351137                        "Brand ID:                        %#04x\n", 
    11361138                        (uEAX >> 8) & 0xf, (uEAX >> 20) & 0x7f, ASMGetCpuFamily(uEAX), 
    1137                         (uEAX >> 4) & 0xf, (uEAX >> 16) & 0x0f, ASMGetCpuModel(uEAX), 
     1139                        (uEAX >> 4) & 0xf, (uEAX >> 16) & 0x0f, ASMGetCpuModel(uEAX, fIntel), 
    11381140                        ASMGetCpuStepping(uEAX), 
    11391141                        (Guest.ebx >> 24) & 0xff, 
     
    13091311                        "Brand ID:                        %#05x\n", 
    13101312                        (uEAX >> 8) & 0xf, (uEAX >> 20) & 0x7f, ASMGetCpuFamily(uEAX), 
    1311                         (uEAX >> 4) & 0xf, (uEAX >> 16) & 0x0f, ASMGetCpuModel(uEAX), 
     1313                        (uEAX >> 4) & 0xf, (uEAX >> 16) & 0x0f, ASMGetCpuModel(uEAX, fIntel), 
    13121314                        ASMGetCpuStepping(uEAX), 
    13131315                        Guest.ebx & 0xfff); 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy