Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 02-27-2006, 09:38 AM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default CPUID

I'm using the following code to get the CPUID string. The problem is that it returns the family/model/stepping together, instead of filling the array. I know nothing about asm, so help would be appreciated.

[Delphi]
TCPUID = Array[1..4] of LongInt;

...

function GetCPUID: TCPUID; assembler; register;
asm
PUSH EBX
PUSH EDI
MOV EDI,EAX
MOV EAX,1
DW $A20F
STOSD
MOV EAX,EBX
STOSD
MOV EAX,ECX
STOSD
MOV EAX,EDX
STOSD
POP EDI
POP EBX
end;

...

Memo1.Lines.Add('CPUID 1 (family): ' + IntToHex(CPUID[1], 3));
Memo1.Lines.Add('CPUID 2 (model): ' + IntToHex(CPUID[2], 3));
Memo1.Lines.Add('CPUID 3 (stepping): ' + IntToHex(CPUID[3], 3));
[/Delphi]


The family/mode/stepping is combined in CPUID[1]? Am I missing something?
Reply With Quote
  #2  
Old 02-27-2006, 01:03 PM
BaraoZemo BaraoZemo is offline
Senior Member
 
Join Date: Nov 2001
Posts: 3,577
Default RE: CPUID

hi,

what do you want ?

get a "unique -cpuid- number" ?

[DELPHI]//************************************************** ***********

function cpuid: dword;
const
ID_BIT = $200000; // EFLAGS ID bit
type
TCPUID = array[1..4] of Longint;
var
CPUID: TCPUID;
I: integer;

function IsCPUID_Available: Boolean; register;
asm
PUSHFD {direct access to flags no possible, only via stack}
POP EAX {flags to EAX}
MOV EDX,EAX {save current flags}
XOR EAX,ID_BIT {not ID bit}
PUSH EAX {onto stack}
POPFD {from stack to flags, with not ID bit}
PUSHFD {back to stack}
POP EAX {get back to EAX}
XOR EAX,EDX {check if ID bit affected}
JZ @exit {no, CPUID not availavle}
MOV AL,True {Result=True}
@exit:
end;

function GetCPUID: TCPUID; assembler; register;
asm
PUSH EBX {Save affected register}
PUSH EDI
MOV EDI,EAX {@Resukt}
MOV EAX,1
DW $A20F {CPUID Command}
STOSD {CPUID[1]}
MOV EAX,EBX
STOSD {CPUID[2]}
MOV EAX,ECX
STOSD {CPUID[3]}
MOV EAX,EDX
STOSD {CPUID[4]}
POP EDI {Restore registers}
POP EBX
end;

begin
for I := Low(CPUID) to High(CPUID) do CPUID[I] := -1;
if IsCPUID_Available then CPUID := GetCPUID;
Result := 10000 * CPUID[1] + CPUID[4];
end;



//how call the function in your program

procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(floattostr(cpuid));
end;[/DELPHI]


Regards
BaraoZemo

ps, don't forget to click in the button and Accept as Answer if this helped you!
Reply With Quote
  #3  
Old 02-27-2006, 02:39 PM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default RE: CPUID

Hello, well I just thought the CPUID returned the family/model/stepping seperately.


[Delphi]
STOSD {CPUID[1]}
MOV EAX,EBX
STOSD {CPUID[2]}
MOV EAX,ECX
STOSD {CPUID[3]}
MOV EAX,EDX
STOSD {CPUID[4]}
[/Delphi]

"The "CPU signature" function (eax=$1, returned in eax) returns stepping, model and family information in the format of the table below:

Bits Description
0..3 Stepping
4..7 Model
8..11 Family"


So wouldn't CPUID[1] be 0, CPUID[2] family, CPUID[3] model, CPUID[4] stepping?

I'm not trying to get a unique number, but the family & model & stepping # seperately.
Reply With Quote
  #4  
Old 02-27-2006, 03:32 PM
BaraoZemo BaraoZemo is offline
Senior Member
 
Join Date: Nov 2001
Posts: 3,577
Default RE: CPUID

don't use you own code to detect cpu family.. this is the bad way, because you will need a high updated code.. lets windows detect this to you.. (get the cpu type from windows registry)

1) The bad way (using a proprietary code)

[link=http://www.torry.net/vcl/system/cpu/acpuid.zip]CPU v.1.001 [/link]

[link=http://www.torry.net/vcl/system/cpu/cpuid.zip]CPUDI 1.2[/link]


[link=http://www.torry.net/vcl/system/systeminfo/MSIC.zip]Mitec Sysinfo pack[/link]



2) the good way (get the info from windows registry)

[DELPHI]uses registry;

type

{********************************* System Info ************************************}
TCPUInfo = record
VendorIdentifier,
Identifier : string;
MHz,
FeatureSet : word;
end;

{********************************* System Info ************************************}
procedure InitCPUInfo ( var ACPU: TCPUInfo);
begin
with ACPU do begin
Identifier := '';
VendorIdentifier := '';
MHz := 0;
FeatureSet := 0;
end;
end;


function FindCPUInfo: TCPUInfo;
const
CPURootKey = HKEY_LOCAL_MACHINE;
CPUKey = 'HARDWARE\DESCRIPTION\System\CentralProcessor\0';
var
Reg: TRegistry;
KeyGood: boolean;
CPUInfo: TCPUInfo;
begin // FindCPUInfo
InitCPUInfo ( CPUInfo);
Reg := TRegistry.Create;
try
Reg.RootKey := CPURootKey;
KeyGood := Reg.OpenKey(CPUKey, false);
if KeyGood then begin
with CPUInfo do begin
if Reg.ValueExists('VendorIdentifier') then
VendorIdentifier := Reg.ReadString('VendorIdentifier');
if Reg.ValueExists('Identifier') then
Identifier := Reg.ReadString('Identifier');
if Reg.ValueExists('~MHz') then
MHz := Reg.ReadInteger('~MHz');
// I get a "Range" error with Feature set???????
{ if Reg.ValueExists('FeatureSet') then
FeatureSet := Reg.ReadInteger('FeatureSet');}
// there is more information there if you care to decypher it
end; // with
end; // if KeyGood
Reg.CloseKey;
finally
Reg.free;
end;
Result := CPUInfo;
end; // FindCPUInfo;


procedure TForm1.Button1Click(Sender: TObject);
var MyCPUInfo: TCPUINFO;
begin
mycpuinfo:=FindCPUInfo;
with mycpuinfo do begin
label1.caption := Identifier;
label2.caption := VendorIdentifier;
label3.caption := inttostr(MHz);
label4.caption := inttostr(FeatureSet);
end;

end;[/DELPHI]

Regards
BaraoZemo

ps, don't forget to click in the button and Accept as Answer if this helped you!
Reply With Quote
  #5  
Old 02-27-2006, 03:40 PM
BaraoZemo BaraoZemo is offline
Senior Member
 
Join Date: Nov 2001
Posts: 3,577
Default RE: CPUID

i updated my code..

[DELPHI]uses registry;

type

{********************************* System Info ************************************}
TCPUInfo = record
VendorIdentifier,
ProcessorName : string;
Identifier : string;
MHz,
FeatureSet : word;
end;

{********************************* System Info ************************************}
procedure InitCPUInfo ( var ACPU: TCPUInfo);
begin
with ACPU do begin
ProcessorName := '';
Identifier := '';
VendorIdentifier := '';
MHz := 0;
FeatureSet := 0;
end;
end;


function FindCPUInfo: TCPUInfo;
const
CPURootKey = HKEY_LOCAL_MACHINE;
CPUKey = 'HARDWARE\DESCRIPTION\System\CentralProcessor\0';
var
Reg: TRegistry;
KeyGood: boolean;
CPUInfo: TCPUInfo;
begin // FindCPUInfo
InitCPUInfo ( CPUInfo);
Reg := TRegistry.Create;
try
Reg.RootKey := CPURootKey;
KeyGood := Reg.OpenKey(CPUKey, false);
if KeyGood then begin
with CPUInfo do begin
if Reg.ValueExists('ProcessorNameString') then
ProcessorName := Reg.ReadString('ProcessorNameString');
if Reg.ValueExists('VendorIdentifier') then
VendorIdentifier := Reg.ReadString('VendorIdentifier');
if Reg.ValueExists('Identifier') then
Identifier := Reg.ReadString('Identifier');
if Reg.ValueExists('~MHz') then
MHz := Reg.ReadInteger('~MHz');
end; // with
end; // if KeyGood
Reg.CloseKey;
finally
Reg.free;
end;
Result := CPUInfo;
end; // FindCPUInfo;


procedure TForm1.Button1Click(Sender: TObject);
var MyCPUInfo: TCPUINFO;
begin
mycpuinfo:=FindCPUInfo;
with mycpuinfo do begin
label1.caption := ProcessorName;
label2.caption := Identifier;
label3.caption := VendorIdentifier;
label4.caption := inttostr(MHz);
label5.caption := inttostr(FeatureSet);
end;

end;[/DELPHI]

Regards
BaraoZemo

ps, don't forget to click in the button and Accept as Answer if this helped you!
Reply With Quote
  #6  
Old 02-27-2006, 07:19 PM
Jasser Jasser is online now
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 4,833
Default RE: CPUID

BaraoZemo,

Does this function works with AMD and Pentium processors?

Regards,
Abdulaziz Jasser
Reply With Quote
  #7  
Old 02-28-2006, 02:30 AM
BaraoZemo BaraoZemo is offline
Senior Member
 
Join Date: Nov 2001
Posts: 3,577
Default RE: CPUID

i use amd athlon...and works fine for me...

Regards
BaraoZemo

ps, don't forget to click in the button and Accept as Answer if this helped you!
Reply With Quote
  #8  
Old 02-28-2006, 05:58 AM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default RE: CPUID

Actually, it shouldn't need any more updating than using the registry because they both contain the same data. The registry key 'VendorIdentifier' is what CPUID returns (in EBX, ECX, and EDX) if EAX = 0. Also you get family/model/stepping info if EAX = 1. So to detect the CPU details you're still working with the same data, only it's directly with asm.
Reply With Quote
  #9  
Old 02-28-2006, 06:10 AM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default RE: CPUID

I also forgot to mention, the registry doesn't always show the family/model/stepping either which is my main problem. It does show it under the identifier key for mine, but I looked on a 98 machine and it didn't show it.
Reply With Quote
  #10  
Old 02-28-2006, 06:49 AM
BaraoZemo BaraoZemo is offline
Senior Member
 
Join Date: Nov 2001
Posts: 3,577
Default RE: CPUID

hi,

look the Acpuid.pas inside this package.
(search for the procedure tcpuinfo.scancpumodel)
and you will find the code to "decode" the bits that you need
http://www.torry.net/vcl/system/cpu/acpuid.zip



Regards
BaraoZemo

ps, don't forget to click in the button and Accept as Answer if this helped you!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 04:24 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.