summaryrefslogtreecommitdiff
path: root/EmulatorPkg/Library/ThunkProtocolList
diff options
context:
space:
mode:
authorjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>2011-06-28 16:47:23 +0000
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>2011-06-28 16:47:23 +0000
commitbb89ec1a7ec2f8d35033df9e47b3604925da3bd3 (patch)
tree32d38e02ccab98dbac4c3014a12ac365775e8eb3 /EmulatorPkg/Library/ThunkProtocolList
parentd3e0289ccf641481f2cbdcbb0d5868c393b7edbb (diff)
downloadedk2-platforms-bb89ec1a7ec2f8d35033df9e47b3604925da3bd3.tar.xz
InOsEmuPkg: Rename package to EmulatorPkg & Sec to Host
* Rename InOsEmuPkg to EmulatorPkg * Rename Unix/Sec to Unix/Host Signed-off-by: jljusten Reviewed-by: andrewfish Reviewed-by: geekboy15a git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11918 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'EmulatorPkg/Library/ThunkProtocolList')
-rw-r--r--EmulatorPkg/Library/ThunkProtocolList/ThunkProtocolList.c138
-rw-r--r--EmulatorPkg/Library/ThunkProtocolList/ThunkProtocolList.inf36
2 files changed, 174 insertions, 0 deletions
diff --git a/EmulatorPkg/Library/ThunkProtocolList/ThunkProtocolList.c b/EmulatorPkg/Library/ThunkProtocolList/ThunkProtocolList.c
new file mode 100644
index 0000000000..5aed594b6e
--- /dev/null
+++ b/EmulatorPkg/Library/ThunkProtocolList/ThunkProtocolList.c
@@ -0,0 +1,138 @@
+/** @file
+ Emulator Thunk to abstract OS services from pure EFI code
+
+ Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
+ Copyright (c) 2011, 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.
+
+**/
+
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+#include <Protocol/EmuIoThunk.h>
+
+
+#define EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE SIGNATURE_32('E','m','u','T')
+
+typedef struct {
+ UINTN Signature;
+ EMU_IO_THUNK_PROTOCOL Data;
+ BOOLEAN EmuBusDriver;
+ LIST_ENTRY Link;
+} EMU_IO_THUNK_PROTOCOL_DATA;
+
+LIST_ENTRY mThunkList = INITIALIZE_LIST_HEAD_VARIABLE (mThunkList);
+
+
+EFI_STATUS
+EFIAPI
+AddThunkProtocol (
+ IN EMU_IO_THUNK_PROTOCOL *ThunkIo,
+ IN CHAR16 *ConfigString,
+ IN BOOLEAN EmuBusDriver
+ )
+{
+ CHAR16 *StartString;
+ CHAR16 *SubString;
+ UINTN Instance;
+ EMU_IO_THUNK_PROTOCOL_DATA *Private;
+
+ if (ThunkIo == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Instance = 0;
+ StartString = AllocatePool (StrSize (ConfigString));
+ StrCpy (StartString, ConfigString);
+ while (*StartString != '\0') {
+
+ //
+ // Find the end of the sub string
+ //
+ SubString = StartString;
+ while (*SubString != '\0' && *SubString != '!') {
+ SubString++;
+ }
+
+ if (*SubString == '!') {
+ //
+ // Replace token with '\0' to make sub strings. If this is the end
+ // of the string SubString will already point to NULL.
+ //
+ *SubString = '\0';
+ SubString++;
+ }
+
+ Private = AllocatePool (sizeof (EMU_IO_THUNK_PROTOCOL_DATA));
+ if (Private == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ Private->Signature = EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE;
+ Private->EmuBusDriver = EmuBusDriver;
+
+ CopyMem (&Private->Data, ThunkIo, sizeof (EMU_IO_THUNK_PROTOCOL));
+ Private->Data.Instance = Instance++;
+ Private->Data.ConfigString = StartString;
+
+ InsertTailList (&mThunkList, &Private->Link);
+
+ //
+ // Parse Next sub string. This will point to '\0' if we are at the end.
+ //
+ StartString = SubString;
+ }
+
+ return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+EFIAPI
+GetNextThunkProtocol (
+ IN BOOLEAN EmuBusDriver,
+ OUT EMU_IO_THUNK_PROTOCOL **Instance OPTIONAL
+ )
+{
+ LIST_ENTRY *Link;
+ EMU_IO_THUNK_PROTOCOL_DATA *Private;
+
+ if (mThunkList.ForwardLink == &mThunkList) {
+ // Skip parsing an empty list
+ return EFI_NOT_FOUND;
+ }
+
+ for (Link = mThunkList.ForwardLink; Link != &mThunkList; Link = Link->ForwardLink) {
+ Private = CR (Link, EMU_IO_THUNK_PROTOCOL_DATA, Link, EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE);
+ if (EmuBusDriver & !Private->EmuBusDriver) {
+ continue;
+ } else if (*Instance == NULL) {
+ // Find 1st match in list
+ *Instance = &Private->Data;
+ return EFI_SUCCESS;
+ } else if (*Instance == &Private->Data) {
+ // Matched previous call so look for valid next entry
+ Link = Link->ForwardLink;
+ if (Link == &mThunkList) {
+ return EFI_NOT_FOUND;
+ }
+ Private = CR (Link, EMU_IO_THUNK_PROTOCOL_DATA, Link, EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE);
+ *Instance = &Private->Data;
+ return EFI_SUCCESS;
+ }
+ }
+
+
+ return EFI_NOT_FOUND;
+}
+
diff --git a/EmulatorPkg/Library/ThunkProtocolList/ThunkProtocolList.inf b/EmulatorPkg/Library/ThunkProtocolList/ThunkProtocolList.inf
new file mode 100644
index 0000000000..06668835f3
--- /dev/null
+++ b/EmulatorPkg/Library/ThunkProtocolList/ThunkProtocolList.inf
@@ -0,0 +1,36 @@
+## @file
+#
+# 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 = ThunkProtocolList
+ FILE_GUID = 7833616E-AE0D-594F-870C-80E68682D587
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = MemoryAllocationLib|BASE SEC USER_DEFINED
+
+[Sources]
+ ThunkProtocolList.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ EmulatorPkg/EmulatorPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+
+
+