获得Intel CPU的信息<br>下面这个函数会返回一个字符串列表及特性集合,这个函数只对Intel 486及以上的CPU有效。其他CPU将返回[cpuNonIntel] 或 [cpuNoCPUID].<br><br>用法:<br><br>GetCpuFeatures(memo1.Lines);<br><br>支持的特性<br>---------------------------------------<br>CPU Family 6<br>CPU Model 7<br>CPU Stepping 3<br>On-Chip FPU<br>VirtualMode Extensions<br>Debugging Extensions<br>Page Size Extensions<br>Time Stamp Counter<br>Model Specific Registers<br>Physical Address Extensions<br>Machine Check Extensions<br>CMPXCHG8B Instruction<br>Fast System Call<br>Memory Type Range Registers<br>Page Global Enable<br>Machine Check Architecture<br>Conditional Move Instruction<br>Page Attribute Table<br>32 Bit Page Size Extension<br>Intel MMX Technology<br>Fast Floating Point Save and Restore<br>Streaming SIMD Extensions<br><br>unit Unit2;<br>interface<br>uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms;<br><br>type<br> TForm2 = class(TForm)<br> private<br> { Private declarations }<br> public<br> { Public declarations } end;<br><br> TCpuFeature = (cpuNoCPUID,cpuNonIntel,cpuOnChipFPU,<br> cpuVirtualModeExtensions,cpuDebuggingExtensions,<br> cpuPageSizeExtensions,cpuTimeStampCounter,<br> cpuModelSpecificRegisters,cpuPhysicalAddressExtensions,<br> cpuMachineCheckExtensions,cpuCMPXCHG8B,cpuOnChipAPIC,<br> cpuFastSystemCall,cpuMemoryRangeRegisters,cpuPageGlobalEnable,<br> cpuMachineCheckArchitecture,cpuConditionalMoveInstruction,<br> cpuPageAttributeTable,cpu32bitPageSzExtension,<br> cpuProcessorSerialNum,cpuMMXTechnology,cpuFastFloatingPoint,<br> cpuSIMDExtensions);<br><br> TCpuFeatures = set of TCpuFeature;<br><br> function GetCpuFeatures(FeatureList : TStrings = nil) : TCpuFeatures;<br><br>var Form2: TForm2;<br>implementation<br>{$R *.DFM}<br><br>function GetCpuFeatures(FeatureList : TStrings = nil) : TCpuFeatures;<br>const<br> FPU_FLAG = $0001;<br> VME_FLAG = $0002;<br> DE_FLAG = $0004;<br> PSE_FLAG = $0008;<br> TSC_FLAG = $0010;<br> MSR_FLAG = $0020;<br> PAE_FLAG = $0040;<br> MCE_FLAG = $0080;<br> CX8_FLAG = $0100;<br> APIC_FLAG = $0200;<br> SEP_FLAG = $0800;<br> MTRR_FLAG = $1000;<br> PGE_FLAG = $2000;<br> MCA_FLAG = $4000;<br> CMOV_FLAG = $8000;<br> PAT_FLAG = $10000;<br> PSE36_FLAG = $20000;<br> PSNUM_FLAG = $40000;<br> MMX_FLAG = $800000;<br> FXSR_FLAG = $1000000;<br> SIMD_FLAG = $2000000;<br><br>var IsIntel : boolean;<br> VendorID : array [0..12] of char;<br> IntelID : array [0..12] of char;<br> FeaturesFlag,CpuSignature : DWord;<br> Temp : DWord;<br> RetVar : TCpuFeatures;<br> CpuType : byte;<br><br> procedure CheckFeature(FeatureFlag : DWord;<br> const Item : string;<br> cpuFeatureType : TCpuFeature);<br> begin<br> if FeaturesFlag and FeatureFlag = FeatureFlag then begin<br> if FeatureList <> nil then FeatureList.Add(Item);<br> include(RetVar,cpuFeatureType);<br> end;<br> end;<br><br>begin<br> RetVar := [];<br> if FeatureList <> nil then FeatureList.Clear;<br> IsIntel := false;<br> IntelId := 'GenuineIntel'#0;<br> VendorID := '------------'#0;<br><br> try<br> asm<br><br> //确认是否支持Intel CPUID调用<br> push ebx<br> push esi<br> push edi<br> mov eax,0 // Set up for CPUID instruction<br> db 00fh // CPUID - Get Vendor and check INTEL<br> db 0a2h<br> mov dword ptr VendorId,ebx<br> mov dword ptr VendorId[+4],edx<br> mov dword ptr VendorId[+8],ecx<br> cmp dword ptr IntelId,ebx //检查是否是Intel CPU<br> jne @@EndCPUID<br> cmp dword ptr IntelId[+4],edx<br> jne @@EndCPUID<br> cmp dword ptr IntelId[+8],ecx<br> jne @@EndCPUID // 非Intel CPU<br><br> mov byte ptr IsIntel,1 // Set IsIntel to true<br> cmp eax,1 // Ensure 1 is valid input for CPUID<br> jl @@EndCPUID // Else jump to end<br><br> mov eax,1<br> db 00fh // CPUID - Get features,family etc.<br> db 0a2h<br> mov CpuSignature,eax<br> mov FeaturesFlag,edx<br> shr eax,8 // Isolate family<br> and eax,0fh<br> mov byte ptr CpuType,al // Set cputype with family<br><br> @@EndCPUID :<br><br> pop edi // 恢复寄存器<br> pop esi<br> pop ebx<br> end;<br><br> // 检查特性掩码<br> if IsIntel then begin<br> if FeatureList <> nil then begin<br> FeatureList.Add('CPU Family ' + IntToStr(CpuType));<br> Temp := (CpuSignature shr 4) and $0f;<br> FeatureList.Add('CPU Model ' + IntToStr(Temp));<br> Temp := CpuSignature and $0f;<br> FeatureList.Add('CPU Stepping ' + IntToStr(Temp));<br> end;<br><br> CheckFeature(FPU_FLAG,'On-Chip FPU',cpuOnChipFPU);<br> CheckFeature(VME_FLAG,<br> 'VirtualMode Extensions',cpuVirtualModeExtensions);<br> CheckFeature(DE_FLAG,'Debugging Extensions',cpuDebuggingExtensions);<br> CheckFeature(PSE_FLAG,'Page Size Extensions',cpuPageSizeExtensions);<br> CheckFeature(TSC_FLAG,'Time Stamp Counter',cpuTimeStampCounter);<br> CheckFeature(MSR_FLAG,<br> 'Model Specific Registers',cpuModelSpecificRegisters);<br> CheckFeature(PAE_FLAG,<br> 'Physical Address Extensions',<br> cpuPhysicalAddressExtensions);<br> CheckFeature(MCE_FLAG,<br> 'Machine Check Extensions',cpuMachineCheckExtensions);<br> CheckFeature(CX8_FLAG,'CMPXCHG8B Instruction',cpuCMPXCHG8B);<br> CheckFeature(APIC_FLAG,'On Chip APIC',cpuOnChipAPIC);<br> CheckFeature(SEP_FLAG,'Fast System Call',cpuFastSystemCall);<br> CheckFeature(MTRR_FLAG,<br> 'Memory Type Range Registers',cpuMemoryRangeRegisters);<br> CheckFeature(PGE_FLAG,'Page Global Enable',cpuPageGlobalEnable);<br> CheckFeature(MCA_FLAG,<br> 'Machine Check Architecture',cpuMachineCheckArchitecture);<br> CheckFeature(CMOV_FLAG,<br> 'Conditional Move Instruction',<br> cpuConditionalMoveInstruction);<br> CheckFeature(PAT_FLAG,'Page Attribute Table',cpuPageAttributeTable);<br> CheckFeature(PSE36_FLAG,<br> '32 Bit Page Size Extension',cpu32BitPageSzExtension);<br> CheckFeature(PSNUM_FLAG,<br> 'Processor Serial Number',cpuProcessorSerialNum);<br> CheckFeature(MMX_FLAG,'Intel MMX Technology',cpuMMXTechnology);<br> CheckFeature(FXSR_FLAG,<br> 'Fast Floating Point Save and Restore',<br> cpuFastFloatingPoint);<br> CheckFeature(SIMD_FLAG,'Streaming SIMD Extensions',cpuSIMDExtensions);<br> end<br> else begin<br> if FeatureList <> nil then<br> FeatureList.Add('Non-Intel or >486 Chip - Features Unknown');<br> include(RetVar,cpuNonIntel);<br> end;<br> except<br> if FeatureList <> nil then FeatureList.Add('No CPUID Support');<br> include(RetVar,cpuNoCPUID);<br> end;<br><br> Result := RetVar;<br>end;<br><br>end.<br><br>