]> git.proxmox.com Git - mirror_edk2.git/commitdiff
IntelFrameworkModulePkg/LegacyBios: Use macro to enable/disable page 0
authorJian J Wang <jian.j.wang@intel.com>
Thu, 7 Dec 2017 09:00:23 +0000 (17:00 +0800)
committerStar Zeng <star.zeng@intel.com>
Fri, 8 Dec 2017 06:38:45 +0000 (14:38 +0800)
Current implementation uses following two methods

    EnableNullDetection()
    DisableNullDetection()

to enable/disable page 0. These two methods will check PCD
PcdNullPointerDetectionPropertyMask to know if the page 0 is disabled or not.
This is due to the fact that old GCD service doesn't provide paging related
attributes of memory block. Since this issue has been fixed, GCD services
can be used to determine the paging status of page 0. This is also make it
possible to just use a new macro

    ACCESS_PAGE0_CODE(
      <code accessing page 0>
    );

to replace above methods to do the same job, which also makes code more
readability.

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>
IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBda.c
IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c
IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBiosDxe.inf
IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBiosInterface.h
IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBootSupport.c
IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyPci.c
IntelFrameworkModulePkg/Csm/LegacyBiosDxe/Thunk.c

index c6670febeea4fca52dca96a41640983476636c65..a94cba435c2921c9b45c2beaeb1e060e7c7a6aed 100644 (file)
@@ -34,37 +34,36 @@ LegacyBiosInitBda (
   BDA_STRUC *Bda;\r
   UINT8     *Ebda;\r
 \r
   BDA_STRUC *Bda;\r
   UINT8     *Ebda;\r
 \r
-  DisableNullDetection ();\r
-\r
   Bda   = (BDA_STRUC *) ((UINTN) 0x400);\r
   Ebda  = (UINT8 *) ((UINTN) 0x9fc00);\r
 \r
   Bda   = (BDA_STRUC *) ((UINTN) 0x400);\r
   Ebda  = (UINT8 *) ((UINTN) 0x9fc00);\r
 \r
-  ZeroMem (Bda, 0x100);\r
+  ACCESS_PAGE0_CODE (\r
+    ZeroMem (Bda, 0x100);\r
+    //\r
+    // 640k-1k for EBDA\r
+    //\r
+    Bda->MemSize        = 0x27f;\r
+    Bda->KeyHead        = 0x1e;\r
+    Bda->KeyTail        = 0x1e;\r
+    Bda->FloppyData     = 0x00;\r
+    Bda->FloppyTimeout  = 0xff;\r
+\r
+    Bda->KeyStart       = 0x001E;\r
+    Bda->KeyEnd         = 0x003E;\r
+    Bda->KeyboardStatus = 0x10;\r
+    Bda->Ebda           = 0x9fc0;\r
+\r
+    //\r
+    // Move LPT time out here and zero out LPT4 since some SCSI OPROMS\r
+    // use this as scratch pad (LPT4 is Reserved)\r
+    //\r
+    Bda->Lpt1_2Timeout  = 0x1414;\r
+    Bda->Lpt3_4Timeout  = 0x1400;\r
+\r
+  );\r
+\r
   ZeroMem (Ebda, 0x400);\r
   ZeroMem (Ebda, 0x400);\r
-  //\r
-  // 640k-1k for EBDA\r
-  //\r
-  Bda->MemSize        = 0x27f;\r
-  Bda->KeyHead        = 0x1e;\r
-  Bda->KeyTail        = 0x1e;\r
-  Bda->FloppyData     = 0x00;\r
-  Bda->FloppyTimeout  = 0xff;\r
-\r
-  Bda->KeyStart       = 0x001E;\r
-  Bda->KeyEnd         = 0x003E;\r
-  Bda->KeyboardStatus = 0x10;\r
-  Bda->Ebda           = 0x9fc0;\r
-\r
-  //\r
-  // Move LPT time out here and zero out LPT4 since some SCSI OPROMS\r
-  // use this as scratch pad (LPT4 is Reserved)\r
-  //\r
-  Bda->Lpt1_2Timeout  = 0x1414;\r
-  Bda->Lpt3_4Timeout  = 0x1400;\r
-\r
-  *Ebda               = 0x01;\r
-\r
-  EnableNullDetection ();\r
+  *Ebda = 0x01;\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
index c6461f554705b869cfc522b122b7fbf6ad7e98c1..fca08a8fa26d4be275576f8b6156290f96a9e5fc 100644 (file)
@@ -786,115 +786,6 @@ ToggleEndOfDxeStatus (
   return;\r
 }\r
 \r
   return;\r
 }\r
 \r
-//\r
-// Legacy BIOS needs to access memory between 0-4095, which will cause page\r
-// fault exception if NULL pointer detection mechanism is enabled. Following\r
-// functions can be used to disable/enable NULL pointer detection before/after\r
-// accessing those memory.\r
-//\r
-\r
-/**\r
-   Enable NULL pointer detection.\r
-**/\r
-VOID\r
-EnableNullDetection (\r
-  VOID\r
-  )\r
-{\r
-  EFI_STATUS                            Status;\r
-  EFI_GCD_MEMORY_SPACE_DESCRIPTOR       Desc;\r
-\r
-  if (((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) == 0)\r
-      ||\r
-      ((mEndOfDxe)  &&\r
-       ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT7|BIT0))\r
-        == (BIT7|BIT0)))\r
-     ) {\r
-    return;\r
-  }\r
-\r
-  //\r
-  // Check current capabilities and attributes\r
-  //\r
-  Status = gDS->GetMemorySpaceDescriptor (0, &Desc);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  //\r
-  // Try to add EFI_MEMORY_RP support if necessary\r
-  //\r
-  if ((Desc.Capabilities & EFI_MEMORY_RP) == 0) {\r
-    Desc.Capabilities |= EFI_MEMORY_RP;\r
-    Status = gDS->SetMemorySpaceCapabilities (0, EFI_PAGES_TO_SIZE(1),\r
-                                              Desc.Capabilities);\r
-    ASSERT_EFI_ERROR (Status);\r
-    if (EFI_ERROR (Status)) {\r
-      return;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Don't bother if EFI_MEMORY_RP is already set.\r
-  //\r
-  if ((Desc.Attributes & EFI_MEMORY_RP) == 0) {\r
-    Desc.Attributes |= EFI_MEMORY_RP;\r
-    Status = gDS->SetMemorySpaceAttributes (0, EFI_PAGES_TO_SIZE(1),\r
-                                            Desc.Attributes);\r
-    ASSERT_EFI_ERROR (Status);\r
-  }\r
-}\r
-\r
-/**\r
-   Disable NULL pointer detection.\r
-**/\r
-VOID\r
-DisableNullDetection (\r
-  VOID\r
-  )\r
-{\r
-  EFI_STATUS                            Status;\r
-  EFI_GCD_MEMORY_SPACE_DESCRIPTOR       Desc;\r
-\r
-  if (((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) == 0)\r
-      ||\r
-      ((mEndOfDxe)  &&\r
-       ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT7|BIT0))\r
-        == (BIT7|BIT0)))\r
-     ) {\r
-    return;\r
-  }\r
-\r
-  //\r
-  // Check current capabilities and attributes\r
-  //\r
-  Status = gDS->GetMemorySpaceDescriptor (0, &Desc);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  //\r
-  // Try to add EFI_MEMORY_RP support if necessary\r
-  //\r
-  if ((Desc.Capabilities & EFI_MEMORY_RP) == 0) {\r
-    Desc.Capabilities |= EFI_MEMORY_RP;\r
-    Status = gDS->SetMemorySpaceCapabilities (0, EFI_PAGES_TO_SIZE(1),\r
-                                              Desc.Capabilities);\r
-    ASSERT_EFI_ERROR (Status);\r
-    if (EFI_ERROR (Status)) {\r
-      return;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Don't bother if EFI_MEMORY_RP is already cleared.\r
-  //\r
-  if ((Desc.Attributes & EFI_MEMORY_RP) != 0) {\r
-    Desc.Attributes &= ~EFI_MEMORY_RP;\r
-    Status = gDS->SetMemorySpaceAttributes (0, EFI_PAGES_TO_SIZE(1),\r
-                                            Desc.Attributes);\r
-    ASSERT_EFI_ERROR (Status);\r
-  } else {\r
-    DEBUG ((DEBUG_WARN, "!!! Page 0 is supposed to be disabled !!!\r\n"));\r
-  }\r
-}\r
-\r
 /**\r
   Install Driver to produce Legacy BIOS protocol.\r
 \r
 /**\r
   Install Driver to produce Legacy BIOS protocol.\r
 \r
@@ -1095,10 +986,10 @@ LegacyBiosInstall (
   // Initialize region from 0x0000 to 4k. This initializes interrupt vector\r
   // range.\r
   //\r
   // Initialize region from 0x0000 to 4k. This initializes interrupt vector\r
   // range.\r
   //\r
-  DisableNullDetection ();\r
-  gBS->SetMem ((VOID *) ClearPtr, 0x400, INITIAL_VALUE_BELOW_1K);\r
-  ZeroMem ((VOID *) ((UINTN)ClearPtr + 0x400), 0xC00);\r
-  EnableNullDetection ();\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
 \r
   //\r
   // Allocate pages for OPROM usage\r
@@ -1237,16 +1128,14 @@ LegacyBiosInstall (
   //\r
   // Save Unexpected interrupt vector so can restore it just prior to boot\r
   //\r
   //\r
   // Save Unexpected interrupt vector so can restore it just prior to boot\r
   //\r
-  DisableNullDetection ();\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
-\r
-  EnableNullDetection ();\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
   //\r
   // Save EFI value\r
index 6efc7f36ae61975668142f125894c1368f39f879..180c18e3fc34a2a8d5057b772b4dda30115ad6ed 100644 (file)
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdHighPmmMemorySize            ## CONSUMES\r
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdOpromReservedMemoryBase      ## CONSUMES\r
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdOpromReservedMemorySize      ## CONSUMES\r
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdHighPmmMemorySize            ## CONSUMES\r
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdOpromReservedMemoryBase      ## CONSUMES\r
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdOpromReservedMemorySize      ## CONSUMES\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask        ## CONSUMES\r
 \r
 [Depex]\r
   gEfiLegacyRegion2ProtocolGuid AND gEfiLegacyInterruptProtocolGuid AND gEfiLegacyBiosPlatformProtocolGuid AND gEfiLegacy8259ProtocolGuid AND gEfiGenericMemTestProtocolGuid AND gEfiCpuArchProtocolGuid AND gEfiTimerArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid\r
 \r
 [Depex]\r
   gEfiLegacyRegion2ProtocolGuid AND gEfiLegacyInterruptProtocolGuid AND gEfiLegacyBiosPlatformProtocolGuid AND gEfiLegacy8259ProtocolGuid AND gEfiGenericMemTestProtocolGuid AND gEfiCpuArchProtocolGuid AND gEfiTimerArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid\r
index 86a3b09080916014316b38b76d750b2e1245423d..cc2fc9fc135839596f909bd300ef812f31aae050 100644 (file)
@@ -1544,20 +1544,4 @@ LegacyBiosInstallVgaRom (
   IN  LEGACY_BIOS_INSTANCE            *Private\r
   );\r
 \r
   IN  LEGACY_BIOS_INSTANCE            *Private\r
   );\r
 \r
-/**\r
-   Enable NULL pointer detection.\r
-**/\r
-VOID\r
-EnableNullDetection (\r
-  VOID\r
-  );\r
-\r
-/**\r
-   Disable NULL pointer detection.\r
-**/\r
-VOID\r
-DisableNullDetection (\r
-  VOID\r
-  );\r
-\r
 #endif\r
 #endif\r
index c2ac69ce690835ce41612d4f0e20228f90adec4a..57ab78d6484cce913a9b693d45a98b23bd73ceb3 100644 (file)
@@ -1041,7 +1041,9 @@ GenericLegacyBoot (
   //\r
   // Setup BDA and EBDA standard areas before Legacy Boot\r
   //\r
   //\r
   // Setup BDA and EBDA standard areas before Legacy Boot\r
   //\r
-  LegacyBiosCompleteBdaBeforeBoot (Private);\r
+  ACCESS_PAGE0_CODE (\r
+    LegacyBiosCompleteBdaBeforeBoot (Private);\r
+  );\r
   LegacyBiosCompleteStandardCmosBeforeBoot (Private);\r
 \r
   //\r
   LegacyBiosCompleteStandardCmosBeforeBoot (Private);\r
 \r
   //\r
@@ -1073,10 +1075,10 @@ GenericLegacyBoot (
   // Use 182/10 to avoid floating point math.\r
   //\r
   LocalTime = (LocalTime * 182) / 10;\r
   // Use 182/10 to avoid floating point math.\r
   //\r
   LocalTime = (LocalTime * 182) / 10;\r
-  DisableNullDetection ();\r
-  BdaPtr    = (UINT32 *) (UINTN)0x46C;\r
-  *BdaPtr   = LocalTime;\r
-  EnableNullDetection ();\r
+  ACCESS_PAGE0_CODE (\r
+    BdaPtr    = (UINT32 *) (UINTN)0x46C;\r
+    *BdaPtr   = LocalTime;\r
+  );\r
 \r
   //\r
   // Shadow PCI ROMs. We must do this near the end since this will kick\r
 \r
   //\r
   // Shadow PCI ROMs. We must do this near the end since this will kick\r
@@ -1322,15 +1324,15 @@ GenericLegacyBoot (
     //          set of TIANO vectors) or takes it over.\r
     //\r
     //\r
     //          set of TIANO vectors) or takes it over.\r
     //\r
     //\r
-    DisableNullDetection ();\r
-    BaseVectorMaster = (UINT32 *) (sizeof (UINT32) * PROTECTED_MODE_BASE_VECTOR_MASTER);\r
-    for (Index = 0; Index < 8; Index++) {\r
-      Private->ThunkSavedInt[Index] = BaseVectorMaster[Index];\r
-      if (Private->ThunkSeg == (UINT16) (BaseVectorMaster[Index] >> 16)) {\r
-        BaseVectorMaster[Index] = (UINT32) (Private->BiosUnexpectedInt);\r
+    ACCESS_PAGE0_CODE (\r
+      BaseVectorMaster = (UINT32 *) (sizeof (UINT32) * PROTECTED_MODE_BASE_VECTOR_MASTER);\r
+      for (Index = 0; Index < 8; Index++) {\r
+        Private->ThunkSavedInt[Index] = BaseVectorMaster[Index];\r
+        if (Private->ThunkSeg == (UINT16) (BaseVectorMaster[Index] >> 16)) {\r
+          BaseVectorMaster[Index] = (UINT32) (Private->BiosUnexpectedInt);\r
+        }\r
       }\r
       }\r
-    }\r
-    EnableNullDetection ();\r
+    );\r
 \r
     ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET));\r
     Regs.X.AX = Legacy16Boot;\r
 \r
     ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET));\r
     Regs.X.AX = Legacy16Boot;\r
@@ -1344,12 +1346,12 @@ GenericLegacyBoot (
       0\r
       );\r
 \r
       0\r
       );\r
 \r
-    DisableNullDetection ();\r
-    BaseVectorMaster = (UINT32 *) (sizeof (UINT32) * PROTECTED_MODE_BASE_VECTOR_MASTER);\r
-    for (Index = 0; Index < 8; Index++) {\r
-      BaseVectorMaster[Index] = Private->ThunkSavedInt[Index];\r
-    }\r
-    EnableNullDetection ();\r
+    ACCESS_PAGE0_CODE (\r
+      BaseVectorMaster = (UINT32 *) (sizeof (UINT32) * PROTECTED_MODE_BASE_VECTOR_MASTER);\r
+      for (Index = 0; Index < 8; Index++) {\r
+        BaseVectorMaster[Index] = Private->ThunkSavedInt[Index];\r
+      }\r
+    );\r
   }\r
   Private->LegacyBootEntered = TRUE;\r
   if ((mBootMode == BOOT_LEGACY_OS) || (mBootMode == BOOT_UNCONVENTIONAL_DEVICE)) {\r
   }\r
   Private->LegacyBootEntered = TRUE;\r
   if ((mBootMode == BOOT_LEGACY_OS) || (mBootMode == BOOT_UNCONVENTIONAL_DEVICE)) {\r
@@ -1737,11 +1739,11 @@ LegacyBiosBuildE820 (
   //\r
   // First entry is 0 to (640k - EBDA)\r
   //\r
   //\r
   // First entry is 0 to (640k - EBDA)\r
   //\r
-  DisableNullDetection ();\r
-  E820Table[0].BaseAddr  = 0;\r
-  E820Table[0].Length    = (UINT64) ((*(UINT16 *) (UINTN)0x40E) << 4);\r
-  E820Table[0].Type      = EfiAcpiAddressRangeMemory;\r
-  EnableNullDetection ();\r
+  ACCESS_PAGE0_CODE (\r
+    E820Table[0].BaseAddr  = 0;\r
+    E820Table[0].Length    = (UINT64) ((*(UINT16 *) (UINTN)0x40E) << 4);\r
+    E820Table[0].Type      = EfiAcpiAddressRangeMemory;\r
+  );\r
 \r
   //\r
   // Second entry is (640k - EBDA) to 640k\r
 \r
   //\r
   // Second entry is (640k - EBDA) to 640k\r
@@ -1975,8 +1977,6 @@ LegacyBiosCompleteBdaBeforeBoot (
   UINT16                      MachineConfig;\r
   DEVICE_PRODUCER_DATA_HEADER *SioPtr;\r
 \r
   UINT16                      MachineConfig;\r
   DEVICE_PRODUCER_DATA_HEADER *SioPtr;\r
 \r
-  DisableNullDetection ();\r
-\r
   Bda           = (BDA_STRUC *) ((UINTN) 0x400);\r
   MachineConfig = 0;\r
 \r
   Bda           = (BDA_STRUC *) ((UINTN) 0x400);\r
   MachineConfig = 0;\r
 \r
@@ -2035,8 +2035,6 @@ LegacyBiosCompleteBdaBeforeBoot (
   MachineConfig       = (UINT16) (MachineConfig + 0x00 + 0x02 + (SioPtr->MousePresent * 0x04));\r
   Bda->MachineConfig  = MachineConfig;\r
 \r
   MachineConfig       = (UINT16) (MachineConfig + 0x00 + 0x02 + (SioPtr->MousePresent * 0x04));\r
   Bda->MachineConfig  = MachineConfig;\r
 \r
-  EnableNullDetection ();\r
-\r
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -2063,17 +2061,15 @@ LegacyBiosUpdateKeyboardLedStatus (
 \r
   Private             = LEGACY_BIOS_INSTANCE_FROM_THIS (This);\r
 \r
 \r
   Private             = LEGACY_BIOS_INSTANCE_FROM_THIS (This);\r
 \r
-  DisableNullDetection ();\r
-\r
-  Bda                 = (BDA_STRUC *) ((UINTN) 0x400);\r
-  LocalLeds           = Leds;\r
-  Bda->LedStatus      = (UINT8) ((Bda->LedStatus &~0x07) | LocalLeds);\r
-  LocalLeds           = (UINT8) (LocalLeds << 4);\r
-  Bda->ShiftStatus    = (UINT8) ((Bda->ShiftStatus &~0x70) | LocalLeds);\r
-  LocalLeds           = (UINT8) (Leds & 0x20);\r
-  Bda->KeyboardStatus = (UINT8) ((Bda->KeyboardStatus &~0x20) | LocalLeds);\r
-\r
-  EnableNullDetection ();\r
+  ACCESS_PAGE0_CODE (\r
+    Bda                 = (BDA_STRUC *) ((UINTN) 0x400);\r
+    LocalLeds           = Leds;\r
+    Bda->LedStatus      = (UINT8) ((Bda->LedStatus &~0x07) | LocalLeds);\r
+    LocalLeds           = (UINT8) (LocalLeds << 4);\r
+    Bda->ShiftStatus    = (UINT8) ((Bda->ShiftStatus &~0x70) | LocalLeds);\r
+    LocalLeds           = (UINT8) (Leds & 0x20);\r
+    Bda->KeyboardStatus = (UINT8) ((Bda->KeyboardStatus &~0x20) | LocalLeds);\r
+  );\r
 \r
   //\r
   // Call into Legacy16 code to allow it to do any processing\r
 \r
   //\r
   // Call into Legacy16 code to allow it to do any processing\r
@@ -2119,9 +2115,9 @@ LegacyBiosCompleteStandardCmosBeforeBoot (
   //            to large capacity drives\r
   // CMOS 14 = BDA 40:10 plus bit 3(display enabled)\r
   //\r
   //            to large capacity drives\r
   // CMOS 14 = BDA 40:10 plus bit 3(display enabled)\r
   //\r
-  DisableNullDetection ();\r
-  Bda = (UINT8)(*((UINT8 *)((UINTN)0x410)) | BIT3);\r
-  EnableNullDetection ();\r
+  ACCESS_PAGE0_CODE (\r
+    Bda = (UINT8)(*((UINT8 *)((UINTN)0x410)) | BIT3);\r
+  );\r
 \r
   //\r
   // Force display enabled\r
 \r
   //\r
   // Force display enabled\r
index d38cef3e33e26f5d3b0f85d4e0d24c0b909091a9..b10a9dcef6aa34be854f4f3a22a9761bb95b0ae5 100644 (file)
@@ -2403,35 +2403,33 @@ LegacyBiosInstallRom (
   // 2. BBS compliants drives will not change 40:75 until boot time.\r
   // 3. Onboard IDE controllers will change 40:75\r
   //\r
   // 2. BBS compliants drives will not change 40:75 until boot time.\r
   // 3. Onboard IDE controllers will change 40:75\r
   //\r
-  DisableNullDetection ();\r
-\r
-  LocalDiskStart = (UINT8) ((*(UINT8 *) ((UINTN) 0x475)) + 0x80);\r
-  if ((Private->Disk4075 + 0x80) < LocalDiskStart) {\r
-    //\r
-    // Update table since onboard IDE drives found\r
-    //\r
-    Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].PciSegment        = 0xff;\r
-    Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].PciBus            = 0xff;\r
-    Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].PciDevice         = 0xff;\r
-    Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].PciFunction       = 0xff;\r
-    Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].StartDriveNumber  = (UINT8) (Private->Disk4075 + 0x80);\r
-    Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].EndDriveNumber    = LocalDiskStart;\r
-    Private->LegacyEfiHddTableIndex ++;\r
-    Private->Disk4075 = (UINT8) (LocalDiskStart & 0x7f);\r
-    Private->DiskEnd  = LocalDiskStart;\r
-  }\r
-\r
-  if (PciHandle != mVgaHandle) {\r
+  ACCESS_PAGE0_CODE (\r
+    LocalDiskStart = (UINT8) ((*(UINT8 *) ((UINTN) 0x475)) + 0x80);\r
+    if ((Private->Disk4075 + 0x80) < LocalDiskStart) {\r
+      //\r
+      // Update table since onboard IDE drives found\r
+      //\r
+      Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].PciSegment        = 0xff;\r
+      Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].PciBus            = 0xff;\r
+      Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].PciDevice         = 0xff;\r
+      Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].PciFunction       = 0xff;\r
+      Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].StartDriveNumber  = (UINT8) (Private->Disk4075 + 0x80);\r
+      Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].EndDriveNumber    = LocalDiskStart;\r
+      Private->LegacyEfiHddTableIndex ++;\r
+      Private->Disk4075 = (UINT8) (LocalDiskStart & 0x7f);\r
+      Private->DiskEnd  = LocalDiskStart;\r
+    }\r
 \r
 \r
-    EnablePs2Keyboard ();\r
+    if (PciHandle != mVgaHandle) {\r
 \r
 \r
-    //\r
-    // Store current mode settings since PrepareToScanRom may change mode.\r
-    //\r
-    VideoMode = *(UINT8 *) ((UINTN) (0x400 + BDA_VIDEO_MODE));\r
-  }\r
+      EnablePs2Keyboard ();\r
 \r
 \r
-  EnableNullDetection ();\r
+      //\r
+      // Store current mode settings since PrepareToScanRom may change mode.\r
+      //\r
+      VideoMode = *(UINT8 *) ((UINTN) (0x400 + BDA_VIDEO_MODE));\r
+    }\r
+  );\r
 \r
   //\r
   // Notify the platform that we are about to scan the ROM\r
 \r
   //\r
   // Notify the platform that we are about to scan the ROM\r
@@ -2473,11 +2471,11 @@ LegacyBiosInstallRom (
   // Multiply result by 18.2 for number of ticks since midnight.\r
   // Use 182/10 to avoid floating point math.\r
   //\r
   // Multiply result by 18.2 for number of ticks since midnight.\r
   // Use 182/10 to avoid floating point math.\r
   //\r
-  DisableNullDetection ();\r
-  LocalTime = (LocalTime * 182) / 10;\r
-  BdaPtr    = (UINT32 *) ((UINTN) 0x46C);\r
-  *BdaPtr   = LocalTime;\r
-  EnableNullDetection ();\r
+  ACCESS_PAGE0_CODE (\r
+    LocalTime = (LocalTime * 182) / 10;\r
+    BdaPtr    = (UINT32 *) ((UINTN) 0x46C);\r
+    *BdaPtr   = LocalTime;\r
+  );\r
   \r
   //\r
   // Pass in handoff data\r
   \r
   //\r
   // Pass in handoff data\r
@@ -2573,9 +2571,9 @@ LegacyBiosInstallRom (
     //\r
     // Set mode settings since PrepareToScanRom may change mode\r
     //\r
     //\r
     // Set mode settings since PrepareToScanRom may change mode\r
     //\r
-    DisableNullDetection ();\r
-    OldVideoMode = *(UINT8 *) ((UINTN) (0x400 + BDA_VIDEO_MODE));\r
-    EnableNullDetection ();\r
+    ACCESS_PAGE0_CODE ({\r
+      OldVideoMode = *(UINT8 *) ((UINTN) (0x400 + BDA_VIDEO_MODE));\r
+    });\r
 \r
     if (VideoMode != OldVideoMode) {\r
       //\r
 \r
     if (VideoMode != OldVideoMode) {\r
       //\r
@@ -2617,9 +2615,9 @@ LegacyBiosInstallRom (
     }\r
   }\r
 \r
     }\r
   }\r
 \r
-  DisableNullDetection ();\r
-  LocalDiskEnd = (UINT8) ((*(UINT8 *) ((UINTN) 0x475)) + 0x80);\r
-  EnableNullDetection ();\r
+  ACCESS_PAGE0_CODE (\r
+    LocalDiskEnd = (UINT8) ((*(UINT8 *) ((UINTN) 0x475)) + 0x80);\r
+  );\r
   \r
   //\r
   // Allow platform to perform any required actions after the\r
   \r
   //\r
   // Allow platform to perform any required actions after the\r
index d249479c56ef6d172bf16c8b8553bb56d9e056d1..d330f4870baa62608e3c6035968d16cc6df61cf1 100644 (file)
@@ -73,10 +73,10 @@ LegacyBiosInt86 (
   // The base address of legacy interrupt vector table is 0.\r
   // We use this base address to get the legacy interrupt handler.\r
   //\r
   // The base address of legacy interrupt vector table is 0.\r
   // We use this base address to get the legacy interrupt handler.\r
   //\r
-  DisableNullDetection ();\r
-  Segment               = (UINT16)(((UINT32 *)0)[BiosInt] >> 16);\r
-  Offset                = (UINT16)((UINT32 *)0)[BiosInt];\r
-  EnableNullDetection ();\r
+  ACCESS_PAGE0_CODE (\r
+    Segment               = (UINT16)(((UINT32 *)0)[BiosInt] >> 16);\r
+    Offset                = (UINT16)((UINT32 *)0)[BiosInt];\r
+  );\r
   \r
   return InternalLegacyBiosFarCall (\r
            This,\r
   \r
   return InternalLegacyBiosFarCall (\r
            This,\r
@@ -286,29 +286,6 @@ InternalLegacyBiosFarCall (
 \r
   AsmThunk16 (&mThunkContext);\r
 \r
 \r
   AsmThunk16 (&mThunkContext);\r
 \r
-  //\r
-  // OPROM may allocate EBDA range by itself and change EBDA base and EBDA size.\r
-  // Get the current EBDA base address, and compared with pre-allocate minimum\r
-  // EBDA base address, if the current EBDA base address is smaller, it indicates\r
-  // PcdEbdaReservedMemorySize should be adjusted to larger for more OPROMs.\r
-  //\r
-  DEBUG_CODE (\r
-    {\r
-      UINTN                 EbdaBaseAddress;\r
-      UINTN                 ReservedEbdaBaseAddress;\r
-\r
-      //\r
-      // Skip this part of debug code if NULL pointer detection is enabled\r
-      //\r
-      if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) == 0) {\r
-        EbdaBaseAddress = (*(UINT16 *) (UINTN) 0x40E) << 4;\r
-        ReservedEbdaBaseAddress = CONVENTIONAL_MEMORY_TOP\r
-                                  - PcdGet32 (PcdEbdaReservedMemorySize);\r
-        ASSERT (ReservedEbdaBaseAddress <= EbdaBaseAddress);\r
-      }\r
-    }\r
-  );\r
-\r
   if (Stack != NULL && StackSize != 0) {\r
     //\r
     // Copy low memory stack to Stack\r
   if (Stack != NULL && StackSize != 0) {\r
     //\r
     // Copy low memory stack to Stack\r
@@ -334,6 +311,26 @@ InternalLegacyBiosFarCall (
   //\r
   gBS->RestoreTPL (OriginalTpl);\r
   \r
   //\r
   gBS->RestoreTPL (OriginalTpl);\r
   \r
+  //\r
+  // OPROM may allocate EBDA range by itself and change EBDA base and EBDA size.\r
+  // Get the current EBDA base address, and compared with pre-allocate minimum\r
+  // EBDA base address, if the current EBDA base address is smaller, it indicates\r
+  // PcdEbdaReservedMemorySize should be adjusted to larger for more OPROMs.\r
+  //\r
+  DEBUG_CODE (\r
+    {\r
+      UINTN                 EbdaBaseAddress;\r
+      UINTN                 ReservedEbdaBaseAddress;\r
+\r
+      ACCESS_PAGE0_CODE (\r
+        EbdaBaseAddress = (*(UINT16 *) (UINTN) 0x40E) << 4;\r
+        ReservedEbdaBaseAddress = CONVENTIONAL_MEMORY_TOP\r
+                                  - PcdGet32 (PcdEbdaReservedMemorySize);\r
+        ASSERT (ReservedEbdaBaseAddress <= EbdaBaseAddress);\r
+      );\r
+    }\r
+  );\r
+\r
   //\r
   // Restore interrupt of debug timer\r
   //\r
   //\r
   // Restore interrupt of debug timer\r
   //\r