给定一个CPU型号,如何生成对应的cpuidearly启动失败指令?注意不是获取是生成 !

CPUID 指令的使用
CPUID 指令的使用
使用 CPUID 指令可以从 processor 厂商里获得关于 processor 的详细信息,CPUID 指令是从 Intel 486 处理器以后开始加入支持。
1. 检测处理器是否支持 cpuid 指令
现在的处理器都支持 cpuid 指令,确实没必要去检测是否支持,除非在古老的机器上运行才有必要。
当然,这里只是作为一个知识点介绍,在 eflags.ID 标志位是 Processor Feature Identification 位,通过修改这个标志位的值,以此来检测是否支持 cpuid 指令。
;-------------------------------------------------------; test cpuid enable;-------------------------------------------------------&&&&&&& pushfd&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ; save eflags&&&&&&& mov eax, dword [esp]&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ; get old eflags&&&&&&& xor dword [esp], 0x200000&&&&&&&&&&&&&&&&&&&&&&&& ; xor the eflags.ID value&&&&&&& popfd&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ; restore new eflags&&&&&&& pushfd&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ; save eflags again&&&&&&& pop ebx&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ; get new eflags&&&&&&& cmp eax, ebx&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ; test eflags.ID is modify&&&&&&& jne support&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ; OK! support CPUID instruction
no_support:
&&&&&&& lea si, [failure_msg]&&&&&&& mov ah, 0x0e&&&&&&& xor bh, bh&&&&&&& call printmsg
&&&&&&& jmp $
support:&&&&&&& ... ...
上面这个代码能成功地修改 eflags.ID 标志位,说明 cpu 是支持 cpuid 指令的。
2. cpuid 的使用方法
cpuid 指令由 eax 寄存器获得输入,执行 cpuid 指令前,将功能号传给 eax 寄存器:
所获得的 cpu 信息返回到 eax,ebx,ecx 以及 edx 寄存器,每一个功能所得到的信息格式是不一样的。
mov eax, 0&&&&&&&&&&&&&&&&&& ; function 0cpuid
上面代码中,将功能号 0 来获取信息,那么它将返回值是:
eax:最大的基本功能号
ebx:&Genu&
edx: &ineI&
ecx:&ntel&
这几个字符串组合起来就是 &GenuineIntel& 对于 AMD 的处理器来说,它返回的字符串是:"AuthenticAMD"
下面代码用来测试 CPU 的厂商是 intel 还是 amd
&&&&&&& mov eax, 0&&&&&&& cpuid&&&&&&& test_intel:&&&&&&& cmp ecx, 0x6c65746e&&&&&&& jnz test_amd&&&&&&& cmp edx, 0x49656e69&&&&&&& jnz test_amd&&&&&&& cmp ebx, 0x756e6547&&&&&&& jnz test_amd&&&&&&& lea si, [vendor_intel]&&&&&&& call printmsg&&&&&&& jz next_do
test_amd:&&&&&&& cmp ecx, 0x444d4163&&&&&&& &&&&&&& jnz test_other&&&&&&& cmp edx, 0x69746e65&&&&&&& jnz test_other&&&&&&& cmp ebx, 0x&&&&&&& jnz test_other&&&&&&& lea si, [vendor_amd]&&&&&&& call printmsg&&&&&&& jz next_do
test_other:&&&&&&& lea si, [vendor_other]&&&&&&& call printmsg
简单地通过直接比较 ebx, ecx 和 edx 的值来确定。
3. 获得最大功能号
cpuid 返回的信号包括:
每种信息都有 CPU 所支持的最大功能号,扩展功能号以 0x 开头
&&&&&&& mov eax, 0&&&&&&&&&&&&&&&&&&&&&&&&& ; get largest basic function input&&&&&&& cpuid
&&&&&&& mov eax, 0x&&&&&&&&&&&&&&&& ; get largest extended function input&&&&&&& cpuid
eax 寄存器返回的是 CPU 所支持的最大功能号,得到扩展最大功能号以 0x 作为输入。
4. 得到 CPU 的基本功能信息
使用基本功能号 1 可以获得 CPU 的基本功能信息:
eax 返回 CPU 的家族型号等
ecx 和 edx 返回 CPU 的功能信息
&&&&&&& mov eax, 1&&&&&&& cpuid&&&&&&& mov esi, ecx&&&&&&& mov ebx, ecx_feature_function_table&&&&&&& call print_msg
;--------------------------------; input:;&&&&&&& esi: feature information;&&&&&&& ebx: function table;--------------------------------
print_msg:&&&&&&& xor eax, eax
print_msg_loop:&&&&&&& &&&&&&& cmp eax, 31&&&&&&& jg print_msg_done&&&&&&& &&&&&&& lea edi, [ebx+eax*4]&&&&&&& cmp dword [edi], 0&&&&&&& jnz do_print_msg&&&&&&& inc eax&&&&&&& jmp print_msg_next&&&&&&& do_print_msg:&&&&&&& mov edi, [edi]&&&&&&& call puts&&&&&&& &&&&&&& bt esi, eax&&&&&&& jc print_yes&&&&&&& mov edi, no&&&&&&& call puts&&&&&&& jmp print_msg_next&&&&&&& print_yes:&&&&&&& &&&&&&& mov edi, yes&&&&&&& call puts
print_msg_next:&&&&&&& &&&&&&& inc eax&&&&&&& jmp print_msg_loop&&&&&&& print_msg_done:&&&&&&& &&&&&&& ret
yes&&&&&&&&&&&&&&& db 'yes', 10, 0no&&&&&&&&&&&&&&& db 'no', 10, 0&&&&&&&
ecx_msg:B0&&&&&&&&&&&&&&& db 'SSE3 Extension:&&&&&&&&&&&&&&&&&&&&& ',& 0B1&&&&&&&&&&&&&&& db 'Carryless Multiplication:&&&&&&&&&&& ',& 0B2&&&&&&&&&&&&&&& db '64-bit DS Area:&&&&&&&&&&&&&&&&&&&&& ',& 0B3&&&&&&&&&&&&&&& db 'MONITOR/MWAIT:&&&&&&&&&&&&&&&&&&&&&& ',& 0B4&&&&&&&&&&&&&&& db 'CPL Qualified Debug Store:&&&&&&&&&& ',& 0B5&&&&&&&&&&&&&&& db 'Virtual Machine Extensions:&&&&&&&&& ',& 0B6&&&&&&&&&&&&&&& db 'SaferMode Extensions:&&&&&&&&&&&&&&& ',& 0B7&&&&&&&&&&&&&&& db 'Enhanced Intel SpeedStep Technology: ',& 0B8&&&&&&&&&&&&&&& db 'Thermal Monitor 2:&&&&&&&&&&&&&&&&&& ',& 0B9&&&&&&&&&&&&&&& db 'SSSE3 Extensions:&&&&&&&&&&&&&&&&&&& ',& 0B10&&&&&&&&&&&&&&& db 'L1 Context ID:&&&&&&&&&&&&&&&&&&&&&& ',& 0B12&&&&&&&&&&&&&&& db 'Fused Multiply Add:&&&&&&&&&&&&&&&&& ',& 0B13&&&&&&&&&&&&&&& db 'CMPXCHG16B:&&&&&&&&&&&&&&&&&&&&&&&&& ',& 0B14&&&&&&&&&&&&&&& db 'Update Control:&&&&&&&&&&&&&&&&&&&&& ',& 0B15&&&&&&&&&&&&&&& db 'Perf/Debug Capability MSR:&&&&&&&&&& ',& 0B17&&&&&&&&&&&&&&& db 'Process-context Identifiers:&&&&&&&& ',& 0B18&&&&&&&&&&&&&&& db 'Direct Cache Access:&&&&&&&&&&&&&&&& ',& 0B19&&&&&&&&&&&&&&& db 'SSE4.1:&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ',& 0B20&&&&&&&&&&&&&&& db 'SSE4.2:&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ',& 0B21&&&&&&&&&&&&&&& db 'x2APIC:&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ',& 0B22&&&&&&&&&&&&&&& db 'MOVEBE:&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ',& 0B23&&&&&&&&&&&&&&& db 'POPCNT:&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ',& 0B24&&&&&&&&&&&&&&& db 'TSC-Deadline:&&&&&&&&&&&&&&&&&&&&&&& ',& 0B25&&&&&&&&&&&&&&& db 'AES:&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ',& 0B26&&&&&&&&&&&&&&& db 'XSAVE:&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ',& 0B27&&&&&&&&&&&&&&& db 'OSXSAVE:&&&&&&&&&&&&&&&&&&&&&&&&&&&& ',& 0B28&&&&&&&&&&&&&&& db 'AVX:&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ',& 0
ecx_feature_function_table:&&&&&&& dd B0&&&&&&& dd B1&&&&&&& dd B2&&&&&&& dd B3&&&&&&& dd B4&&&&&&& dd B5&&&&&&& dd B6&&&&&&& dd B7&&&&&&& dd B8&&&&&&& dd B9&&&&&&& dd B10&&&&&&& dd 0&&&&&&&&&&&&&&&&&&&&&&& ; reserved&&&&&&& dd B12&&&&&&& dd B13&&&&&&& dd B14&&&&&&& dd B15&&&&&&& dd 0&&&&&&&&&&&&&&&&&&&&&&& ; reserved&&&&&&& dd B17&&&&&&& dd B18&&&&&&& dd B19&&&&&&& dd B20&&&&&&& dd B21&&&&&&& dd B22&&&&&&& dd B23&&&&&&& dd B24&&&&&&& dd B25&&&&&&& dd B26&&&&&&& dd B27&&&&&&& dd B28&&&&&&& dd 0&&&&&&&&&&&&&&&&&&&&&&& ; reserved&&&&&&& dd 0&&&&&&&&&&&&&&&&&&&&&&& ; reserved&&&&&&& dd 0&&&&&&&&&&&&&&&&&&&&&&& ; 0
上面的代码读取 ecx,并显示出它的 feature 信息,下面是在 vmware 上的运行结果:
上面的信息是返回在 ecx 寄存器,返回在 edx 寄存器的信息是:
edx_msg:BIT0&&&&&&& db 'FPU:& ', 0BIT1&&&&&&& db 'VME:& ', 0BIT2&&&&&&& db 'DE:&& ', 0BIT3&&&&&&& db 'PSE:& ', 0BIT4&&&&&&& db 'TSC:& ', 0BIT5&&&&&&& db 'MSR:& ', 0BIT6&&&&&&& db 'PAE:& ', 0BIT7&&&&&&& db 'MCE:& ', 0BIT8&&&&&&& db 'CMPXCHG8B: ', 0BIT9&&&&&&& db 'APIC: ', 0BIT11&&&&&&& db 'SYSENTER/SYSEXIT:', 0BIT12&&&&&&& db 'MTRR: ', 0BIT13&&&&&&& db 'PGE:& ', 0BIT14&&&&&&& db 'MCA:& ', 0BIT15&&&&&&& db 'CMOV: ', 0BIT16&&&&&&& db 'PAT:& ', 0BIT17&&&&&&& db 'PSE36:', 0BIT18&&&&&&& db 'PNS:& ', 0BIT19&&&&&&& db 'CLFSH:', 0BIT21&&&&&&& db 'Debug Store:', 0BIT22&&&&&&& db 'ACPI: ', 0BIT23&&&&&&& db 'MMX:& ', 0BIT24&&&&&&& db 'FXSR: ', 0BIT25&&&&&&& db 'SSE:& ', 0BIT26&&&&&&&& db 'SSE2: ', 0BIT27&&&&&&& db 'Self snoop:', 0BIT28&&&&&&& db 'HTT:& ', 0BIT29&&&&&&& db 'TM:&& ', 0BIT31&&&&&&& db 'PBE:& ', 0
edx_feature_function_table:&&&&&&& dd BIT0&&&&&&& dd BIT1&&&&&&& dd BIT2&&&&&&& dd BIT3&&&&&&& dd BIT4&&&&&&& dd BIT5&&&&&&& dd BIT6&&&&&&& dd BIT7&&&&&&& dd BIT8&&&&&&& dd BIT9&&&&&&& dd 0&&&&&&&&&&& ; reserved&&&&&&& dd BIT11&&&&&&& dd BIT12&&&&&&& dd BIT13&&&&&&& dd BIT14&&&&&&& dd BIT15&&&&&&& dd BIT16&&&&&&& dd BIT17&&&&&&& dd BIT18&&&&&&& dd BIT19&&&&&&& dd 0&&&&&&&&&& ; reserved&&&&&&& dd BIT21&&&&&&& dd BIT22&&&&&&& dd BIT23&&&&&&& dd BIT24&&&&&&& dd BIT25&&&&&&& dd BIT26&&&&&&& dd BIT27&&&&&&& dd BIT28&&&&&&& dd BIT29&&&&&&& dd 0&&&&&&&&&& ; reserved&&&&&&& dd BIT31
运行结果如下:
版权所有 mik&& cpuid指令
cpuid就是一条读取CPU各种信息的一条指令,大概是从80486的某个版本开始就存在了。
CPUID这条指令,除了用于识别CPU(CPU的型号、家族、类型等),还可以读出CPU支持的功能(比如是否支持MMX,是否支持4MB的页等等),内容的确是十分丰富。CPUID指令有两组功能,一组返回的是基本信息,另一组返回的是扩展信息。
1、如何判断CPU是否支持CPUID指令&&&
前面说过,大概是从80486开始才有的cpuid这个指令,是不是所有的80486家族CPU都有这个指令我也不是很清楚,但在EFLAGS中的bit
21可以识别CPU是否支持CPUID指令,如下图:
在CPU中,FLAGS只有16位长,在80386CPU中,bit
21被保留未用,在支持CPUID指令的CPU中,这一位将为1。
2、CPUID指令的执行方法&&&
把功能代码放在EAX寄存器中,执行CPUID指令即可。例如:
&&& mov eax,
前面说过CPUID指令分为两组,一组返回基本信息,一组返回扩展信息,当执行返回基本信息的CPUID指令时,EAX中功能代码的bit
31为0,当执行返回扩展信息的CPUID指令时,EAX中的功能代码的bit
31为1。那么不管是那组功能,如何知道EAX中的功能代码最大可以是多少呢?根据Intel的说明,可以用如下方法:
&&& mov eax,
执行完CPUID指令后,EAX中返回的值就是返回基本信息时,功能代码的最大值,在执行CPUID指令要求返回基本信息时,EAX中的值必须小于或等于该值。
&&& mov eax,
执行完CPUID指令后,EAX中返回的值就是返回扩展信息时,功能代码的最大值,在执行CPUID指令要求返回扩展信息时,EAX中的值必须小于或等于该值。
由于很多编译器都不能编译CPUID指令,所以了解CPUID指令的操作码是必要的,CPUID指令的操作码是:
3、返回基本信息的功能全貌&&&
在实际介绍每一个功能之前,我们先通过一张图了解一下返回基本信息的功能全貌。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
4、EAX=0:获取CPU的Vendor
Vendor ID这个东西,在以前介绍PCI的文章中应该介绍过,实际上就是制造商的标识,用下面的方法执行该功能:
&&& mov eax,
执行CPUID指令后,AX中返回的内容前面已经说过了,返回的Vendor
ID固定为12个ASCII字符依次存放在EBX、EDX、ECX中,对于Intel的CPU,返回的字符串永远是:GenuineIntel。对应在三个寄存器中的值如下:
EBX=756E6547h,EDX=49656E69h,ECX=6C65746Eh
大家可以参考图2。
尽管本文是介绍Intel的CPUID指令,但下面还是尽我所知,列出其它厂家生产的IA-32架构CPU的Vendor
ID,希望能对需要这些资料的人有所帮助。
AMDisbetter! ---- 早期AMD K5芯片的工程样品芯片
AuthenticAMD ---- AMD
CentourHauls ---- Centour
CyrixInstead ---- Cyrix
GenuineTMx86 或 TransmetaCPU ---- Transmeta
Geode by NSC ---- National Semiconductor
NexGenDriven ---- NexGen
SiS SiS SiS& ---- SiS
RiseRiseRise ---- Rise
UMC UMC UMC& ---- UMC
VIA VIA VIA& ---- VIA
5、EAX=1:处理器签名(Processor
Signiture)和功能(Feature)位&&&
mov eax, 1
执行完成后,处理器签名放在EAX中,功能位及其它杂七杂八的内容分别放在EBX、ECX和EDX中。
处理器签名(Processor
Signiture):
返回在EAX中,定义如下:
图中的灰色区域表示没有定义。前面说过,当CPU复位时,会在EDX中返回处理器签名,从80486以后,这个签名和上面的定义完全一样,只是放在不同的寄存器中而已。前面还提到过,80386在复位时也返回处理器签名,但80386返回的签名格式是和上面不同的,后面可能会提到。
通过处理器签名,可以确定CPU的具体型号,以下是部分Intel
CPU的处理器签名数据(资料来自Intel):
前面说过,80386尽管没有CPUID指令,但在复位时也是可以返回处理器签名的,下面是80386返回的处理器签名的格式:
下面是80386处理器签名的识别方法(资料来自Intel):
关于Stepping的说明:&&&
Intel和AMD都有Stepping的概念,用来标识一款同样规模的微处理器从一开始到你用的这款处理器经历的设计过程,用一个字母和一个数字表示。一般来说,一款同样规模的微处理器的第一个版本是A0,如果改进了设计,则可以通过改变字母或者数字进行标识,如果仅仅改变数字(比如改成A3),说明进行了一些辅助的改进,如果字母和数字都改变,说明改动较大,Stepping可以使用户可以识别微处理器的版本。下面是一个Stepping的例子。
当处理器签名一样时的处理
有时候,从处理器签名上仍然不能识别CPU,比如根据Intel提供的资料,Pentium II, Model 5、Pentium II
Xeon, Model 5和Celeron&, Model
5的处理器签名完全一样,要区别他们只能通过检查他们的高速缓存(Cache)的大小,后面将介绍使用CPUID指令获得CPU高速缓存信息的方法,如果没有高速缓存,则是Celeron&处理器;如果L2高速缓存为1MB或者2MB,则应该是Pentium
II Xeon处理器,其它情况则应该是Pentium II处理器或者是只有512KB高速缓存的Pentium II
Xeon处理器。
有些情况下,如果从处理器签名上不能区分CPU,也可以使用Brand ID(在EBX的bit7:0返回)来区分CPU,比如Pentium
III, Model 8、Pentium III Xeon, Model 8和Celeron&, Model
8三种处理器的处理器签名也是一样的,但它们的Brand ID是不同的。
关于处理器类型的定义
在处理器签名中的bit12:13返回的是处理器类型,其定义如下
Descriptor
---------------------------------------------
以前的OEM处理器
OverDrive&处理器
多处理器(指可用于多处理器系统)
&功能标志(Feature Flag)
在EDX和ECX中返回的功能标志表明着该CPU都支持那些功能
EDX定义如下(资料来源与Intel):
bit& Name& Description
--------------------------------------------------------------------------------
00& FPU&& FPU
Virtual Mode Extended
DE&&& Debugging
03& PSE&& Page
Size Extension
04& TSC&& Time
Stamp Counter
05& MSR&& Model
Specific Registers
Physical Address Extension
Machine-Check Exception
CMPXCHG8 Instruction
09& APIC& On-chip APIC
11& SEP&& Fast
System Call
12& MTRR& Memory Type Range
13& PGE&& Page
Global Enable
Machine-Check Architecture
15& CMOV& Conditional Move
Instruction
16& PAT&& Page
Attribute Table
17& PSE-36 36-bit Page Size Extension
Processor serial number is present and enabled
19& CLFSH CLFLUSH Instruction
DS&&& Debug
22& ACPI& Thermal Monitor and
Software Controlled Clock Facilities
23& MMX&& MMX
technology
24& FXSR& FXSAVE and FXSTOR
Instructions
Streaming SIMD Extensions
26& SSE2& Streaming SIMD
Extensions 2
Self-Snoop
Multi-Threading
TM&&& Thermal
30& IA64& IA64 Capabilities
Pending Break Enable
ECX定义如下(资料来自Intel):
Description
---------------------------------------------------------
Streaming SIMD Extensions 3
01&&&&&&&&&&&
DTES64&& 64-Bit Debug Store
03&& MONITOR&
MONITOR/MWAIT
DS-CPL&& CPL Qualified Debug
Virtual Machine Extensions
Safer Mode Extensions
Enhanced Intel SpeedStep& Technology
Thermal Monitor 2
Supplemental Streaming SIMD Extensions 3
10&& CNXT-ID& L1
Context ID
12:11&&&&&&&&&&
CMPXCHG16B
xTPR Update Control
Perfmon and Debug Capability
17:16&&&&&&&&&&
Direct Cache Access
SSE4.1&& Streaming SIMD
Extensions 4.1
SSE4.2&& Streaming SIMD
Extensions 4.2
x2APIC&& Extended xAPIC
MOVBE&&& MOVBE
Instruction
POPCNT&& POPCNT Instruction
25:24&&&&&&&&&&
XSAVE/XSTOR States
27&& OSXSAVE
31:28&&&&&&&&&&
下面是在DEBUG中当EAX=0时执行CPUID指令时的情况:
下面是在DEBUG中当EAX=1时执行CPUID指令时的情况
6、EAX=2:高速缓存描述符(Cache
Descriptor)
&&& mov eax,
执行完CPUID指令后,高速缓存描述符和TLB(Translation Lookable
Buffer)特性将在EAX、EBX、ECX和EDX中返回,每个寄存器中的4个字节分别表示4个描述符,描述符中不同的值表示不同的含义(后面有定义),其中EAX中的最低8位(AL)的值表示要得到完整的高速缓存的信息,需要执行EAX=2的CPUID指令的次数(一般都为1,在我这里的数台机器里,还没有为2的),同时,寄存器的最高位(bit
31)为0,表示该寄存器中的描述符是有效的,下面是描述符值的定义(资料来源与Intel):
Value&& Cache or TLB Descriptor
Description
----------------------------------------------------------------------------------------
Instruction TLB: 4-KB Pages, 4-way set associative, 32
Instruction TLB: 4-MB Pages, fully associative, 2 entries
03h&&& Data TLB:
4-KB Pages, 4-way set associative, 64 entries
04h&&& Data TLB:
4-MB Pages, 4-way set associative, 8 entries
05h&&& Data TLB:
4-MB Pages, 4-way set associative, 32 entries
06h&& 1st-level instruction
cache: 8-KB, 4-way set associative, 32-byte line size
08h&& 1st-level instruction
cache: 16-KB, 4-way set associative, 32-byte line size
09h&& 1st-level Instruction
Cache: 32-KB, 4-way set associative, 64-byte line size
0Ah&& 1st-level data cache: 8-KB,
2-way set associative, 32-byte line size
0Ch&& 1st-level data cache:
16-KB, 4-way set associative, 32-byte line size
0Dh&& 1st-level Data Cache:
16-KB, 4-way set associative, 64-byte line size, ECC
21h&& 256-KB L2 (MLC), 8-way set
associative, 64-byte line size
22h&& 3rd-level cache: 512-KB,
4-way set associative, sectored cache, 64-byte line size
23h&& 3rd-level cache: 1-MB,
8-way set associative, sectored cache, 64-byte line size
25h&& 3rd-level cache: 2-MB,
8-way set associative, sectored cache, 64-byte line size
29h&& 3rd-level cache: 4-MB,
8-way set associative, sectored cache, 64-byte line size
2Ch&& 1st-level data cache:
32-KB, 8-way set associative, 64-byte line size
30h&& 1st-level instruction
cache: 32-KB, 8-way set associative, 64-byte line size
39h&& 2nd-level cache: 128-KB,
4-way set associative, sectored cache, 64-byte line size
3Ah&& 2nd-level cache: 192-KB,
6-way set associative, sectored cache, 64-byte line size
3Bh&& 2nd-level cache: 128-KB,
2-way set associative, sectored cache, 64-byte line size
3Ch&& 2nd-level cache: 256-KB,
4-way set associative, sectored cache, 64-byte line size
3Dh&& 2nd-level cache: 384-KB,
6-way set associative, sectored cache, 64-byte line size
3Eh&& 2nd-level cache: 512-KB,
4-way set associative, sectored cache, 64-byte line size
40h&& No 2nd-level cache or, if
processor contains a valid 2nd-level cache, no 3rd-level
41h&& 2nd-level cache: 128-KB,
4-way set associative, 32-byte line size
42h&& 2nd-level cache: 256-KB,
4-way set associative, 32-byte line size
43h&& 2nd-level cache: 512-KB,
4-way set associative, 32-byte line size
44h&& 2nd-level cache: 1-MB,
4-way set associative, 32-byte line size
45h&& 2nd-level cache: 2-MB,
4-way set associative, 32-byte line size
46h&& 3rd-level cache: 4-MB,
4-way set associative, 64-byte line size
47h&& 3rd-level cache: 8-MB,
8-way set associative, 64-byte line size
48h&& 2nd-level cache: 3-MB,
12-way set associative, 64-byte line size, unified on-die
49h&& 3rd-level cache: 4-MB,
16-way set associative, 64-byte line size(Intel Xeon
&&&&&&&&&&
processor MP, Family 0Fh, Model 06h) 2nd-level cache: 4-MB, 16-way
set associative,
&&&&&&&&&&
64-byte line size
4Ah&& 3rd-level cache: 6-MB,
12-way set associative, 64-byte line size
4Bh&& 3rd-level cache: 8-MB,
16-way set associative, 64-byte line size
4Ch&& 3rd-level cache: 12-MB,
12-way set associative, 64-byte line size
4Dh&& 3rd-level cache: 16-MB,
16-way set associative, 64-byte line size
4Eh&& 2nd-level cache: 6-MB,
24-way set associative, 64-byte line size
50h&& Instruction TLB: 4-KB, 2-MB
or 4-MB pages, fully associative, 64 entries
51h&& Instruction TLB: 4-KB, 2-MB
or 4-MB pages, fully associative, 128 entries
52h&& Instruction TLB: 4-KB, 2-MB
or 4-MB pages, fully associative, 256 entries
55h&& Instruction TLB: 2-MB or
4-MB pages, fully associative, 7 entries
56h&& L1 Data TLB: 4-MB pages,
4-way set associative, 16 entries
57h&& L1 Data TLB: 4-KB pages,
4-way set associative, 16 entries
5Ah&& Data TLB0: 2-MB or 4-MB
pages, 4-way associative, 32 entries
5Bh&& Data TLB: 4-KB or 4-MB
pages, fully associative, 64 entries
5Ch&& Data TLB: 4-KB or 4-MB
pages, fully associative, 128 entries
5Dh&& Data TLB: 4-KB or 4-MB
pages, fully associative, 256 entries
60h&& 1st-level data cache:
16-KB, 8-way set associative, sectored cache, 64-byte line
66h&& 1st-level data cache: 8-KB,
4-way set associative, sectored cache, 64-byte line size
67h&& 1st-level data cache:
16-KB, 4-way set associative, sectored cache, 64-byte line
68h&& 1st-level data cache:
32-KB, 4 way set associative, sectored cache, 64-byte line
70h&& Trace cache: 12K-uops,
8-way set associative
71h&& Trace cache: 16K-uops,
8-way set associative
72h&& Trace cache: 32K-uops,
8-way set associative
73h&& Trace cache: 64K-uops,
8-way set associative
78h&& 2nd-level cache: 1-MB,
4-way set associative, 64-byte line size
79h&& 2nd-level cache: 128-KB,
8-way set associative, sectored cache, 64-byte line size
7Ah&& 2nd-level cache: 256-KB,
8-way set associative, sectored cache, 64-byte line size
7Bh&& 2nd-level cache: 512-KB,
8-way set associative, sectored cache, 64-byte line size
7Ch&& 2nd-level cache: 1-MB,
8-way set associative, sectored cache, 64-byte line size
7Dh&& 2nd-level cache: 2-MB,
8-way set associative, 64-byte line size
7Fh&& 2nd-level cache: 512-KB,
2-way set associative, 64-byte line size
82h&& 2nd-level cache: 256-KB,
8-way set associative, 32-byte line size
83h&& 2nd-level cache: 512-KB,
8-way set associative, 32-byte line size
84h&& 2nd-level cache: 1-MB,
8-way set associative, 32-byte line size
85h&& 2nd-level cache: 2-MB,
8-way set associative, 32-byte line size
86h&& 2nd-level cache: 512-KB,
4-way set associative, 64-byte line size
87h&& 2nd-level cache: 1-MB,
8-way set associative, 64-byte line size
B0h&& Instruction TLB: 4-KB
Pages, 4-way set associative, 128 entries
B1h&& Instruction TLB: 2-MB
pages, 4-way, 8 entries or 4M pages, 4-way, 4 entries
B2h&& Instruction TLB: 4-KB
pages, 4-way set associative, 64 entries
B3h&& Data TLB: 4-KB Pages, 4-way
set associative, 128 entries
B4h&& Data TLB: 4-KB Pages, 4-way
set associative, 256 entries
CAh&& Shared 2nd-level TLB: 4 KB
pages, 4-way set associative, 512 entries
D0h&& 512KB L3 Cache, 4-way set
associative, 64-byte line size
D1h&& 1-MB L3 Cache, 4-way set
associative, 64-byte line size
D2h&& 2-MB L3 Cache, 4-way set
associative, 64-byte line size
D6h&& 1-MB L3 Cache, 8-way set
associative, 64-byte line size
D7h&& 2-MB L3 Cache, 8-way set
associative, 64-byte line size
D8h&& 4-MB L3 Cache, 8-way set
associative, 64-byte line size
DCh&& 2-MB L3 Cache, 12-way set
associative, 64-byte line size
DDh&& 4-MB L3 Cache, 12-way set
associative, 64-byte line size
DEh&& 8-MB L3 Cache, 12-way set
associative, 64-byte line size
E2h&& 2-MB L3 Cache, 16-way set
associative, 64-byte line size
E3h&& 4-MB L3 Cache, 16-way set
associative, 64-byte line size
E4h&& 8-MB L3 Cache, 16-way set
associative, 64-byte line size
F0h&& 64-byte Prefetching
F1h&& 128-byte Prefetching
举例来说,在我的机器上执行记过如下:
EAX、EBX、ECX和EDX的bit
31均为0,说明其中的描述符均有效,EAX中的低8位(AL)为1,说明执行一次即可,下面是描述符含义:
&&& 05h:Data
TLB: 4-MB Pages, 4-way set associative, 32 entries
B0h:Instruction TLB: 4-KB Pages, 4-way set associative, 128
B1h:Instruction TLB: 2-MB pages, 4-way, 8 entries or 4M pages,
4-way, 4 entries
&&& 56h:L1 Data
TLB: 4-MB pages, 4-way set associative, 16 entries
&&& 57h:L1 Data
TLB: 4-KB pages, 4-way set associative, 16 entries
&&& F0h:64-byte
Prefetching
2Ch:1st-level data cache: 32-KB, 8-way set associative, 64-byte
&&& B4h:Data
TLB: 4-KB Pages, 4-way set associative, 256 entries
30h:1st-level instruction cache: 32-KB, 8-way set associative,
64-byte line size
7Dh:2nd-level cache: 2-MB, 8-way set associative, 64-byte line
7、EAX=3:处理器序列号
&&& 只有Pentium
III提供该功能,486以后的CPU就不再提供该功能,据说是出于隐私的原因。查看你的处理器是否支持处理器序列号功能,可以执行EAX=1的
CPUID指令,然后查看EDX的PSN功能(bit
18),如果为1,说明你的处理器可以返回序列号,否则不支持序列号功能或者是序列号功能被关闭了。
处理器序列号一共96位,最高32位就是处理器签名,通过执行EAX=1的CPUID指令获得,其余的64位在执行EAX=3的CPUID指令后,中间32位在EDX中,最低32位在ECX中。
顺便提一句,AMD所有的CPU都没有提供过处理器序列号的功能。&
CPUID指令的基本信息,其实后面还有好几个,不过我在我这里的机器(大概有7、8台吧),好像都不支持,大多数只支持EAX=0、1、2三个,所以后面的就不介绍了。
8、EAX=h:最大扩展功能号
&&& mov eax,
该功能除了能够向(一)中介绍的那样返回CPU支持的最大扩展功能号外,并没有其它作用,EBX、ECX、EDX都不返回有意义的信息。
9、EAX=h:返回CPU支持的扩展功能&&&
mov eax, h
执行CPUID指令后,扩展功能标志在EDX和ECX中返回,EDX中的定义如下:
Description
-------------------------------------------------------------------
10:00&&&&&&&&&&&&
SYSCALL&& SYSCALL/SYSRET
19:12&&&&&&&&&&&&
Bit Execution Disable Bit
28:21&&&&&&&&&&&&
29&&& Intel& 64
Intel& 64 Instruction Set Architecture
31:30&&&&&&&&&&&&
返回在ECX中的位定义:
Description
-------------------------------------------------------------------
LAHF / SAHF
31:01&&&&&&&&&&&&
10、EAX=h、h、h:返回处理器名称/商标字符串
mov eax, h
&&& ......
&&& mov eax,
&&& ......
&&& mov eax,
每次调用CPUID分别在EAX、EBX、ECX、EDX中返回16个ASCII字符,处理器名称/商标字串最多48个字符,前导字符为空格,结束字符为
NULL,在寄存器中的排列顺序为little-endian(即低字符在前),下面程序可以在DOS下显示处理器名称/商标字串(使用MASM
&&&&&&&&&&&&&&&
.model tiny
&&&&&&&&&&&&&&&
cseg&&&&&&&&&&&
segment para public 'code'
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
assume& cs:cseg, ds:cseg, es:cseg
cpuid&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
not_supported
&&&&&&&&&&&&&&&
di, offset CPU_name
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
save_string
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
save_string
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
save_string
&&&&&&&&&&&&&&&
dx, offset crlf
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
si, offset CPU_name
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
disp_char:
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
not_supported:
&&&&&&&&&&&&&&&
save_string:
&&&&&&&&&&&&&&&
dword ptr [di], eax
&&&&&&&&&&&&&&&
dword ptr [di + 4], ebx
&&&&&&&&&&&&&&&
dword ptr [di + 8], ecx
&&&&&&&&&&&&&&&
dword ptr [di + 12], edx
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
crlf&&&&&&&&&&&
0dh, 0ah, '$'
CPU_name&&&&&&&
cseg&&&&&&&&&&&
&&&&&&&&&&&&&&&
11、EAX=h:备用
12、EAX=h:扩展L2高速缓存功能
&&& mov eax,
执行完CPUID指令后,相应信息在ECX中返回,以下是ECX中返回信息的定义:
Description
-----------------------------------------------------------
31:16&&& L2
Cache size described in 1024-byte units.
15:12&&& L2
Cache Associativity Encodings
&&&&&&&&&&&&&&
00h Disabled
&&&&&&&&&&&&&&
01h Direct mapped
&&&&&&&&&&&&&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&&&
08h 16-Way
&&&&&&&&&&&&&&
0Fh Fully associative
L2 Cache Line Size in bytes.
13、EAX=h:电源管理
&&& mov eax,
执行CPUID指令后,是否支持电源管理功能在EDX的bit8中返回,其余位无意义。
14、EAX=h:虚拟地址和物理地址大小&&&
mov eax, h
执行CPUID指令后,物理地址的大小在EAX的bit[7:0]返回,虚拟地址的大小在EAX的bit[15:8]返回,返回的内容为虚拟(物理)地址的位数。例如在我的机器上的运行结果如下:
表明我的机器支持36位的物理地址和48位的虚拟地址。
&&摘自:&&
在C++中使用:
unsigned int
processor=0;//首个处理器CPU
&unsigned int wCPU_SerialNo_00_31 = 0;
&unsigned int wCPU_SerialNo_32_63 = 0;
&unsigned int wCPU_SerialNo_64_93 = 0;
#define PSN_FLAG (0x1 && 18)
&int errCode = 0;
&int psn_falg = PSN_FLAG;&
&DWORD_PTR dwThreadAffinitiMask = (0x1
&& processor);
&SetThreadAffinityMask(GetCurrentThread(),
dwThreadAffinitiMask);
&&&cmp ebx,
'uneG'&&&&&
//GenuineIntel
wrong_processor
&&&cmp edx,
wrong_processor
&&&cmp ecx,
wrong_processor
&&&// now we
have an Intel-Processor:
&&&// get CPU
feature flag..
wCPU_SerialNo_64_93,eax&&&&&&
//处理器序列号一共96位,最高32位就是处理器签名
edx,PSN_FLAG&&&&&&&&&&&&&&&&&
//18bit:PSN&Processor serial number is present and
edx,PSN_FLAG
psn_not_supported_or_disabled
&&&// get the
wCPU_SerialNo_32_63,edx&&&&&&&&&
//中间32位在EDX中
wCPU_SerialNo_00_31,ecx&&&&&&&&&
//最低32位在ECX中
wrong_processor:
&&mov errCode, 1;
&&jmp _exit_;
psn_not_supported_or_disabled:
&&mov errCode, 2;
&dwThreadAffinitiMask = 0
&SetThreadAffinityMask(GetCurrentThread(),
dwThreadAffinitiMask);
&//errCode=0:有效CPU序列号,1:非Intel;2:不支持或无序列号
&sCPUID.Format(_T("%.8X-%.8X-%.8X"),wCPU_SerialNo_64_93,
wCPU_SerialNo_32_63, wCPU_SerialNo_00_31);
点击查看。
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

我要回帖

更多关于 cpuidearly 的文章

 

随机推荐