]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/CpuDxe/CpuPageTable.c
BaseTools: Library hashing fix and optimization for --hash feature
[mirror_edk2.git] / UefiCpuPkg / CpuDxe / CpuPageTable.c
index 0a980b97534edfb27d956fe6d01cf5fdc137500f..c369b44f128e70a3e49e94adf5b484782fecdfb9 100644 (file)
@@ -4,29 +4,16 @@
   Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
   Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>\r
 \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
-\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
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include <Base.h>\r
 #include <Uefi.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/CpuLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/PeCoffGetEntryPointLib.h>\r
 #include <Library/SerialPortLib.h>\r
 #include <Library/SynchronizationLib.h>\r
 #include <Library/PrintLib.h>\r
-#include <Protocol/MpService.h>\r
 #include <Protocol/SmmBase2.h>\r
 #include <Register/Cpuid.h>\r
 #include <Register/Msr.h>\r
@@ -107,6 +94,7 @@ PAGE_ATTRIBUTE_TABLE mPageAttributeTable[] = {
 };\r
 \r
 PAGE_TABLE_POOL                   *mPageTablePool = NULL;\r
+BOOLEAN                           mPageTablePoolLock = FALSE;\r
 PAGE_TABLE_LIB_PAGING_CONTEXT     mPagingContext;\r
 EFI_SMM_BASE2_PROTOCOL            *mSmmBase2 = NULL;\r
 \r
@@ -1053,6 +1041,16 @@ InitializePageTablePool (
   VOID                      *Buffer;\r
   BOOLEAN                   IsModified;\r
 \r
+  //\r
+  // Do not allow re-entrance.\r
+  //\r
+  if (mPageTablePoolLock) {\r
+    return FALSE;\r
+  }\r
+\r
+  mPageTablePoolLock = TRUE;\r
+  IsModified = FALSE;\r
+\r
   //\r
   // Always reserve at least PAGE_TABLE_POOL_UNIT_PAGES, including one page for\r
   // header.\r
@@ -1063,9 +1061,15 @@ InitializePageTablePool (
   Buffer = AllocateAlignedPages (PoolPages, PAGE_TABLE_POOL_ALIGNMENT);\r
   if (Buffer == NULL) {\r
     DEBUG ((DEBUG_ERROR, "ERROR: Out of aligned pages\r\n"));\r
-    return FALSE;\r
+    goto Done;\r
   }\r
 \r
+  DEBUG ((\r
+    DEBUG_INFO,\r
+    "Paging: added %lu pages to page table pool\r\n",\r
+    (UINT64)PoolPages\r
+    ));\r
+\r
   //\r
   // Link all pools into a list for easier track later.\r
   //\r
@@ -1099,7 +1103,9 @@ InitializePageTablePool (
     );\r
   ASSERT (IsModified == TRUE);\r
 \r
-  return TRUE;\r
+Done:\r
+  mPageTablePoolLock = FALSE;\r
+  return IsModified;\r
 }\r
 \r
 /**\r
@@ -1288,7 +1294,16 @@ PageFaultExceptionHandler (
   // Display ExceptionType, CPU information and Image information\r
   //\r
   DumpCpuContext (ExceptionType, SystemContext);\r
-  if (!NonStopMode) {\r
+  if (NonStopMode) {\r
+    //\r
+    // Set TF in EFLAGS\r
+    //\r
+    if (mPagingContext.MachineType == IMAGE_FILE_MACHINE_I386) {\r
+      SystemContext.SystemContextIa32->Eflags |= (UINT32)BIT8;\r
+    } else {\r
+      SystemContext.SystemContextX64->Rflags |= (UINT64)BIT8;\r
+    }\r
+  } else {\r
     CpuDeadLoop ();\r
   }\r
 }\r