]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/CpuId.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / CpuId.c
1 /** @file
2 AsmCpuid function.
3
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 /**
10 Retrieves CPUID information.
11
12 Executes the CPUID instruction with EAX set to the value specified by Index.
13 This function always returns Index.
14 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
15 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
16 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
17 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
18 This function is only available on IA-32 and x64.
19
20 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
21 instruction.
22 @param RegisterEax A pointer to the 32-bit EAX value returned by the CPUID
23 instruction. This is an optional parameter that may be NULL.
24 @param RegisterEbx A pointer to the 32-bit EBX value returned by the CPUID
25 instruction. This is an optional parameter that may be NULL.
26 @param RegisterEcx A pointer to the 32-bit ECX value returned by the CPUID
27 instruction. This is an optional parameter that may be NULL.
28 @param RegisterEdx A pointer to the 32-bit EDX value returned by the CPUID
29 instruction. This is an optional parameter that may be NULL.
30
31 @return Index.
32
33 **/
34 UINT32
35 EFIAPI
36 AsmCpuid (
37 IN UINT32 Index,
38 OUT UINT32 *RegisterEax, OPTIONAL
39 OUT UINT32 *RegisterEbx, OPTIONAL
40 OUT UINT32 *RegisterEcx, OPTIONAL
41 OUT UINT32 *RegisterEdx OPTIONAL
42 )
43 {
44 _asm {
45 mov eax, Index
46 cpuid
47 push ecx
48 mov ecx, RegisterEax
49 jecxz SkipEax
50 mov [ecx], eax
51 SkipEax:
52 mov ecx, RegisterEbx
53 jecxz SkipEbx
54 mov [ecx], ebx
55 SkipEbx:
56 pop eax
57 mov ecx, RegisterEcx
58 jecxz SkipEcx
59 mov [ecx], eax
60 SkipEcx:
61 mov ecx, RegisterEdx
62 jecxz SkipEdx
63 mov [ecx], edx
64 SkipEdx:
65 mov eax, Index
66 }
67 }
68