]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/CpuIdEx.c
c685e5ec4e299c9cc6a4779be7861905e08e82b5
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / CpuIdEx.c
1 /** @file
2 AsmCpuidEx function.
3
4 Copyright (c) 2006 - 2007, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 //
16 // Include common header file for this module.
17 //
18
19
20 /**
21 Retrieves CPUID information using an extended leaf identifier.
22
23 Executes the CPUID instruction with EAX set to the value specified by Index
24 and ECX set to the value specified by SubIndex. This function always returns
25 Index. This function is only available on IA-32 and x64.
26
27 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
28 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
29 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
30 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
31
32 @param Index The 32-bit value to load into EAX prior to invoking the
33 CPUID instruction.
34 @param SubIndex The 32-bit value to load into ECX prior to invoking the
35 CPUID instruction.
36 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
37 instruction. This is an optional parameter that may be
38 NULL.
39 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
40 instruction. This is an optional parameter that may be
41 NULL.
42 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
43 instruction. This is an optional parameter that may be
44 NULL.
45 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
46 instruction. This is an optional parameter that may be
47 NULL.
48
49 @return Index
50
51 **/
52 UINT32
53 EFIAPI
54 AsmCpuidEx (
55 IN UINT32 Index,
56 IN UINT32 SubIndex,
57 OUT UINT32 *RegisterEax, OPTIONAL
58 OUT UINT32 *RegisterEbx, OPTIONAL
59 OUT UINT32 *RegisterEcx, OPTIONAL
60 OUT UINT32 *RegisterEdx OPTIONAL
61 )
62 {
63 _asm {
64 mov eax, Index
65 mov ecx, SubIndex
66 cpuid
67 push ecx
68 mov ecx, RegisterEax
69 jecxz SkipEax
70 mov [ecx], eax
71 SkipEax:
72 mov ecx, RegisterEbx
73 jecxz SkipEbx
74 mov [ecx], ebx
75 SkipEbx:
76 pop eax
77 mov ecx, RegisterEcx
78 jecxz SkipEcx
79 mov [ecx], eax
80 SkipEcx:
81 mov ecx, RegisterEdx
82 jecxz SkipEdx
83 mov [ecx], edx
84 SkipEdx:
85 mov eax, Index
86 }
87 }