]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBootSupport.c
IntelFrameworkModulePkg: Clean up source files
[mirror_edk2.git] / IntelFrameworkModulePkg / Csm / LegacyBiosDxe / LegacyBootSupport.c
index 6c2688b4a423cf7e5e0db2fd1d5c375f9d342a77..a7b8e6a9a0ae7f4ded9293b5b8f4646935939b93 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, 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
@@ -91,7 +91,7 @@ PrintBbsTable (
     //\r
     // Print DescString\r
     //\r
-    String = (CHAR8 *)(UINTN)((BbsTable[Index].DescStringSegment << 4) + BbsTable[Index].DescStringOffset);\r
+    String = (CHAR8 *)(((UINTN)BbsTable[Index].DescStringSegment << 4) + BbsTable[Index].DescStringOffset);\r
     if (String != NULL) {\r
       DEBUG ((EFI_D_INFO," ("));\r
       for (SubIndex = 0; String[SubIndex] != 0; SubIndex++) {\r
@@ -791,15 +791,15 @@ CreateSmbiosTableInReservedMemory (
   )\r
 {\r
   SMBIOS_TABLE_ENTRY_POINT    *EntryPointStructure;\r
-  \r
-  if ((mRuntimeSmbiosEntryPoint == NULL) || \r
-      (mReserveSmbiosEntryPoint == 0) || \r
+\r
+  if ((mRuntimeSmbiosEntryPoint == NULL) ||\r
+      (mReserveSmbiosEntryPoint == 0) ||\r
       (mStructureTableAddress == 0)) {\r
     return;\r
   }\r
-  \r
+\r
   EntryPointStructure = (SMBIOS_TABLE_ENTRY_POINT *) mRuntimeSmbiosEntryPoint;\r
-  \r
+\r
   //\r
   // Copy SMBIOS Entry Point Structure\r
   //\r
@@ -808,7 +808,7 @@ CreateSmbiosTableInReservedMemory (
     EntryPointStructure,\r
     EntryPointStructure->EntryPointLength\r
   );\r
-  \r
+\r
   //\r
   // Copy SMBIOS Structure Table into EfiReservedMemoryType memory\r
   //\r
@@ -817,22 +817,22 @@ CreateSmbiosTableInReservedMemory (
     (VOID *)(UINTN) EntryPointStructure->TableAddress,\r
     EntryPointStructure->TableLength\r
   );\r
-  \r
+\r
   //\r
   // Update TableAddress in Entry Point Structure\r
   //\r
   EntryPointStructure = (SMBIOS_TABLE_ENTRY_POINT *)(UINTN) mReserveSmbiosEntryPoint;\r
   EntryPointStructure->TableAddress = (UINT32)(UINTN) mStructureTableAddress;\r
-  \r
+\r
   //\r
   // Fixup checksums in the Entry Point Structure\r
   //\r
   EntryPointStructure->IntermediateChecksum = 0;\r
   EntryPointStructure->EntryPointStructureChecksum = 0;\r
 \r
-  EntryPointStructure->IntermediateChecksum = \r
+  EntryPointStructure->IntermediateChecksum =\r
     CalculateCheckSum8 (\r
-      (UINT8 *) EntryPointStructure + OFFSET_OF (SMBIOS_TABLE_ENTRY_POINT, IntermediateAnchorString), \r
+      (UINT8 *) EntryPointStructure + OFFSET_OF (SMBIOS_TABLE_ENTRY_POINT, IntermediateAnchorString),\r
       EntryPointStructure->EntryPointLength - OFFSET_OF (SMBIOS_TABLE_ENTRY_POINT, IntermediateAnchorString)\r
       );\r
   EntryPointStructure->EntryPointStructureChecksum =\r
@@ -898,7 +898,7 @@ GenericLegacyBoot (
 \r
   EfiToLegacy16BootTable->MajorVersion = EFI_TO_LEGACY_MAJOR_VERSION;\r
   EfiToLegacy16BootTable->MinorVersion = EFI_TO_LEGACY_MINOR_VERSION;\r
-  \r
+\r
   //\r
   // If booting to a legacy OS then force HDD drives to the appropriate\r
   // boot mode by calling GetIdeHandle.\r
@@ -916,7 +916,7 @@ GenericLegacyBoot (
                                   );\r
     if (!EFI_ERROR (Status)) {\r
       IdeController = HandleBuffer[0];\r
-    }   \r
+    }\r
   }\r
   //\r
   // Unlock the Legacy BIOS region\r
@@ -1041,7 +1041,9 @@ GenericLegacyBoot (
   //\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
@@ -1073,8 +1075,10 @@ GenericLegacyBoot (
   // Use 182/10 to avoid floating point math.\r
   //\r
   LocalTime = (LocalTime * 182) / 10;\r
-  BdaPtr    = (UINT32 *) (UINTN)0x46C;\r
-  *BdaPtr   = LocalTime;\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
@@ -1291,7 +1295,7 @@ GenericLegacyBoot (
     // Disable DXE Timer while executing in real mode\r
     //\r
     Private->Timer->SetTimerPeriod (Private->Timer, 0);\r
-    \r
+\r
     //\r
     // Save and disable interrupt of debug timer\r
     //\r
@@ -1320,13 +1324,15 @@ GenericLegacyBoot (
     //          set of TIANO vectors) or takes it over.\r
     //\r
     //\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
 \r
     ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET));\r
     Regs.X.AX = Legacy16Boot;\r
@@ -1340,10 +1346,12 @@ GenericLegacyBoot (
       0\r
       );\r
 \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
+    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
@@ -1456,8 +1464,8 @@ LegacyBiosBootUnconventionalDevice (
   }\r
 \r
   UcdTable = (UD_TABLE *) AllocatePool (\r
-                                                                                                               sizeof (UD_TABLE)\r
-                                                                                                               );\r
+                            sizeof (UD_TABLE)\r
+                            );\r
   if (NULL == UcdTable) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -1613,10 +1621,19 @@ EfiMemoryTypeToE820Type (
   case EfiBootServicesCode:\r
   case EfiBootServicesData:\r
   case EfiConventionalMemory:\r
+  //\r
+  // The memory of EfiRuntimeServicesCode and EfiRuntimeServicesData are\r
+  // usable memory for legacy OS, because legacy OS is not aware of EFI runtime concept.\r
+  // In ACPI specification, EfiRuntimeServiceCode and EfiRuntimeServiceData\r
+  // should be mapped to AddressRangeReserved. This statement is for UEFI OS, not for legacy OS.\r
+  //\r
   case EfiRuntimeServicesCode:\r
   case EfiRuntimeServicesData:\r
     return EfiAcpiAddressRangeMemory;\r
 \r
+  case EfiPersistentMemory:\r
+    return EfiAddressRangePersistentMemory;\r
+\r
   case EfiACPIReclaimMemory:\r
     return EfiAcpiAddressRangeACPI;\r
 \r
@@ -1722,9 +1739,11 @@ LegacyBiosBuildE820 (
   //\r
   // First entry is 0 to (640k - EBDA)\r
   //\r
-  E820Table[0].BaseAddr  = 0;\r
-  E820Table[0].Length    = (UINT64) ((*(UINT16 *) (UINTN)0x40E) << 4);\r
-  E820Table[0].Type      = EfiAcpiAddressRangeMemory;\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
@@ -2040,15 +2059,18 @@ LegacyBiosUpdateKeyboardLedStatus (
   UINT8                 LocalLeds;\r
   EFI_IA32_REGISTER_SET Regs;\r
 \r
-  Bda                 = (BDA_STRUC *) ((UINTN) 0x400);\r
-\r
   Private             = LEGACY_BIOS_INSTANCE_FROM_THIS (This);\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
+  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
@@ -2093,7 +2115,9 @@ LegacyBiosCompleteStandardCmosBeforeBoot (
   //            to large capacity drives\r
   // CMOS 14 = BDA 40:10 plus bit 3(display enabled)\r
   //\r
-  Bda = (UINT8)(*((UINT8 *)((UINTN)0x410)) | BIT3);\r
+  ACCESS_PAGE0_CODE (\r
+    Bda = (UINT8)(*((UINT8 *)((UINTN)0x410)) | BIT3);\r
+  );\r
 \r
   //\r
   // Force display enabled\r