⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getcpuid.pas

📁 放弃了先前的采用报表实现
💻 PAS
📖 第 1 页 / 共 3 页
字号:
Unit GetCPUID;
Interface
Uses Windows, Mmsystem, SysUtils, Math, Dialogs;
Type
   TCpuRec = Record
      Name: String[128];
      Vendor: String[12];
      Frequency: word;
      Family: integer;
      Model: integer;
      Stepping: integer;
      L1DCache: word;
      L1ICache: word;
      L2Cache: word;
   End;
   TCpuType = (cpu8086, cpu286, cpu386, cpu486, cpuPentium);
   TCPUIDARRAY = Array[1..4] Of Longint;
   TCpuData = Object
      Function GetCPUID: String;
      Function GetCPUIDSupport: Boolean;
      Function GetVendorString: String;
      Function GetCPUFrequency: word;
      Procedure GetFMS(Var Family, Model, Stepping: byte);
      Function GetMaxCpuId: dword;
      Function CheckFPU: Boolean;
      Function CheckTSC: Boolean;
      Function CheckMSR: Boolean;
      Function CheckMPS: Boolean;
      Function GetNoCpus: cardinal;
      Function CheckPN: Boolean;
      Function CheckCMPXCHG8B: Boolean;
      Function CheckCMOVe: Boolean;
      Function CheckSelfSnoop: Boolean;
      Function CheckDebugTraceStore: Boolean;
      Function CheckFXSAVEFXRSTOR: Boolean;
      Function CheckMMX: Boolean;
      Function CheckMMXplus: Boolean;
      Function CheckSSE: Boolean;
      Function CheckSSE2: Boolean;
      Function CheckAMD3DNow: Boolean;
      Function CheckAMD3DNowPlus: Boolean;
      Function GetMaxExtendedFunctions: dword;
      Procedure GetExtendedFMS(Var Family, Model, Stepping: byte);
      Function GetExtendedCpuName: String;
      Function GetExtendedL1DCache: word;
      Function GetExtendedL1ICache: word;
      Function GetExtendedL2Cache: word;

      Function CheckCeleron: Boolean;
      Function CheckPentiumIII: Boolean;
      Function CheckXeon: Boolean;
      Function CheckPentium4: Boolean;
      Function CheckIthanium: Boolean;

  //****Aici am conrectat****
      Function IntelP5N: String;
      Function IntelP6N: String;
  //****Pana aici****
      Function AMDK5N: String;
      Function Cyrix686N: String;
      Function GenericCpuN: String;
      Function P5CacheL1DI: word;
      Function P6CacheL1DI: word;
      Function P6CacheL2: word;

      Function AuthenticAMD: TCpuRec;

      Function GenuineIntel: TCpuRec;
      Function CyrixInstead: TCpuRec;
      Function GenericCPU: TCpuRec;
   End;
Const
   Intel486         : Array[0..8] Of String =
      ('Intel 486 DX',
      'Intel 486 DX',
      'Intel 486 SX',
      'Intel 486 DX2',
      'Intel 486 SL',
      'Intel 486 SX2',
      'Intel 486 DX2',
      'Intel 486 DX4',
      'Intel 486 DX4');
   UMC486           : Array[0..1] Of String =
      ('UMC U5D', 'UMC U5S');
   AMD486           : Array[0..5] Of String =
      ('AMD 486 DX2',
      'AMD 486 DX2',
      'AMD 486 DX4',
      'AMD 486 DX4',
      'AMD 5x86',
      'AMD 5x86');
   IntelP5          : Array[0..6] Of String =
      ('Intel Pentium P5 A-Step',
      'Intel Pentium P5',
      'Intel Pentium P54C',
      'Intel Pentium P24T Overdrive',
      'Intel Pentium MMX P55C',
      'Intel Pentium P54C',
      'Intel Pentium MMX P55C');
   NexGenNx586      = 'NexGen Nx586';
   Cyrix4x86        = 'VIA Cyrix 4x86';
   Cyrix5x86        = 'VIA Cyrix 5x86';
   CyrixMediaGX     = 'VIA Cyrix Media GX';
   CyrixM1          = 'VIA Cyrix 6x86';
   CyrixM2          = 'VIA Cyrix 6x86MX';
   CyrixIII         = 'VIA Cyrix III';
   AMDK5            : Array[0..3] Of String =
      ('AMD SSA5 (PR75/PR90/PR100)',
      'AMD 5k86 (PR120/PR133)',
      'AMD 5k86 (PR166)',
      'AMD 5k86 (PR200)');
   AMDK6            : Array[0..4] Of String =
      ('AMD K6 (166~233)',
      'AMD K6 (266~300)',
      'AMD K6-2',
      'AMD K6-III',
      'AMD K6-2+ or K6-III+');
   Centaur          : Array[0..2] Of String =
      ('Centaur C6',
      'Centaur C2',
      'Centaur C3');
   Rise             : Array[0..1] Of String =
      ('Rise mP6',
      'Rise mP6');
   IntelP6          : Array[0..7] Of String =
      ('Intel Pentium Pro A-Step',
      'Intel Pentium Pro',
      'Intel Pentium II',
      'Intel Pentium II',
      'Intel Pentium II',
      'Intel Pentium III',
      'Intel Pentium III',
      'Intel Pentium III');
   AMDK7            : Array[0..3] Of String =
      ('AMD Athlon(tm) Processor',
      'AMD Athlon(tm) Processor',
      'AMD Duron(tm) Processor',
      'AMD Thunderbird Processor');
   IntelP4          = 'Intel Pentium 4';
Var
   CpuData          : TCpuData;
Implementation

Function TCpuData.GetCPUIDSupport: Boolean;
Var
   TempDetect       : dword;
Begin
   Asm
    pushf
    pushfd
    push eax
    push ebx
    push ecx
    push edx

    pushfd
    pop eax
    mov ebx,eax
    xor eax,$00200000
    push eax
    popfd
    pushfd
    pop eax
    push ebx
    popfd
    xor eax,ebx
    mov TempDetect,eax

    pop edx
    pop ecx
    pop ebx
    pop eax
    popfd
    popf
   End;
   GetCPUIDSupport := (TempDetect = $00200000);
End;

Function TCpuData.GetVendorString: String;
Var
   s1, s2, s3       : Array[0..3] Of char;
   TempVendor       : String;
   i                : integer;
Begin
   Asm
    push eax
    push ebx
    push ecx
    push edx
    mov eax,0
    dw $A20F               /// cpuid
    mov s1,ebx
    mov s2,edx
    mov s3,ecx
    pop edx
    pop ecx
    pop ebx
    pop eax
   End;
   TempVendor := '';
   For i := 0 To 3 Do
      TempVendor := TempVendor + s1[i];
   For i := 0 To 3 Do
      TempVendor := TempVendor + s2[i];
   For i := 0 To 3 Do
      TempVendor := TempVendor + s3[i];
   GetVendorString := TempVendor;
End;

Function TCpuData.GetCPUFrequency: word;
Var
   TimeStart        : integer;
   TimeStop         : integer;
   StartTicks       : dword;
   EndTicks         : dword;
   TotalTicks       : dword;
   cpuSpeed         : dword;
   NeverExit        : Boolean;
Begin
   TimeStart := 0;
   TimeStop := 0;
   StartTicks := 0;
   EndTicks := 0;
   TotalTicks := 0;
   cpuSpeed := 0;
   NeverExit := true;
   TimeStart := timeGetTime;
   While NeverExit Do Begin
      TimeStop := timeGetTime;
      If ((TimeStop - TimeStart) > 1) Then Begin
         Asm
          xor eax,eax
          xor ebx,ebx
          xor ecx,ecx
          xor edx,edx
          dW $A20F               /// cpuid
          dW $310F                /// rdtsc
          mov StartTicks,eax
         End;
         Break;
      End;
   End;
   TimeStart := TimeStop;
   While NeverExit Do Begin
      TimeStop := timeGetTime;
      If ((TimeStop - TimeStart) > 1000) Then Begin
         Asm
           xor eax,eax
           xor ebx,ebx
           xor ecx,ecx
           xor edx,edx
           db $0F,$A2               /// cpuid
           db $0F,$31               /// rdtsc
           mov EndTicks,eax
         End;
         Break;
      End;
   End;
   TotalTicks := EndTicks - StartTicks;
   cpuSpeed := TotalTicks Div 1000000;
   GetCPUFrequency := cpuSpeed;
End;

Procedure TCpuData.GetFMS(Var Family, Model, Stepping: byte);
Var
   TempFlags        : dword;
   BinFlags         : Array[0..31] Of byte;
   i, Pos           : integer;
Begin
   Asm
    push eax
    push ebx
    push ecx
    push edx
    mov eax,1
    db $0F,$A2               /// cpuid
    mov TempFlags,eax
    pop edx
    pop ecx
    pop ebx
    pop eax
   End;
   For i := 0 To 31 Do Begin
      BinFlags[i] := TempFlags Mod 2;
      TempFlags := TempFlags Div 2;
   End;
   Family := 0;
   Model := 0;
   Stepping := 0;
   Pos := 0;
   For i := 0 To 3 Do Begin
      Stepping := Stepping + (BinFlags[Pos] * StrToInt(FloatToStr(Power(2,
         i))));
      inc(Pos);
   End;
   Pos := 4;
   For i := 0 To 3 Do Begin
      Model := Model + (BinFlags[Pos] * StrToInt(FloatToStr(Power(2, i))));
      inc(Pos);
   End;
   Pos := 8;
   For i := 0 To 3 Do Begin
      Family := Family + (BinFlags[Pos] * StrToInt(FloatToStr(Power(2,
         i))));
      inc(Pos);
   End;
End;

Function TCpuData.GetMaxCpuId: dword;
Var
   TempMax          : dword;
Begin
   Asm
    push eax
    push ebx
    push ecx
    push edx
    mov eax,0
    db $0F,$A2               /// cpuid
    mov TempMax,eax
    pop edx
    pop ecx
    pop ebx
    pop eax
   End;
   GetMaxCpuId := TempMax;
End;

Function TCpuData.CheckFPU: Boolean;
Label
   NoFpu;
Var
   TempCheck        : dword;
Begin
   TempCheck := 1;
   Asm
    push eax
    push ebx
    push ecx
    push edx
    mov eax,1
    db $0F,$A2               /// cpuid
    test edx,$1
    jz NoFpu
    mov edx,0
    mov TempCheck,edx
  NoFpu:
    pop edx
    pop ecx
    pop ebx
    pop eax
   End;
   CheckFPU := (TempCheck = 0);
End;

Function TCpuData.CheckTSC: Boolean;
Label
   NoTSC;
Var
   TempCheck        : dword;
Begin
   TempCheck := 1;
   Asm
    push eax
    push ebx
    push ecx
    push edx
    mov eax,1
    db $0F,$A2               /// cpuid
    test edx,$10
    jz NoTSC
    mov edx,0
    mov TempCheck,edx
  NoTSC:
    pop edx
    pop ecx
    pop ebx
    pop eax
   End;
   CheckTSC := (TempCheck = 0);
End;

Function TCpuData.CheckMSR: Boolean;
Label
   NoMSR;
Var
   TempCheck        : dword;
Begin
   TempCheck := 1;
   Asm
    push eax
    push ebx
    push ecx
    push edx
    mov eax,1
    db $0F,$A2               /// cpuid
    test edx,$20
    jz NoMSR
    mov edx,0
    mov TempCheck,edx
  NoMSR:
    pop edx
    pop ecx
    pop ebx
    pop eax
   End;
   CheckMSR := (TempCheck = 0);
End;

Function TCpuData.CheckMPS: Boolean;
Var
   SysInfo          : TSystemInfo;
Begin
   GetSystemInfo(SysInfo);
   CheckMPS := (SysInfo.dwNumberOfProcessors > 1);
End;

Function TCpuData.GetNoCpus: cardinal;
Var
   SysInfo          : TSystemInfo;
Begin
   GetSystemInfo(SysInfo);
   GetNoCpus := SysInfo.dwNumberOfProcessors;
End;

Function TCpuData.CheckPN: Boolean;
Label
   NoPN;
Var
   TempCheck        : dword;
Begin
   TempCheck := 1;
   Asm
    push eax
    push ebx
    push ecx
    push edx
    mov eax,1
    db $0F,$A2               /// cpuid
    test edx,$40000
    jz NoPN
    mov edx,0
    mov TempCheck,edx
  NoPN:
    pop edx
    pop ecx
    pop ebx
    pop eax
   End;
   CheckPN := (TempCheck = 0);
End;

Function TCpuData.CheckCMPXCHG8B: Boolean;
Label
   NoCMPXCHG8B;
Var
   TempCheck        : dword;
Begin
   TempCheck := 1;
   Asm
    push eax
    push ebx
    push ecx
    push edx
    mov eax,1
    db $0F,$A2               /// cpuid
    test edx,$100
    jz NoCMPXCHG8B
    mov edx,0
    mov TempCheck,edx
  NoCMPXCHG8B:
    pop edx
    pop ecx
    pop ebx
    pop eax
   End;
   CheckCMPXCHG8B := (TempCheck = 0);
End;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -