]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkPkg/Include/Protocol/LegacyBios.h
IntelFrameworkPkg/LegacyBios.h: Add a macro to guarantee page 0 access
[mirror_edk2.git] / IntelFrameworkPkg / Include / Protocol / LegacyBios.h
index d18c063c32c6adc463fd59f8bd08be197675f7f6..00a149e38783c24089e0ba0afbc4186c7af3da55 100644 (file)
@@ -232,7 +232,7 @@ typedef struct {
   ///\r
   /// Start Address of Upper Memory Area (UMA) to be set as Read/Write. If\r
   /// UmaAddress is a valid address in the shadow RAM, it also indicates that the region\r
-  /// from 0xC0000 to (UmaAddress ¨C 1) can be used for Option ROM.\r
+  /// from 0xC0000 to (UmaAddress - 1) can be used for Option ROM.\r
   ///\r
   UINT32                            UmaAddress;\r
 \r
@@ -1197,7 +1197,7 @@ BOOLEAN
                             - 01 = ROM Found.\r
                             - 02 = ROM is a valid legacy ROM.\r
 \r
-  @retval EFI_SUCCESS       The Legacy Option ROM availible for this device\r
+  @retval EFI_SUCCESS       The Legacy Option ROM available for this device\r
   @retval EFI_UNSUPPORTED   The Legacy Option ROM is not supported.\r
 \r
 **/\r
@@ -1518,6 +1518,42 @@ struct _EFI_LEGACY_BIOS_PROTOCOL {
   EFI_LEGACY_BIOS_BOOT_UNCONVENTIONAL_DEVICE  BootUnconventionalDevice;\r
 };\r
 \r
+//\r
+// Legacy BIOS needs to access memory in page 0 (0-4095), which is disabled if\r
+// NULL pointer detection feature is enabled. Following macro can be used to\r
+// enable/disable page 0 before/after accessing it.\r
+//\r
+#define ACCESS_PAGE0_CODE(statements)                           \\r
+  do {                                                          \\r
+    EFI_STATUS                            Status_;              \\r
+    EFI_GCD_MEMORY_SPACE_DESCRIPTOR       Desc_;                \\r
+                                                                \\r
+    Desc_.Attributes = 0;                                       \\r
+    Status_ = gDS->GetMemorySpaceDescriptor (0, &Desc_);        \\r
+    ASSERT_EFI_ERROR (Status_);                                 \\r
+    if ((Desc_.Attributes & EFI_MEMORY_RP) != 0) {              \\r
+      Status_ = gDS->SetMemorySpaceAttributes (                 \\r
+                      0,                                        \\r
+                      EFI_PAGES_TO_SIZE(1),                     \\r
+                      Desc_.Attributes & ~(UINT64)EFI_MEMORY_RP \\r
+                      );                                        \\r
+      ASSERT_EFI_ERROR (Status_);                               \\r
+    }                                                           \\r
+                                                                \\r
+    {                                                           \\r
+      statements;                                               \\r
+    }                                                           \\r
+                                                                \\r
+    if ((Desc_.Attributes & EFI_MEMORY_RP) != 0) {              \\r
+      Status_ = gDS->SetMemorySpaceAttributes (                 \\r
+                      0,                                        \\r
+                      EFI_PAGES_TO_SIZE(1),                     \\r
+                      Desc_.Attributes                          \\r
+                      );                                        \\r
+      ASSERT_EFI_ERROR (Status_);                               \\r
+    }                                                           \\r
+  } while (FALSE)\r
+\r
 extern EFI_GUID gEfiLegacyBiosProtocolGuid;\r
 \r
 #endif\r