home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 February / Chip_2004-02_cd1.bin / zkuste / konfig / download / msic / Help / Int / MSI_CPU.int < prev    next >
Text File  |  2003-08-26  |  14KB  |  366 lines

  1. {*******************************************************}
  2. {                            }
  3. {    MiTeC System Information Component        }
  4. {        CPU Detection Part            }
  5. {        version 8.3 for Delphi 5,6,7            }
  6. {                            }
  7. {    Copyright ⌐ 1997,2003 Michal Mutl        }
  8. {                            }
  9. {*******************************************************}
  10.  
  11. {$INCLUDE MITEC_DEF.INC}
  12.  
  13. unit MSI_CPU;
  14.  
  15. interface
  16.  
  17. uses
  18.   SysUtils, Windows, Classes, MSI_Common;
  19.  
  20. type
  21.   TCPUType = (ctPrimary, ctOverDrive, ctSecondary, ctUnknown);
  22.   TCPUFamily = (cfUnknown, cf8086, cf286, cf386, cf486, cf586, cf686, cf786, cf8086_64);
  23.   TCPUArchitecture = (IA_32, IA_64);
  24.  
  25.   TCPUIDResult = packed record
  26.     EAX: Cardinal;
  27.     EBX: Cardinal;
  28.     ECX: Cardinal;
  29.     EDX: Cardinal;
  30.   end;
  31.  
  32.   TIntelCache = array [0..15] of Byte;
  33.  
  34.   TAMDCache = record
  35.     L12MDataTLB: array [0..1] of Byte;  //Entries, Associativity
  36.     L12MInstructionTLB: array [0..1] of Byte;
  37.     L14KDataTLB: array [0..1] of Byte;
  38.     L14KInstructionTLB: array [0..1] of Byte;
  39.     L1DataCache: array [0..3] of Byte;  // Line size(B), Lines per tag, Associativity, Size(KB)
  40.     L1ICache: array [0..3] of Byte;
  41.     L22MDataTLB: array [0..1] of Byte;
  42.     L22MInstructionTLB: array [0..1] of Byte;
  43.     L24KDataTLB: array [0..1] of Byte;
  44.     L24KInstructionTLB: array [0..1] of Byte;
  45.     Level2Cache: array [0..3] of Byte;
  46.   end;
  47.  
  48.   TCyrixCache = record
  49.     L1CacheInfo: array [0..3] of Byte;
  50.     TLBInfo: array [0..3] of Byte;
  51.   end;
  52.  
  53.   TFreqInfo = record
  54.     RawFreq: Cardinal;
  55.     NormFreq: Cardinal;
  56.     InCycles: Cardinal;
  57.     ExTicks: Cardinal;
  58.   end;
  59.  
  60. const
  61. { CPUID EFLAGS Id bit }
  62.   CPUIDID_BIT    =    $200000;
  63.  
  64. { CPUID execution levels }
  65.   CPUID_MAXLEVEL    : DWORD = $0;
  66.   CPUID_VENDORSIGNATURE : DWORD = $0;
  67.   CPUID_CPUSIGNATURE    : DWORD = $1;
  68.   CPUID_CPUFEATURESET    : DWORD = $1;
  69.   CPUID_CACHETLB    : DWORD = $2;
  70.   CPUID_CPUSERIALNUMBER : DWORD = $3;
  71.   CPUID_MAXLEVELEX    : DWORD = $80000000;
  72.   CPUID_CPUSIGNATUREEX    : DWORD = $80000001;
  73.   CPUID_CPUMARKETNAME1    : DWORD = $80000002;
  74.   CPUID_CPUMARKETNAME2    : DWORD = $80000003;
  75.   CPUID_CPUMARKETNAME3    : DWORD = $80000004;
  76.   CPUID_LEVEL1CACHETLB    : DWORD = $80000005;
  77.   CPUID_LEVEL2CACHETLB    : DWORD = $80000006;
  78.   CPUID_APMFEATURESET    : DWORD = $80000007;
  79.   CPUID_PHYSADDR    : DWORD = $80000008;
  80.  
  81. { CPU vendors }
  82.   VENDOR_UNKNOWN    = 0;
  83.   VENDOR_INTEL        = 1;
  84.   VENDOR_AMD        = 2;
  85.   VENDOR_CYRIX        = 3;
  86.   VENDOR_IDT        = 4;
  87.   VENDOR_NEXGEN     = 5;
  88.   VENDOR_UMC        = 6;
  89.   VENDOR_RISE        = 7;
  90.   VENDOR_TM        = 8;
  91.   VENDOR_SIS        = 9;
  92.   VENDOR_NSC        = 10;
  93.  
  94. { Standard feature set flags }
  95.   SFS_FPU    = 0;
  96.   SFS_VME    = 1;
  97.   SFS_DE     = 2;
  98.   SFS_PSE    = 3;
  99.   SFS_TSC    = 4;
  100.   SFS_MSR    = 5;
  101.   SFS_PAE    = 6;
  102.   SFS_MCE    = 7;
  103.   SFS_CX8    = 8;
  104.   SFS_APIC   = 9;
  105.   SFS_SEP    = 11;
  106.   SFS_MTRR   = 12;
  107.   SFS_PGE    = 13;
  108.   SFS_MCA    = 14;
  109.   SFS_CMOV   = 15;
  110.   SFS_PAT    = 16;
  111.   SFS_PSE36  = 17;
  112.   SFS_PSN    = 18;
  113.   SFS_CLFSH  = 19;
  114.   SFS_DS     = 21;
  115.   SFS_ACPI   = 22;
  116.   SFS_MMX    = 23;
  117.   SFS_FXSR   = 24;
  118.   SFS_SSE    = 25;
  119.   SFS_SSE2   = 26;
  120.   SFS_SS     = 27;
  121.   SFS_HTT    = 28;
  122.   SFS_TM     = 29;
  123.  
  124.  
  125. { Extended feature set flags (duplicates removed) }
  126.   EFS_MP      = 19; { Multiprocessing capable }
  127.   EFS_EXMMXA  = 22; { AMD Specific }
  128.   EFS_EXMMXC  = 24; { Cyrix Specific }
  129.   EFS_3DNOW   = 31;
  130.   EFS_EX3DNOW = 30;
  131.  
  132.  
  133. { AMD Cache Associativity }
  134.   AMDCA_L2OFF        = $0;
  135.   AMDCA_DIRECTMAPPED = $1;
  136.   AMDCA_2WAY         = $2;
  137.   AMDCA_4WAY         = $4;
  138.   AMDCA_8WAY         = $6;
  139.   AMDCA_16WAY        = $8;
  140.   AMDCA_FULL         = $F;
  141.  
  142. type
  143.   TCPUFeatures = class(TPersistent)
  144.   private
  145.     FSEP: boolean;
  146.     FMTRR: boolean;
  147.     FMSR: boolean;
  148.     FPSE: boolean;
  149.     FTSC: boolean;
  150.     FMCE: boolean;
  151.     FMMX: boolean;
  152.     FPAT: boolean;
  153.     FPAE: boolean;
  154.     FVME: boolean;
  155.     FPGE: boolean;
  156.     FCMOV: boolean;
  157.     FFPU: boolean;
  158.     FCX8: boolean;
  159.     FSIMD: Boolean;
  160.     FMCA: boolean;
  161.     FAPIC: boolean;
  162.     FDE: boolean;
  163.     FPSE36: boolean;
  164.     FSERIAL: Boolean;
  165.     F3DNOW: boolean;
  166.     FEX3DNOW: Boolean;
  167.     FEXMMX: Boolean;
  168.     FCLFSH: Boolean;
  169.     FACPI: Boolean;
  170.     FSS: Boolean;
  171.     FSIMD2: Boolean;
  172.     FTM: Boolean;
  173.     FDS: Boolean;
  174.     FFXSR: Boolean;
  175.     FHTT: Boolean;
  176.   public
  177.     CPUID: TCPUIDResult;
  178.     procedure GetInfo;
  179.     procedure Report(var sl: TStringList; Standalone: Boolean = True); virtual;
  180.     procedure GetFeaturesStr(var sl: TStringList);
  181.   published
  182.     property _3DNOW :Boolean read F3DNOW {$IFNDEF D6PLUS} write F3DNOW {$ENDIF} stored False;
  183.     property EX_3DNOW :Boolean read FEX3DNOW {$IFNDEF D6PLUS} write FEX3DNOW {$ENDIF} stored False;
  184.     property EX_MMX :Boolean read FEXMMX {$IFNDEF D6PLUS} write FEXMMX {$ENDIF} stored False;
  185.     property TM :Boolean read FTM {$IFNDEF D6PLUS} write FTM {$ENDIF} stored false;
  186.     property HTT :Boolean read FHTT {$IFNDEF D6PLUS} write FHTT {$ENDIF} stored False;
  187.     property SS :Boolean read FSS {$IFNDEF D6PLUS} write FSS {$ENDIF} stored false;
  188.     property SSE2 :Boolean read FSIMD2 {$IFNDEF D6PLUS} write FSIMD2 {$ENDIF} stored False;
  189.     property SSE :Boolean read FSIMD {$IFNDEF D6PLUS} write FSIMD {$ENDIF} stored False;
  190.     property FXSR :Boolean read FFXSR {$IFNDEF D6PLUS} write FFXSR {$ENDIF} stored false;
  191.     property MMX :Boolean read FMMX {$IFNDEF D6PLUS} write FMMX {$ENDIF} stored false;
  192.     property ACPI :Boolean read FACPI {$IFNDEF D6PLUS} write FACPI {$ENDIF} stored false;
  193.     property DS :Boolean read FDS {$IFNDEF D6PLUS} write FDS {$ENDIF} stored false;
  194.     property CLFSH :Boolean read FCLFSH {$IFNDEF D6PLUS} write FCLFSH {$ENDIF} stored false;
  195.     property PSN :Boolean read FSERIAL {$IFNDEF D6PLUS} write FSERIAL {$ENDIF} stored False;
  196.     property PSE36 :Boolean read FPSE36 {$IFNDEF D6PLUS} write FPSE36 {$ENDIF} stored false;
  197.     property PAT :Boolean read FPAT {$IFNDEF D6PLUS} write FPAT {$ENDIF} stored false;
  198.     property CMOV :Boolean read FCMOV {$IFNDEF D6PLUS} write FCMOV {$ENDIF} stored false;
  199.     property MCA :Boolean read FMCA {$IFNDEF D6PLUS} write FMCA {$ENDIF} stored false;
  200.     property PGE :Boolean read FPGE {$IFNDEF D6PLUS} write FPGE {$ENDIF} stored false;
  201.     property MTRR :Boolean read FMTRR {$IFNDEF D6PLUS} write FMTRR {$ENDIF} stored false;
  202.     property SEP :Boolean read FSEP {$IFNDEF D6PLUS} write FSEP {$ENDIF} stored false;
  203.     property APIC :Boolean read FAPIC {$IFNDEF D6PLUS} write FAPIC {$ENDIF} stored false;
  204.     property CX8 :Boolean read FCX8 {$IFNDEF D6PLUS} write FCX8 {$ENDIF} stored false;
  205.     property MCE :Boolean read FMCE {$IFNDEF D6PLUS} write FMCE {$ENDIF} stored false;
  206.     property PAE :Boolean read FPAE {$IFNDEF D6PLUS} write FPAE {$ENDIF} stored false;
  207.     property MSR :Boolean read FMSR {$IFNDEF D6PLUS} write FMSR {$ENDIF} stored false;
  208.     property TSC :Boolean read FTSC {$IFNDEF D6PLUS} write FTSC {$ENDIF} stored false;
  209.     property PSE :Boolean read FPSE {$IFNDEF D6PLUS} write FPSE {$ENDIF} stored false;
  210.     property DE :Boolean read FDE {$IFNDEF D6PLUS} write FDE {$ENDIF} stored false;
  211.     property VME :Boolean read FVME {$IFNDEF D6PLUS} write FVME {$ENDIF} stored false;
  212.     property FPU :Boolean read FFPU {$IFNDEF D6PLUS} write FFPU {$ENDIF} stored false;
  213.   end;
  214.  
  215.   TCPUCache = class(TPersistent)
  216.   private
  217.     FFamily: integer;
  218.     FStepping: integer;
  219.     FModel: Integer;
  220.     FVendorID: string;
  221.  
  222.     FLevel2: LongInt;
  223.     FLevel1: LongInt;
  224.     FLevel1Data: LongInt;
  225.     FLevel1Code: LongInt;
  226.     FDesc: TStrings;
  227.     FLevel3: LongInt;
  228.  
  229.   public
  230.     IntelCache: TIntelCache;
  231.     AMDCache: TAMDCache;
  232.     CyrixCache: TCyrixCache;
  233.     constructor Create;
  234.     destructor Destroy; override;
  235.     procedure GetInfo(AVendor: DWORD);
  236.     procedure Report(var sl :TStringList; Standalone: Boolean = True); virtual;
  237.  
  238.     property Descriptions: TStrings read FDesc;
  239.     property L1Data: LongInt read FLevel1Data;
  240.     property L1Code: LongInt read FLevel1Code;
  241.   published
  242.     property Level1: LongInt read FLevel1 {$IFNDEF D6PLUS} write FLevel1 {$ENDIF} stored FALSE;
  243.     property Level2: LongInt read FLevel2 {$IFNDEF D6PLUS} write FLevel2 {$ENDIF} stored FALSE;
  244.     property Level3: LongInt read FLevel3 {$IFNDEF D6PLUS} write FLevel3 {$ENDIF} stored FALSE;
  245.   end;
  246.  
  247.   TCPU = class(TPersistent)
  248.   private
  249.     FFreq :integer;
  250.     FFeatures: TCPUFeatures;
  251.     FVendorReg: string;
  252.     FVendorIDReg: string;
  253.     FCount: integer;
  254.     FFamily: integer;
  255.     FStepping: integer;
  256.     FModel: integer;
  257.     FVendorID: string;
  258.     FTyp: DWORD;
  259.     FLevel: DWORD;
  260.     FCache: TCPUCache;
  261.     FSerial: string;
  262.     FDIV: Boolean;
  263.     FVendorCPUID: string;
  264.     FVendorIDCPUID: string;
  265.     FBrand: DWORD;
  266.     FCPUVendor: DWORD;
  267.     FCodeName: string;
  268.     FVendorEx: string;
  269.     FMode: TExceptionMode;
  270.     FCPUSig: TCPUIDResult;
  271.     FExtModel: integer;
  272.     FExtFamily: integer;
  273.     FCPUFamily: TCPUFamily;
  274.     FCPUType: TCPUType;
  275.     FExtStep: integer;
  276.     FCPUSigEx: TCPUIDResult;
  277.     FExtLevel: DWORD;
  278.     FPNSReg: string;
  279.     FFreqReg: DWORD;
  280.     FArch: TCPUArchitecture;
  281.     FGetCache, FGetFeat: Boolean;
  282.   public
  283.     constructor Create;
  284.     destructor Destroy; override;
  285.     procedure GetInfo(AGetCache: Boolean = True; AGetFeatures: Boolean = True);
  286.     procedure Report(var sl :TStringList; Standalone: Boolean = True); virtual;
  287.  
  288.     property RegistryVendor :string read FVendorReg {$IFNDEF D6PLUS} write FVendorReg {$ENDIF} stored false;
  289.     property RegistryVendorID :string read FVendorIDReg {$IFNDEF D6PLUS} write FVendorIDReg {$ENDIF} stored False;
  290.     property RegistryNameString :string read FPNSReg {$IFNDEF D6PLUS} write FPNSReg {$ENDIF} stored False;
  291.     property RegistryFrequency :DWORD read FFreqReg {$IFNDEF D6PLUS} write FFreqReg {$ENDIF} stored False;
  292.     property CPUIDVendor :string read FVendorCPUID {$IFNDEF D6PLUS} write FVendorCPUID {$ENDIF} stored false;
  293.     property CPUIDNameString :string read FVendorIDCPUID {$IFNDEF D6PLUS} write FVendorIDCPUID {$ENDIF} stored False;
  294.     property ExtendedFamily :integer read FExtFamily {$IFNDEF D6PLUS} write FExtFamily {$ENDIF} stored false;
  295.     property ExtendedModel :integer read FExtModel {$IFNDEF D6PLUS} write FExtModel {$ENDIF} stored false;
  296.     property ExtendedStepping :integer read FExtStep {$IFNDEF D6PLUS} write FExtStep {$ENDIF} stored false;
  297.     property Brand: DWORD read FBrand {$IFNDEF D6PLUS} write FBrand {$ENDIF} stored False;
  298.     property Typ: DWORD read FTyp {$IFNDEF D6PLUS} write FTyp {$ENDIF} stored False;
  299.     property MaxFunctionLevel: DWORD read FLevel {$IFNDEF D6PLUS} write FLevel {$ENDIF} stored False;
  300.     property MaxExtendedFunctionLevel: DWORD read FExtLevel {$IFNDEF D6PLUS} write FExtLevel {$ENDIF} stored False;
  301.     property VendorType: DWORD read FCPUVendor {$IFNDEF D6PLUS} write FCPUVendor {$ENDIF} stored False;
  302.     property Signature: TCPUIDResult read FCPUSig {$IFNDEF D6PLUS} write FCPUSig {$ENDIF} stored False;
  303.     property ExtendedSignature: TCPUIDResult read FCPUSigEx {$IFNDEF D6PLUS} write FCPUSigEx {$ENDIF} stored False;
  304.   published
  305.     property ExceptionMode: TExceptionMode read FMode write FMode;
  306.     property Count :integer read FCount {$IFNDEF D6PLUS} write FCount {$ENDIF} stored false;
  307.     property Vendor :string read FVendorEx {$IFNDEF D6PLUS} write FVendorEx {$ENDIF} stored False;
  308.  
  309.     property FriendlyName :string read FVendorID {$IFNDEF D6PLUS} write FVendorID {$ENDIF} stored false;
  310.     property CodeName: string read FCodeName {$IFNDEF D6PLUS} write FCodeName {$ENDIF} stored False;
  311.     property Frequency :integer read FFreq {$IFNDEF D6PLUS} write FFreq {$ENDIF} stored false;
  312.  
  313.     property Family :integer read FFamily {$IFNDEF D6PLUS} write FFamily {$ENDIF} stored false;
  314.     property Model :integer read FModel {$IFNDEF D6PLUS} write FModel {$ENDIF} stored false;
  315.     property Stepping :integer read FStepping {$IFNDEF D6PLUS} write FStepping {$ENDIF} stored false;
  316.     property Features :TCPUFeatures read FFeatures  {$IFNDEF D6PLUS} write FFeatures {$ENDIF} stored false;
  317.     property Cache: TCPUCache read FCache  {$IFNDEF D6PLUS} write FCache {$ENDIF} stored false;
  318.     property SerialNumber: string read FSerial {$IFNDEF D6PLUS} write FSerial {$ENDIF} stored False;
  319.     property FDIVBug: Boolean read FDIV {$IFNDEF D6PLUS} write FDIV {$ENDIF} stored False;
  320.  
  321.     property CPUType: TCPUType read FCPUType {$IFNDEF D6PLUS} write FCPUType {$ENDIF} stored False;
  322.     property FamilyType :TCPUFamily read FCPUFamily {$IFNDEF D6PLUS} write FCPUFamily {$ENDIF} stored false;
  323.     property Architecture: TCPUArchitecture read FArch {$IFNDEF D6PLUS} write FArch {$ENDIF} stored False;
  324.   end;
  325.  
  326. function ExecuteCPUID: TCPUIDResult; assembler;
  327. function GetCPUVendor: DWORD;
  328.  
  329. var
  330.   CPUID_Level: DWORD;
  331.  
  332. const
  333.   CPUVendorsEx :array[VENDOR_INTEL..VENDOR_NSC] of string =
  334.                       ('Intel Corporation',
  335.                        'Advanced Micro Devices',
  336.                        'Cyrix Corporation',
  337.                        'IDT/Centaur/VIA',
  338.                        'NexGen Inc.',
  339.                        'United Microelectronics Corp',
  340.                        'Rise Technology',
  341.                                        'Transmeta',
  342.                                        'SiS',
  343.                                        'National Semiconductor');
  344.  
  345.   CPUVendors :array[VENDOR_INTEL..VENDOR_NSC] of string =
  346.                       ('Intel',
  347.                        'AMD',
  348.                        'Cyrix',
  349.                        'IDT',
  350.                        'NexGen',
  351.                        'UMC',
  352.                        'Rise',
  353.                                        'Transmeta',
  354.                                        'SiS',
  355.                                        'NSC');
  356.  
  357.   CPUTypes: array[TCPUType] of string = ('Primary','OverDrive', 'Secondary', 'Unknown');
  358.  
  359. function GetCPUSpeed_M1: TFreqInfo;
  360. function GetCPUSpeed_M2(ADelay: DWORD): Single;
  361. function GetCPUSpeed_M3: Double;
  362. function RoundFrequency(const Frequency: Integer): Integer;
  363.  
  364. implementation
  365.  
  366.