W
weiliu
Unregistered / Unconfirmed
GUEST, unregistred user!
下面这个程序是我写的通过CPUID取得CPU的FAMILY,已经运行通过,在P4-2.0G的CPU上已经得到值为15,同CPU-Z是一样的:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TCPUIDResult = packed record
EAX: DWord;
EBX: DWord;
ECX: DWord;
EDX: DWord;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function CPUID(EAX: DWord): TCPUIDResult;
var
rEAX, rEBX, rECX, rEDX: DWord;
begin
asm
push EAX
push EBX
push ECX
push EDX
mov EAX,EAX
//******************************************************
//cpuid指令,因为Delphi的汇编编译器没有内置该指令,
//所以用该指令的机器语言代码$0F,$A2来实现
//******************************************************
db $0F,$A2
mov rEAX,EAX
mov rEBX,EBX
mov rECX,ECX
mov rEDX,EDX
pop EDX
pop ECX
pop EBX
pop EAX
end;
Result.EAX := rEAX;
Result.EBX := rEBX;
Result.ECX := rECX;
Result.EDX := rEDX;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
lvCPUID : TCPUIDResult;
begin
lvCPUID := cpuid(1);
showmessage(inttostr((lvCPUID.EAX and $F00) shr 8));
end;
end.
同样的代码,稍加修改,准备取得CPU其它的一些参数,想利用MSR,程序修改为如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TCPUIDResult = packed record
EAX: DWord;
EBX: DWord;
ECX: DWord;
EDX: DWord;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function RDMSR(ECX: DWord): TCPUIDResult;
var
rEAX, rEBX, rECX, rEDX: DWord;
begin
asm
push EAX
push EBX
push ECX
push EDX
mov EAX,EAX
//******************************************************
//rdmsr指令,因为Delphi的汇编编译器没有内置该指令,
//所以用该指令的机器语言代码$0F,$32来实现
//******************************************************
db $0F,$32
mov rEAX,EAX
mov rEBX,EBX
mov rECX,ECX
mov rEDX,EDX
pop EDX
pop ECX
pop EBX
pop EAX
end;
Result.EAX := rEAX;
Result.EBX := rEBX;
Result.ECX := rECX;
Result.EDX := rEDX;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
lvCPUID : TCPUIDResult;
begin
lvCPUID := RDMSR($198);
showmessage(inttostr((lvCPUID.EAX shr 8) and $FF));
end;
end.
运行后提示Privileged instruction(特权指令),失败。
查阅一些资料,看到RDMSR只能在实模式下运行,如果一定要在WINDOWS下运行,需要特别制做驱动,还有的资料说要提升权限CPL0,有谁知道具体的方法。
因为CPU-Z等一些软件,肯定是通过RDMSR来得到CPU的很多信息,比如倍频的,它们都可以在WINDOWS下运行。值得注意的是,早期版本的CPUZ,在执行的时候会自动产生一个CPUZ.VXD在程序所在的文件夹中,程序退出后就跟着被删除,这个VXD估计就是这驱动。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TCPUIDResult = packed record
EAX: DWord;
EBX: DWord;
ECX: DWord;
EDX: DWord;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function CPUID(EAX: DWord): TCPUIDResult;
var
rEAX, rEBX, rECX, rEDX: DWord;
begin
asm
push EAX
push EBX
push ECX
push EDX
mov EAX,EAX
//******************************************************
//cpuid指令,因为Delphi的汇编编译器没有内置该指令,
//所以用该指令的机器语言代码$0F,$A2来实现
//******************************************************
db $0F,$A2
mov rEAX,EAX
mov rEBX,EBX
mov rECX,ECX
mov rEDX,EDX
pop EDX
pop ECX
pop EBX
pop EAX
end;
Result.EAX := rEAX;
Result.EBX := rEBX;
Result.ECX := rECX;
Result.EDX := rEDX;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
lvCPUID : TCPUIDResult;
begin
lvCPUID := cpuid(1);
showmessage(inttostr((lvCPUID.EAX and $F00) shr 8));
end;
end.
同样的代码,稍加修改,准备取得CPU其它的一些参数,想利用MSR,程序修改为如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TCPUIDResult = packed record
EAX: DWord;
EBX: DWord;
ECX: DWord;
EDX: DWord;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function RDMSR(ECX: DWord): TCPUIDResult;
var
rEAX, rEBX, rECX, rEDX: DWord;
begin
asm
push EAX
push EBX
push ECX
push EDX
mov EAX,EAX
//******************************************************
//rdmsr指令,因为Delphi的汇编编译器没有内置该指令,
//所以用该指令的机器语言代码$0F,$32来实现
//******************************************************
db $0F,$32
mov rEAX,EAX
mov rEBX,EBX
mov rECX,ECX
mov rEDX,EDX
pop EDX
pop ECX
pop EBX
pop EAX
end;
Result.EAX := rEAX;
Result.EBX := rEBX;
Result.ECX := rECX;
Result.EDX := rEDX;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
lvCPUID : TCPUIDResult;
begin
lvCPUID := RDMSR($198);
showmessage(inttostr((lvCPUID.EAX shr 8) and $FF));
end;
end.
运行后提示Privileged instruction(特权指令),失败。
查阅一些资料,看到RDMSR只能在实模式下运行,如果一定要在WINDOWS下运行,需要特别制做驱动,还有的资料说要提升权限CPL0,有谁知道具体的方法。
因为CPU-Z等一些软件,肯定是通过RDMSR来得到CPU的很多信息,比如倍频的,它们都可以在WINDOWS下运行。值得注意的是,早期版本的CPUZ,在执行的时候会自动产生一个CPUZ.VXD在程序所在的文件夹中,程序退出后就跟着被删除,这个VXD估计就是这驱动。