diff options
author | Jian J Wang <jian.j.wang@intel.com> | 2017-12-05 15:57:38 +0800 |
---|---|---|
committer | Star Zeng <star.zeng@intel.com> | 2017-12-08 14:38:44 +0800 |
commit | 7619eed8aa260c9527d72ccd525ce70060b64f1f (patch) | |
tree | acf708e4852686ac1de7657d4a9f3ee835b88f56 /IntelFrameworkPkg/Include | |
parent | 2b55daaef0f3f53059c5c858ca6fd53b03eb5d4c (diff) | |
download | edk2-7619eed8aa260c9527d72ccd525ce70060b64f1f.tar.gz edk2-7619eed8aa260c9527d72ccd525ce70060b64f1f.tar.bz2 edk2-7619eed8aa260c9527d72ccd525ce70060b64f1f.zip |
IntelFrameworkPkg/LegacyBios.h: Add a macro to guarantee page 0 access
Due to the introduction of NULL pointer detection feature, page 0 will be
disabled if the feature is enabled, which will cause legacy code failed to
update legacy data in page 0. This macro is introduced to make sure the
page 0 is enabled before those code and restore the original status of it
afterwards.
Another reason to introduce this macro is to eliminate the dependency on
the PcdNullPointerDetectionPropertyMask. Because this is a new PCD, it
could cause some backward compatibility issue for some old packages.
This macro will simply check if the page 0 is disabled or not. If it's
disabled, it will enable it before code updating page 0 and disable it
afterwards. Otherwise, this macro will do nothing to page 0.
The usage of the macro will be look like (similar to DEBUG_CODE macro):
ACCESS_PAGE0_CODE(
<code accessing page 0>
);
Cc: Liming Gao <liming.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Diffstat (limited to 'IntelFrameworkPkg/Include')
-rw-r--r-- | IntelFrameworkPkg/Include/Protocol/LegacyBios.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/IntelFrameworkPkg/Include/Protocol/LegacyBios.h b/IntelFrameworkPkg/Include/Protocol/LegacyBios.h index 641f101bce..00a149e387 100644 --- a/IntelFrameworkPkg/Include/Protocol/LegacyBios.h +++ b/IntelFrameworkPkg/Include/Protocol/LegacyBios.h @@ -1518,6 +1518,42 @@ struct _EFI_LEGACY_BIOS_PROTOCOL { EFI_LEGACY_BIOS_BOOT_UNCONVENTIONAL_DEVICE BootUnconventionalDevice;
};
+//
+// Legacy BIOS needs to access memory in page 0 (0-4095), which is disabled if
+// NULL pointer detection feature is enabled. Following macro can be used to
+// enable/disable page 0 before/after accessing it.
+//
+#define ACCESS_PAGE0_CODE(statements) \
+ do { \
+ EFI_STATUS Status_; \
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR Desc_; \
+ \
+ Desc_.Attributes = 0; \
+ Status_ = gDS->GetMemorySpaceDescriptor (0, &Desc_); \
+ ASSERT_EFI_ERROR (Status_); \
+ if ((Desc_.Attributes & EFI_MEMORY_RP) != 0) { \
+ Status_ = gDS->SetMemorySpaceAttributes ( \
+ 0, \
+ EFI_PAGES_TO_SIZE(1), \
+ Desc_.Attributes & ~(UINT64)EFI_MEMORY_RP \
+ ); \
+ ASSERT_EFI_ERROR (Status_); \
+ } \
+ \
+ { \
+ statements; \
+ } \
+ \
+ if ((Desc_.Attributes & EFI_MEMORY_RP) != 0) { \
+ Status_ = gDS->SetMemorySpaceAttributes ( \
+ 0, \
+ EFI_PAGES_TO_SIZE(1), \
+ Desc_.Attributes \
+ ); \
+ ASSERT_EFI_ERROR (Status_); \
+ } \
+ } while (FALSE)
+
extern EFI_GUID gEfiLegacyBiosProtocolGuid;
#endif
|