]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add InOsEmuPkg. Like UnixPkg and Nt32Pkg, but EFI code can be common and does not...
authorandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 11 May 2011 18:31:20 +0000 (18:31 +0000)
committerandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 11 May 2011 18:31:20 +0000 (18:31 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11641 6f19259b-4bc3-4df7-8a09-765794883524

142 files changed:
InOsEmuPkg/AutoScanPei/AutoScanPei.c [new file with mode: 0644]
InOsEmuPkg/AutoScanPei/AutoScanPei.inf [new file with mode: 0644]
InOsEmuPkg/BootModePei/BootModePei.c [new file with mode: 0644]
InOsEmuPkg/BootModePei/BootModePei.inf [new file with mode: 0644]
InOsEmuPkg/CpuRuntimeDxe/Cpu.c [new file with mode: 0644]
InOsEmuPkg/CpuRuntimeDxe/Cpu.inf [new file with mode: 0644]
InOsEmuPkg/CpuRuntimeDxe/CpuDriver.h [new file with mode: 0644]
InOsEmuPkg/CpuRuntimeDxe/CpuIo.c [new file with mode: 0644]
InOsEmuPkg/CpuRuntimeDxe/Strings.uni [new file with mode: 0644]
InOsEmuPkg/EmuBusDriverDxe/ComponentName.c [new file with mode: 0644]
InOsEmuPkg/EmuBusDriverDxe/EmuBusDriverDxe.c [new file with mode: 0644]
InOsEmuPkg/EmuBusDriverDxe/EmuBusDriverDxe.h [new file with mode: 0644]
InOsEmuPkg/EmuBusDriverDxe/EmuBusDriverDxe.inf [new file with mode: 0644]
InOsEmuPkg/EmuGopDxe/ComponentName.c [new file with mode: 0644]
InOsEmuPkg/EmuGopDxe/EmuGopDxe.inf [new file with mode: 0644]
InOsEmuPkg/EmuGopDxe/Gop.h [new file with mode: 0644]
InOsEmuPkg/EmuGopDxe/GopDriver.c [new file with mode: 0644]
InOsEmuPkg/EmuGopDxe/GopInput.c [new file with mode: 0644]
InOsEmuPkg/EmuGopDxe/GopScreen.c [new file with mode: 0644]
InOsEmuPkg/EmuSimpleFileSystemDxe/ComponentName.c [new file with mode: 0644]
InOsEmuPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystem.c [new file with mode: 0644]
InOsEmuPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystem.h [new file with mode: 0644]
InOsEmuPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystemDxe.inf [new file with mode: 0644]
InOsEmuPkg/EmuThunkDxe/EmuThunk.c [new file with mode: 0644]
InOsEmuPkg/EmuThunkDxe/EmuThunk.inf [new file with mode: 0644]
InOsEmuPkg/FirmwareVolumePei/FirmwareVolumePei.c [new file with mode: 0644]
InOsEmuPkg/FirmwareVolumePei/FirmwareVolumePei.inf [new file with mode: 0644]
InOsEmuPkg/FlashMapPei/FlashMapPei.c [new file with mode: 0644]
InOsEmuPkg/FlashMapPei/FlashMapPei.inf [new file with mode: 0644]
InOsEmuPkg/FvbServicesRuntimeDxe/FWBlockService.c [new file with mode: 0644]
InOsEmuPkg/FvbServicesRuntimeDxe/FvbInfo.c [new file with mode: 0644]
InOsEmuPkg/FvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf [new file with mode: 0644]
InOsEmuPkg/FvbServicesRuntimeDxe/FwBlockService.h [new file with mode: 0644]
InOsEmuPkg/InOsEmuPkg.dec [new file with mode: 0644]
InOsEmuPkg/Include/Guid/EmuSystemConfig.h [new file with mode: 0644]
InOsEmuPkg/Include/Library/EmuThunkLib.h [new file with mode: 0644]
InOsEmuPkg/Include/Library/KeyMapLib.h [new file with mode: 0644]
InOsEmuPkg/Include/Library/ThunkPpiList.h [new file with mode: 0644]
InOsEmuPkg/Include/Library/ThunkProtocolList.h [new file with mode: 0644]
InOsEmuPkg/Include/Ppi/EmuPeiServicesTableUpdate.h [new file with mode: 0644]
InOsEmuPkg/Include/Ppi/EmuThunk.h [new file with mode: 0644]
InOsEmuPkg/Include/Protocol/EmuFileSystem.h [new file with mode: 0644]
InOsEmuPkg/Include/Protocol/EmuGraphicsWindow.h [new file with mode: 0644]
InOsEmuPkg/Include/Protocol/EmuIoThunk.h [new file with mode: 0644]
InOsEmuPkg/Include/Protocol/EmuPthreadThunk.h [new file with mode: 0644]
InOsEmuPkg/Include/Protocol/EmuThunk.h [new file with mode: 0644]
InOsEmuPkg/Library/DxeEmuLib/DxeEmuLib.c [new file with mode: 0644]
InOsEmuPkg/Library/DxeEmuLib/DxeEmuLib.inf [new file with mode: 0644]
InOsEmuPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.c [new file with mode: 0644]
InOsEmuPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.inf [new file with mode: 0644]
InOsEmuPkg/Library/DxeEmuSerialPortLib/DxeEmuSerialPortLib.c [new file with mode: 0644]
InOsEmuPkg/Library/DxeEmuSerialPortLib/DxeEmuSerialPortLib.inf [new file with mode: 0644]
InOsEmuPkg/Library/EmuBdsLib/BdsPlatform.c [new file with mode: 0644]
InOsEmuPkg/Library/EmuBdsLib/BdsPlatform.h [new file with mode: 0644]
InOsEmuPkg/Library/EmuBdsLib/EmuBdsLib.inf [new file with mode: 0644]
InOsEmuPkg/Library/EmuBdsLib/PlatformData.c [new file with mode: 0644]
InOsEmuPkg/Library/KeyMapLibNull/KeyMapLibNull.c [new file with mode: 0644]
InOsEmuPkg/Library/KeyMapLibNull/KeyMapLibNull.inf [new file with mode: 0644]
InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiCoreServicesTablePointerLib.inf [new file with mode: 0644]
InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiServicesTablePointer.c [new file with mode: 0644]
InOsEmuPkg/Library/PeiEmuPeCoffExtraActionLib/PeiEmuPeCoffExtraActionLib.c [new file with mode: 0644]
InOsEmuPkg/Library/PeiEmuPeCoffExtraActionLib/PeiEmuPeCoffExtraActionLib.inf [new file with mode: 0644]
InOsEmuPkg/Library/PeiEmuPeCoffGetEntryPointLib/PeiEmuPeCoffGetEntryPointLib.c [new file with mode: 0644]
InOsEmuPkg/Library/PeiEmuPeCoffGetEntryPointLib/PeiEmuPeCoffGetEntryPointLib.inf [new file with mode: 0644]
InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.c [new file with mode: 0644]
InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf [new file with mode: 0644]
InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointer.c [new file with mode: 0644]
InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf [new file with mode: 0644]
InOsEmuPkg/Library/ThunkPpiList/ThunkPpiList.c [new file with mode: 0644]
InOsEmuPkg/Library/ThunkPpiList/ThunkPpiList.inf [new file with mode: 0644]
InOsEmuPkg/Library/ThunkProtocolList/ThunkProtocolList.c [new file with mode: 0644]
InOsEmuPkg/Library/ThunkProtocolList/ThunkProtocolList.inf [new file with mode: 0644]
InOsEmuPkg/MetronomeDxe/Metronome.c [new file with mode: 0644]
InOsEmuPkg/MetronomeDxe/Metronome.h [new file with mode: 0644]
InOsEmuPkg/MetronomeDxe/Metronome.inf [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturer.uni [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerData.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerFunction.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscBiosVendor.uni [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscBiosVendorData.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscBiosVendorFunction.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscBootInformationData.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscBootInformationFunction.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscChassisManufacturer.uni [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscChassisManufacturerData.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscChassisManufacturerFunction.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscDevicePath.h [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscNumberOfInstallableLanguagesData.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscNumberOfInstallableLanguagesFunction.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscOemString.uni [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscOemStringData.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscOemStringFunction.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignator.uni [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorData.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorFunction.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscResetCapabilitiesData.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscResetCapabilitiesFunction.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.h [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.uni [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubclassDriverDataTable.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemLanguageString.uni [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemLanguageStringData.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemLanguageStringFunction.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemManufacturer.uni [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerData.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerFunction.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemOptionString.uni [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemOptionStringData.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemOptionStringFunction.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignation.uni [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignationData.c [new file with mode: 0644]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignationFunction.c [new file with mode: 0644]
InOsEmuPkg/RealTimeClockRuntimeDxe/RealTimeClock.c [new file with mode: 0644]
InOsEmuPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf [new file with mode: 0644]
InOsEmuPkg/ResetRuntimeDxe/Reset.c [new file with mode: 0644]
InOsEmuPkg/ResetRuntimeDxe/Reset.inf [new file with mode: 0644]
InOsEmuPkg/ThunkPpiToProtocolPei/ThunkPpiToProtocolPei.c [new file with mode: 0644]
InOsEmuPkg/ThunkPpiToProtocolPei/ThunkPpiToProtocolPei.inf [new file with mode: 0644]
InOsEmuPkg/TimerDxe/Timer.c [new file with mode: 0644]
InOsEmuPkg/TimerDxe/Timer.h [new file with mode: 0644]
InOsEmuPkg/TimerDxe/Timer.inf [new file with mode: 0644]
InOsEmuPkg/Unix/.gdbinit [new file with mode: 0644]
InOsEmuPkg/Unix/Sec/EmuThunk.c [new file with mode: 0644]
InOsEmuPkg/Unix/Sec/FwVol.c [new file with mode: 0644]
InOsEmuPkg/Unix/Sec/Gasket.h [new file with mode: 0644]
InOsEmuPkg/Unix/Sec/PosixFileSystem.c [new file with mode: 0644]
InOsEmuPkg/Unix/Sec/Pthreads.c [new file with mode: 0644]
InOsEmuPkg/Unix/Sec/SecMain.c [new file with mode: 0644]
InOsEmuPkg/Unix/Sec/SecMain.h [new file with mode: 0644]
InOsEmuPkg/Unix/Sec/SecMain.inf [new file with mode: 0644]
InOsEmuPkg/Unix/Sec/X11GraphicsWindow.c [new file with mode: 0644]
InOsEmuPkg/Unix/Sec/X64/Gasket.S [new file with mode: 0644]
InOsEmuPkg/Unix/Sec/X64/SwitchStack.S [new file with mode: 0644]
InOsEmuPkg/Unix/UnixX64.dsc [new file with mode: 0644]
InOsEmuPkg/Unix/UnixX64.fdf [new file with mode: 0644]
InOsEmuPkg/Unix/Xcode/xcode_project64/XcodeBuild.sh [new file with mode: 0755]
InOsEmuPkg/Unix/Xcode/xcode_project64/xcode_project.xcodeproj/default.pbxuser [new file with mode: 0644]
InOsEmuPkg/Unix/Xcode/xcode_project64/xcode_project.xcodeproj/project.pbxproj [new file with mode: 0644]
InOsEmuPkg/Unix/build64.sh [new file with mode: 0755]
InOsEmuPkg/build64.sh [new file with mode: 0755]

diff --git a/InOsEmuPkg/AutoScanPei/AutoScanPei.c b/InOsEmuPkg/AutoScanPei/AutoScanPei.c
new file mode 100644 (file)
index 0000000..78cdd34
--- /dev/null
@@ -0,0 +1,109 @@
+/*++ @file\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+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
+#include "PiPei.h"\r
+#include <Ppi/EmuThunk.h>\r
+#include <Ppi/MemoryDiscovered.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeimEntryPoint.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PeimInitializeAutoScanPei (\r
+  IN       EFI_PEI_FILE_HANDLE       FileHandle,\r
+  IN CONST EFI_PEI_SERVICES          **PeiServices\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Perform a call-back into the SEC simulator to get a memory value\r
+\r
+Arguments:\r
+  FfsHeader   - General purpose data available to every PEIM\r
+  PeiServices - General purpose services available to every PEIM.\r
+    \r
+Returns:\r
+  None\r
+\r
+**/\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_PEI_PPI_DESCRIPTOR      *PpiDescriptor;\r
+  EMU_THUNK_PPI               *Thunk;\r
+  UINT64                      MemorySize;\r
+  EFI_PHYSICAL_ADDRESS        MemoryBase;\r
+  UINTN                       Index;\r
+  EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;\r
+\r
+\r
+  DEBUG ((EFI_D_ERROR, "Emu Autoscan PEIM Loaded\n"));\r
+\r
+  //\r
+  // Get the PEI UNIX Autoscan PPI\r
+  //\r
+  Status = PeiServicesLocatePpi (\r
+             &gEmuThunkPpiGuid,      // GUID\r
+             0,                      // INSTANCE\r
+             &PpiDescriptor,         // EFI_PEI_PPI_DESCRIPTOR\r
+             (VOID **)&Thunk         // PPI\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Index = 0;\r
+  do {\r
+    Status = Thunk->MemoryAutoScan (Index, &MemoryBase, &MemorySize);\r
+    if (!EFI_ERROR (Status)) {\r
+      Attributes =\r
+        (\r
+          EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
+          EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
+          EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |\r
+          EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r
+          EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r
+          EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE\r
+        );\r
+\r
+      if (Index == 0) {\r
+        //\r
+        // Register the memory with the PEI Core\r
+        //\r
+        Status = PeiServicesInstallPeiMemory (MemoryBase, MemorySize);\r
+        ASSERT_EFI_ERROR (Status);\r
+\r
+        Attributes |= EFI_RESOURCE_ATTRIBUTE_TESTED;\r
+      }\r
+      \r
+      BuildResourceDescriptorHob (\r
+        EFI_RESOURCE_SYSTEM_MEMORY,\r
+        Attributes,\r
+        MemoryBase,\r
+        MemorySize\r
+        );\r
+    }\r
+    Index++;\r
+  } while (!EFI_ERROR (Status));\r
+\r
+  //\r
+  // Build the CPU hob with 36-bit addressing and 16-bits of IO space.\r
+  //\r
+  BuildCpuHob (36, 16);\r
+  \r
+  return Status;\r
+}\r
diff --git a/InOsEmuPkg/AutoScanPei/AutoScanPei.inf b/InOsEmuPkg/AutoScanPei/AutoScanPei.inf
new file mode 100644 (file)
index 0000000..b8692ca
--- /dev/null
@@ -0,0 +1,58 @@
+## @file\r
+# Component description file for EmuAutoScan module\r
+#\r
+# This module abstracts memory auto-scan in a Emu environment.\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = AutoScanPei\r
+  FILE_GUID                      = 2D6F6BCC-9681-8E42-8579-B57DCD0060F0\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = PeimInitializeAutoScanPei\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]\r
+  AutoScanPei.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+#  MdeModulePkg/MdeModulePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+  PeiServicesTablePointerLib\r
+  PeiServicesLib\r
+  HobLib\r
+  BaseMemoryLib\r
+  BaseLib\r
+  PeimEntryPoint\r
+  DebugLib\r
+\r
+\r
+[Ppis]\r
+  gEfiPeiMemoryDiscoveredPpiGuid                # PPI ALWAYS_PRODUCED\r
+  gEmuThunkPpiGuid                              # PPI ALWAYS_CONSUMED\r
+\r
+\r
+[Depex]\r
+  gEmuThunkPpiGuid AND gEfiPeiMasterBootModePpiGuid\r
+\r
diff --git a/InOsEmuPkg/BootModePei/BootModePei.c b/InOsEmuPkg/BootModePei/BootModePei.c
new file mode 100644 (file)
index 0000000..e26e929
--- /dev/null
@@ -0,0 +1,94 @@
+/** @file\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+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
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiPei.h>\r
+\r
+#include <Library/PcdLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+\r
+\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_PEI_FILE_HANDLE       FileHandle,\r
+  IN CONST 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
+{\r
+  EFI_STATUS    Status;\r
+  EFI_BOOT_MODE BootMode;\r
+\r
+  DEBUG ((EFI_D_ERROR, "Emu Boot Mode PEIM Loaded\n"));\r
+\r
+  BootMode  = FixedPcdGet32 (PcdEmuBootMode);\r
+\r
+  Status    = PeiServicesSetBootMode (BootMode);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = PeiServicesInstallPpi (&mPpiListBootMode);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  if (BootMode == BOOT_IN_RECOVERY_MODE) {\r
+    Status = PeiServicesInstallPpi (&mPpiListRecoveryBootMode);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
+  return Status;\r
+}\r
diff --git a/InOsEmuPkg/BootModePei/BootModePei.inf b/InOsEmuPkg/BootModePei/BootModePei.inf
new file mode 100644 (file)
index 0000000..d162552
--- /dev/null
@@ -0,0 +1,59 @@
+## @file\r
+# Component description file for BootMode module\r
+#\r
+# This module provides platform specific function to detect boot mode.\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = 64196C76-58E3-0B4D-9484-B54F7C4349CA\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\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]\r
+  BootModePei.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.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
+[FixedPcd]\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuBootMode\r
+\r
+[Depex]\r
+  TRUE\r
+\r
diff --git a/InOsEmuPkg/CpuRuntimeDxe/Cpu.c b/InOsEmuPkg/CpuRuntimeDxe/Cpu.c
new file mode 100644 (file)
index 0000000..2b1e1d1
--- /dev/null
@@ -0,0 +1,339 @@
+/*++ @file\r
+  Emu driver to produce CPU Architectural Protocol.\r
+  \r
+Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+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
+#include "CpuDriver.h"\r
+\r
+UINT64  mTimerPeriod;\r
+\r
+CPU_ARCH_PROTOCOL_PRIVATE mCpuTemplate = {\r
+  CPU_ARCH_PROT_PRIVATE_SIGNATURE,\r
+  NULL,\r
+  {\r
+    EmuFlushCpuDataCache,\r
+    EmuEnableInterrupt,\r
+    EmuDisableInterrupt,\r
+    EmuGetInterruptState,\r
+    EmuInit,\r
+    EmuRegisterInterruptHandler,\r
+    EmuGetTimerValue,\r
+    EmuSetMemoryAttributes,\r
+    0,\r
+    4\r
+  },\r
+  {\r
+    {\r
+      CpuMemoryServiceRead,\r
+      CpuMemoryServiceWrite\r
+    },\r
+    {\r
+      CpuIoServiceRead,\r
+      CpuIoServiceWrite\r
+    }\r
+  },\r
+  TRUE\r
+};\r
+\r
+#define EFI_CPU_DATA_MAXIMUM_LENGTH 0x100\r
+\r
+\r
+\r
+//\r
+// Service routines for the driver\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+EmuFlushCpuDataCache (\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
+  if (FlushType == EfiCpuFlushTypeWriteBackInvalidate) {\r
+    //\r
+    // Only WB flush is supported. We actually need do nothing on Emu emulator\r
+    // environment. Classify this to follow EFI spec\r
+    //\r
+    return EFI_SUCCESS;\r
+  }\r
+  //\r
+  // Other flush types are not supported by Emu emulator\r
+  //\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuEnableInterrupt (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This\r
+  )\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  Private                 = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  Private->InterruptState = TRUE;\r
+  gEmuThunk->EnableInterrupt ();\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuDisableInterrupt (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This\r
+  )\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  Private                 = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  Private->InterruptState = FALSE;\r
+  gEmuThunk->DisableInterrupt ();\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuGetInterruptState (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  OUT BOOLEAN               *State\r
+  )\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
+EmuInit (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_CPU_INIT_TYPE      InitType\r
+  )\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
+EmuRegisterInterruptHandler (\r
+  IN EFI_CPU_ARCH_PROTOCOL      *This,\r
+  IN EFI_EXCEPTION_TYPE         InterruptType,\r
+  IN EFI_CPU_INTERRUPT_HANDLER  InterruptHandler\r
+  )\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 Emu emulation\r
+  //\r
+  Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuGetTimerValue (\r
+  IN  EFI_CPU_ARCH_PROTOCOL *This,\r
+  IN  UINT32                TimerIndex,\r
+  OUT UINT64                *TimerValue,\r
+  OUT UINT64                *TimerPeriod OPTIONAL\r
+  )\r
+{\r
+  if (TimerValue == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (TimerIndex != 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  *TimerValue = gEmuThunk->QueryPerformanceCounter ();\r
+  \r
+  if (TimerPeriod != NULL) {\r
+    *TimerPeriod = mTimerPeriod;\r
+  } \r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSetMemoryAttributes (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_PHYSICAL_ADDRESS   BaseAddress,\r
+  IN UINT64                 Length,\r
+  IN UINT64                 Attributes\r
+  )\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
+\r
+\r
+/**\r
+  Logs SMBIOS record.\r
+\r
+  @param  Smbios   Pointer to SMBIOS protocol instance.\r
+  @param  Buffer   Pointer to the data buffer.\r
+\r
+**/\r
+VOID\r
+LogSmbiosData (\r
+  IN  EFI_SMBIOS_PROTOCOL        *Smbios,\r
+  IN  UINT8                      *Buffer\r
+  )\r
+{\r
+  EFI_STATUS         Status;\r
+  EFI_SMBIOS_HANDLE  SmbiosHandle;\r
+  \r
+  SmbiosHandle = 0;\r
+  Status = Smbios->Add (\r
+                     Smbios,\r
+                     NULL,\r
+                     &SmbiosHandle,\r
+                     (EFI_SMBIOS_TABLE_HEADER*)Buffer\r
+                     );\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+VOID\r
+CpuUpdateSmbios (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  UINT32                      TotalSize;\r
+  EFI_SMBIOS_PROTOCOL         *Smbios;\r
+  EFI_HII_HANDLE              HiiHandle;\r
+  STRING_REF                  Token;\r
+  UINTN                       CpuVerStrLen;\r
+  EFI_STRING                  CpuVerStr;\r
+  SMBIOS_TABLE_TYPE4          *SmbiosRecord;\r
+  CHAR8                       *OptionalStrStart;\r
+\r
+  //\r
+  // Locate Smbios protocol.\r
+  //\r
+  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&Smbios);\r
+  \r
+  if (EFI_ERROR (Status)) {\r
+    return;\r
+  }\r
+\r
+  //\r
+  // Initialize strings to HII database\r
+  //\r
+  HiiHandle = HiiAddPackages (\r
+                &gEfiCallerIdGuid,\r
+                NULL,\r
+                CpuStrings,\r
+                NULL\r
+                );\r
+  ASSERT (HiiHandle != NULL);\r
+\r
+  Token  = STRING_TOKEN (STR_PROCESSOR_VERSION);\r
+  CpuVerStr = HiiGetPackageString(&gEfiCallerIdGuid, Token, NULL);\r
+  CpuVerStrLen = StrLen(CpuVerStr);\r
+  ASSERT (CpuVerStrLen <= SMBIOS_STRING_MAX_LENGTH);\r
+\r
+  TotalSize = sizeof(SMBIOS_TABLE_TYPE4) + CpuVerStrLen + 1 + 1;\r
+  SmbiosRecord = AllocatePool(TotalSize);\r
+  ZeroMem(SmbiosRecord, TotalSize);\r
+\r
+  SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION;\r
+  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE4);\r
+  //\r
+  // Make handle chosen by smbios protocol.add automatically.\r
+  //\r
+  SmbiosRecord->Hdr.Handle = 0;  \r
+  //\r
+  // Processor version is the 1st string.\r
+  //\r
+  SmbiosRecord->ProcessorVersion = 1;\r
+  //\r
+  // Store CPU frequency data record to data hub - It's an emulator so make up a value\r
+  //\r
+  SmbiosRecord->CurrentSpeed  = 1234;\r
+\r
+  OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);\r
+  UnicodeStrToAsciiStr(CpuVerStr, OptionalStrStart);\r
+\r
+  //\r
+  // Now we have got the full smbios record, call smbios protocol to add this record.\r
+  //\r
+  LogSmbiosData(Smbios, (UINT8 *) SmbiosRecord);\r
+  FreePool (SmbiosRecord);\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    Status;\r
+  UINT64        Frequency;\r
+\r
+  //\r
+  // Retrieve the frequency of the performance counter in Hz.\r
+  //  \r
+  Frequency = gEmuThunk->QueryPerformanceFrequency ();\r
+  \r
+  //\r
+  // Convert frequency in Hz to a clock period in femtoseconds.\r
+  //\r
+  mTimerPeriod = DivU64x64Remainder (1000000000000000, Frequency, NULL);\r
+\r
+  CpuUpdateSmbios ();\r
+\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &mCpuTemplate.Handle,\r
+                  &gEfiCpuArchProtocolGuid,   &mCpuTemplate.Cpu,\r
+                  &gEfiCpuIo2ProtocolGuid,    &mCpuTemplate.CpuIo,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
diff --git a/InOsEmuPkg/CpuRuntimeDxe/Cpu.inf b/InOsEmuPkg/CpuRuntimeDxe/Cpu.inf
new file mode 100644 (file)
index 0000000..44e651f
--- /dev/null
@@ -0,0 +1,65 @@
+## @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 - 2010, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions 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
+\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]\r
+  CpuIo.c\r
+  Cpu.c\r
+  CpuDriver.h\r
+  Strings.uni\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  HiiLib\r
+  DebugLib\r
+  BaseLib\r
+  EmuThunkLib\r
+\r
+[Protocols]\r
+  gEmuIoThunkProtocolGuid                       # PROTOCOL_NOTIFY SOMETIMES_CONSUMED\r
+  gEfiSmbiosProtocolGuid                        # PROTOCOL SOMETIMES_CONSUMED\r
+  gEfiHiiProtocolGuid                           # PROTOCOL SOMETIMES_CONSUMED\r
+  gEfiCpuIo2ProtocolGuid                        # PROTOCOL ALWAYS_PRODUCED\r
+  gEfiCpuArchProtocolGuid                       # PROTOCOL ALWAYS_PRODUCED\r
+\r
+[Depex]\r
+  gEfiSmbiosProtocolGuid\r
diff --git a/InOsEmuPkg/CpuRuntimeDxe/CpuDriver.h b/InOsEmuPkg/CpuRuntimeDxe/CpuDriver.h
new file mode 100644 (file)
index 0000000..a836f63
--- /dev/null
@@ -0,0 +1,172 @@
+/*++ @file\r
+\r
+Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+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
+#ifndef _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_\r
+#define _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_\r
+\r
+\r
+#include <FrameworkDxe.h>\r
+#include <IndustryStandard/SmBios.h>\r
+#include <Protocol/Cpu.h>\r
+#include <Protocol/Smbios.h>\r
+#include <Protocol/FrameworkHii.h>\r
+#include <Guid/DataHubRecords.h>\r
+#include <Protocol/CpuIo2.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HiiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/EmuThunkLib.h>\r
+\r
+\r
+extern UINT8  CpuStrings[];\r
+\r
+//\r
+// Internal Data Structures\r
+//\r
+#define CPU_ARCH_PROT_PRIVATE_SIGNATURE 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_IO2_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_IO2_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_IO2_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_IO2_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_IO2_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
+EmuFlushCpuDataCache (\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
+EmuEnableInterrupt (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuDisableInterrupt (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuGetInterruptState (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  OUT BOOLEAN               *State\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuInit (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_CPU_INIT_TYPE      InitType\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuRegisterInterruptHandler (\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
+EmuGetTimerValue (\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
+EmuSetMemoryAttributes (\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/InOsEmuPkg/CpuRuntimeDxe/CpuIo.c b/InOsEmuPkg/CpuRuntimeDxe/CpuIo.c
new file mode 100644 (file)
index 0000000..6f63375
--- /dev/null
@@ -0,0 +1,333 @@
+/*++ @file\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
+Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+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
+#include <FrameworkDxe.h>\r
+#include <Protocol/Cpu.h>\r
+#include <Protocol/DataHub.h>\r
+#include <Guid/DataHubRecords.h>\r
+#include <Protocol/CpuIo2.h>\r
+#include <Protocol/FrameworkHii.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_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_IO2_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
+{\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_IO2_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
+{\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_IO2_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
+{\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_IO2_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
+{\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
+/*++\r
+\r
+Routine 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
+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
+  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/InOsEmuPkg/CpuRuntimeDxe/Strings.uni b/InOsEmuPkg/CpuRuntimeDxe/Strings.uni
new file mode 100644 (file)
index 0000000..4f8d41e
Binary files /dev/null and b/InOsEmuPkg/CpuRuntimeDxe/Strings.uni differ
diff --git a/InOsEmuPkg/EmuBusDriverDxe/ComponentName.c b/InOsEmuPkg/EmuBusDriverDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..e8be214
--- /dev/null
@@ -0,0 +1,247 @@
+/** @file\r
+\r
+Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+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
+**/\r
+\r
+#include "EmuBusDriverDxe.h"\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBusDriverComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBusDriverComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  );\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL     gEmuBusDriverComponentName = {\r
+  EmuBusDriverComponentNameGetDriverName,\r
+  EmuBusDriverComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+//\r
+// EFI Component Name 2 Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEmuBusDriverComponentName2 = {\r
+  (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) EmuBusDriverComponentNameGetDriverName,\r
+  (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) EmuBusDriverComponentNameGetControllerName,\r
+  "en"\r
+};\r
+\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mEmuBusDriverNameTable[] = {\r
+  { "eng", L"Emu Bus Driver" },\r
+  { NULL , NULL }\r
+};\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the driver.\r
+\r
+  This function retrieves the user readable name of a driver in the form of a\r
+  Unicode string. If the driver specified by This has a user readable name in\r
+  the language specified by Language, then a pointer to the driver name is\r
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
+  by This does not support the language specified by Language,\r
+  then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language. This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified\r
+                                in RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  DriverName[out]       A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                driver specified by This in the language\r
+                                specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
+                                This and the language specified by Language was\r
+                                returned in DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBusDriverComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+{\r
+  return LookupUnicodeString2 (\r
+          Language,\r
+          This->SupportedLanguages,\r
+          mEmuBusDriverNameTable,\r
+          DriverName,\r
+          (BOOLEAN)(This == &gEmuBusDriverComponentName)\r
+          );\r
+}\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by a driver.\r
+\r
+  This function retrieves the user readable name of the controller specified by\r
+  ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
+  driver specified by This has a user readable name in the language specified by\r
+  Language, then a pointer to the controller name is returned in ControllerName,\r
+  and EFI_SUCCESS is returned.  If the driver specified by This is not currently\r
+  managing the controller specified by ControllerHandle and ChildHandle,\r
+  then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
+  support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  ControllerHandle[in]  The handle of a controller that the driver\r
+                                specified by This is managing.  This handle\r
+                                specifies the controller whose name is to be\r
+                                returned.\r
+\r
+  @param  ChildHandle[in]       The handle of the child controller to retrieve\r
+                                the name of.  This is an optional parameter that\r
+                                may be NULL.  It will be NULL for device\r
+                                drivers.  It will also be NULL for a bus drivers\r
+                                that wish to retrieve the name of the bus\r
+                                controller.  It will not be NULL for a bus\r
+                                driver that wishes to retrieve the name of a\r
+                                child controller.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language.  This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified in\r
+                                RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  ControllerName[out]   A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                controller specified by ControllerHandle and\r
+                                ChildHandle in the language specified by\r
+                                Language from the point of view of the driver\r
+                                specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name in\r
+                                the language specified by Language for the\r
+                                driver specified by This was returned in\r
+                                DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+                                EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
+                                managing the controller specified by\r
+                                ControllerHandle and ChildHandle.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBusDriverComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_IO_THUNK_PROTOCOL   *EmuIo;\r
+  EMU_IO_DEVICE           *Private;\r
+\r
+  //\r
+  // Make sure this driver is currently managing ControllHandle\r
+  //\r
+  Status = EfiTestManagedDevice (\r
+             ControllerHandle,\r
+             gEmuBusDriverBinding.DriverBindingHandle,\r
+             &gEmuThunkProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // This is a bus driver, so ChildHandle can not be NULL.\r
+  //\r
+  if (ChildHandle == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = EfiTestChildHandle (\r
+             ControllerHandle,\r
+             ChildHandle,\r
+             &gEmuThunkProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ChildHandle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (VOID**)&EmuIo,\r
+                  gEmuBusDriverBinding.DriverBindingHandle,\r
+                  ChildHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = EMU_IO_DEVICE_FROM_THIS (EmuIo);\r
+\r
+  return LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           Private->ControllerNameTable,\r
+           ControllerName,\r
+           (BOOLEAN)(This == &gEmuBusDriverComponentName)\r
+          );\r
+}\r
diff --git a/InOsEmuPkg/EmuBusDriverDxe/EmuBusDriverDxe.c b/InOsEmuPkg/EmuBusDriverDxe/EmuBusDriverDxe.c
new file mode 100644 (file)
index 0000000..b76236f
--- /dev/null
@@ -0,0 +1,537 @@
+/** @file\r
+ Emu Bus driver\r
\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+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
+#include "EmuBusDriverDxe.h"\r
+\r
+\r
+\r
+//\r
+// DriverBinding protocol global\r
+//\r
+EFI_DRIVER_BINDING_PROTOCOL           gEmuBusDriverBinding = {\r
+  EmuBusDriverBindingSupported,\r
+  EmuBusDriverBindingStart,\r
+  EmuBusDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBusDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
+  EMU_THUNK_PROTOCOL        *EmuThunk;\r
+  UINTN                     Index;\r
+\r
+  //\r
+  // Check the contents of the first Device Path Node of RemainingDevicePath to make sure\r
+  // it is a legal Device Path Node for this bus driver's children.\r
+  //\r
+  if (RemainingDevicePath != NULL) {\r
+    //\r
+    // Check if RemainingDevicePath is the End of Device Path Node, \r
+    // if yes, go on checking other conditions\r
+    //\r
+    if (!IsDevicePathEnd (RemainingDevicePath)) {\r
+      //\r
+      // If RemainingDevicePath isn't the End of Device Path Node,\r
+      // check its validation\r
+      //\r
+      if (RemainingDevicePath->Type != HARDWARE_DEVICE_PATH ||\r
+          RemainingDevicePath->SubType != HW_VENDOR_DP ||\r
+          DevicePathNodeLength(RemainingDevicePath) != sizeof(EMU_VENDOR_DEVICE_PATH_NODE)) {\r
+        return EFI_UNSUPPORTED;\r
+      }\r
+    }\r
+  }\r
+  \r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEmuThunkProtocolGuid,\r
+                  (VOID **)&EmuThunk   ,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (Status == EFI_ALREADY_STARTED) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        &gEmuThunkProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        ControllerHandle\r
+        );\r
+\r
+  //\r
+  // Open the EFI Device Path protocol needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **)&ParentDevicePath,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (Status == EFI_ALREADY_STARTED) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+\r
+  //\r
+  // Close protocol, don't use device path protocol in the Support() function\r
+  //\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        &gEfiDevicePathProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        ControllerHandle\r
+        );\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBusDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+  EFI_STATUS                      InstallStatus;\r
+  EMU_THUNK_PROTOCOL              *EmuThunk;\r
+  EFI_DEVICE_PATH_PROTOCOL        *ParentDevicePath;\r
+  EMU_IO_DEVICE                   *EmuDevice;\r
+  EMU_BUS_DEVICE                  *EmuBusDevice;\r
+  EMU_IO_THUNK_PROTOCOL           *EmuIoThunk;\r
+  UINTN                           Index;\r
+  CHAR16                          *StartString;\r
+  CHAR16                          *SubString;\r
+  UINTN                           StringSize;\r
+  UINT16                          ComponentName[512];\r
+  EMU_VENDOR_DEVICE_PATH_NODE     *Node;\r
+  BOOLEAN                         CreateDevice;\r
+  CHAR16                          *TempStr;\r
+  CHAR16                          *PcdTempStr;\r
+  UINTN                           TempStrSize;\r
+\r
+\r
+  Status = EFI_UNSUPPORTED;\r
+\r
+  //\r
+  // Grab the protocols we need\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **)&ParentDevicePath,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
+    return Status;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEmuThunkProtocolGuid,\r
+                  (VOID **)&EmuThunk,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
+    return Status;\r
+  }\r
+\r
+  if (Status != EFI_ALREADY_STARTED) {\r
+    EmuBusDevice = AllocatePool (sizeof (EMU_BUS_DEVICE));\r
+    if (EmuBusDevice == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
+    EmuBusDevice->Signature           = EMU_BUS_DEVICE_SIGNATURE;\r
+    EmuBusDevice->ControllerNameTable = NULL;\r
+\r
+    AddUnicodeString2 (\r
+      "eng",\r
+      gEmuBusDriverComponentName.SupportedLanguages,\r
+      &EmuBusDevice->ControllerNameTable,\r
+      L"InOsEmu Bus Controller",\r
+      TRUE\r
+      );\r
+    AddUnicodeString2 (\r
+      "en",\r
+      gEmuBusDriverComponentName2.SupportedLanguages,\r
+      &EmuBusDevice->ControllerNameTable,\r
+      L"InOsEmu Bus Controller",\r
+      FALSE\r
+      );\r
+\r
+\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &ControllerHandle,\r
+                    &gEfiCallerIdGuid, EmuBusDevice,\r
+                    NULL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      FreeUnicodeStringTable (EmuBusDevice->ControllerNameTable);\r
+      gBS->FreePool (EmuBusDevice);\r
+      return Status;\r
+    }\r
+  }\r
+\r
+\r
+  for (Status = EFI_SUCCESS, EmuIoThunk = NULL; !EFI_ERROR (Status); ) {\r
+    Status = EmuThunk->GetNextProtocol (TRUE, &EmuIoThunk);\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
+    }\r
+\r
+    CreateDevice = TRUE;\r
+    if (RemainingDevicePath != NULL) {\r
+      CreateDevice  = FALSE;\r
+      //\r
+      // Check if RemainingDevicePath is the End of Device Path Node, \r
+      // if yes, don't create any child device \r
+      //\r
+      if (!IsDevicePathEnd (RemainingDevicePath)) {\r
+        //\r
+        // If RemainingDevicePath isn't the End of Device Path Node,\r
+        // check its validation\r
+        //\r
+        Node          = (EMU_VENDOR_DEVICE_PATH_NODE *) RemainingDevicePath;\r
+        if (Node->VendorDevicePath.Header.Type == HARDWARE_DEVICE_PATH &&\r
+            Node->VendorDevicePath.Header.SubType == HW_VENDOR_DP &&\r
+            DevicePathNodeLength (&Node->VendorDevicePath.Header) == sizeof (EMU_VENDOR_DEVICE_PATH_NODE)\r
+            ) {\r
+          if (CompareGuid (&Node->VendorDevicePath.Guid, EmuIoThunk->Protocol) && Node->Instance == EmuIoThunk->Instance) {\r
+            CreateDevice = TRUE;\r
+          }\r
+        }\r
+      }\r
+    }\r
+\r
+    if (CreateDevice) {\r
+      //\r
+      // Allocate instance structure, and fill in parent information.\r
+      //\r
+      EmuDevice = AllocatePool (sizeof (EMU_IO_DEVICE));\r
+      if (EmuDevice == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+\r
+      EmuDevice->Handle             = NULL;\r
+      EmuDevice->ControllerHandle   = ControllerHandle;\r
+      EmuDevice->ParentDevicePath   = ParentDevicePath;\r
+      CopyMem (&EmuDevice->EmuIoThunk, EmuIoThunk, sizeof (EMU_IO_THUNK_PROTOCOL));\r
+      \r
+      EmuDevice->ControllerNameTable = NULL;\r
+\r
+      StrnCpy (ComponentName, EmuIoThunk->ConfigString, sizeof (ComponentName)/sizeof (CHAR16));\r
+\r
+      EmuDevice->DevicePath = EmuBusCreateDevicePath (\r
+                                  ParentDevicePath,\r
+                                  EmuIoThunk->Protocol,\r
+                                  EmuIoThunk->Instance\r
+                                  );\r
+      if (EmuDevice->DevicePath == NULL) {\r
+        gBS->FreePool (EmuDevice);\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+\r
+      AddUnicodeString (\r
+        "eng",\r
+        gEmuBusDriverComponentName.SupportedLanguages,\r
+        &EmuDevice->ControllerNameTable,\r
+        ComponentName\r
+        );\r
+\r
+      EmuDevice->Signature = EMU_IO_DEVICE_SIGNATURE;\r
+\r
+      InstallStatus = gBS->InstallMultipleProtocolInterfaces (\r
+                            &EmuDevice->Handle,\r
+                            &gEfiDevicePathProtocolGuid,  EmuDevice->DevicePath,\r
+                            &gEmuIoThunkProtocolGuid,     &EmuDevice->EmuIoThunk,\r
+                            NULL\r
+                            );\r
+      if (EFI_ERROR (InstallStatus)) {\r
+        FreeUnicodeStringTable (EmuDevice->ControllerNameTable);\r
+        gBS->FreePool (EmuDevice);\r
+      } else {\r
+        //\r
+        // Open For Child Device\r
+        //\r
+        Status = gBS->OpenProtocol (\r
+                        ControllerHandle,\r
+                        &gEmuThunkProtocolGuid,\r
+                        (VOID **)&EmuThunk   ,\r
+                        This->DriverBindingHandle,\r
+                        EmuDevice->Handle,\r
+                        EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+                        );\r
+        if (!EFI_ERROR (Status)) {\r
+          InstallStatus = EFI_SUCCESS;\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  return InstallStatus;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBusDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  UINTN                     Index;\r
+  BOOLEAN                   AllChildrenStopped;\r
+  EMU_IO_THUNK_PROTOCOL     *EmuIoThunk;\r
+  EMU_BUS_DEVICE            *EmuBusDevice;\r
+  EMU_IO_DEVICE             *EmuDevice;\r
+  EMU_THUNK_PROTOCOL        *EmuThunk;\r
+\r
+  //\r
+  // Complete all outstanding transactions to Controller.\r
+  // Don't allow any new transaction to Controller to be started.\r
+  //\r
+\r
+  if (NumberOfChildren == 0) {\r
+    //\r
+    // Close the bus driver\r
+    //\r
+    Status = gBS->OpenProtocol (\r
+                    ControllerHandle,\r
+                    &gEfiCallerIdGuid,\r
+                    (VOID **)&EmuBusDevice,\r
+                    This->DriverBindingHandle,\r
+                    ControllerHandle,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    gBS->UninstallMultipleProtocolInterfaces (\r
+          ControllerHandle,\r
+          &gEfiCallerIdGuid,  EmuBusDevice,\r
+          NULL\r
+          );\r
+\r
+    FreeUnicodeStringTable (EmuBusDevice->ControllerNameTable);\r
+\r
+    gBS->FreePool (EmuBusDevice);\r
+\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEmuThunkProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiDevicePathProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  AllChildrenStopped = TRUE;\r
+\r
+  for (Index = 0; Index < NumberOfChildren; Index++) {\r
+\r
+    Status = gBS->OpenProtocol (\r
+                    ChildHandleBuffer[Index],\r
+                    &gEmuIoThunkProtocolGuid,\r
+                    (VOID **)&EmuIoThunk,\r
+                    This->DriverBindingHandle,\r
+                    ControllerHandle,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+      EmuDevice = EMU_IO_DEVICE_FROM_THIS (EmuIoThunk);\r
+\r
+      Status = gBS->CloseProtocol (\r
+                      ControllerHandle,\r
+                      &gEmuThunkProtocolGuid,\r
+                      This->DriverBindingHandle,\r
+                      EmuDevice->Handle\r
+                      );\r
+\r
+      Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                      EmuDevice->Handle,\r
+                      &gEfiDevicePathProtocolGuid,  EmuDevice->DevicePath,\r
+                      &gEmuIoThunkProtocolGuid,     EmuDevice->EmuIoThunk,\r
+                      NULL\r
+                      );\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        gBS->OpenProtocol (\r
+              ControllerHandle,\r
+              &gEmuThunkProtocolGuid,\r
+              (VOID **) &EmuThunk   ,\r
+              This->DriverBindingHandle,\r
+              EmuDevice->Handle,\r
+              EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+              );\r
+      } else {\r
+        //\r
+        // Close the child handle\r
+        //\r
+        FreeUnicodeStringTable (EmuDevice->ControllerNameTable);\r
+        FreePool (EmuDevice);\r
+      }\r
+    }\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      AllChildrenStopped = FALSE;\r
+    }\r
+  }\r
+\r
+  if (!AllChildrenStopped) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/*++\r
+\r
+Routine Description:\r
+  Create a device path node using Guid and InstanceNumber and append it to\r
+  the passed in RootDevicePath\r
+\r
+Arguments:\r
+  RootDevicePath - Root of the device path to return.\r
+\r
+  Guid           - GUID to use in vendor device path node.\r
+\r
+  InstanceNumber - Instance number to use in the vendor device path. This\r
+                    argument is needed to make sure each device path is unique.\r
+\r
+Returns:\r
+\r
+  EFI_DEVICE_PATH_PROTOCOL \r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EmuBusCreateDevicePath (\r
+  IN  EFI_DEVICE_PATH_PROTOCOL  *RootDevicePath,\r
+  IN  EFI_GUID                  *Guid,\r
+  IN  UINT16                    InstanceNumber\r
+  )\r
+{\r
+  EMU_VENDOR_DEVICE_PATH_NODE  DevicePath;\r
+\r
+  DevicePath.VendorDevicePath.Header.Type     = HARDWARE_DEVICE_PATH;\r
+  DevicePath.VendorDevicePath.Header.SubType  = HW_VENDOR_DP;\r
+  SetDevicePathNodeLength (&DevicePath.VendorDevicePath.Header, sizeof (EMU_VENDOR_DEVICE_PATH_NODE));\r
+\r
+  //\r
+  // The GUID defines the Class\r
+  //\r
+  CopyMem (&DevicePath.VendorDevicePath.Guid, Guid, sizeof (EFI_GUID));\r
+\r
+  //\r
+  // Add an instance number so we can make sure there are no Device Path\r
+  // duplication.\r
+  //\r
+  DevicePath.Instance = InstanceNumber;\r
+\r
+  return AppendDevicePathNode (\r
+          RootDevicePath,\r
+          (EFI_DEVICE_PATH_PROTOCOL *) &DevicePath\r
+          );\r
+}\r
+\r
+\r
+\r
+/**\r
+  The user Entry Point for module EmuBusDriver. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeEmuBusDriver (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gEmuBusDriverBinding,\r
+             ImageHandle,\r
+             &gEmuBusDriverComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+\r
+\r
diff --git a/InOsEmuPkg/EmuBusDriverDxe/EmuBusDriverDxe.h b/InOsEmuPkg/EmuBusDriverDxe/EmuBusDriverDxe.h
new file mode 100644 (file)
index 0000000..e5eee56
--- /dev/null
@@ -0,0 +1,116 @@
+/*++ @file\r
+\r
+Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+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
+#ifndef __EMU_BUS_DRIVER_H__\r
+#define __EMU_BUS_DRIVER_H__\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Protocol/DevicePath.h>\r
+#include <Protocol/EmuThunk.h>\r
+#include <Protocol/EmuIoThunk.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DevicePathLib.h>\r
+\r
+extern EFI_DRIVER_BINDING_PROTOCOL  gEmuBusDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gEmuBusDriverComponentName;\r
+extern EFI_COMPONENT_NAME2_PROTOCOL gEmuBusDriverComponentName2;\r
+\r
+\r
+//\r
+// Unix Bus Controller Structure\r
+//\r
+#define EMU_BUS_DEVICE_SIGNATURE SIGNATURE_32 ('L', 'X', 'B', 'D')\r
+\r
+typedef struct {\r
+  UINT64                    Signature;\r
+  EFI_UNICODE_STRING_TABLE  *ControllerNameTable;\r
+} EMU_BUS_DEVICE;\r
+\r
+//\r
+// Unix Child Device Controller Structure\r
+//\r
+#define EMU_IO_DEVICE_SIGNATURE  SIGNATURE_32 ('L', 'X', 'V', 'D')\r
+\r
+typedef struct {\r
+  UINT64                    Signature;\r
+  EFI_HANDLE                Handle;\r
+  EMU_IO_THUNK_PROTOCOL     EmuIoThunk;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+\r
+  //\r
+  // Private data about the parent\r
+  //\r
+  EFI_HANDLE                ControllerHandle;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
+\r
+  EFI_UNICODE_STRING_TABLE  *ControllerNameTable;\r
+\r
+} EMU_IO_DEVICE;\r
+\r
+#define EMU_IO_DEVICE_FROM_THIS(a) \\r
+  CR(a, EMU_IO_DEVICE, EmuIoThunk, EMU_IO_DEVICE_SIGNATURE)\r
+\r
+\r
+\r
+//\r
+// Driver Binding Protocol function prototypes\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBusDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     Handle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  );\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBusDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     ParentHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  );\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBusDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  );\r
+\r
+//\r
+// Unix Bus Driver private worker functions\r
+//\r
+EFI_DEVICE_PATH_PROTOCOL  *\r
+EmuBusCreateDevicePath (\r
+  IN  EFI_DEVICE_PATH_PROTOCOL  *RootDevicePath,\r
+  IN  EFI_GUID                  *Guid,\r
+  IN  UINT16                    InstanceNumber\r
+  );\r
+\r
+\r
+#endif\r
diff --git a/InOsEmuPkg/EmuBusDriverDxe/EmuBusDriverDxe.inf b/InOsEmuPkg/EmuBusDriverDxe/EmuBusDriverDxe.inf
new file mode 100644 (file)
index 0000000..88c2764
--- /dev/null
@@ -0,0 +1,63 @@
+## @file\r
+# Emu Bus driver\r
+#\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = EmuBusDriver\r
+  FILE_GUID                      = 9842073D-95D9-9F49-BD3F-2E29525125DF\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = InitializeEmuBusDriver\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
+#  DRIVER_BINDING                =  gEmuBusDriverBinding                        \r
+#  COMPONENT_NAME                =  gEmuBusDriverComponentName                  \r
+#\r
+\r
+[Sources]\r
+  ComponentName.c\r
+  EmuBusDriverDxe.c\r
+  \r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  DevicePathLib\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  PcdLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  BaseLib\r
+  DebugLib\r
+\r
+\r
+[Protocols]\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL TO_START\r
+  gEmuThunkProtocolGuid                         # PROTOCOL TO_START\r
+  gEmuIoThunkProtocolGuid                       # PROTOCOL BY_START\r
+\r
+\r
+\r
diff --git a/InOsEmuPkg/EmuGopDxe/ComponentName.c b/InOsEmuPkg/EmuGopDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..9360fa1
--- /dev/null
@@ -0,0 +1,250 @@
+/** @file\r
+\r
+Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2010,Apple Inc. All rights reserved.<BR>\r
+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
+  ComponentName.c\r
+\r
+Abstract:\r
+\r
+**/\r
+\r
+#include "Gop.h"\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+EmuGopComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuGopComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  );\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+EFI_COMPONENT_NAME_PROTOCOL     gEmuGopComponentName = {\r
+  EmuGopComponentNameGetDriverName,\r
+  EmuGopComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+//\r
+// EFI Component Name 2 Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEmuGopComponentName2 = {\r
+  (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) EmuGopComponentNameGetDriverName,\r
+  (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) EmuGopComponentNameGetControllerName,\r
+  "en"\r
+};\r
+\r
+\r
+EFI_UNICODE_STRING_TABLE mEmuGopDriverNameTable[] = {\r
+  { "eng", L"InOsEmu GOP Driver" },\r
+  { NULL , NULL }\r
+};\r
+\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the driver.\r
+\r
+  This function retrieves the user readable name of a driver in the form of a\r
+  Unicode string. If the driver specified by This has a user readable name in\r
+  the language specified by Language, then a pointer to the driver name is\r
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
+  by This does not support the language specified by Language,\r
+  then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language. This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified\r
+                                in RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  DriverName[out]       A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                driver specified by This in the language\r
+                                specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
+                                This and the language specified by Language was\r
+                                returned in DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuGopComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+{\r
+  return LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           mEmuGopDriverNameTable,\r
+           DriverName,\r
+           (BOOLEAN)(This == &gEmuGopComponentName)\r
+           );\r
+}\r
+\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by a driver.\r
+\r
+  This function retrieves the user readable name of the controller specified by\r
+  ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
+  driver specified by This has a user readable name in the language specified by\r
+  Language, then a pointer to the controller name is returned in ControllerName,\r
+  and EFI_SUCCESS is returned.  If the driver specified by This is not currently\r
+  managing the controller specified by ControllerHandle and ChildHandle,\r
+  then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
+  support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  ControllerHandle[in]  The handle of a controller that the driver\r
+                                specified by This is managing.  This handle\r
+                                specifies the controller whose name is to be\r
+                                returned.\r
+\r
+  @param  ChildHandle[in]       The handle of the child controller to retrieve\r
+                                the name of.  This is an optional parameter that\r
+                                may be NULL.  It will be NULL for device\r
+                                drivers.  It will also be NULL for a bus drivers\r
+                                that wish to retrieve the name of the bus\r
+                                controller.  It will not be NULL for a bus\r
+                                driver that wishes to retrieve the name of a\r
+                                child controller.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language.  This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified in\r
+                                RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  ControllerName[out]   A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                controller specified by ControllerHandle and\r
+                                ChildHandle in the language specified by\r
+                                Language from the point of view of the driver\r
+                                specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name in\r
+                                the language specified by Language for the\r
+                                driver specified by This was returned in\r
+                                DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+                                EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
+                                managing the controller specified by\r
+                                ControllerHandle and ChildHandle.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuGopComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput;\r
+  GOP_PRIVATE_DATA              *Private;\r
+\r
+  //\r
+  // This is a device driver, so ChildHandle must be NULL.\r
+  //\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Make sure this driver is currently managing ControllerHandle\r
+  //\r
+  Status = EfiTestManagedDevice (\r
+             ControllerHandle,\r
+             gEmuGopDriverBinding.DriverBindingHandle,\r
+             &gEmuIoThunkProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiGraphicsOutputProtocolGuid,\r
+                  (VOID **)&GraphicsOutput,\r
+                  gEmuGopDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = GOP_PRIVATE_DATA_FROM_THIS (GraphicsOutput);\r
+\r
+  return LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           Private->ControllerNameTable,\r
+           ControllerName,\r
+           (BOOLEAN)(This == &gEmuGopComponentName)\r
+           );\r
+}\r
diff --git a/InOsEmuPkg/EmuGopDxe/EmuGopDxe.inf b/InOsEmuPkg/EmuGopDxe/EmuGopDxe.inf
new file mode 100644 (file)
index 0000000..2a988c9
--- /dev/null
@@ -0,0 +1,69 @@
+## @file\r
+# GOP driver\r
+#\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = EmuGopDxe\r
+  FILE_GUID                      = BCC87E0D-86D6-4D4D-8040-2D983D368BD1\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = InitializeEmuGop\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
+#  DRIVER_BINDING                =  gEmuGopDriverBinding                        \r
+#  COMPONENT_NAME                =  gEmuGopComponentName                        \r
+#\r
+\r
+[Sources]\r
+  ComponentName.c\r
+  GopScreen.c\r
+  GopDriver.c\r
+  GopInput.c\r
+  Gop.h\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  BaseLib\r
+  DebugLib\r
+  KeyMapLib\r
+  \r
+\r
+[Guids]\r
+  gEfiEventExitBootServicesGuid                # SOMETIMES_CONSUMED  Create Event: EVENT_GROUP_GUID\r
+\r
+\r
+[Protocols]\r
+  gEfiGraphicsOutputProtocolGuid\r
+  gEfiSimpleTextInProtocolGuid                  # PROTOCOL BY_START\r
+  gEfiSimpleTextInputExProtocolGuid             # PROTOCOL BY_START\r
+  gEfiSimplePointerProtocolGuid                 # PROTOCOL BY_START\r
+  gEmuIoThunkProtocolGuid                       # PROTOCOL TO_START\r
+  gEmuGraphicsWindowProtocolGuid                # PROTOCOL TO_START\r
diff --git a/InOsEmuPkg/EmuGopDxe/Gop.h b/InOsEmuPkg/EmuGopDxe/Gop.h
new file mode 100644 (file)
index 0000000..03e33ea
--- /dev/null
@@ -0,0 +1,195 @@
+/*++ @file
+
+Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
+Portions copyright (c) 2010,Apple Inc. All rights reserved.<BR>
+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.             
+
+**/
+
+#ifndef __UGA_H_
+#define __UGA_H_
+
+#include <PiDxe.h>
+
+#include <Protocol/GraphicsOutput.h>
+#include <Protocol/SimpleTextIn.h>
+#include <Protocol/SimpleTextInEx.h>
+#include <Protocol/SimplePointer.h>
+#include <Protocol/EmuIoThunk.h>
+#include <Protocol/EmuGraphicsWindow.h>
+
+#include <Guid/EventGroup.h>
+
+#include <Library/DebugLib.h>
+#include <Library/BaseLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/UefiLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/KeyMapLib.h>
+
+
+#define MAX_Q 256
+
+typedef struct {
+  UINTN         Front;
+  UINTN         Rear;
+  UINTN         Count;
+  EFI_INPUT_KEY Q[MAX_Q];
+} GOP_QUEUE_FIXED;
+
+#define EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('U', 'g', 'S', 'n')
+typedef struct _EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY {
+  UINTN                                 Signature;
+  EFI_HANDLE                            NotifyHandle;
+  EFI_KEY_DATA                          KeyData;
+  EFI_KEY_NOTIFY_FUNCTION               KeyNotificationFn;
+  EFI_EVENT                             Event;
+  LIST_ENTRY                            NotifyEntry;
+} EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY;
+  
+#define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
+
+typedef struct {
+  UINT32                     HorizontalResolution;
+  UINT32                     VerticalResolution;
+  UINT32                     ColorDepth;
+  UINT32                     RefreshRate;
+} GOP_MODE_DATA;
+
+
+
+extern EFI_DRIVER_BINDING_PROTOCOL gEmuGopDriverBinding;
+extern EFI_COMPONENT_NAME_PROTOCOL gEmuGopComponentName;
+
+#define EMU_UGA_CLASS_NAME       L"EmuGopWindow"
+
+#define GOP_PRIVATE_DATA_SIGNATURE  SIGNATURE_32 ('G', 'o', 'p', 'N')
+typedef struct {
+  UINT64                            Signature;
+
+  EFI_HANDLE                        Handle;
+  EFI_GRAPHICS_OUTPUT_PROTOCOL      GraphicsOutput;
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL    SimpleTextIn;
+  EFI_SIMPLE_POINTER_PROTOCOL       SimplePointer;
+
+  EMU_IO_THUNK_PROTOCOL             *EmuIoThunk;
+  EMU_GRAPHICS_WINDOW_PROTOCOL      *EmuGraphicsWindow;
+
+  EFI_UNICODE_STRING_TABLE          *ControllerNameTable;
+
+  EFI_SIMPLE_POINTER_MODE           PointerMode;
+  //
+  // GOP Private Data for QueryMode ()
+  //
+  GOP_MODE_DATA                     *ModeData;
+
+
+  //
+  // UGA Private Data knowing when to start hardware
+  //
+  BOOLEAN                           HardwareNeedsStarting;
+
+  CHAR16                            *WindowName;
+
+  GOP_QUEUE_FIXED                   Queue;
+
+  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleTextInEx;
+  EFI_KEY_STATE                     KeyState;
+  LIST_ENTRY                        NotifyList;  
+} GOP_PRIVATE_DATA;
+
+
+#define GOP_PRIVATE_DATA_FROM_THIS(a)  \
+         CR(a, GOP_PRIVATE_DATA, GraphicsOutput, GOP_PRIVATE_DATA_SIGNATURE)
+
+#define GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS(a)  \
+         CR(a, GOP_PRIVATE_DATA, SimpleTextIn, GOP_PRIVATE_DATA_SIGNATURE)
+
+#define GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS(a)  \
+         CR(a, GOP_PRIVATE_DATA, SimpleTextInEx, GOP_PRIVATE_DATA_SIGNATURE)
+
+#define GOP_PRIVATE_DATA_FROM_POINTER_MODE_THIS(a)  \
+         CR(a, GOP_PRIVATE_DATA, SimplePointer, GOP_PRIVATE_DATA_SIGNATURE)
+
+
+//
+// Global Protocol Variables
+//
+extern EFI_DRIVER_BINDING_PROTOCOL  gEmuGopDriverBinding;
+extern EFI_COMPONENT_NAME_PROTOCOL  gEmuGopComponentName;
+extern EFI_COMPONENT_NAME2_PROTOCOL gEmuGopComponentName2;
+
+//
+// Gop Hardware abstraction internal worker functions
+//
+EFI_STATUS
+EmuGopSupported (
+  IN  EMU_IO_THUNK_PROTOCOL  *EmuIoThunk
+  );
+
+EFI_STATUS
+EmuGopConstructor (
+  IN  GOP_PRIVATE_DATA    *Private
+  );
+
+EFI_STATUS
+EmuGopDestructor (
+  IN  GOP_PRIVATE_DATA    *Private
+  );
+
+
+EFI_STATUS
+GopPrivateAddQ (
+  IN  GOP_PRIVATE_DATA    *Private,
+  IN  EFI_INPUT_KEY       Key
+  );
+
+EFI_STATUS
+EmuGopInitializeSimpleTextInForWindow (
+  IN  GOP_PRIVATE_DATA    *Private
+  );
+
+EFI_STATUS
+EmuGopInitializeSimplePointerForWindow (
+  IN  GOP_PRIVATE_DATA    *Private
+  );
+
+EFI_STATUS
+EmuGopStartWindow (
+  IN  GOP_PRIVATE_DATA    *Private,
+  IN  UINT32              HorizontalResolution,
+  IN  UINT32              VerticalResolution,
+  IN  UINT32              ColorDepth,
+  IN  UINT32              RefreshRate
+  );
+
+VOID
+EFIAPI
+ShutdownGopEvent (
+  IN EFI_EVENT  Event,
+  IN VOID       *Context
+  );
+
+VOID
+EFIAPI
+GopPrivateMakeCallbackFunction (
+  IN VOID           *Context,
+  IN EFI_KEY_DATA   *KeyData
+  );
+
+VOID
+EFIAPI
+GopPrivateBreakCallbackFunction (
+  IN VOID           *Context,
+  IN EFI_KEY_DATA   *KeyData
+  );
+
+#endif
diff --git a/InOsEmuPkg/EmuGopDxe/GopDriver.c b/InOsEmuPkg/EmuGopDxe/GopDriver.c
new file mode 100644 (file)
index 0000000..8ddaa86
--- /dev/null
@@ -0,0 +1,443 @@
+/*++ @file\r
+\r
+Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2010,Apple Inc. All rights reserved.<BR>\r
+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
+#include "Gop.h"\r
+\r
+\r
+EFI_STATUS\r
+FreeNotifyList (\r
+  IN OUT LIST_ENTRY           *ListHead\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+  ListHead   - The list head\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - Free the notify list successfully\r
+  EFI_INVALID_PARAMETER - ListHead is invalid.\r
+\r
+**/\r
+{\r
+  EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *NotifyNode;\r
+\r
+  if (ListHead == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  while (!IsListEmpty (ListHead)) {\r
+    NotifyNode = CR (\r
+                   ListHead->ForwardLink, \r
+                   EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY, \r
+                   NotifyEntry, \r
+                   EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE\r
+                   );\r
+    RemoveEntryList (ListHead->ForwardLink);\r
+    gBS->FreePool (NotifyNode);\r
+  }\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Tests to see if this driver supports a given controller. If a child device is provided, \r
+  it further tests to see if this driver supports creating a handle for the specified child device.\r
+\r
+  This function checks to see if the driver specified by This supports the device specified by \r
+  ControllerHandle. Drivers will typically use the device path attached to \r
+  ControllerHandle and/or the services from the bus I/O abstraction attached to \r
+  ControllerHandle to determine if the driver supports ControllerHandle. This function \r
+  may be called many times during platform initialization. In order to reduce boot times, the tests \r
+  performed by this function must be very small, and take as little time as possible to execute. This \r
+  function must not change the state of any hardware devices, and this function must be aware that the \r
+  device specified by ControllerHandle may already be managed by the same driver or a \r
+  different driver. This function must match its calls to AllocatePages() with FreePages(), \r
+  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().  \r
+  Because ControllerHandle may have been previously started by the same driver, if a protocol is \r
+  already in the opened state, then it must not be closed with CloseProtocol(). This is required \r
+  to guarantee the state of ControllerHandle is not modified by this function.\r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to test. This handle \r
+                                   must support a protocol interface that supplies \r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This \r
+                                   parameter is ignored by device drivers, and is optional for bus \r
+                                   drivers. For bus drivers, if this parameter is not NULL, then \r
+                                   the bus driver must determine if the bus controller specified \r
+                                   by ControllerHandle and the child controller specified \r
+                                   by RemainingDevicePath are both supported by this \r
+                                   bus driver.\r
+\r
+  @retval EFI_SUCCESS              The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is supported by the driver specified by This.\r
+  @retval EFI_ALREADY_STARTED      The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by the driver\r
+                                   specified by This.\r
+  @retval EFI_ACCESS_DENIED        The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by a different\r
+                                   driver or an application that requires exclusive access.\r
+                                   Currently not implemented.\r
+  @retval EFI_UNSUPPORTED          The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is not supported by the driver specified by This.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuGopDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_IO_THUNK_PROTOCOL   *EmuIoThunk;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (VOID **)&EmuIoThunk,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = EmuGopSupported (EmuIoThunk);\r
+\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+        Handle,\r
+        &gEmuIoThunkProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Handle\r
+        );\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Starts a device controller or a bus controller.\r
+\r
+  The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
+  As a result, much of the error checking on the parameters to Start() has been moved into this \r
+  common boot service. It is legal to call Start() from other locations, \r
+  but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE.\r
+  2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
+     EFI_DEVICE_PATH_PROTOCOL.\r
+  3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
+     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.  \r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to start. This handle \r
+                                   must support a protocol interface that supplies \r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This \r
+                                   parameter is ignored by device drivers, and is optional for bus \r
+                                   drivers. For a bus driver, if this parameter is NULL, then handles \r
+                                   for all the children of Controller are created by this driver.  \r
+                                   If this parameter is not NULL and the first Device Path Node is \r
+                                   not the End of Device Path Node, then only the handle for the \r
+                                   child device specified by the first Device Path Node of \r
+                                   RemainingDevicePath is created by this driver.\r
+                                   If the first Device Path Node of RemainingDevicePath is \r
+                                   the End of Device Path Node, no child handle is created by this\r
+                                   driver.\r
+\r
+  @retval EFI_SUCCESS              The device was started.\r
+  @retval EFI_DEVICE_ERROR         The device could not be started due to a device error.Currently not implemented.\r
+  @retval EFI_OUT_OF_RESOURCES     The request could not be completed due to a lack of resources.\r
+  @retval Others                   The driver failded to start the device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuGopDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
+  )\r
+{\r
+  EMU_IO_THUNK_PROTOCOL   *EmuIoThunk;\r
+  EFI_STATUS              Status;\r
+  GOP_PRIVATE_DATA        *Private;\r
+\r
+  //\r
+  // Grab the protocols we need\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (VOID **)&EmuIoThunk,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Allocate Private context data for SGO inteface.\r
+  //\r
+  Private = NULL;\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  sizeof (GOP_PRIVATE_DATA),\r
+                  (VOID **)&Private\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+  //\r
+  // Set up context record\r
+  //\r
+  Private->Signature           = GOP_PRIVATE_DATA_SIGNATURE;\r
+  Private->Handle              = Handle;\r
+  Private->EmuIoThunk          = EmuIoThunk;\r
+  Private->WindowName          = EmuIoThunk->ConfigString;\r
+  Private->ControllerNameTable = NULL;\r
+\r
+  AddUnicodeString (\r
+    "eng",\r
+    gEmuGopComponentName.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    EmuIoThunk->ConfigString\r
+    );\r
+  AddUnicodeString2 (\r
+    "en",\r
+    gEmuGopComponentName2.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    EmuIoThunk->ConfigString,\r
+    FALSE\r
+    );\r
+\r
+  Status = EmuGopConstructor (Private);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+  //\r
+  // Publish the Gop interface to the world\r
+  //\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Private->Handle,\r
+                  &gEfiGraphicsOutputProtocolGuid,    &Private->GraphicsOutput,\r
+                  &gEfiSimpleTextInProtocolGuid,      &Private->SimpleTextIn,\r
+                  &gEfiSimplePointerProtocolGuid,     &Private->SimplePointer,\r
+                  &gEfiSimpleTextInputExProtocolGuid, &Private->SimpleTextInEx,\r
+                  NULL\r
+                  );\r
+\r
+Done:\r
+  if (EFI_ERROR (Status)) {\r
+\r
+    gBS->CloseProtocol (\r
+          Handle,\r
+          &gEmuIoThunkProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Handle\r
+          );\r
+\r
+    if (Private != NULL) {\r
+      //\r
+      // On Error Free back private data\r
+      //\r
+      if (Private->ControllerNameTable != NULL) {\r
+        FreeUnicodeStringTable (Private->ControllerNameTable);\r
+      }\r
+      if (Private->SimpleTextIn.WaitForKey != NULL) {\r
+        gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);\r
+      }\r
+      if (Private->SimpleTextInEx.WaitForKeyEx != NULL) {\r
+        gBS->CloseEvent (Private->SimpleTextInEx.WaitForKeyEx);\r
+      }\r
+      FreeNotifyList (&Private->NotifyList);\r
+\r
+      gBS->FreePool (Private);\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Stops a device controller or a bus controller.\r
+  \r
+  The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). \r
+  As a result, much of the error checking on the parameters to Stop() has been moved \r
+  into this common boot service. It is legal to call Stop() from other locations, \r
+  but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
+     same driver's Start() function.\r
+  2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
+     EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
+     Start() function, and the Start() function must have called OpenProtocol() on\r
+     ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
+  \r
+  @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must \r
+                                support a bus specific I/O protocol for the driver \r
+                                to use to stop the device.\r
+  @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.\r
+  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL \r
+                                if NumberOfChildren is 0.\r
+\r
+  @retval EFI_SUCCESS           The device was stopped.\r
+  @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuGopDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  )\r
+{\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
+  EFI_STATUS                   Status;\r
+  GOP_PRIVATE_DATA             *Private;\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiGraphicsOutputProtocolGuid,\r
+                  (VOID **)&GraphicsOutput,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // If the GOP interface does not exist the driver is not started\r
+    //\r
+    return EFI_NOT_STARTED;\r
+  }\r
+\r
+  //\r
+  // Get our private context information\r
+  //\r
+  Private = GOP_PRIVATE_DATA_FROM_THIS (GraphicsOutput);\r
+\r
+  //\r
+  // Remove the SGO interface from the system\r
+  //\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  Private->Handle,\r
+                  &gEfiGraphicsOutputProtocolGuid,    &Private->GraphicsOutput,\r
+                  &gEfiSimpleTextInProtocolGuid,      &Private->SimpleTextIn,\r
+                  &gEfiSimplePointerProtocolGuid,     &Private->SimplePointer,\r
+                  &gEfiSimpleTextInputExProtocolGuid, &Private->SimpleTextInEx,\r
+                  NULL\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Shutdown the hardware\r
+    //\r
+    Status = EmuGopDestructor (Private);\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+\r
+    gBS->CloseProtocol (\r
+          Handle,\r
+          &gEmuIoThunkProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Handle\r
+          );\r
+\r
+    //\r
+    // Free our instance data\r
+    //\r
+    FreeUnicodeStringTable (Private->ControllerNameTable);\r
+    \r
+    Status = gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);\r
+    ASSERT_EFI_ERROR (Status);\r
+    \r
+    Status = gBS->CloseEvent (Private->SimpleTextInEx.WaitForKeyEx);\r
+    ASSERT_EFI_ERROR (Status);\r
+    \r
+    FreeNotifyList (&Private->NotifyList);\r
+\r
+    gBS->FreePool (Private);\r
+\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+///\r
+/// This protocol provides the services required to determine if a driver supports a given controller. \r
+/// If a controller is supported, then it also provides routines to start and stop the controller.\r
+///\r
+EFI_DRIVER_BINDING_PROTOCOL gEmuGopDriverBinding = {\r
+  EmuGopDriverBindingSupported,\r
+  EmuGopDriverBindingStart,\r
+  EmuGopDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+\r
+\r
+/**\r
+  The user Entry Point for module EmuGop. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeEmuGop (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  Status = EfiLibInstallDriverBindingComponentName2 (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gEmuGopDriverBinding,\r
+             ImageHandle,\r
+             &gEmuGopComponentName,\r
+             &gEmuGopComponentName2\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
+\r
diff --git a/InOsEmuPkg/EmuGopDxe/GopInput.c b/InOsEmuPkg/EmuGopDxe/GopInput.c
new file mode 100644 (file)
index 0000000..f6c7959
--- /dev/null
@@ -0,0 +1,899 @@
+/*++ @file
+
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+Portions copyright (c) 2010 0 2011,Apple Inc. All rights reserved.<BR>
+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.
+
+
+**/
+
+#include "Gop.h"
+
+
+BOOLEAN
+GopPrivateIsKeyRegistered (
+  IN EFI_KEY_DATA  *RegsiteredData,
+  IN EFI_KEY_DATA  *InputData
+  )
+/*++
+
+Routine Description:
+
+Arguments:
+
+  RegsiteredData    - A pointer to a buffer that is filled in with the keystroke 
+                      state data for the key that was registered.
+  InputData         - A pointer to a buffer that is filled in with the keystroke 
+                      state data for the key that was pressed.
+
+Returns:
+  TRUE              - Key be pressed matches a registered key.
+  FLASE             - Match failed. 
+  
+**/
+{
+  ASSERT (RegsiteredData != NULL && InputData != NULL);
+  
+  if ((RegsiteredData->Key.ScanCode    != InputData->Key.ScanCode) ||
+      (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) {
+    return FALSE;  
+  }      
+  
+  //
+  // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.
+  //
+  if (RegsiteredData->KeyState.KeyShiftState != 0 &&
+      RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) {
+    return FALSE;    
+  }   
+  if (RegsiteredData->KeyState.KeyToggleState != 0 &&
+      RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) {
+    return FALSE;    
+  }     
+  
+  return TRUE;
+
+}
+
+
+VOID
+EFIAPI
+GopPrivateMakeCallbackFunction (
+  IN VOID           *Context,
+  IN EFI_KEY_DATA   *KeyData
+  )
+{ 
+  LIST_ENTRY                        *Link;
+  EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY  *CurrentNotify;
+  GOP_PRIVATE_DATA                  *Private = (GOP_PRIVATE_DATA *)Context;
+  
+  KeyMapMake (KeyData);
+
+  for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
+    CurrentNotify = CR (
+                      Link, 
+                      EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY, 
+                      NotifyEntry, 
+                      EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE
+                      );
+    if (GopPrivateIsKeyRegistered (&CurrentNotify->KeyData, KeyData)) { 
+      // We could be called at a high TPL so signal an event to call the registered function 
+      // at a lower TPL.
+      gBS->SignalEvent (CurrentNotify->Event);
+    }
+  }    
+}
+
+
+VOID
+EFIAPI
+GopPrivateBreakCallbackFunction (
+  IN VOID           *Context,
+  IN EFI_KEY_DATA   *KeyData
+  )
+{ 
+  GOP_PRIVATE_DATA  *Private = (GOP_PRIVATE_DATA *)Context;
+  
+  KeyMapBreak (KeyData);
+}
+
+
+
+//
+// Simple Text In implementation.
+//
+
+/**
+  Reset the input device and optionally run diagnostics
+
+  @param  This                 Protocol instance pointer.
+  @param  ExtendedVerification Driver may perform diagnostics on reset.
+
+  @retval EFI_SUCCESS          The device was reset.
+  @retval EFI_DEVICE_ERROR     The device is not functioning properly and could not be reset.
+
+**/
+EFI_STATUS
+EFIAPI
+EmuGopSimpleTextInReset (
+  IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL       *This,
+  IN BOOLEAN                              ExtendedVerification
+  )
+{
+  GOP_PRIVATE_DATA  *Private;
+  EFI_KEY_DATA      KeyData;
+  EFI_TPL           OldTpl;
+
+  Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);
+  if (Private->EmuGraphicsWindow == NULL) {
+    return EFI_SUCCESS;
+  }
+
+  //
+  // Enter critical section
+  //
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
+
+  //
+  // A reset is draining the Queue
+  //
+  while (Private->EmuGraphicsWindow->GetKey (Private->EmuGraphicsWindow, &KeyData) == EFI_SUCCESS)
+    ;
+
+  //
+  // Leave critical section and return
+  //
+  gBS->RestoreTPL (OldTpl);
+  return EFI_SUCCESS;
+}
+
+
+/**
+  Reads the next keystroke from the input device. The WaitForKey Event can
+  be used to test for existence of a keystroke via WaitForEvent () call.
+
+  @param  This  Protocol instance pointer.
+  @param  Key   A pointer to a buffer that is filled in with the keystroke
+                information for the key that was pressed.
+
+  @retval EFI_SUCCESS      The keystroke information was returned.
+  @retval EFI_NOT_READY    There was no keystroke data available.
+  @retval EFI_DEVICE_ERROR The keystroke information was not returned due to
+                           hardware errors.
+
+**/
+EFI_STATUS
+EFIAPI
+EmuGopSimpleTextInReadKeyStroke (
+  IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL       *This,
+  OUT EFI_INPUT_KEY                       *Key
+  )
+{
+  GOP_PRIVATE_DATA  *Private;
+  EFI_STATUS        Status;
+  EFI_TPL           OldTpl;
+  EFI_KEY_DATA      KeyData;
+
+  Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);
+  if (Private->EmuGraphicsWindow == NULL) {
+    return EFI_NOT_READY;
+  }
+
+  //
+  // Enter critical section
+  //
+  OldTpl  = gBS->RaiseTPL (TPL_NOTIFY);
+
+  Status  = Private->EmuGraphicsWindow->GetKey (Private->EmuGraphicsWindow, &KeyData);
+  CopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY));
+
+  //
+  // Leave critical section and return
+  //
+  gBS->RestoreTPL (OldTpl);
+
+  return Status;
+}
+
+
+
+/**
+  SimpleTextIn and SimpleTextInEx Notify Wait Event 
+
+  @param  Event                 Event whose notification function is being invoked.
+  @param  Context               Pointer to GOP_PRIVATE_DATA.
+
+**/
+VOID
+EFIAPI
+EmuGopSimpleTextInWaitForKey (
+  IN EFI_EVENT          Event,
+  IN VOID               *Context
+  )
+{
+  GOP_PRIVATE_DATA  *Private;
+  EFI_STATUS        Status;
+  EFI_TPL           OldTpl;
+
+  Private = (GOP_PRIVATE_DATA *) Context;
+  if (Private->EmuGraphicsWindow == NULL) {
+    return;
+  }
+
+  //
+  // Enter critical section
+  //
+  OldTpl  = gBS->RaiseTPL (TPL_NOTIFY);
+
+  Status  = Private->EmuGraphicsWindow->CheckKey (Private->EmuGraphicsWindow);
+  if (!EFI_ERROR (Status)) {
+    //
+    // If a there is a key in the queue signal our event.
+    //
+    gBS->SignalEvent (Event);
+  }
+  //
+  // Leave critical section and return
+  //
+  gBS->RestoreTPL (OldTpl);
+}
+
+
+//
+// Simple Text Input Ex protocol functions
+//
+
+
+/**
+  The Reset() function resets the input device hardware. As part
+  of initialization process, the firmware/device will make a quick
+  but reasonable attempt to verify that the device is functioning.
+  If the ExtendedVerification flag is TRUE the firmware may take
+  an extended amount of time to verify the device is operating on
+  reset. Otherwise the reset operation is to occur as quickly as
+  possible. The hardware verification process is not defined by
+  this specification and is left up to the platform firmware or
+  driver to implement.
+
+  @param This                 A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
+
+  @param ExtendedVerification Indicates that the driver may
+                              perform a more exhaustive
+                              verification operation of the
+                              device during reset.
+
+
+  @retval EFI_SUCCESS       The device was reset.
+  
+  @retval EFI_DEVICE_ERROR  The device is not functioning
+                            correctly and could not be reset.
+
+**/
+EFI_STATUS
+EFIAPI
+EmuGopSimpleTextInExResetEx (
+  IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,
+  IN BOOLEAN                            ExtendedVerification
+  )
+/*++
+
+  Routine Description:
+    Reset the input device and optionaly run diagnostics
+
+  Arguments:
+    This                 - Protocol instance pointer.
+    ExtendedVerification - Driver may perform diagnostics on reset.
+
+  Returns:
+    EFI_SUCCESS           - The device was reset.
+
+**/
+{
+  GOP_PRIVATE_DATA *Private;
+
+  Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This);
+  
+  return EFI_SUCCESS;
+}
+
+
+
+/**
+  The function reads the next keystroke from the input device. If
+  there is no pending keystroke the function returns
+  EFI_NOT_READY. If there is a pending keystroke, then
+  KeyData.Key.ScanCode is the EFI scan code defined in Error!
+  Reference source not found. The KeyData.Key.UnicodeChar is the
+  actual printable character or is zero if the key does not
+  represent a printable character (control key, function key,
+  etc.). The KeyData.KeyState is shift state for the character
+  reflected in KeyData.Key.UnicodeChar or KeyData.Key.ScanCode .
+  When interpreting the data from this function, it should be
+  noted that if a class of printable characters that are
+  normally adjusted by shift modifiers (e.g. Shift Key + "f"
+  key) would be presented solely as a KeyData.Key.UnicodeChar
+  without the associated shift state. So in the previous example
+  of a Shift Key + "f" key being pressed, the only pertinent
+  data returned would be KeyData.Key.UnicodeChar with the value
+  of "F". This of course would not typically be the case for
+  non-printable characters such as the pressing of the Right
+  Shift Key + F10 key since the corresponding returned data
+  would be reflected both in the KeyData.KeyState.KeyShiftState
+  and KeyData.Key.ScanCode values. UEFI drivers which implement
+  the EFI_SIMPLE_TEXT_INPUT_EX protocol are required to return
+  KeyData.Key and KeyData.KeyState values. These drivers must
+  always return the most current state of
+  KeyData.KeyState.KeyShiftState and
+  KeyData.KeyState.KeyToggleState. It should also be noted that
+  certain input devices may not be able to produce shift or toggle
+  state information, and in those cases the high order bit in the
+  respective Toggle and Shift state fields should not be active.
+
+  
+  @param This     A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
+
+  @param KeyData  A pointer to a buffer that is filled in with
+                  the keystroke state data for the key that was
+                  pressed.
+
+  
+  @retval EFI_SUCCESS     The keystroke information was
+                          returned.
+  
+  @retval EFI_NOT_READY   There was no keystroke data available.
+                          EFI_DEVICE_ERROR The keystroke
+                          information was not returned due to
+                          hardware errors.
+
+
+**/
+EFI_STATUS
+EFIAPI
+EmuGopSimpleTextInExReadKeyStrokeEx (
+  IN  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
+  OUT EFI_KEY_DATA                      *KeyData
+  )
+/*++
+
+  Routine Description:
+    Reads the next keystroke from the input device. The WaitForKey Event can 
+    be used to test for existance of a keystroke via WaitForEvent () call.
+
+  Arguments:
+    This       - Protocol instance pointer.
+    KeyData    - A pointer to a buffer that is filled in with the keystroke 
+                 state data for the key that was pressed.
+
+  Returns:
+    EFI_SUCCESS           - The keystroke information was returned.
+    EFI_NOT_READY         - There was no keystroke data availiable.
+    EFI_DEVICE_ERROR      - The keystroke information was not returned due to 
+                            hardware errors.
+    EFI_INVALID_PARAMETER - KeyData is NULL.                        
+
+**/
+{
+  EFI_STATUS        Status;
+  GOP_PRIVATE_DATA  *Private;
+  EFI_TPL           OldTpl;
+
+
+  if (KeyData == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);
+  if (Private->EmuGraphicsWindow == NULL) {
+    return EFI_NOT_READY;
+  }
+
+  //
+  // Enter critical section
+  //
+  OldTpl  = gBS->RaiseTPL (TPL_NOTIFY);
+
+  Status  = Private->EmuGraphicsWindow->GetKey(Private->EmuGraphicsWindow, KeyData);
+
+  //
+  // Leave critical section and return
+  //
+  gBS->RestoreTPL (OldTpl);
+
+  return Status;
+}
+
+
+
+/**
+  The SetState() function allows the input device hardware to
+  have state settings adjusted.
+  
+  @param This           A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
+  
+  @param KeyToggleState Pointer to the EFI_KEY_TOGGLE_STATE to
+                        set the state for the input device.
+  
+  
+  @retval EFI_SUCCESS       The device state was set appropriately.
+
+  @retval EFI_DEVICE_ERROR  The device is not functioning
+                            correctly and could not have the
+                            setting adjusted.
+
+  @retval EFI_UNSUPPORTED   The device does not support the
+                            ability to have its state set.
+
+**/
+EFI_STATUS
+EFIAPI
+EmuGopSimpleTextInExSetState (
+  IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,
+  IN EFI_KEY_TOGGLE_STATE               *KeyToggleState
+  )
+{
+  GOP_PRIVATE_DATA  *Private;
+  EFI_STATUS        Status;
+  EFI_TPL           OldTpl;
+
+  Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);
+  if (Private->EmuGraphicsWindow == NULL) {
+    return EFI_NOT_READY;
+  }
+
+  //
+  // Enter critical section
+  //
+  OldTpl  = gBS->RaiseTPL (TPL_NOTIFY);
+
+  Status  = Private->EmuGraphicsWindow->KeySetState (Private->EmuGraphicsWindow, KeyToggleState);
+  //
+  // Leave critical section and return
+  //
+  gBS->RestoreTPL (OldTpl);
+
+  return Status;
+}
+
+
+/**
+  SimpleTextIn and SimpleTextInEx Notify Wait Event 
+
+  @param  Event                 Event whose notification function is being invoked.
+  @param  Context               Pointer to GOP_PRIVATE_DATA.
+
+**/
+VOID
+EFIAPI
+EmuGopRegisterKeyCallback (
+  IN EFI_EVENT          Event,
+  IN VOID               *Context
+  )
+{
+  EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *ExNotify = (EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *)Context;
+  
+  ExNotify->KeyNotificationFn (&ExNotify->KeyData);
+}
+
+
+
+/**
+  The RegisterKeystrokeNotify() function registers a function
+  which will be called when a specified keystroke will occur.
+  
+  @param This                     A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
+  
+  @param KeyData                  A pointer to a buffer that is filled in with
+                                  the keystroke information for the key that was
+                                  pressed.
+  
+  @param KeyNotificationFunction  Points to the function to be
+                                  called when the key sequence
+                                  is typed specified by KeyData.
+  
+  
+  @param NotifyHandle             Points to the unique handle assigned to
+                                  the registered notification.
+  
+  @retval EFI_SUCCESS           The device state was set
+                                appropriately.
+
+  @retval EFI_OUT_OF_RESOURCES  Unable to allocate necessary
+                                data structures.
+
+**/
+EFI_STATUS
+EFIAPI
+EmuGopSimpleTextInExRegisterKeyNotify (
+  IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,
+  IN EFI_KEY_DATA                       *KeyData,
+  IN EFI_KEY_NOTIFY_FUNCTION            KeyNotificationFunction,
+  OUT EFI_HANDLE                        *NotifyHandle
+  )
+{
+  EFI_STATUS                          Status;
+  GOP_PRIVATE_DATA                    *Private;
+  EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY     *CurrentNotify;
+  LIST_ENTRY                          *Link;
+  EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY     *NewNotify;
+
+  if (KeyData == NULL || KeyNotificationFunction == NULL || NotifyHandle == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This);
+
+  //
+  // Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.
+  //
+  for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
+    CurrentNotify = CR (
+                      Link, 
+                      EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY, 
+                      NotifyEntry, 
+                      EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE
+                      );
+    if (GopPrivateIsKeyRegistered (&CurrentNotify->KeyData, KeyData)) { 
+      if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) {
+        *NotifyHandle = CurrentNotify->NotifyHandle;
+        return EFI_SUCCESS;
+      }
+    }
+  }    
+  
+  //
+  // Allocate resource to save the notification function
+  //  
+  NewNotify = (EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *) AllocateZeroPool (sizeof (EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY));
+  if (NewNotify == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  NewNotify->Signature         = EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE;     
+  NewNotify->KeyNotificationFn = KeyNotificationFunction;
+  NewNotify->NotifyHandle      = (EFI_HANDLE) NewNotify;
+  CopyMem (&NewNotify->KeyData, KeyData, sizeof (KeyData));
+  InsertTailList (&Private->NotifyList, &NewNotify->NotifyEntry);
+  
+  Status = gBS->CreateEvent (
+                  EVT_NOTIFY_SIGNAL,
+                  TPL_NOTIFY,
+                  EmuGopRegisterKeyCallback,
+                  NewNotify,
+                  &NewNotify->Event
+                  );
+  ASSERT_EFI_ERROR (Status);
+
+
+  *NotifyHandle = NewNotify->NotifyHandle;  
+  
+  return EFI_SUCCESS;
+  
+}
+
+
+/**
+  The UnregisterKeystrokeNotify() function removes the
+  notification which was previously registered.
+  
+  @param This               A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
+  
+  @param NotificationHandle The handle of the notification
+                            function being unregistered.
+  
+  @retval EFI_SUCCESS The device state was set appropriately.
+  
+  @retval EFI_INVALID_PARAMETER The NotificationHandle is
+                                invalid.
+
+**/
+EFI_STATUS
+EFIAPI
+EmuGopSimpleTextInExUnregisterKeyNotify (
+  IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,
+  IN EFI_HANDLE                         NotificationHandle
+  )
+/*++
+
+  Routine Description:
+    Remove a registered notification function from a particular keystroke.
+
+  Arguments:
+    This                    - Protocol instance pointer.    
+    NotificationHandle      - The handle of the notification function being unregistered.
+
+  Returns:
+    EFI_SUCCESS             - The notification function was unregistered successfully.
+    EFI_INVALID_PARAMETER   - The NotificationHandle is invalid.
+                              
+**/   
+{
+  GOP_PRIVATE_DATA                   *Private;
+  LIST_ENTRY                         *Link;
+  EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *CurrentNotify;
+
+  if (NotificationHandle == NULL) {
+    return EFI_INVALID_PARAMETER;
+  } 
+
+  if (((EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *) NotificationHandle)->Signature != EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE) {
+    return EFI_INVALID_PARAMETER;
+  } 
+
+  Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This);
+
+  for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
+    CurrentNotify = CR (
+                      Link, 
+                      EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY, 
+                      NotifyEntry, 
+                      EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE
+                      );       
+    if (CurrentNotify->NotifyHandle == NotificationHandle) {
+      //
+      // Remove the notification function from NotifyList and free resources
+      //
+      RemoveEntryList (&CurrentNotify->NotifyEntry);    
+      
+      gBS->CloseEvent (CurrentNotify->Event);
+
+      gBS->FreePool (CurrentNotify);            
+      return EFI_SUCCESS;
+    }
+  }
+
+  //
+  // Can not find the specified Notification Handle
+  //
+  return EFI_INVALID_PARAMETER;
+}
+
+
+
+/**
+  Initialize SimplelTextIn and SimpleTextInEx protocols in the Private
+  context structure.
+
+  @param  Private               Context structure to fill in. 
+
+  @return EFI_SUCCESS           Initialization was a success
+
+**/
+EFI_STATUS
+EmuGopInitializeSimpleTextInForWindow (
+  IN  GOP_PRIVATE_DATA    *Private
+  )
+{
+  EFI_STATUS  Status;
+
+  //
+  // Initialize Simple Text In protoocol
+  //
+  Private->SimpleTextIn.Reset         = EmuGopSimpleTextInReset;
+  Private->SimpleTextIn.ReadKeyStroke = EmuGopSimpleTextInReadKeyStroke;
+
+  Status = gBS->CreateEvent (
+                  EVT_NOTIFY_WAIT,
+                  TPL_NOTIFY,
+                  EmuGopSimpleTextInWaitForKey,
+                  Private,
+                  &Private->SimpleTextIn.WaitForKey
+                  );
+  ASSERT_EFI_ERROR (Status);
+  
+  
+  //
+  // Initialize Simple Text In Ex
+  //
+  
+  Private->SimpleTextInEx.Reset               = EmuGopSimpleTextInExResetEx;
+  Private->SimpleTextInEx.ReadKeyStrokeEx     = EmuGopSimpleTextInExReadKeyStrokeEx;
+  Private->SimpleTextInEx.SetState            = EmuGopSimpleTextInExSetState;
+  Private->SimpleTextInEx.RegisterKeyNotify   = EmuGopSimpleTextInExRegisterKeyNotify;
+  Private->SimpleTextInEx.UnregisterKeyNotify = EmuGopSimpleTextInExUnregisterKeyNotify;
+
+  Private->SimpleTextInEx.Reset (&Private->SimpleTextInEx, FALSE);
+  
+  InitializeListHead (&Private->NotifyList);
+
+  Status = gBS->CreateEvent (
+                  EVT_NOTIFY_WAIT,
+                  TPL_NOTIFY,
+                  EmuGopSimpleTextInWaitForKey,
+                  Private,
+                  &Private->SimpleTextInEx.WaitForKeyEx
+                  );
+  ASSERT_EFI_ERROR (Status);
+
+
+  return Status;
+}
+
+
+
+
+
+
+
+//
+// Simple Pointer implementation.
+//
+
+
+/**                                                                 
+  Resets the pointer device hardware.
+    
+  @param  This                  A pointer to the EFI_SIMPLE_POINTER_PROTOCOL
+                                instance.                                   
+  @param  ExtendedVerification  Indicates that the driver may perform a more exhaustive
+                                verification operation of the device during reset.                                       
+                                
+  @retval EFI_SUCCESS           The device was reset.
+  @retval EFI_DEVICE_ERROR      The device is not functioning correctly and could not be reset.  
+                                   
+**/
+EFI_STATUS
+EFIAPI
+EmuGopSimplePointerReset (
+  IN EFI_SIMPLE_POINTER_PROTOCOL          *This,
+  IN BOOLEAN                              ExtendedVerification
+  )
+{
+  GOP_PRIVATE_DATA             *Private;
+  EFI_SIMPLE_POINTER_STATE     State;
+  EFI_TPL                      OldTpl;
+
+  Private = GOP_PRIVATE_DATA_FROM_POINTER_MODE_THIS (This);
+  if (Private->EmuGraphicsWindow == NULL) {
+    return EFI_SUCCESS;
+  }
+
+  //
+  // Enter critical section
+  //
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
+
+  //
+  // A reset is draining the Queue
+  //
+  while (Private->EmuGraphicsWindow->GetPointerState (Private->EmuGraphicsWindow, &State) == EFI_SUCCESS)
+    ;
+
+  //
+  // Leave critical section and return
+  //
+  gBS->RestoreTPL (OldTpl);
+  return EFI_SUCCESS;
+}
+
+
+/**                                                                 
+  Retrieves the current state of a pointer device.
+    
+  @param  This                  A pointer to the EFI_SIMPLE_POINTER_PROTOCOL
+                                instance.                                   
+  @param  State                 A pointer to the state information on the pointer device.
+                                
+  @retval EFI_SUCCESS           The state of the pointer device was returned in State.
+  @retval EFI_NOT_READY         The state of the pointer device has not changed since the last call to
+                                GetState().                                                           
+  @retval EFI_DEVICE_ERROR      A device error occurred while attempting to retrieve the pointer device's
+                                current state.                                                           
+                                   
+**/
+EFI_STATUS
+EFIAPI
+EmuGopSimplePointerGetState (
+  IN EFI_SIMPLE_POINTER_PROTOCOL          *This,
+  IN OUT EFI_SIMPLE_POINTER_STATE         *State
+  )
+{
+  GOP_PRIVATE_DATA  *Private;
+  EFI_STATUS        Status;
+  EFI_TPL           OldTpl;
+
+  Private = GOP_PRIVATE_DATA_FROM_POINTER_MODE_THIS (This);
+  if (Private->EmuGraphicsWindow == NULL) {
+    return EFI_NOT_READY;
+  }
+
+  //
+  // Enter critical section
+  //
+  OldTpl  = gBS->RaiseTPL (TPL_NOTIFY);
+
+  Status  = Private->EmuGraphicsWindow->GetPointerState (Private->EmuGraphicsWindow, State);
+  //
+  // Leave critical section and return
+  //
+  gBS->RestoreTPL (OldTpl);
+
+  return Status;
+}
+
+
+/**
+  SimplePointer Notify Wait Event 
+
+  @param  Event                 Event whose notification function is being invoked.
+  @param  Context               Pointer to GOP_PRIVATE_DATA.
+
+**/
+VOID
+EFIAPI
+EmuGopSimplePointerWaitForInput (
+  IN EFI_EVENT          Event,
+  IN VOID               *Context
+  )
+{
+  GOP_PRIVATE_DATA  *Private;
+  EFI_STATUS        Status;
+  EFI_TPL           OldTpl;
+
+  Private = (GOP_PRIVATE_DATA *) Context;
+  if (Private->EmuGraphicsWindow == NULL) {
+    return;
+  }
+
+  //
+  // Enter critical section
+  //
+  OldTpl  = gBS->RaiseTPL (TPL_NOTIFY);
+
+  Status  = Private->EmuGraphicsWindow->CheckPointer (Private->EmuGraphicsWindow);
+  if (!EFI_ERROR (Status)) {
+    //
+    // If the pointer state has changed, signal our event.
+    //
+    gBS->SignalEvent (Event);
+  }
+  //
+  // Leave critical section and return
+  //
+  gBS->RestoreTPL (OldTpl);
+}
+
+
+/**
+  SimplePointer constructor 
+
+  @param  Private Context structure to fill in.      
+
+  @retval EFI_SUCCESS Constructor had success        
+
+**/
+EFI_STATUS
+EmuGopInitializeSimplePointerForWindow (
+  IN  GOP_PRIVATE_DATA    *Private
+  )
+{
+  EFI_STATUS  Status;
+
+  //
+  // Initialize Simple Pointer protoocol
+  //
+  Private->PointerMode.ResolutionX = 1;
+  Private->PointerMode.ResolutionY = 1;
+  Private->PointerMode.ResolutionZ = 1;
+  Private->PointerMode.LeftButton  = TRUE;
+  Private->PointerMode.RightButton = TRUE;
+
+  Private->SimplePointer.Reset     = EmuGopSimplePointerReset;
+  Private->SimplePointer.GetState  = EmuGopSimplePointerGetState;
+  Private->SimplePointer.Mode      = &Private->PointerMode;
+
+  Status = gBS->CreateEvent (
+                  EVT_NOTIFY_WAIT,
+                  TPL_NOTIFY,
+                  EmuGopSimplePointerWaitForInput,
+                  Private,
+                  &Private->SimplePointer.WaitForInput
+                  );
+
+  return Status;
+}
diff --git a/InOsEmuPkg/EmuGopDxe/GopScreen.c b/InOsEmuPkg/EmuGopDxe/GopScreen.c
new file mode 100644 (file)
index 0000000..e7e58ad
--- /dev/null
@@ -0,0 +1,420 @@
+/*++ @file
+
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+Portions copyright (c) 2010 - 2011, Apple Inc. 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:
+
+    EmuGopScreen.c
+
+Abstract:
+
+  This file produces the graphics abstration of UGA. It is called by
+  EmuGopDriver.c file which deals with the EFI 1.1 driver model.
+  This file just does graphics.
+
+**/
+
+#include "Gop.h"
+
+
+EFI_EVENT               mGopScreenExitBootServicesEvent;
+
+GOP_MODE_DATA mGopModeData[] = {
+    { 800,  600, 0, 0 },
+    { 640,  480, 0, 0 },
+    { 720,  400, 0, 0 },
+    {1024,  768, 0, 0 },
+    {1280, 1024, 0, 0 }
+    };
+
+
+/**
+  Returns information for an available graphics mode that the graphics device
+  and the set of active video output devices supports.
+
+  @param  This                  The EFI_GRAPHICS_OUTPUT_PROTOCOL instance.
+  @param  ModeNumber            The mode number to return information on.
+  @param  SizeOfInfo            A pointer to the size, in bytes, of the Info buffer.
+  @param  Info                  A pointer to callee allocated buffer that returns information about ModeNumber.
+
+  @retval EFI_SUCCESS           Mode information returned.
+  @retval EFI_BUFFER_TOO_SMALL  The Info buffer was too small.
+  @retval EFI_DEVICE_ERROR      A hardware error occurred trying to retrieve the video mode.
+  @retval EFI_NOT_STARTED       Video display is not initialized. Call SetMode ()
+  @retval EFI_INVALID_PARAMETER One of the input args was NULL.
+
+**/
+EFI_STATUS
+EFIAPI
+EmuGopQuerytMode (
+  IN  EFI_GRAPHICS_OUTPUT_PROTOCOL          *This,
+  IN  UINT32                                ModeNumber,
+  OUT UINTN                                 *SizeOfInfo,
+  OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  **Info
+  )
+{
+  GOP_PRIVATE_DATA  *Private;
+
+  Private = GOP_PRIVATE_DATA_FROM_THIS (This);
+
+  if (Info == NULL || SizeOfInfo == NULL || (UINTN) ModeNumber >= This->Mode->MaxMode) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  *Info = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
+  if (*Info == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  *SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
+
+  (*Info)->Version = 0;
+  (*Info)->HorizontalResolution = Private->ModeData[ModeNumber].HorizontalResolution;
+  (*Info)->VerticalResolution   = Private->ModeData[ModeNumber].VerticalResolution;
+  (*Info)->PixelFormat = PixelBltOnly;
+  (*Info)->PixelsPerScanLine = (*Info)->HorizontalResolution;
+
+  return EFI_SUCCESS;
+}
+
+
+
+/**
+  Set the video device into the specified mode and clears the visible portions of 
+  the output display to black.
+
+  @param  This              The EFI_GRAPHICS_OUTPUT_PROTOCOL instance.
+  @param  ModeNumber        Abstraction that defines the current video mode.
+
+  @retval EFI_SUCCESS       The graphics mode specified by ModeNumber was selected.
+  @retval EFI_DEVICE_ERROR  The device had an error and could not complete the request.
+  @retval EFI_UNSUPPORTED   ModeNumber is not supported by this device.
+
+**/
+EFI_STATUS
+EFIAPI
+EmuGopSetMode (
+  IN  EFI_GRAPHICS_OUTPUT_PROTOCOL  *This,
+  IN  UINT32                        ModeNumber
+  )
+{
+  EFI_STATUS                      Status;
+  GOP_PRIVATE_DATA                *Private;
+  GOP_MODE_DATA                   *ModeData;
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL   Fill;
+
+  Private = GOP_PRIVATE_DATA_FROM_THIS (This);
+
+  if (ModeNumber >= This->Mode->MaxMode) {
+    return EFI_UNSUPPORTED;
+  }
+
+  ModeData = &Private->ModeData[ModeNumber];
+  This->Mode->Mode = ModeNumber;
+  Private->GraphicsOutput.Mode->Info->HorizontalResolution = ModeData->HorizontalResolution;
+  Private->GraphicsOutput.Mode->Info->VerticalResolution = ModeData->VerticalResolution;
+  Private->GraphicsOutput.Mode->Info->PixelsPerScanLine = ModeData->HorizontalResolution;
+
+  if (Private->HardwareNeedsStarting) {
+    Status = EmuGopStartWindow (
+              Private,
+              ModeData->HorizontalResolution,
+              ModeData->VerticalResolution,
+              ModeData->ColorDepth,
+              ModeData->RefreshRate
+              );
+    if (EFI_ERROR (Status)) {
+      return EFI_DEVICE_ERROR;
+    }
+
+    Private->HardwareNeedsStarting = FALSE;
+  }
+  
+  
+  Status = Private->EmuGraphicsWindow->Size(
+                            Private->EmuGraphicsWindow,
+                            ModeData->HorizontalResolution,
+                            ModeData->VerticalResolution
+                            );
+
+
+  Fill.Red                      = 0x7f;
+  Fill.Green                    = 0x7F;
+  Fill.Blue                     = 0x7f;
+  This->Blt (
+          This,
+          &Fill,
+          EfiBltVideoFill,
+          0,
+          0,
+          0,
+          0,
+          ModeData->HorizontalResolution,
+          ModeData->VerticalResolution,
+          ModeData->HorizontalResolution * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
+          );
+  return EFI_SUCCESS;
+}
+
+
+
+/**
+  Blt a rectangle of pixels on the graphics screen. Blt stands for BLock Transfer.
+  
+  @param  This         Protocol instance pointer.
+  @param  BltBuffer    Buffer containing data to blit into video buffer. This
+                       buffer has a size of Width*Height*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
+  @param  BltOperation Operation to perform on BlitBuffer and video memory
+  @param  SourceX      X coordinate of source for the BltBuffer.
+  @param  SourceY      Y coordinate of source for the BltBuffer.
+  @param  DestinationX X coordinate of destination for the BltBuffer.
+  @param  DestinationY Y coordinate of destination for the BltBuffer.
+  @param  Width        Width of rectangle in BltBuffer in pixels.
+  @param  Height       Hight of rectangle in BltBuffer in pixels.
+  @param  Delta        OPTIONAL
+
+  @retval EFI_SUCCESS           The Blt operation completed.
+  @retval EFI_INVALID_PARAMETER BltOperation is not valid.
+  @retval EFI_DEVICE_ERROR      A hardware error occured writting to the video buffer.
+
+**/
+EFI_STATUS
+EFIAPI
+EmuGopBlt (
+  IN  EFI_GRAPHICS_OUTPUT_PROTOCOL            *This,
+  IN  EFI_GRAPHICS_OUTPUT_BLT_PIXEL           *BltBuffer,   OPTIONAL
+  IN  EFI_GRAPHICS_OUTPUT_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
+  )
+{
+  GOP_PRIVATE_DATA  *Private;
+  EFI_TPL           OriginalTPL;
+  EFI_STATUS        Status;
+  EMU_GRAPHICS_WINDOWS__BLT_ARGS      GopBltArgs;
+
+  Private = GOP_PRIVATE_DATA_FROM_THIS (This);
+
+  if ((BltOperation < 0) || (BltOperation >= EfiGraphicsOutputBltOperationMax)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (Width == 0 || Height == 0) {
+    return EFI_INVALID_PARAMETER;
+  }
+  //
+  // If Delta is zero, then the entire BltBuffer is being used, so Delta
+  // is the number of bytes in each row of BltBuffer.  Since BltBuffer is Width pixels size,
+  // the number of bytes in each row can be computed.
+  //
+  if (Delta == 0) {
+    Delta = Width * sizeof (EFI_UGA_PIXEL);
+  }
+
+  //
+  // We have to raise to TPL Notify, so we make an atomic write the frame buffer.
+  // We would not want a timer based event (Cursor, ...) to come in while we are
+  // doing this operation.
+  //
+  OriginalTPL = gBS->RaiseTPL (TPL_NOTIFY);
+
+  //
+  // Pack UGA Draw protocol parameters to EMU_GRAPHICS_WINDOWS__BLT_ARGS structure to adapt to
+  // GopBlt() API of Unix UGA IO protocol.
+  //
+  GopBltArgs.DestinationX = DestinationX;
+  GopBltArgs.DestinationY = DestinationY;
+  GopBltArgs.Height       = Height;
+  GopBltArgs.Width        = Width;
+  GopBltArgs.SourceX      = SourceX;
+  GopBltArgs.SourceY      = SourceY;
+  GopBltArgs.Delta        = Delta;
+  Status = Private->EmuGraphicsWindow->Blt (
+                            Private->EmuGraphicsWindow,
+                            (EFI_UGA_PIXEL *)BltBuffer,
+                            (EFI_UGA_BLT_OPERATION)BltOperation,
+                            &GopBltArgs
+                            );
+
+  gBS->RestoreTPL (OriginalTPL);
+
+  return Status;
+}
+
+
+//
+// Construction and Destruction functions
+//
+
+EFI_STATUS
+EmuGopSupported (
+  IN  EMU_IO_THUNK_PROTOCOL  *EmuIoThunk
+  )
+{
+  //
+  // Check to see if the IO abstraction represents a device type we support.
+  //
+  // This would be replaced a check of PCI subsystem ID, etc.
+  //
+  if (!CompareGuid (EmuIoThunk->Protocol, &gEmuGraphicsWindowProtocolGuid)) {
+    return EFI_UNSUPPORTED;
+  }
+
+  return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+EmuGopStartWindow (
+  IN  GOP_PRIVATE_DATA    *Private,
+  IN  UINT32              HorizontalResolution,
+  IN  UINT32              VerticalResolution,
+  IN  UINT32              ColorDepth,
+  IN  UINT32              RefreshRate
+  )
+{
+  EFI_STATUS          Status;
+
+  //
+  // Register to be notified on exit boot services so we can destroy the window.
+  //
+  Status = gBS->CreateEvent (
+                  EVT_SIGNAL_EXIT_BOOT_SERVICES,
+                  TPL_CALLBACK,
+                  ShutdownGopEvent,
+                  Private,
+                  &mGopScreenExitBootServicesEvent
+                  );
+
+  Status = Private->EmuIoThunk->Open (Private->EmuIoThunk);
+  if (!EFI_ERROR (Status)) {
+    Private->EmuGraphicsWindow = Private->EmuIoThunk->Interface;
+    
+    // Register callback to support RegisterKeyNotify()
+    Status  = Private->EmuGraphicsWindow->RegisterKeyNotify (
+                                            Private->EmuGraphicsWindow, 
+                                            GopPrivateMakeCallbackFunction, 
+                                            GopPrivateBreakCallbackFunction, 
+                                            Private
+                                            );
+    ASSERT_EFI_ERROR (Status);
+  }
+  return Status;
+}
+
+EFI_STATUS
+EmuGopConstructor (
+  GOP_PRIVATE_DATA    *Private
+  )
+{
+  Private->ModeData = mGopModeData;
+
+  Private->GraphicsOutput.QueryMode      = EmuGopQuerytMode;
+  Private->GraphicsOutput.SetMode        = EmuGopSetMode;
+  Private->GraphicsOutput.Blt            = EmuGopBlt;
+
+  //
+  // Allocate buffer for Graphics Output Protocol mode information
+  //
+  Private->GraphicsOutput.Mode = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE));
+  if (Private->GraphicsOutput.Mode == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+  Private->GraphicsOutput.Mode->Info = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
+  if (Private->GraphicsOutput.Mode->Info == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  Private->GraphicsOutput.Mode->MaxMode = sizeof(mGopModeData) / sizeof(GOP_MODE_DATA);
+  //
+  // Till now, we have no idea about the window size.
+  //
+  Private->GraphicsOutput.Mode->Mode = GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER;
+  Private->GraphicsOutput.Mode->Info->Version = 0;
+  Private->GraphicsOutput.Mode->Info->HorizontalResolution = 0;
+  Private->GraphicsOutput.Mode->Info->VerticalResolution = 0;
+  Private->GraphicsOutput.Mode->Info->PixelFormat = PixelBltOnly;
+  Private->GraphicsOutput.Mode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
+  Private->GraphicsOutput.Mode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) (UINTN) NULL;
+  Private->GraphicsOutput.Mode->FrameBufferSize = 0;
+
+  Private->HardwareNeedsStarting  = TRUE;
+  Private->EmuGraphicsWindow                  = NULL;
+
+  EmuGopInitializeSimpleTextInForWindow (Private);
+
+  EmuGopInitializeSimplePointerForWindow (Private);
+
+  return EFI_SUCCESS;
+}
+
+
+
+EFI_STATUS
+EmuGopDestructor (
+  GOP_PRIVATE_DATA     *Private
+  )
+{
+  EFI_STATUS  Status;
+  
+  Status = EFI_SUCCESS;
+  if (!Private->HardwareNeedsStarting) {
+    Status = Private->EmuIoThunk->Open (Private->EmuIoThunk);
+    Private->EmuGraphicsWindow = NULL;
+  }
+
+  //
+  // Free graphics output protocol occupied resource
+  //
+  if (Private->GraphicsOutput.Mode != NULL) {
+    if (Private->GraphicsOutput.Mode->Info != NULL) {
+      FreePool (Private->GraphicsOutput.Mode->Info);
+    }
+    FreePool (Private->GraphicsOutput.Mode);
+  }
+
+  return EFI_SUCCESS;
+}
+
+
+VOID
+EFIAPI
+ShutdownGopEvent (
+  IN EFI_EVENT  Event,
+  IN VOID       *Context
+  )
+/*++
+
+Routine Description:
+
+  This is the UGA screen's callback notification function for exit-boot-services.
+  All we do here is call EmuGopDestructor().
+
+Arguments:
+
+  Event   - not used
+  Context - pointer to the Private structure.
+
+Returns:
+
+  None.
+
+**/
+{
+  EFI_STATUS  Status;
+  Status = EmuGopDestructor (Context);
+}
+
diff --git a/InOsEmuPkg/EmuSimpleFileSystemDxe/ComponentName.c b/InOsEmuPkg/EmuSimpleFileSystemDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..fa6404a
--- /dev/null
@@ -0,0 +1,244 @@
+/** @file\r
+\r
+Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+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
+#include "EmuSimpleFileSystem.h"\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSimpleFileSystemComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSimpleFileSystemComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                                        *This,\r
+  IN  EFI_HANDLE                                                         ControllerHandle,\r
+  IN  EFI_HANDLE                                                         ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                                              *Language,\r
+  OUT CHAR16                                                             **ControllerName\r
+  );\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL  gEmuSimpleFileSystemComponentName = {\r
+  EmuSimpleFileSystemComponentNameGetDriverName,\r
+  EmuSimpleFileSystemComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL  gEmuSimpleFileSystemComponentName2 = {\r
+  (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)EmuSimpleFileSystemComponentNameGetDriverName,\r
+  (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)EmuSimpleFileSystemComponentNameGetControllerName,\r
+  "en"\r
+};\r
+\r
+EFI_UNICODE_STRING_TABLE mEmuSimpleFileSystemDriverNameTable[] = {\r
+  {\r
+    "eng;en",\r
+    L"Emu Simple File System Driver"\r
+  },\r
+  {\r
+    NULL,\r
+    NULL\r
+  }\r
+};\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the driver.\r
+\r
+  This function retrieves the user readable name of a driver in the form of a\r
+  Unicode string. If the driver specified by This has a user readable name in\r
+  the language specified by Language, then a pointer to the driver name is\r
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
+  by This does not support the language specified by Language,\r
+  then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language. This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified\r
+                                in RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  DriverName[out]       A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                driver specified by This in the language\r
+                                specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
+                                This and the language specified by Language was\r
+                                returned in DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSimpleFileSystemComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+{\r
+  return LookupUnicodeString2 (\r
+          Language,\r
+          This->SupportedLanguages,\r
+          mEmuSimpleFileSystemDriverNameTable,\r
+          DriverName,\r
+          (BOOLEAN)(This == &gEmuSimpleFileSystemComponentName)\r
+          );\r
+}\r
+\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by a driver.\r
+\r
+  This function retrieves the user readable name of the controller specified by\r
+  ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
+  driver specified by This has a user readable name in the language specified by\r
+  Language, then a pointer to the controller name is returned in ControllerName,\r
+  and EFI_SUCCESS is returned.  If the driver specified by This is not currently\r
+  managing the controller specified by ControllerHandle and ChildHandle,\r
+  then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
+  support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  ControllerHandle[in]  The handle of a controller that the driver\r
+                                specified by This is managing.  This handle\r
+                                specifies the controller whose name is to be\r
+                                returned.\r
+\r
+  @param  ChildHandle[in]       The handle of the child controller to retrieve\r
+                                the name of.  This is an optional parameter that\r
+                                may be NULL.  It will be NULL for device\r
+                                drivers.  It will also be NULL for a bus drivers\r
+                                that wish to retrieve the name of the bus\r
+                                controller.  It will not be NULL for a bus\r
+                                driver that wishes to retrieve the name of a\r
+                                child controller.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language.  This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified in\r
+                                RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  ControllerName[out]   A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                controller specified by ControllerHandle and\r
+                                ChildHandle in the language specified by\r
+                                Language from the point of view of the driver\r
+                                specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name in\r
+                                the language specified by Language for the\r
+                                driver specified by This was returned in\r
+                                DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+                                EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
+                                managing the controller specified by\r
+                                ControllerHandle and ChildHandle.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSimpleFileSystemComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                                        *This,\r
+  IN  EFI_HANDLE                                                         ControllerHandle,\r
+  IN  EFI_HANDLE                                                         ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                                              *Language,\r
+  OUT CHAR16                                                             **ControllerName\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL   *SimpleFileSystem;\r
+  EMU_SIMPLE_FILE_SYSTEM_PRIVATE    *Private;\r
+\r
+  //\r
+  // This is a device driver, so ChildHandle must be NULL.\r
+  //\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Make sure this driver is currently managing ControllerHandle\r
+  //\r
+  Status = EfiTestManagedDevice (\r
+             ControllerHandle,\r
+             gEmuSimpleFileSystemDriverBinding.DriverBindingHandle,\r
+             &gEmuIoThunkProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiSimpleFileSystemProtocolGuid,\r
+                  (VOID**)&SimpleFileSystem,\r
+                  gEmuSimpleFileSystemDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (SimpleFileSystem);\r
+\r
+  return LookupUnicodeString2 (\r
+          Language,\r
+          This->SupportedLanguages,\r
+          Private->ControllerNameTable,\r
+          ControllerName,\r
+          (BOOLEAN)(This == &gEmuSimpleFileSystemComponentName)\r
+          );\r
+}\r
diff --git a/InOsEmuPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystem.c b/InOsEmuPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystem.c
new file mode 100644 (file)
index 0000000..b7181fd
--- /dev/null
@@ -0,0 +1,914 @@
+/*++ @file\r
+  Produce Simple File System abstractions for directories on your PC using Posix APIs.\r
+  The configuration of what devices to mount or emulate comes from UNIX \r
+  environment variables. The variables must be visible to the Microsoft* \r
+  Developer Studio for them to work.\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+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
+#include "EmuSimpleFileSystem.h"\r
+\r
+\r
+\r
+\r
+/**\r
+  Opens a new file relative to the source file's location.\r
+\r
+  @param  This       The protocol instance pointer.\r
+  @param  NewHandle  Returns File Handle for FileName.\r
+  @param  FileName   Null terminated string. "\", ".", and ".." are supported.\r
+  @param  OpenMode   Open mode for file.\r
+  @param  Attributes Only used for EFI_FILE_MODE_CREATE.\r
+\r
+  @retval EFI_SUCCESS          The device was opened.\r
+  @retval EFI_NOT_FOUND        The specified file could not be found on the device.\r
+  @retval EFI_NO_MEDIA         The device has no media.\r
+  @retval EFI_MEDIA_CHANGED    The media has changed.\r
+  @retval EFI_DEVICE_ERROR     The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
+  @retval EFI_ACCESS_DENIED    The service denied access to the file.\r
+  @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.\r
+  @retval EFI_VOLUME_FULL      The volume is full.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSimpleFileSystemOpen (\r
+  IN  EFI_FILE_PROTOCOL   *This,\r
+  OUT EFI_FILE_PROTOCOL   **NewHandle,\r
+  IN  CHAR16              *FileName,\r
+  IN  UINT64              OpenMode,\r
+  IN  UINT64              Attributes\r
+  )\r
+{\r
+  EMU_EFI_FILE_PRIVATE              *PrivateFile;\r
+\r
+  //\r
+  // Check for obvious invalid parameters.\r
+  //\r
+  if (This == NULL || NewHandle == NULL || FileName == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  switch (OpenMode) {\r
+  case EFI_FILE_MODE_CREATE | EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:\r
+    if (Attributes &~EFI_FILE_VALID_ATTR) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    if (Attributes & EFI_FILE_READ_ONLY) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+  //\r
+  // fall through\r
+  //\r
+  case EFI_FILE_MODE_READ:\r
+  case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:\r
+    break;\r
+\r
+  default:\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  PrivateFile     = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  return PrivateFile->Io->Open (PrivateFile->Io, NewHandle, FileName, OpenMode, Attributes);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Close the file handle\r
+\r
+  @param  This          Protocol instance pointer.\r
+\r
+  @retval EFI_SUCCESS   The file was closed.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSimpleFileSystemClose (\r
+  IN EFI_FILE_PROTOCOL  *This\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_EFI_FILE_PRIVATE    *PrivateFile;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Status = PrivateFile->Io->Close (PrivateFile->Io);\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->FreePool (PrivateFile);\r
+  }\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  \r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Close and delete the file handle.\r
+\r
+  @param  This                     Protocol instance pointer.\r
+                                   \r
+  @retval EFI_SUCCESS              The file was closed and deleted.\r
+  @retval EFI_WARN_DELETE_FAILURE  The handle was closed but the file was not deleted.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSimpleFileSystemDelete (\r
+  IN EFI_FILE_PROTOCOL  *This\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_EFI_FILE_PRIVATE    *PrivateFile;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  \r
+  PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Status = PrivateFile->Io->Delete (PrivateFile->Io);\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->FreePool (PrivateFile);\r
+  }\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Read data from the file.\r
+\r
+  @param  This       Protocol instance pointer.\r
+  @param  BufferSize On input size of buffer, on output amount of data in buffer.\r
+  @param  Buffer     The buffer in which data is read.\r
+\r
+  @retval EFI_SUCCESS          Data was read.\r
+  @retval EFI_NO_MEDIA         The device has no media.\r
+  @retval EFI_DEVICE_ERROR     The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
+  @retval EFI_BUFFER_TO_SMALL  BufferSize is too small. BufferSize contains required size.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSimpleFileSystemRead (\r
+  IN     EFI_FILE_PROTOCOL  *This,\r
+  IN OUT UINTN              *BufferSize,\r
+  OUT    VOID               *Buffer\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_EFI_FILE_PRIVATE    *PrivateFile;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  if (This == NULL || BufferSize == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  if ((*BufferSize != 0) && (Buffer == NULL)) {\r
+    // Buffer can be NULL  if *BufferSize is zero\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  \r
+  PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Status = PrivateFile->Io->Read (PrivateFile->Io, BufferSize, Buffer);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Write data to a file.\r
+\r
+  @param  This       Protocol instance pointer.\r
+  @param  BufferSize On input size of buffer, on output amount of data in buffer.\r
+  @param  Buffer     The buffer in which data to write.\r
+\r
+  @retval EFI_SUCCESS          Data was written.\r
+  @retval EFI_UNSUPPORTED      Writes to Open directory are not supported.\r
+  @retval EFI_NO_MEDIA         The device has no media.\r
+  @retval EFI_DEVICE_ERROR     The device reported an error.\r
+  @retval EFI_DEVICE_ERROR     An attempt was made to write to a deleted file.\r
+  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED  The device is write protected.\r
+  @retval EFI_ACCESS_DENIED    The file was open for read only.\r
+  @retval EFI_VOLUME_FULL      The volume is full.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSimpleFileSystemWrite (\r
+  IN     EFI_FILE_PROTOCOL  *This,\r
+  IN OUT UINTN              *BufferSize,\r
+  IN     VOID               *Buffer\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EMU_EFI_FILE_PRIVATE *PrivateFile;\r
+  EFI_TPL               OldTpl;\r
+\r
+  if (This == NULL || BufferSize == NULL || Buffer == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Status = PrivateFile->Io->Write (PrivateFile->Io, BufferSize, Buffer);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Set a files current position\r
+\r
+  @param  This            Protocol instance pointer.\r
+  @param  Position        Byte position from the start of the file.\r
+                          \r
+  @retval EFI_SUCCESS     Position was updated.\r
+  @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSimpleFileSystemGetPosition (\r
+  IN  EFI_FILE_PROTOCOL   *This,\r
+  OUT UINT64              *Position\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EMU_EFI_FILE_PRIVATE *PrivateFile;\r
+  EFI_TPL               OldTpl;\r
+\r
+  if (This == NULL || Position == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  \r
+  PrivateFile   = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Status = PrivateFile->Io->GetPosition (PrivateFile->Io, Position);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Get a file's current position\r
+\r
+  @param  This            Protocol instance pointer.\r
+  @param  Position        Byte position from the start of the file.\r
+                          \r
+  @retval EFI_SUCCESS     Position was updated.\r
+  @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open..\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSimpleFileSystemSetPosition (\r
+  IN EFI_FILE_PROTOCOL  *This,\r
+  IN UINT64             Position\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_EFI_FILE_PRIVATE    *PrivateFile;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  \r
+  PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Status = PrivateFile->Io->SetPosition (PrivateFile->Io, Position);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Get information about a file.\r
+\r
+  @param  This            Protocol instance pointer.\r
+  @param  InformationType Type of information to return in Buffer.\r
+  @param  BufferSize      On input size of buffer, on output amount of data in buffer.\r
+  @param  Buffer          The buffer to return data.\r
+\r
+  @retval EFI_SUCCESS          Data was returned.\r
+  @retval EFI_UNSUPPORTED      InformationType is not supported.\r
+  @retval EFI_NO_MEDIA         The device has no media.\r
+  @retval EFI_DEVICE_ERROR     The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED  The device is write protected.\r
+  @retval EFI_ACCESS_DENIED    The file was open for read only.\r
+  @retval EFI_BUFFER_TOO_SMALL Buffer was too small; required size returned in BufferSize.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSimpleFileSystemGetInfo (\r
+  IN     EFI_FILE_PROTOCOL  *This,\r
+  IN     EFI_GUID           *InformationType,\r
+  IN OUT UINTN              *BufferSize,\r
+  OUT    VOID               *Buffer\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  EMU_EFI_FILE_PRIVATE              *PrivateFile;\r
+  EFI_TPL                           OldTpl;\r
+\r
+  if (This == NULL || InformationType == NULL || BufferSize == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+    \r
+  PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Status = PrivateFile->Io->GetInfo (PrivateFile->Io, InformationType, BufferSize, Buffer);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Set information about a file\r
+\r
+  @param  File            Protocol instance pointer.\r
+  @param  InformationType Type of information in Buffer.\r
+  @param  BufferSize      Size of buffer.\r
+  @param  Buffer          The data to write.\r
+\r
+  @retval EFI_SUCCESS          Data was set.\r
+  @retval EFI_UNSUPPORTED      InformationType is not supported.\r
+  @retval EFI_NO_MEDIA         The device has no media.\r
+  @retval EFI_DEVICE_ERROR     The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED  The device is write protected.\r
+  @retval EFI_ACCESS_DENIED    The file was open for read only.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSimpleFileSystemSetInfo (\r
+  IN EFI_FILE_PROTOCOL*This,\r
+  IN EFI_GUID         *InformationType,\r
+  IN UINTN            BufferSize,\r
+  IN VOID             *Buffer\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  EMU_EFI_FILE_PRIVATE              *PrivateFile;\r
+  EFI_TPL                           OldTpl;\r
+\r
+  //\r
+  // Check for invalid parameters.\r
+  //\r
+  if (This == NULL || InformationType == NULL || BufferSize == 0 || Buffer == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  \r
+  PrivateFile               = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Status = PrivateFile->Io->SetInfo (PrivateFile->Io, InformationType, BufferSize, Buffer);\r
+\r
+  gBS->RestoreTPL (OldTpl);  \r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Flush data back for the file handle.\r
+\r
+  @param  This Protocol instance pointer.\r
+\r
+  @retval EFI_SUCCESS          Data was flushed.\r
+  @retval EFI_UNSUPPORTED      Writes to Open directory are not supported.\r
+  @retval EFI_NO_MEDIA         The device has no media.\r
+  @retval EFI_DEVICE_ERROR     The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED  The device is write protected.\r
+  @retval EFI_ACCESS_DENIED    The file was open for read only.\r
+  @retval EFI_VOLUME_FULL      The volume is full.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSimpleFileSystemFlush (\r
+  IN EFI_FILE_PROTOCOL  *This\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EMU_EFI_FILE_PRIVATE      *PrivateFile;\r
+  EFI_TPL                   OldTpl;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  \r
+  PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Status = PrivateFile->Io->Flush (PrivateFile->Io);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Open the root directory on a volume.\r
+\r
+  @param  This Protocol instance pointer.\r
+  @param  Root Returns an Open file handle for the root directory\r
+\r
+  @retval EFI_SUCCESS          The device was opened.\r
+  @retval EFI_UNSUPPORTED      This volume does not support the file system.\r
+  @retval EFI_NO_MEDIA         The device has no media.\r
+  @retval EFI_DEVICE_ERROR     The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
+  @retval EFI_ACCESS_DENIED    The service denied access to the file.\r
+  @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSimpleFileSystemOpenVolume (\r
+  IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL  *This,\r
+  OUT EFI_FILE_PROTOCOL               **Root\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  EMU_SIMPLE_FILE_SYSTEM_PRIVATE    *Private;\r
+  EMU_EFI_FILE_PRIVATE              *PrivateFile;\r
+  EFI_TPL                           OldTpl;\r
+\r
+  if (This == NULL || Root == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Private = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  PrivateFile = AllocatePool (sizeof (EMU_EFI_FILE_PRIVATE));\r
+  if (PrivateFile == NULL) {\r
+    goto Done;\r
+  }\r
+  \r
+  PrivateFile->Signature            = EMU_EFI_FILE_PRIVATE_SIGNATURE;\r
+  PrivateFile->IoThunk              = Private->IoThunk;\r
+  PrivateFile->SimpleFileSystem     = This;\r
+  PrivateFile->EfiFile.Revision     = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;\r
+  PrivateFile->EfiFile.Open         = EmuSimpleFileSystemOpen;\r
+  PrivateFile->EfiFile.Close        = EmuSimpleFileSystemClose;\r
+  PrivateFile->EfiFile.Delete       = EmuSimpleFileSystemDelete;\r
+  PrivateFile->EfiFile.Read         = EmuSimpleFileSystemRead;\r
+  PrivateFile->EfiFile.Write        = EmuSimpleFileSystemWrite;\r
+  PrivateFile->EfiFile.GetPosition  = EmuSimpleFileSystemGetPosition;\r
+  PrivateFile->EfiFile.SetPosition  = EmuSimpleFileSystemSetPosition;\r
+  PrivateFile->EfiFile.GetInfo      = EmuSimpleFileSystemGetInfo;\r
+  PrivateFile->EfiFile.SetInfo      = EmuSimpleFileSystemSetInfo;\r
+  PrivateFile->EfiFile.Flush        = EmuSimpleFileSystemFlush;\r
+\r
+  *Root = &PrivateFile->EfiFile;\r
+\r
+  Status = Private->Io->OpenVolume (Private->Io, &PrivateFile->Io);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+  \r
+  AddUnicodeString2 (\r
+    "eng",\r
+    gEmuSimpleFileSystemComponentName.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    Private->IoThunk->ConfigString,\r
+    TRUE\r
+    );\r
+\r
+  AddUnicodeString2 (\r
+    "en",\r
+    gEmuSimpleFileSystemComponentName.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    Private->IoThunk->ConfigString,\r
+    FALSE\r
+    );\r
+\r
+\r
+Done:\r
+  if (EFI_ERROR (Status)) {\r
+    if (PrivateFile) {\r
+      gBS->FreePool (PrivateFile);\r
+    }\r
+    \r
+    *Root = NULL;\r
+  }\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Tests to see if this driver supports a given controller. If a child device is provided, \r
+  it further tests to see if this driver supports creating a handle for the specified child device.\r
+\r
+  This function checks to see if the driver specified by This supports the device specified by \r
+  ControllerHandle. Drivers will typically use the device path attached to \r
+  ControllerHandle and/or the services from the bus I/O abstraction attached to \r
+  ControllerHandle to determine if the driver supports ControllerHandle. This function \r
+  may be called many times during platform initialization. In order to reduce boot times, the tests \r
+  performed by this function must be very small, and take as little time as possible to execute. This \r
+  function must not change the state of any hardware devices, and this function must be aware that the \r
+  device specified by ControllerHandle may already be managed by the same driver or a \r
+  different driver. This function must match its calls to AllocatePages() with FreePages(), \r
+  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().  \r
+  Because ControllerHandle may have been previously started by the same driver, if a protocol is \r
+  already in the opened state, then it must not be closed with CloseProtocol(). This is required \r
+  to guarantee the state of ControllerHandle is not modified by this function.\r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to test. This handle \r
+                                   must support a protocol interface that supplies \r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This \r
+                                   parameter is ignored by device drivers, and is optional for bus \r
+                                   drivers. For bus drivers, if this parameter is not NULL, then \r
+                                   the bus driver must determine if the bus controller specified \r
+                                   by ControllerHandle and the child controller specified \r
+                                   by RemainingDevicePath are both supported by this \r
+                                   bus driver.\r
+\r
+  @retval EFI_SUCCESS              The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is supported by the driver specified by This.\r
+  @retval EFI_ALREADY_STARTED      The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by the driver\r
+                                   specified by This.\r
+  @retval EFI_ACCESS_DENIED        The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by a different\r
+                                   driver or an application that requires exclusive access.\r
+                                   Currently not implemented.\r
+  @retval EFI_UNSUPPORTED          The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is not supported by the driver specified by This.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSimpleFileSystemDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_IO_THUNK_PROTOCOL  *EmuIoThunk;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (VOID **)&EmuIoThunk,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Make sure GUID is for a File System handle.\r
+  //\r
+  Status = EFI_UNSUPPORTED;\r
+  if (CompareGuid (EmuIoThunk->Protocol, &gEfiSimpleFileSystemProtocolGuid)) {\r
+    Status = EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        &gEmuIoThunkProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        ControllerHandle\r
+        );\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Starts a device controller or a bus controller.\r
+\r
+  The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
+  As a result, much of the error checking on the parameters to Start() has been moved into this \r
+  common boot service. It is legal to call Start() from other locations, \r
+  but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE.\r
+  2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
+     EFI_DEVICE_PATH_PROTOCOL.\r
+  3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
+     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.  \r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to start. This handle \r
+                                   must support a protocol interface that supplies \r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This \r
+                                   parameter is ignored by device drivers, and is optional for bus \r
+                                   drivers. For a bus driver, if this parameter is NULL, then handles \r
+                                   for all the children of Controller are created by this driver.  \r
+                                   If this parameter is not NULL and the first Device Path Node is \r
+                                   not the End of Device Path Node, then only the handle for the \r
+                                   child device specified by the first Device Path Node of \r
+                                   RemainingDevicePath is created by this driver.\r
+                                   If the first Device Path Node of RemainingDevicePath is \r
+                                   the End of Device Path Node, no child handle is created by this\r
+                                   driver.\r
+\r
+  @retval EFI_SUCCESS              The device was started.\r
+  @retval EFI_DEVICE_ERROR         The device could not be started due to a device error.Currently not implemented.\r
+  @retval EFI_OUT_OF_RESOURCES     The request could not be completed due to a lack of resources.\r
+  @retval Others                   The driver failded to start the device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSimpleFileSystemDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  EMU_IO_THUNK_PROTOCOL             *EmuIoThunk;\r
+  EMU_SIMPLE_FILE_SYSTEM_PRIVATE    *Private;\r
+  INTN i;\r
+\r
+  Private = NULL;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (VOID **)&EmuIoThunk,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Validate GUID\r
+  //\r
+  if (!CompareGuid (EmuIoThunk->Protocol, &gEfiSimpleFileSystemProtocolGuid)) {\r
+    Status = EFI_UNSUPPORTED;\r
+    goto Done;\r
+  }\r
+\r
+  Private = AllocatePool (sizeof (EMU_SIMPLE_FILE_SYSTEM_PRIVATE));\r
+  if (Private == NULL) {\r
+    goto Done;\r
+  }\r
+\r
+  Status = EmuIoThunk->Open (EmuIoThunk);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  Private->Signature = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE;\r
+  Private->IoThunk   = EmuIoThunk;\r
+  Private->Io        = EmuIoThunk->Interface;\r
+  \r
+  Private->SimpleFileSystem.Revision    = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;\r
+  Private->SimpleFileSystem.OpenVolume  = EmuSimpleFileSystemOpenVolume;\r
+\r
+  Private->ControllerNameTable = NULL;\r
+\r
+  AddUnicodeString2 (\r
+    "eng",\r
+    gEmuSimpleFileSystemComponentName.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    EmuIoThunk->ConfigString,\r
+    TRUE\r
+    );\r
+    \r
+  AddUnicodeString2 (\r
+    "en",\r
+    gEmuSimpleFileSystemComponentName2.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    EmuIoThunk->ConfigString,\r
+    FALSE\r
+    );\r
+\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &ControllerHandle,\r
+                  &gEfiSimpleFileSystemProtocolGuid,  &Private->SimpleFileSystem,\r
+                  NULL\r
+                  );\r
+\r
+Done:\r
+  if (EFI_ERROR (Status)) {\r
+    if (Private != NULL) {\r
+      if (Private->ControllerNameTable != NULL) {\r
+        FreeUnicodeStringTable (Private->ControllerNameTable);\r
+      }\r
+      \r
+      gBS->FreePool (Private);\r
+    \r
+    }\r
+\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEmuIoThunkProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Stops a device controller or a bus controller.\r
+  \r
+  The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). \r
+  As a result, much of the error checking on the parameters to Stop() has been moved \r
+  into this common boot service. It is legal to call Stop() from other locations, \r
+  but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
+     same driver's Start() function.\r
+  2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
+     EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
+     Start() function, and the Start() function must have called OpenProtocol() on\r
+     ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
+  \r
+  @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must \r
+                                support a bus specific I/O protocol for the driver \r
+                                to use to stop the device.\r
+  @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.\r
+  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL \r
+                                if NumberOfChildren is 0.\r
+\r
+  @retval EFI_SUCCESS           The device was stopped.\r
+  @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSimpleFileSystemDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL   *SimpleFileSystem;\r
+  EMU_SIMPLE_FILE_SYSTEM_PRIVATE    *Private;\r
+\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiSimpleFileSystemProtocolGuid,\r
+                  (VOID **)&SimpleFileSystem,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (SimpleFileSystem);\r
+  Status = Private->IoThunk->Close (Private->IoThunk);\r
+\r
+  //\r
+  // Uninstall the Simple File System Protocol from ControllerHandle\r
+  //\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  ControllerHandle,\r
+                  &gEfiSimpleFileSystemProtocolGuid,  &Private->SimpleFileSystem,\r
+                  NULL\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = gBS->CloseProtocol (\r
+                    ControllerHandle,\r
+                    &gEmuIoThunkProtocolGuid,\r
+                    This->DriverBindingHandle,\r
+                    ControllerHandle\r
+                    );\r
+  }\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Free our instance data\r
+    //\r
+    FreeUnicodeStringTable (Private->ControllerNameTable);\r
+    gBS->FreePool (Private);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gEmuSimpleFileSystemDriverBinding = {\r
+  EmuSimpleFileSystemDriverBindingSupported,\r
+  EmuSimpleFileSystemDriverBindingStart,\r
+  EmuSimpleFileSystemDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+\r
+\r
+\r
+/**\r
+  The user Entry Point for module EmuSimpleFileSystem. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeEmuSimpleFileSystem(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  Status = EfiLibInstallDriverBindingComponentName2 (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gEmuSimpleFileSystemDriverBinding,\r
+             ImageHandle,\r
+             &gEmuSimpleFileSystemComponentName,\r
+             &gEmuSimpleFileSystemComponentName2\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
diff --git a/InOsEmuPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystem.h b/InOsEmuPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystem.h
new file mode 100644 (file)
index 0000000..5a1182c
--- /dev/null
@@ -0,0 +1,80 @@
+/*++ @file\r
+  Produce Simple File System abstractions for a directory on your PC using Unix APIs.\r
+  The configuration of what devices to mount or emulate comes from  \r
+  environment variables.\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+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
+#ifndef _EMU_SIMPLE_FILE_SYSTEM_H_\r
+#define _EMU_SIMPLE_FILE_SYSTEM_H_\r
+\r
+#include "PiDxe.h"\r
+\r
+#include <Guid/FileSystemInfo.h>\r
+#include <Guid/FileInfo.h>\r
+#include <Guid/FileSystemVolumeLabelInfo.h>\r
+\r
+#include <Protocol/EmuIoThunk.h>\r
+#include <Protocol/SimpleFileSystem.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+\r
+extern EFI_DRIVER_BINDING_PROTOCOL  gEmuSimpleFileSystemDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gEmuSimpleFileSystemComponentName;\r
+extern EFI_COMPONENT_NAME2_PROTOCOL gEmuSimpleFileSystemComponentName2;\r
+\r
+#define EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE SIGNATURE_32 ('E', 'M', 'f', 's')\r
+\r
+typedef struct {\r
+  UINTN                           Signature;\r
+  EMU_IO_THUNK_PROTOCOL           *IoThunk;\r
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFileSystem;\r
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Io;\r
+  EFI_UNICODE_STRING_TABLE        *ControllerNameTable;\r
+} EMU_SIMPLE_FILE_SYSTEM_PRIVATE;\r
+\r
+#define EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS(a) \\r
+  CR (a, \\r
+      EMU_SIMPLE_FILE_SYSTEM_PRIVATE, \\r
+      SimpleFileSystem, \\r
+      EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE \\r
+      )\r
+\r
+#define EMU_EFI_FILE_PRIVATE_SIGNATURE SIGNATURE_32 ('e', 'm', 'f', 's')\r
+\r
+typedef struct {\r
+  UINTN                           Signature;\r
+  EMU_IO_THUNK_PROTOCOL           *IoThunk;\r
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;\r
+  EFI_FILE_PROTOCOL               EfiFile;\r
+  EFI_FILE_PROTOCOL               *Io;\r
+} EMU_EFI_FILE_PRIVATE;\r
+\r
+#define EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS(a) \\r
+  CR (a, \\r
+      EMU_EFI_FILE_PRIVATE, \\r
+      EfiFile, \\r
+      EMU_EFI_FILE_PRIVATE_SIGNATURE \\r
+      )\r
+\r
+\r
+\r
+#endif \r
diff --git a/InOsEmuPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystemDxe.inf b/InOsEmuPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystemDxe.inf
new file mode 100644 (file)
index 0000000..f05f156
--- /dev/null
@@ -0,0 +1,55 @@
+## @file\r
+# Simple filesystem driver\r
+#\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = EmuSimpleFileSystem\r
+  FILE_GUID                      = 35B72237-3926-CF4A-A7F3-1449F9E0E4BD\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = InitializeEmuSimpleFileSystem\r
+\r
+\r
+[Sources]\r
+  ComponentName.c\r
+  EmuSimpleFileSystem.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  BaseLib\r
+  DebugLib\r
+\r
+\r
+[Guids]\r
+  gEfiFileSystemVolumeLabelInfoIdGuid           # SOMETIMES_CONSUMED\r
+  gEfiFileInfoGuid                              # SOMETIMES_CONSUMED\r
+  gEfiFileSystemInfoGuid                        # SOMETIMES_CONSUMED\r
+\r
+\r
+[Protocols]\r
+  gEfiSimpleFileSystemProtocolGuid               # PROTOCOL BY_START\r
+  gEmuIoThunkProtocolGuid                        # PROTOCOL TO_START\r
+\r
diff --git a/InOsEmuPkg/EmuThunkDxe/EmuThunk.c b/InOsEmuPkg/EmuThunkDxe/EmuThunk.c
new file mode 100644 (file)
index 0000000..a0661c8
--- /dev/null
@@ -0,0 +1,89 @@
+/*++ @file\r
+\r
+Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+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
+#include <PiDxe.h>\r
+\r
+#include <Protocol/DevicePath.h>\r
+#include <Protocol/EmuThunk.h> \r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/EmuThunkLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DevicePathLib.h>\r
+\r
+//\r
+// EmuThunk Device Path Protocol Instance\r
+//\r
+EMU_THUNK_DEVICE_PATH mEmuThunkDevicePath = {\r
+  {\r
+    {\r
+      {\r
+        HARDWARE_DEVICE_PATH,\r
+        HW_VENDOR_DP,\r
+        {\r
+          (UINT8) (sizeof (EMU_VENDOR_DEVICE_PATH_NODE)),\r
+          (UINT8) ((sizeof (EMU_VENDOR_DEVICE_PATH_NODE)) >> 8)\r
+        }\r
+      },\r
+      EMU_THUNK_PROTOCOL_GUID\r
+    },\r
+    0\r
+  },\r
+  {\r
+    END_DEVICE_PATH_TYPE,\r
+    END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+    {\r
+      END_DEVICE_PATH_LENGTH,\r
+      0\r
+    }\r
+  }\r
+};\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeEmuThunk (\r
+  IN EFI_HANDLE                            ImageHandle,\r
+  IN EFI_SYSTEM_TABLE                      *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Install UnixThunk Protocol and it's associated Device Path protocol\r
+\r
+Arguments:\r
+  (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r
+\r
+Returns:\r
+  EFI_SUCEESS - UnixThunk protocol is added or error status from \r
+                gBS->InstallMultiProtocolInterfaces().\r
+\r
+**/\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_HANDLE  Handle;\r
+\r
+  Handle = NULL;\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Handle,\r
+                  &gEmuThunkProtocolGuid,       gEmuThunk,\r
+                  &gEfiDevicePathProtocolGuid,  &mEmuThunkDevicePath,\r
+                  NULL\r
+                  );\r
+\r
+  return Status;\r
+}\r
diff --git a/InOsEmuPkg/EmuThunkDxe/EmuThunk.inf b/InOsEmuPkg/EmuThunkDxe/EmuThunk.inf
new file mode 100644 (file)
index 0000000..314a6f3
--- /dev/null
@@ -0,0 +1,59 @@
+## @file\r
+#   A DXE driver to produce EMU_THUNK_PROTOCOL\r
+#\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = EmuThunk\r
+  FILE_GUID                      = 2F62A818-4A72-CD40-90B9-FF00DAABEE7B\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = InitializeEmuThunk\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]\r
+  EmuThunk.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  EmuThunkLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  DebugLib\r
+  DevicePathLib\r
+\r
+\r
+\r
+[Protocols]\r
+  gEfiDevicePathProtocolGuid                # PROTOCOL ALWAYS_PRODUCED\r
+  gEmuThunkProtocolGuid                     # PROTOCOL ALWAYS_PRODUCED\r
+\r
+\r
+[Depex]\r
+  TRUE\r
+\r
diff --git a/InOsEmuPkg/FirmwareVolumePei/FirmwareVolumePei.c b/InOsEmuPkg/FirmwareVolumePei/FirmwareVolumePei.c
new file mode 100644 (file)
index 0000000..ec9fe5c
--- /dev/null
@@ -0,0 +1,130 @@
+/*++ @file\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+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
+#include "PiPei.h"\r
+#include <Ppi/EmuThunk.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeimEntryPoint.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PeimInitializeFirmwareVolumePei (\r
+  IN       EFI_PEI_FILE_HANDLE       FileHandle,\r
+  IN CONST EFI_PEI_SERVICES          **PeiServices\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Perform a call-back into the SEC simulator to get address of the Firmware Hub\r
+\r
+Arguments:\r
+  FfsHeader   - Ffs Header availible to every PEIM\r
+  PeiServices - General purpose services available to every PEIM.\r
+    \r
+Returns:\r
+  None\r
+\r
+**/\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_PEI_PPI_DESCRIPTOR      *PpiDescriptor;\r
+  EMU_THUNK_PPI               *Thunk;\r
+  EFI_PHYSICAL_ADDRESS        FdBase;\r
+  EFI_PHYSICAL_ADDRESS        FdFixUp;\r
+  EFI_FIRMWARE_VOLUME_HEADER  *FvHeader;\r
+  UINT64                      FdSize;\r
+  UINTN                       Index;\r
+\r
+  DEBUG ((EFI_D_ERROR, "Unix Firmware Volume PEIM Loaded\n"));\r
+\r
+  //\r
+  // Get the Fwh Information PPI\r
+  //\r
+  Status = PeiServicesLocatePpi (\r
+              &gEmuThunkPpiGuid,  // GUID\r
+              0,                  // INSTANCE\r
+              &PpiDescriptor,     // EFI_PEI_PPI_DESCRIPTOR\r
+              (VOID **)&Thunk     // PPI\r
+              );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Index = 0;\r
+  do {\r
+    //\r
+    // Get information about all the FD's in the system\r
+    //\r
+    Status = Thunk->FirmwareDevices (Index, &FdBase, &FdSize, &FdFixUp);\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Assume the FD starts with an FV header\r
+      //\r
+      FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) FdBase;\r
+\r
+      //\r
+      // Make an FV Hob for the first FV in the FD\r
+      //\r
+      BuildFvHob (FdBase, FvHeader->FvLength);\r
+\r
+      if (Index == 0) {\r
+        //\r
+        // Assume the first FD was produced by the NT32.DSC\r
+        //  All these strange offests are needed to keep in\r
+        //  sync with the FlashMap and NT32.dsc file\r
+        //\r
+        BuildResourceDescriptorHob (\r
+          EFI_RESOURCE_FIRMWARE_DEVICE,\r
+          (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),\r
+          FdBase,\r
+          ( \r
+            FvHeader->FvLength + \r
+            PcdGet32 (PcdFlashNvStorageVariableSize) +\r
+            PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +\r
+            PcdGet32 (PcdFlashNvStorageFtwSpareSize) +\r
+            PcdGet32 (PcdEmuFlashNvStorageEventLogSize)\r
+          )\r
+        );\r
+\r
+        //\r
+        // Hard code the address of the spare block and variable services.\r
+        //  Assume it's a hard coded offset from FV0 in FD0.\r
+        //\r
+        FdSize  = \r
+          PcdGet32 (PcdFlashNvStorageVariableSize) +\r
+          PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +\r
+          PcdGet32 (PcdFlashNvStorageFtwSpareSize) +\r
+          PcdGet32 (PcdEmuFlashNvStorageEventLogSize);\r
+\r
+        BuildFvHob (FdFixUp + PcdGet64 (PcdEmuFlashNvStorageVariableBase), FdSize);\r
+      } else {\r
+        //\r
+        // For other FD's just map them in.\r
+        //\r
+        BuildResourceDescriptorHob (\r
+          EFI_RESOURCE_FIRMWARE_DEVICE,\r
+          (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),\r
+          FdBase,\r
+          FdSize\r
+          );\r
+      }\r
+    }\r
+\r
+    Index++;\r
+  } while (!EFI_ERROR (Status));\r
+\r
+  return Status;\r
+}\r
diff --git a/InOsEmuPkg/FirmwareVolumePei/FirmwareVolumePei.inf b/InOsEmuPkg/FirmwareVolumePei/FirmwareVolumePei.inf
new file mode 100644 (file)
index 0000000..02a4474
--- /dev/null
@@ -0,0 +1,60 @@
+## @file\r
+# Component description file for EmuFwh module\r
+#\r
+# This PEIM will produce the HOB to describe Firmware Volume, Firmware Devices\r
+#  on the Emu emulator.\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = FirmwareVolumePei\r
+  FILE_GUID                      = 6DB075DE-449E-2644-96D0-CC5A1B4C3B2A\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = PeimInitializeFirmwareVolumePei\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]\r
+  FirmwareVolumePei.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+  PeiServicesTablePointerLib\r
+  PeiServicesLib\r
+  HobLib\r
+  PeimEntryPoint\r
+  DebugLib\r
+\r
+[Pcd]\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageEventLogSize\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageVariableBase\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize\r
+\r
+[Ppis]\r
+  gEmuThunkPpiGuid                               # PPI ALWAYS_CONSUMED\r
+\r
+[Depex]\r
+  gEmuThunkPpiGuid AND gEfiPeiMemoryDiscoveredPpiGuid\r
+\r
diff --git a/InOsEmuPkg/FlashMapPei/FlashMapPei.c b/InOsEmuPkg/FlashMapPei/FlashMapPei.c
new file mode 100644 (file)
index 0000000..955c462
--- /dev/null
@@ -0,0 +1,83 @@
+/*++ @file\r
+  PEIM to build GUIDed HOBs for platform specific flash map\r
+\r
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+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
+#include "PiPei.h"\r
+\r
+#include <Guid/SystemNvDataGuid.h>\r
+#include <Ppi/EmuThunk.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeimEntryPoint.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PeimInitializeFlashMap (\r
+  IN       EFI_PEI_FILE_HANDLE       FileHandle,\r
+  IN CONST EFI_PEI_SERVICES          **PeiServices\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Build GUIDed HOBs for platform specific flash map\r
+  \r
+Arguments:\r
+  FfsHeader   - A pointer to the EFI_FFS_FILE_HEADER structure.\r
+  PeiServices - General purpose services available to every PEIM.\r
+    \r
+Returns:\r
+  EFI_STATUS\r
+\r
+**/\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_THUNK_PPI           *Thunk;\r
+  EFI_PEI_PPI_DESCRIPTOR  *PpiDescriptor;\r
+  EFI_PHYSICAL_ADDRESS    FdBase;\r
+  EFI_PHYSICAL_ADDRESS    FdFixUp;\r
+  UINT64                  FdSize;\r
+\r
+  DEBUG ((EFI_D_ERROR, "InOsEmuPkg Flash Map PEIM Loaded\n"));\r
+\r
+  //\r
+  // Get the Fwh Information PPI\r
+  //\r
+  Status = PeiServicesLocatePpi (\r
+            &gEmuThunkPpiGuid, // GUID\r
+            0,                 // INSTANCE\r
+            &PpiDescriptor,     // EFI_PEI_PPI_DESCRIPTOR\r
+            (VOID **)&Thunk       // PPI\r
+            );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Assume that FD0 contains the Flash map.\r
+  //\r
+  Status = Thunk->FirmwareDevices (0, &FdBase, &FdSize, &FdFixUp);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  \r
+  PcdSet64 (PcdFlashNvStorageVariableBase64, PcdGet64 (PcdEmuFlashNvStorageVariableBase) + FdFixUp);\r
+  PcdSet64 (PcdFlashNvStorageFtwWorkingBase64, PcdGet64 (PcdEmuFlashNvStorageFtwWorkingBase) + FdFixUp);\r
+  PcdSet64 (PcdFlashNvStorageFtwSpareBase64, PcdGet64 (PcdEmuFlashNvStorageFtwSpareBase) + FdFixUp);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/InOsEmuPkg/FlashMapPei/FlashMapPei.inf b/InOsEmuPkg/FlashMapPei/FlashMapPei.inf
new file mode 100644 (file)
index 0000000..ed5bc3b
--- /dev/null
@@ -0,0 +1,68 @@
+## @file\r
+# Component description file for FlashMap PEI module\r
+#\r
+# This module installs FlashMap PPI which is used to get flash layout information.\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = FlashMapPei\r
+  FILE_GUID                      = C9FAF091-57F8-A64C-A07A-445B124F0D93\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = PeimInitializeFlashMap\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]\r
+  FlashMapPei.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+  PcdLib\r
+  BaseMemoryLib\r
+  PeiServicesTablePointerLib\r
+  PeiServicesLib\r
+  HobLib\r
+  PeimEntryPoint\r
+  DebugLib\r
+\r
+\r
+[Ppis]\r
+  gEmuThunkPpiGuid                               # PPI ALWAYS_CONSUMED\r
+\r
+[Pcd]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64\r
+\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageFtwWorkingBase\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageFtwSpareBase\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageVariableBase\r
+\r
+[Depex]\r
+  gEmuThunkPpiGuid\r
+\r
diff --git a/InOsEmuPkg/FvbServicesRuntimeDxe/FWBlockService.c b/InOsEmuPkg/FvbServicesRuntimeDxe/FWBlockService.c
new file mode 100644 (file)
index 0000000..a95b180
--- /dev/null
@@ -0,0 +1,1360 @@
+/*++ @file\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+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
+#include "PiDxe.h"\r
+#include <Guid/EventGroup.h>\r
+#include <Protocol/FirmwareVolumeBlock.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/DevicePathLib.h>\r
+\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
+\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);\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 = NULL;\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_2                *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 = NULL;\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 = NULL;\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_2  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_2  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_2  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
+FvbSetVolumeAttributes (\r
+  IN UINTN                                Instance,\r
+  IN OUT EFI_FVB_ATTRIBUTES_2             *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_2 \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 = NULL;\r
+  EFI_FVB_ATTRIBUTES_2  OldAttributes;\r
+  EFI_FVB_ATTRIBUTES_2  *AttribPtr;\r
+  UINT32                Capabilities;\r
+  UINT32                OldStatus;\r
+  UINT32                NewStatus;\r
+  EFI_STATUS            Status;\r
+  EFI_FVB_ATTRIBUTES_2  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_2 *) &(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 CONST 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 CONST 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 CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL     *This,\r
+  OUT EFI_FVB_ATTRIBUTES_2                        *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 CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL     *This,\r
+  IN OUT EFI_FVB_ATTRIBUTES_2                     *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 CONST 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 = NULL;\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 CONST 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 CONST 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
+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 = NULL;\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 (IsDevicePathEnd (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
+    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
+  return EFI_SUCCESS;\r
+}\r
diff --git a/InOsEmuPkg/FvbServicesRuntimeDxe/FvbInfo.c b/InOsEmuPkg/FvbServicesRuntimeDxe/FvbInfo.c
new file mode 100644 (file)
index 0000000..34f2910
--- /dev/null
@@ -0,0 +1,154 @@
+/*++ @file\r
+  Defines data structure that is the volume header found.These data is intent\r
+  to decouple FVB driver with FV header.\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+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
+#include <PiDxe.h>\r
+\r
+#include <Guid/EventGroup.h>\r
+#include <Guid/FirmwareFileSystem2.h>\r
+#include <Guid/SystemNvDataGuid.h>\r
+\r
+#include <Protocol/FirmwareVolumeBlock.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 <Library/DevicePathLib.h>\r
+\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 (PcdEmuFlashFvRecoverySize),\r
+    {\r
+      {\r
+        0,\r
+      },  // ZeroVector[16]\r
+      EFI_FIRMWARE_FILE_SYSTEM2_GUID,\r
+      FixedPcdGet32 (PcdEmuFlashFvRecoverySize),\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
+      2,  // Revision\r
+      {\r
+        {\r
+          FixedPcdGet32 (PcdEmuFlashFvRecoverySize)/FixedPcdGet32 (PcdEmuFirmwareBlockSize),\r
+          FixedPcdGet32 (PcdEmuFirmwareBlockSize),\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 (PcdEmuFlashNvStorageEventLogSize),\r
+    {\r
+      {\r
+        0,\r
+      },  // ZeroVector[16]\r
+      EFI_SYSTEM_NV_DATA_FV_GUID,\r
+      FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \\r
+      FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \\r
+      FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \\r
+      FixedPcdGet32 (PcdEmuFlashNvStorageEventLogSize),\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
+      2,  // Revision\r
+      {\r
+        {\r
+          (FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \\r
+          FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \\r
+          FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \\r
+          FixedPcdGet32 (PcdEmuFlashNvStorageEventLogSize)) / FixedPcdGet32 (PcdEmuFirmwareBlockSize),\r
+          FixedPcdGet32 (PcdEmuFirmwareBlockSize),\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/InOsEmuPkg/FvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf b/InOsEmuPkg/FvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
new file mode 100644 (file)
index 0000000..d343867
--- /dev/null
@@ -0,0 +1,80 @@
+## @file\r
+# Component description file for Emu Fimware Volume Block DXE driver module.\r
+#\r
+# This DXE runtime driver implements and produces the Fimware Volue Block Protocol on \r
+#  Emu emulator.\r
+# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = A01E498C-96E8-2A4C-95F4-85248F989753\r
+  MODULE_TYPE                    = DXE_RUNTIME_DRIVER\r
+  VERSION_STRING                 = 1.0\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]\r
+  FvbInfo.c\r
+  FWBlockService.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  HobLib\r
+  DebugLib\r
+  UefiRuntimeLib\r
+  DxeServicesTableLib\r
+  BaseLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  DevicePathLib\r
+\r
+[Guids]\r
+  gEfiEventVirtualAddressChangeGuid             # ALWAYS_CONSUMED  Create Event: EVENT_GROUP_GUID\r
+\r
+[Protocols]\r
+  gEfiFirmwareVolumeBlockProtocolGuid           # PROTOCOL ALWAYS_PRODUCED\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL SOMETIMES_PRODUCED\r
+\r
+[FixedPcd]\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFirmwareFdSize\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFirmwareBlockSize\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashFvRecoveryBase\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashFvRecoverySize\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageEventLogBase\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageEventLogSize\r
+\r
+[Pcd]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase\r
+\r
+[Depex]\r
+  TRUE\r
+\r
diff --git a/InOsEmuPkg/FvbServicesRuntimeDxe/FwBlockService.h b/InOsEmuPkg/FvbServicesRuntimeDxe/FwBlockService.h
new file mode 100644 (file)
index 0000000..e498451
--- /dev/null
@@ -0,0 +1,219 @@
+/*++ @file\r
+  Firmware volume block driver for Intel Firmware Hub (FWH) device\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+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
+#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
+} 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            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_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_2             *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_2                *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  CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  OUT       EFI_FVB_ATTRIBUTES_2                         *Attributes\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolSetAttributes (\r
+  IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  IN OUT   EFI_FVB_ATTRIBUTES_2                         *Attributes\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolGetPhysicalAddress (\r
+  IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  OUT      EFI_PHYSICAL_ADDRESS                         *Address\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolGetBlockSize (\r
+  IN CONST 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 CONST 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 CONST 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 CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL    *This,\r
+  ...\r
+  )\r
+;\r
+\r
+#endif\r
diff --git a/InOsEmuPkg/InOsEmuPkg.dec b/InOsEmuPkg/InOsEmuPkg.dec
new file mode 100644 (file)
index 0000000..14f1040
--- /dev/null
@@ -0,0 +1,85 @@
+## @file\r
+#\r
+# This is the Emu Emulation Environment Platform\r
+#\r
+# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#    This program and the accompanying materials are licensed and made available \r
+#    under the terms and conditions of the BSD License which accompanies this distribution.\r
+#    The full text of the license may be found at http://opensource.org/licenses/bsd-license.php\r
+#    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES\r
+#    OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+  DEC_VERSION                    = 0x00010005\r
+  PACKAGE_NAME                   = InOsEmuPkg\r
+  PACKAGE_GUID                   = 36E48BD7-7D92-5A47-A2CD-513F072E3300\r
+  PACKAGE_VERSION                = 0.1\r
+\r
+\r
+[Includes]\r
+  Include\r
+\r
+\r
+[LibraryClasses]\r
+  ThunkPpiList|Include/Library/ThunkPpiList.h\r
+  ThunkProtocolList|Include/Library/ThunkProtocolList.h\r
+  EmuThunkLib|Include/Library/EmuThunkLib.h\r
+  KeyMap|Include/Library/KeyMapLib.h\r
+\r
+[Protocols]\r
+  gEmuThunkProtocolGuid          = { 0x398DCA31, 0x3505, 0xDB47, { 0xBD, 0x93, 0x1D, 0x38, 0x5F, 0x79, 0x13, 0x15 } }\r
+  gEmuIoThunkProtocolGuid        = { 0x453368F6, 0x7C85, 0x434A, { 0xA9, 0x8A, 0x72, 0xD1, 0xB7, 0xFF, 0xA9, 0x26 } }\r
+  gEmuGraphicsWindowProtocolGuid = { 0x30FD316A, 0x6728, 0x2E41, { 0xA6, 0x90, 0x0D, 0x13, 0x33, 0xD8, 0xCA, 0xC1 } }\r
+  gEmuPthreadThunkProtocolGuid   = { 0x3B1E4B7C, 0x09D8, 0x944F, { 0xA4, 0x08, 0x13, 0x09, 0xEB, 0x8B, 0x44, 0x27 } }\r
+\r
+[Ppis]\r
+  gEmuThunkPpiGuid                  = { 0xE113F896, 0x75CF, 0xF640, { 0x81, 0x7F, 0xC8, 0x5A, 0x79, 0xE8, 0xAE, 0x67 } }\r
+  gEmuPeiServicesTableUpdatePpiGuid =  { 0xFA93020C, 0x6CDF, 0x1946, { 0x86, 0x35, 0x72, 0xCB, 0x51, 0x9E, 0xCF, 0xFD } }\r
+\r
+\r
+[Guids]\r
+  gInOsEmuPkgTokenSpaceGuid  = { 0x4F792E68, 0xE8C8, 0x794E, { 0xB1, 0xD8, 0x37, 0x03, 0xF3, 0xF2, 0xD5, 0xA5 } }\r
+  gEmuSystemConfigGuid       = { 0xF8626165, 0x6CEB, 0x924A, { 0xBA, 0xFC, 0xF1, 0x3A, 0xB9, 0xD6, 0x57, 0x28 } }\r
+\r
+#  gEmuVirtualDisksGuid       = {0xf2ba331a, 0x8985, 0x11db, {0xa4, 0x06, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+#  gEmuPhysicalDisksGuid      = {0xf2bdcc96, 0x8985, 0x11db, {0x87, 0x19, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+#  gEmuFileSystemGuid         = {0xf2c16b9e, 0x8985, 0x11db, {0x92, 0xc8, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+#  gEmuSerialPortGuid         = {0x6d3a727d, 0x66c8, 0x4d19, {0x87, 0xe6, 0x02, 0x15, 0x86, 0x14, 0x90, 0xf3}}\r
+#  gEmuNetworkGuid            = {0x081603B4, 0x0F1D, 0x4022, {0xB6, 0xFD, 0x4C, 0xE3, 0x5E, 0x09, 0xA1, 0xA6}}\r
+\r
+[PcdsFixedAtBuild]\r
+   gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageVariableBase|0x0|UINT64|0x00001014\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageFtwSpareBase|0x0|UINT64|0x00001015\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageFtwWorkingBase|0x0|UINT64|0x00001016\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFdBaseAddress|0x0|UINT64|0x00001017\r
+\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageEventLogBase|0x0|UINT64|0x0000100e\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageEventLogSize|0x0|UINT32|0x0000100f\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashFvRecoveryBase|0x0|UINT64|0x00001010\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashFvRecoverySize|0x0|UINT32|0x00001011\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFirmwareFdSize|0x0|UINT32|0x00001012\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFirmwareBlockSize|0|UINT32|0x00001013\r
\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuApCount|L"0"|VOID*|0x00001019\r
+\r
+[PcdsFixedAtBuild, PcdsPatchableInModule] \r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuBootMode|1|UINT32|0x00001006\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFirmwareVolume|L"..\\Fv\\Fv_Recovery.fd"|VOID*|0x00001009\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuMemorySize|L"64!64"|VOID*|0x0000100c\r
+  \r
+\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuPhysicalDisk|L"E:RW;245760;512"|VOID*|0x00001000\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuVirtualDisk|L"FW;40960;512"|VOID*|0x00001001\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuGop|L"GOP Window"|VOID*|0x00001018\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFileSystem|L".!../../../../../EdkShellBinPkg/bin/ia32/Apps"|VOID*|0x00001004\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuSerialPort|L"/dev/ttyS0"|VOID*|0x00001002\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuNetworkInterface|L"en0"|VOID*|0x0000100d\r
+\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuCpuModel|L"Intel(R) Processor Model"|VOID*|0x00001007\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuCpuSpeed|L"3000"|VOID*|0x00001008\r
+\r
+\r
diff --git a/InOsEmuPkg/Include/Guid/EmuSystemConfig.h b/InOsEmuPkg/Include/Guid/EmuSystemConfig.h
new file mode 100644 (file)
index 0000000..b3a7d9b
--- /dev/null
@@ -0,0 +1,36 @@
+/** @file\r
+  Setup Variable data structure for Emu platform.\r
+\r
+Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
+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
+#ifndef __EMU_SYSTEM_CONFIG_H__\r
+#define __EMU_SYSTEM_CONFIG_H__\r
+\r
+#define EFI_EMU_SYSTEM_CONFIG_GUID  \\r
+ { 0x9C4FB516, 0x3A1E, 0xD847, { 0xA1, 0xA1, 0x70, 0x58, 0xB6, 0x98, 0x67, 0x32 } }\r
+\r
+\r
+#pragma pack(1)\r
+typedef struct {\r
+  //\r
+  // Console output mode\r
+  //\r
+  UINT32        ConOutColumn;\r
+  UINT32        ConOutRow;\r
+} EMU_SYSTEM_CONFIGURATION;\r
+#pragma pack()\r
+\r
+\r
+extern EFI_GUID   gEmuSystemConfigGuid;\r
+\r
+#endif\r
diff --git a/InOsEmuPkg/Include/Library/EmuThunkLib.h b/InOsEmuPkg/Include/Library/EmuThunkLib.h
new file mode 100644 (file)
index 0000000..d8f55b8
--- /dev/null
@@ -0,0 +1,22 @@
+/*++ @file
+
+Copyright (c) 2011, Apple Inc. All rights reserved.<BR>
+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.             
+
+**/
+
+#ifndef __EMU_THUNK_LIB_H__
+#define __EMU_THUNK_LIB_H__
+
+#include <Protocol/EmuThunk.h>
+
+
+extern EMU_THUNK_PROTOCOL   *gEmuThunk;
+
+#endif
diff --git a/InOsEmuPkg/Include/Library/KeyMapLib.h b/InOsEmuPkg/Include/Library/KeyMapLib.h
new file mode 100644 (file)
index 0000000..7bd29a7
--- /dev/null
@@ -0,0 +1,43 @@
+/*++ @file\r
+\r
+Copyright (c) 2011, Apple Inc. All rights reserved. \r
+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
+#include <Protocol/SimpleTextInEx.h>\r
+\r
+\r
+/**\r
+  KeyMapMake gets called on key presses.\r
+\r
+  @param  KeyData       Key that was pressed.\r
+\r
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+KeyMapMake (\r
+  IN EFI_KEY_DATA   *KeyData\r
+  );\r
+\r
+/**\r
+  KeyMapBreak gets called on key releases.\r
+\r
+  @param  KeyData       Key that was pressed.\r
+\r
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+KeyMapBreak (\r
+  IN EFI_KEY_DATA   *KeyData\r
+  );\r
diff --git a/InOsEmuPkg/Include/Library/ThunkPpiList.h b/InOsEmuPkg/Include/Library/ThunkPpiList.h
new file mode 100644 (file)
index 0000000..febc972
--- /dev/null
@@ -0,0 +1,33 @@
+/** @file\r
+  All 3rd parties to register the PPIs passed into PEI Core\r
+\r
+  Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>\r
+  \r
+  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
+#include <PiPei.h>\r
+\r
+\r
+EFI_PEI_PPI_DESCRIPTOR *\r
+GetThunkPpiList (\r
+  VOID\r
+  );\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+AddThunkPpi (\r
+  IN  UINTN     Flags,\r
+  IN  EFI_GUID  *Guid,\r
+  IN  VOID      *Ppi\r
+  );\r
+\r
+\r
diff --git a/InOsEmuPkg/Include/Library/ThunkProtocolList.h b/InOsEmuPkg/Include/Library/ThunkProtocolList.h
new file mode 100644 (file)
index 0000000..5b25f9c
--- /dev/null
@@ -0,0 +1,35 @@
+/** @file\r
+  Emulator Thunk to abstract OS services from pure EFI code\r
+\r
+  Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>\r
+  \r
+  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
+#include <Uefi.h>\r
+#include <Protocol/EmuIoThunk.h>\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+AddThunkProtocol (\r
+  IN  EMU_IO_THUNK_PROTOCOL   *ThunkIo,  \r
+  IN  CHAR16                  *ConfigString,\r
+  IN  BOOLEAN                 EmuBusDriver\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GetNextThunkProtocol (\r
+  IN  BOOLEAN                 EmuBusDriver,\r
+  OUT EMU_IO_THUNK_PROTOCOL   **Instance  \r
+  );\r
+  \r
+\r
diff --git a/InOsEmuPkg/Include/Ppi/EmuPeiServicesTableUpdate.h b/InOsEmuPkg/Include/Ppi/EmuPeiServicesTableUpdate.h
new file mode 100644 (file)
index 0000000..f706eac
--- /dev/null
@@ -0,0 +1,27 @@
+/** @file\r
+  Emulator Thunk to abstract OS services from pure EFI code\r
+\r
+  Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>\r
+  \r
+  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
+#ifndef __EMU_PEI_SERVICE_TABLE_UPDATE_PPI_H__\r
+#define __EMU_PEI_SERVICE_TABLE_UPDATE_PPI_H__\r
+\r
+#define _EMU_PEI_SERVICE_TABLE_UPDATE_PPI_GUID  \\r
+ { 0xFA93020C, 0x6CDF, 0x1946, { 0x86, 0x35, 0x72, 0xCB, 0x51, 0x9E, 0xCF, 0xFD } }\r
+\r
+\r
+\r
+\r
+extern EFI_GUID gEmuPeiServicesTableUpdatePpiGuid;\r
+\r
+#endif\r
diff --git a/InOsEmuPkg/Include/Ppi/EmuThunk.h b/InOsEmuPkg/Include/Ppi/EmuThunk.h
new file mode 100644 (file)
index 0000000..61047e3
--- /dev/null
@@ -0,0 +1,128 @@
+/** @file\r
+  Emulator Thunk to abstract OS services from pure EFI code\r
+\r
+  Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>\r
+  \r
+  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
+#ifndef __EMU_THUNK_PPI_H__\r
+#define __EMU_THUNK_PPI_H__\r
+\r
+#define EMU_THUNK_PPI_GUID  \\r
+ { 0xB958B78C, 0x1D3E, 0xEE40, { 0x8B, 0xF4, 0xF0, 0x63, 0x2D, 0x06, 0x39, 0x16 } }\r
+\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
+\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\r
+EFI_STATUS\r
+(EFIAPI *EMU_PEI_AUTOSCAN) (\r
+  IN  UINTN                 Index,\r
+  OUT EFI_PHYSICAL_ADDRESS  *MemoryBase,\r
+  OUT UINT64                *MemorySize\r
+  );\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
+  FixUp  - Difference between actual FD address and build address\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\r
+EFI_STATUS\r
+(EFIAPI *EMU_PEI_FD_INFORMATION) (\r
+  IN     UINTN                  Index,\r
+  IN OUT EFI_PHYSICAL_ADDRESS   *FdBase,\r
+  IN OUT UINT64                 *FdSize,\r
+  IN OUT EFI_PHYSICAL_ADDRESS   *FixUp\r
+  );\r
+\r
+\r
+/*++\r
+\r
+Routine Description:\r
+  Export of EMU_THUNK_PROTOCOL from the SEC.\r
+\r
+Returns:\r
+  EFI_SUCCESS - Data returned\r
+\r
+**/\r
+typedef\r
+VOID *\r
+(EFIAPI *EMU_PEI_THUNK_INTERFACE) (\r
+  VOID\r
+  );\r
+\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\r
+EFI_STATUS\r
+(EFIAPI *EMU_PEI_LOAD_FILE) (\r
+  VOID                  *Pe32Data,\r
+  EFI_PHYSICAL_ADDRESS  *ImageAddress,\r
+  UINT64                *ImageSize,\r
+  EFI_PHYSICAL_ADDRESS  *EntryPoint\r
+  );\r
+\r
+\r
+typedef struct {\r
+  EMU_PEI_AUTOSCAN                  MemoryAutoScan;\r
+  EMU_PEI_FD_INFORMATION            FirmwareDevices;\r
+  EMU_PEI_THUNK_INTERFACE           Thunk;\r
+  EMU_PEI_LOAD_FILE                 LoadFile;\r
+} EMU_THUNK_PPI;\r
+\r
+extern EFI_GUID gEmuThunkPpiGuid;\r
+\r
+#endif\r
diff --git a/InOsEmuPkg/Include/Protocol/EmuFileSystem.h b/InOsEmuPkg/Include/Protocol/EmuFileSystem.h
new file mode 100644 (file)
index 0000000..3713acf
--- /dev/null
@@ -0,0 +1,140 @@
+/** @file
+  SimpleFileSystem protocol as defined in the UEFI 2.0 specification.
+
+  The SimpleFileSystem protocol is the programmatic access to the FAT (12,16,32) 
+  file system specified in UEFI 2.0. It can also be used to abstract a file  
+  system other than FAT.
+
+  UEFI 2.0 can boot from any valid EFI image contained in a SimpleFileSystem.
+
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+Portions copyright (c) 2011, Apple Inc. All rights reserved. 
+This program and the accompanying materials are licensed and made available under 
+the terms and conditions of the BSD License that 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.             
+
+**/
+
+#ifndef _EMU_UGA_IO_H_
+#define _EMU_UGA_IO_H_
+
+#include <Protocol/SimplePointer.h>
+#include <Protocol/SimpleTextIn.h>
+#include <Protocol/SimpleTextInEx.h>
+#include <Protocol/UgaDraw.h>
+
+#define EMU_GRAPHICS_WINDOW_PROTOCOL_GUID \
+ { 0x30FD316A, 0x6728, 0x2E41, { 0xA6, 0x90, 0x0D, 0x13, 0x33, 0xD8, 0xCA, 0xC1 } }
+
+typedef struct _EMU_GRAPHICS_WINDOW_PROTOCOL EMU_GRAPHICS_WINDOW_PROTOCOL;
+
+typedef
+EFI_STATUS
+(EFIAPI *EMU_GRAPHICS_WINDOWS_CLOSE)(
+  EMU_GRAPHICS_WINDOW_PROTOCOL *Uga
+  );
+
+typedef
+EFI_STATUS
+(EFIAPI *EMU_GRAPHICS_WINDOWS_SIZE)(
+  EMU_GRAPHICS_WINDOW_PROTOCOL  *Uga, 
+  UINT32                        Width, 
+  UINT32                        Height
+  );
+
+typedef
+EFI_STATUS
+(EFIAPI *EMU_GRAPHICS_WINDOWS_CHECK_KEY)(
+  EMU_GRAPHICS_WINDOW_PROTOCOL *Uga
+  );
+
+typedef
+EFI_STATUS
+(EFIAPI *EMU_GRAPHICS_WINDOWS_GET_KEY)(
+  EMU_GRAPHICS_WINDOW_PROTOCOL  *Uga, 
+  EFI_KEY_DATA                  *key
+  );
+
+typedef
+EFI_STATUS
+(EFIAPI *EMU_GRAPHICS_WINDOWS_KEY_SET_STATE) (
+  IN EMU_GRAPHICS_WINDOW_PROTOCOL   *GraphicsWindows, 
+  IN EFI_KEY_TOGGLE_STATE           *KeyToggleState
+  );
+
+
+typedef 
+VOID
+(EFIAPI *EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK) (
+  IN VOID           *Context,
+  IN EFI_KEY_DATA   *KeyData
+  );
+
+typedef
+EFI_STATUS
+(EFIAPI *EMU_GRAPHICS_WINDOWS_REGISTER_KEY_NOTIFY) (
+  IN EMU_GRAPHICS_WINDOW_PROTOCOL                       *GraphicsWindows, 
+  IN EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK   CallBack,
+  IN VOID                                               *Context
+  );
+
+
+typedef struct {
+    UINTN                                   SourceX;
+    UINTN                                   SourceY;
+    UINTN                                   DestinationX;
+    UINTN                                   DestinationY;
+    UINTN                                   Width;
+    UINTN                                   Height;
+    UINTN                                   Delta;
+} EMU_GRAPHICS_WINDOWS__BLT_ARGS;
+
+typedef
+EFI_STATUS
+(EFIAPI *EMU_GRAPHICS_WINDOWS_BLT)(
+  IN  EMU_GRAPHICS_WINDOW_PROTOCOL            *GraphicsWindows,
+  IN  EFI_UGA_PIXEL                           *BltBuffer OPTIONAL,
+  IN  EFI_UGA_BLT_OPERATION                   BltOperation,
+  IN  EMU_GRAPHICS_WINDOWS__BLT_ARGS          *Args
+  );
+
+typedef
+BOOLEAN
+(EFIAPI *EMU_GRAPHICS_WINDOWS_IS_KEY_PRESSED) ( 
+  IN  EMU_GRAPHICS_WINDOW_PROTOCOL  *GraphicsWindows, 
+  IN  EFI_KEY_DATA                  *KeyData
+  );
+
+typedef
+EFI_STATUS
+(EFIAPI *EMU_GRAPHICS_WINDOWS_CHECK_POINTER)(
+  EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindows
+  );
+
+typedef
+EFI_STATUS
+(EFIAPI *EMU_GRAPHICS_WINDOWS_GET_POINTER_STATE)(
+  EMU_GRAPHICS_WINDOW_PROTOCOL  *GraphicsWindows,
+  EFI_SIMPLE_POINTER_STATE      *state
+  );
+
+struct _EMU_GRAPHICS_WINDOW_PROTOCOL {
+  EMU_GRAPHICS_WINDOWS_SIZE                    Size;
+  EMU_GRAPHICS_WINDOWS_CHECK_KEY               CheckKey;
+  EMU_GRAPHICS_WINDOWS_KEY_SET_STATE           KeySetState;
+  EMU_GRAPHICS_WINDOWS_GET_KEY                 GetKey;
+  EMU_GRAPHICS_WINDOWS_REGISTER_KEY_NOTIFY     RegisterKeyNotify;
+  EMU_GRAPHICS_WINDOWS_BLT                     Blt;
+  EMU_GRAPHICS_WINDOWS_IS_KEY_PRESSED          IsKeyPressed;
+  EMU_GRAPHICS_WINDOWS_CHECK_POINTER           CheckPointer;
+  EMU_GRAPHICS_WINDOWS_GET_POINTER_STATE       GetPointerState;
+};
+
+
+extern EFI_GUID gEmuGraphicsWindowProtocolGuid;
+
+#endif
diff --git a/InOsEmuPkg/Include/Protocol/EmuGraphicsWindow.h b/InOsEmuPkg/Include/Protocol/EmuGraphicsWindow.h
new file mode 100644 (file)
index 0000000..e1afa0e
--- /dev/null
@@ -0,0 +1,134 @@
+/*++ @file
+
+Copyright (c) 2006, Tristan Gingold. All rights reserved.<BR>
+Portitions copyright (c) 2010 - 2011, Apple Inc. 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.
+
+**/
+
+#ifndef _EMU_UGA_IO_H_
+#define _EMU_UGA_IO_H_
+
+#include <Protocol/SimplePointer.h>
+#include <Protocol/SimpleTextIn.h>
+#include <Protocol/SimpleTextInEx.h>
+#include <Protocol/UgaDraw.h>
+
+#define EMU_GRAPHICS_WINDOW_PROTOCOL_GUID \
+ { 0x30FD316A, 0x6728, 0x2E41, { 0xA6, 0x90, 0x0D, 0x13, 0x33, 0xD8, 0xCA, 0xC1 } }
+
+typedef struct _EMU_GRAPHICS_WINDOW_PROTOCOL EMU_GRAPHICS_WINDOW_PROTOCOL;
+
+typedef
+EFI_STATUS
+(EFIAPI *EMU_GRAPHICS_WINDOWS_CLOSE)(
+  EMU_GRAPHICS_WINDOW_PROTOCOL *Uga
+  );
+
+typedef
+EFI_STATUS
+(EFIAPI *EMU_GRAPHICS_WINDOWS_SIZE)(
+  EMU_GRAPHICS_WINDOW_PROTOCOL  *Uga, 
+  UINT32                        Width, 
+  UINT32                        Height
+  );
+
+typedef
+EFI_STATUS
+(EFIAPI *EMU_GRAPHICS_WINDOWS_CHECK_KEY)(
+  EMU_GRAPHICS_WINDOW_PROTOCOL *Uga
+  );
+
+typedef
+EFI_STATUS
+(EFIAPI *EMU_GRAPHICS_WINDOWS_GET_KEY)(
+  EMU_GRAPHICS_WINDOW_PROTOCOL  *Uga, 
+  EFI_KEY_DATA                  *key
+  );
+
+typedef
+EFI_STATUS
+(EFIAPI *EMU_GRAPHICS_WINDOWS_KEY_SET_STATE) (
+  IN EMU_GRAPHICS_WINDOW_PROTOCOL   *GraphicsWindows, 
+  IN EFI_KEY_TOGGLE_STATE           *KeyToggleState
+  );
+
+
+typedef 
+VOID
+(EFIAPI *EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK) (
+  IN VOID           *Context,
+  IN EFI_KEY_DATA   *KeyData
+  );
+
+typedef
+EFI_STATUS
+(EFIAPI *EMU_GRAPHICS_WINDOWS_REGISTER_KEY_NOTIFY) (
+  IN EMU_GRAPHICS_WINDOW_PROTOCOL                       *GraphicsWindows, 
+  IN EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK   MakeCallBack,
+  IN EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK   BreakCallBack,
+  IN VOID                                               *Context
+  );
+
+
+typedef struct {
+    UINTN                                   SourceX;
+    UINTN                                   SourceY;
+    UINTN                                   DestinationX;
+    UINTN                                   DestinationY;
+    UINTN                                   Width;
+    UINTN                                   Height;
+    UINTN                                   Delta;
+} EMU_GRAPHICS_WINDOWS__BLT_ARGS;
+
+typedef
+EFI_STATUS
+(EFIAPI *EMU_GRAPHICS_WINDOWS_BLT)(
+  IN  EMU_GRAPHICS_WINDOW_PROTOCOL            *GraphicsWindows,
+  IN  EFI_UGA_PIXEL                           *BltBuffer OPTIONAL,
+  IN  EFI_UGA_BLT_OPERATION                   BltOperation,
+  IN  EMU_GRAPHICS_WINDOWS__BLT_ARGS          *Args
+  );
+
+typedef
+BOOLEAN
+(EFIAPI *EMU_GRAPHICS_WINDOWS_IS_KEY_PRESSED) ( 
+  IN  EMU_GRAPHICS_WINDOW_PROTOCOL  *GraphicsWindows, 
+  IN  EFI_KEY_DATA                  *KeyData
+  );
+
+typedef
+EFI_STATUS
+(EFIAPI *EMU_GRAPHICS_WINDOWS_CHECK_POINTER)(
+  EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindows
+  );
+
+typedef
+EFI_STATUS
+(EFIAPI *EMU_GRAPHICS_WINDOWS_GET_POINTER_STATE)(
+  EMU_GRAPHICS_WINDOW_PROTOCOL  *GraphicsWindows,
+  EFI_SIMPLE_POINTER_STATE      *state
+  );
+
+struct _EMU_GRAPHICS_WINDOW_PROTOCOL {
+  EMU_GRAPHICS_WINDOWS_SIZE                    Size;
+  EMU_GRAPHICS_WINDOWS_CHECK_KEY               CheckKey;
+  EMU_GRAPHICS_WINDOWS_KEY_SET_STATE           KeySetState;
+  EMU_GRAPHICS_WINDOWS_GET_KEY                 GetKey;
+  EMU_GRAPHICS_WINDOWS_REGISTER_KEY_NOTIFY     RegisterKeyNotify;
+  EMU_GRAPHICS_WINDOWS_BLT                     Blt;
+  EMU_GRAPHICS_WINDOWS_IS_KEY_PRESSED          IsKeyPressed;
+  EMU_GRAPHICS_WINDOWS_CHECK_POINTER           CheckPointer;
+  EMU_GRAPHICS_WINDOWS_GET_POINTER_STATE       GetPointerState;
+};
+
+
+extern EFI_GUID gEmuGraphicsWindowProtocolGuid;
+
+#endif
diff --git a/InOsEmuPkg/Include/Protocol/EmuIoThunk.h b/InOsEmuPkg/Include/Protocol/EmuIoThunk.h
new file mode 100644 (file)
index 0000000..af132be
--- /dev/null
@@ -0,0 +1,51 @@
+/** @file\r
+  Emulator Thunk to abstract OS services from pure EFI code\r
+\r
+  Copyright (c) 2010 - 2011, Apple Inc. All rights reserved.<BR>\r
+  \r
+  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
+#ifndef __EMU_IO_THUNK__ \r
+#define __EMU_IO_THUNK__\r
+\r
+\r
+#define EMU_IO_THUNK_PROTOCO_GUID  \\r
+ { 0x453368F6, 0x7C85, 0x434A, { 0xA9, 0x8A, 0x72, 0xD1, 0xB7, 0xFF, 0xA9, 0x26 } }\r
+\r
+\r
+typedef struct _EMU_IO_THUNK_PROTOCOL  EMU_IO_THUNK_PROTOCOL;\r
+\r
+\r
+typedef \r
+EFI_STATUS\r
+(EFIAPI *EMU_IO_THUNK_PROTOCOL_CLOSE_OPEN) (\r
+  IN  EMU_IO_THUNK_PROTOCOL   *This\r
+  );\r
+\r
+typedef \r
+EFI_STATUS\r
+(EFIAPI *EMU_IO_THUNK_PROTOCOL_CLOSE_CLOSE) (\r
+  IN  EMU_IO_THUNK_PROTOCOL   *This\r
+  );\r
+\r
+struct _EMU_IO_THUNK_PROTOCOL {\r
+  EFI_GUID                            *Protocol;\r
+  VOID                                *Interface;  /// Only be valid after Open() is called\r
+  CHAR16                              *ConfigString;\r
+  UINT16                              Instance;\r
+  EMU_IO_THUNK_PROTOCOL_CLOSE_OPEN    Open;\r
+  EMU_IO_THUNK_PROTOCOL_CLOSE_CLOSE   Close;\r
+  VOID                                *Private;    /// Used by implementation \r
+};\r
+\r
+extern EFI_GUID gEmuIoThunkProtocolGuid;\r
+\r
+#endif\r
diff --git a/InOsEmuPkg/Include/Protocol/EmuPthreadThunk.h b/InOsEmuPkg/Include/Protocol/EmuPthreadThunk.h
new file mode 100644 (file)
index 0000000..80325f4
--- /dev/null
@@ -0,0 +1,105 @@
+/** @file\r
+  Emulator Thunk to abstract OS services from pure EFI code\r
+\r
+  Copyright (c) 2010 - 2011, Apple Inc. All rights reserved.<BR>\r
+  \r
+  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
+#ifndef __EMU_PTHREAD_THUNK__ \r
+#define __EMU_PTHREAD_THUNK__\r
+\r
+#define EMU_PTHREAD_THUNK_PROTOCO_GUID  \\r
+ { 0x3B1E4B7C, 0x09D8, 0x944F, { 0xA4, 0x08, 0x13, 0x09, 0xEB, 0x8B, 0x44, 0x27 } }\r
+\r
+\r
+typedef struct _EMU_PTREAD_THUNK_PROTOCOL  EMU_PTREAD_THUNK_PROTOCOL;\r
+\r
+\r
+typedef \r
+UINTN\r
+(EFIAPI *PTREAD_THUNK_MUTEXT_LOCK) (\r
+  IN VOID *Mutex\r
+  );            \r
+\r
+\r
+typedef \r
+UINTN\r
+(EFIAPI *PTREAD_THUNK_MUTEXT_UNLOCK) (\r
+  IN VOID *Mutex\r
+  );                        \r
+\r
+\r
+typedef \r
+UINTN\r
+(EFIAPI *PTREAD_THUNK_MUTEX_TRY_LOCK) (\r
+  IN VOID *Mutex\r
+  );                      \r
+\r
+\r
+typedef \r
+VOID *\r
+(EFIAPI *PTREAD_THUNK_MUTEX_INIT) (\r
+  IN VOID\r
+  );                     \r
+\r
+\r
+typedef \r
+UINTN\r
+(EFIAPI *PTREAD_THUNK_MUTEX_DISTROY) (\r
+  IN VOID *Mutex\r
+  );                            \r
+\r
+\r
+\r
+typedef \r
+VOID *\r
+(*PTREAD_THUNK_THEAD_ENTRY) (\r
+  IN  VOID *Context\r
+  );\r
+\r
+typedef \r
+UINTN\r
+(EFIAPI *PTREAD_THUNK_CREATE_THREAD) (\r
+  IN  VOID                      *Thread,\r
+  IN  VOID                      *Attribute,\r
+  IN  PTREAD_THUNK_THEAD_ENTRY  Start,\r
+  IN  VOID                      *Context\r
+  );\r
+\r
+typedef \r
+VOID\r
+(EFIAPI *PTREAD_THUNK_EXIT_THREAD) (\r
+  IN VOID *ValuePtr\r
+  );                            \r
+\r
+  \r
+typedef \r
+UINTN\r
+(EFIAPI *PTREAD_THUNK_SELF) (\r
+  VOID\r
+  );                              \r
+\r
+\r
+struct _EMU_PTREAD_THUNK_PROTOCOL {\r
+  PTREAD_THUNK_MUTEXT_LOCK      MutextLock;\r
+  PTREAD_THUNK_MUTEXT_UNLOCK    MutexUnlock;\r
+  PTREAD_THUNK_MUTEX_TRY_LOCK   MutexTryLock;\r
+  PTREAD_THUNK_MUTEX_INIT       MutexInit;\r
+  PTREAD_THUNK_MUTEX_DISTROY    MutexDistroy;\r
+  PTREAD_THUNK_CREATE_THREAD    CreateThread;\r
+  PTREAD_THUNK_EXIT_THREAD      ExitThread;\r
+  PTREAD_THUNK_SELF             Self;\r
+};\r
+\r
+extern EFI_GUID gEmuPthreadThunkProtocolGuid;\r
+\r
+#endif\r
+\r
diff --git a/InOsEmuPkg/Include/Protocol/EmuThunk.h b/InOsEmuPkg/Include/Protocol/EmuThunk.h
new file mode 100644 (file)
index 0000000..411cd3e
--- /dev/null
@@ -0,0 +1,199 @@
+/** @file\r
+  Emulator Thunk to abstract OS services from pure EFI code\r
+\r
+  Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>\r
+  \r
+  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
+#ifndef __EMU_THUNK_PROTOCOL_H__\r
+#define __EMU_THUNK_PROTOCOL_H__\r
+\r
+#define EMU_THUNK_PROTOCOL_GUID  \\r
+  { 0xA37D7CCD, 0x8E91, 0xFB48, { 0xA0, 0xBD, 0x64, 0xC1, 0x83, 0xA3, 0xB4, 0x3F } }\r
+\r
+// neded for things like EFI_TIME_CAPABILITIES\r
+#include <Uefi.h>\r
+\r
+#include <Library/PeCoffExtraActionLib.h>\r
+\r
+#include <Protocol/EmuIoThunk.h>\r
+#include <Protocol/DevicePath.h>\r
+\r
+\r
+typedef struct {\r
+  VENDOR_DEVICE_PATH  VendorDevicePath;\r
+  UINT32              Instance;\r
+} EMU_VENDOR_DEVICE_PATH_NODE;\r
+\r
+typedef struct {\r
+  EMU_VENDOR_DEVICE_PATH_NODE Vendor;\r
+  EFI_DEVICE_PATH_PROTOCOL    EndDevicePath;\r
+} EMU_THUNK_DEVICE_PATH;\r
+\r
+\r
+\r
+typedef struct _EMU_THUNK_PROTOCOL  EMU_THUNK_PROTOCOL;\r
+\r
+\r
+\r
+typedef \r
+EFI_STATUS\r
+(EFIAPI *EMU_WRITE_STD_ERROR) (\r
+  IN UINT8     *Buffer,\r
+  IN UINTN     NumberOfBytes\r
+  );\r
+\r
+typedef \r
+EFI_STATUS\r
+(EFIAPI *EMU_PE_COFF_GET_ENTRY_POINT) (\r
+  IN     VOID  *Pe32Data,\r
+  IN OUT VOID  **EntryPoint\r
+  );\r
+\r
+typedef \r
+VOID\r
+(EFIAPI *EMU_PE_COFF_RELOCATE_EXTRA_ACTION) (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  );\r
+\r
+typedef \r
+VOID\r
+(EFIAPI *EMU_PE_COFF_UNLOAD_EXTRA_ACTION) (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  );\r
+\r
+typedef\r
+VOID\r
+(EFIAPI *EMU_ENABLE_INERRUPTS) (\r
+  VOID\r
+  );\r
+  \r
+typedef\r
+VOID\r
+(EFIAPI *EMU_DISABLE_INERRUPTS) (\r
+  VOID\r
+  );\r
+\r
+typedef\r
+UINT64\r
+(EFIAPI *EMU_QUERY_PERFORMANCE_FREQENCY) (\r
+  VOID\r
+  );\r
+\r
+typedef\r
+UINT64\r
+(EFIAPI *EMU_QUERY_PERFORMANCE_COUNTER) (\r
+  VOID\r
+  );\r
+\r
+typedef\r
+VOID\r
+(EFIAPI *EMU_SLEEP) (\r
+  IN  UINT64    Milliseconds\r
+  );\r
+\r
+typedef\r
+VOID\r
+(EFIAPI *EMU_EXIT) (\r
+  IN  UINTN    Status\r
+  );\r
+  \r
+typedef\r
+VOID\r
+(EFIAPI *EMU_GET_TIME) (\r
+  OUT  EFI_TIME               *Time,\r
+  OUT EFI_TIME_CAPABILITIES   *Capabilities OPTIONAL\r
+  );\r
+  \r
+typedef\r
+VOID\r
+(EFIAPI *EMU_SET_TIME) (\r
+  IN   EFI_TIME               *Time\r
+  );\r
+\r
+\r
+typedef\r
+VOID\r
+(EFIAPI EMU_SET_TIMER_CALLBACK) (\r
+  IN  UINT64  DeltaMs\r
+  );\r
+\r
+typedef\r
+VOID\r
+(EFIAPI *EMU_SET_TIMER) (\r
+  IN  UINT64                  PeriodMs,\r
+  IN  EMU_SET_TIMER_CALLBACK  CallBack\r
+  );\r
+  \r
+\r
+\r
+/**\r
+  Enumerates the current set of protocol instances that abstract OS services from EFI.\r
+  \r
+  A given protocol can have multiple instances. Usually a protocol is configured via a\r
+  single PCD string. The data associated for each instance is seperated via a ! in the string. \r
+  EMU_IO_THUNK_PROTOCOL_CLOSE.ConfigString will contain the information in the PCD string up to the next !.\r
+  Thus each instance has a unique ConfigString. \r
+\r
+  @param  EmuBusDriver          TRUE means only return protocol instances that need to be produced\r
+                                by the EmuBusDriver. FALSE means return all possible protocols\r
+  @param  Instance              On input the protocol to search for, or NULL to start a search \r
+                                of all the supported protocol instances. \r
+  @param  NextProtocol          On output it represents the next value to be passed into Protocol. \r
+  @param  Interface             A pointer to the EMU_IO_THUNK_PROTOCOL_CLOSE interface. \r
+\r
+  @retval EFI_SUCCESS           The function completed successfully.\r
+  @retval EFI_NOT_FOUND         The next protocol instance was not found.\r
+  @retval EFI_INVALID_PARAMETER Instance is NULL.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EMU_GET_NEXT_PROTOCOL) (\r
+  IN  BOOLEAN                 EmuBusDriver,\r
+  OUT EMU_IO_THUNK_PROTOCOL   **Instance  OPTIONAL\r
+  );\r
+  \r
+\r
+struct _EMU_THUNK_PROTOCOL {\r
+  // Used for early debug printing\r
+  EMU_WRITE_STD_ERROR               WriteStdErr;\r
+  \r
+  ///\r
+  /// PE/COFF loader hooks to get symbols loaded\r
+  ///\r
+  EMU_PE_COFF_GET_ENTRY_POINT       PeCoffGetEntryPoint;\r
+  EMU_PE_COFF_RELOCATE_EXTRA_ACTION PeCoffRelocateImageExtraAction;\r
+  EMU_PE_COFF_UNLOAD_EXTRA_ACTION   PeCoffUnloadImageExtraAction;\r
+  \r
+  ///\r
+  /// DXE Architecture Protocol Services\r
+  ///\r
+  EMU_ENABLE_INERRUPTS              EnableInterrupt;\r
+  EMU_DISABLE_INERRUPTS             DisableInterrupt;\r
+  EMU_QUERY_PERFORMANCE_FREQENCY    QueryPerformanceFrequency;\r
+  EMU_QUERY_PERFORMANCE_COUNTER     QueryPerformanceCounter;\r
+\r
+  EMU_SLEEP                         Sleep;\r
+  EMU_EXIT                          Exit;\r
+  EMU_GET_TIME                      GetTime;                \r
+  EMU_SET_TIME                      SetTime;\r
+  EMU_SET_TIMER                     SetTimer;  \r
+  \r
+  ///\r
+  /// Generic System Services\r
+  ///\r
+  EMU_GET_NEXT_PROTOCOL             GetNextProtocol;\r
+};\r
+\r
+extern EFI_GUID gEmuThunkProtocolGuid;\r
+\r
+#endif\r
diff --git a/InOsEmuPkg/Library/DxeEmuLib/DxeEmuLib.c b/InOsEmuPkg/Library/DxeEmuLib/DxeEmuLib.c
new file mode 100644 (file)
index 0000000..79e9fbc
--- /dev/null
@@ -0,0 +1,52 @@
+/*++ @file\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+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
+#include <PiDxe.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/EmuThunkLib.h>\r
+\r
+#include <Protocol/EmuThunk.h>\r
+\r
+\r
+EMU_THUNK_PROTOCOL   *gEmuThunk = NULL;\r
+\r
+\r
+/**\r
+  The constructor function caches the pointer of EMU Thunk protocol.\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
+DxeEmuLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_HOB_GUID_TYPE        *GuidHob;\r
+\r
+  GuidHob = GetFirstGuidHob (&gEmuThunkProtocolGuid);\r
+  ASSERT (GuidHob != NULL);\r
+  \r
+  gEmuThunk = (EMU_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+  ASSERT (gEmuThunk != NULL);\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/InOsEmuPkg/Library/DxeEmuLib/DxeEmuLib.inf b/InOsEmuPkg/Library/DxeEmuLib/DxeEmuLib.inf
new file mode 100644 (file)
index 0000000..de395d6
--- /dev/null
@@ -0,0 +1,45 @@
+## @file\r
+# A library to produce the global variable 'gEmuThunk'\r
+#\r
+# This library contains a single global variable 'gEmuThunk' along with a constructor to \r
+# initialize that global.\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = DxeEmuLib\r
+  FILE_GUID                      = 31479AFD-B06F-4E4A-863B-A8F7E7710778\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = EmuThunkLib \r
+\r
+  CONSTRUCTOR                    = DxeEmuLibConstructor\r
+\r
+\r
+[Sources]\r
+  DxeEmuLib.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+  HobLib\r
+  DebugLib\r
+\r
+\r
+[Protocols]\r
+  gEmuThunkProtocolGuid                     # PROTOCOL ALWAYS_CONSUMED\r
+\r
diff --git a/InOsEmuPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.c b/InOsEmuPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.c
new file mode 100644 (file)
index 0000000..fdb8d53
--- /dev/null
@@ -0,0 +1,103 @@
+/** @file\r
+  Provides services to perform additional actions to relocate and unload\r
+  PE/Coff image for Emu environment specific purpose such as souce level debug.\r
+  This version only works for DXE phase  \r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>\r
+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
+#include <PiDxe.h>\r
+\r
+#include <Protocol/EmuThunk.h>\r
+\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/PeCoffExtraActionLib.h>\r
+\r
+//\r
+// Cache of UnixThunk protocol \r
+//\r
+EMU_THUNK_PROTOCOL   *mThunk = NULL;\r
+\r
+\r
+/**\r
+  The constructor function gets  the pointer of the WinNT thunk functions\r
+  It will ASSERT() if Unix thunk protocol is not installed.\r
+\r
+  @retval EFI_SUCCESS   Unix thunk protocol is found and cached.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DxeEmuPeCoffLibExtraActionConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+   EFI_HOB_GUID_TYPE        *GuidHob;\r
+\r
+  //\r
+  // Retrieve EmuThunkProtocol from GUID'ed HOB\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gEmuThunkProtocolGuid);\r
+  ASSERT (GuidHob != NULL);\r
+  mThunk = (EMU_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+  ASSERT (mThunk != NULL);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Performs additional actions after a PE/COFF image has been loaded and relocated.\r
+\r
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext  Pointer to the image context structure that describes the\r
+                        PE/COFF image that has already been loaded and relocated.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PeCoffLoaderRelocateImageExtraAction (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  if (mThunk != NULL) {\r
+    mThunk->PeCoffRelocateImageExtraAction (ImageContext);\r
+  }\r
+}\r
+\r
+\r
+\r
+/**\r
+  Performs additional actions just before a PE/COFF image is unloaded.  Any resources\r
+  that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.\r
+  \r
+  If ImageContext is NULL, then ASSERT().\r
+  \r
+  @param  ImageContext  Pointer to the image context structure that describes the\r
+                        PE/COFF image that is being unloaded.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PeCoffLoaderUnloadImageExtraAction (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  if (mThunk != NULL) {\r
+    mThunk->PeCoffUnloadImageExtraAction (ImageContext);\r
+  }\r
+}\r
diff --git a/InOsEmuPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.inf b/InOsEmuPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.inf
new file mode 100644 (file)
index 0000000..7c1b4ca
--- /dev/null
@@ -0,0 +1,48 @@
+## @file
+# PeCoff extra action libary for DXE phase that run Emu emulator.
+#
+# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
+# Portions copyright (c) 2011, Apple Inc. 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.
+
+#
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = DxeEmuPeCoffExtraActionLib
+  FILE_GUID                      = 68FCD487-D230-6846-95B1-5E1F2EF942C4
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = PeCoffExtraActionLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_DRIVER
+
+  CONSTRUCTOR                    = DxeEmuPeCoffLibExtraActionConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+#  VALID_ARCHITECTURES           = IA32
+#
+
+[Sources]
+  DxeEmuPeCoffExtraActionLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  InOsEmuPkg/InOsEmuPkg.dec
+
+[LibraryClasses]
+  DebugLib
+  HobLib
+  BaseMemoryLib
+
+[Protocols]
+  gEmuThunkProtocolGuid                     # PROTOCOL ALWAYS_CONSUMED
+
diff --git a/InOsEmuPkg/Library/DxeEmuSerialPortLib/DxeEmuSerialPortLib.c b/InOsEmuPkg/Library/DxeEmuSerialPortLib/DxeEmuSerialPortLib.c
new file mode 100644 (file)
index 0000000..b4ef86e
--- /dev/null
@@ -0,0 +1,119 @@
+/** @file\r
+  Serial Port Lib that thunks back to Emulator services to write to StdErr. \r
+  All read functions are stubed out. \r
+\r
+  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Portions copyright (c) 2011, Apple Inc. All rights reserved.<BR>\r
+  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
+#include <PiDxe.h>\r
+#include <Library/SerialPortLib.h>\r
+#include <Library/EmuThunkLib.h>\r
+\r
+\r
+\r
+\r
+/**\r
+  Initialize the serial device hardware.\r
+  \r
+  If no initialization is required, then return RETURN_SUCCESS.\r
+  If the serial device was successfully initialized, then return RETURN_SUCCESS.\r
+  If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.\r
+  \r
+  @retval RETURN_SUCCESS        The serial device was initialized.\r
+  @retval RETURN_DEVICE_ERROR   The serial device could not be initialized.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+SerialPortInitialize (\r
+  VOID\r
+  )\r
+{\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Write data from buffer to serial device. \r
\r
+  Writes NumberOfBytes data bytes from Buffer to the serial device.  \r
+  The number of bytes actually written to the serial device is returned.\r
+  If the return value is less than NumberOfBytes, then the write operation failed.\r
+  If Buffer is NULL, then ASSERT(). \r
+  If NumberOfBytes is zero, then return 0.\r
+\r
+  @param  Buffer           The pointer to the data buffer to be written.\r
+  @param  NumberOfBytes    The number of bytes to written to the serial device.\r
+\r
+  @retval 0                NumberOfBytes is 0.\r
+  @retval >0               The number of bytes written to the serial device.  \r
+                           If this value is less than NumberOfBytes, then the read operation failed.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+SerialPortWrite (\r
+  IN UINT8     *Buffer,\r
+  IN UINTN     NumberOfBytes\r
+  )\r
+{\r
+  return gEmuThunk->WriteStdErr (Buffer, NumberOfBytes);\r
+}\r
+\r
+\r
+/**\r
+  Read data from serial device and save the datas in buffer.\r
\r
+  Reads NumberOfBytes data bytes from a serial device into the buffer\r
+  specified by Buffer. The number of bytes actually read is returned. \r
+  If the return value is less than NumberOfBytes, then the rest operation failed.\r
+  If Buffer is NULL, then ASSERT(). \r
+  If NumberOfBytes is zero, then return 0.\r
+\r
+  @param  Buffer           The pointer to the data buffer to store the data read from the serial device.\r
+  @param  NumberOfBytes    The number of bytes which will be read.\r
+\r
+  @retval 0                Read data failed; No data is to be read.\r
+  @retval >0               The actual number of bytes read from serial device.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+SerialPortRead (\r
+  OUT UINT8     *Buffer,\r
+  IN  UINTN     NumberOfBytes\r
+  )\r
+{\r
+  return 0;\r
+}\r
+\r
+/**\r
+  Polls a serial device to see if there is any data waiting to be read.\r
+\r
+  Polls a serial device to see if there is any data waiting to be read.\r
+  If there is data waiting to be read from the serial device, then TRUE is returned.\r
+  If there is no data waiting to be read from the serial device, then FALSE is returned.\r
+\r
+  @retval TRUE             Data is waiting to be read from the serial device.\r
+  @retval FALSE            There is no data waiting to be read from the serial device.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+SerialPortPoll (\r
+  VOID\r
+  )\r
+{\r
+  return FALSE;\r
+}\r
+\r
+\r
diff --git a/InOsEmuPkg/Library/DxeEmuSerialPortLib/DxeEmuSerialPortLib.inf b/InOsEmuPkg/Library/DxeEmuSerialPortLib/DxeEmuSerialPortLib.inf
new file mode 100644 (file)
index 0000000..115ad28
--- /dev/null
@@ -0,0 +1,40 @@
+## @file\r
+#  Write only instance of Serial Port Library with empty functions.\r
+#\r
+#  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+#  Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = DxeEmuSerialPortLibNull\r
+  FILE_GUID                      = DF08A29A-F60B-E649-AA79-A1490E863A5D\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = SerialPortLib| DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER SMM_CORE UEFI_APPLICATION UEFI_DRIVE\r
+\r
+\r
+[Sources]\r
+  DxeEmuSerialPortLib.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+  \r
+[LibraryClasses]\r
+  EmuThunkLib\r
+\r
+\r
+\r
+  \r
+\r
diff --git a/InOsEmuPkg/Library/EmuBdsLib/BdsPlatform.c b/InOsEmuPkg/Library/EmuBdsLib/BdsPlatform.c
new file mode 100644 (file)
index 0000000..8f47ef9
--- /dev/null
@@ -0,0 +1,557 @@
+/*++ @file\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+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
+#include "BdsPlatform.h"\r
+\r
+EMU_SYSTEM_CONFIGURATION mSystemConfigData;\r
+\r
+VOID\r
+SetupVariableInit (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+  UINTN                           Size;\r
+\r
+  Size = sizeof (mSystemConfigData);\r
+  Status = gRT->GetVariable (\r
+                  L"Setup",\r
+                  &gEmuSystemConfigGuid,\r
+                  NULL,\r
+                  &Size,\r
+                  (VOID *) &mSystemConfigData\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // SetupVariable is corrupt\r
+    //\r
+    mSystemConfigData.ConOutRow = PcdGet32 (PcdConOutColumn);\r
+    mSystemConfigData.ConOutColumn = PcdGet32 (PcdConOutRow);\r
+\r
+    Status = gRT->SetVariable (\r
+                    L"Setup",\r
+                    &gEmuSystemConfigGuid,\r
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                    sizeof (mSystemConfigData),\r
+                    (VOID *) &mSystemConfigData\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "Failed to save Setup Variable to non-volatile storage, Status = %r\n", Status));\r
+    }\r
+  }\r
+}\r
+\r
+//\r
+// BDS Platform Functions\r
+//\r
+VOID\r
+EFIAPI\r
+PlatformBdsInit (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Platform Bds init. Include the platform firmware vendor, revision\r
+  and so crc check.\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None.\r
+\r
+**/\r
+{\r
+  SetupVariableInit ();\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
+  IN BASEM_MEMORY_TEST           BaseMemoryTest\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
+  BaseMemoryTest   - A pointer to BdsMemoryTest()\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
+    EnableQuietBoot (PcdGetPtr(PcdLogoFile));\r
+    //\r
+    // Perform system diagnostic\r
+    //\r
+    Status = BaseMemoryTest (MemoryTestLevel);\r
+    if (EFI_ERROR (Status)) {\r
+      DisableQuietBoot ();\r
+    }\r
+\r
+    return ;\r
+  }\r
+  //\r
+  // Perform system diagnostic\r
+  //\r
+  Status = BaseMemoryTest (MemoryTestLevel);\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+PlatformBdsPolicyBehavior (\r
+  IN OUT LIST_ENTRY                  *DriverOptionList,\r
+  IN OUT LIST_ENTRY                  *BootOptionList,\r
+  IN PROCESS_CAPSULES                ProcessCapsules,\r
+  IN BASEM_MEMORY_TEST               BaseMemoryTest\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
+  DriverOptionList - The header of the driver option link list\r
+  \r
+  BootOptionList   - The header of the boot option link list\r
+\r
+  ProcessCapsules  - A pointer to ProcessCapsules()\r
+\r
+  BaseMemoryTest   - A pointer to BaseMemoryTest()\r
+\r
+Returns:\r
+\r
+  None.\r
+  \r
+**/\r
+{\r
+  EFI_STATUS     Status;\r
+  UINT16         Timeout;\r
+  EFI_BOOT_MODE  BootMode;\r
+\r
+  //\r
+  // Init the time out value\r
+  //\r
+  Timeout = PcdGet16 (PcdPlatformBootTimeOut);\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 (&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 (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, BaseMemoryTest);\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, BaseMemoryTest);\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, BaseMemoryTest);\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, BaseMemoryTest);\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
+EFIAPI\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
+EFIAPI\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
+\r
+**/\r
+{\r
+  CHAR16  *TmpStr;\r
+\r
+  //\r
+  // If Boot returned with failed status then we need to pop up a UI and wait\r
+  // 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
+EFI_STATUS\r
+PlatformBdsNoConsoleAction (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  \r
+  This function is remained for IBV/OEM to do some platform action,\r
+  if there no console device can be connected.\r
+\r
+Arguments:\r
+  \r
+  None.\r
+  \r
+Returns:\r
+  \r
+  EFI_SUCCESS      - Direct return success now.\r
+\r
+**/\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+PlatformBdsLockNonUpdatableFlash (\r
+  VOID\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+/**\r
+  Lock the ConsoleIn device in system table. All key\r
+  presses will be ignored until the Password is typed in. The only way to\r
+  disable the password is to type it in to a ConIn device.\r
+\r
+  @param  Password        Password used to lock ConIn device.\r
+\r
+  @retval EFI_SUCCESS     lock the Console In Spliter virtual handle successfully.\r
+  @retval EFI_UNSUPPORTED Password not found\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LockKeyboards (\r
+  IN  CHAR16    *Password\r
+  )\r
+{\r
+    return EFI_UNSUPPORTED;\r
+}\r
diff --git a/InOsEmuPkg/Library/EmuBdsLib/BdsPlatform.h b/InOsEmuPkg/Library/EmuBdsLib/BdsPlatform.h
new file mode 100644 (file)
index 0000000..a76ec2e
--- /dev/null
@@ -0,0 +1,97 @@
+/*++ @file\r
+\r
+Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+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
+#ifndef _BDS_PLATFORM_H\r
+#define _BDS_PLATFORM_H\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Guid/EmuSystemConfig.h>\r
+#include <Protocol/EmuThunk.h>\r
+#include <Protocol/EmuIoThunk.h>\r
+#include <Protocol/EmuGraphicsWindow.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/GenericBdsLib.h>\r
+#include <Library/PlatformBdsLib.h>\r
+#include <Library/DevicePathLib.h>\r
+\r
+\r
+extern BDS_CONSOLE_CONNECT_ENTRY  gPlatformConsole[];\r
+extern EFI_DEVICE_PATH_PROTOCOL   *gPlatformConnectSequence[];\r
+extern EFI_DEVICE_PATH_PROTOCOL   *gPlatformDriverOption[];\r
+\r
+#define gEndEntire \\r
+  { \\r
+    END_DEVICE_PATH_TYPE,\\r
+    END_ENTIRE_DEVICE_PATH_SUBTYPE,\\r
+    END_DEVICE_PATH_LENGTH,\\r
+    0\\r
+  }\r
+\r
+\r
+typedef struct {\r
+  EMU_VENDOR_DEVICE_PATH_NODE     EmuBus;\r
+  EMU_VENDOR_DEVICE_PATH_NODE     EmuGraphicsWindow;\r
+  EFI_DEVICE_PATH_PROTOCOL        End;\r
+} EMU_PLATFORM_UGA_DEVICE_PATH;\r
+\r
+\r
+//\r
+// Platform BDS Functions\r
+//\r
+VOID\r
+PlatformBdsGetDriverOption (\r
+  IN LIST_ENTRY               *BdsDriverLists\r
+  );\r
+\r
+EFI_STATUS\r
+BdsMemoryTest (\r
+  EXTENDMEM_COVERAGE_LEVEL Level\r
+  );\r
+\r
+\r
+VOID\r
+PlatformBdsConnectSequence (\r
+  VOID\r
+  );\r
+\r
+EFI_STATUS\r
+ProcessCapsules (\r
+  EFI_BOOT_MODE BootMode\r
+  );\r
+\r
+EFI_STATUS\r
+PlatformBdsConnectConsole (\r
+  IN BDS_CONSOLE_CONNECT_ENTRY   *PlatformConsole\r
+  );\r
+\r
+EFI_STATUS\r
+PlatformBdsNoConsoleAction (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+PlatformBdsEnterFrontPage (\r
+  IN UINT16                 TimeoutDefault,\r
+  IN BOOLEAN                ConnectAllHappened\r
+  );\r
+\r
+#endif // _BDS_PLATFORM_H\r
diff --git a/InOsEmuPkg/Library/EmuBdsLib/EmuBdsLib.inf b/InOsEmuPkg/Library/EmuBdsLib/EmuBdsLib.inf
new file mode 100644 (file)
index 0000000..27f6337
--- /dev/null
@@ -0,0 +1,66 @@
+## @file\r
+# Platfrom BDS driver\r
+#\r
+# Do platform action customized by IBV/OEM.\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = EmuBdsLib\r
+  FILE_GUID                      =  59569181-CBF8-2E44-9C3E-C2AB2F5608E1\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PlatformBdsLib|DXE_DRIVER   \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]\r
+  BdsPlatform.c\r
+  PlatformData.c\r
+  BdsPlatform.h\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  MemoryAllocationLib\r
+  UefiBootServicesTableLib\r
+  UefiRuntimeServicesTableLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  PcdLib\r
+  GenericBdsLib\r
+  DevicePathLib\r
+\r
+\r
+[Guids]\r
+  gEmuSystemConfigGuid\r
+\r
+[Pcd]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutRow\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdPlatformBootTimeOut\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdLogoFile\r
+  \r
+[Depex]\r
+  gEfiVariableArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid\r
diff --git a/InOsEmuPkg/Library/EmuBdsLib/PlatformData.c b/InOsEmuPkg/Library/EmuBdsLib/PlatformData.c
new file mode 100644 (file)
index 0000000..e20099b
--- /dev/null
@@ -0,0 +1,69 @@
+/*++ @file\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+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
+#include "BdsPlatform.h"\r
+\r
+\r
+\r
+EMU_PLATFORM_UGA_DEVICE_PATH gGopDevicePath = {\r
+  {\r
+    {\r
+      {\r
+        HARDWARE_DEVICE_PATH,\r
+        HW_VENDOR_DP,\r
+        {\r
+          (UINT8) (sizeof (EMU_VENDOR_DEVICE_PATH_NODE)),\r
+          (UINT8) ((sizeof (EMU_VENDOR_DEVICE_PATH_NODE)) >> 8)\r
+        }\r
+      },\r
+      EMU_THUNK_PROTOCOL_GUID\r
+    },\r
+    0\r
+  },\r
+  {\r
+      HARDWARE_DEVICE_PATH,\r
+      HW_VENDOR_DP,\r
+      {\r
+        (UINT8) (sizeof (EMU_VENDOR_DEVICE_PATH_NODE)),\r
+        (UINT8) ((sizeof (EMU_VENDOR_DEVICE_PATH_NODE)) >> 8)\r
+      },\r
+      EMU_GRAPHICS_WINDOW_PROTOCOL_GUID,\r
+      0\r
+  },\r
+  gEndEntire\r
+};\r
+\r
+//\r
+// Predefined platform default console device path\r
+//\r
+BDS_CONSOLE_CONNECT_ENTRY   gPlatformConsole[] = {\r
+  {\r
+    (EFI_DEVICE_PATH_PROTOCOL *) &gGopDevicePath,\r
+    (CONSOLE_OUT | CONSOLE_IN)\r
+  },\r
+  {\r
+    NULL,\r
+    0\r
+  }\r
+};\r
+\r
+//\r
+// Predefined platform specific driver option\r
+//\r
+EFI_DEVICE_PATH_PROTOCOL    *gPlatformDriverOption[] = { NULL };\r
+\r
+//\r
+// Predefined platform connect sequence\r
+//\r
+EFI_DEVICE_PATH_PROTOCOL    *gPlatformConnectSequence[] = { NULL };\r
diff --git a/InOsEmuPkg/Library/KeyMapLibNull/KeyMapLibNull.c b/InOsEmuPkg/Library/KeyMapLibNull/KeyMapLibNull.c
new file mode 100644 (file)
index 0000000..5a80870
--- /dev/null
@@ -0,0 +1,50 @@
+/*++ @file\r
+\r
+Copyright (c) 2011, Apple Inc. All rights reserved. \r
+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
+#include <Uefi.h>\r
+#include <Protocol/SimpleTextInEx.h>\r
+\r
+\r
+/**\r
+  KeyMapMake gets called on key presses.\r
+\r
+  @param  KeyData       Key that was pressed.\r
+\r
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+KeyMapMake (\r
+  IN EFI_KEY_DATA   *KeyData\r
+  )\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  KeyMapBreak gets called on key releases.\r
+\r
+  @param  KeyData       Key that was pressed.\r
+\r
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+KeyMapBreak (\r
+  IN EFI_KEY_DATA   *KeyData\r
+  )\r
+{\r
+  return EFI_SUCCESS;\r
+}
\ No newline at end of file
diff --git a/InOsEmuPkg/Library/KeyMapLibNull/KeyMapLibNull.inf b/InOsEmuPkg/Library/KeyMapLibNull/KeyMapLibNull.inf
new file mode 100644 (file)
index 0000000..46483df
--- /dev/null
@@ -0,0 +1,39 @@
+## @file\r
+# A library to produce the global variable 'gEmuThunk'\r
+#\r
+# This library contains a single global variable 'gEmuThunk' along with a constructor to \r
+# initialize that global.\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = KeyMapLibNull\r
+  FILE_GUID                      = 6B7067C7-A843-A34C-9530-48446963B740\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = KeyMapLib \r
+\r
+[Sources]\r
+  KeyMapLibNull.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+  HobLib\r
+  DebugLib\r
+\r
+\r
diff --git a/InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiCoreServicesTablePointerLib.inf b/InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiCoreServicesTablePointerLib.inf
new file mode 100644 (file)
index 0000000..2510d69
--- /dev/null
@@ -0,0 +1,45 @@
+## @file\r
+# Instance of PEI Services Table Pointer Library using global variable for the table pointer.\r
+#\r
+# PEI Services Table Pointer Library implementation that retrieves a pointer to the\r
+#  PEI Services Table from a global variable. Not available to modules that execute from\r
+#  read-only memory.\r
+#\r
+# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+#  Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = InOsEmuPkgPeiCoreServicesTablePointerLib\r
+  FILE_GUID                      = E9A22529-44FA-3E4A-A66B-1E918E7AB26A\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PeiServicesTablePointerLib|PEI_CORE\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC (EBC is for build only)\r
+#\r
+\r
+[Sources]\r
+  PeiServicesTablePointer.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+\r
+[Ppis]\r
+  gEmuPeiServicesTableUpdatePpiGuid\r
+\r
diff --git a/InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiServicesTablePointer.c b/InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiServicesTablePointer.c
new file mode 100644 (file)
index 0000000..1c68939
--- /dev/null
@@ -0,0 +1,102 @@
+/** @file\r
+  PEI Services Table Pointer Library for PEI Core.\r
+  \r
+  This library is used for PEI Core which does executed from flash device directly but\r
+  executed in memory. When the PEI Core does a Set of the PEI Service table pointer \r
+  a PPI is reinstalled so that PEIMs can update the copy of the PEI Services table \r
+  they have cached. \r
+\r
+  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Portiions copyrigth (c) 2011, Apple Inc. All rights reserved. \r
+  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
+#include <PiPei.h>\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#include <Ppi/EmuPeiServicesTableUpdate.h>\r
+\r
+\r
+CONST EFI_PEI_SERVICES  **gPeiServices = NULL;\r
+\r
+/**\r
+  Caches a pointer PEI Services Table. \r
\r
+  Caches the pointer to the PEI Services Table specified by PeiServicesTablePointer \r
+  in a CPU specific manner as specified in the CPU binding section of the Platform Initialization \r
+  Pre-EFI Initialization Core Interface Specification. \r
+  \r
+  If PeiServicesTablePointer is NULL, then ASSERT().\r
+  \r
+  @param    PeiServicesTablePointer   The address of PeiServices pointer.\r
+**/\r
+VOID\r
+EFIAPI\r
+SetPeiServicesTablePointer (\r
+  IN CONST EFI_PEI_SERVICES **PeiServicesTablePointer\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_PEI_PPI_DESCRIPTOR  *PpiDescriptor;\r
+  VOID                    *NotUsed;\r
+\r
+  gPeiServices = PeiServicesTablePointer; \r
+  \r
+  Status = (*PeiServicesTablePointer)->LocatePpi (\r
+                                        PeiServicesTablePointer,\r
+                                        &gEmuPeiServicesTableUpdatePpiGuid, // GUID\r
+                                        0,                 // INSTANCE\r
+                                        &PpiDescriptor,    // EFI_PEI_PPI_DESCRIPTOR\r
+                                        &NotUsed           // PPI\r
+                                        );\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Standard PI Mechanism is to use negative offset from IDT. \r
+    // We can't do that in the emulator, so we make up a constant location\r
+    // that every one can use. The first try may fail as the PEI Core is still\r
+    // initializing its self, but that is OK. \r
+    //\r
+\r
+    // Reinstall PPI to consumers know to update PEI Services pointer\r
+    Status = (*PeiServicesTablePointer)->ReInstallPpi (\r
+                                            PeiServicesTablePointer,\r
+                                            PpiDescriptor,\r
+                                            PpiDescriptor\r
+                                            );\r
+\r
+  }\r
+\r
+}\r
+\r
+/**\r
+  Retrieves the cached value of the PEI Services Table pointer.\r
+\r
+  Returns the cached value of the PEI Services Table pointer in a CPU specific manner \r
+  as specified in the CPU binding section of the Platform Initialization Pre-EFI \r
+  Initialization Core Interface Specification.\r
+  \r
+  If the cached PEI Services Table pointer is NULL, then ASSERT().\r
+\r
+  @return  The pointer to PeiServices.\r
+\r
+**/\r
+CONST EFI_PEI_SERVICES **\r
+EFIAPI\r
+GetPeiServicesTablePointer (\r
+  VOID\r
+  )\r
+{\r
+  ASSERT (gPeiServices != NULL);\r
+  ASSERT (*gPeiServices != NULL);\r
+  return gPeiServices;\r
+}\r
+\r
+\r
diff --git a/InOsEmuPkg/Library/PeiEmuPeCoffExtraActionLib/PeiEmuPeCoffExtraActionLib.c b/InOsEmuPkg/Library/PeiEmuPeCoffExtraActionLib/PeiEmuPeCoffExtraActionLib.c
new file mode 100644 (file)
index 0000000..b88bd00
--- /dev/null
@@ -0,0 +1,106 @@
+/** @file\r
+  Provides services to perform additional actions to relocate and unload\r
+  PE/Coff image for Emu environment specific purpose such as souce level debug.\r
+  This version only works for PEI phase\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>\r
+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
+#include <PiPei.h>\r
+#include <Ppi/EmuThunk.h>\r
+#include <Protocol/EmuThunk.h>\r
+\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/PeCoffExtraActionLib.h>\r
+\r
+//\r
+// Cache of UnixThunk protocol \r
+//\r
+EMU_THUNK_PROTOCOL   *mThunk = NULL;\r
+\r
+/**\r
+  The function caches the pointer of the Unix thunk functions\r
+  It will ASSERT() if Unix thunk ppi is not installed.\r
+\r
+  @retval EFI_SUCCESS   WinNT thunk protocol is found and cached.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuPeCoffGetThunkStucture (\r
+  )\r
+{\r
+  EMU_THUNK_PPI     *ThunkPpi;\r
+  EFI_STATUS        Status;\r
+\r
+  \r
+  //\r
+  // Locate Unix ThunkPpi for retrieving standard output handle\r
+  //\r
+  Status = PeiServicesLocatePpi (\r
+              &gEmuThunkPpiGuid,\r
+              0,\r
+              NULL,\r
+              (VOID **) &ThunkPpi\r
+              );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  mThunk  = (EMU_THUNK_PROTOCOL *) ThunkPpi->Thunk ();\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Performs additional actions after a PE/COFF image has been loaded and relocated.\r
+\r
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext  Pointer to the image context structure that describes the\r
+                        PE/COFF image that has already been loaded and relocated.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PeCoffLoaderRelocateImageExtraAction (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  if (mThunk == NULL) {\r
+    EmuPeCoffGetThunkStucture ();\r
+  }\r
+    mThunk->PeCoffRelocateImageExtraAction (ImageContext);\r
+  }\r
+\r
+\r
+/**\r
+  Performs additional actions just before a PE/COFF image is unloaded.  Any resources\r
+  that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.\r
+  \r
+  If ImageContext is NULL, then ASSERT().\r
+  \r
+  @param  ImageContext  Pointer to the image context structure that describes the\r
+                        PE/COFF image that is being unloaded.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PeCoffLoaderUnloadImageExtraAction (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  if (mThunk == NULL) {\r
+    EmuPeCoffGetThunkStucture ();\r
+  }\r
+  mThunk->PeCoffUnloadImageExtraAction (ImageContext);\r
+}\r
diff --git a/InOsEmuPkg/Library/PeiEmuPeCoffExtraActionLib/PeiEmuPeCoffExtraActionLib.inf b/InOsEmuPkg/Library/PeiEmuPeCoffExtraActionLib/PeiEmuPeCoffExtraActionLib.inf
new file mode 100644 (file)
index 0000000..3fd4a8a
--- /dev/null
@@ -0,0 +1,46 @@
+## @file
+# PeCoff extra action libary for Pei phase that run Emu emulator.
+#
+# Lib to provide memory journal status code reporting Routines
+# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
+# Portions copyright (c) 2011, Apple Inc. 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.
+
+#
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = PeiEmuPeCoffExtraActionLib
+  FILE_GUID                      = 79C4E72A-730B-F040-8129-95877B3A97A8
+  MODULE_TYPE                    = PEIM
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = PeCoffExtraActionLib|PEI_CORE PEIM
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+#  VALID_ARCHITECTURES           = IA32
+#
+
+[Sources]
+  PeiEmuPeCoffExtraActionLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  InOsEmuPkg/InOsEmuPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  PeiServicesLib
+  DebugLib
+
+[Ppis]
+  gEmuThunkPpiGuid                          # PPI ALWAYS_CONSUMED
diff --git a/InOsEmuPkg/Library/PeiEmuPeCoffGetEntryPointLib/PeiEmuPeCoffGetEntryPointLib.c b/InOsEmuPkg/Library/PeiEmuPeCoffGetEntryPointLib/PeiEmuPeCoffGetEntryPointLib.c
new file mode 100644 (file)
index 0000000..0b4be07
--- /dev/null
@@ -0,0 +1,297 @@
+/*++ @file\r
+\r
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>\r
+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
+#include "PiPei.h"\r
+#include <Library/PeCoffGetEntryPointLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <IndustryStandard/PeImage.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#include <Ppi/EmuThunk.h>\r
+#include <Protocol/EmuThunk.h>\r
+\r
+\r
+\r
+/**\r
+  Retrieves and returns a pointer to the entry point to a PE/COFF image that has been loaded\r
+  into system memory with the PE/COFF Loader Library functions.\r
+\r
+  Retrieves the entry point to the PE/COFF image specified by Pe32Data and returns this entry\r
+  point in EntryPoint.  If the entry point could not be retrieved from the PE/COFF image, then\r
+  return RETURN_INVALID_PARAMETER.  Otherwise return RETURN_SUCCESS.\r
+  If Pe32Data is NULL, then ASSERT().\r
+  If EntryPoint is NULL, then ASSERT().\r
+\r
+  @param  Pe32Data                  The pointer to the PE/COFF image that is loaded in system memory.\r
+  @param  EntryPoint                The pointer to entry point to the PE/COFF image to return.\r
+\r
+  @retval RETURN_SUCCESS            EntryPoint was returned.\r
+  @retval RETURN_INVALID_PARAMETER  The entry point could not be found in the PE/COFF image.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderGetEntryPoint (\r
+  IN     VOID  *Pe32Data,\r
+  IN OUT VOID  **EntryPoint\r
+  )\r
+{\r
+  EMU_THUNK_PPI           *ThunkPpi;\r
+  EFI_STATUS              Status;\r
+  EMU_THUNK_PROTOCOL      *Thunk;\r
+\r
+  //\r
+  // Locate EmuThunkPpi for retrieving standard output handle\r
+  //\r
+  Status = PeiServicesLocatePpi (\r
+              &gEmuThunkPpiGuid,\r
+             0,\r
+              NULL,\r
+              (VOID **) &ThunkPpi\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Thunk  = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();\r
+\r
+  return Thunk->PeCoffGetEntryPoint (Pe32Data, EntryPoint);\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 Emu 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_IA64:\r
+      //\r
+      // Assume PE32+ image with X64 or IA64 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
+        case CODEVIEW_SIGNATURE_MTOC:\r
+          return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY));\r
+        default:\r
+          break;\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  return NULL;\r
+}\r
+\r
+\r
+/**\r
+  Returns the size of the PE/COFF headers\r
+\r
+  Returns the size of the PE/COFF header specified by Pe32Data.\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 Size of PE/COFF header in bytes or zero if not a valid image.\r
+\r
+**/\r
+UINT32\r
+EFIAPI\r
+PeCoffGetSizeOfHeaders (\r
+  IN VOID     *Pe32Data\r
+  )\r
+{\r
+  EFI_IMAGE_DOS_HEADER                  *DosHdr;\r
+  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION   Hdr;\r
+  UINTN                                 SizeOfHeaders;\r
+\r
+  ASSERT (Pe32Data   != NULL);\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
+    SizeOfHeaders = sizeof (EFI_TE_IMAGE_HEADER) + (UINTN)Hdr.Te->BaseOfCode - (UINTN)Hdr.Te->StrippedSize;\r
+  } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
+    SizeOfHeaders = Hdr.Pe32->OptionalHeader.SizeOfHeaders;\r
+  } else {\r
+    SizeOfHeaders = 0;\r
+  }\r
+\r
+  return SizeOfHeaders;\r
+}\r
+\r
diff --git a/InOsEmuPkg/Library/PeiEmuPeCoffGetEntryPointLib/PeiEmuPeCoffGetEntryPointLib.inf b/InOsEmuPkg/Library/PeiEmuPeCoffGetEntryPointLib/PeiEmuPeCoffGetEntryPointLib.inf
new file mode 100644 (file)
index 0000000..d09fd22
--- /dev/null
@@ -0,0 +1,49 @@
+## @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 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = PeiEmuPeCoffGetEntryPointLib\r
+  FILE_GUID                      = 1CBED347-7DE6-BC48-AC68-3758598124D2\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PeCoffGetEntryPointLib \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]\r
+  PeiEmuPeCoffGetEntryPointLib.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  PeiServicesLib\r
+  DebugLib\r
+\r
+\r
+[Ppis]\r
+  gEmuThunkPpiGuid                       # PPI ALWAYS_CONSUMED\r
+\r
diff --git a/InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.c b/InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.c
new file mode 100644 (file)
index 0000000..aa4e80c
--- /dev/null
@@ -0,0 +1,140 @@
+/** @file\r
+  Serial Port Lib that thunks back to Emulator services to write to StdErr. \r
+  All read functions are stubed out. There is no constructor so this lib can \r
+  be linked with PEI Core.\r
+\r
+  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Portions copyright (c) 2011, Apple Inc. All rights reserved.<BR>\r
+  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
+#include <PiPei.h>\r
+#include <Library/SerialPortLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+\r
+#include <Ppi/EmuThunk.h>\r
+#include <Protocol/EmuThunk.h>\r
+\r
+\r
+\r
+/**\r
+  Initialize the serial device hardware.\r
+  \r
+  If no initialization is required, then return RETURN_SUCCESS.\r
+  If the serial device was successfully initialized, then return RETURN_SUCCESS.\r
+  If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.\r
+  \r
+  @retval RETURN_SUCCESS        The serial device was initialized.\r
+  @retval RETURN_DEVICE_ERROR   The serial device could not be initialized.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+SerialPortInitialize (\r
+  VOID\r
+  )\r
+{\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Write data from buffer to serial device. \r
\r
+  Writes NumberOfBytes data bytes from Buffer to the serial device.  \r
+  The number of bytes actually written to the serial device is returned.\r
+  If the return value is less than NumberOfBytes, then the write operation failed.\r
+  If Buffer is NULL, then ASSERT(). \r
+  If NumberOfBytes is zero, then return 0.\r
+\r
+  @param  Buffer           The pointer to the data buffer to be written.\r
+  @param  NumberOfBytes    The number of bytes to written to the serial device.\r
+\r
+  @retval 0                NumberOfBytes is 0.\r
+  @retval >0               The number of bytes written to the serial device.  \r
+                           If this value is less than NumberOfBytes, then the read operation failed.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+SerialPortWrite (\r
+  IN UINT8     *Buffer,\r
+  IN UINTN     NumberOfBytes\r
+  )\r
+{\r
+  EMU_THUNK_PPI           *ThunkPpi;\r
+  EFI_STATUS              Status;\r
+  EMU_THUNK_PROTOCOL      *Thunk;\r
+\r
+  //\r
+  // Locate EmuThunkPpi for retrieving standard output handle\r
+  //\r
+  Status = PeiServicesLocatePpi (\r
+              &gEmuThunkPpiGuid,\r
+              0,\r
+              NULL,\r
+              (VOID **) &ThunkPpi\r
+             );\r
+  if (!EFI_ERROR (Status)) {\r
+    Thunk  = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();\r
+    return Thunk->WriteStdErr (Buffer, NumberOfBytes);\r
+  }\r
+  \r
+  return 0;\r
+}\r
+\r
+\r
+/**\r
+  Read data from serial device and save the datas in buffer.\r
\r
+  Reads NumberOfBytes data bytes from a serial device into the buffer\r
+  specified by Buffer. The number of bytes actually read is returned. \r
+  If the return value is less than NumberOfBytes, then the rest operation failed.\r
+  If Buffer is NULL, then ASSERT(). \r
+  If NumberOfBytes is zero, then return 0.\r
+\r
+  @param  Buffer           The pointer to the data buffer to store the data read from the serial device.\r
+  @param  NumberOfBytes    The number of bytes which will be read.\r
+\r
+  @retval 0                Read data failed; No data is to be read.\r
+  @retval >0               The actual number of bytes read from serial device.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+SerialPortRead (\r
+  OUT UINT8     *Buffer,\r
+  IN  UINTN     NumberOfBytes\r
+  )\r
+{\r
+  return 0;\r
+}\r
+\r
+/**\r
+  Polls a serial device to see if there is any data waiting to be read.\r
+\r
+  Polls a serial device to see if there is any data waiting to be read.\r
+  If there is data waiting to be read from the serial device, then TRUE is returned.\r
+  If there is no data waiting to be read from the serial device, then FALSE is returned.\r
+\r
+  @retval TRUE             Data is waiting to be read from the serial device.\r
+  @retval FALSE            There is no data waiting to be read from the serial device.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+SerialPortPoll (\r
+  VOID\r
+  )\r
+{\r
+  return FALSE;\r
+}\r
+\r
+\r
diff --git a/InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf b/InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf
new file mode 100644 (file)
index 0000000..663967d
--- /dev/null
@@ -0,0 +1,45 @@
+## @file\r
+#  Write only instance of Serial Port Library with empty functions.\r
+#\r
+#  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+#  Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = PeiEmuSerialPortLibNull\r
+  FILE_GUID                      = E4541241-8897-411a-91F8-7D7E45837146\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = SerialPortLib| PEI_CORE PEIM\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources]\r
+  PeiEmuSerialPortLib.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+  \r
+[LibraryClasses]\r
+  PeiServicesLib\r
+\r
+[Ppis]\r
+  gEmuThunkPpiGuid                       # PPI ALWAYS_CONSUMED\r
+\r
+\r
+  \r
+\r
diff --git a/InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointer.c b/InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointer.c
new file mode 100644 (file)
index 0000000..6a58a74
--- /dev/null
@@ -0,0 +1,134 @@
+/** @file\r
+  PEI Services Table Pointer Library.\r
+  \r
+  This library is used for PEIM which does executed from flash device directly but\r
+  executed in memory.\r
+\r
+  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Portiions copyrigth (c) 2011, Apple Inc. All rights reserved. \r
+  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
+#include <PiPei.h>\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#include <Ppi/EmuPeiServicesTableUpdate.h>\r
+\r
+\r
+CONST EFI_PEI_SERVICES  **gPeiServices = NULL;\r
+\r
+/**\r
+  Caches a pointer PEI Services Table. \r
\r
+  Caches the pointer to the PEI Services Table specified by PeiServicesTablePointer \r
+  in a CPU specific manner as specified in the CPU binding section of the Platform Initialization \r
+  Pre-EFI Initialization Core Interface Specification. \r
+  \r
+  If PeiServicesTablePointer is NULL, then ASSERT().\r
+  \r
+  @param    PeiServicesTablePointer   The address of PeiServices pointer.\r
+**/\r
+VOID\r
+EFIAPI\r
+SetPeiServicesTablePointer (\r
+  IN CONST EFI_PEI_SERVICES ** PeiServicesTablePointer\r
+  )\r
+{\r
+  ASSERT (PeiServicesTablePointer != NULL);\r
+  ASSERT (*PeiServicesTablePointer != NULL);\r
+  gPeiServices = PeiServicesTablePointer;\r
+}\r
+\r
+/**\r
+  Retrieves the cached value of the PEI Services Table pointer.\r
+\r
+  Returns the cached value of the PEI Services Table pointer in a CPU specific manner \r
+  as specified in the CPU binding section of the Platform Initialization Pre-EFI \r
+  Initialization Core Interface Specification.\r
+  \r
+  If the cached PEI Services Table pointer is NULL, then ASSERT().\r
+\r
+  @return  The pointer to PeiServices.\r
+\r
+**/\r
+CONST EFI_PEI_SERVICES **\r
+EFIAPI\r
+GetPeiServicesTablePointer (\r
+  VOID\r
+  )\r
+{\r
+  ASSERT (gPeiServices != NULL);\r
+  ASSERT (*gPeiServices != NULL);\r
+  return gPeiServices;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Notification service to be called when gEmuThunkPpiGuid is installed.\r
+\r
+  @param  PeiServices                 Indirect reference to the PEI Services Table.\r
+  @param  NotifyDescriptor          Address of the notification descriptor data structure. Type\r
+          EFI_PEI_NOTIFY_DESCRIPTOR is defined above.\r
+  @param  Ppi                             Address of the PPI that was installed.\r
+\r
+  @retval   EFI_STATUS                This function will install a PPI to PPI database. The status\r
+                                                  code will be the code for (*PeiServices)->InstallPpi.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiServicesTablePointerNotifyCallback (\r
+  IN EFI_PEI_SERVICES              **PeiServices,\r
+  IN EFI_PEI_NOTIFY_DESCRIPTOR     *NotifyDescriptor,\r
+  IN VOID                          *Ppi\r
+  )\r
+{\r
+  gPeiServices = (CONST EFI_PEI_SERVICES  **)PeiServices;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnThunkList = {\r
+  (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+  &gEmuPeiServicesTableUpdatePpiGuid,\r
+  PeiServicesTablePointerNotifyCallback \r
+};\r
+\r
+\r
+/**\r
+  Constructor register notification on when PPI updates. If PPI is \r
+  alreay installed registering the notify will cause the handle to \r
+  run.\r
+\r
+  @param  FileHandle   The handle of FFS header the loaded driver.\r
+  @param  PeiServices  The pointer to the PEI services.\r
+\r
+  @retval EFI_SUCCESS  The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiServicesTablePointerLibConstructor (\r
+  IN EFI_PEI_FILE_HANDLE        FileHandle,\r
+  IN CONST EFI_PEI_SERVICES     **PeiServices\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  // register to be told when PeiServices pointer is updated\r
+  Status = (*PeiServices)->NotifyPpi (PeiServices, &mNotifyOnThunkList);\r
+  ASSERT_EFI_ERROR (Status);\r
+  return Status;\r
+}\r
+\r
+\r
diff --git a/InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf b/InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf
new file mode 100644 (file)
index 0000000..29d790a
--- /dev/null
@@ -0,0 +1,47 @@
+## @file\r
+# Instance of PEI Services Table Pointer Library using global variable for the table pointer.\r
+#\r
+# PEI Services Table Pointer Library implementation that retrieves a pointer to the\r
+#  PEI Services Table from a global variable. Not available to modules that execute from\r
+#  read-only memory.\r
+#\r
+# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = InOsEmuPkgPeiServicesTablePointerLib\r
+  FILE_GUID                      =  5FD8B4ED-D66F-C144-9953-AC557C649925\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PeiServicesTablePointerLib|PEIM\r
+\r
+  CONSTRUCTOR                    = PeiServicesTablePointerLibConstructor\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC (EBC is for build only)\r
+#\r
+\r
+[Sources]\r
+  PeiServicesTablePointer.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+\r
+[Ppis]\r
+  gEmuPeiServicesTableUpdatePpiGuid\r
+\r
diff --git a/InOsEmuPkg/Library/ThunkPpiList/ThunkPpiList.c b/InOsEmuPkg/Library/ThunkPpiList/ThunkPpiList.c
new file mode 100644 (file)
index 0000000..3531b84
--- /dev/null
@@ -0,0 +1,72 @@
+/** @file\r
+  Emulator Thunk to abstract OS services from pure EFI code\r
+\r
+  Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>\r
+  \r
+  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
+#include <PiPei.h>\r
+#include <Library/BaseLib.h>\r
+\r
+#include <stdlib.h>\r
+\r
+\r
+UINTN                   gThunkPpiListSize = 0;\r
+EFI_PEI_PPI_DESCRIPTOR  *gThunkPpiList = NULL;\r
+\r
+\r
+\r
+EFI_PEI_PPI_DESCRIPTOR *\r
+GetThunkPpiList (\r
+  VOID\r
+  )\r
+{\r
+  UINTN Index;\r
+  \r
+  if (gThunkPpiList == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  Index = (gThunkPpiListSize/sizeof (EFI_PEI_PPI_DESCRIPTOR)) - 1;\r
+  gThunkPpiList[Index].Flags |= EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;\r
+  \r
+  return gThunkPpiList;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+AddThunkPpi (\r
+  IN  UINTN     Flags,\r
+  IN  EFI_GUID  *Guid,\r
+  IN  VOID      *Ppi\r
+  )\r
+{\r
+  UINTN Index;\r
+  \r
+  gThunkPpiList = realloc (gThunkPpiList, gThunkPpiListSize + sizeof (EFI_PEI_PPI_DESCRIPTOR));\r
+  if (gThunkPpiList == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  \r
+  Index = (gThunkPpiListSize/sizeof (EFI_PEI_PPI_DESCRIPTOR));\r
+  gThunkPpiList[Index].Flags = Flags;\r
+  gThunkPpiList[Index].Guid  = Guid;\r
+  gThunkPpiList[Index].Ppi   = Ppi;\r
+  gThunkPpiListSize += sizeof (EFI_PEI_PPI_DESCRIPTOR);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+\r
+\r
+\r
diff --git a/InOsEmuPkg/Library/ThunkPpiList/ThunkPpiList.inf b/InOsEmuPkg/Library/ThunkPpiList/ThunkPpiList.inf
new file mode 100644 (file)
index 0000000..aa4bb5a
--- /dev/null
@@ -0,0 +1,38 @@
+## @file\r
+# Place thunk PPI in HOB.\r
+#\r
+# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = ThunkPpiList\r
+  FILE_GUID                      = 465FDE84-E8B0-B04B-A843-A03F68F617A9\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = MemoryAllocationLib|SEC BASE USER_DEFINED\r
+\r
+[Sources]\r
+  ThunkPpiList.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  BaseMemoryLib\r
+\r
+[BuildOptions]\r
+   XCODE:*_*_*_DLINK_PATH == gcc\r
+\r
diff --git a/InOsEmuPkg/Library/ThunkProtocolList/ThunkProtocolList.c b/InOsEmuPkg/Library/ThunkProtocolList/ThunkProtocolList.c
new file mode 100644 (file)
index 0000000..3c53716
--- /dev/null
@@ -0,0 +1,138 @@
+/** @file\r
+  Emulator Thunk to abstract OS services from pure EFI code\r
+\r
+  Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>\r
+  \r
+  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
+#include <Uefi.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#include <Protocol/EmuIoThunk.h>\r
+\r
+#include <stdlib.h>\r
+\r
+\r
+#define EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE SIGNATURE_32('E','m','u','T')\r
+\r
+typedef struct {\r
+  UINTN                 Signature;\r
+  EMU_IO_THUNK_PROTOCOL Data;\r
+  BOOLEAN               EmuBusDriver;\r
+  LIST_ENTRY            Link;\r
+} EMU_IO_THUNK_PROTOCOL_DATA;\r
+\r
+LIST_ENTRY  mThunkList = INITIALIZE_LIST_HEAD_VARIABLE (mThunkList);\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+AddThunkProtocol (\r
+  IN  EMU_IO_THUNK_PROTOCOL   *ThunkIo,  \r
+  IN  CHAR16                  *ConfigString,\r
+  IN  BOOLEAN                 EmuBusDriver\r
+  )\r
+{\r
+  CHAR16                      *StartString;\r
+  CHAR16                      *SubString;\r
+  UINTN                       Instance;\r
+  EMU_IO_THUNK_PROTOCOL_DATA  *Private;\r
+  \r
+  if (ThunkIo == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  Instance = 0;\r
+  StartString = malloc (StrSize (ConfigString));\r
+  StrCpy (StartString, ConfigString);\r
+  while (*StartString != '\0') {\r
+\r
+    //\r
+    // Find the end of the sub string\r
+    //\r
+    SubString = StartString;\r
+    while (*SubString != '\0' && *SubString != '!') {\r
+      SubString++;\r
+    }\r
+\r
+    if (*SubString == '!') {\r
+      //\r
+      // Replace token with '\0' to make sub strings. If this is the end\r
+      //  of the string SubString will already point to NULL.\r
+      //\r
+      *SubString = '\0';\r
+      SubString++;\r
+    }\r
+\r
+    Private = malloc (sizeof (EMU_IO_THUNK_PROTOCOL_DATA));\r
+    if (Private == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    Private->Signature          = EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE;\r
+    Private->EmuBusDriver       = EmuBusDriver;\r
+\r
+    CopyMem (&Private->Data, ThunkIo, sizeof (EMU_IO_THUNK_PROTOCOL));    \r
+    Private->Data.Instance      = Instance++;\r
+    Private->Data.ConfigString  = StartString;\r
+    \r
+    InsertTailList (&mThunkList, &Private->Link);\r
+\r
+    //\r
+    // Parse Next sub string. This will point to '\0' if we are at the end.\r
+    //\r
+    StartString = SubString;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GetNextThunkProtocol (\r
+  IN  BOOLEAN                 EmuBusDriver,\r
+  OUT EMU_IO_THUNK_PROTOCOL   **Instance  OPTIONAL\r
+  )\r
+{\r
+  LIST_ENTRY                   *Link; \r
+  EMU_IO_THUNK_PROTOCOL_DATA   *Private; \r
+  \r
+  if (mThunkList.ForwardLink == &mThunkList) {\r
+    // Skip parsing an empty list\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  \r
+  for (Link = mThunkList.ForwardLink; Link != &mThunkList; Link = Link->ForwardLink) {\r
+    Private = CR (Link, EMU_IO_THUNK_PROTOCOL_DATA, Link, EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE);\r
+    if (EmuBusDriver & !Private->EmuBusDriver) {\r
+      continue;\r
+    } else if (*Instance == NULL) {\r
+      // Find 1st match in list\r
+      *Instance = &Private->Data;\r
+      return EFI_SUCCESS;\r
+    } else if (*Instance == &Private->Data) {\r
+      // Matched previous call so look for valid next entry\r
+      Link = Link->ForwardLink;\r
+      if (Link == &mThunkList) {\r
+        return EFI_NOT_FOUND;\r
+      }\r
+      Private = CR (Link, EMU_IO_THUNK_PROTOCOL_DATA, Link, EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE);\r
+      *Instance = &Private->Data;\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+   \r
+   \r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
diff --git a/InOsEmuPkg/Library/ThunkProtocolList/ThunkProtocolList.inf b/InOsEmuPkg/Library/ThunkProtocolList/ThunkProtocolList.inf
new file mode 100644 (file)
index 0000000..387a650
--- /dev/null
@@ -0,0 +1,36 @@
+## @file\r
+#\r
+# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = ThunkProtocolList\r
+  FILE_GUID                      = 7833616E-AE0D-594F-870C-80E68682D587\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = MemoryAllocationLib|BASE SEC USER_DEFINED\r
+\r
+[Sources]\r
+  ThunkProtocolList.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  BaseMemoryLib\r
+\r
+\r
+\r
diff --git a/InOsEmuPkg/MetronomeDxe/Metronome.c b/InOsEmuPkg/MetronomeDxe/Metronome.c
new file mode 100644 (file)
index 0000000..34f9469
--- /dev/null
@@ -0,0 +1,125 @@
+/*++ @file\r
+  Emu Emulation Metronome Architectural Protocol Driver as defined in DXE CIS\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2010 - 2011, Apple Inc. All rights reserved.\r
+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
+#include "Metronome.h"\r
+\r
+\r
+//\r
+// Global Variables\r
+//\r
+EFI_METRONOME_ARCH_PROTOCOL mMetronome = {\r
+  EmuMetronomeDriverWaitForTick,\r
+  TICK_PERIOD\r
+};\r
+\r
+//\r
+// Worker Functions\r
+//\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuMetronomeDriverWaitForTick (\r
+  IN EFI_METRONOME_ARCH_PROTOCOL  *This,\r
+  IN UINT32                       TickNumber\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The WaitForTick() function waits for the number of ticks specified by\r
+  TickNumber from a known time source in the platform.  If TickNumber of\r
+  ticks are detected, then EFI_SUCCESS is returned.  The actual time passed\r
+  between entry of this function and the first tick is between 0 and\r
+  TickPeriod 100 nS units.  If you want to guarantee that at least TickPeriod\r
+  time has elapsed, wait for two ticks.  This function waits for a hardware\r
+  event to determine when a tick occurs.  It is possible for interrupt\r
+  processing, or exception processing to interrupt the execution of the\r
+  WaitForTick() function.  Depending on the hardware source for the ticks, it\r
+  is possible for a tick to be missed.  This function cannot guarantee that\r
+  ticks will not be missed.  If a timeout occurs waiting for the specified\r
+  number of ticks, then EFI_TIMEOUT is returned.\r
+\r
+Arguments:\r
+\r
+  This       - The EFI_METRONOME_ARCH_PROTOCOL instance.\r
+  TickNumber - Number of ticks to wait.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - The wait for the number of ticks specified by TickNumber\r
+                succeeded.\r
+\r
+**/\r
+{\r
+  UINT64  SleepTime;\r
+\r
+  //\r
+  // Calculate the time to sleep.  Emu smallest unit to sleep is 1 millisec\r
+  // Tick Period is in 100ns units, divide by 10000 to convert to ms\r
+  //\r
+  SleepTime = DivU64x32 (MultU64x32 ((UINT64) TickNumber, TICK_PERIOD) + 9999, 10000);\r
+  gEmuThunk->Sleep (SleepTime);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuMetronomeDriverInitialize (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Initialize the Metronome Architectural Protocol driver\r
+\r
+Arguments:\r
+\r
+  ImageHandle - ImageHandle of the loaded driver\r
+\r
+\r
+  SystemTable - Pointer to the System Table\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - Metronome Architectural Protocol created\r
+\r
+  EFI_OUT_OF_RESOURCES  - Not enough resources available to initialize driver.\r
+\r
+  EFI_DEVICE_ERROR      - A device error occured attempting to initialize the driver.\r
+\r
+**/\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_HANDLE  Handle;\r
+\r
+\r
+  //\r
+  // Install the Metronome Architectural Protocol onto a new handle\r
+  //\r
+  Handle = NULL;\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &Handle,\r
+                  &gEfiMetronomeArchProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &mMetronome\r
+                  );\r
+\r
+  return Status;\r
+}\r
diff --git a/InOsEmuPkg/MetronomeDxe/Metronome.h b/InOsEmuPkg/MetronomeDxe/Metronome.h
new file mode 100644 (file)
index 0000000..5115e0b
--- /dev/null
@@ -0,0 +1,56 @@
+/*++ @file\r
+  Emu Emulation Metronome Architectural Protocol Driver as defined in DXE CIS\r
+\r
+Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2010 - 2011, Apple Inc. All rights reserved.\r
+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
+#ifndef _EMU_THUNK_METRONOME_H_\r
+#define _EMU_THUNK_METRONOME_H_\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/EmuThunkLib.h>\r
+\r
+#include <Protocol/Metronome.h>\r
+\r
+\r
+\r
+//\r
+// Period of on tick in 100 nanosecond units\r
+//\r
+#define TICK_PERIOD 2000\r
+\r
+//\r
+// Function Prototypes\r
+//\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuMetronomeDriverInitialize (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuMetronomeDriverWaitForTick (\r
+  IN EFI_METRONOME_ARCH_PROTOCOL  *This,\r
+  IN UINT32                       TickNumber\r
+  );\r
+\r
+#endif\r
diff --git a/InOsEmuPkg/MetronomeDxe/Metronome.inf b/InOsEmuPkg/MetronomeDxe/Metronome.inf
new file mode 100644 (file)
index 0000000..4befdf3
--- /dev/null
@@ -0,0 +1,59 @@
+## @file\r
+# Emu Emulation Metronome Architectural Protocol Driver as defined in DXE CIS\r
+#\r
+# This metronome module simulates metronome by Sleep WinAPI.\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = Metronome\r
+  FILE_GUID                      = f348f6fe-8985-11db-b4c3-0040d02b1835\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = EmuMetronomeDriverInitialize\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]\r
+  Metronome.h\r
+  Metronome.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+  \r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  EmuThunkLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  DebugLib\r
+  BaseLib\r
+\r
+\r
+[Protocols]\r
+  gEfiMetronomeArchProtocolGuid                 # PROTOCOL ALWAYS_PRODUCED\r
+\r
+\r
+[Depex]\r
+  TRUE\r
+\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturer.uni b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturer.uni
new file mode 100644 (file)
index 0000000..669654e
Binary files /dev/null and b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturer.uni differ
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerData.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerData.c
new file mode 100644 (file)
index 0000000..52d1204
--- /dev/null
@@ -0,0 +1,57 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
+  MiscBaseBoardManufacturerData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+**/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SMBIOS_TABLE_DATA(EFI_MISC_BASE_BOARD_MANUFACTURER_DATA, MiscBaseBoardManufacturer) = {\r
+  STRING_TOKEN(STR_MISC_BASE_BOARD_MANUFACTURER),\r
+  STRING_TOKEN(STR_MISC_BASE_BOARD_PRODUCT_NAME),\r
+  STRING_TOKEN(STR_MISC_BASE_BOARD_VERSION),\r
+  STRING_TOKEN(STR_MISC_BASE_BOARD_SERIAL_NUMBER),\r
+  STRING_TOKEN(STR_MISC_BASE_BOARD_ASSET_TAG),\r
+  STRING_TOKEN(STR_MISC_BASE_BOARD_CHASSIS_LOCATION),\r
+  {                         // BaseBoardFeatureFlags\r
+    1,                      // Motherboard\r
+    0,                      // RequiresDaughterCard\r
+    0,                      // Removable\r
+    1,                      // Replaceable,\r
+    0,                      // HotSwappable\r
+    0,                      // Reserved\r
+  },\r
+  EfiBaseBoardTypeUnknown,  // BaseBoardType\r
+  {                         // BaseBoardChassisLink\r
+    EFI_MISC_SUBCLASS_GUID, // ProducerName\r
+    1,                      // Instance\r
+    1,                      // SubInstance\r
+  },\r
+  0,                        // BaseBoardNumberLinks\r
+  {                         // LinkN\r
+    EFI_MISC_SUBCLASS_GUID, // ProducerName\r
+    1,                      // Instance\r
+    1,                      // SubInstance\r
+  },\r
+};\r
+\r
+/* eof - MiscBaseBoardManufacturerData.c */\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerFunction.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerFunction.c
new file mode 100644 (file)
index 0000000..04f5a1e
--- /dev/null
@@ -0,0 +1,167 @@
+/** @file\r
+  BaseBoard manufacturer information boot time changes.\r
+  SMBIOS type 2.\r
+\r
+  Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
+  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
+#include "MiscSubClassDriver.h"\r
+/**\r
+  This function makes boot time changes to the contents of the\r
+  MiscBaseBoardManufacturer (Type 2).\r
+\r
+  @param  RecordData                 Pointer to copy of RecordData from the Data Table.  \r
+\r
+  @retval EFI_SUCCESS                All parameters were valid.\r
+  @retval EFI_UNSUPPORTED            Unexpected RecordType value.\r
+  @retval EFI_INVALID_PARAMETER      Invalid parameter was found.\r
+\r
+**/\r
+MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer)\r
+{\r
+  CHAR8                           *OptionalStrStart;\r
+  UINTN                           ManuStrLen;\r
+  UINTN                           ProductStrLen;\r
+  UINTN                           VerStrLen;\r
+  UINTN                           AssertTagStrLen;\r
+  UINTN                           SerialNumStrLen;\r
+  UINTN                           ChassisStrLen;\r
+  EFI_STATUS                      Status;\r
+  EFI_STRING                      Manufacturer;\r
+  EFI_STRING                      Product;\r
+  EFI_STRING                      Version;\r
+  EFI_STRING                      SerialNumber;\r
+  EFI_STRING                      AssertTag;\r
+  EFI_STRING                      Chassis;\r
+  STRING_REF                      TokenToGet;\r
+  EFI_SMBIOS_HANDLE               SmbiosHandle;\r
+  SMBIOS_TABLE_TYPE2              *SmbiosRecord;\r
+  EFI_MISC_BASE_BOARD_MANUFACTURER   *ForType2InputData;\r
+\r
+  ForType2InputData = (EFI_MISC_BASE_BOARD_MANUFACTURER *)RecordData;\r
+\r
+  //\r
+  // First check for invalid parameters.\r
+  //\r
+  if (RecordData == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_MANUFACTURER);\r
+  Manufacturer = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  ManuStrLen = StrLen(Manufacturer);\r
+  if (ManuStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_PRODUCT_NAME);\r
+  Product = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  ProductStrLen = StrLen(Product);\r
+  if (ProductStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_VERSION);\r
+  Version = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  VerStrLen = StrLen(Version);\r
+  if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_SERIAL_NUMBER);\r
+  SerialNumber = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  SerialNumStrLen = StrLen(SerialNumber);\r
+  if (SerialNumStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_ASSET_TAG);\r
+  AssertTag = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  AssertTagStrLen = StrLen(AssertTag);\r
+  if (AssertTagStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_CHASSIS_LOCATION);\r
+  Chassis = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  ChassisStrLen = StrLen(Chassis);\r
+  if (ChassisStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+\r
+  //\r
+  // Two zeros following the last string.\r
+  //\r
+  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + ChassisStrLen +1 + 1);\r
+  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + ChassisStrLen +1 + 1);\r
+\r
+  SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION;\r
+  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE2);\r
+  //\r
+  // Make handle chosen by smbios protocol.add automatically.\r
+  //\r
+  SmbiosRecord->Hdr.Handle = 0;  \r
+  //\r
+  // Manu will be the 1st optional string following the formatted structure.\r
+  // \r
+  SmbiosRecord->Manufacturer = 1;  \r
+  //\r
+  // ProductName will be the 2st optional string following the formatted structure.\r
+  // \r
+  SmbiosRecord->ProductName  = 2;  \r
+  //\r
+  // Version will be the 3rd optional string following the formatted structure.\r
+  //\r
+  SmbiosRecord->Version = 3;  \r
+  //\r
+  // SerialNumber will be the 4th optional string following the formatted structure.\r
+  //\r
+  SmbiosRecord->SerialNumber = 4;  \r
+  //\r
+  // AssertTag will be the 5th optional string following the formatted structure.\r
+  //\r
+  SmbiosRecord->AssetTag = 5;  \r
+\r
+  //\r
+  // LocationInChassis will be the 6th optional string following the formatted structure.\r
+  //\r
+  SmbiosRecord->LocationInChassis = 6;  \r
+  SmbiosRecord->FeatureFlag = (*(BASE_BOARD_FEATURE_FLAGS*)&(ForType2InputData->BaseBoardFeatureFlags));\r
+  SmbiosRecord->ChassisHandle  = 0;\r
+  SmbiosRecord->BoardType      = (UINT8)ForType2InputData->BaseBoardType;\r
+  SmbiosRecord->NumberOfContainedObjectHandles = 0;\r
+  \r
+  OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);\r
+  //\r
+  // Since we fill NumberOfContainedObjectHandles = 0 for simple, just after this filed to fill string\r
+  //\r
+  OptionalStrStart -= 2;\r
+  UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart);\r
+  UnicodeStrToAsciiStr(Product, OptionalStrStart + ManuStrLen + 1);\r
+  UnicodeStrToAsciiStr(Version, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1);\r
+  UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1);\r
+  UnicodeStrToAsciiStr(AssertTag, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1);\r
+  UnicodeStrToAsciiStr(Chassis, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1);\r
+  //\r
+  // Now we have got the full smbios record, call smbios protocol to add this record.\r
+  //\r
+  SmbiosHandle = 0;\r
+  Status = Smbios-> Add(\r
+                      Smbios, \r
+                      NULL,\r
+                      &SmbiosHandle, \r
+                      (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord\r
+                      );\r
+\r
+  FreePool(SmbiosRecord);\r
+  return Status;\r
+}\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscBiosVendor.uni b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscBiosVendor.uni
new file mode 100644 (file)
index 0000000..dda02d2
Binary files /dev/null and b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscBiosVendor.uni differ
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscBiosVendorData.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscBiosVendorData.c
new file mode 100644 (file)
index 0000000..b9a8ced
--- /dev/null
@@ -0,0 +1,88 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
+  MiscBiosVendorData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+**/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SMBIOS_TABLE_DATA(EFI_MISC_BIOS_VENDOR_DATA, MiscBiosVendor) = {\r
+  STRING_TOKEN(STR_MISC_BIOS_VENDOR),       // BiosVendor\r
+  STRING_TOKEN(STR_MISC_BIOS_VERSION),      // BiosVersion\r
+  STRING_TOKEN(STR_MISC_BIOS_RELEASE_DATE), // BiosReleaseDate\r
+  0xBABE, // BiosStartingAddress\r
+  {       // BiosPhysicalDeviceSize\r
+    2,    // Value\r
+    3,    // Exponent\r
+  },\r
+  {       // BiosCharacteristics1\r
+    0,    // Reserved1                         :2\r
+    0,    // Unknown                           :1\r
+    1,    // BiosCharacteristicsNotSupported   :1\r
+    0,    // IsaIsSupported                    :1\r
+    0,    // McaIsSupported                    :1\r
+    0,    // EisaIsSupported                   :1\r
+    0,    // PciIsSupported                    :1\r
+    0,    // PcmciaIsSupported                 :1\r
+    0,    // PlugAndPlayIsSupported            :1\r
+    0,    // ApmIsSupported                    :1\r
+    0,    // BiosIsUpgradable                  :1\r
+    0,    // BiosShadowingAllowed              :1\r
+    0,    // VlVesaIsSupported                 :1\r
+    0,    // EscdSupportIsAvailable            :1\r
+    0,    // BootFromCdIsSupported             :1\r
+    0,    // SelectableBootIsSupported         :1\r
+    0,    // RomBiosIsSocketed                 :1\r
+    0,    // BootFromPcmciaIsSupported         :1\r
+    0,    // EDDSpecificationIsSupported       :1\r
+    0,    // JapaneseNecFloppyIsSupported      :1\r
+    0,    // JapaneseToshibaFloppyIsSupported  :1\r
+    0,    // Floppy525_360IsSupported          :1\r
+    0,    // Floppy525_12IsSupported           :1\r
+    0,    // Floppy35_720IsSupported           :1\r
+    0,    // Floppy35_288IsSupported           :1\r
+    0,    // PrintScreenIsSupported            :1\r
+    0,    // Keyboard8042IsSupported           :1\r
+    0,    // SerialIsSupported                 :1\r
+    0,    // PrinterIsSupported                :1\r
+    0,    // CgaMonoIsSupported                :1\r
+    0,    // NecPc98                           :1\r
+    0,    // AcpiIsSupported                   :1\r
+    0,    // UsbLegacyIsSupported              :1\r
+    0,    // AgpIsSupported                    :1\r
+    0,    // I20BootIsSupported                :1\r
+    0,    // Ls120BootIsSupported              :1\r
+    0,    // AtapiZipDriveBootIsSupported      :1\r
+    0,    // Boot1394IsSupported               :1\r
+    0,    // SmartBatteryIsSupported           :1\r
+    0,    // BiosBootSpecIsSupported           :1\r
+    0,    // FunctionKeyNetworkBootIsSupported :1\r
+    0     // Reserved                          :22\r
+  },\r
+  {       // BiosCharacteristics2\r
+    0,    // BiosReserved                      :16\r
+    0,    // SystemReserved                    :16\r
+    0     // Reserved                          :32\r
+  },\r
+};\r
+\r
+/* eof - MiscBiosVendorData.c */\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscBiosVendorFunction.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscBiosVendorFunction.c
new file mode 100644 (file)
index 0000000..6d64ef4
--- /dev/null
@@ -0,0 +1,202 @@
+/** @file\r
+  BIOS vendor information boot time changes.\r
+  Misc. subclass type 2.\r
+  SMBIOS type 0.\r
+\r
+  Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
+  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
+#include "MiscSubClassDriver.h"\r
+\r
+/**\r
+  This function returns the value & exponent to Base2 for a given\r
+  Hex value. This is used to calculate the BiosPhysicalDeviceSize.\r
+\r
+  @param Value                      The hex value which is to be converted into value-exponent form\r
+  @param Exponent                   The exponent out of the conversion\r
+\r
+  @retval EFI_SUCCESS               All parameters were valid and *Value & *Exponent have been set.\r
+  @retval EFI_INVALID_PARAMETER     Invalid parameter was found.\r
+  \r
+**/\r
+EFI_STATUS  \r
+GetValueExponentBase2(\r
+  IN OUT UINTN        *Value,\r
+  OUT    UINTN        *Exponent\r
+  )\r
+{\r
+  if ((Value == NULL) || (Exponent == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  while ((*Value % 2) == 0) {\r
+    *Value=*Value/2;\r
+    (*Exponent)++;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Field Filling Function. Transform an EFI_EXP_BASE2_DATA to a byte, with '64k'\r
+  as the unit.\r
+\r
+  @param  Base2Data              Pointer to Base2_Data\r
+\r
+  @retval EFI_SUCCESS            Transform successfully.       \r
+  @retval EFI_INVALID_PARAMETER  Invalid parameter was found.    \r
+\r
+**/\r
+UINT16\r
+Base2ToByteWith64KUnit (\r
+  IN      EFI_EXP_BASE2_DATA  *Base2Data\r
+  )\r
+{  \r
+  UINT16              Value;\r
+  UINT16              Exponent;\r
+\r
+  Value     = Base2Data->Value;\r
+  Exponent  = Base2Data->Exponent;\r
+  Exponent -= 16;\r
+  Value <<= Exponent;\r
+\r
+  return Value;\r
+}\r
+\r
+\r
+/**\r
+  This function makes boot time changes to the contents of the\r
+  MiscBiosVendor (Type 0).\r
+\r
+  @param  RecordData                 Pointer to copy of RecordData from the Data Table.\r
+\r
+  @retval EFI_SUCCESS                All parameters were valid.\r
+  @retval EFI_UNSUPPORTED            Unexpected RecordType value.\r
+  @retval EFI_INVALID_PARAMETER      Invalid parameter was found.\r
+\r
+**/\r
+MISC_SMBIOS_TABLE_FUNCTION(MiscBiosVendor)\r
+{\r
+  CHAR8                 *OptionalStrStart;\r
+  UINTN                 VendorStrLen;\r
+  UINTN                 VerStrLen;\r
+  UINTN                 DateStrLen;\r
+  CHAR16                *Version;\r
+  CHAR16                *ReleaseDate;\r
+  EFI_STATUS            Status;\r
+  EFI_STRING            Char16String;\r
+  STRING_REF            TokenToGet;\r
+  STRING_REF            TokenToUpdate;\r
+  SMBIOS_TABLE_TYPE0    *SmbiosRecord;\r
+  EFI_SMBIOS_HANDLE     SmbiosHandle;\r
+  EFI_MISC_BIOS_VENDOR *ForType0InputData;\r
+\r
+  ForType0InputData        = (EFI_MISC_BIOS_VENDOR *)RecordData;\r
+\r
+  //\r
+  // First check for invalid parameters.\r
+  //\r
+  if (RecordData == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Version = (CHAR16 *) PcdGetPtr (PcdFirmwareVersionString);\r
+  if (StrLen (Version) > 0) {     \r
+    TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_VERSION);\r
+    HiiSetString (mHiiHandle, TokenToUpdate, Version, NULL);\r
+  }\r
+  \r
+  ReleaseDate = (CHAR16 *) PcdGetPtr (PcdFirmwareReleaseDateString);\r
+  if (StrLen(ReleaseDate) > 0) {\r
+    TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE);\r
+    HiiSetString (mHiiHandle, TokenToUpdate, ReleaseDate, NULL);\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_BIOS_VENDOR);\r
+  Char16String = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  VendorStrLen = StrLen(Char16String);\r
+  if (VendorStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_BIOS_VERSION);\r
+  Version = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  VerStrLen = StrLen(Version);\r
+  if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE);\r
+  ReleaseDate = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  DateStrLen = StrLen(ReleaseDate);\r
+  if (DateStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  \r
+  //\r
+  // Two zeros following the last string.\r
+  //\r
+  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE0) + VendorStrLen + 1 + VerStrLen + 1 + DateStrLen + 1 + 1);\r
+  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE0) + VendorStrLen + 1 + VerStrLen + 1 + DateStrLen + 1 + 1);\r
+\r
+  SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BIOS_INFORMATION;\r
+  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE0);\r
+  //\r
+  // Make handle chosen by smbios protocol.add automatically.\r
+  //\r
+  SmbiosRecord->Hdr.Handle = 0;\r
+  //\r
+  // Vendor will be the 1st optional string following the formatted structure.\r
+  //\r
+  SmbiosRecord->Vendor = 1;  \r
+  //\r
+  // Version will be the 2nd optional string following the formatted structure.\r
+  //\r
+  SmbiosRecord->BiosVersion = 2;\r
+  SmbiosRecord->BiosSegment = (UINT16)ForType0InputData->BiosStartingAddress;\r
+  //\r
+  // ReleaseDate will be the 3rd optional string following the formatted structure.\r
+  //\r
+  SmbiosRecord->BiosReleaseDate = 3;\r
+  //\r
+  // Nt32 has no PCD value to indicate BIOS Size, just fill 0 for simply.\r
+  //\r
+  SmbiosRecord->BiosSize = 0;\r
+  SmbiosRecord->BiosCharacteristics = *(MISC_BIOS_CHARACTERISTICS*)(&ForType0InputData->BiosCharacteristics1);\r
+  //\r
+  // CharacterExtensionBytes also store in ForType0InputData->BiosCharacteristics1 later two bytes to save size.\r
+  //\r
+  SmbiosRecord->BIOSCharacteristicsExtensionBytes[0] = *((UINT8 *) &ForType0InputData->BiosCharacteristics1 + 4);\r
+  SmbiosRecord->BIOSCharacteristicsExtensionBytes[1] = *((UINT8 *) &ForType0InputData->BiosCharacteristics1 + 5);\r
+\r
+  SmbiosRecord->SystemBiosMajorRelease = ForType0InputData->BiosMajorRelease;\r
+  SmbiosRecord->SystemBiosMinorRelease = ForType0InputData->BiosMinorRelease;\r
+  SmbiosRecord->EmbeddedControllerFirmwareMajorRelease = ForType0InputData->BiosEmbeddedFirmwareMajorRelease;\r
+  SmbiosRecord->EmbeddedControllerFirmwareMinorRelease = ForType0InputData->BiosEmbeddedFirmwareMinorRelease;\r
+\r
+  OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);\r
+  UnicodeStrToAsciiStr(Char16String, OptionalStrStart);\r
+  UnicodeStrToAsciiStr(Version, OptionalStrStart + VendorStrLen + 1);\r
+  UnicodeStrToAsciiStr(ReleaseDate, OptionalStrStart + VendorStrLen + 1 + VerStrLen + 1);\r
+  //\r
+  // Now we have got the full smbios record, call smbios protocol to add this record.\r
+  //\r
+  SmbiosHandle = 0;\r
+  Status = Smbios-> Add(\r
+                      Smbios, \r
+                      NULL,\r
+                      &SmbiosHandle, \r
+                      (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord\r
+                      );\r
+\r
+  FreePool(SmbiosRecord);\r
+  return Status;\r
+}\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscBootInformationData.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscBootInformationData.c
new file mode 100644 (file)
index 0000000..0b7c57a
--- /dev/null
@@ -0,0 +1,33 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
+  MiscBootInformationData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+**/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SMBIOS_TABLE_DATA(EFI_MISC_BOOT_INFORMATION_STATUS_DATA, BootInformationStatus) = {\r
+  EfiBootInformationStatusNoError,  // BootInformationStatus\r
+  {0}                                 // BootInformationData\r
+};\r
+\r
+/* eof - MiscBootInformationData.c */\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscBootInformationFunction.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscBootInformationFunction.c
new file mode 100644 (file)
index 0000000..65c9792
--- /dev/null
@@ -0,0 +1,73 @@
+/** @file\r
+  boot information boot time changes.\r
+  SMBIOS type 32.\r
+\r
+  Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
+  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
+#include "MiscSubClassDriver.h"\r
+\r
+\r
+/**\r
+  This function makes boot time changes to the contents of the\r
+  MiscBootInformation (Type 32).\r
+\r
+  @param  RecordData                 Pointer to copy of RecordData from the Data Table.  \r
+\r
+  @retval EFI_SUCCESS                All parameters were valid.\r
+  @retval EFI_UNSUPPORTED            Unexpected RecordType value.\r
+  @retval EFI_INVALID_PARAMETER      Invalid parameter was found.\r
+\r
+**/\r
+\r
+MISC_SMBIOS_TABLE_FUNCTION(BootInformationStatus)\r
+{\r
+  EFI_STATUS                         Status;\r
+  EFI_SMBIOS_HANDLE                  SmbiosHandle;\r
+  SMBIOS_TABLE_TYPE32                *SmbiosRecord;\r
+  EFI_MISC_BOOT_INFORMATION_STATUS*  ForType32InputData;\r
\r
+  ForType32InputData = (EFI_MISC_BOOT_INFORMATION_STATUS *)RecordData;\r
+\r
+  //\r
+  // First check for invalid parameters.\r
+  //\r
+  if (RecordData == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Two zeros following the last string.\r
+  //\r
+  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE32) + 1 + 1);\r
+  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE32) + 1 + 1);\r
+\r
+  SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_BOOT_INFORMATION;\r
+  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE32);\r
+  //\r
+  // Make handle chosen by smbios protocol.add automatically.\r
+  //\r
+  SmbiosRecord->Hdr.Handle = 0;  \r
+  SmbiosRecord->BootStatus = (UINT8)ForType32InputData->BootInformationStatus;\r
+\r
+  //\r
+  // Now we have got the full smbios record, call smbios protocol to add this record.\r
+  //\r
+  SmbiosHandle = 0;\r
+  Status = Smbios-> Add(\r
+                      Smbios, \r
+                      NULL,\r
+                      &SmbiosHandle, \r
+                      (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord\r
+                      );\r
+  FreePool(SmbiosRecord);\r
+  return Status;\r
+}\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscChassisManufacturer.uni b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscChassisManufacturer.uni
new file mode 100644 (file)
index 0000000..177ff38
Binary files /dev/null and b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscChassisManufacturer.uni differ
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscChassisManufacturerData.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscChassisManufacturerData.c
new file mode 100644 (file)
index 0000000..795658b
--- /dev/null
@@ -0,0 +1,45 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
+  MiscChassisManufacturerData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+**/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Chassis Manufacturer data.\r
+//\r
+MISC_SMBIOS_TABLE_DATA(EFI_MISC_CHASSIS_MANUFACTURER_DATA, MiscChassisManufacturer) = {\r
+  STRING_TOKEN(STR_MISC_CHASSIS_MANUFACTURER),  // ChassisManufactrurer\r
+  STRING_TOKEN(STR_MISC_CHASSIS_VERSION),       // ChassisVersion\r
+  STRING_TOKEN(STR_MISC_CHASSIS_SERIAL_NUMBER), // ChassisSerialNumber\r
+  STRING_TOKEN(STR_MISC_CHASSIS_ASSET_TAG),     // ChassisAssetTag\r
+  {                               // ChassisTypeStatus\r
+    EfiMiscChassisTypeOther,      // ChassisType\r
+    0,                            // ChassisLockPresent\r
+    0                             // Reserved\r
+  },\r
+  EfiChassisStateOther,           // ChassisBootupState\r
+  EfiChassisStateOther,           // ChassisPowerSupplyState\r
+  EfiChassisStateOther,           // ChassisThermalState\r
+  EfiChassisSecurityStatusOther,  // ChassisSecurityState\r
+  0                               // ChassisOemDefined\r
+};\r
+\r
+/* eof - MiscChassisManufacaturerData.c */\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscChassisManufacturerFunction.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscChassisManufacturerFunction.c
new file mode 100644 (file)
index 0000000..fd1262b
--- /dev/null
@@ -0,0 +1,137 @@
+/** @file\r
+  Chassis manufacturer information boot time changes.\r
+  SMBIOS type 3.\r
+\r
+  Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
+  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
+#include "MiscSubClassDriver.h"\r
+\r
+/**\r
+  This function makes boot time changes to the contents of the\r
+  MiscChassisManufacturer (Type 3).\r
+\r
+  @param  RecordData                 Pointer to copy of RecordData from the Data Table.  \r
+\r
+  @retval EFI_SUCCESS                All parameters were valid.\r
+  @retval EFI_UNSUPPORTED            Unexpected RecordType value.\r
+  @retval EFI_INVALID_PARAMETER      Invalid parameter was found.\r
+\r
+**/\r
+MISC_SMBIOS_TABLE_FUNCTION(MiscChassisManufacturer)\r
+{\r
+  CHAR8                           *OptionalStrStart;\r
+  UINTN                           ManuStrLen;\r
+  UINTN                           VerStrLen;\r
+  UINTN                           AssertTagStrLen;\r
+  UINTN                           SerialNumStrLen;\r
+  EFI_STATUS                      Status;\r
+  EFI_STRING                      Manufacturer;\r
+  EFI_STRING                      Version;\r
+  EFI_STRING                      SerialNumber;\r
+  EFI_STRING                      AssertTag;\r
+  STRING_REF                      TokenToGet;\r
+  EFI_SMBIOS_HANDLE               SmbiosHandle;\r
+  SMBIOS_TABLE_TYPE3              *SmbiosRecord;\r
+  EFI_MISC_CHASSIS_MANUFACTURER   *ForType3InputData;\r
+\r
+  ForType3InputData = (EFI_MISC_CHASSIS_MANUFACTURER *)RecordData;\r
+\r
+  //\r
+  // First check for invalid parameters.\r
+  //\r
+  if (RecordData == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_MANUFACTURER);\r
+  Manufacturer = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  ManuStrLen = StrLen(Manufacturer);\r
+  if (ManuStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_VERSION);\r
+  Version = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  VerStrLen = StrLen(Version);\r
+  if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_SERIAL_NUMBER);\r
+  SerialNumber = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  SerialNumStrLen = StrLen(SerialNumber);\r
+  if (SerialNumStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_ASSET_TAG);\r
+  AssertTag = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  AssertTagStrLen = StrLen(AssertTag);\r
+  if (AssertTagStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Two zeros following the last string.\r
+  //\r
+  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1  + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + 1);\r
+  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1  + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + 1);\r
+\r
+  SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_ENCLOSURE;\r
+  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE3);\r
+  //\r
+  // Make handle chosen by smbios protocol.add automatically.\r
+  //\r
+  SmbiosRecord->Hdr.Handle = 0;  \r
+  //\r
+  // Manu will be the 1st optional string following the formatted structure.\r
+  // \r
+  SmbiosRecord->Manufacturer = 1;  \r
+  SmbiosRecord->Type = (UINT8)ForType3InputData->ChassisType.ChassisType;\r
+  //\r
+  // Version will be the 2nd optional string following the formatted structure.\r
+  //\r
+  SmbiosRecord->Version = 2;  \r
+  //\r
+  // SerialNumber will be the 3rd optional string following the formatted structure.\r
+  //\r
+  SmbiosRecord->SerialNumber = 3;  \r
+  //\r
+  // AssertTag will be the 4th optional string following the formatted structure.\r
+  //\r
+  SmbiosRecord->AssetTag = 4;  \r
+  SmbiosRecord->BootupState = (UINT8)ForType3InputData->ChassisBootupState;\r
+  SmbiosRecord->PowerSupplyState = (UINT8)ForType3InputData->ChassisPowerSupplyState;\r
+  SmbiosRecord->ThermalState = (UINT8)ForType3InputData->ChassisThermalState;\r
+  SmbiosRecord->SecurityStatus = (UINT8)ForType3InputData->ChassisSecurityState;\r
+  CopyMem (SmbiosRecord->OemDefined,(UINT8*)&ForType3InputData->ChassisOemDefined, 4);\r
+\r
+  OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);\r
+  UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart);\r
+  UnicodeStrToAsciiStr(Version, OptionalStrStart + ManuStrLen + 1);\r
+  UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + ManuStrLen + 1 + VerStrLen + 1);\r
+  UnicodeStrToAsciiStr(AssertTag, OptionalStrStart + ManuStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1);\r
+\r
+  //\r
+  // Now we have got the full smbios record, call smbios protocol to add this record.\r
+  //\r
+  SmbiosHandle = 0;\r
+  Status = Smbios-> Add(\r
+                      Smbios, \r
+                      NULL,\r
+                      &SmbiosHandle, \r
+                      (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord\r
+                      );\r
+\r
+  FreePool(SmbiosRecord);\r
+  return Status;\r
+}\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscDevicePath.h b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscDevicePath.h
new file mode 100644 (file)
index 0000000..b1a9acf
--- /dev/null
@@ -0,0 +1,175 @@
+/*++\r
\r
+Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+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
+  MiscDevicePath.h\r
+\r
+Abstract:\r
+\r
+  Misc class required EFI Device Path definitions (Ports, slots & \r
+  onboard devices)\r
+\r
+**/\r
+\r
+#ifndef _MISC_DEVICE_PATH_H\r
+#define _MISC_DEVICE_PATH_H\r
+\r
+\r
+#pragma pack(1)\r
+//\r
+// USB\r
+//\r
+\r
+/* For reference:\r
+#define USB1_1_STR  "ACPI(PNP0A03,0)/PCI(1D,0)."\r
+#define USB1_2_STR  "ACPI(PNP0A03,0)/PCI(1D,1)."\r
+#define USB1_3_STR  "ACPI(PNP0A03,0)/PCI(1D,2)."\r
+#define USB2_1_STR  "ACPI(PNP0A03,0)/PCI(1D,7)." \r
+*/\r
+\r
+//\r
+// #define acpi { 0x02, 0x01, 0x00, 0x0C, 0x0a0341d0, 0x00000000 }\r
+// #define pci( device,function)  { 0x01, 0x01, 0x00, 0x06, device, function }\r
+// #define end  { 0xFF, 0xFF, 0x00, 0x04 }\r
+//\r
+#define DP_ACPI \\r
+  { \\r
+      {ACPI_DEVICE_PATH, ACPI_DP, {(UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), (UINT8) \\r
+      ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8)}}, EISA_PNP_ID (0x0A03), 0 \\r
+  }\r
+#define DP_PCI(device, function) \\r
+  { \\r
+      {HARDWARE_DEVICE_PATH, HW_PCI_DP, {(UINT8) (sizeof (PCI_DEVICE_PATH)), (UINT8) \\r
+       ((sizeof (PCI_DEVICE_PATH)) >> 8)}}, function, device \\r
+  }\r
+#define DP_END \\r
+  { \\r
+    END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, {END_DEVICE_PATH_LENGTH, 0} \\r
+  }\r
+\r
+#define DP_LPC(eisaid, function) \\r
+  { \\r
+    {ACPI_DEVICE_PATH, ACPI_DP, {(UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), (UINT8) \\r
+     ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8)}}, EISA_PNP_ID (eisaid), function \\r
+  }\r
+\r
+//\r
+// Shanmu >> moved to TianoDevicePath.h\r
+//\r
+\r
+/*\r
+typedef struct _USB_PORT_DEVICE_PATH\r
+{\r
+  ACPI_HID_DEVICE_PATH    PciRootBridgeDevicePath;\r
+  PCI_DEVICE_PATH      PciBusDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+} USB_PORT_DEVICE_PATH;\r
+\r
+\r
+//IDE ??I am not sure. Should this be ATAPI_DEVICE_PATH\r
+typedef struct _IDE_DEVICE_PATH\r
+{\r
+  ACPI_HID_DEVICE_PATH    PciRootBridgeDevicePath;\r
+  PCI_DEVICE_PATH      PciBusDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+} IDE_DEVICE_PATH;\r
+\r
+//RMC Connector\r
+typedef struct _RMC_CONN_DEVICE_PATH\r
+{\r
+  ACPI_HID_DEVICE_PATH    PciRootBridgeDevicePath;\r
+  PCI_DEVICE_PATH      PciBridgeDevicePath;\r
+  PCI_DEVICE_PATH      PciBusDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+} RMC_CONN_DEVICE_PATH;\r
+\r
+//static RMC_CONN_DEVICE_PATH mRmcConnDevicePath = { acpi, pci( 0x1E,0x00 ),pci( 0x0A,0x00 ), end };\r
+\r
+//RIDE\r
+typedef struct _RIDE_DEVICE_PATH\r
+{\r
+  ACPI_HID_DEVICE_PATH    PciRootBridgeDevicePath;\r
+  PCI_DEVICE_PATH      PciBridgeDevicePath;\r
+  PCI_DEVICE_PATH      PciBusDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+} RIDE_DEVICE_PATH;\r
+\r
+//static RIDE_DEVICE_PATH mRideDevicePath = { acpi, pci( 0x1E,0x00 ),pci( 0x02,0x00 ), end };\r
+\r
+//Gigabit NIC\r
+//typedef struct _GB_NIC_DEVICE_PATH\r
+//{\r
+//  ACPI_HID_DEVICE_PATH      PciRootBridgeDevicePath;\r
+//  PCI_DEVICE_PATH            PciBridgeDevicePath;\r
+//  PCI_DEVICE_PATH            PciXBridgeDevicePath;\r
+//  PCI_DEVICE_PATH            PciXBusDevicePath;\r
+//  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+//} GB_NIC_DEVICE_PATH;\r
+\r
+//static GB_NIC_DEVICE_PATH mGbNicDevicePath = { acpi, pci( 0x03,0x00 ),pci( 0x1F,0x00 ),pci( 0x07,0x00 ), end };\r
+\r
+\r
+//P/S2 Connector\r
+typedef struct _PS2_CONN_DEVICE_PATH\r
+{\r
+  ACPI_HID_DEVICE_PATH    PciRootBridgeDevicePath;\r
+  PCI_DEVICE_PATH      LpcBridgeDevicePath;\r
+  ACPI_HID_DEVICE_PATH    LpcBusDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+} PS2_CONN_DEVICE_PATH;\r
+\r
+//static PS2_CONN_DEVICE_PATH mPs2KeyboardDevicePath   = { acpi, pci( 0x1F,0x00 ),lpc( 0x0303,0 ), end };\r
+//static PS2_CONN_DEVICE_PATH mPs2MouseDevicePath      = { acpi, pci( 0x1F,0x00 ),lpc( 0x0303,1 ), end };\r
+\r
+//Serial Port Connector\r
+typedef struct _SERIAL_CONN_DEVICE_PATH\r
+{\r
+  ACPI_HID_DEVICE_PATH    PciRootBridgeDevicePath;\r
+  PCI_DEVICE_PATH      LpcBridgeDevicePath;\r
+  ACPI_HID_DEVICE_PATH    LpcBusDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+} SERIAL_CONN_DEVICE_PATH;\r
+\r
+//static SERIAL_CONN_DEVICE_PATH mCom1DevicePath   = { acpi, pci( 0x1F,0x00 ),lpc( 0x0501,0 ), end };\r
+//static SERIAL_CONN_DEVICE_PATH mCom2DevicePath   = { acpi, pci( 0x1F,0x00 ),lpc( 0x0501,1 ), end };\r
+\r
+//Parallel Port Connector\r
+typedef struct _PARALLEL_CONN_DEVICE_PATH\r
+{\r
+  ACPI_HID_DEVICE_PATH    PciRootBridgeDevicePath;\r
+  PCI_DEVICE_PATH      LpcBridgeDevicePath;\r
+  ACPI_HID_DEVICE_PATH    LpcBusDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+} PARALLEL_CONN_DEVICE_PATH;\r
+\r
+//static PARALLEL_CONN_DEVICE_PATH mLpt1DevicePath   = { acpi, pci( 0x1F,0x00 ),lpc( 0x0401,0 ), end };\r
+\r
+//Floopy Connector\r
+typedef struct _FLOOPY_CONN_DEVICE_PATH\r
+{\r
+  ACPI_HID_DEVICE_PATH    PciRootBridgeDevicePath;\r
+  PCI_DEVICE_PATH      LpcBridgeDevicePath;\r
+  ACPI_HID_DEVICE_PATH    LpcBusDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+} FLOOPY_CONN_DEVICE_PATH;\r
+\r
+//static FLOOPY_CONN_DEVICE_PATH mFloopyADevicePath   = { acpi, pci( 0x1F,0x00 ),lpc( 0x0604,0 ), end };\r
+//static FLOOPY_CONN_DEVICE_PATH mFloopyBDevicePath   = { acpi, pci( 0x1F,0x00 ),lpc( 0x0604,1 ), end };\r
+\r
+*/\r
+\r
+//\r
+// End Shanmu\r
+//\r
+#pragma pack()\r
+\r
+#endif\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscNumberOfInstallableLanguagesData.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscNumberOfInstallableLanguagesData.c
new file mode 100644 (file)
index 0000000..88d9d0f
--- /dev/null
@@ -0,0 +1,38 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
+  MiscNumberOfInstallableLanguagesData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+**/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SMBIOS_TABLE_DATA(EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES_DATA, NumberOfInstallableLanguages)\r
+= {\r
+  1,    // NumberOfInstallableLanguages\r
+  {     // LanguageFlags\r
+    0,  // AbbreviatedLanguageFormat\r
+    0   // Reserved\r
+  },\r
+  0,    // CurrentLanguageNumber\r
+};\r
+\r
+/* eof - MiscNumberOfInstallableLanguagesData.c */\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscNumberOfInstallableLanguagesFunction.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscNumberOfInstallableLanguagesFunction.c
new file mode 100644 (file)
index 0000000..9bd7f4d
--- /dev/null
@@ -0,0 +1,238 @@
+/** @file\r
+  This driver parses the mSmbiosMiscDataTable structure and reports\r
+  any generated data.\r
+\r
+  Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
+  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
+#include "MiscSubClassDriver.h"\r
+/*++\r
+  Check whether the language is supported for given HII handle\r
+\r
+  @param   HiiHandle     The HII package list handle.\r
+  @param   Offset        The offest of current lanague in the supported languages.\r
+  @param   CurrentLang   The language code.\r
+\r
+  @retval  TRUE          Supported.\r
+  @retval  FALSE         Not Supported.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+CurrentLanguageMatch (\r
+  IN  EFI_HII_HANDLE                   HiiHandle,\r
+  OUT UINT16                           *Offset,\r
+  OUT CHAR8                            *CurrentLang\r
+  )\r
+{\r
+  CHAR8     *DefaultLang;\r
+  CHAR8     *BestLanguage;\r
+  CHAR8     *Languages;\r
+  CHAR8     *MatchLang;\r
+  CHAR8     *EndMatchLang;\r
+  UINTN     CompareLength;\r
+  \r
+  Languages = HiiGetSupportedLanguages (HiiHandle);\r
+  if (Languages == NULL) {\r
+    return;\r
+  }\r
+\r
+  CurrentLang  = GetEfiGlobalVariable (L"PlatformLang");\r
+  DefaultLang  = (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang);\r
+  BestLanguage = GetBestLanguage (\r
+                   Languages,\r
+                   FALSE,\r
+                   (CurrentLang != NULL) ? CurrentLang : "",\r
+                   DefaultLang,\r
+                   NULL\r
+                   );\r
+  if (BestLanguage != NULL) {\r
+    //\r
+    // Find the best matching RFC 4646 language, compute the offset.\r
+    //\r
+    CompareLength = AsciiStrLen (BestLanguage);\r
+    for (MatchLang = Languages, (*Offset) = 0; MatchLang != '\0'; (*Offset)++) {\r
+      //\r
+      // Seek to the end of current match language. \r
+      //\r
+      for (EndMatchLang = MatchLang; *EndMatchLang != '\0' && *EndMatchLang != ';'; EndMatchLang++);\r
+  \r
+      if ((EndMatchLang == MatchLang + CompareLength) && AsciiStrnCmp(MatchLang, BestLanguage, CompareLength) == 0) {\r
+        //\r
+        // Find the current best Language in the supported languages\r
+        //\r
+        break;\r
+      }\r
+      //\r
+      // best language match be in the supported language.\r
+      //\r
+      ASSERT (*EndMatchLang == ';');\r
+      MatchLang = EndMatchLang + 1;\r
+    }\r
+    FreePool (BestLanguage);\r
+  }\r
+\r
+  FreePool (Languages);\r
+  if (CurrentLang != NULL) {\r
+    FreePool (CurrentLang);\r
+  }\r
+  return ;\r
+}\r
+\r
+\r
+/**\r
+  Get next language from language code list (with separator ';').\r
+\r
+  @param  LangCode       Input: point to first language in the list. On\r
+                         Otput: point to next language in the list, or\r
+                                NULL if no more language in the list.\r
+  @param  Lang           The first language in the list.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+GetNextLanguage (\r
+  IN OUT CHAR8      **LangCode,\r
+  OUT CHAR8         *Lang\r
+  )\r
+{\r
+  UINTN  Index;\r
+  CHAR8  *StringPtr;\r
+\r
+  ASSERT (LangCode != NULL);\r
+  ASSERT (*LangCode != NULL);\r
+  ASSERT (Lang != NULL);\r
+\r
+  Index     = 0;\r
+  StringPtr = *LangCode;\r
+  while (StringPtr[Index] != 0 && StringPtr[Index] != ';') {\r
+    Index++;\r
+  }\r
+\r
+  CopyMem (Lang, StringPtr, Index);\r
+  Lang[Index] = 0;\r
+\r
+  if (StringPtr[Index] == ';') {\r
+    Index++;\r
+  }\r
+  *LangCode = StringPtr + Index;\r
+}\r
+\r
+/**\r
+  This function returns the number of supported languages on HiiHandle.\r
+\r
+  @param   HiiHandle    The HII package list handle.\r
+\r
+  @retval  The number of supported languages.\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+GetSupportedLanguageNumber (\r
+  IN EFI_HII_HANDLE    HiiHandle\r
+  )\r
+{\r
+  CHAR8   *Lang;\r
+  CHAR8   *Languages;\r
+  CHAR8   *LanguageString;\r
+  UINT16  LangNumber;\r
+  \r
+  Languages = HiiGetSupportedLanguages (HiiHandle);\r
+  if (Languages == NULL) {\r
+    return 0;\r
+  }\r
+\r
+  LangNumber = 0;\r
+  Lang = AllocatePool (AsciiStrSize (Languages));\r
+  if (Lang != NULL) {\r
+    LanguageString = Languages;\r
+    while (*LanguageString != 0) {\r
+      GetNextLanguage (&LanguageString, Lang);\r
+      LangNumber++;\r
+    }\r
+    FreePool (Lang);\r
+  }\r
+  FreePool (Languages);\r
+  return LangNumber;\r
+}\r
+\r
+\r
+/**\r
+  This function makes boot time changes to the contents of the\r
+  MiscNumberOfInstallableLanguages (Type 13).\r
+\r
+  @param  RecordData                 Pointer to copy of RecordData from the Data Table.\r
+\r
+  @retval EFI_SUCCESS                All parameters were valid.\r
+  @retval EFI_UNSUPPORTED            Unexpected RecordType value.\r
+  @retval EFI_INVALID_PARAMETER      Invalid parameter was found.\r
+\r
+**/\r
+MISC_SMBIOS_TABLE_FUNCTION(NumberOfInstallableLanguages)\r
+{\r
+  UINTN                                     LangStrLen;\r
+  CHAR8                                     CurrentLang[SMBIOS_STRING_MAX_LENGTH + 1];\r
+  CHAR8                                     *OptionalStrStart;\r
+  UINT16                                    Offset;\r
+  EFI_STATUS                                Status;\r
+  EFI_SMBIOS_HANDLE                         SmbiosHandle;\r
+  SMBIOS_TABLE_TYPE13                       *SmbiosRecord;\r
+  EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES  *ForType13InputData;\r
\r
+  ForType13InputData = (EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES *)RecordData;\r
+\r
+  //\r
+  // First check for invalid parameters.\r
+  //\r
+  if (RecordData == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  ForType13InputData->NumberOfInstallableLanguages = GetSupportedLanguageNumber (mHiiHandle);\r
+\r
+  //\r
+  // Try to check if current langcode matches with the langcodes in installed languages\r
+  //\r
+  ZeroMem(CurrentLang, SMBIOS_STRING_MAX_LENGTH + 1);\r
+  CurrentLanguageMatch (mHiiHandle, &Offset, CurrentLang);\r
+  LangStrLen = AsciiStrLen(CurrentLang);\r
+\r
+  //\r
+  // Two zeros following the last string.\r
+  //\r
+  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE13) + LangStrLen + 1 + 1);\r
+  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE13) + LangStrLen + 1 + 1);\r
+\r
+  SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BIOS_LANGUAGE_INFORMATION;\r
+  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE13);\r
+  //\r
+  // Make handle chosen by smbios protocol.add automatically.\r
+  //\r
+  SmbiosRecord->Hdr.Handle = 0;  \r
+\r
+  SmbiosRecord->InstallableLanguages = (UINT8)ForType13InputData->NumberOfInstallableLanguages;\r
+  SmbiosRecord->Flags = (UINT8)ForType13InputData->LanguageFlags.AbbreviatedLanguageFormat;\r
+  SmbiosRecord->CurrentLanguages = 1;\r
+  OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);\r
+  AsciiStrCpy(OptionalStrStart, CurrentLang);\r
+  //\r
+  // Now we have got the full smbios record, call smbios protocol to add this record.\r
+  //\r
+  SmbiosHandle = 0;\r
+  Status = Smbios-> Add(\r
+                      Smbios, \r
+                      NULL,\r
+                      &SmbiosHandle, \r
+                      (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord\r
+                      );\r
+  FreePool(SmbiosRecord);\r
+  return Status;\r
+}\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscOemString.uni b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscOemString.uni
new file mode 100644 (file)
index 0000000..782a83b
Binary files /dev/null and b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscOemString.uni differ
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscOemStringData.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscOemStringData.c
new file mode 100644 (file)
index 0000000..1d07815
--- /dev/null
@@ -0,0 +1,32 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
+    MiscOemStringData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+**/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SMBIOS_TABLE_DATA(EFI_MISC_OEM_STRING_DATA, OemString) = {\r
+  { STRING_TOKEN(STR_MISC_OEM_STRING) }\r
+};\r
+\r
+/* eof - MiscOemStringData.c */\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscOemStringFunction.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscOemStringFunction.c
new file mode 100644 (file)
index 0000000..94fc71c
--- /dev/null
@@ -0,0 +1,80 @@
+/** @file\r
+  boot information boot time changes.\r
+  SMBIOS type 11.\r
+\r
+  Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
+  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
+#include "MiscSubClassDriver.h"\r
+/**\r
+  This function makes boot time changes to the contents of the\r
+  MiscOemString (Type 11).\r
+\r
+  @param  RecordData                 Pointer to copy of RecordData from the Data Table.  \r
+\r
+  @retval EFI_SUCCESS                All parameters were valid.\r
+  @retval EFI_UNSUPPORTED            Unexpected RecordType value.\r
+  @retval EFI_INVALID_PARAMETER      Invalid parameter was found.\r
+\r
+**/\r
+MISC_SMBIOS_TABLE_FUNCTION(OemString)\r
+{\r
+  UINTN                    OemStrLen;\r
+  CHAR8                    *OptionalStrStart;\r
+  EFI_STATUS               Status;\r
+  EFI_STRING               OemStr;\r
+  STRING_REF               TokenToGet;\r
+  EFI_SMBIOS_HANDLE        SmbiosHandle;\r
+  SMBIOS_TABLE_TYPE11      *SmbiosRecord;\r
+\r
+  //\r
+  // First check for invalid parameters.\r
+  //\r
+  if (RecordData == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_OEM_STRING);\r
+  OemStr = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  OemStrLen = StrLen(OemStr);\r
+  if (OemStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Two zeros following the last string.\r
+  //\r
+  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE11) + OemStrLen + 1 + 1);\r
+  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE11) + OemStrLen + 1 + 1);\r
+\r
+  SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_OEM_STRINGS;\r
+  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE11);\r
+  //\r
+  // Make handle chosen by smbios protocol.add automatically.\r
+  // \r
+  SmbiosRecord->Hdr.Handle = 0;  \r
+  SmbiosRecord->StringCount = 1;\r
+  OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);\r
+  UnicodeStrToAsciiStr(OemStr, OptionalStrStart);\r
+\r
+  //\r
+  // Now we have got the full smbios record, call smbios protocol to add this record.\r
+  //\r
+  SmbiosHandle = 0;\r
+  Status = Smbios-> Add(\r
+                      Smbios, \r
+                      NULL,\r
+                      &SmbiosHandle, \r
+                      (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord\r
+                      );\r
+  FreePool(SmbiosRecord);\r
+  return Status;\r
+}\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignator.uni b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignator.uni
new file mode 100644 (file)
index 0000000..87c5a81
Binary files /dev/null and b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignator.uni differ
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorData.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorData.c
new file mode 100644 (file)
index 0000000..7d511e1
--- /dev/null
@@ -0,0 +1,99 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
+  MiscPortInternalConnectorDesignatorData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+**/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SMBIOS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortInternalConnectorDesignator) = {\r
+  STRING_TOKEN(STR_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR),  // PortInternalConnectorDesignator\r
+  STRING_TOKEN(STR_MISC_PORT_EXTERNAL_CONNECTOR_DESIGNATOR),  // PortExternalConnectorDesignator\r
+  EfiPortConnectorTypeOther,  // PortInternalConnectorType\r
+  EfiPortConnectorTypeOther,  // PortExternalConnectorType\r
+  EfiPortTypeNone,            // PortType\r
+  {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath\r
+};\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SMBIOS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortKeyboard) = {\r
+  STRING_TOKEN (STR_MISC_PORT_INTERNAL_KEYBOARD),   // PortInternalConnectorDesignator\r
+  STRING_TOKEN (STR_MISC_PORT_EXTERNAL_KEYBOARD),   // PortExternalConnectorDesignator\r
+  EfiPortConnectorTypeNone, // PortInternalConnectorType\r
+  EfiPortConnectorTypePS2,  // PortExternalConnectorType\r
+  EfiPortTypeKeyboard,      // PortType\r
+  // mPs2KbyboardDevicePath                          // PortPath\r
+  //\r
+  {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath\r
+};\r
+\r
+MISC_SMBIOS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortMouse) = {\r
+  STRING_TOKEN (STR_MISC_PORT_INTERNAL_MOUSE),      // PortInternalConnectorDesignator\r
+  STRING_TOKEN (STR_MISC_PORT_EXTERNAL_MOUSE),      // PortExternalConnectorDesignator\r
+  EfiPortConnectorTypeNone, // PortInternalConnectorType\r
+  EfiPortConnectorTypePS2,  // PortExternalConnectorType\r
+  EfiPortTypeMouse,         // PortType\r
+  // mPs2MouseDevicePath                // PortPath\r
+  //\r
+  {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath\r
+};\r
+\r
+\r
+MISC_SMBIOS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortCom1) = {\r
+  STRING_TOKEN(STR_MISC_PORT_INTERNAL_COM1),\r
+  STRING_TOKEN(STR_MISC_PORT_EXTERNAL_COM1),\r
+  EfiPortConnectorTypeNone,\r
+  EfiPortConnectorTypeDB9Female,\r
+  EfiPortTypeSerial16550ACompatible,\r
+  {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath\r
+};\r
+\r
+MISC_SMBIOS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortCom2) = {\r
+  STRING_TOKEN(STR_MISC_PORT_INTERNAL_COM2),\r
+  STRING_TOKEN(STR_MISC_PORT_EXTERNAL_COM2),\r
+  EfiPortConnectorTypeNone,\r
+  EfiPortConnectorTypeDB9Female,\r
+  EfiPortTypeSerial16550ACompatible,\r
+  {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath\r
+};\r
+\r
+MISC_SMBIOS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortExtensionPower) = {\r
+  STRING_TOKEN(STR_MISC_PORT_INTERNAL_EXTENSION_POWER),\r
+  STRING_TOKEN(STR_MISC_PORT_EXTERNAL_EXTENSION_POWER),\r
+  EfiPortConnectorTypeOther,\r
+  EfiPortConnectorTypeNone,\r
+  EfiPortTypeOther,\r
+  {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath\r
+};\r
+\r
+MISC_SMBIOS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortFloppy) = {\r
+  STRING_TOKEN(STR_MISC_PORT_INTERNAL_FLOPPY),\r
+  STRING_TOKEN(STR_MISC_PORT_EXTERNAL_FLOPPY),\r
+  EfiPortConnectorTypeOnboardFloppy,\r
+  EfiPortConnectorTypeNone,\r
+  EfiPortTypeOther,\r
+  {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath\r
+};\r
+\r
+/* eof - MiscPortInternalConnectorDesignatorData.c */\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorFunction.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorFunction.c
new file mode 100644 (file)
index 0000000..89c8815
--- /dev/null
@@ -0,0 +1,177 @@
+/*++\r
\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
+  MiscPortInternalConnectorDesignatorFunction.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+**/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+\r
+MISC_SMBIOS_TABLE_FUNCTION (\r
+  MiscPortInternalConnectorDesignator\r
+  )\r
+/*++\r
+Description:\r
+\r
+  This function makes boot time changes to the contents of the\r
+  MiscPortConnectorInformation (Type 8).\r
+\r
+Parameters:\r
+\r
+  RecordType\r
+    Type of record to be processed from the Data Table.\r
+    mMiscSubclassDataTable[].RecordType\r
+\r
+  RecordLen\r
+    Size of static RecordData from the Data Table.\r
+    mMiscSubclassDataTable[].RecordLen\r
+\r
+  RecordData\r
+    Pointer to copy of RecordData from the Data Table.  Changes made\r
+    to this copy will be written to the Data Hub but will not alter\r
+    the contents of the static Data Table.\r
+\r
+  LogRecordData\r
+    Set *LogRecordData to TRUE to log RecordData to Data Hub.\r
+    Set *LogRecordData to FALSE when there is no more data to log.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS\r
+    All parameters were valid and *RecordData and *LogRecordData have\r
+    been set.\r
+\r
+  EFI_UNSUPPORTED\r
+    Unexpected RecordType value.\r
+\r
+  EFI_INVALID_PARAMETER\r
+    One of the following parameter conditions was true:\r
+      RecordLen was zero.\r
+      RecordData was NULL.\r
+      LogRecordData was NULL.\r
+**/\r
+{\r
+  CHAR8                                        *OptionalStrStart;\r
+  UINTN                                        InternalRefStrLen;\r
+  UINTN                                        ExternalRefStrLen;  \r
+  EFI_STRING                                   InternalRef;\r
+  EFI_STRING                                   ExternalRef;\r
+  STRING_REF                                   TokenForInternal;\r
+  STRING_REF                                   TokenForExternal;\r
+  EFI_STATUS                                   Status;\r
+  SMBIOS_TABLE_TYPE8                           *SmbiosRecord;\r
+  EFI_SMBIOS_HANDLE                            SmbiosHandle;\r
+  EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR  *ForType8InputData;\r
+  \r
+  ForType8InputData = (EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR *)RecordData;\r
+  //\r
+  // First check for invalid parameters.\r
+  //\r
+  if (RecordData == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  TokenForInternal = 0;\r
+  TokenForExternal = 0;\r
+  \r
+  switch (ForType8InputData->PortInternalConnectorDesignator) { \r
+\r
+    case STR_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR:\r
+      TokenForInternal = STRING_TOKEN (STR_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR);\r
+      TokenForExternal = STRING_TOKEN(STR_MISC_PORT_EXTERNAL_CONNECTOR_DESIGNATOR);\r
+      break;\r
+    case STR_MISC_PORT_INTERNAL_KEYBOARD:\r
+      TokenForInternal = STRING_TOKEN (STR_MISC_PORT_INTERNAL_KEYBOARD);\r
+      TokenForExternal = STRING_TOKEN(STR_MISC_PORT_EXTERNAL_KEYBOARD);\r
+      break;\r
+    case STR_MISC_PORT_INTERNAL_MOUSE:\r
+      TokenForInternal = STRING_TOKEN (STR_MISC_PORT_INTERNAL_MOUSE);\r
+      TokenForExternal = STRING_TOKEN(STR_MISC_PORT_EXTERNAL_MOUSE);\r
+      break;\r
+    case STR_MISC_PORT_INTERNAL_COM1:\r
+      TokenForInternal = STRING_TOKEN (STR_MISC_PORT_INTERNAL_COM1);\r
+      TokenForExternal = STRING_TOKEN(STR_MISC_PORT_EXTERNAL_COM1);\r
+      break;\r
+    case STR_MISC_PORT_INTERNAL_COM2:\r
+      TokenForInternal = STRING_TOKEN (STR_MISC_PORT_INTERNAL_COM2);\r
+      TokenForExternal = STRING_TOKEN(STR_MISC_PORT_EXTERNAL_COM2);\r
+      break;\r
+    case STR_MISC_PORT_INTERNAL_EXTENSION_POWER:\r
+      TokenForInternal = STRING_TOKEN (STR_MISC_PORT_INTERNAL_EXTENSION_POWER);\r
+      TokenForExternal = STRING_TOKEN(STR_MISC_PORT_EXTERNAL_EXTENSION_POWER);\r
+      break;\r
+    case STR_MISC_PORT_INTERNAL_FLOPPY:\r
+      TokenForInternal = STRING_TOKEN (STR_MISC_PORT_INTERNAL_FLOPPY);\r
+      TokenForExternal = STRING_TOKEN(STR_MISC_PORT_EXTERNAL_FLOPPY);\r
+      break;\r
+    default:\r
+      break;\r
+  }\r
+\r
+  InternalRef = HiiGetPackageString(&gEfiCallerIdGuid, TokenForInternal, NULL);\r
+  InternalRefStrLen = StrLen(InternalRef);\r
+  if (InternalRefStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  ExternalRef = HiiGetPackageString(&gEfiCallerIdGuid, TokenForExternal, NULL);\r
+  ExternalRefStrLen = StrLen(ExternalRef);\r
+  if (ExternalRefStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Two zeros following the last string.\r
+  //\r
+  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE8) + InternalRefStrLen + 1 + ExternalRefStrLen + 1 + 1);\r
+  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE8) + InternalRefStrLen + 1 + ExternalRefStrLen + 1 + 1);\r
+\r
+  SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_PORT_CONNECTOR_INFORMATION;\r
+  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE8);\r
+  //\r
+  // Make handle chosen by smbios protocol.add automatically.\r
+  //\r
+  SmbiosRecord->Hdr.Handle = 0;  \r
+  SmbiosRecord->InternalReferenceDesignator = 1;\r
+  SmbiosRecord->InternalConnectorType = (UINT8)ForType8InputData->PortInternalConnectorType;\r
+  SmbiosRecord->ExternalReferenceDesignator = 2;\r
+  SmbiosRecord->ExternalConnectorType = (UINT8)ForType8InputData->PortExternalConnectorType;\r
+  SmbiosRecord->PortType = (UINT8)ForType8InputData->PortType;\r
+  \r
+  OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);\r
+  UnicodeStrToAsciiStr(InternalRef, OptionalStrStart);\r
+  UnicodeStrToAsciiStr(ExternalRef, OptionalStrStart + InternalRefStrLen + 1);\r
+\r
+  //\r
+  // Now we have got the full smbios record, call smbios protocol to add this record.\r
+  //\r
+  SmbiosHandle = 0;\r
+  Status = Smbios-> Add(\r
+                      Smbios, \r
+                      NULL,\r
+                      &SmbiosHandle, \r
+                      (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord\r
+                      );\r
+  FreePool(SmbiosRecord);\r
+  return Status;\r
+}\r
+\r
+\r
+\r
+/* eof - MiscSystemManufacturerFunction.c */\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscResetCapabilitiesData.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscResetCapabilitiesData.c
new file mode 100644 (file)
index 0000000..f591a2e
--- /dev/null
@@ -0,0 +1,42 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
+    MiscResetCapabilitiesData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+**/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SMBIOS_TABLE_DATA(EFI_MISC_RESET_CAPABILITIES, MiscResetCapabilities) = {\r
+  {     // ResetCapabilities\r
+    0,  // Status\r
+    0,  // BootOption\r
+    0,  // BootOptionOnLimit\r
+    0,  // WatchdogTimerPresent\r
+    0   // Reserved\r
+  },\r
+  0,    // ResetCount\r
+  0,    // ResetLimit\r
+  0,    // ResetTimerInterval\r
+  0     // ResetTimeout\r
+};\r
+\r
+/* eof - MiscResetCapabilities.c */\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscResetCapabilitiesFunction.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscResetCapabilitiesFunction.c
new file mode 100644 (file)
index 0000000..8303c5a
--- /dev/null
@@ -0,0 +1,76 @@
+/** @file\r
+  ResetCapabilities.\r
+  SMBIOS type 23.\r
+\r
+  Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
+  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
+#include "MiscSubClassDriver.h"\r
+/**\r
+  This function makes boot time changes to the contents of the\r
+  MiscOemString (Type 11).\r
+\r
+  @param  RecordData                 Pointer to copy of RecordData from the Data Table.  \r
+\r
+  @retval EFI_SUCCESS                All parameters were valid.\r
+  @retval EFI_UNSUPPORTED            Unexpected RecordType value.\r
+  @retval EFI_INVALID_PARAMETER      Invalid parameter was found.\r
+\r
+**/\r
+MISC_SMBIOS_TABLE_FUNCTION(MiscResetCapabilities)\r
+{\r
+  EFI_STATUS               Status;\r
+  EFI_SMBIOS_HANDLE        SmbiosHandle;\r
+  SMBIOS_TABLE_TYPE23      *SmbiosRecord;\r
+  EFI_MISC_RESET_CAPABILITIES   *ForType23InputData;\r
+  \r
+  ForType23InputData = (EFI_MISC_RESET_CAPABILITIES *)RecordData;\r
+\r
+  //\r
+  // First check for invalid parameters.\r
+  //\r
+  if (RecordData == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+\r
+  //\r
+  // Two zeros following the last string.\r
+  //\r
+  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE23) + 1 + 1);\r
+  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE23) + 1 + 1);\r
+\r
+  SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_RESET;\r
+  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE23);\r
+  //\r
+  // Make handle chosen by smbios protocol.add automatically.\r
+  // \r
+  SmbiosRecord->Hdr.Handle    = 0;  \r
+  SmbiosRecord->Capabilities  = *(UINT8*)&(ForType23InputData->ResetCapabilities);\r
+  SmbiosRecord->ResetCount    = (UINT16)ForType23InputData->ResetCount;\r
+  SmbiosRecord->ResetLimit    = (UINT16)ForType23InputData->ResetLimit;  \r
+  SmbiosRecord->TimerInterval = (UINT16)ForType23InputData->ResetTimerInterval;\r
+  SmbiosRecord->Timeout       = (UINT16)ForType23InputData->ResetTimeout;\r
+\r
+  //\r
+  // Now we have got the full smbios record, call smbios protocol to add this record.\r
+  //\r
+  SmbiosHandle = 0;\r
+  Status = Smbios-> Add(\r
+                      Smbios, \r
+                      NULL,\r
+                      &SmbiosHandle, \r
+                      (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord\r
+                      );\r
+  FreePool(SmbiosRecord);\r
+  return Status;\r
+}\r
+\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.h b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.h
new file mode 100644 (file)
index 0000000..7e5be7e
--- /dev/null
@@ -0,0 +1,122 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
+  MiscSubclassDriver.h\r
+\r
+Abstract:\r
+\r
+  Header file for MiscSubclass Driver.\r
+\r
+**/\r
+\r
+#ifndef _MISC_SUBCLASS_DRIVER_H\r
+#define _MISC_SUBCLASS_DRIVER_H\r
+\r
+#include <FrameworkDxe.h>\r
+\r
+#include <Guid/DataHubRecords.h>\r
+#include <IndustryStandard/SmBios.h>\r
+#include <Protocol/Smbios.h>\r
+#include <Protocol/EmuIoThunk.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 <Library/DevicePathLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+\r
+#include <MiscDevicePath.h>\r
+#include <Protocol/FrameworkHii.h>\r
+#include <Library/HiiLib.h>\r
+\r
+//\r
+// Data table entry update function.\r
+//\r
+typedef EFI_STATUS (EFIAPI EFI_MISC_SMBIOS_DATA_FUNCTION) (\r
+  IN  VOID                 *RecordData,\r
+  IN  EFI_SMBIOS_PROTOCOL  *Smbios\r
+  );\r
+\r
+//\r
+// Data table entry definition.\r
+//\r
+typedef struct {\r
+  //\r
+  // intermediat input data for SMBIOS record\r
+  //\r
+  VOID                              *RecordData;\r
+  EFI_MISC_SMBIOS_DATA_FUNCTION     *Function;\r
+} EFI_MISC_SMBIOS_DATA_TABLE;\r
+\r
+//\r
+// Data Table extern definitions.\r
+//\r
+#define MISC_SMBIOS_TABLE_EXTERNS(NAME1, NAME2, NAME3) \\r
+extern NAME1 NAME2 ## Data; \\r
+extern EFI_MISC_SMBIOS_DATA_FUNCTION NAME3 ## Function\r
+\r
+\r
+//\r
+// Data Table entries\r
+//\r
+#define MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION(NAME1, NAME2) \\r
+{ \\r
+  & NAME1 ## Data, \\r
+  & NAME2 ## Function \\r
+}\r
+\r
+//\r
+// Global definition macros.\r
+//\r
+#define MISC_SMBIOS_TABLE_DATA(NAME1, NAME2) \\r
+  NAME1 NAME2 ## Data\r
+\r
+#define MISC_SMBIOS_TABLE_FUNCTION(NAME2) \\r
+  EFI_STATUS EFIAPI NAME2 ## Function( \\r
+  IN  VOID                  *RecordData, \\r
+  IN  EFI_SMBIOS_PROTOCOL   *Smbios \\r
+  )\r
+\r
+\r
+//\r
+// Data Table Array\r
+//\r
+extern EFI_MISC_SMBIOS_DATA_TABLE mMiscSubclassDataTable[];\r
+\r
+//\r
+// Data Table Array Entries\r
+//\r
+extern UINTN                        mMiscSubclassDataTableEntries;\r
+extern UINT8                        MiscSubclassStrings[];\r
+extern EFI_HII_HANDLE               mHiiHandle;\r
+\r
+//\r
+// Prototypes\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+MiscSubclassDriverEntryPoint (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  );\r
+\r
+\r
+#endif /* _MISC_SUBCLASS_DRIVER_H */\r
+\r
+/* eof - MiscSubclassDriver.h */\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf
new file mode 100644 (file)
index 0000000..aed93f5
--- /dev/null
@@ -0,0 +1,103 @@
+## @file\r
+# Misc Sub class driver\r
+#\r
+# Parses the MiscSubclassDataTable and reports any generated data to the DataHub.\r
+#  All .uni file who tagged with "ToolCode="DUMMY"" in following file list is included by\r
+#  MiscSubclassDriver.uni file, the StrGather tool will expand MiscSubclassDriver.uni file \r
+#  and parse all .uni file.\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions 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                      = MiscSubclass\r
+  FILE_GUID                      = f2fbd108-8985-11db-b06a-0040d02b1835\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = MiscSubclassDriverEntryPoint\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]\r
+  MiscBaseBoardManufacturer.uni\r
+  MiscBaseBoardManufacturerData.c\r
+  MiscBaseBoardManufacturerFunction.c\r
+  MiscBiosVendor.uni\r
+  MiscBiosVendorData.c\r
+  MiscBiosVendorFunction.c\r
+  MiscBootInformationData.c  \r
+  MiscBootInformationFunction.c\r
+  MiscChassisManufacturer.uni\r
+  MiscChassisManufacturerData.c\r
+  MiscChassisManufacturerFunction.c\r
+  MiscNumberOfInstallableLanguagesData.c\r
+  MiscNumberOfInstallableLanguagesFunction.c\r
+  MiscOemString.uni  \r
+  MiscOemStringData.c  \r
+  MiscOemStringFunction.c  \r
+  MiscPortInternalConnectorDesignator.uni\r
+  MiscPortInternalConnectorDesignatorData.c  \r
+  MiscPortInternalConnectorDesignatorFunction.c\r
+  MiscResetCapabilitiesData.c\r
+  MiscResetCapabilitiesFunction.c\r
+  MiscSystemLanguageString.uni\r
+  MiscSystemLanguageStringData.c\r
+  MiscSystemLanguageStringFunction.c\r
+  MiscSystemManufacturer.uni\r
+  MiscSystemManufacturerData.c\r
+  MiscSystemManufacturerFunction.c\r
+  MiscSystemOptionString.uni\r
+  MiscSystemOptionStringData.c\r
+  MiscSystemOptionStringFunction.c\r
+  MiscSystemSlotDesignation.uni\r
+  MiscSystemSlotDesignationData.c\r
+  MiscSystemSlotDesignationFunction.c\r
+  MiscDevicePath.h\r
+  MiscSubClassDriver.h\r
+  MiscSubClassDriver.uni\r
+  MiscSubclassDriverDataTable.c\r
+  MiscSubclassDriverEntryPoint.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+  DevicePathLib\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  HiiLib\r
+  DebugLib\r
+  BaseLib\r
+  PcdLib\r
+\r
+[Protocols]\r
+  gEfiSmbiosProtocolGuid                        # PROTOCOL ALWAYS_CONSUMED\r
+\r
+[Pcd]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareReleaseDateString\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString\r
+  gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLang  \r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuMemorySize\r
+\r
+\r
+[Depex]\r
+  gEfiSmbiosProtocolGuid\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.uni b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.uni
new file mode 100644 (file)
index 0000000..7a4e8a2
Binary files /dev/null and b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.uni differ
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubclassDriverDataTable.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubclassDriverDataTable.c
new file mode 100644 (file)
index 0000000..cb71f7d
--- /dev/null
@@ -0,0 +1,78 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
+  MiscSubclassDriverDataTable.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+**/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+\r
+//\r
+// External definitions referenced by Data Table entries.\r
+//\r
+MISC_SMBIOS_TABLE_EXTERNS ( EFI_MISC_BASE_BOARD_MANUFACTURER_DATA, MiscBaseBoardManufacturer, MiscBaseBoardManufacturer);\r
+MISC_SMBIOS_TABLE_EXTERNS ( EFI_MISC_BIOS_VENDOR_DATA, MiscBiosVendor,MiscBiosVendor );\r
+MISC_SMBIOS_TABLE_EXTERNS ( EFI_MISC_BOOT_INFORMATION_STATUS_DATA, BootInformationStatus, BootInformationStatus);\r
+MISC_SMBIOS_TABLE_EXTERNS ( EFI_MISC_CHASSIS_MANUFACTURER_DATA, MiscChassisManufacturer, MiscChassisManufacturer);\r
+MISC_SMBIOS_TABLE_EXTERNS ( EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES_DATA,NumberOfInstallableLanguages, NumberOfInstallableLanguages);\r
+MISC_SMBIOS_TABLE_EXTERNS ( EFI_MISC_OEM_STRING_DATA,OemString, OemString);\r
+MISC_SMBIOS_TABLE_EXTERNS ( EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortInternalConnectorDesignator, MiscPortInternalConnectorDesignator);\r
+MISC_SMBIOS_TABLE_EXTERNS ( EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortKeyboard, MiscPortInternalConnectorDesignator);\r
+MISC_SMBIOS_TABLE_EXTERNS ( EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortMouse, MiscPortInternalConnectorDesignator);\r
+MISC_SMBIOS_TABLE_EXTERNS ( EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortCom1, MiscPortInternalConnectorDesignator);\r
+MISC_SMBIOS_TABLE_EXTERNS ( EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortCom2, MiscPortInternalConnectorDesignator);\r
+MISC_SMBIOS_TABLE_EXTERNS ( EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortExtensionPower, MiscPortInternalConnectorDesignator);\r
+MISC_SMBIOS_TABLE_EXTERNS ( EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortFloppy, MiscPortInternalConnectorDesignator);\r
+MISC_SMBIOS_TABLE_EXTERNS ( EFI_MISC_RESET_CAPABILITIES, MiscResetCapabilities, MiscResetCapabilities);\r
+MISC_SMBIOS_TABLE_EXTERNS ( EFI_MISC_SYSTEM_LANGUAGE_STRING_DATA,SystemLanguageString, SystemLanguageString);\r
+MISC_SMBIOS_TABLE_EXTERNS ( EFI_MISC_SYSTEM_MANUFACTURER_DATA, MiscSystemManufacturer, MiscSystemManufacturer);\r
+MISC_SMBIOS_TABLE_EXTERNS ( EFI_MISC_SYSTEM_OPTION_STRING_DATA, SystemOptionString, SystemOptionString);\r
+MISC_SMBIOS_TABLE_EXTERNS ( EFI_MISC_SYSTEM_SLOT_DESIGNATION_DATA, MiscSystemSlotDesignation, MiscSystemSlotDesignation);\r
+\r
+\r
+//\r
+// Data Table.\r
+//\r
+EFI_MISC_SMBIOS_DATA_TABLE  mMiscSubclassDataTable[] = {\r
+  MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION( MiscBaseBoardManufacturer, MiscBaseBoardManufacturer),\r
+  MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION( MiscBiosVendor,MiscBiosVendor ),\r
+  MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION( BootInformationStatus, BootInformationStatus),\r
+  MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION( MiscChassisManufacturer, MiscChassisManufacturer),\r
+  MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION(NumberOfInstallableLanguages, NumberOfInstallableLanguages),\r
+  MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION(OemString, OemString),\r
+  MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION( MiscPortInternalConnectorDesignator, MiscPortInternalConnectorDesignator),\r
+  MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION( MiscPortKeyboard, MiscPortInternalConnectorDesignator),\r
+  MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION( MiscPortMouse, MiscPortInternalConnectorDesignator),\r
+  MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION( MiscPortCom1, MiscPortInternalConnectorDesignator),\r
+  MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION( MiscPortCom2, MiscPortInternalConnectorDesignator),\r
+  MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION( MiscPortExtensionPower, MiscPortInternalConnectorDesignator),\r
+  MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION( MiscPortFloppy, MiscPortInternalConnectorDesignator),\r
+  MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION( MiscResetCapabilities, MiscResetCapabilities),\r
+  MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION(SystemLanguageString, SystemLanguageString),\r
+  MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION( MiscSystemManufacturer, MiscSystemManufacturer),\r
+  MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION( SystemOptionString, SystemOptionString),  \r
+  MISC_SMBIOS_TABLE_ENTRY_DATA_AND_FUNCTION( MiscSystemSlotDesignation, MiscSystemSlotDesignation),  \r
+  };\r
\r
+//\r
+// Number of Data Table entries.\r
+//\r
+UINTN mMiscSubclassDataTableEntries = (sizeof mMiscSubclassDataTable) / sizeof (EFI_MISC_SMBIOS_DATA_TABLE);\r
+\r
+/* eof - MiscSubclassDriverDataTable.c */\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c
new file mode 100644 (file)
index 0000000..065ab6f
--- /dev/null
@@ -0,0 +1,170 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
+  MiscSubclassDriverEntryPoint.c\r
+\r
+Abstract:\r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+**/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+EFI_HII_HANDLE  mHiiHandle;\r
+\r
+/**\r
+  This is the standard EFI driver point that detects whether there is a\r
+  MemoryConfigurationData Variable and, if so, reports memory configuration info\r
+  to the DataHub.\r
+\r
+  @param  ImageHandle  Handle for the image of this driver\r
+  @param  SystemTable  Pointer to the EFI System Table\r
+\r
+  @return EFI_SUCCESS if the data is successfully reported\r
+  @return EFI_NOT_FOUND if the HOB list could not be located.\r
+\r
+**/\r
+EFI_STATUS\r
+LogMemorySmbiosRecord (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+  UINT64                          TotalMemorySize;\r
+  UINT8                           NumSlots;\r
+  SMBIOS_TABLE_TYPE19             *Type19Record;\r
+  EFI_SMBIOS_HANDLE               MemArrayMappedAddrSmbiosHandle;\r
+  EFI_SMBIOS_PROTOCOL             *Smbios;\r
+  CHAR16                          *MemString;\r
+\r
+  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID**)&Smbios);\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  NumSlots        = 1;\r
+\r
+  //\r
+  // Process Memory String in form size!size ...\r
+  // So 64!64 is 128 MB\r
+  //\r
+  MemString   = (CHAR16 *)PcdGetPtr (PcdEmuMemorySize);\r
+  for (TotalMemorySize = 0; *MemString != '\0';) {\r
+    TotalMemorySize += StrDecimalToUint64 (MemString);\r
+    while (*MemString != '\0') {\r
+      if (*MemString == '!') {\r
+        MemString++;       \r
+        break;\r
+      }\r
+      MemString++;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Convert Total Memory Size to based on KiloByte\r
+  //\r
+  TotalMemorySize = LShiftU64 (TotalMemorySize, 20);\r
+  //\r
+  // Generate Memory Array Mapped Address info\r
+  //\r
+  Type19Record = AllocatePool(sizeof (SMBIOS_TABLE_TYPE19));\r
+  ZeroMem(Type19Record, sizeof(SMBIOS_TABLE_TYPE19));\r
+  Type19Record->Hdr.Type = EFI_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS;\r
+  Type19Record->Hdr.Length = sizeof(SMBIOS_TABLE_TYPE19);\r
+  Type19Record->Hdr.Handle = 0;\r
+  Type19Record->StartingAddress = 0;\r
+  Type19Record->EndingAddress =  (UINT32)RShiftU64(TotalMemorySize, 10) - 1;\r
+  Type19Record->MemoryArrayHandle = 0;\r
+  Type19Record->PartitionWidth = (UINT8)(NumSlots); \r
+\r
+  //\r
+  // Generate Memory Array Mapped Address info (TYPE 19)\r
+  //\r
+  MemArrayMappedAddrSmbiosHandle = 0;\r
+  Status = Smbios->Add (Smbios, NULL, &MemArrayMappedAddrSmbiosHandle, (EFI_SMBIOS_TABLE_HEADER*) Type19Record);\r
+  FreePool(Type19Record);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+MiscSubclassDriverEntryPoint (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+/*++\r
+Description:\r
+\r
+  Standard EFI driver point.  This driver parses the mMiscSubclassDataTable\r
+  structure and reports any generated data to the DataHub.\r
+\r
+Arguments:\r
+\r
+  ImageHandle\r
+    Handle for the image of this driver\r
+\r
+  SystemTable\r
+    Pointer to the EFI System Table\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS\r
+    The data was successfully reported to the Data Hub.\r
+\r
+**/\r
+{\r
+  UINTN                Index;\r
+  EFI_STATUS           EfiStatus;\r
+  EFI_SMBIOS_PROTOCOL  *Smbios;  \r
+\r
+  EfiStatus = gBS->LocateProtocol(&gEfiSmbiosProtocolGuid, NULL, (VOID**)&Smbios);\r
+\r
+  if (EFI_ERROR(EfiStatus)) {\r
+    DEBUG((EFI_D_ERROR, "Could not locate SMBIOS protocol.  %r\n", EfiStatus));\r
+    return EfiStatus;\r
+  }\r
+\r
+  mHiiHandle = HiiAddPackages (\r
+                 &gEfiCallerIdGuid,\r
+                 NULL,\r
+                 MiscSubclassStrings,\r
+                 NULL\r
+                 );\r
+  ASSERT (mHiiHandle != NULL);\r
+\r
+  for (Index = 0; Index < mMiscSubclassDataTableEntries; ++Index) {\r
+    //\r
+    // If the entry have a function pointer, just log the data.\r
+    //\r
+    if (mMiscSubclassDataTable[Index].Function != NULL) {\r
+      EfiStatus = (*mMiscSubclassDataTable[Index].Function)(\r
+        mMiscSubclassDataTable[Index].RecordData,\r
+        Smbios\r
+        );\r
+\r
+      if (EFI_ERROR(EfiStatus)) {\r
+        DEBUG((EFI_D_ERROR, "Misc smbios store error.  Index=%d, ReturnStatus=%r\n", Index, EfiStatus));\r
+        return EfiStatus;\r
+      }\r
+    }\r
+  }\r
+\r
+  //\r
+  // Log Memory SMBIOS Record\r
+  //\r
+  EfiStatus = LogMemorySmbiosRecord();\r
+  return EfiStatus;\r
+}\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemLanguageString.uni b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemLanguageString.uni
new file mode 100644 (file)
index 0000000..709c53a
Binary files /dev/null and b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemLanguageString.uni differ
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemLanguageStringData.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemLanguageStringData.c
new file mode 100644 (file)
index 0000000..0dc706e
--- /dev/null
@@ -0,0 +1,33 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
+  MiscSystemLanguageStringData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+**/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SMBIOS_TABLE_DATA(EFI_MISC_SYSTEM_LANGUAGE_STRING_DATA, SystemLanguageString) = {\r
+  0,\r
+  STRING_TOKEN(STR_MISC_SYSTEM_LANGUAGE_STRING)\r
+};\r
+\r
+/* eof - MiscSystemLanguageStringData.c */\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemLanguageStringFunction.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemLanguageStringFunction.c
new file mode 100644 (file)
index 0000000..3e10c63
--- /dev/null
@@ -0,0 +1,85 @@
+/** @file\r
+  ResetCapabilities.\r
+  SMBIOS type 23.\r
+\r
+  Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
+  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
+#include "MiscSubClassDriver.h"\r
+/**\r
+  This function makes boot time changes to the contents of the\r
+  MiscOemString (Type 11).\r
+\r
+  @param  RecordData                 Pointer to copy of RecordData from the Data Table.  \r
+\r
+  @retval EFI_SUCCESS                All parameters were valid.\r
+  @retval EFI_UNSUPPORTED            Unexpected RecordType value.\r
+  @retval EFI_INVALID_PARAMETER      Invalid parameter was found.\r
+\r
+**/\r
+MISC_SMBIOS_TABLE_FUNCTION(SystemLanguageString)\r
+{\r
+  EFI_STATUS               Status;\r
+  EFI_SMBIOS_HANDLE        SmbiosHandle;\r
+  SMBIOS_TABLE_TYPE13      *SmbiosRecord;\r
+  UINTN                    StrLeng;\r
+  CHAR8                    *OptionalStrStart;\r
+  EFI_STRING               Str;\r
+  STRING_REF               TokenToGet;\r
+  \r
+\r
+  //\r
+  // First check for invalid parameters.\r
+  //\r
+  if (RecordData == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_LANGUAGE_STRING);\r
+  Str = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  StrLeng = StrLen(Str);\r
+  if (StrLeng > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Two zeros following the last string.\r
+  //\r
+  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE13) + StrLeng + 1 + 1);\r
+  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE13) + StrLeng + 1 + 1);\r
+\r
+  SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BIOS_LANGUAGE_INFORMATION;\r
+  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE13);\r
+  //\r
+  // Make handle chosen by smbios protocol.add automatically.\r
+  // \r
+  SmbiosRecord->Hdr.Handle    = 0;\r
+  SmbiosRecord->InstallableLanguages = 1;\r
+  SmbiosRecord->Flags   = 1;\r
+  SmbiosRecord->CurrentLanguages = 1;\r
+  OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);\r
+  UnicodeStrToAsciiStr(Str, OptionalStrStart);\r
+  \r
+\r
+  //\r
+  // Now we have got the full smbios record, call smbios protocol to add this record.\r
+  //\r
+  SmbiosHandle = 0;\r
+  Status = Smbios-> Add(\r
+                      Smbios, \r
+                      NULL,\r
+                      &SmbiosHandle, \r
+                      (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord\r
+                      );\r
+  FreePool(SmbiosRecord);\r
+  return Status;\r
+}\r
+\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemManufacturer.uni b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemManufacturer.uni
new file mode 100644 (file)
index 0000000..3ff890b
Binary files /dev/null and b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemManufacturer.uni differ
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerData.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerData.c
new file mode 100644 (file)
index 0000000..13befc4
--- /dev/null
@@ -0,0 +1,57 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
+  MiscSystemManufacturerData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+**/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) System Manufacturer data.\r
+//\r
+MISC_SMBIOS_TABLE_DATA(EFI_MISC_SYSTEM_MANUFACTURER_DATA, MiscSystemManufacturer)\r
+= {\r
+  STRING_TOKEN(STR_MISC_SYSTEM_MANUFACTURER),\r
+  // SystemManufactrurer\r
+  STRING_TOKEN(STR_MISC_SYSTEM_PRODUCT_NAME),\r
+  // SystemProductName\r
+  STRING_TOKEN(STR_MISC_SYSTEM_VERSION),\r
+  // SystemVersion\r
+  STRING_TOKEN(STR_MISC_SYSTEM_SERIAL_NUMBER),\r
+  // SystemSerialNumber\r
+  {\r
+    0xbadfaced,\r
+    0xdead,\r
+    0xbeef,\r
+    {\r
+      0x13,\r
+      0x13,\r
+      0x13,\r
+      0x13,\r
+      0x13,\r
+      0x13,\r
+      0x13,\r
+      0x13\r
+    }\r
+  },\r
+  // SystemUuid\r
+  EfiSystemWakeupTypePowerSwitch  // SystemWakeupType\r
+};\r
+\r
+/* eof - MiscSystemManufacturerData.c */\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerFunction.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerFunction.c
new file mode 100644 (file)
index 0000000..9d2a3cb
--- /dev/null
@@ -0,0 +1,140 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
+  MiscSystemManufacturerFunction.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+**/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+/**\r
+  This function makes boot time changes to the contents of the\r
+  MiscSystemManufacturer (Type 1).\r
+\r
+  @param  RecordData                 Pointer to copy of RecordData from the Data Table.  \r
+\r
+  @retval EFI_SUCCESS                All parameters were valid.\r
+  @retval EFI_UNSUPPORTED            Unexpected RecordType value.\r
+  @retval EFI_INVALID_PARAMETER      Invalid parameter was found.\r
+\r
+**/\r
+MISC_SMBIOS_TABLE_FUNCTION(MiscSystemManufacturer)\r
+{\r
+  CHAR8                             *OptionalStrStart;\r
+  UINTN                             ManuStrLen;\r
+  UINTN                             VerStrLen;\r
+  UINTN                             PdNameStrLen;\r
+  UINTN                             SerialNumStrLen;\r
+  EFI_STATUS                        Status;\r
+  EFI_STRING                        Manufacturer;\r
+  EFI_STRING                        ProductName;\r
+  EFI_STRING                        Version;\r
+  EFI_STRING                        SerialNumber;\r
+  STRING_REF                        TokenToGet;\r
+  EFI_SMBIOS_HANDLE                 SmbiosHandle;\r
+  SMBIOS_TABLE_TYPE1                *SmbiosRecord;\r
+  EFI_MISC_SYSTEM_MANUFACTURER      *ForType1InputData;\r
+\r
+  ForType1InputData = (EFI_MISC_SYSTEM_MANUFACTURER *)RecordData;\r
+\r
+  //\r
+  // First check for invalid parameters.\r
+  //\r
+  if (RecordData == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_MANUFACTURER);\r
+  Manufacturer = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  ManuStrLen = StrLen(Manufacturer);\r
+  if (ManuStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_PRODUCT_NAME);\r
+  ProductName = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  PdNameStrLen = StrLen(ProductName);\r
+  if (PdNameStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_VERSION);\r
+  Version = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  VerStrLen = StrLen(Version);\r
+  if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SERIAL_NUMBER);\r
+  SerialNumber = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  SerialNumStrLen = StrLen(SerialNumber);\r
+  if (SerialNumStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Two zeros following the last string.\r
+  //\r
+  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE1) + ManuStrLen + 1 + PdNameStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + 1);\r
+  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE1) + ManuStrLen + 1 + PdNameStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + 1);\r
+\r
+  SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_INFORMATION;\r
+  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE1);\r
+  //\r
+  // Make handle chosen by smbios protocol.add automatically.\r
+  // \r
+  SmbiosRecord->Hdr.Handle = 0;  \r
+  //\r
+  // Manu will be the 1st optional string following the formatted structure.\r
+  //\r
+  SmbiosRecord->Manufacturer = 1;\r
+  //\r
+  // ProductName will be the 2nd optional string following the formatted structure.\r
+  //\r
+  SmbiosRecord->ProductName = 2;  \r
+  //\r
+  // Version will be the 3rd optional string following the formatted structure.  \r
+  //\r
+  SmbiosRecord->Version = 3;  \r
+  //\r
+  // Version will be the 4th optional string following the formatted structure.\r
+  //\r
+  SmbiosRecord->SerialNumber = 4;\r
+  CopyMem ((UINT8 *) (&SmbiosRecord->Uuid),&ForType1InputData->SystemUuid,16);\r
+  SmbiosRecord->WakeUpType = (UINT8)ForType1InputData->SystemWakeupType;\r
+\r
+  OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);\r
+  UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart);\r
+  UnicodeStrToAsciiStr(ProductName, OptionalStrStart + ManuStrLen + 1);\r
+  UnicodeStrToAsciiStr(Version, OptionalStrStart + ManuStrLen + 1 + PdNameStrLen + 1);\r
+  UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + ManuStrLen + 1 + PdNameStrLen + 1 + VerStrLen + 1);\r
+\r
+  //\r
+  // Now we have got the full smbios record, call smbios protocol to add this record.\r
+  //\r
+  SmbiosHandle = 0;\r
+  Status = Smbios-> Add(\r
+                      Smbios, \r
+                      NULL,\r
+                      &SmbiosHandle, \r
+                      (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord\r
+                      );\r
+  FreePool(SmbiosRecord);\r
+  return Status;\r
+}\r
+\r
+/* eof - MiscSystemManufacturerFunction.c */\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemOptionString.uni b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemOptionString.uni
new file mode 100644 (file)
index 0000000..abf2da7
Binary files /dev/null and b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemOptionString.uni differ
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemOptionStringData.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemOptionStringData.c
new file mode 100644 (file)
index 0000000..581586b
--- /dev/null
@@ -0,0 +1,32 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
+  MiscSystemOptionStringData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+**/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SMBIOS_TABLE_DATA(EFI_MISC_SYSTEM_OPTION_STRING_DATA, SystemOptionString) = {\r
+  {STRING_TOKEN(STR_MISC_SYSTEM_OPTION_STRING)}\r
+};\r
+\r
+/* eof - MiscSystemOptionStringData.c */\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemOptionStringFunction.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemOptionStringFunction.c
new file mode 100644 (file)
index 0000000..a910634
--- /dev/null
@@ -0,0 +1,83 @@
+/** @file\r
+  BIOS system option string boot time changes.\r
+  SMBIOS type 12.\r
+\r
+  Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
+  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
+#include "MiscSubClassDriver.h"\r
+\r
+\r
+/**\r
+  This function makes boot time changes to the contents of the\r
+  MiscSystemOptionString (Type 12).\r
+\r
+  @param  RecordData                 Pointer to copy of RecordData from the Data Table.  \r
+\r
+  @retval EFI_SUCCESS                All parameters were valid.\r
+  @retval EFI_UNSUPPORTED            Unexpected RecordType value.\r
+  @retval EFI_INVALID_PARAMETER      Invalid parameter was found.\r
+\r
+**/\r
+MISC_SMBIOS_TABLE_FUNCTION(SystemOptionString)\r
+{\r
+  CHAR8                             *OptionalStrStart;\r
+  UINTN                             OptStrLen;\r
+  EFI_STRING                        OptionString;\r
+  EFI_STATUS                        Status;\r
+  STRING_REF                        TokenToGet;\r
+  EFI_SMBIOS_HANDLE                 SmbiosHandle;\r
+  SMBIOS_TABLE_TYPE12               *SmbiosRecord;\r
+\r
+  //\r
+  // First check for invalid parameters.\r
+  //\r
+  if (RecordData == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_OPTION_STRING);\r
+  OptionString = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  OptStrLen = StrLen(OptionString);\r
+  if (OptStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
\r
+  //\r
+  // Two zeros following the last string.\r
+  //\r
+  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE12) + OptStrLen + 1 + 1);\r
+  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE12) + OptStrLen + 1 + 1);\r
+\r
+  SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_CONFIGURATION_OPTIONS;\r
+  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE12);\r
+  //\r
+  // Make handle chosen by smbios protocol.add automatically.\r
+  //\r
+  SmbiosRecord->Hdr.Handle = 0;  \r
+\r
+  SmbiosRecord->StringCount = 1;\r
+  OptionalStrStart = (CHAR8*) (SmbiosRecord + 1);\r
+  UnicodeStrToAsciiStr(OptionString, OptionalStrStart);\r
+  //\r
+  // Now we have got the full smbios record, call smbios protocol to add this record.\r
+  //\r
+  SmbiosHandle = 0;\r
+  Status = Smbios-> Add(\r
+                      Smbios, \r
+                      NULL,\r
+                      &SmbiosHandle, \r
+                      (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord\r
+                      );\r
+\r
+  FreePool(SmbiosRecord);\r
+  return Status;\r
+}\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignation.uni b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignation.uni
new file mode 100644 (file)
index 0000000..45e9ce3
Binary files /dev/null and b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignation.uni differ
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignationData.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignationData.c
new file mode 100644 (file)
index 0000000..11b2339
--- /dev/null
@@ -0,0 +1,52 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
+    MiscSystemSlotDesignationData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+**/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SMBIOS_TABLE_DATA(EFI_MISC_SYSTEM_SLOT_DESIGNATION_DATA, MiscSystemSlotDesignation) = {\r
+  STRING_TOKEN(STR_MISC_SYSTEM_SLOT_DESIGNATION),   // SlotDesignation\r
+  EfiSlotTypeOther,         // SlotType\r
+  EfiSlotDataBusWidthOther, // SlotDataBusWidth\r
+  EfiSlotUsageOther,        // SlotUsage\r
+  EfiSlotLengthOther,       // SlotLength\r
+  0,                        // SlotId\r
+  {                         // SlotCharacteristics\r
+    0,                      // CharacteristicsUnknown  :1;\r
+    0,                      // Provides50Volts         :1;\r
+    0,                      // Provides33Volts         :1;\r
+    0,                      // SharedSlot              :1;\r
+    0,                      // PcCard16Supported       :1;\r
+    0,                      // CardBusSupported        :1;\r
+    0,                      // ZoomVideoSupported      :1;\r
+    0,                      // ModemRingResumeSupported:1;\r
+    0,                      // PmeSignalSupported      :1;\r
+    0,                      // HotPlugDevicesSupported :1;\r
+    0,                      // SmbusSignalSupported    :1;\r
+    0                       // Reserved                :21;\r
+  },\r
+  {0, 0, {0, 0}}            // SlotDevicePath\r
+};\r
+\r
+/* eof - MiscSystemSlotsData.c */\r
diff --git a/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignationFunction.c b/InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignationFunction.c
new file mode 100644 (file)
index 0000000..72c4137
--- /dev/null
@@ -0,0 +1,97 @@
+/** @file\r
+  BIOS system slot designator information boot time changes.\r
+  SMBIOS type 9.\r
+\r
+  Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
+  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
+#include "MiscSubClassDriver.h"\r
+/**\r
+  This function makes boot time changes to the contents of the\r
+  MiscSystemSlotDesignator structure (Type 9).\r
+\r
+  @param  RecordData                 Pointer to copy of RecordData from the Data Table.  \r
+\r
+  @retval EFI_SUCCESS                All parameters were valid.\r
+  @retval EFI_UNSUPPORTED            Unexpected RecordType value.\r
+  @retval EFI_INVALID_PARAMETER      Invalid parameter was found.\r
+\r
+**/\r
+MISC_SMBIOS_TABLE_FUNCTION(MiscSystemSlotDesignation)\r
+{\r
+  CHAR8                              *OptionalStrStart;\r
+  UINTN                              SlotDesignationStrLen;\r
+  EFI_STATUS                         Status;\r
+  EFI_STRING                         SlotDesignation;\r
+  STRING_REF                         TokenToGet;\r
+  SMBIOS_TABLE_TYPE9                 *SmbiosRecord;\r
+  EFI_SMBIOS_HANDLE                  SmbiosHandle;\r
+  EFI_MISC_SYSTEM_SLOT_DESIGNATION*  ForType9InputData;\r
+\r
+  ForType9InputData = (EFI_MISC_SYSTEM_SLOT_DESIGNATION *)RecordData;\r
+\r
+  //\r
+  // First check for invalid parameters.\r
+  //\r
+  if (RecordData == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  TokenToGet = 0;\r
+  switch (ForType9InputData->SlotDesignation) {\r
+    case STR_MISC_SYSTEM_SLOT_DESIGNATION: \r
+      TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_DESIGNATION);\r
+      break;\r
+    default:\r
+      break;\r
+  }\r
+\r
+  SlotDesignation = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
+  SlotDesignationStrLen = StrLen(SlotDesignation);\r
+  if (SlotDesignationStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  \r
+  //\r
+  // Two zeros following the last string.\r
+  //\r
+  SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE9) + SlotDesignationStrLen + 1 + 1);\r
+  ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE9) +SlotDesignationStrLen + 1 + 1);\r
+\r
+  SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_SLOTS;\r
+  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE9);\r
+  SmbiosRecord->Hdr.Handle = 0; \r
+  SmbiosRecord->SlotDesignation = 1;\r
+  SmbiosRecord->SlotType = ForType9InputData->SlotType;\r
+  SmbiosRecord->SlotDataBusWidth = ForType9InputData->SlotDataBusWidth;\r
+  SmbiosRecord->CurrentUsage = ForType9InputData->SlotUsage;\r
+  SmbiosRecord->SlotLength = ForType9InputData->SlotLength;\r
+  SmbiosRecord->SlotID = ForType9InputData->SlotId;\r
+  \r
+  //\r
+  // Slot Characteristics\r
+  //\r
+  CopyMem ((UINT8 *) &SmbiosRecord->SlotCharacteristics1,(UINT8 *) &ForType9InputData->SlotCharacteristics,2);\r
+  OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);\r
+  UnicodeStrToAsciiStr(SlotDesignation, OptionalStrStart);\r
+  //  \r
+  // Now we have got the full smbios record, call smbios protocol to add this record.\r
+  //\r
+  SmbiosHandle = 0;\r
+  Status = Smbios-> Add(\r
+                      Smbios, \r
+                      NULL,\r
+                      &SmbiosHandle, \r
+                      (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord\r
+                      );\r
+  FreePool(SmbiosRecord);\r
+  return Status;\r
+}\r
diff --git a/InOsEmuPkg/RealTimeClockRuntimeDxe/RealTimeClock.c b/InOsEmuPkg/RealTimeClockRuntimeDxe/RealTimeClock.c
new file mode 100644 (file)
index 0000000..05c34bd
--- /dev/null
@@ -0,0 +1,305 @@
+/*++\r
+  Emu RTC Architectural Protocol Driver as defined in PI\r
+\r
+Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2010 - 2011, Apple Inc. All rights reserved.\r
+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
+#include <PiDxe.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/EmuThunkLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#include <Protocol/RealTimeClock.h>\r
+\r
+BOOLEAN\r
+DayValid (\r
+  IN  EFI_TIME  *Time\r
+  );\r
+\r
+BOOLEAN\r
+IsLeapYear (\r
+  IN EFI_TIME   *Time\r
+  );\r
+\r
+EFI_STATUS\r
+RtcTimeFieldsValid (\r
+  IN EFI_TIME *Time\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeRealTimeClock (\r
+  IN EFI_HANDLE                          ImageHandle,\r
+  IN EFI_SYSTEM_TABLE                    *SystemTable\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuGetTime (\r
+  OUT EFI_TIME                                 * Time,\r
+  OUT EFI_TIME_CAPABILITIES                    * Capabilities OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Service routine for RealTimeClockInstance->GetTime \r
+\r
+Arguments:\r
+\r
+  Time          - A pointer to storage that will receive a snapshot of the current time.\r
+\r
+  Capabilities  - A pointer to storage that will receive the capabilities of the real time clock\r
+                  in the platform. This includes the real time clock's resolution and accuracy.  \r
+                  All reported device capabilities are rounded up.  This is an OPTIONAL argument.\r
+\r
+Returns:\r
+\r
+  EFI_SUCEESS   - The underlying GetSystemTime call occurred and returned\r
+                  Note that in the NT32 emulation, the GetSystemTime call has no return value\r
+                  thus you will always receive a EFI_SUCCESS on this.\r
+\r
+**/\r
+{\r
+\r
+  //\r
+  // Check parameter for null pointer\r
+  //\r
+  if (Time == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+\r
+  }\r
+\r
+  gEmuThunk->GetTime (Time, Capabilities);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSetTime (\r
+  IN EFI_TIME   *Time\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Service routine for RealTimeClockInstance->SetTime \r
+\r
+Arguments:\r
+\r
+  Time          - A pointer to storage containing the time and date information to\r
+                  program into the real time clock.\r
+\r
+Returns:\r
+\r
+  EFI_SUCEESS           - The operation completed successfully.\r
+                  \r
+  EFI_INVALID_PARAMETER - One of the fields in Time is out of range.\r
+\r
+  EFI_DEVICE_ERROR      - The operation could not be complete due to a device error.\r
+\r
+**/\r
+{\r
+  EFI_STATUS            Status;\r
+\r
+  if (Time == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Make sure that the time fields are valid\r
+  //\r
+  Status = RtcTimeFieldsValid (Time);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuGetWakeupTime (\r
+  OUT BOOLEAN        *Enabled,\r
+  OUT BOOLEAN        *Pending,\r
+  OUT EFI_TIME       *Time\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Service routine for RealTimeClockInstance->GetWakeupTime\r
+\r
+Arguments:\r
+  This          - Indicates the protocol instance structure.\r
+\r
+  Enabled       - Indicates if the alarm is currently enabled or disabled.\r
+\r
+  Pending       - Indicates if the alarm signal is pending and requires\r
+                  acknowledgement.\r
+\r
+  Time          - The current alarm setting.\r
+\r
+Returns:\r
+\r
+  EFI_SUCEESS           - The operation completed successfully.\r
+                  \r
+  EFI_DEVICE_ERROR      - The operation could not be complete due to a device error.\r
+\r
+  EFI_UNSUPPORTED       - The operation is not supported on this platform.\r
+\r
+**/\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSetWakeupTime (\r
+  IN BOOLEAN      Enable,\r
+  OUT EFI_TIME    *Time\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Service routine for RealTimeClockInstance->SetWakeupTime\r
+\r
+Arguments:\r
+\r
+  Enabled       - Enable or disable the wakeup alarm.\r
+\r
+  Time          - If enable is TRUE, the time to set the wakup alarm for.\r
+                  If enable is FALSE, then this parameter is optional, and\r
+                  may be NULL.\r
+\r
+Returns:\r
+\r
+  EFI_SUCEESS           - The operation completed successfully.\r
+                  \r
+  EFI_DEVICE_ERROR      - The operation could not be complete due to a device error.\r
+\r
+  EFI_INVALID_PARAMETER - A field in Time is out of range.\r
+\r
+  EFI_UNSUPPORTED       - The operation is not supported on this platform.\r
+\r
+**/\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeRealTimeClock (\r
+  IN EFI_HANDLE                            ImageHandle,\r
+  IN EFI_SYSTEM_TABLE                      *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Install Real Time Clock Protocol \r
+\r
+Arguments:\r
+  ImageHandle - Image Handle\r
+  SystemTable - Pointer to system table\r
+\r
+Returns:\r
+\r
+  EFI_SUCEESS - Real Time Clock Services are installed into the Runtime Services Table\r
+\r
+**/\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_HANDLE  Handle;\r
+\r
+  SystemTable->RuntimeServices->GetTime       = EmuGetTime;\r
+  SystemTable->RuntimeServices->SetTime       = EmuSetTime;\r
+  SystemTable->RuntimeServices->GetWakeupTime = EmuGetWakeupTime;\r
+  SystemTable->RuntimeServices->SetWakeupTime = EmuSetWakeupTime;\r
+\r
+  Handle = NULL;\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Handle,\r
+                  &gEfiRealTimeClockArchProtocolGuid,\r
+                  NULL,\r
+                  NULL\r
+                  );\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+RtcTimeFieldsValid (\r
+  IN EFI_TIME *Time\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Arguments:\r
\r
+  Returns: \r
+**/\r
+{\r
+  if (Time->Year < 1998 ||\r
+      Time->Year > 2099 ||\r
+      Time->Month < 1 ||\r
+      Time->Month > 12 ||\r
+      (!DayValid (Time)) ||\r
+      Time->Hour > 23 ||\r
+      Time->Minute > 59 ||\r
+      Time->Second > 59 ||\r
+      Time->Nanosecond > 999999999 ||\r
+      (!(Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE || (Time->TimeZone >= -1440 && Time->TimeZone <= 1440))) ||\r
+      (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))\r
+      ) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+BOOLEAN\r
+DayValid (\r
+  IN  EFI_TIME  *Time\r
+  )\r
+{\r
+\r
+  STATIC const INTN  DayOfMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r
+\r
+  if (Time->Day < 1 ||\r
+      Time->Day > DayOfMonth[Time->Month - 1] ||\r
+      (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))\r
+      ) {\r
+    return FALSE;\r
+  }\r
+\r
+  return TRUE;\r
+}\r
+\r
+BOOLEAN\r
+IsLeapYear (\r
+  IN EFI_TIME   *Time\r
+  )\r
+{\r
+  if (Time->Year % 4 == 0) {\r
+    if (Time->Year % 100 == 0) {\r
+      if (Time->Year % 400 == 0) {\r
+        return TRUE;\r
+      } else {\r
+        return FALSE;\r
+      }\r
+    } else {\r
+      return TRUE;\r
+    }\r
+  } else {\r
+    return FALSE;\r
+  }\r
+}\r
diff --git a/InOsEmuPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf b/InOsEmuPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf
new file mode 100644 (file)
index 0000000..8aa4903
--- /dev/null
@@ -0,0 +1,57 @@
+## @file\r
+# Emu Real time clock Architectural Protocol Driver as defined in PI\r
+#\r
+# This real time clock module simulates virtual device by time WinAPI.\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = RealTimeClock\r
+  FILE_GUID                      = f3552032-8985-11db-8429-0040d02b1835\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = InitializeRealTimeClock\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]\r
+  RealTimeClock.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  EmuThunkLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  DebugLib\r
+  BaseLib\r
+\r
+\r
+[Protocols]\r
+  gEfiRealTimeClockArchProtocolGuid             # PROTOCOL ALWAYS_PRODUCED\r
+\r
+\r
+[Depex]\r
+  TRUE\r
+\r
diff --git a/InOsEmuPkg/ResetRuntimeDxe/Reset.c b/InOsEmuPkg/ResetRuntimeDxe/Reset.c
new file mode 100644 (file)
index 0000000..14594c7
--- /dev/null
@@ -0,0 +1,114 @@
+/*++ @file\r
+  Reset Architectural Protocol as defined in UEFI/PI under Emulation\r
+\r
+Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2010 - 2011, Apple Inc. All rights reserved.\r
+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
+#include <PiDxe.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/EmuThunkLib.h>\r
+\r
+#include <Protocol/Reset.h>\r
+\r
+\r
+VOID\r
+EFIAPI\r
+EmuResetSystem (\r
+  IN EFI_RESET_TYPE   ResetType,\r
+  IN EFI_STATUS       ResetStatus,\r
+  IN UINTN            DataSize,\r
+  IN VOID             *ResetData OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINTN       HandleCount;\r
+  EFI_HANDLE  *HandleBuffer;\r
+  UINTN       Index;\r
+\r
+  //\r
+  // Disconnect all\r
+  //\r
+  Status = gBS->LocateHandleBuffer (\r
+                  AllHandles,\r
+                  NULL,\r
+                  NULL,\r
+                  &HandleCount,\r
+                  &HandleBuffer\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    for (Index = 0; Index < HandleCount; Index++) {\r
+      Status = gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);\r
+    }\r
+  \r
+    gBS->FreePool (HandleBuffer);\r
+  }\r
+\r
+\r
+  //\r
+  // Discard ResetType, always return 0 as exit code\r
+  //\r
+  gEmuThunk->Exit (0);\r
+\r
+  //\r
+  // Should never go here\r
+  //\r
+  ASSERT (FALSE);\r
+\r
+  return;\r
+}\r
+\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeEmuReset (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+\r
+Arguments:\r
+\r
+  ImageHandle of the loaded driver\r
+  Pointer to the System Table\r
+\r
+Returns:\r
+\r
+  Status\r
+**/\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_HANDLE  Handle;\r
+\r
+  SystemTable->RuntimeServices->ResetSystem = EmuResetSystem;\r
+\r
+  Handle = NULL;\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Handle,\r
+                  &gEfiResetArchProtocolGuid,\r
+                  NULL,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
+\r
diff --git a/InOsEmuPkg/ResetRuntimeDxe/Reset.inf b/InOsEmuPkg/ResetRuntimeDxe/Reset.inf
new file mode 100644 (file)
index 0000000..93eb5ca
--- /dev/null
@@ -0,0 +1,57 @@
+## @file\r
+# Emu Emulation Reset Architectural Protocol Driver as defined in PI\r
+#\r
+# This Reset module simulates system reset by process exit on Emulator.\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = EmuReset\r
+  FILE_GUID                      = 50A18017-37AD-8743-BCF2-DF1A8FF12FAB\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = InitializeEmuReset\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]\r
+  Reset.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  EmuThunkLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  DebugLib\r
+  BaseLib\r
+\r
+\r
+[Protocols]\r
+  gEfiResetArchProtocolGuid                     # PROTOCOL ALWAYS_PRODUCED\r
+\r
+\r
+[Depex]\r
+  TRUE\r
+\r
diff --git a/InOsEmuPkg/ThunkPpiToProtocolPei/ThunkPpiToProtocolPei.c b/InOsEmuPkg/ThunkPpiToProtocolPei/ThunkPpiToProtocolPei.c
new file mode 100644 (file)
index 0000000..b2b7801
--- /dev/null
@@ -0,0 +1,74 @@
+/*++ @file\r
+  UEFI/PI PEIM to abstract construction of firmware volume in a Unix environment.\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2010 - 2011, Apple Inc. All rights reserved.\r
+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
+#include <PiPei.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeimEntryPoint.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+\r
+#include <Ppi/EmuThunk.h>\r
+#include <Protocol/EmuThunk.h>\r
+\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PeiInitialzeThunkPpiToProtocolPei (\r
+  IN       EFI_PEI_FILE_HANDLE       FileHandle,\r
+  IN CONST EFI_PEI_SERVICES          **PeiServices\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Perform a call-back into the SEC simulator to get Unix Stuff\r
+\r
+Arguments:\r
+\r
+  PeiServices - General purpose services available to every PEIM.\r
+    \r
+Returns:\r
+\r
+  None\r
+\r
+**/\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_PEI_PPI_DESCRIPTOR  *PpiDescriptor;\r
+  EMU_THUNK_PPI           *Thunk;\r
+  VOID                    *Ptr;\r
+\r
+  DEBUG ((EFI_D_ERROR, "Emu Thunk PEIM Loaded\n"));\r
+\r
+  Status = PeiServicesLocatePpi (\r
+              &gEmuThunkPpiGuid,        // GUID\r
+              0,                        // INSTANCE\r
+              &PpiDescriptor,           // EFI_PEI_PPI_DESCRIPTOR\r
+              (VOID **)&Thunk           // PPI\r
+              );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Ptr = Thunk->Thunk ();\r
+\r
+  BuildGuidDataHob (\r
+    &gEmuThunkProtocolGuid,              // Guid\r
+    &Ptr,                                // Buffer\r
+    sizeof (VOID *)                      // Sizeof Buffer\r
+    );\r
+  return Status;\r
+}\r
diff --git a/InOsEmuPkg/ThunkPpiToProtocolPei/ThunkPpiToProtocolPei.inf b/InOsEmuPkg/ThunkPpiToProtocolPei/ThunkPpiToProtocolPei.inf
new file mode 100644 (file)
index 0000000..470568f
--- /dev/null
@@ -0,0 +1,55 @@
+## @file\r
+# Stuff driver\r
+#\r
+# Tiano PEIM to abstract construction of firmware volume in a Emu environment.\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = ThunkPpiToProtocolPei\r
+  FILE_GUID                      = C32A66D5-D8B7-2640-B768-082C8F083C37\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = PeiInitialzeThunkPpiToProtocolPei\r
+\r
+\r
+[Sources]\r
+  ThunkPpiToProtocolPei.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  PeiServicesTablePointerLib\r
+  PeiServicesLib\r
+  HobLib\r
+  PeimEntryPoint\r
+  DebugLib\r
+\r
+\r
+[Protocols]\r
+  gEmuThunkProtocolGuid                     # PROTOCOL ALWAYS_CONSUMED\r
+\r
+\r
+[Ppis]\r
+  gEmuThunkPpiGuid                          # PPI ALWAYS_CONSUMED\r
+\r
+\r
+[Depex]\r
+  gEmuThunkPpiGuid AND gEfiPeiMemoryDiscoveredPpiGuid\r
+\r
diff --git a/InOsEmuPkg/TimerDxe/Timer.c b/InOsEmuPkg/TimerDxe/Timer.c
new file mode 100644 (file)
index 0000000..1435913
--- /dev/null
@@ -0,0 +1,351 @@
+/*++ @file\r
+  Emu Emulation Timer Architectural Protocol Driver as defined in DXE CIS\r
+\r
+  This Timer module uses an Emu Thread to simulate the timer-tick driven\r
+  timer service.  In the future, the Thread creation should possibly be\r
+  abstracted by the CPU architectural protocol\r
+\r
+Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2010 - 2011, Apple Inc. All rights reserved.\r
+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
+#include "PiDxe.h"\r
+#include <Protocol/Timer.h>\r
+#include <Protocol/Cpu.h>\r
+#include "Timer.h"\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/EmuThunkLib.h>\r
+\r
+//\r
+// Pointer to the CPU Architectural Protocol instance\r
+//\r
+EFI_CPU_ARCH_PROTOCOL   *mCpu;\r
+\r
+//\r
+// The Timer Architectural Protocol that this driver produces\r
+//\r
+EFI_TIMER_ARCH_PROTOCOL mTimer = {\r
+  EmuTimerDriverRegisterHandler,\r
+  EmuTimerDriverSetTimerPeriod,\r
+  EmuTimerDriverGetTimerPeriod,\r
+  EmuTimerDriverGenerateSoftInterrupt\r
+};\r
+\r
+//\r
+// The notification function to call on every timer interrupt\r
+//\r
+EFI_TIMER_NOTIFY        mTimerNotifyFunction = NULL;\r
+\r
+//\r
+// The current period of the timer interrupt\r
+//\r
+UINT64                  mTimerPeriodMs;\r
+\r
+\r
+VOID\r
+EFIAPI\r
+TimerCallback (UINT64 DeltaMs)\r
+{\r
+  EFI_TPL           OriginalTPL;\r
+  EFI_TIMER_NOTIFY  CallbackFunction;\r
+\r
+\r
+  OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+\r
+  if (OriginalTPL < TPL_HIGH_LEVEL) {\r
+    CallbackFunction = mTimerNotifyFunction;\r
+\r
+    //\r
+    // Only invoke the callback function if a Non-NULL handler has been\r
+    // registered. Assume all other handlers are legal.\r
+    //\r
+    if (CallbackFunction != NULL) {\r
+      CallbackFunction ((UINT64) (DeltaMs * 10000));\r
+    }\r
+  }\r
+\r
+  gBS->RestoreTPL (OriginalTPL);\r
+\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuTimerDriverRegisterHandler (\r
+  IN EFI_TIMER_ARCH_PROTOCOL           *This,\r
+  IN EFI_TIMER_NOTIFY                  NotifyFunction\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function registers the handler NotifyFunction so it is called every time\r
+  the timer interrupt fires.  It also passes the amount of time since the last\r
+  handler call to the NotifyFunction.  If NotifyFunction is NULL, then the\r
+  handler is unregistered.  If the handler is registered, then EFI_SUCCESS is\r
+  returned.  If the CPU does not support registering a timer interrupt handler,\r
+  then EFI_UNSUPPORTED is returned.  If an attempt is made to register a handler\r
+  when a handler is already registered, then EFI_ALREADY_STARTED is returned.\r
+  If an attempt is made to unregister a handler when a handler is not registered,\r
+  then EFI_INVALID_PARAMETER is returned.  If an error occurs attempting to\r
+  register the NotifyFunction with the timer interrupt, then EFI_DEVICE_ERROR\r
+  is returned.\r
+\r
+Arguments:\r
+\r
+  This           - The EFI_TIMER_ARCH_PROTOCOL instance.\r
+\r
+  NotifyFunction - The function to call when a timer interrupt fires.  This\r
+                   function executes at TPL_HIGH_LEVEL.  The DXE Core will\r
+                   register a handler for the timer interrupt, so it can know\r
+                   how much time has passed.  This information is used to\r
+                   signal timer based events.  NULL will unregister the handler.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The timer handler was registered.\r
+\r
+  EFI_UNSUPPORTED       - The platform does not support timer interrupts.\r
+\r
+  EFI_ALREADY_STARTED   - NotifyFunction is not NULL, and a handler is already\r
+                          registered.\r
+\r
+  EFI_INVALID_PARAMETER - NotifyFunction is NULL, and a handler was not\r
+                          previously registered.\r
+\r
+  EFI_DEVICE_ERROR      - The timer handler could not be registered.\r
+\r
+**/\r
+{\r
+  //\r
+  // Check for invalid parameters\r
+  //\r
+  if (NotifyFunction == NULL && mTimerNotifyFunction == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (NotifyFunction != NULL && mTimerNotifyFunction != NULL) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  if (NotifyFunction == NULL) {\r
+    /* Disable timer.  */\r
+    gEmuThunk->SetTimer (0, TimerCallback);\r
+  } else if (mTimerNotifyFunction == NULL) {\r
+    /* Enable Timer.  */\r
+    gEmuThunk->SetTimer (mTimerPeriodMs, TimerCallback);\r
+  }\r
+  mTimerNotifyFunction = NotifyFunction;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuTimerDriverSetTimerPeriod (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This,\r
+  IN UINT64                   TimerPeriod\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function adjusts the period of timer interrupts to the value specified\r
+  by TimerPeriod.  If the timer period is updated, then the selected timer\r
+  period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned.  If\r
+  the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.\r
+  If an error occurs while attempting to update the timer period, then the\r
+  timer hardware will be put back in its state prior to this call, and\r
+  EFI_DEVICE_ERROR is returned.  If TimerPeriod is 0, then the timer interrupt\r
+  is disabled.  This is not the same as disabling the CPU's interrupts.\r
+  Instead, it must either turn off the timer hardware, or it must adjust the\r
+  interrupt controller so that a CPU interrupt is not generated when the timer\r
+  interrupt fires.\r
+\r
+Arguments:\r
+\r
+  This        - The EFI_TIMER_ARCH_PROTOCOL instance.\r
+\r
+  TimerPeriod - The rate to program the timer interrupt in 100 nS units.  If\r
+                the timer hardware is not programmable, then EFI_UNSUPPORTED is\r
+                returned.  If the timer is programmable, then the timer period\r
+                will be rounded up to the nearest timer period that is supported\r
+                by the timer hardware.  If TimerPeriod is set to 0, then the\r
+                timer interrupts will be disabled.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS      - The timer period was changed.\r
+\r
+  EFI_UNSUPPORTED  - The platform cannot change the period of the timer interrupt.\r
+\r
+  EFI_DEVICE_ERROR - The timer period could not be changed due to a device error.\r
+\r
+**/\r
+{\r
+\r
+  //\r
+  // If TimerPeriod is 0, then the timer thread should be canceled\r
+  // If the TimerPeriod is valid, then create and/or adjust the period of the timer thread\r
+  //\r
+  if (TimerPeriod == 0\r
+      || ((TimerPeriod > TIMER_MINIMUM_VALUE)\r
+    && (TimerPeriod < TIMER_MAXIMUM_VALUE))) {\r
+    mTimerPeriodMs = DivU64x32 (TimerPeriod + 5000, 10000);\r
+\r
+    gEmuThunk->SetTimer (mTimerPeriodMs, TimerCallback);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuTimerDriverGetTimerPeriod (\r
+  IN EFI_TIMER_ARCH_PROTOCOL            *This,\r
+  OUT UINT64                            *TimerPeriod\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function retrieves the period of timer interrupts in 100 ns units,\r
+  returns that value in TimerPeriod, and returns EFI_SUCCESS.  If TimerPeriod\r
+  is NULL, then EFI_INVALID_PARAMETER is returned.  If a TimerPeriod of 0 is\r
+  returned, then the timer is currently disabled.\r
+\r
+Arguments:\r
+\r
+  This        - The EFI_TIMER_ARCH_PROTOCOL instance.\r
+\r
+  TimerPeriod - A pointer to the timer period to retrieve in 100 ns units.  If\r
+                0 is returned, then the timer is currently disabled.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The timer period was returned in TimerPeriod.\r
+\r
+  EFI_INVALID_PARAMETER - TimerPeriod is NULL.\r
+\r
+**/\r
+{\r
+  if (TimerPeriod == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *TimerPeriod = mTimerPeriodMs * 10000;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuTimerDriverGenerateSoftInterrupt (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function generates a soft timer interrupt. If the platform does not support soft\r
+  timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCESS is returned.\r
+  If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.RegisterHandler()\r
+  service, then a soft timer interrupt will be generated. If the timer interrupt is\r
+  enabled when this service is called, then the registered handler will be invoked. The\r
+  registered handler should not be able to distinguish a hardware-generated timer\r
+  interrupt from a software-generated timer interrupt.\r
+\r
+Arguments:\r
+\r
+  This  -  The EFI_TIMER_ARCH_PROTOCOL instance.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS       - The soft timer interrupt was generated.\r
+\r
+  EFI_UNSUPPORTEDT  - The platform does not support the generation of soft timer interrupts.\r
+\r
+**/\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuTimerDriverInitialize (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Initialize the Timer Architectural Protocol driver\r
+\r
+Arguments:\r
+\r
+  ImageHandle - ImageHandle of the loaded driver\r
+\r
+  SystemTable - Pointer to the System Table\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - Timer Architectural Protocol created\r
+\r
+  EFI_OUT_OF_RESOURCES  - Not enough resources available to initialize driver.\r
+\r
+  EFI_DEVICE_ERROR      - A device error occured attempting to initialize the driver.\r
+\r
+**/\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_HANDLE  Handle;\r
+\r
+  //\r
+  // Make sure the Timer Architectural Protocol is not already installed in the system\r
+  //\r
+  ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiTimerArchProtocolGuid);\r
+\r
+  //\r
+  // Get the CPU Architectural Protocol instance\r
+  //\r
+  Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (void *)&mCpu);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Install the Timer Architectural Protocol onto a new handle\r
+  //\r
+  Handle = NULL;\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &Handle,\r
+                  &gEfiTimerArchProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &mTimer\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Start the timer thread at the default timer period\r
+  //\r
+  Status = mTimer.SetTimerPeriod (&mTimer, DEFAULT_TIMER_TICK_DURATION);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/InOsEmuPkg/TimerDxe/Timer.h b/InOsEmuPkg/TimerDxe/Timer.h
new file mode 100644 (file)
index 0000000..27fc676
--- /dev/null
@@ -0,0 +1,73 @@
+/*++ @file\r
+  Emu Emulation Architectural Protocol Driver as defined in UEFI/PI.\r
+  This Timer module uses an UNIX Thread to simulate the timer-tick driven\r
+  timer service.\r
+\r
+Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2010 - 2011, Apple Inc. All rights reserved.\r
+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
+#ifndef _TIMER_H_\r
+#define _TIMER_H_\r
+\r
+\r
+\r
+\r
+//\r
+// Legal timer value range in 100 ns units\r
+//\r
+#define TIMER_MINIMUM_VALUE 0\r
+#define TIMER_MAXIMUM_VALUE (0x100000000ULL - 1)\r
+\r
+//\r
+// Default timer value in 100 ns units (50 ms)\r
+//\r
+#define DEFAULT_TIMER_TICK_DURATION 500000\r
+\r
+//\r
+// Function Prototypes\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+EmuTimerDriverInitialize (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuTimerDriverRegisterHandler (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This,\r
+  IN EFI_TIMER_NOTIFY         NotifyFunction\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuTimerDriverSetTimerPeriod (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This,\r
+  IN UINT64                   TimerPeriod\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuTimerDriverGetTimerPeriod (\r
+  IN EFI_TIMER_ARCH_PROTOCOL   *This,\r
+  OUT UINT64                   *TimerPeriod\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuTimerDriverGenerateSoftInterrupt (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This\r
+  );\r
+\r
+#endif\r
diff --git a/InOsEmuPkg/TimerDxe/Timer.inf b/InOsEmuPkg/TimerDxe/Timer.inf
new file mode 100644 (file)
index 0000000..9282fae
--- /dev/null
@@ -0,0 +1,59 @@
+## @file\r
+# Emu Emulation Timer Architectural Protocol Driver as defined in DXE CIS\r
+#\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+#  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                      = EmuTimer\r
+  FILE_GUID                      = 87E1BB14-4D5C-7C4E-A90E-E1415687D062\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = EmuTimerDriverInitialize\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]\r
+  Timer.c\r
+  Timer.h\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  EmuThunkLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  DebugLib\r
+  BaseLib\r
+\r
+\r
+[Protocols]\r
+  gEfiCpuArchProtocolGuid                       # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiTimerArchProtocolGuid                     # PROTOCOL ALWAYS_PRODUCED\r
+\r
+\r
+[Depex]\r
+  gEfiCpuArchProtocolGuid\r
+\r
diff --git a/InOsEmuPkg/Unix/.gdbinit b/InOsEmuPkg/Unix/.gdbinit
new file mode 100644 (file)
index 0000000..173818c
--- /dev/null
@@ -0,0 +1,8 @@
+set confirm off
+set output-radix 16
+b SecGdbScriptBreak
+command
+silent
+source SecMain.gdb
+c
+end
diff --git a/InOsEmuPkg/Unix/Sec/EmuThunk.c b/InOsEmuPkg/Unix/Sec/EmuThunk.c
new file mode 100644 (file)
index 0000000..abae70b
--- /dev/null
@@ -0,0 +1,314 @@
+/*++ @file
+  Since the SEC is the only program in our emulation we 
+  must use a UEFI/PI mechanism to export APIs to other modules.
+  This is the role of the EFI_EMU_THUNK_PROTOCOL.
+
+  The mUnixThunkTable exists so that a change to EFI_EMU_THUNK_PROTOCOL
+  will cause an error in initializing the array if all the member functions
+  are not added. It looks like adding a element to end and not initializing
+  it may cause the table to be initaliized with the members at the end being
+  set to zero. This is bad as jumping to zero will crash.
+
+Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
+Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
+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.             
+
+**/
+
+#include "SecMain.h"
+
+#ifdef __APPLE__
+#define DebugAssert _Mangle__DebugAssert
+
+#include <assert.h>
+#include <CoreServices/CoreServices.h>
+#include <mach/mach.h>
+#include <mach/mach_time.h>
+
+#undef DebugAssert
+#endif
+
+int settimer_initialized;
+struct timeval settimer_timeval;
+void (*settimer_callback)(UINT64 delta);
+
+BOOLEAN gEmulatorInterruptEnabled = FALSE;
+
+
+UINTN
+SecWriteStdErr (
+  IN UINT8     *Buffer,
+  IN UINTN     NumberOfBytes
+  )
+{
+  ssize_t Return;
+  
+  Return = write (1, (const void *)Buffer, (size_t)NumberOfBytes);
+  
+  return (Return == -1) ? 0 : Return;
+}
+
+
+
+void
+settimer_handler (int sig)
+{
+  struct timeval timeval;
+  UINT64 delta;
+
+  gettimeofday (&timeval, NULL);
+  delta = ((UINT64)timeval.tv_sec * 1000) + (timeval.tv_usec / 1000)
+    - ((UINT64)settimer_timeval.tv_sec * 1000) 
+    - (settimer_timeval.tv_usec / 1000);
+  settimer_timeval = timeval;
+  
+  if (settimer_callback) {
+    ReverseGasketUint64 (settimer_callback, delta);
+  }
+}
+
+VOID
+SecSetTimer (
+  IN  UINT64                  PeriodMs,
+  IN  EMU_SET_TIMER_CALLBACK  CallBack
+  )
+{
+  struct itimerval timerval;
+  UINT32 remainder;
+
+  if (!settimer_initialized) {
+    struct sigaction act;
+
+    settimer_initialized = 1;
+    act.sa_handler = settimer_handler;
+    act.sa_flags = 0;
+    sigemptyset (&act.sa_mask);
+    gEmulatorInterruptEnabled = TRUE;
+    if (sigaction (SIGALRM, &act, NULL) != 0) {
+      printf ("SetTimer: sigaction error %s\n", strerror (errno));
+    }
+    if (gettimeofday (&settimer_timeval, NULL) != 0) {
+      printf ("SetTimer: gettimeofday error %s\n", strerror (errno));
+    }
+  }
+  timerval.it_value.tv_sec = DivU64x32(PeriodMs, 1000);
+  DivU64x32Remainder(PeriodMs, 1000, &remainder);
+  timerval.it_value.tv_usec = remainder * 1000;
+  timerval.it_value.tv_sec = DivU64x32(PeriodMs, 1000);
+  timerval.it_interval = timerval.it_value;
+  
+  if (setitimer (ITIMER_REAL, &timerval, NULL) != 0) {
+    printf ("SetTimer: setitimer error %s\n", strerror (errno));
+  }
+  settimer_callback = CallBack;
+}
+
+
+VOID
+SecEnableInterrupt (
+  VOID
+  )
+{
+  sigset_t  sigset;
+
+  gEmulatorInterruptEnabled = TRUE;
+  // Since SetTimer() uses SIGALRM we emulate turning on and off interrupts 
+  // by enabling/disabling SIGALRM.
+  sigemptyset (&sigset);
+  sigaddset (&sigset, SIGALRM);
+  pthread_sigmask (SIG_UNBLOCK, &sigset, NULL);
+}
+
+
+VOID
+SecDisableInterrupt (
+  VOID
+  )
+{
+  sigset_t  sigset;
+
+  // Since SetTimer() uses SIGALRM we emulate turning on and off interrupts 
+  // by enabling/disabling SIGALRM.
+  sigemptyset (&sigset);
+  sigaddset (&sigset, SIGALRM);
+  pthread_sigmask (SIG_BLOCK, &sigset, NULL);
+  gEmulatorInterruptEnabled = FALSE;
+}
+
+
+BOOLEAN
+SecInterruptEanbled (void)
+{
+  return gEmulatorInterruptEnabled;
+}
+
+
+UINT64
+QueryPerformanceFrequency (
+  VOID
+  )
+{
+  // Hard code to nanoseconds
+  return 1000000000ULL;
+}
+
+UINT64
+QueryPerformanceCounter (
+  VOID
+  )
+{
+#if __APPLE__
+  UINT64          Start;
+  Nanoseconds     elapsedNano;
+
+  Start = mach_absolute_time ();
+  
+  // Convert to nanoseconds.
+
+  // Have to do some pointer fun because AbsoluteToNanoseconds 
+  // works in terms of UnsignedWide, which is a structure rather 
+    // than a proper 64-bit integer.
+  elapsedNano = AbsoluteToNanoseconds (*(AbsoluteTime *) &Start);
+
+  return *(uint64_t *) &elapsedNano;
+#else
+  // Need to figure out what to do for Linux?
+  return 0;
+#endif
+}
+  
+
+
+VOID
+SecSleep (
+  IN  UINT64 Milliseconds
+  )
+{
+  struct timespec rq, rm;
+  struct timeval  start, end;
+  unsigned long  MicroSec;
+  
+  rq.tv_sec = Milliseconds / 1000;
+  rq.tv_nsec = (Milliseconds % 1000) * 1000000;
+
+  //
+  // nanosleep gets interrupted by our timer tic. 
+  // we need to track wall clock time or we will stall for way too long
+  //
+  gettimeofday (&start, NULL);
+  end.tv_sec  = start.tv_sec + rq.tv_sec;
+  MicroSec = (start.tv_usec + rq.tv_nsec/1000);
+  end.tv_usec = MicroSec % 1000000;
+  if (MicroSec > 1000000) {
+    end.tv_sec++;
+  }
+
+  while (nanosleep (&rq, &rm) == -1) {
+    if (errno != EINTR) {
+      break;
+    }
+    gettimeofday (&start, NULL);
+    if (start.tv_sec > end.tv_sec) {
+      break;
+    } if ((start.tv_sec == end.tv_sec) && (start.tv_usec > end.tv_usec)) {
+      break;
+    }
+    rq = rm;
+  } 
+}
+
+VOID
+SecExit (
+  UINTN   Status
+  )
+{
+  exit (Status);
+}
+
+
+VOID
+SecGetTime (
+  OUT  EFI_TIME               *Time,
+  OUT EFI_TIME_CAPABILITIES   *Capabilities OPTIONAL
+  )
+{
+  struct tm *tm;
+  time_t t;
+
+  t = time (NULL);
+  tm = localtime (&t);
+
+  Time->Year = 1900 + tm->tm_year;
+  Time->Month = tm->tm_mon + 1;
+  Time->Day = tm->tm_mday;
+  Time->Hour = tm->tm_hour;
+  Time->Minute = tm->tm_min;
+  Time->Second = tm->tm_sec;
+  Time->Nanosecond = 0;
+  Time->TimeZone = timezone;
+  Time->Daylight = (daylight ? EFI_TIME_ADJUST_DAYLIGHT : 0)
+    | (tm->tm_isdst > 0 ? EFI_TIME_IN_DAYLIGHT : 0);
+    
+  if (Capabilities != NULL) {
+    Capabilities->Resolution  = 1;
+    Capabilities->Accuracy    = 50000000;
+    Capabilities->SetsToZero  = FALSE;
+  }
+}
+
+
+
+VOID
+SecSetTime (
+  IN  EFI_TIME               *Time
+  )
+{
+  // Don't change the time on the system
+  // We could save delta to localtime() and have SecGetTime adjust return values?
+  return;
+}
+
+
+EFI_STATUS
+SecGetNextProtocol (
+  IN  BOOLEAN                 EmuBusDriver,
+  OUT EMU_IO_THUNK_PROTOCOL   **Instance   OPTIONAL
+  )
+{
+  return GetNextThunkProtocol (EmuBusDriver, Instance);
+}
+
+
+EMU_THUNK_PROTOCOL gEmuThunkProtocol = {
+  GasketSecWriteStdErr,
+  GasketSecPeCoffGetEntryPoint,
+  GasketSecPeCoffRelocateImageExtraAction,
+  GasketSecPeCoffUnloadImageExtraAction,
+  GasketSecEnableInterrupt,
+  GasketSecDisableInterrupt,
+  GasketQueryPerformanceFrequency,
+  GasketQueryPerformanceCounter,
+  GasketSecSleep,
+  GasketSecExit,
+  GasketSecGetTime,                
+  GasketSecSetTime,
+  GasketSecSetTimer,  
+  GasketSecGetNextProtocol
+};
+
+
+VOID
+SecInitThunkProtocol (
+  VOID
+  )
+{
+  // timezone and daylight lib globals depend on tzset be called 1st.
+  tzset ();
+}
+
diff --git a/InOsEmuPkg/Unix/Sec/FwVol.c b/InOsEmuPkg/Unix/Sec/FwVol.c
new file mode 100644 (file)
index 0000000..a9a09a4
--- /dev/null
@@ -0,0 +1,309 @@
+/*++ @file\r
+  A simple FV stack so the SEC can extract the SEC Core from an\r
+  FV.\r
+\r
+Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+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
+#include "SecMain.h"\r
+\r
+#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \\r
+  (ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1))\r
+\r
+EFI_FFS_FILE_STATE\r
+GetFileState (\r
+  IN UINT8                ErasePolarity,\r
+  IN EFI_FFS_FILE_HEADER  *FfsHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Returns the highest bit set of the State field\r
+\r
+Arguments:\r
+  ErasePolarity   - Erase Polarity  as defined by EFI_FVB2_ERASE_POLARITY\r
+                    in the Attributes field.\r
+  FfsHeader       - Pointer to FFS File Header.\r
+\r
+Returns:\r
+  Returns the highest bit in the State field\r
+\r
+**/\r
+{\r
+  EFI_FFS_FILE_STATE  FileState;\r
+  EFI_FFS_FILE_STATE  HighestBit;\r
+\r
+  FileState = FfsHeader->State;\r
+\r
+  if (ErasePolarity != 0) {\r
+    FileState = (EFI_FFS_FILE_STATE)~FileState;\r
+  }\r
+\r
+  HighestBit = 0x80;\r
+  while (HighestBit != 0 && (HighestBit & FileState) == 0) {\r
+    HighestBit >>= 1;\r
+  }\r
+\r
+  return HighestBit;\r
+}\r
+\r
+UINT8\r
+CalculateHeaderChecksum (\r
+  IN EFI_FFS_FILE_HEADER  *FileHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Calculates the checksum of the header of a file.\r
+\r
+Arguments:\r
+  FileHeader       - Pointer to FFS File Header.\r
+\r
+Returns:\r
+  Checksum of the header.\r
+  \r
+**/\r
+{\r
+  UINT8 *ptr;\r
+  UINTN Index;\r
+  UINT8 Sum;\r
+\r
+  Sum = 0;\r
+  ptr = (UINT8 *) FileHeader;\r
+\r
+  for (Index = 0; Index < sizeof (EFI_FFS_FILE_HEADER) - 3; Index += 4) {\r
+    Sum = (UINT8) (Sum + ptr[Index]);\r
+    Sum = (UINT8) (Sum + ptr[Index + 1]);\r
+    Sum = (UINT8) (Sum + ptr[Index + 2]);\r
+    Sum = (UINT8) (Sum + ptr[Index + 3]);\r
+  }\r
+\r
+  for (; Index < sizeof (EFI_FFS_FILE_HEADER); Index++) {\r
+    Sum = (UINT8) (Sum + ptr[Index]);\r
+  }\r
+  //\r
+  // State field (since this indicates the different state of file).\r
+  //\r
+  Sum = (UINT8) (Sum - FileHeader->State);\r
+  //\r
+  // Checksum field of the file is not part of the header checksum.\r
+  //\r
+  Sum = (UINT8) (Sum - FileHeader->IntegrityCheck.Checksum.File);\r
+\r
+  return Sum;\r
+}\r
+\r
+EFI_STATUS\r
+SecFfsFindNextFile (\r
+  IN EFI_FV_FILETYPE             SearchType,\r
+  IN EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader,\r
+  IN OUT EFI_FFS_FILE_HEADER     **FileHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+    Given the input file pointer, search for the next matching file in the\r
+    FFS volume as defined by SearchType. The search starts from FileHeader inside\r
+    the Firmware Volume defined by FwVolHeader.\r
+\r
+Arguments:\r
+    SearchType - Filter to find only files of this type.\r
+                 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r
+    FwVolHeader - Pointer to the FV header of the volume to search.\r
+                  This parameter must point to a valid FFS volume.\r
+    FileHeader  - Pointer to the current file from which to begin searching.\r
+                  This pointer will be updated upon return to reflect the file\r
+                  found.\r
+\r
+Returns:\r
+    EFI_NOT_FOUND - No files matching the search criteria were found\r
+    EFI_SUCCESS\r
+\r
+**/\r
+{\r
+  EFI_FFS_FILE_HEADER *FfsFileHeader;\r
+  UINT32              FileLength;\r
+  UINT32              FileOccupiedSize;\r
+  UINT32              FileOffset;\r
+  UINT64              FvLength;\r
+  UINT8               ErasePolarity;\r
+  UINT8               FileState;\r
+\r
+  FvLength = FwVolHeader->FvLength;\r
+  if (FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) {\r
+    ErasePolarity = 1;\r
+  } else {\r
+    ErasePolarity = 0;\r
+  }\r
+  //\r
+  // If FileHeader is not specified (NULL) start with the first file in the\r
+  // firmware volume.  Otherwise, start from the FileHeader.\r
+  //\r
+  if (*FileHeader == NULL) {\r
+    FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FwVolHeader + FwVolHeader->HeaderLength);\r
+  } else {\r
+    //\r
+    // Length is 24 bits wide so mask upper 8 bits\r
+    // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.\r
+    //\r
+    FileLength        = *(UINT32 *) (*FileHeader)->Size & 0x00FFFFFF;\r
+    FileOccupiedSize  = GET_OCCUPIED_SIZE (FileLength, 8);\r
+    FfsFileHeader     = (EFI_FFS_FILE_HEADER *) ((UINT8 *) *FileHeader + FileOccupiedSize);\r
+  }\r
+\r
+  FileOffset = (UINT32) ((UINT8 *) FfsFileHeader - (UINT8 *) FwVolHeader);\r
+\r
+  while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) {\r
+    //\r
+    // Get FileState which is the highest bit of the State\r
+    //\r
+    FileState = GetFileState (ErasePolarity, FfsFileHeader);\r
+\r
+    switch (FileState) {\r
+\r
+    case EFI_FILE_HEADER_INVALID:\r
+      FileOffset += sizeof (EFI_FFS_FILE_HEADER);\r
+      FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER));\r
+      break;\r
+\r
+    case EFI_FILE_DATA_VALID:\r
+    case EFI_FILE_MARKED_FOR_UPDATE:\r
+      if (CalculateHeaderChecksum (FfsFileHeader) == 0) {\r
+        FileLength        = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF;\r
+        FileOccupiedSize  = GET_OCCUPIED_SIZE (FileLength, 8);\r
+\r
+        if ((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) {\r
+\r
+          *FileHeader = FfsFileHeader;\r
+\r
+          return EFI_SUCCESS;\r
+        }\r
+\r
+        FileOffset += FileOccupiedSize;\r
+        FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize);\r
+      } else {\r
+        return EFI_NOT_FOUND;\r
+      }\r
+      break;\r
+\r
+    case EFI_FILE_DELETED:\r
+      FileLength        = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF;\r
+      FileOccupiedSize  = GET_OCCUPIED_SIZE (FileLength, 8);\r
+      FileOffset += FileOccupiedSize;\r
+      FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize);\r
+      break;\r
+\r
+    default:\r
+      return EFI_NOT_FOUND;\r
+\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+EFI_STATUS\r
+SecFfsFindSectionData (\r
+  IN EFI_SECTION_TYPE      SectionType,\r
+  IN EFI_FFS_FILE_HEADER   *FfsFileHeader,\r
+  IN OUT VOID              **SectionData\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+    Given the input file pointer, search for the next matching section in the\r
+    FFS volume.\r
+\r
+Arguments:\r
+    SearchType    - Filter to find only sections of this type.\r
+    FfsFileHeader - Pointer to the current file to search.\r
+    SectionData   - Pointer to the Section matching SectionType in FfsFileHeader.\r
+                     NULL if section not found\r
+\r
+Returns:\r
+    EFI_NOT_FOUND - No files matching the search criteria were found\r
+    EFI_SUCCESS\r
+\r
+**/\r
+{\r
+  UINT32                    FileSize;\r
+  EFI_COMMON_SECTION_HEADER *Section;\r
+  UINT32                    SectionLength;\r
+  UINT32                    ParsedLength;\r
+\r
+  //\r
+  // Size is 24 bits wide so mask upper 8 bits.\r
+  //    Does not include FfsFileHeader header size\r
+  // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned.\r
+  //\r
+  Section   = (EFI_COMMON_SECTION_HEADER *) (FfsFileHeader + 1);\r
+  FileSize  = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF;\r
+  FileSize -= sizeof (EFI_FFS_FILE_HEADER);\r
+\r
+  *SectionData  = NULL;\r
+  ParsedLength  = 0;\r
+  while (ParsedLength < FileSize) {\r
+    if (Section->Type == SectionType) {\r
+      *SectionData = (VOID *) (Section + 1);\r
+      return EFI_SUCCESS;\r
+    }\r
+    //\r
+    // Size is 24 bits wide so mask upper 8 bits.\r
+    // SectionLength is adjusted it is 4 byte aligned.\r
+    // Go to the next section\r
+    //\r
+    SectionLength = *(UINT32 *) Section->Size & 0x00FFFFFF;\r
+    SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);\r
+\r
+    ParsedLength += SectionLength;\r
+    Section = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) Section + SectionLength);\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+EFI_STATUS\r
+SecFfsFindPeiCore (\r
+  IN  EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader,\r
+  OUT VOID                        **Pe32Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Given the pointer to the Firmware Volume Header find the SEC\r
+  core and return it's PE32 image.\r
+\r
+Arguments:\r
+  FwVolHeader - Pointer to memory mapped FV\r
+  Pe32Data - Pointer to SEC PE32 iamge.\r
\r
+Returns:  \r
+  EFI_SUCCESS - Pe32Data is valid\r
+  other       - Failure\r
+\r
+**/\r
+{\r
+  EFI_STATUS          Status;\r
+  EFI_FFS_FILE_HEADER *FileHeader;\r
+  EFI_FV_FILETYPE     SearchType;\r
+\r
+  SearchType  = EFI_FV_FILETYPE_PEI_CORE;\r
+  FileHeader  = NULL;\r
+  do {\r
+    Status = SecFfsFindNextFile (SearchType, FwVolHeader, &FileHeader);\r
+    if (!EFI_ERROR (Status)) {\r
+      Status = SecFfsFindSectionData (EFI_SECTION_PE32, FileHeader, Pe32Data);\r
+      return Status;\r
+    }\r
+  } while (!EFI_ERROR (Status));\r
+\r
+  return Status;\r
+}\r
diff --git a/InOsEmuPkg/Unix/Sec/Gasket.h b/InOsEmuPkg/Unix/Sec/Gasket.h
new file mode 100644 (file)
index 0000000..665a075
--- /dev/null
@@ -0,0 +1,420 @@
+/** @file\r
+\r
+  Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>\r
+\r
+  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
+#ifndef _GASKET_H_\r
+#define _GASKET_H_\r
+\r
+//\r
+// EMU_THUNK_PROTOCOL gaskets (EFIAPI to UNIX ABI)\r
+//\r
+\r
+UINTN\r
+GasketSecWriteStdErr (\r
+  IN UINT8     *Buffer,\r
+  IN UINTN     NumberOfBytes\r
+  );\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+GasketSecPeCoffGetEntryPoint (\r
+  IN     VOID  *Pe32Data,\r
+  IN OUT VOID  **EntryPoint\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+GasketSecPeCoffRelocateImageExtraAction (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+GasketSecPeCoffUnloadImageExtraAction (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+GasketSecSetTimer (\r
+  IN  UINT64                  PeriodMs,\r
+  IN  EMU_SET_TIMER_CALLBACK  CallBack\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+GasketSecEnableInterrupt (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+GasketSecDisableInterrupt (\r
+  VOID\r
+  );\r
+  \r
+UINT64  \r
+GasketQueryPerformanceFrequency (\r
+  VOID\r
+  );\r
+\r
+UINT64\r
+GasketQueryPerformanceCounter (\r
+  VOID\r
+  );\r
+\r
+\r
+VOID\r
+EFIAPI\r
+GasketSecSleep (\r
+  IN  UINT64 Milliseconds\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+GasketSecExit (\r
+  UINTN   Status\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+GasketSecGetTime (\r
+  OUT  EFI_TIME               *Time,\r
+  OUT EFI_TIME_CAPABILITIES   *Capabilities OPTIONAL\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+GasketSecSetTime (\r
+  IN  EFI_TIME               *Time\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSecGetNextProtocol (\r
+  IN  BOOLEAN                 EmuBusDriver,\r
+  OUT EMU_IO_THUNK_PROTOCOL   **Instance  OPTIONAL\r
+  );\r
+\r
+\r
+// PPIs produced by SEC  \r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSecUnixPeiLoadFile (\r
+  IN  VOID                  *Pe32Data,  \r
+  IN  EFI_PHYSICAL_ADDRESS  *ImageAddress,  \r
+  IN  UINT64                *ImageSize,  \r
+  OUT EFI_PHYSICAL_ADDRESS  *EntryPoint  \r
+  );\r
+  \r
+EFI_STATUS\r
+EFIAPI\r
+GasketSecUnixPeiAutoScan (\r
+  IN  UINTN                 Index,\r
+  OUT EFI_PHYSICAL_ADDRESS  *MemoryBase,\r
+  OUT UINT64                *MemorySize\r
+  );\r
+  \r
+VOID *\r
+EFIAPI\r
+GasketSecEmuThunkAddress (\r
+  VOID\r
+  );\r
+\r
\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSecUnixUnixFwhAddress (\r
+  IN OUT UINT64                *FwhSize,\r
+  IN OUT EFI_PHYSICAL_ADDRESS  *FwhBase\r
+  );\r
+  \r
+\r
+\r
+//\r
+// Reverse (UNIX to EFIAPI) gaskets\r
+//\r
+\r
+typedef\r
+void\r
+(*CALL_BACK) (\r
+  UINT64 Delta\r
+  );\r
+\r
+UINTN\r
+ReverseGasketUint64 (\r
+  CALL_BACK CallBack,\r
+  UINT64 a\r
+  );\r
+\r
+UINTN\r
+ReverseGasketUint64Uint64 (\r
+  VOID      *CallBack,\r
+  VOID      *Context,\r
+  VOID      *Key\r
+  );\r
+\r
+//\r
+// Gasket functions for EFI_EMU_UGA_IO_PROTOCOL\r
+//\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketX11Size (\r
+  EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo,\r
+  UINT32 Width,\r
+  UINT32 Height\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketX11CheckKey (\r
+  EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketX11GetKey (\r
+  EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo,\r
+  EFI_KEY_DATA                 *key\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketX11KeySetState (\r
+  EMU_GRAPHICS_WINDOW_PROTOCOL  *GraphicsWindowsIo,\r
+  EFI_KEY_TOGGLE_STATE          *KeyToggleState\r
+  );\r
+  \r
+EFI_STATUS\r
+EFIAPI  \r
+GasketX11RegisterKeyNotify ( \r
+  IN EMU_GRAPHICS_WINDOW_PROTOCOL                         *GraphicsWindowsIo, \r
+  IN EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK     MakeCallBack,\r
+  IN EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK     BreakCallBack,\r
+  IN VOID                                                 *Context\r
+  );\r
+\r
+  \r
+EFI_STATUS\r
+EFIAPI\r
+GasketX11Blt (\r
+  IN  EMU_GRAPHICS_WINDOW_PROTOCOL            *GraphicsWindows,\r
+  IN  EFI_UGA_PIXEL                           *BltBuffer OPTIONAL,\r
+  IN  EFI_UGA_BLT_OPERATION                   BltOperation,\r
+  IN  EMU_GRAPHICS_WINDOWS__BLT_ARGS          *Args\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketX11CheckPointer (\r
+  EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo\r
+  );\r
+\r
+EFI_STATUS \r
+EFIAPI \r
+GasketX11GetPointerState (\r
+  EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo, \r
+  EFI_SIMPLE_POINTER_STATE *state\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketX11GraphicsWindowOpen (\r
+  IN  EMU_IO_THUNK_PROTOCOL   *This\r
+  );\r
\r
+EFI_STATUS\r
+EFIAPI\r
+GasketX11GraphicsWindowClose (\r
+  IN  EMU_IO_THUNK_PROTOCOL   *This\r
+  );\r
+\r
+// Pthreads\r
+\r
+UINTN\r
+EFIAPI\r
+GasketPthreadMutexLock (\r
+  IN VOID *Mutex\r
+  );            \r
+\r
+\r
+\r
+UINTN\r
+EFIAPI\r
+GasketPthreadMutexUnLock (\r
+  IN VOID *Mutex\r
+  );                        \r
+\r
\r
+UINTN\r
+EFIAPI\r
+GasketPthreadMutexTryLock (\r
+  IN VOID *Mutex\r
+  );                      \r
+\r
\r
+VOID *\r
+EFIAPI\r
+GasketPthreadMutexInit (\r
+  IN VOID\r
+  );                     \r
+\r
\r
+UINTN\r
+EFIAPI\r
+GasketPthreadMutexDestroy (\r
+  IN VOID *Mutex\r
+  );                            \r
+\r
\r
+UINTN\r
+EFIAPI\r
+GasketPthreadCreate (\r
+  IN  VOID                      *Thread,\r
+  IN  VOID                      *Attribute,\r
+  IN  PTREAD_THUNK_THEAD_ENTRY  Start,\r
+  IN  VOID                      *Context\r
+  );\r
\r
+VOID\r
+EFIAPI\r
+GasketPthreadExit (\r
+  IN VOID *ValuePtr\r
+  );                            \r
+\r
+   \r
+UINTN\r
+EFIAPI\r
+GasketPthreadSelf (\r
+  VOID\r
+  );                              \r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketPthreadOpen (\r
+  IN  EMU_IO_THUNK_PROTOCOL   *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketPthreadClose (\r
+  IN  EMU_IO_THUNK_PROTOCOL   *This\r
+  );\r
+\r
+\r
+// PosixFileSystem\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketPosixOpenVolume (\r
+  IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL    *This,\r
+  OUT EFI_FILE_PROTOCOL                 **Root\r
+  );\r
+  \r
+EFI_STATUS\r
+EFIAPI\r
+GasketPosixFileOpen (\r
+  IN EFI_FILE_PROTOCOL        *This,\r
+  OUT EFI_FILE_PROTOCOL       **NewHandle,\r
+  IN CHAR16                   *FileName,\r
+  IN UINT64                   OpenMode,\r
+  IN UINT64                   Attributes\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketPosixFileCLose (\r
+  IN EFI_FILE_PROTOCOL  *This\r
+  );\r
+  \r
+EFI_STATUS\r
+EFIAPI\r
+GasketPosixFileDelete (\r
+  IN EFI_FILE_PROTOCOL  *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketPosixFileRead (\r
+  IN EFI_FILE_PROTOCOL        *This,\r
+  IN OUT UINTN                *BufferSize,\r
+  OUT VOID                    *Buffer\r
+  );\r
+  \r
+EFI_STATUS\r
+EFIAPI\r
+GasketPosixFileWrite (\r
+  IN EFI_FILE_PROTOCOL        *This,\r
+  IN OUT UINTN                *BufferSize,\r
+  IN VOID                     *Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketPosixFileSetPossition (\r
+  IN EFI_FILE_PROTOCOL        *This,\r
+  IN UINT64                   Position\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketPosixFileGetPossition (\r
+  IN EFI_FILE_PROTOCOL        *This,\r
+  OUT UINT64                  *Position\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketPosixFileGetInfo (\r
+  IN EFI_FILE_PROTOCOL        *This,\r
+  IN EFI_GUID                 *InformationType,\r
+  IN OUT UINTN                *BufferSize,\r
+  OUT VOID                    *Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketPosixFileSetInfo (\r
+  IN EFI_FILE_PROTOCOL        *This,\r
+  IN EFI_GUID                 *InformationType,\r
+  IN UINTN                    BufferSize,\r
+  IN VOID                     *Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketPosixFileFlush (\r
+  IN EFI_FILE_PROTOCOL  *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketPosixFileSystmeThunkOpen (\r
+  IN  EMU_IO_THUNK_PROTOCOL   *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketPosixFileSystmeThunkClose (\r
+  IN  EMU_IO_THUNK_PROTOCOL   *This\r
+  );\r
+\r
+\r
+\r
+#endif\r
+\r
+\r
diff --git a/InOsEmuPkg/Unix/Sec/PosixFileSystem.c b/InOsEmuPkg/Unix/Sec/PosixFileSystem.c
new file mode 100644 (file)
index 0000000..d2d3e6d
--- /dev/null
@@ -0,0 +1,1556 @@
+/*++ @file
+ POSIX Pthreads to emulate APs and implement threads
+
+Copyright (c) 2011, Apple Inc. 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.
+
+
+**/
+
+#include "SecMain.h"
+
+
+#define EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE SIGNATURE_32 ('E', 'P', 'f', 's')
+
+typedef struct {
+  UINTN                           Signature;
+  EMU_IO_THUNK_PROTOCOL           *Thunk;
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFileSystem;
+  CHAR8                           *FilePath;
+  CHAR16                          *VolumeLabel;
+  BOOLEAN                         FileHandlesOpen;
+} EMU_SIMPLE_FILE_SYSTEM_PRIVATE;
+
+#define EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS(a) \
+  CR (a, \
+      EMU_SIMPLE_FILE_SYSTEM_PRIVATE, \
+      SimpleFileSystem, \
+      EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE \
+      )
+
+
+#define EMU_EFI_FILE_PRIVATE_SIGNATURE SIGNATURE_32 ('E', 'P', 'f', 'i')
+
+typedef struct {
+  UINTN                           Signature;
+  EMU_IO_THUNK_PROTOCOL           *Thunk;
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;
+  EFI_FILE_PROTOCOL               EfiFile;
+  int                             fd;
+  DIR                             *Dir;
+  BOOLEAN                         IsRootDirectory;
+  BOOLEAN                         IsDirectoryPath;
+  BOOLEAN                         IsOpenedByRead;
+  char                            *FileName;
+  struct dirent                   *Dirent;
+} EMU_EFI_FILE_PRIVATE;
+
+#define EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS(a) \
+  CR (a, \
+      EMU_EFI_FILE_PRIVATE, \
+      EfiFile, \
+      EMU_EFI_FILE_PRIVATE_SIGNATURE \
+      )
+
+EFI_STATUS
+PosixFileGetInfo (
+  IN EFI_FILE_PROTOCOL        *This,
+  IN EFI_GUID                 *InformationType,
+  IN OUT UINTN                *BufferSize,
+  OUT VOID                    *Buffer
+  );
+
+EFI_STATUS
+PosixFileSetInfo (
+  IN EFI_FILE_PROTOCOL        *This,
+  IN EFI_GUID                 *InformationType,
+  IN UINTN                    BufferSize,
+  IN VOID                     *Buffer
+  );
+
+
+EFI_FILE_PROTOCOL gPosixFileProtocol = {
+  EFI_FILE_REVISION,
+  GasketPosixFileOpen,
+  GasketPosixFileCLose,
+  GasketPosixFileDelete,
+  GasketPosixFileRead,
+  GasketPosixFileWrite,
+  GasketPosixFileGetPossition,
+  GasketPosixFileSetPossition,
+  GasketPosixFileGetInfo,
+  GasketPosixFileSetInfo,
+  GasketPosixFileFlush
+};
+
+EFI_SIMPLE_FILE_SYSTEM_PROTOCOL gPosixFileSystemProtocol = {
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION,
+  GasketPosixOpenVolume,
+};
+
+
+/**
+  Open the root directory on a volume.
+
+  @param  This Protocol instance pointer.
+  @param  Root Returns an Open file handle for the root directory
+
+  @retval EFI_SUCCESS          The device was opened.
+  @retval EFI_UNSUPPORTED      This volume does not support the file system.
+  @retval EFI_NO_MEDIA         The device has no media.
+  @retval EFI_DEVICE_ERROR     The device reported an error.
+  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
+  @retval EFI_ACCESS_DENIED    The service denied access to the file.
+  @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.
+
+**/
+EFI_STATUS
+PosixOpenVolume (
+  IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL    *This,
+  OUT EFI_FILE_PROTOCOL                 **Root
+  )
+{
+  EFI_STATUS                        Status;
+  EMU_SIMPLE_FILE_SYSTEM_PRIVATE    *Private;
+  EMU_EFI_FILE_PRIVATE              *PrivateFile;
+
+  Private     = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (This);
+
+  Status = EFI_OUT_OF_RESOURCES;
+  PrivateFile = malloc (sizeof (EMU_EFI_FILE_PRIVATE));
+  if (PrivateFile == NULL) {
+    goto Done;
+  }
+  
+  PrivateFile->FileName = malloc (AsciiStrSize (Private->FilePath));
+  if (PrivateFile->FileName == NULL) {
+    goto Done;
+  }
+  AsciiStrCpy (PrivateFile->FileName, Private->FilePath);
+  
+  PrivateFile->Signature            = EMU_EFI_FILE_PRIVATE_SIGNATURE;
+  PrivateFile->Thunk                = Private->Thunk;
+  PrivateFile->SimpleFileSystem     = This;
+  PrivateFile->IsRootDirectory      = TRUE;
+  PrivateFile->IsDirectoryPath      = TRUE;
+  PrivateFile->IsOpenedByRead       = TRUE;
+  
+  CopyMem (&PrivateFile->EfiFile, &gPosixFileProtocol, sizeof (EFI_FILE_PROTOCOL));
+
+  PrivateFile->fd                   = -1;
+  PrivateFile->Dir                  = NULL;
+  PrivateFile->Dirent               = NULL;
+  
+  *Root = &PrivateFile->EfiFile;
+
+  PrivateFile->Dir = opendir (PrivateFile->FileName);
+  if (PrivateFile->Dir == NULL) {
+    Status = EFI_ACCESS_DENIED;
+  } else {
+    Status = EFI_SUCCESS;
+  }
+
+Done:
+  if (EFI_ERROR (Status)) {
+    if (PrivateFile != NULL) {
+      if (PrivateFile->FileName != NULL) {
+        free (PrivateFile->FileName);
+      }
+
+      free (PrivateFile);
+    }
+    
+    *Root = NULL;
+  }
+  
+  return Status;
+}
+
+
+EFI_STATUS
+ErrnoToEfiStatus ()
+{
+  switch (errno) {
+  case EACCES:
+    return EFI_ACCESS_DENIED;
+    
+  case EDQUOT:
+  case ENOSPC:
+    return EFI_VOLUME_FULL;
+     
+  default:
+    return EFI_DEVICE_ERROR;      
+  }
+}
+
+VOID
+CutPrefix (
+  IN  CHAR8  *Str,
+  IN  UINTN   Count
+  )
+{
+  CHAR8  *Pointer;
+
+  if (AsciiStrLen (Str) < Count) {
+    ASSERT (0);
+  }
+
+  for (Pointer = Str; *(Pointer + Count); Pointer++) {
+    *Pointer = *(Pointer + Count);
+  }
+
+  *Pointer = *(Pointer + Count);
+}
+
+
+VOID
+PosixSystemTimeToEfiTime (
+  IN  time_t                SystemTime,
+  OUT EFI_TIME              *Time
+  )
+{
+  struct tm *tm;
+
+  tm           = gmtime (&SystemTime);
+  Time->Year   = tm->tm_year;
+  Time->Month  = tm->tm_mon + 1;
+  Time->Day    = tm->tm_mday;
+  Time->Hour   = tm->tm_hour;
+  Time->Minute = tm->tm_min;
+  Time->Second = tm->tm_sec;
+  Time->Nanosecond = 0;
+  
+  Time->TimeZone = timezone;
+  Time->Daylight = (daylight ? EFI_TIME_ADJUST_DAYLIGHT : 0) | (tm->tm_isdst > 0 ? EFI_TIME_IN_DAYLIGHT : 0);
+}
+
+
+EFI_STATUS
+UnixSimpleFileSystemFileInfo (
+  EMU_EFI_FILE_PRIVATE            *PrivateFile,
+  IN     CHAR8                    *FileName,
+  IN OUT UINTN                    *BufferSize,
+  OUT    VOID                     *Buffer
+  )
+{
+  EFI_STATUS                  Status;
+  UINTN                       Size;
+  UINTN                       NameSize;
+  UINTN                       ResultSize;
+  EFI_FILE_INFO               *Info;
+  CHAR8                       *RealFileName;
+  CHAR8                       *TempPointer;
+  CHAR16                      *BufferFileName;
+  struct stat                 buf;
+
+  if (FileName != NULL) {
+    RealFileName = FileName;
+  }
+  else if (PrivateFile->IsRootDirectory) {
+    RealFileName = "";
+  } else {
+    RealFileName  = PrivateFile->FileName;
+  }
+
+  TempPointer = RealFileName;
+  while (*TempPointer) {
+    if (*TempPointer == '/') {
+      RealFileName = TempPointer + 1;
+    }
+
+    TempPointer++;
+  }
+
+  Size        = SIZE_OF_EFI_FILE_INFO;
+  NameSize    = AsciiStrSize (RealFileName) * 2;
+  ResultSize  = Size + NameSize;
+
+  if (*BufferSize < ResultSize) {
+    *BufferSize = ResultSize;
+    return EFI_BUFFER_TOO_SMALL;
+  }
+  if (stat (FileName == NULL ? PrivateFile->FileName : FileName, &buf) < 0) {
+    return EFI_DEVICE_ERROR;
+  }
+
+  Status  = EFI_SUCCESS;
+
+  Info    = Buffer;
+  ZeroMem (Info, ResultSize);
+
+  Info->Size          = ResultSize;
+  Info->FileSize      = buf.st_size;
+  Info->PhysicalSize  = MultU64x32 (buf.st_blocks, buf.st_blksize);
+
+  PosixSystemTimeToEfiTime (buf.st_ctime, &Info->CreateTime);
+  PosixSystemTimeToEfiTime (buf.st_atime, &Info->LastAccessTime);
+  PosixSystemTimeToEfiTime (buf.st_mtime, &Info->ModificationTime);
+
+  if (!(buf.st_mode & S_IWUSR)) {
+    Info->Attribute |= EFI_FILE_READ_ONLY;
+  }
+
+  if (S_ISDIR(buf.st_mode)) {
+    Info->Attribute |= EFI_FILE_DIRECTORY;
+  }
+
+
+  BufferFileName = (CHAR16 *)((CHAR8 *) Buffer + Size);
+  while (*RealFileName) {
+    *BufferFileName++ = *RealFileName++;
+  }
+  *BufferFileName = 0;
+
+  *BufferSize = ResultSize;
+  return Status;
+}
+
+BOOLEAN
+IsZero (
+  IN VOID   *Buffer,
+  IN UINTN  Length
+  )
+{
+  if (Buffer == NULL || Length == 0) {
+    return FALSE;
+  }
+
+  if (*(UINT8 *) Buffer != 0) {
+    return FALSE;
+  }
+
+  if (Length > 1) {
+    if (!CompareMem (Buffer, (UINT8 *) Buffer + 1, Length - 1)) {
+      return FALSE;
+    }
+  }
+
+  return TRUE;
+}
+
+
+
+/**
+  Opens a new file relative to the source file's location.
+
+  @param  This       The protocol instance pointer.
+  @param  NewHandle  Returns File Handle for FileName.
+  @param  FileName   Null terminated string. "\", ".", and ".." are supported.
+  @param  OpenMode   Open mode for file.
+  @param  Attributes Only used for EFI_FILE_MODE_CREATE.
+
+  @retval EFI_SUCCESS          The device was opened.
+  @retval EFI_NOT_FOUND        The specified file could not be found on the device.
+  @retval EFI_NO_MEDIA         The device has no media.
+  @retval EFI_MEDIA_CHANGED    The media has changed.
+  @retval EFI_DEVICE_ERROR     The device reported an error.
+  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
+  @retval EFI_ACCESS_DENIED    The service denied access to the file.
+  @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.
+  @retval EFI_VOLUME_FULL      The volume is full.
+
+**/
+EFI_STATUS
+PosixFileOpen (
+  IN EFI_FILE_PROTOCOL        *This,
+  OUT EFI_FILE_PROTOCOL       **NewHandle,
+  IN CHAR16                   *FileName,
+  IN UINT64                   OpenMode,
+  IN UINT64                   Attributes
+  )
+{
+  EFI_FILE_PROTOCOL                 *Root;
+  EMU_EFI_FILE_PRIVATE              *PrivateFile;
+  EMU_EFI_FILE_PRIVATE              *NewPrivateFile;
+  EMU_SIMPLE_FILE_SYSTEM_PRIVATE    *PrivateRoot;
+  EFI_STATUS                        Status;
+  CHAR16                            *Src;
+  char                              *Dst;
+  CHAR8                             *RealFileName;
+  char                              *ParseFileName;
+  char                              *GuardPointer;
+  CHAR8                             TempChar;
+  UINTN                             Count;
+  BOOLEAN                           TrailingDash;
+  BOOLEAN                           LoopFinish;
+  UINTN                             InfoSize;
+  EFI_FILE_INFO                     *Info;
+  struct stat                       finfo;
+  int                               res;
+  
+
+  PrivateFile     = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+  PrivateRoot     = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);
+  NewPrivateFile  = NULL;
+  Status          = EFI_OUT_OF_RESOURCES;
+
+  //
+  // BUGBUG: assume an open of root
+  // if current location, return current data
+  //
+  if ((StrCmp (FileName, L"\\") == 0) || 
+      (StrCmp (FileName, L".") == 0 && PrivateFile->IsRootDirectory)) {
+OpenRoot:
+    Status          = PosixOpenVolume (PrivateFile->SimpleFileSystem, &Root);
+    NewPrivateFile  = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (Root);
+    goto Done;
+  }
+
+  TrailingDash = FALSE;
+  if (FileName[StrLen (FileName) - 1] == L'\\') {
+    TrailingDash = TRUE;
+    FileName[StrLen (FileName) - 1]  = 0;
+  }
+
+  //
+  // Attempt to open the file
+  //
+  NewPrivateFile = malloc (sizeof (EMU_EFI_FILE_PRIVATE));
+  if (NewPrivateFile == NULL) {
+    goto Done;
+  }
+
+  CopyMem (NewPrivateFile, PrivateFile, sizeof (EMU_EFI_FILE_PRIVATE));
+
+  NewPrivateFile->FileName = malloc (AsciiStrSize (PrivateFile->FileName) + 1 + StrLen (FileName) + 1);
+  if (NewPrivateFile->FileName == NULL) {
+    goto Done;
+  }
+
+  if (*FileName == L'\\') {
+    AsciiStrCpy (NewPrivateFile->FileName, PrivateRoot->FilePath);
+    // Skip first '\'.
+    Src = FileName + 1;
+  } else {
+    AsciiStrCpy (NewPrivateFile->FileName, PrivateFile->FileName);
+    Src = FileName;
+  }
+  Dst = NewPrivateFile->FileName + AsciiStrLen (NewPrivateFile->FileName);
+  GuardPointer = NewPrivateFile->FileName + AsciiStrLen (PrivateRoot->FilePath);
+  *Dst++ = '/';
+  // Convert unicode to ascii and '\' to '/'
+  while (*Src) {
+    if (*Src == '\\') {
+      *Dst++ = '/';
+    } else {
+      *Dst++ = *Src;
+    }
+    Src++;
+  }
+  *Dst = 0;
+      
+
+  //
+  // Get rid of . and .., except leading . or ..
+  //
+
+  //
+  // GuardPointer protect simplefilesystem root path not be destroyed
+  //
+
+  LoopFinish    = FALSE;
+  while (!LoopFinish) {
+    LoopFinish = TRUE;
+
+    for (ParseFileName = GuardPointer; *ParseFileName; ParseFileName++) {
+      if (*ParseFileName == '.' &&
+          (*(ParseFileName + 1) == 0 || *(ParseFileName + 1) == '/') &&
+          *(ParseFileName - 1) == '/'
+          ) {
+
+        //
+        // cut /.
+        //
+        CutPrefix (ParseFileName - 1, 2);
+        LoopFinish = FALSE;
+        break;
+      }
+
+      if (*ParseFileName == '.' &&
+          *(ParseFileName + 1) == '.' &&
+          (*(ParseFileName + 2) == 0 || *(ParseFileName + 2) == '/') &&
+          *(ParseFileName - 1) == '/'
+          ) {
+
+        ParseFileName--;
+        Count = 3;
+
+        while (ParseFileName != GuardPointer) {
+          ParseFileName--;
+          Count++;
+          if (*ParseFileName == '/') {
+            break;
+          }
+        }
+
+        //
+        // cut /.. and its left directory
+        //
+        CutPrefix (ParseFileName, Count);
+        LoopFinish = FALSE;
+        break;
+      }
+    }
+  }
+
+  if (AsciiStrCmp (NewPrivateFile->FileName, PrivateRoot->FilePath) == 0) {
+    NewPrivateFile->IsRootDirectory = TRUE;
+    free (NewPrivateFile->FileName);
+    free (NewPrivateFile);
+    goto OpenRoot;
+  }
+
+  RealFileName = NewPrivateFile->FileName + AsciiStrLen(NewPrivateFile->FileName) - 1;
+  while (RealFileName > NewPrivateFile->FileName && *RealFileName != '/') {
+    RealFileName--;
+  }
+  
+  TempChar            = *(RealFileName - 1);
+  *(RealFileName - 1) = 0;
+  *(RealFileName - 1) = TempChar;
+
+
+  //
+  // Test whether file or directory
+  //
+  NewPrivateFile->IsRootDirectory = FALSE;
+  NewPrivateFile->fd = -1;
+  NewPrivateFile->Dir = NULL;
+  if (OpenMode & EFI_FILE_MODE_CREATE) {
+    if (Attributes & EFI_FILE_DIRECTORY) {
+      NewPrivateFile->IsDirectoryPath = TRUE;
+    } else {
+      NewPrivateFile->IsDirectoryPath = FALSE;
+    }
+  } else {
+    res = stat (NewPrivateFile->FileName, &finfo);
+    if (res == 0 && S_ISDIR(finfo.st_mode)) {
+      NewPrivateFile->IsDirectoryPath = TRUE;
+    } else {
+      NewPrivateFile->IsDirectoryPath = FALSE;
+    }
+  }
+
+  if (OpenMode & EFI_FILE_MODE_WRITE) {
+    NewPrivateFile->IsOpenedByRead = FALSE;
+  } else {
+    NewPrivateFile->IsOpenedByRead = TRUE;
+  }
+
+  Status = EFI_SUCCESS;
+
+  //
+  // deal with directory
+  //
+  if (NewPrivateFile->IsDirectoryPath) {
+    if ((OpenMode & EFI_FILE_MODE_CREATE)) {
+      //
+      // Create a directory
+      //
+      if (mkdir (NewPrivateFile->FileName, 0777) != 0) {
+        if (errno != EEXIST) {
+          //free (TempFileName);
+          Status = EFI_ACCESS_DENIED;
+          goto Done;
+        }
+      }
+    }
+
+    NewPrivateFile->Dir = opendir (NewPrivateFile->FileName);
+    if (NewPrivateFile->Dir == NULL) {
+      if (errno == EACCES) {
+        Status = EFI_ACCESS_DENIED;
+      } else {
+        Status = EFI_NOT_FOUND;
+      }
+
+      goto Done;
+    }
+
+  } else {
+    //
+    // deal with file
+    //
+    NewPrivateFile->fd = open (
+                          NewPrivateFile->FileName,
+                          ((OpenMode & EFI_FILE_MODE_CREATE) ? O_CREAT : 0) | (NewPrivateFile->IsOpenedByRead ? O_RDONLY : O_RDWR),
+                          0666
+                          );
+    if (NewPrivateFile->fd < 0) {
+      if (errno == ENOENT) {
+        Status = EFI_NOT_FOUND;
+      } else {
+        Status = EFI_ACCESS_DENIED;
+      }
+    }
+  }
+
+  if ((OpenMode & EFI_FILE_MODE_CREATE) && Status == EFI_SUCCESS) {
+    //
+    // Set the attribute
+    //
+    InfoSize  = 0;
+    Info      = NULL;
+    Status    = PosixFileGetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, &InfoSize, Info);
+    if (Status != EFI_BUFFER_TOO_SMALL) {
+      Status = EFI_DEVICE_ERROR;
+      goto Done;
+    }
+    
+    Info = malloc (InfoSize);
+    if (Info == NULL) {
+      goto Done;
+    }
+
+    Status = PosixFileGetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, &InfoSize, Info);
+    if (EFI_ERROR (Status)) {
+      goto Done;
+    }
+
+    Info->Attribute = Attributes;
+    PosixFileSetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, InfoSize, Info);
+    
+    free (Info);
+  }
+
+Done: ;
+  if (TrailingDash) {
+    FileName[StrLen (FileName) + 1]  = 0;
+    FileName[StrLen (FileName)]      = L'\\';
+  }
+
+  if (EFI_ERROR (Status)) {
+    if (NewPrivateFile) {
+      if (NewPrivateFile->FileName) {
+        free (NewPrivateFile->FileName);
+      }
+
+      free (NewPrivateFile);
+    }
+  } else {
+    *NewHandle = &NewPrivateFile->EfiFile;
+  }
+
+  return Status;
+}
+
+
+
+/**
+  Close the file handle
+
+  @param  This          Protocol instance pointer.
+
+  @retval EFI_SUCCESS   The device was opened.
+
+**/
+EFI_STATUS
+PosixFileCLose (
+  IN EFI_FILE_PROTOCOL  *This
+  )
+{
+  EMU_EFI_FILE_PRIVATE *PrivateFile;
+
+  PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+
+  if (PrivateFile->fd >= 0) {
+    close (PrivateFile->fd);
+  }
+  if (PrivateFile->Dir != NULL) {
+    closedir (PrivateFile->Dir);
+  }
+
+  PrivateFile->fd = -1;
+  PrivateFile->Dir = NULL;
+
+  if (PrivateFile->FileName) {
+    free (PrivateFile->FileName);
+  }
+
+  free (PrivateFile);
+
+  return EFI_SUCCESS;
+}
+
+
+/**
+  Close and delete the file handle.
+
+  @param  This                     Protocol instance pointer.
+                                   
+  @retval EFI_SUCCESS              The device was opened.
+  @retval EFI_WARN_DELETE_FAILURE  The handle was closed but the file was not deleted.
+
+**/
+EFI_STATUS
+PosixFileDelete (
+  IN EFI_FILE_PROTOCOL  *This
+  )
+{
+  EFI_STATUS              Status;
+  EMU_EFI_FILE_PRIVATE   *PrivateFile;
+  
+  PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+  Status      = EFI_WARN_DELETE_FAILURE;
+
+  if (PrivateFile->IsDirectoryPath) {
+    if (PrivateFile->Dir != NULL) {
+      closedir (PrivateFile->Dir);
+      PrivateFile->Dir = NULL;
+    }
+
+    if (rmdir (PrivateFile->FileName) == 0) {
+      Status = EFI_SUCCESS;
+    }
+  } else {
+    close (PrivateFile->fd);
+    PrivateFile->fd = -1;
+
+    if (!PrivateFile->IsOpenedByRead) {
+      if (!unlink (PrivateFile->FileName)) {
+        Status = EFI_SUCCESS;
+      }
+    }
+  }
+
+  free (PrivateFile->FileName);
+  free (PrivateFile);
+
+  return Status;
+}
+
+
+/**
+  Read data from the file.
+
+  @param  This       Protocol instance pointer.
+  @param  BufferSize On input size of buffer, on output amount of data in buffer.
+  @param  Buffer     The buffer in which data is read.
+
+  @retval EFI_SUCCESS          Data was read.
+  @retval EFI_NO_MEDIA         The device has no media.
+  @retval EFI_DEVICE_ERROR     The device reported an error.
+  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
+  @retval EFI_BUFFER_TO_SMALL  BufferSize is too small. BufferSize contains required size.
+
+**/
+EFI_STATUS
+PosixFileRead (
+  IN EFI_FILE_PROTOCOL        *This,
+  IN OUT UINTN                *BufferSize,
+  OUT VOID                    *Buffer
+  )
+{
+  EMU_EFI_FILE_PRIVATE    *PrivateFile;
+  EFI_STATUS              Status;
+  int                     Res;
+  UINTN                   Size;
+  UINTN                   NameSize;
+  UINTN                   ResultSize;
+  CHAR8                   *FullFileName;
+
+
+  PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+
+  if (!PrivateFile->IsDirectoryPath) {
+    if (PrivateFile->fd < 0) {
+      Status = EFI_DEVICE_ERROR;
+      goto Done;
+    }
+
+    Res = read (PrivateFile->fd, Buffer, *BufferSize);
+    if (Res < 0) {
+      Status = EFI_DEVICE_ERROR;
+      goto Done;
+    }
+    *BufferSize = Res;
+    Status = EFI_SUCCESS;
+    goto Done;
+  }
+
+  //
+  // Read on a directory.
+  //
+  if (PrivateFile->Dir == NULL) {
+    Status = EFI_DEVICE_ERROR;
+    goto Done;
+  }
+
+  if (PrivateFile->Dirent == NULL) {
+    PrivateFile->Dirent = readdir (PrivateFile->Dir);
+    if (PrivateFile->Dirent == NULL) {
+      *BufferSize = 0;
+      Status = EFI_SUCCESS;
+      goto Done;
+    }
+  }
+
+  Size        = SIZE_OF_EFI_FILE_INFO;
+  NameSize    = AsciiStrLen (PrivateFile->Dirent->d_name) + 1;
+  ResultSize  = Size + 2 * NameSize;
+
+  if (*BufferSize < ResultSize) {
+    *BufferSize = ResultSize;
+    Status = EFI_BUFFER_TOO_SMALL;
+    goto Done;
+  }
+  Status  = EFI_SUCCESS;
+
+  *BufferSize = ResultSize;
+
+  FullFileName = malloc (AsciiStrLen(PrivateFile->FileName) + 1 + NameSize);
+  if (FullFileName == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
+    goto Done;  
+  }
+         
+  AsciiStrCpy (FullFileName, PrivateFile->FileName);
+  AsciiStrCat (FullFileName, "/");
+  AsciiStrCat (FullFileName, PrivateFile->Dirent->d_name);
+  Status = UnixSimpleFileSystemFileInfo (
+            PrivateFile,
+            FullFileName,
+            BufferSize,
+            Buffer
+            );
+  free (FullFileName);
+
+  PrivateFile->Dirent = NULL;
+
+Done:
+  return Status;
+}
+
+
+
+/**
+  Write data to a file.
+
+  @param  This       Protocol instance pointer.
+  @param  BufferSize On input size of buffer, on output amount of data in buffer.
+  @param  Buffer     The buffer in which data to write.
+
+  @retval EFI_SUCCESS          Data was written.
+  @retval EFI_UNSUPPORTED      Writes to Open directory are not supported.
+  @retval EFI_NO_MEDIA         The device has no media.
+  @retval EFI_DEVICE_ERROR     The device reported an error.
+  @retval EFI_DEVICE_ERROR     An attempt was made to write to a deleted file.
+  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
+  @retval EFI_WRITE_PROTECTED  The device is write protected.
+  @retval EFI_ACCESS_DENIED    The file was open for read only.
+  @retval EFI_VOLUME_FULL      The volume is full.
+
+**/
+EFI_STATUS
+PosixFileWrite (
+  IN EFI_FILE_PROTOCOL        *This,
+  IN OUT UINTN                *BufferSize,
+  IN VOID                     *Buffer
+  )
+{
+  EMU_EFI_FILE_PRIVATE  *PrivateFile;
+  int                   Res;
+
+
+  PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+
+  if (PrivateFile->fd < 0) {
+    return EFI_DEVICE_ERROR;
+  }
+
+  if (PrivateFile->IsDirectoryPath) {
+    return EFI_UNSUPPORTED;
+  }
+
+  if (PrivateFile->IsOpenedByRead) {
+    return EFI_ACCESS_DENIED;
+  }
+
+  Res = write (PrivateFile->fd, Buffer, *BufferSize);
+  if (Res == (UINTN)-1) {
+    return ErrnoToEfiStatus ();
+  }
+  
+  *BufferSize = Res;
+  return EFI_SUCCESS;
+}
+
+
+
+/**
+  Set a files current position
+
+  @param  This            Protocol instance pointer.
+  @param  Position        Byte position from the start of the file.
+                          
+  @retval EFI_SUCCESS     Data was written.
+  @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open.
+
+**/
+EFI_STATUS
+PosixFileSetPossition (
+  IN EFI_FILE_PROTOCOL        *This,
+  IN UINT64                   Position
+  )
+{
+  EMU_EFI_FILE_PRIVATE    *PrivateFile;
+  off_t                   Pos;
+
+  PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+
+  if (PrivateFile->IsDirectoryPath) {
+    if (Position != 0) {
+      return EFI_UNSUPPORTED;
+    }
+
+    if (PrivateFile->Dir == NULL) {
+      return EFI_DEVICE_ERROR;
+    }
+    rewinddir (PrivateFile->Dir);
+    return EFI_SUCCESS;
+  } else {
+    if (Position == (UINT64) -1) {
+      Pos = lseek (PrivateFile->fd, 0, SEEK_END);
+    } else {
+      Pos = lseek (PrivateFile->fd, Position, SEEK_SET);
+    }
+    if (Pos == (off_t)-1) {
+      return ErrnoToEfiStatus ();
+    }
+    return EFI_SUCCESS;
+  }
+}
+
+
+
+/**
+  Get a file's current position
+
+  @param  This            Protocol instance pointer.
+  @param  Position        Byte position from the start of the file.
+                          
+  @retval EFI_SUCCESS     Data was written.
+  @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open..
+
+**/
+EFI_STATUS
+PosixFileGetPossition (
+  IN EFI_FILE_PROTOCOL        *This,
+  OUT UINT64                  *Position
+  )
+{
+  EFI_STATUS            Status;
+  EMU_EFI_FILE_PRIVATE  *PrivateFile;
+  
+  PrivateFile   = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+
+  if (PrivateFile->IsDirectoryPath) {
+    Status = EFI_UNSUPPORTED;
+  } else {
+    *Position = (UINT64)lseek (PrivateFile->fd, 0, SEEK_CUR);
+    Status = (*Position == (UINT64) -1) ? ErrnoToEfiStatus () : EFI_SUCCESS;
+  }
+
+  return Status;
+}
+
+
+/**
+  Get information about a file.
+
+  @param  This            Protocol instance pointer.
+  @param  InformationType Type of information to return in Buffer.
+  @param  BufferSize      On input size of buffer, on output amount of data in buffer.
+  @param  Buffer          The buffer to return data.
+
+  @retval EFI_SUCCESS          Data was returned.
+  @retval EFI_UNSUPPORTED      InformationType is not supported.
+  @retval EFI_NO_MEDIA         The device has no media.
+  @retval EFI_DEVICE_ERROR     The device reported an error.
+  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
+  @retval EFI_WRITE_PROTECTED  The device is write protected.
+  @retval EFI_ACCESS_DENIED    The file was open for read only.
+  @retval EFI_BUFFER_TOO_SMALL Buffer was too small; required size returned in BufferSize.
+
+**/
+EFI_STATUS
+PosixFileGetInfo (
+  IN EFI_FILE_PROTOCOL        *This,
+  IN EFI_GUID                 *InformationType,
+  IN OUT UINTN                *BufferSize,
+  OUT VOID                    *Buffer
+  )
+{
+  EFI_STATUS                        Status;
+  EMU_EFI_FILE_PRIVATE              *PrivateFile;
+  EFI_FILE_SYSTEM_INFO              *FileSystemInfoBuffer;
+  int                               UnixStatus;
+  EMU_SIMPLE_FILE_SYSTEM_PRIVATE    *PrivateRoot;
+  struct statfs                     buf;
+
+  PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+  PrivateRoot = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);
+
+  Status = EFI_SUCCESS;
+  if (CompareGuid (InformationType, &gEfiFileInfoGuid)) {
+    Status = UnixSimpleFileSystemFileInfo (PrivateFile, NULL, BufferSize, Buffer);
+  } else if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {
+    if (*BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel)) {
+      *BufferSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel);
+      return EFI_BUFFER_TOO_SMALL;
+    }
+
+    UnixStatus = statfs (PrivateFile->FileName, &buf);
+    if (UnixStatus < 0) {
+      return EFI_DEVICE_ERROR;
+    }
+
+    FileSystemInfoBuffer            = (EFI_FILE_SYSTEM_INFO *) Buffer;
+    FileSystemInfoBuffer->Size      = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel);
+    FileSystemInfoBuffer->ReadOnly  = FALSE;
+
+    //
+    // Succeeded
+    //
+    FileSystemInfoBuffer->VolumeSize  = MultU64x32 (buf.f_blocks, buf.f_bsize);
+    FileSystemInfoBuffer->FreeSpace   = MultU64x32 (buf.f_bavail, buf.f_bsize);
+    FileSystemInfoBuffer->BlockSize   = buf.f_bsize;
+
+
+    StrCpy ((CHAR16 *) FileSystemInfoBuffer->VolumeLabel, PrivateRoot->VolumeLabel);
+    *BufferSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel);
+    
+  } else if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {
+    if (*BufferSize < StrSize (PrivateRoot->VolumeLabel)) {
+      *BufferSize = StrSize (PrivateRoot->VolumeLabel);
+      return EFI_BUFFER_TOO_SMALL;
+    }
+
+    StrCpy ((CHAR16 *) Buffer, PrivateRoot->VolumeLabel);
+    *BufferSize = StrSize (PrivateRoot->VolumeLabel);
+
+  }
+
+  return Status;
+}
+
+
+/**
+  Set information about a file
+
+  @param  File            Protocol instance pointer.
+  @param  InformationType Type of information in Buffer.
+  @param  BufferSize      Size of buffer.
+  @param  Buffer          The data to write.
+
+  @retval EFI_SUCCESS          Data was returned.
+  @retval EFI_UNSUPPORTED      InformationType is not supported.
+  @retval EFI_NO_MEDIA         The device has no media.
+  @retval EFI_DEVICE_ERROR     The device reported an error.
+  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
+  @retval EFI_WRITE_PROTECTED  The device is write protected.
+  @retval EFI_ACCESS_DENIED    The file was open for read only.
+
+**/
+EFI_STATUS
+PosixFileSetInfo (
+  IN EFI_FILE_PROTOCOL        *This,
+  IN EFI_GUID                 *InformationType,
+  IN UINTN                    BufferSize,
+  IN VOID                     *Buffer
+  )
+{
+  EMU_SIMPLE_FILE_SYSTEM_PRIVATE    *PrivateRoot;
+  EMU_EFI_FILE_PRIVATE              *PrivateFile;
+  EFI_FILE_INFO                     *OldFileInfo;
+  EFI_FILE_INFO                     *NewFileInfo;
+  EFI_STATUS                        Status;
+  UINTN                             OldInfoSize;
+  mode_t                            NewAttr;
+  struct stat                       OldAttr;
+  CHAR8                             *OldFileName;
+  CHAR8                             *NewFileName;
+  CHAR8                             *CharPointer;
+  BOOLEAN                           AttrChangeFlag;
+  BOOLEAN                           NameChangeFlag;
+  BOOLEAN                           SizeChangeFlag;
+  BOOLEAN                           TimeChangeFlag;
+  struct tm                         NewLastAccessSystemTime;
+  struct tm                         NewLastWriteSystemTime;
+  EFI_FILE_SYSTEM_INFO              *NewFileSystemInfo;
+  CHAR8                             *AsciiFilePtr;
+  CHAR16                            *UnicodeFilePtr;
+  int                               UnixStatus;
+  struct utimbuf                    Utime;
+  
+
+  PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+  PrivateRoot = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);
+  errno       = 0;
+  Status      = EFI_UNSUPPORTED;
+  OldFileInfo = NewFileInfo = NULL;
+  OldFileName = NewFileName = NULL;
+  AttrChangeFlag = NameChangeFlag = SizeChangeFlag = TimeChangeFlag = FALSE;
+
+  //
+  // Set file system information.
+  //
+  if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {
+    if (BufferSize < (SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel))) {
+      Status = EFI_BAD_BUFFER_SIZE;
+      goto Done;
+    }
+
+    NewFileSystemInfo = (EFI_FILE_SYSTEM_INFO *) Buffer;
+
+    free (PrivateRoot->VolumeLabel);
+
+    PrivateRoot->VolumeLabel = malloc (StrSize (NewFileSystemInfo->VolumeLabel));
+    if (PrivateRoot->VolumeLabel == NULL) {
+      goto Done;
+    }
+
+    StrCpy (PrivateRoot->VolumeLabel, NewFileSystemInfo->VolumeLabel);
+
+    Status = EFI_SUCCESS;
+    goto Done;
+  }
+
+  //
+  // Set volume label information.
+  //
+  if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {
+    if (BufferSize < StrSize (PrivateRoot->VolumeLabel)) {
+      Status = EFI_BAD_BUFFER_SIZE;
+      goto Done;
+    }
+
+    StrCpy (PrivateRoot->VolumeLabel, (CHAR16 *) Buffer);
+
+    Status = EFI_SUCCESS;
+    goto Done;
+  }
+
+  if (!CompareGuid (InformationType, &gEfiFileInfoGuid)) {
+    Status = EFI_UNSUPPORTED;
+    goto Done;
+  }
+
+  if (BufferSize < SIZE_OF_EFI_FILE_INFO) {
+    Status = EFI_BAD_BUFFER_SIZE;
+    goto Done;
+  }
+
+  //
+  // Set file/directory information.
+  //
+
+  //
+  // Check for invalid set file information parameters.
+  //
+  NewFileInfo = (EFI_FILE_INFO *) Buffer;
+  if (NewFileInfo->Size <= sizeof (EFI_FILE_INFO) ||
+      (NewFileInfo->Attribute &~(EFI_FILE_VALID_ATTR)) ||
+      (sizeof (UINTN) == 4 && NewFileInfo->Size > 0xFFFFFFFF)
+      ) {
+    Status = EFI_INVALID_PARAMETER;
+    goto Done;
+  }
+
+  //
+  // Get current file information so we can determine what kind
+  // of change request this is.
+  //
+  OldInfoSize = 0;
+  Status = UnixSimpleFileSystemFileInfo (PrivateFile, NULL, &OldInfoSize, NULL);
+  if (Status != EFI_BUFFER_TOO_SMALL) {
+    Status = EFI_DEVICE_ERROR;
+    goto Done;
+  }
+
+  OldFileInfo = malloc (OldInfoSize);
+  if (OldFileInfo == NULL) {
+    goto Done;
+  }
+
+  Status = UnixSimpleFileSystemFileInfo (PrivateFile, NULL, &OldInfoSize, OldFileInfo);
+  if (EFI_ERROR (Status)) {
+    goto Done;
+  }
+
+  OldFileName = malloc (AsciiStrSize (PrivateFile->FileName));
+  if (OldFileInfo == NULL) {
+    goto Done;
+  }
+
+  AsciiStrCpy (OldFileName, PrivateFile->FileName);
+
+  //
+  // Make full pathname from new filename and rootpath.
+  //
+  if (NewFileInfo->FileName[0] == '\\') {
+    NewFileName = malloc (AsciiStrLen (PrivateRoot->FilePath) + 1 + StrLen (NewFileInfo->FileName) + 1);
+    if (NewFileName == NULL) {
+      goto Done;
+    }
+
+    AsciiStrCpy (NewFileName, PrivateRoot->FilePath);
+    AsciiFilePtr = NewFileName + AsciiStrLen(NewFileName);
+    UnicodeFilePtr = NewFileInfo->FileName + 1;
+    *AsciiFilePtr++ ='/';
+  } else {
+    NewFileName = malloc (AsciiStrLen (PrivateFile->FileName) + 2 + StrLen (NewFileInfo->FileName) + 1);
+    if (NewFileName == NULL) {
+      goto Done;
+    }
+
+    AsciiStrCpy (NewFileName, PrivateRoot->FilePath);
+    AsciiFilePtr = NewFileName + AsciiStrLen(NewFileName);
+    if ((AsciiFilePtr[-1] != '/') && (NewFileInfo->FileName[0] != '/')) {
+      // make sure there is a / between Root FilePath and NewFileInfo Filename
+      AsciiFilePtr[0] = '/';      
+      AsciiFilePtr[1] = '\0';
+      AsciiFilePtr++;
+    }
+    UnicodeFilePtr = NewFileInfo->FileName;
+  }
+  // Convert to ascii.
+  while (*UnicodeFilePtr) {
+    *AsciiFilePtr++ = *UnicodeFilePtr++;
+  }
+  *AsciiFilePtr = 0;
+
+  //
+  // Is there an attribute change request?
+  //
+  if (NewFileInfo->Attribute != OldFileInfo->Attribute) {
+    if ((NewFileInfo->Attribute & EFI_FILE_DIRECTORY) != (OldFileInfo->Attribute & EFI_FILE_DIRECTORY)) {
+      Status = EFI_INVALID_PARAMETER;
+      goto Done;
+    }
+
+    AttrChangeFlag = TRUE;
+  }
+
+  //
+  // Is there a name change request?
+  // bugbug: - Should really use EFI_UNICODE_COLLATION_PROTOCOL
+  //
+  if (StrCmp (NewFileInfo->FileName, OldFileInfo->FileName)) {
+    NameChangeFlag = TRUE;
+  }
+
+  //
+  // Is there a size change request?
+  //
+  if (NewFileInfo->FileSize != OldFileInfo->FileSize) {
+    SizeChangeFlag = TRUE;
+  }
+
+  //
+  // Is there a time stamp change request?
+  //
+  if (!IsZero (&NewFileInfo->CreateTime, sizeof (EFI_TIME)) &&
+      CompareMem (&NewFileInfo->CreateTime, &OldFileInfo->CreateTime, sizeof (EFI_TIME))
+      ) {
+    TimeChangeFlag = TRUE;
+  } else if (!IsZero (&NewFileInfo->LastAccessTime, sizeof (EFI_TIME)) &&
+             CompareMem (&NewFileInfo->LastAccessTime, &OldFileInfo->LastAccessTime, sizeof (EFI_TIME))
+             ) {
+    TimeChangeFlag = TRUE;
+  } else if (!IsZero (&NewFileInfo->ModificationTime, sizeof (EFI_TIME)) &&
+             CompareMem (&NewFileInfo->ModificationTime, &OldFileInfo->ModificationTime, sizeof (EFI_TIME))
+             ) {
+    TimeChangeFlag = TRUE;
+  }
+
+  //
+  // All done if there are no change requests being made.
+  //
+  if (!(AttrChangeFlag || NameChangeFlag || SizeChangeFlag || TimeChangeFlag)) {
+    Status = EFI_SUCCESS;
+    goto Done;
+  }
+
+  //
+  // Set file or directory information.
+  //
+  if (stat (OldFileName, &OldAttr) != 0) {
+    Status = ErrnoToEfiStatus ();
+    goto Done;
+  }
+
+  //
+  // Name change.
+  //
+  if (NameChangeFlag) {
+    //
+    // Close the handles first
+    //
+    if (PrivateFile->IsOpenedByRead) {
+      Status = EFI_ACCESS_DENIED;
+      goto Done;
+    }
+
+    for (CharPointer = NewFileName; *CharPointer != 0 && *CharPointer != L'/'; CharPointer++) {
+    }
+
+    if (*CharPointer != 0) {
+      Status = EFI_ACCESS_DENIED;
+      goto Done;
+    }
+
+    UnixStatus = rename (OldFileName, NewFileName);
+    if (UnixStatus == 0) {
+      //
+      // modify file name
+      //
+      free (PrivateFile->FileName);
+
+      PrivateFile->FileName = malloc (AsciiStrSize (NewFileName));
+      if (PrivateFile->FileName == NULL) {
+        goto Done;
+      }
+
+      AsciiStrCpy (PrivateFile->FileName, NewFileName);
+    } else {
+      Status    = EFI_DEVICE_ERROR;
+      goto Done;
+    }
+  }
+
+  //
+  //  Size change
+  //
+  if (SizeChangeFlag) {
+    if (PrivateFile->IsDirectoryPath) {
+      Status = EFI_UNSUPPORTED;
+      goto Done;
+    }
+
+    if (PrivateFile->IsOpenedByRead || OldFileInfo->Attribute & EFI_FILE_READ_ONLY) {
+      Status = EFI_ACCESS_DENIED;
+      goto Done;
+    }
+
+    if (ftruncate (PrivateFile->fd, NewFileInfo->FileSize) != 0) {
+      Status = ErrnoToEfiStatus ();
+      goto Done;
+    }
+
+  }
+
+  //
+  // Time change
+  //
+  if (TimeChangeFlag) {
+    NewLastAccessSystemTime.tm_year    = NewFileInfo->LastAccessTime.Year;
+    NewLastAccessSystemTime.tm_mon     = NewFileInfo->LastAccessTime.Month;
+    NewLastAccessSystemTime.tm_mday    = NewFileInfo->LastAccessTime.Day;
+    NewLastAccessSystemTime.tm_hour    = NewFileInfo->LastAccessTime.Hour;
+    NewLastAccessSystemTime.tm_min     = NewFileInfo->LastAccessTime.Minute;
+    NewLastAccessSystemTime.tm_sec     = NewFileInfo->LastAccessTime.Second;
+    NewLastAccessSystemTime.tm_isdst   = 0;
+
+    Utime.actime = mktime (&NewLastAccessSystemTime);
+
+    NewLastWriteSystemTime.tm_year    = NewFileInfo->ModificationTime.Year;
+    NewLastWriteSystemTime.tm_mon     = NewFileInfo->ModificationTime.Month;
+    NewLastWriteSystemTime.tm_mday    = NewFileInfo->ModificationTime.Day;
+    NewLastWriteSystemTime.tm_hour    = NewFileInfo->ModificationTime.Hour;
+    NewLastWriteSystemTime.tm_min     = NewFileInfo->ModificationTime.Minute;
+    NewLastWriteSystemTime.tm_sec     = NewFileInfo->ModificationTime.Second;
+    NewLastWriteSystemTime.tm_isdst   = 0;
+
+    Utime.modtime = mktime (&NewLastWriteSystemTime);
+
+    if (Utime.actime == (time_t)-1 || Utime.modtime == (time_t)-1) {
+      goto Done;
+    }
+
+    if (utime (PrivateFile->FileName, &Utime) == -1) {
+      Status = ErrnoToEfiStatus ();
+      goto Done;
+    }
+  }
+
+  //
+  // No matter about AttrChangeFlag, Attribute must be set.
+  // Because operation before may cause attribute change.
+  //
+  NewAttr = OldAttr.st_mode;
+
+  if (NewFileInfo->Attribute & EFI_FILE_READ_ONLY) {
+    NewAttr &= ~(S_IRUSR | S_IRGRP | S_IROTH);
+  } else {
+    NewAttr |= S_IRUSR;
+  }
+
+  if (chmod (NewFileName, NewAttr) != 0) {
+    Status = ErrnoToEfiStatus ();
+  }
+
+Done:
+  if (OldFileInfo != NULL) {
+    free (OldFileInfo);
+  }
+
+  if (OldFileName != NULL) {
+    free (OldFileName);
+  }
+
+  if (NewFileName != NULL) {
+    free (NewFileName);
+  }
+
+  return Status;
+}
+
+
+/**
+  Flush data back for the file handle.
+
+  @param  This Protocol instance pointer.
+
+  @retval EFI_SUCCESS          Data was written.
+  @retval EFI_UNSUPPORTED      Writes to Open directory are not supported.
+  @retval EFI_NO_MEDIA         The device has no media.
+  @retval EFI_DEVICE_ERROR     The device reported an error.
+  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
+  @retval EFI_WRITE_PROTECTED  The device is write protected.
+  @retval EFI_ACCESS_DENIED    The file was open for read only.
+  @retval EFI_VOLUME_FULL      The volume is full.
+
+**/
+EFI_STATUS
+PosixFileFlush (
+  IN EFI_FILE_PROTOCOL  *This
+  )
+{
+  EMU_EFI_FILE_PRIVATE     *PrivateFile;
+
+  
+  PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+
+  if (PrivateFile->IsDirectoryPath) {
+    return EFI_UNSUPPORTED;
+  }
+
+  if (PrivateFile->IsOpenedByRead) {
+    return EFI_ACCESS_DENIED;
+  }
+
+  if (PrivateFile->fd < 0) {
+    return EFI_DEVICE_ERROR;
+  }
+
+  if (fsync (PrivateFile->fd) != 0) {
+    return ErrnoToEfiStatus ();
+  }
+
+  return EFI_SUCCESS;
+}
+
+
+
+EFI_STATUS
+PosixFileSystmeThunkOpen (
+  IN  EMU_IO_THUNK_PROTOCOL   *This
+  )
+{
+  EMU_SIMPLE_FILE_SYSTEM_PRIVATE  *Private;
+  UINTN                           i;
+  
+  if (This->Private != NULL) {
+    return EFI_ALREADY_STARTED;
+  }
+  
+  if (!CompareGuid (This->Protocol, &gEfiSimpleFileSystemProtocolGuid)) {
+    return EFI_UNSUPPORTED;
+  }
+  
+  Private = malloc (sizeof (EMU_SIMPLE_FILE_SYSTEM_PRIVATE));
+  if (Private == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  Private->FilePath = malloc (StrLen (This->ConfigString) + 1);
+  if (Private->FilePath == NULL) {
+    free (Private);
+    return EFI_OUT_OF_RESOURCES;    
+  }
+  
+  // Convert Unicode to Ascii
+  for (i = 0; This->ConfigString[i] != 0; i++) {
+    Private->FilePath[i] = This->ConfigString[i];
+  }
+  Private->FilePath[i] = 0;
+
+
+  Private->VolumeLabel = malloc (StrLen (L"EFI_EMULATED"));
+  if (Private->VolumeLabel == NULL) {
+    free (Private->FilePath);
+    free (Private);
+    return EFI_OUT_OF_RESOURCES;
+  }
+  StrCpy (Private->VolumeLabel, L"EFI_EMULATED");
+  
+  Private->Signature = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE;
+  Private->Thunk     = This;
+  CopyMem (&Private->SimpleFileSystem, &gPosixFileSystemProtocol, sizeof (Private->SimpleFileSystem));
+  Private->FileHandlesOpen = FALSE;
+  This->Interface = &Private->SimpleFileSystem;
+  This->Private   = Private;
+  return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+PosixFileSystmeThunkClose (
+  IN  EMU_IO_THUNK_PROTOCOL   *This
+  )
+{
+  EMU_SIMPLE_FILE_SYSTEM_PRIVATE  *Private;
+
+  if (!CompareGuid (This->Protocol, &gEfiSimpleFileSystemProtocolGuid)) {
+    return EFI_UNSUPPORTED;
+  }
+  
+  Private = This->Private;
+  
+  if (Private->FileHandlesOpen) {
+    //
+    // Close only supported if all the EFI_FILE_HANDLEs have been closed.
+    //
+    return EFI_NOT_READY;
+  }
+
+  if (This->Private != NULL) {
+    if (Private->VolumeLabel == NULL) {
+      free (Private->VolumeLabel);
+    }   
+    free (This->Private);
+  }
+  
+  return EFI_SUCCESS;
+}
+
+
+EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo = {
+  &gEfiSimpleFileSystemProtocolGuid,
+  NULL,
+  NULL,
+  0,
+  GasketPosixFileSystmeThunkOpen,
+  GasketPosixFileSystmeThunkClose,
+  NULL
+};
+
+
diff --git a/InOsEmuPkg/Unix/Sec/Pthreads.c b/InOsEmuPkg/Unix/Sec/Pthreads.c
new file mode 100644 (file)
index 0000000..273be5d
--- /dev/null
@@ -0,0 +1,233 @@
+/*++ @file
+ POSIX Pthreads to emulate APs and implement threads
+
+Copyright (c) 2011, Apple Inc. 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.
+
+
+**/
+
+#include "SecMain.h"
+#include <pthread.h>
+
+
+UINTN
+EFIAPI
+PthreadMutexLock (
+  IN VOID *Mutex
+  )
+{
+  return (UINTN)pthread_mutex_lock ((pthread_mutex_t *)Mutex);
+}
+
+
+
+UINTN
+EFIAPI
+PthreadMutexUnLock (
+  IN VOID *Mutex
+  )                        
+{
+  return (UINTN)pthread_mutex_unlock ((pthread_mutex_t *)Mutex);
+}
+
+UINTN
+EFIAPI
+PthreadMutexTryLock (
+  IN VOID *Mutex
+  )                      
+{
+  return (UINTN)pthread_mutex_trylock ((pthread_mutex_t *)Mutex);
+}
+
+
+VOID *
+PthreadMutexInit (
+  IN VOID
+  )
+{
+  pthread_mutex_t *Mutex;
+  int             err;
+  
+  Mutex = malloc (sizeof (pthread_mutex_t));
+  err = pthread_mutex_init (Mutex, NULL);
+  if (err == 0) {
+    return Mutex;
+  }
+  
+  return NULL;
+}
+
+
+UINTN
+PthreadMutexDestroy (
+  IN VOID *Mutex
+  )
+{
+  if (Mutex != NULL) {
+    return pthread_mutex_destroy ((pthread_mutex_t *)Mutex);
+  }
+  
+  return -1;
+}
+
+// Can't store this data on PthreadCreate stack so we need a global
+typedef struct {
+  pthread_mutex_t             Mutex;
+  PTREAD_THUNK_THEAD_ENTRY    Start;
+} THREAD_MANGLE;
+
+THREAD_MANGLE mThreadMangle = {
+  PTHREAD_MUTEX_INITIALIZER,
+  NULL
+};
+
+VOID *
+SecFakePthreadStart (
+  VOID  *Context
+  )
+{
+  PTREAD_THUNK_THEAD_ENTRY  Start;
+  sigset_t                  SigMask;
+  
+  // Save global on the stack before we unlock
+  Start   = mThreadMangle.Start;
+  pthread_mutex_unlock (&mThreadMangle.Mutex);
+  
+  // Mask all signals to the APs
+  sigfillset (&SigMask); 
+  pthread_sigmask (SIG_BLOCK, &SigMask, NULL);
+  
+  //
+  // We have to start the thread in SEC as we need to follow
+  // OS X calling conventions. We can then call back into 
+  // to the callers Start.
+  //
+  // This is a great example of how all problems in computer 
+  // science can be solved by adding another level of indirection
+  //
+ return  (VOID *)ReverseGasketUint64 ((CALL_BACK)Start, (UINTN)Context);
+}
+  
+UINTN
+PthreadCreate (
+  IN  VOID                      *Thread,
+  IN  VOID                      *Attribute,
+  IN  PTREAD_THUNK_THEAD_ENTRY  Start,
+  IN  VOID                      *Context
+  )
+{
+  int         err;
+  BOOLEAN     EnabledOnEntry;    
+  
+  //
+  // Threads inherit interrupt state so disable interrupts before we start thread
+  //
+  if (SecInterruptEanbled ()) {
+    SecDisableInterrupt ();
+    EnabledOnEntry = TRUE;
+  } else {
+    EnabledOnEntry = FALSE;
+  }
+  
+  // Aquire lock for global, SecFakePthreadStart runs in a different thread.
+  pthread_mutex_lock (&mThreadMangle.Mutex);
+  mThreadMangle.Start   = Start;
+  
+  err = pthread_create (Thread, Attribute, SecFakePthreadStart, Context);
+  if (err != 0) {
+    // Thread failed to launch so release the lock;
+    pthread_mutex_unlock (&mThreadMangle.Mutex);
+  }
+  
+  if (EnabledOnEntry) {
+    // Restore interrupt state
+    SecEnableInterrupt ();
+  }    
+
+  return err;
+}
+
+
+VOID
+PthreadExit (
+  IN VOID *ValuePtr
+  )
+{ 
+  pthread_exit (ValuePtr);
+  return;
+}
+
+   
+UINTN
+PthreadSelf (
+  VOID
+  )
+{
+  // POSIX currently allows pthread_t to be a structure or arithmetic type.
+  // Check out sys/types.h to make sure this will work if you are porting. 
+  // On OS X (Darwin) pthread_t is a pointer to a structure so this code works.
+  return (UINTN)pthread_self (); 
+}
+
+
+EMU_PTREAD_THUNK_PROTOCOL gPthreadThunk = {
+  GasketPthreadMutexLock,
+  GasketPthreadMutexUnLock,
+  GasketPthreadMutexTryLock,
+  GasketPthreadMutexInit,
+  GasketPthreadMutexDestroy,
+  GasketPthreadCreate,
+  GasketPthreadExit,
+  GasketPthreadSelf
+};
+
+
+EFI_STATUS
+PthreadOpen (
+  IN  EMU_IO_THUNK_PROTOCOL   *This
+  )
+{
+  if (This->Instance != 0) {
+    // Only single instance is supported
+    return EFI_NOT_FOUND;
+  }
+  
+  if (This->ConfigString[0] == L'0') {
+    // If AP count is zero no need for threads
+    return EFI_NOT_FOUND;
+  }
+  
+  This->Interface = &gPthreadThunk;
+  
+  return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+PthreadClose (
+  IN  EMU_IO_THUNK_PROTOCOL   *This
+  )
+{
+  return EFI_SUCCESS;
+}
+
+
+EMU_IO_THUNK_PROTOCOL gPthreadThunkIo = {
+  &gEmuPthreadThunkProtocolGuid,
+  NULL,
+  NULL,
+  0,
+  GasketPthreadOpen,
+  GasketPthreadClose,
+  NULL
+};
+
+
diff --git a/InOsEmuPkg/Unix/Sec/SecMain.c b/InOsEmuPkg/Unix/Sec/SecMain.c
new file mode 100644 (file)
index 0000000..8677ab5
--- /dev/null
@@ -0,0 +1,1148 @@
+/*++ @file
+
+Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
+Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
+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.
+
+**/
+
+#include "SecMain.h"
+
+#ifdef __APPLE__
+#define MAP_ANONYMOUS MAP_ANON
+char *gGdbWorkingFileName = NULL;
+#endif
+
+
+//
+// Globals
+//
+
+EMU_THUNK_PPI mSecEmuThunkPpi = {
+  GasketSecUnixPeiAutoScan,
+  GasketSecUnixFdAddress,
+  GasketSecEmuThunkAddress,
+  GasketSecUnixPeiLoadFile
+};
+
+EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = { 
+  GasketSecTemporaryRamSupport
+};
+
+
+
+//
+// Default information about where the FD is located.
+//  This array gets filled in with information from EFI_FIRMWARE_VOLUMES
+//  EFI_FIRMWARE_VOLUMES is a host environment variable set by system.cmd.
+//  The number of array elements is allocated base on parsing
+//  EFI_FIRMWARE_VOLUMES and the memory is never freed.
+//
+UINTN                                     gFdInfoCount = 0;
+EMU_FD_INFO                              *gFdInfo;
+
+//
+// Array that supports seperate memory rantes.
+//  The memory ranges are set in system.cmd via the EFI_MEMORY_SIZE variable.
+//  The number of array elements is allocated base on parsing
+//  EFI_MEMORY_SIZE and the memory is never freed.
+//
+UINTN                                     gSystemMemoryCount = 0;
+EMU_SYSTEM_MEMORY                       *gSystemMemory;
+
+
+
+UINTN                        mImageContextModHandleArraySize = 0;
+IMAGE_CONTEXT_TO_MOD_HANDLE  *mImageContextModHandleArray = NULL;
+
+
+
+EFI_PHYSICAL_ADDRESS *
+MapMemory (
+  INTN fd,
+  UINT64 length,
+  INTN   prot,
+  INTN   flags);
+
+EFI_STATUS
+MapFile (
+  IN  CHAR8                     *FileName,
+  IN OUT  EFI_PHYSICAL_ADDRESS  *BaseAddress,
+  OUT UINT64                    *Length
+  );
+
+EFI_STATUS
+EFIAPI
+SecNt32PeCoffRelocateImage (
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext
+  );
+
+
+int
+main (
+  IN  int   Argc,
+  IN  char  **Argv,
+  IN  char  **Envp
+  )
+/*++
+
+Routine Description:
+  Main entry point to SEC for Unix. This is a unix program
+
+Arguments:
+  Argc - Number of command line arguments
+  Argv - Array of command line argument strings
+  Envp - Array of environmemt variable strings
+
+Returns:
+  0 - Normal exit
+  1 - Abnormal exit
+
+**/
+{
+  EFI_STATUS            Status;
+  EFI_PHYSICAL_ADDRESS  InitialStackMemory;
+  UINT64                InitialStackMemorySize;
+  UINTN                 Index;
+  UINTN                 Index1;
+  UINTN                 Index2;
+  UINTN                 PeiIndex;
+  CHAR8                 *FileName;
+  BOOLEAN               Done;
+  VOID                  *PeiCoreFile;
+  CHAR16                *MemorySizeStr;
+  CHAR16                *FirmwareVolumesStr;
+  UINTN                 *StackPointer;
+
+  setbuf(stdout, 0);
+  setbuf(stderr, 0);
+
+  MemorySizeStr      = (CHAR16 *) PcdGetPtr (PcdEmuMemorySize);
+  FirmwareVolumesStr = (CHAR16 *) PcdGetPtr (PcdEmuFirmwareVolume);
+
+  printf ("\nEDK SEC Main UNIX Emulation Environment from edk2.sourceforge.net\n");
+
+  //
+  // PPIs pased into PEI_CORE
+  //
+  AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEfiTemporaryRamSupportPpiGuid, &mSecTemporaryRamSupportPpi);
+  AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEmuThunkPpiGuid, &mSecEmuThunkPpi);
+  AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEmuPeiServicesTableUpdatePpiGuid, NULL);
+
+  SecInitThunkProtocol ();
+  
+  //
+  // Emulator Bus Driver Thunks
+  //
+  AddThunkProtocol (&gX11ThunkIo, (CHAR16 *)PcdGetPtr (PcdEmuGop), TRUE); 
+  AddThunkProtocol (&gPosixFileSystemThunkIo, (CHAR16 *)PcdGetPtr (PcdEmuFileSystem), TRUE); 
+  
+  //
+  // Emulator other Thunks
+  //
+  AddThunkProtocol (&gPthreadThunkIo, (CHAR16 *)PcdGetPtr (PcdEmuApCount), FALSE); 
+
+  // EmuSecLibConstructor ();
+
+#ifdef __APPLE__
+  //
+  // We can't use dlopen on OS X, so we need a scheme to get symboles into gdb
+  // We need to create a temp file that contains gdb commands so we can load
+  // symbols when we load every PE/COFF image.
+  //
+  Index = strlen (*Argv);
+  gGdbWorkingFileName = malloc (Index + strlen(".gdb") + 1);
+  strcpy (gGdbWorkingFileName, *Argv);
+  strcat (gGdbWorkingFileName, ".gdb");
+#endif
+
+
+  //
+  // Allocate space for gSystemMemory Array
+  //
+  gSystemMemoryCount  = CountSeperatorsInString (MemorySizeStr, '!') + 1;
+  gSystemMemory       = calloc (gSystemMemoryCount, sizeof (EMU_SYSTEM_MEMORY));
+  if (gSystemMemory == NULL) {
+    printf ("ERROR : Can not allocate memory for system.  Exiting.\n");
+    exit (1);
+  }
+  //
+  // Allocate space for gSystemMemory Array
+  //
+  gFdInfoCount  = CountSeperatorsInString (FirmwareVolumesStr, '!') + 1;
+  gFdInfo       = calloc (gFdInfoCount, sizeof (EMU_FD_INFO));
+  if (gFdInfo == NULL) {
+    printf ("ERROR : Can not allocate memory for fd info.  Exiting.\n");
+    exit (1);
+  }
+
+  printf ("  BootMode 0x%02x\n", (unsigned int)PcdGet32 (PcdEmuBootMode));
+
+  //
+  // Open up a 128K file to emulate temp memory for PEI.
+  //  on a real platform this would be SRAM, or using the cache as RAM.
+  //  Set InitialStackMemory to zero so UnixOpenFile will allocate a new mapping
+  //
+  InitialStackMemorySize  = STACK_SIZE;
+  InitialStackMemory = (UINTN)MapMemory(0,
+          (UINT32) InitialStackMemorySize,
+          PROT_READ | PROT_WRITE | PROT_EXEC,
+          MAP_ANONYMOUS | MAP_PRIVATE);
+  if (InitialStackMemory == 0) {
+    printf ("ERROR : Can not open SecStack Exiting\n");
+    exit (1);
+  }
+
+  printf ("  SEC passing in %u KB of temp RAM at 0x%08lx to PEI\n",
+    (unsigned int)(InitialStackMemorySize / 1024),
+    (unsigned long)InitialStackMemory);
+
+  for (StackPointer = (UINTN*) (UINTN) InitialStackMemory;
+     StackPointer < (UINTN*)(UINTN)((UINTN) InitialStackMemory + (UINT64) InitialStackMemorySize);
+     StackPointer ++) {
+    *StackPointer = 0x5AA55AA5;
+  }
+
+  //
+  // Open All the firmware volumes and remember the info in the gFdInfo global
+  //
+  FileName = (CHAR8 *)malloc (StrLen (FirmwareVolumesStr) + 1);
+  if (FileName == NULL) {
+    printf ("ERROR : Can not allocate memory for firmware volume string\n");
+    exit (1);
+  }
+
+  Index2 = 0;
+  for (Done = FALSE, Index = 0, PeiIndex = 0, PeiCoreFile = NULL;
+       FirmwareVolumesStr[Index2] != 0;
+       Index++) {
+    for (Index1 = 0; (FirmwareVolumesStr[Index2] != '!') && (FirmwareVolumesStr[Index2] != 0); Index2++)
+      FileName[Index1++] = FirmwareVolumesStr[Index2];
+    if (FirmwareVolumesStr[Index2] == '!')
+      Index2++;
+    FileName[Index1]  = '\0';
+
+    //
+    // Open the FD and remmeber where it got mapped into our processes address space
+    //
+    Status = MapFile (
+          FileName,
+          &gFdInfo[Index].Address,
+          &gFdInfo[Index].Size
+          );
+    if (EFI_ERROR (Status)) {
+      printf ("ERROR : Can not open Firmware Device File %s (%x).  Exiting.\n", FileName, (unsigned int)Status);
+      exit (1);
+    }
+
+    printf ("  FD loaded from %s at 0x%08lx",
+      FileName, (unsigned long)gFdInfo[Index].Address);
+
+    if (PeiCoreFile == NULL) {
+      //
+      // Assume the beginning of the FD is an FV and look for the PEI Core.
+      // Load the first one we find.
+      //
+      Status = SecFfsFindPeiCore ((EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) gFdInfo[Index].Address, &PeiCoreFile);
+      if (!EFI_ERROR (Status)) {
+        PeiIndex = Index;
+        printf (" contains SEC Core");
+      }
+    }
+
+    printf ("\n");
+  }
+  //
+  // Calculate memory regions and store the information in the gSystemMemory
+  //  global for later use. The autosizing code will use this data to
+  //  map this memory into the SEC process memory space.
+  //
+  Index1 = 0;
+  Index = 0;
+  while (1) {
+    UINTN val = 0;
+    //
+    // Save the size of the memory.
+    //
+    while (MemorySizeStr[Index1] >= '0' && MemorySizeStr[Index1] <= '9') {
+      val = val * 10 + MemorySizeStr[Index1] - '0';
+      Index1++;
+    }
+    gSystemMemory[Index++].Size = val * 0x100000;
+    if (MemorySizeStr[Index1] == 0)
+      break;
+    Index1++;
+  }
+
+  printf ("\n");
+
+  //
+  // Hand off to PEI Core
+  //
+  SecLoadFromCore ((UINTN) InitialStackMemory, (UINTN) InitialStackMemorySize, (UINTN) gFdInfo[0].Address, PeiCoreFile);
+
+  //
+  // If we get here, then the PEI Core returned. This is an error as PEI should
+  //  always hand off to DXE.
+  //
+  printf ("ERROR : PEI Core returned\n");
+  exit (1);
+}
+
+EFI_PHYSICAL_ADDRESS *
+MapMemory (
+  INTN fd,
+  UINT64 length,
+  INTN   prot,
+  INTN   flags)
+{
+  STATIC UINTN base  = 0x40000000;
+  CONST UINTN  align = (1 << 24);
+  VOID         *res  = NULL;
+  BOOLEAN      isAligned = 0;
+
+  //
+  // Try to get an aligned block somewhere in the address space of this
+  // process.
+  //
+  while((!isAligned) && (base != 0)) {
+    res = mmap ((void *)base, length, prot, flags, fd, 0);
+    if (res == MAP_FAILED) {
+      return NULL;
+    }
+    if ((((UINTN)res) & ~(align-1)) == (UINTN)res) {
+      isAligned=1;
+    }
+    else {
+      munmap(res, length);
+      base += align;
+    }
+  }
+  return res;
+}
+
+EFI_STATUS
+MapFile (
+  IN  CHAR8                     *FileName,
+  IN OUT  EFI_PHYSICAL_ADDRESS  *BaseAddress,
+  OUT UINT64                    *Length
+  )
+/*++
+
+Routine Description:
+  Opens and memory maps a file using Unix services. If BaseAddress is non zero
+  the process will try and allocate the memory starting at BaseAddress.
+
+Arguments:
+  FileName            - The name of the file to open and map
+  MapSize             - The amount of the file to map in bytes
+  CreationDisposition - The flags to pass to CreateFile().  Use to create new files for
+                        memory emulation, and exiting files for firmware volume emulation
+  BaseAddress         - The base address of the mapped file in the user address space.
+                         If passed in as NULL the a new memory region is used.
+                         If passed in as non NULL the request memory region is used for
+                          the mapping of the file into the process space.
+  Length              - The size of the mapped region in bytes
+
+Returns:
+  EFI_SUCCESS      - The file was opened and mapped.
+  EFI_NOT_FOUND    - FileName was not found in the current directory
+  EFI_DEVICE_ERROR - An error occured attempting to map the opened file
+
+**/
+{
+  int fd;
+  VOID    *res;
+  UINTN   FileSize;
+
+  fd = open (FileName, O_RDONLY);
+  if (fd < 0)
+    return EFI_NOT_FOUND;
+  FileSize = lseek (fd, 0, SEEK_END);
+
+
+  res = MapMemory(fd, FileSize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
+
+  close (fd);
+
+  if (res == MAP_FAILED)
+    return EFI_DEVICE_ERROR;
+
+  *Length = (UINT64) FileSize;
+  *BaseAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) res;
+
+  return EFI_SUCCESS;
+}
+
+
+
+VOID
+SecLoadFromCore (
+  IN  UINTN   LargestRegion,
+  IN  UINTN   LargestRegionSize,
+  IN  UINTN   BootFirmwareVolumeBase,
+  IN  VOID    *PeiCorePe32File
+  )
+/*++
+
+Routine Description:
+  This is the service to load the PEI Core from the Firmware Volume
+
+Arguments:
+  LargestRegion           - Memory to use for PEI.
+  LargestRegionSize       - Size of Memory to use for PEI
+  BootFirmwareVolumeBase  - Start of the Boot FV
+  PeiCorePe32File         - PEI Core PE32
+
+Returns:
+  Success means control is transfered and thus we should never return
+
+**/
+{
+  EFI_STATUS                  Status;
+  EFI_PHYSICAL_ADDRESS        TopOfMemory;
+  VOID                        *TopOfStack;
+  UINT64                      PeiCoreSize;
+  EFI_PHYSICAL_ADDRESS        PeiCoreEntryPoint;
+  EFI_PHYSICAL_ADDRESS        PeiImageAddress;
+  EFI_SEC_PEI_HAND_OFF        *SecCoreData;
+  UINTN                       PeiStackSize;
+
+  //
+  // Compute Top Of Memory for Stack and PEI Core Allocations
+  //
+  TopOfMemory  = LargestRegion + LargestRegionSize;
+  PeiStackSize = (UINTN)RShiftU64((UINT64)STACK_SIZE,1);
+
+  //
+  // |-----------| <---- TemporaryRamBase + TemporaryRamSize
+  // |   Heap    |
+  // |           |
+  // |-----------| <---- StackBase / PeiTemporaryMemoryBase
+  // |           |
+  // |  Stack    |
+  // |-----------| <---- TemporaryRamBase
+  //
+  TopOfStack  = (VOID *)(LargestRegion + PeiStackSize);
+  TopOfMemory = LargestRegion + PeiStackSize;
+
+  //
+  // Reservet space for storing PeiCore's parament in stack.
+  //
+  TopOfStack  = (VOID *)((UINTN)TopOfStack - sizeof (EFI_SEC_PEI_HAND_OFF) - CPU_STACK_ALIGNMENT);
+  TopOfStack  = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
+
+
+  //
+  // Bind this information into the SEC hand-off state
+  //
+  SecCoreData                        = (EFI_SEC_PEI_HAND_OFF*)(UINTN) TopOfStack;
+  SecCoreData->DataSize               = sizeof(EFI_SEC_PEI_HAND_OFF);
+  SecCoreData->BootFirmwareVolumeBase = (VOID*)BootFirmwareVolumeBase;
+  SecCoreData->BootFirmwareVolumeSize = PcdGet32 (PcdEmuFirmwareFdSize);
+  SecCoreData->TemporaryRamBase       = (VOID*)(UINTN)LargestRegion;
+  SecCoreData->TemporaryRamSize       = STACK_SIZE;
+  SecCoreData->StackBase              = SecCoreData->TemporaryRamBase;
+  SecCoreData->StackSize              = PeiStackSize;
+  SecCoreData->PeiTemporaryRamBase    = (VOID*) ((UINTN) SecCoreData->TemporaryRamBase + PeiStackSize);
+  SecCoreData->PeiTemporaryRamSize    = STACK_SIZE - PeiStackSize;
+
+  //
+  // Load the PEI Core from a Firmware Volume
+  //
+  Status = SecUnixPeiLoadFile (
+            PeiCorePe32File,
+            &PeiImageAddress,
+            &PeiCoreSize,
+            &PeiCoreEntryPoint
+            );
+  if (EFI_ERROR (Status)) {
+    return ;
+  }
+
+  //
+  // Transfer control to the PEI Core
+  //
+  PeiSwitchStacks (
+    (SWITCH_STACK_ENTRY_POINT) (UINTN) PeiCoreEntryPoint,
+    SecCoreData,
+    (VOID *)GetThunkPpiList (),
+    NULL,
+    TopOfStack
+    );
+  //
+  // If we get here, then the PEI Core returned.  This is an error
+  //
+  return ;
+}
+
+EFI_STATUS
+EFIAPI
+SecUnixPeiAutoScan (
+  IN  UINTN                 Index,
+  OUT EFI_PHYSICAL_ADDRESS  *MemoryBase,
+  OUT UINT64                *MemorySize
+  )
+/*++
+
+Routine Description:
+  This service is called from Index == 0 until it returns EFI_UNSUPPORTED.
+  It allows discontiguous memory regions to be supported by the emulator.
+  It uses gSystemMemory[] and gSystemMemoryCount that were created by
+  parsing the host environment variable EFI_MEMORY_SIZE.
+  The size comes from the varaible and the address comes from the call to
+  UnixOpenFile.
+
+Arguments:
+  Index      - Which memory region to use
+  MemoryBase - Return Base address of memory region
+  MemorySize - Return size in bytes of the memory region
+
+Returns:
+  EFI_SUCCESS - If memory region was mapped
+  EFI_UNSUPPORTED - If Index is not supported
+
+**/
+{
+  void *res;
+
+  if (Index >= gSystemMemoryCount) {
+    return EFI_UNSUPPORTED;
+  }
+
+  *MemoryBase = 0;
+  res = MapMemory(0, gSystemMemory[Index].Size,
+      PROT_READ | PROT_WRITE | PROT_EXEC,
+      MAP_PRIVATE | MAP_ANONYMOUS);
+  if (res == MAP_FAILED)
+    return EFI_DEVICE_ERROR;
+  *MemorySize = gSystemMemory[Index].Size;
+  *MemoryBase = (UINTN)res;
+  gSystemMemory[Index].Memory = *MemoryBase;
+
+  return EFI_SUCCESS;
+}
+
+VOID *
+EFIAPI
+SecEmuThunkAddress (
+  VOID
+  )
+/*++
+
+Routine Description:
+  Since the SEC is the only Unix program in stack it must export
+  an interface to do POSIX calls.  gUnix is initailized in UnixThunk.c.
+
+Arguments:
+  InterfaceSize - sizeof (EFI_WIN_NT_THUNK_PROTOCOL);
+  InterfaceBase - Address of the gUnix global
+
+Returns:
+  EFI_SUCCESS - Data returned
+
+**/
+{
+  return &gEmuThunkProtocol;
+}
+
+
+EFI_STATUS
+SecUnixPeiLoadFile (
+  IN  VOID                    *Pe32Data,
+  OUT EFI_PHYSICAL_ADDRESS    *ImageAddress,
+  OUT UINT64                  *ImageSize,
+  OUT EFI_PHYSICAL_ADDRESS    *EntryPoint
+  )
+/*++
+
+Routine Description:
+  Loads and relocates a PE/COFF image into memory.
+
+Arguments:
+  Pe32Data         - The base address of the PE/COFF file that is to be loaded and relocated
+  ImageAddress     - The base address of the relocated PE/COFF image
+  ImageSize        - The size of the relocated PE/COFF image
+  EntryPoint       - The entry point of the relocated PE/COFF image
+
+Returns:
+  EFI_SUCCESS   - The file was loaded and relocated
+  EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file
+
+**/
+{
+  EFI_STATUS                            Status;
+  PE_COFF_LOADER_IMAGE_CONTEXT          ImageContext;
+
+  ZeroMem (&ImageContext, sizeof (ImageContext));
+  ImageContext.Handle     = Pe32Data;
+
+  ImageContext.ImageRead  = (PE_COFF_LOADER_READ_FILE) SecImageRead;
+
+  Status                  = PeCoffLoaderGetImageInfo (&ImageContext);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+
+  //
+  // Allocate space in UNIX (not emulator) memory. Extra space is for alignment
+  //
+  ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) MapMemory (
+    0,
+    (UINT32) (ImageContext.ImageSize + (ImageContext.SectionAlignment * 2)),
+    PROT_READ | PROT_WRITE | PROT_EXEC,
+    MAP_ANONYMOUS | MAP_PRIVATE
+    );
+  if (ImageContext.ImageAddress == 0) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  //
+  // Align buffer on section boundry
+  //
+  ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;
+  ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)(ImageContext.SectionAlignment - 1));
+
+
+  Status = PeCoffLoaderLoadImage (&ImageContext);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Status = PeCoffLoaderRelocateImage (&ImageContext);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+
+  SecPeCoffRelocateImageExtraAction (&ImageContext);
+
+  //
+  // BugBug: Flush Instruction Cache Here when CPU Lib is ready
+  //
+
+  *ImageAddress = ImageContext.ImageAddress;
+  *ImageSize    = ImageContext.ImageSize;
+  *EntryPoint   = ImageContext.EntryPoint;
+
+  return EFI_SUCCESS;
+}
+
+
+RETURN_STATUS
+EFIAPI
+SecPeCoffGetEntryPoint (
+  IN     VOID  *Pe32Data,
+  IN OUT VOID  **EntryPoint
+  )
+{
+  EFI_STATUS              Status;
+  EFI_PHYSICAL_ADDRESS    ImageAddress;
+  UINT64                  ImageSize;
+  EFI_PHYSICAL_ADDRESS    PhysEntryPoint;
+
+  Status = SecUnixPeiLoadFile (Pe32Data, &ImageAddress, &ImageSize, &PhysEntryPoint);
+
+  *EntryPoint = (VOID *)(UINTN)PhysEntryPoint;
+  return Status;
+}
+
+
+
+EFI_STATUS
+EFIAPI
+SecUnixFdAddress (
+  IN     UINTN                 Index,
+  IN OUT EFI_PHYSICAL_ADDRESS  *FdBase,
+  IN OUT UINT64                *FdSize,
+  IN OUT EFI_PHYSICAL_ADDRESS  *FixUp
+  )
+/*++
+
+Routine Description:
+  Return the FD Size and base address. Since the FD is loaded from a
+  file into host memory only the SEC will know it's address.
+
+Arguments:
+  Index  - Which FD, starts at zero.
+  FdSize - Size of the FD in bytes
+  FdBase - Start address of the FD. Assume it points to an FV Header
+  FixUp  - Difference between actual FD address and build address
+
+Returns:
+  EFI_SUCCESS     - Return the Base address and size of the FV
+  EFI_UNSUPPORTED - Index does nto map to an FD in the system
+
+**/
+{
+  if (Index >= gFdInfoCount) {
+    return EFI_UNSUPPORTED;
+  }
+
+  *FdBase = gFdInfo[Index].Address;
+  *FdSize = gFdInfo[Index].Size;
+  *FixUp  = 0;
+
+  if (*FdBase == 0 && *FdSize == 0) {
+    return EFI_UNSUPPORTED;
+  }
+
+  if (Index == 0) {
+    //
+    // FD 0 has XIP code and well known PCD values
+    // If the memory buffer could not be allocated at the FD build address
+    // the Fixup is the difference.
+    //
+    *FixUp = *FdBase - PcdGet64 (PcdEmuFdBaseAddress);
+  }
+
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+SecImageRead (
+  IN     VOID    *FileHandle,
+  IN     UINTN   FileOffset,
+  IN OUT UINTN   *ReadSize,
+  OUT    VOID    *Buffer
+  )
+/*++
+
+Routine Description:
+  Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file
+
+Arguments:
+  FileHandle - The handle to the PE/COFF file
+  FileOffset - The offset, in bytes, into the file to read
+  ReadSize   - The number of bytes to read from the file starting at FileOffset
+  Buffer     - A pointer to the buffer to read the data into.
+
+Returns:
+  EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset
+
+**/
+{
+  CHAR8 *Destination8;
+  CHAR8 *Source8;
+  UINTN Length;
+
+  Destination8  = Buffer;
+  Source8       = (CHAR8 *) ((UINTN) FileHandle + FileOffset);
+  Length        = *ReadSize;
+  while (Length--) {
+    *(Destination8++) = *(Source8++);
+  }
+
+  return EFI_SUCCESS;
+}
+
+UINTN
+CountSeperatorsInString (
+  IN  const CHAR16   *String,
+  IN  CHAR16         Seperator
+  )
+/*++
+
+Routine Description:
+  Count the number of seperators in String
+
+Arguments:
+  String    - String to process
+  Seperator - Item to count
+
+Returns:
+  Number of Seperator in String
+
+**/
+{
+  UINTN Count;
+
+  for (Count = 0; *String != '\0'; String++) {
+    if (*String == Seperator) {
+      Count++;
+    }
+  }
+
+  return Count;
+}
+
+
+EFI_STATUS
+AddHandle (
+  IN  PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext,
+  IN  VOID                                 *ModHandle
+  )
+/*++
+
+Routine Description:
+  Store the ModHandle in an array indexed by the Pdb File name.
+  The ModHandle is needed to unload the image.
+
+Arguments:
+  ImageContext - Input data returned from PE Laoder Library. Used to find the
+                 .PDB file name of the PE Image.
+  ModHandle    - Returned from LoadLibraryEx() and stored for call to
+                 FreeLibrary().
+
+Returns:
+  EFI_SUCCESS - ModHandle was stored.
+
+**/
+{
+  UINTN                       Index;
+  IMAGE_CONTEXT_TO_MOD_HANDLE *Array;
+  UINTN                       PreviousSize;
+
+
+  Array = mImageContextModHandleArray;
+  for (Index = 0; Index < mImageContextModHandleArraySize; Index++, Array++) {
+    if (Array->ImageContext == NULL) {
+      //
+      // Make a copy of the stirng and store the ModHandle
+      //
+      Array->ImageContext = ImageContext;
+      Array->ModHandle    = ModHandle;
+      return EFI_SUCCESS;
+    }
+  }
+
+  //
+  // No free space in mImageContextModHandleArray so grow it by
+  // IMAGE_CONTEXT_TO_MOD_HANDLE entires. realloc will
+  // copy the old values to the new locaiton. But it does
+  // not zero the new memory area.
+  //
+  PreviousSize = mImageContextModHandleArraySize * sizeof (IMAGE_CONTEXT_TO_MOD_HANDLE);
+  mImageContextModHandleArraySize += MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE;
+
+  mImageContextModHandleArray = realloc (mImageContextModHandleArray, mImageContextModHandleArraySize * sizeof (IMAGE_CONTEXT_TO_MOD_HANDLE));
+  if (mImageContextModHandleArray == NULL) {
+    ASSERT (FALSE);
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  memset (mImageContextModHandleArray + PreviousSize, 0, MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE * sizeof (IMAGE_CONTEXT_TO_MOD_HANDLE));
+
+  return AddHandle (ImageContext, ModHandle);
+}
+
+
+VOID *
+RemoveHandle (
+  IN  PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext
+  )
+/*++
+
+Routine Description:
+  Return the ModHandle and delete the entry in the array.
+
+Arguments:
+  ImageContext - Input data returned from PE Laoder Library. Used to find the
+                 .PDB file name of the PE Image.
+
+Returns:
+  ModHandle - ModHandle assoicated with ImageContext is returned
+  NULL      - No ModHandle associated with ImageContext
+
+**/
+{
+  UINTN                        Index;
+  IMAGE_CONTEXT_TO_MOD_HANDLE  *Array;
+
+  if (ImageContext->PdbPointer == NULL) {
+    //
+    // If no PDB pointer there is no ModHandle so return NULL
+    //
+    return NULL;
+  }
+
+  Array = mImageContextModHandleArray;
+  for (Index = 0; Index < mImageContextModHandleArraySize; Index++, Array++) {
+    if (Array->ImageContext == ImageContext) {
+      //
+      // If you find a match return it and delete the entry
+      //
+      Array->ImageContext = NULL;
+      return Array->ModHandle;
+    }
+  }
+
+  return NULL;
+}
+
+
+
+//
+// Target for gdb breakpoint in a script that uses gGdbWorkingFileName to source a
+// add-symbol-file command. Hey what can you say scripting in gdb is not that great....
+//
+// Put .gdbinit in the CWD where you do gdb SecMain.dll for source level debug
+//
+// cat .gdbinit
+// b SecGdbScriptBreak
+// command
+// silent
+// source SecMain.dll.gdb
+// c
+// end
+//
+VOID
+SecGdbScriptBreak (
+  VOID
+  )
+{
+}
+
+VOID
+SecUnixLoaderBreak (
+  VOID
+  )
+{
+}
+
+BOOLEAN
+IsPdbFile (
+  IN  CHAR8   *PdbFileName
+  )
+{
+  UINTN Len;
+
+  if (PdbFileName == NULL) {
+    return FALSE;
+  }
+
+  Len = strlen (PdbFileName);
+  if ((Len < 5)|| (PdbFileName[Len - 4] != '.')) {
+    return FALSE;
+  }
+
+  if ((PdbFileName[Len - 3] == 'P' || PdbFileName[Len - 3] == 'p') &&
+      (PdbFileName[Len - 2] == 'D' || PdbFileName[Len - 2] == 'd') &&
+      (PdbFileName[Len - 1] == 'B' || PdbFileName[Len - 1] == 'b')) {
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+
+#define MAX_SPRINT_BUFFER_SIZE 0x200
+
+void
+PrintLoadAddress (
+  IN PE_COFF_LOADER_IMAGE_CONTEXT          *ImageContext
+  )
+{
+  if (ImageContext->PdbPointer == NULL) {
+    fprintf (stderr,
+      "0x%08lx Loading NO DEBUG with entry point 0x%08lx\n",
+      (unsigned long)(ImageContext->ImageAddress),
+      (unsigned long)ImageContext->EntryPoint
+      );
+  } else {
+    fprintf (stderr,
+      "0x%08lx Loading %s with entry point 0x%08lx\n",
+      (unsigned long)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders),
+      ImageContext->PdbPointer,
+      (unsigned long)ImageContext->EntryPoint
+      );
+  }
+  // Keep output synced up
+  fflush (stderr);
+}
+
+
+VOID
+EFIAPI
+SecPeCoffRelocateImageExtraAction (
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext
+  )
+{
+
+#ifdef __APPLE__
+  BOOLEAN EnabledOnEntry;
+
+   //
+   // Make sure writting of the file is an atomic operation
+   //
+   if (SecInterruptEanbled ()) {
+     SecDisableInterrupt ();
+     EnabledOnEntry = TRUE;
+   } else {
+     EnabledOnEntry = FALSE;
+   }
+
+  PrintLoadAddress (ImageContext);
+
+  //
+  // In mach-o (OS X executable) dlopen() can only load files in the MH_DYLIB of MH_BUNDLE format.
+  // To convert to PE/COFF we need to construct a mach-o with the MH_PRELOAD format. We create
+  // .dSYM files for the PE/COFF images that can be used by gdb for source level debugging.
+  //
+  FILE  *GdbTempFile;
+
+  //
+  // In the Mach-O to PE/COFF conversion the size of the PE/COFF headers is not accounted for.
+  // Thus we need to skip over the PE/COFF header when giving load addresses for our symbol table.
+  //
+  if (ImageContext->PdbPointer != NULL && !IsPdbFile (ImageContext->PdbPointer)) {
+    //
+    // Now we have a database of the images that are currently loaded
+    //
+
+    //
+    // 'symbol-file' will clear out currnet symbol mappings in gdb.
+    // you can do a 'add-symbol-file filename address' for every image we loaded to get source
+    // level debug in gdb. Note Sec, being a true application will work differently.
+    //
+    // We add the PE/COFF header size into the image as the mach-O does not have a header in
+    // loaded into system memory.
+    //
+    // This gives us a data base of gdb commands and after something is unloaded that entry will be
+    // removed. We don't yet have the scheme of how to comunicate with gdb, but we have the
+    // data base of info ready to roll.
+    //
+    // We could use qXfer:libraries:read, but OS X GDB does not currently support it.
+    //  <library-list>
+    //    <library name="/lib/libc.so.6">   // ImageContext->PdbPointer
+    //      <segment address="0x10000000"/> // ImageContext->ImageAddress + ImageContext->SizeOfHeaders
+    //    </library>
+    //  </library-list>
+    //
+
+    //
+    // Write the file we need for the gdb script
+    //
+    GdbTempFile = fopen (gGdbWorkingFileName, "w");
+    if (GdbTempFile != NULL) {
+      fprintf (GdbTempFile, "add-symbol-file %s 0x%08lx\n", ImageContext->PdbPointer, (long unsigned int)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders));
+      fclose (GdbTempFile);
+
+      //
+      // Target for gdb breakpoint in a script that uses gGdbWorkingFileName to set a breakpoint.
+      // Hey what can you say scripting in gdb is not that great....
+      //
+      SecGdbScriptBreak ();
+    } else {
+      ASSERT (FALSE);
+    }
+
+    AddHandle (ImageContext, ImageContext->PdbPointer);
+
+    if (EnabledOnEntry) {
+      SecEnableInterrupt ();
+    }
+
+    
+  }
+
+#else
+
+  void        *Handle = NULL;
+  void        *Entry = NULL;
+
+  if (ImageContext->PdbPointer == NULL) {
+    return;
+  }
+
+  if (!IsPdbFile (ImageContext->PdbPointer)) {
+    return;
+  }
+
+  fprintf (stderr,
+     "Loading %s 0x%08lx - entry point 0x%08lx\n",
+     ImageContext->PdbPointer,
+     (unsigned long)ImageContext->ImageAddress,
+     (unsigned long)ImageContext->EntryPoint);
+
+  Handle = dlopen (ImageContext->PdbPointer, RTLD_NOW);
+
+  if (Handle) {
+    Entry = dlsym (Handle, "_ModuleEntryPoint");
+  } else {
+    printf("%s\n", dlerror());
+  }
+
+  if (Entry != NULL) {
+    ImageContext->EntryPoint = (UINTN)Entry;
+    printf("Change %s Entrypoint to :0x%08lx\n", ImageContext->PdbPointer, (unsigned long)Entry);
+  }
+
+  SecUnixLoaderBreak ();
+
+#endif
+
+  return;
+}
+
+
+VOID
+EFIAPI
+SecPeCoffUnloadImageExtraAction (
+  IN PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext
+  )
+{
+  VOID *Handle;
+
+  Handle = RemoveHandle (ImageContext);
+
+#ifdef __APPLE__
+  FILE  *GdbTempFile;
+  BOOLEAN EnabledOnEntry;
+
+  if (Handle != NULL) {
+    //
+    // Need to skip .PDB files created from VC++
+    //
+    if (!IsPdbFile (ImageContext->PdbPointer)) {
+       if (SecInterruptEanbled ()) {
+         SecDisableInterrupt ();
+         EnabledOnEntry = TRUE;
+       } else {
+         EnabledOnEntry = FALSE;
+       }
+       
+      //
+      // Write the file we need for the gdb script
+      //
+      GdbTempFile = fopen (gGdbWorkingFileName, "w");
+      if (GdbTempFile != NULL) {
+        fprintf (GdbTempFile, "remove-symbol-file %s\n", ImageContext->PdbPointer);
+        fclose (GdbTempFile);
+
+        //
+        // Target for gdb breakpoint in a script that uses gGdbWorkingFileName to set a breakpoint.
+        // Hey what can you say scripting in gdb is not that great....
+        //
+        SecGdbScriptBreak ();
+      } else {
+        ASSERT (FALSE);
+      }
+      
+      if (EnabledOnEntry) {
+        SecEnableInterrupt ();
+      }
+    }
+  }
+
+#else
+  //
+  // Don't want to confuse gdb with symbols for something that got unloaded
+  //
+  if (Handle != NULL) {
+    dlclose (Handle);
+  }
+
+#endif
+  return;
+}
+
+
diff --git a/InOsEmuPkg/Unix/Sec/SecMain.h b/InOsEmuPkg/Unix/Sec/SecMain.h
new file mode 100644 (file)
index 0000000..6e352b1
--- /dev/null
@@ -0,0 +1,306 @@
+/*++ @file\r
+\r
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>\r
+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
+#ifndef _SEC_MAIN_H__\r
+#define _SEC_MAIN_H__\r
+\r
+#include <PiPei.h>\r
+#include <Uefi.h>\r
+\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
+\r
+#include <Library/ThunkPpiList.h>\r
+#include <Library/ThunkProtocolList.h>\r
+\r
+#include <Ppi/EmuThunk.h>\r
+#include <Ppi/StatusCode.h>\r
+#include <Ppi/TemporaryRamSupport.h>\r
+#include <Ppi/EmuPeiServicesTableUpdate.h>\r
+\r
+#include <Protocol/SimplePointer.h>\r
+#include <Protocol/SimpleTextIn.h>\r
+#include <Protocol/SimpleTextInEx.h>\r
+#include <Protocol/UgaDraw.h>\r
+#include <Protocol/SimpleFileSystem.h>\r
+\r
+#include <Protocol/EmuThunk.h>\r
+#include <Protocol/EmuIoThunk.h>\r
+#include <Protocol/EmuGraphicsWindow.h>\r
+#include <Protocol/EmuPthreadThunk.h>\r
+\r
+#include <Guid/FileInfo.h>\r
+#include <Guid/FileSystemInfo.h>\r
+#include <Guid/FileSystemVolumeLabelInfo.h>\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+\r
+#include <sys/types.h>\r
+#include <sys/stat.h>\r
+#include <sys/termios.h>\r
+#include <sys/time.h>\r
+\r
+#if __CYGWIN__\r
+#include <sys/dirent.h>\r
+#else\r
+#include <sys/dir.h>\r
+#endif\r
+\r
+#include <sys/mman.h>\r
+#include <dlfcn.h>\r
+\r
+#include <unistd.h>\r
+#include <poll.h>\r
+#include <fcntl.h>\r
+#include <time.h>\r
+#include <signal.h>\r
+#include <errno.h>\r
+#include <string.h>\r
+#include <stdlib.h>\r
+#include <sys/ioctl.h>\r
+\r
+#include <sys/socket.h>\r
+#include <netdb.h>\r
+#include <netinet/in.h>\r
+#include <net/if.h>\r
+#include <ifaddrs.h>\r
+\r
+#ifdef __APPLE__\r
+#include <net/if_dl.h>\r
+#include <net/bpf.h>\r
+#include <sys/param.h>\r
+#include <sys/mount.h>\r
+#define _XOPEN_SOURCE\r
+#ifndef _Bool\r
+  #define _Bool char // for clang debug\r
+#endif\r
+#else\r
+#include <termio.h>\r
+#include <sys/vfs.h>\r
+#endif \r
+\r
+#include <utime.h>\r
+\r
+#include "Gasket.h"\r
+\r
+\r
+#define STACK_SIZE                0x20000      \r
+\r
+typedef struct {\r
+  EFI_PHYSICAL_ADDRESS  Address;\r
+  UINT64                Size;\r
+} EMU_FD_INFO;\r
+\r
+typedef struct {\r
+  EFI_PHYSICAL_ADDRESS  Memory;\r
+  UINT64                Size;\r
+} EMU_SYSTEM_MEMORY;\r
+\r
+\r
+#define MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE 0x100\r
+\r
+typedef struct {\r
+  PE_COFF_LOADER_IMAGE_CONTEXT   *ImageContext;\r
+  VOID                           *ModHandle;\r
+} IMAGE_CONTEXT_TO_MOD_HANDLE;\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecUnixPeiLoadFile (\r
+  VOID                  *Pe32Data,  \r
+  EFI_PHYSICAL_ADDRESS  *ImageAddress,  \r
+  UINT64                *ImageSize,  \r
+  EFI_PHYSICAL_ADDRESS  *EntryPoint  \r
+  );\r
+\r
+int\r
+main (\r
+  IN  int   Argc,\r
+  IN  char  **Argv,\r
+  IN  char  **Envp\r
+  );\r
+\r
+VOID\r
+SecLoadFromCore (\r
+  IN  UINTN   LargestRegion,\r
+  IN  UINTN   LargestRegionSize,\r
+  IN  UINTN   BootFirmwareVolumeBase,\r
+  IN  VOID    *PeiCoreFile\r
+  );\r
+\r
+EFI_STATUS\r
+SecLoadFile (\r
+  IN  VOID                    *Pe32Data,\r
+  IN  EFI_PHYSICAL_ADDRESS    *ImageAddress,\r
+  IN  UINT64                  *ImageSize,\r
+  IN  EFI_PHYSICAL_ADDRESS    *EntryPoint\r
+  );\r
+\r
+EFI_STATUS\r
+SecFfsFindPeiCore (\r
+  IN  EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader,\r
+  OUT VOID                        **Pe32Data\r
+  );\r
+\r
+EFI_STATUS\r
+SecFfsFindNextFile (\r
+  IN EFI_FV_FILETYPE             SearchType,\r
+  IN EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader,\r
+  IN OUT EFI_FFS_FILE_HEADER     **FileHeader\r
+  );\r
+\r
+EFI_STATUS\r
+SecFfsFindSectionData (\r
+  IN EFI_SECTION_TYPE      SectionType,\r
+  IN EFI_FFS_FILE_HEADER   *FfsFileHeader,\r
+  IN OUT VOID              **SectionData\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecUnixPeCoffLoaderLoadAsDll (\r
+  IN CHAR8    *PdbFileName,\r
+  IN VOID     **ImageEntryPoint,\r
+  OUT VOID    **ModHandle\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecUnixPeCoffLoaderFreeLibrary (\r
+  OUT VOID    *ModHandle\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecUnixFdAddress (\r
+  IN     UINTN                 Index,\r
+  IN OUT EFI_PHYSICAL_ADDRESS  *FdBase,\r
+  IN OUT UINT64                *FdSize,\r
+  IN OUT EFI_PHYSICAL_ADDRESS  *FixUp\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSecUnixFdAddress (\r
+  IN     UINTN                 Index,\r
+  IN OUT EFI_PHYSICAL_ADDRESS  *FdBase,\r
+  IN OUT UINT64                *FdSize,\r
+  IN OUT EFI_PHYSICAL_ADDRESS  *FixUp\r
+  )\r
+;\r
+\r
+\r
+EFI_STATUS\r
+GetImageReadFunction (\r
+  IN PE_COFF_LOADER_IMAGE_CONTEXT          *ImageContext,\r
+  IN EFI_PHYSICAL_ADDRESS                  *TopOfMemory\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecImageRead (\r
+  IN     VOID    *FileHandle,\r
+  IN     UINTN   FileOffset,\r
+  IN OUT UINTN   *ReadSize,\r
+  OUT    VOID    *Buffer\r
+  );\r
+\r
+CHAR16                            *\r
+AsciiToUnicode (\r
+  IN  CHAR8   *Ascii,\r
+  IN  UINTN   *StrLen OPTIONAL\r
+  );\r
+\r
+UINTN\r
+CountSeperatorsInString (\r
+  IN  const CHAR16   *String,\r
+  IN  CHAR16   Seperator\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecTemporaryRamSupport (\r
+  IN CONST EFI_PEI_SERVICES   **PeiServices,\r
+  IN EFI_PHYSICAL_ADDRESS     TemporaryMemoryBase,\r
+  IN EFI_PHYSICAL_ADDRESS     PermanentMemoryBase,\r
+  IN UINTN                    CopySize\r
+  );\r
+  \r
+EFI_STATUS\r
+EFIAPI\r
+GasketSecTemporaryRamSupport (\r
+  IN CONST EFI_PEI_SERVICES   **PeiServices,\r
+  IN EFI_PHYSICAL_ADDRESS     TemporaryMemoryBase,\r
+  IN EFI_PHYSICAL_ADDRESS     PermanentMemoryBase,\r
+  IN UINTN                    CopySize\r
+  );\r
+\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+SecPeCoffGetEntryPoint (\r
+  IN     VOID  *Pe32Data,\r
+  IN OUT VOID  **EntryPoint\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+SecPeCoffRelocateImageExtraAction (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+SecPeCoffLoaderUnloadImageExtraAction (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  );\r
+\r
+\r
+VOID\r
+EFIAPI\r
+PeiSwitchStacks (\r
+  IN      SWITCH_STACK_ENTRY_POINT  EntryPoint,\r
+  IN      VOID                      *Context1,  OPTIONAL\r
+  IN      VOID                      *Context2,  OPTIONAL\r
+  IN      VOID                      *Context3,  OPTIONAL\r
+  IN      VOID                      *NewStack\r
+  );\r
+\r
+VOID\r
+SecInitThunkProtocol (\r
+  VOID\r
+  );\r
+  \r
+\r
+VOID SecSleep (UINT64 Milliseconds);\r
+VOID SecEnableInterrupt (VOID);\r
+VOID SecDisableInterrupt (VOID);\r
+BOOLEAN SecInterruptEanbled (VOID);\r
+\r
+\r
+extern EMU_THUNK_PROTOCOL    gEmuThunkProtocol;\r
+extern EMU_IO_THUNK_PROTOCOL gX11ThunkIo;\r
+extern EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo;\r
+extern EMU_IO_THUNK_PROTOCOL gPthreadThunkIo;\r
+\r
+\r
+#endif\r
diff --git a/InOsEmuPkg/Unix/Sec/SecMain.inf b/InOsEmuPkg/Unix/Sec/SecMain.inf
new file mode 100644 (file)
index 0000000..24a36be
--- /dev/null
@@ -0,0 +1,118 @@
+## @file\r
+# Entry Point of Emu Emulator\r
+#\r
+# Main executable file of Unix Emulator that loads PEI core after initialization finished.\r
+# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>\r
+#\r
+#  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                      = SecMain\r
+  FILE_GUID                      = 8863C0AD-7724-C84B-88E5-A33B116D1485\r
+  MODULE_TYPE                    = USER_DEFINED\r
+#  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\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]\r
+  SecMain.c\r
+  EmuThunk.c\r
+  FwVol.c\r
+  X11GraphicsWindow.c\r
+  Pthreads.c\r
+  PosixFileSystem.c\r
+\r
+[Sources.X64]\r
+  X64/Gasket.S        # convert between Emu x86_64 ABI and EFI X64 ABI\r
+  X64/SwitchStack.S\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  PcdLib\r
+  PrintLib\r
+  BaseMemoryLib\r
+  BaseLib\r
+  PeCoffLib\r
+  ThunkPpiList\r
+  ThunkProtocolList\r
+\r
+\r
+[Ppis]\r
+  gEfiPeiStatusCodePpiGuid                      # PPI ALWAYS_PRODUCED\r
+  gEfiTemporaryRamSupportPpiGuid\r
+  gEmuThunkPpiGuid\r
+  gEmuPeiServicesTableUpdatePpiGuid\r
+\r
+[Protocols]\r
+  gEmuIoThunkProtocolGuid\r
+  gEmuIoThunkProtocolGuid\r
+  gEmuGraphicsWindowProtocolGuid\r
+  gEmuPthreadThunkProtocolGuid\r
+  gEfiSimpleFileSystemProtocolGuid\r
+  \r
+\r
+[Guids]\r
+  gEfiFileSystemVolumeLabelInfoIdGuid           # SOMETIMES_CONSUMED\r
+  gEfiFileInfoGuid                              # SOMETIMES_CONSUMED\r
+  gEfiFileSystemInfoGuid                        # SOMETIMES_CONSUMED\r
+\r
+[Pcd]\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuBootMode\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFirmwareVolume\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuMemorySize\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFdBaseAddress\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFirmwareFdSize\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFirmwareBlockSize\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuApCount\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuPhysicalDisk\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuVirtualDisk\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuGop|L"GOP Window"\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFileSystem\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuSerialPort\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuNetworkInterface\r
+\r
+\r
+[BuildOptions]\r
+   GCC:*_*_IA32_DLINK_FLAGS == -o $(BIN_DIR)/SecMain -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o -L/usr/X11R6/lib -lXext -lX11 /usr/lib/crtn.o\r
+   GCC:*_*_*_DLINK2_FLAGS == -lc\r
+   GCC:*_*_IA32_CC_FLAGS == -m32 -g -fshort-wchar -fno-strict-aliasing -Wall -malign-double -idirafter/usr/include -c -include $(DEST_DIR_DEBUG)/AutoGen.h -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings\r
+   GCC:*_*_IA32_PP_FLAGS == -m32 -E -x assembler-with-cpp -include $(DEST_DIR_DEBUG)/AutoGen.h\r
+   GCC:*_*_IA32_ASM_FLAGS == -m32 -c -x assembler -imacros $(DEST_DIR_DEBUG)/AutoGen.h\r
+\r
+   GCC:*_*_X64_DLINK_FLAGS == -o $(BIN_DIR)/SecMain -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/crt1.o /usr/lib/crti.o -L/usr/X11R6/lib -lXext -lX11 /usr/lib/crtn.o\r
+   GCC:*_*_X64_CC_FLAGS == -m64 -g -fshort-wchar -fno-strict-aliasing -Wall -malign-double -idirafter/usr/include -c -include $(DEST_DIR_DEBUG)/AutoGen.h -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings\r
+   GCC:*_*_X64_PP_FLAGS == -m64 -E -x assembler-with-cpp -include $(DEST_DIR_DEBUG)/AutoGen.h\r
+   GCC:*_*_X64_ASM_FLAGS == -m64 -c -x assembler -imacros $(DEST_DIR_DEBUG)/AutoGen.h\r
+\r
+#\r
+# Need to do this link via gcc and not ld as the pathing to libraries changes from OS version to OS version\r
+#\r
+   XCODE:*_*_IA32_DLINK_PATH == gcc\r
+   XCODE:*_*_IA32_DLINK_FLAGS == -arch i386 -o $(BIN_DIR)/SecMain -L/usr/X11R6/lib -lXext -lX11 -framework IOKit -framework Carbon\r
+   XCODE:*_*_IA32_ASM_FLAGS == -arch i386 -g\r
+\r
+   XCODE:*_*_X64_DLINK_PATH == gcc\r
+   XCODE:*_*_X64_DLINK_FLAGS == -o $(BIN_DIR)/SecMain -L/usr/X11R6/lib -lXext -lX11 -lIOKit -framework Carbon\r
+   XCODE:*_*_X64_ASM_FLAGS == -g\r
diff --git a/InOsEmuPkg/Unix/Sec/X11GraphicsWindow.c b/InOsEmuPkg/Unix/Sec/X11GraphicsWindow.c
new file mode 100644 (file)
index 0000000..1920f33
--- /dev/null
@@ -0,0 +1,976 @@
+/*++ @file
+
+Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
+Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
+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.             
+
+**/
+
+#include "SecMain.h"
+
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xos.h>
+#include <X11/extensions/XShm.h>
+#include <X11/keysym.h>
+#include <X11/cursorfont.h>
+
+#define KEYSYM_LOWER  0
+#define KEYSYM_UPPER  1
+
+/* XQueryPointer  */
+
+struct uga_drv_shift_mask {
+  unsigned char shift;
+  unsigned char size;
+  unsigned char csize;
+};
+
+#define NBR_KEYS 32
+typedef struct {
+  EMU_GRAPHICS_WINDOW_PROTOCOL GraphicsIo;
+
+  Display *display;
+  int screen;      /* values for window_size in main */
+  Window win;
+  GC gc;
+  Visual *visual;
+
+  int depth;
+  unsigned int width;
+  unsigned int height;
+  unsigned int line_bytes;
+  unsigned int pixel_shift;
+  unsigned char *image_data;
+
+  struct uga_drv_shift_mask r, g, b;
+
+  int use_shm;
+  XShmSegmentInfo xshm_info;
+  XImage *image;
+
+  unsigned int key_rd;
+  unsigned int key_wr;
+  unsigned int key_count;
+  EFI_KEY_DATA keys[NBR_KEYS];
+
+  EFI_KEY_STATE KeyState;
+  
+  EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK    MakeRegisterdKeyCallback;
+  EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK    BreakRegisterdKeyCallback;
+  VOID                                                *RegisterdKeyCallbackContext;
+  
+  int                        previous_x;
+  int                        previous_y;
+  EFI_SIMPLE_POINTER_STATE   pointer_state;
+  int                        pointer_state_changed;
+} GRAPHICS_IO_PRIVATE;
+
+void
+HandleEvents(GRAPHICS_IO_PRIVATE *drv);
+
+void
+fill_shift_mask (struct uga_drv_shift_mask *sm, unsigned long mask)
+{
+  sm->shift = 0;
+  sm->size = 0;
+  while ((mask & 1) == 0)
+    {
+      mask >>= 1;
+      sm->shift++;
+    }
+  while (mask & 1)
+    {
+      sm->size++;
+      mask >>= 1;
+    }
+  sm->csize = 8 - sm->size;
+}
+
+int
+TryCreateShmImage (
+  IN  GRAPHICS_IO_PRIVATE *drv
+  )
+{
+  drv->image = XShmCreateImage (drv->display, drv->visual,
+                 drv->depth, ZPixmap, NULL, &drv->xshm_info,
+                 drv->width, drv->height);
+  if (drv->image == NULL)
+    return 0;
+
+  switch (drv->image->bitmap_unit) {
+  case 32:
+    drv->pixel_shift = 2;
+    break;
+  case 16:
+    drv->pixel_shift = 1;
+    break;
+  case 8:
+    drv->pixel_shift = 0;
+    break;
+  }
+
+  drv->xshm_info.shmid = shmget
+                          (IPC_PRIVATE, drv->image->bytes_per_line * drv->image->height,
+                          IPC_CREAT | 0777);
+  if (drv->xshm_info.shmid < 0) {
+    XDestroyImage(drv->image);
+    return 0;
+  }
+      
+  drv->image_data = shmat (drv->xshm_info.shmid, NULL, 0);
+  if(!drv->image_data) {
+    shmctl (drv->xshm_info.shmid, IPC_RMID, NULL);
+    XDestroyImage(drv->image);
+    return 0;
+  }
+  
+#ifndef __APPLE__  
+  //
+  // This closes shared memory in real time on OS X. Only closes after folks quit using
+  // it on Linux. 
+  //
+  /* Can this fail ?  */
+  shmctl (drv->xshm_info.shmid, IPC_RMID, NULL);
+#endif
+
+  drv->xshm_info.shmaddr = (char*)drv->image_data;
+  drv->image->data = (char*)drv->image_data;
+
+  if (!XShmAttach (drv->display, &drv->xshm_info)) {
+    shmdt (drv->image_data);
+    XDestroyImage(drv->image);
+    return 0;
+  }
+  return 1;
+}
+
+
+EFI_STATUS
+X11Size(
+  IN  EMU_GRAPHICS_WINDOW_PROTOCOL  *GraphicsIo, 
+  IN  UINT32                        Width, 
+  IN  UINT32                        Height
+  )
+{
+  GRAPHICS_IO_PRIVATE *drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo;
+  XSizeHints size_hints;
+
+  /* Destroy current buffer if created.  */
+  if (drv->image != NULL)
+    {
+      /* Before destroy buffer, need to make sure the buffer available for access. */
+      XDestroyImage(drv->image);
+
+      if (drv->use_shm)
+        shmdt (drv->image_data);
+
+      drv->image_data = NULL;
+      drv->image = NULL;
+    }
+
+  drv->width = Width;
+  drv->height = Height;
+  XResizeWindow (drv->display, drv->win, Width, Height);
+
+  /* Allocate image.  */
+  if (XShmQueryExtension(drv->display) && TryCreateShmImage(drv)) {
+    drv->use_shm = 1;
+  } else {
+    drv->use_shm = 0;
+    if (drv->depth > 16)
+      drv->pixel_shift = 2;
+    else if (drv->depth > 8)
+      drv->pixel_shift = 1;
+    else
+      drv->pixel_shift = 0;
+      
+      drv->image_data = malloc((drv->width * drv->height) << drv->pixel_shift);
+      drv->image = XCreateImage (drv->display, drv->visual, drv->depth,
+                                  ZPixmap, 0, (char *)drv->image_data,
+                                  drv->width, drv->height,
+                                  8 << drv->pixel_shift, 0);
+    }
+  drv->line_bytes = drv->image->bytes_per_line;
+  fill_shift_mask (&drv->r, drv->image->red_mask);
+  fill_shift_mask (&drv->g, drv->image->green_mask);
+  fill_shift_mask (&drv->b, drv->image->blue_mask);
+
+  /* Set WM hints.  */
+  size_hints.flags = PSize | PMinSize | PMaxSize;
+  size_hints.min_width = size_hints.max_width = size_hints.base_width = Width;
+  size_hints.min_height = size_hints.max_height = size_hints.base_height = Height;
+  XSetWMNormalHints (drv->display, drv->win, &size_hints);
+
+  XMapWindow (drv->display, drv->win);
+  HandleEvents(drv);
+  return EFI_SUCCESS;
+}
+
+void
+handleKeyEvent(GRAPHICS_IO_PRIVATE *drv, XEvent *ev, BOOLEAN Make)
+{
+  KeySym        *KeySym;
+  EFI_KEY_DATA  KeyData;
+  int           KeySymArraySize;
+  if (Make) {
+    if (drv->key_count == NBR_KEYS) {
+      return;
+    }
+  }
+
+  // keycode is a physical key on the keyboard
+  // KeySym is a mapping of a physical key
+  // KeyboardMapping is the array of KeySym for a given keycode. key, shifted key, option key, command key, ...
+  //
+  // Returns an array of KeySymArraySize of KeySym for the keycode. [0] is lower case, [1] is upper case,
+  // [2] and [3] are based on option and command modifiers. The problem we have is command V
+  // could be mapped to a crazy Unicode character so the old scheme of returning a string. 
+  //
+  KeySym = XGetKeyboardMapping (drv->display, ev->xkey.keycode, 1, &KeySymArraySize);
+   
+  KeyData.Key.ScanCode = 0;
+  KeyData.Key.UnicodeChar = 0;
+  KeyData.KeyState.KeyShiftState = 0;
+
+  //
+  // Skipping EFI_SCROLL_LOCK_ACTIVE & EFI_NUM_LOCK_ACTIVE since they are not on Macs  
+  //
+  if ((ev->xkey.state & LockMask) == 0) {
+    drv->KeyState.KeyToggleState &= ~EFI_CAPS_LOCK_ACTIVE;
+  } else {
+    if (Make) {
+      drv->KeyState.KeyToggleState |= EFI_CAPS_LOCK_ACTIVE;
+    }
+  }
+  
+  // Skipping EFI_MENU_KEY_PRESSED and EFI_SYS_REQ_PRESSED
+  
+  switch (*KeySym) {
+  case XK_Control_R:
+    if (Make) {
+      drv->KeyState.KeyShiftState |=  EFI_RIGHT_CONTROL_PRESSED;
+    } else {
+      drv->KeyState.KeyShiftState &= ~EFI_RIGHT_CONTROL_PRESSED;
+    }
+   break;
+  case XK_Control_L:
+    if (Make) {    
+      drv->KeyState.KeyShiftState |=  EFI_LEFT_CONTROL_PRESSED;
+    } else {
+      drv->KeyState.KeyShiftState &= ~EFI_LEFT_CONTROL_PRESSED;
+    }
+    break;
+
+  case XK_Shift_R:
+    if (Make) {
+      drv->KeyState.KeyShiftState |=  EFI_RIGHT_SHIFT_PRESSED;
+    } else {
+      drv->KeyState.KeyShiftState &= ~EFI_RIGHT_SHIFT_PRESSED;
+    }
+    break;
+  case XK_Shift_L:
+    if (Make) {
+      drv->KeyState.KeyShiftState |=  EFI_LEFT_SHIFT_PRESSED;
+    } else {
+      drv->KeyState.KeyShiftState &= ~EFI_LEFT_SHIFT_PRESSED;
+    }
+    break;
+  
+  case XK_Mode_switch:
+    if (Make) {
+      drv->KeyState.KeyShiftState |=  EFI_LEFT_ALT_PRESSED;
+    } else {
+      drv->KeyState.KeyShiftState &= ~EFI_LEFT_ALT_PRESSED;
+    }
+    break;
+
+  case XK_Meta_R:
+    if (Make) {
+      drv->KeyState.KeyShiftState |=  EFI_RIGHT_LOGO_PRESSED;
+    } else {
+      drv->KeyState.KeyShiftState &= ~EFI_RIGHT_LOGO_PRESSED;
+    }
+    break;
+  case XK_Meta_L:
+    if (Make) {
+      drv->KeyState.KeyShiftState |=  EFI_LEFT_LOGO_PRESSED;
+    } else {
+      drv->KeyState.KeyShiftState &= ~EFI_LEFT_LOGO_PRESSED;
+    }
+    break;
+  
+  case XK_KP_Home:
+  case XK_Home:       KeyData.Key.ScanCode = SCAN_HOME;       break;
+  
+  case XK_KP_End:
+  case XK_End:        KeyData.Key.ScanCode = SCAN_END;        break;
+  
+  case XK_KP_Left: 
+  case XK_Left:       KeyData.Key.ScanCode = SCAN_LEFT;       break;
+  
+  case XK_KP_Right:
+  case XK_Right:      KeyData.Key.ScanCode = SCAN_RIGHT;      break;
+  
+  case XK_KP_Up:
+  case XK_Up:         KeyData.Key.ScanCode = SCAN_UP;         break;
+  
+  case XK_KP_Down:
+  case XK_Down:       KeyData.Key.ScanCode = SCAN_DOWN;       break;
+  
+  case XK_KP_Delete:
+  case XK_Delete:       KeyData.Key.ScanCode = SCAN_DELETE;     break;
+  
+  case XK_KP_Insert:  
+  case XK_Insert:     KeyData.Key.ScanCode = SCAN_INSERT;     break;
+  
+  case XK_KP_Page_Up:
+  case XK_Page_Up:    KeyData.Key.ScanCode = SCAN_PAGE_UP;    break;
+  
+  case XK_KP_Page_Down:
+  case XK_Page_Down:  KeyData.Key.ScanCode = SCAN_PAGE_DOWN;  break;
+  
+  case XK_Escape:     KeyData.Key.ScanCode = SCAN_ESC;        break;
+
+  
+  case XK_KP_F1:
+  case XK_F1:   KeyData.Key.ScanCode = SCAN_F1;   break;
+  
+  case XK_KP_F2:
+  case XK_F2:   KeyData.Key.ScanCode = SCAN_F2;   break;
+
+  case XK_KP_F3:
+  case XK_F3:   KeyData.Key.ScanCode = SCAN_F3;   break;
+
+  case XK_KP_F4:
+  case XK_F4:   KeyData.Key.ScanCode = SCAN_F4;   break;
+
+  case XK_F5:   KeyData.Key.ScanCode = SCAN_F5;   break;
+  case XK_F6:   KeyData.Key.ScanCode = SCAN_F6;   break;
+  case XK_F7:   KeyData.Key.ScanCode = SCAN_F7;   break;
+  
+  // Don't map into X11 by default on a Mac
+  // System Preferences->Keyboard->Keyboard Shortcuts can be configured 
+  // to not use higher function keys as shortcuts and the will show up
+  // in X11. 
+  case XK_F8:   KeyData.Key.ScanCode = SCAN_F8;   break;
+  case XK_F9:   KeyData.Key.ScanCode = SCAN_F9;   break;
+  case XK_F10:  KeyData.Key.ScanCode = SCAN_F10;  break;
+  
+  case XK_F11:  KeyData.Key.ScanCode = SCAN_F11;  break;
+  case XK_F12:  KeyData.Key.ScanCode = SCAN_F12;  break;
+  
+  case XK_F13:  KeyData.Key.ScanCode = SCAN_F13;  break;
+  case XK_F14:  KeyData.Key.ScanCode = SCAN_F14;  break;
+  case XK_F15:  KeyData.Key.ScanCode = SCAN_F15;  break;
+  case XK_F16:  KeyData.Key.ScanCode = SCAN_F16;  break;
+  case XK_F17:  KeyData.Key.ScanCode = SCAN_F17;  break;
+  case XK_F18:  KeyData.Key.ScanCode = SCAN_F18;  break;
+  case XK_F19:  KeyData.Key.ScanCode = SCAN_F19;  break;
+  case XK_F20:  KeyData.Key.ScanCode = SCAN_F20;  break;
+  case XK_F21:  KeyData.Key.ScanCode = SCAN_F21;  break;
+  case XK_F22:  KeyData.Key.ScanCode = SCAN_F22;  break;
+  case XK_F23:  KeyData.Key.ScanCode = SCAN_F23;  break;
+  case XK_F24:  KeyData.Key.ScanCode = SCAN_F24;  break;
+
+  // No mapping in X11
+  //case XK_:   KeyData.Key.ScanCode = SCAN_MUTE;            break;             
+  //case XK_:   KeyData.Key.ScanCode = SCAN_VOLUME_UP;       break;            
+  //case XK_:   KeyData.Key.ScanCode = SCAN_VOLUME_DOWN;     break;       
+  //case XK_:   KeyData.Key.ScanCode = SCAN_BRIGHTNESS_UP;   break;      
+  //case XK_:   KeyData.Key.ScanCode = SCAN_BRIGHTNESS_DOWN; break;    
+  //case XK_:   KeyData.Key.ScanCode = SCAN_SUSPEND;         break; 
+  //case XK_:   KeyData.Key.ScanCode = SCAN_HIBERNATE;       break; 
+  //case XK_:   KeyData.Key.ScanCode = SCAN_TOGGLE_DISPLAY;  break;       
+  //case XK_:   KeyData.Key.ScanCode = SCAN_RECOVERY;        break;      
+  //case XK_:   KeyData.Key.ScanCode = SCAN_EJECT;           break;     
+
+  case XK_BackSpace:  KeyData.Key.UnicodeChar = 0x0008; break;
+
+  case XK_KP_Tab:
+  case XK_Tab:        KeyData.Key.UnicodeChar = 0x0009; break;
+
+  case XK_Linefeed:   KeyData.Key.UnicodeChar = 0x000a; break;
+  
+  case XK_KP_Enter:
+  case XK_Return:     KeyData.Key.UnicodeChar = 0x000d; break;
+
+  case XK_KP_Equal      : KeyData.Key.UnicodeChar = L'='; break;                     
+  case XK_KP_Multiply   : KeyData.Key.UnicodeChar = L'*'; break;                  
+  case XK_KP_Add        : KeyData.Key.UnicodeChar = L'+'; break;                       
+  case XK_KP_Separator  : KeyData.Key.UnicodeChar = L'~'; break;                  
+  case XK_KP_Subtract   : KeyData.Key.UnicodeChar = L'-'; break;                  
+  case XK_KP_Decimal    : KeyData.Key.UnicodeChar = L'.'; break;                   
+  case XK_KP_Divide     : KeyData.Key.UnicodeChar = L'/'; break;                    
+
+  case XK_KP_0    : KeyData.Key.UnicodeChar = L'0'; break;                         
+  case XK_KP_1    : KeyData.Key.UnicodeChar = L'1'; break;                         
+  case XK_KP_2    : KeyData.Key.UnicodeChar = L'2'; break;                         
+  case XK_KP_3    : KeyData.Key.UnicodeChar = L'3'; break;                         
+  case XK_KP_4    : KeyData.Key.UnicodeChar = L'4'; break;                        
+  case XK_KP_5    : KeyData.Key.UnicodeChar = L'5'; break;                         
+  case XK_KP_6    : KeyData.Key.UnicodeChar = L'6'; break;                         
+  case XK_KP_7    : KeyData.Key.UnicodeChar = L'7'; break;                         
+  case XK_KP_8    : KeyData.Key.UnicodeChar = L'8'; break;                        
+  case XK_KP_9    : KeyData.Key.UnicodeChar = L'9'; break;                         
+
+  default:
+    ;
+  }
+
+  // The global state is our state
+  KeyData.KeyState.KeyShiftState = drv->KeyState.KeyShiftState;
+  KeyData.KeyState.KeyToggleState = drv->KeyState.KeyToggleState;
+
+  if (*KeySym < XK_BackSpace) {
+    if (((drv->KeyState.KeyShiftState & (EFI_LEFT_SHIFT_PRESSED | EFI_RIGHT_SHIFT_PRESSED)) != 0) ||
+        ((drv->KeyState.KeyToggleState & EFI_CAPS_LOCK_ACTIVE) != 0) ) {
+      
+      KeyData.Key.UnicodeChar = (CHAR16)KeySym[KEYSYM_UPPER];
+
+      // Per UEFI spec since we converted the Unicode clear the shift bits we pass up 
+      KeyData.KeyState.KeyShiftState &= ~(EFI_LEFT_SHIFT_PRESSED | EFI_RIGHT_SHIFT_PRESSED);
+    } else {
+      KeyData.Key.UnicodeChar = (CHAR16)KeySym[KEYSYM_LOWER];
+    }
+  } else {
+    // XK_BackSpace is the start of XK_MISCELLANY. These are the XK_? keys we process in this file 
+    ; 
+  }
+  
+  if (Make) {
+    memcpy (&drv->keys[drv->key_wr], &KeyData, sizeof (EFI_KEY_DATA));
+    drv->key_wr = (drv->key_wr + 1) % NBR_KEYS;
+    drv->key_count++; 
+    if (drv->MakeRegisterdKeyCallback != NULL) {
+      ReverseGasketUint64Uint64 (drv->MakeRegisterdKeyCallback ,drv->RegisterdKeyCallbackContext, &KeyData);
+    }
+  } else {
+    if (drv->BreakRegisterdKeyCallback != NULL) {
+      ReverseGasketUint64Uint64 (drv->BreakRegisterdKeyCallback ,drv->RegisterdKeyCallbackContext, &KeyData);
+    }
+  }
+}
+
+
+void
+handleMouseMoved(GRAPHICS_IO_PRIVATE *drv, XEvent *ev)
+{
+  if ( ev->xmotion.x != drv->previous_x )
+  {
+    drv->pointer_state.RelativeMovementX += ( ev->xmotion.x - drv->previous_x );
+  drv->previous_x = ev->xmotion.x;
+  drv->pointer_state_changed = 1;
+  }
+
+  if ( ev->xmotion.y != drv->previous_y )
+  {
+    drv->pointer_state.RelativeMovementY += ( ev->xmotion.y - drv->previous_y );
+    drv->previous_y = ev->xmotion.y;
+  drv->pointer_state_changed = 1;
+  }
+
+  drv->pointer_state.RelativeMovementZ = 0;
+}
+
+void
+handleMouseDown(GRAPHICS_IO_PRIVATE *drv, XEvent *ev, BOOLEAN Pressed)
+{
+  if ( ev->xbutton.button == Button1 )
+  {
+    drv->pointer_state_changed = ( drv->pointer_state.LeftButton != Pressed );
+  drv->pointer_state.LeftButton = Pressed;
+  }
+  if ( ev->xbutton.button == Button2 )
+  {
+    drv->pointer_state_changed = ( drv->pointer_state.RightButton != Pressed );
+  drv->pointer_state.RightButton = Pressed;
+  }
+}
+
+void
+Redraw(GRAPHICS_IO_PRIVATE *drv, UINTN X, UINTN Y, UINTN Width, UINTN Height)
+{
+  if (drv->use_shm)
+    XShmPutImage (drv->display, drv->win, drv->gc, drv->image,
+                   X, Y, X, Y, Width, Height, False);
+  else
+    XPutImage (drv->display, drv->win, drv->gc, drv->image,
+                X, Y, X, Y, Width, Height);
+  XFlush(drv->display);
+}
+
+void
+HandleEvent(GRAPHICS_IO_PRIVATE *drv, XEvent *ev)
+{
+  switch (ev->type)
+    {
+    case Expose:
+      Redraw(drv, ev->xexpose.x, ev->xexpose.y,
+        ev->xexpose.width, ev->xexpose.height);
+      break;
+    case GraphicsExpose:
+      Redraw(drv, ev->xgraphicsexpose.x, ev->xgraphicsexpose.y,
+        ev->xgraphicsexpose.width, ev->xgraphicsexpose.height);
+      break;
+    case KeyPress:
+      handleKeyEvent(drv, ev, TRUE);
+      break;
+    case KeyRelease:
+      handleKeyEvent(drv, ev, FALSE);
+      break;
+    case MappingNotify:
+      XRefreshKeyboardMapping(&ev->xmapping);
+      break;
+    case MotionNotify:
+      handleMouseMoved(drv, ev);
+      break;
+    case ButtonPress:
+      handleMouseDown(drv, ev, TRUE);
+    break;
+    case ButtonRelease:
+      handleMouseDown(drv, ev, FALSE);
+    break;
+#if 0
+    case DestroyNotify:
+      XCloseDisplay (drv->display);
+      exit (1);
+      break;
+#endif
+    case NoExpose:
+    default:
+      break;
+    }
+}
+
+void
+HandleEvents(GRAPHICS_IO_PRIVATE *drv)
+{
+  while (XPending(drv->display) != 0)
+    {
+      XEvent ev;
+
+      XNextEvent (drv->display, &ev);
+      HandleEvent(drv, &ev);
+    }
+}
+
+unsigned long
+X11PixelToColor (GRAPHICS_IO_PRIVATE *drv, EFI_UGA_PIXEL pixel)
+{
+  return ((pixel.Red >> drv->r.csize) << drv->r.shift)
+    | ((pixel.Green >> drv->g.csize) << drv->g.shift)
+    | ((pixel.Blue >> drv->b.csize) << drv->b.shift);
+}
+
+EFI_UGA_PIXEL
+X11ColorToPixel (GRAPHICS_IO_PRIVATE *drv, unsigned long val)
+{
+  EFI_UGA_PIXEL res;
+
+  memset (&res, 0, sizeof (EFI_UGA_PIXEL));
+  /* FIXME: should round instead of truncate.  */
+  res.Red = (val >> drv->r.shift) << drv->r.csize;
+  res.Green = (val >> drv->g.shift) << drv->g.csize;
+  res.Blue = (val >> drv->b.shift) << drv->b.csize;
+
+  return res;
+}
+
+STATIC EFI_STATUS
+CheckKeyInternal( GRAPHICS_IO_PRIVATE *drv, BOOLEAN delay )
+{
+  HandleEvents(drv);
+  if (drv->key_count != 0)
+    return EFI_SUCCESS;
+  if ( delay )
+    /* EFI is polling.  Be CPU-friendly.  */
+    SecSleep (20);
+    return EFI_NOT_READY;
+  }
+
+EFI_STATUS
+X11CheckKey(EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsIo)
+{
+  GRAPHICS_IO_PRIVATE  *drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo;
+  return CheckKeyInternal(drv, TRUE);
+}
+
+EFI_STATUS
+EFIAPI
+X11GetKey (
+  IN  EMU_GRAPHICS_WINDOW_PROTOCOL  *GraphicsIo, 
+  IN  EFI_KEY_DATA                   *KeyData
+  )
+{
+  GRAPHICS_IO_PRIVATE *drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo;
+  EFI_STATUS status;
+
+  status = CheckKeyInternal(drv, FALSE);
+  if (status != EFI_SUCCESS)
+    return status;
+
+  CopyMem (KeyData, &drv->keys[drv->key_rd], sizeof (EFI_KEY_DATA));
+  drv->key_rd = (drv->key_rd + 1) % NBR_KEYS;
+  drv->key_count--;
+  return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+EFIAPI
+X11KeySetState (
+  IN EMU_GRAPHICS_WINDOW_PROTOCOL   *GraphicsIo, 
+  IN EFI_KEY_TOGGLE_STATE       *KeyToggleState
+  )
+{
+  GRAPHICS_IO_PRIVATE  *drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo;
+//  XKeyEvent       event;
+  
+  if (*KeyToggleState & EFI_CAPS_LOCK_ACTIVE) {
+    if ((drv->KeyState.KeyToggleState & EFI_CAPS_LOCK_ACTIVE) == 0) {
+      //
+      // We could create an XKeyEvent and send a XK_Caps_Lock to
+      // the UGA/GOP Window
+      //
+    }
+  }
+    
+  drv->KeyState.KeyToggleState = *KeyToggleState;
+  return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+EFIAPI
+X11RegisterKeyNotify (
+  IN EMU_GRAPHICS_WINDOW_PROTOCOL                       *GraphicsIo, 
+  IN EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK    MakeCallBack,
+  IN EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK    BreakCallBack,
+  IN VOID                                                *Context
+  )
+{
+  GRAPHICS_IO_PRIVATE  *drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo;
+
+  drv->MakeRegisterdKeyCallback         = MakeCallBack;
+  drv->BreakRegisterdKeyCallback        = BreakCallBack;
+  drv->RegisterdKeyCallbackContext = Context;
+
+  return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+X11Blt (
+  IN EMU_GRAPHICS_WINDOW_PROTOCOL             *GraphicsIo,
+  IN  EFI_UGA_PIXEL                           *BltBuffer OPTIONAL,
+  IN  EFI_UGA_BLT_OPERATION                   BltOperation,
+  IN  EMU_GRAPHICS_WINDOWS__BLT_ARGS          *Args
+  )
+{
+  GRAPHICS_IO_PRIVATE *Private = (GRAPHICS_IO_PRIVATE *)GraphicsIo;
+  UINTN             DstY;
+  UINTN             SrcY;
+  UINTN             DstX;
+  UINTN             SrcX;
+  UINTN             Index;
+  EFI_UGA_PIXEL     *Blt;
+  UINT8             *Dst;
+  UINT8             *Src;
+  UINTN             Nbr;
+  unsigned long     Color;
+
+  //
+  //  Check bounds
+  //
+  if (BltOperation == EfiUgaVideoToBltBuffer
+      || BltOperation == EfiUgaVideoToVideo) {
+    //
+    // Source is Video.
+    //
+    if (Args->SourceY + Args->Height > Private->height) {
+      return EFI_INVALID_PARAMETER;
+    }
+
+    if (Args->SourceX + Args->Width > Private->width) {
+      return EFI_INVALID_PARAMETER;
+    }
+  }
+
+  if (BltOperation == EfiUgaBltBufferToVideo
+      || BltOperation == EfiUgaVideoToVideo
+      || BltOperation == EfiUgaVideoFill) {
+    //
+    // Destination is Video
+    //
+    if (Args->DestinationY + Args->Height > Private->height) {
+      return EFI_INVALID_PARAMETER;
+    }
+
+    if (Args->DestinationX + Args->Width > Private->width) {
+      return EFI_INVALID_PARAMETER;
+    }
+  }
+
+  switch (BltOperation) {
+  case EfiUgaVideoToBltBuffer:
+    Blt = (EFI_UGA_PIXEL *)((UINT8 *)BltBuffer + (Args->DestinationY * Args->Delta) + Args->DestinationX * sizeof (EFI_UGA_PIXEL));
+    Args->Delta -= Args->Width * sizeof (EFI_UGA_PIXEL);
+    for (SrcY = Args->SourceY; SrcY < (Args->Height + Args->SourceY); SrcY++) {
+      for (SrcX = Args->SourceX; SrcX < (Args->Width + Args->SourceX); SrcX++) {
+        *Blt++ = X11ColorToPixel(Private,
+                                  XGetPixel(Private->image, SrcX, SrcY));
+      }
+      Blt = (EFI_UGA_PIXEL *) ((UINT8 *) Blt + Args->Delta);
+    }
+    break;
+  case EfiUgaBltBufferToVideo:
+    Blt = (EFI_UGA_PIXEL *)((UINT8 *)BltBuffer + (Args->SourceY * Args->Delta) + Args->SourceX * sizeof (EFI_UGA_PIXEL));
+    Args->Delta -= Args->Width * sizeof (EFI_UGA_PIXEL);
+    for (DstY = Args->DestinationY; DstY < (Args->Height + Args->DestinationY); DstY++) {
+      for (DstX = Args->DestinationX; DstX < (Args->Width + Args->DestinationX); DstX++) {
+        XPutPixel(Private->image, DstX, DstY, X11PixelToColor(Private, *Blt));
+        Blt++;
+      }
+      Blt = (EFI_UGA_PIXEL *) ((UINT8 *) Blt + Args->Delta);
+    }
+    break;
+  case EfiUgaVideoToVideo:
+    Dst = Private->image_data + (Args->DestinationX << Private->pixel_shift)
+      + Args->DestinationY * Private->line_bytes;
+    Src = Private->image_data + (Args->SourceX << Private->pixel_shift)
+      + Args->SourceY * Private->line_bytes;
+    Nbr = Args->Width << Private->pixel_shift;
+    if (Args->DestinationY < Args->SourceY) {
+      for (Index = 0; Index < Args->Height; Index++) {
+        memcpy (Dst, Src, Nbr);
+        Dst += Private->line_bytes;
+        Src += Private->line_bytes;
+      }
+    }
+    else {
+      Dst += (Args->Height - 1) * Private->line_bytes;
+      Src += (Args->Height - 1) * Private->line_bytes;
+      for (Index = 0; Index < Args->Height; Index++) {
+      //
+      // Source and Destination Y may be equal, therefore Dst and Src may
+      // overlap.
+      //
+      memmove (Dst, Src, Nbr);
+      Dst -= Private->line_bytes;
+      Src -= Private->line_bytes;
+      }
+    }
+    break;
+  case EfiUgaVideoFill:
+    Color = X11PixelToColor(Private, *BltBuffer);
+    for (DstY = Args->DestinationY; DstY < (Args->Height + Args->DestinationY); DstY++) {
+      for (DstX = Args->DestinationX; DstX < (Args->Width + Args->DestinationX); DstX++) {
+        XPutPixel(Private->image, DstX, DstY, Color);
+      }
+    }
+    break;
+  default:
+      return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  //  Refresh screen.
+  //
+  switch (BltOperation) {
+  case EfiUgaVideoToVideo:
+    XCopyArea(Private->display, Private->win, Private->win, Private->gc,
+               Args->SourceX, Args->SourceY, Args->Width, Args->Height, Args->DestinationX, Args->DestinationY);
+    while (1) {
+      XEvent ev;
+
+      XNextEvent (Private->display, &ev);
+      HandleEvent(Private, &ev);
+      if (ev.type == NoExpose || ev.type == GraphicsExpose)
+        break;
+    }
+    break;
+  case EfiUgaVideoFill:
+    Color = X11PixelToColor(Private, *BltBuffer);
+    XSetForeground(Private->display, Private->gc, Color);
+    XFillRectangle(Private->display, Private->win, Private->gc,
+                    Args->DestinationX, Args->DestinationY, Args->Width, Args->Height);
+    XFlush(Private->display);
+    break;
+  case EfiUgaBltBufferToVideo:
+    Redraw(Private, Args->DestinationX, Args->DestinationY, Args->Width, Args->Height);
+    break;
+  default:
+    break;
+  }
+  return EFI_SUCCESS;
+}
+
+STATIC EFI_STATUS
+CheckPointerInternal( GRAPHICS_IO_PRIVATE *drv, BOOLEAN delay )
+{
+  HandleEvents(drv);
+  if (drv->pointer_state_changed != 0)
+    return EFI_SUCCESS;
+  if ( delay )
+    /* EFI is polling.  Be CPU-friendly.  */
+    SecSleep (20);
+  return EFI_NOT_READY;
+}
+
+EFI_STATUS
+X11CheckPointer(EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsIo)
+{
+  GRAPHICS_IO_PRIVATE  *drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo;
+  return( CheckPointerInternal( drv, TRUE ) );
+}
+
+EFI_STATUS
+X11GetPointerState (EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsIo, EFI_SIMPLE_POINTER_STATE *state)
+{
+  GRAPHICS_IO_PRIVATE *drv = (GRAPHICS_IO_PRIVATE *)GraphicsIo;
+  EFI_STATUS status;
+
+  status = CheckPointerInternal( drv, FALSE );
+  if (status != EFI_SUCCESS)
+    return status;
+  
+  memcpy( state, &drv->pointer_state, sizeof( EFI_SIMPLE_POINTER_STATE ) );
+
+  drv->pointer_state.RelativeMovementX = 0;
+  drv->pointer_state.RelativeMovementY = 0;
+  drv->pointer_state.RelativeMovementZ = 0;
+  drv->pointer_state_changed = 0;
+  return EFI_SUCCESS;
+}
+
+
+
+EFI_STATUS
+X11GraphicsWindowOpen (
+  IN  EMU_IO_THUNK_PROTOCOL   *This
+  )
+{
+  GRAPHICS_IO_PRIVATE *drv;
+  unsigned int border_width = 0;
+  char *display_name = NULL;
+  int title_len;
+
+  drv = (GRAPHICS_IO_PRIVATE *)calloc (1, sizeof (GRAPHICS_IO_PRIVATE));
+  if (drv == NULL)
+    return EFI_OUT_OF_RESOURCES;
+
+  drv->GraphicsIo.Size                = GasketX11Size;
+  drv->GraphicsIo.CheckKey            = GasketX11CheckKey;
+  drv->GraphicsIo.GetKey              = GasketX11GetKey;
+  drv->GraphicsIo.KeySetState         = GasketX11KeySetState;
+  drv->GraphicsIo.RegisterKeyNotify   = GasketX11RegisterKeyNotify;
+  drv->GraphicsIo.Blt                 = GasketX11Blt;
+  drv->GraphicsIo.CheckPointer        = GasketX11CheckPointer;
+  drv->GraphicsIo.GetPointerState     = GasketX11GetPointerState;
+  
+
+  drv->key_count = 0;
+  drv->key_rd = 0;
+  drv->key_wr = 0;
+  drv->KeyState.KeyShiftState      = EFI_SHIFT_STATE_VALID;
+  drv->KeyState.KeyToggleState     = EFI_TOGGLE_STATE_VALID;
+  drv->MakeRegisterdKeyCallback    = NULL;
+  drv->BreakRegisterdKeyCallback   = NULL;
+  drv->RegisterdKeyCallbackContext = NULL;
+  
+  
+  drv->display = XOpenDisplay (display_name);
+  if (drv->display == NULL) {
+    fprintf (stderr, "uga: cannot connect to X server %s\n", XDisplayName (display_name));
+    free (drv);
+    return EFI_DEVICE_ERROR;
+  }
+  drv->screen = DefaultScreen (drv->display);
+  drv->visual = DefaultVisual (drv->display, drv->screen);
+  drv->win = XCreateSimpleWindow
+               (drv->display, RootWindow (drv->display, drv->screen),
+                0, 0, 4, 4, border_width,
+                WhitePixel (drv->display, drv->screen),
+                BlackPixel (drv->display, drv->screen));
+
+  drv->depth = DefaultDepth (drv->display, drv->screen);
+  XDefineCursor (drv->display, drv->win, XCreateFontCursor (drv->display, XC_pirate)); 
+
+  /* Compute title len and convert to Ascii.  */
+  for (title_len = 0; This->ConfigString[title_len] != 0; title_len++)
+    ;
+  {
+    char title[title_len + 1];
+    int i;
+    for (i = 0; i < title_len; i++)
+      title[i] = This->ConfigString[i];
+    title[i] = 0;
+    
+    XStoreName (drv->display, drv->win, title);
+  }
+
+//  XAutoRepeatOff (drv->display);
+  XSelectInput (drv->display, drv->win,
+                 ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask );
+  drv->gc = DefaultGC (drv->display, drv->screen);
+
+  This->Private   = (VOID *)drv;
+  This->Interface = (VOID *)drv;
+  return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+X11GraphicsWindowClose (
+  IN  EMU_IO_THUNK_PROTOCOL   *This
+  )
+{
+  GRAPHICS_IO_PRIVATE *drv = (GRAPHICS_IO_PRIVATE *)This->Private;
+
+  if (drv == NULL)
+    return EFI_SUCCESS;
+  if (drv->image != NULL)
+    {
+      XDestroyImage(drv->image);
+
+      if (drv->use_shm)
+        shmdt (drv->image_data);
+
+      drv->image_data = NULL;
+      drv->image = NULL;
+    }
+  XDestroyWindow(drv->display, drv->win);
+  XCloseDisplay(drv->display);
+  
+#ifdef __APPLE__
+  // Free up the shared memory
+  shmctl (drv->xshm_info.shmid, IPC_RMID, NULL);
+#endif
+  
+  free(drv);
+  return EFI_SUCCESS;
+}
+
+
+EMU_IO_THUNK_PROTOCOL gX11ThunkIo = {
+  &gEmuGraphicsWindowProtocolGuid,
+  NULL,
+  NULL,
+  0,
+  GasketX11GraphicsWindowOpen,
+  GasketX11GraphicsWindowClose,
+  NULL
+};
+
+
diff --git a/InOsEmuPkg/Unix/Sec/X64/Gasket.S b/InOsEmuPkg/Unix/Sec/X64/Gasket.S
new file mode 100644 (file)
index 0000000..fde3028
--- /dev/null
@@ -0,0 +1,1054 @@
+#------------------------------------------------------------------------------
+#
+# Manage differenced between UNIX ABI and EFI/Windows ABI
+#
+# EFI  Arg passing: RCX, RDX, R8,  R9
+#                   Callee allocates 32 bytes on stack to spill registers
+# UNIX Arg passing: RDI, RSI, RDX, RCX, R8, R9
+# RSI, RDI calle-save on EFI, scatch on UNIX callign
+#
+# Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
+# 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.
+#
+#------------------------------------------------------------------------------
+
+//
+// Gaskets are EFI ABI to UNIX ABI calls
+// EFI ABI code will sub 40 (0x28) from %rsp before calling a function
+//  This is the 32 (0x20) byte to spill registers and 8 bytes to align stack on 16 byte boundry.
+//
+  .text
+
+// 32 byte shadow to spill rcx-r9, 8 bytes to align stack on 16 byte boundry
+// Any call with 0 - 4 arguments allocates 40 bytes on the stack.
+// For more than 4 args you always have to increase in quanta of 16 so 5 or 6 args is 56, 
+// 7 or 8 args is 72, and 9 or 10 args is 88
+
+
+
+  .text
+  
+//
+// EMU_THUNK_PROTOCOL gaskets (EFIAPI to UNIX ABI)
+//
+
+
+
+
+ASM_GLOBAL ASM_PFX(GasketSecWriteStdErr)
+ASM_PFX(GasketSecWriteStdErr):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq    %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq    %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+
+  call  ASM_PFX(SecWriteStdErr)
+  
+  popq  %rdi            // restore state
+  popq  %rsi
+  popq  %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketSecSetTimer)
+ASM_PFX(GasketSecSetTimer):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq    %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq    %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+
+  call  ASM_PFX(SecSetTimer)
+  
+  popq  %rdi            // restore state
+  popq  %rsi
+  popq  %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketSecEnableInterrupt)
+ASM_PFX(GasketSecEnableInterrupt):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  call    ASM_PFX(SecEnableInterrupt)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketSecDisableInterrupt)
+ASM_PFX(GasketSecDisableInterrupt):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  call    ASM_PFX(SecDisableInterrupt)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+ASM_GLOBAL ASM_PFX(GasketQueryPerformanceFrequency)
+ASM_PFX(GasketQueryPerformanceFrequency):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  call    ASM_PFX(QueryPerformanceFrequency)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketQueryPerformanceCounter)
+ASM_PFX(GasketQueryPerformanceCounter):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  call    ASM_PFX(QueryPerformanceCounter)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketSecSleep)
+ASM_PFX(GasketSecSleep):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq    %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq    %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call  ASM_PFX(SecSleep)
+  
+  popq  %rdi            // restore state
+  popq  %rsi
+  popq  %rbp
+  ret
+  
+  
+ASM_GLOBAL ASM_PFX(GasketSecExit)
+ASM_PFX(GasketSecExit):
+  pushq   %rbp                 // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  movq    %rcx, %rdi           // Swizzle args 
+  call    ASM_PFX(SecExit)     // Less to do as we will never return to EFI ABI world
+LDEAD_LOOP:
+  jmp  LDEAD_LOOP              // _exit should never return
+
+  
+ASM_GLOBAL ASM_PFX(GasketSecGetTime)
+ASM_PFX(GasketSecGetTime):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+
+  call  ASM_PFX(SecGetTime)
+
+  popq  %rdi            // restore state
+  popq  %rsi
+  popq  %rbp
+  ret
+
+ASM_GLOBAL ASM_PFX(GasketSecSetTime)
+ASM_PFX(GasketSecSetTime):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+
+  call  ASM_PFX(SecSetTime)
+
+  popq  %rdi            // restore state
+  popq  %rsi
+  popq  %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketSecGetNextProtocol)
+ASM_PFX(GasketSecGetNextProtocol):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+  movq    %r9,  %rcx
+
+  call    ASM_PFX(SecGetNextProtocol)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+// PPIs produced by SEC
+
+ASM_GLOBAL ASM_PFX(GasketSecPeCoffGetEntryPoint)
+ASM_PFX(GasketSecPeCoffGetEntryPoint):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+
+  call    ASM_PFX(SecPeCoffGetEntryPoint)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+ASM_GLOBAL ASM_PFX(GasketSecPeCoffRelocateImageExtraAction)
+ASM_PFX(GasketSecPeCoffRelocateImageExtraAction):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(SecPeCoffRelocateImageExtraAction)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+ASM_GLOBAL ASM_PFX(GasketSecPeCoffUnloadImageExtraAction)
+ASM_PFX(GasketSecPeCoffUnloadImageExtraAction):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(SecPeCoffUnloadImageExtraAction)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+ASM_GLOBAL ASM_PFX(GasketSecEmuThunkAddress)
+ASM_PFX(GasketSecEmuThunkAddress):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  call    ASM_PFX(SecEmuThunkAddress)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+//
+// Gasket functions for EFI_EMU_UGA_IO_PROTOCOL
+//
+
+ASM_GLOBAL ASM_PFX(GasketX11Size)
+ASM_PFX(GasketX11Size):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+  movq    %r9,  %rcx
+
+  call    ASM_PFX(X11Size)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketX11CheckKey)
+ASM_PFX(GasketX11CheckKey):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(X11CheckKey)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+ASM_GLOBAL ASM_PFX(GasketX11GetKey)
+ASM_PFX(GasketX11GetKey):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+
+  call    ASM_PFX(X11GetKey)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketX11KeySetState)
+ASM_PFX(GasketX11KeySetState):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+
+  call    ASM_PFX(X11KeySetState)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+  
+ASM_GLOBAL ASM_PFX(GasketX11RegisterKeyNotify)
+ASM_PFX(GasketX11RegisterKeyNotify):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+  movq    %r9,  %rcx
+
+  call    ASM_PFX(X11RegisterKeyNotify)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+  
+ASM_GLOBAL ASM_PFX(GasketX11Blt)
+ASM_PFX(GasketX11Blt):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+  movq    %r9,  %rcx
+
+  call    ASM_PFX(X11Blt)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketX11CheckPointer)
+ASM_PFX(GasketX11CheckPointer):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(X11CheckPointer)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketX11GetPointerState)
+ASM_PFX(GasketX11GetPointerState):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+
+  call    ASM_PFX(X11GetPointerState)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketX11GraphicsWindowOpen)
+ASM_PFX(GasketX11GraphicsWindowOpen):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(X11GraphicsWindowOpen)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+ASM_GLOBAL ASM_PFX(GasketX11GraphicsWindowClose)
+ASM_PFX(GasketX11GraphicsWindowClose):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %r9,  %rcx
+
+  call    ASM_PFX(X11GraphicsWindowClose)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+// Pthreads
+
+ASM_GLOBAL ASM_PFX(GasketPthreadMutexLock)
+ASM_PFX(GasketPthreadMutexLock):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(PthreadMutexLock)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketPthreadMutexUnLock)
+ASM_PFX(GasketPthreadMutexUnLock):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(PthreadMutexUnLock)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+ASM_GLOBAL ASM_PFX(GasketPthreadMutexTryLock)
+ASM_PFX(GasketPthreadMutexTryLock):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(PthreadMutexTryLock)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+ASM_GLOBAL ASM_PFX(GasketPthreadMutexInit)
+ASM_PFX(GasketPthreadMutexInit):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+
+  call    ASM_PFX(PthreadMutexInit)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketPthreadMutexDestroy)
+ASM_PFX(GasketPthreadMutexDestroy):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(PthreadMutexDestroy)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketPthreadCreate)
+ASM_PFX(GasketPthreadCreate):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+  movq    %r9,  %rcx
+
+  call    ASM_PFX(PthreadCreate)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+                          
+ASM_GLOBAL ASM_PFX(GasketPthreadExit)
+ASM_PFX(GasketPthreadExit):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(PthreadExit)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+                            
+ASM_GLOBAL ASM_PFX(GasketPthreadSelf)
+ASM_PFX(GasketPthreadSelf):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+
+  call    ASM_PFX(PthreadSelf)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketPthreadOpen)
+ASM_PFX(GasketPthreadOpen):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(PthreadOpen)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketPthreadClose)
+ASM_PFX(GasketPthreadClose):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(PthreadClose)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+
+
+//
+// UNIX ABI to EFI ABI call
+//
+// UINTN
+// ReverseGasketUint64 (
+//   void *Api,
+//   UINTN Arg1
+//   );
+ASM_GLOBAL ASM_PFX(ReverseGasketUint64)
+ASM_PFX(ReverseGasketUint64):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  movq    %rdi, %rax    // Swizzle args 
+  movq    %rsi, %rcx     
+
+  subq  $32, %rsp        // 32-byte shadow space
+  call  *%rax
+  addq  $32, %rsp
+
+  popq   %rbp          
+  ret
+
+//
+// UNIX ABI to EFI ABI call
+//
+// UINTN
+// ReverseGasketUint64Uint64 (
+//   void *Api,
+//   UINTN Arg1
+//   UINTN Arg2
+//   );
+ASM_GLOBAL ASM_PFX(ReverseGasketUint64Uint64)
+ASM_PFX(ReverseGasketUint64Uint64):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  movq    %rdi, %rax    // Swizzle args 
+  movq    %rsi, %rcx     
+
+  subq  $32, %rsp        // 32-byte shadow space
+  call  *%rax
+  addq  $32, %rsp
+
+  popq   %rbp          
+  ret
+  
+
+// Sec PPI Callbacks - Check Me
+
+ASM_GLOBAL ASM_PFX(GasketSecUnixPeiLoadFile)
+ASM_PFX(GasketSecUnixPeiLoadFile):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+  movq    %r9,  %rcx
+
+  call    ASM_PFX(SecUnixPeiLoadFile)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+
+ASM_GLOBAL ASM_PFX(GasketSecUnixPeiAutoScan)
+ASM_PFX(GasketSecUnixPeiAutoScan):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+
+  call    ASM_PFX(SecUnixPeiAutoScan)
+  
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketSecUnixFdAddress)
+ASM_PFX(GasketSecUnixFdAddress):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+  movq    %r9,  %rcx
+
+  call    ASM_PFX(SecUnixFdAddress)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+// EmuIoThunk SimpleFileSystem
+
+ASM_GLOBAL ASM_PFX(GasketPosixOpenVolume)
+ASM_PFX(GasketPosixOpenVolume):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+  movq    %r9,  %rcx
+
+  call    ASM_PFX(PosixOpenVolume)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketPosixFileOpen)
+ASM_PFX(GasketPosixFileOpen):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+  movq    %r9,  %rcx
+  movq    0x30(%rbp), %r8 
+  call    ASM_PFX(PosixFileOpen)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketPosixFileCLose)
+ASM_PFX(GasketPosixFileCLose):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(PosixFileCLose)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+  
+ASM_GLOBAL ASM_PFX(GasketPosixFileDelete)
+ASM_PFX(GasketPosixFileDelete):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(PosixFileDelete)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketPosixFileRead)
+ASM_PFX(GasketPosixFileRead):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+
+  call    ASM_PFX(PosixFileRead)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+  
+ASM_GLOBAL ASM_PFX(GasketPosixFileWrite)
+ASM_PFX(GasketPosixFileWrite):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+
+  call    ASM_PFX(PosixFileWrite)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketPosixFileSetPossition)
+ASM_PFX(GasketPosixFileSetPossition):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+
+  call    ASM_PFX(PosixFileSetPossition)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketPosixFileGetPossition)
+ASM_PFX(GasketPosixFileGetPossition):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+
+  call    ASM_PFX(PosixFileGetPossition)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketPosixFileGetInfo)
+ASM_PFX(GasketPosixFileGetInfo):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+  movq    %r9,  %rcx
+
+  call    ASM_PFX(PosixFileGetInfo)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketPosixFileSetInfo)
+ASM_PFX(GasketPosixFileSetInfo):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+  movq    %r9,  %rcx
+
+  call    ASM_PFX(PosixFileSetInfo)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketPosixFileFlush)
+ASM_PFX(GasketPosixFileFlush):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(PosixFileFlush)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketPosixFileSystmeThunkOpen)
+ASM_PFX(GasketPosixFileSystmeThunkOpen):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(PosixFileSystmeThunkOpen)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketPosixFileSystmeThunkClose)
+ASM_PFX(GasketPosixFileSystmeThunkClose):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(PosixFileSystmeThunkClose)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+
+
+
+
+
diff --git a/InOsEmuPkg/Unix/Sec/X64/SwitchStack.S b/InOsEmuPkg/Unix/Sec/X64/SwitchStack.S
new file mode 100644 (file)
index 0000000..0d4e502
--- /dev/null
@@ -0,0 +1,112 @@
+#------------------------------------------------------------------------------\r
+#\r
+# Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+# Portitions copyright (c) 2011, Apple Inc. All rights reserved.\r
+# 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
+# Routine Description:\r
+#\r
+#   Routine for switching stacks with 3 parameters EFI ABI\r
+#   Convert UNIX to EFI ABI\r
+#\r
+# Arguments:\r
+#\r
+#   (rdi) EntryPoint    - Entry point with new stack.\r
+#   (rsi) Context1      - Parameter1 for entry point. (rcx)\r
+#   (rdx) Context2      - Parameter2 for entry point. (rdx) \r
+#   (rcx) Context3      - Parameter3 for entry point. (r8)\r
+#   (r8)  NewStack      - The pointer to new stack.\r
+#\r
+# Returns:\r
+#\r
+#   None\r
+#\r
+#------------------------------------------------------------------------------\r
+ASM_GLOBAL ASM_PFX(PeiSwitchStacks)\r
+ASM_PFX(PeiSwitchStacks):\r
+    pushq   $0            // tells gdb to stop unwinding frame\r
+    movq    %rsp, %rbp\r
+\r
+    movq    %r8,  %rsp\r
+    \r
+    movq    %rdi, %rax\r
+    movq    %rsi, %rcx\r
+    movq    %rcx, %r8    \r
+    \r
+    #\r
+    # Reserve space for register parameters (rcx, rdx, r8 & r9) on the stack,\r
+    # in case the callee wishes to spill them.\r
+    #\r
+    subq    $32, %rsp  // 32-byte shadow space plus alignment pad\r
+    call    *%rax\r
+\r
+  \r
+\r
+//  EFI_STATUS\r
+//  EFIAPI\r
+//  SecTemporaryRamSupport (\r
+//    IN CONST EFI_PEI_SERVICES   **PeiServices,         // %rcx\r
+//    IN EFI_PHYSICAL_ADDRESS     TemporaryMemoryBase,   // %rdx\r
+//    IN EFI_PHYSICAL_ADDRESS     PermanentMemoryBase,   // %r8 \r
+//    IN UINTN                    CopySize               // %r9\r
+//    )\r
+//\r
+ASM_GLOBAL ASM_PFX(GasketSecTemporaryRamSupport)\r
+ASM_PFX(GasketSecTemporaryRamSupport):\r
+  // Adjust callers %rbp to account for stack move\r
+  subq    %rdx, %rbp     // Calc offset of %rbp in Temp Memory\r
+  addq    %r8,  %rbp     // add in permanent base to offset\r
+  \r
+  pushq   %rbp           // stack frame is for the debugger\r
+  movq    %rsp, %rbp\r
+\r
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI\r
+  pushq   %rdi\r
+\r
+  pushq   %rdx          // Save TemporaryMemoryBase\r
+  pushq   %r8           // Save PermanentMemoryBase\r
+  pushq   %r9           // Save CopySize\r
+  \r
+  //\r
+  // Copy all of temp RAM to permanent memory, including stack\r
+  //\r
+  // CopyMem (PermanentMemoryBase, TemporaryMemoryBase, CopySize);\r
+  //          %rdi,                %rsi,                %rdx\r
+  movq    %r8,  %rdi    // Swizzle args  \r
+  movq    %rdx, %rsi\r
+  movq    %r9,  %rdx\r
+  call    ASM_PFX(CopyMem)\r
+  // Temp mem stack now copied to permanent location. %esp still in temp memory\r
+  \r
+  popq    %r9           // CopySize (old stack)\r
+  popq    %r8           // PermanentMemoryBase (old stack)\r
+  popq    %rdx          // TemporaryMemoryBase (old stack)\r
+    \r
+  movq    %rsp, %rcx    // Move to new stack\r
+  subq    %rdx, %rcx    // Calc offset of stack in Temp Memory\r
+  addq    %r8,  %rcx    // Calc PermanentMemoryBase address\r
+  movq    %rcx, %rsp    // Update stack \r
+  // Stack now points to permanent memory\r
+  \r
+  // ZeroMem (TemporaryMemoryBase /* rdi */, CopySize /* rsi */);\r
+  movq    %rdx, %rdi\r
+  movq    %r9,  %rsi\r
+  call    ASM_PFX(ZeroMem)\r
+\r
+  // This data comes off the NEW stack\r
+  popq    %rdi   \r
+  popq    %rsi\r
+  popq    %rbp\r
+  ret\r
+\r
+\r
diff --git a/InOsEmuPkg/Unix/UnixX64.dsc b/InOsEmuPkg/Unix/UnixX64.dsc
new file mode 100644 (file)
index 0000000..88c4218
--- /dev/null
@@ -0,0 +1,377 @@
+## @file\r
+#\r
+# EFI/Framework Emulation Platform with UEFI HII interface supported.\r
+#\r
+# The Emulation Platform can be used to debug individual modules, prior to creating\r
+#       a real platform. This also provides an example for how an DSC is created.\r
+# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2010 - 2011, Apple Inc. All rights reserved.<BR>\r
+#\r
+#    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 Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  PLATFORM_NAME                  = EmuUnix\r
+  PLATFORM_GUID                  = 05FD064D-1073-E844-936C-A0E16317107D\r
+  PLATFORM_VERSION               = 0.3\r
+  DSC_ SPECIFICATION             = 0x00010005\r
+  OUTPUT_DIRECTORY               = Build/EmuUnixX64\r
+  SUPPORTED_ARCHITECTURES        = X64\r
+  BUILD_TARGETS                  = DEBUG|RELEASE\r
+  SKUID_IDENTIFIER               = DEFAULT\r
+  FLASH_DEFINITION               = InOsEmuPkg/Unix/UnixX64.fdf\r
+\r
+################################################################################\r
+#\r
+# SKU Identification section - list of all SKU IDs supported by this Platform.\r
+#\r
+################################################################################\r
+[SkuIds]\r
+  0|DEFAULT\r
+\r
+################################################################################\r
+#\r
+# Library Class section - list of all Library Classes needed by this Platform.\r
+#\r
+################################################################################\r
+[LibraryClasses]\r
+  #\r
+  # Entry point\r
+  #\r
+  PeiCoreEntryPoint|MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf\r
+  PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf\r
+  DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf\r
+  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf\r
+  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf\r
+  #\r
+  # Basic\r
+  #\r
+  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf\r
+  SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf\r
+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf\r
+  CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf\r
+  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf\r
+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf\r
+  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf\r
+\r
+  #\r
+  # UEFI & PI\r
+  #\r
+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf\r
+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
+  UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf\r
+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf\r
+  UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf\r
+  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf\r
+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
+  UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf\r
+\r
+  PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf\r
+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf\r
+  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
+  #\r
+  # Generic Modules\r
+  #\r
+  UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf\r
+  NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf\r
+  IpIoLib|MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.inf\r
+  UdpIoLib|MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf\r
+  DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf\r
+  OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf\r
+  GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf\r
+  SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf\r
+  TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf\r
+  SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf\r
+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf\r
+  #\r
+  # Platform\r
+  #\r
+  PlatformBdsLib|InOsEmuPkg/Library/EmuBdsLib/EmuBdsLib.inf\r
+  KeyMapLib|InOsEmuPkg/Library/KeyMapLibNull/KeyMapLibNull.inf\r
+  \r
+  #\r
+  # Misc\r
+  #\r
+  DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf\r
+  PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf\r
+  DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf\r
+  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf\r
+\r
+\r
+[LibraryClasses.common.USER_DEFINED, LibraryClasses.common.BASE]\r
+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf\r
+  PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf\r
+  MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf\r
+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf\r
+\r
+  ThunkPpiList|InOsEmuPkg/Library/ThunkPpiList/ThunkPpiList.inf\r
+  ThunkProtocolList|InOsEmuPkg/Library/ThunkProtocolList/ThunkProtocolList.inf\r
+\r
+\r
+[LibraryClasses.common.PEIM, LibraryClasses.common.PEI_CORE]\r
+  HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf\r
+  MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf\r
+  ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf\r
+  PeCoffGetEntryPointLib|InOsEmuPkg/Library/PeiEmuPeCoffGetEntryPointLib/PeiEmuPeCoffGetEntryPointLib.inf\r
+  PeCoffExtraActionLib|InOsEmuPkg/Library/PeiEmuPeCoffExtraActionLib/PeiEmuPeCoffExtraActionLib.inf\r
+  ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf\r
+\r
+[LibraryClasses.common.PEI_CORE]\r
+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  PeiServicesTablePointerLib|InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiCoreServicesTablePointerLib.inf\r
+  SerialPortLib|InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf\r
+\r
+[LibraryClasses.common.PEIM]\r
+  PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf\r
+  PeiServicesTablePointerLib|InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf\r
+\r
+[LibraryClasses.common.DXE_CORE]\r
+  HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf\r
+  MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf\r
+  ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf\r
+  PeCoffExtraActionLib|InOsEmuPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.inf\r
+  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf\r
+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+\r
+[LibraryClasses.common.DXE_RUNTIME_DRIVER, LibraryClasses.common.UEFI_DRIVER, LibraryClasses.common.DXE_DRIVER, LibraryClasses.common.UEFI_APPLICATION]\r
+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
+  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
+  ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf\r
+  EmuThunkLib|InOsEmuPkg/Library/DxeEmuLib/DxeEmuLib.inf\r
+  PeCoffExtraActionLib|InOsEmuPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.inf\r
+\r
+[LibraryClasses.common.UEFI_DRIVER]\r
+  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
\r
+[LibraryClasses.common.UEFI_APPLICATION]\r
+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+\r
+\r
+################################################################################\r
+#\r
+# Pcd Section - list of all EDK II PCD Entries defined by this Platform.\r
+#\r
+################################################################################\r
+[PcdsFeatureFlag]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode|FALSE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial|TRUE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreImageLoaderSearchTeSectionFirst|FALSE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE\r
+\r
+[PcdsFixedAtBuild]\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000040\r
+  gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x0f\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x1f\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxSizeNonPopulateCapsule|0x0\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxSizePopulateCapsule|0x0\r
+\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFirmwareFdSize|0x002a0000\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFirmwareBlockSize|0x10000\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFirmwareVolume|L"../Fv/Fv_Recovery.fd"\r
+  \r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuMemorySizeForSecMain|L"64!64"\r
+  \r
+#define BOOT_WITH_FULL_CONFIGURATION                  0x00\r
+#define BOOT_WITH_MINIMAL_CONFIGURATION               0x01\r
+#define BOOT_ASSUMING_NO_CONFIGURATION_CHANGES        0x02\r
+#define BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS 0x03\r
+#define BOOT_WITH_DEFAULT_SETTINGS                    0x04\r
+#define BOOT_ON_S4_RESUME                             0x05\r
+#define BOOT_ON_S5_RESUME                             0x06\r
+#define BOOT_ON_S2_RESUME                             0x10\r
+#define BOOT_ON_S3_RESUME                             0x11\r
+#define BOOT_ON_FLASH_UPDATE                          0x12\r
+#define BOOT_IN_RECOVERY_MODE                         0x20\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuBootMode|0\r
+  \r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuApCount|L"0"\r
+\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuPhysicalDisk|L"E:RW;245760;512"\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuVirtualDisk|L"FW;40960;512"\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuGop|L"GOP Window"\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuFileSystem|L".!../../../../ShellBinPkg/UefiShell/X64!../../../../Build/Shell/DEBUG_XCLANG"\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuSerialPort|L"/dev/ttyS0"\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuNetworkInterface|L"en0"\r
+\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuCpuModel|L"Intel(R) Processor Model"\r
+  gInOsEmuPkgTokenSpaceGuid.PcdEmuCpuSpeed|L"3000"\r
+\r
+################################################################################\r
+#\r
+# Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Platform\r
+#\r
+################################################################################\r
+\r
+[PcdsDynamicDefault.common.DEFAULT]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64|0\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64|0\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0\r
+\r
+[PcdsDynamicHii.common.DEFAULT]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn|L"Setup"|gEmuSystemConfigGuid|0x0|80\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutRow|L"Setup"|gEmuSystemConfigGuid|0x4|25\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdPlatformBootTimeOut|L"Timeout"|gEfiGlobalVariableGuid|0x0|10\r
+\r
+\r
+###################################################################################################\r
+#\r
+# Components Section - list of the modules and components that will be processed by compilation\r
+#                      tools and the EDK II tools to generate PE32/PE32+/Coff image files.\r
+#\r
+# Note: The EDK II DSC file is not used to specify how compiled binary images get placed\r
+#       into firmware volume images. This section is just a list of modules to compile from\r
+#       source into UEFI-compliant binaries.\r
+#       It is the FDF file that contains information on combining binary files into firmware\r
+#       volume images, whose concept is beyond UEFI and is described in PI specification.\r
+#       Binary modules do not need to be listed in this section, as they should be\r
+#       specified in the FDF file. For example: Shell binary (Shell_Full.efi), FAT binary (Fat.efi),\r
+#       Logo (Logo.bmp), and etc.\r
+#       There may also be modules listed in this section that are not required in the FDF file,\r
+#       When a module listed here is excluded from FDF file, then UEFI-compliant binary will be\r
+#       generated for it, but the binary will not be put into any firmware volume.\r
+#\r
+###################################################################################################\r
+[Components]\r
+!if $(SEC_ONLY)\r
+  ##\r
+  #  SEC Phase modules\r
+  ##\r
+  InOsEmuPkg/Unix/Sec/SecMain.inf\r
+!else\r
+  ##\r
+  #  PEI Phase modules\r
+  ##\r
+  MdeModulePkg/Core/Pei/PeiMain.inf\r
+  MdeModulePkg/Universal/PCD/Pei/Pcd.inf  {\r
+   <LibraryClasses>\r
+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  }\r
+  MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf\r
+  MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf {\r
+   <LibraryClasses>\r
+      SerialPortLib|InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf\r
+  }\r
+  \r
+  IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf\r
+  InOsEmuPkg/BootModePei/BootModePei.inf\r
+  MdeModulePkg/Universal/Variable/Pei/VariablePei.inf\r
+  InOsEmuPkg/AutoScanPei/AutoScanPei.inf\r
+  InOsEmuPkg/FirmwareVolumePei/FirmwareVolumePei.inf\r
+  InOsEmuPkg/FlashMapPei/FlashMapPei.inf\r
+  InOsEmuPkg/ThunkPpiToProtocolPei/ThunkPpiToProtocolPei.inf\r
+  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf {\r
+    <LibraryClasses>\r
+      # turn off CR3 write so that DXE IPL will not crash emulator\r
+      BaseLib|UnixPkg/Library/UnixBaseLib/UnixBaseLib.inf\r
+  }\r
+\r
+  ##\r
+  #  DXE Phase modules\r
+  ##\r
+  MdeModulePkg/Core/Dxe/DxeMain.inf {\r
+    <LibraryClasses>\r
+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf\r
+      NULL|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf\r
+  }\r
+  MdeModulePkg/Universal/PCD/Dxe/Pcd.inf {\r
+    <LibraryClasses>\r
+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  }\r
+\r
+  MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf\r
+  MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf {\r
+   <LibraryClasses>\r
+      SerialPortLib|InOsEmuPkg/Library/DxeEmuSerialPortLib/DxeEmuSerialPortLib.inf    \r
+  }\r
+\r
+  InOsEmuPkg/MetronomeDxe/Metronome.inf\r
+  InOsEmuPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf\r
+  InOsEmuPkg/ResetRuntimeDxe/Reset.inf\r
+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf\r
+  InOsEmuPkg/FvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf\r
+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf\r
+  MdeModulePkg/Universal/EbcDxe/EbcDxe.inf\r
+  MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf\r
+  InOsEmuPkg/EmuThunkDxe/EmuThunk.inf\r
+  InOsEmuPkg/CpuRuntimeDxe/Cpu.inf\r
+  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf\r
+  InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf\r
+  InOsEmuPkg/TimerDxe/Timer.inf\r
+\r
+\r
+  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf\r
+  MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf\r
+  MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf\r
+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf\r
+  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf\r
+  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf\r
+  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf\r
+  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf\r
+  IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf\r
+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf\r
+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf\r
+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf\r
+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf\r
+  MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf\r
+  MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf\r
+  MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf\r
+  IntelFrameworkModulePkg/Bus/Pci/IdeBusDxe/IdeBusDxe.inf\r
+\r
+  InOsEmuPkg/EmuBusDriverDxe/EmuBusDriverDxe.inf\r
+  InOsEmuPkg/EmuGopDxe/EmuGopDxe.inf\r
+  InOsEmuPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystemDxe.inf\r
+\r
+!if $(0)\r
+  UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf\r
+  UnixPkg/UnixSerialIoDxe/UnixSerialIo.inf\r
+  UnixPkg/UnixConsoleDxe/UnixConsole.inf\r
+  UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.inf\r
+!endif\r
+\r
+  MdeModulePkg/Application/HelloWorld/HelloWorld.inf\r
+\r
+  #\r
+  # Network stack drivers\r
+  #\r
+##!if $(NETWORK_SUPPORT) & $(0)\r
+!if $(0)\r
+  UnixPkg/UnixSnpDxe/UnixSnpDxe.inf\r
+!endif\r
+  MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf\r
+  MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf\r
+  MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf\r
+  MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf\r
+  MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf\r
+  MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf\r
+  MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf\r
+  MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf\r
+  MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf\r
+  MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf\r
+\r
+  MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf\r
+  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf\r
+  MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf\r
+  MdeModulePkg/Universal/PrintDxe/PrintDxe.inf\r
+  MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf {\r
+    <LibraryClasses>\r
+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  }\r
+\r
+!if $(COMPILE_BINS)\r
+  FatPkg/EnhancedFatDxe/Fat.inf\r
+!endif\r
+!endif  \r
diff --git a/InOsEmuPkg/Unix/UnixX64.fdf b/InOsEmuPkg/Unix/UnixX64.fdf
new file mode 100644 (file)
index 0000000..48d9179
--- /dev/null
@@ -0,0 +1,382 @@
+## @file\r
+# This is Unix FDF file with UEFI HII features enabled\r
+#\r
+# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2009 - 2011, Apple Inc. All rights reserved.<BR>\r
+#\r
+#    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
+# FD Section\r
+# The [FD] Section is made up of the definition statements and a\r
+# description of what goes into  the Flash Device Image.  Each FD section\r
+# defines one flash "device" image.  A flash device image may be one of\r
+# the following: Removable media bootable image (like a boot floppy\r
+# image,) an Option ROM image (that would be "flashed" into an add-in\r
+# card,) a System "Flash"  image (that would be burned into a system's\r
+# flash) or an Update ("Capsule") image that will be used to update and\r
+# existing system flash.\r
+#\r
+################################################################################\r
+[FD.Fv_Recovery]\r
+#\r
+# In OS X PEIMs are really XIP, so we need to make this address match the malloced \r
+# buffer for the FD (0x41000000). If this address does not match the FV will get\r
+# relocated in place (works, but not a great idea).\r
+#\r
+BaseAddress   = 0x102000000|gInOsEmuPkgTokenSpaceGuid.PcdEmuFdBaseAddress   #The base address of the FLASH Device.\r
+Size          = 0x005a0000|gInOsEmuPkgTokenSpaceGuid.PcdEmuFirmwareFdSize  #The size in bytes of the FLASH Device\r
+ErasePolarity = 1\r
+BlockSize     = 0x10000\r
+NumBlocks     = 0x5a\r
+\r
+################################################################################\r
+#\r
+# Following are lists of FD Region layout which correspond to the locations of different\r
+# images within the flash device.\r
+#\r
+# Regions must be defined in ascending order and may not overlap.\r
+#\r
+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by\r
+# the pipe "|" character, followed by the size of the region, also in hex with the leading\r
+# "0x" characters. Like:\r
+# Offset|Size\r
+# PcdOffsetCName|PcdSizeCName\r
+# RegionType <FV, DATA, or FILE>\r
+#\r
+################################################################################\r
+0x00000000|0x00580000\r
+gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashFvRecoveryBase|gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashFvRecoverySize\r
+FV = FvRecovery\r
+\r
+0x00580000|0x0000c000\r
+gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageVariableBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize\r
+#NV_VARIABLE_STORE\r
+DATA = {\r
+  ## This is the EFI_FIRMWARE_VOLUME_HEADER\r
+  # ZeroVector []\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  # FileSystemGuid: gEfiSystemNvDataFvGuid         =\r
+  #  { 0xFFF12B8D, 0x7696, 0x4C8B, { 0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50 }}\r
+  0x8D, 0x2B, 0xF1, 0xFF, 0x96, 0x76, 0x8B, 0x4C,\r
+  0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50,\r
+  # FvLength: 0x20000\r
+  0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  # Signature "_FVH"       #Attributes\r
+  0x5f, 0x46, 0x56, 0x48, 0xff, 0xfe, 0x04, 0x00,\r
+  # HeaderLength #CheckSum #ExtHeaderOffset #Reserved #Revision\r
+  0x48, 0x00, 0x36, 0x09, 0x00, 0x00, 0x00, 0x02,\r
+  # Blockmap[0]: 2 Blocks * 0x10000 Bytes / Block\r
+  0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,\r
+  # Blockmap[1]: End\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  ## This is the VARIABLE_STORE_HEADER\r
+  #Signature: gEfiVariableGuid =\r
+  #  { 0xddcf3616, 0x3275, 0x4164, { 0x98, 0xb6, 0xfe, 0x85, 0x70, 0x7f, 0xfe, 0x7d }}\r
+  0x16, 0x36, 0xcf, 0xdd, 0x75, 0x32, 0x64, 0x41,\r
+  0x98, 0xb6, 0xfe, 0x85, 0x70, 0x7f, 0xfe, 0x7d,\r
+  #Size: 0xc000 (gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize) - 0x48 (size of EFI_FIRMWARE_VOLUME_HEADER) = 0xBFB8\r
+  # This can speed up the Variable Dispatch a bit.\r
+  0xB8, 0xBF, 0x00, 0x00,\r
+  #FORMATTED: 0x5A #HEALTHY: 0xFE #Reserved: UINT16 #Reserved1: UINT32\r
+  0x5A, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\r
+}\r
+\r
+0x0058c000|0x00002000\r
+#NV_EVENT_LOG\r
+gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageEventLogBase|gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageEventLogSize\r
+\r
+0x0058e000|0x00002000\r
+gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageFtwWorkingBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize\r
+#NV_FTW_WORKING\r
+DATA = {\r
+  # EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER->Signature = gEfiSystemNvDataFvGuid         =\r
+  #  { 0xFFF12B8D, 0x7696, 0x4C8B, { 0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50 }}\r
+  0x8D, 0x2B, 0xF1, 0xFF, 0x96, 0x76, 0x8B, 0x4C,\r
+  0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50,\r
+  # Crc:UINT32            #WorkingBlockValid:1, WorkingBlockInvalid:1, Reserved\r
+  0x77, 0x13, 0x9B, 0xD7, 0xFE, 0xFF, 0xFF, 0xFF,\r
+  # WriteQueueSize: UINT64\r
+  0xE0, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\r
+}\r
+\r
+0x00590000|0x00010000\r
+#NV_FTW_SPARE\r
+gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageFtwSpareBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize\r
+\r
+################################################################################\r
+#\r
+# FV Section\r
+#\r
+# [FV] section is used to define what components or modules are placed within a flash\r
+# device file.  This section also defines order the components and modules are positioned\r
+# within the image.  The [FV] section consists of define statements, set statements and\r
+# module statements.\r
+#\r
+################################################################################\r
+[FV.FvRecovery]\r
+FvAlignment        = 16         #FV alignment and FV attributes setting.\r
+ERASE_POLARITY     = 1\r
+MEMORY_MAPPED      = TRUE\r
+STICKY_WRITE       = TRUE\r
+LOCK_CAP           = TRUE\r
+LOCK_STATUS        = TRUE\r
+WRITE_DISABLED_CAP = TRUE\r
+WRITE_ENABLED_CAP  = TRUE\r
+WRITE_STATUS       = TRUE\r
+WRITE_LOCK_CAP     = TRUE\r
+WRITE_LOCK_STATUS  = TRUE\r
+READ_DISABLED_CAP  = TRUE\r
+READ_ENABLED_CAP   = TRUE\r
+READ_STATUS        = TRUE\r
+READ_LOCK_CAP      = TRUE\r
+READ_LOCK_STATUS   = TRUE\r
+\r
+################################################################################\r
+#\r
+# The INF statements point to EDK component and EDK II module INF files, which will be placed into this FV image.\r
+# Parsing tools will scan the INF file to determine the type of component or module.\r
+# The component or module type is used to reference the standard rules\r
+# defined elsewhere in the FDF file.\r
+#\r
+# The format for INF statements is:\r
+# INF $(PathAndInfFileName)\r
+#\r
+################################################################################\r
+##\r
+#  PEI Phase modules\r
+##\r
+##\r
+#  PEI Apriori file example, more PEIM module added later.\r
+##\r
+APRIORI PEI {\r
+  INF  MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf\r
+  INF  MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf\r
+  INF  MdeModulePkg/Universal/PCD/Pei/Pcd.inf\r
+  }\r
+APRIORI DXE {\r
+  INF  MdeModulePkg/Universal/PCD/Dxe/Pcd.inf\r
+  INF  InOsEmuPkg/MetronomeDxe/Metronome.inf\r
+  }\r
+INF  MdeModulePkg/Core/Pei/PeiMain.inf\r
+INF  MdeModulePkg/Universal/PCD/Pei/Pcd.inf\r
+INF  MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf\r
+INF  MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf\r
+INF  InOsEmuPkg/BootModePei/BootModePei.inf\r
+INF  InOsEmuPkg/AutoScanPei/AutoScanPei.inf\r
+INF  InOsEmuPkg/FirmwareVolumePei/FirmwareVolumePei.inf\r
+INF  InOsEmuPkg/FlashMapPei/FlashMapPei.inf\r
+INF  InOsEmuPkg/ThunkPpiToProtocolPei/ThunkPpiToProtocolPei.inf\r
+INF  MdeModulePkg/Universal/Variable/Pei/VariablePei.inf\r
+INF  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf\r
+\r
+##\r
+#  DXE Phase modules\r
+##\r
+INF  MdeModulePkg/Core/Dxe/DxeMain.inf\r
+INF  MdeModulePkg/Universal/PCD/Dxe/Pcd.inf  \r
+INF  MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf\r
+INF  MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf\r
+INF  InOsEmuPkg/MetronomeDxe/Metronome.inf\r
+INF  InOsEmuPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf\r
+INF  InOsEmuPkg/ResetRuntimeDxe/Reset.inf\r
+INF  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf\r
+INF  InOsEmuPkg/FvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf\r
+INF  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf\r
+INF  MdeModulePkg/Universal/EbcDxe/EbcDxe.inf\r
+INF  MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf\r
+INF  InOsEmuPkg/EmuThunkDxe/EmuThunk.inf\r
+INF  InOsEmuPkg/CpuRuntimeDxe/Cpu.inf\r
+INF  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf\r
+INF  InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf\r
+INF  InOsEmuPkg/TimerDxe/Timer.inf\r
+INF  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf\r
+INF  MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf\r
+INF  MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf\r
+INF  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf\r
+INF  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf\r
+INF  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf\r
+INF  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf\r
+INF  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf\r
+INF  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf\r
+INF  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf\r
+INF  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf\r
+INF  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf\r
+INF  MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf\r
+INF  MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf\r
+INF  MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf\r
+INF  IntelFrameworkModulePkg/Bus/Pci/IdeBusDxe/IdeBusDxe.inf\r
+INF  MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf\r
+\r
+INF  InOsEmuPkg/EmuBusDriverDxe/EmuBusDriverDxe.inf \r
+INF  InOsEmuPkg/EmuGopDxe/EmuGopDxe.inf\r
+INF  InOsEmuPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystemDxe.inf\r
+\r
+#INF  UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf\r
+#INF  UnixPkg/UnixSerialIoDxe/UnixSerialIo.inf\r
+INF  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf\r
+INF  MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf\r
+INF  MdeModulePkg/Universal/PrintDxe/PrintDxe.inf\r
+INF  IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf \r
+INF  MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf\r
+INF  MdeModulePkg/Application/HelloWorld/HelloWorld.inf\r
+\r
+#\r
+# Network stack drivers\r
+#\r
+!if $(NETWORK_SUPPORT)\r
+#INF  UnixPkg/UnixSnpDxe/UnixSnpDxe.inf\r
+!endif\r
+INF  MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf\r
+INF  MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf\r
+INF  MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf\r
+INF  MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf\r
+INF  MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf\r
+INF  MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf\r
+INF  MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf\r
+INF  MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf\r
+INF  MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf\r
+INF  MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf\r
+\r
\r
+!if $(COMPILE_BINS)\r
+INF FatPkg/EnhancedFatDxe/Fat.inf\r
+!else\r
+# Used checked in Visual Studio binaries\r
+INF  RuleOverride = BINARY USE = X64 FatBinPkg/EnhancedFatDxe/Fat.inf\r
+!endif\r
+\r
+ FILE APPLICATION = PCD(gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile) {\r
+#  SECTION PE32 = ShellBinPkg/UefiShell/X64/Shell.efi\r
+  SECTION PE32 = Build/GccShellPkg/DEBUG_XCLANG/X64/ShellFull.efi\r
+  SECTION UI = "Shell"\r
+ }\r
+\r
+FILE FREEFORM = PCD(gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdLogoFile) {\r
+  SECTION RAW = MdeModulePkg/Logo/Logo.bmp\r
+}\r
+   \r
+   \r
+################################################################################\r
+#  \r
+# Rules are use with the [FV] section's module INF type to define\r
+# how an FFS file is created for a given INF file. The following Rule are the default\r
+# rules for the different module type. User can add the customized rules to define the\r
+# content of the FFS file.\r
+#  \r
+################################################################################\r
+   \r
+   \r
+############################################################################\r
+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   # \r
+############################################################################\r
+#  \r
+#[Rule.Common.DXE_DRIVER]\r
+#  FILE DRIVER = $(NAMED_GUID) {\r
+#    DXE_DEPEX    DXE_DEPEX Optional      $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+#    COMPRESS PI_STD {\r
+#      GUIDED {\r
+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+#        UI       STRING="$(MODULE_NAME)" Optional\r
+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+#      }\r
+#    }\r
+#  }\r
+#\r
+############################################################################\r
+\r
+[Rule.Common.PEI_CORE]\r
+  FILE PEI_CORE = $(NAMED_GUID) {\r
+    PE32     PE32    Align=32       $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI       STRING ="$(MODULE_NAME)" Optional         \r
+    VERSION  STRING ="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)    \r
+  }\r
+\r
+[Rule.Common.PEIM]\r
+  FILE PEIM = $(NAMED_GUID) {\r
+     PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+     PE32      PE32   Align=32       $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+     UI       STRING="$(MODULE_NAME)" Optional         \r
+     VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)   \r
+  }\r
+\r
+[Rule.Common.DXE_CORE]\r
+  FILE DXE_CORE = $(NAMED_GUID) {\r
+    COMPRESS PI_STD {\r
+      PE32     PE32           $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+      UI       STRING="$(MODULE_NAME)" Optional\r
+      VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+    }\r
+  }\r
+\r
+[Rule.Common.UEFI_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX Optional      $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    COMPRESS PI_STD {\r
+      GUIDED {\r
+        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+        UI       STRING="$(MODULE_NAME)" Optional\r
+        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+      }\r
+    }\r
+  }\r
+\r
+[Rule.Common.DXE_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX Optional      $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    COMPRESS PI_STD {\r
+      GUIDED {\r
+        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+        UI       STRING="$(MODULE_NAME)" Optional\r
+        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+      }\r
+    }\r
+  }\r
+\r
+[Rule.Common.DXE_RUNTIME_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX Optional      $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    COMPRESS PI_STD {\r
+      GUIDED {\r
+        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+        UI       STRING="$(MODULE_NAME)" Optional\r
+        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+      }\r
+    }\r
+  }\r
+\r
+[Rule.Common.UEFI_APPLICATION]\r
+  FILE APPLICATION = $(NAMED_GUID) {\r
+    COMPRESS PI_STD {\r
+      GUIDED {\r
+        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+        UI       STRING="$(MODULE_NAME)" Optional\r
+        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+      }\r
+    }\r
+  }\r
+\r
+[Rule.Common.UEFI_DRIVER.BINARY]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX DXE_DEPEX Optional      |.depex\r
+    PE32      PE32                    |.efi\r
+    UI        STRING="$(MODULE_NAME)" Optional\r
+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+  }\r
+\r
+[Rule.Common.UEFI_APPLICATION.BINARY]\r
+  FILE APPLICATION = $(NAMED_GUID) {\r
+    PE32      PE32                    |.efi\r
+    UI        STRING="$(MODULE_NAME)" Optional\r
+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+  }\r
+\r
diff --git a/InOsEmuPkg/Unix/Xcode/xcode_project64/XcodeBuild.sh b/InOsEmuPkg/Unix/Xcode/xcode_project64/XcodeBuild.sh
new file mode 100755 (executable)
index 0000000..634b1b0
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/bash
+#
+# External makefile Xcode project project uses this script to build and clean from the Xcode GUI
+#
+# Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
+#
+# 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.
+#
+
+# force exit on error
+set -e
+
+#
+# Source the workspace and set up the environment variables we need
+#
+cd ../..
+echo `pwd`
+./build64.sh $1 $2 $3 $4 $5 $6 $8
diff --git a/InOsEmuPkg/Unix/Xcode/xcode_project64/xcode_project.xcodeproj/default.pbxuser b/InOsEmuPkg/Unix/Xcode/xcode_project64/xcode_project.xcodeproj/default.pbxuser
new file mode 100644 (file)
index 0000000..c0d3198
--- /dev/null
@@ -0,0 +1,191 @@
+// !$*UTF8*$!
+{
+       08FB7793FE84155DC02AAC07 /* Project object */ = {
+               activeBuildConfigurationName = Debug;
+               activeExecutable = BA11A1010FB10BCE00D06FEC /* SecMain.dll */;
+               activeTarget = D28A88AD04BDD90700651E21 /* xcode_project */;
+               breakpoints = (
+                       BA11A11A0FB10E0700D06FEC /* SecGdbScriptBreak */,
+               );
+               codeSenseManager = BA11A0FE0FB10B4800D06FEC /* Code sense */;
+               executables = (
+                       BA11A1010FB10BCE00D06FEC /* SecMain.dll */,
+               );
+               perUserDictionary = {
+                       "PBXConfiguration.PBXBreakpointsDataSource.v1:1CA1AED706398EBD00589147" = {
+                               PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
+                               PBXFileTableDataSourceColumnSortingKey = PBXBreakpointsDataSource_BreakpointID;
+                               PBXFileTableDataSourceColumnWidthsKey = (
+                                       20,
+                                       20,
+                                       198,
+                                       20,
+                                       99,
+                                       99,
+                                       29,
+                                       20,
+                               );
+                               PBXFileTableDataSourceColumnsKey = (
+                                       PBXBreakpointsDataSource_ActionID,
+                                       PBXBreakpointsDataSource_TypeID,
+                                       PBXBreakpointsDataSource_BreakpointID,
+                                       PBXBreakpointsDataSource_UseID,
+                                       PBXBreakpointsDataSource_LocationID,
+                                       PBXBreakpointsDataSource_ConditionID,
+                                       PBXBreakpointsDataSource_IgnoreCountID,
+                                       PBXBreakpointsDataSource_ContinueID,
+                               );
+                       };
+                       PBXConfiguration.PBXFileTableDataSource3.PBXExecutablesDataSource = {
+                               PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
+                               PBXFileTableDataSourceColumnSortingKey = PBXExecutablesDataSource_NameID;
+                               PBXFileTableDataSourceColumnWidthsKey = (
+                                       22,
+                                       300,
+                                       229,
+                               );
+                               PBXFileTableDataSourceColumnsKey = (
+                                       PBXExecutablesDataSource_ActiveFlagID,
+                                       PBXExecutablesDataSource_NameID,
+                                       PBXExecutablesDataSource_CommentsID,
+                               );
+                       };
+                       PBXConfiguration.PBXFileTableDataSource3.PBXFileTableDataSource = {
+                               PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
+                               PBXFileTableDataSourceColumnSortingKey = PBXFileDataSource_Filename_ColumnID;
+                               PBXFileTableDataSourceColumnWidthsKey = (
+                                       20,
+                                       341,
+                                       20,
+                                       48,
+                                       43,
+                                       43,
+                                       20,
+                               );
+                               PBXFileTableDataSourceColumnsKey = (
+                                       PBXFileDataSource_FiletypeID,
+                                       PBXFileDataSource_Filename_ColumnID,
+                                       PBXFileDataSource_Built_ColumnID,
+                                       PBXFileDataSource_ObjectSize_ColumnID,
+                                       PBXFileDataSource_Errors_ColumnID,
+                                       PBXFileDataSource_Warnings_ColumnID,
+                                       PBXFileDataSource_Target_ColumnID,
+                               );
+                       };
+                       PBXPerProjectTemplateStateSaveDate = 263260969;
+                       PBXWorkspaceStateSaveDate = 263260969;
+               };
+               sourceControlManager = BA11A0FD0FB10B4800D06FEC /* Source Control */;
+               userBuildSettings = {
+               };
+       };
+       BA11A0FD0FB10B4800D06FEC /* Source Control */ = {
+               isa = PBXSourceControlManager;
+               fallbackIsa = XCSourceControlManager;
+               isSCMEnabled = 0;
+               repositoryNamesForRoots = {
+               };
+               scmConfiguration = {
+               };
+       };
+       BA11A0FE0FB10B4800D06FEC /* Code sense */ = {
+               isa = PBXCodeSenseManager;
+               indexTemplatePath = "";
+       };
+       BA11A1010FB10BCE00D06FEC /* SecMain.dll */ = {
+               isa = PBXExecutable;
+               activeArgIndices = (
+               );
+               argumentStrings = (
+               );
+               autoAttachOnCrash = 1;
+               breakpointsEnabled = 1;
+               configStateDict = {
+                       "PBXLSLaunchAction-0" = {
+                               PBXLSLaunchAction = 0;
+                               PBXLSLaunchStartAction = 1;
+                               PBXLSLaunchStdioStyle = 2;
+                               PBXLSLaunchStyle = 0;
+                               class = PBXLSRunLaunchConfig;
+                               commandLineArgs = (
+                               );
+                               displayName = "Executable Runner";
+                               environment = {
+                               };
+                               identifier = com.apple.Xcode.launch.runConfig;
+                               remoteHostInfo = "";
+                               startActionInfo = "";
+                       };
+                       "PBXLSLaunchAction-1" = {
+                               PBXLSLaunchAction = 1;
+                               PBXLSLaunchStartAction = 1;
+                               PBXLSLaunchStdioStyle = 2;
+                               PBXLSLaunchStyle = 0;
+                               class = PBXGDB_LaunchConfig;
+                               commandLineArgs = (
+                               );
+                               displayName = GDB;
+                               environment = {
+                               };
+                               identifier = com.apple.Xcode.launch.GDBMI_Config;
+                               remoteHostInfo = "";
+                               startActionInfo = "";
+                       };
+               };
+               customDataFormattersEnabled = 0;
+               dataTipCustomDataFormattersEnabled = 1;
+               dataTipShowTypeColumn = 1;
+               dataTipSortType = 0;
+               debuggerPlugin = GDBDebugging;
+               disassemblyDisplayState = 0;
+               dylibVariantSuffix = "";
+               enableDebugStr = 1;
+               environmentEntries = (
+               );
+               executableSystemSymbolLevel = 0;
+               executableUserSymbolLevel = 0;
+               launchableReference = BA11A1020FB10BCE00D06FEC /* SecMain.dll */;
+               libgmallocEnabled = 0;
+               name = SecMain.dll;
+               savedGlobals = {
+               };
+               showTypeColumn = 0;
+               sourceDirectories = (
+               );
+               startupPath = ../../../Build/UnixX64/DEBUG_UNIXPKG/X64;
+       };
+       BA11A1020FB10BCE00D06FEC /* SecMain.dll */ = {
+               isa = PBXFileReference;
+               lastKnownFileType = "compiled.mach-o.executable";
+               name = SecMain.dll;
+               path = ../../../Build/UnixX64/DEBUG_UNIXPKG/X64/SecMain;
+               sourceTree = SOURCE_ROOT;
+       };
+       BA11A11A0FB10E0700D06FEC /* SecGdbScriptBreak */ = {
+               isa = PBXSymbolicBreakpoint;
+               actions = (
+                       BA11A11E0FB10E2200D06FEC /* XCBreakpointCommandAction */,
+               );
+               breakpointStyle = 1;
+               continueAfterActions = 1;
+               countType = 0;
+               delayBeforeContinue = 0;
+               hitCount = 0;
+               ignoreCount = 0;
+               location = SecMain;
+               modificationTime = 263261853.260195;
+               originalNumberOfMultipleMatches = 1;
+               state = 1;
+               symbolName = SecGdbScriptBreak;
+       };
+       BA11A11E0FB10E2200D06FEC /* XCBreakpointCommandAction */ = {
+               isa = XCBreakpointCommandAction;
+               command = "source SecMain.gdb";
+               fallbackIsa = XCBreakpointAction;
+               logCommand = 0;
+               useDebuggerSideImplementation = 1;
+       };
+       D28A88AD04BDD90700651E21 /* xcode_project */ = {
+               activeExec = 0;
+       };
+}
diff --git a/InOsEmuPkg/Unix/Xcode/xcode_project64/xcode_project.xcodeproj/project.pbxproj b/InOsEmuPkg/Unix/Xcode/xcode_project64/xcode_project.xcodeproj/project.pbxproj
new file mode 100644 (file)
index 0000000..9bd13bd
--- /dev/null
@@ -0,0 +1,124 @@
+// !$*UTF8*$!
+{
+       archiveVersion = 1;
+       classes = {
+       };
+       objectVersion = 45;
+       objects = {
+
+/* Begin PBXGroup section */
+               08FB7794FE84155DC02AAC07 /* xcode_project */ = {
+                       isa = PBXGroup;
+                       children = (
+                       );
+                       name = xcode_project;
+                       sourceTree = "<group>";
+               };
+/* End PBXGroup section */
+
+/* Begin PBXLegacyTarget section */
+               D28A88AD04BDD90700651E21 /* xcode_project */ = {
+                       isa = PBXLegacyTarget;
+                       buildArgumentsString = "$(ACTION)";
+                       buildConfigurationList = 1DEB918F08733D9F0010E9CD /* Build configuration list for PBXLegacyTarget "xcode_project" */;
+                       buildPhases = (
+                       );
+                       buildToolPath = ./XcodeBuild.sh;
+                       buildWorkingDirectory = "";
+                       dependencies = (
+                       );
+                       name = xcode_project;
+                       passBuildSettingsInEnvironment = 1;
+                       productName = xcode_project;
+               };
+/* End PBXLegacyTarget section */
+
+/* Begin PBXProject section */
+               08FB7793FE84155DC02AAC07 /* Project object */ = {
+                       isa = PBXProject;
+                       buildConfigurationList = 1DEB919308733D9F0010E9CD /* Build configuration list for PBXProject "xcode_project" */;
+                       compatibilityVersion = "Xcode 3.1";
+                       developmentRegion = English;
+                       hasScannedForEncodings = 1;
+                       knownRegions = (
+                               English,
+                               Japanese,
+                               French,
+                               German,
+                       );
+                       mainGroup = 08FB7794FE84155DC02AAC07 /* xcode_project */;
+                       projectDirPath = "";
+                       projectRoot = "";
+                       targets = (
+                               D28A88AD04BDD90700651E21 /* xcode_project */,
+                       );
+               };
+/* End PBXProject section */
+
+/* Begin XCBuildConfiguration section */
+               1DEB919008733D9F0010E9CD /* Debug */ = {
+                       isa = XCBuildConfiguration;
+                       buildSettings = {
+                               PRODUCT_NAME = xcode_project;
+                       };
+                       name = Debug;
+               };
+               1DEB919108733D9F0010E9CD /* Release */ = {
+                       isa = XCBuildConfiguration;
+                       buildSettings = {
+                               COPY_PHASE_STRIP = YES;
+                               GCC_ENABLE_FIX_AND_CONTINUE = NO;
+                               OTHER_CFLAGS = "";
+                               OTHER_LDFLAGS = "";
+                               PRODUCT_NAME = xcode_project;
+                       };
+                       name = Release;
+               };
+               1DEB919408733D9F0010E9CD /* Debug */ = {
+                       isa = XCBuildConfiguration;
+                       buildSettings = {
+                               ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+                               GCC_WARN_ABOUT_RETURN_TYPE = YES;
+                               GCC_WARN_UNUSED_VARIABLE = YES;
+                               ONLY_ACTIVE_ARCH = YES;
+                               PREBINDING = NO;
+                               SDKROOT = macosx10.6;
+                       };
+                       name = Debug;
+               };
+               1DEB919508733D9F0010E9CD /* Release */ = {
+                       isa = XCBuildConfiguration;
+                       buildSettings = {
+                               ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+                               GCC_WARN_ABOUT_RETURN_TYPE = YES;
+                               GCC_WARN_UNUSED_VARIABLE = YES;
+                               PREBINDING = NO;
+                               SDKROOT = macosx10.6;
+                       };
+                       name = Release;
+               };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+               1DEB918F08733D9F0010E9CD /* Build configuration list for PBXLegacyTarget "xcode_project" */ = {
+                       isa = XCConfigurationList;
+                       buildConfigurations = (
+                               1DEB919008733D9F0010E9CD /* Debug */,
+                               1DEB919108733D9F0010E9CD /* Release */,
+                       );
+                       defaultConfigurationIsVisible = 0;
+                       defaultConfigurationName = Release;
+               };
+               1DEB919308733D9F0010E9CD /* Build configuration list for PBXProject "xcode_project" */ = {
+                       isa = XCConfigurationList;
+                       buildConfigurations = (
+                               1DEB919408733D9F0010E9CD /* Debug */,
+                               1DEB919508733D9F0010E9CD /* Release */,
+                       );
+                       defaultConfigurationIsVisible = 0;
+                       defaultConfigurationName = Release;
+               };
+/* End XCConfigurationList section */
+       };
+       rootObject = 08FB7793FE84155DC02AAC07 /* Project object */;
+}
diff --git a/InOsEmuPkg/Unix/build64.sh b/InOsEmuPkg/Unix/build64.sh
new file mode 100755 (executable)
index 0000000..e575a92
--- /dev/null
@@ -0,0 +1,132 @@
+#!/bin/bash
+#
+# Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
+# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+#
+# 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.
+#
+
+set -e
+shopt -s nocasematch
+
+
+#
+# Setup workspace if it is not set
+#
+if [ -z "$WORKSPACE" ]
+then
+  echo Initializing workspace
+  if [ ! -e `pwd`/edksetup.sh ]
+  then
+    cd ../..
+  fi
+# This version is for the tools in the BaseTools project.
+# this assumes svn pulls have the same root dir
+#  export EDK_TOOLS_PATH=`pwd`/../BaseTools
+# This version is for the tools source in edk2
+  export EDK_TOOLS_PATH=`pwd`/BaseTools
+  echo $EDK_TOOLS_PATH
+  source edksetup.sh BaseTools
+else
+  echo Building from: $WORKSPACE
+fi
+
+#
+# Pick a default tool type for a given OS
+#
+TARGET_TOOLS=MYTOOLS
+UNIXPKG_TOOLS=GCC44
+NETWORK_SUPPORT=
+COMPILE_BINS=
+case `uname` in
+  CYGWIN*) echo Cygwin not fully supported yet. ;;
+  Darwin*)
+      Major=$(uname -r | cut -f 1 -d '.')
+      if [[ $Major == 9 ]]
+      then
+        echo UnixPkg requires Snow Leopard or later OS
+        exit 1
+      else
+        TARGET_TOOLS=XCODE32
+        UNIXPKG_TOOLS=XCLANG
+      fi
+      NETWORK_SUPPORT="-D NETWORK_SUPPORT"
+      COMPILE_BINS="-D COMPILE_BINS"
+      ;;
+  Linux*) TARGET_TOOLS=ELFGCC ;;
+
+esac
+
+BUILD_ROOT_ARCH=$WORKSPACE/Build/EmuUnixX64/DEBUG_"$UNIXPKG_TOOLS"/X64
+
+if  [[ ! -f `which build` || ! -f `which GenFv` ]];
+then
+  # build the tools if they don't yet exist. Bin scheme
+  echo Building tools as they are not in the path
+  make -C $WORKSPACE/BaseTools
+elif [[ ( -f `which build` ||  -f `which GenFv` )  && ! -d  $EDK_TOOLS_PATH/Source/C/bin ]];
+then
+  # build the tools if they don't yet exist. BinWrapper scheme
+  echo Building tools no $EDK_TOOLS_PATH/Source/C/bin directory
+  make -C $WORKSPACE/BaseTools
+else
+  echo using prebuilt tools
+fi
+
+
+for arg in "$@"
+do
+  if [[ $arg == run ]]; then
+    case `uname` in
+      Darwin*)
+        #
+        # On Darwin we can't use dlopen, so we have to load the real PE/COFF images.
+        # This .gdbinit script sets a breakpoint that loads symbols for the PE/COFFEE
+        # images that get loaded in SecMain
+        #
+        cp $WORKSPACE/InOsEmuPkg/Unix/.gdbinit $WORKSPACE/Build/EmuUnixX64/DEBUG_"$UNIXPKG_TOOLS"/X64
+        ;;
+    esac
+
+    /usr/bin/gdb $BUILD_ROOT_ARCH/SecMain -q -cd=$BUILD_ROOT_ARCH
+    exit
+  fi
+
+  if [[ $arg == cleanall ]]; then
+    make -C $WORKSPACE/BaseTools clean
+    build -p $WORKSPACE/InOsEmuPkg/Unix/UnixX64.dsc -a X64 -t $TARGET_TOOLS -D SEC_ONLY -n 3 clean
+    build -p $WORKSPACE/InOsEmuPkg/Unix/UnixX64.dsc -a X64 -t $UNIXPKG_TOOLS -n 3 clean
+    build -p $WORKSPACE/ShellPkg/ShellPkg.dsc -a X64 -t $UNIXPKG_TOOLS -n 3 clean
+    exit $?
+  fi
+
+  if [[ $arg == clean ]]; then
+    build -p $WORKSPACE/InOsEmuPkg/Unix/UnixX64.dsc -a X64 -t $TARGET_TOOLS -D SEC_ONLY -n 3 clean
+    build -p $WORKSPACE/InOsEmuPkg/Unix/UnixX64.dsc -a X64 -t $UNIXPKG_TOOLS -n 3 clean
+    exit $?
+  fi
+
+  if [[ $arg == shell ]]; then
+    build -p $WORKSPACE/ShellPkg/ShellPkg.dsc -a X64 -t $UNIXPKG_TOOLS -n 3 $2 $3 $4 $5 $6 $7 $8
+    cp Build/Shell/DEBUG_$UNIXPKG_TOOLS/X64/Shell.efi ShellBinPkg/UefiShell/X64/Shell.efi
+    exit $?
+  fi
+done
+
+
+#
+# Build the edk2 UnixPkg
+#
+echo $PATH
+echo `which build`
+build -p $WORKSPACE/InOsEmuPkg/Unix/UnixX64.dsc      -a X64 -t $TARGET_TOOLS -D SEC_ONLY -n 3 $1 $2 $3 $4 $5 $6 $7 $8  modules
+build -p $WORKSPACE/InOsEmuPkg/Unix/UnixX64.dsc      -a X64 -t $UNIXPKG_TOOLS $NETWORK_SUPPORT -n 3 $1 $2 $3 $4 $5 $6 $7 $8
+cp $WORKSPACE/Build/EmuUnixX64/DEBUG_"$TARGET_TOOLS"/X64/SecMain $WORKSPACE/Build/EmuUnixX64/DEBUG_"$UNIXPKG_TOOLS"/X64
+exit $?
+
diff --git a/InOsEmuPkg/build64.sh b/InOsEmuPkg/build64.sh
new file mode 100755 (executable)
index 0000000..a1d47b7
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/bash
+#
+# Copyright (c) 2011, Apple Inc. All rights reserved.<BR>
+#
+# 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.
+#
+
+cd Unix
+. build64.sh $1 $2 $3 $4 $5 $6 $7 $8
+