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