Check in following modules,
authorxgu3 <xgu3@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 5 Jul 2007 07:05:28 +0000 (07:05 +0000)
committerxgu3 <xgu3@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 5 Jul 2007 07:05:28 +0000 (07:05 +0000)
DxeIpl
ConPlatform
ConSplitter
GraphicsConsole
Terminal
DevicePath

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3069 6f19259b-4bc3-4df7-8a09-765794883524

63 files changed:
IntelFrameworkPkg/Include/Protocol/FrameworkHii.h [new file with mode: 0644]
MdeModulePkg/Core/DxeIplPeim/CommonHeader.h [new file with mode: 0644]
MdeModulePkg/Core/DxeIplPeim/DxeIpl.dxs [new file with mode: 0644]
MdeModulePkg/Core/DxeIplPeim/DxeIpl.h [new file with mode: 0644]
MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf [new file with mode: 0644]
MdeModulePkg/Core/DxeIplPeim/DxeIpl.msa [new file with mode: 0644]
MdeModulePkg/Core/DxeIplPeim/DxeLoad.c [new file with mode: 0644]
MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c [new file with mode: 0644]
MdeModulePkg/Core/DxeIplPeim/Ia32/ImageRead.c [new file with mode: 0644]
MdeModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.c [new file with mode: 0644]
MdeModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.h [new file with mode: 0644]
MdeModulePkg/Core/DxeIplPeim/Ipf/DxeLoadFunc.c [new file with mode: 0644]
MdeModulePkg/Core/DxeIplPeim/Ipf/ImageRead.c [new file with mode: 0644]
MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c [new file with mode: 0644]
MdeModulePkg/Include/Common/DecompressLibraryHob.h [new file with mode: 0644]
MdeModulePkg/MdeModulePkg.dec
MdeModulePkg/MdeModulePkg.dsc
MdeModulePkg/Universal/Console/ConPlatformDxe/CommonHeader.h [new file with mode: 0644]
MdeModulePkg/Universal/Console/ConPlatformDxe/ComponentName.c [new file with mode: 0644]
MdeModulePkg/Universal/Console/ConPlatformDxe/ComponentName.h [new file with mode: 0644]
MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c [new file with mode: 0644]
MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h [new file with mode: 0644]
MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.inf [new file with mode: 0644]
MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.msa [new file with mode: 0644]
MdeModulePkg/Universal/Console/ConSplitterDxe/CommonHeader.h [new file with mode: 0644]
MdeModulePkg/Universal/Console/ConSplitterDxe/ComponentName.c [new file with mode: 0644]
MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c [new file with mode: 0644]
MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.h [new file with mode: 0644]
MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.inf [new file with mode: 0644]
MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.msa [new file with mode: 0644]
MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterGraphics.c [new file with mode: 0644]
MdeModulePkg/Universal/Console/GraphicsConsoleDxe/CommonHeader.h [new file with mode: 0644]
MdeModulePkg/Universal/Console/GraphicsConsoleDxe/ComponentName.c [new file with mode: 0644]
MdeModulePkg/Universal/Console/GraphicsConsoleDxe/ComponentName.h [new file with mode: 0644]
MdeModulePkg/Universal/Console/GraphicsConsoleDxe/EntryPoint.c [new file with mode: 0644]
MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c [new file with mode: 0644]
MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.h [new file with mode: 0644]
MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.inf [new file with mode: 0644]
MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.msa [new file with mode: 0644]
MdeModulePkg/Universal/Console/GraphicsConsoleDxe/LaffStd.c [new file with mode: 0644]
MdeModulePkg/Universal/Console/TerminalDxe/CommonHeader.h [new file with mode: 0644]
MdeModulePkg/Universal/Console/TerminalDxe/ComponentName.c [new file with mode: 0644]
MdeModulePkg/Universal/Console/TerminalDxe/EntryPoint.c [new file with mode: 0644]
MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c [new file with mode: 0644]
MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h [new file with mode: 0644]
MdeModulePkg/Universal/Console/TerminalDxe/Terminal.inf [new file with mode: 0644]
MdeModulePkg/Universal/Console/TerminalDxe/Terminal.msa [new file with mode: 0644]
MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c [new file with mode: 0644]
MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c [new file with mode: 0644]
MdeModulePkg/Universal/Console/TerminalDxe/ansi.c [new file with mode: 0644]
MdeModulePkg/Universal/Console/TerminalDxe/vtutf8.c [new file with mode: 0644]
MdeModulePkg/Universal/DevicePathDxe/CommonHeader.h [new file with mode: 0644]
MdeModulePkg/Universal/DevicePathDxe/DevicePath.c [new file with mode: 0644]
MdeModulePkg/Universal/DevicePathDxe/DevicePath.h [new file with mode: 0644]
MdeModulePkg/Universal/DevicePathDxe/DevicePath.inf [new file with mode: 0644]
MdeModulePkg/Universal/DevicePathDxe/DevicePath.msa [new file with mode: 0644]
MdeModulePkg/Universal/DevicePathDxe/DevicePathFromText.c [new file with mode: 0644]
MdeModulePkg/Universal/DevicePathDxe/DevicePathToText.c [new file with mode: 0644]
MdeModulePkg/Universal/DevicePathDxe/DevicePathUtilities.c [new file with mode: 0644]
Nt32Pkg/Library/Nt32PeCoffLoaderLib/CommonHeader.h
Nt32Pkg/Library/Nt32PeCoffLoaderLib/Nt32PeCoffLoaderLib.inf
Nt32Pkg/Nt32Pkg.dec
Nt32Pkg/Nt32Pkg.dsc

diff --git a/IntelFrameworkPkg/Include/Protocol/FrameworkHii.h b/IntelFrameworkPkg/Include/Protocol/FrameworkHii.h
new file mode 100644 (file)
index 0000000..ae3d379
--- /dev/null
@@ -0,0 +1,950 @@
+/** @file\r
+  This file defines the Human Interface Infrastructure protocol which will\r
+  be used by resources which want to publish IFR/Font/String data and have it\r
+  collected by the Configuration engine.\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
+\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:  FrameworkHii.h\r
+\r
+  @par Revision Reference:\r
+  This protocol is defined in HII spec 0.92.\r
+\r
+**/\r
+\r
+#ifndef _FRAMEWORK_HII_H_\r
+#define _FRAMEWORK_HII_H_\r
+\r
+#include <PiDxe.h>\r
+\r
+//\r
+// To get EFI_GRAPHICS_OUTPUT_BLT_PIXEL,\r
+// is defined in MdePkg/Protocol/GraphicsOutput.h\r
+//\r
+#include <Protocol/GraphicsOutput.h>\r
+\r
+#define EFI_HII_PROTOCOL_GUID \\r
+  { \\r
+    0xd7ad636e, 0xb997, 0x459b, {0xbf, 0x3f, 0x88, 0x46, 0x89, 0x79, 0x80, 0xe1} \\r
+  }\r
+\r
+// BugBug:\r
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+// If UGA goes away we need to put this some place. I'm not sure where?\r
+//\r
+//typedef struct {\r
+//  UINT8 Blue;\r
+//  UINT8 Green;\r
+//  UINT8 Red;\r
+//  UINT8 Reserved;\r
+//} EFI_UGA_PIXEL;\r
+\r
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+//\r
+\r
+typedef struct _EFI_HII_PROTOCOL  EFI_HII_PROTOCOL;\r
+\r
+//\r
+// Global definition\r
+//\r
+#define NARROW_CHAR         0xFFF0\r
+#define WIDE_CHAR           0xFFF1\r
+#define NON_BREAKING_CHAR   0xFFF2\r
+#define GLYPH_WIDTH         8\r
+#define GLYPH_HEIGHT        19\r
+\r
+#define EFI_HII_FONT        1\r
+#define EFI_HII_STRING      2\r
+#define EFI_HII_IFR         3\r
+#define EFI_HII_KEYBOARD    4\r
+#define EFI_HII_HANDLES     5\r
+#define EFI_HII_VARIABLE    6\r
+#define EFI_HII_DEVICE_PATH 7\r
+\r
+\r
+// References to string tokens must use this macro to enable scanning for\r
+// token usages.\r
+//\r
+#define STRING_TOKEN(t) t\r
+\r
+//\r
+// The following types are currently defined:\r
+//\r
+typedef UINT16  EFI_FORM_ID;\r
+typedef UINT16  EFI_FORM_LABEL;\r
+\r
+#pragma pack(1)\r
+\r
+typedef struct {\r
+  UINT32  Length;\r
+  UINT16  Type;\r
+} EFI_HII_PACK_HEADER;\r
+\r
+//\r
+// A form list consists of a large variety of structure\r
+// possibilities so to represent the binary blob of data\r
+// associated with a package of forms, we will assume a\r
+// pointer to a self-describing data buffer.\r
+//\r
+typedef struct {\r
+  EFI_HII_PACK_HEADER Header;\r
+} EFI_HII_IFR_PACK;\r
+\r
+typedef struct {\r
+  EFI_HII_PACK_HEADER Header;           // Must be filled in\r
+  EFI_HANDLE          ImageHandle;      // Must be filled in\r
+  EFI_HANDLE          DeviceHandle;     // Optional\r
+  EFI_HANDLE          ControllerHandle; // Optional\r
+  EFI_HANDLE          CallbackHandle;   // Optional\r
+  EFI_HANDLE          COBExportHandle;  // Optional\r
+} EFI_HII_HANDLE_PACK;\r
+\r
+//\r
+// ********************************************************\r
+// EFI_VARIABLE_CONTENTS\r
+// ********************************************************\r
+//\r
+typedef struct {\r
+  EFI_HII_PACK_HEADER Header;\r
+  EFI_GUID            VariableGuid;\r
+  UINT32              VariableNameLength;\r
+  UINT16              VariableId;\r
+  //\r
+  //  CHAR16                VariableName[]; //Null-terminated\r
+  //\r
+} EFI_HII_VARIABLE_PACK;\r
+\r
+//\r
+// ********************************************************\r
+// EFI_DEVICE_PATH_PACK\r
+// ********************************************************\r
+//\r
+typedef struct {\r
+  EFI_HII_PACK_HEADER Header;\r
+  //\r
+  //  EFI_DEVICE_PATH       DevicePath[];\r
+  //\r
+} EFI_HII_DEVICE_PATH_PACK;\r
+\r
+//\r
+// ********************************************************\r
+// EFI_HII_DATA_TABLE\r
+// ********************************************************\r
+//\r
+typedef struct {\r
+  EFI_HII_HANDLE  HiiHandle;\r
+  EFI_GUID        PackageGuid;\r
+  UINT32          DataTableSize;\r
+  UINT32          IfrDataOffset;\r
+  UINT32          StringDataOffset;\r
+  UINT32          VariableDataOffset;\r
+  UINT32          DevicePathOffset;\r
+  UINT32          NumberOfVariableData;\r
+  UINT32          NumberOfLanguages;\r
+  //\r
+  // EFI_HII_DEVICE_PATH_PACK DevicePath[];\r
+  // EFI_HII_VARIABLE_PACK VariableData[];\r
+  // EFI_HII_IFR_PACK IfrData;\r
+  // EFI_HII_STRING_PACK StringData[];\r
+  //\r
+} EFI_HII_DATA_TABLE;\r
+\r
+//\r
+// ********************************************************\r
+// EFI_HII_EXPORT_TABLE\r
+// ********************************************************\r
+//\r
+typedef struct {\r
+  UINT32    NumberOfHiiDataTables;\r
+  EFI_GUID  Revision;\r
+  //\r
+  // EFI_HII_DATA_TABLE HiiDataTable[];\r
+  //\r
+} EFI_HII_EXPORT_TABLE;\r
+\r
+typedef struct {\r
+  BOOLEAN               FormSetUpdate;      // If TRUE, next variable is significant\r
+  EFI_PHYSICAL_ADDRESS  FormCallbackHandle; // If not 0, will update Formset with this info\r
+  BOOLEAN               FormUpdate;         // If TRUE, next variable is significant\r
+  UINT16                FormValue;          // specify which form is to be updated if FormUpdate value is TRUE.\r
+  STRING_REF            FormTitle;          // If not 0, will update Form with this info\r
+  UINT16                DataCount;          // The number of Data entries in this structure\r
+  UINT8                 *Data;              // An array of 1+ op-codes, specified by DataCount\r
+} EFI_HII_UPDATE_DATA;\r
+\r
+//\r
+// String attributes\r
+//\r
+#define LANG_RIGHT_TO_LEFT  0x00000001\r
+\r
+//\r
+// A string package is used to localize strings to a particular\r
+// language.  The package is associated with a particular driver\r
+// or set of drivers.  Tools are used to associate tokens with\r
+// string references in forms and in programs.  These tokens are\r
+// language agnostic.  When paired with a language pack (directly\r
+// or indirectly), the string token resolves into an actual\r
+// UNICODE string.  The NumStringPointers determines how many\r
+// StringPointers (offset values) there are as well as the total\r
+// number of Strings that are defined.\r
+//\r
+typedef struct {\r
+  EFI_HII_PACK_HEADER Header;\r
+  RELOFST             LanguageNameString;\r
+  RELOFST             PrintableLanguageName;\r
+  UINT32              NumStringPointers;\r
+  UINT32              Attributes;\r
+  //\r
+  //  RELOFST               StringPointers[];\r
+  //  EFI_STRING            Strings[];\r
+  //\r
+} EFI_HII_STRING_PACK;\r
+\r
+//\r
+// Glyph Attributes\r
+//\r
+#define EFI_GLYPH_NON_SPACING   1\r
+#define EFI_GLYPH_WIDE          2\r
+\r
+typedef struct {\r
+  CHAR16  UnicodeWeight;\r
+  UINT8   Attributes;\r
+  UINT8   GlyphCol1[GLYPH_HEIGHT];\r
+} EFI_NARROW_GLYPH;\r
+\r
+typedef struct {\r
+  CHAR16  UnicodeWeight;\r
+  UINT8   Attributes;\r
+  UINT8   GlyphCol1[GLYPH_HEIGHT];\r
+  UINT8   GlyphCol2[GLYPH_HEIGHT];\r
+  UINT8   Pad[3];\r
+} EFI_WIDE_GLYPH;\r
+\r
+//\r
+// A font list consists of a font header followed by a series\r
+// of glyph structures.  Note that fonts are not language specific.\r
+//\r
+typedef struct {\r
+  EFI_HII_PACK_HEADER Header;\r
+  UINT16              NumberOfNarrowGlyphs;\r
+  UINT16              NumberOfWideGlyphs;\r
+} EFI_HII_FONT_PACK;\r
+\r
+//\r
+// The IfrData in the EFI_HII_IFR_PACK structure definition\r
+// is variable length, and not really part of the header. To\r
+// simplify from code the size of the header, define an\r
+// identical structure that does not include the IfrData field.\r
+// Then use sizeof() this new structure to determine the\r
+// actual size of the header.\r
+//\r
+typedef struct {\r
+  EFI_HII_PACK_HEADER Header;\r
+} EFI_HII_IFR_PACK_HEADER;\r
+\r
+//\r
+// pedef EFI_HII_PACK_HEADER EFI_HII_IFR_PACK_HEADER;\r
+//\r
+typedef enum {\r
+  EfiKeyLCtrl,\r
+  EfiKeyA0,\r
+  EfiKeyLAlt,\r
+  EfiKeySpaceBar,\r
+  EfiKeyA2,\r
+  EfiKeyA3,\r
+  EfiKeyA4,\r
+  EfiKeyRCtrl,\r
+  EfiKeyLeftArrow,\r
+  EfiKeyDownArrow,\r
+  EfiKeyRightArrow,\r
+  EfiKeyZero,\r
+  EfiKeyPeriod,\r
+  EfiKeyEnter,\r
+  EfiKeyLShift,\r
+  EfiKeyB0,\r
+  EfiKeyB1,\r
+  EfiKeyB2,\r
+  EfiKeyB3,\r
+  EfiKeyB4,\r
+  EfiKeyB5,\r
+  EfiKeyB6,\r
+  EfiKeyB7,\r
+  EfiKeyB8,\r
+  EfiKeyB9,\r
+  EfiKeyB10,\r
+  EfiKeyRshift,\r
+  EfiKeyUpArrow,\r
+  EfiKeyOne,\r
+  EfiKeyTwo,\r
+  EfiKeyThree,\r
+  EfiKeyCapsLock,\r
+  EfiKeyC1,\r
+  EfiKeyC2,\r
+  EfiKeyC3,\r
+  EfiKeyC4,\r
+  EfiKeyC5,\r
+  EfiKeyC6,\r
+  EfiKeyC7,\r
+  EfiKeyC8,\r
+  EfiKeyC9,\r
+  EfiKeyC10,\r
+  EfiKeyC11,\r
+  EfiKeyC12,\r
+  EfiKeyFour,\r
+  EfiKeyFive,\r
+  EfiKeySix,\r
+  EfiKeyPlus,\r
+  EfiKeyTab,\r
+  EfiKeyD1,\r
+  EfiKeyD2,\r
+  EfiKeyD3,\r
+  EfiKeyD4,\r
+  EfiKeyD5,\r
+  EfiKeyD6,\r
+  EfiKeyD7,\r
+  EfiKeyD8,\r
+  EfiKeyD9,\r
+  EfiKeyD10,\r
+  EfiKeyD11,\r
+  EfiKeyD12,\r
+  EfiKeyD13,\r
+  EfiKeyDel,\r
+  EfiKeyEnd,\r
+  EfiKeyPgDn,\r
+  EfiKeySeven,\r
+  EfiKeyEight,\r
+  EfiKeyNine,\r
+  EfiKeyE0,\r
+  EfiKeyE1,\r
+  EfiKeyE2,\r
+  EfiKeyE3,\r
+  EfiKeyE4,\r
+  EfiKeyE5,\r
+  EfiKeyE6,\r
+  EfiKeyE7,\r
+  EfiKeyE8,\r
+  EfiKeyE9,\r
+  EfiKeyE10,\r
+  EfiKeyE11,\r
+  EfiKeyE12,\r
+  EfiKeyBackSpace,\r
+  EfiKeyIns,\r
+  EfiKeyHome,\r
+  EfiKeyPgUp,\r
+  EfiKeyNLck,\r
+  EfiKeySlash,\r
+  EfiKeyAsterisk,\r
+  EfiKeyMinus,\r
+  EfiKeyEsc,\r
+  EfiKeyF1,\r
+  EfiKeyF2,\r
+  EfiKeyF3,\r
+  EfiKeyF4,\r
+  EfiKeyF5,\r
+  EfiKeyF6,\r
+  EfiKeyF7,\r
+  EfiKeyF8,\r
+  EfiKeyF9,\r
+  EfiKeyF10,\r
+  EfiKeyF11,\r
+  EfiKeyF12,\r
+  EfiKeyPrint,\r
+  EfiKeySLck,\r
+  EfiKeyPause\r
+} EFI_KEY;\r
+\r
+typedef struct {\r
+  EFI_KEY Key;\r
+  CHAR16  Unicode;\r
+  CHAR16  ShiftedUnicode;\r
+  CHAR16  AltGrUnicode;\r
+  CHAR16  ShiftedAltGrUnicode;\r
+  UINT16  Modifier;\r
+} EFI_KEY_DESCRIPTOR;\r
+\r
+//\r
+// This structure allows a sparse set of keys to be redefined\r
+// or a complete redefinition of the keyboard layout.  Most\r
+// keyboards have a lot of commonality in their layouts, therefore\r
+// only defining those keys that need to change from the default\r
+// minimizes the passed in information.\r
+//\r
+// Additionally, when an update occurs, the active keyboard layout\r
+// will be switched to the newly updated keyboard layout.  This\r
+// allows for situations that when a keyboard layout driver is\r
+// loaded as part of system initialization, the system will default\r
+// the keyboard behavior to the new layout.\r
+//\r
+// Each call to update the keyboard mapping should contain the\r
+// complete set of key descriptors to be updated, since every\r
+// call to the HII which contains an EFI_HII_KEYBOARD_PACK will\r
+// wipe the previous set of overrides.  A call to\r
+//\r
+typedef struct {\r
+  EFI_HII_PACK_HEADER Header;\r
+  EFI_KEY_DESCRIPTOR  *Descriptor;\r
+  UINT8               DescriptorCount;\r
+} EFI_HII_KEYBOARD_PACK;\r
+\r
+//\r
+// The EFI_HII_PACKAGES can contain different types of packages just\r
+// after the structure as inline data.\r
+//\r
+typedef struct {\r
+  UINTN     NumberOfPackages;\r
+  EFI_GUID  *GuidId;\r
+  //\r
+  // EFI_HII_HANDLE_PACK    *HandlePack;        // Only one pack.\r
+  // EFI_HII_IFR_PACK       *IfrPack;           // Only one pack.\r
+  // EFI_HII_FONT_PACK      *FontPack[];        // Multiple packs ok\r
+  // EFI_HII_STRING_PACK    *StringPack[];      // Multiple packs ok\r
+  // EFI_HII_KEYBOARD_PACK  *KeyboardPack[];    // Multiple packs ok\r
+  //\r
+} EFI_HII_PACKAGES;\r
+\r
+typedef struct _EFI_HII_VARIABLE_PACK_LIST {\r
+  struct _EFI_HII_VARIABLE_PACK_LIST   *NextVariablePack;\r
+  EFI_HII_VARIABLE_PACK                *VariablePack;\r
+} EFI_HII_VARIABLE_PACK_LIST;\r
+\r
+#pragma pack()\r
+\r
+/**\r
+  Registers the various packs that are passed in via the Packages parameter.\r
+\r
+  @param  This                  A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param  Packages              A pointer to an EFI_HII_PACKAGES package instance.\r
+  @param  Handle                A pointer to the EFI_HII_HANDLE instance.\r
+\r
+  @retval EFI_SUCCESS           Data was extracted from Packages, the database\r
+                                was updated with the data, and Handle returned successfully.\r
+  @retval EFI_INVALID_PARAMETER The content of Packages was invalid.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_HII_NEW_PACK) (\r
+  IN  EFI_HII_PROTOCOL    *This,\r
+  IN  EFI_HII_PACKAGES    *Packages,\r
+  OUT EFI_HII_HANDLE      *Handle\r
+  );\r
+\r
+/**\r
+  Removes a package from the HII database.\r
+\r
+  @param  This                  A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param  Handle                The handle that was registered to the data that is requested\r
+                                for removal.\r
+\r
+  @retval EFI_SUCCESS           The data associated with the Handle was removed\r
+                                from the HII database.\r
+  @retval EFI_INVALID_PARAMETER The Handle was not valid.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_HII_REMOVE_PACK) (\r
+  IN EFI_HII_PROTOCOL    *This,\r
+  IN EFI_HII_HANDLE      Handle\r
+  );\r
+\r
+/**\r
+  Determines the handles that are currently active in the database.\r
+\r
+  @param  This                  A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param  HandleBufferLength    On input, a pointer to the length of the handle\r
+                                buffer. On output, the length of the handle buffer that is required\r
+                                for the handles found.\r
+  @param  Handle                An array of EFI_HII_HANDLE instances returned.\r
+\r
+  @retval EFI_SUCCESS           Handle was updated successfully.\r
+  @retval EFI_BUFFER_TOO_SMALL  The HandleBufferLength parameter indicates\r
+                                that Handle is too small to support the number of handles.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_HII_FIND_HANDLES) (\r
+  IN     EFI_HII_PROTOCOL *This,\r
+  IN OUT UINT16           *HandleBufferLength,\r
+  OUT    EFI_HII_HANDLE   *Handle\r
+  );\r
+\r
+/**\r
+  Exports the contents of the database into a buffer.\r
+\r
+  @param  This                  A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param  Handle                An EFI_HII_HANDLE that corresponds to the desired\r
+                                handle to export. If the value is 0, the entire database will be exported.\r
+                                In either case, the data will be exported in a format described by the\r
+                                structure definition of EFI_HII_EXPORT_TABLE.\r
+  @param  BufferSize\r
+  On input, a pointer to the length of the buffer. On output, the length\r
+  of the buffer that is required for the export data.\r
+  @param  Buffer                A pointer to a buffer that will contain the results of the export function.\r
+\r
+  @retval EFI_SUCCESS           The buffer was successfully filled with BufferSize amount of data.\r
+  @retval EFI_BUFFER_TOO_SMALL  The value in BufferSize was too small to contain the export data.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_HII_EXPORT) (\r
+  IN     EFI_HII_PROTOCOL *This,\r
+  IN     EFI_HII_HANDLE   Handle,\r
+  IN OUT UINTN            *BufferSize,\r
+  OUT    VOID             *Buffer\r
+  );\r
+\r
+/**\r
+  Remove any new strings that were added after the initial string export\r
+  for this handle.\r
+\r
+  @param  This                  A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param  Handle                The handle on which the string resides.\r
+\r
+  @retval EFI_SUCCESS           Remove strings from the handle successfully.\r
+  @retval EFI_INVALID_PARAMETER The Handle was unknown.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_HII_RESET_STRINGS) (\r
+  IN     EFI_HII_PROTOCOL   *This,\r
+  IN     EFI_HII_HANDLE     Handle\r
+  );\r
+\r
+/**\r
+  Tests if all of the characters in a string have corresponding font characters.\r
+\r
+  @param  This                  A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param  StringToTest          A pointer to a Unicode string.\r
+  @param  FirstMissing          A pointer to an index into the string. On input,\r
+                                the index of the first character in the StringToTest to examine. On exit,\r
+                                the index of the first character encountered for which a glyph is unavailable.\r
+                                If all glyphs in the string are available, the index is the index of the\r
+                                terminator of the string.\r
+  @param  GlyphBufferSize       A pointer to a value. On output, if the function\r
+                                returns EFI_SUCCESS, it contains the amount of memory that is required to\r
+                                store the string's glyph equivalent.\r
+\r
+  @retval EFI_SUCCESS           All glyphs are available. Note that an empty string\r
+                                always returns this value.\r
+  @retval EFI_NOT_FOUND         A glyph was not found for a character.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_HII_TEST_STRING) (\r
+  IN     EFI_HII_PROTOCOL  *This,\r
+  IN     CHAR16            *StringToTest,\r
+  IN OUT UINT32            *FirstMissing,\r
+  OUT    UINT32            *GlyphBufferSize\r
+  );\r
+\r
+/**\r
+  Translates a Unicode character into the corresponding font glyph.\r
+\r
+  @param  This                  A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param  Source                A pointer to a Unicode string.\r
+  @param  Index                 On input, the offset into the string from which to fetch\r
+                                the character.On successful completion, the index is updated to the first\r
+                                character past the character(s) making up the just extracted glyph.\r
+  @param  GlyphBuffer           Pointer to an array where the glyphs corresponding\r
+                                to the characters in the source may be stored. GlyphBuffer is assumed\r
+                                to be wide enough to accept a wide glyph character.\r
+  @param  BitWidth              If EFI_SUCCESS was returned, the UINT16 pointed to by\r
+                                this value is filled with the length of the glyph in pixels. It is unchanged\r
+                                if the call was unsuccessful.\r
+  @param  InternalStatus        The cell pointed to by this parameter must be\r
+                                initialized to zero prior to invoking the call the first time for any string.\r
+\r
+  @retval EFI_SUCCESS           It worked.\r
+  @retval EFI_NOT_FOUND         A glyph for a character was not found.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_HII_GET_GLYPH) (\r
+  IN     EFI_HII_PROTOCOL  *This,\r
+  IN     CHAR16            *Source,\r
+  IN OUT UINT16            *Index,\r
+  OUT    UINT8             **GlyphBuffer,\r
+  OUT    UINT16            *BitWidth,\r
+  IN OUT UINT32            *InternalStatus\r
+  );\r
+\r
+/**\r
+  Translates a glyph into the format required for input to the Universal\r
+  Graphics Adapter (UGA) Block Transfer (BLT) routines.\r
+\r
+  @param  This                  A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param  GlyphBuffer           A pointer to the buffer that contains glyph data.\r
+  @param  Foreground            The foreground setting requested to be used for the\r
+                                generated BltBuffer data.\r
+  @param  Background            The background setting requested to be used for the\r
+                                generated BltBuffer data.\r
+  @param  Count                 The entry in the BltBuffer upon which to act.\r
+  @param  Width                 The width in bits of the glyph being converted.\r
+  @param  Height                The height in bits of the glyph being converted\r
+  @param  BltBuffer             A pointer to the buffer that contains the data that is\r
+                                ready to be used by the UGA BLT routines.\r
+\r
+  @retval EFI_SUCCESS           It worked.\r
+  @retval EFI_NOT_FOUND         A glyph for a character was not found.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_HII_GLYPH_TO_BLT) (\r
+  IN     EFI_HII_PROTOCOL             *This,\r
+  IN     UINT8                        *GlyphBuffer,\r
+  IN     EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground,\r
+  IN     EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background,\r
+  IN     UINTN                         Count,\r
+  IN     UINTN                         Width,\r
+  IN     UINTN                         Height,\r
+  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer\r
+  );\r
+\r
+/**\r
+  Allows a new string to be added to an already existing string package.\r
+\r
+  @param  This                  A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param  Pointer               to a NULL-terminated string containing a single ISO 639-2\r
+                                language identifier, indicating the language in which the string is translated.\r
+  @param  Handle                The handle of the language pack to which the string is to be added.\r
+  @param  Reference             The identifier of the string to be added. If the reference\r
+                                value is zero, then the string will be assigned a new identifier on that\r
+                                handle for the language specified. Otherwise, the string will be updated\r
+                                with the NewString Value.\r
+  @param  NewString             The string to be added.\r
+\r
+  @retval EFI_SUCCESS           The string was effectively registered.\r
+  @retval EFI_INVALID_PARAMETER The Handle was unknown.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_HII_NEW_STRING) (\r
+  IN     EFI_HII_PROTOCOL      *This,\r
+  IN     CHAR16                *Language,\r
+  IN     EFI_HII_HANDLE        Handle,\r
+  IN OUT STRING_REF            *Reference,\r
+  IN     CHAR16                *NewString\r
+  );\r
+\r
+/**\r
+  Allows a program to determine the primary languages that are supported\r
+  on a given handle.\r
+\r
+  @param  This                  A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param  Handle                The handle on which the strings reside.\r
+  @param  LanguageString        A string allocated by GetPrimaryLanguages() that\r
+                                contains a list of all primary languages registered on the handle.\r
+\r
+  @retval EFI_SUCCESS           LanguageString was correctly returned.\r
+  @retval EFI_INVALID_PARAMETER The Handle was unknown.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_HII_GET_PRI_LANGUAGES) (\r
+  IN  EFI_HII_PROTOCOL    *This,\r
+  IN  EFI_HII_HANDLE      Handle,\r
+  OUT EFI_STRING          *LanguageString\r
+  );\r
+\r
+/**\r
+  Allows a program to determine which secondary languages are supported\r
+  on a given handle for a given primary language.\r
+\r
+  @param  This                  A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param  Handle                The handle on which the strings reside.\r
+  @param  PrimaryLanguage       Pointer to a NULL-terminated string containing a single\r
+                                ISO 639-2 language identifier, indicating the primary language.\r
+  @param  LanguageString        A string allocated by GetSecondaryLanguages()\r
+                                containing a list of all secondary languages registered on the handle.\r
+\r
+  @retval EFI_SUCCESS           LanguageString was correctly returned.\r
+  @retval EFI_INVALID_PARAMETER The Handle was unknown.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_HII_GET_SEC_LANGUAGES) (\r
+  IN  EFI_HII_PROTOCOL    *This,\r
+  IN  EFI_HII_HANDLE      Handle,\r
+  IN  CHAR16              *PrimaryLanguage,\r
+  OUT EFI_STRING          *LanguageString\r
+  );\r
+\r
+/**\r
+  Extracts a string from a package already registered with the EFI HII database.\r
+\r
+  @param  This                  A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param  Handle                The handle on which the string resides.\r
+  @param  Token                 The string token assigned to the string.\r
+  @param  Raw                   If TRUE, the string is returned unedited in the internal\r
+                                storage format described above. If false, the string returned is edited\r
+                                by replacing <cr> with <space> and by removing special characters such\r
+                                as the <wide> prefix.\r
+  @param  LanguageString        Pointer to a NULL-terminated string containing a\r
+                                single ISO 639-2 language identifier, indicating the language to print.\r
+                                If the LanguageString is empty (starts with a NULL), the default system\r
+                                language will be used to determine the language.\r
+  @param  BufferLength          Length of the StringBuffer.\r
+  @param  StringBuffer          The buffer designed to receive the characters in the string.\r
+\r
+  @retval EFI_SUCCESS           StringBuffer is filled with a NULL-terminated string.\r
+  @retval EFI_INVALID_PARAMETER The handle or string token is unknown.\r
+  @retval EFI_BUFFER_TOO_SMALL  The buffer provided was not large enough to\r
+                                allow the entire string to be stored.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_HII_GET_STRING) (\r
+  IN     EFI_HII_PROTOCOL  *This,\r
+  IN     EFI_HII_HANDLE    Handle,\r
+  IN     STRING_REF        Token,\r
+  IN     BOOLEAN           Raw,\r
+  IN     CHAR16            *LanguageString,\r
+  IN OUT UINTN             *BufferLength,\r
+  OUT    EFI_STRING        StringBuffer\r
+  );\r
+\r
+/**\r
+  Allows a program to extract a part of a string of not more than a given width.\r
+\r
+  @param  This                  A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param  Handle                The handle on which the string resides.\r
+  @param  Token                 The string token assigned to the string.\r
+  @param  Index                 On input, the offset into the string where the line is to start.\r
+                                On output, the index is updated to point to beyond the last character returned\r
+                                in the call.\r
+  @param  LineWidth             The maximum width of the line in units of narrow glyphs.\r
+  @param  LanguageString        Pointer to a NULL-terminated string containing a\r
+                                single ISO 639-2 language identifier, indicating the language to print.\r
+  @param  BufferLength          Pointer to the length of the StringBuffer.\r
+  @param  StringBuffer          The buffer designed to receive the characters in the string.\r
+\r
+  @retval EFI_SUCCESS           StringBuffer filled with characters that will fit on the line.\r
+  @retval EFI_NOT_FOUND         The font glyph for at least one of the characters in\r
+                                the string is not in the font database.\r
+  @retval EFI_BUFFER_TOO_SMALL  The buffer provided was not large enough\r
+                                to allow the entire string to be stored.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_HII_GET_LINE) (\r
+  IN     EFI_HII_PROTOCOL  *This,\r
+  IN     EFI_HII_HANDLE    Handle,\r
+  IN     STRING_REF        Token,\r
+  IN OUT UINT16            *Index,\r
+  IN     UINT16            LineWidth,\r
+  IN     CHAR16            *LanguageString,\r
+  IN OUT UINT16            *BufferLength,\r
+  OUT    EFI_STRING        StringBuffer\r
+  );\r
+\r
+/**\r
+  Allows a program to extract a form or form package that has previously\r
+  been registered with the HII database.\r
+\r
+  @param  This                  A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param  Handle                Handle on which the form resides.\r
+  @param  FormId                The ID of the form to return. If the ID is zero,\r
+                                the entire form package is returned.\r
+  @param  BufferLength          On input, the length of the Buffer. On output,\r
+                                the length of the returned buffer,\r
+  @param  Buffer                The buffer designed to receive the form(s).\r
+\r
+  @retval EFI_SUCCESS           Buffer filled with the requested forms. BufferLength\r
+                                was updated.\r
+  @retval EFI_INVALID_PARAMETER The handle is unknown.\r
+  @retval EFI_NOT_FOUND         A form on the requested handle cannot be found with\r
+                                the requested FormId.\r
+  @retval EFI_BUFFER_TOO_SMALL  The buffer provided was not large enough\r
+                                to allow the form to be stored.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_HII_GET_FORMS) (\r
+  IN     EFI_HII_PROTOCOL  *This,\r
+  IN     EFI_HII_HANDLE    Handle,\r
+  IN     EFI_FORM_ID       FormId,\r
+  IN OUT UINTN             *BufferLength,\r
+  OUT    UINT8             *Buffer\r
+  );\r
+\r
+/**\r
+  Extracts the defaults that are associated with a given handle in the HII database.\r
+\r
+  @param  This                  A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param  Handle                The HII handle from which will have default data retrieved.\r
+  @param  DefaultMask           The mask used to specify some type of default override when extracting\r
+                                the default image data.\r
+  @param  VariablePackList      A indirect pointer to the first entry of a link list with\r
+                                type EFI_HII_VARIABLE_PACK_LIST.\r
+\r
+  @retval EFI_SUCCESS           The VariablePackList was populated with the appropriate\r
+                                default setting data.\r
+  @retval EFI_NOT_FOUND         The IFR does not have any explicit or default map(s).\r
+  @retval EFI_INVALID_PARAMETER The HII database entry associated with Handle\r
+                                contain invalid data.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_HII_GET_DEFAULT_IMAGE) (\r
+  IN     EFI_HII_PROTOCOL           *This,\r
+  IN     EFI_HII_HANDLE             Handle,\r
+  IN     UINTN                      DefaultMask,\r
+  OUT    EFI_HII_VARIABLE_PACK_LIST **VariablePackList\r
+  );\r
+\r
+/**\r
+  Allows the caller to update a form or form package that has previously been\r
+  registered with the EFI HII database.\r
+\r
+  @param  This                  A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param  Handle                Handle of the package where the form to be updated resides.\r
+  @param  Label                 The label inside the form package where the update is to take place.\r
+  @param  AddData               If TRUE, adding data at a given Label; otherwise,\r
+                                if FALSE, removing data at a given Label.\r
+  @param  Data                  The buffer containing the new tags to insert after the Label\r
+\r
+  @retval EFI_SUCCESS           The form was updated with the new tags.\r
+  @retval EFI_INVALID_PARAMETER The buffer for the buffer length does not\r
+                                contain an integral number of tags.\r
+  @retval EFI_NOT_FOUND         The Handle, Label, or FormId was not found.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_HII_UPDATE_FORM) (\r
+  IN EFI_HII_PROTOCOL     *This,\r
+  IN EFI_HII_HANDLE       Handle,\r
+  IN EFI_FORM_LABEL       Label,\r
+  IN BOOLEAN              AddData,\r
+  IN EFI_HII_UPDATE_DATA  *Data\r
+  );\r
+\r
+/**\r
+  Retrieves the current keyboard layout.\r
+\r
+  @param  This                  A pointer to the EFI_HII_PROTOCOL instance.\r
+  @param  DescriptorCount       A pointer to the number of Descriptor entries being\r
+                                described in the keyboard layout being retrieved.\r
+  @param  Descriptor            A pointer to a buffer containing an array of EFI_KEY_DESCRIPTOR\r
+                                entries. Each entry will reflect the definition of a specific physical key.\r
+\r
+  @retval EFI_SUCCESS           The keyboard layout was retrieved successfully.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_HII_GET_KEYBOARD_LAYOUT) (\r
+  IN     EFI_HII_PROTOCOL    *This,\r
+  OUT    UINT16              *DescriptorCount,\r
+  OUT    EFI_KEY_DESCRIPTOR  *Descriptor\r
+  );\r
+\r
+/**\r
+  @par Protocol Description:\r
+  The HII Protocol manages the HII database, which is a repository for data\r
+  having to do with fonts, strings, forms, keyboards, and other future human\r
+  interface items.\r
+\r
+  @param NewPack\r
+  Extracts the various packs from a package list.\r
+\r
+  @param RemovePack\r
+  Removes a package from the HII database.\r
+\r
+  @param FindHandles\r
+  Determines the handles that are currently active in the database.\r
+\r
+  @param ExportDatabase\r
+  Export the entire contents of the database to a buffer.\r
+\r
+  @param TestString\r
+  Tests if all of the characters in a string have corresponding font characters.\r
+\r
+  @param GetGlyph\r
+  Translates a Unicode character into the corresponding font glyph.\r
+\r
+  @param GlyphToBlt\r
+  Converts a glyph value into a format that is ready for a UGA BLT command.\r
+\r
+  @param NewString\r
+  Allows a new string to be added to an already existing string package.\r
+\r
+  @param GetPrimaryLanguages\r
+  Allows a program to determine the primary languages that are supported\r
+  on a given handle.\r
+\r
+  @param GetSecondaryLanguages\r
+  Allows a program to determine which secondary languages are supported\r
+  on a given handle for a given primary language.\r
+\r
+  @param GetString\r
+  Extracts a string from a package that is already registered with the\r
+  EFI HII database.\r
+\r
+  @param ResetString\r
+  Remove any new strings that were added after the initial string export\r
+  for this handle.\r
+\r
+  @param GetLine\r
+  Allows a program to extract a part of a string of not more than a given width.\r
+\r
+  @param GetForms\r
+  Allows a program to extract a form or form package that has been previously registered.\r
+\r
+  @param GetDefaultImage\r
+  Allows a program to extract the nonvolatile image that represents the default storage image.\r
+\r
+  @param UpdateForm\r
+  Allows a program to update a previously registered form.\r
+\r
+  @param GetKeyboardLayout\r
+  Allows a program to extract the current keyboard layout.\r
+\r
+**/\r
+struct _EFI_HII_PROTOCOL {\r
+  EFI_HII_NEW_PACK            NewPack;\r
+  EFI_HII_REMOVE_PACK         RemovePack;\r
+  EFI_HII_FIND_HANDLES        FindHandles;\r
+  EFI_HII_EXPORT              ExportDatabase;\r
+\r
+  EFI_HII_TEST_STRING         TestString;\r
+  EFI_HII_GET_GLYPH           GetGlyph;\r
+  EFI_HII_GLYPH_TO_BLT        GlyphToBlt;\r
+\r
+  EFI_HII_NEW_STRING          NewString;\r
+  EFI_HII_GET_PRI_LANGUAGES   GetPrimaryLanguages;\r
+  EFI_HII_GET_SEC_LANGUAGES   GetSecondaryLanguages;\r
+  EFI_HII_GET_STRING          GetString;\r
+  EFI_HII_RESET_STRINGS       ResetStrings;\r
+  EFI_HII_GET_LINE            GetLine;\r
+  EFI_HII_GET_FORMS           GetForms;\r
+  EFI_HII_GET_DEFAULT_IMAGE   GetDefaultImage;\r
+  EFI_HII_UPDATE_FORM         UpdateForm;\r
+\r
+  EFI_HII_GET_KEYBOARD_LAYOUT GetKeyboardLayout;\r
+};\r
+\r
+extern EFI_GUID gEfiHiiProtocolGuid;\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Core/DxeIplPeim/CommonHeader.h b/MdeModulePkg/Core/DxeIplPeim/CommonHeader.h
new file mode 100644 (file)
index 0000000..2240f6d
--- /dev/null
@@ -0,0 +1,56 @@
+/**@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) 2006 - 2007, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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/DxeIpl.h>\r
+#include <Ppi/S3Resume.h>\r
+#include <Protocol/EdkDecompress.h>\r
+#include <Ppi/EndOfPeiPhase.h>\r
+#include <Protocol/CustomizedDecompress.h>\r
+#include <Protocol/Decompress.h>\r
+#include <Ppi/Security.h>\r
+#include <Ppi/SectionExtraction.h>\r
+#include <Ppi/LoadFile.h>\r
+#include <Ppi/RecoveryModule.h>\r
+#include <Ppi/MemoryDiscovered.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeimEntryPoint.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
+#include <Library/CacheMaintenanceLib.h>\r
+#include <Library/PeCoffLoaderLib.h>\r
+#include <Library/UefiDecompressLib.h>\r
+#include <Library/CustomDecompressLib.h>\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/PeCoffLib.h>\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.dxs b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.dxs
new file mode 100644 (file)
index 0000000..015c180
--- /dev/null
@@ -0,0 +1,28 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  DxeIpl.dxs\r
+\r
+Abstract:\r
+\r
+  Dependency expression file for DXE Initial Program Loader PEIM.\r
+  \r
+--*/  \r
+\r
+#include <PeimDepex.h>\r
+\r
+DEPENDENCY_START\r
+   EFI_PEI_PERMANENT_MEMORY_INSTALLED_PPI_GUID\r
+DEPENDENCY_END\r
+\r
+\r
diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.h b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.h
new file mode 100644 (file)
index 0000000..5315b8b
--- /dev/null
@@ -0,0 +1,117 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  DxeIpl.h\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+#ifndef __PEI_DXEIPL_H__\r
+#define __PEI_DXEIPL_H__\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#define STACK_SIZE      0x20000\r
+#define BSP_STORE_SIZE  0x4000\r
+\r
+#define GET_OCCUPIED_SIZE(ActualSize, Alignment) ((ActualSize + (Alignment - 1)) & ~(Alignment - 1))\r
+\r
+extern BOOLEAN gInMemory;\r
+\r
+EFI_STATUS\r
+PeiFindFile (\r
+  IN  UINT8                  Type,\r
+  IN  UINT16                 SectionType,\r
+  OUT EFI_GUID               *FileName,\r
+  OUT VOID                   **Pe32Data\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+PeiLoadFile (\r
+  IN  EFI_PEI_PE_COFF_LOADER_PROTOCOL           *PeiEfiPeiPeCoffLoader,\r
+  IN  VOID                                      *Pe32Data,\r
+  OUT EFI_PHYSICAL_ADDRESS                      *ImageAddress,\r
+  OUT UINT64                                    *ImageSize,\r
+  OUT EFI_PHYSICAL_ADDRESS                      *EntryPoint\r
+  )\r
+;\r
+\r
+\r
+EFI_STATUS\r
+GetImageReadFunction (\r
+  IN      PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+PeiImageRead (\r
+  IN     VOID    *FileHandle,\r
+  IN     UINTN   FileOffset,\r
+  IN OUT UINTN   *ReadSize,\r
+  OUT    VOID    *Buffer\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+DxeIplLoadFile (\r
+  IN EFI_PEI_FV_FILE_LOADER_PPI                 *This,\r
+  IN  EFI_FFS_FILE_HEADER                       *FfsHeader,\r
+  OUT EFI_PHYSICAL_ADDRESS                      *ImageAddress,\r
+  OUT UINT64                                    *ImageSize,\r
+  OUT EFI_PHYSICAL_ADDRESS                      *EntryPoint\r
+  );\r
+\r
+EFI_STATUS\r
+ShadowDxeIpl (\r
+  IN EFI_FFS_FILE_HEADER                       *DxeIpl,\r
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL           *PeiEfiPeiPeCoffLoader\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+DxeLoadCore (\r
+  IN EFI_DXE_IPL_PPI       *This,\r
+  IN EFI_PEI_SERVICES      **PeiServices,\r
+  IN EFI_PEI_HOB_POINTERS  HobList\r
+  );\r
+\r
+VOID\r
+HandOffToDxeCore (\r
+  IN EFI_PHYSICAL_ADDRESS   DxeCoreEntryPoint,\r
+  IN EFI_PEI_HOB_POINTERS   HobList,\r
+  IN EFI_PEI_PPI_DESCRIPTOR *EndOfPeiSignal\r
+  );\r
+\r
+EFI_STATUS\r
+PeiProcessFile (\r
+  IN      UINT16                 SectionType,\r
+  IN      EFI_FFS_FILE_HEADER    *FfsFileHeader,\r
+  OUT     VOID                   **Pe32Data,\r
+  IN      EFI_PEI_HOB_POINTERS   *OrigHob\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PeimInitializeDxeIpl (\r
+  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r
+  IN EFI_PEI_SERVICES          **PeiServices\r
+  );\r
+\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
new file mode 100644 (file)
index 0000000..96e578f
--- /dev/null
@@ -0,0 +1,171 @@
+#/** @file\r
+# Component description file for DxeIpl module\r
+#\r
+# The responsibility of this module is to load the DXE Core from a Firmware Volume. This implementation i used to load a 32-bit DXE Core.\r
+# Copyright (c) 2006 - 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                      = DxeIpl\r
+  FILE_GUID                      = 86D70125-BAA3-4296-A62F-602BEBBB9081\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = PeimInitializeDxeIpl\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
+  DxeIpl.h\r
+  DxeLoad.c\r
+  CommonHeader.h\r
+\r
+[Sources.Ia32]\r
+  Ia32/VirtualMemory.h\r
+  Ia32/VirtualMemory.c\r
+  Ia32/DxeLoadFunc.c\r
+  Ia32/ImageRead.c\r
+\r
+[Sources.X64]\r
+  X64/DxeLoadFunc.c\r
+  Ia32/ImageRead.c\r
+\r
+[Sources.IPF]\r
+  Ipf/DxeLoadFunc.c\r
+  Ipf/ImageRead.c\r
+\r
+[Sources.EBC]\r
+  X64/DxeLoadFunc.c\r
+  Ia32/ImageRead.c\r
+\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
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.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
+  PeCoffLib\r
+  PcdLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  PeiServicesTablePointerLib\r
+  CustomDecompressLib\r
+  TianoDecompressLib\r
+  UefiDecompressLib\r
+  EdkPeCoffLoaderLib\r
+  CacheMaintenanceLib\r
+  ReportStatusCodeLib\r
+  PeiServicesLib\r
+  HobLib\r
+  BaseLib\r
+  PeimEntryPoint\r
+  DebugLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Guid C Name Section - list of Guids that this module uses or produces.\r
+#\r
+################################################################################\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
+  gEfiCustomizedDecompressProtocolGuid          # PROTOCOL SOMETIMES_PRODUCED\r
+  gEfiTianoDecompressProtocolGuid               # PROTOCOL SOMETIMES_PRODUCED\r
+  gEfiDecompressProtocolGuid                    # PROTOCOL SOMETIMES_PRODUCED\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
+  gEfiPeiSecurityPpiGuid                        # PPI SOMETIMES_CONSUMED\r
+  gEfiPeiSectionExtractionPpiGuid               # PPI SOMETIMES_CONSUMED\r
+  gEfiPeiS3ResumePpiGuid                        # PPI SOMETIMES_CONSUMED\r
+  gEfiPeiRecoveryModulePpiGuid                  # PPI SOMETIMES_CONSUMED\r
+  gEfiEndOfPeiSignalPpiGuid                     # PPI SOMETIMES_PRODUCED\r
+  gEfiPeiFvFileLoaderPpiGuid                    # PPI SOMETIMES_PRODUCED\r
+  gEfiDxeIplPpiGuid                             # PPI SOMETIMES_PRODUCED\r
+  gEfiPeiPeCoffLoaderGuid                       \r
+\r
+\r
+################################################################################\r
+#\r
+# Pcd FEATURE_FLAG - list of PCDs that this module is coded for.\r
+#\r
+################################################################################\r
+\r
+[PcdsFeatureFlag.common]\r
+  PcdDxeIplSupportCustomDecompress|gEfiEdkModulePkgTokenSpaceGuid\r
+  PcdDxeIplSupportTianoDecompress|gEfiEdkModulePkgTokenSpaceGuid\r
+  PcdDxeIplSupportEfiDecompress|gEfiEdkModulePkgTokenSpaceGuid\r
+  PcdDxeIplBuildShareCodeHobs|gEfiEdkModulePkgTokenSpaceGuid\r
+\r
+[PcdsFeatureFlag.IA32]\r
+  PcdDxeIplSwitchToLongMode|gEfiMdeModulePkgTokenSpaceGuid\r
+\r
+\r
+################################################################################\r
+#\r
+# Dependency Expression Section - list of Dependency expressions that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Depex]\r
+  gEfiPeiMemoryDiscoveredPpiGuid\r
+\r
diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.msa b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.msa
new file mode 100644 (file)
index 0000000..c552966
--- /dev/null
@@ -0,0 +1,168 @@
+<?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>DxeIpl</ModuleName>\r
+    <ModuleType>PEIM</ModuleType>\r
+    <GuidValue>86D70125-BAA3-4296-A62F-602BEBBB9081</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for DxeIpl module</Abstract>\r
+    <Description>The responsibility of this module is to load the DXE Core from a Firmware Volume.  This implementation i used to load a 32-bit DXE Core.</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>DxeIpl</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeimEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>HobLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeiServicesLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>ReportStatusCodeLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>CacheMaintenanceLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>EdkPeCoffLoaderLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDecompressLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>TianoDecompressLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>CustomDecompressLib</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>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PcdLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeCoffLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>DxeLoad.c</Filename>\r
+    <Filename>DxeIpl.h</Filename>\r
+    <Filename>DxeIpl.dxs</Filename>\r
+    <Filename SupArchList="IA32 X64 EBC">Ia32/ImageRead.c</Filename>\r
+    <Filename SupArchList="IA32">Ia32/DxeLoadFunc.c</Filename>\r
+    <Filename SupArchList="IA32">Ia32/VirtualMemory.c</Filename>\r
+    <Filename SupArchList="IA32">Ia32/VirtualMemory.h</Filename>\r
+    <Filename SupArchList="X64 EBC">X64/DxeLoadFunc.c</Filename>\r
+    <Filename SupArchList="IPF">Ipf/ImageRead.c</Filename>\r
+    <Filename SupArchList="IPF">Ipf/DxeLoadFunc.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="SOMETIMES_PRODUCED">\r
+      <ProtocolCName>gEfiDecompressProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="SOMETIMES_PRODUCED">\r
+      <ProtocolCName>gEfiTianoDecompressProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="SOMETIMES_PRODUCED">\r
+      <ProtocolCName>gEfiCustomizedDecompressProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <PPIs>\r
+    <Ppi Usage="SOMETIMES_PRODUCED">\r
+      <PpiCName>gEfiDxeIplPpiGuid</PpiCName>\r
+    </Ppi>\r
+    <Ppi Usage="SOMETIMES_PRODUCED">\r
+      <PpiCName>gEfiPeiFvFileLoaderPpiGuid</PpiCName>\r
+    </Ppi>\r
+    <Ppi Usage="SOMETIMES_PRODUCED">\r
+      <PpiCName>gEfiEndOfPeiSignalPpiGuid</PpiCName>\r
+    </Ppi>\r
+    <Ppi Usage="SOMETIMES_CONSUMED">\r
+      <PpiCName>gEfiPeiRecoveryModulePpiGuid</PpiCName>\r
+    </Ppi>\r
+    <Ppi Usage="SOMETIMES_CONSUMED">\r
+      <PpiCName>gEfiPeiS3ResumePpiGuid</PpiCName>\r
+    </Ppi>\r
+    <Ppi Usage="SOMETIMES_CONSUMED">\r
+      <PpiCName>gEfiPeiSectionExtractionPpiGuid</PpiCName>\r
+    </Ppi>\r
+    <Ppi Usage="SOMETIMES_CONSUMED">\r
+      <PpiCName>gEfiPeiSecurityPpiGuid</PpiCName>\r
+    </Ppi>\r
+  </PPIs>\r
+  <Guids>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiPeiPeCoffLoaderGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>PeimInitializeDxeIpl</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+  <PcdCoded>\r
+    <PcdEntry PcdItemType="FEATURE_FLAG" Usage="ALWAYS_CONSUMED" SupArchList="IA32">\r
+      <C_Name>PcdDxeIplSwitchToLongMode</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkModulePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <DefaultValue>TRUE</DefaultValue>\r
+      <HelpText>If this feature is enabled, then the DXE IPL will load a 64-bit DxeCore.</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="FEATURE_FLAG" Usage="ALWAYS_CONSUMED">\r
+      <C_Name>PcdDxeIplBuildShareCodeHobs</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkModulePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <DefaultValue>FALSE</DefaultValue>\r
+      <HelpText>If this feature is enabled, DXE IPL will build a series of HOBs to share code with DXE Core.</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="FEATURE_FLAG" Usage="ALWAYS_CONSUMED">\r
+      <C_Name>PcdDxeIplSupportEfiDecompress</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkModulePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <DefaultValue>TRUE</DefaultValue>\r
+      <HelpText>If this feature is enabled, then the DXE IPL must support decompressing files compressed with the EFI Compression algorithm</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="FEATURE_FLAG" Usage="ALWAYS_CONSUMED">\r
+      <C_Name>PcdDxeIplSupportTianoDecompress</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkModulePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <DefaultValue>TRUE</DefaultValue>\r
+      <HelpText>If this feature is enabled, then the DXE IPL must support decompressing files compressed with the Tiano Compression algorithm</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="FEATURE_FLAG" Usage="ALWAYS_CONSUMED">\r
+      <C_Name>PcdDxeIplSupportCustomDecompress</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkModulePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <DefaultValue>TRUE</DefaultValue>\r
+      <HelpText>If this feature is enabled, then the DXE IPL must support decompressing files compressed with the Custom Compression algorithm</HelpText>\r
+    </PcdEntry>\r
+  </PcdCoded>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c b/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c
new file mode 100644 (file)
index 0000000..eec1d86
--- /dev/null
@@ -0,0 +1,980 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  DxeLoad.c\r
+\r
+Abstract:\r
+\r
+  Last PEIM.\r
+  Responsibility of this module is to load the DXE Core from a Firmware Volume.\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "DxeIpl.h"\r
+\r
+// porting note remove later\r
+#include "Common/DecompressLibraryHob.h"\r
+#include "FrameworkPei.h"\r
+// end of remove later\r
+\r
+BOOLEAN gInMemory = FALSE;\r
+\r
+//\r
+// Module Globals used in the DXE to PEI handoff\r
+// These must be module globals, so the stack can be switched\r
+//\r
+static EFI_DXE_IPL_PPI mDxeIplPpi = {\r
+  DxeLoadCore\r
+};\r
+\r
+static EFI_PEI_FV_FILE_LOADER_PPI mLoadFilePpi = {\r
+  DxeIplLoadFile\r
+};\r
+\r
+static EFI_PEI_PPI_DESCRIPTOR     mPpiList[] = {\r
+  {\r
+  EFI_PEI_PPI_DESCRIPTOR_PPI,\r
+  &gEfiPeiFvFileLoaderPpiGuid,\r
+  &mLoadFilePpi\r
+  },\r
+  {\r
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+  &gEfiDxeIplPpiGuid,\r
+  &mDxeIplPpi\r
+  }\r
+};\r
+\r
+static EFI_PEI_PPI_DESCRIPTOR     mPpiSignal = {\r
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+  &gEfiEndOfPeiSignalPpiGuid,\r
+  NULL\r
+};\r
+\r
+GLOBAL_REMOVE_IF_UNREFERENCED DECOMPRESS_LIBRARY  gEfiDecompress = {\r
+  UefiDecompressGetInfo,\r
+  UefiDecompress\r
+};\r
+\r
+GLOBAL_REMOVE_IF_UNREFERENCED DECOMPRESS_LIBRARY  gCustomDecompress = {\r
+  CustomDecompressGetInfo,\r
+  CustomDecompress\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PeimInitializeDxeIpl (\r
+  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r
+  IN EFI_PEI_SERVICES          **PeiServices\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Initializes the Dxe Ipl PPI\r
+\r
+Arguments:\r
+\r
+  FfsHeader   - Pointer to FFS file header\r
+  PeiServices - General purpose services available to every PEIM.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                                Status;\r
+  EFI_PEI_PE_COFF_LOADER_PROTOCOL           *PeiEfiPeiPeCoffLoader;\r
+  EFI_BOOT_MODE                             BootMode;\r
+\r
+  Status = PeiServicesGetBootMode (&BootMode);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  if (!gInMemory && (BootMode != BOOT_ON_S3_RESUME)) {   \r
+    //\r
+    // The DxeIpl has not yet been shadowed\r
+    //\r
+    PeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)GetPeCoffLoaderProtocol ();\r
+\r
+    //\r
+    // Shadow DxeIpl and then re-run its entry point\r
+    //\r
+    Status = ShadowDxeIpl (FfsHeader, PeiEfiPeiPeCoffLoader);\r
+  } else {\r
+    //\r
+    // Install FvFileLoader and DxeIpl PPIs.\r
+    //\r
+    Status = PeiServicesInstallPpi (mPpiList);\r
+    ASSERT_EFI_ERROR(Status);\r
+  }\r
+  \r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+DxeLoadCore (\r
+  IN EFI_DXE_IPL_PPI       *This,\r
+  IN EFI_PEI_SERVICES      **PeiServices,\r
+  IN EFI_PEI_HOB_POINTERS  HobList\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Main entry point to last PEIM\r
+\r
+Arguments:\r
+  This         - Entry point for DXE IPL PPI\r
+  PeiServices  - General purpose services available to every PEIM.\r
+  HobList      - Address to the Pei HOB list\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS          - DEX core was successfully loaded.\r
+  EFI_OUT_OF_RESOURCES - There are not enough resources to load DXE core.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                                Status;\r
+  EFI_GUID                                  DxeCoreFileName;\r
+  EFI_GUID                                  FirmwareFileName;\r
+  VOID                                      *Pe32Data;\r
+  VOID                                      *FvImageData;     \r
+  EFI_PHYSICAL_ADDRESS                      DxeCoreAddress;\r
+  UINT64                                    DxeCoreSize;\r
+  EFI_PHYSICAL_ADDRESS                      DxeCoreEntryPoint;\r
+  EFI_PEI_PE_COFF_LOADER_PROTOCOL           *PeiEfiPeiPeCoffLoader;\r
+  EFI_BOOT_MODE                             BootMode;\r
+  EFI_PEI_RECOVERY_MODULE_PPI               *PeiRecovery;\r
+  EFI_PEI_S3_RESUME_PPI                     *S3Resume;\r
+\r
+//  PERF_START (PeiServices, L"DxeIpl", NULL, 0);\r
+\r
+  //\r
+  // if in S3 Resume, restore configure\r
+  //\r
+  Status = PeiServicesGetBootMode (&BootMode);\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  if (BootMode == BOOT_ON_S3_RESUME) {\r
+    Status = PeiServicesLocatePpi (\r
+               &gEfiPeiS3ResumePpiGuid,\r
+               0,\r
+               NULL,\r
+               (VOID **)&S3Resume\r
+               );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    Status = S3Resume->S3RestoreConfig (PeiServices);\r
+    ASSERT_EFI_ERROR (Status);\r
+  } else if (BootMode == BOOT_IN_RECOVERY_MODE) {\r
+\r
+    Status = PeiServicesLocatePpi (\r
+               &gEfiPeiRecoveryModulePpiGuid,\r
+               0,\r
+               NULL,\r
+               (VOID **)&PeiRecovery\r
+               );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    Status = PeiRecovery->LoadRecoveryCapsule (PeiServices, PeiRecovery);\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "Load Recovery Capsule Failed.(Status = %r)\n", Status));\r
+      CpuDeadLoop ();\r
+    }\r
+\r
+    //\r
+    // Now should have a HOB with the DXE core w/ the old HOB destroyed\r
+    //\r
+  }\r
+\r
+  //\r
+  // Install the PEI Protocols that are shared between PEI and DXE\r
+  //\r
+  PeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)GetPeCoffLoaderProtocol ();\r
+  ASSERT (PeiEfiPeiPeCoffLoader != NULL);\r
+\r
+\r
+  //\r
+  // Find the EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE type compressed Firmware Volume file\r
+  // The file found will be processed by PeiProcessFile: It will first be decompressed to\r
+  // a normal FV, then a corresponding FV type hob will be built. \r
+  //\r
+  Status = PeiFindFile (\r
+             EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE,\r
+             EFI_SECTION_FIRMWARE_VOLUME_IMAGE,\r
+             &FirmwareFileName,\r
+             &FvImageData\r
+             );\r
+\r
+  //\r
+  // Find the DXE Core in a Firmware Volume\r
+  //\r
+  Status = PeiFindFile (\r
+            EFI_FV_FILETYPE_DXE_CORE,\r
+            EFI_SECTION_PE32,\r
+            &DxeCoreFileName,\r
+            &Pe32Data\r
+            );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Load the DXE Core from a Firmware Volume\r
+  //\r
+  Status = PeiLoadFile (\r
+             PeiEfiPeiPeCoffLoader,\r
+             Pe32Data,\r
+             &DxeCoreAddress,\r
+             &DxeCoreSize,\r
+             &DxeCoreEntryPoint\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Add HOB for the DXE Core\r
+  //\r
+  BuildModuleHob (\r
+    &DxeCoreFileName,\r
+    DxeCoreAddress,\r
+    DxeCoreSize,\r
+    DxeCoreEntryPoint\r
+    );\r
+\r
+  //\r
+  // Report Status Code EFI_SW_PEI_PC_HANDOFF_TO_NEXT\r
+  //\r
+  REPORT_STATUS_CODE (\r
+    EFI_PROGRESS_CODE,\r
+    EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_CORE_PC_HANDOFF_TO_NEXT\r
+    );\r
+\r
+  if (FeaturePcdGet (PcdDxeIplBuildShareCodeHobs)) {\r
+    if (FeaturePcdGet (PcdDxeIplSupportEfiDecompress)) {\r
+      //\r
+      // Add HOB for the EFI Decompress Protocol\r
+      //\r
+      BuildGuidDataHob (\r
+        &gEfiDecompressProtocolGuid,\r
+        (VOID *)&gEfiDecompress,\r
+        sizeof (gEfiDecompress)\r
+        );\r
+    }\r
+    if (FeaturePcdGet (PcdDxeIplSupportCustomDecompress)) {\r
+      //\r
+      // Add HOB for the user customized Decompress Protocol\r
+      //\r
+      BuildGuidDataHob (\r
+        &gEfiCustomizedDecompressProtocolGuid,\r
+        (VOID *)&gCustomDecompress,\r
+        sizeof (gCustomDecompress)\r
+        );\r
+    }\r
+\r
+    //\r
+    // Add HOB for the PE/COFF Loader Protocol\r
+    //\r
+    BuildGuidDataHob (\r
+      &gEfiPeiPeCoffLoaderGuid,\r
+      (VOID *)&PeiEfiPeiPeCoffLoader,\r
+      sizeof (VOID *)\r
+      );\r
+  }\r
+\r
+  //\r
+  // Transfer control to the DXE Core\r
+  // The handoff state is simply a pointer to the HOB list\r
+  //\r
+\r
+  DEBUG ((EFI_D_INFO, "DXE Core Entry Point 0x%08x\n", (UINTN) DxeCoreEntryPoint));\r
+  HandOffToDxeCore (DxeCoreEntryPoint, HobList, &mPpiSignal);\r
+  //\r
+  // If we get here, then the DXE Core returned.  This is an error\r
+  // Dxe Core should not return.\r
+  //\r
+  ASSERT (FALSE);\r
+  CpuDeadLoop ();\r
+\r
+  return EFI_OUT_OF_RESOURCES;\r
+}\r
+\r
+EFI_STATUS\r
+PeiFindFile (\r
+  IN  UINT8                  Type,\r
+  IN  UINT16                 SectionType,\r
+  OUT EFI_GUID               *FileName,\r
+  OUT VOID                   **Pe32Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Finds a PE/COFF of a specific Type and SectionType in the Firmware Volumes\r
+  described in the HOB list. Able to search in a compression set in a FFS file.\r
+  But only one level of compression is supported, that is, not able to search\r
+  in a compression set that is within another compression set.\r
+\r
+Arguments:\r
+\r
+  Type        - The Type of file to retrieve\r
+\r
+  SectionType - The type of section to retrieve from a file\r
+\r
+  FileName    - The name of the file found in the Firmware Volume\r
+\r
+  Pe32Data    - Pointer to the beginning of the PE/COFF file found in the Firmware Volume\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS   - The file was found, and the name is returned in FileName, and a pointer to\r
+                  the PE/COFF image is returned in Pe32Data\r
+\r
+  EFI_NOT_FOUND - The file was not found in the Firmware Volumes present in the HOB List\r
+\r
+--*/\r
+{\r
+  EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader;\r
+  EFI_FFS_FILE_HEADER         *FfsFileHeader;\r
+  EFI_STATUS                  Status;\r
+  EFI_PEI_HOB_POINTERS        Hob;\r
+\r
+\r
+  FwVolHeader   = NULL;\r
+  FfsFileHeader = NULL;\r
+  Status        = EFI_SUCCESS;\r
+\r
+  //\r
+  // For each Firmware Volume, look for a specified type\r
+  // of file and break out until no one is found \r
+  //\r
+  Hob.Raw = GetHobList ();\r
+  while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_FV, Hob.Raw)) != NULL) {\r
+    FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) (Hob.FirmwareVolume->BaseAddress);\r
+    //\r
+    // Make sure the FV HOB does not get corrupted.\r
+    //\r
+    ASSERT (FwVolHeader->Signature == EFI_FVH_SIGNATURE);\r
+\r
+    Status = PeiServicesFfsFindNextFile (\r
+               Type,\r
+               FwVolHeader,\r
+               &FfsFileHeader\r
+               );\r
+    if (!EFI_ERROR (Status)) {\r
+      Status = PeiProcessFile (\r
+                 SectionType,\r
+                 FfsFileHeader,\r
+                 Pe32Data,\r
+                 &Hob\r
+                 );\r
+      CopyMem (FileName, &FfsFileHeader->Name, sizeof (EFI_GUID));\r
+      //\r
+      // Find all Fv type ffs to get all FvImage and add them into FvHob\r
+      //\r
+      if (!EFI_ERROR (Status) && (Type != EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE)) {\r
+        return EFI_SUCCESS;\r
+      }\r
+    }\r
+    Hob.Raw = GET_NEXT_HOB (Hob);\r
+  }\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+EFI_STATUS\r
+PeiLoadFile (\r
+  IN  EFI_PEI_PE_COFF_LOADER_PROTOCOL           *PeiEfiPeiPeCoffLoader,\r
+  IN  VOID                                      *Pe32Data,\r
+  OUT EFI_PHYSICAL_ADDRESS                      *ImageAddress,\r
+  OUT UINT64                                    *ImageSize,\r
+  OUT EFI_PHYSICAL_ADDRESS                      *EntryPoint\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Loads and relocates a PE/COFF image into memory.\r
+\r
+Arguments:\r
+\r
+  PeiEfiPeiPeCoffLoader - Pointer to a PE COFF loader protocol\r
+\r
+  Pe32Data         - The base address of the PE/COFF file that is to be loaded and relocated\r
+\r
+  ImageAddress     - The base address of the relocated PE/COFF image\r
+\r
+  ImageSize        - The size of the relocated PE/COFF image\r
+\r
+  EntryPoint       - The entry point of the relocated PE/COFF image\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS   - The file was loaded and relocated\r
+\r
+  EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                            Status;\r
+  PE_COFF_LOADER_IMAGE_CONTEXT          ImageContext;\r
+\r
+  ZeroMem (&ImageContext, sizeof (ImageContext));\r
+  ImageContext.Handle = Pe32Data;\r
+  Status              = GetImageReadFunction (&ImageContext);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = PeiEfiPeiPeCoffLoader->GetImageInfo (PeiEfiPeiPeCoffLoader, &ImageContext);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Allocate Memory for the image\r
+  //\r
+  ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) AllocatePages (EFI_SIZE_TO_PAGES ((UINT32) ImageContext.ImageSize));\r
+  ASSERT (ImageContext.ImageAddress != 0);\r
+\r
+  //\r
+  // Load the image to our new buffer\r
+  //\r
+  Status = PeiEfiPeiPeCoffLoader->LoadImage (PeiEfiPeiPeCoffLoader, &ImageContext);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Relocate the image in our new buffer\r
+  //\r
+  Status = PeiEfiPeiPeCoffLoader->RelocateImage (PeiEfiPeiPeCoffLoader, &ImageContext);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Flush the instruction cache so the image data is written before we execute it\r
+  //\r
+  InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);\r
+\r
+  *ImageAddress = ImageContext.ImageAddress;\r
+  *ImageSize    = ImageContext.ImageSize;\r
+  *EntryPoint   = ImageContext.EntryPoint;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+ShadowDxeIpl (\r
+  IN EFI_FFS_FILE_HEADER                       *DxeIplFileHeader,\r
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL           *PeiEfiPeiPeCoffLoader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Shadow the DXE IPL to a different memory location. This occurs after permanent\r
+  memory has been discovered.\r
+\r
+Arguments:\r
+\r
+  DxeIplFileHeader      - Pointer to the FFS file header of the DXE IPL driver\r
+\r
+  PeiEfiPeiPeCoffLoader - Pointer to a PE COFF loader protocol\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS   - DXE IPL was successfully shadowed to a different memory location.\r
+\r
+  EFI_ ERROR    - The shadow was unsuccessful.\r
+\r
+\r
+--*/\r
+{\r
+  UINTN                     SectionLength;\r
+  UINTN                     OccupiedSectionLength;\r
+  EFI_PHYSICAL_ADDRESS      DxeIplAddress;\r
+  UINT64                    DxeIplSize;\r
+  EFI_PHYSICAL_ADDRESS      DxeIplEntryPoint;\r
+  EFI_STATUS                Status;\r
+  EFI_COMMON_SECTION_HEADER *Section;\r
+\r
+  Section = (EFI_COMMON_SECTION_HEADER *) (DxeIplFileHeader + 1);\r
+\r
+  while ((Section->Type != EFI_SECTION_PE32) && (Section->Type != EFI_SECTION_TE)) {\r
+    SectionLength         = *(UINT32 *) (Section->Size) & 0x00ffffff;\r
+    OccupiedSectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);\r
+    Section               = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) Section + OccupiedSectionLength);\r
+  }\r
+  //\r
+  // Relocate DxeIpl into memory by using loadfile service\r
+  //\r
+  Status = PeiLoadFile (\r
+            PeiEfiPeiPeCoffLoader,\r
+            (VOID *) (Section + 1),\r
+            &DxeIplAddress,\r
+            &DxeIplSize,\r
+            &DxeIplEntryPoint\r
+            );\r
+\r
+  if (Status == EFI_SUCCESS) {\r
+    //\r
+    // Set gInMemory global variable to TRUE to indicate the dxeipl is shadowed.\r
+    //\r
+    *(BOOLEAN *) ((UINTN) &gInMemory + (UINTN) DxeIplEntryPoint - (UINTN) _ModuleEntryPoint) = TRUE;\r
+    Status = ((EFI_PEIM_ENTRY_POINT) (UINTN) DxeIplEntryPoint) ((EFI_PEI_FILE_HANDLE *) DxeIplFileHeader, GetPeiServicesTablePointer());\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+DxeIplLoadFile (\r
+  IN EFI_PEI_FV_FILE_LOADER_PPI                 *This,\r
+  IN  EFI_FFS_FILE_HEADER                       *FfsHeader,\r
+  OUT EFI_PHYSICAL_ADDRESS                      *ImageAddress,\r
+  OUT UINT64                                    *ImageSize,\r
+  OUT EFI_PHYSICAL_ADDRESS                      *EntryPoint\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Given a pointer to an FFS file containing a PE32 image, get the\r
+  information on the PE32 image, and then "load" it so that it\r
+  can be executed.\r
+\r
+Arguments:\r
+\r
+  This  - pointer to our file loader protocol\r
+\r
+  FfsHeader - pointer to the FFS file header of the FFS file that\r
+              contains the PE32 image we want to load\r
+\r
+  ImageAddress  - returned address where the PE32 image is loaded\r
+\r
+  ImageSize     - returned size of the loaded PE32 image\r
+\r
+  EntryPoint    - entry point to the loaded PE32 image\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS  - The FFS file was successfully loaded.\r
+\r
+  EFI_ERROR    - Unable to load the FFS file.\r
+\r
+--*/\r
+{\r
+  EFI_PEI_PE_COFF_LOADER_PROTOCOL           *PeiEfiPeiPeCoffLoader;\r
+  EFI_STATUS                                Status;\r
+  VOID                                      *Pe32Data;\r
+\r
+  Pe32Data = NULL;\r
+  PeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)GetPeCoffLoaderProtocol ();\r
+\r
+  //\r
+  // Preprocess the FFS file to get a pointer to the PE32 information\r
+  // in the enclosed PE32 image.\r
+  //\r
+  Status = PeiProcessFile (\r
+            EFI_SECTION_PE32,\r
+            FfsHeader,\r
+            &Pe32Data,\r
+            NULL\r
+            );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Load the PE image from the FFS file\r
+  //\r
+  Status = PeiLoadFile (\r
+            PeiEfiPeiPeCoffLoader,\r
+            Pe32Data,\r
+            ImageAddress,\r
+            ImageSize,\r
+            EntryPoint\r
+            );\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+PeiProcessFile (\r
+  IN      UINT16                 SectionType,\r
+  IN      EFI_FFS_FILE_HEADER    *FfsFileHeader,\r
+  OUT     VOID                   **Pe32Data,\r
+  IN      EFI_PEI_HOB_POINTERS   *OrigHob\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+  SectionType       - The type of section in the FFS file to process.\r
+\r
+  FfsFileHeader     - Pointer to the FFS file to process, looking for the\r
+                      specified SectionType\r
+\r
+  Pe32Data          - returned pointer to the start of the PE32 image found\r
+                      in the FFS file.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS       - found the PE32 section in the FFS file\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                      Status;\r
+  VOID                            *SectionData;\r
+  DECOMPRESS_LIBRARY              *DecompressLibrary;\r
+  UINT8                           *DstBuffer;\r
+  UINT8                           *ScratchBuffer;\r
+  UINT32                          DstBufferSize;\r
+  UINT32                          ScratchBufferSize;\r
+  EFI_COMMON_SECTION_HEADER       *CmpSection;\r
+  UINTN                           CmpSectionLength;\r
+  UINTN                           OccupiedCmpSectionLength;\r
+  VOID                            *CmpFileData;\r
+  UINTN                           CmpFileSize;\r
+  EFI_COMMON_SECTION_HEADER       *Section;\r
+  UINTN                           SectionLength;\r
+  UINTN                           OccupiedSectionLength;\r
+  UINT64                          FileSize;\r
+  UINT32                          AuthenticationStatus;\r
+  EFI_PEI_SECTION_EXTRACTION_PPI  *SectionExtract;\r
+  UINT32                          BufferSize;\r
+  UINT8                           *Buffer;\r
+  EFI_PEI_SECURITY_PPI            *Security;\r
+  BOOLEAN                         StartCrisisRecovery;\r
+  EFI_GUID                        TempGuid;\r
+  EFI_FIRMWARE_VOLUME_HEADER      *FvHeader;\r
+  EFI_COMPRESSION_SECTION         *CompressionSection;\r
+\r
+  //\r
+  // Initialize local variables.\r
+  //\r
+  DecompressLibrary = NULL;\r
+  DstBuffer         = NULL;\r
+  DstBufferSize     = 0;\r
+\r
+  Status = PeiServicesFfsFindSectionData (\r
+             EFI_SECTION_COMPRESSION,\r
+             FfsFileHeader,\r
+             &SectionData\r
+             );\r
+\r
+  //\r
+  // First process the compression section\r
+  //\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Yes, there is a compression section, so extract the contents\r
+    // Decompress the image here\r
+    //\r
+    Section = (EFI_COMMON_SECTION_HEADER *) (UINTN) (VOID *) ((UINT8 *) (FfsFileHeader) + (UINTN) sizeof (EFI_FFS_FILE_HEADER));\r
+\r
+    do {\r
+      SectionLength         = *(UINT32 *) (Section->Size) & 0x00ffffff;\r
+      OccupiedSectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);\r
+\r
+      //\r
+      // Was the DXE Core file encapsulated in a GUID'd section?\r
+      //\r
+      if (Section->Type == EFI_SECTION_GUID_DEFINED) {\r
+\r
+        //\r
+        // This following code constitutes the addition of the security model\r
+        // to the DXE IPL.\r
+        //\r
+        //\r
+        // Set a default authenticatino state\r
+        //\r
+        AuthenticationStatus = 0;\r
+\r
+        Status = PeiServicesLocatePpi (\r
+                   &gEfiPeiSectionExtractionPpiGuid,\r
+                   0,\r
+                   NULL,\r
+                   (VOID **)&SectionExtract\r
+                   );\r
+\r
+        if (EFI_ERROR (Status)) {\r
+          return Status;\r
+        }\r
+        //\r
+        // Verify Authentication State\r
+        //\r
+        CopyMem (&TempGuid, Section + 1, sizeof (EFI_GUID));\r
+\r
+        Status = SectionExtract->PeiGetSection (\r
+                                  GetPeiServicesTablePointer(),\r
+                                  SectionExtract,\r
+                                  (EFI_SECTION_TYPE *) &SectionType,\r
+                                  &TempGuid,\r
+                                  0,\r
+                                  (VOID **) &Buffer,\r
+                                  &BufferSize,\r
+                                  &AuthenticationStatus\r
+                                  );\r
+\r
+        if (EFI_ERROR (Status)) {\r
+          return Status;\r
+        }\r
+        //\r
+        // If not ask the Security PPI, if exists, for disposition\r
+        //\r
+        //\r
+        Status = PeiServicesLocatePpi (\r
+                   &gEfiPeiSecurityPpiGuid,\r
+                   0,\r
+                   NULL,\r
+                   (VOID **)&Security\r
+                   );\r
+        if (EFI_ERROR (Status)) {\r
+          return Status;\r
+        }\r
+\r
+        Status = Security->AuthenticationState (\r
+                            GetPeiServicesTablePointer(),\r
+                            (struct _EFI_PEI_SECURITY_PPI *) Security,\r
+                            AuthenticationStatus,\r
+                            FfsFileHeader,\r
+                            &StartCrisisRecovery\r
+                            );\r
+\r
+        if (EFI_ERROR (Status)) {\r
+          return Status;\r
+        }\r
+        //\r
+        // If there is a security violation, report to caller and have\r
+        // the upper-level logic possible engender a crisis recovery\r
+        //\r
+        if (StartCrisisRecovery) {\r
+          return EFI_SECURITY_VIOLATION;\r
+        }\r
+      }\r
+\r
+      if (Section->Type == EFI_SECTION_PE32) {\r
+        //\r
+        // This is what we want\r
+        //\r
+        *Pe32Data = (VOID *) (Section + 1);\r
+        return EFI_SUCCESS;\r
+      } else if (Section->Type == EFI_SECTION_COMPRESSION) {\r
+        //\r
+        // This is a compression set, expand it\r
+        //\r
+        CompressionSection  = (EFI_COMPRESSION_SECTION *) Section;\r
+\r
+        switch (CompressionSection->CompressionType) {\r
+        case EFI_STANDARD_COMPRESSION:\r
+          //\r
+          // Load EFI standard compression.\r
+          //\r
+          if (FeaturePcdGet (PcdDxeIplSupportTianoDecompress)) {\r
+            DecompressLibrary = &gEfiDecompress;\r
+          } else {\r
+            ASSERT (FALSE);\r
+            return EFI_NOT_FOUND;\r
+          }\r
+          break;\r
+\r
+        // porting note the original branch for customized compress is removed, it should be change to use GUID compress\r
+\r
+        case EFI_NOT_COMPRESSED:\r
+          //\r
+          // Allocate destination buffer\r
+          //\r
+          DstBufferSize = CompressionSection->UncompressedLength;\r
+          DstBuffer     = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize));\r
+          if (DstBuffer == NULL) {\r
+            return EFI_OUT_OF_RESOURCES;\r
+          }\r
+          //\r
+          // stream is not actually compressed, just encapsulated.  So just copy it.\r
+          //\r
+          CopyMem (DstBuffer, CompressionSection + 1, DstBufferSize);\r
+          break;\r
+\r
+        default:\r
+          //\r
+          // Don't support other unknown compression type.\r
+          //\r
+          ASSERT_EFI_ERROR (Status);\r
+          return EFI_NOT_FOUND;\r
+        }\r
+        \r
+        if (CompressionSection->CompressionType != EFI_NOT_COMPRESSED) {\r
+          //\r
+          // For compressed data, decompress them to dstbuffer.\r
+          //\r
+          Status = DecompressLibrary->GetInfo (\r
+                     (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
+                     (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION),\r
+                     &DstBufferSize,\r
+                     &ScratchBufferSize\r
+                     );\r
+          if (EFI_ERROR (Status)) {\r
+            //\r
+            // GetInfo failed\r
+            //\r
+            DEBUG ((EFI_D_ERROR, "Decompress GetInfo Failed - %r\n", Status));\r
+            return EFI_NOT_FOUND;\r
+          }\r
+  \r
+          //\r
+          // Allocate scratch buffer\r
+          //\r
+          ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));\r
+          if (ScratchBuffer == NULL) {\r
+            return EFI_OUT_OF_RESOURCES;\r
+          }\r
+  \r
+          //\r
+          // Allocate destination buffer\r
+          //\r
+          DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize));\r
+          if (DstBuffer == NULL) {\r
+            return EFI_OUT_OF_RESOURCES;\r
+          }\r
+  \r
+          //\r
+          // Call decompress function\r
+          //\r
+          Status = DecompressLibrary->Decompress (\r
+                      (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
+                      DstBuffer,\r
+                      ScratchBuffer\r
+                      );\r
+          if (EFI_ERROR (Status)) {\r
+            //\r
+            // Decompress failed\r
+            //\r
+            DEBUG ((EFI_D_ERROR, "Decompress Failed - %r\n", Status));\r
+            return EFI_NOT_FOUND;\r
+          }\r
+        }\r
+\r
+        //\r
+        // Decompress successfully.\r
+        // Loop the decompressed data searching for expected section.\r
+        //\r
+        CmpSection = (EFI_COMMON_SECTION_HEADER *) DstBuffer;\r
+        CmpFileData = (VOID *) DstBuffer;\r
+        CmpFileSize = DstBufferSize;\r
+        do {\r
+          CmpSectionLength = *(UINT32 *) (CmpSection->Size) & 0x00ffffff;\r
+          if (CmpSection->Type == SectionType) {\r
+            //\r
+            // This is what we want\r
+            //\r
+            if (SectionType == EFI_SECTION_PE32) {\r
+              *Pe32Data = (VOID *) (CmpSection + 1);\r
+              return EFI_SUCCESS;\r
+            } else if (SectionType == EFI_SECTION_FIRMWARE_VOLUME_IMAGE) {\r
+              // \r
+              // Firmware Volume Image in this Section\r
+              // Skip the section header to get FvHeader\r
+              //\r
+              FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (CmpSection + 1);\r
+    \r
+              if (FvHeader->Signature == EFI_FVH_SIGNATURE) {\r
+                //\r
+                // Because FvLength in FvHeader is UINT64 type, \r
+                // so FvHeader must meed at least 8 bytes alignment.\r
+                // If current FvImage base address doesn't meet its alignment,\r
+                // we need to reload this FvImage to another correct memory address.\r
+                //\r
+                if (((UINTN) FvHeader % sizeof (UINT64)) != 0) {\r
+                  DstBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINTN) CmpSectionLength - sizeof (EFI_COMMON_SECTION_HEADER)), sizeof (UINT64));\r
+                  if (DstBuffer == NULL) {\r
+                    return EFI_OUT_OF_RESOURCES;\r
+                  }\r
+                  CopyMem (DstBuffer, FvHeader, (UINTN) CmpSectionLength - sizeof (EFI_COMMON_SECTION_HEADER));\r
+                  FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) DstBuffer;  \r
+                }\r
+\r
+                //\r
+                // Build new FvHob for new decompressed Fv image.\r
+                //\r
+                BuildFvHob ((EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader, FvHeader->FvLength);\r
+                \r
+                //\r
+                // Set the original FvHob to unused.\r
+                //\r
+                if (OrigHob != NULL) {\r
+                  OrigHob->Header->HobType = EFI_HOB_TYPE_UNUSED;\r
+                }\r
+                \r
+                //\r
+                // return found FvImage data.\r
+                //\r
+                *Pe32Data = (VOID *) FvHeader;\r
+                return EFI_SUCCESS;\r
+              }\r
+            }\r
+          }\r
+          OccupiedCmpSectionLength  = GET_OCCUPIED_SIZE (CmpSectionLength, 4);\r
+          CmpSection                = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) CmpSection + OccupiedCmpSectionLength);\r
+        } while (CmpSection->Type != 0 && (UINTN) ((UINT8 *) CmpSection - (UINT8 *) CmpFileData) < CmpFileSize);\r
+      }\r
+      //\r
+      // End of the decompression activity\r
+      //\r
+\r
+      Section   = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) Section + OccupiedSectionLength);\r
+      FileSize  = FfsFileHeader->Size[0] & 0xFF;\r
+      FileSize += (FfsFileHeader->Size[1] << 8) & 0xFF00;\r
+      FileSize += (FfsFileHeader->Size[2] << 16) & 0xFF0000;\r
+      FileSize &= 0x00FFFFFF;\r
+    } while (Section->Type != 0 && (UINTN) ((UINT8 *) Section - (UINT8 *) FfsFileHeader) < FileSize);\r
+    \r
+    //\r
+    // search all sections (compression and non compression) in this FFS, don't \r
+    // find expected section.\r
+    //\r
+    return EFI_NOT_FOUND;\r
+  } else {\r
+    //\r
+    // For those FFS that doesn't contain compression section, directly search \r
+    // PE or TE section in this FFS.\r
+    //\r
+\r
+    Status = PeiServicesFfsFindSectionData (\r
+               EFI_SECTION_PE32,\r
+               FfsFileHeader,\r
+               &SectionData\r
+               );\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      Status = PeiServicesFfsFindSectionData (\r
+                 EFI_SECTION_TE,\r
+                 FfsFileHeader,\r
+                 &SectionData\r
+                 );\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+    }\r
+  }\r
+\r
+  *Pe32Data = SectionData;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
new file mode 100644 (file)
index 0000000..d3fbcb2
--- /dev/null
@@ -0,0 +1,136 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  DxeLoadFunc.c\r
+\r
+Abstract:\r
+\r
+  Ia32-specifc functionality for DxeLoad.\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "DxeIpl.h"\r
+#include "VirtualMemory.h"\r
+\r
+//\r
+// Global Descriptor Table (GDT)\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED IA32_GDT gGdtEntries [] = {\r
+/* selector { Global Segment Descriptor                              } */  \r
+/* 0x00 */  {{0,      0,  0,  0,    0,  0,  0,  0,    0,  0, 0,  0,  0}}, //null descriptor \r
+/* 0x08 */  {{0xffff, 0,  0,  0x2,  1,  0,  1,  0xf,  0,  0, 1,  1,  0}}, //linear data segment descriptor\r
+/* 0x10 */  {{0xffff, 0,  0,  0xf,  1,  0,  1,  0xf,  0,  0, 1,  1,  0}}, //linear code segment descriptor\r
+/* 0x18 */  {{0xffff, 0,  0,  0x3,  1,  0,  1,  0xf,  0,  0, 1,  1,  0}}, //system data segment descriptor\r
+/* 0x20 */  {{0xffff, 0,  0,  0xa,  1,  0,  1,  0xf,  0,  0, 1,  1,  0}}, //system code segment descriptor\r
+/* 0x28 */  {{0,      0,  0,  0,    0,  0,  0,  0,    0,  0, 0,  0,  0}}, //spare segment descriptor\r
+/* 0x30 */  {{0xffff, 0,  0,  0x2,  1,  0,  1,  0xf,  0,  0, 1,  1,  0}}, //system data segment descriptor\r
+/* 0x38 */  {{0xffff, 0,  0,  0xa,  1,  0,  1,  0xf,  0,  1, 0,  1,  0}}, //system code segment descriptor\r
+/* 0x40 */  {{0,      0,  0,  0,    0,  0,  0,  0,    0,  0, 0,  0,  0}}, //spare segment descriptor\r
+};\r
+\r
+//\r
+// IA32 Gdt register\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED CONST IA32_DESCRIPTOR gGdt = {\r
+  sizeof (gGdtEntries) - 1,\r
+  (UINTN) gGdtEntries\r
+  };\r
+\r
+VOID\r
+HandOffToDxeCore (\r
+  IN EFI_PHYSICAL_ADDRESS   DxeCoreEntryPoint,\r
+  IN EFI_PEI_HOB_POINTERS   HobList,\r
+  IN EFI_PEI_PPI_DESCRIPTOR *EndOfPeiSignal\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_PHYSICAL_ADDRESS      BaseOfStack;\r
+  EFI_PHYSICAL_ADDRESS      TopOfStack;\r
+  UINTN                     PageTables;\r
+\r
+  Status = PeiServicesAllocatePages (EfiBootServicesData, EFI_SIZE_TO_PAGES (STACK_SIZE), &BaseOfStack);\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  if (FeaturePcdGet(PcdDxeIplSwitchToLongMode)) {\r
+    //\r
+    // Compute the top of the stack we were allocated, which is used to load X64 dxe core. \r
+    // Pre-allocate a 32 bytes which confroms to x64 calling convention.\r
+    //\r
+    // The first four parameters to a function are passed in rcx, rdx, r8 and r9. \r
+    // Any further parameters are pushed on the stack. Furthermore, space (4 * 8bytes) for the \r
+    // register parameters is reserved on the stack, in case the called function \r
+    // wants to spill them; this is important if the function is variadic. \r
+    //\r
+    TopOfStack = BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - 32;\r
+\r
+    //\r
+    //  X64 Calling Conventions requires that the stack must be aligned to 16 bytes\r
+    //\r
+    TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, 16);\r
+\r
+    //\r
+    // Load the GDT of Go64. Since the GDT of 32-bit Tiano locates in the BS_DATA\r
+    // memory, it may be corrupted when copying FV to high-end memory \r
+    //\r
+    AsmWriteGdtr (&gGdt);\r
+    //\r
+    // Create page table and save PageMapLevel4 to CR3\r
+    //\r
+    PageTables = CreateIdentityMappingPageTables ();\r
+\r
+    //\r
+    // End of PEI phase singal\r
+    //\r
+    Status = PeiServicesInstallPpi (EndOfPeiSignal);\r
+    ASSERT_EFI_ERROR (Status);\r
+    \r
+    AsmWriteCr3 (PageTables);\r
+     //\r
+    // Go to Long Mode. Interrupts will not get turned on until the CPU AP is loaded.\r
+    // Call x64 drivers passing in single argument, a pointer to the HOBs.\r
+    // \r
+    AsmEnablePaging64 (\r
+      SYS_CODE64_SEL,\r
+      DxeCoreEntryPoint,\r
+      (EFI_PHYSICAL_ADDRESS)(UINTN)(HobList.Raw),\r
+      0,\r
+      TopOfStack\r
+      );\r
+  } else {\r
+    //\r
+    // Compute the top of the stack we were allocated. Pre-allocate a UINTN\r
+    // for safety.\r
+    //\r
+    TopOfStack = BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT;\r
+    TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
+\r
+    //\r
+    // End of PEI phase singal\r
+    //\r
+    Status = PeiServicesInstallPpi (EndOfPeiSignal);\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    SwitchStack (\r
+      (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,\r
+      HobList.Raw,\r
+      NULL,\r
+      (VOID *) (UINTN) TopOfStack\r
+      );\r
+  } \r
+}\r
+\r
diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/ImageRead.c b/MdeModulePkg/Core/DxeIplPeim/Ia32/ImageRead.c
new file mode 100644 (file)
index 0000000..f7bef7e
--- /dev/null
@@ -0,0 +1,117 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  ImageRead.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "DxeIpl.h"\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PeiImageRead (\r
+  IN     VOID    *FileHandle,\r
+  IN     UINTN   FileOffset,\r
+  IN OUT UINTN   *ReadSize,\r
+  OUT    VOID    *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file\r
+\r
+Arguments:\r
+\r
+  FileHandle - The handle to the PE/COFF file\r
+\r
+  FileOffset - The offset, in bytes, into the file to read\r
+\r
+  ReadSize   - The number of bytes to read from the file starting at FileOffset\r
+\r
+  Buffer     - A pointer to the buffer to read the data into.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset\r
+\r
+--*/\r
+{\r
+  UINT8 *Destination32;\r
+  UINT8 *Source32;\r
+  UINTN  Length;\r
+\r
\r
+  Destination32 = Buffer;\r
+  Source32      = (UINT8 *) ((UINTN) FileHandle + FileOffset);\r
+\r
+  //\r
+  // This function assumes 32-bit alignment to increase performance\r
+  //\r
+//  ASSERT (ALIGN_POINTER (Destination32, sizeof (UINT32)) == Destination32);\r
+//  ASSERT (ALIGN_POINTER (Source32, sizeof (UINT32)) == Source32);\r
+\r
+  Length = *ReadSize;\r
+  while (Length--) {\r
+    *(Destination32++) = *(Source32++);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+GetImageReadFunction (\r
+  IN      PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Support routine to return the PE32 Image Reader.\r
+  If the PeiImageRead() function is less than a page\r
+  in legnth. If the function is more than a page the DXE IPL will crash!!!!\r
+\r
+Arguments:\r
+  ImageContext  - The context of the image being loaded\r
+\r
+Returns:\r
+  EFI_SUCCESS - If Image function location is found\r
+\r
+--*/\r
+{\r
+  VOID        *MemoryBuffer;\r
+\r
+  if (gInMemory) {\r
+    ImageContext->ImageRead = PeiImageRead;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // BugBug; This code assumes PeiImageRead() is less than a page in size!\r
+  //  Allocate a page so we can shaddow the read function from FLASH into \r
+  //  memory to increase performance. \r
+  //\r
+  \r
+  MemoryBuffer = AllocateCopyPool (0x400, (VOID *)(UINTN) PeiImageRead);\r
+  ASSERT (MemoryBuffer != NULL);\r
+\r
+  ImageContext->ImageRead = (PE_COFF_LOADER_READ_FILE) (UINTN) MemoryBuffer;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.c b/MdeModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.c
new file mode 100644 (file)
index 0000000..f4a6a4f
--- /dev/null
@@ -0,0 +1,173 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+  VirtualMemory.c\r
+  \r
+Abstract:\r
+\r
+  x64 Virtual Memory Management Services in the form of an IA-32 driver.  \r
+  Used to establish a 1:1 Virtual to Physical Mapping that is required to\r
+  enter Long Mode (x64 64-bit mode).\r
+\r
+  While we make a 1:1 mapping (identity mapping) for all physical pages \r
+  we still need to use the MTRR's to ensure that the cachability attirbutes\r
+  for all memory regions is correct.\r
+\r
+  The basic idea is to use 2MB page table entries where ever possible. If\r
+  more granularity of cachability is required then 4K page tables are used.\r
+\r
+  References:\r
+    1) IA-32 Intel(R) Atchitecture Software Developer's Manual Volume 1:Basic Architecture, Intel\r
+    2) IA-32 Intel(R) Atchitecture Software Developer's Manual Volume 2:Instruction Set Reference, Intel\r
+    3) IA-32 Intel(R) Atchitecture Software Developer's Manual Volume 3:System Programmer's Guide, Intel\r
+  \r
+--*/  \r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "VirtualMemory.h"\r
+\r
+UINTN\r
+CreateIdentityMappingPageTables (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Allocates and fills in the Page Directory and Page Table Entries to\r
+  establish a 1:1 Virtual to Physical mapping.\r
+\r
+Arguments:\r
+\r
+  NumberOfProcessorPhysicalAddressBits - Number of processor address bits to use.\r
+                                         Limits the number of page table entries \r
+                                         to the physical address space.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           The 1:1 Virtual to Physical identity mapping was created\r
+\r
+--*/\r
+{  \r
+  UINT8                                         PhysicalAddressBits;\r
+  EFI_PHYSICAL_ADDRESS                          PageAddress;\r
+  UINTN                                         IndexOfPml4Entries;\r
+  UINTN                                         IndexOfPdpEntries;\r
+  UINTN                                         IndexOfPageDirectoryEntries;\r
+  UINTN                                         NumberOfPml4EntriesNeeded;\r
+  UINTN                                         NumberOfPdpEntriesNeeded;\r
+  PAGE_MAP_AND_DIRECTORY_POINTER                *PageMapLevel4Entry;\r
+  PAGE_MAP_AND_DIRECTORY_POINTER                *PageMap;\r
+  PAGE_MAP_AND_DIRECTORY_POINTER                *PageDirectoryPointerEntry;\r
+  PAGE_TABLE_ENTRY                              *PageDirectoryEntry;\r
+  UINTN                                         TotalPagesNum;\r
+  UINTN                                         BigPageAddress;\r
+  VOID                                          *Hob;\r
+\r
+  //\r
+  // Get physical address bits supported from CPU HOB.\r
+  //\r
+  PhysicalAddressBits = 36;\r
+  \r
+  Hob = GetFirstHob (EFI_HOB_TYPE_CPU);\r
+  if (Hob != NULL) {\r
+    PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace;    \r
+  }\r
+\r
+  //\r
+  // Calculate the table entries needed.\r
+  //\r
+  if (PhysicalAddressBits <= 39 ) {\r
+    NumberOfPml4EntriesNeeded = 1;\r
+    NumberOfPdpEntriesNeeded =  1 << (PhysicalAddressBits - 30);\r
+  } else {\r
+    NumberOfPml4EntriesNeeded = 1 << (PhysicalAddressBits - 39);\r
+    NumberOfPdpEntriesNeeded = 512;\r
+  }\r
+\r
+  //\r
+  // Pre-allocate big pages to avoid later allocations. \r
+  //\r
+  TotalPagesNum = (NumberOfPdpEntriesNeeded + 1) * NumberOfPml4EntriesNeeded + 1;\r
+  BigPageAddress = (UINTN) AllocatePages (TotalPagesNum);\r
+  ASSERT (BigPageAddress != 0);\r
+\r
+  //\r
+  // By architecture only one PageMapLevel4 exists - so lets allocate storage for it.\r
+  //\r
+  PageMap         = (VOID *) BigPageAddress;\r
+  BigPageAddress += EFI_PAGE_SIZE;\r
+\r
+  PageMapLevel4Entry = PageMap;\r
+  PageAddress        = 0;\r
+  for (IndexOfPml4Entries = 0; IndexOfPml4Entries < NumberOfPml4EntriesNeeded; IndexOfPml4Entries++, PageMapLevel4Entry++) {\r
+    //\r
+    // Each PML4 entry points to a page of Page Directory Pointer entires.\r
+    // So lets allocate space for them and fill them in in the IndexOfPdpEntries loop.\r
+    //\r
+    PageDirectoryPointerEntry = (VOID *) BigPageAddress;\r
+    BigPageAddress += EFI_PAGE_SIZE;\r
+\r
+    //\r
+    // Make a PML4 Entry\r
+    //\r
+    PageMapLevel4Entry->Uint64 = (UINT64)(UINTN)PageDirectoryPointerEntry;\r
+    PageMapLevel4Entry->Bits.ReadWrite = 1;\r
+    PageMapLevel4Entry->Bits.Present = 1;\r
+\r
+    for (IndexOfPdpEntries = 0; IndexOfPdpEntries < NumberOfPdpEntriesNeeded; IndexOfPdpEntries++, PageDirectoryPointerEntry++) {\r
+      //\r
+      // Each Directory Pointer entries points to a page of Page Directory entires.\r
+      // So allocate space for them and fill them in in the IndexOfPageDirectoryEntries loop.\r
+      //       \r
+      PageDirectoryEntry = (VOID *) BigPageAddress;\r
+      BigPageAddress += EFI_PAGE_SIZE;\r
+\r
+      //\r
+      // Fill in a Page Directory Pointer Entries\r
+      //\r
+      PageDirectoryPointerEntry->Uint64 = (UINT64)(UINTN)PageDirectoryEntry;\r
+      PageDirectoryPointerEntry->Bits.ReadWrite = 1;\r
+      PageDirectoryPointerEntry->Bits.Present = 1;\r
+\r
+      for (IndexOfPageDirectoryEntries = 0; IndexOfPageDirectoryEntries < 512; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PageAddress += 0x200000) {\r
+        //\r
+        // Fill in the Page Directory entries\r
+        //\r
+        PageDirectoryEntry->Uint64 = (UINT64)PageAddress;\r
+        PageDirectoryEntry->Bits.ReadWrite = 1;\r
+        PageDirectoryEntry->Bits.Present = 1;\r
+        PageDirectoryEntry->Bits.MustBe1 = 1;\r
+\r
+      }\r
+    }\r
+  }\r
+\r
+  //\r
+  // For the PML4 entries we are not using fill in a null entry.\r
+  // For now we just copy the first entry.\r
+  //\r
+  for (; IndexOfPml4Entries < 512; IndexOfPml4Entries++, PageMapLevel4Entry++) {\r
+     CopyMem (\r
+       PageMapLevel4Entry,\r
+       PageMap,\r
+       sizeof (PAGE_MAP_AND_DIRECTORY_POINTER)\r
+       );\r
+  }\r
+\r
+  return (UINTN)PageMap; // FIXME\r
+}\r
+\r
diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.h b/MdeModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.h
new file mode 100644 (file)
index 0000000..4e6614e
--- /dev/null
@@ -0,0 +1,112 @@
+/*++ \r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+  VirtualMemory.h\r
+  \r
+Abstract:\r
+\r
+  x64 Long Mode Virtual Memory Management Definitions  \r
+\r
+  References:\r
+    1) IA-32 Intel(R) Atchitecture Software Developer's Manual Volume 1:Basic Architecture, Intel\r
+    2) IA-32 Intel(R) Atchitecture Software Developer's Manual Volume 2:Instruction Set Reference, Intel\r
+    3) IA-32 Intel(R) Atchitecture Software Developer's Manual Volume 3:System Programmer's Guide, Intel\r
+    4) AMD64 Architecture Programmer's Manual Volume 2: System Programming\r
+--*/  \r
+#ifndef _VIRTUAL_MEMORY_H_\r
+#define _VIRTUAL_MEMORY_H_\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#define SYS_CODE64_SEL 0x38\r
+\r
+#pragma pack(1)\r
+\r
+typedef union {\r
+  struct {\r
+    UINT32  LimitLow    : 16;\r
+    UINT32  BaseLow     : 16;\r
+    UINT32  BaseMid     : 8;\r
+    UINT32  Type        : 4;\r
+    UINT32  System      : 1;\r
+    UINT32  Dpl         : 2;\r
+    UINT32  Present     : 1;\r
+    UINT32  LimitHigh   : 4;\r
+    UINT32  Software    : 1;\r
+    UINT32  Reserved    : 1;\r
+    UINT32  DefaultSize : 1;\r
+    UINT32  Granularity : 1;\r
+    UINT32  BaseHigh    : 8;\r
+  } Bits;\r
+  UINT64  Uint64;\r
+} IA32_GDT;\r
+\r
+//\r
+// Page-Map Level-4 Offset (PML4) and\r
+// Page-Directory-Pointer Offset (PDPE) entries 4K & 2MB\r
+//\r
+\r
+typedef union {\r
+  struct {\r
+    UINT64  Present:1;                // 0 = Not present in memory, 1 = Present in memory\r
+    UINT64  ReadWrite:1;              // 0 = Read-Only, 1= Read/Write\r
+    UINT64  UserSupervisor:1;         // 0 = Supervisor, 1=User\r
+    UINT64  WriteThrough:1;           // 0 = Write-Back caching, 1=Write-Through caching\r
+    UINT64  CacheDisabled:1;          // 0 = Cached, 1=Non-Cached\r
+    UINT64  Accessed:1;               // 0 = Not accessed, 1 = Accessed (set by CPU)\r
+    UINT64  Reserved:1;               // Reserved\r
+    UINT64  MustBeZero:2;             // Must Be Zero\r
+    UINT64  Available:3;              // Available for use by system software\r
+    UINT64  PageTableBaseAddress:40;  // Page Table Base Address\r
+    UINT64  AvabilableHigh:11;        // Available for use by system software\r
+    UINT64  Nx:1;                     // No Execute bit\r
+  } Bits;\r
+  UINT64    Uint64;\r
+} PAGE_MAP_AND_DIRECTORY_POINTER;\r
+\r
+//\r
+// Page Table Entry 2MB\r
+//\r
+typedef union {\r
+  struct {\r
+    UINT64  Present:1;                // 0 = Not present in memory, 1 = Present in memory\r
+    UINT64  ReadWrite:1;              // 0 = Read-Only, 1= Read/Write\r
+    UINT64  UserSupervisor:1;         // 0 = Supervisor, 1=User\r
+    UINT64  WriteThrough:1;           // 0 = Write-Back caching, 1=Write-Through caching\r
+    UINT64  CacheDisabled:1;          // 0 = Cached, 1=Non-Cached\r
+    UINT64  Accessed:1;               // 0 = Not accessed, 1 = Accessed (set by CPU)\r
+    UINT64  Dirty:1;                  // 0 = Not Dirty, 1 = written by processor on access to page\r
+    UINT64  MustBe1:1;                // Must be 1 \r
+    UINT64  Global:1;                 // 0 = Not global page, 1 = global page TLB not cleared on CR3 write\r
+    UINT64  Available:3;              // Available for use by system software\r
+    UINT64  PAT:1;                    //\r
+    UINT64  MustBeZero:8;             // Must be zero;\r
+    UINT64  PageTableBaseAddress:31;  // Page Table Base Address\r
+    UINT64  AvabilableHigh:11;        // Available for use by system software\r
+    UINT64  Nx:1;                     // 0 = Execute Code, 1 = No Code Execution\r
+  } Bits;\r
+  UINT64    Uint64;\r
+} PAGE_TABLE_ENTRY;\r
+\r
+#pragma pack()\r
+\r
+UINTN\r
+CreateIdentityMappingPageTables (\r
+  VOID\r
+  )\r
+;\r
+\r
+#endif \r
diff --git a/MdeModulePkg/Core/DxeIplPeim/Ipf/DxeLoadFunc.c b/MdeModulePkg/Core/DxeIplPeim/Ipf/DxeLoadFunc.c
new file mode 100644 (file)
index 0000000..3feb2e5
--- /dev/null
@@ -0,0 +1,77 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  IpfDxeLoad.c\r
+\r
+Abstract:\r
+\r
+  Ipf-specifc functionality for DxeLoad.\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "DxeIpl.h"\r
+\r
+VOID\r
+HandOffToDxeCore (\r
+  IN EFI_PHYSICAL_ADDRESS   DxeCoreEntryPoint,\r
+  IN EFI_PEI_HOB_POINTERS   HobList,\r
+  IN EFI_PEI_PPI_DESCRIPTOR *EndOfPeiSignal\r
+  )\r
+{\r
+  VOID                *BaseOfStack;\r
+  VOID                *TopOfStack;\r
+  VOID                *BspStore;\r
+  EFI_STATUS          Status;\r
+\r
+  //\r
+  // Allocate 128KB for the Stack\r
+  //\r
+  BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE));\r
+  ASSERT (BaseOfStack != NULL);\r
+\r
+  //\r
+  // Allocate 16KB for the BspStore\r
+  //\r
+  BspStore    = AllocatePages (EFI_SIZE_TO_PAGES (BSP_STORE_SIZE));\r
+  ASSERT (BspStore != NULL);\r
+  //\r
+  // Build BspStoreHob\r
+  //\r
+  BuildBspStoreHob ((EFI_PHYSICAL_ADDRESS) (UINTN) BspStore, BSP_STORE_SIZE, EfiBootServicesData);\r
+\r
+  //\r
+  // Compute the top of the stack we were allocated. Pre-allocate a UINTN\r
+  // for safety.\r
+  //\r
+  TopOfStack = (VOID *) ((UINTN) BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);\r
+  TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
+\r
+  //\r
+  // End of PEI phase singal\r
+  //\r
+  Status = PeiServicesInstallPpi (EndOfPeiSignal);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  SwitchStack (\r
+    (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,\r
+    HobList.Raw,\r
+    NULL,\r
+    TopOfStack,\r
+    BspStore\r
+    );\r
+}\r
diff --git a/MdeModulePkg/Core/DxeIplPeim/Ipf/ImageRead.c b/MdeModulePkg/Core/DxeIplPeim/Ipf/ImageRead.c
new file mode 100644 (file)
index 0000000..5002fe8
--- /dev/null
@@ -0,0 +1,77 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  ImageRead.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "DxeIpl.h"\r
+\r
+EFI_STATUS\r
+PeiImageRead (\r
+  IN     VOID    *FileHandle,\r
+  IN     UINTN   FileOffset,\r
+  IN OUT UINTN   *ReadSize,\r
+  OUT    VOID    *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file\r
+\r
+Arguments:\r
+\r
+  FileHandle - The handle to the PE/COFF file\r
+\r
+  FileOffset - The offset, in bytes, into the file to read\r
+\r
+  ReadSize   - The number of bytes to read from the file starting at FileOffset\r
+\r
+  Buffer     - A pointer to the buffer to read the data into.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset\r
+\r
+--*/\r
+{\r
+  CHAR8 *Destination8;\r
+  CHAR8 *Source8;\r
+  volatile UINTN Length;\r
+\r
+  Destination8  = Buffer;\r
+  Source8       = (CHAR8 *) ((UINTN) FileHandle + FileOffset);\r
+  Length        = *ReadSize;\r
+  while (Length--) {\r
+    *(Destination8++) = *(Source8++);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+GetImageReadFunction (\r
+  IN      PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  ImageContext->ImageRead = PeiImageRead;\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c b/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c
new file mode 100644 (file)
index 0000000..1d5709a
--- /dev/null
@@ -0,0 +1,65 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  DxeLoadFunc.c\r
+\r
+Abstract:\r
+\r
+  Ia32-specifc functionality for DxeLoad.\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "DxeIpl.h"\r
+\r
+VOID\r
+HandOffToDxeCore (\r
+  IN EFI_PHYSICAL_ADDRESS   DxeCoreEntryPoint,\r
+  IN EFI_PEI_HOB_POINTERS   HobList,\r
+  IN EFI_PEI_PPI_DESCRIPTOR *EndOfPeiSignal\r
+  )\r
+{\r
+  VOID                *BaseOfStack;\r
+  VOID                *TopOfStack;\r
+  EFI_STATUS          Status;\r
+\r
+  //\r
+  // Allocate 128KB for the Stack\r
+  //\r
+  BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE));\r
+  ASSERT (BaseOfStack != NULL);\r
+\r
+  //\r
+  // Compute the top of the stack we were allocated. Pre-allocate a UINTN\r
+  // for safety.\r
+  //\r
+  TopOfStack = (VOID *) ((UINTN) BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);\r
+  TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
+\r
+  //\r
+  // End of PEI phase singal\r
+  //\r
+  Status = PeiServicesInstallPpi (EndOfPeiSignal);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  SwitchStack (\r
+    (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,\r
+    HobList.Raw,\r
+    NULL,\r
+    TopOfStack\r
+    );\r
+}\r
diff --git a/MdeModulePkg/Include/Common/DecompressLibraryHob.h b/MdeModulePkg/Include/Common/DecompressLibraryHob.h
new file mode 100644 (file)
index 0000000..ee7b8a2
--- /dev/null
@@ -0,0 +1,47 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  DecompressLibraryHob.h\r
+\r
+Abstract:\r
+\r
+  Declaration of HOB that is used to pass decompressor library functions from PEI to DXE\r
+\r
+--*/\r
+\r
+#ifndef __DECOMPRESS_LIBRARY_HOB_H__\r
+#define __DECOMPRESS_LIBRARY_HOB_H__\r
+\r
+typedef\r
+RETURN_STATUS\r
+(EFIAPI *DECOMPRESS_LIBRARY_GET_INFO) (\r
+  IN  CONST VOID  *Source,\r
+  IN  UINT32      SourceSize,\r
+  OUT UINT32      *DestinationSize,\r
+  OUT UINT32      *ScratchSize\r
+  );\r
+\r
+typedef\r
+RETURN_STATUS\r
+(EFIAPI *DECOMPRESS_LIBRARY_DECOMPRESS) (\r
+  IN CONST VOID  *Source,\r
+  IN OUT VOID    *Destination,\r
+  IN OUT VOID    *Scratch\r
+  );\r
+\r
+typedef struct {\r
+  DECOMPRESS_LIBRARY_GET_INFO    GetInfo;\r
+  DECOMPRESS_LIBRARY_DECOMPRESS  Decompress;\r
+} DECOMPRESS_LIBRARY;\r
+\r
+#endif\r
index b8a09d1..b4b46d9 100644 (file)
@@ -67,6 +67,9 @@
   ##gEfiPeiPeCoffLoaderGuid will be removed in future\r
   gEfiPeiPeCoffLoaderGuid        = { 0xd8117cff, 0x94a6, 0x11d4, {0x9a, 0x3a, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } }\r
   gEfiPeiCorePrivateGuid         = { 0xd641a0f5, 0xcb7c, 0x4846, { 0xa3, 0x80, 0x1d, 0x01, 0xb4, 0xd9, 0xe3, 0xb9 }}\r
+  gEfiEndOfPeiSignalPpiGuid      = { 0x605EA650, 0xC65C, 0x42e1, { 0xBA, 0x80, 0x91, 0xA5, 0x2A, 0xB6, 0x18, 0xC6 }}\r
+  gEfiPeiFvFileLoaderPpiGuid     = { 0x7e1f0d85, 0x04ff, 0x4bb2, { 0x86, 0x6a, 0x31, 0xa2, 0x99, 0x6a, 0x48, 0xa8 }}\r
+\r
   \r
 ################################################################################\r
 #\r
 \r
 \r
 [PcdsFeatureFlag.IA32]\r
-  PcdDxeIplSwitchToLongMode|0x0001003b|gEfiEdkModulePkgTokenSpaceGuid|BOOLEAN|TRUE\r
+  PcdDxeIplSwitchToLongMode|0x0001003b|gEfiMdeModulePkgTokenSpaceGuid|BOOLEAN|TRUE\r
 \r
 \r
index d01a147..8980453 100644 (file)
   PrintLib|${WORKSPACE}/MdePkg/Library/BasePrintLib/BasePrintLib.inf\r
   TimerLib|${WORKSPACE}/MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf\r
   UefiDecompressLib|${WORKSPACE}/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf\r
+  EdkPeCoffLoaderLib|${WORKSPACE}/MdeModulePkg/Library/PeiDxePeCoffLoaderLib/PeCoffLoaderLib.inf\r
+  ReportStatusCodeLib|${WORKSPACE}/IntelFrameworkPkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf\r
+  CustomDecompressLib|${WORKSPACE}/IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf \r
+  HiiLib|${WORKSPACE}/IntelFrameworkPkg/Library/HiiLibFramework/HiiLib.inf\r
+  \r
 \r
 [LibraryClasses.IA32]\r
   IoLib|${WORKSPACE}/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf\r
   FvbServiceLib|${WORKSPACE}/MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf\r
   ReportStatusCodeLib|${WORKSPACE}/IntelFrameworkPkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
   ScsiLib|$(WORKSPACE)/MdePkg/Library/UefiScsiLib/UefiScsiLib.inf\r
+  FrameworkHiiLib|$(WORKSPACE)/IntelFrameworkPkg/Library/FrameworkHiiLib/HiiLib.inf\r
 \r
 [LibraryClasses.common.DXE_RUNTIME_DRIVER]\r
   HobLib|${WORKSPACE}/MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   PcdPeiPcdDatabaseCallbackOnSetEnabled|gEfiEdkModulePkgTokenSpaceGuid|TRUE\r
   PcdPeiPcdDatabaseExEnabled|gEfiEdkModulePkgTokenSpaceGuid|TRUE\r
   PcdNtEmulatorEnable|gEfiEdkModulePkgTokenSpaceGuid|FALSE\r
+  PcdDevicePathSupportDevicePathFromText|gEfiEdkModulePkgTokenSpaceGuid|FALSE\r
+  PcdDevicePathSupportDevicePathToText|gEfiEdkModulePkgTokenSpaceGuid|FALSE\r
+  PcdDxeIplSupportCustomDecompress|gEfiEdkModulePkgTokenSpaceGuid|TRUE\r
+  PcdDxeIplBuildShareCodeHobs|gEfiEdkModulePkgTokenSpaceGuid|FALSE  \r
+  PcdDxeIplSupportEfiDecompress|gEfiEdkModulePkgTokenSpaceGuid|TRUE\r
+  PcdDxeIplSupportTianoDecompress|gEfiEdkModulePkgTokenSpaceGuid|TRUE\r
+  PcdDxeIplSupportCustomDecompress|gEfiEdkModulePkgTokenSpaceGuid|TRUE \r
 \r
 #  PcdStatusCodeUseOEM|gEfiIntelFrameworkModulePkgTokenSpaceGuid|FALSE\r
 \r
+[PcdsFeatureFlag.IA32]\r
+  PcdDxeIplSwitchToLongMode|gEfiMdeModulePkgTokenSpaceGuid|TRUE\r
+\r
 [PcdsFixedAtBuild.common]\r
   PcdMaximumUnicodeStringLength|gEfiMdePkgTokenSpaceGuid|1000000\r
   PcdMaximumAsciiStringLength|gEfiMdePkgTokenSpaceGuid|1000000\r
   $(WORKSPACE)/MdeModulePkg/Universal/PCD/Pei/Pcd.inf\r
   $(WORKSPACE)/MdeModulePkg/Core/Dxe/DxeMain.inf\r
   $(WORKSPACE)/MdeModulePkg/Core/Pei/PeiMain.inf\r
+  ${WORKSPACE}/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.inf\r
+  ${WORKSPACE}/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.inf\r
+  ${WORKSPACE}/MdeModulePkg/Universal/DevicePathDxe/DevicePath.inf\r
+  ${WORKSPACE}/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.inf\r
+  ${WORKSPACE}/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.inf\r
+  ${WORKSPACE}/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf\r
+\r
 \r
 [Components.X64]\r
   ${WORKSPACE}/MdeModulePkg/Application/HelloWorld/HelloWorld.inf\r
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/CommonHeader.h b/MdeModulePkg/Universal/Console/ConPlatformDxe/CommonHeader.h
new file mode 100644 (file)
index 0000000..5a5ef99
--- /dev/null
@@ -0,0 +1,54 @@
+/**@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) 2006 - 2007, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/SimpleTextOut.h>\r
+#include <Guid/GlobalVariable.h>\r
+#include <Guid/ConsoleInDevice.h>\r
+#include <Protocol/DevicePath.h>\r
+#include <Protocol/SimpleTextIn.h>\r
+#include <Guid/HotPlugDevice.h>\r
+#include <Guid/StandardErrorDevice.h>\r
+#include <Guid/ConsoleOutDevice.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+//\r
+// Driver Binding Externs\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextInDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL gConPlatformComponentName;\r
+extern EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextOutDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL gConPlatformComponentName;\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ComponentName.c b/MdeModulePkg/Universal/Console/ConPlatformDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..146eee6
--- /dev/null
@@ -0,0 +1,146 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  ComponentName.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+\r
+\r
+#include "ConPlatform.h"\r
+#include "ComponentName.h"\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+EFI_COMPONENT_NAME_PROTOCOL     gConPlatformComponentName = {\r
+  ConPlatformComponentNameGetDriverName,\r
+  ConPlatformComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+STATIC EFI_UNICODE_STRING_TABLE mConPlatformDriverNameTable[] = {\r
+  {\r
+    "eng",\r
+    L"Platform Console Management Driver"\r
+  },\r
+  {\r
+    NULL,\r
+    NULL\r
+  }\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConPlatformComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
+\r
+  Arguments:\r
+    This       - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    Language   - A pointer to a three character ISO 639-2 language identifier.\r
+                 This is the language of the driver name that that the caller \r
+                 is requesting, and it must match one of the languages specified\r
+                 in SupportedLanguages.  The number of languages supported by a \r
+                 driver is up to the driver writer.\r
+    DriverName - A pointer to the Unicode string to return.  This Unicode string\r
+                 is the name of the driver specified by This in the language \r
+                 specified by Language.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the Driver specified by This\r
+                            and the language specified by Language was returned \r
+                            in DriverName.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - DriverName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  return LookupUnicodeString (\r
+           Language,\r
+           gConPlatformComponentName.SupportedLanguages,\r
+           mConPlatformDriverNameTable,\r
+           DriverName\r
+           );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConPlatformComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the controller\r
+    that is being managed by an EFI Driver.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    ControllerHandle - The handle of a controller that the driver specified by \r
+                       This is managing.  This handle specifies the controller \r
+                       whose name is to be returned.\r
+    ChildHandle      - The handle of the child controller to retrieve the name \r
+                       of.  This is an optional parameter that may be NULL.  It \r
+                       will be NULL for device drivers.  It will also be NULL \r
+                       for a bus drivers that wish to retrieve the name of the \r
+                       bus controller.  It will not be NULL for a bus driver \r
+                       that wishes to retrieve the name of a child controller.\r
+    Language         - A pointer to a three character ISO 639-2 language \r
+                       identifier.  This is the language of the controller name \r
+                       that that the caller is requesting, and it must match one\r
+                       of the languages specified in SupportedLanguages.  The \r
+                       number of languages supported by a driver is up to the \r
+                       driver writer.\r
+    ControllerName   - A pointer to the Unicode string to return.  This Unicode\r
+                       string is the name of the controller specified by \r
+                       ControllerHandle and ChildHandle in the language \r
+                       specified by Language from the point of view of the \r
+                       driver specified by This. \r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the user readable name in the\r
+                            language specified by Language for the driver \r
+                            specified by This was returned in DriverName.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid \r
+                            EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ControllerName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently \r
+                            managing the controller specified by \r
+                            ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ComponentName.h b/MdeModulePkg/Universal/Console/ConPlatformDxe/ComponentName.h
new file mode 100644 (file)
index 0000000..17c4348
--- /dev/null
@@ -0,0 +1,45 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+    ComponentName.h\r
+    \r
+Abstract:\r
+\r
+--*/\r
+\r
+#ifndef CON_MANAGE_COMPONENT_NAME_H_\r
+#define CON_MANAGE_COMPONENT_NAME_H_\r
+\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+ConPlatformComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConPlatformComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  );\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
new file mode 100644 (file)
index 0000000..d86ea47
--- /dev/null
@@ -0,0 +1,950 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+    ConPlatform.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+#include <Uefi.h>\r
+\r
+#include "ConPlatform.h"\r
+\r
+\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/SimpleTextOut.h>\r
+#include <Guid/GlobalVariable.h>\r
+#include <Guid/ConsoleInDevice.h>\r
+#include <Protocol/DevicePath.h>\r
+#include <Protocol/SimpleTextIn.h>\r
+#include <Guid/HotPlugDevice.h>\r
+#include <Guid/StandardErrorDevice.h>\r
+#include <Guid/ConsoleOutDevice.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+//\r
+// Driver Binding Externs\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextInDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL gConPlatformComponentName;\r
+extern EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextOutDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL gConPlatformComponentName;\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextInDriverBinding = {\r
+  ConPlatformTextInDriverBindingSupported,\r
+  ConPlatformTextInDriverBindingStart,\r
+  ConPlatformTextInDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextOutDriverBinding = {\r
+  ConPlatformTextOutDriverBindingSupported,\r
+  ConPlatformTextOutDriverBindingStart,\r
+  ConPlatformTextOutDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+/**\r
+  The user Entry Point for module ConPlatform. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeConPlatform(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  //\r
+  // Install driver model protocol(s).\r
+  //\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gConPlatformTextInDriverBinding,\r
+             ImageHandle,\r
+             &gConPlatformComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gConPlatformTextOutDriverBinding,\r
+             NULL,\r
+             &gConPlatformComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConPlatformTextInDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Supported\r
+\r
+Arguments:\r
+  (Standard DriverBinding Protocol Supported() function)\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  return ConPlatformDriverBindingSupported (\r
+          This,\r
+          ControllerHandle,\r
+          RemainingDevicePath,\r
+          &gEfiSimpleTextInProtocolGuid\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConPlatformTextOutDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Supported\r
+\r
+Arguments:\r
+  (Standard DriverBinding Protocol Supported() function)\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  return ConPlatformDriverBindingSupported (\r
+          This,\r
+          ControllerHandle,\r
+          RemainingDevicePath,\r
+          &gEfiSimpleTextOutProtocolGuid\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+ConPlatformDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath,\r
+  IN  EFI_GUID                     *ProtocolGuid\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Supported\r
+\r
+Arguments:\r
+  (Standard DriverBinding Protocol Supported() function)\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  VOID        *Interface;\r
+\r
+  //\r
+  // Test to see if this is a physical device by checking to see if\r
+  // it has a Device Path Protocol\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  NULL,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Test to see if this device supports the Simple Text Output Protocol\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  ProtocolGuid,\r
+                  (VOID **) &Interface,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        ProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        ControllerHandle\r
+        );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConPlatformTextInDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+\r
+Arguments:\r
+  (Standard DriverBinding Protocol Start() function)\r
+\r
+Returns:\r
+\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_DEVICE_PATH_PROTOCOL    *DevicePath;\r
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn;\r
+\r
+  //\r
+  // Get the Device Path Protocol so the environment variables can be updated\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &DevicePath,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Open the Simple Input Protocol BY_DRIVER\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiSimpleTextInProtocolGuid,\r
+                  (VOID **) &TextIn,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Check the device handle, if it is a hot plug device,\r
+  // do not put the device path into ConInDev, and install\r
+  // gEfiConsoleInDeviceGuid to the device handle directly.\r
+  // The policy is, make hot plug device plug in and play immediately.\r
+  //\r
+  if (IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) {\r
+    gBS->InstallMultipleProtocolInterfaces (\r
+          &ControllerHandle,\r
+          &gEfiConsoleInDeviceGuid,\r
+          NULL,\r
+          NULL\r
+          );\r
+  } else {\r
+    //\r
+    // Append the device path to the ConInDev environment variable\r
+    //\r
+    ConPlatformUpdateDeviceVariable (\r
+      VarConsoleInpDev,\r
+      DevicePath,\r
+      APPEND\r
+      );\r
+\r
+    //\r
+    // If the device path is an instance in the ConIn environment variable,\r
+    // then install EfiConsoleInDeviceGuid onto ControllerHandle\r
+    //\r
+    Status = ConPlatformUpdateDeviceVariable (\r
+              VarConsoleInp,\r
+              DevicePath,\r
+              CHECK\r
+              );\r
+\r
+    if (!EFI_ERROR (Status)) {\r
+      gBS->InstallMultipleProtocolInterfaces (\r
+            &ControllerHandle,\r
+            &gEfiConsoleInDeviceGuid,\r
+            NULL,\r
+            NULL\r
+            );\r
+    } else {\r
+      gBS->CloseProtocol (\r
+            ControllerHandle,\r
+            &gEfiSimpleTextInProtocolGuid,\r
+            This->DriverBindingHandle,\r
+            ControllerHandle\r
+            );\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConPlatformTextOutDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+\r
+Arguments:\r
+  (Standard DriverBinding Protocol Start() function)\r
+\r
+Returns:\r
+\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_DEVICE_PATH_PROTOCOL      *DevicePath;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *TextOut;\r
+  BOOLEAN                       NeedClose;\r
+\r
+  NeedClose = TRUE;\r
+\r
+  //\r
+  // Get the Device Path Protocol so the environment variables can be updated\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &DevicePath,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Open the Simple Text Output Protocol BY_DRIVER\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiSimpleTextOutProtocolGuid,\r
+                  (VOID **) &TextOut,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Check the device handle, if it is a hot plug device,\r
+  // do not put the device path into ConOutDev and StdErrDev,\r
+  // and install gEfiConsoleOutDeviceGuid to the device handle directly.\r
+  // The policy is, make hot plug device plug in and play immediately.\r
+  //\r
+  if (IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) {\r
+    gBS->InstallMultipleProtocolInterfaces (\r
+          &ControllerHandle,\r
+          &gEfiConsoleOutDeviceGuid,\r
+          NULL,\r
+          NULL\r
+          );\r
+  } else {\r
+    //\r
+    // Append the device path to the ConOutDev environment variable\r
+    //\r
+    ConPlatformUpdateDeviceVariable (\r
+      VarConsoleOutDev,\r
+      DevicePath,\r
+      APPEND\r
+      );\r
+    //\r
+    // Append the device path to the StdErrDev environment variable\r
+    //\r
+    ConPlatformUpdateDeviceVariable (\r
+      VarErrorOutDev,\r
+      DevicePath,\r
+      APPEND\r
+      );\r
+\r
+    //\r
+    // If the device path is an instance in the ConOut environment variable,\r
+    // then install EfiConsoleOutDeviceGuid onto ControllerHandle\r
+    //\r
+    Status = ConPlatformUpdateDeviceVariable (\r
+              VarConsoleOut,\r
+              DevicePath,\r
+              CHECK\r
+              );\r
+\r
+    if (!EFI_ERROR (Status)) {\r
+      NeedClose = FALSE;\r
+      Status = gBS->InstallMultipleProtocolInterfaces (\r
+                      &ControllerHandle,\r
+                      &gEfiConsoleOutDeviceGuid,\r
+                      NULL,\r
+                      NULL\r
+                      );\r
+    }\r
+    //\r
+    // If the device path is an instance in the StdErr environment variable,\r
+    // then install EfiStandardErrorDeviceGuid onto ControllerHandle\r
+    //\r
+    Status = ConPlatformUpdateDeviceVariable (\r
+              VarErrorOut,\r
+              DevicePath,\r
+              CHECK\r
+              );\r
+    if (!EFI_ERROR (Status)) {\r
+      NeedClose = FALSE;\r
+      gBS->InstallMultipleProtocolInterfaces (\r
+            &ControllerHandle,\r
+            &gEfiStandardErrorDeviceGuid,\r
+            NULL,\r
+            NULL\r
+            );\r
+    }\r
+\r
+    if (NeedClose) {\r
+      gBS->CloseProtocol (\r
+            ControllerHandle,\r
+            &gEfiSimpleTextOutProtocolGuid,\r
+            This->DriverBindingHandle,\r
+            ControllerHandle\r
+            );\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConPlatformTextInDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+  (Standard DriverBinding Protocol Stop() function)\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+\r
+  //\r
+  // hot plug device is not included into the console associated variables,\r
+  // so no need to check variable for those hot plug devices.\r
+  //\r
+  if (!IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) {\r
+    //\r
+    // Get the Device Path Protocol so the environment variables can be updated\r
+    //\r
+    Status = gBS->OpenProtocol (\r
+                    ControllerHandle,\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    (VOID **) &DevicePath,\r
+                    This->DriverBindingHandle,\r
+                    ControllerHandle,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Remove DevicePath from ConInDev\r
+      //\r
+      ConPlatformUpdateDeviceVariable (\r
+        VarConsoleInpDev,\r
+        DevicePath,\r
+        DELETE\r
+        );\r
+    }\r
+  }\r
+  //\r
+  // Uninstall the Console Device GUIDs from Controller Handle\r
+  //\r
+  ConPlatformUnInstallProtocol (\r
+    This,\r
+    ControllerHandle,\r
+    &gEfiConsoleInDeviceGuid\r
+    );\r
+\r
+  //\r
+  // Close the Simple Input Protocol\r
+  //\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        &gEfiSimpleTextInProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        ControllerHandle\r
+        );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConPlatformTextOutDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+  (Standard DriverBinding Protocol Stop() function)\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+\r
+  //\r
+  // hot plug device is not included into the console associated variables,\r
+  // so no need to check variable for those hot plug devices.\r
+  //\r
+  if (!IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) {\r
+    //\r
+    // Get the Device Path Protocol so the environment variables can be updated\r
+    //\r
+    Status = gBS->OpenProtocol (\r
+                    ControllerHandle,\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    (VOID **) &DevicePath,\r
+                    This->DriverBindingHandle,\r
+                    ControllerHandle,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Remove DevicePath from ConOutDev, and StdErrDev\r
+      //\r
+      ConPlatformUpdateDeviceVariable (\r
+        VarConsoleOutDev,\r
+        DevicePath,\r
+        DELETE\r
+        );\r
+      ConPlatformUpdateDeviceVariable (\r
+        VarErrorOutDev,\r
+        DevicePath,\r
+        DELETE\r
+        );\r
+    }\r
+  }\r
+  //\r
+  // Uninstall the Console Device GUIDs from Controller Handle\r
+  //\r
+  ConPlatformUnInstallProtocol (\r
+    This,\r
+    ControllerHandle,\r
+    &gEfiConsoleOutDeviceGuid\r
+    );\r
+\r
+  ConPlatformUnInstallProtocol (\r
+    This,\r
+    ControllerHandle,\r
+    &gEfiStandardErrorDeviceGuid\r
+    );\r
+\r
+  //\r
+  // Close the Simple Text Output Protocol\r
+  //\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        &gEfiSimpleTextOutProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        ControllerHandle\r
+        );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+VOID\r
+ConPlatformUnInstallProtocol (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_GUID                     *ProtocolGuid\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  ProtocolGuid,\r
+                  NULL,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->UninstallMultipleProtocolInterfaces (\r
+          Handle,\r
+          ProtocolGuid,\r
+          NULL,\r
+          NULL\r
+          );\r
+  }\r
+\r
+  return ;\r
+}\r
+\r
+VOID *\r
+ConPlatformGetVariable (\r
+  IN  CHAR16    *Name\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Read the EFI variable (Name) and return a dynamically allocated\r
+  buffer, and the size of the buffer. On failure return NULL.\r
+\r
+Arguments:\r
+  Name       - String part of EFI variable name\r
+\r
+Returns:\r
+  Dynamically allocated memory that contains a copy of the EFI variable.\r
+  Caller is repsoncible freeing the buffer.\r
+\r
+  NULL - Variable was not read\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  VOID        *Buffer;\r
+  UINTN       BufferSize;\r
+\r
+  BufferSize  = 0;\r
+  Buffer      = NULL;\r
+\r
+  //\r
+  // Test to see if the variable exists.  If it doesn't reuturn NULL\r
+  //\r
+  Status = gRT->GetVariable (\r
+                  Name,\r
+                  &gEfiGlobalVariableGuid,\r
+                  NULL,\r
+                  &BufferSize,\r
+                  Buffer\r
+                  );\r
+\r
+  if (Status == EFI_BUFFER_TOO_SMALL) {\r
+    //\r
+    // Allocate the buffer to return\r
+    //\r
+    Buffer = AllocatePool (BufferSize);\r
+    if (Buffer == NULL) {\r
+      return NULL;\r
+    }\r
+    //\r
+    // Read variable into the allocated buffer.\r
+    //\r
+    Status = gRT->GetVariable (\r
+                    Name,\r
+                    &gEfiGlobalVariableGuid,\r
+                    NULL,\r
+                    &BufferSize,\r
+                    Buffer\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      FreePool (Buffer);\r
+      Buffer = NULL;\r
+    }\r
+  }\r
+\r
+  return Buffer;\r
+}\r
+\r
+EFI_STATUS\r
+ConPlatformMatchDevicePaths (\r
+  IN  EFI_DEVICE_PATH_PROTOCOL  * Multi,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL  * Single,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath OPTIONAL,\r
+  IN  BOOLEAN                   Delete\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Function compares a device path data structure to that of all the nodes of a\r
+  second device path instance.\r
+\r
+Arguments:\r
+  Multi        - A pointer to a multi-instance device path data structure.\r
+\r
+  Single       - A pointer to a single-instance device path data structure.\r
+\r
+  NewDevicePath - If Delete is TRUE, this parameter must not be null, and it\r
+                  points to the remaining device path data structure.\r
+                  (remaining device path = Multi - Single.)\r
+\r
+  Delete        - If TRUE, means removing Single from Multi.\r
+                  If FALSE, the routine just check whether Single matches\r
+                  with any instance in Multi.\r
+\r
+Returns:\r
+\r
+  The function returns EFI_SUCCESS if the Single is contained within Multi.\r
+  Otherwise, EFI_NOT_FOUND is returned.\r
+\r
+--*/\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath1;\r
+  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath2;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePathInst;\r
+  UINTN                     Size;\r
+\r
+  //\r
+  // The passed in DevicePath should not be NULL\r
+  //\r
+  if ((!Multi) || (!Single)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  //\r
+  // if performing Delete operation, the NewDevicePath must not be NULL.\r
+  //\r
+  TempDevicePath1 = NULL;\r
+\r
+  DevicePath      = Multi;\r
+  DevicePathInst  = GetNextDevicePathInstance (&DevicePath, &Size);\r
+\r
+  //\r
+  // search for the match of 'Single' in 'Multi'\r
+  //\r
+  while (DevicePathInst) {\r
+    if (CompareMem (Single, DevicePathInst, Size) == 0) {\r
+      if (!Delete) {\r
+        FreePool (DevicePathInst);\r
+        return EFI_SUCCESS;\r
+      }\r
+    } else {\r
+      if (Delete) {\r
+        TempDevicePath2 = AppendDevicePathInstance (\r
+                            TempDevicePath1,\r
+                            DevicePathInst\r
+                            );\r
+        if (TempDevicePath1 != NULL) {\r
+          FreePool (TempDevicePath1);\r
+        }\r
+        TempDevicePath1 = TempDevicePath2;\r
+      }\r
+    }\r
+\r
+    FreePool (DevicePathInst);\r
+    DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
+  }\r
+\r
+  if (Delete) {\r
+    *NewDevicePath = TempDevicePath1;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+EFI_STATUS\r
+ConPlatformUpdateDeviceVariable (\r
+  IN  CHAR16                    *VariableName,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL  *DevicePath,\r
+  IN  CONPLATFORM_VAR_OPERATION Operation\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_DEVICE_PATH_PROTOCOL  *VariableDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *NewVariableDevicePath;\r
+\r
+  VariableDevicePath    = NULL;\r
+  NewVariableDevicePath = NULL;\r
+\r
+  //\r
+  // Get Variable according to variable name.\r
+  // The memory for Variable is allocated within ConPlatformGetVarible(),\r
+  // it is the caller's responsibility to free the memory before return.\r
+  //\r
+  VariableDevicePath = ConPlatformGetVariable (VariableName);\r
+\r
+  if (Operation != DELETE) {\r
+\r
+    Status = ConPlatformMatchDevicePaths (\r
+              VariableDevicePath,\r
+              DevicePath,\r
+              NULL,\r
+              FALSE\r
+              );\r
+\r
+    if ((Operation == CHECK) || (!EFI_ERROR (Status))) {\r
+      //\r
+      // The device path is already in the variable\r
+      //\r
+      if (VariableDevicePath != NULL) {\r
+        FreePool (VariableDevicePath);\r
+      }\r
+\r
+      return Status;\r
+    }\r
+    //\r
+    // The device path is not in variable. Append DevicePath to the\r
+    // environment variable that is a multi-instance device path.\r
+    //\r
+    Status = EFI_SUCCESS;\r
+    NewVariableDevicePath = AppendDevicePathInstance (\r
+                              VariableDevicePath,\r
+                              DevicePath\r
+                              );\r
+    if (NewVariableDevicePath == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
+  } else {\r
+    //\r
+    // Remove DevicePath from the environment variable that\r
+    // is a multi-instance device path.\r
+    //\r
+    Status = ConPlatformMatchDevicePaths (\r
+              VariableDevicePath,\r
+              DevicePath,\r
+              &NewVariableDevicePath,\r
+              TRUE\r
+              );\r
+  }\r
+\r
+  if (VariableDevicePath != NULL) {\r
+    FreePool (VariableDevicePath);\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = gRT->SetVariable (\r
+                  VariableName,\r
+                  &gEfiGlobalVariableGuid,\r
+                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                  GetDevicePathSize (NewVariableDevicePath),\r
+                  NewVariableDevicePath\r
+                  );\r
+\r
+  FreePool (NewVariableDevicePath);\r
+\r
+  return Status;\r
+}\r
+\r
+BOOLEAN\r
+IsHotPlugDevice (\r
+  EFI_HANDLE    DriverBindingHandle,\r
+  EFI_HANDLE    ControllerHandle\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // HotPlugDeviceGuid indicates ControllerHandle stands for a hot plug device.\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiHotPlugDeviceGuid,\r
+                  NULL,\r
+                  DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+\r
+  return TRUE;\r
+}\r
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
new file mode 100644 (file)
index 0000000..a103515
--- /dev/null
@@ -0,0 +1,132 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+    ConPlatform.h\r
+    \r
+Abstract:\r
+\r
+--*/\r
+\r
+#ifndef CON_MANAGE_H_\r
+#define CON_MANAGE_H_\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#define VarConsoleInpDev  L"ConInDev"\r
+#define VarConsoleInp     L"ConIn"\r
+#define VarConsoleOutDev  L"ConOutDev"\r
+#define VarConsoleOut     L"ConOut"\r
+#define VarErrorOutDev    L"ErrOutDev"\r
+#define VarErrorOut       L"ErrOut"\r
+\r
+typedef enum {\r
+  CHECK,\r
+  APPEND,\r
+  DELETE\r
+} CONPLATFORM_VAR_OPERATION;\r
+\r
+EFI_STATUS\r
+ConPlatformDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath,\r
+  IN  EFI_GUID                     *ProtocolGuid\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConPlatformTextInDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConPlatformTextOutDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConPlatformTextInDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConPlatformTextOutDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConPlatformTextInDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConPlatformTextOutDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  );\r
+\r
+VOID\r
+ConPlatformUnInstallProtocol (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_GUID                     *ProtocolGuid\r
+  );\r
+\r
+VOID *\r
+ConPlatformGetVariable (\r
+  IN  CHAR16              *Name\r
+  );\r
+\r
+EFI_STATUS\r
+ConPlatformMatchDevicePaths (\r
+  IN  EFI_DEVICE_PATH_PROTOCOL  * Multi,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL  * Single,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath OPTIONAL,\r
+  IN  BOOLEAN                   Delete\r
+  );\r
+\r
+EFI_STATUS\r
+ConPlatformUpdateDeviceVariable (\r
+  IN  CHAR16                    *VariableName,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL  *DevicePath,\r
+  IN  CONPLATFORM_VAR_OPERATION Operation\r
+  );\r
+\r
+BOOLEAN\r
+IsHotPlugDevice (\r
+  EFI_HANDLE    DriverBindingHandle,\r
+  EFI_HANDLE    ControllerHandle\r
+  );\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.inf b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.inf
new file mode 100644 (file)
index 0000000..ede8698
--- /dev/null
@@ -0,0 +1,112 @@
+#/** @file\r
+# Console Platfrom Driver\r
+#\r
+# Console Platfrom DXE Driver, install Console protocols\r
+# Copyright (c) 2006 - 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                      = ConPlatform\r
+  FILE_GUID                      = 51ccf399-4fdf-4e55-a45b-e123f84d456a\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeConPlatform\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+#  DRIVER_BINDING                =  gConPlatformTextInDriverBinding              \r
+#  COMPONENT_NAME                =  gConPlatformComponentName                    \r
+#  DRIVER_BINDING                =  gConPlatformTextOutDriverBinding             \r
+#  COMPONENT_NAME                =  gConPlatformComponentName                    \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
+  ComponentName.c\r
+  ComponentName.h\r
+  ConPlatform.h\r
+  ConPlatform.c\r
+  CommonHeader.h\r
+\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
+  MemoryAllocationLib\r
+  DevicePathLib\r
+  UefiRuntimeServicesTableLib\r
+  UefiBootServicesTableLib\r
+  BaseMemoryLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\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
+  gEfiGlobalVariableGuid                        # SOMETIMES_CONSUMED L"ErrOut"\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
+  gEfiHotPlugDeviceGuid                         # PROTOCOL TO_START\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL TO_START\r
+  gEfiSimpleTextInProtocolGuid                  # PROTOCOL TO_START\r
+  gEfiSimpleTextOutProtocolGuid                 # PROTOCOL TO_START\r
+  gEfiStandardErrorDeviceGuid                   # PROTOCOL BY_START\r
+  gEfiConsoleOutDeviceGuid                      # PROTOCOL BY_START\r
+  gEfiConsoleInDeviceGuid                       # PROTOCOL BY_START\r
+\r
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.msa b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.msa
new file mode 100644 (file)
index 0000000..a4300e5
--- /dev/null
@@ -0,0 +1,135 @@
+<?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>ConPlatform</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>51ccf399-4fdf-4e55-a45b-e123f84d456a</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Console Platfrom Driver</Abstract>\r
+    <Description>Console Platfrom DXE Driver, install Console protocols</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
+    <License>All rights reserved. This program and the accompanying materials\r
+      are licensed and made available under the terms and conditions of the BSD License\r
+      which accompanies this distribution.  The full text of the license may be found at\r
+      http://opensource.org/licenses/bsd-license.php\r
+      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+      WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>ConPlatform</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverModelLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</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
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiRuntimeServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DevicePathLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>ConPlatform.c</Filename>\r
+    <Filename>ConPlatform.h</Filename>\r
+    <Filename>ComponentName.h</Filename>\r
+    <Filename>ComponentName.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiConsoleInDeviceGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiConsoleOutDeviceGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiStandardErrorDeviceGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiSimpleTextOutProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiSimpleTextInProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiHotPlugDeviceGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Variables>\r
+    <Variable Usage="SOMETIMES_CONSUMED">\r
+      <VariableName>0x0043 0x006F 0x006E 0x0049 0x006E 0x0044 0x0065 0x0076</VariableName>\r
+      <GuidC_Name>gEfiGlobalVariableGuid</GuidC_Name>\r
+      <HelpText>L"ConInDev" global variable will be updated if the serial device is not a hot plug device.</HelpText>\r
+    </Variable>\r
+    <Variable Usage="SOMETIMES_CONSUMED">\r
+      <VariableName>0x0043 0x006F 0x006E 0x0049 0x006E</VariableName>\r
+      <GuidC_Name>gEfiGlobalVariableGuid</GuidC_Name>\r
+      <HelpText>L"ConIn" global variable will be updated if the serial device is not a hot plug device.</HelpText>\r
+    </Variable>\r
+    <Variable Usage="SOMETIMES_CONSUMED">\r
+      <VariableName>0x0043 0x006F 0x006E 0x004F 0x0075 0x0074 0x0044 0x0065 0x0076</VariableName>\r
+      <GuidC_Name>gEfiGlobalVariableGuid</GuidC_Name>\r
+      <HelpText>L"ConOutDev" global variable will be updated if the serial device is not a hot plug device.</HelpText>\r
+    </Variable>\r
+    <Variable Usage="SOMETIMES_CONSUMED">\r
+      <VariableName>0x0043 0x006F 0x006E 0x004F 0x0075 0x0074</VariableName>\r
+      <GuidC_Name>gEfiGlobalVariableGuid</GuidC_Name>\r
+      <HelpText>L"ConOut" global variable will be updated if the serial device is not a hot plug device.</HelpText>\r
+    </Variable>\r
+    <Variable Usage="SOMETIMES_CONSUMED">\r
+      <VariableName>0x0045 0x0072 0x0072 0x004F 0x0075 0x0074 0x0044 0x0065 0x0076</VariableName>\r
+      <GuidC_Name>gEfiGlobalVariableGuid</GuidC_Name>\r
+      <HelpText>L"ErrOutDev" global variable will be updated if the serial device is not a hot plug device.</HelpText>\r
+    </Variable>\r
+    <Variable Usage="SOMETIMES_CONSUMED">\r
+      <VariableName>0x0045 0x0072 0x0072 0x004F 0x0075 0x0074</VariableName>\r
+      <GuidC_Name>gEfiGlobalVariableGuid</GuidC_Name>\r
+      <HelpText>L"ErrOut" global variable will be updated if the serial device is not a hot plug device.</HelpText>\r
+    </Variable>\r
+  </Variables>\r
+  <Guids>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiGlobalVariableGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <DriverBinding>gConPlatformTextInDriverBinding</DriverBinding>\r
+      <ComponentName>gConPlatformComponentName</ComponentName>\r
+    </Extern>\r
+    <Extern>\r
+      <DriverBinding>gConPlatformTextOutDriverBinding</DriverBinding>\r
+      <ComponentName>gConPlatformComponentName</ComponentName>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdeModulePkg/Universal/Console/ConSplitterDxe/CommonHeader.h b/MdeModulePkg/Universal/Console/ConSplitterDxe/CommonHeader.h
new file mode 100644 (file)
index 0000000..7feaec4
--- /dev/null
@@ -0,0 +1,61 @@
+/**@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) 2006 - 2007, Intel Corporation\r
+  All rights reserved. This program and the accompanying materials\r
+   are licensed and made available under the terms and conditions of the BSD License\r
+   which accompanies this distribution. The full text of the license may be found at\r
+   http://opensource.org/licenses/bsd-license.php\r
+   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/PrimaryStandardErrorDevice.h>\r
+#include <Guid/PrimaryConsoleOutDevice.h>\r
+#include <Protocol/GraphicsOutput.h>\r
+#include <Guid/PrimaryConsoleInDevice.h>\r
+#include <Protocol/SimplePointer.h>\r
+#include <Protocol/SimpleTextOut.h>\r
+#include <Guid/ConsoleInDevice.h>\r
+#include <Protocol/SimpleTextIn.h>\r
+#include <Protocol/ConsoleControl.h>\r
+#include <Guid/StandardErrorDevice.h>\r
+#include <Guid/ConsoleOutDevice.h>\r
+#include <Protocol/UgaDraw.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+//\r
+// Driver Binding Externs\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL gConSplitterConInDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL gConSplitterConInComponentName;\r
+extern EFI_DRIVER_BINDING_PROTOCOL gConSplitterSimplePointerDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL gConSplitterSimplePointerComponentName;\r
+extern EFI_DRIVER_BINDING_PROTOCOL gConSplitterConOutDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL gConSplitterConOutComponentName;\r
+extern EFI_DRIVER_BINDING_PROTOCOL gConSplitterStdErrDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL gConSplitterStdErrComponentName;\r
+\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/Console/ConSplitterDxe/ComponentName.c b/MdeModulePkg/Universal/Console/ConSplitterDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..6d1bf15
--- /dev/null
@@ -0,0 +1,485 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  ComponentName.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "ConSplitter.h"\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+EFI_COMPONENT_NAME_PROTOCOL     gConSplitterConInComponentName = {\r
+  ConSplitterComponentNameGetDriverName,\r
+  ConSplitterConInComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+EFI_COMPONENT_NAME_PROTOCOL     gConSplitterSimplePointerComponentName = {\r
+  ConSplitterComponentNameGetDriverName,\r
+  ConSplitterSimplePointerComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+EFI_COMPONENT_NAME_PROTOCOL     gConSplitterConOutComponentName = {\r
+  ConSplitterComponentNameGetDriverName,\r
+  ConSplitterConOutComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+EFI_COMPONENT_NAME_PROTOCOL     gConSplitterStdErrComponentName = {\r
+  ConSplitterComponentNameGetDriverName,\r
+  ConSplitterStdErrComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mConSplitterDriverNameTable[] = {\r
+  {\r
+    "eng",\r
+    (CHAR16 *) L"Console Splitter Driver"\r
+  },\r
+  {\r
+    NULL,\r
+    NULL\r
+  }\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mConSplitterConInControllerNameTable[] = {\r
+  {\r
+    "eng",\r
+    (CHAR16 *) L"Primary Console Input Device"\r
+  },\r
+  {\r
+    NULL,\r
+    NULL\r
+  }\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mConSplitterSimplePointerControllerNameTable[] = {\r
+  {\r
+    "eng",\r
+    (CHAR16 *) L"Primary Simple Pointer Device"\r
+  },\r
+  {\r
+    NULL,\r
+    NULL\r
+  }\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mConSplitterConOutControllerNameTable[] = {\r
+  {\r
+    "eng",\r
+    (CHAR16 *) L"Primary Console Output Device"\r
+  },\r
+  {\r
+    NULL,\r
+    NULL\r
+  }\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mConSplitterStdErrControllerNameTable[] = {\r
+  {\r
+    "eng",\r
+    (CHAR16 *) L"Primary Standard Error Device"\r
+  },\r
+  {\r
+    NULL,\r
+    NULL\r
+  }\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
+\r
+  Arguments:\r
+    This       - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    Language   - A pointer to a three character ISO 639-2 language identifier.\r
+                 This is the language of the driver name that that the caller \r
+                 is requesting, and it must match one of the languages specified\r
+                 in SupportedLanguages.  The number of languages supported by a \r
+                 driver is up to the driver writer.\r
+    DriverName - A pointer to the Unicode string to return.  This Unicode string\r
+                 is the name of the driver specified by This in the language \r
+                 specified by Language.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the Driver specified by This\r
+                            and the language specified by Language was returned \r
+                            in DriverName.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - DriverName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  return LookupUnicodeString (\r
+           Language,\r
+           gConSplitterConInComponentName.SupportedLanguages,\r
+           mConSplitterDriverNameTable,\r
+           DriverName\r
+           );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterConInComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the controller\r
+    that is being managed by an EFI Driver.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    ControllerHandle - The handle of a controller that the driver specified by \r
+                       This is managing.  This handle specifies the controller \r
+                       whose name is to be returned.\r
+    ChildHandle      - The handle of the child controller to retrieve the name \r
+                       of.  This is an optional parameter that may be NULL.  It \r
+                       will be NULL for device drivers.  It will also be NULL \r
+                       for a bus drivers that wish to retrieve the name of the \r
+                       bus controller.  It will not be NULL for a bus driver \r
+                       that wishes to retrieve the name of a child controller.\r
+    Language         - A pointer to a three character ISO 639-2 language \r
+                       identifier.  This is the language of the controller name \r
+                       that that the caller is requesting, and it must match one\r
+                       of the languages specified in SupportedLanguages.  The \r
+                       number of languages supported by a driver is up to the \r
+                       driver writer.\r
+    ControllerName   - A pointer to the Unicode string to return.  This Unicode\r
+                       string is the name of the controller specified by \r
+                       ControllerHandle and ChildHandle in the language \r
+                       specified by Language from the point of view of the \r
+                       driver specified by This. \r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the user readable name in the\r
+                            language specified by Language for the driver \r
+                            specified by This was returned in DriverName.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid \r
+                            EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ControllerName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently \r
+                            managing the controller specified by \r
+                            ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                     Status;\r
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn;\r
+  //\r
+  // here ChildHandle is not an Optional parameter.\r
+  //\r
+  if (ChildHandle == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiSimpleTextInProtocolGuid,\r
+                  (VOID **) &TextIn,\r
+                  NULL,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return LookupUnicodeString (\r
+           Language,\r
+           gConSplitterConInComponentName.SupportedLanguages,\r
+           mConSplitterConInControllerNameTable,\r
+           ControllerName\r
+           );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterSimplePointerComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the controller\r
+    that is being managed by an EFI Driver.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    ControllerHandle - The handle of a controller that the driver specified by \r
+                       This is managing.  This handle specifies the controller \r
+                       whose name is to be returned.\r
+    ChildHandle      - The handle of the child controller to retrieve the name \r
+                       of.  This is an optional parameter that may be NULL.  It \r
+                       will be NULL for device drivers.  It will also be NULL \r
+                       for a bus drivers that wish to retrieve the name of the \r
+                       bus controller.  It will not be NULL for a bus driver \r
+                       that wishes to retrieve the name of a child controller.\r
+    Language         - A pointer to a three character ISO 639-2 language \r
+                       identifier.  This is the language of the controller name \r
+                       that that the caller is requesting, and it must match one\r
+                       of the languages specified in SupportedLanguages.  The \r
+                       number of languages supported by a driver is up to the \r
+                       driver writer.\r
+    ControllerName   - A pointer to the Unicode string to return.  This Unicode\r
+                       string is the name of the controller specified by \r
+                       ControllerHandle and ChildHandle in the language \r
+                       specified by Language from the point of view of the \r
+                       driver specified by This. \r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the user readable name in the\r
+                            language specified by Language for the driver \r
+                            specified by This was returned in DriverName.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid \r
+                            EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ControllerName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently \r
+                            managing the controller specified by \r
+                            ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;\r
+  //\r
+  // here ChildHandle is not an Optional parameter.\r
+  //\r
+  if (ChildHandle == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiSimplePointerProtocolGuid,\r
+                  (VOID **) &SimplePointer,\r
+                  NULL,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gConSplitterSimplePointerComponentName.SupportedLanguages,\r
+          mConSplitterSimplePointerControllerNameTable,\r
+          ControllerName\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterConOutComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the controller\r
+    that is being managed by an EFI Driver.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    ControllerHandle - The handle of a controller that the driver specified by \r
+                       This is managing.  This handle specifies the controller \r
+                       whose name is to be returned.\r
+    ChildHandle      - The handle of the child controller to retrieve the name \r
+                       of.  This is an optional parameter that may be NULL.  It \r
+                       will be NULL for device drivers.  It will also be NULL \r
+                       for a bus drivers that wish to retrieve the name of the \r
+                       bus controller.  It will not be NULL for a bus driver \r
+                       that wishes to retrieve the name of a child controller.\r
+    Language         - A pointer to a three character ISO 639-2 language \r
+                       identifier.  This is the language of the controller name \r
+                       that that the caller is requesting, and it must match one\r
+                       of the languages specified in SupportedLanguages.  The \r
+                       number of languages supported by a driver is up to the \r
+                       driver writer.\r
+    ControllerName   - A pointer to the Unicode string to return.  This Unicode\r
+                       string is the name of the controller specified by \r
+                       ControllerHandle and ChildHandle in the language \r
+                       specified by Language from the point of view of the \r
+                       driver specified by This. \r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the user readable name in the\r
+                            language specified by Language for the driver \r
+                            specified by This was returned in DriverName.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid \r
+                            EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ControllerName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently \r
+                            managing the controller specified by \r
+                            ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                       Status;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *TextOut;\r
+  //\r
+  // here ChildHandle is not an Optional parameter.\r
+  //\r
+  if (ChildHandle == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiSimpleTextOutProtocolGuid,\r
+                  (VOID **) &TextOut,\r
+                  NULL,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gConSplitterConOutComponentName.SupportedLanguages,\r
+          mConSplitterConOutControllerNameTable,\r
+          ControllerName\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterStdErrComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the controller\r
+    that is being managed by an EFI Driver.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    ControllerHandle - The handle of a controller that the driver specified by \r
+                       This is managing.  This handle specifies the controller \r
+                       whose name is to be returned.\r
+    ChildHandle      - The handle of the child controller to retrieve the name \r
+                       of.  This is an optional parameter that may be NULL.  It \r
+                       will be NULL for device drivers.  It will also be NULL \r
+                       for a bus drivers that wish to retrieve the name of the \r
+                       bus controller.  It will not be NULL for a bus driver \r
+                       that wishes to retrieve the name of a child controller.\r
+    Language         - A pointer to a three character ISO 639-2 language \r
+                       identifier.  This is the language of the controller name \r
+                       that that the caller is requesting, and it must match one\r
+                       of the languages specified in SupportedLanguages.  The \r
+                       number of languages supported by a driver is up to the \r
+                       driver writer.\r
+    ControllerName   - A pointer to the Unicode string to return.  This Unicode\r
+                       string is the name of the controller specified by \r
+                       ControllerHandle and ChildHandle in the language \r
+                       specified by Language from the point of view of the \r
+                       driver specified by This. \r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the user readable name in the\r
+                            language specified by Language for the driver \r
+                            specified by This was returned in DriverName.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid \r
+                            EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ControllerName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently \r
+                            managing the controller specified by \r
+                            ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                       Status;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *ErrOut;\r
+  //\r
+  // here ChildHandle is not an Optional parameter.\r
+  //\r
+  if (ChildHandle == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiSimpleTextOutProtocolGuid,\r
+                  (VOID **) &ErrOut,\r
+                  NULL,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gConSplitterStdErrComponentName.SupportedLanguages,\r
+          mConSplitterStdErrControllerNameTable,\r
+          ControllerName\r
+          );\r
+}\r
diff --git a/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c b/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c
new file mode 100644 (file)
index 0000000..ead6d65
--- /dev/null
@@ -0,0 +1,3467 @@
+/**@file\r
+  Console Splitter Driver. Any Handle that attatched\r
+  EFI_CONSOLE_IDENTIFIER_PROTOCOL can be bound by this driver.\r
+\r
+  So far it works like any other driver by opening a SimpleTextIn and/or\r
+  SimpleTextOut protocol with EFI_OPEN_PROTOCOL_BY_DRIVER attributes. The big\r
+  difference is this driver does not layer a protocol on the passed in\r
+  handle, or construct a child handle like a standard device or bus driver.\r
+  This driver produces three virtual handles as children, one for console input\r
+  splitter, one for console output splitter and one for error output splitter.\r
+  EFI_CONSOLE_SPLIT_PROTOCOL will be attatched onto each virtual handle to\r
+  identify the splitter type.\r
+\r
+  Each virtual handle, that supports both the EFI_CONSOLE_SPLIT_PROTOCOL\r
+  and Console I/O protocol, will be produced in the driver entry point.\r
+  The virtual handle are added on driver entry and never removed.\r
+  Such design ensures sytem function well during none console device situation.\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
+#include "ConSplitter.h"\r
+\r
+//\r
+// Global Variables\r
+//\r
+STATIC TEXT_IN_SPLITTER_PRIVATE_DATA  mConIn = {\r
+  TEXT_IN_SPLITTER_PRIVATE_DATA_SIGNATURE,\r
+  (EFI_HANDLE) NULL,\r
+  {\r
+    ConSplitterTextInReset,\r
+    ConSplitterTextInReadKeyStroke,\r
+    (EFI_EVENT) NULL\r
+  },\r
+  0,\r
+  (EFI_SIMPLE_TEXT_INPUT_PROTOCOL **) NULL,\r
+  0,\r
+\r
+  {\r
+    ConSplitterSimplePointerReset,\r
+    ConSplitterSimplePointerGetState,\r
+    (EFI_EVENT) NULL,\r
+    (EFI_SIMPLE_POINTER_MODE *) NULL\r
+  },\r
+  {\r
+    0x10000,\r
+    0x10000,\r
+    0x10000,\r
+    TRUE,\r
+    TRUE\r
+  },\r
+  0,\r
+  (EFI_SIMPLE_POINTER_PROTOCOL **) NULL,\r
+  0,\r
+\r
+  FALSE,\r
+  {\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\r
+  },\r
+  0,\r
+  {\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\r
+  },\r
+  (EFI_EVENT) NULL,\r
+\r
+  FALSE,\r
+  FALSE\r
+};\r
+\r
+STATIC TEXT_OUT_SPLITTER_PRIVATE_DATA mConOut = {\r
+  TEXT_OUT_SPLITTER_PRIVATE_DATA_SIGNATURE,\r
+  (EFI_HANDLE) NULL,\r
+  {\r
+    ConSplitterTextOutReset,\r
+    ConSplitterTextOutOutputString,\r
+    ConSplitterTextOutTestString,\r
+    ConSplitterTextOutQueryMode,\r
+    ConSplitterTextOutSetMode,\r
+    ConSplitterTextOutSetAttribute,\r
+    ConSplitterTextOutClearScreen,\r
+    ConSplitterTextOutSetCursorPosition,\r
+    ConSplitterTextOutEnableCursor,\r
+    (EFI_SIMPLE_TEXT_OUTPUT_MODE *) NULL\r
+  },\r
+  {\r
+    1,\r
+    0,\r
+    0,\r
+    0,\r
+    0,\r
+    FALSE,\r
+  },\r
+  {\r
+    ConSpliterGraphicsOutputQueryMode,\r
+    ConSpliterGraphicsOutputSetMode,\r
+    ConSpliterGraphicsOutputBlt,\r
+    NULL\r
+  },\r
+  (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) NULL,\r
+  (TEXT_OUT_GOP_MODE *) NULL,\r
+  0,\r
+  TRUE,\r
+  {\r
+    ConSpliterConsoleControlGetMode,\r
+    ConSpliterConsoleControlSetMode,\r
+    ConSpliterConsoleControlLockStdIn\r
+  },\r
+\r
+  0,\r
+  (TEXT_OUT_AND_GOP_DATA *) NULL,\r
+  0,\r
+  (TEXT_OUT_SPLITTER_QUERY_DATA *) NULL,\r
+  0,\r
+  (INT32 *) NULL,\r
+\r
+  EfiConsoleControlScreenText,\r
+  0,\r
+  0,\r
+  (CHAR16 *) NULL,\r
+  (INT32 *) NULL\r
+};\r
+\r
+STATIC TEXT_OUT_SPLITTER_PRIVATE_DATA mStdErr = {\r
+  TEXT_OUT_SPLITTER_PRIVATE_DATA_SIGNATURE,\r
+  (EFI_HANDLE) NULL,\r
+  {\r
+    ConSplitterTextOutReset,\r
+    ConSplitterTextOutOutputString,\r
+    ConSplitterTextOutTestString,\r
+    ConSplitterTextOutQueryMode,\r
+    ConSplitterTextOutSetMode,\r
+    ConSplitterTextOutSetAttribute,\r
+    ConSplitterTextOutClearScreen,\r
+    ConSplitterTextOutSetCursorPosition,\r
+    ConSplitterTextOutEnableCursor,\r
+    (EFI_SIMPLE_TEXT_OUTPUT_MODE *) NULL\r
+  },\r
+  {\r
+    1,\r
+    0,\r
+    0,\r
+    0,\r
+    0,\r
+    FALSE,\r
+  },\r
+  {\r
+    ConSpliterGraphicsOutputQueryMode,\r
+    ConSpliterGraphicsOutputSetMode,\r
+    ConSpliterGraphicsOutputBlt,\r
+    NULL\r
+  },\r
+  (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) NULL,\r
+  (TEXT_OUT_GOP_MODE *) NULL,\r
+  0,\r
+  TRUE,\r
+  {\r
+    ConSpliterConsoleControlGetMode,\r
+    ConSpliterConsoleControlSetMode,\r
+    ConSpliterConsoleControlLockStdIn\r
+  },\r
+\r
+  0,\r
+  (TEXT_OUT_AND_GOP_DATA *) NULL,\r
+  0,\r
+  (TEXT_OUT_SPLITTER_QUERY_DATA *) NULL,\r
+  0,\r
+  (INT32 *) NULL,\r
+\r
+  EfiConsoleControlScreenText,\r
+  0,\r
+  0,\r
+  (CHAR16 *) NULL,\r
+  (INT32 *) NULL\r
+};\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL           gConSplitterConInDriverBinding = {\r
+  ConSplitterConInDriverBindingSupported,\r
+  ConSplitterConInDriverBindingStart,\r
+  ConSplitterConInDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL           gConSplitterSimplePointerDriverBinding = {\r
+  ConSplitterSimplePointerDriverBindingSupported,\r
+  ConSplitterSimplePointerDriverBindingStart,\r
+  ConSplitterSimplePointerDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL           gConSplitterConOutDriverBinding = {\r
+  ConSplitterConOutDriverBindingSupported,\r
+  ConSplitterConOutDriverBindingStart,\r
+  ConSplitterConOutDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL           gConSplitterStdErrDriverBinding = {\r
+  ConSplitterStdErrDriverBindingSupported,\r
+  ConSplitterStdErrDriverBindingStart,\r
+  ConSplitterStdErrDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+/**\r
+  The user Entry Point for module ConSplitter. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeConSplitter(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  //\r
+  // Install driver model protocol(s).\r
+  //\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gConSplitterConInDriverBinding,\r
+             ImageHandle,\r
+             &gConSplitterConInComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gConSplitterSimplePointerDriverBinding,\r
+             NULL,\r
+             &gConSplitterSimplePointerComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gConSplitterConOutDriverBinding,\r
+             NULL,\r
+             &gConSplitterConOutComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gConSplitterStdErrDriverBinding,\r
+             NULL,\r
+             &gConSplitterStdErrComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  //\r
+  // Call the original Entry Point\r
+  //\r
+  Status = ConSplitterDriverEntry (ImageHandle, SystemTable);\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterDriverEntry (\r
+  IN EFI_HANDLE                       ImageHandle,\r
+  IN EFI_SYSTEM_TABLE                 *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Intialize a virtual console device to act as an agrigator of physical console\r
+  devices.\r
+\r
+Arguments:\r
+  ImageHandle - (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r
+  SystemTable - (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r
+Returns:\r
+  EFI_SUCCESS\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // The driver creates virtual handles for ConIn, ConOut, and StdErr.\r
+  // The virtual handles will always exist even if no console exist in the\r
+  // system. This is need to support hotplug devices like USB.\r
+  //\r
+  //\r
+  // Create virtual device handle for StdErr Splitter\r
+  //\r
+  Status = ConSplitterTextOutConstructor (&mStdErr);\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &mStdErr.VirtualHandle,\r
+                    &gEfiSimpleTextOutProtocolGuid,\r
+                    &mStdErr.TextOut,\r
+                    &gEfiPrimaryStandardErrorDeviceGuid,\r
+                    NULL,\r
+                    NULL\r
+                    );\r
+  }\r
+  //\r
+  // Create virtual device handle for ConIn Splitter\r
+  //\r
+  Status = ConSplitterTextInConstructor (&mConIn);\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &mConIn.VirtualHandle,\r
+                    &gEfiSimpleTextInProtocolGuid,\r
+                    &mConIn.TextIn,\r
+                    &gEfiSimplePointerProtocolGuid,\r
+                    &mConIn.SimplePointer,\r
+                    &gEfiPrimaryConsoleInDeviceGuid,\r
+                    NULL,\r
+                    NULL\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Update the EFI System Table with new virtual console\r
+      //\r
+      gST->ConsoleInHandle  = mConIn.VirtualHandle;\r
+      gST->ConIn            = &mConIn.TextIn;\r
+    }\r
+  }\r
+  //\r
+  // Create virtual device handle for ConOut Splitter\r
+  //\r
+  Status = ConSplitterTextOutConstructor (&mConOut);\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // In UEFI mode, Graphics Output Protocol is installed on virtual handle.\r
+    //\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &mConOut.VirtualHandle,\r
+                    &gEfiSimpleTextOutProtocolGuid,\r
+                    &mConOut.TextOut,\r
+                    &gEfiGraphicsOutputProtocolGuid,\r
+                    &mConOut.GraphicsOutput,\r
+                    &gEfiConsoleControlProtocolGuid,\r
+                    &mConOut.ConsoleControl,\r
+                    &gEfiPrimaryConsoleOutDeviceGuid,\r
+                    NULL,\r
+                    NULL\r
+                    );\r
+\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Update the EFI System Table with new virtual console\r
+      //\r
+      gST->ConsoleOutHandle = mConOut.VirtualHandle;\r
+      gST->ConOut           = &mConOut.TextOut;\r
+    }\r
+\r
+  }\r
+  //\r
+  // Update the CRC32 in the EFI System Table header\r
+  //\r
+  gST->Hdr.CRC32 = 0;\r
+  gBS->CalculateCrc32 (\r
+        (UINT8 *) &gST->Hdr,\r
+        gST->Hdr.HeaderSize,\r
+        &gST->Hdr.CRC32\r
+        );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+ConSplitterTextInConstructor (\r
+  TEXT_IN_SPLITTER_PRIVATE_DATA       *ConInPrivate\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Construct the ConSplitter.\r
+\r
+Arguments:\r
+\r
+  ConInPrivate    - A pointer to the TEXT_IN_SPLITTER_PRIVATE_DATA structure.\r
+\r
+Returns:\r
+  EFI_OUT_OF_RESOURCES - Out of resources.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Initilize console input splitter's private data.\r
+  //\r
+  Status = ConSplitterGrowBuffer (\r
+            sizeof (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *),\r
+            &ConInPrivate->TextInListCount,\r
+            (VOID **) &ConInPrivate->TextInList\r
+            );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  //\r
+  // Create Event to support locking StdIn Device\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  ConSpliterConsoleControlLockStdInEvent,\r
+                  NULL,\r
+                  &ConInPrivate->LockEvent\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_WAIT,\r
+                  TPL_NOTIFY,\r
+                  ConSplitterTextInWaitForKey,\r
+                  ConInPrivate,\r
+                  &ConInPrivate->TextIn.WaitForKey\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  ConInPrivate->SimplePointer.Mode = &ConInPrivate->SimplePointerMode;\r
+\r
+  Status = ConSplitterGrowBuffer (\r
+            sizeof (EFI_SIMPLE_POINTER_PROTOCOL *),\r
+            &ConInPrivate->PointerListCount,\r
+            (VOID **) &ConInPrivate->PointerList\r
+            );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_WAIT,\r
+                  TPL_NOTIFY,\r
+                  ConSplitterSimplePointerWaitForInput,\r
+                  ConInPrivate,\r
+                  &ConInPrivate->SimplePointer.WaitForInput\r
+                  );\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+ConSplitterTextOutConstructor (\r
+  TEXT_OUT_SPLITTER_PRIVATE_DATA      *ConOutPrivate\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Initilize console output splitter's private data.\r
+  //\r
+  ConOutPrivate->TextOut.Mode = &ConOutPrivate->TextOutMode;\r
+\r
+  Status = ConSplitterGrowBuffer (\r
+            sizeof (TEXT_OUT_AND_GOP_DATA),\r
+            &ConOutPrivate->TextOutListCount,\r
+            (VOID **) &ConOutPrivate->TextOutList\r
+            );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Status = ConSplitterGrowBuffer (\r
+            sizeof (TEXT_OUT_SPLITTER_QUERY_DATA),\r
+            &ConOutPrivate->TextOutQueryDataCount,\r
+            (VOID **) &ConOutPrivate->TextOutQueryData\r
+            );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  //\r
+  // Setup the DevNullTextOut console to 80 x 25\r
+  //\r
+  ConOutPrivate->TextOutQueryData[0].Columns  = 80;\r
+  ConOutPrivate->TextOutQueryData[0].Rows     = 25;\r
+  DevNullTextOutSetMode (ConOutPrivate, 0);\r
+\r
+  //\r
+  // Setup resource for mode information in Graphics Output Protocol interface\r
+  //\r
+  if ((ConOutPrivate->GraphicsOutput.Mode = AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE))) == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  if ((ConOutPrivate->GraphicsOutput.Mode->Info = AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION))) == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  //\r
+  // Setup the DevNullGraphicsOutput to 800 x 600 x 32 bits per pixel\r
+  //\r
+  if ((ConOutPrivate->GraphicsOutputModeBuffer = AllocateZeroPool (sizeof (TEXT_OUT_GOP_MODE))) == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  ConOutPrivate->GraphicsOutputModeBuffer[0].HorizontalResolution = 800;\r
+  ConOutPrivate->GraphicsOutputModeBuffer[0].VerticalResolution = 600;\r
+\r
+  //\r
+  // Initialize the following items, theset items remain unchanged in GraphicsOutput->SetMode()\r
+  //  GraphicsOutputMode->Info->Version, GraphicsOutputMode->Info->PixelFormat\r
+  //  GraphicsOutputMode->SizeOfInfo, GraphicsOutputMode->FrameBufferBase, GraphicsOutputMode->FrameBufferSize\r
+  //\r
+  ConOutPrivate->GraphicsOutput.Mode->Info->Version = 0;\r
+  ConOutPrivate->GraphicsOutput.Mode->Info->PixelFormat = PixelBltOnly;\r
+  ConOutPrivate->GraphicsOutput.Mode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
+  ConOutPrivate->GraphicsOutput.Mode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) NULL;\r
+  ConOutPrivate->GraphicsOutput.Mode->FrameBufferSize = 0;\r
+\r
+  ConOutPrivate->GraphicsOutput.Mode->MaxMode = 1;\r
+  //\r
+  // Initial current mode to unknow state, and then set to mode 0\r
+  //\r
+  ConOutPrivate->GraphicsOutput.Mode->Mode = 0xffff;\r
+  ConOutPrivate->GraphicsOutput.SetMode (&ConOutPrivate->GraphicsOutput, 0);\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+ConSplitterSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      ControllerHandle,\r
+  IN  EFI_GUID                        *Guid\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Generic Supported Check\r
+\r
+Arguments:\r
+  This              - Pointer to protocol.\r
+  ControllerHandle  - Controller Handle.\r
+  Guid              - Guid.\r
+\r
+Returns:\r
+\r
+  EFI_UNSUPPORTED - unsupported.\r
+  EFI_SUCCESS     - operation is OK.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  VOID        *Instance;\r
+\r
+  //\r
+  // Make sure the Console Splitter does not attempt to attach to itself\r
+  //\r
+  if (ControllerHandle == mConIn.VirtualHandle) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (ControllerHandle == mConOut.VirtualHandle) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (ControllerHandle == mStdErr.VirtualHandle) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Check to see whether the handle has the ConsoleInDevice GUID on it\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  Guid,\r
+                  &Instance,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        Guid,\r
+        This->DriverBindingHandle,\r
+        ControllerHandle\r
+        );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterConInDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Console In Supported Check\r
+\r
+Arguments:\r
+  This              - Pointer to protocol.\r
+  ControllerHandle  - Controller handle.\r
+  RemainingDevicePath  - Remaining device path.\r
+\r
+Returns:\r
+\r
+  EFI_STATUS\r
+\r
+--*/\r
+{\r
+  return ConSplitterSupported (\r
+          This,\r
+          ControllerHandle,\r
+          &gEfiConsoleInDeviceGuid\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterSimplePointerDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Standard Error Supported Check\r
+\r
+Arguments:\r
+  This              - Pointer to protocol.\r
+  ControllerHandle  - Controller handle.\r
+  RemainingDevicePath  - Remaining device path.\r
+\r
+Returns:\r
+\r
+  EFI_STATUS\r
+\r
+--*/\r
+{\r
+  return ConSplitterSupported (\r
+          This,\r
+          ControllerHandle,\r
+          &gEfiSimplePointerProtocolGuid\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterConOutDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Console Out Supported Check\r
+\r
+Arguments:\r
+  This              - Pointer to protocol.\r
+  ControllerHandle  - Controller handle.\r
+  RemainingDevicePath  - Remaining device path.\r
+\r
+Returns:\r
+\r
+  EFI_STATUS\r
+\r
+--*/\r
+{\r
+  return ConSplitterSupported (\r
+          This,\r
+          ControllerHandle,\r
+          &gEfiConsoleOutDeviceGuid\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterStdErrDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Standard Error Supported Check\r
+\r
+Arguments:\r
+  This              - Pointer to protocol.\r
+  ControllerHandle  - Controller handle.\r
+  RemainingDevicePath  - Remaining device path.\r
+\r
+Returns:\r
+\r
+  EFI_STATUS\r
+\r
+--*/\r
+{\r
+  return ConSplitterSupported (\r
+          This,\r
+          ControllerHandle,\r
+          &gEfiStandardErrorDeviceGuid\r
+          );\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      ControllerHandle,\r
+  IN  EFI_HANDLE                      ConSplitterVirtualHandle,\r
+  IN  EFI_GUID                        *DeviceGuid,\r
+  IN  EFI_GUID                        *InterfaceGuid,\r
+  IN  VOID                            **Interface\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Start ConSplitter on ControllerHandle, and create the virtual\r
+  agrogated console device on first call Start for a SimpleTextIn handle.\r
+\r
+Arguments:\r
+  (Standard DriverBinding Protocol Start() function)\r
+\r
+Returns:\r
+  EFI_ERROR if a SimpleTextIn protocol is not started.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  VOID        *Instance;\r
+\r
+  //\r
+  // Check to see whether the handle has the ConsoleInDevice GUID on it\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  DeviceGuid,\r
+                  &Instance,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  DeviceGuid,\r
+                  &Instance,\r
+                  This->DriverBindingHandle,\r
+                  ConSplitterVirtualHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return gBS->OpenProtocol (\r
+                ControllerHandle,\r
+                InterfaceGuid,\r
+                Interface,\r
+                This->DriverBindingHandle,\r
+                ConSplitterVirtualHandle,\r
+                EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterConInDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Start ConSplitter on ControllerHandle, and create the virtual\r
+  agrogated console device on first call Start for a SimpleTextIn handle.\r
+\r
+Arguments:\r
+  This              - Pointer to protocol.\r
+  ControllerHandle  - Controller handle.\r
+  RemainingDevicePath  - Remaining device path.\r
+\r
+Returns:\r
+\r
+  EFI_STATUS\r
+  EFI_ERROR if a SimpleTextIn protocol is not started.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                     Status;\r
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn;\r
+\r
+  //\r
+  // Start ConSplitter on ControllerHandle, and create the virtual\r
+  // agrogated console device on first call Start for a SimpleTextIn handle.\r
+  //\r
+  Status = ConSplitterStart (\r
+            This,\r
+            ControllerHandle,\r
+            mConIn.VirtualHandle,\r
+            &gEfiConsoleInDeviceGuid,\r
+            &gEfiSimpleTextInProtocolGuid,\r
+            (VOID **) &TextIn\r
+            );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return ConSplitterTextInAddDevice (&mConIn, TextIn);\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterSimplePointerDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Start ConSplitter on ControllerHandle, and create the virtual\r
+  agrogated console device on first call Start for a SimpleTextIn handle.\r
+\r
+Arguments:\r
+  This              - Pointer to protocol.\r
+  ControllerHandle  - Controller handle.\r
+  RemainingDevicePath  - Remaining device path.\r
+\r
+Returns:\r
+\r
+  EFI_ERROR if a SimpleTextIn protocol is not started.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;\r
+\r
+  Status = ConSplitterStart (\r
+            This,\r
+            ControllerHandle,\r
+            mConIn.VirtualHandle,\r
+            &gEfiSimplePointerProtocolGuid,\r
+            &gEfiSimplePointerProtocolGuid,\r
+            (VOID **) &SimplePointer\r
+            );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return ConSplitterSimplePointerAddDevice (&mConIn, SimplePointer);\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterConOutDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Start ConSplitter on ControllerHandle, and create the virtual\r
+  agrogated console device on first call Start for a SimpleTextIn handle.\r
+\r
+Arguments:\r
+  This              - Pointer to protocol.\r
+  ControllerHandle  - Controller handle.\r
+  RemainingDevicePath  - Remaining device path.\r
+\r
+Returns:\r
+  EFI_ERROR if a SimpleTextIn protocol is not started.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                       Status;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *TextOut;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL     *GraphicsOutput;\r
+  EFI_UGA_DRAW_PROTOCOL            *UgaDraw;\r
+\r
+  Status = ConSplitterStart (\r
+            This,\r
+            ControllerHandle,\r
+            mConOut.VirtualHandle,\r
+            &gEfiConsoleOutDeviceGuid,\r
+            &gEfiSimpleTextOutProtocolGuid,\r
+            (VOID **) &TextOut\r
+            );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Try to Open Graphics Output protocol\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiGraphicsOutputProtocolGuid,\r
+                  (VOID **) &GraphicsOutput,\r
+                  This->DriverBindingHandle,\r
+                  mConOut.VirtualHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    GraphicsOutput = NULL;\r
+  }\r
+  //\r
+  // Open UGA_DRAW protocol\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiUgaDrawProtocolGuid,\r
+                  (VOID **) &UgaDraw,\r
+                  This->DriverBindingHandle,\r
+                  mConOut.VirtualHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    UgaDraw = NULL;\r
+  }\r
+  //\r
+  // If both ConOut and StdErr incorporate the same Text Out device,\r
+  // their MaxMode and QueryData should be the intersection of both.\r
+  //\r
+  Status = ConSplitterTextOutAddDevice (&mConOut, TextOut, GraphicsOutput, UgaDraw);\r
+  ConSplitterTextOutSetAttribute (&mConOut.TextOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterStdErrDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Start ConSplitter on ControllerHandle, and create the virtual\r
+  agrogated console device on first call Start for a SimpleTextIn handle.\r
+\r
+Arguments:\r
+  This              - Pointer to protocol.\r
+  ControllerHandle  - Controller handle.\r
+  RemainingDevicePath  - Remaining device path.\r
+\r
+Returns:\r
+  EFI_ERROR if a SimpleTextIn protocol is not started.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                       Status;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *TextOut;\r
+\r
+  Status = ConSplitterStart (\r
+            This,\r
+            ControllerHandle,\r
+            mStdErr.VirtualHandle,\r
+            &gEfiStandardErrorDeviceGuid,\r
+            &gEfiSimpleTextOutProtocolGuid,\r
+            (VOID **) &TextOut\r
+            );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // If both ConOut and StdErr incorporate the same Text Out device,\r
+  // their MaxMode and QueryData should be the intersection of both.\r
+  //\r
+  Status = ConSplitterTextOutAddDevice (&mStdErr, TextOut, NULL, NULL);\r
+  ConSplitterTextOutSetAttribute (&mStdErr.TextOut, EFI_TEXT_ATTR (EFI_MAGENTA, EFI_BLACK));\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (mStdErr.CurrentNumberOfConsoles == 1) {\r
+    gST->StandardErrorHandle  = mStdErr.VirtualHandle;\r
+    gST->StdErr               = &mStdErr.TextOut;\r
+    //\r
+    // Update the CRC32 in the EFI System Table header\r
+    //\r
+    gST->Hdr.CRC32 = 0;\r
+    gBS->CalculateCrc32 (\r
+          (UINT8 *) &gST->Hdr,\r
+          gST->Hdr.HeaderSize,\r
+          &gST->Hdr.CRC32\r
+          );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      ControllerHandle,\r
+  IN  EFI_HANDLE                      ConSplitterVirtualHandle,\r
+  IN  EFI_GUID                        *DeviceGuid,\r
+  IN  EFI_GUID                        *InterfaceGuid,\r
+  IN  VOID                            **Interface\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+  (Standard DriverBinding Protocol Stop() function)\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  InterfaceGuid,\r
+                  Interface,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // close the protocol refered.\r
+  //\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        DeviceGuid,\r
+        This->DriverBindingHandle,\r
+        ConSplitterVirtualHandle\r
+        );\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        DeviceGuid,\r
+        This->DriverBindingHandle,\r
+        ControllerHandle\r
+        );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterConInDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      ControllerHandle,\r
+  IN  UINTN                           NumberOfChildren,\r
+  IN  EFI_HANDLE                      *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+  (Standard DriverBinding Protocol Stop() function)\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                     Status;\r
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn;\r
+\r
+  if (NumberOfChildren == 0) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  Status = ConSplitterStop (\r
+            This,\r
+            ControllerHandle,\r
+            mConIn.VirtualHandle,\r
+            &gEfiConsoleInDeviceGuid,\r
+            &gEfiSimpleTextInProtocolGuid,\r
+            (VOID **) &TextIn\r
+            );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Delete this console input device's data structures.\r
+  //\r
+  return ConSplitterTextInDeleteDevice (&mConIn, TextIn);\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterSimplePointerDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      ControllerHandle,\r
+  IN  UINTN                           NumberOfChildren,\r
+  IN  EFI_HANDLE                      *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+  (Standard DriverBinding Protocol Stop() function)\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;\r
+\r
+  if (NumberOfChildren == 0) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  Status = ConSplitterStop (\r
+            This,\r
+            ControllerHandle,\r
+            mConIn.VirtualHandle,\r
+            &gEfiSimplePointerProtocolGuid,\r
+            &gEfiSimplePointerProtocolGuid,\r
+            (VOID **) &SimplePointer\r
+            );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Delete this console input device's data structures.\r
+  //\r
+  return ConSplitterSimplePointerDeleteDevice (&mConIn, SimplePointer);\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterConOutDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      ControllerHandle,\r
+  IN  UINTN                           NumberOfChildren,\r
+  IN  EFI_HANDLE                      *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+  (Standard DriverBinding Protocol Stop() function)\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                       Status;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *TextOut;\r
+\r
+  if (NumberOfChildren == 0) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  Status = ConSplitterStop (\r
+            This,\r
+            ControllerHandle,\r
+            mConOut.VirtualHandle,\r
+            &gEfiConsoleOutDeviceGuid,\r
+            &gEfiSimpleTextOutProtocolGuid,\r
+            (VOID **) &TextOut\r
+            );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Delete this console output device's data structures.\r
+  //\r
+  return ConSplitterTextOutDeleteDevice (&mConOut, TextOut);\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterStdErrDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      ControllerHandle,\r
+  IN  UINTN                           NumberOfChildren,\r
+  IN  EFI_HANDLE                      *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+  (Standard DriverBinding Protocol Stop() function)\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - Complete successfully.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                       Status;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *TextOut;\r
+\r
+  if (NumberOfChildren == 0) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  Status = ConSplitterStop (\r
+            This,\r
+            ControllerHandle,\r
+            mStdErr.VirtualHandle,\r
+            &gEfiStandardErrorDeviceGuid,\r
+            &gEfiSimpleTextOutProtocolGuid,\r
+            (VOID **) &TextOut\r
+            );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Delete this console error out device's data structures.\r
+  //\r
+  Status = ConSplitterTextOutDeleteDevice (&mStdErr, TextOut);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (mStdErr.CurrentNumberOfConsoles == 0) {\r
+    gST->StandardErrorHandle  = NULL;\r
+    gST->StdErr               = NULL;\r
+    //\r
+    // Update the CRC32 in the EFI System Table header\r
+    //\r
+    gST->Hdr.CRC32 = 0;\r
+    gBS->CalculateCrc32 (\r
+          (UINT8 *) &gST->Hdr,\r
+          gST->Hdr.HeaderSize,\r
+          &gST->Hdr.CRC32\r
+          );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+ConSplitterGrowBuffer (\r
+  IN  UINTN                           SizeOfCount,\r
+  IN  UINTN                           *Count,\r
+  IN OUT  VOID                        **Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Take the passed in Buffer of size SizeOfCount and grow the buffer\r
+  by MAX (CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT, MaxGrow) * SizeOfCount\r
+  bytes. Copy the current data in Buffer to the new version of Buffer\r
+  and free the old version of buffer.\r
+\r
+\r
+Arguments:\r
+  SizeOfCount - Size of element in array\r
+  Count       - Current number of elements in array\r
+  Buffer      - Bigger version of passed in Buffer with all the data\r
+\r
+Returns:\r
+  EFI_SUCCESS - Buffer size has grown\r
+  EFI_OUT_OF_RESOURCES - Could not grow the buffer size\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  UINTN NewSize;\r
+  UINTN OldSize;\r
+  VOID  *Ptr;\r
+\r
+  //\r
+  // grow the buffer to new buffer size,\r
+  // copy the old buffer's content to the new-size buffer,\r
+  // then free the old buffer.\r
+  //\r
+  OldSize = *Count * SizeOfCount;\r
+  *Count += CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT;\r
+  NewSize = *Count * SizeOfCount;\r
+\r
+  Ptr     = AllocateZeroPool (NewSize);\r
+  if (Ptr == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  CopyMem (Ptr, *Buffer, OldSize);\r
+\r
+  if (*Buffer != NULL) {\r
+    FreePool (*Buffer);\r
+  }\r
+\r
+  *Buffer = Ptr;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+ConSplitterTextInAddDevice (\r
+  IN  TEXT_IN_SPLITTER_PRIVATE_DATA   *Private,\r
+  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *TextIn\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS\r
+  EFI_OUT_OF_RESOURCES\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // If the Text In List is full, enlarge it by calling growbuffer().\r
+  //\r
+  if (Private->CurrentNumberOfConsoles >= Private->TextInListCount) {\r
+    Status = ConSplitterGrowBuffer (\r
+              sizeof (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *),\r
+              &Private->TextInListCount,\r
+              (VOID **) &Private->TextInList\r
+              );\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  }\r
+  //\r
+  // Add the new text-in device data structure into the Text In List.\r
+  //\r
+  Private->TextInList[Private->CurrentNumberOfConsoles] = TextIn;\r
+  Private->CurrentNumberOfConsoles++;\r
+\r
+  //\r
+  // Extra CheckEvent added to reduce the double CheckEvent() in UI.c\r
+  //\r
+  gBS->CheckEvent (TextIn->WaitForKey);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+ConSplitterTextInDeleteDevice (\r
+  IN  TEXT_IN_SPLITTER_PRIVATE_DATA   *Private,\r
+  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *TextIn\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS\r
+  EFI_NOT_FOUND\r
+\r
+--*/\r
+{\r
+  UINTN Index;\r
+  //\r
+  // Remove the specified text-in device data structure from the Text In List,\r
+  // and rearrange the remaining data structures in the Text In List.\r
+  //\r
+  for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {\r
+    if (Private->TextInList[Index] == TextIn) {\r
+      for (Index = Index; Index < Private->CurrentNumberOfConsoles - 1; Index++) {\r
+        Private->TextInList[Index] = Private->TextInList[Index + 1];\r
+      }\r
+\r
+      Private->CurrentNumberOfConsoles--;\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+EFI_STATUS\r
+ConSplitterSimplePointerAddDevice (\r
+  IN  TEXT_IN_SPLITTER_PRIVATE_DATA   *Private,\r
+  IN  EFI_SIMPLE_POINTER_PROTOCOL     *SimplePointer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  EFI_OUT_OF_RESOURCES\r
+  EFI_SUCCESS\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // If the Text In List is full, enlarge it by calling growbuffer().\r
+  //\r
+  if (Private->CurrentNumberOfPointers >= Private->PointerListCount) {\r
+    Status = ConSplitterGrowBuffer (\r
+              sizeof (EFI_SIMPLE_POINTER_PROTOCOL *),\r
+              &Private->PointerListCount,\r
+              (VOID **) &Private->PointerList\r
+              );\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  }\r
+  //\r
+  // Add the new text-in device data structure into the Text In List.\r
+  //\r
+  Private->PointerList[Private->CurrentNumberOfPointers] = SimplePointer;\r
+  Private->CurrentNumberOfPointers++;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+ConSplitterSimplePointerDeleteDevice (\r
+  IN  TEXT_IN_SPLITTER_PRIVATE_DATA   *Private,\r
+  IN  EFI_SIMPLE_POINTER_PROTOCOL     *SimplePointer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  UINTN Index;\r
+  //\r
+  // Remove the specified text-in device data structure from the Text In List,\r
+  // and rearrange the remaining data structures in the Text In List.\r
+  //\r
+  for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {\r
+    if (Private->PointerList[Index] == SimplePointer) {\r
+      for (Index = Index; Index < Private->CurrentNumberOfPointers - 1; Index++) {\r
+        Private->PointerList[Index] = Private->PointerList[Index + 1];\r
+      }\r
+\r
+      Private->CurrentNumberOfPointers--;\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+ConSplitterGrowMapTable (\r
+  IN  TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  UINTN Size;\r
+  UINTN NewSize;\r
+  UINTN TotalSize;\r
+  INT32 *TextOutModeMap;\r
+  INT32 *OldTextOutModeMap;\r
+  INT32 *SrcAddress;\r
+  INT32 Index;\r
+\r
+  NewSize           = Private->TextOutListCount * sizeof (INT32);\r
+  OldTextOutModeMap = Private->TextOutModeMap;\r
+  TotalSize         = NewSize * Private->TextOutQueryDataCount;\r
+\r
+  TextOutModeMap    = AllocateZeroPool (TotalSize);\r
+  if (TextOutModeMap == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  SetMem (TextOutModeMap, TotalSize, 0xFF);\r
+  Private->TextOutModeMap = TextOutModeMap;\r
+\r
+  //\r
+  // If TextOutList has been enlarged, need to realloc the mode map table\r
+  // The mode map table is regarded as a two dimension array.\r
+  //\r
+  //                         Old                    New\r
+  //  0   ---------> TextOutListCount ----> TextOutListCount\r
+  //  |   -------------------------------------------\r
+  //  |  |                    |                      |\r
+  //  |  |                    |                      |\r
+  //  |  |                    |                      |\r
+  //  |  |                    |                      |\r
+  //  |  |                    |                      |\r
+  // \/  |                    |                      |\r
+  //      -------------------------------------------\r
+  // QueryDataCount\r
+  //\r
+  if (OldTextOutModeMap != NULL) {\r
+\r
+    Size        = Private->CurrentNumberOfConsoles * sizeof (INT32);\r
+    Index       = 0;\r
+    SrcAddress  = OldTextOutModeMap;\r
+\r
+    //\r
+    // Copy the old data to the new one\r
+    //\r
+    while (Index < Private->TextOutMode.MaxMode) {\r
+      CopyMem (TextOutModeMap, SrcAddress, Size);\r
+      TextOutModeMap += NewSize;\r
+      SrcAddress += Size;\r
+      Index++;\r
+    }\r
+    //\r
+    // Free the old buffer\r
+    //\r
+    FreePool (OldTextOutModeMap);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+ConSplitterAddOutputMode (\r
+  IN  TEXT_OUT_SPLITTER_PRIVATE_DATA     *Private,\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *TextOut\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  INT32       MaxMode;\r
+  INT32       Mode;\r
+  UINTN       Index;\r
+\r
+  MaxMode                       = TextOut->Mode->MaxMode;\r
+  Private->TextOutMode.MaxMode  = MaxMode;\r
+\r
+  //\r
+  // Grow the buffer if query data buffer is not large enough to\r
+  // hold all the mode supported by the first console.\r
+  //\r
+  while (MaxMode > (INT32) Private->TextOutQueryDataCount) {\r
+    Status = ConSplitterGrowBuffer (\r
+              sizeof (TEXT_OUT_SPLITTER_QUERY_DATA),\r
+              &Private->TextOutQueryDataCount,\r
+              (VOID **) &Private->TextOutQueryData\r
+              );\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  }\r
+  //\r
+  // Allocate buffer for the output mode map\r
+  //\r
+  Status = ConSplitterGrowMapTable (Private);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  //\r
+  // As the first textout device, directly add the mode in to QueryData\r
+  // and at the same time record the mapping between QueryData and TextOut.\r
+  //\r
+  Mode  = 0;\r
+  Index = 0;\r
+  while (Mode < MaxMode) {\r
+    TextOut->QueryMode (\r
+              TextOut,\r
+              Mode,\r
+              &Private->TextOutQueryData[Mode].Columns,\r
+              &Private->TextOutQueryData[Mode].Rows\r
+              );\r
+    Private->TextOutModeMap[Index] = Mode;\r
+    Mode++;\r
+    Index += Private->TextOutListCount;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+VOID\r
+ConSplitterGetIntersection (\r
+  IN  INT32                           *TextOutModeMap,\r
+  IN  INT32                           *NewlyAddedMap,\r
+  IN  UINTN                           MapStepSize,\r
+  IN  UINTN                           NewMapStepSize,\r
+  OUT INT32                           *MaxMode,\r
+  OUT INT32                           *CurrentMode\r
+  )\r
+{\r
+  INT32 Index;\r
+  INT32 *CurrentMapEntry;\r
+  INT32 *NextMapEntry;\r
+  INT32 CurrentMaxMode;\r
+  INT32 Mode;\r
+\r
+  Index           = 0;\r
+  CurrentMapEntry = TextOutModeMap;\r
+  NextMapEntry    = TextOutModeMap;\r
+  CurrentMaxMode  = *MaxMode;\r
+  Mode            = *CurrentMode;\r
+\r
+  while (Index < CurrentMaxMode) {\r
+    if (*NewlyAddedMap == -1) {\r
+      //\r
+      // This mode is not supported any more. Remove it. Special care\r
+      // must be taken as this remove will also affect current mode;\r
+      //\r
+      if (Index == *CurrentMode) {\r
+        Mode = -1;\r
+      } else if (Index < *CurrentMode) {\r
+        Mode--;\r
+      }\r
+      (*MaxMode)--;\r
+    } else {\r
+      if (CurrentMapEntry != NextMapEntry) {\r
+        CopyMem (NextMapEntry, CurrentMapEntry, MapStepSize * sizeof (INT32));\r
+      }\r
+\r
+      NextMapEntry += MapStepSize;\r
+    }\r
+\r
+    CurrentMapEntry += MapStepSize;\r
+    NewlyAddedMap += NewMapStepSize;\r
+    Index++;\r
+  }\r
+\r
+  *CurrentMode = Mode;\r
+\r
+  return ;\r
+}\r
+\r
+STATIC\r
+VOID\r
+ConSplitterSyncOutputMode (\r
+  IN  TEXT_OUT_SPLITTER_PRIVATE_DATA     *Private,\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *TextOut\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+  Private - Private data structure.\r
+  TextOut - Text Out Protocol.\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  INT32                         CurrentMaxMode;\r
+  INT32                         Mode;\r
+  INT32                         Index;\r
+  INT32                         *TextOutModeMap;\r
+  INT32                         *MapTable;\r
+  TEXT_OUT_SPLITTER_QUERY_DATA  *TextOutQueryData;\r
+  UINTN                         Rows;\r
+  UINTN                         Columns;\r
+  UINTN                         StepSize;\r
+\r
+  //\r
+  // Must make sure that current mode won't change even if mode number changes\r
+  //\r
+  CurrentMaxMode    = Private->TextOutMode.MaxMode;\r
+  TextOutModeMap    = Private->TextOutModeMap;\r
+  StepSize          = Private->TextOutListCount;\r
+  TextOutQueryData  = Private->TextOutQueryData;\r
+\r
+  //\r
+  // Query all the mode that the newly added TextOut supports\r
+  //\r
+  Mode      = 0;\r
+  MapTable  = TextOutModeMap + Private->CurrentNumberOfConsoles;\r
+  while (Mode < TextOut->Mode->MaxMode) {\r
+    TextOut->QueryMode (TextOut, Mode, &Columns, &Rows);\r
+\r
+    //\r
+    // Search the QueryData database to see if they intersects\r
+    //\r
+    Index = 0;\r
+    while (Index < CurrentMaxMode) {\r
+      if ((TextOutQueryData[Index].Rows == Rows) && (TextOutQueryData[Index].Columns == Columns)) {\r
+        MapTable[Index * StepSize] = Mode;\r
+        break;\r
+      }\r
+\r
+      Index++;\r
+    }\r
+\r
+    Mode++;\r
+  }\r
+  //\r
+  // Now search the TextOutModeMap table to find the intersection of supported\r
+  // mode between ConSplitter and the newly added device.\r
+  //\r
+  ConSplitterGetIntersection (\r
+    TextOutModeMap,\r
+    MapTable,\r
+    StepSize,\r
+    StepSize,\r
+    &Private->TextOutMode.MaxMode,\r
+    &Private->TextOutMode.Mode\r
+    );\r
+\r
+  return ;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+ConSplitterGetIntersectionBetweenConOutAndStrErr (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+  EFI_OUT_OF_RESOURCES\r
+\r
+--*/\r
+{\r
+  UINTN                         ConOutNumOfConsoles;\r
+  UINTN                         StdErrNumOfConsoles;\r
+  TEXT_OUT_AND_GOP_DATA         *ConOutTextOutList;\r
+  TEXT_OUT_AND_GOP_DATA         *StdErrTextOutList;\r
+  UINTN                         Indexi;\r
+  UINTN                         Indexj;\r
+  UINTN                         Rows;\r
+  UINTN                         Columns;\r
+  INT32                         ConOutMaxMode;\r
+  INT32                         StdErrMaxMode;\r
+  INT32                         Mode;\r
+  INT32                         Index;\r
+  INT32                         *ConOutModeMap;\r
+  INT32                         *StdErrModeMap;\r
+  INT32                         *ConOutMapTable;\r
+  INT32                         *StdErrMapTable;\r
+  TEXT_OUT_SPLITTER_QUERY_DATA  *ConOutQueryData;\r
+  TEXT_OUT_SPLITTER_QUERY_DATA  *StdErrQueryData;\r
+  BOOLEAN                       FoundTheSameTextOut;\r
+  UINTN                         ConOutMapTableSize;\r
+  UINTN                         StdErrMapTableSize;\r
+\r
+  ConOutNumOfConsoles = mConOut.CurrentNumberOfConsoles;\r
+  StdErrNumOfConsoles = mStdErr.CurrentNumberOfConsoles;\r
+  ConOutTextOutList   = mConOut.TextOutList;\r
+  StdErrTextOutList   = mStdErr.TextOutList;\r
+\r
+  Indexi              = 0;\r
+  FoundTheSameTextOut = FALSE;\r
+  while ((Indexi < ConOutNumOfConsoles) && (!FoundTheSameTextOut)) {\r
+    Indexj = 0;\r
+    while (Indexj < StdErrNumOfConsoles) {\r
+      if (ConOutTextOutList->TextOut == StdErrTextOutList->TextOut) {\r
+        FoundTheSameTextOut = TRUE;\r
+        break;\r
+      }\r
+\r
+      Indexj++;\r
+      StdErrTextOutList++;\r
+    }\r
+\r
+    Indexi++;\r
+    ConOutTextOutList++;\r
+  }\r
+\r
+  if (!FoundTheSameTextOut) {\r
+    return EFI_SUCCESS;\r
+  }\r
+  //\r
+  // Must make sure that current mode won't change even if mode number changes\r
+  //\r
+  ConOutMaxMode     = mConOut.TextOutMode.MaxMode;\r
+  ConOutModeMap     = mConOut.TextOutModeMap;\r
+  ConOutQueryData   = mConOut.TextOutQueryData;\r
+\r
+  StdErrMaxMode     = mStdErr.TextOutMode.MaxMode;\r
+  StdErrModeMap     = mStdErr.TextOutModeMap;\r
+  StdErrQueryData   = mStdErr.TextOutQueryData;\r
+\r
+  //\r
+  // Allocate the map table and set the map table's index to -1.\r
+  //\r
+  ConOutMapTableSize  = ConOutMaxMode * sizeof (INT32);\r
+  ConOutMapTable      = AllocateZeroPool (ConOutMapTableSize);\r
+  if (ConOutMapTable == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  SetMem (ConOutMapTable, ConOutMapTableSize, 0xFF);\r
+\r
+  StdErrMapTableSize  = StdErrMaxMode * sizeof (INT32);\r
+  StdErrMapTable      = AllocateZeroPool (StdErrMapTableSize);\r
+  if (StdErrMapTable == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  SetMem (StdErrMapTable, StdErrMapTableSize, 0xFF);\r
+\r
+  //\r
+  // Find the intersection of the two set of modes. If they actually intersect, the\r
+  // correponding entry in the map table is set to 1.\r
+  //\r
+  Mode = 0;\r
+  while (Mode < ConOutMaxMode) {\r
+    //\r
+    // Search the other's QueryData database to see if they intersect\r
+    //\r
+    Index   = 0;\r
+    Rows    = ConOutQueryData[Mode].Rows;\r
+    Columns = ConOutQueryData[Mode].Columns;\r
+    while (Index < StdErrMaxMode) {\r
+      if ((StdErrQueryData[Index].Rows == Rows) && (StdErrQueryData[Index].Columns == Columns)) {\r
+        ConOutMapTable[Mode]  = 1;\r
+        StdErrMapTable[Index] = 1;\r
+        break;\r
+      }\r
+\r
+      Index++;\r
+    }\r
+\r
+    Mode++;\r
+  }\r
+  //\r
+  // Now search the TextOutModeMap table to find the intersection of supported\r
+  // mode between ConSplitter and the newly added device.\r
+  //\r
+  ConSplitterGetIntersection (\r
+    ConOutModeMap,\r
+    ConOutMapTable,\r
+    mConOut.TextOutListCount,\r
+    1,\r
+    &(mConOut.TextOutMode.MaxMode),\r
+    &(mConOut.TextOutMode.Mode)\r
+    );\r
+  if (mConOut.TextOutMode.Mode < 0) {\r
+    mConOut.TextOut.SetMode (&(mConOut.TextOut), 0);\r
+  }\r
+\r
+  ConSplitterGetIntersection (\r
+    StdErrModeMap,\r
+    StdErrMapTable,\r
+    mStdErr.TextOutListCount,\r
+    1,\r
+    &(mStdErr.TextOutMode.MaxMode),\r
+    &(mStdErr.TextOutMode.Mode)\r
+    );\r
+  if (mStdErr.TextOutMode.Mode < 0) {\r
+    mStdErr.TextOut.SetMode (&(mStdErr.TextOut), 0);\r
+  }\r
+\r
+  FreePool (ConOutMapTable);\r
+  FreePool (StdErrMapTable);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+ConSplitterAddGraphicsOutputMode (\r
+  IN  TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private,\r
+  IN  EFI_GRAPHICS_OUTPUT_PROTOCOL    *GraphicsOutput,\r
+  IN  EFI_UGA_DRAW_PROTOCOL           *UgaDraw\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                           Status;\r
+  UINTN                                Index;\r
+  TEXT_OUT_GOP_MODE                    *Mode;\r
+  UINTN                                SizeOfInfo;\r
+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE    *CurrentGraphicsOutputMode;\r
+  TEXT_OUT_GOP_MODE                    *ModeBuffer;\r
+  TEXT_OUT_GOP_MODE                    *MatchedMode;\r
+  UINTN                                NumberIndex;\r
+  BOOLEAN                              Match;\r
+\r
+  if ((GraphicsOutput == NULL) && (UgaDraw == NULL)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  CurrentGraphicsOutputMode = Private->GraphicsOutput.Mode;\r
+\r
+  if (GraphicsOutput != NULL) {\r
+    if (Private->CurrentNumberOfGraphicsOutput == 0) {\r
+        //\r
+        // This is the first Graphics Output device added\r
+        //\r
+        CurrentGraphicsOutputMode->MaxMode = GraphicsOutput->Mode->MaxMode;\r
+        CurrentGraphicsOutputMode->Mode = GraphicsOutput->Mode->Mode;\r
+        CopyMem (CurrentGraphicsOutputMode->Info, GraphicsOutput->Mode->Info, GraphicsOutput->Mode->SizeOfInfo);\r
+        CurrentGraphicsOutputMode->SizeOfInfo = GraphicsOutput->Mode->SizeOfInfo;\r
+        CurrentGraphicsOutputMode->FrameBufferBase = GraphicsOutput->Mode->FrameBufferBase;\r
+        CurrentGraphicsOutputMode->FrameBufferSize = GraphicsOutput->Mode->FrameBufferSize;\r
+\r
+        //\r
+        // Allocate resource for the private mode buffer\r
+        //\r
+        ModeBuffer = AllocatePool (sizeof (TEXT_OUT_GOP_MODE) * GraphicsOutput->Mode->MaxMode);\r
+        if (ModeBuffer == NULL) {\r
+          return EFI_OUT_OF_RESOURCES;\r
+        }\r
+        FreePool (Private->GraphicsOutputModeBuffer);\r
+        Private->GraphicsOutputModeBuffer = ModeBuffer;\r
+\r
+        //\r
+        // Store all supported display modes to the private mode buffer\r
+        //\r
+        Mode = ModeBuffer;\r
+        for (Index = 0; Index < GraphicsOutput->Mode->MaxMode; Index++) {\r
+          Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) Index, &SizeOfInfo, &Info);\r
+          if (EFI_ERROR (Status)) {\r
+            return Status;\r
+          }\r
+          Mode->HorizontalResolution = Info->HorizontalResolution;\r
+          Mode->VerticalResolution = Info->VerticalResolution;\r
+          Mode++;\r