diff options
Diffstat (limited to 'EmulatorPkg/Library/DxeEmuLib')
-rw-r--r-- | EmulatorPkg/Library/DxeEmuLib/DxeEmuLib.c | 88 | ||||
-rw-r--r-- | EmulatorPkg/Library/DxeEmuLib/DxeEmuLib.inf | 46 |
2 files changed, 134 insertions, 0 deletions
diff --git a/EmulatorPkg/Library/DxeEmuLib/DxeEmuLib.c b/EmulatorPkg/Library/DxeEmuLib/DxeEmuLib.c new file mode 100644 index 0000000000..2e42ea6151 --- /dev/null +++ b/EmulatorPkg/Library/DxeEmuLib/DxeEmuLib.c @@ -0,0 +1,88 @@ +/*++ @file
+
+Copyright (c) 2006 - 2008, 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.
+
+**/
+
+#include <PiDxe.h>
+
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/EmuThunkLib.h>
+#include <Library/BaseMemoryLib.h>
+
+EMU_THUNK_PROTOCOL *gEmuThunk = NULL;
+
+
+/**
+ The constructor function caches the pointer of EMU Thunk protocol.
+
+ @param ImageHandle The firmware allocated handle for the EFI image.
+ @param SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+DxeEmuLibConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_HOB_GUID_TYPE *GuidHob;
+
+ GuidHob = GetFirstGuidHob (&gEmuThunkProtocolGuid);
+ ASSERT (GuidHob != NULL);
+
+ gEmuThunk = (EMU_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));
+ ASSERT (gEmuThunk != NULL);
+
+ return EFI_SUCCESS;
+}
+
+
+/**
+ Serach the EMU IO Thunk database for a matching EMU IO Thunk
+ Protocol instance.
+
+ @param Protocol Protocol to search for.
+ @param Instance Instance of protocol to search for.
+
+ @retval NULL Protocol and Instance not found.
+ @retval other EMU IO Thunk protocol that matched.
+
+**/
+EMU_IO_THUNK_PROTOCOL *
+EFIAPI
+GetIoThunkInstance (
+ IN EFI_GUID *Protocol,
+ IN UINTN Instance
+ )
+{
+ EFI_STATUS Status;
+ EMU_IO_THUNK_PROTOCOL *EmuIoThunk;
+
+ for (Status = EFI_SUCCESS, EmuIoThunk = NULL; !EFI_ERROR (Status); ) {
+ Status = gEmuThunk->GetNextProtocol (FALSE, &EmuIoThunk);
+ if (EFI_ERROR (Status)) {
+ break;
+ }
+
+ if (EmuIoThunk->Instance == Instance) {
+ if (CompareGuid (EmuIoThunk->Protocol, Protocol)) {
+ return EmuIoThunk;
+ }
+ }
+ }
+
+ return NULL;
+}
\ No newline at end of file diff --git a/EmulatorPkg/Library/DxeEmuLib/DxeEmuLib.inf b/EmulatorPkg/Library/DxeEmuLib/DxeEmuLib.inf new file mode 100644 index 0000000000..731bddae9e --- /dev/null +++ b/EmulatorPkg/Library/DxeEmuLib/DxeEmuLib.inf @@ -0,0 +1,46 @@ +## @file
+# A library to produce the global variable 'gEmuThunk'
+#
+# This library contains a single global variable 'gEmuThunk' along with a constructor to
+# initialize that global.
+# 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
+# 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 = DxeEmuLib
+ FILE_GUID = 31479AFD-B06F-4E4A-863B-A8F7E7710778
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = EmuThunkLib
+
+ CONSTRUCTOR = DxeEmuLibConstructor
+
+
+[Sources]
+ DxeEmuLib.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ EmulatorPkg/EmulatorPkg.dec
+
+[LibraryClasses]
+ HobLib
+ DebugLib
+ BaseMemoryLib
+
+
+[Protocols]
+ gEmuThunkProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+
|