CPU type detection

- sometimes the system needs to know precisely on what type of cpu is
  running. The cpu type id detected during arch specific
  initialization and kept in the machine structure for later use.

- as a side-effect the information is exported to userland
This commit is contained in:
Tomas Hruby
2010-09-23 14:42:19 +00:00
parent 6e385a1b01
commit 8eece1c00c
3 changed files with 47 additions and 0 deletions

View File

@@ -304,8 +304,43 @@ PUBLIC void restore_fpu(struct proc *pr)
}
}
PRIVATE void cpu_identify(void)
{
u32_t eax, ebx, ecx, edx;
eax = 0;
_cpuid(&eax, &ebx, &ecx, &edx);
if (ebx == INTEL_CPUID_GEN_EBX && ecx == INTEL_CPUID_GEN_ECX &&
edx == INTEL_CPUID_GEN_EDX) {
machine.cpu_type.vendor = CPU_VENDOR_INTEL;
printf("Genuine Intel found\n");
} else if (ebx == AMD_CPUID_GEN_EBX && ecx == AMD_CPUID_GEN_ECX &&
edx == AMD_CPUID_GEN_EDX) {
machine.cpu_type.vendor = CPU_VENDOR_AMD;
printf("Authentic AMD found\n");
} else
machine.cpu_type.vendor = CPU_VENDOR_UNKNOWN;
if (eax == 0)
return;
eax = 1;
_cpuid(&eax, &ebx, &ecx, &edx);
machine.cpu_type.family = (eax >> 8) & 0xf;
if (machine.cpu_type.family == 0xf)
machine.cpu_type.family += (eax >> 20) & 0xff;
machine.cpu_type.model = (eax >> 4) & 0xf;
if (machine.cpu_type.model == 0xf || machine.cpu_type.model == 0x6)
machine.cpu_type.model += ((eax >> 16) & 0xf) << 4 ;
machine.cpu_type.stepping = eax & 0xf;
}
PUBLIC void arch_init(void)
{
cpu_identify();
#ifdef CONFIG_APIC
/*
* this is setting kernel segments to cover most of the phys memory. The

View File

@@ -153,6 +153,10 @@
#define AMD_CPUID_GEN_EDX 0x69746e65 /* ASCII value of "enti" */
#define AMD_CPUID_GEN_ECX 0x444d4163 /* ASCII value of "cAMD" */
#define CPU_VENDOR_INTEL 0
#define CPU_VENDOR_AMD 2
#define CPU_VENDOR_UNKNOWN 0xff
/* fpu context should be saved in 16-byte aligned memory */
#define FPUALIGN 16