Port EdkUnixPkg to UnixPkg. The changes are listed as follows:
authoreric_tian <eric_tian@de2fecce-e211-0410-80a6-f3fac2684e05>
Mon, 30 Jun 2008 05:08:49 +0000 (05:08 +0000)
committereric_tian <eric_tian@de2fecce-e211-0410-80a6-f3fac2684e05>
Mon, 30 Jun 2008 05:08:49 +0000 (05:08 +0000)
1. change *.msa to *.inf, and create platform configuration files .dec&.dsc&.fdf to comply with Edk2 build process
2. using PCD mechanism to replace macro.
3. change Sec code to cowork with PI1.0 Pei Core and produce temparory memory ppi.

git-svn-id: https://edk2.tianocore.org/svn/edk2/trunk@5380 de2fecce-e211-0410-80a6-f3fac2684e05

165 files changed:
edk2/UnixPkg/BootModePei/BootModePei.c [new file with mode: 0644]
edk2/UnixPkg/BootModePei/BootModePei.inf [new file with mode: 0644]
edk2/UnixPkg/BootModePei/BootModePei.msa [new file with mode: 0644]
edk2/UnixPkg/CpuRuntimeDxe/Cpu.c [new file with mode: 0644]
edk2/UnixPkg/CpuRuntimeDxe/Cpu.inf [new file with mode: 0644]
edk2/UnixPkg/CpuRuntimeDxe/Cpu.msa [new file with mode: 0644]
edk2/UnixPkg/CpuRuntimeDxe/CpuDriver.h [new file with mode: 0644]
edk2/UnixPkg/CpuRuntimeDxe/CpuIo.c [new file with mode: 0644]
edk2/UnixPkg/CpuRuntimeDxe/Strings.uni [new file with mode: 0644]
edk2/UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c [new file with mode: 0644]
edk2/UnixPkg/FvbServicesRuntimeDxe/FvbInfo.c [new file with mode: 0644]
edk2/UnixPkg/FvbServicesRuntimeDxe/FwBlockService.h [new file with mode: 0644]
edk2/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf [new file with mode: 0644]
edk2/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.msa [new file with mode: 0644]
edk2/UnixPkg/Include/Common/UnixInclude.h [new file with mode: 0644]
edk2/UnixPkg/Include/FlashLayout.h [new file with mode: 0644]
edk2/UnixPkg/Include/Library/UnixLib.h [new file with mode: 0644]
edk2/UnixPkg/Include/Ppi/UnixAutoScan.h [new file with mode: 0644]
edk2/UnixPkg/Include/Ppi/UnixFwh.h [new file with mode: 0644]
edk2/UnixPkg/Include/Ppi/UnixPeiLoadFile.h [new file with mode: 0644]
edk2/UnixPkg/Include/Ppi/UnixThunk.h [new file with mode: 0644]
edk2/UnixPkg/Include/Protocol/UnixIo.h [new file with mode: 0644]
edk2/UnixPkg/Include/Protocol/UnixThunk.h [new file with mode: 0644]
edk2/UnixPkg/Include/Protocol/UnixUgaIo.h [new file with mode: 0644]
edk2/UnixPkg/Include/UnixDxe.h [new file with mode: 0644]
edk2/UnixPkg/Include/UnixPeim.h [new file with mode: 0644]
edk2/UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf [new file with mode: 0644]
edk2/UnixPkg/Library/DxeUnixLib/DxeUnixLib.msa [new file with mode: 0644]
edk2/UnixPkg/Library/DxeUnixLib/UnixLib.c [new file with mode: 0644]
edk2/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf [new file with mode: 0644]
edk2/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.msa [new file with mode: 0644]
edk2/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c [new file with mode: 0644]
edk2/UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.c [new file with mode: 0644]
edk2/UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.inf [new file with mode: 0644]
edk2/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.inf [new file with mode: 0644]
edk2/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.msa [new file with mode: 0644]
edk2/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c [new file with mode: 0644]
edk2/UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.c [new file with mode: 0644]
edk2/UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.inf [new file with mode: 0644]
edk2/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.inf [new file with mode: 0644]
edk2/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.msa [new file with mode: 0644]
edk2/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c [new file with mode: 0644]
edk2/UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.c [new file with mode: 0644]
edk2/UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.inf [new file with mode: 0644]
edk2/UnixPkg/Library/UnixBdsLib/BdsPlatform.c [new file with mode: 0644]
edk2/UnixPkg/Library/UnixBdsLib/BdsPlatform.h [new file with mode: 0644]
edk2/UnixPkg/Library/UnixBdsLib/PlatformBds.inf [new file with mode: 0644]
edk2/UnixPkg/Library/UnixBdsLib/PlatformBds.msa [new file with mode: 0644]
edk2/UnixPkg/Library/UnixBdsLib/PlatformData.c [new file with mode: 0644]
edk2/UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoader.c [new file with mode: 0644]
edk2/UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoaderLib.inf [new file with mode: 0644]
edk2/UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoaderLib.msa [new file with mode: 0644]
edk2/UnixPkg/MetronomeDxe/Metronome.c [new file with mode: 0644]
edk2/UnixPkg/MetronomeDxe/Metronome.h [new file with mode: 0644]
edk2/UnixPkg/MetronomeDxe/Metronome.inf [new file with mode: 0644]
edk2/UnixPkg/MetronomeDxe/Metronome.msa [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturer.uni [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerData.c [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscBiosVendor.uni [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscBiosVendorData.c [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscBootInformationData.c [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscChassisManufacturer.uni [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscChassisManufacturerData.c [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscDevicePath.h [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscNumberOfInstallableLanguagesData.c [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscOemString.uni [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscOemStringData.c [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignator.uni [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorData.c [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorFunction.c [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscResetCapabilitiesData.c [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.h [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.msa [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.uni [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverDataTable.c [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscSystemLanguageString.uni [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscSystemLanguageStringData.c [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturer.uni [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerData.c [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerFunction.c [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscSystemOptionString.uni [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscSystemOptionStringData.c [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignation.uni [new file with mode: 0644]
edk2/UnixPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignationData.c [new file with mode: 0644]
edk2/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.c [new file with mode: 0644]
edk2/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf [new file with mode: 0644]
edk2/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.msa [new file with mode: 0644]
edk2/UnixPkg/ResetRuntimeDxe/Reset.c [new file with mode: 0644]
edk2/UnixPkg/ResetRuntimeDxe/Reset.inf [new file with mode: 0644]
edk2/UnixPkg/ResetRuntimeDxe/Reset.msa [new file with mode: 0644]
edk2/UnixPkg/Sec/FwVol.c [new file with mode: 0644]
edk2/UnixPkg/Sec/SecMain.c [new file with mode: 0644]
edk2/UnixPkg/Sec/SecMain.h [new file with mode: 0644]
edk2/UnixPkg/Sec/SecMain.inf [new file with mode: 0644]
edk2/UnixPkg/Sec/SecMain.msa [new file with mode: 0644]
edk2/UnixPkg/Sec/Stack.S [new file with mode: 0644]
edk2/UnixPkg/Sec/UgaX11.c [new file with mode: 0644]
edk2/UnixPkg/Sec/UnixThunk.c [new file with mode: 0644]
edk2/UnixPkg/TimerDxe/Timer.c [new file with mode: 0644]
edk2/UnixPkg/TimerDxe/Timer.h [new file with mode: 0644]
edk2/UnixPkg/TimerDxe/Timer.inf [new file with mode: 0644]
edk2/UnixPkg/TimerDxe/Timer.msa [new file with mode: 0644]
edk2/UnixPkg/UnixAutoScanPei/UnixAutoScan.c [new file with mode: 0644]
edk2/UnixPkg/UnixAutoScanPei/UnixAutoScan.inf [new file with mode: 0644]
edk2/UnixPkg/UnixAutoScanPei/UnixAutoScan.msa [new file with mode: 0644]
edk2/UnixPkg/UnixBlockIoDxe/ComponentName.c [new file with mode: 0644]
edk2/UnixPkg/UnixBlockIoDxe/DriverConfiguration.c [new file with mode: 0644]
edk2/UnixPkg/UnixBlockIoDxe/DriverDiagnostics.c [new file with mode: 0644]
edk2/UnixPkg/UnixBlockIoDxe/EntryPoint.c [new file with mode: 0644]
edk2/UnixPkg/UnixBlockIoDxe/UnixBlockIo.c [new file with mode: 0644]
edk2/UnixPkg/UnixBlockIoDxe/UnixBlockIo.h [new file with mode: 0644]
edk2/UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf [new file with mode: 0644]
edk2/UnixPkg/UnixBlockIoDxe/UnixBlockIo.msa [new file with mode: 0644]
edk2/UnixPkg/UnixBusDriverDxe/ComponentName.c [new file with mode: 0644]
edk2/UnixPkg/UnixBusDriverDxe/EntryPoint.c [new file with mode: 0644]
edk2/UnixPkg/UnixBusDriverDxe/UnixBusDriver.c [new file with mode: 0644]
edk2/UnixPkg/UnixBusDriverDxe/UnixBusDriver.h [new file with mode: 0644]
edk2/UnixPkg/UnixBusDriverDxe/UnixBusDriver.inf [new file with mode: 0644]
edk2/UnixPkg/UnixBusDriverDxe/UnixBusDriver.msa [new file with mode: 0644]
edk2/UnixPkg/UnixConsoleDxe/ComponentName.c [new file with mode: 0644]
edk2/UnixPkg/UnixConsoleDxe/Console.c [new file with mode: 0644]
edk2/UnixPkg/UnixConsoleDxe/Console.h [new file with mode: 0644]
edk2/UnixPkg/UnixConsoleDxe/ConsoleIn.c [new file with mode: 0644]
edk2/UnixPkg/UnixConsoleDxe/ConsoleOut.c [new file with mode: 0644]
edk2/UnixPkg/UnixConsoleDxe/EntryPoint.c [new file with mode: 0644]
edk2/UnixPkg/UnixConsoleDxe/UnixConsole.inf [new file with mode: 0644]
edk2/UnixPkg/UnixConsoleDxe/UnixConsole.msa [new file with mode: 0644]
edk2/UnixPkg/UnixFirmwareVolumePei/UnixFwh.c [new file with mode: 0644]
edk2/UnixPkg/UnixFirmwareVolumePei/UnixFwh.inf [new file with mode: 0644]
edk2/UnixPkg/UnixFirmwareVolumePei/UnixFwh.msa [new file with mode: 0644]
edk2/UnixPkg/UnixFlashMapPei/FlashMap.c [new file with mode: 0644]
edk2/UnixPkg/UnixFlashMapPei/FlashMap.inf [new file with mode: 0644]
edk2/UnixPkg/UnixFlashMapPei/FlashMap.msa [new file with mode: 0644]
edk2/UnixPkg/UnixPkg.dec [new file with mode: 0644]
edk2/UnixPkg/UnixPkg.dsc [new file with mode: 0644]
edk2/UnixPkg/UnixPkg.fdf [new file with mode: 0644]
edk2/UnixPkg/UnixSerialIoDxe/ComponentName.c [new file with mode: 0644]
edk2/UnixPkg/UnixSerialIoDxe/EntryPoint.c [new file with mode: 0644]
edk2/UnixPkg/UnixSerialIoDxe/UnixSerialIo.c [new file with mode: 0644]
edk2/UnixPkg/UnixSerialIoDxe/UnixSerialIo.h [new file with mode: 0644]
edk2/UnixPkg/UnixSerialIoDxe/UnixSerialIo.inf [new file with mode: 0644]
edk2/UnixPkg/UnixSerialIoDxe/UnixSerialIo.msa [new file with mode: 0644]
edk2/UnixPkg/UnixSimpleFileSystemDxe/ComponentName.c [new file with mode: 0644]
edk2/UnixPkg/UnixSimpleFileSystemDxe/EntryPoint.c [new file with mode: 0644]
edk2/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.c [new file with mode: 0644]
edk2/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.h [new file with mode: 0644]
edk2/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.inf [new file with mode: 0644]
edk2/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.msa [new file with mode: 0644]
edk2/UnixPkg/UnixThunkDxe/UnixThunk.c [new file with mode: 0644]
edk2/UnixPkg/UnixThunkDxe/UnixThunk.h [new file with mode: 0644]
edk2/UnixPkg/UnixThunkDxe/UnixThunk.inf [new file with mode: 0644]
edk2/UnixPkg/UnixThunkDxe/UnixThunk.msa [new file with mode: 0644]
edk2/UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.c [new file with mode: 0644]
edk2/UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.inf [new file with mode: 0644]
edk2/UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.msa [new file with mode: 0644]
edk2/UnixPkg/UnixUgaDxe/ComponentName.c [new file with mode: 0644]
edk2/UnixPkg/UnixUgaDxe/EntryPoint.c [new file with mode: 0644]
edk2/UnixPkg/UnixUgaDxe/UnixUga.h [new file with mode: 0644]
edk2/UnixPkg/UnixUgaDxe/UnixUga.inf [new file with mode: 0644]
edk2/UnixPkg/UnixUgaDxe/UnixUga.msa [new file with mode: 0644]
edk2/UnixPkg/UnixUgaDxe/UnixUgaDriver.c [new file with mode: 0644]
edk2/UnixPkg/UnixUgaDxe/UnixUgaInput.c [new file with mode: 0644]
edk2/UnixPkg/UnixUgaDxe/UnixUgaScreen.c [new file with mode: 0644]

diff --git a/edk2/UnixPkg/BootModePei/BootModePei.c b/edk2/UnixPkg/BootModePei/BootModePei.c
new file mode 100644 (file)
index 0000000..b7f3ad0
--- /dev/null
@@ -0,0 +1,101 @@
+/**@file\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  BootMode.c\r
+   \r
+Abstract:\r
+\r
+  Tiano PEIM to provide the platform support functionality within Unix\r
+\r
+**/\r
+\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiPei.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Ppi/MasterBootMode.h>\r
+#include <Ppi/BootInRecoveryMode.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeimEntryPoint.h>\r
+\r
+\r
+//\r
+// Module globals\r
+//\r
+EFI_PEI_PPI_DESCRIPTOR  mPpiListBootMode = {\r
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+  &gEfiPeiMasterBootModePpiGuid,\r
+  NULL\r
+};\r
+\r
+EFI_PEI_PPI_DESCRIPTOR  mPpiListRecoveryBootMode = {\r
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+  &gEfiPeiBootInRecoveryModePpiGuid,\r
+  NULL\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeBootMode (\r
+  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r
+  IN EFI_PEI_SERVICES          **PeiServices\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Peform the boot mode determination logic\r
+\r
+Arguments:\r
+\r
+  PeiServices - General purpose services available to every PEIM.\r
+    \r
+Returns:\r
+\r
+  Status -  EFI_SUCCESS if the boot mode could be set\r
+\r
+--*/\r
+// TODO:    FfsHeader - add argument and description to function comment\r
+{\r
+  EFI_STATUS  Status;\r
+  UINTN       BootMode;\r
+\r
+  DEBUG ((EFI_D_ERROR, "Unix Boot Mode PEIM Loaded\n"));\r
+\r
+  //\r
+  // Let's assume things are OK if not told otherwise\r
+  // Should we read an environment variable in order to easily change this?\r
+  //\r
+  BootMode  = BOOT_WITH_FULL_CONFIGURATION;\r
+\r
+  Status    = (**PeiServices).SetBootMode (PeiServices, (UINT8) BootMode);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = (**PeiServices).InstallPpi (PeiServices, &mPpiListBootMode);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  if (BootMode == BOOT_IN_RECOVERY_MODE) {\r
+    Status = (**PeiServices).InstallPpi (PeiServices, &mPpiListRecoveryBootMode);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
+  return Status;\r
+}\r
diff --git a/edk2/UnixPkg/BootModePei/BootModePei.inf b/edk2/UnixPkg/BootModePei/BootModePei.inf
new file mode 100644 (file)
index 0000000..d991507
--- /dev/null
@@ -0,0 +1,57 @@
+#/** @file\r
+# Component description file for BootMode module\r
+#\r
+# This module provides platform specific function to detect boot mode.\r
+# Copyright (c) 2006 - 2008, Intel Corporation\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = BootModePei\r
+  FILE_GUID                      = f3ff9aee-8985-11db-b133-0040d02b1835\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeBootMode\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  BootModePei.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  PeiServicesTablePointerLib\r
+  PeiServicesLib\r
+  BaseLib\r
+  PeimEntryPoint\r
+  DebugLib\r
+\r
+\r
+[Ppis]\r
+  gEfiPeiMasterBootModePpiGuid                  # PPI ALWAYS_PRODUCED\r
+  gEfiPeiBootInRecoveryModePpiGuid              # PPI SOMETIMES_PRODUCED\r
+\r
+\r
+[Depex]\r
+  TRUE\r
+\r
diff --git a/edk2/UnixPkg/BootModePei/BootModePei.msa b/edk2/UnixPkg/BootModePei/BootModePei.msa
new file mode 100644 (file)
index 0000000..5b2c8d8
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>BootMode</ModuleName>\r
+    <ModuleType>PEIM</ModuleType>\r
+    <GuidValue>f3ff9aee-8985-11db-b133-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for BootMode module</Abstract>\r
+    <Description>This module provides platform specific function to detect boot mode.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>All rights reserved. This program and the accompanying materials\r
+      are licensed and made available under the terms and conditions of the BSD License\r
+      which accompanies this distribution.  The full text of the license may be found at\r
+      http://opensource.org/licenses/bsd-license.php\r
+      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+      WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>BootMode</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeimEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeiServicesLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeiServicesTablePointerLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>BootMode.c</Filename>\r
+    <Filename>BootMode.dxs</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <PPIs>\r
+    <Ppi Usage="SOMETIMES_PRODUCED">\r
+      <PpiCName>gEfiPeiBootInRecoveryModePpiGuid</PpiCName>\r
+    </Ppi>\r
+    <Ppi Usage="ALWAYS_PRODUCED">\r
+      <PpiCName>gEfiPeiMasterBootModePpiGuid</PpiCName>\r
+    </Ppi>\r
+  </PPIs>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>InitializeBootMode</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/edk2/UnixPkg/CpuRuntimeDxe/Cpu.c b/edk2/UnixPkg/CpuRuntimeDxe/Cpu.c
new file mode 100644 (file)
index 0000000..aef2c30
--- /dev/null
@@ -0,0 +1,536 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  Cpu.c\r
+\r
+Abstract:\r
+\r
+  Unix Emulation Architectural Protocol Driver as defined in Tiano.\r
+  This CPU module abstracts the interrupt subsystem of a platform and\r
+  the CPU-specific setjump/long pair.  Other services are not implemented\r
+  in this driver.\r
+\r
+--*/\r
+#include "PiDxe.h"\r
+#include <Protocol/Cpu.h>\r
+#include <Protocol/DataHub.h>\r
+#include <Guid/DataHubRecords.h>\r
+#include <Protocol/CpuIo.h>\r
+#include <Protocol/FrameworkHii.h>\r
+#include <Guid/DataHubProducer.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HiiLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Framework/DataHubRecords.h>\r
+#include "CpuDriver.h"\r
+#include "UnixDxe.h"\r
+#include <Protocol/UnixIo.h>\r
+\r
+#define EFI_CPU_DATA_MAXIMUM_LENGTH 0x100\r
+\r
+CPU_ARCH_PROTOCOL_PRIVATE mCpuTemplate = {\r
+  CPU_ARCH_PROT_PRIVATE_SIGNATURE,\r
+  NULL,\r
+  {\r
+    UnixFlushCpuDataCache,\r
+    UnixEnableInterrupt,\r
+    UnixDisableInterrupt,\r
+    UnixGetInterruptState,\r
+    UnixInit,\r
+    UnixRegisterInterruptHandler,\r
+    UnixGetTimerValue,\r
+    UnixSetMemoryAttributes,\r
+    0,\r
+    4\r
+  },\r
+  {\r
+    CpuMemoryServiceRead,\r
+    CpuMemoryServiceWrite,\r
+    CpuIoServiceRead,\r
+    CpuIoServiceWrite\r
+  },\r
+  0,\r
+  TRUE\r
+};\r
+\r
+typedef union {\r
+  EFI_CPU_DATA_RECORD *DataRecord;\r
+  UINT8               *Raw;\r
+} EFI_CPU_DATA_RECORD_BUFFER;\r
+\r
+EFI_SUBCLASS_TYPE1_HEADER mCpuDataRecordHeader = {\r
+  EFI_PROCESSOR_SUBCLASS_VERSION,       // Version\r
+  sizeof (EFI_SUBCLASS_TYPE1_HEADER),   // Header Size\r
+  0,                                    // Instance, Initialize later\r
+  EFI_SUBCLASS_INSTANCE_NON_APPLICABLE, // SubInstance\r
+  0                                     // RecordType, Initialize later\r
+};\r
+\r
+//\r
+// Service routines for the driver\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+UnixFlushCpuDataCache (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_PHYSICAL_ADDRESS   Start,\r
+  IN UINT64                 Length,\r
+  IN EFI_CPU_FLUSH_TYPE     FlushType\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This routine would provide support for flushing the CPU data cache.\r
+  In the case of UNIX emulation environment, this flushing is not necessary and\r
+  is thus not implemented.\r
+\r
+Arguments:\r
+\r
+  Pointer to CPU Architectural Protocol interface\r
+  Start adddress in memory to flush\r
+  Length of memory to flush\r
+  Flush type\r
+\r
+Returns:\r
+\r
+  Status\r
+    EFI_SUCCESS\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    FlushType - add argument and description to function comment\r
+// TODO:    EFI_UNSUPPORTED - add return value to function comment\r
+{\r
+  if (FlushType == EfiCpuFlushTypeWriteBackInvalidate) {\r
+    //\r
+    // Only WB flush is supported. We actually need do nothing on UNIX emulator\r
+    // environment. Classify this to follow EFI spec\r
+    //\r
+    return EFI_SUCCESS;\r
+  }\r
+  //\r
+  // Other flush types are not supported by UNIX emulator\r
+  //\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixEnableInterrupt (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This routine provides support for emulation of the interrupt enable of the\r
+  the system.  For our purposes, CPU enable is just a BOOLEAN that the Timer\r
+  Architectural Protocol observes in order to defer behaviour while in its\r
+  emulated interrupt, or timer tick.\r
+\r
+Arguments:\r
+\r
+  Pointer to CPU Architectural Protocol interface\r
+\r
+Returns:\r
+\r
+  Status\r
+    EFI_SUCCESS\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  Private                 = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  Private->InterruptState = TRUE;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixDisableInterrupt (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This routine provides support for emulation of the interrupt disable of the\r
+  the system.  For our purposes, CPU enable is just a BOOLEAN that the Timer\r
+  Architectural Protocol observes in order to defer behaviour while in its\r
+  emulated interrupt, or timer tick.\r
+\r
+Arguments:\r
+\r
+  Pointer to CPU Architectural Protocol interface\r
+\r
+Returns:\r
+\r
+  Status\r
+    EFI_SUCCESS\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  Private                 = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  Private->InterruptState = FALSE;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixGetInterruptState (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  OUT BOOLEAN               *State\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This routine provides support for emulation of the interrupt disable of the\r
+  the system.  For our purposes, CPU enable is just a BOOLEAN that the Timer\r
+  Architectural Protocol observes in order to defer behaviour while in its\r
+  emulated interrupt, or timer tick.\r
+\r
+Arguments:\r
+\r
+  Pointer to CPU Architectural Protocol interface\r
+\r
+Returns:\r
+\r
+  Status\r
+    EFI_SUCCESS\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    State - add argument and description to function comment\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  if (State == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  *State  = Private->InterruptState;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixInit (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_CPU_INIT_TYPE      InitType\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This routine would support generation of a CPU INIT.  At\r
+  present, this code does not provide emulation.\r
+\r
+Arguments:\r
+\r
+  Pointer to CPU Architectural Protocol interface\r
+  INIT Type\r
+\r
+Returns:\r
+\r
+  Status\r
+    EFI_UNSUPPORTED - not yet implemented\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    InitType - add argument and description to function comment\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixRegisterInterruptHandler (\r
+  IN EFI_CPU_ARCH_PROTOCOL      *This,\r
+  IN EFI_EXCEPTION_TYPE         InterruptType,\r
+  IN EFI_CPU_INTERRUPT_HANDLER  InterruptHandler\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This routine would support registration of an interrupt handler.  At\r
+  present, this code does not provide emulation.\r
+\r
+Arguments:\r
+\r
+  Pointer to CPU Architectural Protocol interface\r
+  Pointer to interrupt handlers\r
+  Interrupt type\r
+\r
+Returns:\r
+\r
+  Status\r
+    EFI_UNSUPPORTED - not yet implemented\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    InterruptType - add argument and description to function comment\r
+// TODO:    InterruptHandler - add argument and description to function comment\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  //\r
+  // Do parameter checking for EFI spec conformance\r
+  //\r
+  if (InterruptType < 0 || InterruptType > 0xff) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Do nothing for Nt32 emulation\r
+  //\r
+  Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixGetTimerValue (\r
+  IN  EFI_CPU_ARCH_PROTOCOL *This,\r
+  IN  UINT32                TimerIndex,\r
+  OUT UINT64                *TimerValue,\r
+  OUT UINT64                *TimerPeriod OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This routine would support querying of an on-CPU timer.  At present,\r
+  this code does not provide timer emulation.\r
+\r
+Arguments:\r
+\r
+  This        - Pointer to CPU Architectural Protocol interface\r
+  TimerIndex  - Index of given CPU timer\r
+  TimerValue  - Output of the timer\r
+  TimerPeriod - Output of the timer period\r
+\r
+Returns:\r
+\r
+  EFI_UNSUPPORTED       - not yet implemented\r
+  EFI_INVALID_PARAMETER - TimeValue is NULL\r
+\r
+--*/\r
+{\r
+  if (TimerValue == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // No timer supported\r
+  //\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSetMemoryAttributes (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_PHYSICAL_ADDRESS   BaseAddress,\r
+  IN UINT64                 Length,\r
+  IN UINT64                 Attributes\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This routine would support querying of an on-CPU timer.  At present,\r
+  this code does not provide timer emulation.\r
+\r
+Arguments:\r
+\r
+  Pointer to CPU Architectural Protocol interface\r
+  Start address of memory region\r
+  The size in bytes of the memory region\r
+  The bit mask of attributes to set for the memory region\r
+\r
+Returns:\r
+\r
+  Status\r
+    EFI_UNSUPPORTED - not yet implemented\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    BaseAddress - add argument and description to function comment\r
+// TODO:    Length - add argument and description to function comment\r
+// TODO:    Attributes - add argument and description to function comment\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  //\r
+  // Check for invalid parameter for Spec conformance\r
+  //\r
+  if (Length == 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Do nothing for Nt32 emulation\r
+  //\r
+  Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+VOID\r
+CpuUpdateDataHub (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  This function will log processor version and frequency data to data hub.\r
+\r
+Arguments:\r
+  Event        - Event whose notification function is being invoked.\r
+  Context      - Pointer to the notification function's context.\r
+\r
+Returns:\r
+  None.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_CPU_DATA_RECORD_BUFFER  RecordBuffer;\r
+  UINT32                      HeaderSize;\r
+  UINT32                      TotalSize;\r
+  EFI_DATA_HUB_PROTOCOL       *DataHub;\r
+  EFI_HII_HANDLE              HiiHandle;\r
+\r
+  //\r
+  // Locate DataHub protocol.\r
+  //\r
+  Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, &DataHub);\r
+  if (EFI_ERROR (Status)) {\r
+    return;\r
+  }\r
+\r
+  //\r
+  // Initialize data record header\r
+  //\r
+  mCpuDataRecordHeader.Instance = 1;\r
+  HeaderSize                    = sizeof (EFI_SUBCLASS_TYPE1_HEADER);\r
+\r
+  RecordBuffer.Raw              = AllocatePool (HeaderSize + EFI_CPU_DATA_MAXIMUM_LENGTH);\r
+  if (RecordBuffer.Raw == NULL) {\r
+    return ;\r
+  }\r
+\r
+  //\r
+  // Initialize strings to HII database\r
+  //\r
+  HiiLibAddPackages (1, &gEfiProcessorProducerGuid, NULL, &HiiHandle, CpuStrings);\r
+  \r
+\r
+  CopyMem (RecordBuffer.Raw, &mCpuDataRecordHeader, HeaderSize);\r
+\r
+\r
+  RecordBuffer.DataRecord->DataRecordHeader.RecordType      = ProcessorVersionRecordType;\r
+  RecordBuffer.DataRecord->VariableRecord.ProcessorVersion  = STRING_TOKEN (STR_INTEL_GENUINE_PROCESSOR);\r
+  TotalSize = HeaderSize + sizeof (EFI_PROCESSOR_VERSION_DATA);\r
+\r
+  Status = DataHub->LogData (\r
+                      DataHub,\r
+                      &gEfiProcessorSubClassGuid,\r
+                      &gEfiProcessorProducerGuid,\r
+                      EFI_DATA_RECORD_CLASS_DATA,\r
+                      RecordBuffer.Raw,\r
+                      TotalSize\r
+                      );\r
+\r
+  //\r
+  // Store CPU frequency data record to data hub - It's an emulator so make up a value\r
+  //\r
+  RecordBuffer.DataRecord->DataRecordHeader.RecordType                    = ProcessorCoreFrequencyRecordType;\r
+  RecordBuffer.DataRecord->VariableRecord.ProcessorCoreFrequency.Value    = 1234;\r
+  RecordBuffer.DataRecord->VariableRecord.ProcessorCoreFrequency.Exponent = 6;\r
+  TotalSize = HeaderSize + sizeof (EFI_PROCESSOR_CORE_FREQUENCY_DATA);\r
+\r
+  Status = DataHub->LogData (\r
+                      DataHub,\r
+                      &gEfiProcessorSubClassGuid,\r
+                      &gEfiProcessorProducerGuid,\r
+                      EFI_DATA_RECORD_CLASS_DATA,\r
+                      RecordBuffer.Raw,\r
+                      TotalSize\r
+                      );\r
+\r
+  FreePool (RecordBuffer.Raw);\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeCpu (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Initialize the state information for the CPU Architectural Protocol\r
+\r
+Arguments:\r
+\r
+  ImageHandle of the loaded driver\r
+  Pointer to the System Table\r
+\r
+Returns:\r
+\r
+  Status\r
+\r
+  EFI_SUCCESS           - protocol instance can be published\r
+  EFI_OUT_OF_RESOURCES  - cannot allocate protocol data structure\r
+  EFI_DEVICE_ERROR      - cannot create the thread\r
+\r
+--*/\r
+// TODO:    SystemTable - add argument and description to function comment\r
+{\r
+  EFI_STATUS                Status;\r
+\r
+  CpuUpdateDataHub ();\r
+\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &mCpuTemplate.Handle,\r
+                  &gEfiCpuArchProtocolGuid,   &mCpuTemplate.Cpu,\r
+                  &gEfiCpuIoProtocolGuid,     &mCpuTemplate.CpuIo,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  DEBUG ((EFI_D_ERROR, "CPU Architectural Protocol Loaded\n"));\r
+\r
+  return Status;\r
+}\r
diff --git a/edk2/UnixPkg/CpuRuntimeDxe/Cpu.inf b/edk2/UnixPkg/CpuRuntimeDxe/Cpu.inf
new file mode 100644 (file)
index 0000000..a8613ff
--- /dev/null
@@ -0,0 +1,73 @@
+#/** @file\r
+# Component description file for Cpu module.\r
+#\r
+# This CPU module abstracts the interrupt subsystem of a platform and the CPU-specific setjump-long pair.\r
+# Copyright (c) 2006 - 2008, Intel Corporation\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = Cpu\r
+  FILE_GUID                      = f3794b60-8985-11db-8e53-0040d02b1835\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeCpu\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  CpuIo.c\r
+  Cpu.c\r
+  CpuDriver.h\r
+  Strings.uni\r
+\r
+\r
+[Packages]\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  HiiLib\r
+  DebugLib\r
+  BaseLib\r
+\r
+\r
+[Guids]\r
+  gEfiProcessorSubClassGuid                     # SOMETIMES_CONSUMED\r
+  gEfiProcessorProducerGuid                     # SOMETIMES_CONSUMED\r
+\r
+\r
+[Protocols]\r
+  gEfiUnixIoProtocolGuid                        # PROTOCOL_NOTIFY SOMETIMES_CONSUMED\r
+  gEfiDataHubProtocolGuid                       # PROTOCOL SOMETIMES_CONSUMED\r
+  gEfiHiiProtocolGuid                           # PROTOCOL SOMETIMES_CONSUMED\r
+  gEfiCpuIoProtocolGuid                         # PROTOCOL ALWAYS_PRODUCED\r
+  gEfiCpuArchProtocolGuid                       # PROTOCOL ALWAYS_PRODUCED\r
+\r
+\r
+[Depex]\r
+  gEfiDataHubProtocolGuid
\ No newline at end of file
diff --git a/edk2/UnixPkg/CpuRuntimeDxe/Cpu.msa b/edk2/UnixPkg/CpuRuntimeDxe/Cpu.msa
new file mode 100644 (file)
index 0000000..b6be83f
--- /dev/null
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>Cpu</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>f3794b60-8985-11db-8e53-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for Cpu module.</Abstract>\r
+    <Description>This CPU module abstracts the interrupt subsystem of a platform and the CPU-specific setjump-long pair.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>All rights reserved. This program and the accompanying materials\r
+      are licensed and made available under the terms and conditions of the BSD License\r
+      which accompanies this distribution.  The full text of the license may be found at\r
+      http://opensource.org/licenses/bsd-license.php\r
+      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+      WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>Cpu</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>HiiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>Strings.uni</Filename>\r
+    <Filename>CpuDriver.h</Filename>\r
+    <Filename>Cpu.c</Filename>\r
+    <Filename>CpuIo.c</Filename>\r
+    <Filename>Cpu.dxs</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiCpuArchProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiCpuIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="SOMETIMES_CONSUMED">\r
+      <ProtocolCName>gEfiHiiProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="SOMETIMES_CONSUMED">\r
+      <ProtocolCName>gEfiDataHubProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <ProtocolNotify Usage="SOMETIMES_CONSUMED">\r
+      <ProtocolNotifyCName>gEfiUnixIoProtocolGuid</ProtocolNotifyCName>\r
+    </ProtocolNotify>\r
+  </Protocols>\r
+  <DataHubs>\r
+    <DataHubRecord Usage="SOMETIMES_PRODUCED">\r
+      <DataHubCName>ProcessorVersion</DataHubCName>\r
+    </DataHubRecord>\r
+    <DataHubRecord Usage="SOMETIMES_PRODUCED">\r
+      <DataHubCName>ProcessorCoreFrequency</DataHubCName>\r
+    </DataHubRecord>\r
+  </DataHubs>\r
+  <Guids>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiProcessorProducerGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiProcessorSubClassGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiUnixCPUModelGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiUnixCPUSpeedGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>InitializeCpu</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/edk2/UnixPkg/CpuRuntimeDxe/CpuDriver.h b/edk2/UnixPkg/CpuRuntimeDxe/CpuDriver.h
new file mode 100644 (file)
index 0000000..8898143
--- /dev/null
@@ -0,0 +1,163 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  CpuDriver.h\r
+\r
+Abstract:\r
+\r
+  UNIX Emulation Architectural Protocol Driver as defined in Tiano.\r
+\r
+--*/\r
+\r
+#ifndef _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_\r
+#define _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_\r
+\r
+\r
+\r
+extern UINT8  CpuStrings[];\r
+\r
+//\r
+// Internal Data Structures\r
+//\r
+#define CPU_ARCH_PROT_PRIVATE_SIGNATURE EFI_SIGNATURE_32 ('c', 'a', 'p', 'd')\r
+\r
+typedef struct {\r
+  UINTN                 Signature;\r
+  EFI_HANDLE            Handle;\r
+\r
+  EFI_CPU_ARCH_PROTOCOL Cpu;\r
+  EFI_CPU_IO_PROTOCOL   CpuIo;\r
+\r
+  //\r
+  // Local Data for CPU interface goes here\r
+  //\r
+  BOOLEAN               InterruptState;\r
+\r
+} CPU_ARCH_PROTOCOL_PRIVATE;\r
+\r
+#define CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS(a) \\r
+  CR (a, \\r
+      CPU_ARCH_PROTOCOL_PRIVATE, \\r
+      Cpu, \\r
+      CPU_ARCH_PROT_PRIVATE_SIGNATURE \\r
+      )\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceRead (\r
+  IN  EFI_CPU_IO_PROTOCOL               *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            Address,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceWrite (\r
+  IN EFI_CPU_IO_PROTOCOL                *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            Address,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceRead (\r
+  IN EFI_CPU_IO_PROTOCOL                *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            UserAddress,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *UserBuffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceWrite (\r
+  IN EFI_CPU_IO_PROTOCOL                *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            UserAddress,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *UserBuffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeCpu (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixFlushCpuDataCache (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_PHYSICAL_ADDRESS   Start,\r
+  IN UINT64                 Length,\r
+  IN EFI_CPU_FLUSH_TYPE     FlushType\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixEnableInterrupt (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixDisableInterrupt (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixGetInterruptState (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  OUT BOOLEAN               *State\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixInit (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_CPU_INIT_TYPE      InitType\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixRegisterInterruptHandler (\r
+  IN EFI_CPU_ARCH_PROTOCOL      *This,\r
+  IN EFI_EXCEPTION_TYPE         InterruptType,\r
+  IN EFI_CPU_INTERRUPT_HANDLER  InterruptHandler\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixGetTimerValue (\r
+  IN  EFI_CPU_ARCH_PROTOCOL *This,\r
+  IN  UINT32                TimerIndex,\r
+  OUT UINT64                *TimerValue,\r
+  OUT UINT64                *TimerPeriod OPTIONAL\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSetMemoryAttributes (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_PHYSICAL_ADDRESS   BaseAddress,\r
+  IN UINT64                 Length,\r
+  IN UINT64                 Attributes\r
+  );\r
+\r
+#endif\r
diff --git a/edk2/UnixPkg/CpuRuntimeDxe/CpuIo.c b/edk2/UnixPkg/CpuRuntimeDxe/CpuIo.c
new file mode 100644 (file)
index 0000000..2360fff
--- /dev/null
@@ -0,0 +1,350 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  CpuIo.c\r
+\r
+Abstract:\r
+\r
+  This is the code that publishes the CPU I/O Protocol.\r
+  The intent herein is to have a single I/O service that can load\r
+  as early as possible, extend into runtime, and be layered upon by \r
+  the implementations of architectural protocols and the PCI Root\r
+  Bridge I/O Protocol.\r
+\r
+--*/\r
+#include "PiDxe.h"\r
+#include <Protocol/Cpu.h>\r
+#include <Protocol/DataHub.h>\r
+#include <Guid/DataHubRecords.h>\r
+#include <Protocol/CpuIo.h>\r
+#include <Protocol/FrameworkHii.h>\r
+#include <Guid/DataHubProducer.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HiiLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <CpuDriver.h>\r
+\r
+#define IA32_MAX_IO_ADDRESS   0xFFFF\r
+#define IA32_MAX_MEM_ADDRESS  0xFFFFFFFF\r
+\r
+EFI_CPU_IO_PROTOCOL mCpuIoProtocol;\r
+\r
+EFI_STATUS\r
+CpuIoCheckAddressRange (\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            Address,\r
+  IN  UINTN                             Count,\r
+  IN  VOID                              *Buffer,\r
+  IN  UINT64                            Limit\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceRead (\r
+  IN  EFI_CPU_IO_PROTOCOL               *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            Address,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Perform the Memory Access Read service for the CPU I/O Protocol\r
+\r
+Arguments:\r
+\r
+  Pointer to an instance of the CPU I/O Protocol\r
+  Width of the Memory Access\r
+  Address of the Memory access\r
+  Count of the number of accesses to perform\r
+  Pointer to the buffer to read or write from memory\r
+\r
+Returns:\r
+\r
+  Status\r
+\r
+  EFI_SUCCESS             - The data was read from or written to the EFI \r
+                            System.\r
+  EFI_INVALID_PARAMETER   - Width is invalid for this EFI System.\r
+  EFI_INVALID_PARAMETER   - Buffer is NULL.\r
+  EFI_UNSUPPORTED         - The Buffer is not aligned for the given Width.\r
+  EFI_UNSUPPORTED         - The address range specified by Address, Width, \r
+                            and Count is not valid for this EFI System.\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  if (!Buffer) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Do nothing for Nt32 version\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceWrite (\r
+  IN EFI_CPU_IO_PROTOCOL                *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            Address,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Perform the Memory Access Read service for the CPU I/O Protocol\r
+\r
+Arguments:\r
+\r
+  Pointer to an instance of the CPU I/O Protocol\r
+  Width of the Memory Access\r
+  Address of the Memory access\r
+  Count of the number of accesses to perform\r
+  Pointer to the buffer to read or write from memory\r
+\r
+Returns:\r
+\r
+  Status\r
+\r
+  EFI_SUCCESS             - The data was read from or written to the EFI System.\r
+  EFI_INVALID_PARAMETER   - Width is invalid for this EFI System.\r
+  EFI_INVALID_PARAMETER   - Buffer is NULL.\r
+  EFI_UNSUPPORTED         - The Buffer is not aligned for the given Width.\r
+  EFI_UNSUPPORTED         - The address range specified by Address, Width, and \r
+                            Count is not valid for this EFI System.\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  if (!Buffer) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Do nothing for Nt32 version\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceRead (\r
+  IN EFI_CPU_IO_PROTOCOL                *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            UserAddress,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *UserBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  \r
+  This is the service that implements the I/O read\r
+\r
+Arguments:\r
+\r
+  Pointer to an instance of the CPU I/O Protocol\r
+  Width of the Memory Access\r
+  Address of the I/O access\r
+  Count of the number of accesses to perform\r
+  Pointer to the buffer to read or write from I/O space\r
+\r
+Returns:\r
+\r
+  Status\r
+  EFI_SUCCESS             - The data was read from or written to the EFI System.\r
+  EFI_INVALID_PARAMETER   - Width is invalid for this EFI System.\r
+  EFI_INVALID_PARAMETER   - Buffer is NULL.\r
+  EFI_UNSUPPORTED         - The Buffer is not aligned for the given Width.\r
+  EFI_UNSUPPORTED         - The address range specified by Address, Width, and \r
+                            Count is not valid for this EFI System.\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    UserAddress - add argument and description to function comment\r
+// TODO:    UserBuffer - add argument and description to function comment\r
+{\r
+  UINTN       Address;\r
+  EFI_STATUS  Status;\r
+\r
+  if (!UserBuffer) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Address = (UINTN) UserAddress;\r
+\r
+  if (Width >= EfiCpuIoWidthMaximum) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Do nothing for Nt32 version\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceWrite (\r
+  IN EFI_CPU_IO_PROTOCOL                *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            UserAddress,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *UserBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  \r
+  This is the service that implements the I/O Write\r
+\r
+Arguments:\r
+\r
+  Pointer to an instance of the CPU I/O Protocol\r
+  Width of the Memory Access\r
+  Address of the I/O access\r
+  Count of the number of accesses to perform\r
+  Pointer to the buffer to read or write from I/O space\r
+\r
+Returns:\r
+\r
+  Status\r
+\r
+  Status\r
+  EFI_SUCCESS             - The data was read from or written to the EFI System.\r
+  EFI_INVALID_PARAMETER   - Width is invalid for this EFI System.\r
+  EFI_INVALID_PARAMETER   - Buffer is NULL.\r
+  EFI_UNSUPPORTED         - The Buffer is not aligned for the given Width.\r
+  EFI_UNSUPPORTED         - The address range specified by Address, Width, and \r
+                            Count is not valid for this EFI System.\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    UserAddress - add argument and description to function comment\r
+// TODO:    UserBuffer - add argument and description to function comment\r
+{\r
+  UINTN       Address;\r
+  EFI_STATUS  Status;\r
+\r
+  if (!UserBuffer) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Address = (UINTN) UserAddress;\r
+\r
+  if (Width >= EfiCpuIoWidthMaximum) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Do nothing for Nt32 version\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+CpuIoCheckAddressRange (\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            Address,\r
+  IN  UINTN                             Count,\r
+  IN  VOID                              *Buffer,\r
+  IN  UINT64                            Limit\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Width   - TODO: add argument description\r
+  Address - TODO: add argument description\r
+  Count   - TODO: add argument description\r
+  Buffer  - TODO: add argument description\r
+  Limit   - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_UNSUPPORTED - TODO: Add description for return value\r
+  EFI_UNSUPPORTED - TODO: Add description for return value\r
+  EFI_UNSUPPORTED - TODO: Add description for return value\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UINTN AlignMask;\r
+\r
+  if (Address > Limit) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // For FiFo type, the target address won't increase during the access, so treat count as 1\r
+  //\r
+  if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {\r
+    Count = 1;\r
+  }\r
+\r
+  Width = Width & 0x03;\r
+  if (Address - 1 + (1 << Width) * Count > Limit) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  AlignMask = (1 << Width) - 1;\r
+  if ((UINTN) Buffer & AlignMask) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
diff --git a/edk2/UnixPkg/CpuRuntimeDxe/Strings.uni b/edk2/UnixPkg/CpuRuntimeDxe/Strings.uni
new file mode 100644 (file)
index 0000000..fd70fb9
Binary files /dev/null and b/edk2/UnixPkg/CpuRuntimeDxe/Strings.uni differ
diff --git a/edk2/UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c b/edk2/UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c
new file mode 100644 (file)
index 0000000..5889586
--- /dev/null
@@ -0,0 +1,1553 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  FWBlockService.c\r
+    \r
+Abstract:\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+#include "PiDxe.h"\r
+#include <Guid/EventGroup.h>\r
+#include <Protocol/FvbExtension.h>\r
+#include <Protocol/FirmwareVolumeBlock.h>\r
+#include <Guid/AlternateFvBlock.h>\r
+#include <Protocol/DevicePath.h>\r
+\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DxeServicesTableLib.h>\r
+#include <Library/UefiRuntimeLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include "FwBlockService.h"\r
+\r
+ESAL_FWB_GLOBAL         *mFvbModuleGlobal;\r
+\r
+#define EFI_FVB2_STATUS (EFI_FVB2_READ_STATUS | EFI_FVB2_WRITE_STATUS | EFI_FVB2_LOCK_STATUS)\r
+\r
+EFI_FW_VOL_BLOCK_DEVICE mFvbDeviceTemplate = {\r
+  FVB_DEVICE_SIGNATURE,\r
+  {\r
+    {\r
+      {\r
+        HARDWARE_DEVICE_PATH,\r
+        HW_MEMMAP_DP,\r
+        {\r
+          sizeof (MEMMAP_DEVICE_PATH),\r
+          0\r
+        }\r
+      },\r
+      EfiMemoryMappedIO,\r
+      0,\r
+      0,\r
+    },\r
+    {\r
+      END_DEVICE_PATH_TYPE,\r
+      END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+      {\r
+        sizeof (EFI_DEVICE_PATH_PROTOCOL),\r
+        0\r
+      }\r
+    }\r
+  },\r
+  0,\r
+  {\r
+    FvbProtocolGetAttributes,\r
+    FvbProtocolSetAttributes,\r
+    FvbProtocolGetPhysicalAddress,\r
+    FvbProtocolGetBlockSize,\r
+    FvbProtocolRead,\r
+    FvbProtocolWrite,\r
+    FvbProtocolEraseBlocks,\r
+    NULL\r
+  },\r
+  {\r
+    FvbExtendProtocolEraseCustomBlockRange\r
+  }\r
+};\r
+\r
+\r
+\r
+VOID\r
+EFIAPI\r
+FvbVirtualddressChangeEvent (\r
+  IN EFI_EVENT        Event,\r
+  IN VOID             *Context\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Fixup internal data so that EFI and SAL can be call in virtual mode.\r
+  Call the passed in Child Notify event and convert the mFvbModuleGlobal\r
+  date items to there virtual address.\r
+\r
+  mFvbModuleGlobal->FvInstance[FVB_PHYSICAL]  - Physical copy of instance data\r
+  mFvbModuleGlobal->FvInstance[FVB_VIRTUAL]   - Virtual pointer to common \r
+                                                instance data.\r
+\r
+Arguments:\r
+\r
+  (Standard EFI notify event - EFI_EVENT_NOTIFY)\r
+\r
+Returns: \r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_INSTANCE *FwhInstance;\r
+  UINTN               Index;\r
+\r
+  EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal->FvInstance[FVB_VIRTUAL]);\r
+\r
+  //\r
+  // Convert the base address of all the instances\r
+  //\r
+  Index       = 0;\r
+  FwhInstance = mFvbModuleGlobal->FvInstance[FVB_PHYSICAL];\r
+  while (Index < mFvbModuleGlobal->NumFv) {\r
+    EfiConvertPointer (0x0, (VOID **) &FwhInstance->FvBase[FVB_VIRTUAL]);\r
+    FwhInstance = (EFI_FW_VOL_INSTANCE *)\r
+      (\r
+        (UINTN) ((UINT8 *) FwhInstance) + FwhInstance->VolumeHeader.HeaderLength +\r
+          (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))\r
+      );\r
+    Index++;\r
+  }\r
+\r
+  EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal->FvbScratchSpace[FVB_VIRTUAL]);\r
+  EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal);\r
+}\r
+\r
+EFI_STATUS\r
+GetFvbInstance (\r
+  IN  UINTN                               Instance,\r
+  IN  ESAL_FWB_GLOBAL                     *Global,\r
+  OUT EFI_FW_VOL_INSTANCE                 **FwhInstance,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Retrieves the physical address of a memory mapped FV\r
+\r
+Arguments:\r
+  Instance              - The FV instance whose base address is going to be\r
+                          returned\r
+  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
+                          instance data\r
+  FwhInstance           - The EFI_FW_VOL_INSTANCE fimrware instance structure\r
+  Virtual               - Whether CPU is in virtual or physical mode\r
+\r
+Returns: \r
+  EFI_SUCCESS           - Successfully returns\r
+  EFI_INVALID_PARAMETER - Instance not found\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_INSTANCE *FwhRecord;\r
+\r
+  if (Instance >= Global->NumFv) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Find the right instance of the FVB private data\r
+  //\r
+  FwhRecord = Global->FvInstance[Virtual];\r
+  while (Instance > 0) {\r
+    FwhRecord = (EFI_FW_VOL_INSTANCE *)\r
+      (\r
+        (UINTN) ((UINT8 *) FwhRecord) + FwhRecord->VolumeHeader.HeaderLength +\r
+          (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))\r
+      );\r
+    Instance--;\r
+  }\r
+\r
+  *FwhInstance = FwhRecord;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+FvbGetPhysicalAddress (\r
+  IN UINTN                                Instance,\r
+  OUT EFI_PHYSICAL_ADDRESS                *Address,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Retrieves the physical address of a memory mapped FV\r
+\r
+Arguments:\r
+  Instance              - The FV instance whose base address is going to be\r
+                          returned\r
+  Address               - Pointer to a caller allocated EFI_PHYSICAL_ADDRESS \r
+                          that on successful return, contains the base address\r
+                          of the firmware volume. \r
+  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
+                          instance data\r
+  Virtual               - Whether CPU is in virtual or physical mode\r
+\r
+Returns: \r
+  EFI_SUCCESS           - Successfully returns\r
+  EFI_INVALID_PARAMETER - Instance not found\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_INSTANCE *FwhInstance;\r
+  EFI_STATUS          Status;\r
+\r
+  //\r
+  // Find the right instance of the FVB private data\r
+  //\r
+  Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+  ASSERT_EFI_ERROR (Status);\r
+  *Address = FwhInstance->FvBase[Virtual];\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+FvbGetVolumeAttributes (\r
+  IN UINTN                                Instance,\r
+  OUT EFI_FVB_ATTRIBUTES                  *Attributes,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Retrieves attributes, insures positive polarity of attribute bits, returns\r
+  resulting attributes in output parameter\r
+\r
+Arguments:\r
+  Instance              - The FV instance whose attributes is going to be \r
+                          returned\r
+  Attributes            - Output buffer which contains attributes\r
+  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
+                          instance data\r
+  Virtual               - Whether CPU is in virtual or physical mode\r
+\r
+Returns: \r
+  EFI_SUCCESS           - Successfully returns\r
+  EFI_INVALID_PARAMETER - Instance not found\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_INSTANCE *FwhInstance;\r
+  EFI_STATUS          Status;\r
+\r
+  //\r
+  // Find the right instance of the FVB private data\r
+  //\r
+  Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+  ASSERT_EFI_ERROR (Status);\r
+  *Attributes = FwhInstance->VolumeHeader.Attributes;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+FvbGetLbaAddress (\r
+  IN  UINTN                               Instance,\r
+  IN  EFI_LBA                             Lba,\r
+  OUT UINTN                               *LbaAddress,\r
+  OUT UINTN                               *LbaLength,\r
+  OUT UINTN                               *NumOfBlocks,\r
+  IN  ESAL_FWB_GLOBAL                     *Global,\r
+  IN  BOOLEAN                             Virtual\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Retrieves the starting address of an LBA in an FV\r
+\r
+Arguments:\r
+  Instance              - The FV instance which the Lba belongs to\r
+  Lba                   - The logical block address\r
+  LbaAddress            - On output, contains the physical starting address \r
+                          of the Lba\r
+  LbaLength             - On output, contains the length of the block\r
+  NumOfBlocks           - A pointer to a caller allocated UINTN in which the\r
+                          number of consecutive blocks starting with Lba is\r
+                          returned. All blocks in this range have a size of\r
+                          BlockSize\r
+  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
+                          instance data\r
+  Virtual               - Whether CPU is in virtual or physical mode\r
+\r
+Returns: \r
+  EFI_SUCCESS           - Successfully returns\r
+  EFI_INVALID_PARAMETER - Instance not found\r
+\r
+--*/\r
+{\r
+  UINT32                  NumBlocks;\r
+  UINT32                  BlockLength;\r
+  UINTN                   Offset;\r
+  EFI_LBA                 StartLba;\r
+  EFI_LBA                 NextLba;\r
+  EFI_FW_VOL_INSTANCE     *FwhInstance;\r
+  EFI_FV_BLOCK_MAP_ENTRY  *BlockMap;\r
+  EFI_STATUS              Status;\r
+\r
+  //\r
+  // Find the right instance of the FVB private data\r
+  //\r
+  Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  StartLba  = 0;\r
+  Offset    = 0;\r
+  BlockMap  = &(FwhInstance->VolumeHeader.BlockMap[0]);\r
+\r
+  //\r
+  // Parse the blockmap of the FV to find which map entry the Lba belongs to\r
+  //\r
+  while (TRUE) {\r
+    NumBlocks   = BlockMap->NumBlocks;\r
+    BlockLength = BlockMap->Length;\r
+\r
+    if (NumBlocks == 0 || BlockLength == 0) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    NextLba = StartLba + NumBlocks;\r
+\r
+    //\r
+    // The map entry found\r
+    //\r
+    if (Lba >= StartLba && Lba < NextLba) {\r
+      Offset = Offset + (UINTN) MultU64x32 ((Lba - StartLba), BlockLength);\r
+      if (LbaAddress != NULL) {\r
+        *LbaAddress = FwhInstance->FvBase[Virtual] + Offset;\r
+      }\r
+\r
+      if (LbaLength != NULL) {\r
+        *LbaLength = BlockLength;\r
+      }\r
+\r
+      if (NumOfBlocks != NULL) {\r
+        *NumOfBlocks = (UINTN) (NextLba - Lba);\r
+      }\r
+\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    StartLba  = NextLba;\r
+    Offset    = Offset + NumBlocks * BlockLength;\r
+    BlockMap++;\r
+  }\r
+}\r
+\r
+EFI_STATUS\r
+FvbReadBlock (\r
+  IN UINTN                                Instance,\r
+  IN EFI_LBA                              Lba,\r
+  IN UINTN                                BlockOffset,\r
+  IN OUT UINTN                            *NumBytes,\r
+  IN UINT8                                *Buffer,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Reads specified number of bytes into a buffer from the specified block\r
+\r
+Arguments:\r
+  Instance              - The FV instance to be read from\r
+  Lba                   - The logical block address to be read from\r
+  BlockOffset           - Offset into the block at which to begin reading\r
+  NumBytes              - Pointer that on input contains the total size of\r
+                          the buffer. On output, it contains the total number\r
+                          of bytes read\r
+  Buffer                - Pointer to a caller allocated buffer that will be\r
+                          used to hold the data read\r
+  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
+                          instance data\r
+  Virtual               - Whether CPU is in virtual or physical mode\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The firmware volume was read successfully and \r
+                          contents are in Buffer\r
+  EFI_BAD_BUFFER_SIZE   - Read attempted across a LBA boundary. On output,\r
+                          NumBytes contains the total number of bytes returned\r
+                          in Buffer\r
+  EFI_ACCESS_DENIED     - The firmware volume is in the ReadDisabled state\r
+  EFI_DEVICE_ERROR      - The block device is not functioning correctly and \r
+                          could not be read\r
+  EFI_INVALID_PARAMETER - Instance not found, or NumBytes, Buffer are NULL\r
+\r
+--*/\r
+{\r
+  EFI_FVB_ATTRIBUTES  Attributes;\r
+  UINTN               LbaAddress;\r
+  UINTN               LbaLength;\r
+  EFI_STATUS          Status;\r
+\r
+  //\r
+  // Check for invalid conditions\r
+  //\r
+  if ((NumBytes == NULL) || (Buffer == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (*NumBytes == 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = FvbGetLbaAddress (Instance, Lba, &LbaAddress, &LbaLength, NULL, Global, Virtual);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Check if the FV is read enabled\r
+  //\r
+  FvbGetVolumeAttributes (Instance, &Attributes, Global, Virtual);\r
+\r
+  if ((Attributes & EFI_FVB2_READ_STATUS) == 0) {\r
+    return EFI_ACCESS_DENIED;\r
+  }\r
+  //\r
+  // Perform boundary checks and adjust NumBytes\r
+  //\r
+  if (BlockOffset > LbaLength) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (LbaLength < (*NumBytes + BlockOffset)) {\r
+    *NumBytes = (UINT32) (LbaLength - BlockOffset);\r
+    Status    = EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  CopyMem (Buffer, (UINT8 *) (LbaAddress + BlockOffset), (UINTN) (*NumBytes));\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+FvbWriteBlock (\r
+  IN UINTN                                Instance,\r
+  IN EFI_LBA                              Lba,\r
+  IN UINTN                                BlockOffset,\r
+  IN OUT UINTN                            *NumBytes,\r
+  IN UINT8                                *Buffer,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Writes specified number of bytes from the input buffer to the block\r
+\r
+Arguments:\r
+  Instance              - The FV instance to be written to\r
+  Lba                   - The starting logical block index to write to\r
+  BlockOffset           - Offset into the block at which to begin writing\r
+  NumBytes              - Pointer that on input contains the total size of\r
+                          the buffer. On output, it contains the total number\r
+                          of bytes actually written\r
+  Buffer                - Pointer to a caller allocated buffer that contains\r
+                          the source for the write\r
+  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
+                          instance data\r
+  Virtual               - Whether CPU is in virtual or physical mode\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The firmware volume was written successfully\r
+  EFI_BAD_BUFFER_SIZE   - Write attempted across a LBA boundary. On output,\r
+                          NumBytes contains the total number of bytes\r
+                          actually written\r
+  EFI_ACCESS_DENIED     - The firmware volume is in the WriteDisabled state\r
+  EFI_DEVICE_ERROR      - The block device is not functioning correctly and \r
+                          could not be written\r
+  EFI_INVALID_PARAMETER - Instance not found, or NumBytes, Buffer are NULL\r
+\r
+--*/\r
+{\r
+  EFI_FVB_ATTRIBUTES  Attributes;\r
+  UINTN               LbaAddress;\r
+  UINTN               LbaLength;\r
+  EFI_STATUS          Status;\r
+\r
+  //\r
+  // Check for invalid conditions\r
+  //\r
+  if ((NumBytes == NULL) || (Buffer == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (*NumBytes == 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = FvbGetLbaAddress (Instance, Lba, &LbaAddress, &LbaLength, NULL, Global, Virtual);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Check if the FV is write enabled\r
+  //\r
+  FvbGetVolumeAttributes (Instance, &Attributes, Global, Virtual);\r
+\r
+  if ((Attributes & EFI_FVB2_WRITE_STATUS) == 0) {\r
+    return EFI_ACCESS_DENIED;\r
+  }\r
+  //\r
+  // Perform boundary checks and adjust NumBytes\r
+  //\r
+  if (BlockOffset > LbaLength) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (LbaLength < (*NumBytes + BlockOffset)) {\r
+    *NumBytes = (UINT32) (LbaLength - BlockOffset);\r
+    Status    = EFI_BAD_BUFFER_SIZE;\r
+  }\r
+  //\r
+  // Write data\r
+  //\r
+  CopyMem ((UINT8 *) (LbaAddress + BlockOffset), Buffer, (UINTN) (*NumBytes));\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+FvbEraseBlock (\r
+  IN UINTN                                Instance,\r
+  IN EFI_LBA                              Lba,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Erases and initializes a firmware volume block\r
+\r
+Arguments:\r
+  Instance              - The FV instance to be erased\r
+  Lba                   - The logical block index to be erased\r
+  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
+                          instance data\r
+  Virtual               - Whether CPU is in virtual or physical mode\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The erase request was successfully completed\r
+  EFI_ACCESS_DENIED     - The firmware volume is in the WriteDisabled state\r
+  EFI_DEVICE_ERROR      - The block device is not functioning correctly and \r
+                          could not be written. Firmware device may have been\r
+                          partially erased\r
+  EFI_INVALID_PARAMETER - Instance not found\r
+\r
+--*/\r
+{\r
+\r
+  EFI_FVB_ATTRIBUTES  Attributes;\r
+  UINTN               LbaAddress;\r
+  UINTN               LbaLength;\r
+  EFI_STATUS          Status;\r
+  UINT8               Data;\r
+\r
+  //\r
+  // Check if the FV is write enabled\r
+  //\r
+  FvbGetVolumeAttributes (Instance, &Attributes, Global, Virtual);\r
+\r
+  if ((Attributes & EFI_FVB2_WRITE_STATUS) == 0) {\r
+    return EFI_ACCESS_DENIED;\r
+  }\r
+  //\r
+  // Get the starting address of the block for erase.\r
+  //\r
+  Status = FvbGetLbaAddress (Instance, Lba, &LbaAddress, &LbaLength, NULL, Global, Virtual);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if ((Attributes & EFI_FVB2_ERASE_POLARITY) != 0) {\r
+    Data = 0xFF;\r
+  } else {\r
+    Data = 0x0;\r
+  }\r
+\r
+  SetMem ((UINT8 *) LbaAddress, LbaLength, Data);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+FvbEraseCustomBlockRange (\r
+  IN UINTN                                Instance,\r
+  IN EFI_LBA                              StartLba,\r
+  IN UINTN                                OffsetStartLba,\r
+  IN EFI_LBA                              LastLba,\r
+  IN UINTN                                OffsetLastLba,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Erases and initializes a specified range of a firmware volume\r
+\r
+Arguments:\r
+  Instance              - The FV instance to be erased\r
+  StartLba              - The starting logical block index to be erased\r
+  OffsetStartLba        - Offset into the starting block at which to \r
+                          begin erasing\r
+  LastLba               - The last logical block index to be erased\r
+  OffsetStartLba        - Offset into the last block at which to end erasing\r
+  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
+                          instance data\r
+  Virtual               - Whether CPU is in virtual or physical mode\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The firmware volume was erased successfully\r
+  EFI_ACCESS_DENIED     - The firmware volume is in the WriteDisabled state\r
+  EFI_DEVICE_ERROR      - The block device is not functioning correctly and \r
+                          could not be written. Firmware device may have been\r
+                          partially erased\r
+  EFI_INVALID_PARAMETER - Instance not found\r
+\r
+--*/\r
+{\r
+  EFI_LBA Index;\r
+  UINTN   LbaSize;\r
+  UINTN   ScratchLbaSizeData;\r
+  EFI_STATUS Status;\r
+\r
+  //\r
+  // First LBA\r
+  //\r
+  Status = FvbGetLbaAddress (Instance, StartLba, NULL, &LbaSize, NULL, Global, Virtual);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Use the scratch space as the intermediate buffer to transfer data\r
+  // Back up the first LBA in scratch space.\r
+  //\r
+  FvbReadBlock (Instance, StartLba, 0, &LbaSize, Global->FvbScratchSpace[Virtual], Global, Virtual);\r
+\r
+  //\r
+  // erase now\r
+  //\r
+  FvbEraseBlock (Instance, StartLba, Global, Virtual);\r
+  ScratchLbaSizeData = OffsetStartLba;\r
+\r
+  //\r
+  // write the data back to the first block\r
+  //\r
+  if (ScratchLbaSizeData > 0) {\r
+    Status = FvbWriteBlock (Instance, StartLba, 0, &ScratchLbaSizeData, Global->FvbScratchSpace[Virtual], Global, Virtual);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+  //\r
+  // Middle LBAs\r
+  //\r
+  if (LastLba > (StartLba + 1)) {\r
+    for (Index = (StartLba + 1); Index <= (LastLba - 1); Index++) {\r
+      FvbEraseBlock (Instance, Index, Global, Virtual);\r
+    }\r
+  }\r
+  //\r
+  // Last LBAs, the same as first LBAs\r
+  //\r
+  if (LastLba > StartLba) {\r
+    Status = FvbGetLbaAddress (Instance, LastLba, NULL, &LbaSize, NULL, Global, Virtual);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+    FvbReadBlock (Instance, LastLba, 0, &LbaSize, Global->FvbScratchSpace[Virtual], Global, Virtual);\r
+    FvbEraseBlock (Instance, LastLba, Global, Virtual);\r
+  }\r
+\r
+  ScratchLbaSizeData = LbaSize - (OffsetLastLba + 1);\r
+\r
+  if (ScratchLbaSizeData > 0) {\r
+    Status = FvbWriteBlock (\r
+              Instance,\r
+              LastLba,\r
+              (OffsetLastLba + 1),\r
+              &ScratchLbaSizeData,\r
+              Global->FvbScratchSpace[Virtual] + OffsetLastLba + 1,\r
+              Global,\r
+              Virtual\r
+              );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+FvbSetVolumeAttributes (\r
+  IN UINTN                                Instance,\r
+  IN OUT EFI_FVB_ATTRIBUTES               *Attributes,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Modifies the current settings of the firmware volume according to the \r
+  input parameter, and returns the new setting of the volume\r
+\r
+Arguments:\r
+  Instance              - The FV instance whose attributes is going to be \r
+                          modified\r
+  Attributes            - On input, it is a pointer to EFI_FVB_ATTRIBUTES \r
+                          containing the desired firmware volume settings.\r
+                          On successful return, it contains the new settings\r
+                          of the firmware volume\r
+  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
+                          instance data\r
+  Virtual               - Whether CPU is in virtual or physical mode\r
+\r
+Returns: \r
+  EFI_SUCCESS           - Successfully returns\r
+  EFI_ACCESS_DENIED     - The volume setting is locked and cannot be modified\r
+  EFI_INVALID_PARAMETER - Instance not found, or The attributes requested are\r
+                          in conflict with the capabilities as declared in the\r
+                          firmware volume header\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_INSTANCE *FwhInstance;\r
+  EFI_FVB_ATTRIBUTES  OldAttributes;\r
+  EFI_FVB_ATTRIBUTES  *AttribPtr;\r
+  UINT32              Capabilities;\r
+  UINT32              OldStatus;\r
+  UINT32              NewStatus;\r
+  EFI_STATUS          Status;\r
+  EFI_FVB_ATTRIBUTES  UnchangedAttributes;\r
+\r
+\r
+  //\r
+  // Find the right instance of the FVB private data\r
+  //\r
+  Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  AttribPtr     = (EFI_FVB_ATTRIBUTES *) &(FwhInstance->VolumeHeader.Attributes);\r
+  OldAttributes = *AttribPtr;\r
+  Capabilities  = OldAttributes & (EFI_FVB2_READ_DISABLED_CAP | \\r
+                                   EFI_FVB2_READ_ENABLED_CAP | \\r
+                                   EFI_FVB2_WRITE_DISABLED_CAP | \\r
+                                   EFI_FVB2_WRITE_ENABLED_CAP | \\r
+                                   EFI_FVB2_LOCK_CAP \\r
+                                   );\r
+\r
+  OldStatus     = OldAttributes & EFI_FVB2_STATUS;\r
+  NewStatus     = *Attributes & EFI_FVB2_STATUS;\r
+  UnchangedAttributes = EFI_FVB2_READ_DISABLED_CAP  | \\r
+                        EFI_FVB2_READ_ENABLED_CAP   | \\r
+                        EFI_FVB2_WRITE_DISABLED_CAP | \\r
+                        EFI_FVB2_WRITE_ENABLED_CAP  | \\r
+                        EFI_FVB2_LOCK_CAP           | \\r
+                        EFI_FVB2_STICKY_WRITE       | \\r
+                        EFI_FVB2_MEMORY_MAPPED      | \\r
+                        EFI_FVB2_ERASE_POLARITY     | \\r
+                        EFI_FVB2_READ_LOCK_CAP      | \\r
+                        EFI_FVB2_WRITE_LOCK_CAP     | \\r
+                        EFI_FVB2_ALIGNMENT;\r
+\r
+  //\r
+  // Some attributes of FV is read only can *not* be set\r
+  //\r
+  if ((OldAttributes & UnchangedAttributes) ^ (*Attributes & UnchangedAttributes)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // If firmware volume is locked, no status bit can be updated\r
+  //\r
+  if (OldAttributes & EFI_FVB2_LOCK_STATUS) {\r
+    if (OldStatus ^ NewStatus) {\r
+      return EFI_ACCESS_DENIED;\r
+    }\r
+  }\r
+  //\r
+  // Test read disable\r
+  //\r
+  if ((Capabilities & EFI_FVB2_READ_DISABLED_CAP) == 0) {\r
+    if ((NewStatus & EFI_FVB2_READ_STATUS) == 0) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+  //\r
+  // Test read enable\r
+  //\r
+  if ((Capabilities & EFI_FVB2_READ_ENABLED_CAP) == 0) {\r
+    if (NewStatus & EFI_FVB2_READ_STATUS) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+  //\r
+  // Test write disable\r
+  //\r
+  if ((Capabilities & EFI_FVB2_WRITE_DISABLED_CAP) == 0) {\r
+    if ((NewStatus & EFI_FVB2_WRITE_STATUS) == 0) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+  //\r
+  // Test write enable\r
+  //\r
+  if ((Capabilities & EFI_FVB2_WRITE_ENABLED_CAP) == 0) {\r
+    if (NewStatus & EFI_FVB2_WRITE_STATUS) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+  //\r
+  // Test lock\r
+  //\r
+  if ((Capabilities & EFI_FVB2_LOCK_CAP) == 0) {\r
+    if (NewStatus & EFI_FVB2_LOCK_STATUS) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+\r
+  *AttribPtr  = (*AttribPtr) & (0xFFFFFFFF & (~EFI_FVB2_STATUS));\r
+  *AttribPtr  = (*AttribPtr) | NewStatus;\r
+  *Attributes = *AttribPtr;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+//\r
+// FVB protocol APIs\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolGetPhysicalAddress (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  OUT EFI_PHYSICAL_ADDRESS                        *Address\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Retrieves the physical address of the device.\r
+\r
+Arguments:\r
+\r
+  This                  - Calling context\r
+  Address               - Output buffer containing the address.\r
+\r
+Returns:\r
+\r
+Returns: \r
+  EFI_SUCCESS           - Successfully returns\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
+\r
+  FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
+\r
+  return FvbGetPhysicalAddress (FvbDevice->Instance, Address, mFvbModuleGlobal, EfiGoneVirtual ());\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolGetBlockSize (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  IN  EFI_LBA                                     Lba,\r
+  OUT UINTN                                       *BlockSize,\r
+  OUT UINTN                                       *NumOfBlocks\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Retrieve the size of a logical block\r
+\r
+Arguments:\r
+  This                  - Calling context\r
+  Lba                   - Indicates which block to return the size for.\r
+  BlockSize             - A pointer to a caller allocated UINTN in which\r
+                          the size of the block is returned\r
+  NumOfBlocks           - a pointer to a caller allocated UINTN in which the\r
+                          number of consecutive blocks starting with Lba is\r
+                          returned. All blocks in this range have a size of\r
+                          BlockSize\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The firmware volume was read successfully and \r
+                          contents are in Buffer\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
+\r
+  FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
+\r
+  return FvbGetLbaAddress (\r
+          FvbDevice->Instance,\r
+          Lba,\r
+          NULL,\r
+          BlockSize,\r
+          NumOfBlocks,\r
+          mFvbModuleGlobal,\r
+          EfiGoneVirtual ()\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolGetAttributes (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  OUT EFI_FVB_ATTRIBUTES                          *Attributes\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+    Retrieves Volume attributes.  No polarity translations are done.\r
+\r
+Arguments:\r
+    This                - Calling context\r
+    Attributes          - output buffer which contains attributes\r
+\r
+Returns: \r
+  EFI_SUCCESS           - Successfully returns\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
+\r
+  FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
+\r
+  return FvbGetVolumeAttributes (FvbDevice->Instance, Attributes, mFvbModuleGlobal, EfiGoneVirtual ());\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolSetAttributes (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  IN OUT EFI_FVB_ATTRIBUTES                       *Attributes\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Sets Volume attributes. No polarity translations are done.\r
+\r
+Arguments:\r
+  This                  - Calling context\r
+  Attributes            - output buffer which contains attributes\r
+\r
+Returns: \r
+  EFI_SUCCESS           - Successfully returns\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
+\r
+  FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
+\r
+  return FvbSetVolumeAttributes (FvbDevice->Instance, Attributes, mFvbModuleGlobal, EfiGoneVirtual ());\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolEraseBlocks (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL    *This,\r
+  ...  \r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The EraseBlock() function erases one or more blocks as denoted by the \r
+  variable argument list. The entire parameter list of blocks must be verified\r
+  prior to erasing any blocks.  If a block is requested that does not exist \r
+  within the associated firmware volume (it has a larger index than the last \r
+  block of the firmware volume), the EraseBlock() function must return\r
+  EFI_INVALID_PARAMETER without modifying the contents of the firmware volume.\r
+\r
+Arguments:\r
+  This                  - Calling context\r
+  ...                   - Starting LBA followed by Number of Lba to erase. \r
+                          a -1 to terminate the list.\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The erase request was successfully completed\r
+  EFI_ACCESS_DENIED     - The firmware volume is in the WriteDisabled state\r
+  EFI_DEVICE_ERROR      - The block device is not functioning correctly and \r
+                          could not be written. Firmware device may have been\r
+                          partially erased\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
+  EFI_FW_VOL_INSTANCE     *FwhInstance;\r
+  UINTN                   NumOfBlocks;\r
+  VA_LIST                 args;\r
+  EFI_LBA                 StartingLba;\r
+  UINTN                   NumOfLba;\r
+  EFI_STATUS              Status;\r
+\r
+  FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
+\r
+  Status    = GetFvbInstance (FvbDevice->Instance, mFvbModuleGlobal, &FwhInstance, EfiGoneVirtual ());\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  NumOfBlocks = FwhInstance->NumOfBlocks;\r
+\r
+  VA_START (args, This);\r
+\r
+  do {\r
+    StartingLba = VA_ARG (args, EFI_LBA);\r
+    if (StartingLba == EFI_LBA_LIST_TERMINATOR) {\r
+      break;\r
+    }\r
+\r
+    NumOfLba = VA_ARG (args, UINT32);\r
+\r
+    //\r
+    // Check input parameters\r
+    //\r
+    if (NumOfLba == 0) {\r
+      VA_END (args);\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    if ((StartingLba + NumOfLba) > NumOfBlocks) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  } while (1);\r
+\r
+  VA_END (args);\r
+\r
+  VA_START (args, This);\r
+  do {\r
+    StartingLba = VA_ARG (args, EFI_LBA);\r
+    if (StartingLba == EFI_LBA_LIST_TERMINATOR) {\r
+      break;\r
+    }\r
+\r
+    NumOfLba = VA_ARG (args, UINT32);\r
+\r
+    while (NumOfLba > 0) {\r
+      Status = FvbEraseBlock (FvbDevice->Instance, StartingLba, mFvbModuleGlobal, EfiGoneVirtual ());\r
+      if (EFI_ERROR (Status)) {\r
+        VA_END (args);\r
+        return Status;\r
+      }\r
+\r
+      StartingLba++;\r
+      NumOfLba--;\r
+    }\r
+\r
+  } while (1);\r
+\r
+  VA_END (args);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolWrite (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  IN EFI_LBA                                      Lba,\r
+  IN UINTN                                        Offset,\r
+  IN OUT UINTN                                    *NumBytes,\r
+  IN UINT8                                        *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Writes data beginning at Lba:Offset from FV. The write terminates either\r
+  when *NumBytes of data have been written, or when a block boundary is\r
+  reached.  *NumBytes is updated to reflect the actual number of bytes\r
+  written. The write opertion does not include erase. This routine will\r
+  attempt to write only the specified bytes. If the writes do not stick,\r
+  it will return an error.\r
+\r
+Arguments:\r
+  This                  - Calling context\r
+  Lba                   - Block in which to begin write\r
+  Offset                - Offset in the block at which to begin write\r
+  NumBytes              - On input, indicates the requested write size. On\r
+                          output, indicates the actual number of bytes written\r
+  Buffer                - Buffer containing source data for the write.\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The firmware volume was written successfully\r
+  EFI_BAD_BUFFER_SIZE   - Write attempted across a LBA boundary. On output,\r
+                          NumBytes contains the total number of bytes\r
+                          actually written\r
+  EFI_ACCESS_DENIED     - The firmware volume is in the WriteDisabled state\r
+  EFI_DEVICE_ERROR      - The block device is not functioning correctly and \r
+                          could not be written\r
+  EFI_INVALID_PARAMETER - NumBytes or Buffer are NULL\r
+\r
+--*/\r
+{\r
+\r
+  EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
+\r
+  FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
+\r
+  return FvbWriteBlock (FvbDevice->Instance, Lba, Offset, NumBytes, Buffer, mFvbModuleGlobal, EfiGoneVirtual ());\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolRead (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  IN EFI_LBA                                      Lba,\r
+  IN UINTN                                        Offset,\r
+  IN OUT UINTN                                    *NumBytes,\r
+  IN UINT8                                        *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Reads data beginning at Lba:Offset from FV. The Read terminates either\r
+  when *NumBytes of data have been read, or when a block boundary is\r
+  reached.  *NumBytes is updated to reflect the actual number of bytes\r
+  written. The write opertion does not include erase. This routine will\r
+  attempt to write only the specified bytes. If the writes do not stick,\r
+  it will return an error.\r
+\r
+Arguments:\r
+  This                  - Calling context\r
+  Lba                   - Block in which to begin Read\r
+  Offset                - Offset in the block at which to begin Read\r
+  NumBytes              - On input, indicates the requested write size. On\r
+                          output, indicates the actual number of bytes Read\r
+  Buffer                - Buffer containing source data for the Read.\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The firmware volume was read successfully and \r
+                          contents are in Buffer\r
+  EFI_BAD_BUFFER_SIZE   - Read attempted across a LBA boundary. On output,\r
+                          NumBytes contains the total number of bytes returned\r
+                          in Buffer\r
+  EFI_ACCESS_DENIED     - The firmware volume is in the ReadDisabled state\r
+  EFI_DEVICE_ERROR      - The block device is not functioning correctly and \r
+                          could not be read\r
+  EFI_INVALID_PARAMETER - NumBytes or Buffer are NULL\r
+\r
+--*/\r
+{\r
+\r
+  EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
+\r
+  FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
+\r
+  return FvbReadBlock (FvbDevice->Instance, Lba, Offset, NumBytes, Buffer, mFvbModuleGlobal, EfiGoneVirtual ());\r
+}\r
+//\r
+// FVB Extension Protocols\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+FvbExtendProtocolEraseCustomBlockRange (\r
+  IN EFI_FVB_EXTENSION_PROTOCOL           *This,\r
+  IN EFI_LBA                              StartLba,\r
+  IN UINTN                                OffsetStartLba,\r
+  IN EFI_LBA                              LastLba,\r
+  IN UINTN                                OffsetLastLba\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Erases and initializes a specified range of a firmware volume\r
+\r
+Arguments:\r
+  This                  - Calling context\r
+  StartLba              - The starting logical block index to be erased\r
+  OffsetStartLba        - Offset into the starting block at which to \r
+                          begin erasing\r
+  LastLba               - The last logical block index to be erased\r
+  OffsetStartLba        - Offset into the last block at which to end erasing\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The firmware volume was erased successfully\r
+  EFI_ACCESS_DENIED     - The firmware volume is in the WriteDisabled state\r
+  EFI_DEVICE_ERROR      - The block device is not functioning correctly and \r
+                          could not be written. Firmware device may have been\r
+                          partially erased\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
+\r
+  FvbDevice = FVB_EXTEND_DEVICE_FROM_THIS (This);\r
+\r
+  return FvbEraseCustomBlockRange (\r
+          FvbDevice->Instance,\r
+          StartLba,\r
+          OffsetStartLba,\r
+          LastLba,\r
+          OffsetLastLba,\r
+          mFvbModuleGlobal,\r
+          EfiGoneVirtual ()\r
+          );\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+ValidateFvHeader (\r
+  EFI_FIRMWARE_VOLUME_HEADER            *FwVolHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Check the integrity of firmware volume header\r
+\r
+Arguments:\r
+  FwVolHeader           - A pointer to a firmware volume header\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The firmware volume is consistent\r
+  EFI_NOT_FOUND         - The firmware volume has corrupted. So it is not an FV\r
+\r
+--*/\r
+{\r
+  UINT16  *Ptr;\r
+  UINT16  HeaderLength;\r
+  UINT16  Checksum;\r
+\r
+  //\r
+  // Verify the header revision, header signature, length\r
+  // Length of FvBlock cannot be 2**64-1\r
+  // HeaderLength cannot be an odd number\r
+  //\r
+  if ((FwVolHeader->Revision != EFI_FVH_REVISION) ||\r
+      (FwVolHeader->Signature != EFI_FVH_SIGNATURE) ||\r
+      (FwVolHeader->FvLength == ((UINTN) -1)) ||\r
+      ((FwVolHeader->HeaderLength & 0x01) != 0)\r
+      ) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  //\r
+  // Verify the header checksum\r
+  //\r
+  HeaderLength  = (UINT16) (FwVolHeader->HeaderLength / 2);\r
+  Ptr           = (UINT16 *) FwVolHeader;\r
+  Checksum      = 0;\r
+  while (HeaderLength > 0) {\r
+    Checksum = Checksum + (*Ptr);\r
+    HeaderLength--;\r
+    Ptr++;\r
+  }\r
+\r
+  if (Checksum != 0) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  This function does common initialization for FVB services\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                          Status;\r
+  EFI_FW_VOL_INSTANCE                 *FwhInstance;\r
+  EFI_FIRMWARE_VOLUME_HEADER          *FwVolHeader;\r
+  EFI_DXE_SERVICES                    *DxeServices;\r
+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR     Descriptor;\r
+  UINT32                              BufferSize;\r
+  EFI_FV_BLOCK_MAP_ENTRY              *PtrBlockMapEntry;\r
+  EFI_HANDLE                          FwbHandle;\r
+  EFI_FW_VOL_BLOCK_DEVICE             *FvbDevice;\r
+  EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *OldFwbInterface;\r
+  EFI_DEVICE_PATH_PROTOCOL            *TempFwbDevicePath;\r
+  FV_DEVICE_PATH                      TempFvbDevicePathData;\r
+  UINT32                              MaxLbaSize;\r
+  EFI_PHYSICAL_ADDRESS                BaseAddress;\r
+  UINT64                              Length;\r
+  UINTN                               NumOfBlocks;\r
+  EFI_PEI_HOB_POINTERS                FvHob;\r
+\r
+   //\r
+  // Get the DXE services table\r
+  //\r
+  DxeServices = gDS;\r
+\r
+  //\r
+  // Allocate runtime services data for global variable, which contains\r
+  // the private data of all firmware volume block instances\r
+  //\r
+  Status = gBS->AllocatePool (\r
+                  EfiRuntimeServicesData,\r
+                  sizeof (ESAL_FWB_GLOBAL),\r
+                  (VOID**) &mFvbModuleGlobal\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Calculate the total size for all firmware volume block instances\r
+  //\r
+  BufferSize            = 0;\r
+\r
+  FvHob.Raw = GetHobList ();\r
+  while ((FvHob.Raw = GetNextHob (EFI_HOB_TYPE_FV, FvHob.Raw)) != NULL) {\r
+    BaseAddress = FvHob.FirmwareVolume->BaseAddress;\r
+    Length      = FvHob.FirmwareVolume->Length;\r
+    //\r
+    // Check if it is a "real" flash\r
+    //\r
+    Status = DxeServices->GetMemorySpaceDescriptor (\r
+                            BaseAddress,\r
+                            &Descriptor\r
+                            );\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
+    }\r
+\r
+    if (Descriptor.GcdMemoryType != EfiGcdMemoryTypeMemoryMappedIo) {\r
+      FvHob.Raw = GET_NEXT_HOB (FvHob);\r
+      continue;\r
+    }\r
+\r
+    FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;\r
+    Status      = ValidateFvHeader (FwVolHeader);\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Get FvbInfo\r
+      //\r
+      Status = GetFvbInfo (Length, &FwVolHeader);\r
+      if (EFI_ERROR (Status)) {\r
+        FvHob.Raw = GET_NEXT_HOB (FvHob);\r
+        continue;\r
+      }\r
+    }\r
+\r
+    BufferSize += (sizeof (EFI_FW_VOL_INSTANCE) + FwVolHeader->HeaderLength - sizeof (EFI_FIRMWARE_VOLUME_HEADER));\r
+    FvHob.Raw = GET_NEXT_HOB (FvHob);\r
+  }\r
+\r
+  //\r
+  // Only need to allocate once. There is only one copy of physical memory for\r
+  // the private data of each FV instance. But in virtual mode or in physical\r
+  // mode, the address of the the physical memory may be different.\r
+  //\r
+  Status = gBS->AllocatePool (\r
+                  EfiRuntimeServicesData,\r
+                  BufferSize,\r
+                  (VOID**) &mFvbModuleGlobal->FvInstance[FVB_PHYSICAL]\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Make a virtual copy of the FvInstance pointer.\r
+  //\r
+  FwhInstance = mFvbModuleGlobal->FvInstance[FVB_PHYSICAL];\r
+  mFvbModuleGlobal->FvInstance[FVB_VIRTUAL] = FwhInstance;\r
+\r
+  mFvbModuleGlobal->NumFv                   = 0;\r
+  MaxLbaSize = 0;\r
+\r
+  FvHob.Raw = GetHobList ();\r
+  while (NULL != (FvHob.Raw = GetNextHob (EFI_HOB_TYPE_FV, FvHob.Raw))) {\r
+    BaseAddress = FvHob.FirmwareVolume->BaseAddress;\r
+    Length      = FvHob.FirmwareVolume->Length;\r
+    //\r
+    // Check if it is a "real" flash\r
+    //\r
+    Status = DxeServices->GetMemorySpaceDescriptor (\r
+                            BaseAddress,\r
+                            &Descriptor\r
+                            );\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
+    }\r
+\r
+    if (Descriptor.GcdMemoryType != EfiGcdMemoryTypeMemoryMappedIo) {\r
+      FvHob.Raw = GET_NEXT_HOB (FvHob);\r
+      continue;\r
+    }\r
+\r
+    FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;\r
+    Status      = ValidateFvHeader (FwVolHeader);\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Get FvbInfo to provide in FwhInstance.\r
+      //\r
+      Status = GetFvbInfo (Length, &FwVolHeader);\r
+      if (EFI_ERROR (Status)) {\r
+        FvHob.Raw = GET_NEXT_HOB (FvHob);\r
+        continue;\r
+      }\r
+      //\r
+      //  Write healthy FV header back.\r
+      //\r
+      CopyMem (\r
+        (VOID *) (UINTN) BaseAddress,\r
+        (VOID *) FwVolHeader,\r
+        FwVolHeader->HeaderLength\r
+        );\r
+    }\r
+\r
+    FwhInstance->FvBase[FVB_PHYSICAL] = (UINTN) BaseAddress;\r
+    FwhInstance->FvBase[FVB_VIRTUAL]  = (UINTN) BaseAddress;\r
+\r
+    CopyMem ((UINTN *) &(FwhInstance->VolumeHeader), (UINTN *) FwVolHeader, FwVolHeader->HeaderLength);\r
+    FwVolHeader = &(FwhInstance->VolumeHeader);\r
+    EfiInitializeLock (&(FwhInstance->FvbDevLock), TPL_HIGH_LEVEL);\r
+\r
+    NumOfBlocks = 0;\r
+\r
+    for (PtrBlockMapEntry = FwVolHeader->BlockMap; PtrBlockMapEntry->NumBlocks != 0; PtrBlockMapEntry++) {\r
+      //\r
+      // Get the maximum size of a block. The size will be used to allocate\r
+      // buffer for Scratch space, the intermediate buffer for FVB extension\r
+      // protocol\r
+      //\r
+      if (MaxLbaSize < PtrBlockMapEntry->Length) {\r
+        MaxLbaSize = PtrBlockMapEntry->Length;\r
+      }\r
+\r
+      NumOfBlocks = NumOfBlocks + PtrBlockMapEntry->NumBlocks;\r
+    }\r
+    //\r
+    // The total number of blocks in the FV.\r
+    //\r
+    FwhInstance->NumOfBlocks = NumOfBlocks;\r
+\r
+    //\r
+    // Add a FVB Protocol Instance\r
+    //\r
+    Status = gBS->AllocatePool (\r
+                    EfiRuntimeServicesData,\r
+                    sizeof (EFI_FW_VOL_BLOCK_DEVICE),\r
+                    (VOID**) &FvbDevice\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    CopyMem (FvbDevice, &mFvbDeviceTemplate, sizeof (EFI_FW_VOL_BLOCK_DEVICE));\r
+\r
+    FvbDevice->Instance = mFvbModuleGlobal->NumFv;\r
+    mFvbModuleGlobal->NumFv++;\r
+\r
+    //\r
+    // Set up the devicepath\r
+    //\r
+    FvbDevice->DevicePath.MemMapDevPath.StartingAddress = BaseAddress;\r
+    FvbDevice->DevicePath.MemMapDevPath.EndingAddress   = BaseAddress + (FwVolHeader->FvLength - 1);\r
+\r
+    //\r
+    // Find a handle with a matching device path that has supports FW Block protocol\r
+    //\r
+    TempFwbDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) &TempFvbDevicePathData;\r
+    CopyMem (TempFwbDevicePath, &FvbDevice->DevicePath, sizeof (FV_DEVICE_PATH));\r
+    Status = gBS->LocateDevicePath (&gEfiFirmwareVolumeBlockProtocolGuid, &TempFwbDevicePath, &FwbHandle);\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // LocateDevicePath fails so install a new interface and device path\r
+      //\r
+      FwbHandle = NULL;\r
+      Status = gBS->InstallMultipleProtocolInterfaces (\r
+                      &FwbHandle,\r
+                      &gEfiFirmwareVolumeBlockProtocolGuid,\r
+                      &FvbDevice->FwVolBlockInstance,\r
+                      &gEfiDevicePathProtocolGuid,\r
+                      &FvbDevice->DevicePath,\r
+                      NULL\r
+                      );\r
+      ASSERT_EFI_ERROR (Status);\r
+    } else if (EfiIsDevicePathEnd (TempFwbDevicePath)) {\r
+      //\r
+      // Device allready exists, so reinstall the FVB protocol\r
+      //\r
+      Status = gBS->HandleProtocol (\r
+                      FwbHandle,\r
+                      &gEfiFirmwareVolumeBlockProtocolGuid,\r
+                      (VOID**)&OldFwbInterface\r
+                      );\r
+      ASSERT_EFI_ERROR (Status);\r
+\r
+      Status = gBS->ReinstallProtocolInterface (\r
+                      FwbHandle,\r
+                      &gEfiFirmwareVolumeBlockProtocolGuid,\r
+                      OldFwbInterface,\r
+                      &FvbDevice->FwVolBlockInstance\r
+                      );\r
+      ASSERT_EFI_ERROR (Status);\r
+\r
+    } else {\r
+      //\r
+      // There was a FVB protocol on an End Device Path node\r
+      //\r
+      ASSERT (FALSE);\r
+    }\r
+    //\r
+    // Install FVB Extension Protocol on the same handle\r
+    //\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &FwbHandle,\r
+                    &gEfiFvbExtensionProtocolGuid,\r
+                    &FvbDevice->FvbExtension,\r
+                    &gEfiAlternateFvBlockGuid,\r
+                    NULL,\r
+                    NULL\r
+                    );\r
+\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    FwhInstance = (EFI_FW_VOL_INSTANCE *)\r
+      (\r
+        (UINTN) ((UINT8 *) FwhInstance) + FwVolHeader->HeaderLength +\r
+          (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))\r
+      );\r
+\r
+    FvHob.Raw = GET_NEXT_HOB (FvHob);\r
+  }\r
+\r
+  //\r
+  // Allocate for scratch space, an intermediate buffer for FVB extention\r
+  //\r
+  Status = gBS->AllocatePool (\r
+                  EfiRuntimeServicesData,\r
+                  MaxLbaSize,\r
+                  (VOID**)&mFvbModuleGlobal->FvbScratchSpace[FVB_PHYSICAL]\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  mFvbModuleGlobal->FvbScratchSpace[FVB_VIRTUAL] = mFvbModuleGlobal->FvbScratchSpace[FVB_PHYSICAL];\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/edk2/UnixPkg/FvbServicesRuntimeDxe/FvbInfo.c b/edk2/UnixPkg/FvbServicesRuntimeDxe/FvbInfo.c
new file mode 100644 (file)
index 0000000..6670359
--- /dev/null
@@ -0,0 +1,156 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  FvbInfo.c\r
+\r
+Abstract:\r
+\r
+  Defines data structure that is the volume header found.These data is intent\r
+  to decouple FVB driver with FV header.\r
+\r
+--*/\r
+#include "PiDxe.h"\r
+#include <Guid/EventGroup.h>\r
+#include <Protocol/FvbExtension.h>\r
+#include <Protocol/FirmwareVolumeBlock.h>\r
+#include <Guid/AlternateFvBlock.h>\r
+#include <Protocol/DevicePath.h>\r
+\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DxeServicesTableLib.h>\r
+#include <Library/UefiRuntimeLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Guid/FirmwareFileSystem2.h>\r
+#include <Guid/SystemNvDataGuid.h>\r
+\r
+typedef struct {\r
+  UINT64                      FvLength;\r
+  EFI_FIRMWARE_VOLUME_HEADER  FvbInfo;\r
+  //\r
+  // EFI_FV_BLOCK_MAP_ENTRY    ExtraBlockMap[n];//n=0\r
+  //\r
+  EFI_FV_BLOCK_MAP_ENTRY      End[1];\r
+} EFI_FVB_MEDIA_INFO;\r
+\r
+EFI_FVB_MEDIA_INFO  mPlatformFvbMediaInfo[] = {\r
+  //\r
+  // Recovery BOIS FVB\r
+  //\r
+  {\r
+    FixedPcdGet32 (PcdUnixFlashFvRecoverySize),\r
+    {\r
+      {\r
+        0,\r
+      },  // ZeroVector[16]\r
+      EFI_FIRMWARE_FILE_SYSTEM2_GUID,\r
+      FixedPcdGet32 (PcdUnixFlashFvRecoverySize),\r
+      EFI_FVH_SIGNATURE,\r
+      EFI_FVB2_READ_ENABLED_CAP |\r
+        EFI_FVB2_READ_STATUS |\r
+        EFI_FVB2_WRITE_ENABLED_CAP |\r
+        EFI_FVB2_WRITE_STATUS |\r
+        EFI_FVB2_ERASE_POLARITY,\r
+      sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),\r
+      0,  // CheckSum\r
+      0,  // ExtHeaderOffset\r
+      {\r
+        0,\r
+      },  // Reserved[1]\r
+      1,  // Revision\r
+      {\r
+        {\r
+          FixedPcdGet32 (PcdUnixFlashFvRecoverySize)/FixedPcdGet32 (PcdUnixFirmwareBlockSize),\r
+          FixedPcdGet32 (PcdUnixFirmwareBlockSize),\r
+        }\r
+      }\r
+    },\r
+    {\r
+      {\r
+        0,\r
+        0\r
+      }\r
+    }\r
+  },\r
+  //\r
+  // Systen NvStorage FVB\r
+  //\r
+  {\r
+    FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \\r
+    FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \\r
+    FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \\r
+    FixedPcdGet32 (PcdUnixFlashNvStorageEventLogSize),\r
+    {\r
+      {\r
+        0,\r
+      },  // ZeroVector[16]\r
+      EFI_SYSTEM_NV_DATA_HOB_GUID,\r
+      FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \\r
+      FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \\r
+      FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \\r
+      FixedPcdGet32 (PcdUnixFlashNvStorageEventLogSize),\r
+      EFI_FVH_SIGNATURE,\r
+      EFI_FVB2_READ_ENABLED_CAP |\r
+        EFI_FVB2_READ_STATUS |\r
+        EFI_FVB2_WRITE_ENABLED_CAP |\r
+        EFI_FVB2_WRITE_STATUS |\r
+        EFI_FVB2_ERASE_POLARITY,\r
+      sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),\r
+      0,  // CheckSum\r
+      0,  // ExtHeaderOffset\r
+      {\r
+        0,\r
+      },  // Reserved[1]\r
+      1,  // Revision\r
+      {\r
+        {\r
+          (FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \\r
+          FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \\r
+          FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \\r
+          FixedPcdGet32 (PcdUnixFlashNvStorageEventLogSize)) / FixedPcdGet32 (PcdUnixFirmwareBlockSize),\r
+          FixedPcdGet32 (PcdUnixFirmwareBlockSize),\r
+        }\r
+      }\r
+    },\r
+    {\r
+      {\r
+        0,\r
+        0\r
+      }\r
+    }\r
+  }\r
+};\r
+\r
+EFI_STATUS\r
+GetFvbInfo (\r
+  IN  UINT64                        FvLength,\r
+  OUT EFI_FIRMWARE_VOLUME_HEADER    **FvbInfo\r
+  )\r
+{\r
+  UINTN Index;\r
+\r
+  for (Index = 0; Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO); Index += 1) {\r
+    if (mPlatformFvbMediaInfo[Index].FvLength == FvLength) {\r
+      *FvbInfo = &mPlatformFvbMediaInfo[Index].FvbInfo;\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
diff --git a/edk2/UnixPkg/FvbServicesRuntimeDxe/FwBlockService.h b/edk2/UnixPkg/FvbServicesRuntimeDxe/FwBlockService.h
new file mode 100644 (file)
index 0000000..6f949d3
--- /dev/null
@@ -0,0 +1,238 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  FwBlockService.h\r
+  \r
+Abstract:\r
+\r
+  Firmware volume block driver for Intel Firmware Hub (FWH) device\r
+\r
+--*/\r
+\r
+#ifndef _FW_BLOCK_SERVICE_H\r
+#define _FW_BLOCK_SERVICE_H\r
+\r
+//\r
+// BugBug: Add documentation here for data structure!!!!\r
+//\r
+#define FVB_PHYSICAL  0\r
+#define FVB_VIRTUAL   1\r
+\r
+typedef struct {\r
+  EFI_LOCK                    FvbDevLock;\r
+  UINTN                       FvBase[2];\r
+  UINTN                       NumOfBlocks;\r
+  EFI_FIRMWARE_VOLUME_HEADER  VolumeHeader;\r
+} EFI_FW_VOL_INSTANCE;\r
+\r
+typedef struct {\r
+  UINT32              NumFv;\r
+  EFI_FW_VOL_INSTANCE *FvInstance[2];\r
+  UINT8               *FvbScratchSpace[2];\r
+} ESAL_FWB_GLOBAL;\r
+\r
+//\r
+// Fvb Protocol instance data\r
+//\r
+#define FVB_DEVICE_FROM_THIS(a)         CR (a, EFI_FW_VOL_BLOCK_DEVICE, FwVolBlockInstance, FVB_DEVICE_SIGNATURE)\r
+#define FVB_EXTEND_DEVICE_FROM_THIS(a)  CR (a, EFI_FW_VOL_BLOCK_DEVICE, FvbExtension, FVB_DEVICE_SIGNATURE)\r
+#define FVB_DEVICE_SIGNATURE            EFI_SIGNATURE_32 ('F', 'V', 'B', 'N')\r
+\r
+typedef struct {\r
+  MEMMAP_DEVICE_PATH        MemMapDevPath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevPath;\r
+} FV_DEVICE_PATH;\r
+\r
+typedef struct {\r
+  UINTN                               Signature;\r
+  FV_DEVICE_PATH                      DevicePath;\r
+  UINTN                               Instance;\r
+  EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  FwVolBlockInstance;\r
+  EFI_FVB_EXTENSION_PROTOCOL          FvbExtension;\r
+} EFI_FW_VOL_BLOCK_DEVICE;\r
+\r
+EFI_STATUS\r
+GetFvbInfo (\r
+  IN  UINT64                            FvLength,\r
+  OUT EFI_FIRMWARE_VOLUME_HEADER        **FvbInfo\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+FvbReadBlock (\r
+  IN UINTN                                Instance,\r
+  IN EFI_LBA                              Lba,\r
+  IN UINTN                                BlockOffset,\r
+  IN OUT UINTN                            *NumBytes,\r
+  IN UINT8                                *Buffer,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+FvbWriteBlock (\r
+  IN UINTN                                Instance,\r
+  IN EFI_LBA                              Lba,\r
+  IN UINTN                                BlockOffset,\r
+  IN OUT UINTN                            *NumBytes,\r
+  IN UINT8                                *Buffer,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+FvbEraseBlock (\r
+  IN UINTN                                Instance,\r
+  IN EFI_LBA                              Lba,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+FvbSetVolumeAttributes (\r
+  IN UINTN                                Instance,\r
+  IN OUT EFI_FVB_ATTRIBUTES               *Attributes,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+FvbGetVolumeAttributes (\r
+  IN UINTN                                Instance,\r
+  OUT EFI_FVB_ATTRIBUTES                  *Attributes,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+FvbGetPhysicalAddress (\r
+  IN UINTN                                Instance,\r
+  OUT EFI_PHYSICAL_ADDRESS                *Address,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+;\r
+\r
+\r
+VOID\r
+EFIAPI\r
+FvbClassAddressChangeEvent (\r
+  IN EFI_EVENT        Event,\r
+  IN VOID             *Context\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+FvbGetLbaAddress (\r
+  IN  UINTN                               Instance,\r
+  IN  EFI_LBA                             Lba,\r
+  OUT UINTN                               *LbaAddress,\r
+  OUT UINTN                               *LbaLength,\r
+  OUT UINTN                               *NumOfBlocks,\r
+  IN  ESAL_FWB_GLOBAL                     *Global,\r
+  IN  BOOLEAN                             Virtual\r
+  )\r
+;\r
+\r
+//\r
+// Protocol APIs\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolGetAttributes (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  OUT EFI_FVB_ATTRIBUTES                          *Attributes\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolSetAttributes (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  IN OUT EFI_FVB_ATTRIBUTES                       *Attributes\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolGetPhysicalAddress (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  OUT EFI_PHYSICAL_ADDRESS                        *Address\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolGetBlockSize (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  IN  EFI_LBA                                     Lba,\r
+  OUT UINTN                                       *BlockSize,\r
+  OUT UINTN                                       *NumOfBlocks\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolRead (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  IN EFI_LBA                                      Lba,\r
+  IN UINTN                                        Offset,\r
+  IN OUT UINTN                                    *NumBytes,\r
+  IN UINT8                                        *Buffer\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolWrite (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  IN EFI_LBA                                      Lba,\r
+  IN UINTN                                        Offset,\r
+  IN OUT UINTN                                    *NumBytes,\r
+  IN UINT8                                        *Buffer\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolEraseBlocks (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL    *This,\r
+  ...\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbExtendProtocolEraseCustomBlockRange (\r
+  IN EFI_FVB_EXTENSION_PROTOCOL           *This,\r
+  IN EFI_LBA                              StartLba,\r
+  IN UINTN                                OffsetStartLba,\r
+  IN EFI_LBA                              LastLba,\r
+  IN UINTN                                OffsetLastLba\r
+  )\r
+;\r
+\r
+#endif\r
diff --git a/edk2/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf b/edk2/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf
new file mode 100644 (file)
index 0000000..52cc62e
--- /dev/null
@@ -0,0 +1,90 @@
+#/** @file\r
+# Component description file for Unix Fimware Volume Block DXE driver module.\r
+#\r
+# This DXE runtime driver implements and produces the Fimware Volue Block Protocol on \r
+#  Unix emulator.\r
+# Copyright (c) 2008, Intel Corporation\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = FwBlockService\r
+  FILE_GUID                      = f42fd042-8985-11db-a7db-0040d02b1835\r
+  MODULE_TYPE                    = DXE_RUNTIME_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = FvbInitialize\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.Ia32]\r
+  FvbInfo.c\r
+  FWBlockService.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  HobLib\r
+  DebugLib\r
+  UefiRuntimeLib\r
+  DxeServicesTableLib\r
+  BaseLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+\r
+\r
+[Guids]\r
+  gEfiEventVirtualAddressChangeGuid             # ALWAYS_CONSUMED  Create Event: EVENT_GROUP_GUID\r
+  gEfiAlternateFvBlockGuid                      # ALWAYS_PRODUCED\r
+\r
+\r
+[Protocols]\r
+  gEfiFvbExtensionProtocolGuid                  # PROTOCOL ALWAYS_PRODUCED\r
+  gEfiFirmwareVolumeBlockProtocolGuid           # PROTOCOL ALWAYS_PRODUCED\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL SOMETIMES_PRODUCED\r
+\r
+\r
+[FixedPcd.common]\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareFdSize\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareBlockSize\r
+\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashFvRecoveryBase\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashFvRecoverySize\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogBase\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogSize\r
+\r
+[Pcd.common]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase\r
+\r
+\r
+[Depex]\r
+  TRUE\r
+\r
diff --git a/edk2/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.msa b/edk2/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.msa
new file mode 100644 (file)
index 0000000..3792a00
--- /dev/null
@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>FwBlockService</ModuleName>\r
+    <ModuleType>DXE_RUNTIME_DRIVER</ModuleType>\r
+    <GuidValue>f42fd042-8985-11db-a7db-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for Unix Fimware Volume Block DXE driver module.</Abstract>\r
+    <Description>This DXE runtime driver implements and produces the Fimware Volue Block Protocol on \r
+    Unix emulator.\r
+    </Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>All rights reserved. This program and the accompanying materials\r
+      are licensed and made available under the terms and conditions of the BSD License\r
+      which accompanies this distribution.  The full text of the license may be found at\r
+      http://opensource.org/licenses/bsd-license.php\r
+      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+      WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>FwBlockService</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DxeServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiRuntimeLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>HobLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnixFwh.dxs</Filename>\r
+    <Filename SupArchList="IA32">FWBlockService.c</Filename>\r
+    <Filename SupArchList="IA32">FwBlockService.h</Filename>\r
+    <Filename SupArchList="IA32">FvbInfo.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="SOMETIMES_PRODUCED">\r
+      <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiFirmwareVolumeBlockProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiFvbExtensionProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Events>\r
+    <CreateEvents>\r
+      <EventTypes EventGuidCName="gEfiEventVirtualAddressChangeGuid" Usage="ALWAYS_CONSUMED">\r
+        <EventType>EVENT_GROUP_GUID</EventType>\r
+      </EventTypes>\r
+    </CreateEvents>\r
+  </Events>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_PRODUCED">\r
+      <GuidCName>gEfiAlternateFvBlockGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>FvbInitialize</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/edk2/UnixPkg/Include/Common/UnixInclude.h b/edk2/UnixPkg/Include/Common/UnixInclude.h
new file mode 100644 (file)
index 0000000..9229646
--- /dev/null
@@ -0,0 +1,32 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+  UnixInclude.h\r
+\r
+Abstract:\r
+  Public include file for the Unix Library\r
+\r
+--*/\r
+\r
+#ifndef __UNIX_INCLUDE_H__\r
+#define __UNIX_INCLUDE_H__\r
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/vfs.h>
+#include <sys/poll.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <time.h>
+#include <utime.h>
+#include <unistd.h>
+#endif\r
diff --git a/edk2/UnixPkg/Include/FlashLayout.h b/edk2/UnixPkg/Include/FlashLayout.h
new file mode 100644 (file)
index 0000000..1a13f16
--- /dev/null
@@ -0,0 +1,64 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  FlashLayout.h\r
+   \r
+Abstract:\r
+\r
+  Platform specific flash layout\r
+\r
+  BugBug: We need a better way\r
+\r
+--*/\r
+\r
+#ifndef __EFI_FLASH_LAYOUT__\r
+#define __EFI_FLASH_LAYOUT__\r
+\r
+//\r
+// Firmware Volume Information for Nt32\r
+// adding one working block before FFS FV,\r
+// and another one for spare block behind FFS FV\r
+//\r
+//\r
+// Note: When block number is changed in .dsc file,\r
+//       this value should be changed accordingly!!!\r
+//\r
+#define FIRMWARE_BLOCK_NUMBER                         0x28\r
+\r
+#define EFI_WINNT_FIRMWARE_OFFSET                     0x0\r
+#define EFI_WINNT_FIRMWARE_LENGTH                     (0x10000 * FIRMWARE_BLOCK_NUMBER)\r
+\r
+#define EFI_WINNT_RUNTIME_UPDATABLE_OFFSET            (EFI_WINNT_FIRMWARE_OFFSET + EFI_WINNT_FIRMWARE_LENGTH)\r
+\r
+#define EFI_WINNT_RUNTIME_UPDATABLE_LENGTH            0x10000\r
+\r
+#define EFI_WINNT_FTW_SPARE_BLOCK_OFFSET              (EFI_WINNT_RUNTIME_UPDATABLE_OFFSET + EFI_WINNT_RUNTIME_UPDATABLE_LENGTH)\r
+\r
+#define EFI_WINNT_FTW_SPARE_BLOCK_LENGTH              0x10000\r
+\r
+#define EFI_WINNT_RUNTIME_UPDATABLE_FV_HEADER_LENGTH  0x48\r
+\r
+#define EFI_VARIABLE_STORE_OFFSET                     EFI_WINNT_RUNTIME_UPDATABLE_OFFSET\r
+\r
+#define EFI_VARIABLE_STORE_LENGTH                     0x00C000\r
+\r
+#define EFI_EVENT_LOG_OFFSET                          (EFI_VARIABLE_STORE_OFFSET + EFI_VARIABLE_STORE_LENGTH)\r
+\r
+#define EFI_EVENT_LOG_LENGTH                          0x002000\r
+\r
+#define EFI_FTW_WORKING_OFFSET                        (EFI_EVENT_LOG_OFFSET + EFI_EVENT_LOG_LENGTH)\r
+\r
+#define EFI_FTW_WORKING_LENGTH                        0x002000\r
+\r
+#endif\r
+\r
diff --git a/edk2/UnixPkg/Include/Library/UnixLib.h b/edk2/UnixPkg/Include/Library/UnixLib.h
new file mode 100644 (file)
index 0000000..9797093
--- /dev/null
@@ -0,0 +1,27 @@
+/*++
+
+Copyright (c) 2006, Intel Corporation                                                         
+All rights reserved. This program and the accompanying materials                          
+are licensed and made available under the terms and conditions of the BSD License         
+which accompanies this distribution.  The full text of the license may be found at        
+http://opensource.org/licenses/bsd-license.php                                            
+                                                                                          
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             
+
+Module Name:
+
+  UnixLib.h
+
+Abstract:
+
+  Public include file for the Unix Library
+
+--*/
+
+#ifndef __UNIX_LIB_H__
+#define __UNIX_LIB_H__
+
+extern EFI_UNIX_THUNK_PROTOCOL  *gUnix;
+
+#endif
diff --git a/edk2/UnixPkg/Include/Ppi/UnixAutoScan.h b/edk2/UnixPkg/Include/Ppi/UnixAutoScan.h
new file mode 100644 (file)
index 0000000..0c04d82
--- /dev/null
@@ -0,0 +1,66 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  UnixAutoscan.h\r
+\r
+Abstract:\r
+\r
+Unix Autoscan PPI\r
+\r
+--*/\r
+\r
+#ifndef __UNIX_PEI_AUTOSCAN_H__\r
+#define __UNIX_PEI_AUTOSCAN_H__\r
+\r
+#include <UnixDxe.h>\r
+\r
+#define PEI_UNIX_AUTOSCAN_PPI_GUID \\r
+  { \\r
+    0xf2ed3d14, 0x8985, 0x11db, {0xb0, 0x57, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *PEI_UNIX_AUTOSCAN) (\r
+  IN  UINTN                 Index,\r
+  OUT EFI_PHYSICAL_ADDRESS  *MemoryBase,\r
+  OUT UINT64                *MemorySize\r
+  );\r
+\r
+/*++\r
+\r
+Routine Description:\r
+  This service is called from Index == 0 until it returns EFI_UNSUPPORTED.\r
+  It allows discontiguous memory regions to be supported by the emulator.\r
+  It uses gSystemMemory[] and gSystemMemoryCount that were created by\r
+  parsing the host environment variable EFI_MEMORY_SIZE.\r
+  The size comes from the varaible and the address comes from the call to\r
+  WinNtOpenFile. \r
+\r
+Arguments:\r
+  Index      - Which memory region to use\r
+  MemoryBase - Return Base address of memory region\r
+  MemorySize - Return size in bytes of the memory region\r
+\r
+Returns:\r
+  EFI_SUCCESS - If memory region was mapped\r
+  EFI_UNSUPPORTED - If Index is not supported\r
+\r
+--*/\r
+typedef struct {\r
+  PEI_UNIX_AUTOSCAN UnixAutoScan;\r
+} PEI_UNIX_AUTOSCAN_PPI;\r
+\r
+extern EFI_GUID gPeiUnixAutoScanPpiGuid;\r
+\r
+#endif\r
diff --git a/edk2/UnixPkg/Include/Ppi/UnixFwh.h b/edk2/UnixPkg/Include/Ppi/UnixFwh.h
new file mode 100644 (file)
index 0000000..a9885a5
--- /dev/null
@@ -0,0 +1,62 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  UnixFwh.h\r
+\r
+Abstract:\r
+\r
+  Unix FWH PPI as defined in Tiano\r
+\r
+--*/\r
+\r
+#ifndef __UNIX_PEI_FWH_H__\r
+#define __UNIX_PEI_FWH_H__\r
+\r
+#include <UnixDxe.h>\r
+\r
+#define UNIX_FWH_PPI_GUID \\r
+  { \\r
+    0xf2f0dc30, 0x8985, 0x11db, {0xa1, 0x5b, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *UNIX_FWH_INFORMATION) (\r
+  IN     UINTN                  Index,\r
+  IN OUT EFI_PHYSICAL_ADDRESS   *FdBase,\r
+  IN OUT UINT64                 *FdSize\r
+  );\r
+\r
+/*++\r
+\r
+Routine Description:\r
+  Return the FD Size and base address. Since the FD is loaded from a \r
+  file into host memory only the SEC will know it's address.\r
+\r
+Arguments:\r
+  Index  - Which FD, starts at zero.\r
+  FdSize - Size of the FD in bytes\r
+  FdBase - Start address of the FD. Assume it points to an FV Header\r
+\r
+Returns:\r
+  EFI_SUCCESS     - Return the Base address and size of the FV\r
+  EFI_UNSUPPORTED - Index does nto map to an FD in the system\r
+\r
+--*/\r
+typedef struct {\r
+  UNIX_FWH_INFORMATION  UnixFwh;\r
+} UNIX_FWH_PPI;\r
+\r
+extern EFI_GUID gUnixFwhPpiGuid;\r
+\r
+#endif\r
diff --git a/edk2/UnixPkg/Include/Ppi/UnixPeiLoadFile.h b/edk2/UnixPkg/Include/Ppi/UnixPeiLoadFile.h
new file mode 100644 (file)
index 0000000..b91c630
--- /dev/null
@@ -0,0 +1,65 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+ UnixPeiLoadFile.h\r
+\r
+Abstract:\r
+\r
+  Unix Load File PPI.\r
+\r
+  When the PEI core is done it calls the DXE IPL via PPI\r
+\r
+--*/\r
+\r
+#ifndef __UNIX_PEI_LOAD_FILE_H__\r
+#define __UNIX_PEI_LOAD_FILE_H__\r
+\r
+#include <UnixDxe.h>\r
+\r
+#define UNIX_PEI_LOAD_FILE_GUID \\r
+  { \\r
+    0xf2f48768, 0x8985, 0x11db, {0xb8, 0xda, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *UNIX_PEI_LOAD_FILE) (\r
+  VOID                  *Pe32Data,\r
+  EFI_PHYSICAL_ADDRESS  *ImageAddress,\r
+  UINT64                *ImageSize,\r
+  EFI_PHYSICAL_ADDRESS  *EntryPoint\r
+  );\r
+\r
+/*++\r
+\r
+Routine Description:\r
+  Loads and relocates a PE/COFF image into memory.\r
+\r
+Arguments:\r
+  Pe32Data         - The base address of the PE/COFF file that is to be loaded and relocated\r
+  ImageAddress     - The base address of the relocated PE/COFF image\r
+  ImageSize        - The size of the relocated PE/COFF image\r
+  EntryPoint       - The entry point of the relocated PE/COFF image\r
+\r
+Returns:\r
+  EFI_SUCCESS   - The file was loaded and relocated\r
+  EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file\r
+\r
+--*/\r
+typedef struct {\r
+  UNIX_PEI_LOAD_FILE  PeiLoadFileService;\r
+} UNIX_PEI_LOAD_FILE_PPI;\r
+\r
+extern EFI_GUID gUnixPeiLoadFilePpiGuid;\r
+\r
+#endif\r
diff --git a/edk2/UnixPkg/Include/Ppi/UnixThunk.h b/edk2/UnixPkg/Include/Ppi/UnixThunk.h
new file mode 100644 (file)
index 0000000..866bd61
--- /dev/null
@@ -0,0 +1,56 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  UnixThunk.h\r
+\r
+Abstract:\r
+\r
+  Unix Thunk interface PPI\r
+\r
+--*/\r
+\r
+#ifndef __UNIX_PEI_UNIX_THUNK_H__\r
+#define __UNIX_PEI_UNIX_THUNK_H__\r
+\r
+#include <UnixDxe.h>\r
+\r
+#define PEI_UNIX_THUNK_PPI_GUID \\r
+  { \\r
+    0xf2f830f2, 0x8985, 0x11db, {0x80, 0x6b, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+typedef\r
+VOID *\r
+(EFIAPI *PEI_UNIX_THUNK_INTERFACE) (\r
+  VOID\r
+  );\r
+\r
+/*++\r
+\r
+Routine Description:\r
+  Export of EFI_UNIX_THUNK_PROTOCOL from the Unix SEC.\r
+\r
+Arguments:\r
+  InterfaceBase - Address of the EFI_UNIX_THUNK_PROTOCOL\r
+\r
+Returns:\r
+  EFI_SUCCESS - Data returned\r
+\r
+--*/\r
+typedef struct {\r
+  PEI_UNIX_THUNK_INTERFACE  UnixThunk;\r
+} PEI_UNIX_THUNK_PPI;\r
+\r
+extern EFI_GUID gPeiUnixThunkPpiGuid;\r
+\r
+#endif\r
diff --git a/edk2/UnixPkg/Include/Protocol/UnixIo.h b/edk2/UnixPkg/Include/Protocol/UnixIo.h
new file mode 100644 (file)
index 0000000..1758ecb
--- /dev/null
@@ -0,0 +1,142 @@
+/*++\r
+\r
+Copyright (c) 2004 - 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  UnixIo.h\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+#ifndef _UNIX_IO_H_\r
+#define _UNIX_IO_H_\r
+\r
+#define EFI_UNIX_IO_PROTOCOL_GUID \\r
+  { \\r
+    0xf2e23f54, 0x8985, 0x11db, {0xac, 0x79, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+typedef struct {\r
+  EFI_UNIX_THUNK_PROTOCOL  *UnixThunk;\r
+  EFI_GUID                  *TypeGuid;\r
+  UINT16                    *EnvString;\r
+  UINT16                    InstanceNumber;\r
+} EFI_UNIX_IO_PROTOCOL;\r
+\r
+extern EFI_GUID gEfiUnixIoProtocolGuid;\r
+\r
+//\r
+// The following GUIDs are used in EFI_UNIX_IO_PROTOCOL_GUID\r
+// Device paths. They map 1:1 with UNIX envirnment variables. The variables\r
+// define what virtual hardware the emulator/UnixBusDriver will produce.\r
+//\r
+//\r
+// EFI_UNIX_VIRTUAL_DISKS\r
+//\r
+#define EFI_UNIX_VIRTUAL_DISKS_GUID \\r
+  { \\r
+    0xf2ba331a, 0x8985, 0x11db, {0xa4, 0x06, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+extern EFI_GUID gEfiUnixVirtualDisksGuid;\r
+\r
+//\r
+// EFI_UNIX_PHYSICAL_DISKS\r
+//\r
+#define EFI_UNIX_PHYSICAL_DISKS_GUID \\r
+  { \\r
+    0xf2bdcc96, 0x8985, 0x11db, {0x87, 0x19, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+extern EFI_GUID gEfiUnixPhysicalDisksGuid;\r
+\r
+//\r
+// EFI_UNIX_FILE_SYSTEM\r
+//\r
+#define EFI_UNIX_FILE_SYSTEM_GUID \\r
+  { \\r
+    0xf2c16b9e, 0x8985, 0x11db, {0x92, 0xc8, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+extern EFI_GUID gEfiUnixFileSystemGuid;\r
+\r
+//\r
+// EFI_WIN_NT_SERIAL_PORT\r
+//\r
+#define EFI_UNIX_SERIAL_PORT_GUID \\r
+  { \\r
+    0x6d3a727d, 0x66c8, 0x4d19, {0x87, 0xe6, 0x2, 0x15, 0x86, 0x14, 0x90, 0xf3} \\r
+  }\r
+\r
+extern EFI_GUID gEfiUnixSerialPortGuid;\r
+\r
+//\r
+// EFI_UNIX_UGA\r
+//\r
+#define EFI_UNIX_UGA_GUID \\r
+  { \\r
+    0xf2c8b80e, 0x8985, 0x11db, {0x93, 0xf1, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+extern EFI_GUID gEfiUnixUgaGuid;\r
+\r
+//\r
+// EFI_UNIX_GOP\r
+//\r
+#define EFI_UNIX_GOP_GUID \\r
+  { \\r
+    0xbace07c2, 0x8987, 0x11db, {0xa5, 0x9a, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+extern EFI_GUID gEfiUnixGopGuid;\r
+\r
+//\r
+// EFI_UNIX_CONSOLE\r
+//\r
+#define EFI_UNIX_CONSOLE_GUID \\r
+  { \\r
+    0xf2cc5d06, 0x8985, 0x11db, {0xbb, 0x19, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+extern EFI_GUID gEfiUnixConsoleGuid;\r
+\r
+//\r
+// EFI_UNIX_MEMORY\r
+//\r
+#define EFI_UNIX_MEMORY_GUID \\r
+  { \\r
+    0xf2d006cc, 0x8985, 0x11db, {0xa4, 0x72, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+extern EFI_GUID gEfiUnixMemoryGuid;\r
+\r
+//\r
+// EFI_UNIX_CPU_MODEL\r
+//\r
+#define EFI_UNIX_CPU_MODEL_GUID \\r
+  { \\r
+    0xf2d3b330, 0x8985, 0x11db, {0x8a, 0xa3, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+extern EFI_GUID gEfiUnixCPUModelGuid;\r
+\r
+//\r
+// EFI_UNIX_CPU_SPEED\r
+//\r
+#define EFI_UNIX_CPU_SPEED_GUID \\r
+  { \\r
+    0xf2d74e5a, 0x8985, 0x11db, {0x97, 0x05, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+extern EFI_GUID gEfiUnixCPUSpeedGuid;\r
+\r
+#endif\r
diff --git a/edk2/UnixPkg/Include/Protocol/UnixThunk.h b/edk2/UnixPkg/Include/Protocol/UnixThunk.h
new file mode 100644 (file)
index 0000000..a0908a0
--- /dev/null
@@ -0,0 +1,244 @@
+/*++
+
+Copyright (c) 2004, Intel Corporation                                                         
+All rights reserved. This program and the accompanying materials                          
+are licensed and made available under the terms and conditions of the BSD License         
+which accompanies this distribution.  The full text of the license may be found at        
+http://opensource.org/licenses/bsd-license.php                                            
+                                                                                          
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             
+
+Module Name:
+
+  UnixThunk.h
+
+Abstract:
+
+  This protocol allows an EFI driver in the Unix emulation environment
+  to make Posix calls.
+
+  NEVER make an Unix call directly, always make the call via this protocol.
+
+  There are no This pointers on the protocol member functions as they map
+  exactly into Unix system calls.
+
+--*/
+
+#ifndef _UNIX_THUNK_H_
+#define _UNIX_THUNK_H_
+
+#include <sys/termios.h>
+#include <stdio.h>
+#include <sys/time.h>
+#include <sys/dir.h>
+#include <unistd.h>
+#include <poll.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <time.h>
+#include <signal.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <termio.h>
+#include <sys/ioctl.h>
+#include <sys/vfs.h>
+#include <utime.h>
+
+#define EFI_UNIX_THUNK_PROTOCOL_GUID \
+  { \
+    0xf2e98868, 0x8985, 0x11db, {0x9a, 0x59, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }
+
+typedef
+VOID
+(*UnixSleep) (
+  unsigned long Milliseconds
+  );
+
+typedef
+VOID
+(*UnixExit) (
+  int status  // exit code for all threads
+  );
+
+typedef
+VOID
+(*UnixSetTimer) (UINT64 PeriodMs, VOID (*CallBack)(UINT64 DeltaMs));
+typedef
+VOID
+(*UnixGetLocalTime) (EFI_TIME *Time);
+typedef
+struct tm *
+(*UnixGmTime)(const time_t *timep);
+typedef
+long
+(*UnixGetTimeZone)(void);
+typedef
+int
+(*UnixGetDayLight)(void);
+typedef
+int
+(*UnixPoll)(struct pollfd *pfd, int nfds, int timeout);
+typedef
+int
+(*UnixRead) (int fd, void *buf, int count);
+typedef
+int
+(*UnixWrite) (int fd, const void *buf, int count);
+typedef
+char *
+(*UnixGetenv) (const char *var);
+typedef
+int
+(*UnixOpen) (const char *name, int flags, int mode);
+typedef
+long int
+(*UnixSeek) (int fd, long int off, int whence);
+typedef
+int
+(*UnixFtruncate) (int fd, long int len);
+typedef
+int
+(*UnixClose) (int fd);
+
+typedef
+int
+(*UnixMkdir)(const char *pathname, mode_t mode);
+typedef
+int
+(*UnixRmDir)(const char *pathname);
+typedef
+int
+(*UnixUnLink)(const char *pathname);
+typedef
+int
+(*UnixGetErrno)(VOID);
+typedef
+DIR *
+(*UnixOpenDir)(const char *pathname);
+typedef
+void
+(*UnixRewindDir)(DIR *dir);
+typedef
+struct dirent *
+(*UnixReadDir)(DIR *dir);
+typedef
+int
+(*UnixCloseDir)(DIR *dir);
+typedef
+int
+(*UnixStat)(const char *path, struct stat *buf);
+typedef
+int
+(*UnixStatFs)(const char *path, struct statfs *buf);
+typedef
+int
+(*UnixRename)(const char *oldpath, const char *newpath);
+typedef
+time_t
+(*UnixMkTime)(struct tm *tm);
+typedef
+int
+(*UnixFSync)(int fd);
+typedef
+int
+(*UnixChmod)(const char *path, mode_t mode);
+typedef
+int
+(*UnixUTime)(const char *filename, const struct utimbuf *buf);
+
+struct _EFI_UNIX_UGA_IO_PROTOCOL;
+typedef
+EFI_STATUS
+(*UnixUgaCreate)(struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo,
+                CONST CHAR16 *Title);
+
+typedef
+int
+(*UnixTcflush) (int fildes, int queue_selector);
+
+typedef
+void
+(*UnixPerror) (__const char *__s);
+
+typedef 
+int 
+(*UnixIoCtl) (int fd, unsigned long int __request, ...);
+
+typedef 
+int 
+(*UnixFcntl) (int __fd, int __cmd, ...);
+
+typedef
+int 
+(*UnixCfsetispeed) (struct termios *__termios_p, speed_t __speed);
+
+typedef 
+int 
+(*UnixCfsetospeed) (struct termios *__termios_p, speed_t __speed);
+
+typedef
+int 
+(*UnixTcgetattr) (int __fd, struct termios *__termios_p);
+
+typedef 
+int 
+(*UnixTcsetattr) (int __fd, int __optional_actions,
+                     __const struct termios *__termios_p);
+
+//
+//
+//
+
+#define EFI_UNIX_THUNK_PROTOCOL_SIGNATURE EFI_SIGNATURE_32 ('L', 'N', 'X', 'T')
+
+typedef struct _EFI_UNIX_THUNK_PROTOCOL {
+  UINT64                              Signature;
+
+  UnixSleep                           Sleep;
+  UnixExit                           Exit;
+  UnixSetTimer                        SetTimer;
+  UnixGetLocalTime                             GetLocalTime;
+  UnixGmTime                          GmTime;
+  UnixGetTimeZone                     GetTimeZone;
+  UnixGetDayLight                     GetDayLight;
+  UnixPoll                               Poll;
+  UnixRead                           Read;
+  UnixWrite                          Write;
+  UnixGetenv                         Getenv;
+  UnixOpen                           Open;
+  UnixSeek                           Lseek;
+  UnixFtruncate                      FTruncate;
+  UnixClose                          Close;
+  UnixMkdir                           MkDir;
+  UnixRmDir                           RmDir;
+  UnixUnLink                          UnLink;
+  UnixGetErrno                        GetErrno;
+  UnixOpenDir                         OpenDir;
+  UnixRewindDir                       RewindDir;
+  UnixReadDir                         ReadDir;
+  UnixCloseDir                        CloseDir;
+  UnixStat                            Stat;
+  UnixStatFs                          StatFs;
+  UnixRename                          Rename;
+  UnixMkTime                          MkTime;
+  UnixFSync                           FSync;
+  UnixChmod                           Chmod;
+  UnixUTime                           UTime;
+  UnixTcflush                         Tcflush;
+  UnixUgaCreate                                          UgaCreate;
+  UnixPerror                          Perror;
+  UnixIoCtl                           IoCtl;
+  UnixFcntl                           Fcntl;
+  UnixCfsetispeed                     Cfsetispeed;
+  UnixCfsetospeed                     Cfsetospeed;
+  UnixTcgetattr                       Tcgetattr;
+  UnixTcsetattr                       Tcsetattr;
+} EFI_UNIX_THUNK_PROTOCOL;
+
+extern EFI_GUID gEfiUnixThunkProtocolGuid;
+
+#endif
diff --git a/edk2/UnixPkg/Include/Protocol/UnixUgaIo.h b/edk2/UnixPkg/Include/Protocol/UnixUgaIo.h
new file mode 100644 (file)
index 0000000..63e80be
--- /dev/null
@@ -0,0 +1,72 @@
+/*++
+
+Copyright (c) 2006, Tristan Gingold
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the
+BSD License which accompanies this distribution.  The full text of the
+license may be found at http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+Module Name:
+
+  UnixUgaIo.h
+
+Abstract:
+
+--*/
+
+#ifndef _UNIX_UGA_IO_H_
+#define _UNIX_UGA_IO_H_
+
+#define EFI_UNIX_UGA_IO_PROTOCOL_GUID \
+  { \
+    0xf2e5e2c6, 0x8985, 0x11db, {0xa1, 0x91, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }
+
+struct _EFI_UNIX_UGA_IO_PROTOCOL;
+typedef struct _EFI_UNIX_UGA_IO_PROTOCOL EFI_UNIX_UGA_IO_PROTOCOL;
+
+typedef
+EFI_STATUS
+(*UGAClose)(EFI_UNIX_UGA_IO_PROTOCOL *Uga);
+
+typedef
+EFI_STATUS
+(*UGASize)(EFI_UNIX_UGA_IO_PROTOCOL *Uga, UINT32 Width, UINT32 Height);
+
+typedef
+EFI_STATUS
+(*UGACheckKey)(EFI_UNIX_UGA_IO_PROTOCOL *Uga);
+
+typedef
+EFI_STATUS
+(*UGAGetKey)(EFI_UNIX_UGA_IO_PROTOCOL *Uga, EFI_INPUT_KEY *key);
+
+typedef
+EFI_STATUS
+(*UGABlt)(EFI_UNIX_UGA_IO_PROTOCOL *Uga,
+         IN  EFI_UGA_PIXEL                           *BltBuffer OPTIONAL,
+         IN  EFI_UGA_BLT_OPERATION                   BltOperation,
+         IN  UINTN                                   SourceX,
+         IN  UINTN                                   SourceY,
+         IN  UINTN                                   DestinationX,
+         IN  UINTN                                   DestinationY,
+         IN  UINTN                                   Width,
+         IN  UINTN                                   Height,
+         IN  UINTN                                   Delta OPTIONAL);
+
+struct _EFI_UNIX_UGA_IO_PROTOCOL {
+  VOID                                *Private;
+  UGAClose                            UgaClose;
+  UGASize                             UgaSize;
+  UGACheckKey                         UgaCheckKey;
+  UGAGetKey                           UgaGetKey;
+  UGABlt                              UgaBlt;
+};
+
+
+extern EFI_GUID gEfiUnixUgaIoProtocolGuid;
+
+#endif
diff --git a/edk2/UnixPkg/Include/UnixDxe.h b/edk2/UnixPkg/Include/UnixDxe.h
new file mode 100644 (file)
index 0000000..29a0c16
--- /dev/null
@@ -0,0 +1,36 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+  UnixDxe.h\r
+\r
+Abstract:\r
+  Public include file for the Unix Library\r
+\r
+--*/\r
+\r
+#ifndef __UNIX_DXE_H__\r
+#define __UNIX_DXE_H__\r
+\r
+#include <Ppi/UnixPeiLoadFile.h>\r
+#include <Ppi/UnixAutoScan.h>\r
+#include <Ppi/UnixThunk.h>\r
+#include <Ppi/UnixFwh.h>\r
+\r
+//\r
+//  UnixIo.h depends on UnixThunk.h\r
+//\r
+\r
+#include <Common/UnixInclude.h>
+#include <Protocol/UnixThunk.h>\r
+#include <Protocol/UnixIo.h>\r
+\r
+#endif\r
diff --git a/edk2/UnixPkg/Include/UnixPeim.h b/edk2/UnixPkg/Include/UnixPeim.h
new file mode 100644 (file)
index 0000000..4ddda91
--- /dev/null
@@ -0,0 +1,30 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+  UnixPeim.h\r
+\r
+Abstract:\r
+  Public include file for the Unix Library\r
+\r
+--*/\r
+\r
+#ifndef __UNIX_PEIM_H__\r
+#define __UNIX_PEIM_H__\r
+\r
+#include <Ppi/UnixPeiLoadFile.h>\r
+#include <Ppi/UnixAutoScan.h>\r
+#include <Ppi/UnixThunk.h>\r
+#include <Ppi/UnixFwh.h>\r
+\r
+#include <Protocol/UnixThunk.h>\r
+\r
+#endif\r
diff --git a/edk2/UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf b/edk2/UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf
new file mode 100644 (file)
index 0000000..01c9f1a
--- /dev/null
@@ -0,0 +1,50 @@
+#/** @file\r
+# A library to produce the global variable 'gUnix'\r
+#\r
+# This library contains a single global variable 'gUnix' along with a constructor to initialize that global.\r
+# Copyright (c) 2006 - 2008, Intel Corporation.\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DxeUnixLib\r
+  FILE_GUID                      = f39efc84-8985-11db-ad67-0040d02b1835\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = UnixLib \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = UnixLibConstructor\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  UnixLib.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+[LibraryClasses]\r
+  HobLib\r
+  DebugLib\r
+\r
+\r
+[Protocols]\r
+  gEfiUnixThunkProtocolGuid                     # PROTOCOL ALWAYS_CONSUMED\r
+\r
diff --git a/edk2/UnixPkg/Library/DxeUnixLib/DxeUnixLib.msa b/edk2/UnixPkg/Library/DxeUnixLib/DxeUnixLib.msa
new file mode 100644 (file)
index 0000000..d77a86e
--- /dev/null
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>DxeUnixLib</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>f39efc84-8985-11db-ad67-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>A library to produce the global variable 'gUnix'</Abstract>\r
+    <Description>This library contains a single global variable 'gUnix' along with a constructor to initialize that global.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation.</Copyright>\r
+    <License>All rights reserved. This program and the accompanying materials\r
+      are licensed and made available under the terms and conditions of the BSD License\r
+      which accompanies this distribution.  The full text of the license may be found at\r
+      http://opensource.org/licenses/bsd-license.php\r
+      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+      WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>DxeUnixLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED">\r
+      <Keyword>UnixLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>HobLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnixLib.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiUnixThunkProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <Constructor>UnixLibConstructor</Constructor>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/edk2/UnixPkg/Library/DxeUnixLib/UnixLib.c b/edk2/UnixPkg/Library/DxeUnixLib/UnixLib.c
new file mode 100644 (file)
index 0000000..98bf044
--- /dev/null
@@ -0,0 +1,51 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  UnixLib.c\r
+\r
+Abstract:\r
+\r
+  Unix Library \r
+\r
+--*/\r
+#include "PiDxe.h"\r
+#include "UnixDxe.h"\r
+#include <Library/UnixLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+\r
+EFI_UNIX_THUNK_PROTOCOL *gUnix;\r
+\r
+EFI_STATUS\r
+UnixLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  EFI_HOB_GUID_TYPE        *GuidHob;\r
+\r
+  GuidHob = GetFirstGuidHob (&gEfiUnixThunkProtocolGuid);\r
+  ASSERT (GuidHob != NULL);\r
+  gUnix = (EFI_UNIX_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+  ASSERT (gUnix != NULL);\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/edk2/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf b/edk2/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf
new file mode 100644 (file)
index 0000000..b9aee9e
--- /dev/null
@@ -0,0 +1,61 @@
+#/** @file\r
+# Memory Status Code Library for UEFI drivers\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2007, Intel Corporation.\r
+#\r
+#  All rights reserved.\r
+#  This software and associated documentation (if any) is furnished\r
+#  under a license and may only be used or copied in accordance\r
+#  with the terms of the license. Except as permitted by such\r
+#  license, no part of this software or documentation may be\r
+#  reproduced, stored in a retrieval system, or transmitted in any\r
+#  form or by any means without the express written consent of\r
+#  Intel Corporation.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DxeUnixOemHookStatusCodeLib\r
+  FILE_GUID                      = 0BB6F68A-2FC5-4394-9375-2B43F1C34B59\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = OemHookStatusCodeLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32\r
+#\r
+\r
+[Sources.common]\r
+  UnixOemHookStatusCodeLib.c\r
+\r
+\r
+[Packages]\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  ReportStatusCodeLib\r
+  BaseMemoryLib\r
+  PrintLib\r
+  HobLib\r
+  DebugLib\r
+\r
+\r
+[Guids]\r
+  gEfiStatusCodeSpecificDataGuid                # ALWAYS_CONSUMED\r
+\r
+\r
+[Protocols]\r
+  gEfiUnixThunkProtocolGuid                     # PROTOCOL ALWAYS_CONSUMED\r
+\r
diff --git a/edk2/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.msa b/edk2/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.msa
new file mode 100644 (file)
index 0000000..7e9aeeb
--- /dev/null
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>DxeUnixOemHookStatusCodeLib</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>0BB6F68A-2FC5-4394-9375-2B43F1C34B59</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Memory Status Code Library for UEFI drivers</Abstract>\r
+    <Description>Lib to provide memory journal status code reporting Routines</Description>\r
+    <Copyright>Copyright (c) 2007, Intel Corporation.</Copyright>\r
+    <License>All rights reserved.\r
+      This software and associated documentation (if any) is furnished\r
+      under a license and may only be used or copied in accordance\r
+      with the terms of the license. Except as permitted by such\r
+      license, no part of this software or documentation may be\r
+      reproduced, stored in a retrieval system, or transmitted in any\r
+      form or by any means without the express written consent of\r
+      Intel Corporation.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>DxeUnixOemHookStatusCodeLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER">\r
+      <Keyword>OemHookStatusCodeLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>HobLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PrintLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>ReportStatusCodeLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnixOemHookStatusCodeLib.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiUnixThunkProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiStatusCodeSpecificDataGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/edk2/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c b/edk2/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c
new file mode 100644 (file)
index 0000000..4435d16
--- /dev/null
@@ -0,0 +1,238 @@
+/** @file\r
+  OEM hook status code library functions with no library constructor/destructor\r
+\r
+  Copyright (c) 2006, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Module Name:  UnixOemHookStatusCodeLib.c\r
+\r
+**/\r
+#include "PiDxe.h"\r
+#include <Guid/StatusCodeDataTypeId.h>\r
+#include "UnixDxe.h"\r
+#include <Library/OemHookStatusCodeLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
+#include <FrameworkModuleBase.h>\r
+#include <DebugInfo.h>\r
+\r
+//\r
+// Cache of UnixThunk protocol \r
+//\r
+STATIC\r
+EFI_UNIX_THUNK_PROTOCOL   *mUnix;\r
+\r
+//\r
+// Cache of standard output handle . \r
+//\r
+STATIC\r
+int                      mStdOut;\r
+\r
+/**\r
+\r
+  Initialize OEM status code device .\r
+\r
+  @return    Always return EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+OemHookStatusCodeInitialize (\r
+  VOID\r
+  )\r
+{\r
+  EFI_HOB_GUID_TYPE        *GuidHob;\r
+\r
+  //\r
+  // Retrieve UnixThunkProtocol from GUID'ed HOB\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gEfiUnixThunkProtocolGuid);\r
+  ASSERT (GuidHob != NULL);\r
+  mUnix = (EFI_UNIX_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+  ASSERT (mUnix != NULL);\r
+\r
+  //\r
+  // Cache standard output handle.\r
+  //\r
+  mStdOut = 1;
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Report status code to OEM device.\r
\r
+  @param  CodeType      Indicates the type of status code being reported.  Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.\r
\r
+  @param  Value         Describes the current status of a hardware or software entity.  \r
+                        This included information about the class and subclass that is used to classify the entity \r
+                        as well as an operation.  For progress codes, the operation is the current activity. \r
+                        For error codes, it is the exception.  For debug codes, it is not defined at this time. \r
+                        Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.  \r
+                        Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.\r
\r
+  @param  Instance      The enumeration of a hardware or software entity within the system.  \r
+                        A system may contain multiple entities that match a class/subclass pairing. \r
+                        The instance differentiates between them.  An instance of 0 indicates that instance information is unavailable, \r
+                        not meaningful, or not relevant.  Valid instance numbers start with 1.\r
+\r
+\r
+  @param  CallerId      This optional parameter may be used to identify the caller. \r
+                        This parameter allows the status code driver to apply different rules to different callers. \r
+                        Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.\r
+\r
+\r
+  @param  Data          This optional parameter may be used to pass additional data\r
\r
+  @return               The function always return EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+OemHookStatusCodeReport (\r
+  IN EFI_STATUS_CODE_TYPE     CodeType,\r
+  IN EFI_STATUS_CODE_VALUE    Value,\r
+  IN UINT32                   Instance,\r
+  IN EFI_GUID                 *CallerId, OPTIONAL\r
+  IN EFI_STATUS_CODE_DATA     *Data      OPTIONAL\r
+  )\r
+{\r
+  CHAR8           *Filename;\r
+  CHAR8           *Description;\r
+  CHAR8           *Format;\r
+  CHAR8           Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];\r
+  UINT32          ErrorLevel;\r
+  UINT32          LineNumber;\r
+  UINTN           CharCount;\r
+  VA_LIST         Marker;\r
+  EFI_DEBUG_INFO  *DebugInfo;\r
+\r
+  Buffer[0] = '\0';\r
+\r
+  if (Data != NULL &&\r
+      ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {\r
+    //\r
+    // Print ASSERT() information into output buffer.\r
+    //\r
+    CharCount = AsciiSPrint (\r
+                  Buffer,\r
+                  EFI_STATUS_CODE_DATA_MAX_SIZE,\r
+                  "\n\rASSERT!: %a (%d): %a\n\r",\r
+                  Filename,\r
+                  LineNumber,\r
+                  Description\r
+                  );\r
+\r
+    //\r
+    // Callout to standard output.\r
+    //\r
+    mUnix->Write (\r
+              mStdOut,\r
+              Buffer,\r
+              CharCount\r
+             );
+\r
+    return EFI_SUCCESS;\r
+\r
+  } else if (Data != NULL &&\r
+             ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {\r
+    //\r
+    // Print DEBUG() information into output buffer.\r
+    //\r
+    CharCount = AsciiVSPrint (\r
+                  Buffer, \r
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, \r
+                  Format, \r
+                  Marker\r
+                  );\r
+  } else if (Data != NULL && \r
+             CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&\r
+             (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {\r
+    //\r
+    // Print specific data into output buffer.\r
+    //\r
+    DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);\r
+    Marker    = (VA_LIST) (DebugInfo + 1);\r
+    Format    = (CHAR8 *) (((UINT64 *) Marker) + 12);\r
+\r
+    CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);\r
+  } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {\r
+    //\r
+    // Print ERROR information into output buffer.\r
+    //\r
+    CharCount = AsciiSPrint (\r
+                  Buffer, \r
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, \r
+                  "ERROR: C%x:V%x I%x", \r
+                  CodeType, \r
+                  Value, \r
+                  Instance\r
+                  );\r
+\r
+    //\r
+    // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.\r
+    //\r
+    \r
+    if (CallerId != NULL) {\r
+      CharCount += AsciiSPrint (\r
+                     &Buffer[CharCount - 1],\r
+                     (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
+                     " %g",\r
+                     CallerId\r
+                     );\r
+    }\r
+\r
+    if (Data != NULL) {\r
+      CharCount += AsciiSPrint (\r
+                     &Buffer[CharCount - 1],\r
+                     (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
+                     " %x",\r
+                     Data\r
+                     );\r
+    }\r
+\r
+    CharCount += AsciiSPrint (\r
+                   &Buffer[CharCount - 1],\r
+                   (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
+                   "\n\r"\r
+                   );\r
+  } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {\r
+    CharCount = AsciiSPrint (\r
+                  Buffer, \r
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, \r
+                  "PROGRESS CODE: V%x I%x\n\r", \r
+                  Value, \r
+                  Instance\r
+                  );\r
+  } else {\r
+    CharCount = AsciiSPrint (\r
+                  Buffer, \r
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, \r
+                  "Undefined: C%x:V%x I%x\n\r", \r
+                  CodeType, \r
+                  Value, \r
+                  Instance\r
+                  );\r
+  }\r
+\r
+  //\r
+  // Callout to standard output.\r
+  //\r
+  mUnix->Write (\r
+            mStdOut,\r
+            Buffer,\r
+            CharCount\r
+            );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
diff --git a/edk2/UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.c b/edk2/UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.c
new file mode 100644 (file)
index 0000000..48a6254
--- /dev/null
@@ -0,0 +1,225 @@
+/**@file\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  DxeUnixPeCoffLib.c\r
+\r
+Abstract:\r
+\r
+  Wrap the Unix PE/COFF loader with the PE COFF LOADER guid structure\r
+  to produce PeCoff library class.\r
+\r
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+#include <Guid/PeiPeCoffLoader.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/HobLib.h>\r
+\r
+EFI_PEI_PE_COFF_LOADER_PROTOCOL  *mPeiEfiPeiPeCoffLoader;\r
+\r
+/**\r
+  The constructor function gets the pointer to PeCofferLoader guid structure\r
+  from the guid data hob.\r
+\r
+  It will ASSERT() if the guid hob of PeCofferLoader guid structure doesn't exist.\r
+\r
+  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param  SystemTable   A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DxeUnixPeCoffLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_HOB_GUID_TYPE    *GuidHob;\r
+  \r
+  //\r
+  // Find guid data hob that contains PeCoffLoader guid structure.\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);\r
+  ASSERT (GuidHob != NULL);\r
+\r
+  //\r
+  // Get PeCofferLoader guid structure from guid hob data.\r
+  //\r
+  mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Retrieves information about a PE/COFF image.\r
+\r
+  Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,\r
+  PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva\r
+  fields of the ImageContext structure.  If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.\r
+  If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not\r
+  a supported PE/COFF image type, then return RETURN_UNSUPPORTED.  If any errors occur while\r
+  computing the fields of ImageContext, then the error status is returned in the ImageError field of\r
+  ImageContext. \r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image that needs to be examined by this function.\r
+\r
+  @retval RETURN_SUCCESS            The information on the PE/COFF image was collected.\r
+  @retval RETURN_INVALID_PARAMETER  ImageContext is NULL.\r
+  @retval RETURN_UNSUPPORTED        The PE/COFF image is not supported.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderGetImageInfo (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+    return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().\r
+\r
+  If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of\r
+  ImageContext as the relocation base address.  Otherwise, use the DestinationAddress field\r
+  of ImageContext as the relocation base address.  The caller must allocate the relocation\r
+  fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.  \r
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext        Pointer to the image context structure that describes the PE/COFF\r
+                              image that is being relocated.\r
+\r
+  @retval RETURN_SUCCESS      The PE/COFF image was relocated.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR   The image in not a valid PE/COFF image.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_UNSUPPORTED  A relocation record type is not supported.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderRelocateImage (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  Loads a PE/COFF image into memory.\r
+\r
+  Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer\r
+  specified by the ImageAddress and ImageSize fields of ImageContext.  The caller must allocate\r
+  the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.\r
+  The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.\r
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image that is being loaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was loaded into the buffer specified by\r
+                                    the ImageAddress and ImageSize fields of ImageContext.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_BUFFER_TOO_SMALL   The caller did not provide a large enough buffer.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR         The PE/COFF image is an EFI Runtime image with no relocations.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_INVALID_PARAMETER  The image address is invalid.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderLoadImage (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  ImageRead function that operates on a memory buffer whos base is passed into\r
+  FileHandle. \r
+\r
+  @param  FileHandle        Ponter to baes of the input stream\r
+  @param  FileOffset        Offset to the start of the buffer\r
+  @param  ReadSize          Number of bytes to copy into the buffer\r
+  @param  Buffer            Location to place results of read\r
+\r
+  @retval RETURN_SUCCESS    Data is read from FileOffset from the Handle into \r
+                            the buffer.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderImageReadFromMemory (\r
+  IN     VOID    *FileHandle,\r
+  IN     UINTN   FileOffset,\r
+  IN OUT UINTN   *ReadSize,\r
+  OUT    VOID    *Buffer\r
+  )\r
+{\r
+  return RETURN_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI\r
+  runtime. \r
+  \r
+  PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply\r
+  the fixups with a virtual mapping.\r
+\r
+\r
+  @param  ImageBase          Base address of relocated image\r
+  @param  VirtImageBase      Virtual mapping for ImageBase\r
+  @param  ImageSize          Size of the image to relocate\r
+  @param  RelocationData     Location to place results of read\r
+  \r
+**/\r
+VOID\r
+EFIAPI\r
+PeCoffLoaderRelocateImageForRuntime (\r
+  IN  PHYSICAL_ADDRESS        ImageBase,\r
+  IN  PHYSICAL_ADDRESS        VirtImageBase,\r
+  IN  UINTN                   ImageSize,\r
+  IN  VOID                    *RelocationData\r
+  )\r
+{\r
+}\r
+\r
+/**\r
+  Unloads a loaded PE/COFF image from memory and releases its taken resource.\r
+   \r
+  For Unix emulator, the PE/COFF image loaded by system needs to release.\r
+  For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, \r
+  this function can simply return RETURN_SUCCESS.\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image to be unloaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was unloaded successfully.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderUnloadImage (\r
+  IN PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
diff --git a/edk2/UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.inf b/edk2/UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.inf
new file mode 100644 (file)
index 0000000..b5fd473
--- /dev/null
@@ -0,0 +1,50 @@
+#/** @file\r
+# PeCoff libary for Dxe modules that run Unix emulator.\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2007 - 2008, Intel Corporation\r
+# All rights reserved. This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DxeUnixPeCoffLib\r
+  FILE_GUID                      = 624571b0-4b69-40e3-bd13-78fae0e84270\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PeCoffLib|DXE_CORE DXE_DRIVER\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = DxeUnixPeCoffLibConstructor\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32\r
+#\r
+\r
+[Sources.common]\r
+  DxeUnixPeCoffLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  HobLib\r
+\r
+[Guids]\r
+  gEfiPeiPeCoffLoaderGuid                # ALWAYS_CONSUMED\r
+\r
diff --git a/edk2/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.inf b/edk2/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.inf
new file mode 100644 (file)
index 0000000..5128c3a
--- /dev/null
@@ -0,0 +1,50 @@
+#/** @file\r
+# Component description file for the EdkNt32PeiPeCoffGetEntryPointLib library.\r
+#\r
+# PeCoffGetEntryPointLib library class for NT32 instance implemented by use NTPeiLoadFile PPI.\r
+# Copyright (c) 2008, Intel Corporation\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = EdkUnixPeiPeCoffGetEntryPointLib\r
+  FILE_GUID                      = f3b702e8-8985-11db-9558-0040d02b1835\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PeCoffGetEntryPointLib \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  PeCoffGetEntryPoint.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  PeiServicesLib\r
+  DebugLib\r
+\r
+\r
+[Ppis]\r
+  gUnixPeiLoadFilePpiGuid                       # PPI ALWAYS_CONSUMED\r
+\r
diff --git a/edk2/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.msa b/edk2/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.msa
new file mode 100644 (file)
index 0000000..1c44900
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>EdkUnixPeiPeCoffGetEntryPointLib</ModuleName>\r
+    <ModuleType>PEIM</ModuleType>\r
+    <GuidValue>f3b702e8-8985-11db-9558-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for the EdkNt32PeiPeCoffGetEntryPointLib library.</Abstract>\r
+    <Description>PeCoffGetEntryPointLib library class for NT32 instance implemented by use NTPeiLoadFile PPI.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>All rights reserved. This program and the accompanying materials\r
+      are licensed and made available under the terms and conditions of the BSD License\r
+      which accompanies this distribution.  The full text of the license may be found at\r
+      http://opensource.org/licenses/bsd-license.php\r
+      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+      WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>EdkUnixPeiPeCoffGetEntryPointLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED">\r
+      <Keyword>PeCoffGetEntryPointLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeiServicesLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>PeCoffGetEntryPoint.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <PPIs>\r
+    <Ppi Usage="ALWAYS_CONSUMED">\r
+      <PpiCName>gUnixPeiLoadFilePpiGuid</PpiCName>\r
+    </Ppi>\r
+  </PPIs>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/edk2/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c b/edk2/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c
new file mode 100644 (file)
index 0000000..758ce9d
--- /dev/null
@@ -0,0 +1,266 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  PeCoffGetEntryPoint.c\r
+\r
+Abstract:\r
+\r
+  Tiano PE/COFF loader\r
+\r
+Revision History\r
+\r
+--*/\r
+#include "PiPei.h"\r
+#include <Library/PeCoffGetEntryPointLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Ppi/UnixPeiLoadFile.h>\r
+#include <IndustryStandard/PeImage.h>\r
+#include <Library/DebugLib.h>\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderGetEntryPoint (\r
+  IN     VOID  *Pe32Data,\r
+  IN OUT VOID  **EntryPoint\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Loads a PE/COFF image into memory, this is not follow the original purpose of \r
+  PeCoffGetEntryPoint library class.  But it's ok that Unix package not run on a real \r
+  platform and this is for source level debug.\r
+\r
+Arguments:\r
+\r
+  Pe32Data   - Pointer to a PE/COFF Image\r
+\r
+  EntryPoint - Pointer to the entry point of the PE/COFF image\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS            if the EntryPoint was returned\r
+  EFI_INVALID_PARAMETER  if the EntryPoint could not be found from Pe32Data\r
+\r
+--*/\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_PEI_PPI_DESCRIPTOR  *PpiDescriptor;\r
+  UNIX_PEI_LOAD_FILE_PPI *PeiUnixService;\r
+  EFI_PHYSICAL_ADDRESS    ImageAddress;\r
+  UINT64                  ImageSize;\r
+  EFI_PHYSICAL_ADDRESS    ImageEntryPoint;\r
+\r
+  ASSERT (Pe32Data   != NULL);\r
+  ASSERT (EntryPoint != NULL);\r
+\r
+  Status = PeiServicesLocatePpi (\r
+             &gUnixPeiLoadFilePpiGuid,\r
+             0,\r
+             &PpiDescriptor,\r
+             (void **)&PeiUnixService\r
+             );\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = PeiUnixService->PeiLoadFileService (\r
+                           Pe32Data,\r
+                           &ImageAddress,\r
+                           &ImageSize,\r
+                           &ImageEntryPoint\r
+                           );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  *EntryPoint = (VOID*)(UINTN)ImageEntryPoint;\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Returns the machine type of PE/COFF image. \r
+  This is copied from MDE BasePeCoffGetEntryPointLib, the code should be sync with it.\r
+  The reason is Unix package needs to load the image to memory to support source\r
+  level debug.\r
+   \r
+\r
+  @param  Pe32Data   Pointer to a PE/COFF header\r
+\r
+  @return            Machine type or zero if not a valid iamge\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+PeCoffLoaderGetMachineType (\r
+  IN  VOID  *Pe32Data\r
+  )\r
+{  \r
+  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr;\r
+  EFI_IMAGE_DOS_HEADER                 *DosHdr;\r
+\r
+  ASSERT (Pe32Data   != NULL);\r
+\r
+  DosHdr = (EFI_IMAGE_DOS_HEADER  *)Pe32Data;\r
+  if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
+\r
+  } else {\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)(Pe32Data);\r
+  }\r
+\r
+  if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
+    return Hdr.Te->Machine;\r
+  } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)  {\r
+    return Hdr.Pe32->FileHeader.Machine;\r
+  }\r
+\r
+  return 0x0000;\r
+}\r
+\r
+/**\r
+  Returns a pointer to the PDB file name for a PE/COFF image that has been\r
+  loaded into system memory with the PE/COFF Loader Library functions.\r
+\r
+  Returns the PDB file name for the PE/COFF image specified by Pe32Data.  If\r
+  the PE/COFF image specified by Pe32Data is not a valid, then NULL is\r
+  returned.  If the PE/COFF image specified by Pe32Data does not contain a\r
+  debug directory entry, then NULL is returned.  If the debug directory entry\r
+  in the PE/COFF image specified by Pe32Data does not contain a PDB file name,\r
+  then NULL is returned.\r
+  If Pe32Data is NULL, then ASSERT().\r
+\r
+  @param  Pe32Data   Pointer to the PE/COFF image that is loaded in system\r
+                     memory.\r
+\r
+  @return The PDB file name for the PE/COFF image specified by Pe32Data or NULL\r
+          if it cannot be retrieved.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+PeCoffLoaderGetPdbPointer (\r
+  IN VOID  *Pe32Data\r
+  )\r
+{\r
+  EFI_IMAGE_DOS_HEADER                  *DosHdr;\r
+  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION   Hdr;\r
+  EFI_IMAGE_DATA_DIRECTORY              *DirectoryEntry;\r
+  EFI_IMAGE_DEBUG_DIRECTORY_ENTRY       *DebugEntry;\r
+  UINTN                                 DirCount;\r
+  VOID                                  *CodeViewEntryPointer;\r
+  INTN                                  TEImageAdjust;\r
+  UINT32                                NumberOfRvaAndSizes;\r
+  UINT16                                Magic;\r
+\r
+  ASSERT (Pe32Data   != NULL);\r
+\r
+  TEImageAdjust       = 0;\r
+  DirectoryEntry      = NULL;\r
+  DebugEntry          = NULL;\r
+  NumberOfRvaAndSizes = 0;\r
+\r
+  DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
+  if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
+    //\r
+    // DOS image header is present, so read the PE header after the DOS image header.\r
+    //\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
+  } else {\r
+    //\r
+    // DOS image header is not present, so PE header is at the image base.\r
+    //\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
+  }\r
+\r
+  if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
+    if (Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress != 0) {\r
+      DirectoryEntry  = &Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG];\r
+      TEImageAdjust   = sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize;\r
+      DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN) Hdr.Te +\r
+                    Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress +\r
+                    TEImageAdjust);\r
+    }\r
+  } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
+    //\r
+    // NOTE: We use Machine field to identify PE32/PE32+, instead of Magic.\r
+    //       It is due to backward-compatibility, for some system might\r
+    //       generate PE32+ image with PE32 Magic.\r
+    //\r
+    switch (Hdr.Pe32->FileHeader.Machine) {\r
+    case EFI_IMAGE_MACHINE_IA32:\r
+      //\r
+      // Assume PE32 image with IA32 Machine field.\r
+      //\r
+      Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;\r
+      break;\r
+    case EFI_IMAGE_MACHINE_X64:\r
+    case EFI_IMAGE_MACHINE_IPF:\r
+      //\r
+      // Assume PE32+ image with X64 or IPF Machine field\r
+      //\r
+      Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;\r
+      break;\r
+    default:\r
+      //\r
+      // For unknow Machine field, use Magic in optional Header\r
+      //\r
+      Magic = Hdr.Pe32->OptionalHeader.Magic;\r
+    }\r
+\r
+    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
+      //\r
+      // Use PE32 offset get Debug Directory Entry\r
+      //\r
+      NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;\r
+      DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
+      DebugEntry     = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);\r
+    } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
+      //\r
+      // Use PE32+ offset get Debug Directory Entry\r
+      //\r
+      NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;\r
+      DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
+      DebugEntry     = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);\r
+    }\r
+\r
+    if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {\r
+      DirectoryEntry = NULL;\r
+      DebugEntry = NULL;\r
+    }\r
+  } else {\r
+    return NULL;\r
+  }\r
+\r
+  if (DebugEntry == NULL || DirectoryEntry == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY), DebugEntry++) {\r
+    if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {\r
+      if (DebugEntry->SizeOfData > 0) {\r
+        CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + ((UINTN)Pe32Data) + (UINTN)TEImageAdjust);\r
+        switch (* (UINT32 *) CodeViewEntryPointer) {\r
+        case CODEVIEW_SIGNATURE_NB10:\r
+          return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY));\r
+        case CODEVIEW_SIGNATURE_RSDS:\r
+          return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY));\r
+        default:\r
+          break;\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  return NULL;\r
+}\r
diff --git a/edk2/UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.c b/edk2/UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.c
new file mode 100644 (file)
index 0000000..2c24417
--- /dev/null
@@ -0,0 +1,262 @@
+/**@file\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  PeiCoreUnixPeCoffLib.c\r
+\r
+Abstract:\r
+\r
+  Wrap the Unix PE/COFF loader with the PE COFF LOADER guid structure\r
+  to produce PeCoff library class.\r
+\r
+\r
+**/\r
+\r
+#include <PiPei.h>\r
+#include <Guid/PeiPeCoffLoader.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+\r
+EFI_PEI_PE_COFF_LOADER_PROTOCOL  *mPeiEfiPeiPeCoffLoader = NULL;\r
+\r
+/**\r
+  The function caches the pointer of PeCofferLoader guid structure\r
+  into the guid data hob.\r
+\r
+  The funtion must be called after PeCofferLoader guid structure is installed.\r
+  It will ASSERT() if PeCofferLoader guid structure is not installed.\r
+\r
+  @retval EFI_SUCCESS   PeCofferLoader guid structure is found.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetPeCoffLoaderStucture (\r
+  )\r
+{\r
+  EFI_STATUS           Status;\r
+  EFI_HOB_GUID_TYPE    *GuidHob;\r
+\r
+  Status = EFI_NOT_FOUND;\r
+  \r
+  //\r
+  // Try to get guid data hob that contains PeCoffLoader guid structure.\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);\r
+\r
+  if (GuidHob == NULL) {\r
+    //\r
+    // GuidHob is not ready, try to locate PeCoffLoader guid structure.\r
+    //\r
+    Status = PeiServicesLocatePpi (\r
+                &gEfiPeiPeCoffLoaderGuid,\r
+                0,\r
+                NULL,\r
+                &mPeiEfiPeiPeCoffLoader\r
+                );\r
+    \r
+    //\r
+    // PeCofferLoader guid structure must be installed before this library runs.\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
+    \r
+    //\r
+    // Build guid data hob of PeCofferLoader guid structure for DXE module use. \r
+    //\r
+    BuildGuidDataHob (\r
+      &gEfiPeiPeCoffLoaderGuid,\r
+      (VOID *) &mPeiEfiPeiPeCoffLoader,\r
+      sizeof (VOID *)\r
+      );\r
+  } else {\r
+    //\r
+    // Get PeCofferLoader guid structure directly from guid hob data.\r
+    //\r
+    mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Retrieves information about a PE/COFF image.\r
+\r
+  Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,\r
+  PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva\r
+  fields of the ImageContext structure.  If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.\r
+  If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not\r
+  a supported PE/COFF image type, then return RETURN_UNSUPPORTED.  If any errors occur while\r
+  computing the fields of ImageContext, then the error status is returned in the ImageError field of\r
+  ImageContext. \r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image that needs to be examined by this function.\r
+\r
+  @retval RETURN_SUCCESS            The information on the PE/COFF image was collected.\r
+  @retval RETURN_INVALID_PARAMETER  ImageContext is NULL.\r
+  @retval RETURN_UNSUPPORTED        The PE/COFF image is not supported.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderGetImageInfo (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  if (mPeiEfiPeiPeCoffLoader == NULL) {\r
+    GetPeCoffLoaderStucture ();\r
+  }\r
+  return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().\r
+\r
+  If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of\r
+  ImageContext as the relocation base address.  Otherwise, use the DestinationAddress field\r
+  of ImageContext as the relocation base address.  The caller must allocate the relocation\r
+  fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.  \r
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext        Pointer to the image context structure that describes the PE/COFF\r
+                              image that is being relocated.\r
+\r
+  @retval RETURN_SUCCESS      The PE/COFF image was relocated.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR   The image in not a valid PE/COFF image.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_UNSUPPORTED  A relocation record type is not supported.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderRelocateImage (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  if (mPeiEfiPeiPeCoffLoader == NULL) {\r
+    GetPeCoffLoaderStucture ();\r
+  }\r
+  return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  Loads a PE/COFF image into memory.\r
+\r
+  Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer\r
+  specified by the ImageAddress and ImageSize fields of ImageContext.  The caller must allocate\r
+  the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.\r
+  The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.\r
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image that is being loaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was loaded into the buffer specified by\r
+                                    the ImageAddress and ImageSize fields of ImageContext.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_BUFFER_TOO_SMALL   The caller did not provide a large enough buffer.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR         The PE/COFF image is an EFI Runtime image with no relocations.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_INVALID_PARAMETER  The image address is invalid.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderLoadImage (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  if (mPeiEfiPeiPeCoffLoader == NULL) {\r
+    GetPeCoffLoaderStucture ();\r
+  }\r
+  return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  ImageRead function that operates on a memory buffer whos base is passed into\r
+  FileHandle. \r
+\r
+  @param  FileHandle        Ponter to baes of the input stream\r
+  @param  FileOffset        Offset to the start of the buffer\r
+  @param  ReadSize          Number of bytes to copy into the buffer\r
+  @param  Buffer            Location to place results of read\r
+\r
+  @retval RETURN_SUCCESS    Data is read from FileOffset from the Handle into \r
+                            the buffer.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderImageReadFromMemory (\r
+  IN     VOID    *FileHandle,\r
+  IN     UINTN   FileOffset,\r
+  IN OUT UINTN   *ReadSize,\r
+  OUT    VOID    *Buffer\r
+  )\r
+{\r
+  return RETURN_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI\r
+  runtime. \r
+  \r
+  PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply\r
+  the fixups with a virtual mapping.\r
+\r
+\r
+  @param  ImageBase          Base address of relocated image\r
+  @param  VirtImageBase      Virtual mapping for ImageBase\r
+  @param  ImageSize          Size of the image to relocate\r
+  @param  RelocationData     Location to place results of read\r
+  \r
+**/\r
+VOID\r
+EFIAPI\r
+PeCoffLoaderRelocateImageForRuntime (\r
+  IN  PHYSICAL_ADDRESS        ImageBase,\r
+  IN  PHYSICAL_ADDRESS        VirtImageBase,\r
+  IN  UINTN                   ImageSize,\r
+  IN  VOID                    *RelocationData\r
+  )\r
+{\r
+}\r
+\r
+/**\r
+  Unloads a loaded PE/COFF image from memory and releases its taken resource.\r
+   \r
+  For Unix emulator, the PE/COFF image loaded by system needs to release.\r
+  For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, \r
+  this function can simply return RETURN_SUCCESS.\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image to be unloaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was unloaded successfully.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderUnloadImage (\r
+  IN PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  )\r
+{\r
+  if (mPeiEfiPeiPeCoffLoader == NULL) {\r
+    GetPeCoffLoaderStucture ();\r
+  }\r
+  return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
diff --git a/edk2/UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.inf b/edk2/UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.inf
new file mode 100644 (file)
index 0000000..12b2188
--- /dev/null
@@ -0,0 +1,49 @@
+#/** @file\r
+# PeCoff libary for PeiCore modules that run Unix emulator.\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2007 - 2008, Intel Corporation\r
+# All rights reserved. This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PeiCoreUnixPeCoffLib\r
+  FILE_GUID                      = ef9fd7ee-3181-4b16-adc1-8615f88b58b8\r
+  MODULE_TYPE                    = PEI_CORE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PeCoffLib|PEI_CORE\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32\r
+#\r
+\r
+[Sources.common]\r
+  PeiCoreUnixPeCoffLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+[LibraryClasses]\r
+  PeiServicesLib\r
+  DebugLib\r
+  HobLib\r
+\r
+[Guids]\r
+  gEfiPeiPeCoffLoaderGuid                # ALWAYS_CONSUMED\r
+\r
diff --git a/edk2/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.inf b/edk2/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.inf
new file mode 100644 (file)
index 0000000..0d4c7f6
--- /dev/null
@@ -0,0 +1,61 @@
+#/** @file\r
+# Memory Status Code Library for UEFI drivers\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2007, Intel Corporation.\r
+#\r
+#  All rights reserved.\r
+#  This software and associated documentation (if any) is furnished\r
+#  under a license and may only be used or copied in accordance\r
+#  with the terms of the license. Except as permitted by such\r
+#  license, no part of this software or documentation may be\r
+#  reproduced, stored in a retrieval system, or transmitted in any\r
+#  form or by any means without the express written consent of\r
+#  Intel Corporation.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PeiUnixOemHookStatusCodeLib\r
+  FILE_GUID                      = 23E378C1-B199-49ad-9F14-DAF5D3C7EC28\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = OemHookStatusCodeLib|PEIM \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32\r
+#\r
+\r
+[Sources.common]\r
+  UnixOemHookStatusCodeLib.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  PeiServicesLib\r
+  ReportStatusCodeLib\r
+  BaseMemoryLib\r
+  PrintLib\r
+  DebugLib\r
+\r
+\r
+[Guids]\r
+  gEfiStatusCodeSpecificDataGuid                # ALWAYS_CONSUMED\r
+\r
+\r
+[Ppis]\r
+  gPeiUnixThunkPpiGuid                          # PPI ALWAYS_CONSUMED\r
+\r
diff --git a/edk2/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.msa b/edk2/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.msa
new file mode 100644 (file)
index 0000000..f80a105
--- /dev/null
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>PeiUnixOemHookStatusCodeLib</ModuleName>\r
+    <ModuleType>PEIM</ModuleType>\r
+    <GuidValue>23E378C1-B199-49ad-9F14-DAF5D3C7EC28</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Memory Status Code Library for UEFI drivers</Abstract>\r
+    <Description>Lib to provide memory journal status code reporting Routines</Description>\r
+    <Copyright>Copyright (c) 2007, Intel Corporation.</Copyright>\r
+    <License>All rights reserved.\r
+      This software and associated documentation (if any) is furnished\r
+      under a license and may only be used or copied in accordance\r
+      with the terms of the license. Except as permitted by such\r
+      license, no part of this software or documentation may be\r
+      reproduced, stored in a retrieval system, or transmitted in any\r
+      form or by any means without the express written consent of\r
+      Intel Corporation.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>PeiUnixOemHookStatusCodeLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="PEIM">\r
+      <Keyword>OemHookStatusCodeLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PrintLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>ReportStatusCodeLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeiServicesLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnixOemHookStatusCodeLib.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <PPIs>\r
+    <Ppi Usage="ALWAYS_CONSUMED">\r
+      <PpiCName>gPeiUnixThunkPpiGuid</PpiCName>\r
+    </Ppi>\r
+  </PPIs>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiStatusCodeSpecificDataGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/edk2/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c b/edk2/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c
new file mode 100644 (file)
index 0000000..8d661bc
--- /dev/null
@@ -0,0 +1,246 @@
+/** @file
+  OEM hook status code library functions with no library constructor/destructor
+
+  Copyright (c) 2006 - 2008, Intel Corporation
+  All rights reserved. This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+  Module Name:  UnixOemHookStatusCodeLib.c
+
+**/
+#include "PiPei.h"
+#include <Guid/StatusCodeDataTypeId.h>
+#include <Ppi/UnixThunk.h>
+#include <FrameworkModuleBase.h>
+#include <Library/OemHookStatusCodeLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PrintLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/ReportStatusCodeLib.h>
+#include <Library/PeiServicesLib.h>
+#include <DebugInfo.h>
+
+//
+// Cache of UnixThunk protocol 
+//
+STATIC
+EFI_UNIX_THUNK_PROTOCOL   *mUnix;
+
+//
+// Cache of standard output handle . 
+//
+STATIC
+int                      mStdOut;
+
+/**
+
+  Initialize OEM status code device .
+
+  @return    Always return EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+OemHookStatusCodeInitialize (
+  VOID
+  )
+{
+  PEI_UNIX_THUNK_PPI  *UnixThunkPpi;
+  EFI_STATUS        Status;
+
+  
+  //
+  // Locate Unix ThunkPpi for retrieving standard output handle
+  //
+  Status = PeiServicesLocatePpi (
+              &gPeiUnixThunkPpiGuid,
+              0,
+              NULL,
+              (VOID **) &UnixThunkPpi
+              );
+
+  ASSERT_EFI_ERROR (Status);
+
+  mUnix  = (EFI_UNIX_THUNK_PROTOCOL *) UnixThunkPpi->UnixThunk ();
+  
+  //
+  // Cache standard output handle.
+  //
+  mStdOut = 1;
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Report status code to OEM device.
+  @param  CodeType      Indicates the type of status code being reported.  Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
+  @param  Value         Describes the current status of a hardware or software entity.  
+                        This included information about the class and subclass that is used to classify the entity 
+                        as well as an operation.  For progress codes, the operation is the current activity. 
+                        For error codes, it is the exception.  For debug codes, it is not defined at this time. 
+                        Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.  
+                        Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
+  @param  Instance      The enumeration of a hardware or software entity within the system.  
+                        A system may contain multiple entities that match a class/subclass pairing. 
+                        The instance differentiates between them.  An instance of 0 indicates that instance information is unavailable, 
+                        not meaningful, or not relevant.  Valid instance numbers start with 1.
+
+
+  @param  CallerId      This optional parameter may be used to identify the caller. 
+                        This parameter allows the status code driver to apply different rules to different callers. 
+                        Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
+
+
+  @param  Data          This optional parameter may be used to pass additional data
+  @return               The function always return EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+OemHookStatusCodeReport (
+  IN EFI_STATUS_CODE_TYPE     CodeType,
+  IN EFI_STATUS_CODE_VALUE    Value,
+  IN UINT32                   Instance,
+  IN EFI_GUID                 *CallerId, OPTIONAL
+  IN EFI_STATUS_CODE_DATA     *Data      OPTIONAL
+  )
+{
+  CHAR8           *Filename;
+  CHAR8           *Description;
+  CHAR8           *Format;
+  CHAR8           Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
+  UINT32          ErrorLevel;
+  UINT32          LineNumber;
+  UINTN           CharCount;
+  VA_LIST         Marker;
+  EFI_DEBUG_INFO  *DebugInfo;
+
+  Buffer[0] = '\0';
+
+  if (Data != NULL &&
+      ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
+    //
+    // Print ASSERT() information into output buffer.
+    //
+    CharCount = AsciiSPrint (
+                  Buffer,
+                  EFI_STATUS_CODE_DATA_MAX_SIZE,
+                  "\n\rASSERT!: %a (%d): %a\n\r",
+                  Filename,
+                  LineNumber,
+                  Description
+                  );
+
+    //
+    // Callout to standard output.
+    //
+    mUnix->Write (
+              mStdOut,
+              Buffer,
+              CharCount
+             );
+
+    return EFI_SUCCESS;
+
+  } else if (Data != NULL &&
+             ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
+    //
+    // Print DEBUG() information into output buffer.
+    //
+    CharCount = AsciiVSPrint (
+                  Buffer, 
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, 
+                  Format, 
+                  Marker
+                  );
+  } else if (Data != NULL && 
+             CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&
+             (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {
+    //
+    // Print specific data into output buffer.
+    //
+    DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);
+    Marker    = (VA_LIST) (DebugInfo + 1);
+    Format    = (CHAR8 *) (((UINT64 *) Marker) + 12);
+
+    CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);
+  } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
+    //
+    // Print ERROR information into output buffer.
+    //
+    CharCount = AsciiSPrint (
+                  Buffer, 
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, 
+                  "ERROR: C%x:V%x I%x", 
+                  CodeType, 
+                  Value, 
+                  Instance
+                  );
+
+    //
+    // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
+    //
+    
+    if (CallerId != NULL) {
+      CharCount += AsciiSPrint (
+                     &Buffer[CharCount - 1],
+                     (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
+                     " %g",
+                     CallerId
+                     );
+    }
+
+    if (Data != NULL) {
+      CharCount += AsciiSPrint (
+                     &Buffer[CharCount - 1],
+                     (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
+                     " %x",
+                     Data
+                     );
+    }
+
+    CharCount += AsciiSPrint (
+                   &Buffer[CharCount - 1],
+                   (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
+                   "\n\r"
+                   );
+  } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
+    CharCount = AsciiSPrint (
+                  Buffer, 
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, 
+                  "PROGRESS CODE: V%x I%x\n\r", 
+                  Value, 
+                  Instance
+                  );
+  } else {
+    CharCount = AsciiSPrint (
+                  Buffer, 
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, 
+                  "Undefined: C%x:V%x I%x\n\r", 
+                  CodeType, 
+                  Value, 
+                  Instance
+                  );
+  }
+
+  //
+  // Callout to standard output.
+  //
+  mUnix->Write (
+            mStdOut,
+            Buffer,
+            CharCount
+            );
+
+  return EFI_SUCCESS;
+}
+
diff --git a/edk2/UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.c b/edk2/UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.c
new file mode 100644 (file)
index 0000000..18a2551
--- /dev/null
@@ -0,0 +1,255 @@
+/**@file\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  PeiUnixPeCoffLib.c\r
+\r
+Abstract:\r
+\r
+  Wrap the Unix PE/COFF loader with the PE COFF LOADER guid structure\r
+  to produce PeCoff library class.\r
+\r
+\r
+**/\r
+\r
+#include <PiPei.h>\r
+#include <Guid/PeiPeCoffLoader.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/HobLib.h>\r
+\r
+EFI_PEI_PE_COFF_LOADER_PROTOCOL  *mPeiEfiPeiPeCoffLoader;\r
+\r
+/**\r
+  The constructor function caches the pointer of PeCofferLoader guid structure\r
+  into the guid data hob.\r
+\r
+  The constructor must be called after PeCofferLoader guid structure is installed.\r
+  It will ASSERT() if PeCofferLoader guid structure is not installed.\r
+\r
+  @param  FfsHeader   Pointer to FFS header the loaded driver.\r
+  @param  PeiServices Pointer to the PEI services.\r
+\r
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiUnixPeCoffLibConstructor (\r
+  IN EFI_FFS_FILE_HEADER      *FfsHeader,\r
+  IN EFI_PEI_SERVICES         **PeiServices\r
+  )\r
+{\r
+  EFI_STATUS           Status;\r
+  EFI_HOB_GUID_TYPE    *GuidHob;\r
+\r
+  Status = EFI_NOT_FOUND;\r
+  \r
+  //\r
+  // Try to get guid data hob that contains PeCoffLoader guid structure.\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);\r
+\r
+  if (GuidHob == NULL) {\r
+    //\r
+    // GuidHob is not ready, try to locate PeCoffLoader guid structure.\r
+    //\r
+    Status = (*PeiServices)->LocatePpi (\r
+                              PeiServices,\r
+                              &gEfiPeiPeCoffLoaderGuid,\r
+                              0,\r
+                              NULL,\r
+                              &mPeiEfiPeiPeCoffLoader\r
+                              );\r
+    \r
+    //\r
+    // PeCofferLoader guid structure must be installed before this library runs.\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
+    \r
+    //\r
+    // Build guid data hob of PeCofferLoader guid structure for DXE module use. \r
+    //\r
+    BuildGuidDataHob (\r
+      &gEfiPeiPeCoffLoaderGuid,\r
+      (VOID *) &mPeiEfiPeiPeCoffLoader,\r
+      sizeof (VOID *)\r
+      );\r
+  } else {\r
+    //\r
+    // Get PeCofferLoader guid structure directly from guid hob data.\r
+    //\r
+    mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Retrieves information about a PE/COFF image.\r
+\r
+  Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,\r
+  PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva\r
+  fields of the ImageContext structure.  If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.\r
+  If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not\r
+  a supported PE/COFF image type, then return RETURN_UNSUPPORTED.  If any errors occur while\r
+  computing the fields of ImageContext, then the error status is returned in the ImageError field of\r
+  ImageContext. \r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image that needs to be examined by this function.\r
+\r
+  @retval RETURN_SUCCESS            The information on the PE/COFF image was collected.\r
+  @retval RETURN_INVALID_PARAMETER  ImageContext is NULL.\r
+  @retval RETURN_UNSUPPORTED        The PE/COFF image is not supported.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderGetImageInfo (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+    return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().\r
+\r
+  If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of\r
+  ImageContext as the relocation base address.  Otherwise, use the DestinationAddress field\r
+  of ImageContext as the relocation base address.  The caller must allocate the relocation\r
+  fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.  \r
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext        Pointer to the image context structure that describes the PE/COFF\r
+                              image that is being relocated.\r
+\r
+  @retval RETURN_SUCCESS      The PE/COFF image was relocated.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR   The image in not a valid PE/COFF image.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_UNSUPPORTED  A relocation record type is not supported.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderRelocateImage (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  Loads a PE/COFF image into memory.\r
+\r
+  Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer\r
+  specified by the ImageAddress and ImageSize fields of ImageContext.  The caller must allocate\r
+  the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.\r
+  The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.\r
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image that is being loaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was loaded into the buffer specified by\r
+                                    the ImageAddress and ImageSize fields of ImageContext.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_BUFFER_TOO_SMALL   The caller did not provide a large enough buffer.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR         The PE/COFF image is an EFI Runtime image with no relocations.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_INVALID_PARAMETER  The image address is invalid.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderLoadImage (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  ImageRead function that operates on a memory buffer whos base is passed into\r
+  FileHandle. \r
+\r
+  @param  FileHandle        Ponter to baes of the input stream\r
+  @param  FileOffset        Offset to the start of the buffer\r
+  @param  ReadSize          Number of bytes to copy into the buffer\r
+  @param  Buffer            Location to place results of read\r
+\r
+  @retval RETURN_SUCCESS    Data is read from FileOffset from the Handle into \r
+                            the buffer.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderImageReadFromMemory (\r
+  IN     VOID    *FileHandle,\r
+  IN     UINTN   FileOffset,\r
+  IN OUT UINTN   *ReadSize,\r
+  OUT    VOID    *Buffer\r
+  )\r
+{\r
+  return RETURN_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI\r
+  runtime. \r
+  \r
+  PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply\r
+  the fixups with a virtual mapping.\r
+\r
+\r
+  @param  ImageBase          Base address of relocated image\r
+  @param  VirtImageBase      Virtual mapping for ImageBase\r
+  @param  ImageSize          Size of the image to relocate\r
+  @param  RelocationData     Location to place results of read\r
+  \r
+**/\r
+VOID\r
+EFIAPI\r
+PeCoffLoaderRelocateImageForRuntime (\r
+  IN  PHYSICAL_ADDRESS        ImageBase,\r
+  IN  PHYSICAL_ADDRESS        VirtImageBase,\r
+  IN  UINTN                   ImageSize,\r
+  IN  VOID                    *RelocationData\r
+  )\r
+{\r
+}\r
+\r
+/**\r
+  Unloads a loaded PE/COFF image from memory and releases its taken resource.\r
+   \r
+  For Unix emulator, the PE/COFF image loaded by system needs to release.\r
+  For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, \r
+  this function can simply return RETURN_SUCCESS.\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image to be unloaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was unloaded successfully.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderUnloadImage (\r
+  IN PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
diff --git a/edk2/UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.inf b/edk2/UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.inf
new file mode 100644 (file)
index 0000000..7be9c26
--- /dev/null
@@ -0,0 +1,50 @@
+#/** @file\r
+# PeCoff libary for PEIM modules that run Unix emulator.\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2007 - 2008, Intel Corporation\r
+# All rights reserved. This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PeiUnixPeCoffLib\r
+  FILE_GUID                      = 91404129-c58a-40bb-8a2b-f05bc05a961c\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PeCoffLib|PEIM\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = PeiUnixPeCoffLibConstructor\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32\r
+#\r
+\r
+[Sources.common]\r
+  PeiUnixPeCoffLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  HobLib\r
+\r
+[Guids]\r
+  gEfiPeiPeCoffLoaderGuid                # ALWAYS_CONSUMED\r
+\r
diff --git a/edk2/UnixPkg/Library/UnixBdsLib/BdsPlatform.c b/edk2/UnixPkg/Library/UnixBdsLib/BdsPlatform.c
new file mode 100644 (file)
index 0000000..7e02767
--- /dev/null
@@ -0,0 +1,514 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  BdsPlatform.c\r
+\r
+Abstract:\r
+\r
+  This file include all platform action which can be customized\r
+  by IBV/OEM.\r
+\r
+--*/\r
+\r
+#include "BdsPlatform.h"\r
+\r
+CHAR16  mFirmwareVendor[] = L"TianoCore.org";\r
+\r
+//\r
+// BDS Platform Functions\r
+//\r
+VOID\r
+PlatformBdsInit (\r
+  IN EFI_BDS_ARCH_PROTOCOL_INSTANCE  *PrivateData\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Platform Bds init. Incude the platform firmware vendor, revision\r
+  and so crc check.\r
+\r
+Arguments:\r
+\r
+  PrivateData  - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance\r
+\r
+Returns:\r
+\r
+  None.\r
+\r
+--*/\r
+{\r
+  //\r
+  // set firmwarevendor, here can be IBV/OEM customize\r
+  //\r
+  gST->FirmwareVendor = AllocateRuntimeCopyPool (\r
+                          sizeof (mFirmwareVendor),\r
+                          &mFirmwareVendor\r
+                          );\r
+  ASSERT (gST->FirmwareVendor != NULL);\r
+\r
+  gST->FirmwareRevision = 0;\r
+\r
+  //\r
+  // Fixup Tasble CRC after we updated Firmware Vendor and Revision\r
+  //\r
+  gBS->CalculateCrc32 ((VOID *) gST, sizeof (EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);\r
+\r
+}\r
+\r
+EFI_STATUS\r
+PlatformBdsConnectConsole (\r
+  IN BDS_CONSOLE_CONNECT_ENTRY   *PlatformConsole\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Connect the predefined platform default console device. Always try to find\r
+  and enable the vga device if have.\r
+\r
+Arguments:\r
+\r
+  PlatformConsole         - Predfined platform default console device array.\r
\r
+Returns:\r
+\r
+  EFI_SUCCESS             - Success connect at least one ConIn and ConOut \r
+                            device, there must have one ConOut device is \r
+                            active vga device.\r
+  \r
+  EFI_STATUS              - Return the status of \r
+                            BdsLibConnectAllDefaultConsoles ()\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINTN       Index;\r
+\r
+  Index   = 0;\r
+  Status  = EFI_SUCCESS;\r
+\r
+  //\r
+  // Have chance to connect the platform default console,\r
+  // the platform default console is the minimue device group\r
+  // the platform should support\r
+  //\r
+  while (PlatformConsole[Index].DevicePath != NULL) {\r
+    //\r
+    // Update the console variable with the connect type\r
+    //\r
+    if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {\r
+      BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].DevicePath, NULL);\r
+    }\r
+\r
+    if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {\r
+      BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].DevicePath, NULL);\r
+    }\r
+\r
+    if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {\r
+      BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].DevicePath, NULL);\r
+    }\r
+\r
+    Index++;\r
+  }\r
+  //\r
+  // Connect the all the default console with current cosole variable\r
+  //\r
+  Status = BdsLibConnectAllDefaultConsoles ();\r
+  return Status;\r
+}\r
+\r
+VOID\r
+PlatformBdsConnectSequence (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Connect with predeined platform connect sequence, \r
+  the OEM/IBV can customize with their own connect sequence.\r
+  \r
+Arguments:\r
+\r
+  None.\r
\r
+Returns:\r
+\r
+  None.\r
+  \r
+--*/\r
+{\r
+  UINTN Index;\r
+\r
+  Index = 0;\r
+\r
+  //\r
+  // Here we can get the customized platform connect sequence\r
+  // Notes: we can connect with new variable which record the\r
+  // last time boots connect device path sequence\r
+  //\r
+  while (gPlatformConnectSequence[Index] != NULL) {\r
+    //\r
+    // Build the platform boot option\r
+    //\r
+    BdsLibConnectDevicePath (gPlatformConnectSequence[Index]);\r
+    Index++;\r
+  }\r
+\r
+  //\r
+  // Just use the simple policy to connect all devices\r
+  //\r
+  BdsLibConnectAll ();\r
+}\r
+\r
+VOID\r
+PlatformBdsGetDriverOption (\r
+  IN OUT LIST_ENTRY              *BdsDriverLists\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Load the predefined driver option, OEM/IBV can customize this\r
+  to load their own drivers\r
+  \r
+Arguments:\r
+\r
+  BdsDriverLists  - The header of the driver option link list.\r
\r
+Returns:\r
+\r
+  None.\r
+  \r
+--*/\r
+{\r
+  UINTN Index;\r
+\r
+  Index = 0;\r
+\r
+  //\r
+  // Here we can get the customized platform driver option\r
+  //\r
+  while (gPlatformDriverOption[Index] != NULL) {\r
+    //\r
+    // Build the platform boot option\r
+    //\r
+    BdsLibRegisterNewOption (BdsDriverLists, gPlatformDriverOption[Index], NULL, L"DriverOrder");\r
+    Index++;\r
+  }\r
+\r
+}\r
+\r
+VOID\r
+PlatformBdsDiagnostics (\r
+  IN EXTENDMEM_COVERAGE_LEVEL    MemoryTestLevel,\r
+  IN BOOLEAN                     QuietBoot\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Perform the platform diagnostic, such like test memory. OEM/IBV also\r
+  can customize this fuction to support specific platform diagnostic.\r
+  \r
+Arguments:\r
+\r
+  MemoryTestLevel  - The memory test intensive level\r
+  \r
+  QuietBoot        - Indicate if need to enable the quiet boot\r
\r
+Returns:\r
+\r
+  None.\r
+  \r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Here we can decide if we need to show\r
+  // the diagnostics screen\r
+  // Notes: this quiet boot code should be remove\r
+  // from the graphic lib\r
+  //\r
+  if (QuietBoot) {\r
+    EnableQuietBootEx (&gEfiDefaultBmpLogoGuid, mBdsImageHandle);\r
+    //\r
+    // Perform system diagnostic\r
+    //\r
+    Status = BdsMemoryTest (MemoryTestLevel);\r
+    if (EFI_ERROR (Status)) {\r
+      DisableQuietBoot ();\r
+    }\r
+\r
+    return ;\r
+  }\r
+  //\r
+  // Perform system diagnostic\r
+  //\r
+  Status = BdsMemoryTest (MemoryTestLevel);\r
+}\r
+\r
+VOID\r
+PlatformBdsPolicyBehavior (\r
+  IN EFI_BDS_ARCH_PROTOCOL_INSTANCE  *PrivateData,\r
+  IN OUT LIST_ENTRY                  *DriverOptionList,\r
+  IN OUT LIST_ENTRY                  *BootOptionList\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The function will excute with as the platform policy, current policy\r
+  is driven by boot mode. IBV/OEM can customize this code for their specific\r
+  policy action.\r
+  \r
+Arguments:\r
+\r
+  PrivateData      - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance\r
+  \r
+  DriverOptionList - The header of the driver option link list\r
+  \r
+  BootOptionList   - The header of the boot option link list\r
\r
+Returns:\r
+\r
+  None.\r
+  \r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT16      Timeout;\r
+\r
+  //\r
+  // Init the time out value\r
+  //\r
+  Timeout = BdsLibGetTimeout ();\r
+\r
+  //\r
+  // Load the driver option as the driver option list\r
+  //\r
+  PlatformBdsGetDriverOption (DriverOptionList);\r
+\r
+  //\r
+  // Get current Boot Mode\r
+  //\r
+  Status = BdsLibGetBootMode (&PrivateData->BootMode);\r
+\r
+  //\r
+  // Go the different platform policy with different boot mode\r
+  // Notes: this part code can be change with the table policy\r
+  //\r
+  switch (PrivateData->BootMode) {\r
+\r
+  case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:\r
+  case BOOT_WITH_MINIMAL_CONFIGURATION:\r
+    //\r
+    // In no-configuration boot mode, we can connect the\r
+    // console directly.\r
+    //\r
+    BdsLibConnectAllDefaultConsoles ();\r
+    PlatformBdsDiagnostics (IGNORE, TRUE);\r
+\r
+    //\r
+    // Perform some platform specific connect sequence\r
+    //\r
+    PlatformBdsConnectSequence ();\r
+\r
+    //\r
+    // Notes: current time out = 0 can not enter the\r
+    // front page\r
+    //\r
+    PlatformBdsEnterFrontPage (Timeout, FALSE);\r
+\r
+    //\r
+    // Check the boot option with the boot option list\r
+    //\r
+    BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");\r
+    break;\r
+\r
+  case BOOT_ON_FLASH_UPDATE:\r
+    //\r
+    // Boot with the specific configuration\r
+    //\r
+    PlatformBdsConnectConsole (gPlatformConsole);\r
+    PlatformBdsDiagnostics (EXTENSIVE, FALSE);\r
+    BdsLibConnectAll ();\r
+    ProcessCapsules (BOOT_ON_FLASH_UPDATE);\r
+    break;\r
+\r
+  case BOOT_IN_RECOVERY_MODE:\r
+    //\r
+    // In recovery mode, just connect platform console\r
+    // and show up the front page\r
+    //\r
+    PlatformBdsConnectConsole (gPlatformConsole);\r
+    PlatformBdsDiagnostics (EXTENSIVE, FALSE);\r
+\r
+    //\r
+    // In recovery boot mode, we still enter to the\r
+    // frong page now\r
+    //\r
+    PlatformBdsEnterFrontPage (Timeout, FALSE);\r
+    break;\r
+\r
+  case BOOT_WITH_FULL_CONFIGURATION:\r
+  case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:\r
+  case BOOT_WITH_DEFAULT_SETTINGS:\r
+  default:\r
+    //\r
+    // Connect platform console\r
+    //\r
+    Status = PlatformBdsConnectConsole (gPlatformConsole);\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Here OEM/IBV can customize with defined action\r
+      //\r
+      PlatformBdsNoConsoleAction ();\r
+    }\r
+\r
+    PlatformBdsDiagnostics (IGNORE, TRUE);\r
+\r
+    //\r
+    // Perform some platform specific connect sequence\r
+    //\r
+    PlatformBdsConnectSequence ();\r
+\r
+    //\r
+    // Give one chance to enter the setup if we\r
+    // have the time out\r
+    //\r
+    PlatformBdsEnterFrontPage (Timeout, FALSE);\r
+\r
+    //\r
+    // Here we have enough time to do the enumeration of boot device\r
+    //\r
+    BdsLibEnumerateAllBootOption (BootOptionList);\r
+    break;\r
+  }\r
+\r
+  return ;\r
+\r
+}\r
+\r
+VOID\r
+PlatformBdsBootSuccess (\r
+  IN  BDS_COMMON_OPTION   *Option\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  \r
+  Hook point after a boot attempt succeeds. We don't expect a boot option to\r
+  return, so the EFI 1.0 specification defines that you will default to an\r
+  interactive mode and stop processing the BootOrder list in this case. This\r
+  is alos a platform implementation and can be customized by IBV/OEM.\r
+\r
+Arguments:\r
+\r
+  Option - Pointer to Boot Option that succeeded to boot.\r
+\r
+Returns:\r
+  \r
+  None.\r
+\r
+--*/\r
+{\r
+  CHAR16  *TmpStr;\r
+\r
+  //\r
+  // If Boot returned with EFI_SUCCESS and there is not in the boot device\r
+  // select loop then we need to pop up a UI and wait for user input.\r
+  //\r
+  TmpStr = Option->StatusString;\r
+  if (TmpStr != NULL) {\r
+    BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r
+    FreePool (TmpStr);\r
+  }\r
+}\r
+\r
+VOID\r
+PlatformBdsBootFail (\r
+  IN  BDS_COMMON_OPTION  *Option,\r
+  IN  EFI_STATUS         Status,\r
+  IN  CHAR16             *ExitData,\r
+  IN  UINTN              ExitDataSize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  \r
+  Hook point after a boot attempt fails.\r
+\r
+Arguments:\r
+  \r
+  Option - Pointer to Boot Option that failed to boot.\r
+\r
+  Status - Status returned from failed boot.\r
+\r
+  ExitData - Exit data returned from failed boot.\r
+\r
+  ExitDataSize - Exit data size returned from failed boot.\r
+\r
+Returns:\r
+  \r
+  None.\r