]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/Ia32/GccInline.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / GccInline.c
index fcb0665866eafda1829c4ddd33bfad06f66ac457..5287200f8754f4f7957a050aff28b75f130533ea 100644 (file)
@@ -1,15 +1,9 @@
 /** @file\r
   GCC inline implementation of BaseLib processor specific functions.\r
-  \r
-  Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
-  Portions copyright (c) 2008-2009 Apple Inc. All rights reserved.<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
+  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -32,8 +26,8 @@ MemoryFence (
   )\r
 {\r
   // This is a little bit of overkill and it is more about the compiler that it is\r
-  // actually processor syncronization. This is like the _ReadWriteBarrier \r
-  // Microsft specific intrinsic\r
+  // actually processor synchronization. This is like the _ReadWriteBarrier\r
+  // Microsoft specific intrinsic\r
   __asm__ __volatile__ ("":::"memory");\r
 }\r
 \r
@@ -65,7 +59,7 @@ EFIAPI
 DisableInterrupts (\r
   VOID\r
   )\r
-{  \r
+{\r
   __asm__ __volatile__ ("cli"::: "memory");\r
 }\r
 \r
@@ -128,13 +122,13 @@ AsmReadMsr64 (
   )\r
 {\r
   UINT64 Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "rdmsr"\r
     : "=A" (Data)   // %0\r
     : "c"  (Index)  // %1\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -168,7 +162,7 @@ AsmWriteMsr64 (
     : "c" (Index),\r
       "A" (Value)\r
     );\r
-    \r
+\r
   return Value;\r
 }\r
 \r
@@ -191,13 +185,13 @@ AsmReadEflags (
   )\r
 {\r
   UINTN Eflags;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "pushfl     \n\t"\r
     "popl %0        "\r
     : "=r" (Eflags)\r
     );\r
-    \r
+\r
   return Eflags;\r
 }\r
 \r
@@ -220,12 +214,12 @@ AsmReadCr0 (
   )\r
 {\r
   UINTN   Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
-    "movl %%cr0,%0" \r
+    "movl %%cr0,%0"\r
     : "=a" (Data)\r
     );\r
-  \r
+\r
   return Data;\r
 }\r
 \r
@@ -247,12 +241,12 @@ AsmReadCr2 (
   )\r
 {\r
   UINTN Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
-    "movl %%cr2, %0" \r
+    "movl %%cr2, %0"\r
     : "=r" (Data)\r
     );\r
-  \r
+\r
   return Data;\r
 }\r
 \r
@@ -273,12 +267,12 @@ AsmReadCr3 (
   )\r
 {\r
   UINTN Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "movl %%cr3, %0"\r
     : "=r" (Data)\r
     );\r
-  \r
+\r
   return Data;\r
 }\r
 \r
@@ -300,12 +294,12 @@ AsmReadCr4 (
   )\r
 {\r
   UINTN Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "movl %%cr4, %0"\r
     : "=a" (Data)\r
     );\r
-  \r
+\r
   return Data;\r
 }\r
 \r
@@ -431,12 +425,12 @@ AsmReadDr0 (
   )\r
 {\r
   UINTN Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "movl %%dr0, %0"\r
     : "=r" (Data)\r
     );\r
-  \r
+\r
   return Data;\r
 }\r
 \r
@@ -458,12 +452,12 @@ AsmReadDr1 (
   )\r
 {\r
   UINTN Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "movl %%dr1, %0"\r
     : "=r" (Data)\r
     );\r
-  \r
+\r
   return Data;\r
 }\r
 \r
@@ -485,12 +479,12 @@ AsmReadDr2 (
   )\r
 {\r
   UINTN Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "movl %%dr2, %0"\r
     : "=r" (Data)\r
     );\r
-  \r
+\r
   return Data;\r
 }\r
 \r
@@ -512,12 +506,12 @@ AsmReadDr3 (
   )\r
 {\r
   UINTN Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "movl %%dr3, %0"\r
     : "=r" (Data)\r
     );\r
-  \r
+\r
   return Data;\r
 }\r
 \r
@@ -539,12 +533,12 @@ AsmReadDr4 (
   )\r
 {\r
   UINTN Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "movl %%dr4, %0"\r
     : "=r" (Data)\r
     );\r
-  \r
+\r
   return Data;\r
 }\r
 \r
@@ -566,12 +560,12 @@ AsmReadDr5 (
   )\r
 {\r
   UINTN Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "movl %%dr5, %0"\r
     : "=r" (Data)\r
     );\r
-  \r
+\r
   return Data;\r
 }\r
 \r
@@ -593,12 +587,12 @@ AsmReadDr6 (
   )\r
 {\r
   UINTN Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "movl %%dr6, %0"\r
     : "=r" (Data)\r
     );\r
-  \r
+\r
   return Data;\r
 }\r
 \r
@@ -620,12 +614,12 @@ AsmReadDr7 (
   )\r
 {\r
   UINTN Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "movl %%dr7, %0"\r
     : "=r" (Data)\r
     );\r
-  \r
+\r
   return Data;\r
 }\r
 \r
@@ -854,12 +848,12 @@ AsmReadCs (
   )\r
 {\r
   UINT16  Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "mov   %%cs, %0"\r
     :"=a" (Data)\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -880,12 +874,12 @@ AsmReadDs (
   )\r
 {\r
   UINT16  Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "mov  %%ds, %0"\r
     :"=a" (Data)\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -906,12 +900,12 @@ AsmReadEs (
   )\r
 {\r
   UINT16  Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "mov  %%es, %0"\r
     :"=a" (Data)\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -932,12 +926,12 @@ AsmReadFs (
   )\r
 {\r
   UINT16  Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "mov  %%fs, %0"\r
     :"=a" (Data)\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -958,12 +952,12 @@ AsmReadGs (
   )\r
 {\r
   UINT16  Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "mov  %%gs, %0"\r
     :"=a" (Data)\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -984,12 +978,12 @@ AsmReadSs (
   )\r
 {\r
   UINT16  Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "mov  %%ds, %0"\r
     :"=a" (Data)\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1010,12 +1004,12 @@ AsmReadTr (
   )\r
 {\r
   UINT16  Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "str  %0"\r
     : "=a" (Data)\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1026,7 +1020,7 @@ AsmReadTr (
   Reads and returns the current GDTR descriptor and returns it in Gdtr. This\r
   function is only available on IA-32 and X64.\r
 \r
-  @param  Gdtr  Pointer to a GDTR descriptor.\r
+  @param  Gdtr  The pointer to a GDTR descriptor.\r
 \r
 **/\r
 VOID\r
@@ -1048,7 +1042,7 @@ InternalX86ReadGdtr (
   Writes and the current GDTR descriptor specified by Gdtr. This function is\r
   only available on IA-32 and X64.\r
 \r
-  @param  Gdtr  Pointer to a GDTR descriptor.\r
+  @param  Gdtr  The pointer to a GDTR descriptor.\r
 \r
 **/\r
 VOID\r
@@ -1062,7 +1056,7 @@ InternalX86WriteGdtr (
     :\r
     : "m" (*Gdtr)\r
     );\r
-    \r
+\r
 }\r
 \r
 \r
@@ -1072,18 +1066,18 @@ InternalX86WriteGdtr (
   Reads and returns the current IDTR descriptor and returns it in Idtr. This\r
   function is only available on IA-32 and X64.\r
 \r
-  @param  Idtr  Pointer to a IDTR descriptor.\r
+  @param  Idtr  The pointer to a IDTR descriptor.\r
 \r
 **/\r
 VOID\r
 EFIAPI\r
 InternalX86ReadIdtr (\r
-  OUT     IA32_DESCRIPTOR           *Ldtr\r
+  OUT     IA32_DESCRIPTOR           *Idtr\r
   )\r
 {\r
   __asm__ __volatile__ (\r
-    "sldt  %0"\r
-    : "=m" (*Ldtr)\r
+    "sidt  %0"\r
+    : "=m" (*Idtr)\r
     );\r
 }\r
 \r
@@ -1094,19 +1088,19 @@ InternalX86ReadIdtr (
   Writes the current IDTR descriptor and returns it in Idtr. This function is\r
   only available on IA-32 and X64.\r
 \r
-  @param  Idtr  Pointer to a IDTR descriptor.\r
+  @param  Idtr  The pointer to a IDTR descriptor.\r
 \r
 **/\r
 VOID\r
 EFIAPI\r
 InternalX86WriteIdtr (\r
-  IN      CONST IA32_DESCRIPTOR     *Ldtr\r
+  IN      CONST IA32_DESCRIPTOR     *Idtr\r
   )\r
 {\r
   __asm__ __volatile__ (\r
     "lidt %0"\r
     :\r
-    : "m" (*Ldtr)\r
+    : "m" (*Idtr)\r
     );\r
 }\r
 \r
@@ -1127,12 +1121,12 @@ AsmReadLdtr (
   )\r
 {\r
   UINT16  Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "sldt  %0"\r
     : "=g" (Data)   // %0\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1167,7 +1161,7 @@ AsmWriteLdtr (
   Buffer. Buffer must be aligned on a 16-byte boundary. This function is only\r
   available on IA-32 and X64.\r
 \r
-  @param  Buffer  Pointer to a buffer to save the floating point/SSE/SSE2 context.\r
+  @param  Buffer  The pointer to a buffer to save the floating point/SSE/SSE2 context.\r
 \r
 **/\r
 VOID\r
@@ -1180,7 +1174,7 @@ InternalX86FxSave (
     "fxsave %0"\r
     :\r
     : "m" (*Buffer)  // %0\r
-    );    \r
+    );\r
 }\r
 \r
 \r
@@ -1191,7 +1185,7 @@ InternalX86FxSave (
   by Buffer. Buffer must be aligned on a 16-byte boundary. This function is\r
   only available on IA-32 and X64.\r
 \r
-  @param  Buffer  Pointer to a buffer to save the floating point/SSE/SSE2 context.\r
+  @param  Buffer  The pointer to a buffer to save the floating point/SSE/SSE2 context.\r
 \r
 **/\r
 VOID\r
@@ -1233,7 +1227,7 @@ AsmReadMm0 (
     "pop  %%edx          \n\t"\r
     : "=A"  (Data)       // %0\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1263,7 +1257,7 @@ AsmReadMm1 (
     "pop  %%edx          \n\t"\r
     : "=A"  (Data)       // %0\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1293,7 +1287,7 @@ AsmReadMm2 (
     "pop  %%edx          \n\t"\r
     : "=A"  (Data)       // %0\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1323,7 +1317,7 @@ AsmReadMm3 (
     "pop  %%edx          \n\t"\r
     : "=A"  (Data)       // %0\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1353,7 +1347,7 @@ AsmReadMm4 (
     "pop  %%edx          \n\t"\r
     : "=A"  (Data)       // %0\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1383,7 +1377,7 @@ AsmReadMm5 (
     "pop  %%edx          \n\t"\r
     : "=A"  (Data)       // %0\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1413,7 +1407,7 @@ AsmReadMm6 (
     "pop  %%edx          \n\t"\r
     : "=A"  (Data)       // %0\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1443,7 +1437,7 @@ AsmReadMm7 (
     "pop  %%edx          \n\t"\r
     : "=A"  (Data)       // %0\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1465,7 +1459,7 @@ AsmWriteMm0 (
 {\r
   __asm__ __volatile__ (\r
     "movq %0, %%mm0"  // %0\r
-    :  \r
+    :\r
     : "m" (Value)\r
     );\r
 }\r
@@ -1488,7 +1482,7 @@ AsmWriteMm1 (
 {\r
   __asm__ __volatile__ (\r
     "movq %0, %%mm1"  // %0\r
-    :  \r
+    :\r
     : "m" (Value)\r
     );\r
 }\r
@@ -1511,7 +1505,7 @@ AsmWriteMm2 (
 {\r
   __asm__ __volatile__ (\r
     "movq %0, %%mm2"  // %0\r
-    :  \r
+    :\r
     : "m" (Value)\r
     );\r
 }\r
@@ -1534,7 +1528,7 @@ AsmWriteMm3 (
 {\r
   __asm__ __volatile__ (\r
     "movq %0, %%mm3"  // %0\r
-    :  \r
+    :\r
     : "m" (Value)\r
     );\r
 }\r
@@ -1557,7 +1551,7 @@ AsmWriteMm4 (
 {\r
   __asm__ __volatile__ (\r
     "movq %0, %%mm4"  // %0\r
-    :  \r
+    :\r
     : "m" (Value)\r
     );\r
 }\r
@@ -1580,7 +1574,7 @@ AsmWriteMm5 (
 {\r
   __asm__ __volatile__ (\r
     "movq %0, %%mm5"  // %0\r
-    :  \r
+    :\r
     : "m" (Value)\r
     );\r
 }\r
@@ -1603,7 +1597,7 @@ AsmWriteMm6 (
 {\r
   __asm__ __volatile__ (\r
     "movq %0, %%mm6"  // %0\r
-    :  \r
+    :\r
     : "m" (Value)\r
     );\r
 }\r
@@ -1626,7 +1620,7 @@ AsmWriteMm7 (
 {\r
   __asm__ __volatile__ (\r
     "movq %0, %%mm7"  // %0\r
-    :  \r
+    :\r
     : "m" (Value)\r
     );\r
 }\r
@@ -1648,13 +1642,13 @@ AsmReadTsc (
   )\r
 {\r
   UINT64  Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "rdtsc"\r
     : "=A" (Data)\r
     );\r
-  \r
-  return Data;  \r
+\r
+  return Data;\r
 }\r
 \r
 \r
@@ -1676,14 +1670,14 @@ AsmReadPmc (
   )\r
 {\r
   UINT64  Data;\r
-  \r
+\r
   __asm__ __volatile__ (\r
     "rdpmc"\r
     : "=A" (Data)\r
     : "c"  (Index)\r
     );\r
-  \r
-  return Data;  \r
+\r
+  return Data;\r
 }\r
 \r
 \r
@@ -1720,7 +1714,7 @@ AsmInvd (
   )\r
 {\r
   __asm__ __volatile__ ("invd":::"memory");\r
-    \r
+\r
 }\r
 \r
 \r
@@ -1745,14 +1739,27 @@ AsmFlushCacheLine (
   IN      VOID                      *LinearAddress\r
   )\r
 {\r
+  UINT32  RegEdx;\r
+\r
+  //\r
+  // If the CPU does not support CLFLUSH instruction,\r
+  // then promote flush range to flush entire cache.\r
+  //\r
+  AsmCpuid (0x01, NULL, NULL, NULL, &RegEdx);\r
+  if ((RegEdx & BIT19) == 0) {\r
+    __asm__ __volatile__ ("wbinvd":::"memory");\r
+    return LinearAddress;\r
+  }\r
+\r
+\r
   __asm__ __volatile__ (\r
     "clflush (%0)"\r
-    : "+a" (LinearAddress) \r
-    : \r
+    : "+a" (LinearAddress)\r
+    :\r
     : "memory"\r
     );\r
-    \r
-    return LinearAddress;\r
+\r
+  return LinearAddress;\r
 }\r
 \r
 \r