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