]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c
UefiCpuPkg: Apply uncrustify changes
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / Ia32 / PageTbl.c
index 9c8e2d15ac46a9d2bf3e153d959273682db53b34..8ec8790c05b690a06ad163e8b568d5a4d1c44c45 100644 (file)
@@ -36,13 +36,13 @@ EnableCet (
 **/\r
 VOID\r
 GetPageTable (\r
-  OUT UINTN   *Base,\r
-  OUT BOOLEAN *FiveLevels OPTIONAL\r
+  OUT UINTN    *Base,\r
+  OUT BOOLEAN  *FiveLevels OPTIONAL\r
   )\r
 {\r
   *Base = ((mInternalCr3 == 0) ?\r
-            (AsmReadCr3 () & PAGING_4K_ADDRESS_MASK_64) :\r
-            mInternalCr3);\r
+           (AsmReadCr3 () & PAGING_4K_ADDRESS_MASK_64) :\r
+           mInternalCr3);\r
   if (FiveLevels != NULL) {\r
     *FiveLevels = FALSE;\r
   }\r
@@ -59,9 +59,9 @@ SmmInitPageTable (
   VOID\r
   )\r
 {\r
-  UINTN                             PageFaultHandlerHookAddress;\r
-  IA32_IDT_GATE_DESCRIPTOR          *IdtEntry;\r
-  EFI_STATUS                        Status;\r
+  UINTN                     PageFaultHandlerHookAddress;\r
+  IA32_IDT_GATE_DESCRIPTOR  *IdtEntry;\r
+  EFI_STATUS                Status;\r
 \r
   //\r
   // Initialize spin lock\r
@@ -72,18 +72,19 @@ SmmInitPageTable (
 \r
   if (FeaturePcdGet (PcdCpuSmmProfileEnable) ||\r
       HEAP_GUARD_NONSTOP_MODE ||\r
-      NULL_DETECTION_NONSTOP_MODE) {\r
+      NULL_DETECTION_NONSTOP_MODE)\r
+  {\r
     //\r
     // Set own Page Fault entry instead of the default one, because SMM Profile\r
     // feature depends on IRET instruction to do Single Step\r
     //\r
     PageFaultHandlerHookAddress = (UINTN)PageFaultIdtHandlerSmmProfile;\r
-    IdtEntry  = (IA32_IDT_GATE_DESCRIPTOR *) gcSmiIdtr.Base;\r
-    IdtEntry += EXCEPT_IA32_PAGE_FAULT;\r
-    IdtEntry->Bits.OffsetLow      = (UINT16)PageFaultHandlerHookAddress;\r
-    IdtEntry->Bits.Reserved_0     = 0;\r
-    IdtEntry->Bits.GateType       = IA32_IDT_GATE_TYPE_INTERRUPT_32;\r
-    IdtEntry->Bits.OffsetHigh     = (UINT16)(PageFaultHandlerHookAddress >> 16);\r
+    IdtEntry                    = (IA32_IDT_GATE_DESCRIPTOR *)gcSmiIdtr.Base;\r
+    IdtEntry                   += EXCEPT_IA32_PAGE_FAULT;\r
+    IdtEntry->Bits.OffsetLow    = (UINT16)PageFaultHandlerHookAddress;\r
+    IdtEntry->Bits.Reserved_0   = 0;\r
+    IdtEntry->Bits.GateType     = IA32_IDT_GATE_TYPE_INTERRUPT_32;\r
+    IdtEntry->Bits.OffsetHigh   = (UINT16)(PageFaultHandlerHookAddress >> 16);\r
   } else {\r
     //\r
     // Register SMM Page Fault Handler\r
@@ -98,6 +99,7 @@ SmmInitPageTable (
   if (FeaturePcdGet (PcdCpuSmmStackGuard)) {\r
     InitializeIDTSmmStackGuard ();\r
   }\r
+\r
   return Gen4GPageTable (TRUE);\r
 }\r
 \r
@@ -124,13 +126,13 @@ SmiDefaultPFHandler (
 VOID\r
 EFIAPI\r
 SmiPFHandler (\r
-  IN EFI_EXCEPTION_TYPE   InterruptType,\r
-  IN EFI_SYSTEM_CONTEXT   SystemContext\r
+  IN EFI_EXCEPTION_TYPE  InterruptType,\r
+  IN EFI_SYSTEM_CONTEXT  SystemContext\r
   )\r
 {\r
-  UINTN             PFAddress;\r
-  UINTN             GuardPageAddress;\r
-  UINTN             CpuIndex;\r
+  UINTN  PFAddress;\r
+  UINTN  GuardPageAddress;\r
+  UINTN  CpuIndex;\r
 \r
   ASSERT (InterruptType == EXCEPT_IA32_PAGE_FAULT);\r
 \r
@@ -143,25 +145,27 @@ SmiPFHandler (
   // or SMM page protection violation.\r
   //\r
   if ((PFAddress >= mCpuHotPlugData.SmrrBase) &&\r
-      (PFAddress < (mCpuHotPlugData.SmrrBase + mCpuHotPlugData.SmrrSize))) {\r
+      (PFAddress < (mCpuHotPlugData.SmrrBase + mCpuHotPlugData.SmrrSize)))\r
+  {\r
     DumpCpuContext (InterruptType, SystemContext);\r
-    CpuIndex = GetCpuIndex ();\r
+    CpuIndex         = GetCpuIndex ();\r
     GuardPageAddress = (mSmmStackArrayBase + EFI_PAGE_SIZE + CpuIndex * mSmmStackSize);\r
     if ((FeaturePcdGet (PcdCpuSmmStackGuard)) &&\r
         (PFAddress >= GuardPageAddress) &&\r
-        (PFAddress < (GuardPageAddress + EFI_PAGE_SIZE))) {\r
+        (PFAddress < (GuardPageAddress + EFI_PAGE_SIZE)))\r
+    {\r
       DEBUG ((DEBUG_ERROR, "SMM stack overflow!\n"));\r
     } else {\r
       if ((SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_ID) != 0) {\r
         DEBUG ((DEBUG_ERROR, "SMM exception at execution (0x%x)\n", PFAddress));\r
         DEBUG_CODE (\r
           DumpModuleInfoByIp (*(UINTN *)(UINTN)SystemContext.SystemContextIa32->Esp);\r
-        );\r
+          );\r
       } else {\r
         DEBUG ((DEBUG_ERROR, "SMM exception at access (0x%x)\n", PFAddress));\r
         DEBUG_CODE (\r
           DumpModuleInfoByIp ((UINTN)SystemContext.SystemContextIa32->Eip);\r
-        );\r
+          );\r
       }\r
 \r
       if (HEAP_GUARD_NONSTOP_MODE) {\r
@@ -169,6 +173,7 @@ SmiPFHandler (
         goto Exit;\r
       }\r
     }\r
+\r
     CpuDeadLoop ();\r
     goto Exit;\r
   }\r
@@ -177,13 +182,14 @@ SmiPFHandler (
   // If a page fault occurs in non-SMRAM range.\r
   //\r
   if ((PFAddress < mCpuHotPlugData.SmrrBase) ||\r
-      (PFAddress >= mCpuHotPlugData.SmrrBase + mCpuHotPlugData.SmrrSize)) {\r
+      (PFAddress >= mCpuHotPlugData.SmrrBase + mCpuHotPlugData.SmrrSize))\r
+  {\r
     if ((SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_ID) != 0) {\r
       DumpCpuContext (InterruptType, SystemContext);\r
       DEBUG ((DEBUG_ERROR, "Code executed on IP(0x%x) out of SMM range after SMM is locked!\n", PFAddress));\r
       DEBUG_CODE (\r
         DumpModuleInfoByIp (*(UINTN *)(UINTN)SystemContext.SystemContextIa32->Esp);\r
-      );\r
+        );\r
       CpuDeadLoop ();\r
       goto Exit;\r
     }\r
@@ -191,13 +197,14 @@ SmiPFHandler (
     //\r
     // If NULL pointer was just accessed\r
     //\r
-    if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT1) != 0 &&\r
-        (PFAddress < EFI_PAGE_SIZE)) {\r
+    if (((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT1) != 0) &&\r
+        (PFAddress < EFI_PAGE_SIZE))\r
+    {\r
       DumpCpuContext (InterruptType, SystemContext);\r
       DEBUG ((DEBUG_ERROR, "!!! NULL pointer access !!!\n"));\r
       DEBUG_CODE (\r
         DumpModuleInfoByIp ((UINTN)SystemContext.SystemContextIa32->Eip);\r
-      );\r
+        );\r
 \r
       if (NULL_DETECTION_NONSTOP_MODE) {\r
         GuardPagePFHandler (SystemContext.SystemContextIa32->ExceptionData);\r
@@ -213,7 +220,7 @@ SmiPFHandler (
       DEBUG ((DEBUG_ERROR, "Access SMM communication forbidden address (0x%x)!\n", PFAddress));\r
       DEBUG_CODE (\r
         DumpModuleInfoByIp ((UINTN)SystemContext.SystemContextIa32->Eip);\r
-      );\r
+        );\r
       CpuDeadLoop ();\r
       goto Exit;\r
     }\r
@@ -241,15 +248,15 @@ SetPageTableAttributes (
   VOID\r
   )\r
 {\r
-  UINTN                 Index2;\r
-  UINTN                 Index3;\r
-  UINT64                *L1PageTable;\r
-  UINT64                *L2PageTable;\r
-  UINT64                *L3PageTable;\r
-  UINTN                 PageTableBase;\r
-  BOOLEAN               IsSplitted;\r
-  BOOLEAN               PageTableSplitted;\r
-  BOOLEAN               CetEnabled;\r
+  UINTN    Index2;\r
+  UINTN    Index3;\r
+  UINT64   *L1PageTable;\r
+  UINT64   *L2PageTable;\r
+  UINT64   *L3PageTable;\r
+  UINTN    PageTableBase;\r
+  BOOLEAN  IsSplitted;\r
+  BOOLEAN  PageTableSplitted;\r
+  BOOLEAN  CetEnabled;\r
 \r
   //\r
   // Don't mark page table to read-only if heap guard is enabled.\r
@@ -259,7 +266,7 @@ SetPageTableAttributes (
   //\r
   if ((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT3 | BIT2)) != 0) {\r
     DEBUG ((DEBUG_INFO, "Don't mark page table to read-only as heap guard is enabled\n"));\r
-    return ;\r
+    return;\r
   }\r
 \r
   //\r
@@ -267,7 +274,7 @@ SetPageTableAttributes (
   //\r
   if (FeaturePcdGet (PcdCpuSmmProfileEnable)) {\r
     DEBUG ((DEBUG_INFO, "Don't mark page table to read-only as SMM profile is enabled\n"));\r
-    return ;\r
+    return;\r
   }\r
 \r
   DEBUG ((DEBUG_INFO, "SetPageTableAttributes\n"));\r
@@ -276,14 +283,15 @@ SetPageTableAttributes (
   // Disable write protection, because we need mark page table to be write protected.\r
   // We need *write* page table memory, to mark itself to be *read only*.\r
   //\r
-  CetEnabled = ((AsmReadCr4() & CR4_CET_ENABLE) != 0) ? TRUE : FALSE;\r
+  CetEnabled = ((AsmReadCr4 () & CR4_CET_ENABLE) != 0) ? TRUE : FALSE;\r
   if (CetEnabled) {\r
     //\r
     // CET must be disabled if WP is disabled.\r
     //\r
-    DisableCet();\r
+    DisableCet ();\r
   }\r
-  AsmWriteCr0 (AsmReadCr0() & ~CR0_WP);\r
+\r
+  AsmWriteCr0 (AsmReadCr0 () & ~CR0_WP);\r
 \r
   do {\r
     DEBUG ((DEBUG_INFO, "Start...\n"));\r
@@ -304,15 +312,17 @@ SetPageTableAttributes (
       SmmSetMemoryAttributesEx ((EFI_PHYSICAL_ADDRESS)(UINTN)L2PageTable, SIZE_4KB, EFI_MEMORY_RO, &IsSplitted);\r
       PageTableSplitted = (PageTableSplitted || IsSplitted);\r
 \r
-      for (Index2 = 0; Index2 < SIZE_4KB/sizeof(UINT64); Index2++) {\r
+      for (Index2 = 0; Index2 < SIZE_4KB/sizeof (UINT64); Index2++) {\r
         if ((L2PageTable[Index2] & IA32_PG_PS) != 0) {\r
           // 2M\r
           continue;\r
         }\r
+\r
         L1PageTable = (UINT64 *)(UINTN)(L2PageTable[Index2] & ~mAddressEncMask & PAGING_4K_ADDRESS_MASK_64);\r
         if (L1PageTable == NULL) {\r
           continue;\r
         }\r
+\r
         SmmSetMemoryAttributesEx ((EFI_PHYSICAL_ADDRESS)(UINTN)L1PageTable, SIZE_4KB, EFI_MEMORY_RO, &IsSplitted);\r
         PageTableSplitted = (PageTableSplitted || IsSplitted);\r
       }\r
@@ -322,15 +332,15 @@ SetPageTableAttributes (
   //\r
   // Enable write protection, after page table updated.\r
   //\r
-  AsmWriteCr0 (AsmReadCr0() | CR0_WP);\r
+  AsmWriteCr0 (AsmReadCr0 () | CR0_WP);\r
   if (CetEnabled) {\r
     //\r
     // re-enable CET.\r
     //\r
-    EnableCet();\r
+    EnableCet ();\r
   }\r
 \r
-  return ;\r
+  return;\r
 }\r
 \r
 /**\r
@@ -343,7 +353,7 @@ SaveCr2 (
   OUT UINTN  *Cr2\r
   )\r
 {\r
-  return ;\r
+  return;\r
 }\r
 \r
 /**\r
@@ -356,7 +366,7 @@ RestoreCr2 (
   IN UINTN  Cr2\r
   )\r
 {\r
-  return ;\r
+  return;\r
 }\r
 \r
 /**\r