]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg: Fix AsmReadMsr64() and AsmWriteMsr64() with GCC toolchain
authorTakuto Naito <naitaku@gmail.com>
Mon, 12 Apr 2021 15:07:18 +0000 (23:07 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 14 Apr 2021 01:50:19 +0000 (01:50 +0000)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3325

1. AsmReadMsr64() in X64/GccInlinePriv.c
AsmReadMsr64 can return uninitialized value if FilterBeforeMsrRead
returns False. This causes build error with the CLANG toolchain.

2. AsmWriteMsr64() in X64/GccInlinePriv.c
In the case that FilterBeforeMsrWrite changes Value and returns True,
The original Value, not the changed Value, is written to the MSR.
This behavior is different from the one of AsmWriteMsr64() in
X64/WriteMsr64.c for the MSFT toolchain.

Signed-off-by: Takuto Naito <naitaku@gmail.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
MdePkg/Library/BaseLib/X64/GccInlinePriv.c

index e4920f21165b57a3d45cadf51ae704efa09d081b..244bd62ee67fbd79c0e393186593f514f76c7d17 100644 (file)
@@ -80,7 +80,7 @@ AsmReadMsr64 (
   }\r
   FilterAfterMsrRead (Index, &Value);\r
 \r
-  return (((UINT64)HighData) << 32) | LowData;\r
+  return Value;\r
 }\r
 \r
 /**\r
@@ -111,11 +111,10 @@ AsmWriteMsr64 (
   UINT32 HighData;\r
   BOOLEAN Flag;\r
 \r
-  LowData  = (UINT32)(Value);\r
-  HighData = (UINT32)(Value >> 32);\r
-\r
   Flag = FilterBeforeMsrWrite (Index, &Value);\r
   if (Flag) {\r
+    LowData  = (UINT32)(Value);\r
+    HighData = (UINT32)(Value >> 32);\r
     __asm__ __volatile__ (\r
       "wrmsr"\r
       :\r