]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/X86Msr.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / BaseLib / X86Msr.c
index b58807fd526981941710b9a1cb620a2c2fb45adb..1995cb8fd31213b697de42b521609dd7c90adb40 100644 (file)
@@ -1,21 +1,13 @@
 /** @file\r
   IA-32/x64 MSR functions.\r
 \r
 /** @file\r
   IA-32/x64 MSR functions.\r
 \r
-  Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
-  All rights reserved. This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 \r
 **/\r
 \r
-\r
 #include "BaseLibInternals.h"\r
 \r
 #include "BaseLibInternals.h"\r
 \r
-\r
 /**\r
   Returns the lower 32-bits of a Machine Specific Register(MSR).\r
 \r
 /**\r
   Returns the lower 32-bits of a Machine Specific Register(MSR).\r
 \r
@@ -33,7 +25,7 @@
 UINT32\r
 EFIAPI\r
 AsmReadMsr32 (\r
 UINT32\r
 EFIAPI\r
 AsmReadMsr32 (\r
-  IN      UINT32                    Index\r
+  IN      UINT32  Index\r
   )\r
 {\r
   return (UINT32)AsmReadMsr64 (Index);\r
   )\r
 {\r
   return (UINT32)AsmReadMsr64 (Index);\r
@@ -59,8 +51,8 @@ AsmReadMsr32 (
 UINT32\r
 EFIAPI\r
 AsmWriteMsr32 (\r
 UINT32\r
 EFIAPI\r
 AsmWriteMsr32 (\r
-  IN      UINT32                    Index,\r
-  IN      UINT32                    Value\r
+  IN      UINT32  Index,\r
+  IN      UINT32  Value\r
   )\r
 {\r
   return (UINT32)AsmWriteMsr64 (Index, Value);\r
   )\r
 {\r
   return (UINT32)AsmWriteMsr64 (Index, Value);\r
@@ -88,8 +80,8 @@ AsmWriteMsr32 (
 UINT32\r
 EFIAPI\r
 AsmMsrOr32 (\r
 UINT32\r
 EFIAPI\r
 AsmMsrOr32 (\r
-  IN      UINT32                    Index,\r
-  IN      UINT32                    OrData\r
+  IN      UINT32  Index,\r
+  IN      UINT32  OrData\r
   )\r
 {\r
   return (UINT32)AsmMsrOr64 (Index, OrData);\r
   )\r
 {\r
   return (UINT32)AsmMsrOr64 (Index, OrData);\r
@@ -117,8 +109,8 @@ AsmMsrOr32 (
 UINT32\r
 EFIAPI\r
 AsmMsrAnd32 (\r
 UINT32\r
 EFIAPI\r
 AsmMsrAnd32 (\r
-  IN      UINT32                    Index,\r
-  IN      UINT32                    AndData\r
+  IN      UINT32  Index,\r
+  IN      UINT32  AndData\r
   )\r
 {\r
   return (UINT32)AsmMsrAnd64 (Index, AndData);\r
   )\r
 {\r
   return (UINT32)AsmMsrAnd64 (Index, AndData);\r
@@ -149,9 +141,9 @@ AsmMsrAnd32 (
 UINT32\r
 EFIAPI\r
 AsmMsrAndThenOr32 (\r
 UINT32\r
 EFIAPI\r
 AsmMsrAndThenOr32 (\r
-  IN      UINT32                    Index,\r
-  IN      UINT32                    AndData,\r
-  IN      UINT32                    OrData\r
+  IN      UINT32  Index,\r
+  IN      UINT32  AndData,\r
+  IN      UINT32  OrData\r
   )\r
 {\r
   return (UINT32)AsmMsrAndThenOr64 (Index, AndData, OrData);\r
   )\r
 {\r
   return (UINT32)AsmMsrAndThenOr64 (Index, AndData, OrData);\r
@@ -182,9 +174,9 @@ AsmMsrAndThenOr32 (
 UINT32\r
 EFIAPI\r
 AsmMsrBitFieldRead32 (\r
 UINT32\r
 EFIAPI\r
 AsmMsrBitFieldRead32 (\r
-  IN      UINT32                    Index,\r
-  IN      UINTN                     StartBit,\r
-  IN      UINTN                     EndBit\r
+  IN      UINT32  Index,\r
+  IN      UINTN   StartBit,\r
+  IN      UINTN   EndBit\r
   )\r
 {\r
   return BitFieldRead32 (AsmReadMsr32 (Index), StartBit, EndBit);\r
   )\r
 {\r
   return BitFieldRead32 (AsmReadMsr32 (Index), StartBit, EndBit);\r
@@ -196,20 +188,21 @@ AsmMsrBitFieldRead32 (
   Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit\r
   field is specified by the StartBit and the EndBit. All other bits in the\r
   destination MSR are preserved. The lower 32-bits of the MSR written is\r
   Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit\r
   field is specified by the StartBit and the EndBit. All other bits in the\r
   destination MSR are preserved. The lower 32-bits of the MSR written is\r
-  returned. The caller must either guarantee that Index and the data written \r
-  is valid, or the caller must set up exception handlers to catch the exceptions. \r
+  returned. The caller must either guarantee that Index and the data written\r
+  is valid, or the caller must set up exception handlers to catch the exceptions.\r
   This function is only available on IA-32 and x64.\r
 \r
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
   This function is only available on IA-32 and x64.\r
 \r
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..31.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
                     Range 0..31.\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..31.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
                     Range 0..31.\r
-  @param  Value     New value of the bit field.\r
+  @param  Value     The new value of the bit field.\r
 \r
   @return The lower 32-bit of the value written to the MSR.\r
 \r
 \r
   @return The lower 32-bit of the value written to the MSR.\r
 \r
@@ -217,10 +210,10 @@ AsmMsrBitFieldRead32 (
 UINT32\r
 EFIAPI\r
 AsmMsrBitFieldWrite32 (\r
 UINT32\r
 EFIAPI\r
 AsmMsrBitFieldWrite32 (\r
-  IN      UINT32                    Index,\r
-  IN      UINTN                     StartBit,\r
-  IN      UINTN                     EndBit,\r
-  IN      UINT32                    Value\r
+  IN      UINT32  Index,\r
+  IN      UINTN   StartBit,\r
+  IN      UINTN   EndBit,\r
+  IN      UINT32  Value\r
   )\r
 {\r
   ASSERT (EndBit < sizeof (Value) * 8);\r
   )\r
 {\r
   ASSERT (EndBit < sizeof (Value) * 8);\r
@@ -243,6 +236,7 @@ AsmMsrBitFieldWrite32 (
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -257,10 +251,10 @@ AsmMsrBitFieldWrite32 (
 UINT32\r
 EFIAPI\r
 AsmMsrBitFieldOr32 (\r
 UINT32\r
 EFIAPI\r
 AsmMsrBitFieldOr32 (\r
-  IN      UINT32                    Index,\r
-  IN      UINTN                     StartBit,\r
-  IN      UINTN                     EndBit,\r
-  IN      UINT32                    OrData\r
+  IN      UINT32  Index,\r
+  IN      UINTN   StartBit,\r
+  IN      UINTN   EndBit,\r
+  IN      UINT32  OrData\r
   )\r
 {\r
   ASSERT (EndBit < sizeof (OrData) * 8);\r
   )\r
 {\r
   ASSERT (EndBit < sizeof (OrData) * 8);\r
@@ -283,6 +277,7 @@ AsmMsrBitFieldOr32 (
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -297,10 +292,10 @@ AsmMsrBitFieldOr32 (
 UINT32\r
 EFIAPI\r
 AsmMsrBitFieldAnd32 (\r
 UINT32\r
 EFIAPI\r
 AsmMsrBitFieldAnd32 (\r
-  IN      UINT32                    Index,\r
-  IN      UINTN                     StartBit,\r
-  IN      UINTN                     EndBit,\r
-  IN      UINT32                    AndData\r
+  IN      UINT32  Index,\r
+  IN      UINTN   StartBit,\r
+  IN      UINTN   EndBit,\r
+  IN      UINT32  AndData\r
   )\r
 {\r
   ASSERT (EndBit < sizeof (AndData) * 8);\r
   )\r
 {\r
   ASSERT (EndBit < sizeof (AndData) * 8);\r
@@ -325,6 +320,8 @@ AsmMsrBitFieldAnd32 (
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -340,11 +337,11 @@ AsmMsrBitFieldAnd32 (
 UINT32\r
 EFIAPI\r
 AsmMsrBitFieldAndThenOr32 (\r
 UINT32\r
 EFIAPI\r
 AsmMsrBitFieldAndThenOr32 (\r
-  IN      UINT32                    Index,\r
-  IN      UINTN                     StartBit,\r
-  IN      UINTN                     EndBit,\r
-  IN      UINT32                    AndData,\r
-  IN      UINT32                    OrData\r
+  IN      UINT32  Index,\r
+  IN      UINTN   StartBit,\r
+  IN      UINTN   EndBit,\r
+  IN      UINT32  AndData,\r
+  IN      UINT32  OrData\r
   )\r
 {\r
   ASSERT (EndBit < sizeof (AndData) * 8);\r
   )\r
 {\r
   ASSERT (EndBit < sizeof (AndData) * 8);\r
@@ -379,8 +376,8 @@ AsmMsrBitFieldAndThenOr32 (
 UINT64\r
 EFIAPI\r
 AsmMsrOr64 (\r
 UINT64\r
 EFIAPI\r
 AsmMsrOr64 (\r
-  IN      UINT32                    Index,\r
-  IN      UINT64                    OrData\r
+  IN      UINT32  Index,\r
+  IN      UINT64  OrData\r
   )\r
 {\r
   return AsmWriteMsr64 (Index, AsmReadMsr64 (Index) | OrData);\r
   )\r
 {\r
   return AsmWriteMsr64 (Index, AsmReadMsr64 (Index) | OrData);\r
@@ -407,15 +404,15 @@ AsmMsrOr64 (
 UINT64\r
 EFIAPI\r
 AsmMsrAnd64 (\r
 UINT64\r
 EFIAPI\r
 AsmMsrAnd64 (\r
-  IN      UINT32                    Index,\r
-  IN      UINT64                    AndData\r
+  IN      UINT32  Index,\r
+  IN      UINT64  AndData\r
   )\r
 {\r
   return AsmWriteMsr64 (Index, AsmReadMsr64 (Index) & AndData);\r
 }\r
 \r
 /**\r
   )\r
 {\r
   return AsmWriteMsr64 (Index, AsmReadMsr64 (Index) & AndData);\r
 }\r
 \r
 /**\r
-  Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise \r
+  Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise\r
   OR, and writes the result back to the 64-bit MSR.\r
 \r
   Reads the 64-bit MSR specified by Index, performs a bitwise AND between read\r
   OR, and writes the result back to the 64-bit MSR.\r
 \r
   Reads the 64-bit MSR specified by Index, performs a bitwise AND between read\r
@@ -438,9 +435,9 @@ AsmMsrAnd64 (
 UINT64\r
 EFIAPI\r
 AsmMsrAndThenOr64 (\r
 UINT64\r
 EFIAPI\r
 AsmMsrAndThenOr64 (\r
-  IN      UINT32                    Index,\r
-  IN      UINT64                    AndData,\r
-  IN      UINT64                    OrData\r
+  IN      UINT32  Index,\r
+  IN      UINT64  AndData,\r
+  IN      UINT64  OrData\r
   )\r
 {\r
   return AsmWriteMsr64 (Index, (AsmReadMsr64 (Index) & AndData) | OrData);\r
   )\r
 {\r
   return AsmWriteMsr64 (Index, (AsmReadMsr64 (Index) & AndData) | OrData);\r
@@ -471,9 +468,9 @@ AsmMsrAndThenOr64 (
 UINT64\r
 EFIAPI\r
 AsmMsrBitFieldRead64 (\r
 UINT64\r
 EFIAPI\r
 AsmMsrBitFieldRead64 (\r
-  IN      UINT32                    Index,\r
-  IN      UINTN                     StartBit,\r
-  IN      UINTN                     EndBit\r
+  IN      UINT32  Index,\r
+  IN      UINTN   StartBit,\r
+  IN      UINTN   EndBit\r
   )\r
 {\r
   return BitFieldRead64 (AsmReadMsr64 (Index), StartBit, EndBit);\r
   )\r
 {\r
   return BitFieldRead64 (AsmReadMsr64 (Index), StartBit, EndBit);\r
@@ -484,20 +481,21 @@ AsmMsrBitFieldRead64 (
 \r
   Writes Value to a bit field in a 64-bit MSR. The bit field is specified by\r
   the StartBit and the EndBit. All other bits in the destination MSR are\r
 \r
   Writes Value to a bit field in a 64-bit MSR. The bit field is specified by\r
   the StartBit and the EndBit. All other bits in the destination MSR are\r
-  preserved. The MSR written is returned. The caller must either guarantee \r
-  that Index and the data written is valid, or the caller must set up exception \r
+  preserved. The MSR written is returned. The caller must either guarantee\r
+  that Index and the data written is valid, or the caller must set up exception\r
   handlers to catch the exceptions. This function is only available on IA-32 and x64.\r
 \r
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
   handlers to catch the exceptions. This function is only available on IA-32 and x64.\r
 \r
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..63.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
                     Range 0..63.\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..63.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
                     Range 0..63.\r
-  @param  Value     New value of the bit field.\r
+  @param  Value     The new value of the bit field.\r
 \r
   @return The value written back to the MSR.\r
 \r
 \r
   @return The value written back to the MSR.\r
 \r
@@ -505,10 +503,10 @@ AsmMsrBitFieldRead64 (
 UINT64\r
 EFIAPI\r
 AsmMsrBitFieldWrite64 (\r
 UINT64\r
 EFIAPI\r
 AsmMsrBitFieldWrite64 (\r
-  IN      UINT32                    Index,\r
-  IN      UINTN                     StartBit,\r
-  IN      UINTN                     EndBit,\r
-  IN      UINT64                    Value\r
+  IN      UINT32  Index,\r
+  IN      UINTN   StartBit,\r
+  IN      UINTN   EndBit,\r
+  IN      UINT64  Value\r
   )\r
 {\r
   return AsmWriteMsr64 (\r
   )\r
 {\r
   return AsmWriteMsr64 (\r
@@ -532,6 +530,7 @@ AsmMsrBitFieldWrite64 (
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -546,10 +545,10 @@ AsmMsrBitFieldWrite64 (
 UINT64\r
 EFIAPI\r
 AsmMsrBitFieldOr64 (\r
 UINT64\r
 EFIAPI\r
 AsmMsrBitFieldOr64 (\r
-  IN      UINT32                    Index,\r
-  IN      UINTN                     StartBit,\r
-  IN      UINTN                     EndBit,\r
-  IN      UINT64                    OrData\r
+  IN      UINT32  Index,\r
+  IN      UINTN   StartBit,\r
+  IN      UINTN   EndBit,\r
+  IN      UINT64  OrData\r
   )\r
 {\r
   return AsmWriteMsr64 (\r
   )\r
 {\r
   return AsmWriteMsr64 (\r
@@ -573,6 +572,7 @@ AsmMsrBitFieldOr64 (
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -587,10 +587,10 @@ AsmMsrBitFieldOr64 (
 UINT64\r
 EFIAPI\r
 AsmMsrBitFieldAnd64 (\r
 UINT64\r
 EFIAPI\r
 AsmMsrBitFieldAnd64 (\r
-  IN      UINT32                    Index,\r
-  IN      UINTN                     StartBit,\r
-  IN      UINTN                     EndBit,\r
-  IN      UINT64                    AndData\r
+  IN      UINT32  Index,\r
+  IN      UINTN   StartBit,\r
+  IN      UINTN   EndBit,\r
+  IN      UINT64  AndData\r
   )\r
 {\r
   return AsmWriteMsr64 (\r
   )\r
 {\r
   return AsmWriteMsr64 (\r
@@ -615,6 +615,8 @@ AsmMsrBitFieldAnd64 (
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -630,11 +632,11 @@ AsmMsrBitFieldAnd64 (
 UINT64\r
 EFIAPI\r
 AsmMsrBitFieldAndThenOr64 (\r
 UINT64\r
 EFIAPI\r
 AsmMsrBitFieldAndThenOr64 (\r
-  IN      UINT32                    Index,\r
-  IN      UINTN                     StartBit,\r
-  IN      UINTN                     EndBit,\r
-  IN      UINT64                    AndData,\r
-  IN      UINT64                    OrData\r
+  IN      UINT32  Index,\r
+  IN      UINTN   StartBit,\r
+  IN      UINTN   EndBit,\r
+  IN      UINT64  AndData,\r
+  IN      UINT64  OrData\r
   )\r
 {\r
   return AsmWriteMsr64 (\r
   )\r
 {\r
   return AsmWriteMsr64 (\r