]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/Ia32/ReadMsr64.c
MdePkg/Baseib: Filter/trace MSR access for IA32/X64
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / ReadMsr64.c
index 6d2394b1a3ef3642dcefe83f0d0082fb75b8fa73..afe3aa5bdc9a7e6be475b48c9edb89925ec7bc38 100644 (file)
@@ -1,13 +1,13 @@
 /** @file\r
   AsmReadMsr64 function\r
 \r
-  Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 \r
-\r
+#include <Library/RegisterFilterLib.h>\r
 \r
 /**\r
   Returns a 64-bit Machine Specific Register(MSR).\r
@@ -24,8 +24,7 @@
 \r
 **/\r
 UINT64\r
-EFIAPI\r
-AsmReadMsr64 (\r
+AsmReadMsr64Internal (\r
   IN UINT32  Index\r
   )\r
 {\r
@@ -35,3 +34,34 @@ AsmReadMsr64 (
   }\r
 }\r
 \r
+/**\r
+  Returns a 64-bit Machine Specific Register(MSR).\r
+\r
+  Reads and returns the 64-bit MSR specified by Index. No parameter checking is\r
+  performed on Index, and some Index values may cause CPU exceptions. The\r
+  caller must either guarantee that Index is valid, or the caller must set up\r
+  exception handlers to catch the exceptions. This function is only available\r
+  on IA-32 and x64.\r
+\r
+  @param  Index The 32-bit MSR index to read.\r
+\r
+  @return The value of the MSR identified by Index.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+AsmReadMsr64 (\r
+  IN UINT32  Index\r
+  )\r
+{\r
+  UINT64                            Value;\r
+  BOOLEAN                           Flag;\r
+\r
+  Flag = FilterBeforeMsrRead (Index, &Value);\r
+  if (Flag) {\r
+    Value = AsmReadMsr64Internal (Index);\r
+  }\r
+  FilterAfterMsrRead (Index, &Value);\r
+\r
+  return Value;\r
+}\r