VirtualBox

Changeset 49988 in vbox


Ignore:
Timestamp:
Dec 19, 2013 2:55:16 PM (11 years ago)
Author:
vboxsync
Message:

CPU: Hacking VIA

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/tools/VBoxCpuReport.cpp

    r49972 r49988  
    498498            }
    499499#if 0
    500             else if (uMsr >= 0xc0011000 && uMsr <= 0xc0011100)
     500            else if (uMsr >= 0x00003170 && uMsr <= 0xc0000090)
    501501            {
    502502                vbCpuRepDebug("testing %#x...\n", uMsr);
     
    523523                if (!fGp)
    524524                    fFlags = 0;
     525                /* VIA HACK - writing to 0x0000317e on a quad core make the core unresponsive. */
     526                else if (uMsr == 0x0000317e && g_enmVendor == CPUMCPUVENDOR_VIA)
     527                {
     528                    uValue = 0;
     529                    fFlags = VBCPUREPMSR_F_WRITE_ONLY;
     530                    fGp    = *pcMsrs == 0
     531                          || (*ppaMsrs)[*pcMsrs - 1].uMsr != 0x0000317d
     532                          || (*ppaMsrs)[*pcMsrs - 1].fFlags != VBCPUREPMSR_F_WRITE_ONLY;
     533                }
    525534                else
    526535                {
    527536                    /* Is it a write only register? */
    528537#if 0
    529                     if (uMsr >= 0xc0011000 && uMsr <= 0xc0011100)
     538                    if (uMsr >= 0x00003170 && uMsr <= 0xc0000090)
    530539                    {
    531540                        vbCpuRepDebug("test writing %#x...\n", uMsr);
     
    567576                    if (RT_FAILURE(rc))
    568577                        return RTMsgErrorRc(rc, "Out of memory (uMsr=%#x).\n", uMsr);
    569                     vbCpuRepDebug("%#010x: uValue=%#llx fFlags=%#x\n", uMsr, uValue, fFlags);
     578                    if (   g_enmVendor != CPUMCPUVENDOR_VIA
     579                        || uValue
     580                        || fFlags)
     581                        vbCpuRepDebug("%#010x: uValue=%#llx fFlags=%#x\n", uMsr, uValue, fFlags);
    570582                }
    571583            }
     
    11181130        case 0x0000103f: return "P6_UNK_0000_103f"; /* P6_M_Dothan. */
    11191131        case 0x000010cd: return "P6_UNK_0000_10cd"; /* P6_M_Dothan. */
     1132
     1133        case 0x00001107: return "VIA_UNK_0000_1107";
     1134        case 0x0000110f: return "VIA_UNK_0000_110f";
     1135        case 0x00001153: return "VIA_UNK_0000_1153";
     1136        case 0x00001200: return "VIA_UNK_0000_1200";
     1137        case 0x00001201: return "VIA_UNK_0000_1201";
     1138        case 0x00001202: return "VIA_UNK_0000_1202";
     1139        case 0x00001203: return "VIA_UNK_0000_1203";
     1140        case 0x00001204: return "VIA_UNK_0000_1204";
     1141        case 0x00001205: return "VIA_UNK_0000_1205";
     1142        case 0x00001206: return "VIA_ALT_VENDOR_EBX";
     1143        case 0x00001207: return "VIA_ALT_VENDOR_ECDX";
     1144        case 0x00001208: return "VIA_UNK_0000_1208";
     1145        case 0x00001209: return "VIA_UNK_0000_1209";
     1146        case 0x0000120a: return "VIA_UNK_0000_120a";
     1147        case 0x0000120b: return "VIA_UNK_0000_120b";
     1148        case 0x0000120c: return "VIA_UNK_0000_120c";
     1149        case 0x0000120d: return "VIA_UNK_0000_120d";
     1150        case 0x0000120e: return "VIA_UNK_0000_120e";
     1151        case 0x0000120f: return "VIA_UNK_0000_120f";
     1152        case 0x00001210: return "VIA_UNK_0000_1210";
     1153        case 0x00001211: return "VIA_UNK_0000_1211";
     1154        case 0x00001212: return "VIA_UNK_0000_1212";
     1155        case 0x00001213: return "VIA_UNK_0000_1213";
     1156        case 0x00001214: return "VIA_UNK_0000_1214";
     1157        case 0x00001220: return "VIA_UNK_0000_1220";
     1158        case 0x00001221: return "VIA_UNK_0000_1221";
     1159        case 0x00001230: return "VIA_UNK_0000_1230";
     1160        case 0x00001231: return "VIA_UNK_0000_1231";
     1161        case 0x00001232: return "VIA_UNK_0000_1232";
     1162        case 0x00001233: return "VIA_UNK_0000_1233";
     1163        case 0x00001234: return "VIA_UNK_0000_1234";
     1164        case 0x00001235: return "VIA_UNK_0000_1235";
     1165        case 0x00001236: return "VIA_UNK_0000_1236";
     1166        case 0x00001237: return "VIA_UNK_0000_1237";
     1167        case 0x00001238: return "VIA_UNK_0000_1238";
     1168        case 0x00001239: return "VIA_UNK_0000_1239";
     1169        case 0x00001240: return "VIA_UNK_0000_1240";
     1170        case 0x00001241: return "VIA_UNK_0000_1241";
     1171        case 0x00001243: return "VIA_UNK_0000_1243";
     1172        case 0x00001245: return "VIA_UNK_0000_1245";
     1173        case 0x00001246: return "VIA_UNK_0000_1246";
     1174        case 0x00001247: return "VIA_UNK_0000_1247";
     1175        case 0x00001248: return "VIA_UNK_0000_1248";
     1176        case 0x00001249: return "VIA_UNK_0000_1249";
     1177        case 0x0000124a: return "VIA_UNK_0000_124a";
     1178
    11201179        case 0x00002000: return "P6_CR0";
    11211180        case 0x00002002: return "P6_CR2";
     
    21942253        case 0x00000053:
    21952254        case 0x00000054:
     2255
    21962256        case 0x00001006:
    21972257        case 0x00001007:
     2258            return VBCPUREPBADNESS_BOND_VILLAIN;
     2259
     2260        case 0x0000120e:
     2261        case 0x00001233:
     2262        case 0x00001239:
     2263        case 0x00001249:
     2264        case 0x0000124a:
     2265            if (g_enmVendor == CPUMCPUVENDOR_VIA)
     2266                return VBCPUREPBADNESS_BOND_VILLAIN;
     2267            break;
     2268
    21982269        case 0xc0010010:
    21992270        case 0xc0010016:
     
    22032274        case 0xc001001a:
    22042275        case 0xc001001d:
    2205         case 0xc001101e:
    22062276        case 0xc0010064: /* P-state fequency, voltage, ++. */
    22072277        case 0xc0010065: /* P-state fequency, voltage, ++. */
     
    22132283        case 0xc001006b: /* P-state fequency, voltage, ++. */
    22142284        case 0xc0010070: /* COFVID Control. */
     2285        case 0xc001101e:
    22152286        case 0xc0011021: /* IC_CFG (instruction cache configuration) */
    22162287        case 0xc0011023: /* CU_CFG (combined unit configuration) */
     
    22332304    return VBCPUREPBADNESS_MOSTLY_HARMLESS;
    22342305}
     2306
     2307
     2308/**
     2309 * Checks if this might be a VIA dummy register.
     2310 *
     2311 * @returns true if it's a dummy, false if it isn't.
     2312 * @param   uMsr                The MSR.
     2313 * @param   uValue              The value.
     2314 * @param   fFlags              The flags.
     2315 */
     2316static bool isMsrViaDummy(uint32_t uMsr, uint64_t uValue, uint32_t fFlags)
     2317{
     2318    if (g_enmVendor != CPUMCPUVENDOR_VIA)
     2319        return false;
     2320
     2321    if (uValue)
     2322        return false;
     2323
     2324    if (fFlags)
     2325        return false;
     2326
     2327    switch (uMsr)
     2328    {
     2329        case 0x00000010:
     2330        case 0x0000001b:
     2331        case 0x000000c1:
     2332        case 0x000000c2:
     2333        case 0x0000011e:
     2334        case 0x00000186:
     2335        case 0x00000187:
     2336        //case 0x00000200 ... (mtrrs will be detected)
     2337            return false;
     2338
     2339        case 0xc0000080:
     2340        case 0xc0000081:
     2341        case 0xc0000082:
     2342        case 0xc0000083:
     2343            if (vbCpuRepSupportsLongMode())
     2344                return false;
     2345            break;
     2346    }
     2347
     2348    if (uMsr >= 0x00001200 && uMsr <= 0x00003fff && queryMsrWriteBadness(uMsr) != VBCPUREPBADNESS_MOSTLY_HARMLESS)
     2349        return false;
     2350
     2351    if (   !msrProberModifyNoChange(uMsr)
     2352        && !msrProberModifyZero(uMsr))
     2353        return false;
     2354
     2355    uint64_t fIgnMask  = 0;
     2356    uint64_t fGpMask   = 0;
     2357    int rc = msrProberModifyBitChanges(uMsr, &fIgnMask, &fGpMask, 0);
     2358    if (RT_FAILURE(rc))
     2359        return false;
     2360
     2361    if (fIgnMask != UINT64_MAX)
     2362        return false;
     2363    if (fGpMask != 0)
     2364        return false;
     2365
     2366    return true;
     2367}
     2368
    22352369
    22362370
     
    23022436
    23032437
    2304 static int printMsrValueIgnoreWrites(uint32_t uMsr, uint64_t uValue, const char *pszAnnotation)
    2305 {
    2306     vbCpuRepPrintf("    MVI(%#010x, \"%s\"", uMsr, getMsrName(uMsr));
     2438
     2439static int printMsrValueIgnoreWritesNamed(uint32_t uMsr, uint64_t uValue, const char *pszName, const char *pszAnnotation)
     2440{
     2441    vbCpuRepPrintf("    MVI(%#010x, \"%s\"", uMsr, pszName);
    23072442    printMsrValueU64(uValue);
    23082443    vbCpuRepPrintf("),");
     
    23112446    printMsrNewLine();
    23122447    return VINF_SUCCESS;
     2448}
     2449
     2450
     2451static int printMsrValueIgnoreWrites(uint32_t uMsr, uint64_t uValue, const char *pszAnnotation)
     2452{
     2453    return printMsrValueIgnoreWritesNamed(uMsr, uValue, getMsrName(uMsr), pszAnnotation);
    23132454}
    23142455
     
    23412482
    23422483
    2343 static int printMsrRangeValueIgnoreWrites(uint32_t uMsr, uint32_t uLast, uint64_t uValue, const char *pszAnnotation)
    2344 {
    2345     vbCpuRepPrintf("    RVI(%#010x, %#010x, \"%s\"", uMsr, uLast, getMsrRangeName(uMsr));
     2484static int printMsrRangeValueIgnoreWritesNamed(uint32_t uMsr, uint32_t uLast, uint64_t uValue, const char *pszName, const char *pszAnnotation)
     2485{
     2486    vbCpuRepPrintf("    RVI(%#010x, %#010x, \"%s\"", uMsr, uLast, pszName);
    23462487    printMsrValueU64(uValue);
    23472488    vbCpuRepPrintf("),");
     
    23502491    printMsrNewLine();
    23512492    return VINF_SUCCESS;
     2493}
     2494
     2495
     2496static int printMsrRangeValueIgnoreWrites(uint32_t uMsr, uint32_t uLast, uint64_t uValue, const char *pszAnnotation)
     2497{
     2498    return printMsrRangeValueIgnoreWritesNamed(uMsr, uLast, uValue, getMsrRangeName(uMsr), pszAnnotation);
    23522499}
    23532500
     
    25812728    return s_szBuf;
    25822729}
    2583 
    25842730
    25852731
     
    27322878            || fGpMaskN   != fGpMask0)
    27332879        {
    2734             if (!fEarlyEndOk)
     2880            if (!fEarlyEndOk && !isMsrViaDummy(uMsr, paMsrs[i].uValue, paMsrs[i].fFlags))
    27352881            {
    27362882                vbCpuRepDebug("MSR %s (%#x) range ended unexpectedly early on %#x: ro=%d ign=%#llx/%#llx gp=%#llx/%#llx [N/0]\n",
     
    28222968
    28232969/**
     2970 * Reports a VIA dummy range.
     2971 *
     2972 * @returns VBox status code.
     2973 * @param   paMsrs              Pointer to the first MSR.
     2974 * @param   cMsrs               The number of MSRs in the array @a paMsr.
     2975 * @param   pidxLoop            Index variable that should be advanced to the
     2976 *                              last MSR entry in the range.
     2977 */
     2978static int reportMsr_ViaDummyRange(VBCPUREPMSR const *paMsrs, uint32_t cMsrs, uint32_t *pidxLoop)
     2979{
     2980    /* Figure how many. */
     2981    uint32_t uMsr  = paMsrs[0].uMsr;
     2982    uint32_t cRegs = 1;
     2983    while (   cRegs < cMsrs
     2984           && paMsrs[cRegs].uMsr == uMsr + cRegs
     2985           && isMsrViaDummy(paMsrs[cRegs].uMsr, paMsrs[cRegs].uValue, paMsrs[cRegs].fFlags))
     2986    {
     2987        cRegs++;
     2988        if (!(cRegs % 0x80))
     2989            vbCpuRepPrintf("VIA dummy detection cRegs=%#x...\n", cRegs);
     2990    }
     2991
     2992    /* Advance. */
     2993    *pidxLoop += cRegs - 1;
     2994
     2995    /* Report it/them. */
     2996    char szName[80];
     2997    if (cRegs == 1)
     2998    {
     2999        RTStrPrintf(szName, sizeof(szName), "ZERO_%04x_%04x", RT_HI_U16(uMsr), RT_LO_U16(uMsr));
     3000        return printMsrValueIgnoreWritesNamed(uMsr, 0, szName, NULL);
     3001    }
     3002
     3003    uint32_t uMsrLast = uMsr +  cRegs - 1;
     3004    RTStrPrintf(szName, sizeof(szName), "ZERO_%04x_%04x_THRU_%04x_%04x",
     3005                RT_HI_U16(uMsr), RT_LO_U16(uMsr), RT_HI_U16(uMsrLast), RT_LO_U16(uMsrLast));
     3006    return printMsrRangeValueIgnoreWritesNamed(uMsr, uMsrLast, 0, szName, NULL);
     3007}
     3008
     3009
     3010/**
    28243011 * Special function for reporting the IA32_APIC_BASE register, as it seems to be
    28253012 * causing trouble on newer systems.
     
    29233110    uint32_t cRegs = 1;
    29243111    while (   cRegs < cMsrs
    2925            && paMsrs[cRegs].uMsr == uMsr + cRegs)
     3112           && paMsrs[cRegs].uMsr == uMsr + cRegs
     3113           && !isMsrViaDummy(paMsrs[cRegs].uMsr, paMsrs[cRegs].uValue, paMsrs[cRegs].fFlags) )
    29263114        cRegs++;
    29273115    if (cRegs & 1)
     
    36243812        int         rc;
    36253813#if 1
    3626         if (uMsr >= 0xc0000000 && g_fIntelNetBurst)
     3814        if (uMsr < 0x00001200)
     3815            continue;
     3816        if (uMsr >= 0x00001238)
    36273817        {
    36283818            vbCpuRepDebug("produceMsrReport: uMsr=%#x (%s)...\n", uMsr, getMsrNameHandled(uMsr));
     
    36403830                rc = reportMsr_Generic(uMsr, fFlags, uValue);
    36413831        }
     3832        /*
     3833         * VIA implement MSRs in a interesting way, so we have to select what we
     3834         * want to handle there to avoid making the code below unreadable.
     3835         */
     3836        else if (isMsrViaDummy(uMsr, uValue, fFlags))
     3837            rc = reportMsr_ViaDummyRange(&paMsrs[i], cMsrs - i, &i);
    36423838        /*
    36433839         * This shall be sorted by uMsr as much as possible.
     
    37183914        else if (uMsr >= 0xc0000408 && uMsr <= 0xc000040f)
    37193915            rc = reportMsr_AmdFam10hMc4MiscN(&paMsrs[i], cMsrs - i, &i);
    3720         else if (uMsr == 0xc0010000)
     3916        else if (uMsr == 0xc0010000 && g_enmVendor == CPUMCPUVENDOR_AMD)
    37213917            rc = reportMsr_AmdK8PerfCtlN(&paMsrs[i], cMsrs - i, &i);
    3722         else if (uMsr == 0xc0010004)
     3918        else if (uMsr == 0xc0010004 && g_enmVendor == CPUMCPUVENDOR_AMD)
    37233919            rc = reportMsr_AmdK8PerfCtrN(&paMsrs[i], cMsrs - i, &i);
    3724         else if (uMsr == 0xc0010010)
     3920        else if (uMsr == 0xc0010010 && g_enmVendor == CPUMCPUVENDOR_AMD)
    37253921            rc = reportMsr_AmdK8SysCfg(uMsr, uValue);
    3726         else if (uMsr == 0xc0010015)
     3922        else if (uMsr == 0xc0010015 && g_enmVendor == CPUMCPUVENDOR_AMD)
    37273923            rc = reportMsr_AmdK8HwCr(uMsr, uValue);
    3728         else if (uMsr == 0xc0010016 || uMsr == 0xc0010018)
     3924        else if ((uMsr == 0xc0010016 || uMsr == 0xc0010018) && g_enmVendor == CPUMCPUVENDOR_AMD)
    37293925            rc = reportMsr_AmdK8IorrBaseN(uMsr, uValue);
    3730         else if (uMsr == 0xc0010017 || uMsr == 0xc0010019)
     3926        else if ((uMsr == 0xc0010017 || uMsr == 0xc0010019) && g_enmVendor == CPUMCPUVENDOR_AMD)
    37313927            rc = reportMsr_AmdK8IorrMaskN(uMsr, uValue);
    3732         else if (uMsr == 0xc001001a || uMsr == 0xc001001d)
     3928        else if ((uMsr == 0xc001001a || uMsr == 0xc001001d) && g_enmVendor == CPUMCPUVENDOR_AMD)
    37333929            rc = reportMsr_AmdK8TopMemN(uMsr, uValue);
    3734         else if (uMsr == 0xc0010030)
     3930        else if (uMsr == 0xc0010030 && g_enmVendor == CPUMCPUVENDOR_AMD)
    37353931            rc = reportMsr_GenRangeFunction(&paMsrs[i], cMsrs - i, 6, "AmdK8CpuNameN", &i);
    3736         else if (uMsr >= 0xc0010044 && uMsr <= 0xc001004a)
     3932        else if (uMsr >= 0xc0010044 && uMsr <= 0xc001004a && g_enmVendor == CPUMCPUVENDOR_AMD)
    37373933            rc = reportMsr_GenRangeFunctionEx(&paMsrs[i], cMsrs - i, 7, "AmdK8McCtlMaskN", 0xc0010044, true /*fEarlyEndOk*/, false, 0, &i);
    3738         else if (uMsr == 0xc0010050)
     3934        else if (uMsr == 0xc0010050 && g_enmVendor == CPUMCPUVENDOR_AMD)
    37393935            rc = reportMsr_GenRangeFunction(&paMsrs[i], cMsrs - i, 4, "AmdK8SmiOnIoTrapN", &i);
    3740         else if (uMsr == 0xc0010064)
     3936        else if (uMsr == 0xc0010064 && g_enmVendor == CPUMCPUVENDOR_AMD)
    37413937            rc = reportMsr_AmdFam10hPStateN(&paMsrs[i], cMsrs - i, &i);
    3742         else if (uMsr == 0xc0010070)
     3938        else if (uMsr == 0xc0010070 && g_enmVendor == CPUMCPUVENDOR_AMD)
    37433939            rc = reportMsr_AmdFam10hCofVidControl(uMsr, uValue);
    3744         else if ((uMsr == 0xc0010118 || uMsr == 0xc0010119) && getMsrFnName(uMsr, NULL))
     3940        else if ((uMsr == 0xc0010118 || uMsr == 0xc0010119) && getMsrFnName(uMsr, NULL) && g_enmVendor == CPUMCPUVENDOR_AMD)
    37453941            rc = printMsrFunction(uMsr, NULL, NULL, annotateValue(uValue)); /* RAZ, write key. */
    3746         else if (uMsr == 0xc0010200)
     3942        else if (uMsr == 0xc0010200 && g_enmVendor == CPUMCPUVENDOR_AMD)
    37473943            rc = reportMsr_AmdGenPerfMixedRange(&paMsrs[i], cMsrs - i, 12, &i);
    3748         else if (uMsr == 0xc0010230)
     3944        else if (uMsr == 0xc0010230 && g_enmVendor == CPUMCPUVENDOR_AMD)
    37493945            rc = reportMsr_AmdGenPerfMixedRange(&paMsrs[i], cMsrs - i, 8, &i);
    3750         else if (uMsr == 0xc0010240)
     3946        else if (uMsr == 0xc0010240 && g_enmVendor == CPUMCPUVENDOR_AMD)
    37513947            rc = reportMsr_AmdGenPerfMixedRange(&paMsrs[i], cMsrs - i, 8, &i);
    3752         else if (uMsr == 0xc0011019 && g_enmMicroarch >= kCpumMicroarch_AMD_15h_Piledriver)
     3948        else if (uMsr == 0xc0011019 && g_enmMicroarch >= kCpumMicroarch_AMD_15h_Piledriver && g_enmVendor == CPUMCPUVENDOR_AMD)
    37533949            rc = reportMsr_GenRangeFunctionEx(&paMsrs[i], cMsrs - i, 3, "AmdK7DrXAddrMaskN", 0xc0011019 - 1,
    37543950                                              false /*fEarlyEndOk*/, false /*fNoIgnMask*/, 0, &i);
    3755         else if (uMsr == 0xc0011021)
     3951        else if (uMsr == 0xc0011021 && g_enmVendor == CPUMCPUVENDOR_AMD)
    37563952            rc = reportMsr_AmdK7InstrCacheCfg(uMsr, uValue);
    37573953        else if (uMsr == 0xc0011023 && CPUMMICROARCH_IS_AMD_FAM_15H(g_enmMicroarch))
    37583954            rc = reportMsr_AmdFam15hCombUnitCfg(uMsr, uValue);
    3759         else if (uMsr == 0xc0011027)
     3955        else if (uMsr == 0xc0011027 && g_enmVendor == CPUMCPUVENDOR_AMD)
    37603956            rc = reportMsr_GenRangeFunctionEx(&paMsrs[i], cMsrs - i, 1, "AmdK7DrXAddrMaskN", 0xc0011027,
    37613957                                              false /*fEarlyEndOk*/, false /*fNoIgnMask*/, 0, &i);
     
    40734269        /* Make it C/C++ acceptable. */
    40744270        strcpy(szNameC, pszName);
    4075         for (char *psz = szNameC; *psz; psz++)
    4076             if (!RT_C_IS_ALNUM(*psz) && *psz != '_')
    4077                 *psz = '_';
    4078         for (size_t off = strlen(szNameC); off > 1 && szNameC[off - 1] == '_'; off--)
    4079             szNameC[off - 1] = '\0';
     4271        unsigned offDst = 0;
     4272        for (unsigned offSrc = 0; ; offSrc++)
     4273        {
     4274            char ch = szNameC[offSrc];
     4275            if (!RT_C_IS_ALNUM(ch) && ch != '_' && ch != '\0')
     4276                ch = '_';
     4277            if (ch == '_' && offDst > 0 && szNameC[offDst - 1] == '_')
     4278                offDst--;
     4279            szNameC[offDst++] = ch;
     4280            if (!ch)
     4281                break;
     4282        }
     4283        while (offDst > 1 && szNameC[offDst - 1] == '_')
     4284            szNameC[--offDst] = '\0';
     4285
    40804286        vbCpuRepDebug("NameC: %s\n", szNameC);
    40814287    }
     
    42324438    } enmOp = kCpuReportOp_Normal;
    42334439    g_pReportOut = NULL;
    4234     g_pDebugOut  = g_pStdErr;
     4440    g_pDebugOut  = NULL;
    42354441    const char *pszOutput   = NULL;
    42364442    const char *pszDebugOut = NULL;
Note: See TracChangeset for help on using the changeset viewer.

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