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