CPUIDは、x86機械語命令の一つ(およびそのアセンブリ・ニーモニック)である。CPUの識別 (IDentification) の意。486の後期のステッピングで導入され、Pentiumで完全に公開された[1]

CPUIDを使用することで、ソフトウェアはプロセッサの形式と機能(例えば、MMXSSEなどの拡張のサポートの有無)を識別することができる。機械語オペコードは0FA2hであり、オペランドとしてEAXレジスタの値でどのような情報を取得するかを指定する。

CPUID命令の使用可否 編集

CPUID命令は一部の80486およびそれ以降のプロセッサで利用できるため、場合によってはCPUID命令が存在するプロセッサであるか否かを事前に判別する必要が生じる。80486以前のプロセッサを識別する必要がある場合には、それぞれの振舞の微妙な違いを利用する難解なテクニックを駆使する必要があった[2][3](たとえばPUSH SPの結果として、PUSHによる変化前と変化後の、どちらの値がプッシュされるか、等)。

80486以上のプロセッサであることが確認できた場合、CPUID命令の存在を確認するためのフラグとして32ビットフラグレジスタ (EFLAGS) の第21ビットが新たに設けられているため、このビットが「変更可能」であればCPUID命令が使用可能であると判断できる。なおEFLAGSは80386以上のプロセッサであればアクセスできるため、80286以下のプロセッサを判別・除外しておく必要はあるものの、CPUID命令の有無だけを調べたいのであれば実質的に80386以上であることが確認できればこのフラグを調べることができる。

CPUID命令の呼び出し 編集

CPUID命令は、EAXレジスタが暗黙のオペランドであり、それ以外の(明示的な)オペランドは無い。どのような情報を返すべきかを指定する値をEAXレジスタに設定し、CPUID命令を実行する。まずEAX = 0でCPUIDを呼び出し、CPUでサポートされている最大のパラメータを取得するべきである。CPUIDの拡張機能情報を取得する場合は、EAXのビット31をセットしてCPUIDを呼び出す。拡張機能情報でサポートされている最大の機能番号を得るためには、EAX = 8000000hでCPUIDを呼び出す。

EAX=0: ベンダIDの取得 編集

これは、CPUベンダのID文字列を返す。12文字のASCII文字列がEBX, EDX, ECXの順序で格納される。基本機能の最大機能番号がEAXに格納される。

既知のCPUベンダのID文字列は以下のとおり:

例えば、ベンダIDが"GenuineIntel"の場合、EBXが0x756e6547、EDXが0x49656e69、ECXが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: プロセッサ情報とプロセッサの機能 編集

これはCPUのステッピング、モデル、ファミリーをEAXに返す(これはCPUの「シグネチャ」とも呼ばれる)。また、機能フラグをEDXとECXに、追加の機能情報をEBXに返す。

EAXに格納される情報のフォーマットは以下のとおり:

  • 3:0 - ステッピング
  • 7:4 - モデル
  • 11:8 - ファミリー
  • 13:12 - プロセッサタイプ
  • 19:16 - 拡張モデル
  • 27:20 - 拡張ファミリー

インテルAMDは、CPUのファミリーを上記の「ファミリー」と「拡張ファミリー」の合計で表示し、モデルを上記の「モデル」と4ビット左シフトした「拡張モデル」の合計で表示するように提案した。

プロセッサ情報と機能フラグはメーカ個別のものであるが、通常は互換性のためにインテルの値を他のメーカも使用している。

また、80386以上のプロセッサではリセット直後のDXレジスタにはこれらの情報(拡張ファミリ・拡張ステッピングは除く)に相当する値が格納されているため、ハード構成によっては80286がプロテクトモードからリアルモードに戻るためのリセット機構(通例、80386以降のシステムでも互換性のために残されている)を利用することで、386/486系プロセッサでもファミリ・モデル・ステッピングなどに相当する情報を得られる場合がある。詳細はIntel 80286およびIntel 80386を参照。

CPUID EAX=1: EDXとECXで取得できる機能フラグ
Bit EDX ECX[注釈 1] Bit
Short Feature Short Feature
0 fpu Onboard x87 FPU sse3 SSE3 (Prescott New Instructions) 0
1 vme Virtual 8086 mode extensions (such as VIF, VIP, PVI) pclmulqdq PCLMULQDQ (carry-less multiply) instruction 1
2 de Debugging extensions (Control register CR4 bit 3) dtes64 64-bit debug store 2
3 pse Page Size Extension (4 MByte pages) monitor MONITOR and MWAIT instructions (Prescott New Instructions]) 3
4 tsc Time Stamp Counter and RDTSC instruction ds-cpl CPL qualified debug store 4
5 msr Model-specific registers and RDMSR/WRMSR instructions vmx Virtual Machine eXtensions 5
6 pae Physical Address Extension smx Safer Mode Extensions (LaGrande) (GETSEC instruction) 6
7 mce Machine Check Exception est Enhanced SpeedStep 7
8 cx8 CMPXCHG8B (compare-and-swap) instruction tm2 Thermal Monitor 2 8
9 apic[注釈 2] Onboard Advanced Programmable Interrupt Controller ssse3 Supplemental SSE3 instructions 9
10 (reserved) (reserved) cnxt-id L1 Context ID 10
11 sep[注釈 3] SYSENTER and SYSEXIT fast system call instructions sdbg Silicon Debug interface 11
12 mtrr Memory Type Range Registers fma Fused multiply-add (FMA3) 12
13 pge Page Global Enable bit in Control register CR4 cx16 CMPXCHG16B instruction 13
14 mca Machine check architecture xtpr Can disable sending task priority messages 14
15 cmov Conditional move: CMOV, FCMOV and FCOMI instructions[注釈 4] pdcm Perfmon & debug capability 15
16 pat Page Attribute Table (reserved)[注釈 5] 16
17 pse-36 36-bit page size extension pcid Process context identifiers (Control register CR4 bit 17) 17
18 psn Processor Serial Number dca Direct cache access for DMA writes 18
19 clfsh CLFLUSH cache line flush instruction (SSE2) sse4.1 SSE4.1 instructions 19
20 (nx) No-execute (NX) bit (Itanium only)[6][注釈 6] sse4.2 SSE4.2 instructions 20
21 ds Debug store: save trace of executed jumps x2apic x2APIC (enhanced APIC) 21
22 acpi Onboard thermal control MSRs for ACPI movbe MOVBE instruction (big-endian) 22
23 mmx MMX instructions (64-bit SIMD) popcnt POPCNT instruction 23
24 fxsr FXSAVE, FXRSTOR instructions, Control register CR4 bit 9 tsc-deadline APIC implements one-shot operation using a TSC deadline value 24
25 sse Streaming SIMD Extensions (SSE) instructions
(aka "Katmai New Instructions"; 128-bit SIMD)
aes-ni AES instruction set 25
26 sse2 SSE2 instructions xsave Extensible processor state save/restore:
XSAVE, XRSTOR, XSETBV, XGETBV instructions
26
27 ss CPU cache implements self-snoop osxsave XSAVE enabled by OS 27
28 htt Hyper-Threading Technology avx Advanced Vector Extensions (256-bit SIMD) 28
29 tm Thermal monitor automatically limits temperature f16c Floating-point conversion instructions to/from FP16 format 29
30 ia64 IA64 processor emulating x86[6] rdrnd RDRAND (on-chip random number generator) feature 30
31 pbe Pending Break Enable (PBE# pin) wakeup capability hypervisor Hypervisor present (always zero on physical CPUs)[7][8] 31

EAX=2: キャッシュとTLBディスクリプタ情報 編集

これは、キャッシュとTLBの機能を示すディスクリプタのリストをEAX, EBX, ECX, EDXレジスタに格納する。

EAX=3: プロセッサ・シリアル・ナンバ 編集

これは、プロセッサのシリアル番号を返す。プロセッサ・シリアル・ナンバは、インテルがPentium IIIで導入したが、プライバシーの懸念のためにこの後のモデルでは実装されていない(PSN機能ビットは常にクリアされている)。トランスメタのEfficeonとCrusoeプロセッサはこの機能を提供している。AMDは、この機能をどのCPUにも実装しなかった。

インテルPentium IIIでは、シリアル番号はEDX:ECXレジスタに格納される。トランスメタのEfficeonではEBX:EAXレジスタに、CrusoeではEBXレジスタだけに格納される。

プロセッサ・シリアル・ナンバ機能を使用するためには、BIOSの設定を有効にする必要があることに注意すべきである。

EAX=80000000h: サポートする最大拡張機能番号の取得 編集

最大の拡張機能番号をEAXに格納する。

EAX=80000001h: 拡張プロセッサ情報とプロセッサの機能 編集

AMD社のCPUの拡張機能フラグをEDXとECXに格納する[9][10]。 EDXのビット 0 から 9, 12 から 17, 23と 24は、AMDのCPUではEAX=1の場合のCPUIDの結果と重複し、IntelのCPUでは未使用である。IntelのCPUでもsyscall, nx, pdpe1gb, rdtscp, lm, lahf_lm, abm/lzcnt, 3dnowprefetchに対応しているものもある。

CPUID EAX=80000001h: Feature bits in EDX and ECX
Bit EDX ECX Bit
Short Feature Short Feature
0 fpu [11] lahf_lm LAHF/SAHF in long mode 0
1 vme [11] cmp_legacy Hyperthreading not valid 1
2 de [11] svm Secure Virtual Machine 2
3 pse [11] extapic Extended APIC space 3
4 tsc [11] cr8_legacy Control register CR8 in 32-bit mode 4
5 msr [11] abm/lzcnt Advanced bit manipulation (LZCNT and POPCNT) 5
6 pae [11] sse4a SSE4a 6
7 mce [11] misalignsse Misaligned SSE mode 7
8 cx8 [11] 3dnowprefetch PREFETCH and PREFETCHW instructions 8
9 apic [11] osvw OS Visible Workaround 9
10 (syscall) (SYSCALL/SYSRET, K6 only) ibs Instruction Based Sampling 10
11 syscall[12][13] SYSCALL and SYSRET instructions xop XOP instruction set 11
12 mtrr [11] skinit SKINIT/STGI instructions 12
13 pge [11] wdt Watchdog timer 13
14 mca [11] (reserved) 14
15 cmov [11] lwp Light Weight Profiling[14] 15
16 pat [11] fma4 4-operand fused multiply-add instructions 16
17 pse36 [11] tce Translation Cache Extension 17
18 (reserved) (reserved) 18
19 ecc "Athlon MP" / "Sempron" CPU brand identification nodeid_msr NodeID MSR (C001_100C)[15] 19
20 nx NX bit (reserved) 20
21 (reserved) tbm Trailing Bit Manipulation 21
22 mmxext Extended MMX topoext Topology Extensions 22
23 mmx [11] perfctr_core Core performance counter extensions 23
24 fxsr [11] perfctr_nb Northbridge performance counter extensions 24
25 fxsr_opt FXSAVE/FXRSTOR optimizations (StreamPerfMon) Streaming performance monitor architecture 25
26 pdpe1gb Gigabyte pages dbx Data breakpoint extensions 26
27 rdtscp RDTSCP instruction perftsc Performance timestamp counter (PTSC) 27
28 (reserved) pcx_l2i L2I perf counter extensions 28
29 lm Long Mode monitorx MONITORX and MWAITX instructions 29
30 3dnowext Extended 3DNow! addr_mask_ext Address mask extension to 32 bits for instruction breakpoints 30
31 3dnow 3DNow! (reserved) 31
  1. ^ On some older processors, executing CPUID with a leaf index (EAX) greater than 0 may leave EBX and ECX unmodified, keeping their old values. For this reason, it is recommended to zero out EBX and ECX before executing CPUID with a leaf index of 1.
    Processors noted to exhibit this behavior include Cyrix MII[1] and IDT WinChip 2.[2]
  2. ^ On early AMD K5 (AuthenticAMD Family 5 Model 0) processors only, EDX bit 9 used to indicate support for PGE instead. This was moved to bit 13 from K5 Model 1 onwards.[3]
  3. ^ On Pentium Pro (GenuineIntel Family 6 Model 1) processors only, EDX bit 11 is invalid - the bit it set, but the SYSENTER and SYSEXIT instructions are not supported on the Pentium Pro.[4]
  4. ^ FCMOV and FCOMI instructions only available if onboard x87 FPU also present (indicated by EDX bit 0).
  5. ^ ECX bit 16 is listed as "Reserved" in public Intel and AMD documentation and is not set in any known processor. However, some versions of the Windows Vista kernel are reported to be checking this bit[5] - if it is set, Vista will recognize it as a "processor channels" feature.
  6. ^ On non-Itanium x86 processors, support for the No-execute bit is indicated in CPUID.(EAX=8000_0001):EDX[bit 20] instead.

EAX=80000002h,80000003h,80000004h: プロセッサブランド文字列 編集

プロセッサブランド文字列をEAX, EBX, ECX, EDXに格納する。全体で48バイトのNULL終端ASCII文字列のプロセッサブランド文字列を得るために、各パラメータを順番に設定しCPUIDを呼び出す必要がある。

EAX=80000005h: 予約 編集

この機能は使用されていない。

EAX=80000006h: 拡張L2キャッシュ情報 編集

ECXにL2キャッシュの詳細情報を格納する。2種類の方法で表したキャッシュサイズと、キャッシュとメモリの対応を示すコードを含む。

EAX=80000007h: 予約 編集

この機能は使用されていない。

EAX=80000008h: 仮想アドレスと物理アドレスのサイズ 編集

最大の仮想アドレスサイズと物理アドレスサイズをEAXに格納する。

関連項目 編集

脚注 編集

  1. ^ Linux 6.3 kernel sources, /arch/x86/include/asm/cpuid.h, line 69
  2. ^ gcc-patches mailing list, CPUID Patch for IDT Winchip, May 21, 2019
  3. ^ AMD, AMD Processor Recognition Application Note, publication #20734, rev D, Jan 1997, page 13
  4. ^ Michal Necasek, SYSENTER, Where Are You?, OS/2 Museum, July 20, 2017
  5. ^ Geoff Chappell, ECX From CPUID Leaf 1, Jan 26, 2020. Archived on May 9, 2020.
  6. ^ a b Intel, Itanium Architecture Software Developer's Manual, rev 2.3, volume 4: IA-32 Instruction Set, may 2010, document number: 323208, table 2-5, page 4:81, see bits 20 and 30. Archived on Feb 15, 2012.
  7. ^ Mechanisms to determine if software is running in a VMware virtual machine”. VMware Knowledge Base. VMWare (2015年5月1日). 2023年8月12日閲覧。 “Intel and AMD CPUs have reserved bit 31 of ECX of CPUID leaf 0x1 as the hypervisor present bit. This bit allows hypervisors to indicate their presence to the guest operating system. Hypervisors set this bit and physical CPUs (all existing and future CPUs) set this bit to zero. Guest operating systems can test bit 31 to detect if they are running inside a virtual machine.”
  8. ^ Hypervisor CPUID Interface Proposal”. LKML Archive on lore.kernel.org (2008年10月1日). 2019年3月15日時点のオリジナルよりアーカイブ。2023年8月12日閲覧。 “Bit 31 of ECX of CPUID leaf 0x1. This bit has been reserved by Intel & AMD for use by hypervisors and indicates the presence of a hypervisor. Virtual CPU's (hypervisors) set this bit to 1 and physical CPU's (all existing and future CPU's) set this bit to zero. This bit can be probed by the guest software to detect whether they are running inside a virtual machine.”
  9. ^ CPUID Specification, publication no.25481, rev 2.34, AMD, (September 2010), オリジナルの18 Aug 2022時点におけるアーカイブ。, https://web.archive.org/web/20220818192714/http://developer.amd.com/wordpress/media/2012/10/25481.pdf 
  10. ^ Linux kernel source code
  11. ^ a b c d e f g h i j k l m n o p q r EDXのビット 0 から 9, 12 から 17, 23と 24は、AMDのCPUではEAX=1の場合のCPUIDの結果と重複、IntelのCPUでは未使用。
  12. ^ インテル社のCPUではCPUIDのsyscallビットはCPUが64ビットモードで動作しているときのみセットされる。
  13. ^ Intel, Intel® 64 and IA-32 Architectures Software Developer’s Manual, order no. 325462-079, march 2023, table 3-8 on page 3-238
  14. ^ Lightweight Profiling Specification, AMD, (August 2010), オリジナルの2012-11-27時点におけるアーカイブ。, https://web.archive.org/web/20121127061327/http://support.amd.com/us/Processor_TechDocs/43724.pdf 2013年4月3日閲覧。 
  15. ^ AMD, Family 10h BKDG, document no. 31116, rev 3.62, jan 11, 2013, p. 388 - lists the NodeId bit. Archived on 16 Jan 2019.

注釈 編集


外部リンク 編集