CPUID

From Wikipedia, the free encyclopedia

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

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

CPUID命令の使用可否

CPUID命令は一部の80486およびそれ以降のプロセッサで利用できるため、場合によってはCPUID命令が存在するプロセッサであるか否かを事前に判別する必要が生じる。80486以前のプロセッサを識別する必要がある場合には、それぞれの振舞の微妙な違いを利用する難解なテクニックを駆使する必要があった(たとえば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を参照。

さらに見る Bit, EDX ...
CPUID EAX=1: EDXとECXで取得できる機能フラグ
Bit EDX ECX[注釈 1] Bit
ShortFeature ShortFeature
0 fpuオンチップ x87 FPU(浮動小数点ユニット) sse3SSE3命令(Prescott New Instructions) 0
1 vme仮想8086モード拡張 (VIF, VIP, PVIなど) pclmulqdqPCLMULQDQ命令 (carry-less multiply) 1
2 deデバッグ拡張 (Control register CR4 bit 3) dtes6464-bit debug store 2
3 pseページサイズ拡張 (4 MByteページ) monitorMONITORMWAIT命令(Prescott New Instructions) 3
4 tscタイムスタンプカウンタ(Time Stamp Counter)とRDTSC命令。 ds-cplCPL qualified debug store 4
5 msrモデル固有レジスタ(Model-specific registers)とRDMSR/WRMSR命令 vmxVirtual Machine eXtensions 5
6 pae物理アドレス拡張 smxSafer Mode Extensions (LaGrande) (GETSEC instruction) 6
7 mceマシンチェック例外(Machine Check Exception) estEnhanced SpeedStep 7
8 cx8CMPXCHG8B命令 tm2Thermal Monitor 2 8
9 apic[注釈 2]オンチップAPIC(Advanced Programmable Interrupt Controller) ssse3Supplemental SSE3命令 9
10 (reserved) (reserved) cnxt-idL1 Context ID 10
11 sep[注釈 3]SYSENTERおよびSYSEXIT命令 sdbgSilicon Debug interface 11
12 mtrrメモリタイプ範囲レジスタ(Memory Type Range Registers) fmaFused multiply-add (FMA3) 12
13 pgeページ・グローバル・イネーブル(Page Global Enable)ビット Control register CR4 cx16CMPXCHG16B命令 13
14 mcaマシン・チェック・アーキテクチャ(Machine check architecture) xtprCan disable sending task priority messages 14
15 cmov条件付き転送命令。CMOV, FCMOV, FCOMIなど[注釈 4] pdcmPerfmon & debug capability 15
16 patページ属性テーブル(Page Attribute Table) (reserved)[注釈 5] 16
17 pse-3636ビットページサイズ拡張 pcidProcess context identifiers (Control register CR4 bit 17) 17
18 psnプロセッサ・シリアル番号 dcaDirect cache access for DMA writes 18
19 clfshCLFLUSH命令 (SSE2) sse4.1SSE4.1命令 19
20 (nx)No-execute (NX) bit (Itanium only)[6][注釈 6] sse4.2SSE4.2命令 20
21 dsデバッグストア。 save trace of executed jumps x2apicx2APIC (enhanced APIC) 21
22 acpiOnboard thermal control MSRs for ACPI movbeMOVBE命令 22
23 mmxMMX命令 popcntPOPCNT命令 23
24 fxsrFXSAVE, FXRSTOR命令。 Control register CR4 bit 9 tsc-deadlineAPIC implements one-shot operation using a TSC deadline value 24
25 sseSSE 命令
(Katmai New Instructions)
aes-niAES命令 25
26 sse2SSE2命令 xsaveExtensible processor state save/restore:
XSAVE, XRSTOR, XSETBV, XGETBV instructions
26
27 ssセルフスヌープ(self-snoop) osxsaveXSAVE enabled by OS 27
28 httハイパー・スレッディング・テクノロジ avxAdvanced Vector Extensions (256-bit SIMD) 28
29 tm温度モニタ(Thermal monitor) f16cFloating-point conversion instructions to/from FP16 format 29
30 ia64IA64 processor emulating x86[6] rdrndRDRAND (on-chip random number generator) feature 30
31 pbePending Break Enable (PBE# pin) wakeup capability hypervisorHypervisor present (always zero on physical CPUs)[7][8] 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=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=7, ECX=0: 拡張機能

EBX, ECX, EDXレジスタに拡張機能フラグを返す。また、EAX=7での呼び出しに使用できるECXの最大値をEAXに返す。

さらに見る Bit, EBX ...
CPUID EAX=7,ECX=0: Extended feature bits in EBX, ECX and EDX
Bit EBX ECX EDX Bit
Short Feature Short Feature Short Feature
0 fsgsbaseAccess to base of FS and GS prefetchwt1PREFETCHWT1 instruction (sgx-tem)? 0
1 IA32_TSC_ADJUST MSR avx512-vbmiAVX-512 Vector Bit Manipulation Instructions sgx-keysAttestation Services for Intel SGX 1
2 sgxSoftware Guard Extensions umipUser-mode Instruction Prevention avx512-4vnniwAVX-512 4-register Neural Network Instructions 2
3 bmi1Bit Manipulation Instruction Set 1 pkuMemory Protection Keys for User-mode pages avx512-4fmapsAVX-512 4-register Multiply Accumulation Single precision 3
4 hleTSX Hardware Lock Elision ospkePKU enabled by OS fsrmFast Short REP MOVSB 4
5 avx2Advanced Vector Extensions 2 waitpkgTimed pause and user-level monitor/wait instructions (TPAUSE, UMONITOR, UMWAIT) uintrUser Inter-processor Interrupts 5
6 fdp-excptn-onlyx87 FPU data pointer register updated on exceptions only avx512-vbmi2AVX-512 Vector Bit Manipulation Instructions 2 (reserved) 6
7 smepSupervisor Mode Execution Prevention cet_ss/shstkControl flow enforcement (CET): shadow stack (SHSTK alternative name) (reserved) 7
8 bmi2Bit Manipulation Instruction Set 2 gfniGalois Field instructions avx512-vp2intersectAVX-512 vector intersection instructions on 32/64-bit integers 8
9 ermsEnhanced REP MOVSB/STOSB vaesVector AES instruction set (VEX-256/EVEX) srbds-ctrlSpecial Register Buffer Data Sampling Mitigations 9
10 invpcidINVPCID instruction vpclmulqdqCLMUL instruction set (VEX-256/EVEX) md-clearVERW instruction clears CPU buffers 10
11 rtmTSX Restricted Transactional Memory avx512-vnniAVX-512 Vector Neural Network Instructions rtm-always-abort[9]All TSX transactions are aborted 11
12 rdt-m/pqmIntel Resource Director (RDT) Monitoring or AMD Platform QOS Monitoring avx512-bitalgAVX-512 BITALG instructions (reserved) 12
13 x87 FPU CS and DS deprecated tme_enTotal Memory Encryption MSRs available rtm-force-abort[9]TSX_FORCE_ABORT (MSR 0x10f) is available 13
14 mpxIntel MPX (Memory Protection Extensions) avx512-vpopcntdqAVX-512 Vector Population Count Double and Quad-word serializeSERIALIZE instruction 14
15 rdt-a/pqeIntel Resource Director (RDT) Allocation or AMD Platform QOS Enforcement (fzm)? hybridMixture of CPU types in processor topology (e.g. Alder Lake) 15
16 avx512-fAVX-512 Foundation la575-level paging (57 address bits) tsxldtrkTSX load address tracking suspend/resume instructions (TSUSLDTRK and TRESLDTRK) 16
17 avx512-dqAVX-512 Doubleword and Quadword Instructions mawauThe value of userspace MPX Address-Width Adjust used by the BNDLDX and BNDSTX Intel MPX instructions in 64-bit mode (reserved) 17
18 rdseedRDSEED instruction pconfigPlatform configuration (Memory Encryption Technologies Instructions) 18
19 adxIntel ADX (Multi-Precision Add-Carry Instruction Extensions) lbrArchitectural Last Branch Records 19
20 smapSupervisor Mode Access Prevention cet-ibtControl flow enforcement (CET): indirect branch tracking 20
21 avx512-ifmaAVX-512 Integer Fused Multiply-Add Instructions (reserved) 21
22 (pcommit)(PCOMMIT instruction, deprecated)[10] rdpidRDPID (Read Processor ID) instruction and IA32_TSC_AUX MSR amx-bf16AMX(Advanced Matrix Extensions) tile computation on bfloat16 numbers 22
23 clflushoptCLFLUSHOPT instruction klAES Key Locker avx512-fp16AVX-512 half-precision floating-point arithmetic instructions[11] 23
24 clwbCLWB (Cache line writeback) instruction bus-lock-detectBus lock debug exceptions amx-tileAMX tile load/store instructions 24
25 ptIntel Processor Trace cldemoteCLDEMOTE (Cache line demote) instruction amx-int8AMX tile computation on 8-bit integers 25
26 avx512-pfAVX-512 Prefetch Instructions (mprr)? ibrs / spec_ctrlSpeculation Control, part of Indirect Branch Control (IBC):
Indirect Branch Restricted Speculation (IBRS) and
Indirect Branch Prediction Barrier (IBPB)[12]
26
27 avx512-erAVX-512 Exponential and Reciprocal Instructions movdiriMOVDIRI instruction stibpSingle Thread Indirect Branch Predictor, part of IBC[12] 27
28 avx512-cdAVX-512 Conflict Detection Instructions movdir64bMOVDIR64B (64-byte direct store) instruction L1D_FLUSHIA32_FLUSH_CMD MSR 28
29 shaSHA-1 and SHA-256 extensions enqcmdEnqueue Stores and EMQCMD/EMQCMDS instructions IA32_ARCH_CAPABILITIES MSR (lists speculative side channel mitigations[12]) 29
30 avx512-bwAVX-512 Byte and Word Instructions sgx-lcSGX Launch Configuration IA32_CORE_CAPABILITIES MSR (lists model-specific core capabilities) 30
31 avx512-vlAVX-512 Vector Length Extensions pksProtection keys for supervisor-mode pages ssbdSpeculative Store Bypass Disable,[12] as mitigation for Speculative Store Bypass (IA32_SPEC_CTRL) 31
閉じる

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

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

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

    AMD社のCPUの拡張機能フラグをEDXとECXに格納する[13][14]。 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に対応しているものもある。

    さらに見る Bit, EDX ...
    CPUID EAX=80000001h: Feature bits in EDX and ECX
    Bit EDX ECX Bit
    Short Feature Short Feature
    0 fpu[注釈 1] lahf_lmLAHF/SAHF in long mode 0
    1 vme[注釈 1] cmp_legacyHyperthreading not valid 1
    2 de[注釈 1] svmSecure Virtual Machine 2
    3 pse[注釈 1] extapicExtended APIC space 3
    4 tsc[注釈 1] cr8_legacyControl register CR8 in 32-bit mode 4
    5 msr[注釈 1] abm/lzcntAdvanced bit manipulation (LZCNT and POPCNT) 5
    6 pae[注釈 1] sse4aSSE4a 6
    7 mce[注釈 1] misalignsseMisaligned SSE mode 7
    8 cx8[注釈 1] 3dnowprefetchPREFETCH and PREFETCHW instructions 8
    9 apic[注釈 1] osvwOS Visible Workaround 9
    10 (syscall)(SYSCALL/SYSRET, K6 only) ibsInstruction Based Sampling 10
    11 syscall[注釈 2][15]SYSCALL and SYSRET instructions xopXOP instruction set 11
    12 mtrr[注釈 1] skinitSKINIT/STGI instructions 12
    13 pge[注釈 1] wdtWatchdog timer 13
    14 mca[注釈 1] (reserved) 14
    15 cmov[注釈 1] lwpLight Weight Profiling[16] 15
    16 pat[注釈 1] fma44-operand fused multiply-add instructions 16
    17 pse36[注釈 1] tceTranslation Cache Extension 17
    18 (reserved) (reserved) 18
    19 ecc"Athlon MP" / "Sempron" CPU brand identification nodeid_msrNodeID MSR (C001_100C)[17] 19
    20 nxNX bit (reserved) 20
    21 (reserved) tbmTrailing Bit Manipulation 21
    22 mmxextExtended MMX topoextTopology Extensions 22
    23 mmx[注釈 1] perfctr_coreCore performance counter extensions 23
    24 fxsr[注釈 1] perfctr_nbNorthbridge performance counter extensions 24
    25 fxsr_optFXSAVE/FXRSTOR optimizations (StreamPerfMon)Streaming performance monitor architecture 25
    26 pdpe1gbGigabyte pages dbxData breakpoint extensions 26
    27 rdtscpRDTSCP instruction perftscPerformance timestamp counter (PTSC) 27
    28 (reserved) pcx_l2iL2I perf counter extensions 28
    29 lmLong Mode monitorxMONITORX and MWAITX instructions 29
    30 3dnowextExtended 3DNow! addr_mask_extAddress mask extension to 32 bits for instruction breakpoints 30
    31 3dnow3DNow! (reserved) 31
    閉じる
    1. EDXのビット 0 から 9, 12 から 17, 23と 24は、AMDのCPUではEAX=1の場合のCPUIDの結果と重複、IntelのCPUでは未使用。
    2. インテル社のCPUではCPUIDのsyscallビットはCPUが64ビットモードで動作しているときのみセットされる。

    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に格納する。

    関連項目

    脚注

    注釈

    外部リンク

    Related Articles

    Wikiwand AI