From bb49590329da222c343e82df3f7128dca80c2aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Hord=C3=A9?= Date: Mon, 2 Apr 2007 14:05:16 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20ensemble=20de=20fonctions=20permettant?= =?UTF-8?q?=20la=20d=C3=A9tection=20de=20la=20CPU?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/cpu.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 lib/cpu.c diff --git a/lib/cpu.c b/lib/cpu.c new file mode 100644 index 0000000..0d90c35 --- /dev/null +++ b/lib/cpu.c @@ -0,0 +1,94 @@ +#include "types.h" +#include "cpu.h" +#include "cpuid.h" +#include "memory.h" +#include "string.h" + + + +static u8 *msg[] = + { + "mmx", + "mmx2", + "sse", + "sse2", + "sse3", + "fpu", + "3dNow!", + "3dNow Extended!", + "HyperThreading", + "apic", + }; + +static u8 space[]=" "; + +void strcpuinfos(cpuinfo *proc,u8 *string) +{ + +} + +u8 getcpuinfos(cpuinfo *proc) +{ +u32 i,maxfunction,maxextended,unused,regeax,regebx,regecx,regedx; +bool *boolean; + +if (!cansetflag (0x00040000)) return 1; /*386 processor - no cpuid*/ +if (!cansetflag (0x00200000)) return 2; /*486 processor with no cpuid*/ + +cpuid(0, &maxfunction, &unused, &unused, &unused); +maxfunction &= 0xffff; +cpuid(0x80000000, &maxextended, &unused, &unused, &unused); +maxextended &= 0xffff; +if (maxfunction >= 1) + { + cpuid(1, ®eax, ®ebx, ®ecx, ®edx); + proc->stepping = (regeax & 0x0000000F); + proc->models = ((regeax>>4) & 0x0000000F); + proc->family = ((regeax>>8) & 0x0000000F); + proc->types = ((regeax>>12) & 0x00000003); + proc->emodels = ((regeax>>16) & 0x0000000F); + proc->efamily = ((regeax>>20) & 0x000000FF); + + proc->brandid = (regeax & 0xF); + proc->linesize = ((regeax>>8) & 0xF); + proc->count = ((regeax>>16) & 0xF); + proc->apicid = ((regeax>>24) & 0xF); + + proc->mmx=((regedx>>23) & 0x00000001); + proc->sse=((regedx>>25) & 0x00000001); + proc->sse2=((regedx>>26) & 0x00000001); + proc->sse3=(regecx & 0x00000001); + proc->fpu=(regedx & 0x00000001); + proc->htt=((regedx>>28) & 0x00000001); + + } +if (maxextended >= 1) + { + cpuid(0x80000001, ®eax, ®ebx, ®ecx, ®edx); + proc->mmx2=((regedx>>22) & 0x00000001); + proc->apic=((regedx>>9) & 0x00000001); + proc->now3d=((regedx>>30) & 0x00000001); + proc->now3d2=((regedx>>31) & 0x00000001); + } +if (maxextended >= 4) + { + int i; + for(i=0;i<3;i++) + cpuid(0x80000002+i, ®eax, ®ebx, ®ecx, ®edx); + memcpy(®eax,&proc->detectedname[0+i*16],4,1); + memcpy(®ebx,&proc->detectedname[4+i*16],4,1); + memcpy(®ecx,&proc->detectedname[8+i*16],4,1); + memcpy(®edx,&proc->detectedname[12+i*16],4,1); + } +boolean=&proc->mmx; +i=0; + +for(i=0;i<10;i++) +if (*(boolean++)==1) +{ +strcat(msg[i],&proc->techs); +strcat(space,&proc->techs); +} + return 0; +} +