From f85b149dae8d705585b8bb79dfeaedcbe735488b Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Thu, 9 Jan 2003 19:54:49 +0000 Subject: [PATCH] Rework part of the previous processor name changes so that we read cpu_exthigh and cpu_brand in printcpuinfo() instead of in identify_cpu(). We also only do it for known-good values of cpu_vendor which is a bit more conservative. Reviewed by: bde (mostly) --- sys/amd64/amd64/identcpu.c | 30 ++++++++++++++++++++++++++++-- sys/amd64/amd64/initcpu.c | 2 -- sys/amd64/amd64/locore.S | 24 ------------------------ sys/amd64/amd64/locore.s | 24 ------------------------ sys/amd64/include/md_var.h | 1 - sys/i386/i386/identcpu.c | 30 ++++++++++++++++++++++++++++-- sys/i386/i386/initcpu.c | 2 -- sys/i386/i386/locore.s | 24 ------------------------ sys/i386/include/md_var.h | 1 - 9 files changed, 56 insertions(+), 82 deletions(-) diff --git a/sys/amd64/amd64/identcpu.c b/sys/amd64/amd64/identcpu.c index 712a97cd6575..4880c742aacf 100644 --- a/sys/amd64/amd64/identcpu.c +++ b/sys/amd64/amd64/identcpu.c @@ -84,8 +84,9 @@ static void print_AMD_assoc(int i); static void print_transmeta_info(void); static void setup_tmx86_longrun(void); +int cpu_class; +u_int cpu_exthigh; /* Highest arg to extended CPUID */ u_int cyrix_did; /* Device ID of Cyrix CPU */ -int cpu_class = CPUCLASS_386; /* least common denominator */ char machine[] = "i386"; SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, machine, 0, "Machine class"); @@ -94,6 +95,8 @@ static char cpu_model[128]; SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD, cpu_model, 0, "Machine model"); +static char cpu_brand[48]; + #define MAX_BRAND_INDEX 8 static const char *cpu_brandtable[MAX_BRAND_INDEX + 1] = { @@ -135,13 +138,36 @@ int has_f00f_bug = 0; /* Initialized so that it can be patched. */ void printcpuinfo(void) { +#if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU) + u_int regs[4], i; +#endif char *brand; cpu_class = i386_cpus[cpu].cpu_class; printf("CPU: "); - strncpy(cpu_model, i386_cpus[cpu].cpu_name, sizeof cpu_model); + strncpy(cpu_model, i386_cpus[cpu].cpu_name, sizeof (cpu_model)); #if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU) + /* Check for extended CPUID information and a processor name. */ + if (cpu_high > 0 && + (strcmp(cpu_vendor, "GenuineIntel") == 0 || + strcmp(cpu_vendor, "AuthenticAMD") == 0 || + strcmp(cpu_vendor, "GenuineTMx86") == 0 || + strcmp(cpu_vendor, "TransmetaCPU") == 0)) { + do_cpuid(0x80000000, regs); + if (regs[0] >= 0x80000000) { + cpu_exthigh = regs[0]; + if (cpu_exthigh >= 0x80000004) { + brand = cpu_brand; + for (i = 0x80000002; i < 0x80000005; i++) { + do_cpuid(i, regs); + memcpy(brand, regs, sizeof(regs)); + brand += sizeof(regs); + } + } + } + } + if (strcmp(cpu_vendor, "GenuineIntel") == 0) { if ((cpu_id & 0xf00) > 0x300) { u_int brand_index; diff --git a/sys/amd64/amd64/initcpu.c b/sys/amd64/amd64/initcpu.c index 581fd631e88a..9f13eb6f931b 100644 --- a/sys/amd64/amd64/initcpu.c +++ b/sys/amd64/amd64/initcpu.c @@ -83,12 +83,10 @@ u_int cpu_id = 0; /* Stepping ID */ u_int cpu_feature = 0; /* Feature flags */ u_int cpu_high = 0; /* Highest arg to CPUID */ u_int cpuid_cpuinfo = 0; /* HyperThreading Info / Brand Index / CLFUSH */ -u_int cpu_exthigh = 0; /* Highest arg to extended CPUID */ #ifdef CPU_ENABLE_SSE u_int cpu_fxsr = 0; /* SSE enabled */ #endif char cpu_vendor[20] = ""; /* CPU Origin code */ -char cpu_brand[48] = ""; /* Brand name */ #ifdef I486_CPU /* diff --git a/sys/amd64/amd64/locore.S b/sys/amd64/amd64/locore.S index 58c008b69852..b9efaf613246 100644 --- a/sys/amd64/amd64/locore.S +++ b/sys/amd64/amd64/locore.S @@ -740,30 +740,6 @@ trycpuid: /* Use the `cpuid' instruction. */ /* Greater than Pentium...call it a Pentium Pro */ movl $CPU_686,R(cpu) 3: - /* Try to read extended CPUID information. */ - movl $0x80000000,%eax # cpuid 80000000 - cpuid - cmpl $0x80000000,%eax # is it a valid value? - jb 5f - movl %eax,R(cpu_exthigh) # highest extended capability - cmpl $0x80000004,%eax # does it have a brand name? - jb 5f - - /* Read the brand name. */ - leal R(cpu_brand),%edi - movl $0x80000002,%esi -4: - movl %esi,%eax - cpuid - movl %eax,(%edi) # Store next 16 characters - movl %ebx,4(%edi) # of brand name - movl %ecx,8(%edi) - movl %edx,12(%edi) - incl %esi # Advance to next set of 16 - addl $16,%edi - cmpl $0x80000004,%esi - jbe 4b -5: ret diff --git a/sys/amd64/amd64/locore.s b/sys/amd64/amd64/locore.s index 58c008b69852..b9efaf613246 100644 --- a/sys/amd64/amd64/locore.s +++ b/sys/amd64/amd64/locore.s @@ -740,30 +740,6 @@ trycpuid: /* Use the `cpuid' instruction. */ /* Greater than Pentium...call it a Pentium Pro */ movl $CPU_686,R(cpu) 3: - /* Try to read extended CPUID information. */ - movl $0x80000000,%eax # cpuid 80000000 - cpuid - cmpl $0x80000000,%eax # is it a valid value? - jb 5f - movl %eax,R(cpu_exthigh) # highest extended capability - cmpl $0x80000004,%eax # does it have a brand name? - jb 5f - - /* Read the brand name. */ - leal R(cpu_brand),%edi - movl $0x80000002,%esi -4: - movl %esi,%eax - cpuid - movl %eax,(%edi) # Store next 16 characters - movl %ebx,4(%edi) # of brand name - movl %ecx,8(%edi) - movl %edx,12(%edi) - incl %esi # Advance to next set of 16 - addl $16,%edi - cmpl $0x80000004,%esi - jbe 4b -5: ret diff --git a/sys/amd64/include/md_var.h b/sys/amd64/include/md_var.h index 1d0a03d4a9f0..107c90e628c4 100644 --- a/sys/amd64/include/md_var.h +++ b/sys/amd64/include/md_var.h @@ -49,7 +49,6 @@ extern u_int cpuid_cpuinfo; extern u_int cpu_id; extern u_int cpu_fxsr; extern char cpu_vendor[]; -extern char cpu_brand[]; extern u_int cyrix_did; extern uint16_t *elan_mmcr; extern char kstack[]; diff --git a/sys/i386/i386/identcpu.c b/sys/i386/i386/identcpu.c index 712a97cd6575..4880c742aacf 100644 --- a/sys/i386/i386/identcpu.c +++ b/sys/i386/i386/identcpu.c @@ -84,8 +84,9 @@ static void print_AMD_assoc(int i); static void print_transmeta_info(void); static void setup_tmx86_longrun(void); +int cpu_class; +u_int cpu_exthigh; /* Highest arg to extended CPUID */ u_int cyrix_did; /* Device ID of Cyrix CPU */ -int cpu_class = CPUCLASS_386; /* least common denominator */ char machine[] = "i386"; SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, machine, 0, "Machine class"); @@ -94,6 +95,8 @@ static char cpu_model[128]; SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD, cpu_model, 0, "Machine model"); +static char cpu_brand[48]; + #define MAX_BRAND_INDEX 8 static const char *cpu_brandtable[MAX_BRAND_INDEX + 1] = { @@ -135,13 +138,36 @@ int has_f00f_bug = 0; /* Initialized so that it can be patched. */ void printcpuinfo(void) { +#if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU) + u_int regs[4], i; +#endif char *brand; cpu_class = i386_cpus[cpu].cpu_class; printf("CPU: "); - strncpy(cpu_model, i386_cpus[cpu].cpu_name, sizeof cpu_model); + strncpy(cpu_model, i386_cpus[cpu].cpu_name, sizeof (cpu_model)); #if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU) + /* Check for extended CPUID information and a processor name. */ + if (cpu_high > 0 && + (strcmp(cpu_vendor, "GenuineIntel") == 0 || + strcmp(cpu_vendor, "AuthenticAMD") == 0 || + strcmp(cpu_vendor, "GenuineTMx86") == 0 || + strcmp(cpu_vendor, "TransmetaCPU") == 0)) { + do_cpuid(0x80000000, regs); + if (regs[0] >= 0x80000000) { + cpu_exthigh = regs[0]; + if (cpu_exthigh >= 0x80000004) { + brand = cpu_brand; + for (i = 0x80000002; i < 0x80000005; i++) { + do_cpuid(i, regs); + memcpy(brand, regs, sizeof(regs)); + brand += sizeof(regs); + } + } + } + } + if (strcmp(cpu_vendor, "GenuineIntel") == 0) { if ((cpu_id & 0xf00) > 0x300) { u_int brand_index; diff --git a/sys/i386/i386/initcpu.c b/sys/i386/i386/initcpu.c index 581fd631e88a..9f13eb6f931b 100644 --- a/sys/i386/i386/initcpu.c +++ b/sys/i386/i386/initcpu.c @@ -83,12 +83,10 @@ u_int cpu_id = 0; /* Stepping ID */ u_int cpu_feature = 0; /* Feature flags */ u_int cpu_high = 0; /* Highest arg to CPUID */ u_int cpuid_cpuinfo = 0; /* HyperThreading Info / Brand Index / CLFUSH */ -u_int cpu_exthigh = 0; /* Highest arg to extended CPUID */ #ifdef CPU_ENABLE_SSE u_int cpu_fxsr = 0; /* SSE enabled */ #endif char cpu_vendor[20] = ""; /* CPU Origin code */ -char cpu_brand[48] = ""; /* Brand name */ #ifdef I486_CPU /* diff --git a/sys/i386/i386/locore.s b/sys/i386/i386/locore.s index 58c008b69852..b9efaf613246 100644 --- a/sys/i386/i386/locore.s +++ b/sys/i386/i386/locore.s @@ -740,30 +740,6 @@ trycpuid: /* Use the `cpuid' instruction. */ /* Greater than Pentium...call it a Pentium Pro */ movl $CPU_686,R(cpu) 3: - /* Try to read extended CPUID information. */ - movl $0x80000000,%eax # cpuid 80000000 - cpuid - cmpl $0x80000000,%eax # is it a valid value? - jb 5f - movl %eax,R(cpu_exthigh) # highest extended capability - cmpl $0x80000004,%eax # does it have a brand name? - jb 5f - - /* Read the brand name. */ - leal R(cpu_brand),%edi - movl $0x80000002,%esi -4: - movl %esi,%eax - cpuid - movl %eax,(%edi) # Store next 16 characters - movl %ebx,4(%edi) # of brand name - movl %ecx,8(%edi) - movl %edx,12(%edi) - incl %esi # Advance to next set of 16 - addl $16,%edi - cmpl $0x80000004,%esi - jbe 4b -5: ret diff --git a/sys/i386/include/md_var.h b/sys/i386/include/md_var.h index 1d0a03d4a9f0..107c90e628c4 100644 --- a/sys/i386/include/md_var.h +++ b/sys/i386/include/md_var.h @@ -49,7 +49,6 @@ extern u_int cpuid_cpuinfo; extern u_int cpu_id; extern u_int cpu_fxsr; extern char cpu_vendor[]; -extern char cpu_brand[]; extern u_int cyrix_did; extern uint16_t *elan_mmcr; extern char kstack[];