rendered paste body//
// ClassCPUID.m
// CPUID
//
//
// Copyleft 2007 - DiegoMax
//
#import "ClassCPUID.h"
@implementation ClassCPUID
-(void)GetInfo
{
[self GetVendorId];
[self GetCpuName];
[self GetStandardLevel01];
}
-(void)GetStandardLevel01
{
uint32_t d[4];
uint32_t s = 0x01;
asm("mov %%ebx, %%esi\n\t"
"cpuid\n\t"
"xchg %%esi, %%ebx"
: "=a" (d[0]),
"=S" (d[1]),
"=c" (d[2]),
"=d" (d[3])
: "a"(s)
);
//The extended processor family is encoded in bits 27...20.
uint32_t Valor = d[0] & 0x0FF00000;
if ([CpuName compare:@"GenuineIntel"])
{
switch (Valor) {
case 0x0000000:
ExtendedFamily = [NSString stringWithString:@"Intel P4"];
break;
default:
ExtendedFamily = [NSString stringWithString:@"-"];
break;
}
}
else //AMD
{
switch (Valor) {
case 0x00000000:
ExtendedFamily = [NSString stringWithString:@"AMD K8 (130 nm)"];
break;
case 0x00100000:
ExtendedFamily = [NSString stringWithString:@"AMD K8 (90 nm Rev D)"];
break;
case 0x00200000:
ExtendedFamily = [NSString stringWithString:@"AMD K8 (90 nm Rev E)"];
break;
case 0x00400000:
ExtendedFamily = [NSString stringWithString:@"AMD K8 (90 nm Rev F)"];
break;
default:
//The family is encoded in bits 11...8.
//Si entro aca, es porque tengo un AMD K7, o sea, no es K8 y es AMD, asi que tengo que revisar
//Los Bits 11 a 8
Valor = d[0] & 0xF00;
switch (Valor) {
case 0x500:
ExtendedFamily = [NSString stringWithString:@"AMD K5, K6"];
case 0x600:
ExtendedFamily = [NSString stringWithString:@"AMD K7"];
break;
default:
ExtendedFamily = [NSString stringWithString:@"-"];
break;
}
break;
}
}
//The model is encoded in bits 7...4.
Valor = d[0] & 0xF0;
if ([CpuName compare:@"GenuineIntel"])
{
switch (Valor) {
case 0x00:
Model = [NSString stringWithString:@"P4 (0.18 µm)"];
break;
case 0x10:
Model = [NSString stringWithString:@"P4 (0.18 µm)"];
break;
case 0x20:
Model = [NSString stringWithString:@"P4 (0.13 µm)"];
break;
case 0x40:
Model = [NSString stringWithString:@"P4 (0.09 µm)"];
break;
case 0x50:
Model = [NSString stringWithString:@"P4 (0.09 µm)"];
break;
case 0x60:
Model = [NSString stringWithString:@"P4 (65 nm)"];
break;
default:
break;
}
}
else //AMD
{
if ([ExtendedFamily compare:@"AMD K7"])
{
switch (Valor) {
case 0x10:
Model = [NSString stringWithString:@"Athlon (0.25 µm)"];
break;
//Copiar todos los Demas
default:
break;
}
}
else if ([ExtendedFamily rangeOfString:@"K8"].location != NSNotFound)
{
//Es un K8
//Tomo los primeros dos bits de los 4 que tengo para saber el socket
Valor = Valor & 0x30;
switch (Valor) {
case 0x00:
Model = [NSString stringWithString:@"Socket 754 or Socket S1"];
break;
case 0x10:
Model = [NSString stringWithString:@"Socket 940"];
break;
case 0x20:
Model = [NSString stringWithString:@"if Rev CG, then see K8 erratum #108"];
break;
default:
break;
}
//Despues hay que tomar los otros dos bits de los 4 que teniamos y verificar la otra info
}
}
[Model retain];
[ExtendedFamily retain];
}
-(void)GetVendorId
{
uint32_t d[4];
uint32_t s = 0x00;
asm("mov %%ebx, %%esi\n\t"
"cpuid\n\t"
"xchg %%esi, %%ebx"
: "=a" (d[0]),
"=S" (d[1]),
"=c" (d[2]),
"=d" (d[3])
: "a"(s)
);
VendorID = [NSString stringWithCString:&d length:16];
[VendorID retain];
}
-(void)GetCpuName
{
uint32_t d[4];
uint32_t s = 0x80000002;
asm("mov %%ebx, %%esi\n\t"
"cpuid\n\t"
"xchg %%esi, %%ebx"
: "=a" (d[0]),
"=S" (d[1]),
"=c" (d[2]),
"=d" (d[3])
: "a"(s)
);
NSString *CpuName1 = [NSString stringWithCString:&d length:16];
s = 0x80000003;
asm("mov %%ebx, %%esi\n\t"
"cpuid\n\t"
"xchg %%esi, %%ebx"
: "=a" (d[0]),
"=S" (d[1]),
"=c" (d[2]),
"=d" (d[3])
: "a"(s)
);
NSString *CpuName2 = [NSString stringWithCString:&d length:16];
s = 0x80000004;
asm("mov %%ebx, %%esi\n\t"
"cpuid\n\t"
"xchg %%esi, %%ebx"
: "=a" (d[0]),
"=S" (d[1]),
"=c" (d[2]),
"=d" (d[3])
: "a"(s)
);
NSString *CpuName3 = [NSString stringWithCString:&d length:16];
CpuName = [[CpuName1 stringByAppendingString:CpuName2] stringByAppendingString: CpuName3];
[CpuName retain];
}
-(void)dealloc {
[CpuName release];
[VendorID release];
[ExtendedFamily release];
[super dealloc];
}
@end