]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c
IntelFrameworkModulePkg/LegacyBios: Use macro to enable/disable page 0
[mirror_edk2.git] / IntelFrameworkModulePkg / Csm / LegacyBiosDxe / LegacyBios.c
index dd2e2b9167c72c009c30ddcbe2b5519799c5a459..fca08a8fa26d4be275576f8b6156290f96a9e5fc 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
 \r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions\r
@@ -40,6 +40,7 @@ VOID                  *mRuntimeSmbiosEntryPoint = NULL;
 EFI_PHYSICAL_ADDRESS  mReserveSmbiosEntryPoint = 0;\r
 EFI_PHYSICAL_ADDRESS  mStructureTableAddress   = 0;\r
 UINTN                 mStructureTablePages     = 0;\r
+BOOLEAN               mEndOfDxe                = FALSE;\r
 \r
 /**\r
   Do an AllocatePages () of type AllocateMaxAddress for EfiBootServicesCode\r
@@ -144,7 +145,7 @@ LegacyBiosGetLegacyRegion (
      );\r
 \r
   if (Regs.X.AX == 0) {\r
-    *LegacyMemoryAddress  = (VOID *) (UINTN) ((Regs.X.DS << 4) + Regs.X.BX);\r
+    *LegacyMemoryAddress  = (VOID *) (((UINTN) Regs.X.DS << 4) + Regs.X.BX);\r
     Status = EFI_SUCCESS;\r
   } else {\r
     Status = EFI_OUT_OF_RESOURCES;\r
@@ -728,7 +729,7 @@ InstallSmbiosEventCallback (
   }\r
   \r
   if ((mStructureTableAddress != 0) && \r
-      (mStructureTablePages < (UINTN) EFI_SIZE_TO_PAGES (EntryPointStructure->TableLength))) {\r
+      (mStructureTablePages < EFI_SIZE_TO_PAGES ((UINT32)EntryPointStructure->TableLength))) {\r
     //\r
     // If original buffer is not enough for the new SMBIOS table, free original buffer and re-allocate\r
     //\r
@@ -765,6 +766,26 @@ InstallSmbiosEventCallback (
   }\r
 }\r
 \r
+/**\r
+  Callback function to toggle EndOfDxe status. NULL pointer detection needs\r
+  this status to decide if it's necessary to change attributes of page 0.\r
+\r
+  @param  Event            Event whose notification function is being invoked.\r
+  @param  Context          The pointer to the notification function's context,\r
+                           which is implementation-dependent.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+ToggleEndOfDxeStatus (\r
+  IN EFI_EVENT                Event,\r
+  IN VOID                     *Context\r
+  )\r
+{\r
+  mEndOfDxe = TRUE;\r
+  return;\r
+}\r
+\r
 /**\r
   Install Driver to produce Legacy BIOS protocol.\r
 \r
@@ -802,6 +823,7 @@ LegacyBiosInstall (
   UINT64                             Length;\r
   UINT8                              *SecureBoot;\r
   EFI_EVENT                          InstallSmbiosEvent;\r
+  EFI_EVENT                          EndOfDxeEvent;\r
 \r
   //\r
   // Load this driver's image to memory\r
@@ -964,8 +986,10 @@ LegacyBiosInstall (
   // Initialize region from 0x0000 to 4k. This initializes interrupt vector\r
   // range.\r
   //\r
-  gBS->SetMem ((VOID *) ClearPtr, 0x400, INITIAL_VALUE_BELOW_1K);\r
-  ZeroMem ((VOID *) ((UINTN)ClearPtr + 0x400), 0xC00);\r
+  ACCESS_PAGE0_CODE (\r
+    gBS->SetMem ((VOID *) ClearPtr, 0x400, INITIAL_VALUE_BELOW_1K);\r
+    ZeroMem ((VOID *) ((UINTN)ClearPtr + 0x400), 0xC00);\r
+  );\r
 \r
   //\r
   // Allocate pages for OPROM usage\r
@@ -1104,12 +1128,15 @@ LegacyBiosInstall (
   //\r
   // Save Unexpected interrupt vector so can restore it just prior to boot\r
   //\r
-  BaseVectorMaster = (UINT32 *) (sizeof (UINT32) * PROTECTED_MODE_BASE_VECTOR_MASTER);\r
-  Private->BiosUnexpectedInt = BaseVectorMaster[0];\r
-  IntRedirCode = (UINT32) (UINTN) Private->IntThunk->InterruptRedirectionCode;\r
-  for (Index = 0; Index < 8; Index++) {\r
-    BaseVectorMaster[Index] = (EFI_SEGMENT (IntRedirCode + Index * 4) << 16) | EFI_OFFSET (IntRedirCode + Index * 4);\r
-  }\r
+  ACCESS_PAGE0_CODE (\r
+    BaseVectorMaster = (UINT32 *) (sizeof (UINT32) * PROTECTED_MODE_BASE_VECTOR_MASTER);\r
+    Private->BiosUnexpectedInt = BaseVectorMaster[0];\r
+    IntRedirCode = (UINT32) (UINTN) Private->IntThunk->InterruptRedirectionCode;\r
+    for (Index = 0; Index < 8; Index++) {\r
+      BaseVectorMaster[Index] = (EFI_SEGMENT (IntRedirCode + Index * 4) << 16) | EFI_OFFSET (IntRedirCode + Index * 4);\r
+    }\r
+  );\r
+\r
   //\r
   // Save EFI value\r
   //\r
@@ -1133,6 +1160,20 @@ LegacyBiosInstall (
                   );\r
   ASSERT_EFI_ERROR (Status);  \r
 \r
+  //\r
+  // Create callback to update status of EndOfDxe, which is needed by NULL\r
+  // pointer detection\r
+  //\r
+  Status = gBS->CreateEventEx (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  ToggleEndOfDxeStatus,\r
+                  NULL,\r
+                  &gEfiEndOfDxeEventGroupGuid,\r
+                  &EndOfDxeEvent\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   //\r
   // Make a new handle and install the protocol\r
   //\r