]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/ReadMsr64.c
afe3aa5bdc9a7e6be475b48c9edb89925ec7bc38
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / ReadMsr64.c
1 /** @file
2 AsmReadMsr64 function
3
4 Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9
10 #include <Library/RegisterFilterLib.h>
11
12 /**
13 Returns a 64-bit Machine Specific Register(MSR).
14
15 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
16 performed on Index, and some Index values may cause CPU exceptions. The
17 caller must either guarantee that Index is valid, or the caller must set up
18 exception handlers to catch the exceptions. This function is only available
19 on IA-32 and x64.
20
21 @param Index The 32-bit MSR index to read.
22
23 @return The value of the MSR identified by Index.
24
25 **/
26 UINT64
27 AsmReadMsr64Internal (
28 IN UINT32 Index
29 )
30 {
31 _asm {
32 mov ecx, Index
33 rdmsr
34 }
35 }
36
37 /**
38 Returns a 64-bit Machine Specific Register(MSR).
39
40 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
41 performed on Index, and some Index values may cause CPU exceptions. The
42 caller must either guarantee that Index is valid, or the caller must set up
43 exception handlers to catch the exceptions. This function is only available
44 on IA-32 and x64.
45
46 @param Index The 32-bit MSR index to read.
47
48 @return The value of the MSR identified by Index.
49
50 **/
51 UINT64
52 EFIAPI
53 AsmReadMsr64 (
54 IN UINT32 Index
55 )
56 {
57 UINT64 Value;
58 BOOLEAN Flag;
59
60 Flag = FilterBeforeMsrRead (Index, &Value);
61 if (Flag) {
62 Value = AsmReadMsr64Internal (Index);
63 }
64 FilterAfterMsrRead (Index, &Value);
65
66 return Value;
67 }