]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/Ia32/GccInline.c
MdePkg: Clean up source files
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / GccInline.c
index 80db16c28bf0b9c5ce729d01ddeb70fafdcda7e3..05d7de3d95e76c35c17af07755e6533e77dc0b35 100644 (file)
@@ -1,12 +1,12 @@
 /** @file\r
   GCC inline implementation of BaseLib processor specific functions.\r
-  \r
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+\r
+  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
   Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
   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
+  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
@@ -32,7 +32,7 @@ MemoryFence (
   )\r
 {\r
   // This is a little bit of overkill and it is more about the compiler that it is\r
-  // actually processor synchronization. This is like the _ReadWriteBarrier \r
+  // actually processor synchronization. This is like the _ReadWriteBarrier\r
   // Microsoft specific intrinsic\r
   __asm__ __volatile__ ("":::"memory");\r
 }\r
@@ -65,7 +65,7 @@ EFIAPI
 DisableInterrupts (\r
   VOID\r
   )\r
-{  \r
+{\r
   __asm__ __volatile__ ("cli"::: "memory");\r
 }\r
 \r
@@ -128,13 +128,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 +168,7 @@ AsmWriteMsr64 (
     : "c" (Index),\r
       "A" (Value)\r
     );\r
-    \r
+\r
   return Value;\r
 }\r
 \r
@@ -191,13 +191,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 +220,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 +247,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 +273,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 +300,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 +431,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 +458,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 +485,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 +512,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 +539,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 +566,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 +593,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 +620,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 +854,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 +880,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 +906,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 +932,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 +958,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 +984,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 +1010,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 +1026,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 +1048,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 +1062,7 @@ InternalX86WriteGdtr (
     :\r
     : "m" (*Gdtr)\r
     );\r
-    \r
+\r
 }\r
 \r
 \r
@@ -1072,7 +1072,7 @@ 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
@@ -1094,7 +1094,7 @@ 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
@@ -1127,12 +1127,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 +1167,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 +1180,7 @@ InternalX86FxSave (
     "fxsave %0"\r
     :\r
     : "m" (*Buffer)  // %0\r
-    );    \r
+    );\r
 }\r
 \r
 \r
@@ -1191,7 +1191,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 +1233,7 @@ AsmReadMm0 (
     "pop  %%edx          \n\t"\r
     : "=A"  (Data)       // %0\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1263,7 +1263,7 @@ AsmReadMm1 (
     "pop  %%edx          \n\t"\r
     : "=A"  (Data)       // %0\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1293,7 +1293,7 @@ AsmReadMm2 (
     "pop  %%edx          \n\t"\r
     : "=A"  (Data)       // %0\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1323,7 +1323,7 @@ AsmReadMm3 (
     "pop  %%edx          \n\t"\r
     : "=A"  (Data)       // %0\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1353,7 +1353,7 @@ AsmReadMm4 (
     "pop  %%edx          \n\t"\r
     : "=A"  (Data)       // %0\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1383,7 +1383,7 @@ AsmReadMm5 (
     "pop  %%edx          \n\t"\r
     : "=A"  (Data)       // %0\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1413,7 +1413,7 @@ AsmReadMm6 (
     "pop  %%edx          \n\t"\r
     : "=A"  (Data)       // %0\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1443,7 +1443,7 @@ AsmReadMm7 (
     "pop  %%edx          \n\t"\r
     : "=A"  (Data)       // %0\r
     );\r
-    \r
+\r
   return Data;\r
 }\r
 \r
@@ -1465,7 +1465,7 @@ AsmWriteMm0 (
 {\r
   __asm__ __volatile__ (\r
     "movq %0, %%mm0"  // %0\r
-    :  \r
+    :\r
     : "m" (Value)\r
     );\r
 }\r
@@ -1488,7 +1488,7 @@ AsmWriteMm1 (
 {\r
   __asm__ __volatile__ (\r
     "movq %0, %%mm1"  // %0\r
-    :  \r
+    :\r
     : "m" (Value)\r
     );\r
 }\r
@@ -1511,7 +1511,7 @@ AsmWriteMm2 (
 {\r
   __asm__ __volatile__ (\r
     "movq %0, %%mm2"  // %0\r
-    :  \r
+    :\r
     : "m" (Value)\r
     );\r
 }\r
@@ -1534,7 +1534,7 @@ AsmWriteMm3 (
 {\r
   __asm__ __volatile__ (\r
     "movq %0, %%mm3"  // %0\r
-    :  \r
+    :\r
     : "m" (Value)\r
     );\r
 }\r
@@ -1557,7 +1557,7 @@ AsmWriteMm4 (
 {\r
   __asm__ __volatile__ (\r
     "movq %0, %%mm4"  // %0\r
-    :  \r
+    :\r
     : "m" (Value)\r
     );\r
 }\r
@@ -1580,7 +1580,7 @@ AsmWriteMm5 (
 {\r
   __asm__ __volatile__ (\r
     "movq %0, %%mm5"  // %0\r
-    :  \r
+    :\r
     : "m" (Value)\r
     );\r
 }\r
@@ -1603,7 +1603,7 @@ AsmWriteMm6 (
 {\r
   __asm__ __volatile__ (\r
     "movq %0, %%mm6"  // %0\r
-    :  \r
+    :\r
     : "m" (Value)\r
     );\r
 }\r
@@ -1626,7 +1626,7 @@ AsmWriteMm7 (
 {\r
   __asm__ __volatile__ (\r
     "movq %0, %%mm7"  // %0\r
-    :  \r
+    :\r
     : "m" (Value)\r
     );\r
 }\r
@@ -1648,13 +1648,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 +1676,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 +1720,7 @@ AsmInvd (
   )\r
 {\r
   __asm__ __volatile__ ("invd":::"memory");\r
-    \r
+\r
 }\r
 \r
 \r
@@ -1745,14 +1745,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