Ticket #3541: haiku_ticket4427_3541_try3c.diff

File haiku_ticket4427_3541_try3c.diff, 4.2 KB (added by v, 15 years ago)

patch. different approach

  • headers/os/kernel/OS.h

     
    482482    B_CPU_INTEL_PENTIUM_M_MODEL_13      = 0x106d, /* Dothan */
    483483    B_CPU_INTEL_PENTIUM_CORE,
    484484    B_CPU_INTEL_PENTIUM_CORE_2,
    485     B_CPU_INTEL_PENTIUM_CORE_2_EXTREME  = 0x11067, /* Core 2 Extreme or Xeon
    486                                                        model 23 on 45 nm */
     485    B_CPU_INTEL_PENTIUM_CORE_2_45_NM    = 0x11067, /* Core 2 on 45 nm
     486                                                       (Core 2 Extreme,
     487                                                       Xeon model 23 or
     488                                                       Core 2 Duo/Quad) */
    487489    B_CPU_INTEL_PENTIUM_CORE_I7     = 0x1106a, /* Core i7 920 @ 2.6(6) */
    488490    B_CPU_INTEL_PENTIUM_IV              = 0x10f0,
    489491    B_CPU_INTEL_PENTIUM_IV_MODEL_1,
  • headers/private/shared/cpu_type.h

     
    6060}
    6161
    6262
     63#ifdef __INTEL__
     64/* parameter 'name' needs to point to an allocated array of 49 characters */
     65void
     66get_cpuid_model_string(char *name)
     67{
     68    /* references:
     69     *
     70     * http://grafi.ii.pw.edu.pl/gbm/x86/cpuid.html
     71     * http://www.sandpile.org/ia32/cpuid.htm
     72     * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/TN13.pdf (Duron erratum)
     73     */
     74
     75    cpuid_info baseInfo;
     76    cpuid_info cpuInfo;
     77    int32 maxStandardFunction, maxExtendedFunction = 0;
     78
     79    memset(name, 0, 49*sizeof(char));
     80
     81    if (get_cpuid(&baseInfo, 0, 0) != B_OK) {
     82        // this CPU doesn't support cpuid
     83        return;
     84    }
     85
     86    maxStandardFunction = baseInfo.eax_0.max_eax;
     87    if (maxStandardFunction >= 500)
     88        maxStandardFunction = 0; /* old Pentium sample chips has cpu signature here */
     89
     90    /* Extended cpuid */
     91
     92    get_cpuid(&cpuInfo, 0x80000000, 0); /* hardcoded to CPU 0 */
     93
     94    // extended cpuid is only supported if max_eax is greater than the service id
     95    if (cpuInfo.eax_0.max_eax > 0x80000000)
     96        maxExtendedFunction = cpuInfo.eax_0.max_eax & 0xff;
     97
     98    if (maxExtendedFunction >=4 ) {
     99        int32 i;
     100       
     101        for (i = 0; i < 3; i++) {
     102            cpuid_info nameInfo;
     103            get_cpuid(&nameInfo, 0x80000002 + i, 0);
     104
     105            memcpy(name, &nameInfo.regs.eax, 4);
     106            memcpy(name + 4, &nameInfo.regs.ebx, 4);
     107            memcpy(name + 8, &nameInfo.regs.ecx, 4);
     108            memcpy(name + 12, &nameInfo.regs.edx, 4);
     109            name += 16;
     110        }
     111    }
     112
     113    return;
     114}
     115#endif  // __INTEL__
     116
     117
    63118const char *
    64119get_cpu_model_string(system_info *info)
    65120{
     121#if __INTEL__
     122    char cpuid_name[49]; /* for use with get_cpuid_model_string() */
     123#endif  // __INTEL__
     124
    66125    // Determine CPU type
    67126    switch (info->cpu_type) {
    68127#if __POWERPC__
     
    106165            return "Pentium III";
    107166        case B_CPU_INTEL_PENTIUM_M:
    108167        case B_CPU_INTEL_PENTIUM_M_MODEL_13:
     168            get_cpuid_model_string(cpuid_name);
     169            if (strcasestr(cpuid_name, "Celeron") != NULL)
     170                return "Pentium M Celeron";
    109171            return "Pentium M";
    110172        case B_CPU_INTEL_ATOM:
    111173            return "Atom";
    112174        case B_CPU_INTEL_PENTIUM_CORE:
    113175            return "Core";
    114176        case B_CPU_INTEL_PENTIUM_CORE_2:
     177            get_cpuid_model_string(cpuid_name);
     178            if (strcasestr(cpuid_name, "Xeon") != NULL)
     179                return "Core 2 Xeon";
    115180            return "Core 2";
    116         case B_CPU_INTEL_PENTIUM_CORE_2_EXTREME:
     181        case B_CPU_INTEL_PENTIUM_CORE_2_45_NM:
     182            get_cpuid_model_string(cpuid_name);
     183            if (strcasestr(cpuid_name, "Duo") != NULL ||
     184                strcasestr(cpuid_name, "Quad") != NULL)
     185                return "Core 2";
     186            if (strcasestr(cpuid_name, "Xeon") != NULL)
     187                return "Core 2 Xeon";
    117188            return "Core 2 Extreme";
    118189        case B_CPU_INTEL_PENTIUM_CORE_I7:
     190            get_cpuid_model_string(cpuid_name);
     191            if (strcasestr(cpuid_name, "Xeon") != NULL)
     192                return "Core i7 Xeon";
    119193            return "Core i7";
    120194        case B_CPU_INTEL_PENTIUM_IV:
    121195        case B_CPU_INTEL_PENTIUM_IV_MODEL_1:
    122196        case B_CPU_INTEL_PENTIUM_IV_MODEL_2:
    123197        case B_CPU_INTEL_PENTIUM_IV_MODEL_3:       
    124198        case B_CPU_INTEL_PENTIUM_IV_MODEL_4:
     199            get_cpuid_model_string(cpuid_name);
     200            if (strcasestr(cpuid_name, "Celeron") != NULL)
     201                return "Pentium 4 Celeron";
     202            if (strcasestr(cpuid_name, "Xeon") != NULL)
     203                return "Pentium 4 Xeon";
    125204            return "Pentium 4";
    126205
    127206        /* AMD */