]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Import some Pei and Dxe related instances for MdePkg.
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 22 Jun 2007 06:57:39 +0000 (06:57 +0000)
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 22 Jun 2007 06:57:39 +0000 (06:57 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2712 6f19259b-4bc3-4df7-8a09-765794883524

82 files changed:
MdePkg/Library/DxeCoreEntryPoint/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.c [new file with mode: 0644]
MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf [new file with mode: 0644]
MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.msa [new file with mode: 0644]
MdePkg/Library/DxeMemoryAllocationLib/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf [new file with mode: 0644]
MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.msa [new file with mode: 0644]
MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c [new file with mode: 0644]
MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLibInternals.h [new file with mode: 0644]
MdePkg/Library/DxePcdLib/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/DxePcdLib/DxePcdLib.c [new file with mode: 0644]
MdePkg/Library/DxePcdLib/DxePcdLib.inf [new file with mode: 0644]
MdePkg/Library/DxePcdLib/DxePcdLib.msa [new file with mode: 0644]
MdePkg/Library/DxeServicesTableLib/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.c [new file with mode: 0644]
MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf [new file with mode: 0644]
MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.msa [new file with mode: 0644]
MdePkg/Library/PeiCoreEntryPoint/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.c [new file with mode: 0644]
MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf [new file with mode: 0644]
MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.msa [new file with mode: 0644]
MdePkg/Library/PeiMemoryAllocationLib/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c [new file with mode: 0644]
MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLibInternals.h [new file with mode: 0644]
MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf [new file with mode: 0644]
MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.msa [new file with mode: 0644]
MdePkg/Library/PeiPcdLib/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/PeiPcdLib/PeiPcdLib.c [new file with mode: 0644]
MdePkg/Library/PeiPcdLib/PeiPcdLib.inf [new file with mode: 0644]
MdePkg/Library/PeiPcdLib/PeiPcdLib.msa [new file with mode: 0644]
MdePkg/Library/PeiResourcePublicationLib/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.c [new file with mode: 0644]
MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf [new file with mode: 0644]
MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.msa [new file with mode: 0644]
MdePkg/Library/PeiServicesTablePointerLib/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointer.c [new file with mode: 0644]
MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf [new file with mode: 0644]
MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.msa [new file with mode: 0644]
MdePkg/Library/SecPeiDxeTimerLibCpu/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/SecPeiDxeTimerLibCpu/IpfTimerLib.c [new file with mode: 0644]
MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf [new file with mode: 0644]
MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.msa [new file with mode: 0644]
MdePkg/Library/SecPeiDxeTimerLibCpu/x86TimerLib.c [new file with mode: 0644]
MdePkg/Library/UefiApplicationEntryPoint/ApplicationEntryPoint.c [new file with mode: 0644]
MdePkg/Library/UefiApplicationEntryPoint/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf [new file with mode: 0644]
MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.msa [new file with mode: 0644]
MdePkg/Library/UefiBootServicesTableLib/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.c [new file with mode: 0644]
MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf [new file with mode: 0644]
MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.msa [new file with mode: 0644]
MdePkg/Library/UefiDebugLibConOut/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/UefiDebugLibConOut/DebugLib.c [new file with mode: 0644]
MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf [new file with mode: 0644]
MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.msa [new file with mode: 0644]
MdePkg/Library/UefiDebugLibStdErr/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/UefiDebugLibStdErr/DebugLib.c [new file with mode: 0644]
MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf [new file with mode: 0644]
MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.msa [new file with mode: 0644]
MdePkg/Library/UefiDevicePathLib/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.c [new file with mode: 0644]
MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf [new file with mode: 0644]
MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.msa [new file with mode: 0644]
MdePkg/Library/UefiDevicePathLibDevicePathProtocol/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c [new file with mode: 0644]
MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLibDevicePathProtocol.inf [new file with mode: 0644]
MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLibDevicePathProtocol.msa [new file with mode: 0644]
MdePkg/Library/UefiDriverEntryPoint/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/UefiDriverEntryPoint/DriverEntryPoint.c [new file with mode: 0644]
MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf [new file with mode: 0644]
MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.msa [new file with mode: 0644]
MdePkg/Library/UefiLib/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/UefiLib/Console.c [new file with mode: 0644]
MdePkg/Library/UefiLib/UefiLib.c [new file with mode: 0644]
MdePkg/Library/UefiLib/UefiLib.inf [new file with mode: 0644]
MdePkg/Library/UefiLib/UefiLib.msa [new file with mode: 0644]
MdePkg/Library/UefiLib/UefiLibPrint.c [new file with mode: 0644]
MdePkg/Library/UefiLib/UefiNotTiano.c [new file with mode: 0644]
MdePkg/Library/UefiRuntimeServicesTableLib/CommonHeader.h [new file with mode: 0644]
MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.c [new file with mode: 0644]
MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf [new file with mode: 0644]
MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.msa [new file with mode: 0644]

diff --git a/MdePkg/Library/DxeCoreEntryPoint/CommonHeader.h b/MdePkg/Library/DxeCoreEntryPoint/CommonHeader.h
new file mode 100644 (file)
index 0000000..6f409d6
--- /dev/null
@@ -0,0 +1,33 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007, Intel Corporation.\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DxeCoreEntryPoint.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.c b/MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.c
new file mode 100644 (file)
index 0000000..34e8461
--- /dev/null
@@ -0,0 +1,68 @@
+/** @file\r
+  Entry point to the DXE Core.\r
+\r
+Copyright (c) 2006, Intel Corporation<BR>\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+//\r
+// Cache copy of HobList pointer. \r
+// \r
+VOID *gHobList = NULL;\r
+\r
+/**\r
+  Enrty point to DXE core.\r
+\r
+  @param  HobStart Pointer of HobList.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+_ModuleEntryPoint (\r
+  IN VOID  *HobStart\r
+  )\r
+{\r
+  //\r
+  // Cache a pointer to the HobList\r
+  //\r
+  gHobList = HobStart;\r
+\r
+  //\r
+  // Call the DXE Core entry point\r
+  //\r
+  ProcessModuleEntryPointList (HobStart);\r
+\r
+  //\r
+  // Should never return\r
+  //\r
+  ASSERT(FALSE);\r
+  CpuDeadLoop ();\r
+}\r
+\r
+\r
+/**\r
+  Wrapper of enrty point to DXE CORE.\r
+\r
+  @param  HobStart Pointer of HobList.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+EfiMain (\r
+  IN VOID  *HobStart\r
+  )\r
+{\r
+  _ModuleEntryPoint (HobStart);\r
+}\r
diff --git a/MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf b/MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf
new file mode 100644 (file)
index 0000000..ad1bb48
--- /dev/null
@@ -0,0 +1,81 @@
+#/** @file\r
+# Component description file for Dxe Core Entry Point Library\r
+#\r
+# Entry Point Library instance used by Dxe Core\r
+# Copyright (c) 2007, Intel Corporation.\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DxeCoreEntryPoint\r
+  FILE_GUID                      = d258d6af-2fc0-4019-9c1f-1101c3dd19b5\r
+  MODULE_TYPE                    = DXE_CORE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = DxeCoreEntryPoint|DXE_CORE \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  DxeCoreEntryPoint.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg\Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+\r
diff --git a/MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.msa b/MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.msa
new file mode 100644 (file)
index 0000000..787a36f
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>DxeCoreEntryPoint</ModuleName>\r
+    <ModuleType>DXE_CORE</ModuleType>\r
+    <GuidValue>d258d6af-2fc0-4019-9c1f-1101c3dd19b5</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for Dxe Core Entry Point Library</Abstract>\r
+    <Description>Entry Point Library instance used by Dxe Core</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation.</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>DxeCoreEntryPoint</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_CORE">\r
+      <Keyword>DxeCoreEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>DxeCoreEntryPoint.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdePkg/Library/DxeMemoryAllocationLib/CommonHeader.h b/MdePkg/Library/DxeMemoryAllocationLib/CommonHeader.h
new file mode 100644 (file)
index 0000000..ef4a5b8
--- /dev/null
@@ -0,0 +1,34 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf b/MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf
new file mode 100644 (file)
index 0000000..9428979
--- /dev/null
@@ -0,0 +1,84 @@
+#/** @file\r
+# Component description file for Dxe Memory Allocation Library\r
+#\r
+# Memory Allocation Library that uses EFI Boot Services to allocate\r
+#  and free memory.\r
+# Copyright (c) 2007, Intel Corporation\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DxeMemoryAllocationLib\r
+  FILE_GUID                      = 4674739d-3195-4fb2-8094-ac1d22d00194\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = MemoryAllocationLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  MemoryAllocationLibInternals.h\r
+  MemoryAllocationLib.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg\Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  BaseMemoryLib\r
+  UefiBootServicesTableLib\r
+\r
diff --git a/MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.msa b/MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.msa
new file mode 100644 (file)
index 0000000..cb4cd7d
--- /dev/null
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>DxeMemoryAllocationLib</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>4674739d-3195-4fb2-8094-ac1d22d00194</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for Dxe Memory Allocation Library</Abstract>\r
+    <Description>Memory Allocation Library that uses EFI Boot Services to allocate
+      and free memory.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>DxeMemoryAllocationLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>MemoryAllocationLib.c</Filename>\r
+    <Filename>MemoryAllocationLibInternals.h</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c b/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c
new file mode 100644 (file)
index 0000000..b25b637
--- /dev/null
@@ -0,0 +1,1077 @@
+/** @file\r
+  Support routines for memory allocation routines for use with drivers.\r
+\r
+  Copyright (c) 2006, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials                          \r
+  are licensed and made available under the terms and conditions of the BSD License         \r
+  which accompanies this distribution.  The full text of the license may be found at        \r
+  http://opensource.org/licenses/bsd-license.php                                            \r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+  Module Name:  MemoryAllocationLib.c\r
+\r
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "MemoryAllocationLibInternals.h"\r
+\r
+/**\r
+  Allocates one or more 4KB pages of a certain memory type.\r
+\r
+  Allocates the number of 4KB pages of a certain memory type and returns a pointer to the allocated\r
+  buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL is returned.\r
+  If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  @param  MemoryType            The type of memory to allocate.\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocatePages (\r
+  IN EFI_MEMORY_TYPE  MemoryType,  \r
+  IN UINTN            Pages\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_PHYSICAL_ADDRESS  Memory; \r
+\r
+  if (Pages == 0) {\r
+    return NULL;\r
+  }\r
+\r
+  Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, Pages, &Memory);\r
+  if (EFI_ERROR (Status)) {\r
+    Memory = 0;\r
+  }\r
+  return (VOID *) (UINTN) Memory;\r
+}\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiBootServicesData.\r
+\r
+  Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the\r
+  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL\r
+  is returned.  If there is not enough memory remaining to satisfy the request, then NULL is\r
+  returned.\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocatePages (\r
+  IN UINTN  Pages\r
+  )\r
+{\r
+  return InternalAllocatePages (EfiBootServicesData, Pages);\r
+}\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiRuntimeServicesData.\r
+\r
+  Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the\r
+  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL\r
+  is returned.  If there is not enough memory remaining to satisfy the request, then NULL is\r
+  returned.\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateRuntimePages (\r
+  IN UINTN  Pages\r
+  )\r
+{\r
+  return InternalAllocatePages (EfiRuntimeServicesData, Pages);\r
+}\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiReservedMemoryType.\r
+\r
+  Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the\r
+  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL\r
+  is returned.  If there is not enough memory remaining to satisfy the request, then NULL is\r
+  returned.\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateReservedPages (\r
+  IN UINTN  Pages\r
+  )\r
+{\r
+  return InternalAllocatePages (EfiReservedMemoryType, Pages);\r
+}\r
+\r
+/**\r
+  Frees one or more 4KB pages that were previously allocated with one of the page allocation\r
+  functions in the Memory Allocation Library.\r
+\r
+  Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer\r
+  must have been allocated on a previous call to the page allocation services of the Memory\r
+  Allocation Library.\r
+  If Buffer was not allocated with a page allocation function in the Memory Allocation Library,\r
+  then ASSERT().\r
+  If Pages is zero, then ASSERT().\r
\r
+  @param  Buffer                Pointer to the buffer of pages to free.\r
+  @param  Pages                 The number of 4 KB pages to free.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+FreePages (\r
+  IN VOID   *Buffer,\r
+  IN UINTN  Pages\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  ASSERT (Pages != 0);\r
+  Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+/**\r
+  Allocates one or more 4KB pages of a certain memory type at a specified alignment.\r
+\r
+  Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment\r
+  specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is returned.\r
+  If there is not enough memory at the specified alignment remaining to satisfy the request, then\r
+  NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  MemoryType            The type of memory to allocate.\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateAlignedPages (\r
+  IN EFI_MEMORY_TYPE  MemoryType,  \r
+  IN UINTN            Pages,\r
+  IN UINTN            Alignment\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_PHYSICAL_ADDRESS  Memory;\r
+  UINTN                 AlignedMemory;\r
+  UINTN                 AlignmentMask;\r
+  UINTN                 UnalignedPages;\r
+  UINTN                 RealPages;\r
+\r
+  //\r
+  // Alignment must be a power of two or zero.\r
+  //\r
+  ASSERT ((Alignment & (Alignment - 1)) == 0);\r
\r
+  if (Pages == 0) {\r
+    return NULL;\r
+  }\r
+  if (Alignment > EFI_PAGE_SIZE) {\r
+    //\r
+    // Caculate the total number of pages since alignment is larger than page size.\r
+    //\r
+    AlignmentMask  = Alignment - 1;\r
+    RealPages      = Pages + EFI_SIZE_TO_PAGES (Alignment);\r
+    //\r
+    // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.\r
+    //\r
+    ASSERT (RealPages > Pages);\r
\r
+    Status         = gBS->AllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory);\r
+    if (EFI_ERROR (Status)) {\r
+      return NULL;\r
+    }\r
+    AlignedMemory  = ((UINTN) Memory + AlignmentMask) & ~AlignmentMask;\r
+    UnalignedPages = EFI_SIZE_TO_PAGES ((UINTN) Memory - AlignedMemory);\r
+    if (UnalignedPages > 0) {\r
+      //\r
+      // Free first unaligned page(s).\r
+      //\r
+      Status = gBS->FreePages (Memory, UnalignedPages);\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+    Memory         = (EFI_PHYSICAL_ADDRESS) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));\r
+    UnalignedPages = RealPages - Pages - UnalignedPages;\r
+    if (UnalignedPages > 0) {\r
+      //\r
+      // Free last unaligned page(s).\r
+      //\r
+      Status = gBS->FreePages (Memory, UnalignedPages);\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+  } else {\r
+    //\r
+    // Do not over-allocate pages in this case.\r
+    //\r
+    Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, Pages, &Memory);\r
+    if (EFI_ERROR (Status)) {\r
+      return NULL;\r
+    }\r
+    AlignedMemory  = (UINTN) Memory;\r
+  }\r
+  return (VOID *) AlignedMemory;\r
+}\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.\r
+\r
+  Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is\r
+  returned.  If there is not enough memory at the specified alignment remaining to satisfy the\r
+  request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedPages (\r
+  IN UINTN  Pages,\r
+  IN UINTN  Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedPages (EfiBootServicesData, Pages, Alignment);\r
+}\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.\r
+\r
+  Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is\r
+  returned.  If there is not enough memory at the specified alignment remaining to satisfy the\r
+  request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedRuntimePages (\r
+  IN UINTN  Pages,\r
+  IN UINTN  Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedPages (EfiRuntimeServicesData, Pages, Alignment);\r
+}\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.\r
+\r
+  Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is\r
+  returned.  If there is not enough memory at the specified alignment remaining to satisfy the\r
+  request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedReservedPages (\r
+  IN UINTN  Pages,\r
+  IN UINTN  Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedPages (EfiReservedMemoryType, Pages, Alignment);\r
+}\r
+\r
+/**\r
+  Frees one or more 4KB pages that were previously allocated with one of the aligned page\r
+  allocation functions in the Memory Allocation Library.\r
+\r
+  Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer\r
+  must have been allocated on a previous call to the aligned page allocation services of the Memory\r
+  Allocation Library.\r
+  If Buffer was not allocated with an aligned page allocation function in the Memory Allocation\r
+  Library, then ASSERT().\r
+  If Pages is zero, then ASSERT().\r
+  \r
+  @param  Buffer                Pointer to the buffer of pages to free.\r
+  @param  Pages                 The number of 4 KB pages to free.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+FreeAlignedPages (\r
+  IN VOID   *Buffer,\r
+  IN UINTN  Pages\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  ASSERT (Pages != 0);\r
+  Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+/**\r
+  Allocates a buffer of a certain pool type.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type and returns a\r
+  pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is\r
+  returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  @param  MemoryType            The type of memory to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocatePool (\r
+  IN EFI_MEMORY_TYPE  MemoryType,  \r
+  IN UINTN            AllocationSize\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  VOID        *Memory;\r
+\r
+  Status = gBS->AllocatePool (MemoryType, AllocationSize, &Memory);\r
+  if (EFI_ERROR (Status)) {\r
+    Memory = NULL;\r
+  }\r
+  return Memory;\r
+}\r
+\r
+/**\r
+  Allocates a buffer of type EfiBootServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a\r
+  pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is\r
+  returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocatePool (\r
+  IN UINTN  AllocationSize\r
+  )\r
+{\r
+  return InternalAllocatePool (EfiBootServicesData, AllocationSize);\r
+}\r
+\r
+/**\r
+  Allocates a buffer of type EfiRuntimeServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns\r
+  a pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is\r
+  returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateRuntimePool (\r
+  IN UINTN  AllocationSize\r
+  )\r
+{\r
+  return InternalAllocatePool (EfiRuntimeServicesData, AllocationSize);\r
+}\r
+\r
+/**\r
+  Allocates a buffer of type EfieservedMemoryType.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType and returns\r
+  a pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is\r
+  returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateReservedPool (\r
+  IN UINTN  AllocationSize\r
+  )\r
+{\r
+  return InternalAllocatePool (EfiReservedMemoryType, AllocationSize);\r
+}\r
+\r
+/**\r
+  Allocates and zeros a buffer of a certian pool type.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer\r
+  with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a valid\r
+  buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the request,\r
+  then NULL is returned.\r
+\r
+  @param  PoolType              The type of memory to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateZeroPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,  \r
+  IN UINTN            AllocationSize\r
+  ) \r
+{\r
+  VOID  *Memory;\r
+\r
+  Memory = InternalAllocatePool (PoolType, AllocationSize);\r
+  if (Memory != NULL) {\r
+    Memory = ZeroMem (Memory, AllocationSize);\r
+  }\r
+  return Memory;\r
+}\r
+\r
+/**\r
+  Allocates and zeros a buffer of type EfiBootServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the\r
+  buffer with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a\r
+  valid buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the\r
+  request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateZeroPool (\r
+  IN UINTN  AllocationSize\r
+  )\r
+{\r
+  return InternalAllocateZeroPool (EfiBootServicesData, AllocationSize);\r
+}\r
+\r
+/**\r
+  Allocates and zeros a buffer of type EfiRuntimeServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the\r
+  buffer with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a\r
+  valid buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the\r
+  request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateRuntimeZeroPool (\r
+  IN UINTN  AllocationSize\r
+  )\r
+{\r
+  return InternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize);\r
+}\r
+\r
+/**\r
+  Allocates and zeros a buffer of type EfiReservedMemoryType.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the\r
+  buffer with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a\r
+  valid buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the\r
+  request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateReservedZeroPool (\r
+  IN UINTN  AllocationSize\r
+  )\r
+{\r
+  return InternalAllocateZeroPool (EfiReservedMemoryType, AllocationSize);\r
+}\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of a certian pool type.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certian pool type, copies\r
+  AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory remaining to satisfy the request, then NULL is returned.\r
+  If Buffer is NULL, then ASSERT().\r
+  If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
+\r
+  @param  PoolType              The type of pool to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateCopyPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,  \r
+  IN UINTN            AllocationSize,\r
+  IN CONST VOID       *Buffer\r
+  ) \r
+{\r
+  VOID  *Memory;\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));\r
+\r
+  Memory = InternalAllocatePool (PoolType, AllocationSize);\r
+  if (Memory != NULL) {\r
+     Memory = CopyMem (Memory, Buffer, AllocationSize);\r
+  }\r
+  return Memory;\r
+} \r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of type EfiBootServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies\r
+  AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory remaining to satisfy the request, then NULL is returned.\r
+  If Buffer is NULL, then ASSERT().\r
+  If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
+\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateCopyPool (\r
+  IN UINTN       AllocationSize,\r
+  IN CONST VOID  *Buffer\r
+  )\r
+{\r
+  return InternalAllocateCopyPool (EfiBootServicesData, AllocationSize, Buffer);\r
+}\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies\r
+  AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory remaining to satisfy the request, then NULL is returned.\r
+  If Buffer is NULL, then ASSERT().\r
+  If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
+\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateRuntimeCopyPool (\r
+  IN UINTN       AllocationSize,\r
+  IN CONST VOID  *Buffer\r
+  )\r
+{\r
+  return InternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer);\r
+}\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of type EfiReservedMemoryType.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies\r
+  AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory remaining to satisfy the request, then NULL is returned.\r
+  If Buffer is NULL, then ASSERT().\r
+  If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
+\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateReservedCopyPool (\r
+  IN UINTN       AllocationSize,\r
+  IN CONST VOID  *Buffer\r
+  )\r
+{\r
+  return InternalAllocateCopyPool (EfiReservedMemoryType, AllocationSize, Buffer);\r
+}\r
+\r
+/**\r
+  Frees a buffer that was previously allocated with one of the pool allocation functions in the\r
+  Memory Allocation Library.\r
+\r
+  Frees the buffer specified by Buffer.  Buffer must have been allocated on a previous call to the\r
+  pool allocation services of the Memory Allocation Library.\r
+  If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,\r
+  then ASSERT().\r
+\r
+  @param  Buffer                Pointer to the buffer to free.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+FreePool (\r
+  IN VOID   *Buffer\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+\r
+  Status = gBS->FreePool (Buffer);\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+/**\r
+  Allocates a buffer of a certain pool type at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment\r
+  specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0, then a valid\r
+  buffer of 0 size is returned.  If there is not enough memory at the specified alignment remaining\r
+  to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  PoolType              The type of pool to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.                            If Alignment is zero, then byte alignment is used.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateAlignedPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,\r
+  IN UINTN            AllocationSize,\r
+  IN UINTN            Alignment\r
+  )\r
+{\r
+  VOID        *RawAddress;\r
+  UINTN       AlignedAddress;\r
+  UINTN       AlignmentMask;\r
+  UINTN       OverAllocationSize;\r
+  UINTN       RealAllocationSize;\r
+  VOID        **FreePointer;\r
+\r
+  //\r
+  // Alignment must be a power of two or zero.\r
+  //\r
+  ASSERT ((Alignment & (Alignment - 1)) == 0);\r
+  \r
+  if (Alignment == 0) {\r
+    AlignmentMask = Alignment;\r
+  } else {\r
+    AlignmentMask = Alignment - 1;\r
+  }\r
+  //\r
+  // Calculate the extra memory size, over-allocate memory pool and get the aligned memory address. \r
+  //\r
+  OverAllocationSize  = sizeof (RawAddress) + AlignmentMask;\r
+  RealAllocationSize  = AllocationSize + OverAllocationSize;\r
+  //\r
+  // Make sure that AllocationSize plus OverAllocationSize does not overflow. \r
+  //\r
+  ASSERT (RealAllocationSize > AllocationSize); \r
+\r
+  RawAddress = InternalAllocatePool (PoolType, RealAllocationSize);\r
+  if (RawAddress == NULL) {\r
+    return NULL;\r
+  }\r
+  AlignedAddress      = ((UINTN) RawAddress + OverAllocationSize) & ~AlignmentMask;\r
+  //\r
+  // Save the original memory address just before the aligned address.\r
+  //\r
+  FreePointer         = (VOID **)(AlignedAddress - sizeof (RawAddress));\r
+  *FreePointer        = RawAddress;\r
+\r
+  return (VOID *) AlignedAddress;\r
+}\r
+\r
+/**\r
+  Allocates a buffer of type EfiBootServicesData at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,\r
+  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified\r
+  alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedPool (\r
+  IN UINTN  AllocationSize,\r
+  IN UINTN  Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedPool (EfiBootServicesData, AllocationSize, Alignment);\r
+}\r
+\r
+/**\r
+  Allocates a buffer of type EfiRuntimeServicesData at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,\r
+  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified\r
+  alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedRuntimePool (\r
+  IN UINTN  AllocationSize,\r
+  IN UINTN  Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedPool (EfiRuntimeServicesData, AllocationSize, Alignment);\r
+}\r
+\r
+/**\r
+  Allocates a buffer of type EfieservedMemoryType at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,\r
+  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified\r
+  alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedReservedPool (\r
+  IN UINTN  AllocationSize,\r
+  IN UINTN  Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedPool (EfiReservedMemoryType, AllocationSize, Alignment);\r
+}\r
+\r
+/**\r
+  Allocates and zeros a buffer of a certain pool type at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment\r
+  specified by Alignment, clears the buffer with zeros, and returns a pointer to the allocated\r
+  buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there is not\r
+  enough memory at the specified alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  PoolType              The type of pool to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateAlignedZeroPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,\r
+  IN UINTN            AllocationSize,\r
+  IN UINTN            Alignment\r
+  )\r
+{\r
+  VOID    *Memory;\r
+  Memory = InternalAllocateAlignedPool (PoolType, AllocationSize, Alignment);\r
+  if (Memory != NULL) {\r
+    Memory = ZeroMem (Memory, AllocationSize);\r
+  }\r
+  return Memory;\r
+}\r
+\r
+/**\r
+  Allocates and zeros a buffer of type EfiBootServicesData at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an\r
+  alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory at the specified alignment remaining to satisfy the request, then NULL is\r
+  returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedZeroPool (\r
+  IN UINTN  AllocationSize,\r
+  IN UINTN  Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedZeroPool (EfiBootServicesData, AllocationSize, Alignment);\r
+}\r
+\r
+/**\r
+  Allocates and zeros a buffer of type EfiRuntimeServicesData at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an\r
+  alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory at the specified alignment remaining to satisfy the request, then NULL is\r
+  returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedRuntimeZeroPool (\r
+  IN UINTN  AllocationSize,\r
+  IN UINTN  Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedZeroPool (EfiRuntimeServicesData, AllocationSize, Alignment);\r
+}\r
+\r
+/**\r
+  Allocates and zeros a buffer of type EfieservedMemoryType at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an\r
+  alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory at the specified alignment remaining to satisfy the request, then NULL is\r
+  returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedReservedZeroPool (\r
+  IN UINTN  AllocationSize,\r
+  IN UINTN  Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedZeroPool (EfiReservedMemoryType, AllocationSize, Alignment);\r
+}\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of a certain pool type at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment\r
+  specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0, then a valid\r
+  buffer of 0 size is returned.  If there is not enough memory at the specified alignment remaining\r
+  to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  PoolType              The type of pool to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateAlignedCopyPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,\r
+  IN UINTN            AllocationSize,\r
+  IN CONST VOID       *Buffer,\r
+  IN UINTN            Alignment\r
+  )\r
+{\r
+  VOID  *Memory;\r
+  \r
+  ASSERT (Buffer != NULL);\r
+  ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));\r
+\r
+  Memory = InternalAllocateAlignedPool (PoolType, AllocationSize, Alignment);\r
+  if (Memory != NULL) {\r
+    Memory = CopyMem (Memory, Buffer, AllocationSize);\r
+  }\r
+  return Memory;\r
+}\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of type EfiBootServicesData at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData type with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,\r
+  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified\r
+  alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedCopyPool (\r
+  IN UINTN       AllocationSize,\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedCopyPool (EfiBootServicesData, AllocationSize, Buffer, Alignment);\r
+}\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of type EfiRuntimeServicesData at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData type with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,\r
+  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified\r
+  alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedRuntimeCopyPool (\r
+  IN UINTN       AllocationSize,\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer, Alignment);\r
+}\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of type EfiReservedMemoryType at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType type with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,\r
+  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified\r
+  alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedReservedCopyPool (\r
+  IN UINTN       AllocationSize,\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedCopyPool (EfiReservedMemoryType, AllocationSize, Buffer, Alignment);\r
+}\r
+\r
+/**\r
+  Frees a buffer that was previously allocated with one of the aligned pool allocation functions \r
+  in the Memory Allocation Library.\r
+\r
+  Frees the buffer specified by Buffer.  Buffer must have been allocated on a previous call to the\r
+  aligned pool allocation services of the Memory Allocation Library.\r
+  If Buffer was not allocated with an aligned pool allocation function in the Memory Allocation\r
+  Library, then ASSERT().\r
+\r
+  @param  Buffer                Pointer to the buffer to free.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+FreeAlignedPool (\r
+  IN VOID   *Buffer\r
+  )\r
+{\r
+  VOID        *RawAddress;\r
+  VOID        **FreePointer;\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Get the pre-saved original address in the over-allocate pool.\r
+  //\r
+  FreePointer = (VOID **)((UINTN) Buffer - sizeof (RawAddress));\r
+  RawAddress  = *FreePointer;\r
+\r
+  Status = gBS->FreePool (RawAddress);\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
diff --git a/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLibInternals.h b/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLibInternals.h
new file mode 100644 (file)
index 0000000..0d8685e
--- /dev/null
@@ -0,0 +1,205 @@
+/** @file\r
+  Internal include file of DXE Memory Allocation Library.\r
+\r
+  Copyright (c) 2006, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Module Name:  MemoryAllocationLibInternals.h\r
+\r
+**/\r
+\r
+#ifndef __DXE_MEMORY_ALLOCATION_LIB_INTERNALS_H__\r
+#define __DXE_MEMORY_ALLOCATION_LIB_INTERNALS_H__\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+/**\r
+  Allocates one or more 4KB pages of a certain memory type.\r
+\r
+  Allocates the number of 4KB pages of a certain memory type and returns a pointer to the allocated\r
+  buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL is returned.\r
+  If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  @param  MemoryType            The type of memory to allocate.\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocatePages (\r
+  IN EFI_MEMORY_TYPE  MemoryType,  \r
+  IN UINTN            Pages\r
+  );\r
+\r
+/**\r
+  Allocates one or more 4KB pages of a certain memory type at a specified alignment.\r
+\r
+  Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment\r
+  specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is returned.\r
+  If there is not enough memory at the specified alignment remaining to satisfy the request, then\r
+  NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  MemoryType            The type of memory to allocate.\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateAlignedPages (\r
+  IN EFI_MEMORY_TYPE  MemoryType,  \r
+  IN UINTN            Pages,\r
+  IN UINTN            Alignment\r
+  );\r
+\r
+/**\r
+  Allocates a buffer of a certain pool type.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type and returns a\r
+  pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is\r
+  returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  @param  MemoryType            The type of memory to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocatePool (\r
+  IN EFI_MEMORY_TYPE  MemoryType,  \r
+  IN UINTN            AllocationSize\r
+  );\r
+\r
+/**\r
+  Allocates and zeros a buffer of a certian pool type.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer\r
+  with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a valid\r
+  buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the request,\r
+  then NULL is returned.\r
+\r
+  @param  PoolType              The type of memory to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateZeroPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,  \r
+  IN UINTN            AllocationSize\r
+  );\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of a certian pool type.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certian pool type, copies\r
+  AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory remaining to satisfy the request, then NULL is returned.\r
+  If Buffer is NULL, then ASSERT().\r
+  If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
+\r
+  @param  PoolType              The type of pool to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateCopyPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,  \r
+  IN UINTN            AllocationSize,\r
+  IN CONST VOID       *Buffer\r
+  );\r
+\r
+/**\r
+  Allocates a buffer of a certain pool type at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment\r
+  specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0, then a valid\r
+  buffer of 0 size is returned.  If there is not enough memory at the specified alignment remaining\r
+  to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  PoolType              The type of pool to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.                            If Alignment is zero, then byte alignment is used.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateAlignedPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,\r
+  IN UINTN            AllocationSize,\r
+  IN UINTN            Alignment\r
+  );\r
+\r
+/**\r
+  Allocates and zeros a buffer of a certain pool type at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment\r
+  specified by Alignment, clears the buffer with zeros, and returns a pointer to the allocated\r
+  buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there is not\r
+  enough memory at the specified alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  PoolType              The type of pool to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateAlignedZeroPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,\r
+  IN UINTN            AllocationSize,\r
+  IN UINTN            Alignment\r
+  );\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of a certain pool type at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment\r
+  specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0, then a valid\r
+  buffer of 0 size is returned.  If there is not enough memory at the specified alignment remaining\r
+  to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  PoolType              The type of pool to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateAlignedCopyPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,\r
+  IN UINTN            AllocationSize,\r
+  IN CONST VOID       *Buffer,\r
+  IN UINTN            Alignment\r
+  );\r
+\r
+#endif\r
diff --git a/MdePkg/Library/DxePcdLib/CommonHeader.h b/MdePkg/Library/DxePcdLib/CommonHeader.h
new file mode 100644 (file)
index 0000000..9d2a5e1
--- /dev/null
@@ -0,0 +1,35 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007, Intel Corporation.\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/Pcd.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/PcdLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/DxePcdLib/DxePcdLib.c b/MdePkg/Library/DxePcdLib/DxePcdLib.c
new file mode 100644 (file)
index 0000000..380d167
--- /dev/null
@@ -0,0 +1,969 @@
+/** @file\r
+Implementation of PcdLib class library for DXE phase.\r
+\r
+Copyright (c) 2006, Intel Corporation<BR>\r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+\r
+Module Name: DxePcdLib.c\r
+\r
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+static PCD_PROTOCOL  *mPcd;\r
+\r
+/**\r
+  The constructor function caches the PCD_PROTOCOL pointer.\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 constructor always return EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PcdLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  Status = gBS->LocateProtocol (&gPcdProtocolGuid, NULL, (VOID **)&mPcd);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Sets the current SKU in the PCD database to the value specified by SkuId.  SkuId is returned.\r
+\r
+  @param[in]  SkuId The SKU value that will be used when the PCD service will retrieve and \r
+              set values associated with a PCD token.\r
+\r
+  @retval SKU_ID Return the SKU ID that just be set.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+LibPcdSetSku (\r
+  IN UINTN  SkuId\r
+  )\r
+{\r
+  ASSERT (SkuId < 0x100);\r
+\r
+  mPcd->SetSku (SkuId);\r
+\r
+  return SkuId;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the 8-bit value for the token specified by TokenNumber. \r
+\r
+  @param[in]  The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber. \r
+\r
+**/\r
+UINT8\r
+EFIAPI\r
+LibPcdGet8 (\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  return mPcd->Get8 (TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the 16-bit value for the token specified by TokenNumber. \r
+\r
+  @param[in]  The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber. \r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+LibPcdGet16 (\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  return mPcd->Get16 (TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the 32-bit value for the token specified by TokenNumber. \r
+\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.\r
+\r
+**/\r
+UINT32\r
+EFIAPI\r
+LibPcdGet32 (\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  return mPcd->Get32 (TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the 64-bit value for the token specified by TokenNumber.\r
+\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+LibPcdGet64 (\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  return mPcd->Get64 (TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the pointer to the buffer of the token specified by TokenNumber.\r
+\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval VOID* Returns the pointer to the token specified by TokenNumber.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+LibPcdGetPtr (\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  return mPcd->GetPtr (TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the Boolean value of the token specified by TokenNumber. \r
+\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber. \r
+\r
+**/\r
+BOOLEAN \r
+EFIAPI\r
+LibPcdGetBool (\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  return mPcd->GetBool (TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the size of the token specified by TokenNumber. \r
+\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINTN Returns the size of the token specified by TokenNumber. \r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+LibPcdGetSize (\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  return mPcd->GetSize (TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the 8-bit value for the token specified by TokenNumber and Guid.\r
+  If Guid is NULL, then ASSERT(). \r
+\r
+  @param[in]  Guid Pointer to a 128-bit unique value that designates \r
+              which namespace to retrieve a value from.\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINT8 Return the UINT8.\r
+\r
+**/\r
+UINT8\r
+EFIAPI\r
+LibPcdGetEx8 (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  ASSERT (Guid != NULL);\r
+  \r
+  return mPcd->Get8Ex (Guid, TokenNumber);\r
+}\r
+\r
+\r
+/**\r
+  Returns the 16-bit value for the token specified by TokenNumber and Guid.\r
+  If Guid is NULL, then ASSERT(). \r
+\r
+  @param[in]  Guid Pointer to a 128-bit unique value that designates \r
+              which namespace to retrieve a value from.\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINT16 Return the UINT16.\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+LibPcdGetEx16 (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  ASSERT (Guid != NULL);\r
+\r
+  return mPcd->Get16Ex (Guid, TokenNumber);\r
+}\r
+\r
+\r
+/**\r
+  Returns the 32-bit value for the token specified by TokenNumber and Guid.\r
+  If Guid is NULL, then ASSERT(). \r
+\r
+  @param[in]  Guid Pointer to a 128-bit unique value that designates \r
+              which namespace to retrieve a value from.\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINT32 Return the UINT32.\r
+\r
+**/\r
+UINT32\r
+EFIAPI\r
+LibPcdGetEx32 (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  ASSERT (Guid != NULL);\r
+\r
+  return mPcd->Get32Ex (Guid, TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the 64-bit value for the token specified by TokenNumber and Guid.\r
+  If Guid is NULL, then ASSERT(). \r
+\r
+  @param[in]  Guid Pointer to a 128-bit unique value that designates \r
+              which namespace to retrieve a value from.\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINT64 Return the UINT64.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+LibPcdGetEx64 (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  ASSERT (Guid != NULL);\r
+  \r
+  return mPcd->Get64Ex (Guid, TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the pointer to the token specified by TokenNumber and Guid.\r
+  If Guid is NULL, then ASSERT(). \r
+\r
+  @param[in]  Guid Pointer to a 128-bit unique value that designates \r
+              which namespace to retrieve a value from.\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval VOID* Return the VOID* pointer.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+LibPcdGetExPtr (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  ASSERT (Guid != NULL);\r
+\r
+  return mPcd->GetPtrEx (Guid, TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the Boolean value of the token specified by TokenNumber and Guid. \r
+  If Guid is NULL, then ASSERT(). \r
+\r
+  @param[in]  Guid Pointer to a 128-bit unique value that designates \r
+              which namespace to retrieve a value from.\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval BOOLEAN Return the BOOLEAN.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+LibPcdGetExBool (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  ASSERT (Guid != NULL);\r
+\r
+  return mPcd->GetBoolEx (Guid, TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the size of the token specified by TokenNumber and Guid. \r
+  If Guid is NULL, then ASSERT(). \r
+\r
+  @param[in]  Guid Pointer to a 128-bit unique value that designates \r
+              which namespace to retrieve a value from.\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINTN Return the size.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+LibPcdGetExSize (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  ASSERT (Guid != NULL);\r
+\r
+  return mPcd->GetSizeEx (Guid, TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the 8-bit value for the token specified by TokenNumber \r
+  to the value specified by Value.  Value is returned.\r
+  \r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The 8-bit value to set.\r
+\r
+  @retval UINT8 Return the value been set.\r
+\r
+**/\r
+UINT8\r
+EFIAPI\r
+LibPcdSet8 (\r
+  IN UINTN             TokenNumber,\r
+  IN UINT8             Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  Status = mPcd->Set8 (TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the 16-bit value for the token specified by TokenNumber \r
+  to the value specified by Value.  Value is returned.\r
+  \r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The 16-bit value to set.\r
+\r
+  @retval UINT16 Return the value been set.\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+LibPcdSet16 (\r
+  IN UINTN             TokenNumber,\r
+  IN UINT16            Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  Status = mPcd->Set16 (TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the 32-bit value for the token specified by TokenNumber \r
+  to the value specified by Value.  Value is returned.\r
+  \r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The 32-bit value to set.\r
+\r
+  @retval UINT32 Return the value been set.\r
+\r
+**/\r
+UINT32\r
+EFIAPI\r
+LibPcdSet32 (\r
+  IN UINTN             TokenNumber,\r
+  IN UINT32             Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  Status = mPcd->Set32 (TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the 64-bit value for the token specified by TokenNumber \r
+  to the value specified by Value.  Value is returned.\r
+  \r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The 64-bit value to set.\r
+\r
+  @retval UINT64 Return the value been set.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+LibPcdSet64 (\r
+  IN UINTN             TokenNumber,\r
+  IN UINT64             Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  Status = mPcd->Set64 (TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets a buffer for the token specified by TokenNumber to \r
+  the value specified by Buffer and SizeOfValue.  Buffer to\r
+  be set is returned. The content of the buffer could be \r
+  overwritten if a Callback on SET is registered with this\r
+  TokenNumber.\r
+  \r
+  If SizeOfValue is greater than the maximum \r
+  size support by TokenNumber, then set SizeOfValue to the \r
+  maximum size supported by TokenNumber and return NULL to \r
+  indicate that the set operation was not actually performed. \r
+  \r
+  If SizeOfValue > 0 and Buffer is NULL, then ASSERT().\r
+  \r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in,out] SizeOfBuffer The size, in bytes, of Buffer.\r
+  @param[in]  Value A pointer to the buffer to set.\r
+\r
+  @retval VOID* Return the pointer for the buffer been set.\r
+\r
+**/\r
+\r
+VOID *\r
+EFIAPI\r
+LibPcdSetPtr (\r
+  IN      UINTN             TokenNumber,\r
+  IN OUT  UINTN             *SizeOfBuffer,\r
+  IN      VOID              *Buffer\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  ASSERT (SizeOfBuffer != NULL);\r
+\r
+  if (*SizeOfBuffer > 0) {\r
+    ASSERT (Buffer != NULL);\r
+  }\r
+\r
+  Status = mPcd->SetPtr (TokenNumber, SizeOfBuffer, Buffer);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return NULL;\r
+  }\r
+\r
+  return Buffer;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the Boolean value for the token specified by TokenNumber \r
+  to the value specified by Value.  Value is returned.\r
+  \r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The boolean value to set.\r
+\r
+  @retval BOOLEAN Return the value been set.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+LibPcdSetBool (\r
+  IN UINTN             TokenNumber,\r
+  IN BOOLEAN           Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  Status = mPcd->SetBool (TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the 8-bit value for the token specified by TokenNumber and \r
+  Guid to the value specified by Value. Value is returned.\r
+  If Guid is NULL, then ASSERT().\r
+  \r
+  @param[in]  Guid Pointer to a 128-bit unique value that \r
+              designates which namespace to set a value from.\r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The 8-bit value to set.\r
+\r
+  @retval UINT8 Return the value been set.\r
+\r
+**/\r
+UINT8\r
+EFIAPI\r
+LibPcdSetEx8 (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber,\r
+  IN UINT8             Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  ASSERT (Guid != NULL);\r
+\r
+  Status = mPcd->Set8Ex (Guid, TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the 16-bit value for the token specified by TokenNumber and \r
+  Guid to the value specified by Value. Value is returned.\r
+  If Guid is NULL, then ASSERT().\r
+  \r
+  @param[in]  Guid Pointer to a 128-bit unique value that \r
+              designates which namespace to set a value from.\r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The 16-bit value to set.\r
+\r
+  @retval UINT8 Return the value been set.\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+LibPcdSetEx16 (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber,\r
+  IN UINT16            Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  ASSERT (Guid != NULL);\r
+\r
+  Status = mPcd->Set16Ex (Guid, TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the 32-bit value for the token specified by TokenNumber and \r
+  Guid to the value specified by Value. Value is returned.\r
+  If Guid is NULL, then ASSERT().\r
+  \r
+  @param[in]  Guid Pointer to a 128-bit unique value that \r
+              designates which namespace to set a value from.\r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The 32-bit value to set.\r
+\r
+  @retval UINT32 Return the value been set.\r
+\r
+**/\r
+UINT32\r
+EFIAPI\r
+LibPcdSetEx32 (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber,\r
+  IN UINT32             Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  ASSERT (Guid != NULL);\r
+\r
+  Status = mPcd->Set32Ex (Guid, TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the 64-bit value for the token specified by TokenNumber and \r
+  Guid to the value specified by Value. Value is returned.\r
+  If Guid is NULL, then ASSERT().\r
+  \r
+  @param[in]  Guid Pointer to a 128-bit unique value that \r
+              designates which namespace to set a value from.\r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The 64-bit value to set.\r
+\r
+  @retval UINT64 Return the value been set.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+LibPcdSetEx64 (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber,\r
+  IN UINT64             Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  ASSERT (Guid != NULL);\r
+\r
+  Status = mPcd->Set64Ex (Guid, TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets a buffer for the token specified by TokenNumber to the value specified by \r
+  Buffer and SizeOfValue.  Buffer is returned.  If SizeOfValue is greater than \r
+  the maximum size support by TokenNumber, then set SizeOfValue to the maximum size \r
+  supported by TokenNumber and return NULL to indicate that the set operation \r
+  was not actually performed. \r
+  \r
+  If SizeOfValue > 0 and Buffer is NULL, then ASSERT().\r
+  \r
+  @param[in]  Guid Pointer to a 128-bit unique value that \r
+              designates which namespace to set a value from.\r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.\r
+  @param[in]  Buffer A pointer to the buffer to set.\r
+\r
+  @retval VOID * Return the pinter to the buffer been set.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+LibPcdSetExPtr (\r
+  IN      CONST GUID        *Guid,\r
+  IN      UINTN             TokenNumber,\r
+  IN OUT  UINTN             *SizeOfBuffer,\r
+  IN      VOID              *Buffer\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  ASSERT (Guid != NULL);\r
+\r
+  ASSERT (SizeOfBuffer != NULL);\r
+\r
+  if (*SizeOfBuffer > 0) {\r
+    ASSERT (Buffer != NULL);\r
+  }\r
+\r
+  Status = mPcd->SetPtrEx (Guid, TokenNumber, SizeOfBuffer, Buffer);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return NULL;\r
+  }\r
+\r
+  return Buffer;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the Boolean value for the token specified by TokenNumber and \r
+  Guid to the value specified by Value. Value is returned.\r
+  If Guid is NULL, then ASSERT().\r
+  \r
+  @param[in]  Guid Pointer to a 128-bit unique value that \r
+              designates which namespace to set a value from.\r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The Boolean value to set.\r
+\r
+  @retval Boolean Return the value been set.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+LibPcdSetExBool (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber,\r
+  IN BOOLEAN           Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  ASSERT (Guid != NULL);\r
+\r
+  Status = mPcd->SetBoolEx (Guid, TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  When the token specified by TokenNumber and Guid is set, \r
+  then notification function specified by NotificationFunction is called.  \r
+  If Guid is NULL, then the default token space is used. \r
+  If NotificationFunction is NULL, then ASSERT().\r
+\r
+  @param[in]  Guid Pointer to a 128-bit unique value that designates which \r
+              namespace to set a value from.  If NULL, then the default \r
+              token space is used.\r
+  @param[in]  TokenNumber The PCD token number to monitor.\r
+  @param[in]  NotificationFunction The function to call when the token \r
+              specified by Guid and TokenNumber is set.\r
+\r
+  @retval VOID\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+LibPcdCallbackOnSet (\r
+  IN CONST GUID               *Guid,       OPTIONAL\r
+  IN UINTN                    TokenNumber,\r
+  IN PCD_CALLBACK             NotificationFunction\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  ASSERT (NotificationFunction != NULL);\r
+\r
+  Status = mPcd->CallbackOnSet (Guid, TokenNumber, NotificationFunction);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Disable a notification function that was established with LibPcdCallbackonSet().\r
+  If NotificationFunction is NULL, then ASSERT().\r
+\r
+  @param[in]  Guid Specify the GUID token space.\r
+  @param[in]  TokenNumber Specify the token number.\r
+  @param[in]  NotificationFunction The callback function to be unregistered.\r
+\r
+  @retval VOID\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+LibPcdCancelCallback (\r
+  IN CONST GUID               *Guid,       OPTIONAL\r
+  IN UINTN                    TokenNumber,\r
+  IN PCD_CALLBACK             NotificationFunction\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  ASSERT (NotificationFunction != NULL);\r
+    \r
+  Status = mPcd->CancelCallback (Guid, TokenNumber, NotificationFunction);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Retrieves the next PCD token number from the token space specified by Guid.  \r
+  If Guid is NULL, then the default token space is used.  If TokenNumber is 0, \r
+  then the first token number is returned.  Otherwise, the token number that \r
+  follows TokenNumber in the token space is returned.  If TokenNumber is the last \r
+  token number in the token space, then 0 is returned.  If TokenNumber is not 0 and \r
+  is not in the token space specified by Guid, then ASSERT().\r
+\r
+  @param[in]  Pointer to a 128-bit unique value that designates which namespace \r
+              to set a value from.  If NULL, then the default token space is used.\r
+  @param[in]  The previous PCD token number.  If 0, then retrieves the first PCD \r
+              token number.\r
+\r
+  @retval UINTN            The next valid token number.\r
+\r
+**/\r
+UINTN                      \r
+EFIAPI\r
+LibPcdGetNextToken (\r
+  IN CONST GUID             *Guid, OPTIONAL\r
+  IN       UINTN            TokenNumber\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  Status = mPcd->GetNextToken (Guid, &TokenNumber);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return TokenNumber;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Retrieves the next PCD token space from a token space specified by Guid.\r
+  Guid of NULL is reserved to mark the default local token namespace on the current\r
+  platform. If Guid is NULL, then the GUID of the first non-local token space of the \r
+  current platform is returned. If Guid is the last non-local token space, \r
+  then NULL is returned. \r
+\r
+  If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().\r
+\r
+\r
+  \r
+  @param[in]  Pointer to a 128-bit unique value that designates from which namespace \r
+              to start the search.\r
+\r
+  @retval CONST GUID *  The next valid token namespace.\r
+\r
+**/\r
+GUID *           \r
+EFIAPI\r
+LibPcdGetNextTokenSpace (\r
+  IN CONST GUID  *Guid\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  Status = mPcd->GetNextTokenSpace (&Guid);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return (GUID *) Guid;\r
+}\r
+\r
+\r
+/**\r
+  Sets the PCD entry specified by PatchVariable to the value specified by Buffer \r
+  and SizeOfValue.  Buffer is returned.  If SizeOfValue is greater than \r
+  MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return \r
+  NULL to indicate that the set operation was not actually performed.  \r
+  If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to \r
+  MaximumDatumSize and NULL must be returned.\r
+  \r
+  If PatchVariable is NULL, then ASSERT().\r
+  If SizeOfValue is NULL, then ASSERT().\r
+  If SizeOfValue > 0 and Buffer is NULL, then ASSERT().\r
+\r
+  @param[in] PatchVariable      A pointer to the global variable in a module that is \r
+                                the target of the set operation.\r
+  @param[in] MaximumDatumSize   The maximum size allowed for the PCD entry specified by PatchVariable.\r
+  @param[in, out] SizeOfBuffer  A pointer to the size, in bytes, of Buffer.\r
+  @param[in] Buffer             A pointer to the buffer to used to set the target variable.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+LibPatchPcdSetPtr (\r
+  IN        VOID        *PatchVariable,\r
+  IN        UINTN       MaximumDatumSize,\r
+  IN OUT    UINTN       *SizeOfBuffer,\r
+  IN CONST  VOID        *Buffer\r
+  )\r
+{\r
+  ASSERT (PatchVariable != NULL);\r
+  ASSERT (SizeOfBuffer  != NULL);\r
+  \r
+  if (*SizeOfBuffer > 0) {\r
+    ASSERT (Buffer != NULL);\r
+  }\r
+\r
+  if ((*SizeOfBuffer > MaximumDatumSize) ||\r
+      (*SizeOfBuffer == MAX_ADDRESS)) {\r
+    *SizeOfBuffer = MaximumDatumSize;\r
+    return NULL;\r
+  }\r
+    \r
+  CopyMem (PatchVariable, Buffer, *SizeOfBuffer);\r
+  \r
+  return (VOID *) Buffer;\r
+}\r
+\r
+\r
+\r
diff --git a/MdePkg/Library/DxePcdLib/DxePcdLib.inf b/MdePkg/Library/DxePcdLib/DxePcdLib.inf
new file mode 100644 (file)
index 0000000..eb6459f
--- /dev/null
@@ -0,0 +1,96 @@
+#/** @file\r
+# PCD Library instance implemented with PCD Protocol\r
+#\r
+# This library instance implement the APIs listed \r
+#  in PCD library class defined in MDE library specification.\r
+#  It is used by modules in DXE phase.\r
+# Copyright (c) 2007, Intel Corporation.\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DxePcdLib\r
+  FILE_GUID                      = af97eb89-4cc6-45f8-a514-ca025b346480\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PcdLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = PcdLibConstructor\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
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  DxePcdLib.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg\Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  BaseMemoryLib\r
+  UefiBootServicesTableLib\r
+  DebugLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
+#                           that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Protocols]\r
+  gPcdProtocolGuid                              # PROTOCOL ALWAYS_CONSUMED\r
+\r
diff --git a/MdePkg/Library/DxePcdLib/DxePcdLib.msa b/MdePkg/Library/DxePcdLib/DxePcdLib.msa
new file mode 100644 (file)
index 0000000..6f95e2e
--- /dev/null
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>DxePcdLib</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>af97eb89-4cc6-45f8-a514-ca025b346480</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>PCD Library instance implemented with PCD Protocol</Abstract>\r
+    <Description>This library instance implement the APIs listed 
+    in PCD library class defined in MDE library specification.
+    It is used by modules in DXE phase.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation.</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>DxePcdLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER">\r
+      <Keyword>PcdLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>DxePcdLib.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gPcdProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <Constructor>PcdLibConstructor</Constructor>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdePkg/Library/DxeServicesTableLib/CommonHeader.h b/MdePkg/Library/DxeServicesTableLib/CommonHeader.h
new file mode 100644 (file)
index 0000000..e922174
--- /dev/null
@@ -0,0 +1,34 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007, Intel Corporation.\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Guid/DxeServices.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DxeServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiLib.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.c b/MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.c
new file mode 100644 (file)
index 0000000..cda2b96
--- /dev/null
@@ -0,0 +1,59 @@
+/** @file\r
+  DXE Library.\r
+\r
+  Copyright (c) 2006, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Module Name:  DxeServicesTableLib.c\r
+\r
+**/\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+//\r
+// Cache copy of the DXE Services Table\r
+//\r
+EFI_DXE_SERVICES  *gDS      = NULL;\r
+\r
+/**\r
+  The constructor function caches the pointer of DXE Services Table.\r
+\r
+  The constructor function caches the pointer of DXE Services Table.\r
+  It will ASSERT() if that operation fails.\r
+  It will ASSERT() if the pointer of DXE Services Table is NULL.\r
+  It will always return EFI_SUCCESS.\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
+DxeServicesTableLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Cache copy of the DXE Services Table\r
+  //\r
+  Status = EfiGetSystemConfigurationTable (&gEfiDxeServicesTableGuid, (VOID **) &gDS);\r
+  ASSERT_EFI_ERROR (Status);\r
+  ASSERT (gDS != NULL);\r
+\r
+  return Status;\r
+}\r
diff --git a/MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf b/MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
new file mode 100644 (file)
index 0000000..a5a47fd
--- /dev/null
@@ -0,0 +1,93 @@
+#/** @file\r
+# Component description file for Dxe Services Table Library.\r
+#\r
+# DXE Services Table Library that retrieves a pointer to the DXE Services\r
+#  Table from the Configuration Table in the EFI System Table.\r
+# Copyright (c) 2007, Intel Corporation.\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DxeServicesTableLib\r
+  FILE_GUID                      = baa1baa3-0a8d-402c-8042-985115fae953\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = DxeServicesTableLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = DxeServicesTableLibConstructor\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
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  DxeServicesTableLib.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg\Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  UefiLib\r
+  DebugLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Guid C Name Section - list of Guids that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Guids]\r
+  gEfiDxeServicesTableGuid                      # ALWAYS_CONSUMED\r
+\r
diff --git a/MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.msa b/MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.msa
new file mode 100644 (file)
index 0000000..83df67e
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>DxeServicesTableLib</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>baa1baa3-0a8d-402c-8042-985115fae953</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for Dxe Services Table Library.</Abstract>\r
+    <Description>DXE Services Table Library that retrieves a pointer to the DXE Services
+      Table from the Configuration Table in the EFI System Table.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation.</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>DxeServicesTableLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER">\r
+      <Keyword>DxeServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>DxeServicesTableLib.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiDxeServicesTableGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <Constructor>DxeServicesTableLibConstructor</Constructor>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdePkg/Library/PeiCoreEntryPoint/CommonHeader.h b/MdePkg/Library/PeiCoreEntryPoint/CommonHeader.h
new file mode 100644 (file)
index 0000000..df5adc8
--- /dev/null
@@ -0,0 +1,31 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007 - 2007, Intel Corporation.\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiPei.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/PeiCoreEntryPoint.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.c b/MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.c
new file mode 100644 (file)
index 0000000..ab2a172
--- /dev/null
@@ -0,0 +1,87 @@
+/** @file\r
+  Entry point to a the PEI Core.\r
+\r
+Copyright (c) 2007, Intel Corporation<BR>\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+/**\r
+  Enrty point to PEI core.\r
+\r
+  @param SecCoreData    Points to a data structure containing\r
+                        information about the PEI core's\r
+                        operating environment, such as the size\r
+                        and location of temporary RAM, the stack\r
+                        location and the BFV location. The type\r
+                        EFI_SEC_PEI_HAND_OFF is\r
+\r
+  @param PpiList        Points to a list of one or more PPI\r
+                        descriptors to be installed initially by\r
+                        the PEI core. An empty PPI list consists\r
+                        of a single descriptor with the end-tag\r
+                        EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST.\r
+                        As part of its initialization phase, the\r
+                        PEI Foundation will add these SEC-hosted\r
+                        PPIs to its PPI database such that both\r
+                        the PEI Foundation and any modules can\r
+                        leverage the associated service calls\r
+                        and/or code in these early PPIs.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+_ModuleEntryPoint (\r
+  IN CONST EFI_SEC_PEI_HAND_OFF    *SecCoreData,\r
+  IN CONST EFI_PEI_PPI_DESCRIPTOR  *PpiList\r
+  )\r
+{\r
+  //\r
+  // Call the PEI Core entry point\r
+  //\r
+  return ProcessModuleEntryPointList (SecCoreData, PpiList, NULL);\r
+}\r
+\r
+\r
+/**\r
+  Wrapper of enrty point to PEI core.\r
+\r
+  @param SecCoreData    Points to a data structure containing\r
+                        information about the PEI core's\r
+                        operating environment, such as the size\r
+                        and location of temporary RAM, the stack\r
+                        location and the BFV location. The type\r
+                        EFI_SEC_PEI_HAND_OFF is\r
+\r
+  @param PpiList        Points to a list of one or more PPI\r
+                        descriptors to be installed initially by\r
+                        the PEI core. An empty PPI list consists\r
+                        of a single descriptor with the end-tag\r
+                        EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST.\r
+                        As part of its initialization phase, the\r
+                        PEI Foundation will add these SEC-hosted\r
+                        PPIs to its PPI database such that both\r
+                        the PEI Foundation and any modules can\r
+                        leverage the associated service calls\r
+                        and/or code in these early PPIs.\r
+\r
+**/\r
+EFI_STATUS\r
+EfiMain (\r
+  IN CONST EFI_SEC_PEI_HAND_OFF    *SecCoreData,\r
+  IN CONST EFI_PEI_PPI_DESCRIPTOR  *PpiList\r
+  )\r
+{\r
+  return _ModuleEntryPoint (SecCoreData, PpiList);\r
+}\r
diff --git a/MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf b/MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf
new file mode 100644 (file)
index 0000000..0d48630
--- /dev/null
@@ -0,0 +1,68 @@
+#/** @file\r
+# Entry point to a the PEI Core\r
+#\r
+# The library contains the entry point to a PEI core Module Type.\r
+# Copyright (c) 2007 - 2007, Intel Corporation.\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PeiCoreEntryPoint\r
+  FILE_GUID                      = b3b0654a-969d-4096-86cb-27e262a02083\r
+  MODULE_TYPE                    = PEI_CORE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PeiCoreEntryPoint|PEI_CORE \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  PeiCoreEntryPoint.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
diff --git a/MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.msa b/MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.msa
new file mode 100644 (file)
index 0000000..cd1015b
--- /dev/null
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>PeiCoreEntryPoint</ModuleName>\r
+    <ModuleType>PEI_CORE</ModuleType>\r
+    <GuidValue>b3b0654a-969d-4096-86cb-27e262a02083</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Entry point to a the PEI Core</Abstract>\r
+    <Description>The library contains the entry point to a PEI core Module Type.</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation.</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>PeiCoreEntryPoint</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="PEI_CORE">\r
+      <Keyword>PeiCoreEntryPoint</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>PeiCoreEntryPoint.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdePkg/Library/PeiMemoryAllocationLib/CommonHeader.h b/MdePkg/Library/PeiMemoryAllocationLib/CommonHeader.h
new file mode 100644 (file)
index 0000000..5c99e07
--- /dev/null
@@ -0,0 +1,34 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiPei.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c b/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
new file mode 100644 (file)
index 0000000..32c62c2
--- /dev/null
@@ -0,0 +1,1079 @@
+/** @file\r
+  Support routines for memory allocation routines for use with drivers.\r
+\r
+  Copyright (c) 2006, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials                          \r
+  are licensed and made available under the terms and conditions of the BSD License         \r
+  which accompanies this distribution.  The full text of the license may be found at        \r
+  http://opensource.org/licenses/bsd-license.php                                            \r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+  Module Name:  MemoryAllocationLib.c\r
+\r
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "MemoryAllocationLibInternals.h"\r
+\r
+/**\r
+  Allocates one or more 4KB pages of a certain memory type.\r
+\r
+  Allocates the number of 4KB pages of a certain memory type and returns a pointer to the allocated\r
+  buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL is returned.\r
+  If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  @param  MemoryType            The type of memory to allocate.\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocatePages (\r
+  IN EFI_MEMORY_TYPE  MemoryType,  \r
+  IN UINTN            Pages\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_PHYSICAL_ADDRESS  Memory; \r
+  EFI_PEI_SERVICES      **PeiServices;\r
+\r
+  if (Pages == 0) {\r
+    return NULL;\r
+  }\r
+\r
+  PeiServices = GetPeiServicesTablePointer ();\r
+  Status = (*PeiServices)->AllocatePages (PeiServices, MemoryType, Pages, &Memory);\r
+  if (EFI_ERROR (Status)) {\r
+    Memory = 0;\r
+  }\r
+  return (VOID *) (UINTN) Memory;\r
+}\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiBootServicesData.\r
+\r
+  Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the\r
+  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL\r
+  is returned.  If there is not enough memory remaining to satisfy the request, then NULL is\r
+  returned.\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocatePages (\r
+  IN UINTN  Pages\r
+  )\r
+{\r
+  return InternalAllocatePages (EfiBootServicesData, Pages);\r
+}\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiRuntimeServicesData.\r
+\r
+  Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the\r
+  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL\r
+  is returned.  If there is not enough memory remaining to satisfy the request, then NULL is\r
+  returned.\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateRuntimePages (\r
+  IN UINTN  Pages\r
+  )\r
+{\r
+  return InternalAllocatePages (EfiRuntimeServicesData, Pages);\r
+}\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiReservedMemoryType.\r
+\r
+  Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the\r
+  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL\r
+  is returned.  If there is not enough memory remaining to satisfy the request, then NULL is\r
+  returned.\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateReservedPages (\r
+  IN UINTN  Pages\r
+  )\r
+{\r
+  return InternalAllocatePages (EfiReservedMemoryType, Pages);\r
+}\r
+\r
+/**\r
+  Frees one or more 4KB pages that were previously allocated with one of the page allocation\r
+  functions in the Memory Allocation Library.\r
+\r
+  Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer\r
+  must have been allocated on a previous call to the page allocation services of the Memory\r
+  Allocation Library.\r
+  If Buffer was not allocated with a page allocation function in the Memory Allocation Library,\r
+  then ASSERT().\r
+  If Pages is zero, then ASSERT().\r
\r
+  @param  Buffer                Pointer to the buffer of pages to free.\r
+  @param  Pages                 The number of 4 KB pages to free.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+FreePages (\r
+  IN VOID   *Buffer,\r
+  IN UINTN  Pages\r
+  )\r
+{\r
+  //\r
+  // PEI phase does not support to free pages, so leave it as NOP.\r
+  //\r
+}\r
+\r
+/**\r
+  Allocates one or more 4KB pages of a certain memory type at a specified alignment.\r
+\r
+  Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment\r
+  specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is returned.\r
+  If there is not enough memory at the specified alignment remaining to satisfy the request, then\r
+  NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  MemoryType            The type of memory to allocate.\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateAlignedPages (\r
+  IN EFI_MEMORY_TYPE  MemoryType,  \r
+  IN UINTN            Pages,\r
+  IN UINTN            Alignment\r
+  )\r
+{\r
+  VOID    *Memory;\r
+  UINTN   AlignmentMask;\r
+\r
+  //\r
+  // Alignment must be a power of two or zero.\r
+  //\r
+  ASSERT ((Alignment & (Alignment - 1)) == 0);\r
+\r
+  if (Pages == 0) {\r
+    return NULL;\r
+  }\r
+  //\r
+  // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.\r
+  //\r
+  ASSERT (Pages <= (MAX_ADDRESS - EFI_SIZE_TO_PAGES (Alignment)));\r
+  //\r
+  // We would rather waste some memory to save PEI code size.\r
+  //\r
+  Memory = InternalAllocatePages (MemoryType, Pages + EFI_SIZE_TO_PAGES (Alignment));\r
+  if (Alignment == 0) {\r
+    AlignmentMask = Alignment;\r
+  } else {\r
+    AlignmentMask = Alignment - 1;  \r
+  }\r
+  return (VOID *) (UINTN) (((UINTN) Memory + AlignmentMask) & ~AlignmentMask);\r
+}\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.\r
+\r
+  Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is\r
+  returned.  If there is not enough memory at the specified alignment remaining to satisfy the\r
+  request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedPages (\r
+  IN UINTN  Pages,\r
+  IN UINTN  Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedPages (EfiBootServicesData, Pages, Alignment);\r
+}\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.\r
+\r
+  Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is\r
+  returned.  If there is not enough memory at the specified alignment remaining to satisfy the\r
+  request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedRuntimePages (\r
+  IN UINTN  Pages,\r
+  IN UINTN  Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedPages (EfiRuntimeServicesData, Pages, Alignment);\r
+}\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.\r
+\r
+  Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is\r
+  returned.  If there is not enough memory at the specified alignment remaining to satisfy the\r
+  request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedReservedPages (\r
+  IN UINTN  Pages,\r
+  IN UINTN  Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedPages (EfiReservedMemoryType, Pages, Alignment);\r
+}\r
+\r
+/**\r
+  Frees one or more 4KB pages that were previously allocated with one of the aligned page\r
+  allocation functions in the Memory Allocation Library.\r
+\r
+  Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer\r
+  must have been allocated on a previous call to the aligned page allocation services of the Memory\r
+  Allocation Library.\r
+  If Buffer was not allocated with an aligned page allocation function in the Memory Allocation\r
+  Library, then ASSERT().\r
+  If Pages is zero, then ASSERT().\r
+  \r
+  @param  Buffer                Pointer to the buffer of pages to free.\r
+  @param  Pages                 The number of 4 KB pages to free.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+FreeAlignedPages (\r
+  IN VOID   *Buffer,\r
+  IN UINTN  Pages\r
+  )\r
+{\r
+  //\r
+  // PEI phase does not support to free pages, so leave it as NOP.\r
+  //\r
+}\r
+\r
+/**\r
+  Allocates a buffer of a certain pool type.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type and returns a\r
+  pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is\r
+  returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  @param  MemoryType            The type of memory to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocatePool (\r
+  IN EFI_MEMORY_TYPE  MemoryType,  \r
+  IN UINTN            AllocationSize\r
+  )\r
+{\r
+  //\r
+  // If we need lots of small runtime/reserved memory type from PEI in the future, \r
+  // we can consider providing a more complex algorithm that allocates runtime pages and \r
+  // provide pool allocations from those pages. \r
+  //\r
+  return InternalAllocatePages (MemoryType, EFI_SIZE_TO_PAGES (AllocationSize));\r
+}\r
+\r
+/**\r
+  Allocates a buffer of type EfiBootServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a\r
+  pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is\r
+  returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocatePool (\r
+  IN UINTN  AllocationSize\r
+  )\r
+{\r
+  EFI_STATUS        Status;\r
+  EFI_PEI_SERVICES  **PeiServices;\r
+  VOID              *Buffer;\r
+  \r
+  PeiServices = GetPeiServicesTablePointer ();\r
+\r
+  Status = (*PeiServices)->AllocatePool (PeiServices, AllocationSize, &Buffer);\r
+  if (EFI_ERROR (Status)) {\r
+    Buffer = NULL;\r
+  }\r
+  return Buffer;\r
+}\r
+\r
+/**\r
+  Allocates a buffer of type EfiRuntimeServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns\r
+  a pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is\r
+  returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateRuntimePool (\r
+  IN UINTN  AllocationSize\r
+  )\r
+{\r
+  return InternalAllocatePool (EfiRuntimeServicesData, AllocationSize);\r
+}\r
+\r
+/**\r
+  Allocates a buffer of type EfieservedMemoryType.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType and returns\r
+  a pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is\r
+  returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateReservedPool (\r
+  IN UINTN  AllocationSize\r
+  )\r
+{\r
+  return InternalAllocatePool (EfiReservedMemoryType, AllocationSize);\r
+}\r
+\r
+/**\r
+  Allocates and zeros a buffer of a certian pool type.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer\r
+  with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a valid\r
+  buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the request,\r
+  then NULL is returned.\r
+\r
+  @param  PoolType              The type of memory to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateZeroPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,  \r
+  IN UINTN            AllocationSize\r
+  ) \r
+{\r
+  VOID  *Memory;\r
+\r
+  Memory = InternalAllocatePool (PoolType, AllocationSize);\r
+  if (Memory != NULL) {\r
+    Memory = ZeroMem (Memory, AllocationSize);\r
+  }\r
+  return Memory;\r
+}\r
+\r
+/**\r
+  Allocates and zeros a buffer of type EfiBootServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the\r
+  buffer with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a\r
+  valid buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the\r
+  request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateZeroPool (\r
+  IN UINTN  AllocationSize\r
+  )\r
+{\r
+  VOID  *Memory;\r
+\r
+  Memory = AllocatePool (AllocationSize);\r
+  if (Memory != NULL) {\r
+    Memory = ZeroMem (Memory, AllocationSize);\r
+  }\r
+  return Memory;\r
+}\r
+\r
+/**\r
+  Allocates and zeros a buffer of type EfiRuntimeServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the\r
+  buffer with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a\r
+  valid buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the\r
+  request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateRuntimeZeroPool (\r
+  IN UINTN  AllocationSize\r
+  )\r
+{\r
+  return InternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize);\r
+}\r
+\r
+/**\r
+  Allocates and zeros a buffer of type EfiReservedMemoryType.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the\r
+  buffer with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a\r
+  valid buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the\r
+  request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateReservedZeroPool (\r
+  IN UINTN  AllocationSize\r
+  )\r
+{\r
+  return InternalAllocateZeroPool (EfiReservedMemoryType, AllocationSize);\r
+}\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of a certian pool type.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certian pool type, copies\r
+  AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory remaining to satisfy the request, then NULL is returned.\r
+  If Buffer is NULL, then ASSERT().\r
+  If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
+\r
+  @param  PoolType              The type of pool to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateCopyPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,  \r
+  IN UINTN            AllocationSize,\r
+  IN CONST VOID       *Buffer\r
+  ) \r
+{\r
+  VOID  *Memory;\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));\r
+\r
+  Memory = InternalAllocatePool (PoolType, AllocationSize);\r
+  if (Memory != NULL) {\r
+     Memory = CopyMem (Memory, Buffer, AllocationSize);\r
+  }\r
+  return Memory;\r
+} \r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of type EfiBootServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies\r
+  AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory remaining to satisfy the request, then NULL is returned.\r
+  If Buffer is NULL, then ASSERT().\r
+  If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
+\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateCopyPool (\r
+  IN UINTN       AllocationSize,\r
+  IN CONST VOID  *Buffer\r
+  )\r
+{\r
+  VOID  *Memory;\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));\r
+\r
+  Memory = AllocatePool (AllocationSize);\r
+  if (Memory != NULL) {\r
+     Memory = CopyMem (Memory, Buffer, AllocationSize);\r
+  }\r
+  return Memory;\r
+}\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies\r
+  AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory remaining to satisfy the request, then NULL is returned.\r
+  If Buffer is NULL, then ASSERT().\r
+  If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
+\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateRuntimeCopyPool (\r
+  IN UINTN       AllocationSize,\r
+  IN CONST VOID  *Buffer\r
+  )\r
+{\r
+  return InternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer);\r
+}\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of type EfiReservedMemoryType.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies\r
+  AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory remaining to satisfy the request, then NULL is returned.\r
+  If Buffer is NULL, then ASSERT().\r
+  If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
+\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateReservedCopyPool (\r
+  IN UINTN       AllocationSize,\r
+  IN CONST VOID  *Buffer\r
+  )\r
+{\r
+  return InternalAllocateCopyPool (EfiReservedMemoryType, AllocationSize, Buffer);\r
+}\r
+\r
+/**\r
+  Frees a buffer that was previously allocated with one of the pool allocation functions in the\r
+  Memory Allocation Library.\r
+\r
+  Frees the buffer specified by Buffer.  Buffer must have been allocated on a previous call to the\r
+  pool allocation services of the Memory Allocation Library.\r
+  If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,\r
+  then ASSERT().\r
+\r
+  @param  Buffer                Pointer to the buffer to free.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+FreePool (\r
+  IN VOID   *Buffer\r
+  )\r
+{\r
+  //\r
+  // PEI phase does not support to free pool, so leave it as NOP.\r
+  //\r
+}\r
+\r
+/**\r
+  Allocates a buffer of a certain pool type at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment\r
+  specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0, then a valid\r
+  buffer of 0 size is returned.  If there is not enough memory at the specified alignment remaining\r
+  to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  PoolType              The type of pool to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.                            If Alignment is zero, then byte alignment is used.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateAlignedPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,\r
+  IN UINTN            AllocationSize,\r
+  IN UINTN            Alignment\r
+  )\r
+{\r
+  VOID    *RawAddress;\r
+  UINTN   AlignedAddress;\r
+  UINTN   AlignmentMask;\r
+\r
+  //\r
+  // Alignment must be a power of two or zero.\r
+  //\r
+  ASSERT ((Alignment & (Alignment - 1)) == 0);\r
+  \r
+  if (Alignment == 0) {\r
+    AlignmentMask = Alignment;\r
+  } else {\r
+    AlignmentMask = Alignment - 1;\r
+  }\r
+  //\r
+  // Make sure that AllocationSize plus AlignmentMask does not overflow.\r
+  //\r
+  ASSERT (AllocationSize <= (MAX_ADDRESS - AlignmentMask));\r
+\r
+  RawAddress      = InternalAllocatePool (PoolType, AllocationSize + AlignmentMask);\r
+  \r
+  AlignedAddress  = ((UINTN) RawAddress + AlignmentMask) & ~AlignmentMask;\r
+    \r
+  return (VOID *) AlignedAddress;\r
+}\r
+\r
+/**\r
+  Allocates a buffer of type EfiBootServicesData at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,\r
+  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified\r
+  alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedPool (\r
+  IN UINTN  AllocationSize,\r
+  IN UINTN  Alignment\r
+  )\r
+{\r
+  VOID    *RawAddress;\r
+  UINTN   AlignedAddress;\r
+  UINTN   AlignmentMask;\r
+\r
+  //\r
+  // Alignment must be a power of two or zero.\r
+  //\r
+  ASSERT ((Alignment & (Alignment - 1)) == 0);\r
+\r
+  if (Alignment == 0) {\r
+    AlignmentMask = Alignment;\r
+  } else {\r
+    AlignmentMask = Alignment - 1;\r
+  }\r
+\r
+  //\r
+  // Make sure that AllocationSize plus AlignmentMask does not overflow.\r
+  //\r
+  ASSERT (AllocationSize <= (MAX_ADDRESS - AlignmentMask));\r
+\r
+  RawAddress      = AllocatePool (AllocationSize + AlignmentMask);\r
+  \r
+  AlignedAddress  = ((UINTN) RawAddress + AlignmentMask) & ~AlignmentMask;\r
+    \r
+  return (VOID *) AlignedAddress;\r
+}\r
+\r
+/**\r
+  Allocates a buffer of type EfiRuntimeServicesData at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,\r
+  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified\r
+  alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedRuntimePool (\r
+  IN UINTN  AllocationSize,\r
+  IN UINTN  Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedPool (EfiRuntimeServicesData, AllocationSize, Alignment);\r
+}\r
+\r
+/**\r
+  Allocates a buffer of type EfieservedMemoryType at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,\r
+  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified\r
+  alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedReservedPool (\r
+  IN UINTN  AllocationSize,\r
+  IN UINTN  Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedPool (EfiReservedMemoryType, AllocationSize, Alignment);\r
+}\r
+\r
+/**\r
+  Allocates and zeros a buffer of a certain pool type at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment\r
+  specified by Alignment, clears the buffer with zeros, and returns a pointer to the allocated\r
+  buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there is not\r
+  enough memory at the specified alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  PoolType              The type of pool to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateAlignedZeroPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,\r
+  IN UINTN            AllocationSize,\r
+  IN UINTN            Alignment\r
+  )\r
+{\r
+  VOID    *Memory;\r
+\r
+  Memory = InternalAllocateAlignedPool (PoolType, AllocationSize, Alignment);\r
+  if (Memory != NULL) {\r
+    Memory = ZeroMem (Memory, AllocationSize);\r
+  }\r
+  return Memory;\r
+}\r
+\r
+/**\r
+  Allocates and zeros a buffer of type EfiBootServicesData at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an\r
+  alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory at the specified alignment remaining to satisfy the request, then NULL is\r
+  returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedZeroPool (\r
+  IN UINTN  AllocationSize,\r
+  IN UINTN  Alignment\r
+  )\r
+{\r
+  VOID    *Memory;\r
+\r
+  Memory = AllocateAlignedPool (AllocationSize, Alignment);\r
+  if (Memory != NULL) {\r
+    Memory = ZeroMem (Memory, AllocationSize);\r
+  }\r
+  return Memory;\r
+}\r
+\r
+/**\r
+  Allocates and zeros a buffer of type EfiRuntimeServicesData at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an\r
+  alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory at the specified alignment remaining to satisfy the request, then NULL is\r
+  returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedRuntimeZeroPool (\r
+  IN UINTN  AllocationSize,\r
+  IN UINTN  Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedZeroPool (EfiRuntimeServicesData, AllocationSize, Alignment);\r
+}\r
+\r
+/**\r
+  Allocates and zeros a buffer of type EfieservedMemoryType at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an\r
+  alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory at the specified alignment remaining to satisfy the request, then NULL is\r
+  returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedReservedZeroPool (\r
+  IN UINTN  AllocationSize,\r
+  IN UINTN  Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedZeroPool (EfiReservedMemoryType, AllocationSize, Alignment);\r
+}\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of a certain pool type at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment\r
+  specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0, then a valid\r
+  buffer of 0 size is returned.  If there is not enough memory at the specified alignment remaining\r
+  to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  PoolType              The type of pool to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateAlignedCopyPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,\r
+  IN UINTN            AllocationSize,\r
+  IN CONST VOID       *Buffer,\r
+  IN UINTN            Alignment\r
+  )\r
+{\r
+  VOID  *Memory;\r
+  \r
+  ASSERT (Buffer != NULL);\r
+  ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));\r
+\r
+  Memory = InternalAllocateAlignedPool (PoolType, AllocationSize, Alignment);\r
+  if (Memory != NULL) {\r
+    Memory = CopyMem (Memory, Buffer, AllocationSize);\r
+  }\r
+  return Memory;\r
+}\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of type EfiBootServicesData at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData type with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,\r
+  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified\r
+  alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedCopyPool (\r
+  IN UINTN       AllocationSize,\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Alignment\r
+  )\r
+{\r
+  VOID  *Memory;\r
+  \r
+  ASSERT (Buffer != NULL);\r
+  ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));\r
+\r
+  Memory = AllocateAlignedPool (AllocationSize, Alignment);\r
+  if (Memory != NULL) {\r
+    Memory = CopyMem (Memory, Buffer, AllocationSize);\r
+  }\r
+  return Memory;\r
+}\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of type EfiRuntimeServicesData at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData type with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,\r
+  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified\r
+  alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedRuntimeCopyPool (\r
+  IN UINTN       AllocationSize,\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer, Alignment);\r
+}\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of type EfiReservedMemoryType at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType type with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,\r
+  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified\r
+  alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedReservedCopyPool (\r
+  IN UINTN       AllocationSize,\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Alignment\r
+  )\r
+{\r
+  return InternalAllocateAlignedCopyPool (EfiReservedMemoryType, AllocationSize, Buffer, Alignment);\r
+}\r
+\r
+/**\r
+  Frees a buffer that was previously allocated with one of the aligned pool allocation functions \r
+  in the Memory Allocation Library.\r
+\r
+  Frees the buffer specified by Buffer.  Buffer must have been allocated on a previous call to the\r
+  aligned pool allocation services of the Memory Allocation Library.\r
+  If Buffer was not allocated with an aligned pool allocation function in the Memory Allocation\r
+  Library, then ASSERT().\r
+\r
+  @param  Buffer                Pointer to the buffer to free.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+FreeAlignedPool (\r
+  IN VOID   *Buffer\r
+  )\r
+{\r
+  //\r
+  // PEI phase does not support to free pool, so leave it as NOP.\r
+  //\r
+}\r
diff --git a/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLibInternals.h b/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLibInternals.h
new file mode 100644 (file)
index 0000000..73745d9
--- /dev/null
@@ -0,0 +1,205 @@
+/** @file\r
+  Internal include file of PEI Memory Allocation Library.\r
+\r
+  Copyright (c) 2006, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Module Name:  MemoryAllocationLibInternals.h\r
+\r
+**/\r
+\r
+#ifndef __PEI_MEMORY_ALLOCATION_LIB_INTERNALS_H__\r
+#define __PEI_MEMORY_ALLOCATION_LIB_INTERNALS_H__\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+/**\r
+  Allocates one or more 4KB pages of a certain memory type.\r
+\r
+  Allocates the number of 4KB pages of a certain memory type and returns a pointer to the allocated\r
+  buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL is returned.\r
+  If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  @param  MemoryType            The type of memory to allocate.\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocatePages (\r
+  IN EFI_MEMORY_TYPE  MemoryType,  \r
+  IN UINTN            Pages\r
+  );\r
+\r
+/**\r
+  Allocates one or more 4KB pages of a certain memory type at a specified alignment.\r
+\r
+  Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment\r
+  specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is returned.\r
+  If there is not enough memory at the specified alignment remaining to satisfy the request, then\r
+  NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  MemoryType            The type of memory to allocate.\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateAlignedPages (\r
+  IN EFI_MEMORY_TYPE  MemoryType,  \r
+  IN UINTN            Pages,\r
+  IN UINTN            Alignment\r
+  );\r
+\r
+/**\r
+  Allocates a buffer of a certain pool type.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type and returns a\r
+  pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is\r
+  returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  @param  MemoryType            The type of memory to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocatePool (\r
+  IN EFI_MEMORY_TYPE  MemoryType,  \r
+  IN UINTN            AllocationSize\r
+  );\r
+\r
+/**\r
+  Allocates and zeros a buffer of a certian pool type.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer\r
+  with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a valid\r
+  buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the request,\r
+  then NULL is returned.\r
+\r
+  @param  PoolType              The type of memory to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateZeroPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,  \r
+  IN UINTN            AllocationSize\r
+  );\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of a certian pool type.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certian pool type, copies\r
+  AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory remaining to satisfy the request, then NULL is returned.\r
+  If Buffer is NULL, then ASSERT().\r
+  If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
+\r
+  @param  PoolType              The type of pool to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateCopyPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,  \r
+  IN UINTN            AllocationSize,\r
+  IN CONST VOID       *Buffer\r
+  );\r
+\r
+/**\r
+  Allocates a buffer of a certain pool type at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment\r
+  specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0, then a valid\r
+  buffer of 0 size is returned.  If there is not enough memory at the specified alignment remaining\r
+  to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  PoolType              The type of pool to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.                            If Alignment is zero, then byte alignment is used.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateAlignedPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,\r
+  IN UINTN            AllocationSize,\r
+  IN UINTN            Alignment\r
+  );\r
+\r
+/**\r
+  Allocates and zeros a buffer of a certain pool type at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment\r
+  specified by Alignment, clears the buffer with zeros, and returns a pointer to the allocated\r
+  buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there is not\r
+  enough memory at the specified alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  PoolType              The type of pool to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateAlignedZeroPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,\r
+  IN UINTN            AllocationSize,\r
+  IN UINTN            Alignment\r
+  );\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of a certain pool type at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment\r
+  specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0, then a valid\r
+  buffer of 0 size is returned.  If there is not enough memory at the specified alignment remaining\r
+  to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  PoolType              The type of pool to allocate.\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+InternalAllocateAlignedCopyPool (\r
+  IN EFI_MEMORY_TYPE  PoolType,\r
+  IN UINTN            AllocationSize,\r
+  IN CONST VOID       *Buffer,\r
+  IN UINTN            Alignment\r
+  );\r
+\r
+#endif\r
diff --git a/MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf b/MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf
new file mode 100644 (file)
index 0000000..ee462f8
--- /dev/null
@@ -0,0 +1,84 @@
+#/** @file\r
+# Component description file for Pei Memory Allocation Library\r
+#\r
+# Memory Allocation Library that uses PEI Services to allocate memory.\r
+#  Free operations are ignored.\r
+# Copyright (c) 2007, Intel Corporation\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PeiMemoryAllocationLib\r
+  FILE_GUID                      = b694e0dc-cd4e-4b30-885b-9c164ed3e74a\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = MemoryAllocationLib|PEIM PEI_CORE \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  MemoryAllocationLibInternals.h\r
+  MemoryAllocationLib.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg\Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  BaseMemoryLib\r
+  PeiServicesTablePointerLib\r
+\r
diff --git a/MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.msa b/MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.msa
new file mode 100644 (file)
index 0000000..602524b
--- /dev/null
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>PeiMemoryAllocationLib</ModuleName>\r
+    <ModuleType>PEIM</ModuleType>\r
+    <GuidValue>b694e0dc-cd4e-4b30-885b-9c164ed3e74a</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for Pei Memory Allocation Library</Abstract>\r
+    <Description>Memory Allocation Library that uses PEI Services to allocate memory.
+      Free operations are ignored.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>PeiMemoryAllocationLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="PEIM PEI_CORE">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeiServicesTablePointerLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>MemoryAllocationLib.c</Filename>\r
+    <Filename>MemoryAllocationLibInternals.h</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdePkg/Library/PeiPcdLib/CommonHeader.h b/MdePkg/Library/PeiPcdLib/CommonHeader.h
new file mode 100644 (file)
index 0000000..dae5581
--- /dev/null
@@ -0,0 +1,35 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiPei.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Ppi/Pcd.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/PcdLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/PeiPcdLib/PeiPcdLib.c b/MdePkg/Library/PeiPcdLib/PeiPcdLib.c
new file mode 100644 (file)
index 0000000..76102c6
--- /dev/null
@@ -0,0 +1,1079 @@
+/** @file\r
+Implementation of PcdLib class library for PEI phase.\r
+\r
+Copyright (c) 2006, Intel Corporation<BR>\r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+\r
+Module Name: PeiPcdLib.c\r
+\r
+**/\r
+\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+/**\r
+  The constructor function retrieve the PCD_PPI pointer.\r
+\r
+  @param[in] VOID\r
+  \r
+  @retval PCD_PPI * The pointer to the PCD_PPI.\r
+\r
+**/\r
+STATIC\r
+PCD_PPI  *\r
+GetPcdPpiPtr (\r
+  VOID\r
+  ) \r
+{\r
+  EFI_STATUS        Status;\r
+  PCD_PPI           *PcdPpi;\r
+  EFI_PEI_SERVICES  **PeiServices;\r
+\r
+\r
+  PeiServices = GetPeiServicesTablePointer ();\r
+\r
+  Status = (**PeiServices).LocatePpi (\r
+                             PeiServices,\r
+                             &gPcdPpiGuid,\r
+                             0,\r
+                             NULL,\r
+                             (VOID **)&PcdPpi\r
+                             );\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return PcdPpi;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the current SKU in the PCD database to the value specified by SkuId.  SkuId is returned.\r
+\r
+  @param[in]  SkuId The SKU value that will be used when the PCD service will retrieve and \r
+              set values associated with a PCD token.\r
+\r
+  @retval SKU_ID Return the SKU ID that just be set.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+LibPcdSetSku (\r
+  IN UINTN  SkuId\r
+  )\r
+{\r
+\r
+  ASSERT (SkuId < 0x100);\r
+\r
+  GetPcdPpiPtr()->SetSku (SkuId);;\r
+\r
+  return SkuId;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the 8-bit value for the token specified by TokenNumber. \r
+\r
+  @param[in]  The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber. \r
+\r
+**/\r
+UINT8\r
+EFIAPI\r
+LibPcdGet8 (\r
+  IN UINTN                        TokenNumber\r
+  )\r
+{\r
+  PCD_PPI * PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  return PcdPpi->Get8 (TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the 16-bit value for the token specified by TokenNumber. \r
+\r
+  @param[in]  The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber. \r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+LibPcdGet16 (\r
+  IN UINTN                        TokenNumber\r
+  )\r
+{\r
+  PCD_PPI  *PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  return PcdPpi->Get16 (TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the 32-bit value for the token specified by TokenNumber. \r
+\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.\r
+\r
+**/\r
+UINT32\r
+EFIAPI\r
+LibPcdGet32 (\r
+  IN UINTN                        TokenNumber\r
+  )\r
+{\r
+  PCD_PPI * PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  return PcdPpi->Get32 (TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the 64-bit value for the token specified by TokenNumber.\r
+\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+LibPcdGet64 (\r
+  IN UINTN                        TokenNumber\r
+  )\r
+{\r
+  PCD_PPI * PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  return PcdPpi->Get64 (TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the pointer to the buffer of the token specified by TokenNumber.\r
+\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval VOID* Returns the pointer to the token specified by TokenNumber.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+LibPcdGetPtr (\r
+  IN UINTN                        TokenNumber\r
+  )\r
+{\r
+  PCD_PPI * PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  return PcdPpi->GetPtr (TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the Boolean value of the token specified by TokenNumber. \r
+\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber. \r
+\r
+**/\r
+BOOLEAN \r
+EFIAPI\r
+LibPcdGetBool (\r
+  IN UINTN                        TokenNumber\r
+  )\r
+{\r
+  PCD_PPI * PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  return PcdPpi->GetBool (TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the size of the token specified by TokenNumber. \r
+\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINTN Returns the size of the token specified by TokenNumber. \r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+LibPcdGetSize (\r
+  IN UINTN                        TokenNumber\r
+  )\r
+{\r
+  PCD_PPI * PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  return PcdPpi->GetSize (TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the 8-bit value for the token specified by TokenNumber and Guid.\r
+  If Guid is NULL, then ASSERT(). \r
+\r
+  @param[in]  Guid Pointer to a 128-bit unique value that designates \r
+              which namespace to retrieve a value from.\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINT8 Return the UINT8.\r
+\r
+**/\r
+UINT8\r
+EFIAPI\r
+LibPcdGetEx8 (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  PCD_PPI * PcdPpi;\r
+\r
+  ASSERT (Guid != NULL);\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  return PcdPpi->Get8Ex (Guid, TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the 16-bit value for the token specified by TokenNumber and Guid.\r
+  If Guid is NULL, then ASSERT(). \r
+\r
+  @param[in]  Guid Pointer to a 128-bit unique value that designates \r
+              which namespace to retrieve a value from.\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINT16 Return the UINT16.\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+LibPcdGetEx16 (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  PCD_PPI * PcdPpi;\r
+\r
+  ASSERT (Guid != NULL);\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  return PcdPpi->Get16Ex (Guid, TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the 32-bit value for the token specified by TokenNumber and Guid.\r
+  If Guid is NULL, then ASSERT(). \r
+\r
+  @param[in]  Guid Pointer to a 128-bit unique value that designates \r
+              which namespace to retrieve a value from.\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINT32 Return the UINT32.\r
+\r
+**/\r
+UINT32\r
+EFIAPI\r
+LibPcdGetEx32 (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  PCD_PPI * PcdPpi;\r
+\r
+  ASSERT (Guid != NULL);\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  return PcdPpi->Get32Ex (Guid, TokenNumber);\r
+}\r
+\r
+\r
+\r
+\r
+/**\r
+  Returns the 64-bit value for the token specified by TokenNumber and Guid.\r
+  If Guid is NULL, then ASSERT(). \r
+\r
+  @param[in]  Guid Pointer to a 128-bit unique value that designates \r
+              which namespace to retrieve a value from.\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINT64 Return the UINT64.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+LibPcdGetEx64 (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  PCD_PPI * PcdPpi;\r
+\r
+  ASSERT (Guid != NULL);\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  return PcdPpi->Get64Ex (Guid, TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the pointer to the token specified by TokenNumber and Guid.\r
+  If Guid is NULL, then ASSERT(). \r
+\r
+  @param[in]  Guid Pointer to a 128-bit unique value that designates \r
+              which namespace to retrieve a value from.\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval VOID* Return the VOID* pointer.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+LibPcdGetExPtr (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  PCD_PPI * PcdPpi;\r
+\r
+  ASSERT (Guid != NULL);\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  return PcdPpi->GetPtrEx (Guid, TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the Boolean value of the token specified by TokenNumber and Guid. \r
+  If Guid is NULL, then ASSERT(). \r
+\r
+  @param[in]  Guid Pointer to a 128-bit unique value that designates \r
+              which namespace to retrieve a value from.\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval BOOLEAN Return the BOOLEAN.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+LibPcdGetExBool (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  PCD_PPI * PcdPpi;\r
+\r
+  ASSERT (Guid != NULL);\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  return PcdPpi->GetBoolEx (Guid, TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Returns the size of the token specified by TokenNumber and Guid. \r
+  If Guid is NULL, then ASSERT(). \r
+\r
+  @param[in]  Guid Pointer to a 128-bit unique value that designates \r
+              which namespace to retrieve a value from.\r
+  @param[in]  TokenNumber The PCD token number to retrieve a current value for.\r
+\r
+  @retval UINTN Return the size.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+LibPcdGetExSize (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber\r
+  )\r
+{\r
+  PCD_PPI * PcdPpi;\r
+\r
+  ASSERT (Guid != NULL);\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  return PcdPpi->GetSizeEx (Guid, TokenNumber);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the 8-bit value for the token specified by TokenNumber \r
+  to the value specified by Value.  Value is returned.\r
+  \r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The 8-bit value to set.\r
+\r
+  @retval UINT8 Return the value been set.\r
+\r
+**/\r
+UINT8\r
+EFIAPI\r
+LibPcdSet8 (\r
+  IN UINTN             TokenNumber,\r
+  IN UINT8             Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  PCD_PPI * PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  Status = PcdPpi->Set8 (TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the 16-bit value for the token specified by TokenNumber \r
+  to the value specified by Value.  Value is returned.\r
+  \r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The 16-bit value to set.\r
+\r
+  @retval UINT16 Return the value been set.\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+LibPcdSet16 (\r
+  IN UINTN             TokenNumber,\r
+  IN UINT16            Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  PCD_PPI * PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  Status = PcdPpi->Set16 (TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the 32-bit value for the token specified by TokenNumber \r
+  to the value specified by Value.  Value is returned.\r
+  \r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The 32-bit value to set.\r
+\r
+  @retval UINT32 Return the value been set.\r
+\r
+**/\r
+UINT32\r
+EFIAPI\r
+LibPcdSet32 (\r
+  IN UINTN             TokenNumber,\r
+  IN UINT32             Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  PCD_PPI * PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  Status = PcdPpi->Set32 (TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the 64-bit value for the token specified by TokenNumber \r
+  to the value specified by Value.  Value is returned.\r
+  \r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The 64-bit value to set.\r
+\r
+  @retval UINT64 Return the value been set.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+LibPcdSet64 (\r
+  IN UINTN             TokenNumber,\r
+  IN UINT64             Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  PCD_PPI * PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  Status = PcdPpi->Set64 (TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets a buffer for the token specified by TokenNumber to \r
+  the value specified by Buffer and SizeOfValue.  Buffer to\r
+  be set is returned. The content of the buffer could be \r
+  overwritten if a Callback on SET is registered with this\r
+  TokenNumber.\r
+  \r
+  If SizeOfValue is greater than the maximum \r
+  size support by TokenNumber, then set SizeOfValue to the \r
+  maximum size supported by TokenNumber and return NULL to \r
+  indicate that the set operation was not actually performed. \r
+  \r
+  If SizeOfValue > 0 and Buffer is NULL, then ASSERT().\r
+  \r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in,out] SizeOfBuffer The size, in bytes, of Buffer.\r
+  @param[in]  Value A pointer to the buffer to set.\r
+\r
+  @retval VOID* Return the pointer for the buffer been set.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+LibPcdSetPtr (\r
+  IN      UINTN             TokenNumber,\r
+  IN OUT  UINTN             *SizeOfBuffer,\r
+  IN      VOID              *Buffer\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  PCD_PPI    *PcdPpi;\r
+\r
+  ASSERT (SizeOfBuffer != NULL);\r
+\r
+  if (*SizeOfBuffer > 0) {\r
+    ASSERT (Buffer != NULL);\r
+  }\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+  \r
+  Status = PcdPpi->SetPtr (TokenNumber, SizeOfBuffer, Buffer);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return NULL;\r
+  }\r
+\r
+  return Buffer;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the Boolean value for the token specified by TokenNumber \r
+  to the value specified by Value.  Value is returned.\r
+  \r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The boolean value to set.\r
+\r
+  @retval BOOLEAN Return the value been set.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+LibPcdSetBool (\r
+  IN UINTN             TokenNumber,\r
+  IN BOOLEAN           Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  PCD_PPI * PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  Status = PcdPpi->SetBool (TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the 8-bit value for the token specified by TokenNumber and \r
+  Guid to the value specified by Value. Value is returned.\r
+  If Guid is NULL, then ASSERT().\r
+  \r
+  @param[in]  Guid Pointer to a 128-bit unique value that \r
+              designates which namespace to set a value from.\r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The 8-bit value to set.\r
+\r
+  @retval UINT8 Return the value been set.\r
+\r
+**/\r
+UINT8\r
+EFIAPI\r
+LibPcdSetEx8 (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber,\r
+  IN UINT8             Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  PCD_PPI * PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  ASSERT (Guid != NULL);\r
+\r
+  Status = PcdPpi->Set8Ex (Guid, TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the 16-bit value for the token specified by TokenNumber and \r
+  Guid to the value specified by Value. Value is returned.\r
+  If Guid is NULL, then ASSERT().\r
+  \r
+  @param[in]  Guid Pointer to a 128-bit unique value that \r
+              designates which namespace to set a value from.\r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The 16-bit value to set.\r
+\r
+  @retval UINT8 Return the value been set.\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+LibPcdSetEx16 (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber,\r
+  IN UINT16            Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  PCD_PPI * PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  ASSERT (Guid != NULL);\r
+  Status = PcdPpi->Set16Ex (Guid, TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the 32-bit value for the token specified by TokenNumber and \r
+  Guid to the value specified by Value. Value is returned.\r
+  If Guid is NULL, then ASSERT().\r
+  \r
+  @param[in]  Guid Pointer to a 128-bit unique value that \r
+              designates which namespace to set a value from.\r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The 32-bit value to set.\r
+\r
+  @retval UINT32 Return the value been set.\r
+\r
+**/\r
+UINT32\r
+EFIAPI\r
+LibPcdSetEx32 (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber,\r
+  IN UINT32             Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  PCD_PPI * PcdPpi;\r
+  ASSERT (Guid != NULL);\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+\r
+  Status = PcdPpi->Set32Ex (Guid, TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the 64-bit value for the token specified by TokenNumber and \r
+  Guid to the value specified by Value. Value is returned.\r
+  If Guid is NULL, then ASSERT().\r
+  \r
+  @param[in]  Guid Pointer to a 128-bit unique value that \r
+              designates which namespace to set a value from.\r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The 64-bit value to set.\r
+\r
+  @retval UINT64 Return the value been set.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+LibPcdSetEx64 (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber,\r
+  IN UINT64            Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  PCD_PPI * PcdPpi;\r
+  ASSERT (Guid != NULL);\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+\r
+  Status = PcdPpi->Set64Ex (Guid, TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets a buffer for the token specified by TokenNumber to the value specified by \r
+  Buffer and SizeOfValue.  Buffer is returned.  If SizeOfValue is greater than \r
+  the maximum size support by TokenNumber, then set SizeOfValue to the maximum size \r
+  supported by TokenNumber and return NULL to indicate that the set operation \r
+  was not actually performed. \r
+  \r
+  If SizeOfValue > 0 and Buffer is NULL, then ASSERT().\r
+  \r
+  @param[in]  Guid Pointer to a 128-bit unique value that \r
+              designates which namespace to set a value from.\r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.\r
+  @param[in]  Buffer A pointer to the buffer to set.\r
+\r
+  @retval VOID * Return the pinter to the buffer been set.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+LibPcdSetExPtr (\r
+  IN      CONST GUID        *Guid,\r
+  IN      UINTN             TokenNumber,\r
+  IN OUT  UINTN             *SizeOfBuffer,\r
+  IN      VOID              *Buffer\r
+  )\r
+{\r
+  EFI_STATUS      Status;\r
+  PCD_PPI         *PcdPpi;\r
+ ASSERT (SizeOfBuffer != NULL);\r
+  if (*SizeOfBuffer > 0) {\r
+    ASSERT (Buffer != NULL);\r
+  }\r
+  ASSERT (Guid != NULL);\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  Status = PcdPpi->SetPtrEx (Guid, TokenNumber, SizeOfBuffer, Buffer);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return NULL;\r
+  }\r
+\r
+  return Buffer;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the Boolean value for the token specified by TokenNumber and \r
+  Guid to the value specified by Value. Value is returned.\r
+  If Guid is NULL, then ASSERT().\r
+  \r
+  @param[in]  Guid Pointer to a 128-bit unique value that \r
+              designates which namespace to set a value from.\r
+  @param[in]  TokenNumber The PCD token number to set a current value for.\r
+  @param[in]  Value The Boolean value to set.\r
+\r
+  @retval Boolean Return the value been set.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+LibPcdSetExBool (\r
+  IN CONST GUID        *Guid,\r
+  IN UINTN             TokenNumber,\r
+  IN BOOLEAN           Value\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  PCD_PPI * PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+  ASSERT (Guid != NULL);\r
+  Status = PcdPpi->SetBoolEx (Guid, TokenNumber, Value);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Value;\r
+}\r
+\r
+\r
+\r
+/**\r
+  When the token specified by TokenNumber and Guid is set, \r
+  then notification function specified by NotificationFunction is called.  \r
+  If Guid is NULL, then the default token space is used. \r
+  If NotificationFunction is NULL, then ASSERT().\r
+\r
+  @param[in]  Guid Pointer to a 128-bit unique value that designates which \r
+              namespace to set a value from.  If NULL, then the default \r
+              token space is used.\r
+  @param[in]  TokenNumber The PCD token number to monitor.\r
+  @param[in]  NotificationFunction The function to call when the token \r
+              specified by Guid and TokenNumber is set.\r
+\r
+  @retval VOID\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+LibPcdCallbackOnSet (\r
+  IN CONST GUID               *Guid,       OPTIONAL\r
+  IN UINTN                    TokenNumber,\r
+  IN PCD_CALLBACK             NotificationFunction\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  PCD_PPI * PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+\r
+  Status = PcdPpi->CallbackOnSet (Guid, TokenNumber, NotificationFunction);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Disable a notification function that was established with LibPcdCallbackonSet().\r
+  If NotificationFunction is NULL, then ASSERT().\r
+\r
+  @param[in]  Guid Specify the GUID token space.\r
+  @param[in]  TokenNumber Specify the token number.\r
+  @param[in]  NotificationFunction The callback function to be unregistered.\r
+\r
+  @retval VOID\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+LibPcdCancelCallback (\r
+  IN CONST GUID               *Guid,       OPTIONAL\r
+  IN UINTN                    TokenNumber,\r
+  IN PCD_CALLBACK             NotificationFunction\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  PCD_PPI * PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+\r
+  Status = PcdPpi->CancelCallback (Guid, TokenNumber, NotificationFunction);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Retrieves the next PCD token number from the token space specified by Guid.  \r
+  If Guid is NULL, then the default token space is used.  If TokenNumber is 0, \r
+  then the first token number is returned.  Otherwise, the token number that \r
+  follows TokenNumber in the token space is returned.  If TokenNumber is the last \r
+  token number in the token space, then 0 is returned.  If TokenNumber is not 0 and \r
+  is not in the token space specified by Guid, then ASSERT().\r
+\r
+  @param[in]  Pointer to a 128-bit unique value that designates which namespace \r
+              to set a value from.  If NULL, then the default token space is used.\r
+  @param[in]  The previous PCD token number.  If 0, then retrieves the first PCD \r
+              token number.\r
+\r
+  @retval UINTN            The next valid token number.\r
+\r
+**/\r
+UINTN                      \r
+EFIAPI\r
+LibPcdGetNextToken (\r
+  IN CONST GUID             *Guid, OPTIONAL\r
+  IN       UINTN            TokenNumber\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  PCD_PPI * PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+\r
+  Status = PcdPpi->GetNextToken (Guid, &TokenNumber);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return TokenNumber;\r
+}\r
+\r
+\r
+/**\r
+  Retrieves the next PCD token space from a token space specified by Guid.\r
+  Guid of NULL is reserved to mark the default local token namespace on the current\r
+  platform. If Guid is NULL, then the GUID of the first non-local token space of the \r
+  current platform is returned. If Guid is the last non-local token space, \r
+  then NULL is returned. \r
+\r
+  If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().\r
+\r
+\r
+  \r
+  @param[in]  Pointer to a 128-bit unique value that designates from which namespace \r
+              to start the search.\r
+\r
+  @retval CONST GUID *  The next valid token namespace.\r
+\r
+**/\r
+GUID *           \r
+EFIAPI\r
+LibPcdGetNextTokenSpace (\r
+  IN CONST GUID  *Guid\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  PCD_PPI * PcdPpi;\r
+\r
+  PcdPpi = GetPcdPpiPtr ();\r
+\r
+\r
+  Status = PcdPpi->GetNextTokenSpace (&Guid);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return (GUID *)Guid;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Sets the PCD entry specified by PatchVariable to the value specified by Buffer \r
+  and SizeOfValue.  Buffer is returned.  If SizeOfValue is greater than \r
+  MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return \r
+  NULL to indicate that the set operation was not actually performed.  \r
+  If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to \r
+  MaximumDatumSize and NULL must be returned.\r
+  \r
+  If PatchVariable is NULL, then ASSERT().\r
+  If SizeOfValue is NULL, then ASSERT().\r
+  If SizeOfValue > 0 and Buffer is NULL, then ASSERT().\r
+\r
+  @param[in] PatchVariable      A pointer to the global variable in a module that is \r
+                                the target of the set operation.\r
+  @param[in] MaximumDatumSize   The maximum size allowed for the PCD entry specified by PatchVariable.\r
+  @param[in, out] SizeOfBuffer  A pointer to the size, in bytes, of Buffer.\r
+  @param[in] Buffer             A pointer to the buffer to used to set the target variable.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+LibPatchPcdSetPtr (\r
+  IN        VOID        *PatchVariable,\r
+  IN        UINTN       MaximumDatumSize,\r
+  IN OUT    UINTN       *SizeOfBuffer,\r
+  IN CONST  VOID        *Buffer\r
+  )\r
+{\r
+  ASSERT (PatchVariable != NULL);\r
+  ASSERT (SizeOfBuffer  != NULL);\r
+  \r
+  if (*SizeOfBuffer > 0) {\r
+    ASSERT (Buffer != NULL);\r
+  }\r
+\r
+  if ((*SizeOfBuffer > MaximumDatumSize) ||\r
+      (*SizeOfBuffer == MAX_ADDRESS)) {\r
+    *SizeOfBuffer = MaximumDatumSize;\r
+    return NULL;\r
+  }\r
+    \r
+  CopyMem (PatchVariable, Buffer, *SizeOfBuffer);\r
+  \r
+  return (VOID *) Buffer;\r
+}\r
+\r
+\r
diff --git a/MdePkg/Library/PeiPcdLib/PeiPcdLib.inf b/MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
new file mode 100644 (file)
index 0000000..25c1e78
--- /dev/null
@@ -0,0 +1,95 @@
+#/** @file\r
+# PCD Library instance implemented with PCD PPI.\r
+#\r
+# This library instance implement the APIs listed \r
+#  in PCD library class defined in MDE library specification.\r
+#  It is used by module in PEI phase.\r
+# Copyright (c) 2007, Intel Corporation\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PeiPcdLib\r
+  FILE_GUID                      = 9dbf6f25-0da2-4a1d-8e12-e78de6ab4d0e\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PcdLib|PEIM PEI_CORE \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  PeiPcdLib.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg\Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  BaseMemoryLib\r
+  PeiServicesTablePointerLib\r
+  DebugLib\r
+\r
+\r
+################################################################################\r
+#\r
+# PPI C Name Section - list of PPI and PPI Notify C Names that this module\r
+#                      uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Ppis]\r
+  gPcdPpiGuid                                   # PPI ALWAYS_CONSUMED\r
+\r
diff --git a/MdePkg/Library/PeiPcdLib/PeiPcdLib.msa b/MdePkg/Library/PeiPcdLib/PeiPcdLib.msa
new file mode 100644 (file)
index 0000000..363cdb4
--- /dev/null
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>PeiPcdLib</ModuleName>\r
+    <ModuleType>PEIM</ModuleType>\r
+    <GuidValue>9dbf6f25-0da2-4a1d-8e12-e78de6ab4d0e</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>PCD Library instance implemented with PCD PPI.</Abstract>\r
+    <Description>This library instance implement the APIs listed 
+    in PCD library class defined in MDE library specification.
+    It is used by module in PEI phase.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>PeiPcdLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="PEIM PEI_CORE">\r
+      <Keyword>PcdLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeiServicesTablePointerLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>PeiPcdLib.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <PPIs>\r
+    <Ppi Usage="ALWAYS_CONSUMED">\r
+      <PpiCName>gPcdPpiGuid</PpiCName>\r
+    </Ppi>\r
+  </PPIs>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdePkg/Library/PeiResourcePublicationLib/CommonHeader.h b/MdePkg/Library/PeiResourcePublicationLib/CommonHeader.h
new file mode 100644 (file)
index 0000000..9aef9c8
--- /dev/null
@@ -0,0 +1,33 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiPei.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/ResourcePublicationLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.c b/MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.c
new file mode 100644 (file)
index 0000000..fca01dc
--- /dev/null
@@ -0,0 +1,55 @@
+/** @file\r
+  Resource Publication Library that uses PEI Core Services to publish system memory.\r
+\r
+  Copyright (c) 2006, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials                          \r
+  are licensed and made available under the terms and conditions of the BSD License         \r
+  which accompanies this distribution.  The full text of the license may be found at        \r
+  http://opensource.org/licenses/bsd-license.php                                            \r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+  Module Name:  PeiResourcePublicationLib.c\r
+\r
+**/\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+/**\r
+  \r
+  Declares the presence of permanent system memory in the platform.\r
+\r
+  Declares that the system memory buffer specified by MemoryBegin and MemoryLength\r
+  as permanent memory that may be used for general purpose use by software.\r
+  The amount of memory available to software may be less than MemoryLength\r
+  if published memory has alignment restrictions.  \r
+\r
+  @param  MemoryBegin               The start address of the memory being declared.\r
+  @param  MemoryLength              The number of bytes of memory being declared.\r
+\r
+  @retval  RETURN_SUCCESS           The memory buffer was published.\r
+  @retval  RETURN_OUT_OF_RESOURCES  There are not enough resources to publish the memory buffer\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PublishSystemMemory (\r
+  IN PHYSICAL_ADDRESS       MemoryBegin,\r
+  IN UINT64                 MemoryLength\r
+  )\r
+{\r
+  EFI_STATUS        Status;\r
+\r
+  ASSERT (MemoryLength > 0);\r
+  ASSERT (MemoryLength <= (MAX_ADDRESS - MemoryBegin + 1));\r
+\r
+  Status      = PeiServicesInstallPeiMemory (MemoryBegin, MemoryLength);\r
+     \r
+  return (RETURN_STATUS) Status;\r
+}\r
+\r
diff --git a/MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf b/MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
new file mode 100644 (file)
index 0000000..ade69a9
--- /dev/null
@@ -0,0 +1,81 @@
+#/** @file\r
+# Component description file for Pei Resource Publication Library\r
+#\r
+# Resource Publication Library that uses PEI Services to publish system memory.\r
+# Copyright (c) 2007, Intel Corporation\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PeiResourcePublicationLib\r
+  FILE_GUID                      = e8d6390d-e190-4957-9ab6-d47d51b01336\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = ResourcePublicationLib|PEIM \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  PeiResourcePublicationLib.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg\Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  PeiServicesLib\r
+\r
diff --git a/MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.msa b/MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.msa
new file mode 100644 (file)
index 0000000..98c5064
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>PeiResourcePublicationLib</ModuleName>\r
+    <ModuleType>PEIM</ModuleType>\r
+    <GuidValue>e8d6390d-e190-4957-9ab6-d47d51b01336</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for Pei Resource Publication Library</Abstract>\r
+    <Description>Resource Publication Library that uses PEI Services to publish system memory.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>PeiResourcePublicationLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="PEIM">\r
+      <Keyword>ResourcePublicationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeiServicesLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>PeiResourcePublicationLib.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdePkg/Library/PeiServicesTablePointerLib/CommonHeader.h b/MdePkg/Library/PeiServicesTablePointerLib/CommonHeader.h
new file mode 100644 (file)
index 0000000..4a68867
--- /dev/null
@@ -0,0 +1,32 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007 - 2007, Intel Corporation.\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiPei.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointer.c b/MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointer.c
new file mode 100644 (file)
index 0000000..6c4d785
--- /dev/null
@@ -0,0 +1,66 @@
+/** @file\r
+  PEI Services Table Pointer Library.\r
+\r
+  Copyright (c) 2006, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Module Name:  PeiServicesTablePointer.c\r
+\r
+**/\r
+\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+static EFI_PEI_SERVICES  **gPeiServices;\r
+\r
+/**\r
+  The function returns the pointer to PEI services.\r
+\r
+  The function returns the pointer to PEI services.\r
+  It will ASSERT() if the pointer to PEI services is NULL.\r
+\r
+  @retval  The pointer to PeiServices.\r
+\r
+**/\r
+EFI_PEI_SERVICES **\r
+GetPeiServicesTablePointer (\r
+  VOID\r
+  )\r
+{\r
+  ASSERT (gPeiServices != NULL);\r
+  return gPeiServices;\r
+}\r
+\r
+\r
+/**\r
+  The constructor function caches the pointer to PEI services.\r
+  \r
+  The constructor function caches the pointer to PEI services.\r
+  It will always return EFI_SUCCESS.\r
+\r
+  @param  FfsHeader   Pointer to FFS header the loaded driver.\r
+  @param  PeiServices Pointer to the PEI services.\r
+\r
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiServicesTablePointerLibConstructor (\r
+  IN EFI_FFS_FILE_HEADER  *FfsHeader,\r
+  IN EFI_PEI_SERVICES     **PeiServices\r
+  )\r
+{\r
+  gPeiServices = PeiServices;\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf b/MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf
new file mode 100644 (file)
index 0000000..bd8c311
--- /dev/null
@@ -0,0 +1,83 @@
+#/** @file\r
+# Component description file for Pei Services Table Library\r
+#\r
+# PEI Services Table 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
+# Copyright (c) 2007 - 2007, Intel Corporation.\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PeiServicesTablePointerLib\r
+  FILE_GUID                      = 1c747f6b-0a58-49ae-8ea3-0327a4fa10e3\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PeiServicesTablePointerLib|PEIM PEI_CORE \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = PeiServicesTablePointerLibConstructor\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
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  PeiServicesTablePointer.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg\Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+\r
diff --git a/MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.msa b/MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.msa
new file mode 100644 (file)
index 0000000..6e84805
--- /dev/null
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>PeiServicesTablePointerLib</ModuleName>\r
+    <ModuleType>PEIM</ModuleType>\r
+    <GuidValue>1c747f6b-0a58-49ae-8ea3-0327a4fa10e3</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for Pei Services Table Library</Abstract>\r
+    <Description>PEI Services Table Library implementation that retrieves a pointer to the
+      PEI Services Table from a global variable.  Not available to modules that execute from
+      read-only memory.</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation.</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>PeiServicesTablePointerLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="PEIM PEI_CORE">\r
+      <Keyword>PeiServicesTablePointerLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>PeiServicesTablePointer.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <Constructor>PeiServicesTablePointerLibConstructor</Constructor>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdePkg/Library/SecPeiDxeTimerLibCpu/CommonHeader.h b/MdePkg/Library/SecPeiDxeTimerLibCpu/CommonHeader.h
new file mode 100644 (file)
index 0000000..7d1af9c
--- /dev/null
@@ -0,0 +1,35 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007 - 2007, Intel Corporation.\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <Base.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/TimerLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/SecPeiDxeTimerLibCpu/IpfTimerLib.c b/MdePkg/Library/SecPeiDxeTimerLibCpu/IpfTimerLib.c
new file mode 100644 (file)
index 0000000..2acdab3
--- /dev/null
@@ -0,0 +1,173 @@
+/** @file\r
+  Timer Library functions built upon ITC on IPF.\r
+\r
+  Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Module Name:  IpfTimerLib.c\r
+\r
+**/\r
+\r
+\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+/**\r
+  Performs a delay measured as number of ticks.\r
+\r
+  An internal function to perform a delay measured as number of ticks. It's\r
+  invoked by MicroSecondDelay() and NanoSecondDelay().\r
+\r
+  @param  Delay Number of ticks to delay.\r
+\r
+**/\r
+STATIC\r
+VOID\r
+InternalIpfDelay (\r
+  IN      INT64                     Delay\r
+  )\r
+{\r
+  INT64                             Ticks;\r
+\r
+  //\r
+  // The target timer count is calculated here\r
+  //\r
+  Ticks = (INT64)AsmReadItc () + Delay;\r
+\r
+  //\r
+  // Wait until time out\r
+  // Delay > 2^63 could not be handled by this function\r
+  // Timer wrap-arounds are handled correctly by this function\r
+  //\r
+  while (Ticks - (INT64)AsmReadItc() >= 0);\r
+}\r
+\r
+/**\r
+  Stalls the CPU for at least the given number of microseconds.\r
+\r
+  Stalls the CPU for the number of microseconds specified by MicroSeconds.\r
+\r
+  @param  MicroSeconds  The minimum number of microseconds to delay.\r
+\r
+  @return MicroSeconds\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+MicroSecondDelay (\r
+  IN      UINTN                     MicroSeconds\r
+  )\r
+{\r
+  InternalIpfDelay (\r
+    GetPerformanceCounterProperties (NULL, NULL) *\r
+    MicroSeconds /\r
+    1000000\r
+    );\r
+  return MicroSeconds;\r
+}\r
+\r
+/**\r
+  Stalls the CPU for at least the given number of nanoseconds.\r
+\r
+  Stalls the CPU for the number of nanoseconds specified by NanoSeconds.\r
+\r
+  @param  NanoSeconds The minimum number of nanoseconds to delay.\r
+\r
+  @return NanoSeconds\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+NanoSecondDelay (\r
+  IN      UINTN                     NanoSeconds\r
+  )\r
+{\r
+  InternalIpfDelay (\r
+    GetPerformanceCounterProperties (NULL, NULL) *\r
+    NanoSeconds /\r
+    1000000000\r
+    );\r
+  return NanoSeconds;\r
+}\r
+\r
+/**\r
+  Retrieves the current value of a 64-bit free running performance counter.\r
+\r
+  Retrieves the current value of a 64-bit free running performance counter. The\r
+  counter can either count up by 1 or count down by 1. If the physical\r
+  performance counter counts by a larger increment, then the counter values\r
+  must be translated. The properties of the counter can be retrieved from\r
+  GetPerformanceCounterProperties().\r
+\r
+  @return The current value of the free running performance counter.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+GetPerformanceCounter (\r
+  VOID\r
+  )\r
+{\r
+  return AsmReadItc ();\r
+}\r
+\r
+/**\r
+  Retrieves the 64-bit frequency in Hz and the range of performance counter\r
+  values.\r
+\r
+  If StartValue is not NULL, then the value that the performance counter starts\r
+  with immediately after is it rolls over is returned in StartValue. If\r
+  EndValue is not NULL, then the value that the performance counter end with\r
+  immediately before it rolls over is returned in EndValue. The 64-bit\r
+  frequency of the performance counter in Hz is always returned. If StartValue\r
+  is less than EndValue, then the performance counter counts up. If StartValue\r
+  is greater than EndValue, then the performance counter counts down. For\r
+  example, a 64-bit free running counter that counts up would have a StartValue\r
+  of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter\r
+  that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.\r
+\r
+  @param  StartValue  The value the performance counter starts with when it\r
+                      rolls over.\r
+  @param  EndValue    The value that the performance counter ends with before\r
+                      it rolls over.\r
+\r
+  @return The frequency in Hz.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+GetPerformanceCounterProperties (\r
+  OUT      UINT64                    *StartValue,  OPTIONAL\r
+  OUT      UINT64                    *EndValue     OPTIONAL\r
+  )\r
+{\r
+  PAL_CALL_RETURN                   PalRet;\r
+  UINT64                            BaseFrequence;\r
+\r
+  PalRet = PalCallStatic (NULL, 13, 0, 0, 0);\r
+  ASSERT (PalRet.Status == 0);\r
+  BaseFrequence = PalRet.r9;\r
+\r
+  PalRet = PalCallStatic (NULL, 14, 0, 0, 0);\r
+  ASSERT (PalRet.Status == 0);\r
+\r
+  if (StartValue != NULL) {\r
+    *StartValue = 0;\r
+  }\r
+\r
+  if (EndValue != NULL) {\r
+    *EndValue = (UINT64)(-1);\r
+  }\r
+\r
+  return BaseFrequence * (PalRet.r11 >> 32) / (UINT32)PalRet.r11;\r
+}\r
diff --git a/MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf b/MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf
new file mode 100644 (file)
index 0000000..f3d13bd
--- /dev/null
@@ -0,0 +1,116 @@
+#/** @file\r
+# Timer Library implementation for Boot Timer moudles that require timer services.\r
+#\r
+# Timer Library that uses CPU resources to provide calibrated\r
+#  delays on IA-32 and x64, and uses ITC on IPF. Note: Because CpuLocalApci\r
+#  and ITC could be programmed by OS, it cannot be used by SMM drivers\r
+#  and runtime drivers, ACPI timer is recommended for SMM drivers and RUNTIME\r
+#  drivers.\r
+# Copyright (c) 2007 - 2007, Intel Corporation.\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = SecPeiDxeTimerLibCpu\r
+  FILE_GUID                      = b5a05743-9b71-489b-a0ed-a0eb3950d23b\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = TimerLib|BASE DXE_CORE DXE_DRIVER DXE_SAL_DRIVER PEIM PEI_CORE SEC UEFI_APPLICATION UEFI_DRIVER \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  CommonHeader.h\r
+\r
+[Sources.Ia32]\r
+  x86TimerLib.c\r
+\r
+[Sources.X64]\r
+  x86TimerLib.c\r
+\r
+[Sources.IPF]\r
+  IpfTimerLib.c\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg\Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+\r
+[LibraryClasses.IA32]\r
+  PcdLib\r
+  IoLib\r
+\r
+[LibraryClasses.X64]\r
+  PcdLib\r
+  IoLib\r
+\r
+[LibraryClasses.IPF]\r
+  DebugLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Pcd DYNAMIC - list of PCDs that this module is coded for.\r
+#\r
+################################################################################\r
+\r
+[PcdsDynamic.IA32]\r
+  PcdFSBClock|gEfiMdePkgTokenSpaceGuid\r
+\r
+[PcdsDynamic.X64]\r
+  PcdFSBClock|gEfiMdePkgTokenSpaceGuid\r
+\r
diff --git a/MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.msa b/MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.msa
new file mode 100644 (file)
index 0000000..d6126f7
--- /dev/null
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>SecPeiDxeTimerLibCpu</ModuleName>\r
+    <ModuleType>BASE</ModuleType>\r
+    <GuidValue>b5a05743-9b71-489b-a0ed-a0eb3950d23b</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Timer Library implementation for Boot Timer moudles that require timer services.</Abstract>\r
+    <Description>Timer Library that uses CPU resources to provide calibrated
+      delays on IA-32 and x64, and uses ITC on IPF. Note: Because CpuLocalApci
+      and ITC could be programmed by OS, it cannot be used by SMM drivers
+      and runtime drivers, ACPI timer is recommended for SMM drivers and RUNTIME
+      drivers.</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation.</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>SecPeiDxeTimerLibCpu</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="BASE DXE_CORE DXE_DRIVER DXE_SAL_DRIVER PEIM PEI_CORE SEC UEFI_APPLICATION UEFI_DRIVER">\r
+      <Keyword>TimerLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED" SupArchList="IA32 X64">\r
+      <Keyword>IoLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED" SupArchList="IPF">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED" SupArchList="IA32 X64">\r
+      <Keyword>PcdLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename SupArchList="IA32">x86TimerLib.c</Filename>\r
+    <Filename SupArchList="X64">x86TimerLib.c</Filename>\r
+    <Filename SupArchList="IPF">IpfTimerLib.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+  <PcdCoded>\r
+    <PcdEntry PcdItemType="DYNAMIC" Usage="ALWAYS_CONSUMED" SupArchList="IA32 X64">\r
+      <C_Name>PcdFSBClock</C_Name>\r
+      <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>This value is FSB Clock frequency. Its unit is Hz and its default value is 200000000, that means FSB frequency is 200Mhz.</HelpText>\r
+    </PcdEntry>\r
+  </PcdCoded>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdePkg/Library/SecPeiDxeTimerLibCpu/x86TimerLib.c b/MdePkg/Library/SecPeiDxeTimerLibCpu/x86TimerLib.c
new file mode 100644 (file)
index 0000000..24ee2e7
--- /dev/null
@@ -0,0 +1,251 @@
+/** @file\r
+  Timer Library functions built upon local APIC on IA32/x64.\r
+\r
+  Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Module Name:  x86TimerLib.c\r
+\r
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+//\r
+// The following array is used in calculating the frequency of local APIC\r
+// timer. Refer to IA-32 developers' manual for more details.\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED\r
+CONST UINT8                           mTimerLibLocalApicDivisor[] = {\r
+  0x02, 0x04, 0x08, 0x10,\r
+  0x02, 0x04, 0x08, 0x10,\r
+  0x20, 0x40, 0x80, 0x01,\r
+  0x20, 0x40, 0x80, 0x01\r
+};\r
+\r
+/**\r
+  Internal function to retrieve the base address of local APIC.\r
+\r
+  Internal function to retrieve the base address of local APIC.\r
+\r
+  @return The base address of local APIC\r
+\r
+**/\r
+STATIC\r
+UINTN\r
+InternalX86GetApicBase (\r
+  VOID\r
+  )\r
+{\r
+  return (UINTN)AsmMsrBitFieldRead64 (27, 12, 35) << 12;\r
+}\r
+\r
+/**\r
+  Internal function to return the frequency of the local APIC timer.\r
+\r
+  Internal function to return the frequency of the local APIC timer.\r
+\r
+  @param  ApicBase  The base address of memory mapped registers of local APIC.\r
+\r
+  @return The frequency of the timer in Hz.\r
+\r
+**/\r
+STATIC\r
+UINT32\r
+InternalX86GetTimerFrequency (\r
+  IN      UINTN                     ApicBase\r
+  )\r
+{\r
+  return\r
+    PcdGet32(PcdFSBClock) /\r
+    mTimerLibLocalApicDivisor[MmioBitFieldRead32 (ApicBase + 0x3e0, 0, 3)];\r
+}\r
+\r
+/**\r
+  Internal function to read the current tick counter of local APIC.\r
+\r
+  Internal function to read the current tick counter of local APIC.\r
+\r
+  @param  ApicBase  The base address of memory mapped registers of local APIC.\r
+\r
+  @return The tick counter read.\r
+\r
+**/\r
+STATIC\r
+INT32\r
+InternalX86GetTimerTick (\r
+  IN      UINTN                     ApicBase\r
+  )\r
+{\r
+  return MmioRead32 (ApicBase + 0x390);\r
+}\r
+\r
+/**\r
+  Stalls the CPU for at least the given number of ticks.\r
+\r
+  Stalls the CPU for at least the given number of ticks. It's invoked by\r
+  MicroSecondDelay() and NanoSecondDelay().\r
+\r
+  @param  ApicBase  The base address of memory mapped registers of local APIC.\r
+  @param  Delay     A period of time to delay in ticks.\r
+\r
+**/\r
+STATIC\r
+VOID\r
+InternalX86Delay (\r
+  IN      UINTN                     ApicBase,\r
+  IN      UINT32                    Delay\r
+  )\r
+{\r
+  INT32                             Ticks;\r
+\r
+  //\r
+  // The target timer count is calculated here\r
+  //\r
+  Ticks = InternalX86GetTimerTick (ApicBase) - Delay;\r
+\r
+  //\r
+  // Wait until time out\r
+  // Delay > 2^31 could not be handled by this function\r
+  // Timer wrap-arounds are handled correctly by this function\r
+  //\r
+  while (InternalX86GetTimerTick (ApicBase) - Ticks >= 0);\r
+}\r
+\r
+/**\r
+  Stalls the CPU for at least the given number of microseconds.\r
+\r
+  Stalls the CPU for the number of microseconds specified by MicroSeconds.\r
+\r
+  @param  MicroSeconds  The minimum number of microseconds to delay.\r
+\r
+  @return MicroSeconds\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+MicroSecondDelay (\r
+  IN      UINTN                     MicroSeconds\r
+  )\r
+{\r
+  UINTN                             ApicBase;\r
+\r
+  ApicBase = InternalX86GetApicBase ();\r
+  InternalX86Delay (\r
+    ApicBase,\r
+    (UINT32)DivU64x32 (\r
+              MultU64x64 (\r
+                InternalX86GetTimerFrequency (ApicBase),\r
+                MicroSeconds\r
+                ),\r
+              1000000u\r
+              )\r
+    );\r
+  return MicroSeconds;\r
+}\r
+\r
+/**\r
+  Stalls the CPU for at least the given number of nanoseconds.\r
+\r
+  Stalls the CPU for the number of nanoseconds specified by NanoSeconds.\r
+\r
+  @param  NanoSeconds The minimum number of nanoseconds to delay.\r
+\r
+  @return NanoSeconds\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+NanoSecondDelay (\r
+  IN      UINTN                     NanoSeconds\r
+  )\r
+{\r
+  UINTN                             ApicBase;\r
+\r
+  ApicBase = InternalX86GetApicBase ();\r
+  InternalX86Delay (\r
+    ApicBase,\r
+    (UINT32)DivU64x32 (\r
+              MultU64x64 (\r
+                InternalX86GetTimerFrequency (ApicBase),\r
+                NanoSeconds\r
+                ),\r
+              1000000000u\r
+              )\r
+    );\r
+  return NanoSeconds;\r
+}\r
+\r
+/**\r
+  Retrieves the current value of a 64-bit free running performance counter.\r
+\r
+  Retrieves the current value of a 64-bit free running performance counter. The\r
+  counter can either count up by 1 or count down by 1. If the physical\r
+  performance counter counts by a larger increment, then the counter values\r
+  must be translated. The properties of the counter can be retrieved from\r
+  GetPerformanceCounterProperties().\r
+\r
+  @return The current value of the free running performance counter.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+GetPerformanceCounter (\r
+  VOID\r
+  )\r
+{\r
+  return (UINT64)(UINT32)InternalX86GetTimerTick (InternalX86GetApicBase ());\r
+}\r
+\r
+/**\r
+  Retrieves the 64-bit frequency in Hz and the range of performance counter\r
+  values.\r
+\r
+  If StartValue is not NULL, then the value that the performance counter starts\r
+  with immediately after is it rolls over is returned in StartValue. If\r
+  EndValue is not NULL, then the value that the performance counter end with\r
+  immediately before it rolls over is returned in EndValue. The 64-bit\r
+  frequency of the performance counter in Hz is always returned. If StartValue\r
+  is less than EndValue, then the performance counter counts up. If StartValue\r
+  is greater than EndValue, then the performance counter counts down. For\r
+  example, a 64-bit free running counter that counts up would have a StartValue\r
+  of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter\r
+  that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.\r
+\r
+  @param  StartValue  The value the performance counter starts with when it\r
+                      rolls over.\r
+  @param  EndValue    The value that the performance counter ends with before\r
+                      it rolls over.\r
+\r
+  @return The frequency in Hz.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+GetPerformanceCounterProperties (\r
+  OUT      UINT64                    *StartValue,  OPTIONAL\r
+  OUT      UINT64                    *EndValue     OPTIONAL\r
+  )\r
+{\r
+  UINTN                             ApicBase;\r
+\r
+  ApicBase = InternalX86GetApicBase ();\r
+\r
+  if (StartValue != NULL) {\r
+    *StartValue = MmioRead32 (ApicBase + 0x380);\r
+  }\r
+\r
+  if (EndValue != NULL) {\r
+    *EndValue = 0;\r
+  }\r
+\r
+  return (UINT64) InternalX86GetTimerFrequency (ApicBase);;\r
+}\r
diff --git a/MdePkg/Library/UefiApplicationEntryPoint/ApplicationEntryPoint.c b/MdePkg/Library/UefiApplicationEntryPoint/ApplicationEntryPoint.c
new file mode 100644 (file)
index 0000000..580668c
--- /dev/null
@@ -0,0 +1,108 @@
+/** @file\r
+  Entry point library instance to a UEFI application.\r
+\r
+Copyright (c) 2007, Intel Corporation<BR>\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+/**\r
+  Enrty point to UEFI application.\r
+\r
+  @param  ImageHandle ImageHandle of the loaded driver.\r
+  @param  SystemTable Pointer to the EFI System Table.\r
+\r
+  @retval  EFI_SUCCESS One or more of the drivers returned a success code.\r
+  @retval  !EFI_SUCESS The return status from the last driver entry point in the list.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+_ModuleEntryPoint (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS                 Status;\r
+\r
+  if (_gUefiDriverRevision != 0) {\r
+    //\r
+    // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the application.\r
+    //\r
+    if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {\r
+      return EFI_INCOMPATIBLE_VERSION;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Call constructor for all libraries.\r
+  //\r
+  ProcessLibraryConstructorList (ImageHandle, SystemTable);\r
+\r
+  //\r
+  // Call the module's entry point\r
+  //\r
+  Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);\r
+\r
+  //\r
+  // Process destructor for all libraries.\r
+  //\r
+  ProcessLibraryDestructorList (ImageHandle, SystemTable);\r
+\r
+  //\r
+  // Return the return status code from the driver entry point\r
+  //\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Invoke the destuctors of all libraries and call gBS->Exit\r
+  to return control to firmware core.\r
+\r
+  @param  Status Status returned by the application that is exiting.\r
+  \r
+  @retval VOID\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+Exit (\r
+  IN EFI_STATUS  Status\r
+  )\r
+\r
+{\r
+  ProcessLibraryDestructorList (gImageHandle, gST);\r
+\r
+  gBS->Exit (gImageHandle, Status, 0, NULL);\r
+}\r
+\r
+/**\r
+  Enrty point wrapper of UEFI Application.\r
+\r
+  @param  ImageHandle ImageHandle of the loaded driver.\r
+  @param  SystemTable Pointer to the EFI System Table.\r
+\r
+  @retval  EFI_SUCCESS One or more of the drivers returned a success code.\r
+  @retval  !EFI_SUCESS The return status from the last driver entry point in the list.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiMain (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  return _ModuleEntryPoint (ImageHandle, SystemTable);\r
+}\r
diff --git a/MdePkg/Library/UefiApplicationEntryPoint/CommonHeader.h b/MdePkg/Library/UefiApplicationEntryPoint/CommonHeader.h
new file mode 100644 (file)
index 0000000..ffc077d
--- /dev/null
@@ -0,0 +1,32 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007, Intel Corporation.\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <Uefi.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/UefiApplicationEntryPoint.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf b/MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
new file mode 100644 (file)
index 0000000..0bb4cde
--- /dev/null
@@ -0,0 +1,80 @@
+#/** @file\r
+# Component description file for the entry point to a EFI Application\r
+#\r
+# Library to abstract entry point to a EFI Application.\r
+# Copyright (c) 2007, Intel Corporation.\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UefiApplicationEntryPoint\r
+  FILE_GUID                      = DADE8301-CB29-4fd5-8148-56FD246C5B88\r
+  MODULE_TYPE                    = UEFI_APPLICATION\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = UefiApplicationEntryPoint|UEFI_APPLICATION \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  ApplicationEntryPoint.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg\Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+\r
diff --git a/MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.msa b/MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.msa
new file mode 100644 (file)
index 0000000..8500f05
--- /dev/null
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>UefiApplicationEntryPoint</ModuleName>\r
+    <ModuleType>UEFI_APPLICATION</ModuleType>\r
+    <GuidValue>DADE8301-CB29-4fd5-8148-56FD246C5B88</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for the entry point to a EFI Application</Abstract>\r
+    <Description>Library to abstract entry point to a EFI Application.</Description>\r
+    <Copyright>Copyright (c) 2007, Intel Corporation.</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UefiApplicationEntryPoint</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="UEFI_APPLICATION">\r
+      <Keyword>UefiApplicationEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>ApplicationEntryPoint.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdePkg/Library/UefiBootServicesTableLib/CommonHeader.h b/MdePkg/Library/UefiBootServicesTableLib/CommonHeader.h
new file mode 100644 (file)
index 0000000..c7a33f2
--- /dev/null
@@ -0,0 +1,32 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007, Intel Corporation.\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.c b/MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.c
new file mode 100644 (file)
index 0000000..b7795e6
--- /dev/null
@@ -0,0 +1,66 @@
+/** @file\r
+  UEFI Boot Services Table Library.\r
+\r
+  Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Module Name:  UefiBootServicesTableLib.c\r
+\r
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+EFI_HANDLE         gImageHandle = NULL;\r
+EFI_SYSTEM_TABLE   *gST         = NULL;\r
+EFI_BOOT_SERVICES  *gBS         = NULL;\r
+\r
+/**\r
+  The constructor function caches the pointer of Boot Services Table.\r
+  \r
+  The constructor function caches the pointer of Boot Services Table through System Table.\r
+  It will ASSERT() if the pointer of System Table is NULL.\r
+  It will ASSERT() if the pointer of Boot Services Table is NULL.\r
+  It will always return EFI_SUCCESS.\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
+UefiBootServicesTableLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  //\r
+  // Cache the Image Handle\r
+  //\r
+  gImageHandle = ImageHandle;\r
+  ASSERT (gImageHandle != NULL);\r
+\r
+  //\r
+  // Cache pointer to the EFI System Table\r
+  //\r
+  gST = SystemTable;\r
+  ASSERT (gST != NULL);\r
+\r
+  //\r
+  // Cache pointer to the EFI Boot Services Table\r
+  //\r
+  gBS = SystemTable->BootServices;\r
+  ASSERT (gBS != NULL);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf b/MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
new file mode 100644 (file)
index 0000000..3d5b1f3
--- /dev/null
@@ -0,0 +1,81 @@
+#/** @file\r
+# UEFI Boot Services Table Library\r
+#\r
+# Library to abstract Framework extensions that conflict with UEFI 2.0 Specification\r
+# Copyright (c) 2007, Intel Corporation.\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UefiBootServicesTableLib\r
+  FILE_GUID                      = ff5c7a2c-ab7a-4366-8616-11c6e53247b6\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = UefiBootServicesTableLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = UefiBootServicesTableLibConstructor\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
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  UefiBootServicesTableLib.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg\Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+\r
diff --git a/MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.msa b/MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.msa
new file mode 100644 (file)
index 0000000..fb332b4
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>UefiBootServicesTableLib</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>ff5c7a2c-ab7a-4366-8616-11c6e53247b6</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>UEFI Boot Services Table Library</Abstract>\r
+    <Description>Library to abstract Framework extensions that conflict with UEFI 2.0 Specification</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation.</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UefiBootServicesTableLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UefiBootServicesTableLib.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <Constructor>UefiBootServicesTableLibConstructor</Constructor>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdePkg/Library/UefiDebugLibConOut/CommonHeader.h b/MdePkg/Library/UefiDebugLibConOut/CommonHeader.h
new file mode 100644 (file)
index 0000000..1851011
--- /dev/null
@@ -0,0 +1,36 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007, Intel Corporation.\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <Uefi.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/UefiDebugLibConOut/DebugLib.c b/MdePkg/Library/UefiDebugLibConOut/DebugLib.c
new file mode 100644 (file)
index 0000000..711f29c
--- /dev/null
@@ -0,0 +1,252 @@
+/** @file\r
+  UEFI Debug Library that uses PrintLib to send messages to CONOUT.\r
+\r
+  Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials                          \r
+  are licensed and made available under the terms and conditions of the BSD License         \r
+  which accompanies this distribution.  The full text of the license may be found at        \r
+  http://opensource.org/licenses/bsd-license.php                                            \r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+//\r
+// Define the maximum debug and assert message length that this library supports \r
+//\r
+#define MAX_DEBUG_MESSAGE_LENGTH  0x100\r
+\r
+\r
+/**\r
+\r
+  Prints a debug message to the debug output device if the specified error level is enabled.\r
+\r
+  If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print \r
+  the message specified by Format and the associated variable argument list to \r
+  the debug output device.\r
+\r
+  If Format is NULL, then ASSERT().\r
+\r
+  @param  ErrorLevel  The error level of the debug message.\r
+  @param  Format      Format string for the debug message to print.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+DebugPrint (\r
+  IN  UINTN        ErrorLevel,\r
+  IN  CONST CHAR8  *Format,\r
+  ...\r
+  )\r
+{\r
+  CHAR16   Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
+  VA_LIST  Marker;\r
+\r
+  //\r
+  // If Format is NULL, then ASSERT().\r
+  //\r
+  ASSERT (Format != NULL);\r
+\r
+  //\r
+  // Check driver debug mask value and global mask\r
+  //\r
+  if ((ErrorLevel & PcdGet32(PcdDebugPrintErrorLevel)) == 0) {\r
+    return;\r
+  }\r
+\r
+  //\r
+  // Convert the DEBUG() message to a Unicode String\r
+  //\r
+  VA_START (Marker, Format);\r
+  UnicodeVSPrintAsciiFormat (Buffer, sizeof (Buffer), Format, Marker);\r
+  VA_END (Marker);\r
+\r
+  //\r
+  // Send the print string to the Console Output device\r
+  //\r
+  if ((gST != NULL) && (gST->ConOut != NULL)) {\r
+    gST->ConOut->OutputString (gST->ConOut, Buffer);\r
+  }\r
+}\r
+\r
+\r
+/**\r
+\r
+  Prints an assert message containing a filename, line number, and description.  \r
+  This may be followed by a breakpoint or a dead loop.\r
+\r
+  Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n" \r
+  to the debug output device.  If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of \r
+  PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if \r
+  DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then \r
+  CpuDeadLoop() is called.  If neither of these bits are set, then this function \r
+  returns immediately after the message is printed to the debug output device.\r
+  DebugAssert() must actively prevent recusrsion.  If DebugAssert() is called while\r
+  processing another DebugAssert(), then DebugAssert() must return immediately.\r
+\r
+  If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r
+\r
+  If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r
+\r
+  @param  FileName     Pointer to the name of the source file that generated the assert condition.\r
+  @param  LineNumber   The line number in the source file that generated the assert condition\r
+  @param  Description  Pointer to the description of the assert condition.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+DebugAssert (\r
+  IN CONST CHAR8  *FileName,\r
+  IN UINTN        LineNumber,\r
+  IN CONST CHAR8  *Description\r
+  )\r
+{\r
+  CHAR16  Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
+\r
+  //\r
+  // Generate the ASSERT() message in Unicode format\r
+  //\r
+  UnicodeSPrintAsciiFormat (Buffer, sizeof (Buffer), "ASSERT %s(%d): %s\n", FileName, LineNumber, Description);\r
+\r
+  //\r
+  // Send the print string to the Console Output device\r
+  //\r
+  if ((gST != NULL) && (gST->ConOut != NULL)) {\r
+    gST->ConOut->OutputString (gST->ConOut, Buffer);\r
+  }\r
+\r
+  //\r
+  // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r
+  //\r
+  if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
+    CpuBreakpoint ();\r
+  } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
+    CpuDeadLoop ();\r
+  }\r
+}\r
+\r
+\r
+/**\r
+\r
+  Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
+\r
+  This function fills Length bytes of Buffer with the value specified by \r
+  PcdDebugClearMemoryValue, and returns Buffer.\r
+\r
+  If Buffer is NULL, then ASSERT().\r
+\r
+  If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
+\r
+  @param   Buffer  Pointer to the target buffer to fill with PcdDebugClearMemoryValue.\r
+  @param   Length  Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue. \r
+\r
+  @return  Buffer\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+DebugClearMemory (\r
+  OUT VOID  *Buffer,\r
+  IN UINTN  Length\r
+  )\r
+{\r
+  //\r
+  // If Buffer is NULL, then ASSERT().\r
+  //\r
+  ASSERT (Buffer != NULL);\r
+\r
+  //\r
+  // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r
+  //\r
+  return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r
+}\r
+\r
+\r
+/**\r
+  \r
+  Returns TRUE if ASSERT() macros are enabled.\r
+\r
+  This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of \r
+  PcdDebugProperyMask is set.  Otherwise FALSE is returned.\r
+\r
+  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r
+  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+DebugAssertEnabled (\r
+  VOID\r
+  )\r
+{\r
+  return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r
+}\r
+\r
+\r
+/**\r
+  \r
+  Returns TRUE if DEBUG()macros are enabled.\r
+\r
+  This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of \r
+  PcdDebugProperyMask is set.  Otherwise FALSE is returned.\r
+\r
+  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r
+  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+DebugPrintEnabled (\r
+  VOID\r
+  )\r
+{\r
+  return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r
+}\r
+\r
+\r
+/**\r
+  \r
+  Returns TRUE if DEBUG_CODE()macros are enabled.\r
+\r
+  This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of \r
+  PcdDebugProperyMask is set.  Otherwise FALSE is returned.\r
+\r
+  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r
+  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+DebugCodeEnabled (\r
+  VOID\r
+  )\r
+{\r
+  return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
+}\r
+\r
+\r
+/**\r
+  \r
+  Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.\r
+\r
+  This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of \r
+  PcdDebugProperyMask is set.  Otherwise FALSE is returned.\r
+\r
+  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r
+  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+DebugClearMemoryEnabled (\r
+  VOID\r
+  )\r
+{\r
+  return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r
+}\r
diff --git a/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf b/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
new file mode 100644 (file)
index 0000000..2d78685
--- /dev/null
@@ -0,0 +1,105 @@
+#/** @file\r
+# Debug Library for UEFI drivers\r
+#\r
+# Library to abstract Framework extensions that conflict with UEFI 2.0 Specification\r
+# Copyright (c) 2007, Intel Corporation.\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UefiDebugLibConOut\r
+  FILE_GUID                      = 5cddfaf3-e9a7-4d16-bdce-1e002df475bb\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = DebugLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  DebugLib.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg\Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  BaseMemoryLib\r
+  BaseLib\r
+  PcdLib\r
+  PrintLib\r
+  UefiBootServicesTableLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Pcd FIXED_AT_BUILD - list of PCDs that this module is coded for.\r
+#\r
+################################################################################\r
+\r
+[PcdsFixedAtBuild.common]\r
+  PcdDebugClearMemoryValue|gEfiMdePkgTokenSpaceGuid\r
+  PcdDebugPropertyMask|gEfiMdePkgTokenSpaceGuid\r
+\r
+\r
+################################################################################\r
+#\r
+# Pcd DYNAMIC - list of PCDs that this module is coded for.\r
+#\r
+################################################################################\r
+\r
+[PcdsDynamic.common]\r
+  PcdDebugPrintErrorLevel|gEfiMdePkgTokenSpaceGuid\r
+\r
diff --git a/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.msa b/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.msa
new file mode 100644 (file)
index 0000000..9acf776
--- /dev/null
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>UefiDebugLibConOut</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>5cddfaf3-e9a7-4d16-bdce-1e002df475bb</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Debug Library for UEFI drivers</Abstract>\r
+    <Description>Library to abstract Framework extensions that conflict with UEFI 2.0 Specification</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation.</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UefiDebugLibConOut</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PrintLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PcdLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>DebugLib.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+  <PcdCoded>\r
+    <PcdEntry PcdItemType="FIXED_AT_BUILD">\r
+      <C_Name>PcdDebugPropertyMask</C_Name>\r
+      <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>The bitmask of flags that specify the enable/disable of Debug
+                Assert, Debug Print, Debug Code, Clear Memory, Assert
+                Breakpoint and Assert Deadloop.</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="FIXED_AT_BUILD">\r
+      <C_Name>PcdDebugClearMemoryValue</C_Name>\r
+      <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>The value used by DebugClearMemory () to fill a certain range
+                of memory.</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdDebugPrintErrorLevel</C_Name>\r
+      <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>The bitmask of flags that specify the kind of debug message
+                output when Debug Print is enabled.</HelpText>\r
+    </PcdEntry>\r
+  </PcdCoded>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdePkg/Library/UefiDebugLibStdErr/CommonHeader.h b/MdePkg/Library/UefiDebugLibStdErr/CommonHeader.h
new file mode 100644 (file)
index 0000000..1851011
--- /dev/null
@@ -0,0 +1,36 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007, Intel Corporation.\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <Uefi.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/UefiDebugLibStdErr/DebugLib.c b/MdePkg/Library/UefiDebugLibStdErr/DebugLib.c
new file mode 100644 (file)
index 0000000..c03009c
--- /dev/null
@@ -0,0 +1,252 @@
+/** @file\r
+  UEFI Debug Library that uses PrintLib to send messages to STDERR.\r
+\r
+  Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials                          \r
+  are licensed and made available under the terms and conditions of the BSD License         \r
+  which accompanies this distribution.  The full text of the license may be found at        \r
+  http://opensource.org/licenses/bsd-license.php                                            \r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+//\r
+// Define the maximum debug and assert message length that this library supports \r
+//\r
+#define MAX_DEBUG_MESSAGE_LENGTH  0x100\r
+\r
+\r
+/**\r
+\r
+  Prints a debug message to the debug output device if the specified error level is enabled.\r
+\r
+  If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print \r
+  the message specified by Format and the associated variable argument list to \r
+  the debug output device.\r
+\r
+  If Format is NULL, then ASSERT().\r
+\r
+  @param  ErrorLevel  The error level of the debug message.\r
+  @param  Format      Format string for the debug message to print.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+DebugPrint (\r
+  IN  UINTN        ErrorLevel,\r
+  IN  CONST CHAR8  *Format,\r
+  ...\r
+  )\r
+{\r
+  CHAR16   Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
+  VA_LIST  Marker;\r
+\r
+  //\r
+  // If Format is NULL, then ASSERT().\r
+  //\r
+  ASSERT (Format != NULL);\r
+\r
+  //\r
+  // Check driver debug mask value and global mask\r
+  //\r
+  if ((ErrorLevel & PcdGet32(PcdDebugPrintErrorLevel)) == 0) {\r
+    return;\r
+  }\r
+\r
+  //\r
+  // Convert the DEBUG() message to a Unicode String\r
+  //\r
+  VA_START (Marker, Format);\r
+  UnicodeVSPrintAsciiFormat (Buffer, sizeof (Buffer), Format, Marker);\r
+  VA_END (Marker);\r
+\r
+  //\r
+  // Send the print string to the Standard Error device\r
+  //\r
+  if ((gST != NULL) && (gST->StdErr != NULL)) {\r
+    gST->StdErr->OutputString (gST->StdErr, Buffer);\r
+  }\r
+}\r
+\r
+\r
+/**\r
+\r
+  Prints an assert message containing a filename, line number, and description.  \r
+  This may be followed by a breakpoint or a dead loop.\r
+\r
+  Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n" \r
+  to the debug output device.  If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of \r
+  PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if \r
+  DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then \r
+  CpuDeadLoop() is called.  If neither of these bits are set, then this function \r
+  returns immediately after the message is printed to the debug output device.\r
+  DebugAssert() must actively prevent recusrsion.  If DebugAssert() is called while\r
+  processing another DebugAssert(), then DebugAssert() must return immediately.\r
+\r
+  If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r
+\r
+  If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r
+\r
+  @param  FileName     Pointer to the name of the source file that generated the assert condition.\r
+  @param  LineNumber   The line number in the source file that generated the assert condition\r
+  @param  Description  Pointer to the description of the assert condition.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+DebugAssert (\r
+  IN CONST CHAR8  *FileName,\r
+  IN UINTN        LineNumber,\r
+  IN CONST CHAR8  *Description\r
+  )\r
+{\r
+  CHAR16  Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
+\r
+  //\r
+  // Generate the ASSERT() message in Unicode format\r
+  //\r
+  UnicodeSPrintAsciiFormat (Buffer, sizeof (Buffer), "ASSERT %s(%d): %s\n", FileName, LineNumber, Description);\r
+\r
+  //\r
+  // Send the print string to the Standard Error device\r
+  //\r
+  if ((gST != NULL) && (gST->StdErr != NULL)) {\r
+    gST->StdErr->OutputString (gST->StdErr, Buffer);\r
+  }\r
+\r
+  //\r
+  // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r
+  //\r
+  if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
+    CpuBreakpoint ();\r
+  } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
+    CpuDeadLoop ();\r
+  }\r
+}\r
+\r
+\r
+/**\r
+\r
+  Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
+\r
+  This function fills Length bytes of Buffer with the value specified by \r
+  PcdDebugClearMemoryValue, and returns Buffer.\r
+\r
+  If Buffer is NULL, then ASSERT().\r
+\r
+  If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
+\r
+  @param   Buffer  Pointer to the target buffer to fill with PcdDebugClearMemoryValue.\r
+  @param   Length  Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue. \r
+\r
+  @return  Buffer\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+DebugClearMemory (\r
+  OUT VOID  *Buffer,\r
+  IN UINTN  Length\r
+  )\r
+{\r
+  //\r
+  // If Buffer is NULL, then ASSERT().\r
+  //\r
+  ASSERT (Buffer != NULL);\r
+\r
+  //\r
+  // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r
+  //\r
+  return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r
+}\r
+\r
+\r
+/**\r
+  \r
+  Returns TRUE if ASSERT() macros are enabled.\r
+\r
+  This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of \r
+  PcdDebugProperyMask is set.  Otherwise FALSE is returned.\r
+\r
+  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r
+  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+DebugAssertEnabled (\r
+  VOID\r
+  )\r
+{\r
+  return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r
+}\r
+\r
+\r
+/**\r
+  \r
+  Returns TRUE if DEBUG()macros are enabled.\r
+\r
+  This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of \r
+  PcdDebugProperyMask is set.  Otherwise FALSE is returned.\r
+\r
+  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r
+  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+DebugPrintEnabled (\r
+  VOID\r
+  )\r
+{\r
+  return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r
+}\r
+\r
+\r
+/**\r
+  \r
+  Returns TRUE if DEBUG_CODE()macros are enabled.\r
+\r
+  This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of \r
+  PcdDebugProperyMask is set.  Otherwise FALSE is returned.\r
+\r
+  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r
+  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+DebugCodeEnabled (\r
+  VOID\r
+  )\r
+{\r
+  return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
+}\r
+\r
+\r
+/**\r
+  \r
+  Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.\r
+\r
+  This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of \r
+  PcdDebugProperyMask is set.  Otherwise FALSE is returned.\r
+\r
+  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r
+  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+DebugClearMemoryEnabled (\r
+  VOID\r
+  )\r
+{\r
+  return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r
+}\r
diff --git a/MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf b/MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf
new file mode 100644 (file)
index 0000000..9f8fbe6
--- /dev/null
@@ -0,0 +1,105 @@
+#/** @file\r
+# Debug Library for UEFI drivers\r
+#\r
+# Library to abstract Framework extensions that conflict with UEFI 2.0 Specification\r
+# Copyright (c) 2007, Intel Corporation.\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UefiDebugLibStdErr\r
+  FILE_GUID                      = b57a1df6-ffdb-4247-a3df-3a562176751a\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = DebugLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  DebugLib.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg\Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  BaseMemoryLib\r
+  BaseLib\r
+  PcdLib\r
+  PrintLib\r
+  UefiBootServicesTableLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Pcd FIXED_AT_BUILD - list of PCDs that this module is coded for.\r
+#\r
+################################################################################\r
+\r
+[PcdsFixedAtBuild.common]\r
+  PcdDebugClearMemoryValue|gEfiMdePkgTokenSpaceGuid\r
+  PcdDebugPropertyMask|gEfiMdePkgTokenSpaceGuid\r
+\r
+\r
+################################################################################\r
+#\r
+# Pcd DYNAMIC - list of PCDs that this module is coded for.\r
+#\r
+################################################################################\r
+\r
+[PcdsDynamic.common]\r
+  PcdDebugPrintErrorLevel|gEfiMdePkgTokenSpaceGuid\r
+\r
diff --git a/MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.msa b/MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.msa
new file mode 100644 (file)
index 0000000..b9371c5
--- /dev/null
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>UefiDebugLibStdErr</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>b57a1df6-ffdb-4247-a3df-3a562176751a</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Debug Library for UEFI drivers</Abstract>\r
+    <Description>Library to abstract Framework extensions that conflict with UEFI 2.0 Specification</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation.</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UefiDebugLibStdErr</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PrintLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PcdLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>DebugLib.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+  <PcdCoded>\r
+    <PcdEntry PcdItemType="FIXED_AT_BUILD">\r
+      <C_Name>PcdDebugPropertyMask</C_Name>\r
+      <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>The bitmask of flags that specify the enable/disable of Debug
+                Assert, Debug Print, Debug Code, Clear Memory, Assert
+                Breakpoint and Assert Deadloop.</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="FIXED_AT_BUILD">\r
+      <C_Name>PcdDebugClearMemoryValue</C_Name>\r
+      <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>The value used by DebugClearMemory () to fill a certain range
+                of memory.</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdDebugPrintErrorLevel</C_Name>\r
+      <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>The bitmask of flags that specify the kind of debug message
+                output when Debug Print is enabled.</HelpText>\r
+    </PcdEntry>\r
+  </PcdCoded>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdePkg/Library/UefiDevicePathLib/CommonHeader.h b/MdePkg/Library/UefiDevicePathLib/CommonHeader.h
new file mode 100644 (file)
index 0000000..d34b4d9
--- /dev/null
@@ -0,0 +1,37 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007 - 2007, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <Uefi.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/DevicePath.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/BaseLib.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.c b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.c
new file mode 100644 (file)
index 0000000..bdc512b
--- /dev/null
@@ -0,0 +1,529 @@
+/** @file\r
+  Device Path services. The thing to remember is device paths are built out of\r
+  nodes. The device path is terminated by an end node that is length\r
+  sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)\r
+  all over this file.\r
+\r
+  The only place where multi-instance device paths are supported is in\r
+  environment varibles. Multi-instance device paths should never be placed\r
+  on a Handle.\r
+\r
+  Copyright (c) 2006, Intel Corporation                                                         \r
+  All rights reserved. This program and the accompanying materials                          \r
+  are licensed and made available under the terms and conditions of the BSD License         \r
+  which accompanies this distribution.  The full text of the license may be found at        \r
+  http://opensource.org/licenses/bsd-license.php                                            \r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+  Module Name:  UefiDevicePathLib.c\r
+\r
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+/**\r
+  Returns the size of a device path in bytes.\r
+\r
+  This function returns the size, in bytes, of the device path data structure specified by\r
+  DevicePath including the end of device path node.  If DevicePath is NULL, then 0 is returned.\r
+\r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+\r
+  @return The size of a device path in bytes.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+GetDevicePathSize (\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  )\r
+{\r
+  CONST EFI_DEVICE_PATH_PROTOCOL  *Start;\r
+\r
+  if (DevicePath == NULL) {\r
+    return 0;\r
+  }\r
+\r
+  //\r
+  // Search for the end of the device path structure\r
+  //\r
+  Start = DevicePath;\r
+  while (!EfiIsDevicePathEnd (DevicePath)) {\r
+    DevicePath = EfiNextDevicePathNode (DevicePath);\r
+  }\r
+\r
+  //\r
+  // Compute the size and add back in the size of the end device path structure\r
+  //\r
+  return ((UINTN) DevicePath - (UINTN) Start) + sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
+}\r
+\r
+/**\r
+  Creates a new device path by appending a second device path to a first device path.\r
+\r
+  This function allocates space for a new copy of the device path specified by DevicePath.  If\r
+  DevicePath is NULL, then NULL is returned.  If the memory is successfully allocated, then the\r
+  contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer\r
+  is returned.  Otherwise, NULL is returned.  \r
+  \r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+\r
+  @return A pointer to the duplicated device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+DuplicateDevicePath (\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;\r
+  UINTN                     Size;\r
+\r
+  //\r
+  // Compute the size\r
+  //\r
+  Size = GetDevicePathSize (DevicePath);\r
+  if (Size == 0) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Allocate space for duplicate device path\r
+  //\r
+  NewDevicePath = AllocateCopyPool (Size, DevicePath);\r
+\r
+  return NewDevicePath;\r
+}\r
+\r
+/**\r
+  Creates a new device path by appending a second device path to a first device path.\r
+\r
+  This function creates a new device path by appending a copy of SecondDevicePath to a copy of\r
+  FirstDevicePath in a newly allocated buffer.  Only the end-of-device-path device node from\r
+  SecondDevicePath is retained. The newly created device path is returned.  \r
+  If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned.  \r
+  If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned.  \r
+  If both FirstDevicePath and SecondDevicePath are NULL, then NULL is returned.  \r
+  If there is not enough memory for the newly allocated buffer, then NULL is returned.\r
+  The memory for the new device path is allocated from EFI boot services memory. It is the\r
+  responsibility of the caller to free the memory allocated.\r
+\r
+  @param  FirstDevicePath            A pointer to a device path data structure.\r
+  @param  SecondDevicePath           A pointer to a device path data structure.\r
+\r
+  @return A pointer to the new device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+AppendDevicePath (\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *FirstDevicePath,  OPTIONAL\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *SecondDevicePath  OPTIONAL\r
+  )\r
+{\r
+  UINTN                     Size;\r
+  UINTN                     Size1;\r
+  UINTN                     Size2;\r
+  EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath2;\r
+\r
+  //\r
+  // If there's only 1 path, just duplicate it.\r
+  //\r
+  if (FirstDevicePath == NULL) {\r
+    return DuplicateDevicePath (SecondDevicePath);\r
+  }\r
+\r
+  if (SecondDevicePath == NULL) {\r
+    return DuplicateDevicePath (FirstDevicePath);\r
+  }\r
+\r
+  //\r
+  // Allocate space for the combined device path. It only has one end node of\r
+  // length EFI_DEVICE_PATH_PROTOCOL.\r
+  //\r
+  Size1         = GetDevicePathSize (FirstDevicePath);\r
+  Size2         = GetDevicePathSize (SecondDevicePath);\r
+  Size          = Size1 + Size2 - sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
+\r
+  NewDevicePath = AllocatePool (Size);\r
+\r
+  if (NewDevicePath != NULL) {\r
+    NewDevicePath = CopyMem (NewDevicePath, FirstDevicePath, Size1);\r
+    //\r
+    // Over write FirstDevicePath EndNode and do the copy\r
+    //\r
+    DevicePath2 = (EFI_DEVICE_PATH_PROTOCOL *) ((CHAR8 *) NewDevicePath +\r
+                  (Size1 - sizeof (EFI_DEVICE_PATH_PROTOCOL)));\r
+    CopyMem (DevicePath2, SecondDevicePath, Size2);\r
+  }\r
+\r
+  return NewDevicePath;\r
+}\r
+\r
+/**\r
+  Creates a new path by appending the device node to the device path.\r
+\r
+  This function creates a new device path by appending a copy of the device node specified by\r
+  DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.\r
+  The end-of-device-path device node is moved after the end of the appended device node.\r
+  If DevicePath is NULL, then NULL is returned.\r
+  If DevicePathNode is NULL, then NULL is returned.\r
+  If there is not enough memory to allocate space for the new device path, then NULL is returned.  \r
+  The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
+  free the memory allocated.\r
+\r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+  @param  DevicePathNode             A pointer to a single device path node.\r
+\r
+  @return A pointer to the new device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+AppendDevicePathNode (\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,     OPTIONAL\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathNode  OPTIONAL\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *NextNode;\r
+  EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;\r
+  UINTN                     NodeLength;\r
+\r
+  if (DevicePath == NULL || DevicePathNode == NULL) {\r
+    return NULL;\r
+  }\r
+  //\r
+  // Build a Node that has a terminator on it\r
+  //\r
+  NodeLength = DevicePathNodeLength (DevicePathNode);\r
+\r
+  TempDevicePath = AllocatePool (NodeLength + sizeof (EFI_DEVICE_PATH_PROTOCOL));\r
+  if (TempDevicePath == NULL) {\r
+    return NULL;\r
+  }\r
+  TempDevicePath = CopyMem (TempDevicePath, DevicePathNode, NodeLength);\r
+  //\r
+  // Add and end device path node to convert Node to device path\r
+  //\r
+  NextNode = NextDevicePathNode (TempDevicePath);\r
+  SetDevicePathEndNode (NextNode);\r
+  //\r
+  // Append device paths\r
+  //\r
+  NewDevicePath = AppendDevicePath (DevicePath, TempDevicePath);\r
+\r
+  FreePool (TempDevicePath);\r
+\r
+  return NewDevicePath;\r
+}\r
+\r
+/**\r
+  Creates a new device path by appending the specified device path instance to the specified device\r
+  path.\r
\r
+  This function creates a new device path by appending a copy of the device path instance specified\r
+  by DevicePathInstance to a copy of the device path secified by DevicePath in a allocated buffer.\r
+  The end-of-device-path device node is moved after the end of the appended device path instance\r
+  and a new end-of-device-path-instance node is inserted between. \r
+  If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r
+  If DevicePathInstance is NULL, then NULL is returned.\r
+  If there is not enough memory to allocate space for the new device path, then NULL is returned.  \r
+  The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
+  free the memory allocated.\r
+  \r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+  @param  DevicePathInstance         A pointer to a device path instance.\r
+\r
+  @return A pointer to the new device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+AppendDevicePathInstance (\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,        OPTIONAL\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathInstance OPTIONAL\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath;\r
+  UINTN                     SrcSize;\r
+  UINTN                     InstanceSize;\r
+\r
+  if (DevicePath == NULL) {\r
+    return DuplicateDevicePath (DevicePathInstance);\r
+  }\r
+\r
+  if (DevicePathInstance == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  SrcSize       = GetDevicePathSize (DevicePath);\r
+  InstanceSize  = GetDevicePathSize (DevicePathInstance);\r
+\r
+  NewDevicePath = AllocatePool (SrcSize + InstanceSize);\r
+  if (NewDevicePath != NULL) {\r
+    \r
+    TempDevicePath = CopyMem (NewDevicePath, DevicePath, SrcSize);;\r
\r
+    while (!IsDevicePathEnd (TempDevicePath)) {\r
+      TempDevicePath = NextDevicePathNode (TempDevicePath);\r
+    }\r
+    \r
+    TempDevicePath->SubType  = END_INSTANCE_DEVICE_PATH_SUBTYPE;\r
+    TempDevicePath           = NextDevicePathNode (TempDevicePath);\r
+    CopyMem (TempDevicePath, DevicePathInstance, InstanceSize);\r
+  }\r
+\r
+  return NewDevicePath;\r
+}\r
+\r
+/**\r
+  Creates a copy of the current device path instance and returns a pointer to the next device path\r
+  instance.\r
+\r
+  This function creates a copy of the current device path instance. It also updates DevicePath to\r
+  point to the next device path instance in the device path (or NULL if no more) and updates Size\r
+  to hold the size of the device path instance copy.\r
+  If DevicePath is NULL, then NULL is returned.\r
+  If there is not enough memory to allocate space for the new device path, then NULL is returned.  \r
+  The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
+  free the memory allocated.\r
+  If Size is NULL, then ASSERT().\r
\r
+  @param  DevicePath                 On input, this holds the pointer to the current device path\r
+                                     instance. On output, this holds the pointer to the next device\r
+                                     path instance or NULL if there are no more device path\r
+                                     instances in the device path pointer to a device path data\r
+                                     structure.\r
+  @param  Size                       On output, this holds the size of the device path instance, in\r
+                                     bytes or zero, if DevicePath is NULL.\r
+\r
+  @return A pointer to the current device path instance.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+GetNextDevicePathInstance (\r
+  IN OUT EFI_DEVICE_PATH_PROTOCOL    **DevicePath,\r
+  OUT UINTN                          *Size\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevPath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ReturnValue;\r
+  UINT8                     Temp;\r
+\r
+  ASSERT (Size != NULL);\r
+\r
+  if (DevicePath == NULL || *DevicePath == NULL) {\r
+    *Size = 0;\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Find the end of the device path instance\r
+  //\r
+  DevPath = *DevicePath;\r
+  while (!IsDevicePathEndType (DevPath)) {\r
+    DevPath = NextDevicePathNode (DevPath);\r
+  }\r
+\r
+  //\r
+  // Compute the size of the device path instance\r
+  //\r
+  *Size = ((UINTN) DevPath - (UINTN) (*DevicePath)) + sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
\r
+  //\r
+  // Make a copy and return the device path instance\r
+  //\r
+  Temp              = DevPath->SubType;\r
+  DevPath->SubType  = END_ENTIRE_DEVICE_PATH_SUBTYPE;\r
+  ReturnValue       = DuplicateDevicePath (*DevicePath);\r
+  DevPath->SubType  = Temp;\r
+\r
+  //\r
+  // If DevPath is the end of an entire device path, then another instance\r
+  // does not follow, so *DevicePath is set to NULL.\r
+  //\r
+  if (DevicePathSubType (DevPath) == END_ENTIRE_DEVICE_PATH_SUBTYPE) {\r
+    *DevicePath = NULL;\r
+  } else {\r
+    *DevicePath = NextDevicePathNode (DevPath);\r
+  }\r
+\r
+  return ReturnValue;\r
+}\r
+\r
+/**\r
+  Creates a copy of the current device path instance and returns a pointer to the next device path\r
+  instance.\r
+\r
+  This function creates a new device node in a newly allocated buffer of size NodeLength and\r
+  initializes the device path node header with NodeType and NodeSubType.  The new device path node\r
+  is returned.\r
+  If NodeLength is smaller than a device path header, then NULL is returned.  \r
+  If there is not enough memory to allocate space for the new device path, then NULL is returned.  \r
+  The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
+  free the memory allocated.\r
+\r
+  @param  NodeType                   The device node type for the new device node.\r
+  @param  NodeSubType                The device node sub-type for the new device node.\r
+  @param  NodeLength                 The length of the new device node.\r
+\r
+  @return The new device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+CreateDeviceNode (\r
+  IN UINT8                           NodeType,\r
+  IN UINT8                           NodeSubType,\r
+  IN UINT16                          NodeLength\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL      *DevicePath;\r
+\r
+  if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {\r
+    //\r
+    // NodeLength is less than the size of the header.\r
+    //\r
+    return NULL;\r
+  }\r
\r
+  DevicePath = AllocatePool (NodeLength);\r
+  if (DevicePath != NULL) {\r
+     DevicePath->Type    = NodeType;\r
+     DevicePath->SubType = NodeSubType;\r
+     SetDevicePathNodeLength (DevicePath, NodeLength);\r
+  }\r
+\r
+  return DevicePath;\r
+}\r
+\r
+/**\r
+  Determines if a device path is single or multi-instance.\r
+\r
+  This function returns TRUE if the device path specified by DevicePath is multi-instance.\r
+  Otherwise, FALSE is returned.  If DevicePath is NULL, then FALSE is returned.\r
+\r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+\r
+  @retval  TRUE                      DevicePath is multi-instance.\r
+  @retval  FALSE                     DevicePath is not multi-instance or DevicePath is NULL.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsDevicePathMultiInstance (\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  )\r
+{\r
+  CONST EFI_DEVICE_PATH_PROTOCOL     *Node;\r
+\r
+  if (DevicePath == NULL) {\r
+    return FALSE;\r
+  }\r
+\r
+  Node = DevicePath;\r
+  while (!EfiIsDevicePathEnd (Node)) {\r
+    if (EfiIsDevicePathEndInstance (Node)) {\r
+      return TRUE;\r
+    }\r
+\r
+    Node = EfiNextDevicePathNode (Node);\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+\r
+/**\r
+  Retrieves the device path protocol from a handle.\r
+\r
+  This function returns the device path protocol from the handle specified by Handle.  If Handle is\r
+  NULL or Handle does not contain a device path protocol, then NULL is returned.\r
\r
+  @param  Handle                     The handle from which to retrieve the device path protocol.\r
+\r
+  @return The device path protocol from the handle specified by Handle.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+DevicePathFromHandle (\r
+  IN EFI_HANDLE                      Handle\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  EFI_STATUS                Status;\r
+\r
+  Status = gBS->HandleProtocol (\r
+                  Handle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID *) &DevicePath\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    DevicePath = NULL;\r
+  }\r
+  return DevicePath;\r
+}\r
+\r
+/**\r
+  Allocates a device path for a file and appends it to an existing device path.\r
+\r
+  If Device is a valid device handle that contains a device path protocol, then a device path for\r
+  the file specified by FileName  is allocated and appended to the device path associated with the\r
+  handle Device.  The allocated device path is returned.  If Device is NULL or Device is a handle\r
+  that does not support the device path protocol, then a device path containing a single device\r
+  path node for the file specified by FileName is allocated and returned.\r
+  If FileName is NULL, then ASSERT().\r
+\r
+  @param  Device                     A pointer to a device handle.  This parameter is optional and\r
+                                     may be NULL.\r
+  @param  FileName                   A pointer to a Null-terminated Unicode string.\r
+\r
+  @return The allocated device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+FileDevicePath (\r
+  IN EFI_HANDLE                      Device,     OPTIONAL\r
+  IN CONST CHAR16                    *FileName\r
+  )\r
+{\r
+  UINTN                     Size;\r
+  FILEPATH_DEVICE_PATH      *FilePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *FileDevicePath;\r
+\r
+  DevicePath = NULL;\r
+\r
+  Size = StrSize (FileName);\r
+  FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + EFI_END_DEVICE_PATH_LENGTH);\r
+  if (FileDevicePath != NULL) {\r
+    FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath;\r
+    FilePath->Header.Type    = MEDIA_DEVICE_PATH;\r
+    FilePath->Header.SubType = MEDIA_FILEPATH_DP;\r
+    CopyMem (&FilePath->PathName, FileName, Size);\r
+    SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH);\r
+    SetDevicePathEndNode (NextDevicePathNode (&FilePath->Header));\r
+\r
+    if (Device != NULL) {\r
+      DevicePath = DevicePathFromHandle (Device);\r
+    }\r
+\r
+    DevicePath = AppendDevicePath (DevicePath, FileDevicePath);\r
+    FreePool (FileDevicePath);\r
+  }\r
+\r
+  return DevicePath;\r
+}\r
+\r
diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
new file mode 100644 (file)
index 0000000..20f6449
--- /dev/null
@@ -0,0 +1,95 @@
+#/** @file\r
+# Component description file for the entry point to a EFIDXE Drivers\r
+#\r
+# Library to abstract Framework extensions that conflict with UEFI 2.0 Specification\r
+# Copyright (c) 2007 - 2007, Intel Corporation\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UefiDevicePathLib\r
+  FILE_GUID                      = 91c1677a-e57f-4191-8b8e-eb7711a716e0\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = DevicePathLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  UefiDevicePathLib.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg\Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  DebugLib\r
+  BaseMemoryLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
+#                           that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Protocols]\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL ALWAYS_CONSUMED\r
+\r
diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.msa b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.msa
new file mode 100644 (file)
index 0000000..b6b94f9
--- /dev/null
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>UefiDevicePathLib</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>91c1677a-e57f-4191-8b8e-eb7711a716e0</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for the entry point to a EFIDXE Drivers</Abstract>\r
+    <Description>Library to abstract Framework extensions that conflict with UEFI 2.0 Specification</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UefiDevicePathLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER">\r
+      <Keyword>DevicePathLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UefiDevicePathLib.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/CommonHeader.h b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/CommonHeader.h
new file mode 100644 (file)
index 0000000..40a075d
--- /dev/null
@@ -0,0 +1,38 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007 - 2007, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <Uefi.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/DevicePathUtilities.h>\r
+#include <Protocol/DevicePath.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c
new file mode 100644 (file)
index 0000000..2492e4b
--- /dev/null
@@ -0,0 +1,353 @@
+/** @file\r
+  UEFI Device Path Library.\r
+\r
+  Copyright (c) 2006, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Module Name:  UefiDevicePathLib.c\r
+\r
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+STATIC EFI_DEVICE_PATH_UTILITIES_PROTOCOL          *mDevicePathUtilities = NULL;\r
+\r
+/**\r
+  The constructor function caches the pointer to DevicePathUtilites protocol.\r
+  \r
+  The constructor function locates DevicePathUtilities protocol from protocol database.\r
+  It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. \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
+DevicePathLibConstructor (\r
+  IN      EFI_HANDLE                ImageHandle,\r
+  IN      EFI_SYSTEM_TABLE          *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiDevicePathUtilitiesProtocolGuid,\r
+                  NULL,\r
+                  (VOID**) &mDevicePathUtilities\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+  ASSERT (mDevicePathUtilities != NULL);\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Returns the size of a device path in bytes.\r
+\r
+  This function returns the size, in bytes, of the device path data structure specified by\r
+  DevicePath including the end of device path node.  If DevicePath is NULL, then 0 is returned.\r
+\r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+\r
+  @return The size of a device path in bytes.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+GetDevicePathSize (\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  )\r
+{\r
+  return mDevicePathUtilities->GetDevicePathSize (DevicePath);\r
+}\r
+\r
+/**\r
+  Creates a new device path by appending a second device path to a first device path.\r
+\r
+  This function allocates space for a new copy of the device path specified by DevicePath.  If\r
+  DevicePath is NULL, then NULL is returned.  If the memory is successfully allocated, then the\r
+  contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer\r
+  is returned.  Otherwise, NULL is returned.  \r
+  \r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+\r
+  @return A pointer to the duplicated device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+DuplicateDevicePath (\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  )\r
+{\r
+  return mDevicePathUtilities->DuplicateDevicePath (DevicePath);\r
+}\r
+\r
+/**\r
+  Creates a new device path by appending a second device path to a first device path.\r
+\r
+  This function creates a new device path by appending a copy of SecondDevicePath to a copy of\r
+  FirstDevicePath in a newly allocated buffer.  Only the end-of-device-path device node from\r
+  SecondDevicePath is retained. The newly created device path is returned.  \r
+  If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned.  \r
+  If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned.  \r
+  If both FirstDevicePath and SecondDevicePath are NULL, then NULL is returned.  \r
+  If there is not enough memory for the newly allocated buffer, then NULL is returned.\r
+  The memory for the new device path is allocated from EFI boot services memory. It is the\r
+  responsibility of the caller to free the memory allocated.\r
+\r
+  @param  FirstDevicePath            A pointer to a device path data structure.\r
+  @param  SecondDevicePath           A pointer to a device path data structure.\r
+\r
+  @return A pointer to the new device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+AppendDevicePath (\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *FirstDevicePath,  OPTIONAL\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *SecondDevicePath  OPTIONAL\r
+  )\r
+{\r
+  return mDevicePathUtilities->AppendDevicePath (FirstDevicePath, SecondDevicePath);\r
+}\r
+\r
+/**\r
+  Creates a new path by appending the device node to the device path.\r
+\r
+  This function creates a new device path by appending a copy of the device node specified by\r
+  DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.\r
+  The end-of-device-path device node is moved after the end of the appended device node.\r
+  If DevicePath is NULL, then NULL is returned.\r
+  If DevicePathNode is NULL, then NULL is returned.\r
+  If there is not enough memory to allocate space for the new device path, then NULL is returned.  \r
+  The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
+  free the memory allocated.\r
+\r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+  @param  DevicePathNode             A pointer to a single device path node.\r
+\r
+  @return A pointer to the new device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+AppendDevicePathNode (\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,     OPTIONAL\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathNode  OPTIONAL\r
+  )\r
+{\r
+  return mDevicePathUtilities->AppendDeviceNode (DevicePath, DevicePathNode);\r
+}\r
+\r
+/**\r
+  Creates a new device path by appending the specified device path instance to the specified device\r
+  path.\r
\r
+  This function creates a new device path by appending a copy of the device path instance specified\r
+  by DevicePathInstance to a copy of the device path secified by DevicePath in a allocated buffer.\r
+  The end-of-device-path device node is moved after the end of the appended device path instance\r
+  and a new end-of-device-path-instance node is inserted between. \r
+  If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r
+  If DevicePathInstance is NULL, then NULL is returned.\r
+  If there is not enough memory to allocate space for the new device path, then NULL is returned.  \r
+  The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
+  free the memory allocated.\r
+  \r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+  @param  DevicePathInstance         A pointer to a device path instance.\r
+\r
+  @return A pointer to the new device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+AppendDevicePathInstance (\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,        OPTIONAL\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathInstance OPTIONAL\r
+  )\r
+{\r
+  return mDevicePathUtilities->AppendDevicePathInstance (DevicePath, DevicePathInstance);\r
+}\r
+\r
+/**\r
+  Creates a copy of the current device path instance and returns a pointer to the next device path\r
+  instance.\r
+\r
+  This function creates a copy of the current device path instance. It also updates DevicePath to\r
+  point to the next device path instance in the device path (or NULL if no more) and updates Size\r
+  to hold the size of the device path instance copy.\r
+  If DevicePath is NULL, then NULL is returned.\r
+  If there is not enough memory to allocate space for the new device path, then NULL is returned.  \r
+  The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
+  free the memory allocated.\r
+  If Size is NULL, then ASSERT().\r
\r
+  @param  DevicePath                 On input, this holds the pointer to the current device path\r
+                                     instance. On output, this holds the pointer to the next device\r
+                                     path instance or NULL if there are no more device path\r
+                                     instances in the device path pointer to a device path data\r
+                                     structure.\r
+  @param  Size                       On output, this holds the size of the device path instance, in\r
+                                     bytes or zero, if DevicePath is NULL.\r
+\r
+  @return A pointer to the current device path instance.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+GetNextDevicePathInstance (\r
+  IN OUT EFI_DEVICE_PATH_PROTOCOL    **DevicePath,\r
+  OUT UINTN                          *Size\r
+  )\r
+{\r
+  ASSERT (Size != NULL);\r
+  return mDevicePathUtilities->GetNextDevicePathInstance (DevicePath, Size);\r
+}\r
+\r
+/**\r
+  Creates a copy of the current device path instance and returns a pointer to the next device path\r
+  instance.\r
+\r
+  This function creates a new device node in a newly allocated buffer of size NodeLength and\r
+  initializes the device path node header with NodeType and NodeSubType.  The new device path node\r
+  is returned.\r
+  If NodeLength is smaller than a device path header, then NULL is returned.  \r
+  If there is not enough memory to allocate space for the new device path, then NULL is returned.  \r
+  The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
+  free the memory allocated.\r
+\r
+  @param  NodeType                   The device node type for the new device node.\r
+  @param  NodeSubType                The device node sub-type for the new device node.\r
+  @param  NodeLength                 The length of the new device node.\r
+\r
+  @return The new device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+CreateDeviceNode (\r
+  IN UINT8                           NodeType,\r
+  IN UINT8                           NodeSubType,\r
+  IN UINT16                          NodeLength\r
+  )\r
+{\r
+  return mDevicePathUtilities->CreateDeviceNode (NodeType, NodeSubType, NodeLength);\r
+}\r
+\r
+/**\r
+  Determines if a device path is single or multi-instance.\r
+\r
+  This function returns TRUE if the device path specified by DevicePath is multi-instance.\r
+  Otherwise, FALSE is returned.  If DevicePath is NULL, then FALSE is returned.\r
+\r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+\r
+  @retval  TRUE                      DevicePath is multi-instance.\r
+  @retval  FALSE                     DevicePath is not multi-instance or DevicePath is NULL.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsDevicePathMultiInstance (\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  )\r
+{\r
+  return mDevicePathUtilities->IsDevicePathMultiInstance (DevicePath);\r
+}\r
+\r
+/**\r
+  Retrieves the device path protocol from a handle.\r
+\r
+  This function returns the device path protocol from the handle specified by Handle.  If Handle is\r
+  NULL or Handle does not contain a device path protocol, then NULL is returned.\r
\r
+  @param  Handle                     The handle from which to retrieve the device path protocol.\r
+\r
+  @return The device path protocol from the handle specified by Handle.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+DevicePathFromHandle (\r
+  IN EFI_HANDLE                      Handle\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  EFI_STATUS                Status;\r
+\r
+  Status = gBS->HandleProtocol (\r
+                  Handle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID *) &DevicePath\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    DevicePath = NULL;\r
+  }\r
+  return DevicePath;\r
+}\r
+\r
+/**\r
+  Allocates a device path for a file and appends it to an existing device path.\r
+\r
+  If Device is a valid device handle that contains a device path protocol, then a device path for\r
+  the file specified by FileName  is allocated and appended to the device path associated with the\r
+  handle Device.  The allocated device path is returned.  If Device is NULL or Device is a handle\r
+  that does not support the device path protocol, then a device path containing a single device\r
+  path node for the file specified by FileName is allocated and returned.\r
+  If FileName is NULL, then ASSERT().\r
+\r
+  @param  Device                     A pointer to a device handle.  This parameter is optional and\r
+                                     may be NULL.\r
+  @param  FileName                   A pointer to a Null-terminated Unicode string.\r
+\r
+  @return The allocated device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+FileDevicePath (\r
+  IN EFI_HANDLE                      Device,     OPTIONAL\r
+  IN CONST CHAR16                    *FileName\r
+  )\r
+{\r
+  UINTN                     Size;\r
+  FILEPATH_DEVICE_PATH      *FilePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *FileDevicePath;\r
+\r
+  DevicePath = NULL;\r
+\r
+  Size = StrSize (FileName);\r
+  FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + EFI_END_DEVICE_PATH_LENGTH);\r
+  if (FileDevicePath != NULL) {\r
+    FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath;\r
+    FilePath->Header.Type    = MEDIA_DEVICE_PATH;\r
+    FilePath->Header.SubType = MEDIA_FILEPATH_DP;\r
+    CopyMem (&FilePath->PathName, FileName, Size);\r
+    SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH);\r
+    SetDevicePathEndNode (NextDevicePathNode (&FilePath->Header));\r
+\r
+    if (Device != NULL) {\r
+      DevicePath = DevicePathFromHandle (Device);\r
+    }\r
+\r
+    DevicePath = AppendDevicePath (DevicePath, FileDevicePath);\r
+    FreePool (FileDevicePath);\r
+  }\r
+\r
+  return DevicePath;\r
+}\r
+\r
diff --git a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLibDevicePathProtocol.inf b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLibDevicePathProtocol.inf
new file mode 100644 (file)
index 0000000..39da015
--- /dev/null
@@ -0,0 +1,98 @@
+#/** @file\r
+# Component description file for Uefi Device Path Library via protocol\r
+#\r
+# Device Path Library that layers on top of the UEFI 2.0 Device Path Protocol.\r
+#  This library is not available for EFI 1.10 modules.\r
+# Copyright (c) 2007 - 2007, Intel Corporation\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UefiDevicePathLibDevicePathProtocol\r
+  FILE_GUID                      = 050EB8C6-C12E-4b86-892B-40985E8B3137\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = DevicePathLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = DevicePathLibConstructor\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
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  UefiDevicePathLib.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg\Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  BaseMemoryLib\r
+  MemoryAllocationLib\r
+  BaseLib\r
+  DebugLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
+#                           that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Protocols]\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiDevicePathUtilitiesProtocolGuid           # PROTOCOL ALWAYS_CONSUMED\r
+\r
diff --git a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLibDevicePathProtocol.msa b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLibDevicePathProtocol.msa
new file mode 100644 (file)
index 0000000..6a095e4
--- /dev/null
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>UefiDevicePathLibDevicePathProtocol</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>050EB8C6-C12E-4b86-892B-40985E8B3137</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for Uefi Device Path Library via protocol</Abstract>\r
+    <Description>Device Path Library that layers on top of the UEFI 2.0 Device Path Protocol.
+      This library is not available for EFI 1.10 modules.</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UefiDevicePathLibDevicePathProtocol</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER">\r
+      <Keyword>DevicePathLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UefiDevicePathLib.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiDevicePathUtilitiesProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <Constructor>DevicePathLibConstructor</Constructor>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdePkg/Library/UefiDriverEntryPoint/CommonHeader.h b/MdePkg/Library/UefiDriverEntryPoint/CommonHeader.h
new file mode 100644 (file)
index 0000000..7749e63
--- /dev/null
@@ -0,0 +1,34 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007 - 2007, Intel Corporation.\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <Uefi.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/LoadedImage.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/UefiDriverEntryPoint/DriverEntryPoint.c b/MdePkg/Library/UefiDriverEntryPoint/DriverEntryPoint.c
new file mode 100644 (file)
index 0000000..8e3b30a
--- /dev/null
@@ -0,0 +1,172 @@
+/** @file\r
+  Entry point to a EFI/DXE driver.\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+\r
+/**\r
+  Unload function that is registered in the LoadImage protocol.  It un-installs\r
+  protocols produced and deallocates pool used by the driver.  Called by the core\r
+  when unloading the driver.\r
+\r
+  @param  ImageHandle\r
+\r
+  @retval EFI_SUCCESS\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+_DriverUnloadHandler (\r
+  EFI_HANDLE ImageHandle\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // If an UnloadImage() handler is specified, then call it\r
+  //\r
+  Status = ProcessModuleUnloadList (ImageHandle);\r
+\r
+  //\r
+  // If the driver specific unload handler does not return an error, then call all of the\r
+  // library destructors.  If the unload handler returned an error, then the driver can not be\r
+  // unloaded, and the library destructors should not be called\r
+  //\r
+  if (!EFI_ERROR (Status)) {\r
+\r
+    ProcessLibraryDestructorList (ImageHandle, gST);\r
+  }\r
+\r
+  //\r
+  // Return the status from the driver specific unload handler\r
+  //\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Notification Entry of ExitBootService event. In the entry, all notifications in _gDriverExitBootServicesEvent[]\r
+  would be invoked.\r
+\r
+  @param Event   The Event that is being processed.\r
+  @param Context Event Context.\r
+\r
+**/\r
+STATIC\r
+VOID\r
+EFIAPI\r
+_DriverExitBootServices (\r
+  IN EFI_EVENT        Event,\r
+  IN VOID             *Context\r
+  )\r
+{\r
+  EFI_EVENT_NOTIFY  ChildNotifyEventHandler;\r
+  UINTN             Index;\r
+\r
+  for (Index = 0; _gDriverExitBootServicesEvent[Index] != NULL; Index++) {\r
+    ChildNotifyEventHandler = _gDriverExitBootServicesEvent[Index];\r
+    ChildNotifyEventHandler (Event, NULL);\r
+  }\r
+}\r
+\r
+/**\r
+  Enrty point to DXE Driver.\r
+\r
+  @param  ImageHandle ImageHandle of the loaded driver.\r
+  @param  SystemTable Pointer to the EFI System Table.\r
+\r
+  @retval  EFI_SUCCESS One or more of the drivers returned a success code.\r
+  @retval  !EFI_SUCESS The return status from the last driver entry point in the list.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+_ModuleEntryPoint (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS                 Status;\r
+  EFI_LOADED_IMAGE_PROTOCOL  *LoadedImage;\r
+\r
+  if (_gUefiDriverRevision != 0) {\r
+    //\r
+    // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver\r
+    //\r
+    if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {\r
+      return EFI_INCOMPATIBLE_VERSION;\r
+    }\r
+  }\r
+\r
+  //\r
+  //  Install unload handler...\r
+  //\r
+  if (_gDriverUnloadImageCount != 0) {\r
+    Status = gBS->HandleProtocol (\r
+                    ImageHandle,\r
+                    &gEfiLoadedImageProtocolGuid,\r
+                    (VOID **)&LoadedImage\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+    LoadedImage->Unload = _DriverUnloadHandler;\r
+  }\r
+\r
+  //\r
+  // Call constructor for all libraries\r
+  //\r
+  ProcessLibraryConstructorList (ImageHandle, SystemTable);\r
+\r
+  //\r
+  // Call the driver entry point\r
+  //\r
+  Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);\r
+\r
+  //\r
+  // If all of the drivers returned errors, then invoke all of the library destructors\r
+  //\r
+  if (EFI_ERROR (Status)) {\r
+    ProcessLibraryDestructorList (ImageHandle, SystemTable);\r
+  }\r
+\r
+  //\r
+  // Return the cummalative return status code from all of the driver entry points\r
+  //\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Enrty point wrapper of DXE Driver.\r
+\r
+  @param  ImageHandle ImageHandle of the loaded driver.\r
+  @param  SystemTable Pointer to the EFI System Table.\r
+\r
+  @retval  EFI_SUCCESS One or more of the drivers returned a success code.\r
+  @retval  !EFI_SUCESS The return status from the last driver entry point in the list.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiMain (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  return _ModuleEntryPoint (ImageHandle, SystemTable);\r
+}\r
diff --git a/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf b/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
new file mode 100644 (file)
index 0000000..b28ed5d
--- /dev/null
@@ -0,0 +1,92 @@
+#/** @file\r
+# Component description file for the entry point to a EFIDXE Drivers\r
+#\r
+# Entry point library to a EFI/DXE driver\r
+# Copyright (c) 2007 - 2007, Intel Corporation.\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UefiDriverEntryPoint\r
+  FILE_GUID                      = 331deb15-454b-48d8-9b74-70d01f3f3556\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = UefiDriverEntryPoint|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER UEFI_DRIVER \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  DriverEntryPoint.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg\Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  DebugLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
+#                           that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Protocols]\r
+  gEfiLoadedImageProtocolGuid                   # PROTOCOL ALWAYS_CONSUMED\r
+\r
diff --git a/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.msa b/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.msa
new file mode 100644 (file)
index 0000000..ce63976
--- /dev/null
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>UefiDriverEntryPoint</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>331deb15-454b-48d8-9b74-70d01f3f3556</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for the entry point to a EFIDXE Drivers</Abstract>\r
+    <Description>Entry point library to a EFI/DXE driver</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation.</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UefiDriverEntryPoint</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER UEFI_DRIVER">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>DriverEntryPoint.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiLoadedImageProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdePkg/Library/UefiLib/CommonHeader.h b/MdePkg/Library/UefiLib/CommonHeader.h
new file mode 100644 (file)
index 0000000..9a52f26
--- /dev/null
@@ -0,0 +1,46 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007, Intel Corporation.\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/DriverBinding.h>\r
+#include <Protocol/ComponentName.h>\r
+#include <Protocol/DriverConfiguration.h>\r
+#include <Protocol/DriverDiagnostics.h>\r
+\r
+\r
+#include <Guid/EventGroup.h>\r
+#include <Guid/EventLegacyBios.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/PrintLib.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/UefiLib/Console.c b/MdePkg/Library/UefiLib/Console.c
new file mode 100644 (file)
index 0000000..b82af08
--- /dev/null
@@ -0,0 +1,287 @@
+/** @file\r
+  Mde UEFI library functions.\r
+\r
+  Copyright (c) 2006, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials                          \r
+  are licensed and made available under the terms and conditions of the BSD License         \r
+  which accompanies this distribution.  The full text of the license may be found at        \r
+  http://opensource.org/licenses/bsd-license.php                                            \r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+  Module Name:  Console.c\r
+\r
+**/\r
+\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+typedef struct {\r
+  CHAR16  WChar;\r
+  UINT32  Width;\r
+} UNICODE_WIDTH_ENTRY;\r
+\r
+UNICODE_WIDTH_ENTRY mUnicodeWidthTable[] = {\r
+  //\r
+  // General script area\r
+  //\r
+  {(CHAR16)0x1FFF,  1},\r
+  /*\r
+   * Merge the blocks and replace them with the above entry as they fall to \r
+   * the same category and they are all narrow glyph. This will reduce search\r
+   * time and table size. The merge will omit the reserved code.\r
+   *\r
+   * Remove the above item if below is un-commented.\r
+   *\r
+  {(CHAR16)0x007F,  1},       // C0 controls and basic Latin. 0x0000-0x007F\r
+  {(CHAR16)0x00FF,  1},       // C1 controls and Latin-1 support. 0x0080-0x00FF\r
+  {(CHAR16)0x017F,  1},       // Latin extended-A. 0x0100-0x017F\r
+  {(CHAR16)0x024F,  1},       // Latin extended-B. 0x0180-0x024F\r
+  {(CHAR16)0x02AF,  1},       // IPA extensions. 0x0250-0x02AF\r
+  {(CHAR16)0x02FF,  1},       // Spacing modifier letters. 0x02B0-0x02FF\r
+  {(CHAR16)0x036F,  1},       // Combining diacritical marks. 0x0300-0x036F\r
+  {(CHAR16)0x03FF,  1},       // Greek. 0x0370-0x03FF\r
+  {(CHAR16)0x04FF,  1},       // Cyrillic. 0x0400-0x04FF\r
+  {(CHAR16)0x052F,  0},       // Unassigned. As Armenian in ver3.0. 0x0500-0x052F\r
+  {(CHAR16)0x058F,  1},       // Armenian. 0x0530-0x058F\r
+  {(CHAR16)0x05FF,  1},       // Hebrew. 0x0590-0x05FF\r
+  {(CHAR16)0x06FF,  1},       // Arabic. 0x0600-0x06FF\r
+  {(CHAR16)0x08FF,  0},       // Unassigned. 0x0700-0x08FF\r
+  {(CHAR16)0x097F,  1},       // Devanagari. 0x0900-0x097F\r
+  {(CHAR16)0x09FF,  1},       // Bengali. 0x0980-0x09FF\r
+  {(CHAR16)0x0A7F,  1},       // Gurmukhi. 0x0A00-0x0A7F\r
+  {(CHAR16)0x0AFF,  1},       // Gujarati. 0x0A80-0x0AFF\r
+  {(CHAR16)0x0B7F,  1},       // Oriya. 0x0B00-0x0B7F\r
+  {(CHAR16)0x0BFF,  1},       // Tamil. (See page 7-92). 0x0B80-0x0BFF\r
+  {(CHAR16)0x0C7F,  1},       // Telugu. 0x0C00-0x0C7F\r
+  {(CHAR16)0x0CFF,  1},       // Kannada. (See page 7-100). 0x0C80-0x0CFF\r
+  {(CHAR16)0x0D7F,  1},       // Malayalam (See page 7-104). 0x0D00-0x0D7F\r
+  {(CHAR16)0x0DFF,  0},       // Unassigned. 0x0D80-0x0DFF\r
+  {(CHAR16)0x0E7F,  1},       // Thai. 0x0E00-0x0E7F\r
+  {(CHAR16)0x0EFF,  1},       // Lao. 0x0E80-0x0EFF\r
+  {(CHAR16)0x0FBF,  1},       // Tibetan. 0x0F00-0x0FBF\r
+  {(CHAR16)0x109F,  0},       // Unassigned. 0x0FC0-0x109F\r
+  {(CHAR16)0x10FF,  1},       // Georgian. 0x10A0-0x10FF\r
+  {(CHAR16)0x11FF,  1},       // Hangul Jamo. 0x1100-0x11FF\r
+  {(CHAR16)0x1DFF,  0},       // Unassigned. 0x1200-0x1DFF\r
+  {(CHAR16)0x1EFF,  1},       // Latin extended additional. 0x1E00-0x1EFF\r
+  {(CHAR16)0x1FFF,  1},       // Greek extended. 0x1F00-0x1FFF\r
+  *\r
+  */\r
+\r
+  //\r
+  // Symbol area\r
+  //\r
+  {(CHAR16)0x2FFF,  1},\r
+  /*\r
+   * Merge the blocks and replace them with the above entry as they fall to \r
+   * the same category and they are all narrow glyph. This will reduce search\r
+   * time and table size. The merge will omit the reserved code.\r
+   *\r
+   * Remove the above item if below is un-commented.\r
+   *\r
+  {(CHAR16)0x206F,  1},       // General punctuation. (See page7-154). 0x200-0x206F\r
+  {(CHAR16)0x209F,  1},       // Superscripts and subscripts. 0x2070-0x209F\r
+  {(CHAR16)0x20CF,  1},       // Currency symbols. 0x20A0-0x20CF\r
+  {(CHAR16)0x20FF,  1},       // Combining diacritical marks for symbols. 0x20D0-0x20FF\r
+  {(CHAR16)0x214F,  1},       // Letterlike sympbols. 0x2100-0x214F\r
+  {(CHAR16)0x218F,  1},       // Number forms. 0x2150-0x218F\r
+  {(CHAR16)0x21FF,  1},       // Arrows. 0x2190-0x21FF\r
+  {(CHAR16)0x22FF,  1},       // Mathematical operators. 0x2200-0x22FF\r
+  {(CHAR16)0x23FF,  1},       // Miscellaneous technical. 0x2300-0x23FF\r
+  {(CHAR16)0x243F,  1},       // Control pictures. 0x2400-0x243F\r
+  {(CHAR16)0x245F,  1},       // Optical character recognition. 0x2440-0x245F\r
+  {(CHAR16)0x24FF,  1},       // Enclosed alphanumerics. 0x2460-0x24FF\r
+  {(CHAR16)0x257F,  1},       // Box drawing. 0x2500-0x257F\r
+  {(CHAR16)0x259F,  1},       // Block elements. 0x2580-0x259F\r
+  {(CHAR16)0x25FF,  1},       // Geometric shapes. 0x25A0-0x25FF\r
+  {(CHAR16)0x26FF,  1},       // Miscellaneous symbols. 0x2600-0x26FF\r
+  {(CHAR16)0x27BF,  1},       // Dingbats. 0x2700-0x27BF\r
+  {(CHAR16)0x2FFF,  0},       // Reserved. 0x27C0-0x2FFF\r
+  *\r
+  */\r
+\r
+  //\r
+  // CJK phonetics and symbol area\r
+  //\r
+  {(CHAR16)0x33FF,  2},\r
+  /*\r
+   * Merge the blocks and replace them with the above entry as they fall to \r
+   * the same category and they are all wide glyph. This will reduce search\r
+   * time and table size. The merge will omit the reserved code.\r
+   *\r
+   * Remove the above item if below is un-commented.\r
+   *\r
+  {(CHAR16)0x303F,  2},       // CJK symbols and punctuation. 0x3000-0x303F\r
+  {(CHAR16)0x309F,  2},       // Hiragana. 0x3040-0x309F\r
+  {(CHAR16)0x30FF,  2},       // Katakana. 0x30A0-0x30FF\r
+  {(CHAR16)0x312F,  2},       // Bopomofo. 0x3100-0x312F\r
+  {(CHAR16)0x318F,  2},       // Hangul compatibility jamo. 0x3130-0x318F\r
+  {(CHAR16)0x319F,  2},       // Kanbun. 0x3190-0x319F\r
+  {(CHAR16)0x31FF,  0},       // Reserved. As Bopomofo extended in ver3.0. 0x31A0-0x31FF\r
+  {(CHAR16)0x32FF,  2},       // Enclosed CJK letters and months. 0x3200-0x32FF\r
+  {(CHAR16)0x33FF,  2},       // CJK compatibility. 0x3300-0x33FF\r
+  *\r
+  */\r
+\r
+  //\r
+  // CJK ideograph area\r
+  //\r
+  {(CHAR16)0x9FFF,  2},\r
+  /*\r
+   * Merge the blocks and replace them with the above entry as they fall to \r
+   * the same category and they are all wide glyph. This will reduce search\r
+   * time and table size. The merge will omit the reserved code.\r
+   *\r
+   * Remove the above item if below is un-commented.\r
+   *\r
+  {(CHAR16)0x4DFF,  0},       // Reserved. 0x3400-0x4DBF as CJK unified ideographs \r
+                      // extension A in ver3.0. 0x3400-0x4DFF\r
+  {(CHAR16)0x9FFF,  2},       // CJK unified ideographs. 0x4E00-0x9FFF\r
+  *\r
+  */\r
+\r
+  //\r
+  // Reserved\r
+  //\r
+  {(CHAR16)0xABFF,  0},       // Reserved. 0xA000-0xA490 as Yi syllables. 0xA490-0xA4D0\r
+  // as Yi radicals in ver3.0. 0xA000-0xABFF\r
+  //\r
+  // Hangul syllables\r
+  //\r
+  {(CHAR16)0xD7FF,  2},\r
+  /*\r
+   * Merge the blocks and replace them with the above entry as they fall to \r
+   * the same category and they are all wide glyph. This will reduce search\r
+   * time and table size. The merge will omit the reserved code.\r
+   *\r
+   * Remove the above item if below is un-commented.\r
+   *\r
+  {(CHAR16)0xD7A3,  2},       // Hangul syllables. 0xAC00-0xD7A3\r
+  {(CHAR16)0xD7FF,  0},       // Reserved. 0xD7A3-0xD7FF\r
+  *\r
+  */\r
+\r
+  //\r
+  // Surrogates area\r
+  //\r
+  {(CHAR16)0xDFFF,  0},       // Surrogates, not used now. 0xD800-0xDFFF\r
+\r
+  //\r
+  // Private use area\r
+  //\r
+  {(CHAR16)0xF8FF,  0},       // Private use area. 0xE000-0xF8FF\r
+\r
+  //\r
+  // Compatibility area and specials\r
+  //\r
+  {(CHAR16)0xFAFF,  2},       // CJK compatibility ideographs. 0xF900-0xFAFF\r
+  {(CHAR16)0xFB4F,  1},       // Alphabetic presentation forms. 0xFB00-0xFB4F\r
+  {(CHAR16)0xFDFF,  1},       // Arabic presentation forms-A. 0xFB50-0xFDFF\r
+  {(CHAR16)0xFE1F,  0},       // Reserved. As variation selectors in ver3.0. 0xFE00-0xFE1F\r
+  {(CHAR16)0xFE2F,  1},       // Combining half marks. 0xFE20-0xFE2F\r
+  {(CHAR16)0xFE4F,  2},       // CJK compatibility forms. 0xFE30-0xFE4F\r
+  {(CHAR16)0xFE6F,  1},       // Small Form Variants. 0xFE50-0xFE6F\r
+  {(CHAR16)0xFEFF,  1},       // Arabic presentation forms-B. 0xFE70-0xFEFF\r
+  {(CHAR16)0xFFEF,  1},       // Half width and full width forms. 0xFF00-0xFFEF\r
+  {(CHAR16)0xFFFF,  0},       // Speicials. 0xFFF0-0xFFFF\r
+};\r
+\r
+/**\r
+  This function computes and returns the width of the Unicode character \r
+  specified by UnicodeChar.\r
+\r
+  @param  UnicodeChar   A Unicode character.\r
+\r
+  @retval 0             The width if UnicodeChar could not be determined.\r
+  @retval 1             UnicodeChar is a narrow glyph.\r
+  @retval 2             UnicodeChar is a wide glyph.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+GetGlyphWidth (\r
+  IN CHAR16  UnicodeChar\r
+  )\r
+{\r
+  UINTN               Index;\r
+  UINTN               Low;\r
+  UINTN               High;\r
+  UNICODE_WIDTH_ENTRY *Item;\r
+\r
+  Item  = NULL;\r
+  Low   = 0;\r
+  High  = (sizeof (mUnicodeWidthTable)) / (sizeof (UNICODE_WIDTH_ENTRY)) - 1;\r
+  while (Low <= High) {\r
+    Index = (Low + High) >> 1;\r
+    Item  = &(mUnicodeWidthTable[Index]);\r
+    if (Index == 0) {\r
+      if (UnicodeChar <= Item->WChar) {\r
+        break;\r
+      }\r
+\r
+      return 0;\r
+    }\r
+\r
+    if (UnicodeChar > Item->WChar) {\r
+      Low = Index + 1;\r
+    } else if (UnicodeChar <= mUnicodeWidthTable[Index - 1].WChar) {\r
+      High = Index - 1;\r
+    } else {\r
+      //\r
+      // Index - 1 < UnicodeChar <= Index. Found\r
+      //\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (Low <= High) {\r
+    return Item->Width;\r
+  }\r
+\r
+  return 0;\r
+}\r
+\r
+/**\r
+  This function computes and returns the display length of\r
+  the Null-terminated Unicode string specified by String.\r
+  If String is NULL, then 0 is returned.\r
+  If any of the widths of the Unicode characters in String\r
+  can not be determined, then 0 is returned.\r
+\r
+  @param  String      A pointer to a Null-terminated Unicode string.\r
+\r
+  @return The display length of the Null-terminated Unicode string specified by String.\r
+  \r
+**/\r
+UINTN\r
+EFIAPI\r
+UnicodeStringDisplayLength (\r
+  IN CONST CHAR16  *String\r
+  )\r
+{\r
+  UINTN      Length;\r
+  UINTN      Width;\r
+\r
+  if (String == NULL) {\r
+    return 0;\r
+  }\r
+\r
+  Length = 0;\r
+  while (*String != 0) {\r
+    Width = GetGlyphWidth (*String);\r
+    if (Width == 0) {\r
+      return 0;\r
+    }\r
+\r
+    Length += Width;\r
+    String++;\r
+  }\r
+\r
+  return Length;\r
+}\r
diff --git a/MdePkg/Library/UefiLib/UefiLib.c b/MdePkg/Library/UefiLib/UefiLib.c
new file mode 100644 (file)
index 0000000..5fe7999
--- /dev/null
@@ -0,0 +1,886 @@
+/** @file\r
+  Mde UEFI library functions.\r
+\r
+  Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Module Name:  UefiLib.c\r
+\r
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+/**\r
+  Compare whether two names of languages are identical.\r
+\r
+  @param  Language1 Name of language 1.\r
+  @param  Language2 Name of language 2.\r
+\r
+  @retval TRUE      Language 1 and language 2 are the same.\r
+  @retval FALSE     Language 1 and language 2 are not the same.\r
+\r
+**/\r
+STATIC\r
+BOOLEAN\r
+CompareIso639LanguageCode (\r
+  IN CONST CHAR8  *Language1,\r
+  IN CONST CHAR8  *Language2\r
+  )\r
+{\r
+  UINT32  Name1;\r
+  UINT32  Name2;\r
+\r
+  Name1 = ReadUnaligned24 ((CONST UINT32 *) Language1);\r
+  Name2 = ReadUnaligned24 ((CONST UINT32 *) Language2);\r
+\r
+  return (BOOLEAN) (Name1 == Name2);\r
+}\r
+\r
+/**\r
+  This function searches the list of configuration tables stored in the EFI System\r
+  Table for a table with a GUID that matches TableGuid.  If a match is found,\r
+  then a pointer to the configuration table is returned in Table, and EFI_SUCCESS\r
+  is returned.  If a matching GUID is not found, then EFI_NOT_FOUND is returned.\r
+\r
+  @param  TableGuid       Pointer to table's GUID type..\r
+  @param  Table           Pointer to the table associated with TableGuid in the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS     A configuration table matching TableGuid was found.\r
+  @retval EFI_NOT_FOUND   A configuration table matching TableGuid could not be found.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiGetSystemConfigurationTable (\r
+  IN  EFI_GUID  *TableGuid,\r
+  OUT VOID      **Table\r
+  )\r
+{\r
+  EFI_SYSTEM_TABLE  *SystemTable;\r
+  UINTN             Index;\r
+\r
+  ASSERT (TableGuid != NULL);\r
+  ASSERT (Table != NULL);\r
+\r
+  SystemTable = gST;\r
+  *Table = NULL;\r
+  for (Index = 0; Index < SystemTable->NumberOfTableEntries; Index++) {\r
+    if (CompareGuid (TableGuid, &(SystemTable->ConfigurationTable[Index].VendorGuid))) {\r
+      *Table = SystemTable->ConfigurationTable[Index].VendorTable;\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+/**\r
+  This function causes the notification function to be executed for every protocol\r
+  of type ProtocolGuid instance that exists in the system when this function is\r
+  invoked.  In addition, every time a protocol of type ProtocolGuid instance is\r
+  installed or reinstalled, the notification function is also executed.\r
+\r
+  @param  ProtocolGuid    Supplies GUID of the protocol upon whose installation the event is fired.\r
+  @param  NotifyTpl       Supplies the task priority level of the event notifications.\r
+  @param  NotifyFunction  Supplies the function to notify when the event is signaled.\r
+  @param  NotifyContext   The context parameter to pass to NotifyFunction.\r
+  @param  Registration    A pointer to a memory location to receive the registration value.\r
+\r
+  @return The notification event that was created.\r
+\r
+**/\r
+EFI_EVENT\r
+EFIAPI\r
+EfiCreateProtocolNotifyEvent(\r
+  IN  EFI_GUID          *ProtocolGuid,\r
+  IN  EFI_TPL           NotifyTpl,\r
+  IN  EFI_EVENT_NOTIFY  NotifyFunction,\r
+  IN  VOID              *NotifyContext,  OPTIONAL\r
+  OUT VOID              **Registration\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_EVENT   Event;\r
+\r
+  //\r
+  // Create the event\r
+  //\r
+\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  NotifyTpl,\r
+                  NotifyFunction,\r
+                  NotifyContext,\r
+                  &Event\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Register for protocol notifactions on this event\r
+  //\r
+\r
+  Status = gBS->RegisterProtocolNotify (\r
+                  ProtocolGuid,\r
+                  Event,\r
+                  Registration\r
+                  );\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Kick the event so we will perform an initial pass of\r
+  // current installed drivers\r
+  //\r
+\r
+  gBS->SignalEvent (Event);\r
+  return Event;\r
+}\r
+\r
+/**\r
+  This function creates an event using NotifyTpl, NoifyFunction, and NotifyContext.\r
+  This event is signaled with EfiNamedEventSignal().  This provide the ability for\r
+  one or more listeners on the same event named by the GUID specified by Name.\r
+\r
+  @param  Name                  Supplies GUID name of the event.\r
+  @param  NotifyTpl             Supplies the task priority level of the event notifications.\r
+  @param  NotifyFunction        Supplies the function to notify when the event is signaled.\r
+  @param  NotifyContext         The context parameter to pass to NotifyFunction.\r
+  @param  Registration          A pointer to a memory location to receive the registration value.\r
+\r
+  @retval EFI_SUCCESS           A named event was created.\r
+  @retval EFI_OUT_OF_RESOURCES  There are not enough resource to create the named event.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiNamedEventListen (\r
+  IN CONST EFI_GUID    *Name,\r
+  IN EFI_TPL           NotifyTpl,\r
+  IN EFI_EVENT_NOTIFY  NotifyFunction,\r
+  IN CONST VOID        *NotifyContext,  OPTIONAL\r
+  OUT VOID             *Registration OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_EVENT   Event;\r
+  VOID        *RegistrationLocal;\r
+\r
+  //\r
+  // Create event\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  NotifyTpl,\r
+                  NotifyFunction,\r
+                  (VOID *) NotifyContext,\r
+                  &Event\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // The Registration is not optional to RegisterProtocolNotify().\r
+  // To make it optional to EfiNamedEventListen(), may need to substitute with a local.\r
+  //\r
+  if (Registration != NULL) {\r
+    RegistrationLocal = Registration;\r
+  } else {\r
+    RegistrationLocal = &RegistrationLocal;\r
+  }\r
+\r
+  //\r
+  // Register for an installation of protocol interface\r
+  //\r
+\r
+  Status = gBS->RegisterProtocolNotify (\r
+                  (EFI_GUID *) Name,\r
+                  Event,\r
+                  RegistrationLocal\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This function signals the named event specified by Name.  The named event must\r
+  have been created with EfiNamedEventListen().\r
+\r
+  @param  Name                  Supplies GUID name of the event.\r
+\r
+  @retval EFI_SUCCESS           A named event was signaled.\r
+  @retval EFI_OUT_OF_RESOURCES  There are not enough resource to signal the named event.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiNamedEventSignal (\r
+  IN CONST EFI_GUID  *Name\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_HANDLE  Handle;\r
+\r
+  Handle = NULL;\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &Handle,\r
+                  (EFI_GUID *) Name,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = gBS->UninstallProtocolInterface (\r
+                  Handle,\r
+                  (EFI_GUID *) Name,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Returns the current TPL.\r
+\r
+  This function returns the current TPL.  There is no EFI service to directly\r
+  retrieve the current TPL. Instead, the RaiseTPL() function is used to raise\r
+  the TPL to TPL_HIGH_LEVEL.  This will return the current TPL.  The TPL level\r
+  can then immediately be restored back to the current TPL level with a call\r
+  to RestoreTPL().\r
+\r
+  @param  VOID\r
+\r
+  @retvale EFI_TPL              The current TPL.\r
+\r
+**/\r
+EFI_TPL\r
+EFIAPI\r
+EfiGetCurrentTpl (\r
+  VOID\r
+  )\r
+{\r
+  EFI_TPL Tpl;\r
+\r
+  Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+  gBS->RestoreTPL (Tpl);\r
+\r
+  return Tpl;\r
+}\r
+\r
+\r
+/**\r
+  This function initializes a basic mutual exclusion lock to the released state\r
+  and returns the lock.  Each lock provides mutual exclusion access at its task\r
+  priority level.  Since there is no preemption or multiprocessor support in EFI,\r
+  acquiring the lock only consists of raising to the locks TPL.\r
+\r
+  @param  Lock       A pointer to the lock data structure to initialize.\r
+  @param  Priority   EFI TPL associated with the lock.\r
+\r
+  @return The lock.\r
+\r
+**/\r
+EFI_LOCK *\r
+EFIAPI\r
+EfiInitializeLock (\r
+  IN OUT EFI_LOCK  *Lock,\r
+  IN EFI_TPL        Priority\r
+  )\r
+{\r
+  ASSERT (Lock != NULL);\r
+  ASSERT (Priority <= TPL_HIGH_LEVEL);\r
+\r
+  Lock->Tpl       = Priority;\r
+  Lock->OwnerTpl  = TPL_APPLICATION;\r
+  Lock->Lock      = EfiLockReleased ;\r
+  return Lock;\r
+}\r
+\r
+/**\r
+  This function raises the system's current task priority level to the task\r
+  priority level of the mutual exclusion lock.  Then, it places the lock in the\r
+  acquired state.\r
+\r
+  @param  Priority  The task priority level of the lock.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+EfiAcquireLock (\r
+  IN EFI_LOCK  *Lock\r
+  )\r
+{\r
+  ASSERT (Lock != NULL);\r
+  ASSERT (Lock->Lock == EfiLockReleased);\r
+\r
+  Lock->OwnerTpl = gBS->RaiseTPL (Lock->Tpl);\r
+  Lock->Lock     = EfiLockAcquired;\r
+}\r
+\r
+/**\r
+  This function raises the system's current task priority level to the task\r
+  priority level of the mutual exclusion lock.  Then, it attempts to place the\r
+  lock in the acquired state.\r
+\r
+  @param  Lock              A pointer to the lock to acquire.\r
+\r
+  @retval EFI_SUCCESS       The lock was acquired.\r
+  @retval EFI_ACCESS_DENIED The lock could not be acquired because it is already owned.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiAcquireLockOrFail (\r
+  IN EFI_LOCK  *Lock\r
+  )\r
+{\r
+\r
+  ASSERT (Lock != NULL);\r
+  ASSERT (Lock->Lock != EfiLockUninitialized);\r
+\r
+  if (Lock->Lock == EfiLockAcquired) {\r
+    //\r
+    // Lock is already owned, so bail out\r
+    //\r
+    return EFI_ACCESS_DENIED;\r
+  }\r
+\r
+  Lock->OwnerTpl = gBS->RaiseTPL (Lock->Tpl);\r
+\r
+  Lock->Lock = EfiLockAcquired;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This function transitions a mutual exclusion lock from the acquired state to\r
+  the released state, and restores the system's task priority level to its\r
+  previous level.\r
+\r
+  @param  Lock  A pointer to the lock to release.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+EfiReleaseLock (\r
+  IN EFI_LOCK  *Lock\r
+  )\r
+{\r
+  EFI_TPL Tpl;\r
+\r
+  ASSERT (Lock != NULL);\r
+  ASSERT (Lock->Lock == EfiLockAcquired);\r
+\r
+  Tpl = Lock->OwnerTpl;\r
+\r
+  Lock->Lock = EfiLockReleased;\r
+\r
+  gBS->RestoreTPL (Tpl);\r
+}\r
+\r
+/**\r
+  Tests whether a controller handle is being managed by a specific driver.\r
+\r
+  This function tests whether the driver specified by DriverBindingHandle is\r
+  currently managing the controller specified by ControllerHandle.  This test\r
+  is performed by evaluating if the the protocol specified by ProtocolGuid is\r
+  present on ControllerHandle and is was opened by DriverBindingHandle with an\r
+  attribute of EFI_OPEN_PROTOCOL_BY_DRIVER.\r
+  If ProtocolGuid is NULL, then ASSERT().\r
+\r
+  @param  ControllerHandle     A handle for a controller to test.\r
+  @param  DriverBindingHandle  Specifies the driver binding handle for the\r
+                               driver.\r
+  @param  ProtocolGuid         Specifies the protocol that the driver specified\r
+                               by DriverBindingHandle opens in its Start()\r
+                               function.\r
+\r
+  @retval EFI_SUCCESS          ControllerHandle is managed by the driver\r
+                               specifed by DriverBindingHandle.\r
+  @retval EFI_UNSUPPORTED      ControllerHandle is not managed by the driver\r
+                               specifed by DriverBindingHandle.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiTestManagedDevice (\r
+  IN CONST EFI_HANDLE       ControllerHandle,\r
+  IN CONST EFI_HANDLE       DriverBindingHandle,\r
+  IN CONST EFI_GUID         *ProtocolGuid\r
+  )\r
+{\r
+  EFI_STATUS     Status;\r
+  VOID           *ManagedInterface;\r
+\r
+  ASSERT (ProtocolGuid != NULL);\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  (EFI_GUID *) ProtocolGuid,\r
+                  &ManagedInterface,\r
+                  DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+           ControllerHandle,\r
+           (EFI_GUID *) ProtocolGuid,\r
+           DriverBindingHandle,\r
+           ControllerHandle\r
+           );\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Tests whether a child handle is a child device of the controller.\r
+\r
+  This function tests whether ChildHandle is one of the children of\r
+  ControllerHandle.  This test is performed by checking to see if the protocol\r
+  specified by ProtocolGuid is present on ControllerHandle and opened by\r
+  ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
+  If ProtocolGuid is NULL, then ASSERT().\r
+\r
+  @param  ControllerHandle     A handle for a (parent) controller to test.\r
+  @param  ChildHandle          A child handle to test.\r
+  @param  ConsumsedGuid        Supplies the protocol that the child controller\r
+                               opens on its parent controller.\r
+\r
+  @retval EFI_SUCCESS          ChildHandle is a child of the ControllerHandle.\r
+  @retval EFI_UNSUPPORTED      ChildHandle is not a child of the\r
+                               ControllerHandle.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiTestChildHandle (\r
+  IN CONST EFI_HANDLE       ControllerHandle,\r
+  IN CONST EFI_HANDLE       ChildHandle,\r
+  IN CONST EFI_GUID         *ProtocolGuid\r
+  )\r
+{\r
+  EFI_STATUS                            Status;\r
+  EFI_OPEN_PROTOCOL_INFORMATION_ENTRY   *OpenInfoBuffer;\r
+  UINTN                                 EntryCount;\r
+  UINTN                                 Index;\r
+\r
+  ASSERT (ProtocolGuid != NULL);\r
+\r
+  //\r
+  // Retrieve the list of agents that are consuming the specific protocol\r
+  // on ControllerHandle.\r
+  //\r
+  Status = gBS->OpenProtocolInformation (\r
+                  ControllerHandle,\r
+                  (EFI_GUID *) ProtocolGuid,\r
+                  &OpenInfoBuffer,\r
+                  &EntryCount\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Inspect if ChildHandle is one of the agents.\r
+  //\r
+  Status = EFI_UNSUPPORTED;\r
+  for (Index = 0; Index < EntryCount; Index++) {\r
+    if ((OpenInfoBuffer[Index].ControllerHandle == ChildHandle) &&\r
+        (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
+      Status = EFI_SUCCESS;\r
+      break;\r
+    }\r
+  }\r
+\r
+  FreePool (OpenInfoBuffer);\r
+  return Status;\r
+}\r
+\r
+/**\r
+  This function looks up a Unicode string in UnicodeStringTable.  If Language is\r
+  a member of SupportedLanguages and a Unicode string is found in UnicodeStringTable\r
+  that matches the language code specified by Language, then it is returned in\r
+  UnicodeString.\r
+\r
+  @param  Language                A pointer to the ISO 639-2 language code for the\r
+                                  Unicode string to look up and return.\r
+  @param  SupportedLanguages      A pointer to the set of ISO 639-2 language codes\r
+                                  that the Unicode string table supports.  Language\r
+                                  must be a member of this set.\r
+  @param  UnicodeStringTable      A pointer to the table of Unicode strings.\r
+  @param  UnicodeString           A pointer to the Unicode string from UnicodeStringTable\r
+                                  that matches the language specified by Language.\r
+\r
+  @retval  EFI_SUCCESS            The Unicode string that matches the language\r
+                                  specified by Language was found\r
+                                  in the table of Unicoide strings UnicodeStringTable,\r
+                                  and it was returned in UnicodeString.\r
+  @retval  EFI_INVALID_PARAMETER  Language is NULL.\r
+  @retval  EFI_INVALID_PARAMETER  UnicodeString is NULL.\r
+  @retval  EFI_UNSUPPORTED        SupportedLanguages is NULL.\r
+  @retval  EFI_UNSUPPORTED        UnicodeStringTable is NULL.\r
+  @retval  EFI_UNSUPPORTED        The language specified by Language is not a\r
+                                  member of SupportedLanguages.\r
+  @retval  EFI_UNSUPPORTED        The language specified by Language is not\r
+                                  supported by UnicodeStringTable.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LookupUnicodeString (\r
+  IN CONST CHAR8                     *Language,\r
+  IN CONST CHAR8                     *SupportedLanguages,\r
+  IN CONST EFI_UNICODE_STRING_TABLE  *UnicodeStringTable,\r
+  OUT CHAR16                         **UnicodeString\r
+  )\r
+{\r
+  //\r
+  // Make sure the parameters are valid\r
+  //\r
+  if (Language == NULL || UnicodeString == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // If there are no supported languages, or the Unicode String Table is empty, then the\r
+  // Unicode String specified by Language is not supported by this Unicode String Table\r
+  //\r
+  if (SupportedLanguages == NULL || UnicodeStringTable == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Make sure Language is in the set of Supported Languages\r
+  //\r
+  while (*SupportedLanguages != 0) {\r
+    if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r
+\r
+      //\r
+      // Search the Unicode String Table for the matching Language specifier\r
+      //\r
+      while (UnicodeStringTable->Language != NULL) {\r
+        if (CompareIso639LanguageCode (Language, UnicodeStringTable->Language)) {\r
+\r
+          //\r
+          // A matching string was found, so return it\r
+          //\r
+          *UnicodeString = UnicodeStringTable->UnicodeString;\r
+          return EFI_SUCCESS;\r
+        }\r
+\r
+        UnicodeStringTable++;\r
+      }\r
+\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+\r
+    SupportedLanguages += 3;\r
+  }\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  This function adds a Unicode string to UnicodeStringTable.\r
+  If Language is a member of SupportedLanguages then UnicodeString is added to\r
+  UnicodeStringTable.  New buffers are allocated for both Language and\r
+  UnicodeString.  The contents of Language and UnicodeString are copied into\r
+  these new buffers.  These buffers are automatically freed when\r
+  FreeUnicodeStringTable() is called.\r
+\r
+  @param  Language                A pointer to the ISO 639-2 language code for the Unicode\r
+                                  string to add.\r
+  @param  SupportedLanguages      A pointer to the set of ISO 639-2 language codes\r
+                                  that the Unicode string table supports.\r
+                                  Language must be a member of this set.\r
+  @param  UnicodeStringTable      A pointer to the table of Unicode strings.\r
+  @param  UnicodeString           A pointer to the Unicode string to add.\r
+\r
+  @retval EFI_SUCCESS             The Unicode string that matches the language\r
+                                  specified by Language was found in the table of\r
+                                  Unicode strings UnicodeStringTable, and it was\r
+                                  returned in UnicodeString.\r
+  @retval EFI_INVALID_PARAMETER   Language is NULL.\r
+  @retval EFI_INVALID_PARAMETER   UnicodeString is NULL.\r
+  @retval EFI_INVALID_PARAMETER   UnicodeString is an empty string.\r
+  @retval EFI_UNSUPPORTED         SupportedLanguages is NULL.\r
+  @retval EFI_ALREADY_STARTED     A Unicode string with language Language is\r
+                                  already present in UnicodeStringTable.\r
+  @retval EFI_OUT_OF_RESOURCES    There is not enough memory to add another\r
+                                  Unicode string to UnicodeStringTable.\r
+  @retval EFI_UNSUPPORTED         The language specified by Language is not a\r
+                                  member of SupportedLanguages.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AddUnicodeString (\r
+  IN CONST CHAR8               *Language,\r
+  IN CONST CHAR8               *SupportedLanguages,\r
+  IN EFI_UNICODE_STRING_TABLE  **UnicodeStringTable,\r
+  IN CONST CHAR16              *UnicodeString\r
+  )\r
+{\r
+  UINTN                     NumberOfEntries;\r
+  EFI_UNICODE_STRING_TABLE  *OldUnicodeStringTable;\r
+  EFI_UNICODE_STRING_TABLE  *NewUnicodeStringTable;\r
+  UINTN                     UnicodeStringLength;\r
+\r
+  //\r
+  // Make sure the parameter are valid\r
+  //\r
+  if (Language == NULL || UnicodeString == NULL || UnicodeStringTable == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // If there are no supported languages, then a Unicode String can not be added\r
+  //\r
+  if (SupportedLanguages == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // If the Unicode String is empty, then a Unicode String can not be added\r
+  //\r
+  if (UnicodeString[0] == 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Make sure Language is a member of SupportedLanguages\r
+  //\r
+  while (*SupportedLanguages != 0) {\r
+    if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r
+\r
+      //\r
+      // Determine the size of the Unicode String Table by looking for a NULL Language entry\r
+      //\r
+      NumberOfEntries = 0;\r
+      if (*UnicodeStringTable != NULL) {\r
+        OldUnicodeStringTable = *UnicodeStringTable;\r
+        while (OldUnicodeStringTable->Language != NULL) {\r
+          if (CompareIso639LanguageCode (Language, OldUnicodeStringTable->Language)) {\r
+            return EFI_ALREADY_STARTED;\r
+          }\r
+\r
+          OldUnicodeStringTable++;\r
+          NumberOfEntries++;\r
+        }\r
+      }\r
+\r
+      //\r
+      // Allocate space for a new Unicode String Table.  It must hold the current number of\r
+      // entries, plus 1 entry for the new Unicode String, plus 1 entry for the end of table\r
+      // marker\r
+      //\r
+      NewUnicodeStringTable = AllocatePool ((NumberOfEntries + 2) * sizeof (EFI_UNICODE_STRING_TABLE));\r
+      if (NewUnicodeStringTable == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+\r
+      //\r
+      // If the current Unicode String Table contains any entries, then copy them to the\r
+      // newly allocated Unicode String Table.\r
+      //\r
+      if (*UnicodeStringTable != NULL) {\r
+        CopyMem (\r
+           NewUnicodeStringTable,\r
+           *UnicodeStringTable,\r
+           NumberOfEntries * sizeof (EFI_UNICODE_STRING_TABLE)\r
+           );\r
+      }\r
+\r
+      //\r
+      // Allocate space for a copy of the Language specifier\r
+      //\r
+      NewUnicodeStringTable[NumberOfEntries].Language = AllocateCopyPool (3, Language);\r
+      if (NewUnicodeStringTable[NumberOfEntries].Language == NULL) {\r
+        gBS->FreePool (NewUnicodeStringTable);\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+\r
+      //\r
+      // Compute the length of the Unicode String\r
+      //\r
+      for (UnicodeStringLength = 0; UnicodeString[UnicodeStringLength] != 0; UnicodeStringLength++)\r
+        ;\r
+\r
+      //\r
+      // Allocate space for a copy of the Unicode String\r
+      //\r
+      NewUnicodeStringTable[NumberOfEntries].UnicodeString = AllocateCopyPool (\r
+                                                              (UnicodeStringLength + 1) * sizeof (CHAR16),\r
+                                                              UnicodeString\r
+                                                              );\r
+      if (NewUnicodeStringTable[NumberOfEntries].UnicodeString == NULL) {\r
+        gBS->FreePool (NewUnicodeStringTable[NumberOfEntries].Language);\r
+        gBS->FreePool (NewUnicodeStringTable);\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+\r
+      //\r
+      // Mark the end of the Unicode String Table\r
+      //\r
+      NewUnicodeStringTable[NumberOfEntries + 1].Language       = NULL;\r
+      NewUnicodeStringTable[NumberOfEntries + 1].UnicodeString  = NULL;\r
+\r
+      //\r
+      // Free the old Unicode String Table\r
+      //\r
+      if (*UnicodeStringTable != NULL) {\r
+        gBS->FreePool (*UnicodeStringTable);\r
+      }\r
+\r
+      //\r
+      // Point UnicodeStringTable at the newly allocated Unicode String Table\r
+      //\r
+      *UnicodeStringTable = NewUnicodeStringTable;\r
+\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    SupportedLanguages += 3;\r
+  }\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  This function frees the table of Unicode strings in UnicodeStringTable.\r
+  If UnicodeStringTable is NULL, then EFI_SUCCESS is returned.\r
+  Otherwise, each language code, and each Unicode string in the Unicode string\r
+  table are freed, and EFI_SUCCESS is returned.\r
+\r
+  @param  UnicodeStringTable  A pointer to the table of Unicode strings.\r
+\r
+  @retval EFI_SUCCESS         The Unicode string table was freed.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FreeUnicodeStringTable (\r
+  IN EFI_UNICODE_STRING_TABLE  *UnicodeStringTable\r
+  )\r
+{\r
+  UINTN Index;\r
+\r
+  //\r
+  // If the Unicode String Table is NULL, then it is already freed\r
+  //\r
+  if (UnicodeStringTable == NULL) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Loop through the Unicode String Table until we reach the end of table marker\r
+  //\r
+  for (Index = 0; UnicodeStringTable[Index].Language != NULL; Index++) {\r
+\r
+    //\r
+    // Free the Language string from the Unicode String Table\r
+    //\r
+    gBS->FreePool (UnicodeStringTable[Index].Language);\r
+\r
+    //\r
+    // Free the Unicode String from the Unicode String Table\r
+    //\r
+    if (UnicodeStringTable[Index].UnicodeString != NULL) {\r
+      gBS->FreePool (UnicodeStringTable[Index].UnicodeString);\r
+    }\r
+  }\r
+\r
+  //\r
+  // Free the Unicode String Table itself\r
+  //\r
+  gBS->FreePool (UnicodeStringTable);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Intialize a driver by installing the Driver Binding Protocol onto the\r
+  driver's DriverBindingHandle.  This is typically the same as the driver's\r
+  ImageHandle, but it can be different if the driver produces multiple\r
+  DriverBinding Protocols.  This function also initializes the EFI Driver\r
+  Library that initializes the global variables gST, gBS, gRT.\r
+\r
+  @param  ImageHandle          The image handle of the driver\r
+  @param  SystemTable          The EFI System Table that was passed to the driver's entry point\r
+  @param  DriverBinding        A Driver Binding Protocol instance that this driver is producing\r
+  @param  DriverBindingHandle  The handle that DriverBinding is to be installe onto.  If this\r
+                               parameter is NULL, then a new handle is created.\r
+\r
+  @retval EFI_SUCCESS          DriverBinding is installed onto DriverBindingHandle\r
+  @retval Other                Status from gBS->InstallProtocolInterface()\r
+\r
+**/\r
+EFI_STATUS\r
+EfiLibInstallDriverBinding (\r
+  IN const EFI_HANDLE             ImageHandle,\r
+  IN const EFI_SYSTEM_TABLE       *SystemTable,\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *DriverBinding,\r
+  IN EFI_HANDLE                   DriverBindingHandle\r
+  )\r
+{\r
+  //\r
+  //  bugbug:Need to implement ...\r
+  //\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Intialize a driver by installing the Driver Binding Protocol onto the\r
+  driver's DriverBindingHandle.  This is typically the same as the driver's\r
+  ImageHandle, but it can be different if the driver produces multiple\r
+  DriverBinding Protocols.  This function also initializes the EFI Driver\r
+  Library that initializes the global variables gST, gBS, gRT.\r
+\r
+  @ImageHandle                 The image handle of the driver\r
+  @SystemTable                 The EFI System Table that was passed to the driver's entry point\r
+  @DriverBinding               A Driver Binding Protocol instance that this driver is producing\r
+  @DriverBindingHandle         The handle that DriverBinding is to be installe onto.  If this\r
+                               parameter is NULL, then a new handle is created.\r
+  @ComponentName               A Component Name Protocol instance that this driver is producing\r
+  @DriverConfiguration         A Driver Configuration Protocol instance that this driver is producing\r
+  @DriverDiagnostics           A Driver Diagnostics Protocol instance that this driver is producing\r
+\r
+  @retval EFI_SUCCESS          DriverBinding is installed onto DriverBindingHandle\r
+  @retval Other                Status from gBS->InstallProtocolInterface()\r
+\r
+**/\r
+EFI_STATUS\r
+EfiLibInstallAllDriverProtocols (\r
+  IN const EFI_HANDLE                         ImageHandle,\r
+  IN const EFI_SYSTEM_TABLE                   *SystemTable,\r
+  IN EFI_DRIVER_BINDING_PROTOCOL              *DriverBinding,\r
+  IN EFI_HANDLE                               DriverBindingHandle,\r
+  IN const EFI_COMPONENT_NAME_PROTOCOL        *ComponentName,       OPTIONAL\r
+  IN const EFI_DRIVER_CONFIGURATION_PROTOCOL  *DriverConfiguration, OPTIONAL\r
+  IN const EFI_DRIVER_DIAGNOSTICS_PROTOCOL    *DriverDiagnostics    OPTIONAL\r
+  )\r
+{\r
+  //\r
+  //  bugbug:Need to implement ...\r
+  //\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
diff --git a/MdePkg/Library/UefiLib/UefiLib.inf b/MdePkg/Library/UefiLib/UefiLib.inf
new file mode 100644 (file)
index 0000000..b38f2b7
--- /dev/null
@@ -0,0 +1,122 @@
+#/** @file\r
+# Component description file for the entry point to a EFIDXE Drivers\r
+#\r
+# Library to abstract Framework extensions that conflict with UEFI 2.0 Specification\r
+# \r
+#  Help Port Framework/Tinao code that has conflicts with UEFI 2.0 by hiding the oldconflicts with library functions and supporting implementations of the old \r
+#  (EDK/EFI 1.10) and new (EDK II/UEFI 2.0) way. This module is a DXE driver as it contains DXE enum extensions for EFI event services.\r
+# Copyright (c) 2007, Intel Corporation.\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UefiLib\r
+  FILE_GUID                      = 3a004ba5-efe0-4a61-9f1a-267a46ae5ba9\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = UefiLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  UefiLibPrint.c\r
+  UefiNotTiano.c\r
+  Console.c\r
+  UefiLib.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg\Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  PrintLib\r
+  PcdLib\r
+  MemoryAllocationLib\r
+  DebugLib\r
+  BaseMemoryLib\r
+  BaseLib\r
+  UefiBootServicesTableLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Guid C Name Section - list of Guids that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Guids]\r
+  gEfiFrameworkDevicePathGuid                   # ALWAYS_CONSUMED\r
+  gEfiEventReadyToBootGuid                      # ALWAYS_CONSUMED\r
+  gEfiEventLegacyBootGuid                       # ALWAYS_CONSUMED\r
+\r
+\r
+[Protocols]\r
+  gEfiDriverBindingProtocolGuid                 # ALWAYS_CONSUMED\r
+  gEfiComponentNameProtocolGuid                 # SOMETIMES_CONSUMED\r
+  gEfiDriverConfigurationProtocolGuid           # SOMETIMES_CONSUMED\r
+  gEfiDriverDiagnosticsProtocolGuid             # SOMETIMES_CONSUMED\r
+\r
+################################################################################\r
+#\r
+# Pcd FIXED_AT_BUILD - list of PCDs that this module is coded for.\r
+#\r
+################################################################################\r
+\r
+[PcdsFixedAtBuild.common]\r
+  PcdUefiLibMaxPrintBufferSize|gEfiMdePkgTokenSpaceGuid\r
+  PcdDriverDiagnosticsDisable|gEfiMdePkgTokenSpaceGuid\r
+  PcdComponentNameDisable|gEfiMdePkgTokenSpaceGuid\r
+\r
diff --git a/MdePkg/Library/UefiLib/UefiLib.msa b/MdePkg/Library/UefiLib/UefiLib.msa
new file mode 100644 (file)
index 0000000..19b5703
--- /dev/null
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>UefiLib</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>3a004ba5-efe0-4a61-9f1a-267a46ae5ba9</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for the entry point to a EFIDXE Drivers</Abstract>\r
+    <Description>Library to abstract Framework extensions that conflict with UEFI 2.0 Specification
+
+ Help Port Framework/Tinao code that has conflicts with UEFI 2.0 by hiding the oldconflicts with library functions and supporting implementations of the old 
+ (EDK/EFI 1.10) and new (EDK II/UEFI 2.0) way. This module is a DXE driver as  it contains DXE enum extensions for EFI event services.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation.</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UefiLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PcdLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PrintLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UefiLib.c</Filename>\r
+    <Filename>Console.c</Filename>\r
+    <Filename>UefiNotTiano.c</Filename>\r
+    <Filename>UefiLibPrint.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiEventLegacyBootGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiEventReadyToBootGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiFrameworkDevicePathGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+  <PcdCoded>\r
+    <PcdEntry PcdItemType="FIXED_AT_BUILD" Usage="ALWAYS_CONSUMED">\r
+      <C_Name>PcdUefiLibMaxPrintBufferSize</C_Name>\r
+      <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>This PCD is used by UefiLib APIs, which are Print, ErrorPrint, AsciiPrint, AsciiErrorPrint. If the length of the formatted Unicode or ASCII string is greater than PcdUefiLibMaxPrintBufferSize, then only the first (PcdUefiLibMaxPrintBufferSize / Sizeof(CHAR16)) Unicode characters or PcdUefiLibMaxPrintBufferSize Ascii characters are sent to the respective console.</HelpText>\r
+    </PcdEntry>\r
+  </PcdCoded>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdePkg/Library/UefiLib/UefiLibPrint.c b/MdePkg/Library/UefiLib/UefiLibPrint.c
new file mode 100644 (file)
index 0000000..f4453e4
--- /dev/null
@@ -0,0 +1,264 @@
+/** @file\r
+  Mde UEFI library API implemention.\r
+  Print to StdErr or ConOut defined in EFI_SYSTEM_TABLE\r
+\r
+  Copyright (c) 2007, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+/**\r
+  Internal function which prints a formatted Unicode string to the console output device\r
+  specified by Console\r
+\r
+  This function prints a formatted Unicode string to the console output device\r
+  specified by Console and returns the number of Unicode characters that printed\r
+  to it.  If the length of the formatted Unicode string is greater than PcdUefiLibMaxPrintBufferSize,\r
+  then only the first PcdUefiLibMaxPrintBufferSize characters are sent to Console.\r
+\r
+  @param Format   Null-terminated Unicode format string.\r
+  @param Console  The output console.\r
+  @param Marker   VA_LIST marker for the variable argument list.\r
+\r
+  If Format is NULL, then ASSERT().\r
+  If Format is not aligned on a 16-bit boundary, then ASSERT().\r
+\r
+**/\r
+\r
+STATIC\r
+UINTN\r
+InternalPrint (\r
+  IN  CONST CHAR16                     *Format,\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *Console,\r
+  IN  VA_LIST                          Marker\r
+  )\r
+{\r
+  UINTN   Return;\r
+  CHAR16  *Buffer;\r
+  UINTN   BufferSize;\r
+\r
+  ASSERT (Format != NULL);\r
+  ASSERT (((UINTN) Format & 0x01) == 0);\r
+\r
+  BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r
+\r
+  Buffer = (CHAR16 *) AllocatePool(BufferSize);\r
+  ASSERT (Buffer != NULL);\r
+\r
+  Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);\r
+\r
+  if (Console != NULL) {\r
+    //\r
+    // To be extra safe make sure Console has been initialized\r
+    //\r
+    Console->OutputString (Console, Buffer);\r
+  }\r
+\r
+  FreePool (Buffer);\r
+\r
+  return Return;\r
+}\r
+\r
+/**\r
+  Prints a formatted Unicode string to the console output device specified by\r
+  ConOut defined in the EFI_SYSTEM_TABLE.\r
+\r
+  This function prints a formatted Unicode string to the console output device\r
+  specified by ConOut in EFI_SYSTEM_TABLE and returns the number of Unicode\r
+  characters that printed to ConOut.  If the length of the formatted Unicode\r
+  string is greater than PcdUefiLibMaxPrintBufferSize, then only the first\r
+  PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r
+\r
+  @param Format   Null-terminated Unicode format string.\r
+  @param ...      VARARG list consumed to process Format.\r
+  If Format is NULL, then ASSERT().\r
+  If Format is not aligned on a 16-bit boundary, then ASSERT().\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+Print (\r
+  IN CONST CHAR16  *Format,\r
+  ...\r
+  )\r
+{\r
+  VA_LIST Marker;\r
+  UINTN   Return;\r
+\r
+  VA_START (Marker, Format);\r
+\r
+  Return = InternalPrint (Format, gST->ConOut, Marker);\r
+\r
+  VA_END (Marker);\r
+\r
+  return Return;\r
+}\r
+\r
+/**\r
+  Prints a formatted Unicode string to the console output device specified by\r
+  StdErr defined in the EFI_SYSTEM_TABLE.\r
+\r
+  This function prints a formatted Unicode string to the console output device\r
+  specified by StdErr in EFI_SYSTEM_TABLE and returns the number of Unicode\r
+  characters that printed to StdErr.  If the length of the formatted Unicode\r
+  string is greater than PcdUefiLibMaxPrintBufferSize, then only the first\r
+  PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.\r
+\r
+  @param Format   Null-terminated Unicode format string.\r
+  @param ...      VARARG list consumed to process Format.\r
+  If Format is NULL, then ASSERT().\r
+  If Format is not aligned on a 16-bit boundary, then ASSERT().\r
+\r
+**/\r
+\r
+UINTN\r
+EFIAPI\r
+ErrorPrint (\r
+  IN CONST CHAR16  *Format,\r
+  ...\r
+  )\r
+{\r
+  VA_LIST Marker;\r
+  UINTN   Return;\r
+\r
+  VA_START (Marker, Format);\r
+\r
+  Return = InternalPrint( Format, gST->StdErr, Marker);\r
+\r
+  VA_END (Marker);\r
+\r
+  return Return;\r
+}\r
+\r
+\r
+/**\r
+  Internal function which prints a formatted ASCII string to the console output device\r
+  specified by Console\r
+\r
+  This function prints a formatted ASCII string to the console output device\r
+  specified by Console and returns the number of ASCII characters that printed\r
+  to it.  If the length of the formatted ASCII string is greater than PcdUefiLibMaxPrintBufferSize,\r
+  then only the first PcdUefiLibMaxPrintBufferSize characters are sent to Console.\r
+\r
+  @param Format   Null-terminated ASCII format string.\r
+  @param Console  The output console.\r
+  @param Marker   VA_LIST marker for the variable argument list.\r
+\r
+  If Format is NULL, then ASSERT().\r
+\r
+**/\r
+\r
+STATIC\r
+UINTN\r
+AsciiInternalPrint (\r
+  IN  CONST CHAR8                      *Format,\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *Console,\r
+  IN  VA_LIST                          Marker\r
+  )\r
+{\r
+  UINTN   Return;\r
+  CHAR16  *Buffer;\r
+  UINTN   BufferSize;\r
+\r
+  ASSERT (Format != NULL);\r
+\r
+  BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r
+\r
+  Buffer = (CHAR16 *) AllocatePool(BufferSize);\r
+  ASSERT (Buffer != NULL);\r
+\r
+  Return = UnicodeVSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);\r
+\r
+  if (Console != NULL) {\r
+    //\r
+    // To be extra safe make sure Console has been initialized\r
+    //\r
+    Console->OutputString (Console, Buffer);\r
+  }\r
+\r
+  FreePool (Buffer);\r
+\r
+  return Return;\r
+}\r
+\r
+/**\r
+  Prints a formatted ASCII string to the console output device specified by\r
+  ConOut defined in the EFI_SYSTEM_TABLE.\r
+\r
+  This function prints a formatted ASCII string to the console output device\r
+  specified by ConOut in EFI_SYSTEM_TABLE and returns the number of ASCII\r
+  characters that printed to ConOut.  If the length of the formatted ASCII\r
+  string is greater than PcdUefiLibMaxPrintBufferSize, then only the first\r
+  PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r
+\r
+  @param Format   Null-terminated ASCII format string.\r
+  @param ...      VARARG list consumed to process Format.\r
+  If Format is NULL, then ASSERT().\r
+  If Format is not aligned on a 16-bit boundary, then ASSERT().\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+AsciiPrint (\r
+  IN CONST CHAR8  *Format,\r
+  ...\r
+  )\r
+{\r
+  VA_LIST Marker;\r
+  UINTN   Return;\r
+\r
+  VA_START (Marker, Format);\r
+\r
+  Return = AsciiInternalPrint( Format, gST->ConOut, Marker);\r
+\r
+  VA_END (Marker);\r
+\r
+  return Return;\r
+}\r
+\r
+/**\r
+  Prints a formatted ASCII string to the console output device specified by\r
+  StdErr defined in the EFI_SYSTEM_TABLE.\r
+\r
+  This function prints a formatted ASCII string to the console output device\r
+  specified by StdErr in EFI_SYSTEM_TABLE and returns the number of ASCII\r
+  characters that printed to StdErr.  If the length of the formatted ASCII\r
+  string is greater than PcdUefiLibMaxPrintBufferSize, then only the first\r
+  PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.\r
+\r
+  @param Format   Null-terminated ASCII format string.\r
+  @param ...      VARARG list consumed to process Format.\r
+  If Format is NULL, then ASSERT().\r
+  If Format is not aligned on a 16-bit boundary, then ASSERT().\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+AsciiErrorPrint (\r
+  IN CONST CHAR8  *Format,\r
+  ...\r
+  )\r
+{\r
+  VA_LIST Marker;\r
+  UINTN   Return;\r
+\r
+  VA_START (Marker, Format);\r
+\r
+  Return = AsciiInternalPrint( Format, gST->StdErr, Marker);\r
+\r
+  VA_END (Marker);\r
+\r
+  return Return;\r
+}\r
+\r
diff --git a/MdePkg/Library/UefiLib/UefiNotTiano.c b/MdePkg/Library/UefiLib/UefiNotTiano.c
new file mode 100644 (file)
index 0000000..b00cc22
--- /dev/null
@@ -0,0 +1,313 @@
+/** @file\r
+  Library functions that abstract areas of conflict between Tiano an UEFI 2.0.\r
+\r
+  Help Port Framework/Tinao code that has conflicts with UEFI 2.0 by hiding the\r
+  oldconflicts with library functions and supporting implementations of the old\r
+  (EDK/EFI 1.10) and new (EDK II/UEFI 2.0) way. This module is a DXE driver as\r
+  it contains DXE enum extensions for EFI event services.\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+/**\r
+  An empty function to pass error checking of CreateEventEx ().\r
+\r
+  This empty function ensures that EFI_EVENT_NOTIFY_SIGNAL_ALL is error\r
+  checked correctly since it is now mapped into CreateEventEx() in UEFI 2.0.\r
+\r
+**/\r
+STATIC\r
+VOID\r
+EFIAPI\r
+InternalEmptyFuntion (\r
+  IN EFI_EVENT                Event,\r
+  IN VOID                     *Context\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+/**\r
+  Create a Legacy Boot Event.\r
+\r
+  Tiano extended the CreateEvent Type enum to add a legacy boot event type.\r
+  This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was\r
+  added and now it's possible to not voilate the UEFI specification by\r
+  declaring a GUID for the legacy boot event class. This library supports\r
+  the EDK/EFI 1.10 form and EDK II/UEFI 2.0 form and allows common code to\r
+  work both ways.\r
+\r
+  @param  LegacyBootEvent   Returns the EFI event returned from gBS->CreateEvent(Ex).\r
+\r
+  @retval EFI_SUCCESS       Event was created.\r
+  @retval Other             Event was not created.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiCreateEventLegacyBoot (\r
+  OUT EFI_EVENT  *LegacyBootEvent\r
+  )\r
+{\r
+  return EfiCreateEventLegacyBootEx (\r
+           TPL_CALLBACK,\r
+           InternalEmptyFuntion,\r
+           NULL,\r
+           LegacyBootEvent\r
+           );\r
+}\r
+\r
+/**\r
+  Create an EFI event in the Legacy Boot Event Group and allows\r
+  the caller to specify a notification function.\r
+\r
+  This function abstracts the creation of the Legacy Boot Event.\r
+  The Framework moved from a proprietary to UEFI 2.0 based mechanism.\r
+  This library abstracts the caller from how this event is created to prevent\r
+  to code form having to change with the version of the specification supported.\r
+  If LegacyBootEvent is NULL, then ASSERT().\r
+\r
+  @param  NotifyTpl         The task priority level of the event.\r
+  @param  NotifyFunction    The notification function to call when the event is signaled.\r
+  @param  NotifyContext     The content to pass to NotifyFunction when the event is signaled.\r
+  @param  LegacyBootEvent   Returns the EFI event returned from gBS->CreateEvent(Ex).\r
+\r
+  @retval EFI_SUCCESS       Event was created.\r
+  @retval Other             Event was not created.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiCreateEventLegacyBootEx (\r
+  IN  EFI_TPL           NotifyTpl,\r
+  IN  EFI_EVENT_NOTIFY  NotifyFunction,  OPTIONAL\r
+  IN  VOID              *NotifyContext,  OPTIONAL\r
+  OUT EFI_EVENT         *LegacyBootEvent\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+\r
+  ASSERT (LegacyBootEvent != NULL);\r
+\r
+  if (gST->Hdr.Revision < 0x00020000) {\r
+    return EFI_UNSUPPORTED;\r
+  } else {\r
+    //\r
+    // For UEFI 2.0 and the future use an Event Group\r
+    //\r
+    Status = gBS->CreateEventEx (\r
+                    EVT_NOTIFY_SIGNAL,\r
+                    NotifyTpl,\r
+                    NotifyFunction,\r
+                    NotifyContext,\r
+                    &gEfiEventLegacyBootGuid,\r
+                    LegacyBootEvent\r
+                    );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Create a Read to Boot Event.\r
+\r
+  Tiano extended the CreateEvent Type enum to add a ready to boot event type.\r
+  This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was\r
+  added and now it's possible to not voilate the UEFI specification and use\r
+  the ready to boot event class defined in UEFI 2.0. This library supports\r
+  the EDK/EFI 1.10 form and EDK II/UEFI 2.0 form and allows common code to\r
+  work both ways.\r
+\r
+  @param  LegacyBootEvent   Returns the EFI event returned from gBS->CreateEvent(Ex).\r
+\r
+  @retval EFI_SUCCESS       Event was created.\r
+  @retval Other             Event was not created.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiCreateEventReadyToBoot (\r
+  OUT EFI_EVENT  *ReadyToBootEvent\r
+  )\r
+{\r
+  return EfiCreateEventReadyToBootEx (\r
+           TPL_CALLBACK ,\r
+           InternalEmptyFuntion,\r
+           NULL,\r
+           ReadyToBootEvent\r
+           );\r
+}\r
+\r
+/**\r
+  Create an EFI event in the Ready To Boot Event Group and allows\r
+  the caller to specify a notification function.\r
+\r
+  This function abstracts the creation of the Ready to Boot Event.\r
+  The Framework moved from a proprietary to UEFI 2.0 based mechanism.\r
+  This library abstracts the caller from how this event is created to prevent\r
+  to code form having to change with the version of the specification supported.\r
+  If ReadyToBootEvent is NULL, then ASSERT().\r
+\r
+  @param  NotifyTpl         The task priority level of the event.\r
+  @param  NotifyFunction    The notification function to call when the event is signaled.\r
+  @param  NotifyContext     The content to pass to NotifyFunction when the event is signaled.\r
+  @param  LegacyBootEvent   Returns the EFI event returned from gBS->CreateEvent(Ex).\r
+\r
+  @retval EFI_SUCCESS       Event was created.\r
+  @retval Other             Event was not created.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiCreateEventReadyToBootEx (\r
+  IN  EFI_TPL           NotifyTpl,\r
+  IN  EFI_EVENT_NOTIFY  NotifyFunction,  OPTIONAL\r
+  IN  VOID              *NotifyContext,  OPTIONAL\r
+  OUT EFI_EVENT         *ReadyToBootEvent\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+\r
+  ASSERT (ReadyToBootEvent != NULL);\r
+\r
+  if (gST->Hdr.Revision < 0x00020000) {\r
+    return EFI_UNSUPPORTED;\r
+  } else {\r
+    //\r
+    // For UEFI 2.0 and the future use an Event Group\r
+    //\r
+    Status = gBS->CreateEventEx (\r
+                    EVT_NOTIFY_SIGNAL,\r
+                    NotifyTpl,\r
+                    NotifyFunction,\r
+                    NotifyContext,\r
+                    &gEfiEventReadyToBootGuid,\r
+                    ReadyToBootEvent\r
+                    );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Signal a Ready to Boot Event.\r
+\r
+  Create a Ready to Boot Event. Signal it and close it. This causes other\r
+  events of the same event group to be signaled in other modules.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+EfiSignalEventReadyToBoot (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  EFI_EVENT     ReadyToBootEvent;\r
+\r
+  Status = EfiCreateEventReadyToBoot (&ReadyToBootEvent);\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->SignalEvent (ReadyToBootEvent);\r
+    gBS->CloseEvent (ReadyToBootEvent);\r
+  }\r
+}\r
+\r
+/**\r
+  Signal a Legacy Boot Event.\r
+\r
+  Create a legacy Boot Event. Signal it and close it. This causes other\r
+  events of the same event group to be signaled in other modules.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+EfiSignalEventLegacyBoot (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  EFI_EVENT     LegacyBootEvent;\r
+\r
+  Status = EfiCreateEventLegacyBoot (&LegacyBootEvent);\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->SignalEvent (LegacyBootEvent);\r
+    gBS->CloseEvent (LegacyBootEvent);\r
+  }\r
+}\r
+\r
+\r
+/**\r
+  Check to see if the Firmware Volume (FV) Media Device Path is valid\r
+\r
+  Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum\r
+  so as we move to UEFI 2.0 support we must use a mechanism that conforms with\r
+  the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed\r
+  device path is defined for Tiano extensions of device path. If the code\r
+  is compiled to conform with the UEFI 2.0 specification use the new device path\r
+  else use the old form for backwards compatability. The return value to this\r
+  function points to a location in FvDevicePathNode and it does not allocate\r
+  new memory for the GUID pointer that is returned.\r
+\r
+  @param  FvDevicePathNode  Pointer to FV device path to check.\r
+\r
+  @retval NULL              FvDevicePathNode is not valid.\r
+  @retval Other             FvDevicePathNode is valid and pointer to NameGuid was returned.\r
+\r
+**/\r
+EFI_GUID *\r
+EFIAPI\r
+EfiGetNameGuidFromFwVolDevicePathNode (\r
+  IN CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH  *FvDevicePathNode\r
+  )\r
+{\r
+  ASSERT (FvDevicePathNode != NULL);\r
+  //\r
+  //  bugbug:Need to implement ...\r
+  //\r
+  return NULL;\r
+}\r
+\r
+\r
+/**\r
+  Initialize a Firmware Volume (FV) Media Device Path node.\r
+\r
+  Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum\r
+  so as we move to UEFI 2.0 support we must use a mechanism that conforms with\r
+  the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed\r
+  device path is defined for Tiano extensions of device path. If the code\r
+  is compiled to conform with the UEFI 2.0 specification use the new device path\r
+  else use the old form for backwards compatability.\r
+\r
+  @param  FvDevicePathNode  Pointer to a FV device path node to initialize\r
+  @param  NameGuid          FV file name to use in FvDevicePathNode\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+EfiInitializeFwVolDevicepathNode (\r
+  IN OUT MEDIA_FW_VOL_FILEPATH_DEVICE_PATH  *FvDevicePathNode,\r
+  IN CONST EFI_GUID                         *NameGuid\r
+  )\r
+{\r
+  ASSERT (FvDevicePathNode  != NULL);\r
+  ASSERT (NameGuid          != NULL);\r
+  //\r
+  //  bugbug:Need to implement ...\r
+  //\r
+}\r
+\r
diff --git a/MdePkg/Library/UefiRuntimeServicesTableLib/CommonHeader.h b/MdePkg/Library/UefiRuntimeServicesTableLib/CommonHeader.h
new file mode 100644 (file)
index 0000000..ca35d63
--- /dev/null
@@ -0,0 +1,32 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2007, Intel Corporation.\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#endif\r
diff --git a/MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.c b/MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.c
new file mode 100644 (file)
index 0000000..7fb7773
--- /dev/null
@@ -0,0 +1,50 @@
+/** @file\r
+  UEFI Runtime Services Table Library.\r
+\r
+  Copyright (c) 2006, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Module Name:  UefiRuntimeServicesTableLib.c\r
+\r
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+EFI_RUNTIME_SERVICES  *gRT = NULL;\r
+\r
+/**\r
+  The constructor function caches the pointer of Runtime Services Table.\r
+\r
+  The constructor function caches the pointer of Runtime Services Table.\r
+  It will ASSERT() if the pointer of Runtime Services Table is NULL.\r
+  It will always return EFI_SUCCESS.\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
+UefiRuntimeServicesTableLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  //\r
+  // Cache pointer to the EFI Runtime Services Table\r
+  //\r
+  gRT = SystemTable->RuntimeServices;\r
+  ASSERT (gRT != NULL);\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf b/MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
new file mode 100644 (file)
index 0000000..86d31fb
--- /dev/null
@@ -0,0 +1,81 @@
+#/** @file\r
+# UEFI Runtime Services Table Library\r
+#\r
+# Library to abstract Framework extensions that conflict with UEFI 2.0 Specification\r
+# Copyright (c) 2007, Intel Corporation.\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UefiRuntimeServicesTableLib\r
+  FILE_GUID                      = 19cbbb97-ff61-45ff-8c3f-dfa66dd118c8\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = UefiRuntimeServicesTableLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = UefiRuntimeServicesTableLibConstructor\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
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  UefiRuntimeServicesTableLib.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg\Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+\r
diff --git a/MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.msa b/MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.msa
new file mode 100644 (file)
index 0000000..47aafb8
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>UefiRuntimeServicesTableLib</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>19cbbb97-ff61-45ff-8c3f-dfa66dd118c8</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>UEFI Runtime Services Table Library</Abstract>\r
+    <Description>Library to abstract Framework extensions that conflict with UEFI 2.0 Specification</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation.</Copyright>\r
+    <License>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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UefiRuntimeServicesTableLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER">\r
+      <Keyword>UefiRuntimeServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UefiRuntimeServicesTableLib.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <Constructor>UefiRuntimeServicesTableLibConstructor</Constructor>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file