1 /** @file
2   AsmCpuidEx function.
3 
4   Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5   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   Retrieves CPUID information using an extended leaf identifier.
17 
18   Executes the CPUID instruction with EAX set to the value specified by Index
19   and ECX set to the value specified by SubIndex. This function always returns
20   Index. This function is only available on IA-32 and x64.
21 
22   If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
23   If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
24   If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
25   If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
26 
27   @param  Index         The 32-bit value to load into EAX prior to invoking the
28                         CPUID instruction.
29   @param  SubIndex      The 32-bit value to load into ECX prior to invoking the
30                         CPUID instruction.
31   @param  RegisterEax   A pointer to the 32-bit EAX value returned by the CPUID
32                         instruction. This is an optional parameter that may be
33                         NULL.
34   @param  RegisterEbx   A pointer to the 32-bit EBX value returned by the CPUID
35                         instruction. This is an optional parameter that may be
36                         NULL.
37   @param  RegisterEcx   A pointer to the 32-bit ECX value returned by the CPUID
38                         instruction. This is an optional parameter that may be
39                         NULL.
40   @param  RegisterEdx   A pointer to the 32-bit EDX value returned by the CPUID
41                         instruction. This is an optional parameter that may be
42                         NULL.
43 
44   @return Index.
45 
46 **/
47 UINT32
48 EFIAPI
AsmCpuidEx(IN UINT32 Index,IN UINT32 SubIndex,OUT UINT32 * RegisterEax,OPTIONAL OUT UINT32 * RegisterEbx,OPTIONAL OUT UINT32 * RegisterEcx,OPTIONAL OUT UINT32 * RegisterEdx OPTIONAL)49 AsmCpuidEx (
50   IN      UINT32                    Index,
51   IN      UINT32                    SubIndex,
52   OUT     UINT32                    *RegisterEax,  OPTIONAL
53   OUT     UINT32                    *RegisterEbx,  OPTIONAL
54   OUT     UINT32                    *RegisterEcx,  OPTIONAL
55   OUT     UINT32                    *RegisterEdx   OPTIONAL
56   )
57 {
58   _asm {
59     mov     eax, Index
60     mov     ecx, SubIndex
61     cpuid
62     push    ecx
63     mov     ecx, RegisterEax
64     jecxz   SkipEax
65     mov     [ecx], eax
66 SkipEax:
67     mov     ecx, RegisterEbx
68     jecxz   SkipEbx
69     mov     [ecx], ebx
70 SkipEbx:
71     pop     eax
72     mov     ecx, RegisterEcx
73     jecxz   SkipEcx
74     mov     [ecx], eax
75 SkipEcx:
76     mov     ecx, RegisterEdx
77     jecxz   SkipEdx
78     mov     [ecx], edx
79 SkipEdx:
80     mov     eax, Index
81   }
82 }
83