CPUID


Free Web Hosting with Website Builder

The CPUID opcode is an instruction (its name derived from CPU IDentification) for the x86 architecture. It was introduced by Intel in the early 1990s for later steppings of the 486 chip, and fully rolled out at the introduction of the Pentium processor.[1]

By using the CPUID opcode, software can determine processor type and the presence of features (like MMX/SSE). The CPUID opcode is 0FA2h and the value in the EAX register specifies what information to return.

Prior to the general availability of the CPUID instruction, programmers would write esoteric machine code which exploited minor differences in CPU behavior in order to determine the processor make and model.[2][3]

Contents

Calling CPUID

In assembly language the CPUID instruction takes no parameters as CPUID implicitly uses the EAX register. The EAX register should be loaded with a value specifying what information to return. CPUID should be called with EAX = 0 first, as this will return the highest calling parameter that the CPU supports. To obtain extended function information CPUID should be called with bit 31 of EAX set. To determine the highest extended function calling parameter, call CPUID with EAX = 80000000h.

EAX=0: Get vendor ID

This returns the CPU's manufacturer ID string - a twelve character ASCII string stored in EBX, EDX, ECX - in that order. The highest basic calling parameter is returned in EAX.

The following are known processor manufacturer ID strings:

For instance, on a GenuineIntel processor values returned in EBX is 0x756e6547, EDX is 0x49656e69 and ECX is 0x6c65746e.

.section	.data
s0:		.string	"Largest Standard Function Number Supported: %i\n"
s1:		.string "Vendor ID: %s\n"
.text
	.global main
 
	.type	main, @function
main:
	pushq	%rbp
	movq	%rsp, %rbp
 
	subl	%eax, %eax
	cpuid
 
	subq	$8, %rsp
	movl	%ebx, (%rsp)
	movl	%edx, 4(%rsp)
	movl	%ecx, 8(%rsp)
	movl	$s0, %edi
	movl	%eax, %esi
	subl	%eax, %eax
	call	printf
 
	movq	$s1, %rdi
	movq	%rsp, %rsi
	subl	%eax, %eax
	call	printf
 
	subl	%eax, %eax
	movq	%rbp, %rsp
	popq	%rbp
	ret

EAX=1: Processor Info and Feature Bits

This returns the CPU's stepping, model, and family information in EAX (also called the signature of a CPU), feature flags in EDX and ECX, and additional feature info in EBX.

The format of the information in EAX is as follows:

  • 3:0 - Stepping
  • 7:4 - Model
  • 11:8 - Family
  • 13:12 - Processor Type
  • 19:16 - Extended Model
  • 27:20 - Extended Family

Intel and AMD have suggested applications to display the family of a CPU as the sum of the "Family" and the "Extended Family" fields shown above, and the model as the sum of the "Model" and the 4-bit left-shifted "Extended Model" fields shown above.

The processor info and feature flags are manufacturer specific but usually the Intel values are used by other manufacturers for the sake of compatibility.

EAX=2: Cache and TLB Descriptor Info

This returns a list of descriptors indicating cache and TLB capabilities in EAX, EBX, ECX and EDX registers.

EAX=3: Processor Serial Number

This returns the processor's serial number. The processor serial number was introduced on Intel Pentium III, but due to privacy concern, this feature is no longer implemented on later models (PSN feature bit is always cleared). Transmeta's Efficeon and Crusoe processors also provide this feature. AMD CPUs however, do not implement this feature in any CPU models.

For Intel Pentium III CPUs, the serial number is returned in EDX:ECX registers. For Transmeta Efficeon CPUs, it is returned in EBX:EAX registers. And for Transmeta Crusoe CPUs, it is returned in EBX register only.

Note that the processor serial number feature must be enabled in the BIOS setting in order to function.

.section	.data
s0:		.string "Processor serial number: %.4hX-%.4hX-%.4hX-%.4hX-%.4hX-%.4hX\n"
.text
	.global main
 
	.type	main, @function
main:
	pushq	%rbp
	movq	%rsp, %rbp
 
	movl	$1, %eax
	cpuid
 
	subq	$4, %rsp
	movl	%eax, (%rsp)
	movq	2(%rsp), %rbx
	movw	%bx, (%rsp)
	movw	%ax, 2(%rsp)
 
	movl	$3, %eax
	cpuid
 
	movl	%edx, 4(%rsp)
	movq	6(%rsp), %rax
	movw	%ax, 4(%rsp)
	movw	%dx, 6(%rsp)
	movl	%ecx, 8(%rsp)
 
	movl	$s0, %edi
	movw	(%rsp), %si
	movw	2(%rsp), %dx
	movw	4(%rsp), %cx
	movw	6(%rsp), %r8w
	movw	8(%rsp), %r8w
	movw	10(%rsp), %r9w
	movw	%r9w, (%rsp)
	subl	%eax, %eax
	call	printf
 
	subl    %eax, %eax
	movq	%rbp, %rsp
	popq	%rbp
	ret

EAX=80000000h: Get Highest Extended Function Supported

The highest calling parameter is returned in EAX.

EAX=80000001h: Extended Processor Info and Feature Bits

This returns extended feature flags in EDX and ECX.

EAX=80000002h,80000003h,80000004h: Processor Brand String

These return the processor brand string in EAX, EBX, ECX and EDX. CPUID must be issued with each parameter in sequence to get the entire 48-byte null-terminated ASCII processor brand string.

.section	.data
s0:		.string	"Processor Brand String: %s\n"
.text
	.global main
 
	.type	main, @function
main:
	pushq	%rbp
	movq	%rsp, %rbp
 
	subq	$44, %rsp
	movl	$0x80000002, %eax
	cpuid
 
	movl	%eax, (%rsp)
	movl	%ebx, 4(%rsp)
	movl	%ecx, 8(%rsp)
	movl	%edx, 12(%rsp)
	addq	$16, %rsp
 
	movl	$0x80000003, %eax
	cpuid
 
	movl	%eax, (%rsp)
	movl	%ebx, 4(%rsp)
	movl	%ecx, 8(%rsp)
	movl	%edx, 12(%rsp)
	addq	$16, %rsp
 
	movl	$0x80000004, %eax
	cpuid
 
	movl	%eax, (%rsp)
	movl	%ebx, 4(%rsp)
	movl	%ecx, 8(%rsp)
	movl	%edx, 12(%rsp)
	subq	$32, %rsp
 
	movl	$s0, %edi
	movq	%rsp, %rsi
	subl	%eax, %eax
	call	printf
 
	subl	%eax, %eax
	movq	%rbp, %rsp
	popq	%rbp
	ret

EAX=80000005h: Reserved

This function isn't used.

EAX=80000006h: Extended L2 Cache Features

Returns details of the L2 cache in ECX, including two different ways to express cache size and codes for cache associativity.

.section	.data
s0:		.string	"L2 Cache: %iMB\n"
.text
	.global main
 
	.type	main, @function
main:
	pushq	%rbp
	movq	%rsp, %rbp
 
	movl	$0x80000006, %eax
	cpuid
 
	subl	%edx, %edx
	movl	%ecx, (%rsp)
	movl	2(%rsp), %eax
	movl	$1024, %ecx
	divl	%ecx
 
	movl	$s0, %edi
	movl	%eax, %esi
	subl	%eax, %eax
	call	printf
 
	subl    %eax, %eax
	movq	%rbp, %rsp
	popq	%rbp
	ret

EAX=80000007h: Reserved

This function isn't used.

EAX=80000008h: Virtual and Physical address Sizes

Returns largest virtual and physical address sizes in EAX.

See also

External links







Why are we here?
All text is available under the terms of the GNU Free Documentation License
This page is cache of Wikipedia. History