]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Port DriverSample.inf, HiiDatabase.inf and SetupBrowser.inf
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 29 Jun 2007 15:14:00 +0000 (15:14 +0000)
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 29 Jun 2007 15:14:00 +0000 (15:14 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2915 6f19259b-4bc3-4df7-8a09-765794883524

38 files changed:
IntelFrameworkModulePkg/IntelFrameworkModulePkg.dsc
IntelFrameworkModulePkg/Universal/DriverSampleDxe/CommonHeader.h [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/DriverSampleDxe/DriverSample.c [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/DriverSampleDxe/DriverSample.dxs [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/DriverSampleDxe/DriverSample.h [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/DriverSampleDxe/DriverSample.inf [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/DriverSampleDxe/DriverSample.msa [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/DriverSampleDxe/Inventory.vfr [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/DriverSampleDxe/InventoryStrings.uni [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/DriverSampleDxe/NVDataStruc.h [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/DriverSampleDxe/Vfr.vfr [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/DriverSampleDxe/VfrStrings.uni [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/CommonHeader.h [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/Fonts.c [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/Forms.c [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/HiiDatabase.c [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/HiiDatabase.dxs [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/HiiDatabase.h [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/HiiDatabase.inf [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/HiiDatabase.msa [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/Keyboard.c [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/Package.c [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/Strings.c [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Boolean.c [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Colors.h [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/SetupBrowserDxe/CommonHeader.h [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/SetupBrowserDxe/InputHandler.c [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Presentation.c [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Print.c [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Print.h [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/SetupBrowserDxe/ProcessOptions.c [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Setup.c [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Setup.h [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/SetupBrowserDxe/SetupBrowser.inf [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/SetupBrowserDxe/SetupBrowser.msa [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/SetupBrowserDxe/SetupBrowserStr.uni [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Ui.c [new file with mode: 0644]
IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Ui.h [new file with mode: 0644]

index 1853aa66b295b4d85fb0b6cf2876cdc85e3d9f98..1382f9da88a7a1e7afbb673d4e1e8994a3d6854d 100644 (file)
   DxeServicesTableLib|${WORKSPACE}/MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
   FvbServiceLib|${WORKSPACE}/MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf\r
   ReportStatusCodeLib|${WORKSPACE}/IntelFrameworkPkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
+  HiiLibFramework|$(WORKSPACE)/IntelFrameworkPkg/Library/HiiLibFramework/HiiLib.inf\r
+  IfrSupportLibFramework|$(WORKSPACE)/IntelFrameworkPkg/Library/IfrSupportLibFramework/IfrSupportLib.inf\r
   PciIncompatibleDeviceSupportLib|${WORKSPACE}/IntelFrameworkModulePkg/Library/PciIncompatibleDeviceSupportLib/PciIncompatibleDeviceSupportLib.inf\r
 \r
+\r
 [LibraryClasses.common.DXE_RUNTIME_DRIVER]\r
   HobLib|${WORKSPACE}/MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   MemoryAllocationLib|${WORKSPACE}/MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf\r
@@ -91,6 +94,8 @@
   UefiRuntimeLib|${WORKSPACE}/MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf\r
   UefiRuntimeServicesTableLib|${WORKSPACE}/MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
   ReportStatusCodeLib|${WORKSPACE}/IntelFrameworkPkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
+  HiiLibFramework|$(WORKSPACE)/IntelFrameworkPkg/Library/HiiLibFramework/HiiLib.inf\r
+  IfrSupportLibFramework|$(WORKSPACE)/IntelFrameworkPkg/Library/IfrSupportLibFramework/IfrSupportLib.inf\r
 \r
 ################################################################################\r
 #\r
   $(WORKSPACE)\IntelFrameworkModulePkg\Universal\DataHub\DataHubStdErr\Dxe\DataHubStdErr.inf\r
   $(WORKSPACE)\IntelFrameworkModulePkg\Universal\StatusCode\Dxe\DxeStatusCode.inf\r
   $(WORKSPACE)\IntelFrameworkModulePkg\Universal\StatusCode\Pei\PeiStatusCode.inf\r
+  $(WORKSPACE)\IntelFrameworkModulePkg\Universal\HiiDataBaseDxe\HiiDatabase.inf\r
+ # $(WORKSPACE)\IntelFrameworkModulePkg\Universal\UserInterface\SetupBrowser\Dxe\SetupBrowser.inf\r
+#  $(WORKSPACE)\IntelFrameworkModulePkg\Universal\DriverSampleDxe\DriverSample.inf\r
+\r
diff --git a/IntelFrameworkModulePkg/Universal/DriverSampleDxe/CommonHeader.h b/IntelFrameworkModulePkg/Universal/DriverSampleDxe/CommonHeader.h
new file mode 100644 (file)
index 0000000..da9f608
--- /dev/null
@@ -0,0 +1,42 @@
+/**@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 <Protocol/FormCallback.h>\r
+#include <Protocol/FrameworkHii.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/IfrSupportLibFramework.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/HiiLibFramework.h>\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Universal/DriverSampleDxe/DriverSample.c b/IntelFrameworkModulePkg/Universal/DriverSampleDxe/DriverSample.c
new file mode 100644 (file)
index 0000000..7415643
--- /dev/null
@@ -0,0 +1,598 @@
+/*++\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
+  DriverSample.c\r
+\r
+Abstract:\r
+\r
+  This is an example of how a driver might export data to the HII protocol to be \r
+  later utilized by the Setup Protocol\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "DriverSample.h"\r
+\r
+#define DISPLAY_ONLY_MY_ITEM  0x0001\r
+\r
+#define STRING_PACK_GUID \\r
+  { \\r
+    0x8160a85f, 0x934d, 0x468b, { 0xa2, 0x35, 0x72, 0x89, 0x59, 0x14, 0xf6, 0xfc } \\r
+  }\r
+\r
+EFI_GUID  mFormSetGuid    = FORMSET_GUID;\r
+EFI_GUID  mStringPackGuid = STRING_PACK_GUID; \r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+DriverCallback (\r
+  IN EFI_FORM_CALLBACK_PROTOCOL       *This,\r
+  IN UINT16                           KeyValue,\r
+  IN EFI_IFR_DATA_ARRAY               *Data,\r
+  OUT EFI_HII_CALLBACK_PACKET         **Packet\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This is the function that is called to provide results data to the driver.  This data\r
+  consists of a unique key which is used to identify what data is either being passed back\r
+  or being asked for. \r
+\r
+Arguments:\r
+\r
+  KeyValue -        A unique value which is sent to the original exporting driver so that it\r
+                    can identify the type of data to expect.  The format of the data tends to\r
+                    vary based on the op-code that geerated the callback.\r
+\r
+  Data -            A pointer to the data being sent to the original exporting driver.\r
+\r
+Returns: \r
+\r
+--*/\r
+{\r
+  EFI_CALLBACK_INFO       *Private;\r
+  EFI_HII_UPDATE_DATA     *UpdateData;\r
+  UINT8                   *Location;\r
+  EFI_HII_CALLBACK_PACKET *DataPacket;\r
+  UINT16                  Value;\r
+  CHAR16                  VariableName[40];\r
+  STATIC UINT16           QuestionId = 0;\r
+  IFR_OPTION              *OptionList;\r
+  UINTN                   Index;\r
+  MyIfrNVData             NVStruc;\r
+\r
+  Private     = EFI_CALLBACK_INFO_FROM_THIS (This);\r
+\r
+  //\r
+  // This should tell me the first offset AFTER the end of the compiled NV map\r
+  // If op-code results are not going to be saved to NV locations ensure the QuestionId\r
+  // is beyond the end of the NVRAM mapping.\r
+  //\r
+  if (QuestionId == 0) {\r
+    QuestionId = sizeof (MyIfrNVData);\r
+  }\r
+\r
+  ZeroMem (VariableName, (sizeof (CHAR16) * 40));\r
+\r
+  switch (KeyValue) {\r
+  case 0x0001:\r
+    //\r
+    // Create a small boot order list\r
+    //\r
+    QuestionId = (UINT16) ((UINTN) (&NVStruc.BootOrder) - (UINTN) (&NVStruc));\r
+\r
+    //\r
+    // Need some memory for OptionList. Allow for up to 8 options.\r
+    //\r
+    OptionList = AllocateZeroPool (sizeof (IFR_OPTION) * 8);\r
+    ASSERT (OptionList != NULL);\r
+\r
+    //\r
+    // Allocate space for creation of Buffer\r
+    //\r
+    UpdateData = AllocateZeroPool (0x1000);\r
+    ASSERT (UpdateData != NULL);\r
+\r
+    //\r
+    // Remove all the op-codes starting with Label 0x2222 to next Label (second label is for convenience\r
+    // so we don't have to keep track of how many op-codes we added or subtracted.  The rules for removal\r
+    // of op-codes are simply that the removal will always stop as soon as a label or the end of a form is\r
+    // encountered.  Therefore, giving a large obnoxious count such as below takes care of other complexities.\r
+    //\r
+    UpdateData->DataCount = 0xFF;\r
+\r
+    //\r
+    // Delete set of op-codes\r
+    //\r
+    Private->Hii->UpdateForm (\r
+                    Private->Hii,\r
+                    Private->RegisteredHandle,\r
+                    (EFI_FORM_LABEL) 0x2222,\r
+                    FALSE,  // If we aren't adding, we are deleting\r
+                    UpdateData\r
+                    );\r
+\r
+    //\r
+    // Create 3 options\r
+    //\r
+    for (Index = 0; Index < 3; Index++) {\r
+      OptionList[Index].StringToken = (UINT16) (STR_BOOT_OPTION1 + Index);\r
+      OptionList[Index].Value       = (UINT16) (Index + 1);\r
+      OptionList[Index].Flags       = RESET_REQUIRED;\r
+    }\r
+\r
+    CreateOrderedListOpCode (\r
+      QuestionId,                               // Question ID\r
+      8,                                        // Max Entries\r
+      (UINT16) STRING_TOKEN (STR_BOOT_OPTIONS), // Token value for the Prompt\r
+      (UINT16) STRING_TOKEN (STR_NULL_STRING),  // Token value for the Help\r
+      OptionList,\r
+      3,\r
+      &UpdateData->Data                         // Buffer location to place op-codes\r
+      );\r
+\r
+    //\r
+    // For one-of/ordered lists commands, they really consist of 2 op-codes (a header and a footer)\r
+    // Each option within a one-of/ordered list is also an op-code\r
+    // So this example has 5 op-codes it is adding since we have a one-of header + 3 options + one-of footer\r
+    //\r
+    UpdateData->DataCount = 0x5;\r
+\r
+    //\r
+    // Add one op-code\r
+    //\r
+    Private->Hii->UpdateForm (\r
+                    Private->Hii,\r
+                    Private->RegisteredHandle,\r
+                    (EFI_FORM_LABEL) 0x2222,\r
+                    TRUE,\r
+                    UpdateData\r
+                    );\r
+\r
+    FreePool (UpdateData);\r
+    FreePool (OptionList);\r
+    break;\r
+\r
+  case 0x0002:\r
+    //\r
+    // Create a large boot order list\r
+    //\r
+    QuestionId = (UINT16) ((UINTN) (&NVStruc.BootOrder) - (UINTN) (&NVStruc));\r
+\r
+    //\r
+    // Need some memory for OptionList. Allow for up to 8 options.\r
+    //\r
+    OptionList = AllocateZeroPool (sizeof (IFR_OPTION) * 8);\r
+    ASSERT (OptionList != NULL);\r
+\r
+    //\r
+    // Allocate space for creation of Buffer\r
+    //\r
+    UpdateData = AllocateZeroPool (0x1000);\r
+    ASSERT (UpdateData != NULL);\r
+\r
+    //\r
+    // Remove all the op-codes starting with Label 0x2222 to next Label (second label is for convenience\r
+    // so we don't have to keep track of how many op-codes we added or subtracted\r
+    //\r
+    UpdateData->DataCount = 0xFF;\r
+\r
+    //\r
+    // Delete one op-code\r
+    //\r
+    Private->Hii->UpdateForm (\r
+                    Private->Hii,\r
+                    Private->RegisteredHandle,\r
+                    (EFI_FORM_LABEL) 0x2222,\r
+                    FALSE,\r
+                    UpdateData\r
+                    );\r
+\r
+    //\r
+    // Create 4 options\r
+    //\r
+    for (Index = 0; Index < 4; Index++) {\r
+      OptionList[Index].StringToken = (UINT16) (STR_BOOT_OPTION1 + Index);\r
+      OptionList[Index].Value       = (UINT16) (Index + 1);\r
+      OptionList[Index].Flags       = RESET_REQUIRED;\r
+    }\r
+\r
+    CreateOrderedListOpCode (\r
+      QuestionId,                               // Question ID\r
+      8,                                        // Max Entries\r
+      (UINT16) STRING_TOKEN (STR_BOOT_OPTIONS), // Token value for the Prompt\r
+      (UINT16) STRING_TOKEN (STR_NULL_STRING),  // Token value for the Help\r
+      OptionList,\r
+      4,\r
+      &UpdateData->Data                         // Buffer location to place op-codes\r
+      );\r
+\r
+    //\r
+    // For one-of commands, they really consist of 2 op-codes (a header and a footer)\r
+    // Each option within a one-of is also an op-code\r
+    // So this example has 6 op-codes it is adding since we have a one-of header + 4 options + one-of footer\r
+    //\r
+    UpdateData->DataCount = 0x6;\r
+\r
+    //\r
+    // Add one op-code\r
+    //\r
+    Private->Hii->UpdateForm (\r
+                    Private->Hii,\r
+                    Private->RegisteredHandle,\r
+                    (EFI_FORM_LABEL) 0x2222,\r
+                    TRUE,\r
+                    UpdateData\r
+                    );\r
+\r
+    FreePool (UpdateData);\r
+    FreePool (OptionList);\r
+    break;\r
+\r
+  case 0x1234:\r
+    //\r
+    // Allocate space for creation of Buffer\r
+    //\r
+    QuestionId = (UINT16) ((UINTN) (&NVStruc.DynamicCheck) - (UINTN) (&NVStruc));\r
+    UpdateData = AllocateZeroPool (0x1000);\r
+    ASSERT (UpdateData != NULL);\r
+\r
+    Location                        = (UINT8 *) &UpdateData->Data;\r
+\r
+    UpdateData->FormSetUpdate       = TRUE;\r
+    UpdateData->FormCallbackHandle  = (EFI_PHYSICAL_ADDRESS) (UINTN) Private->CallbackHandle;\r
+    UpdateData->FormUpdate          = FALSE;\r
+    UpdateData->FormTitle           = 0;\r
+    UpdateData->DataCount           = 2;\r
+\r
+    CreateGotoOpCode (\r
+      1,\r
+      STR_GOTO_FORM1,                                   // Token value for the Prompt\r
+      0,                                                // Goto Help\r
+      0,                                                // Flags\r
+      0,                                                // Key\r
+      &UpdateData->Data                                 // Buffer location to place op-codes\r
+      );\r
+\r
+    Location = Location + ((EFI_IFR_OP_HEADER *) &UpdateData->Data)->Length;\r
+\r
+    CreateCheckBoxOpCode (\r
+      QuestionId,                                       // Question ID\r
+      1,                                                // Data width (BOOLEAN = 1)\r
+      (UINT16) STRING_TOKEN (STR_CHECK_DYNAMIC_PROMPT), // Token value for the Prompt\r
+      (UINT16) STRING_TOKEN (STR_CHECK_DYNAMIC_HELP),   // Token value for the Help\r
+      EFI_IFR_FLAG_INTERACTIVE,                         // Flags\r
+      0x1236,   // Key\r
+      Location  // Buffer location to place op-codes\r
+      );\r
+\r
+    Private->Hii->UpdateForm (\r
+                    Private->Hii,\r
+                    Private->RegisteredHandle,\r
+                    (EFI_FORM_LABEL) 0x1234,\r
+                    TRUE,\r
+                    UpdateData\r
+                    );\r
+\r
+    FreePool (UpdateData);\r
+    QuestionId++;\r
+    break;\r
+\r
+  case 0x1235:\r
+    //\r
+    // Allocate space for creation of Buffer\r
+    //\r
+    UpdateData = AllocateZeroPool (0x1000);\r
+    ASSERT (UpdateData != NULL);\r
+\r
+    //\r
+    // Initialize DataPacket with information intended to remove all\r
+    // previously created op-codes in the dynamic page\r
+    //\r
+    UpdateData->FormSetUpdate       = FALSE;\r
+    UpdateData->FormCallbackHandle  = 0;\r
+    UpdateData->FormUpdate          = FALSE;\r
+    UpdateData->FormTitle           = 0;\r
+    //\r
+    // Unlikely to be more than 0xff op-codes in the dynamic page to remove\r
+    //\r
+    UpdateData->DataCount           = 0xff;\r
+    UpdateData->Data = NULL;\r
+\r
+    //\r
+    // Remove all op-codes from dynamic page\r
+    //\r
+    Private->Hii->UpdateForm (\r
+                    Private->Hii,\r
+                    Private->RegisteredHandle,\r
+                    (EFI_FORM_LABEL) 0x1234,  // Label 0x1234\r
+                    FALSE,                    // Remove Op-codes (will never remove form/endform)\r
+                    UpdateData                // Significant value is UpdateData->DataCount\r
+                    );\r
+\r
+    UpdateData->FormSetUpdate       = FALSE;\r
+    UpdateData->FormCallbackHandle  = 0;\r
+    UpdateData->FormUpdate          = FALSE;\r
+    UpdateData->FormTitle           = 0;\r
+    UpdateData->DataCount           = 1;\r
+\r
+    CreateGotoOpCode (\r
+      1,\r
+      STR_GOTO_FORM1,                         // Token value for the Prompt\r
+      0,                                      // Goto Help\r
+      0,                                      // Flags\r
+      0,                                      // Key\r
+      &UpdateData->Data                       // Buffer location to place op-codes\r
+      );\r
+\r
+    Private->Hii->UpdateForm (\r
+                    Private->Hii,\r
+                    Private->RegisteredHandle,\r
+                    (EFI_FORM_LABEL) 0x1234,\r
+                    TRUE,\r
+                    UpdateData\r
+                    );\r
+\r
+    FreePool (UpdateData);\r
+    break;\r
+\r
+  case 0x1236:\r
+    //\r
+    // If I hit the checkbox, I enter this case statement...\r
+    //\r
+    //\r
+    // Since I am returning an error (for test purposes) I need to pass in the string for the error\r
+    // I will allocate space for the return value.  If an error occurs (which is the case) I can simply return\r
+    // an error and fill in the string parameter, otherwise, I will return information in the DataArray structure.\r
+    // The browser will free this packet structure\r
+    //\r
+    *Packet = AllocateZeroPool (sizeof (EFI_HII_CALLBACK_PACKET) + sizeof (SAMPLE_STRING) + 2);\r
+    ASSERT (*Packet != NULL);\r
+\r
+    //\r
+    // Assign the buffer address to DataPacket\r
+    //\r
+    DataPacket = *Packet;\r
+\r
+    StrCpy (DataPacket->String, (CHAR16 *) SAMPLE_STRING);\r
+    return EFI_DEVICE_ERROR;\r
+\r
+  case 0x1237:\r
+\r
+    *Packet = AllocateZeroPool (sizeof (EFI_HII_CALLBACK_PACKET) + 2);\r
+    ASSERT (*Packet != NULL);\r
+\r
+    //\r
+    // Assign the buffer address to DataPacket\r
+    //\r
+    DataPacket                        = *Packet;\r
+\r
+    DataPacket->DataArray.EntryCount  = 1;\r
+    DataPacket->DataArray.NvRamMap    = NULL;\r
+    ((EFI_IFR_DATA_ENTRY *) (&DataPacket->DataArray + 1))->Flags = EXIT_REQUIRED;\r
+    break;\r
+\r
+  case 0x1555:\r
+    Value = 0x0001;\r
+    UnicodeSPrint (VariableName, 0x80, (CHAR16 *) L"%d", VAR_EQ_TEST_NAME);\r
+\r
+    gRT->SetVariable (\r
+          VariableName,\r
+          &mFormSetGuid,\r
+          EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+          2,\r
+          (VOID *) &Value\r
+          );\r
+    break;\r
+\r
+  case 0x1556:\r
+    Value = 0x1000;\r
+    UnicodeSPrint (VariableName, 0x80, (CHAR16 *) L"%d", VAR_EQ_TEST_NAME);\r
+\r
+    gRT->SetVariable (\r
+          VariableName,\r
+          &mFormSetGuid,\r
+          EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+          2,\r
+          (VOID *) &Value\r
+          );\r
+    break;\r
+\r
+  case 0x1557:\r
+    Value = 0x0000;\r
+    UnicodeSPrint (VariableName, 0x80, (CHAR16 *) L"%d", VAR_EQ_TEST_NAME);\r
+\r
+    gRT->SetVariable (\r
+          VariableName,\r
+          &mFormSetGuid,\r
+          EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+          2,\r
+          (VOID *) &Value\r
+          );\r
+    break;\r
+\r
+  default:\r
+    break;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+DriverSampleInit (\r
+  IN EFI_HANDLE                   ImageHandle,\r
+  IN EFI_SYSTEM_TABLE             *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  EFI_HII_PROTOCOL    *Hii;\r
+  //\r
+  //  EFI_FORM_BROWSER_PROTOCOL       *FormConfig;\r
+  //\r
+  EFI_HII_PACKAGES    *PackageList;\r
+  EFI_HII_HANDLE      HiiHandle;\r
+  STRING_REF          TokenToUpdate;\r
+  STRING_REF          TokenToUpdate2;\r
+  STRING_REF          TokenToUpdate3;\r
+  CHAR16              *NewString;\r
+  EFI_HII_UPDATE_DATA *UpdateData;\r
+  EFI_CALLBACK_INFO   *CallbackInfo;\r
+  EFI_HANDLE          Handle;\r
+  EFI_SCREEN_DESCRIPTOR   Screen;\r
+\r
+  ZeroMem (&Screen, sizeof (EFI_SCREEN_DESCRIPTOR));\r
+\r
+  gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &Screen.RightColumn, &Screen.BottomRow);\r
+\r
+  //\r
+  // Remove 3 characters from top and bottom\r
+  //\r
+  Screen.TopRow     = 3;\r
+  Screen.BottomRow  = Screen.BottomRow - 3;\r
+\r
+  //\r
+  // There should only be one HII protocol\r
+  //\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiHiiProtocolGuid,\r
+                  NULL,\r
+                  (VOID **) &Hii\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;;\r
+  }\r
+\r
+  CallbackInfo = AllocatePool (sizeof (EFI_CALLBACK_INFO));\r
+  if (CallbackInfo == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  CallbackInfo->Signature = EFI_CALLBACK_INFO_SIGNATURE;\r
+  CallbackInfo->Hii       = Hii;\r
+\r
+  //\r
+  // This example does not implement worker functions for the NV accessor functions.  Only a callback evaluator\r
+  //\r
+  CallbackInfo->DriverCallback.NvRead   = NULL;\r
+  CallbackInfo->DriverCallback.NvWrite  = NULL;\r
+  CallbackInfo->DriverCallback.Callback = DriverCallback;\r
+\r
+  //\r
+  // Install protocol interface\r
+  //\r
+  Handle = NULL;\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &Handle,\r
+                  &gEfiFormCallbackProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &CallbackInfo->DriverCallback\r
+                  );\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  CallbackInfo->CallbackHandle  = Handle;\r
+\r
+  PackageList                   = PreparePackages (1, &mStringPackGuid, DriverSampleStrings);\r
+  Status                        = Hii->NewPack (Hii, PackageList, &HiiHandle);\r
+  FreePool (PackageList);\r
+\r
+  PackageList = PreparePackages (1, &mStringPackGuid, InventoryBin);\r
+  Status      = Hii->NewPack (Hii, PackageList, &HiiHandle);\r
+  FreePool (PackageList);\r
+\r
+  PackageList = PreparePackages (1, &mStringPackGuid, VfrBin);\r
+  Status      = Hii->NewPack (Hii, PackageList, &HiiHandle);\r
+  FreePool (PackageList);\r
+\r
+  CallbackInfo->RegisteredHandle = HiiHandle;\r
+\r
+  //\r
+  // Very simple example of how one would update a string that is already\r
+  // in the HII database\r
+  //\r
+  TokenToUpdate = (STRING_REF) STR_CPU_STRING2;\r
+  NewString     = (CHAR16 *) L"700 Mhz";\r
+\r
+  Hii->NewString (Hii, NULL, HiiHandle, &TokenToUpdate, NewString);\r
+\r
+  //\r
+  // Add a string - if 0 will be updated with new Token number\r
+  //\r
+  TokenToUpdate = (STRING_REF) 0;\r
+\r
+  //\r
+  // Add a string - if 0 will be updated with new Token number\r
+  //\r
+  TokenToUpdate2 = (STRING_REF) 0;\r
+\r
+  //\r
+  // Add a string - if 0 will be updated with new Token number\r
+  //\r
+  TokenToUpdate3 = (STRING_REF) 0;\r
+\r
+  Hii->NewString (Hii, NULL, HiiHandle, &TokenToUpdate, (CHAR16 *) L"Desired Speed");\r
+  Hii->NewString (Hii, NULL, HiiHandle, &TokenToUpdate2, (CHAR16 *) L"5 Thz");\r
+  Hii->NewString (Hii, NULL, HiiHandle, &TokenToUpdate3, (CHAR16 *) L"This is next year's desired speed - right?");\r
+\r
+  //\r
+  // Allocate space for creation of Buffer\r
+  //\r
+  UpdateData = AllocateZeroPool (0x1000);\r
+  ASSERT (UpdateData != NULL);\r
+\r
+  //\r
+  // Flag update pending in FormSet\r
+  //\r
+  UpdateData->FormSetUpdate = TRUE;\r
+  //\r
+  // Register CallbackHandle data for FormSet\r
+  //\r
+  UpdateData->FormCallbackHandle = (EFI_PHYSICAL_ADDRESS) (UINTN) CallbackInfo->CallbackHandle;\r
+  UpdateData->FormUpdate  = FALSE;\r
+  UpdateData->FormTitle   = 0;\r
+  UpdateData->DataCount   = 1;\r
+\r
+  CreateTextOpCode (TokenToUpdate, TokenToUpdate2, TokenToUpdate3, 0, 0, &UpdateData->Data);\r
+\r
+  Hii->UpdateForm (Hii, HiiHandle, (EFI_FORM_LABEL) 100, TRUE, UpdateData);\r
+\r
+  FreePool (UpdateData);\r
+\r
+  //\r
+  // Example of how to display only the item we sent to HII\r
+  //\r
+  if (DISPLAY_ONLY_MY_ITEM == 0x0001) {\r
+    //\r
+    // Have the browser pull out our copy of the data, and only display our data\r
+    //\r
+    //    Status = FormConfig->SendForm (FormConfig, TRUE, HiiHandle, NULL, NULL, NULL, &Screen, NULL);\r
+    //\r
+  } else {\r
+    //\r
+    // Have the browser pull out all the data in the HII Database and display it.\r
+    //\r
+    //    Status = FormConfig->SendForm (FormConfig, TRUE, 0, NULL, NULL, NULL, NULL, NULL);\r
+    //\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/IntelFrameworkModulePkg/Universal/DriverSampleDxe/DriverSample.dxs b/IntelFrameworkModulePkg/Universal/DriverSampleDxe/DriverSample.dxs
new file mode 100644 (file)
index 0000000..d88f568
--- /dev/null
@@ -0,0 +1,31 @@
+/*++\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:\r
+\r
+  DriverSample.dxs\r
+\r
+Abstract:\r
+\r
+  Dependency expression source file.\r
+  \r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include <DxeDepex.h>\r
+\r
+DEPENDENCY_START\r
+  EFI_SIMPLE_TEXT_OUT_PROTOCOL_GUID\r
+DEPENDENCY_END\r
diff --git a/IntelFrameworkModulePkg/Universal/DriverSampleDxe/DriverSample.h b/IntelFrameworkModulePkg/Universal/DriverSampleDxe/DriverSample.h
new file mode 100644 (file)
index 0000000..ba3a50d
--- /dev/null
@@ -0,0 +1,64 @@
+/*++\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
+  DriverSample.h\r
+\r
+Abstract:\r
+\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+#ifndef _DRIVER_SAMPLE_H\r
+#define _DRIVER_SAMPLE_H\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "NVDataStruc.h"\r
+\r
+//\r
+// This is the generated header file which includes whatever needs to be exported (strings + IFR)\r
+//\r
+\r
+extern UINT8  VfrBin[];\r
+//\r
+// extern UINT8 VfrStringsStr[];\r
+//\r
+extern UINT8  InventoryBin[];\r
+//\r
+// extern UINT8 InventoryStringsStr[];\r
+//\r
+extern UINT8  DriverSampleStrings[];\r
+\r
+#define SAMPLE_STRING               L"This is an error!"\r
+\r
+#define EFI_CALLBACK_INFO_SIGNATURE EFI_SIGNATURE_32 ('C', 'l', 'b', 'k')\r
+\r
+typedef struct {\r
+  UINTN                       Signature;\r
+  EFI_HANDLE                  CallbackHandle;\r
+  EFI_FORM_CALLBACK_PROTOCOL  DriverCallback;\r
+  UINT16                      *KeyList;\r
+  VOID                        *FormBuffer;\r
+  EFI_HII_HANDLE              RegisteredHandle;\r
+  EFI_HII_PROTOCOL            *Hii;\r
+} EFI_CALLBACK_INFO;\r
+\r
+#define EFI_CALLBACK_INFO_FROM_THIS(a)  CR (a, EFI_CALLBACK_INFO, DriverCallback, EFI_CALLBACK_INFO_SIGNATURE)\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Universal/DriverSampleDxe/DriverSample.inf b/IntelFrameworkModulePkg/Universal/DriverSampleDxe/DriverSample.inf
new file mode 100644 (file)
index 0000000..ea26648
--- /dev/null
@@ -0,0 +1,111 @@
+#/** @file\r
+# Component description file for DriverSample module.\r
+#\r
+# This is an example driver to introduce how to export data to the HII protocol to be later utilized by the Setup Protocol.\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                      = DriverSample\r
+  FILE_GUID                      = FE3542FE-C1D3-4EF8-657C-8048606FF670\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = DriverSampleInit\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
+  DriverSample.dxs\r
+  DriverSample.h\r
+  NVDataStruc.h\r
+  DriverSample.c\r
+  Vfr.vfr\r
+  VfrStrings.uni\r
+  Inventory.vfr\r
+  InventoryStrings.uni\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/IntelFrameworkPkg/Include/Library\r
+  $(WORKSPACE)/MdePkg/Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  IntelFrameworkPkg/IntelFrameworkPkg.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
+  HiiLibFramework\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  IfrSupportLibFramework\r
+  PrintLib\r
+  BaseLib\r
+  UefiDriverEntryPoint\r
+  DebugLib\r
+  UefiRuntimeServicesTableLib\r
+  UefiBootServicesTableLib\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
+  gEfiFormCallbackProtocolGuid                  # PROTOCOL ALWAYS_PRODUCED\r
+  gEfiHiiProtocolGuid                           # PROTOCOL ALWAYS_CONSUMED\r
+\r
diff --git a/IntelFrameworkModulePkg/Universal/DriverSampleDxe/DriverSample.msa b/IntelFrameworkModulePkg/Universal/DriverSampleDxe/DriverSample.msa
new file mode 100644 (file)
index 0000000..4c96b5e
--- /dev/null
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>DriverSample</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>FE3542FE-C1D3-4EF8-657C-8048606FF670</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for DriverSample module.</Abstract>\r
+    <Description>This is an example driver to introduce how to export data to the HII protocol to be later utilized by the Setup Protocol. </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>DriverSample</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\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" RecommendedInstanceGuid="bda39d3a-451b-4350-8266-81ab10fa0523">\r
+      <Keyword>DebugLib</Keyword>\r
+      <HelpText>Recommended libary Instance is PeiDxeDebugLibReportStatusCode instance in MdePkg.</HelpText>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED" RecommendedInstanceGuid="a86fbfca-0183-4eeb-aa8a-762e3b7da1f3">\r
+      <Keyword>PrintLib</Keyword>\r
+      <HelpText>Recommended libary Instance is BasePrintLib instance in MdePkg.</HelpText>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>EdkIfrSupportLib</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>HiiLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>InventoryStrings.uni</Filename>\r
+    <Filename>Inventory.vfr</Filename>\r
+    <Filename>VfrStrings.uni</Filename>\r
+    <Filename>Vfr.vfr</Filename>\r
+    <Filename>DriverSample.c</Filename>\r
+    <Filename>NVDataStruc.h</Filename>\r
+    <Filename>DriverSample.h</Filename>\r
+    <Filename>DriverSample.dxs</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="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiHiiProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiFormCallbackProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <HiiPackages>\r
+    <HiiPackage Usage="ALWAYS_PRODUCED">\r
+      <HiiCName>DriverSampleStrings</HiiCName>\r
+      <HelpText>EFI_HII_STRING type string package from UNI file.</HelpText>\r
+    </HiiPackage>\r
+    <HiiPackage Usage="ALWAYS_PRODUCED">\r
+      <HiiCName>InventoryBin</HiiCName>\r
+      <HelpText>EFI_HII_IFR type form package from VFR file.</HelpText>\r
+    </HiiPackage>\r
+    <HiiPackage Usage="ALWAYS_PRODUCED">\r
+      <HiiCName>VfrBin</HiiCName>\r
+      <HelpText>EFI_HII_IFR type form package from VFR file.</HelpText>\r
+    </HiiPackage>\r
+  </HiiPackages>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>DriverSampleInit</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/IntelFrameworkModulePkg/Universal/DriverSampleDxe/Inventory.vfr b/IntelFrameworkModulePkg/Universal/DriverSampleDxe/Inventory.vfr
new file mode 100644 (file)
index 0000000..434da17
--- /dev/null
@@ -0,0 +1,128 @@
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+// *++\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
+//   Inventory.vfr \r
+// \r
+// Abstract:\r
+// \r
+//   Sample Inventory Data.\r
+// \r
+// Revision History: \r
+// \r
+// --*/\r
+\r
+#include "DriverSampleStrDefs.h"\r
+\r
+#define INVENTORY_GUID    { 0xb3f56470, 0x6141, 0x4621, { 0x8f, 0x19, 0x70, 0x4e, 0x57, 0x7a, 0xa9, 0xe8 } }\r
\r
+formset \r
+  guid     = INVENTORY_GUID,\r
+  title    = STRING_TOKEN(STR_INV_FORM_SET_TITLE),\r
+  help     = STRING_TOKEN(STR_INV_FORM_SET_HELP),\r
+  class    = 0x04,      \r
+  subclass = 0x03,\r
+\r
+  form formid = 1,\r
+       title  = STRING_TOKEN(STR_INV_FORM1_TITLE);  // note formid is a variable (for readability) (UINT16) - also added Form to the line to signify the Op-Code\r
+  \r
+       text \r
+      help   = STRING_TOKEN(STR_INV_VERSION_HELP),\r
+      text   = STRING_TOKEN(STR_INV_VERSION_TEXT),\r
+           text   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      flags  = 0,\r
+      key    = 0;\r
+\r
+       text \r
+      help   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      text   = STRING_TOKEN(STR_INV_VERSION_TEXT2),\r
+           text   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      flags  = 0,\r
+      key    = 0;\r
+\r
+       text \r
+      help   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      text   = STRING_TOKEN(STR_INV_VERSION_TEXT3),\r
+           text   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      flags  = 0,\r
+      key    = 0;\r
+\r
+       text \r
+      help   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      text   = STRING_TOKEN(STR_INV_VERSION_TEXT4),\r
+           text   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      flags  = 0,\r
+      key    = 0;\r
+\r
+    subtitle text = STRING_TOKEN(STR_INV_EMPTY_STRING);\r
+\r
+       text \r
+      help   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      text   = STRING_TOKEN(STR_INV_VERSION_TEXT5),\r
+           text   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      flags  = 0,\r
+      key    = 0;\r
+\r
+       text \r
+      help   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      text   = STRING_TOKEN(STR_INV_VERSION_TEXT6),\r
+           text   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      flags  = 0,\r
+      key    = 0;\r
+\r
+       text \r
+      help   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      text   = STRING_TOKEN(STR_INV_VERSION_TEXT7),\r
+           text   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      flags  = 0,\r
+      key    = 0;\r
+\r
+       text \r
+      help   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      text   = STRING_TOKEN(STR_INV_VERSION_TEXT8),\r
+           text   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      flags  = 0,\r
+      key    = 0;\r
+\r
+       text \r
+      help   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      text   = STRING_TOKEN(STR_INV_VERSION_TEXT9),\r
+           text   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      flags  = 0,\r
+      key    = 0;\r
+\r
+       text \r
+      help   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      text   = STRING_TOKEN(STR_INV_VERSION_TEXT10),\r
+           text   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      flags  = 0,\r
+      key    = 0;\r
+\r
+       text \r
+      help   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      text   = STRING_TOKEN(STR_INV_VERSION_TEXT11),\r
+           text   = STRING_TOKEN(STR_INV_EMPTY_STRING),\r
+      flags  = 0,\r
+      key    = 0;\r
+\r
+    subtitle text = STRING_TOKEN(STR_INV_EMPTY_STRING);\r
+\r
+    subtitle text = STRING_TOKEN(STR_INV_VERSION_TEXT12);\r
+\r
+  endform;\r
+\r
+endformset;\r
diff --git a/IntelFrameworkModulePkg/Universal/DriverSampleDxe/InventoryStrings.uni b/IntelFrameworkModulePkg/Universal/DriverSampleDxe/InventoryStrings.uni
new file mode 100644 (file)
index 0000000..4946b4a
Binary files /dev/null and b/IntelFrameworkModulePkg/Universal/DriverSampleDxe/InventoryStrings.uni differ
diff --git a/IntelFrameworkModulePkg/Universal/DriverSampleDxe/NVDataStruc.h b/IntelFrameworkModulePkg/Universal/DriverSampleDxe/NVDataStruc.h
new file mode 100644 (file)
index 0000000..5b51e94
--- /dev/null
@@ -0,0 +1,67 @@
+/*++\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
+  NVDataStruc.h \r
\r
+Abstract:\r
\r
+  NVData structure used by the sample driver\r
\r
+Revision History: \r
\r
+--*/\r
+\r
+#ifndef _NVDATASTRUC_H\r
+#define _NVDATASTRUC_H\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#define FORMSET_GUID \\r
+  { \\r
+    0xA04A27f4, 0xDF00, 0x4D42, { 0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D } \\r
+  }\r
+\r
+#define INVENTORY_GUID \\r
+  { \\r
+    0xb3f56470, 0x6141, 0x4621, { 0x8f, 0x19, 0x70, 0x4e, 0x57, 0x7a, 0xa9, 0xe8 } \\r
+  }\r
+\r
+#define VAR_EQ_TEST_NAME  0x100\r
+\r
+#pragma pack(1)\r
+typedef struct {\r
+  UINT16  WhatIsThePassword[20];\r
+  UINT16  WhatIsThePassword2[20];\r
+  UINT16  MyStringData[20];\r
+  UINT16  SomethingHiddenForHtml;\r
+  UINT8   HowOldAreYouInYearsManual;\r
+  UINT16  HowTallAreYouManual;\r
+  UINT8   HowOldAreYouInYears;\r
+  UINT16  HowTallAreYou;\r
+  UINT8   MyFavoriteNumber;\r
+  UINT8   TestLateCheck;\r
+  UINT8   TestLateCheck2;\r
+  UINT8   QuestionAboutTreeHugging;\r
+  UINT8   ChooseToActivateNuclearWeaponry;\r
+  UINT8   SuppressGrayOutSomething;\r
+  UINT8   OrderedList[8];\r
+  UINT8   BootOrder[8];\r
+  UINT8   BootOrderLarge;\r
+  UINT8   DynamicCheck;\r
+} MyIfrNVData;\r
+#pragma pack()\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Universal/DriverSampleDxe/Vfr.vfr b/IntelFrameworkModulePkg/Universal/DriverSampleDxe/Vfr.vfr
new file mode 100644 (file)
index 0000000..ee8df04
--- /dev/null
@@ -0,0 +1,627 @@
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+// *++\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
+//   Vfr.vfr \r
+// \r
+// Abstract:\r
+// \r
+//   Sample Setup formset\r
+// \r
+// Revision History: \r
+// \r
+// --*/\r
+\r
+\r
+#include "DriverSampleStrDefs.h" \r
\r
+#include "NVDataStruc.h"\r
+\r
+\r
+typedef struct {\r
+  UINT8         Field8;\r
+  UINT16        Field16;\r
+  UINT8         OrderedList[3];\r
+} MyIfrNVData2;\r
+\r
+typedef struct {\r
+  UINT8         Field8;\r
+  UINT16        Field16;\r
+  UINT8         OrderedList[3];\r
+} MyIfrNVData3;\r
+\r
+#define MY_TEXT_KEY                 0x100 \r
+\r
+#define LABEL_1_VALUE               0x01\r
+#define LABEL_2_VALUE               0x1000\r
+#define LABEL_UPDATE_BBS            0x2222\r
+#define LABEL_END_UPDATE_BBS        0x2223\r
+\r
+formset \r
+  guid     = FORMSET_GUID,\r
+  title    = STRING_TOKEN(STR_FORM_SET_TITLE),  \r
+  help     = STRING_TOKEN(STR_FORM_SET_TITLE_HELP), \r
+  class    = 0x10,      \r
+  subclass = 0,\r
+\r
+  varstore MyIfrNVData2, key = 0x1234, name = MY_DATA2, guid = FORMSET_GUID;\r
+\r
+\r
+  varstore MyIfrNVData3, key = 0x4321, name = MY_DATA3, guid = FORMSET_GUID;\r
+\r
+  form formid = 1,\r
+       title  = STRING_TOKEN(STR_FORM1_TITLE);  // note formid is a variable (for readability) (UINT16) - also added Form to the line to signify the Op-Code\r
+  \r
+    subtitle text = STRING_TOKEN(STR_SUBTITLE_TEXT);\r
+\r
+    subtitle text = STRING_TOKEN(STR_SUBTITLE_TEXT2);\r
+\r
+    banner \r
+      title = STRING_TOKEN(STR_BANNER_TITLE),\r
+      line  1,\r
+      align center;\r
+    \r
+    banner \r
+      title = STRING_TOKEN(STR_BANNER_TITLE),\r
+      line  2,\r
+      align left;\r
+\r
+    banner \r
+      title = STRING_TOKEN(STR_BANNER_TITLE),\r
+      line  2,\r
+      align right;\r
+\r
+       text \r
+      help   = STRING_TOKEN(STR_TEXT_HELP),  \r
+      text   = STRING_TOKEN(STR_CPU_STRING),\r
+           text   = STRING_TOKEN(STR_CPU_STRING2),\r
+      flags  = 0,\r
+      key    = 0;\r
+\r
+       text \r
+      help   = STRING_TOKEN(STR_EXIT_TEXT),  \r
+      text   = STRING_TOKEN(STR_EXIT_TEXT), \r
+           text   = STRING_TOKEN(STR_EXIT_TEXT),\r
+      flags  = INTERACTIVE,\r
+      key    = 0x1237;\r
+\r
+    oneof varid  = MyIfrNVData.SuppressGrayOutSomething,\r
+      prompt      = STRING_TOKEN(STR_ONE_OF_PROMPT),\r
+      help        = STRING_TOKEN(STR_ONE_OF_HELP),  \r
+      option text = STRING_TOKEN(STR_ONE_OF_TEXT4), value = 0x0, flags = 0; \r
+      option text = STRING_TOKEN(STR_ONE_OF_TEXT5), value = 0x1, flags = 0;\r
+      option text = STRING_TOKEN(STR_ONE_OF_TEXT6), value = 0x2, flags = DEFAULT;\r
+    endoneof;\r
+\r
+    oneof varid  = MyIfrNVData.BootOrderLarge,\r
+      prompt      = STRING_TOKEN(STR_ONE_OF_PROMPT),\r
+      help        = STRING_TOKEN(STR_ONE_OF_HELP),  \r
+      option text = STRING_TOKEN(STR_BOOT_ORDER1), value = 0x0, flags = INTERACTIVE, key = 1; \r
+      option text = STRING_TOKEN(STR_BOOT_ORDER2), value = 0x1, flags = INTERACTIVE | DEFAULT, key = 2;\r
+    endoneof;\r
+\r
+    grayoutif  ideqval MyIfrNVData.SuppressGrayOutSomething == 0x1;\r
+    suppressif ideqval MyIfrNVData.SuppressGrayOutSomething == 0x0;\r
+      label 0;\r
+      checkbox varid    = MyIfrNVData.ChooseToActivateNuclearWeaponry,\r
+              prompt   = STRING_TOKEN(STR_CHECK_BOX_PROMPT),\r
+              help     = STRING_TOKEN(STR_CHECK_BOX_HELP),  \r
+              flags    = 1,                  // Flags behavior for checkbox is overloaded so that it equals a DEFAULT value.  1 = ON, 0 = off\r
+              key      = 0,\r
+      endcheckbox;\r
+    endif;\r
+\r
+\r
+    //\r
+    // Ordered list: \r
+    //   sizeof(MyIfrNVData) storage must be UINT8 array, and\r
+    //   size written for the variable must be size of the entire\r
+    //   variable.\r
+    //\r
+    //\r
+    suppressif ideqval MyIfrNVData.SuppressGrayOutSomething == 0x0;\r
+      label LABEL_UPDATE_BBS;\r
+      orderedlist\r
+                varid       = MyIfrNVData.BootOrder,\r
+                prompt      = STRING_TOKEN(STR_BOOT_OPTIONS),\r
+                help        = STRING_TOKEN(STR_NULL_STRING),\r
+                option text = STRING_TOKEN(STR_BOOT_OPTION2), value = 2, flags = RESET_REQUIRED;\r
+                option text = STRING_TOKEN(STR_BOOT_OPTION1), value = 1, flags = RESET_REQUIRED;\r
+                option text = STRING_TOKEN(STR_BOOT_OPTION3), value = 3, flags = RESET_REQUIRED;\r
+                option text = STRING_TOKEN(STR_BOOT_OPTION4), value = 4, flags = RESET_REQUIRED;\r
+      endlist;      \r
+      label LABEL_END_UPDATE_BBS;\r
+    endif;\r
\r
+    suppressif ideqval MyIfrNVData.SuppressGrayOutSomething == 0x2;\r
+      orderedlist    \r
+        varid       = MyIfrNVData.OrderedList,\r
+        prompt      = STRING_TOKEN(STR_TEST_OPCODE),\r
+        help        = STRING_TOKEN(STR_TEXT_HELP),  \r
+        option text = STRING_TOKEN(STR_ONE_OF_TEXT1), value = 4, flags = RESET_REQUIRED;\r
+        option text = STRING_TOKEN(STR_ONE_OF_TEXT2), value = 3, flags = RESET_REQUIRED;\r
+        option text = STRING_TOKEN(STR_ONE_OF_TEXT3), value = 2, flags = RESET_REQUIRED;\r
+        option text = STRING_TOKEN(STR_TEXT_HELP),    value = 1, flags = RESET_REQUIRED;\r
+      endlist;\r
+    endif;\r
+     \r
+    label 100;\r
+\r
+    goto 0x1234, \r
+      prompt  = STRING_TOKEN(STR_GOTO_DYNAMIC), \r
+      help    = STRING_TOKEN(STR_GOTO_HELP),\r
+      flags   = INTERACTIVE, \r
+      key     = 0x1234;\r
+\r
+    goto 0x1234, \r
+      prompt  = STRING_TOKEN(STR_GOTO_DYNAMIC2), \r
+      help    = STRING_TOKEN(STR_GOTO_HELP),\r
+      flags   = INTERACTIVE, \r
+      key     = 0x1235;\r
+    \r
+    //\r
+    // VARSTORE tests\r
+    //\r
+    // Till now, been using variable NvData (must be reserved)\r
+    // now we do a varselect for variable NvData3\r
+    inconsistentif prompt = STRING_TOKEN(STR_ERROR_POPUP),\r
+      ideqid MyIfrNVData3.Field16 == MyIfrNVData3.Field16\r
+    endif;\r
+    // now we do a varselect_pair for variable NvData2 and NvData3\r
+    inconsistentif prompt = STRING_TOKEN(STR_ERROR_POPUP),\r
+      ideqid MyIfrNVData2.Field16 == MyIfrNVData3.Field16\r
+    endif;\r
+\r
+\r
+    // now we do a varselect_pair for variable NvData and NvData2\r
+//    inconsistentif prompt = STRING_TOKEN(STR_ERROR_POPUP),\r
+//      ideqid MyIfrNVData2.Field16 == MyIfrNVData.TestLateCheck\r
+//    endif;\r
+\r
+    inconsistentif prompt = STRING_TOKEN(STR_ERROR_POPUP),\r
+      ideqid MyIfrNVData.TestLateCheck == MyIfrNVData.TestLateCheck2\r
+    endif;\r
+\r
+    oneof varid  = MyIfrNVData.TestLateCheck,\r
+      prompt      = STRING_TOKEN(STR_TEST_OPCODE),\r
+      help        = STRING_TOKEN(STR_ONE_OF_HELP),  \r
+      option text = STRING_TOKEN(STR_ONE_OF_TEXT1), value = 0, flags = LATE_CHECK | RESET_REQUIRED;\r
+      option text = STRING_TOKEN(STR_ONE_OF_TEXT2), value = 1, flags = LATE_CHECK | DEFAULT | RESET_REQUIRED;\r
+    endoneof;\r
+\r
+    oneof varid  = MyIfrNVData.TestLateCheck2,\r
+      prompt      = STRING_TOKEN(STR_TEST_OPCODE2),\r
+      help        = STRING_TOKEN(STR_ONE_OF_HELP),  \r
+      option text = STRING_TOKEN(STR_ONE_OF_TEXT1), value = 0, flags = LATE_CHECK | DEFAULT | RESET_REQUIRED;\r
+      option text = STRING_TOKEN(STR_ONE_OF_TEXT2), value = 1, flags = LATE_CHECK | RESET_REQUIRED;\r
+\r
+    endoneof;\r
+\r
+    oneof varid  = MyIfrNVData.QuestionAboutTreeHugging,\r
+      prompt      = STRING_TOKEN(STR_ONE_OF_PROMPT),\r
+      help        = STRING_TOKEN(STR_ONE_OF_HELP),  \r
+      option text = STRING_TOKEN(STR_ONE_OF_TEXT1), value = 0, flags = RESET_REQUIRED;\r
+      option text = STRING_TOKEN(STR_ONE_OF_TEXT2), value = 1, flags = DEFAULT | RESET_REQUIRED;\r
+      option text = STRING_TOKEN(STR_ONE_OF_TEXT3), value = 0x03, flags = RESET_REQUIRED;\r
+\r
+    endoneof;\r
+\r
+    string    varid    = MyIfrNVData.MyStringData,\r
+              prompt   = STRING_TOKEN(STR_MY_STRING_PROMPT2),\r
+              help     = STRING_TOKEN(STR_MY_STRING_HELP2),\r
+              flags    = INTERACTIVE,\r
+              key      = 0x1234,\r
+              minsize  = 6,\r
+              maxsize  = 0x14,\r
+    endstring; \r
+\r
+       text \r
+      help   = STRING_TOKEN(STR_GRAYOUT_TEST),  \r
+      text   = STRING_TOKEN(STR_GRAYOUT_TEST),\r
+           text   = STRING_TOKEN(STR_GRAYOUT_TEST),\r
+      flags  = INTERACTIVE,\r
+      key    = 0x1555;\r
+\r
+       text \r
+      help   = STRING_TOKEN(STR_SUPPRESS_TEST),  \r
+      text   = STRING_TOKEN(STR_SUPPRESS_TEST),\r
+           text   = STRING_TOKEN(STR_SUPPRESS_TEST),\r
+      flags  = INTERACTIVE,\r
+      key    = 0x1556;\r
+\r
+       text \r
+      help   = STRING_TOKEN(STR_CLEAR_TEST),  \r
+      text   = STRING_TOKEN(STR_CLEAR_TEST),\r
+           text   = STRING_TOKEN(STR_CLEAR_TEST),\r
+      flags  = INTERACTIVE,\r
+      key    = 0x1557;\r
+\r
+    grayoutif  vareqval var(VAR_EQ_TEST_NAME) == 0x1;\r
+    suppressif vareqval var(VAR_EQ_TEST_NAME) == 0x1000; \r
+      label 30;\r
+      checkbox varid    = MyIfrNVData.ChooseToActivateNuclearWeaponry,\r
+              prompt   = STRING_TOKEN(STR_CHECK_BOX_PROMPT),\r
+              help     = STRING_TOKEN(STR_CHECK_BOX_HELP),  \r
+              flags    = 1,\r
+              key      = 0,\r
+      endcheckbox;\r
+    endif;\r
+\r
+\r
+    numeric varid   = MyIfrNVData.HowOldAreYouInYearsManual, \r
+            prompt  = STRING_TOKEN(STR_NUMERIC_MANUAL_PROMPT),\r
+            help    = STRING_TOKEN(STR_NUMERIC_HELP0),\r
+            minimum = 0,\r
+            maximum = 0xf0,      // 0xf0 = 240 in decimal\r
+            step    = 0,         // Stepping of 0 equates to a manual entering\r
+                                 // of a value, otherwise it will auto-increment\r
+                                 // with a left/right arrow\r
+            default = 21, \r
+\r
+    endnumeric;\r
+\r
+    numeric varid   = MyIfrNVData.HowTallAreYouManual, \r
+            prompt  = STRING_TOKEN(STR_TALL_MANUAL_PROMPT),\r
+            help    = STRING_TOKEN(STR_NUMERIC_HELP1),\r
+            minimum = 0,\r
+            maximum = 300,\r
+            step    = 0,         // Stepping of 0 equates to a manual entering\r
+                                 // of a value, otherwise it will auto-increment\r
+                                 // with a left/right arrow\r
+            default = 175, \r
+\r
+    endnumeric;\r
+\r
+    inventory\r
+      help    = STRING_TOKEN(STR_INVENTORY_HELP),\r
+      text    = STRING_TOKEN(STR_INVENTORY_TEXT1),\r
+      text    = STRING_TOKEN(STR_INVENTORY_TEXT2);\r
+\r
+      \r
+    restore defaults,\r
+      formid  = 4,\r
+      prompt  = STRING_TOKEN(STR_RESTORE_DEFAULTS_PROMPT),\r
+      help    = STRING_TOKEN(STR_RESTORE_DEFAULTS_HELP),\r
+      flags   = 0,\r
+      key     = 0;\r
+\r
+    save defaults,\r
+      formid  = 4,\r
+      prompt  = STRING_TOKEN(STR_SAVE_DEFAULTS_PROMPT),\r
+      help    = STRING_TOKEN(STR_SAVE_DEFAULTS_HELP),\r
+      flags   = 0,\r
+      key     = 0;\r
+\r
+    // \r
+    // Case with no flags or key\r
+    //\r
+    save defaults,\r
+      formid  = 4,\r
+      prompt  = STRING_TOKEN(STR_SAVE_DEFAULTS_PROMPT),\r
+      help    = STRING_TOKEN(STR_SAVE_DEFAULTS_HELP);\r
+    //\r
+    // Case with no key\r
+    //\r
+    save defaults,\r
+      formid  = 4,\r
+      prompt  = STRING_TOKEN(STR_SAVE_DEFAULTS_PROMPT),\r
+      help    = STRING_TOKEN(STR_SAVE_DEFAULTS_HELP),\r
+      flags   = 0;\r
+    //\r
+    // Case with no flags\r
+    //\r
+    save defaults,\r
+      formid  = 4,\r
+      prompt  = STRING_TOKEN(STR_SAVE_DEFAULTS_PROMPT),\r
+      help    = STRING_TOKEN(STR_SAVE_DEFAULTS_HELP),\r
+      key     = 0;\r
+\r
+    label LABEL_2_VALUE;\r
+\r
+    grayoutif  ideqval MyIfrNVData.HowOldAreYouInYearsManual == 23 AND ideqval MyIfrNVData.SuppressGrayOutSomething == 0x1;\r
+    numeric varid   = MyIfrNVData.HowOldAreYouInYears,   \r
+            prompt  = STRING_TOKEN(STR_NUMERIC_PROMPT),\r
+            help    = STRING_TOKEN(STR_NUMERIC_HELP2),\r
+            minimum = 0,\r
+            maximum = 243,\r
+            step    = 3,\r
+            default = 18,\r
+\r
+    endnumeric;\r
+\r
+    label LABEL_1_VALUE;\r
+\r
+    //\r
+    // Numeric with no step or default specified\r
+    //\r
+    numeric varid   = MyIfrNVData.HowTallAreYou, \r
+            prompt  = STRING_TOKEN(STR_NUMERIC_PROMPT1),\r
+            help    = STRING_TOKEN(STR_NUMERIC_HELP3),\r
+            minimum = 0,\r
+            maximum = 190,\r
+    //        step    = 1,       // Stepping of 1 if not specified\r
+    //        default = minimum; // if not specified\r
+    endnumeric;\r
+    endif;\r
+\r
+    string    varid    = MyIfrNVData.MyStringData,\r
+              prompt   = STRING_TOKEN(STR_MY_STRING_PROMPT),\r
+              help     = STRING_TOKEN(STR_MY_STRING_HELP),\r
+              minsize  = 6,\r
+              maxsize  = 0x14,\r
+    endstring; \r
+        \r
+    password  varid    = MyIfrNVData.WhatIsThePassword,\r
+              prompt   = STRING_TOKEN(STR_PASSWORD_PROMPT),\r
+              help     = STRING_TOKEN(STR_PASSWORD_HELP),\r
+              minsize  = 6,\r
+              maxsize  = 20, // new opcode \r
+              encoding = 1,\r
+    endpassword; \r
+    password  varid    = MyIfrNVData.WhatIsThePassword2,\r
+              prompt   = STRING_TOKEN(STR_PASSWORD_PROMPT),\r
+              help     = STRING_TOKEN(STR_PASSWORD_HELP),\r
+              minsize  = 6,\r
+              maxsize  = 20, // new opcode \r
+              encoding = 1,\r
+    endpassword; \r
+    //\r
+    // Test with flags and key fields\r
+    //\r
+    password  varid    = MyIfrNVData.WhatIsThePassword,\r
+              prompt   = STRING_TOKEN(STR_PASSWORD_PROMPT),\r
+              help     = STRING_TOKEN(STR_PASSWORD_HELP),\r
+              flags    = INTERACTIVE,\r
+              key      = 0x2000,\r
+              minsize  = 6,\r
+              maxsize  = 20, // new opcode \r
+              encoding = 1,\r
+    endpassword;\r
+\r
+    goto 2, \r
+      prompt = STRING_TOKEN(STR_GOTO_FORM2), //SecondSetupPage  // this too has no end-op and basically it's a jump to a form ONLY\r
+      help   = STRING_TOKEN(STR_GOTO_HELP);\r
+\r
+    goto 3, \r
+      prompt = STRING_TOKEN(STR_GOTO_FORM3), //ThirdSetupPage  // this too has no end-op and basically it's a jump to a form ONLY\r
+      help   = STRING_TOKEN(STR_GOTO_HELP);\r
+\r
+  endform;\r
+\r
+  form formid = 2,               // SecondSetupPage, \r
+       title = STRING_TOKEN(STR_FORM2_TITLE);  // note formid is a variable (for readability) (UINT16) - also added Form to the line to signify the Op-Code\r
+\r
+\r
+    date    year varid  = Date.Year,    // Note that it is a member of NULL, so the RTC will be the system resource to retrieve and save from\r
+            prompt      = STRING_TOKEN(STR_DATE_PROMPT),\r
+            help        = STRING_TOKEN(STR_DATE_YEAR_HELP),\r
+            minimum     = 1998,\r
+            maximum     = 2099,\r
+            step        = 1,\r
+            default     = 2004,\r
+\r
+            month varid = Date.Month,    // Note that it is a member of NULL, so the RTC will be the system resource to retrieve and save from\r
+            prompt      = STRING_TOKEN(STR_DATE_PROMPT),\r
+            help        = STRING_TOKEN(STR_DATE_MONTH_HELP),\r
+            minimum     = 1,\r
+            maximum     = 12,\r
+            step        = 1,\r
+            default     = 1,\r
+\r
+            day varid   = Date.Day,          // Note that it is a member of NULL, so the RTC will be the system resource to retrieve and save from\r
+            prompt      = STRING_TOKEN(STR_DATE_PROMPT),\r
+            help        = STRING_TOKEN(STR_DATE_DAY_HELP),\r
+            minimum     = 1,\r
+            maximum     = 31,\r
+            step        = 0x1,\r
+            default     = 1,\r
+\r
+    enddate;\r
+\r
+    time    hour varid  = Time.Hours,         // Note that it is a member of NULL, so the RTC will be the system resource to retrieve and save from\r
+            prompt      = STRING_TOKEN(STR_TIME_PROMPT),\r
+            help        = STRING_TOKEN(STR_TIME_HOUR_HELP),\r
+            minimum     = 0,\r
+            maximum     = 23,\r
+            step        = 1,\r
+            default     = 0,\r
+\r
+            minute varid  = Time.Minutes,       // Note that it is a member of NULL, so the RTC will be the system resource to retrieve and save from\r
+            prompt        = STRING_TOKEN(STR_TIME_PROMPT),\r
+            help          = STRING_TOKEN(STR_TIME_MINUTE_HELP),\r
+            minimum       = 0,\r
+            maximum       = 59,\r
+            step          = 1,\r
+            default       = 0,\r
+\r
+            second varid  = Time.Seconds,       // Note that it is a member of NULL, so the RTC will be the system resource to retrieve and save from\r
+            prompt        = STRING_TOKEN(STR_TIME_PROMPT),\r
+            help          = STRING_TOKEN(STR_TIME_SECOND_HELP),\r
+            minimum       = 0,\r
+            maximum       = 59,\r
+            step          = 1,\r
+            default       = 0,\r
+\r
+    endtime;\r
+\r
+    date    year varid  = Date.Year,    // Note that it is a member of NULL, so the RTC will be the system resource to retrieve and save from\r
+            prompt      = STRING_TOKEN(STR_DATE_PROMPT),\r
+            help        = STRING_TOKEN(STR_DATE_YEAR_HELP),\r
+            minimum     = 1939,\r
+            maximum     = 2101,\r
+            step        = 1,\r
+            default     = 1964,\r
+\r
+            month varid = Date.Month,    // Note that it is a member of NULL, so the RTC will be the system resource to retrieve and save from\r
+            prompt      = STRING_TOKEN(STR_DATE_PROMPT),\r
+            help        = STRING_TOKEN(STR_DATE_MONTH_HELP),\r
+            minimum     = 1,\r
+            maximum     = 12,\r
+            step        = 1,\r
+            default     = 1,\r
+\r
+            day varid   = Date.Day,          // Note that it is a member of NULL, so the RTC will be the system resource to retrieve and save from\r
+            prompt      = STRING_TOKEN(STR_DATE_PROMPT),\r
+            help        = STRING_TOKEN(STR_DATE_DAY_HELP),\r
+            minimum     = 1,\r
+            maximum     = 31,\r
+            step        = 0x1,\r
+            default     = 1,\r
+\r
+    enddate;\r
+\r
+    time    hour varid  = Time.Hours,         // Note that it is a member of NULL, so the RTC will be the system resource to retrieve and save from\r
+            prompt      = STRING_TOKEN(STR_TIME_PROMPT),\r
+            help        = STRING_TOKEN(STR_TIME_HOUR_HELP),\r
+            minimum     = 0,\r
+            maximum     = 23,\r
+            step        = 1,\r
+            default     = 0,\r
+\r
+            minute varid  = Time.Minutes,       // Note that it is a member of NULL, so the RTC will be the system resource to retrieve and save from\r
+            prompt        = STRING_TOKEN(STR_TIME_PROMPT),\r
+            help          = STRING_TOKEN(STR_TIME_MINUTE_HELP),\r
+            minimum       = 0,\r
+            maximum       = 59,\r
+            step          = 1,\r
+            default       = 0,\r
+\r
+            second varid  = Time.Seconds,       // Note that it is a member of NULL, so the RTC will be the system resource to retrieve and save from\r
+            prompt        = STRING_TOKEN(STR_TIME_PROMPT),\r
+            help          = STRING_TOKEN(STR_TIME_SECOND_HELP),\r
+            minimum       = 0,\r
+            maximum       = 59,\r
+            step          = 1,\r
+            default       = 0,\r
+\r
+    endtime;\r
+\r
+    grayoutif \r
+      ideqval Date.Day == 21\r
+      AND\r
+      ideqval Date.Month == 8;\r
+    \r
+    hidden  value = 32, key = 0x7777;\r
+\r
+    endif; // grayoutif\r
+\r
+    suppressif\r
+      ideqval Date.Day == 8\r
+      AND\r
+      ideqval Date.Month == 21; \r
+    \r
+    hidden  value = 32, key = 0x7777;\r
+\r
+    endif; // suppressif\r
+\r
+\r
+    hidden  value = 32, key = 0x1234;\r
+\r
+    inconsistentif prompt = STRING_TOKEN(STR_ERROR_POPUP),\r
+      ideqval MyIfrNVData.HowOldAreYouInYearsManual == 4\r
+    endif;\r
+     \r
+    inconsistentif prompt = STRING_TOKEN(STR_ERROR_POPUP),\r
+      ideqvallist MyIfrNVData.HowOldAreYouInYearsManual == 1 2 3 4\r
+    endif;\r
+\r
+    inconsistentif prompt = STRING_TOKEN(STR_ERROR_POPUP),\r
+      ideqid MyIfrNVData.HowOldAreYouInYearsManual == MyIfrNVData.MyFavoriteNumber\r
+    endif;\r
+\r
+//    grayoutif \r
+//\r
+// If the day is 31 AND months is any of the following 2, 4, 6, 9, 11\r
+//\r
+    inconsistentif prompt = STRING_TOKEN(STR_ERROR_POPUP),\r
+      ideqval Date.Day == 31 \r
+      AND\r
+      ideqvallist Date.Month == 2 4 6 9 11\r
+    endif;\r
+\r
+//\r
+// If the day is 30 AND month is 2\r
+//\r
+    inconsistentif prompt = STRING_TOKEN(STR_ERROR_POPUP),\r
+      ideqval Date.Day == 30\r
+      AND\r
+      ideqval Date.Month == 2\r
+    endif;\r
+\r
+//\r
+// If the day is 29 AND month is 2 AND it year is NOT a leapyear\r
+//\r
+    inconsistentif prompt = STRING_TOKEN(STR_ERROR_POPUP),\r
+      ideqval Date.Day == 0x1D\r
+      AND\r
+      ideqval Date.Month == 2 \r
+      AND\r
+      NOT\r
+      ideqvallist Date.Year == 2004 2008 20012 20016 2020 2024 2028 2032 2036\r
+    endif;\r
+\r
+    checkbox varid    = MyIfrNVData.ChooseToActivateNuclearWeaponry,\r
+            prompt   = STRING_TOKEN(STR_CHECK_BOX_PROMPT),\r
+            help     = STRING_TOKEN(STR_CHECK_BOX_HELP),  \r
+            flags    = 1,\r
+            key      = 0,\r
+    endcheckbox;\r
+\r
+    text  \r
+      help = STRING_TOKEN(STR_TEXT_HELP),  \r
+      text = STRING_TOKEN(STR_TEXT_TEXT_1);\r
+    \r
+    text \r
+      help   = STRING_TOKEN(STR_TEXT_HELP),  \r
+      text   = STRING_TOKEN(STR_TEXT_TEXT_1),\r
+      text   = STRING_TOKEN(STR_TEXT_TEXT_2),\r
+      flags  = 0,\r
+      key    = MY_TEXT_KEY;\r
+         \r
+    goto 1, \r
+      prompt = STRING_TOKEN(STR_GOTO_FORM1), //MainSetupPage  // this too has no end-op and basically it's a jump to a form ONLY\r
+      help   = STRING_TOKEN(STR_GOTO_HELP);\r
+\r
+  endform;\r
+\r
+  form formid = 3, title = STRING_TOKEN(STR_FORM3_TITLE);  // note formid is a variable (for readability) (UINT16) - also added Form to the line to signify the Op-Code\r
+\r
+    grayoutif  ideqval MyIfrNVData.SuppressGrayOutSomething == 0x1;\r
+      text  \r
+        help = STRING_TOKEN(STR_TEXT_HELP),  \r
+        text = STRING_TOKEN(STR_TEXT_TEXT_1);\r
+        \r
+    endif; //end grayoutif\r
+    \r
+    text  \r
+      help = STRING_TOKEN(STR_TEXT_HELP),  \r
+      text = STRING_TOKEN(STR_TEXT_TEXT_1);\r
+    \r
+  endform;\r
+  \r
+  form formid = 4, title = STRING_TOKEN(STR_FORM3_TITLE);\r
+\r
+  endform;\r
+\r
+  form formid = 0x1234,            // Dynamically created page, \r
+       title = STRING_TOKEN(STR_DYNAMIC_TITLE);  // note formid is a variable (for readability) (UINT16) - also added Form to the line to signify the Op-Code\r
+\r
+    label 0x1234;\r
+\r
+  endform;\r
+\r
+endformset;\r
diff --git a/IntelFrameworkModulePkg/Universal/DriverSampleDxe/VfrStrings.uni b/IntelFrameworkModulePkg/Universal/DriverSampleDxe/VfrStrings.uni
new file mode 100644 (file)
index 0000000..9e9dbf5
Binary files /dev/null and b/IntelFrameworkModulePkg/Universal/DriverSampleDxe/VfrStrings.uni differ
diff --git a/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/CommonHeader.h b/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/CommonHeader.h
new file mode 100644 (file)
index 0000000..2506b80
--- /dev/null
@@ -0,0 +1,41 @@
+/**@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 <FrameworkDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Guid/GlobalVariable.h>\r
+#include <Protocol/FormCallback.h>\r
+#include <Protocol/FrameworkHii.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/IfrSupportLibFramework.h>\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/Fonts.c b/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/Fonts.c
new file mode 100644 (file)
index 0000000..2c3980d
--- /dev/null
@@ -0,0 +1,271 @@
+/*++\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
+  Fonts.c\r
+\r
+Abstract:\r
+\r
+  This file contains the Glyph/Font processing code to the HII database.\r
+\r
+--*/\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "HiiDatabase.h"\r
+\r
+//\r
+// We only need to define a wide glyph, since we will seed the narrow glyph with EFI_NARROW_GLYPH size of\r
+// this data structure\r
+//\r
+UINT8 mUnknownGlyph[38] = {\r
+  0xaa,\r
+  0x55,\r
+  0xaa,\r
+  0x55,\r
+  0xaa,\r
+  0x55,\r
+  0xaa,\r
+  0x55,\r
+  0xaa,\r
+  0x55,\r
+  0xaa,\r
+  0x55,\r
+  0xaa,\r
+  0x55,\r
+  0xaa,\r
+  0x55,\r
+  0xaa,\r
+  0x55,\r
+  0xAA,\r
+  0xaa,\r
+  0x55,\r
+  0xaa,\r
+  0x55,\r
+  0xaa,\r
+  0x55,\r
+  0xaa,\r
+  0x55,\r
+  0xaa,\r
+  0x55,\r
+  0xaa,\r
+  0x55,\r
+  0xaa,\r
+  0x55,\r
+  0xaa,\r
+  0x55,\r
+  0xaa,\r
+  0x55,\r
+  0xAA\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiGetGlyph (\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
+Routine Description:\r
+  Translates a Unicode character into the corresponding font glyph.  \r
+  If the Source was pointing to a non-spacing character, the next Source[*Index]\r
+  character will be parsed and OR'd to the GlyphBuffer until a spacing character\r
+  is found in the Source.  Since non-spacing characters are considered to be the\r
+  same pixel width as a regular character their BitWidth will be reflected correctly\r
+  however due to their special attribute, they are considered to be zero advancing width.\r
+  This basically means that the cursor would not advance, thus the character that follows\r
+  it would overlay the non-spacing character.  The Index is modified to reflect both the\r
+  incoming array entry into the Source string but also the outgoing array entry after having\r
+  parsed the equivalent of a single Glyph's worth of data.\r
+\r
+Arguments:\r
+\r
+Returns: \r
+\r
+--*/\r
+{\r
+  EFI_HII_GLOBAL_DATA *GlobalData;\r
+  EFI_HII_DATA        *HiiData;\r
+  UINTN               Count;\r
+  BOOLEAN             Narrow;\r
+  UINTN               Location;\r
+  UINTN               SearchLocation;\r
+  UINTN               Value;\r
+  CHAR16              Character;\r
+  UINTN               Attributes;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  HiiData         = EFI_HII_DATA_FROM_THIS (This);\r
+\r
+  GlobalData      = HiiData->GlobalData;\r
+  Count           = sizeof (GlobalData->NarrowGlyphs->GlyphCol1);\r
+\r
+  Location        = *Index;\r
+  SearchLocation  = *Index;\r
+  Narrow          = TRUE;\r
+\r
+  if (Source[Location] == NARROW_CHAR || Source[Location] == WIDE_CHAR) {\r
+    *InternalStatus = 0;\r
+  }\r
+  //\r
+  // We don't know what glyph database to look in - let's figure it out\r
+  //\r
+  if (*InternalStatus == 0) {\r
+    //\r
+    // Determine if we are looking for narrow or wide glyph data\r
+    //\r
+    do {\r
+      if (Source[SearchLocation] == NARROW_CHAR || Source[SearchLocation] == WIDE_CHAR) {\r
+        //\r
+        // We found something that identifies what glyph database to look in\r
+        //\r
+        if (Source[SearchLocation] == WIDE_CHAR) {\r
+          Narrow          = FALSE;\r
+          *BitWidth       = WIDE_WIDTH;\r
+          *InternalStatus = WIDE_CHAR;\r
+          Location++;\r
+          break;\r
+        } else {\r
+          Narrow          = TRUE;\r
+          *BitWidth       = NARROW_WIDTH;\r
+          *InternalStatus = NARROW_CHAR;\r
+          Location++;\r
+          break;\r
+        }\r
+      }\r
+    } while (SearchLocation-- > 0);\r
+  }\r
+\r
+  if (*InternalStatus == NARROW_CHAR) {\r
+    Narrow    = TRUE;\r
+    *BitWidth = NARROW_WIDTH;\r
+  } else if (*InternalStatus == WIDE_CHAR) {\r
+    Narrow    = FALSE;\r
+    *BitWidth = WIDE_WIDTH;\r
+  } else {\r
+    //\r
+    // Without otherwise knowing what the width is narrow (e.g. someone passed in a string with index of 0\r
+    // we wouldn't be able to determine the width of the data.)\r
+    // BUGBUG - do we go to wide database and if exist, ignore narrow?  Check Unicode spec....\r
+    //\r
+    Narrow    = TRUE;\r
+    *BitWidth = NARROW_WIDTH;\r
+  }\r
+\r
+  Character = Source[Location];\r
+\r
+  if (Narrow) {\r
+    if (GlobalData->NarrowGlyphs[Character].UnicodeWeight != 0x0000) {\r
+      *GlyphBuffer  = (UINT8 *) (&GlobalData->NarrowGlyphs[Character]);\r
+      Attributes    = GlobalData->NarrowGlyphs[Character].Attributes & EFI_GLYPH_NON_SPACING;\r
+    } else {\r
+      //\r
+      // Glyph is uninitialized - return an error, but hand back the glyph\r
+      //\r
+      *GlyphBuffer  = (UINT8 *) (&GlobalData->NarrowGlyphs[Character]);\r
+      *Index        = (UINT16) (Location + 1);\r
+      return EFI_NOT_FOUND;\r
+    }\r
+  } else {\r
+    //\r
+    // Wide character\r
+    //\r
+    if (GlobalData->WideGlyphs[Character].UnicodeWeight != 0x0000) {\r
+      *GlyphBuffer  = (UINT8 *) (&GlobalData->WideGlyphs[Character]);\r
+      Attributes    = GlobalData->WideGlyphs[Character].Attributes & EFI_GLYPH_NON_SPACING;\r
+    } else {\r
+      //\r
+      // Glyph is uninitialized - return an error, but hand back the glyph\r
+      //\r
+      *GlyphBuffer  = (UINT8 *) (&GlobalData->WideGlyphs[Character]);\r
+      *Index        = (UINT16) (Location + 1);\r
+      return EFI_NOT_FOUND;\r
+    }\r
+  }\r
+  //\r
+  // This is a non-spacing character.  It will be followed by either more non-spacing\r
+  // characters or a regular character.  We need to OR together the data associated with each.\r
+  //\r
+  for (; Attributes != 0; Location++) {\r
+    //\r
+    // Character is the Unicode value which is the index into the Glyph array.\r
+    //\r
+    Character = Source[Location];\r
+\r
+    if (Narrow) {\r
+      for (Value = 0; Value != Count; Value++) {\r
+        *GlyphBuffer[Location + Value] = (UINT8) (*GlyphBuffer[Location + Value] |\r
+                                                  GlobalData->NarrowGlyphs[Character].GlyphCol1[Value]);\r
+      }\r
+\r
+      Attributes = GlobalData->NarrowGlyphs[Character].Attributes & EFI_GLYPH_NON_SPACING;\r
+    } else {\r
+      for (Value = 0; Value != Count; Value++) {\r
+        *GlyphBuffer[Location + Value] = (UINT8) (*GlyphBuffer[Location + Value] | \r
+                                                  GlobalData->WideGlyphs[Character].GlyphCol1[Value]);\r
+        *GlyphBuffer[Location + Value + Count] = (UINT8) (*GlyphBuffer[Location + Value + Count] |\r
+                                                          GlobalData->WideGlyphs[Character].GlyphCol2[Value]);\r
+      }\r
+\r
+      Attributes = GlobalData->WideGlyphs[Character].Attributes & EFI_GLYPH_NON_SPACING;\r
+    }\r
+  }\r
+  //\r
+  // Source[*Index] should point to the next character to process\r
+  //\r
+  *Index = (UINT16) (Location + 1);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiGlyphToBlt (\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
+  UINTN X;\r
+  UINTN Y;\r
+\r
+  //\r
+  // Convert Monochrome bitmap of the Glyph to BltBuffer structure\r
+  //\r
+  for (Y = 0; Y < Height; Y++) {\r
+    for (X = 0; X < Width; X++) {\r
+      if ((((EFI_NARROW_GLYPH *) GlyphBuffer)->GlyphCol1[Y] & (1 << X)) != 0) {\r
+        BltBuffer[Y * Width * Count + (Width - X - 1)] = Foreground;\r
+      } else {\r
+        BltBuffer[Y * Width * Count + (Width - X - 1)] = Background;\r
+      }\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/Forms.c b/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/Forms.c
new file mode 100644 (file)
index 0000000..c9a8d9a
--- /dev/null
@@ -0,0 +1,1582 @@
+/**@file\r
+  This file contains the form processing code to the HII database.\r
+  \r
+Copyright (c) 2006 - 2007 Intel Corporation. <BR>\r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+**/\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "HiiDatabase.h"\r
+\r
+STATIC\r
+CHAR16*\r
+Ascii2Unicode (\r
+  OUT CHAR16         *UnicodeStr,\r
+  IN  CHAR8          *AsciiStr\r
+  )\r
+/*++\r
+  \r
+  Routine Description:\r
+\r
+    This function converts ASCII string to Unicode string.\r
+  \r
+  Arguments:\r
+\r
+    UnicodeStr     - NULL terminated Unicode output string.\r
+    AsciieStr      - NULL terminated ASCII input string.\r
\r
+  Returns: \r
+\r
+    Start of the Unicode ouput string.\r
+    \r
+--*/\r
+\r
+{\r
+  CHAR16      *Str = UnicodeStr;  \r
+  while (TRUE) {\r
+    *(UnicodeStr++) = (CHAR16) *AsciiStr;\r
+    if (*(AsciiStr++) == '\0') {\r
+      return Str;\r
+    }\r
+  }\r
+}\r
+\r
+STATIC\r
+CHAR8*\r
+Unicode2Ascii (\r
+  OUT CHAR8          *AsciiStr,\r
+  IN  CHAR16         *UnicodeStr\r
+  )\r
+/*++\r
+  \r
+  Routine Description:\r
+\r
+    This function converts Unicode string to ASCII string.\r
+  \r
+  Arguments:\r
+\r
+    AsciieStr      - NULL terminated ASCII output string.\r
+    UnicodeStr     - NULL terminated Unicode input string.\r
\r
+  Returns: \r
+\r
+    Start of the ASCII ouput string.\r
+    \r
+--*/\r
+\r
+{\r
+  CHAR8      *Str = AsciiStr;  \r
+  while (TRUE) {\r
+    *(AsciiStr++) = (CHAR8) *UnicodeStr;\r
+    if (*(UnicodeStr++) == '\0') {\r
+      return Str;\r
+    }\r
+  }\r
+}\r
+\r
+STATIC\r
+VOID\r
+ExtractDevicePathData (\r
+  IN     EFI_HII_DATA_TABLE   *DataTable,\r
+  IN     UINT8                *IfrData,\r
+  IN OUT UINT8                **ExportBufferPtr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  \r
+Arguments:\r
+\r
+Returns: \r
+\r
+--*/\r
+{\r
+  UINT8 *ExportBuffer;\r
+\r
+  ExportBuffer = *ExportBufferPtr;\r
+\r
+  //\r
+  // BUGBUG - don't have devicepath data yet, setting dummy value\r
+  //\r
+  DataTable++;\r
+  ExportBuffer  = (UINT8 *) DataTable;\r
+  ((EFI_HII_DEVICE_PATH_PACK *) ExportBuffer)->Header.Type = EFI_HII_DEVICE_PATH;\r
+  ((EFI_HII_DEVICE_PATH_PACK *) ExportBuffer)->Header.Length = (UINT32) (sizeof (EFI_HII_DEVICE_PATH_PACK) + sizeof (EFI_DEVICE_PATH_PROTOCOL));\r
+\r
+  //\r
+  // BUGBUG - part of hack - skip the Device Path Pack.....place some data\r
+  //\r
+  ExportBuffer  = ExportBuffer + sizeof (EFI_HII_DEVICE_PATH_PACK);\r
+\r
+  ((EFI_DEVICE_PATH_PROTOCOL *) ExportBuffer)->Type     = EFI_END_ENTIRE_DEVICE_PATH;\r
+  ((EFI_DEVICE_PATH_PROTOCOL *) ExportBuffer)->SubType  = EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;\r
+\r
+  //\r
+  // BUGBUG - still part of hack....\r
+  //\r
+  ExportBuffer      = ExportBuffer + sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
+  *ExportBufferPtr  = ExportBuffer;\r
+}\r
+\r
+STATIC\r
+VOID\r
+ExtractVariableData (\r
+  IN OUT EFI_HII_DATA_TABLE   *DataTable,\r
+  IN     UINT8                *IfrData,\r
+  IN OUT UINT8                **ExportBufferPtr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function extract the EFI_HII_VARIABLE_PACK portion from the \r
+  each of the EFI_HII_PACKAGE_INSTANCE in HII handle database.\r
+  \r
+Arguments:\r
+\r
+  DataTable       - On input, this parameter point to the EFI_HII_DATA_TABLE structure\r
+                    of the final data buffer for the EFI_HII_EXPORT interface. This function\r
+                    update the NumberOfVariableData attribute.\r
+  IfrData         - It points to a staring address of a EFI_HII_IFR_PACK structure.\r
+  ExportBufferPtr - On input, it points the starting address of the data buffer to \r
+                    host the variable pack. On output, it is the starting address\r
+                    of data buffer for the next extraction operation.\r
+Returns: \r
+\r
+  VOID\r
+  \r
+--*/\r
+{\r
+  EFI_HII_VARIABLE_PACK       *VariableContents;\r
+  UINT8                       *ExportBuffer;\r
+  UINTN                       Index;\r
+  UINTN                       Index2;\r
+  UINTN                       TempValue;\r
+  UINTN                       TempValue2;\r
+  EFI_FORM_CALLBACK_PROTOCOL  *FormCallback;\r
+  EFI_PHYSICAL_ADDRESS        CallbackHandle;\r
+  EFI_STATUS                  Status;\r
+  CHAR16                      *String;\r
+\r
+  FormCallback    = NULL;\r
+  CallbackHandle  = 0;\r
+  ExportBuffer    = *ExportBufferPtr;\r
+\r
+  for (Index = 0; IfrData[Index] != EFI_IFR_END_FORM_SET_OP;) {\r
+    VariableContents = (EFI_HII_VARIABLE_PACK *) ExportBuffer;\r
+\r
+    switch (IfrData[Index]) {\r
+    case EFI_IFR_FORM_SET_OP:\r
+      TempValue = EFI_HII_VARIABLE;\r
+      CopyMem (&VariableContents->Header.Type, &TempValue, sizeof (UINT16));\r
+      CopyMem (&TempValue, &((EFI_IFR_FORM_SET *) &IfrData[Index])->NvDataSize, sizeof (UINT16));\r
+\r
+      //\r
+      // If the variable has 0 size, do not process it\r
+      //\r
+      if (TempValue == 0) {\r
+        break;\r
+      }\r
+      //\r
+      // Add the size of the variable pack overhead.  Later, will also add the size of the\r
+      // name of the variable.\r
+      //\r
+      TempValue = TempValue + sizeof (EFI_HII_VARIABLE_PACK);\r
+\r
+      CopyMem (&VariableContents->Header.Length, &TempValue, sizeof (UINT32));\r
+      CopyMem (\r
+        &CallbackHandle,\r
+        &((EFI_IFR_FORM_SET *) &IfrData[Index])->CallbackHandle,\r
+        sizeof (EFI_PHYSICAL_ADDRESS)\r
+        );\r
+      if (CallbackHandle != 0) {\r
+        Status = gBS->HandleProtocol (\r
+                        (EFI_HANDLE) (UINTN) CallbackHandle,\r
+                        &gEfiFormCallbackProtocolGuid,\r
+                        (VOID *) &FormCallback\r
+                        );\r
+        ASSERT_EFI_ERROR (Status);\r
+      }\r
+      //\r
+      // Since we have a "Setup" variable that wasn't specified by a variable op-code\r
+      // it will have a VariableId of 0.  All other variable op-codes will have a designation\r
+      // of VariableId 1+\r
+      //\r
+      TempValue = 0;\r
+      CopyMem (&VariableContents->VariableId, &TempValue, sizeof (UINT16));\r
+      CopyMem (&VariableContents->VariableGuid, &((EFI_IFR_FORM_SET *) &IfrData[Index])->Guid, sizeof (EFI_GUID));\r
+      TempValue = sizeof (SETUP_MAP_NAME);\r
+      CopyMem (&VariableContents->VariableNameLength, &TempValue, sizeof (UINT32));\r
+\r
+      //\r
+      // Add the size of the name to the Header Length\r
+      //\r
+      TempValue2 = 0;\r
+      CopyMem (&TempValue2, &VariableContents->Header.Length, sizeof (UINT32));\r
+      TempValue2 = TempValue + TempValue2;\r
+      CopyMem (&VariableContents->Header.Length, &TempValue2, sizeof (UINT32));\r
+\r
+      ExportBuffer = ExportBuffer + sizeof (EFI_HII_VARIABLE_PACK);\r
+      CopyMem (ExportBuffer, SETUP_MAP_NAME, sizeof (SETUP_MAP_NAME));\r
+      ExportBuffer = ExportBuffer + sizeof (SETUP_MAP_NAME);\r
+\r
+      CopyMem (&TempValue, &((EFI_IFR_FORM_SET *) &IfrData[Index])->NvDataSize, sizeof (UINT16));\r
+\r
+      if ((FormCallback != NULL) && (FormCallback->NvRead != NULL)) {\r
+        Status = FormCallback->NvRead (\r
+                                 FormCallback,\r
+                                 (CHAR16 *) SETUP_MAP_NAME,\r
+                                 (EFI_GUID *)(UINTN)&VariableContents->VariableGuid,\r
+                                 NULL,\r
+                                 &TempValue,\r
+                                 ExportBuffer\r
+                                 );\r
+        ASSERT_EFI_ERROR (Status);\r
+      } else {\r
+        Status = gRT->GetVariable (\r
+                        (CHAR16 *) SETUP_MAP_NAME,\r
+                        (EFI_GUID *)(UINTN)&VariableContents->VariableGuid,\r
+                        NULL,\r
+                        &TempValue,\r
+                        ExportBuffer\r
+                        );\r
+        ASSERT_EFI_ERROR (Status);\r
+      }\r
+\r
+      ExportBuffer = (UINT8 *) (UINTN) (((UINTN) ExportBuffer) + TempValue);\r
+      DataTable->NumberOfVariableData++;\r
+      break;\r
+\r
+    case EFI_IFR_VARSTORE_OP:\r
+      TempValue = EFI_HII_VARIABLE;\r
+      CopyMem (&VariableContents->Header.Type, &TempValue, sizeof (UINT16));\r
+      CopyMem (&TempValue, &((EFI_IFR_VARSTORE *) &IfrData[Index])->Size, sizeof (UINT16));\r
+\r
+      //\r
+      // If the variable has 0 size, do not process it\r
+      //\r
+      if (TempValue == 0) {\r
+        break;\r
+      }\r
+      //\r
+      // Add the size of the variable pack overhead.  Later, will also add the size of the\r
+      // name of the variable.\r
+      //\r
+      TempValue = TempValue + sizeof (EFI_HII_VARIABLE_PACK);\r
+\r
+      CopyMem (&VariableContents->Header.Length, &TempValue, sizeof (UINT32));\r
+      CopyMem (&VariableContents->VariableId, &((EFI_IFR_VARSTORE *) &IfrData[Index])->VarId, sizeof (UINT16));\r
+      CopyMem (&VariableContents->VariableGuid, &((EFI_IFR_VARSTORE *) &IfrData[Index])->Guid, sizeof (EFI_GUID));\r
+      TempValue = (UINTN) ((EFI_IFR_VARSTORE *) &IfrData[Index])->Header.Length - sizeof (EFI_IFR_VARSTORE);\r
+      TempValue = TempValue * 2;\r
+      CopyMem (&VariableContents->VariableNameLength, &TempValue, sizeof (UINT32));\r
+\r
+      //\r
+      // Add the size of the name to the Header Length\r
+      //\r
+      TempValue2 = 0;\r
+      CopyMem (&TempValue2, &VariableContents->Header.Length, sizeof (UINT32));\r
+      TempValue2 = TempValue + TempValue2;\r
+      CopyMem (&VariableContents->Header.Length, &TempValue2, sizeof (UINT32));\r
+\r
+      ExportBuffer  = ExportBuffer + sizeof (EFI_HII_VARIABLE_PACK);\r
+      String        = (CHAR16 *) ExportBuffer;\r
+      for (Index2 = 0; Index2 < TempValue / 2; Index2++) {\r
+        ExportBuffer[Index2 * 2]      = IfrData[Index + sizeof (EFI_IFR_VARSTORE) + Index2];\r
+        ExportBuffer[Index2 * 2 + 1]  = 0;\r
+      }\r
+\r
+      ExportBuffer = ExportBuffer + TempValue;\r
+\r
+      CopyMem (&TempValue, &((EFI_IFR_VARSTORE *) &IfrData[Index])->Size, sizeof (UINT16));\r
+\r
+      if ((FormCallback != NULL) && (FormCallback->NvRead != NULL)) {\r
+        Status = FormCallback->NvRead (\r
+                                 FormCallback,\r
+                                 String,\r
+                                 (EFI_GUID *)(UINTN)&VariableContents->VariableGuid,\r
+                                 NULL,\r
+                                 &TempValue,\r
+                                 ExportBuffer\r
+                                 );\r
+        ASSERT_EFI_ERROR (Status);\r
+      } else {\r
+        Status = gRT->GetVariable (\r
+                        String,\r
+                        (EFI_GUID *)(UINTN)&VariableContents->VariableGuid,\r
+                        NULL,\r
+                        &TempValue,\r
+                        ExportBuffer\r
+                        );\r
+        ASSERT_EFI_ERROR (Status);\r
+      }\r
+\r
+      ExportBuffer = (UINT8 *) (UINTN) (((UINTN) ExportBuffer) + TempValue);\r
+      DataTable->NumberOfVariableData++;\r
+      break;\r
+    }\r
+\r
+    Index = IfrData[Index + 1] + Index;\r
+  }\r
+  //\r
+  // If we have added a variable pack, add a dummy empty one to signify the end\r
+  //\r
+  if (ExportBuffer != *ExportBufferPtr) {\r
+    VariableContents  = (EFI_HII_VARIABLE_PACK *) ExportBuffer;\r
+    TempValue         = EFI_HII_VARIABLE;\r
+    CopyMem (&VariableContents->Header.Type, &TempValue, sizeof (UINT16));\r
+    TempValue = sizeof (EFI_HII_VARIABLE_PACK);\r
+    CopyMem (&VariableContents->Header.Length, &TempValue, sizeof (UINT32));\r
+    ExportBuffer = ExportBuffer + sizeof (EFI_HII_VARIABLE_PACK);\r
+  }\r
+\r
+  *ExportBufferPtr = ExportBuffer;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiExportDatabase (\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
+Routine Description:\r
+  \r
+  This function allows a program to extract a form or form package that has \r
+  previously been registered with the EFI HII database.\r
+\r
+Arguments:\r
+\r
+Returns: \r
+\r
+--*/\r
+{\r
+  EFI_HII_PACKAGE_INSTANCE  *PackageInstance;\r
+  EFI_HII_DATA              *HiiData;\r
+  EFI_HII_HANDLE_DATABASE   *HandleDatabase;\r
+  EFI_HII_IFR_PACK          *FormPack;\r
+  UINT8                     *RawData;\r
+  UINT8                     *ExportBuffer;\r
+  EFI_HII_EXPORT_TABLE      *ExportTable;\r
+  EFI_HII_DATA_TABLE        *DataTable;\r
+  BOOLEAN                   VariableExist;\r
+  UINT16                    NumberOfHiiDataTables;\r
+  UINTN                     SizeNeeded;\r
+  UINTN                     Index;\r
+  UINTN                     VariableSize;\r
+  UINTN                     TempValue;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  HiiData               = EFI_HII_DATA_FROM_THIS (This);\r
+\r
+  HandleDatabase        = HiiData->DatabaseHead;\r
+\r
+  FormPack              = NULL;\r
+  RawData               = NULL;\r
+  PackageInstance       = NULL;\r
+  NumberOfHiiDataTables = 0;\r
+  VariableSize          = 0;\r
+  TempValue             = 0;\r
+  SizeNeeded            = sizeof (EFI_HII_EXPORT_TABLE);\r
+\r
+  //\r
+  // How many total tables are there?\r
+  //\r
+  for (; HandleDatabase != NULL; HandleDatabase = HandleDatabase->NextHandleDatabase) {\r
+    if ((Handle != 0) && (Handle != HandleDatabase->Handle)) {\r
+      continue;\r
+    }\r
+\r
+    VariableExist = FALSE;\r
+    NumberOfHiiDataTables++;\r
+    PackageInstance = HandleDatabase->Buffer;\r
+    if (PackageInstance == NULL) {\r
+      continue;\r
+    }\r
+    //\r
+    // Extract Size of Export Package\r
+    //\r
+    SizeNeeded = SizeNeeded + PackageInstance->IfrSize \r
+                            + PackageInstance->StringSize\r
+                            + sizeof (EFI_HII_DATA_TABLE)\r
+                            + sizeof (EFI_HII_DEVICE_PATH_PACK);\r
+\r
+    //\r
+    // BUGBUG We aren't inserting Device path data yet\r
+    //\r
+    SizeNeeded = SizeNeeded + sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
+\r
+    //\r
+    // Extract Size of Variable Data\r
+    //\r
+    if (PackageInstance->IfrSize > 0) {\r
+      FormPack = (EFI_HII_IFR_PACK *) ((CHAR8 *) (&PackageInstance->IfrData) + sizeof (EFI_HII_PACK_HEADER));\r
+    } else {\r
+      //\r
+      // No IFR? No variable information\r
+      //\r
+      continue;\r
+    }\r
+\r
+    RawData = (UINT8 *) FormPack;\r
+\r
+    for (Index = 0; RawData[Index] != EFI_IFR_END_FORM_SET_OP;) {\r
+      switch (RawData[Index]) {\r
+      case EFI_IFR_FORM_SET_OP:\r
+        CopyMem (&VariableSize, &((EFI_IFR_FORM_SET *) &RawData[Index])->NvDataSize, sizeof (UINT16));\r
+        SizeNeeded    = SizeNeeded + VariableSize + sizeof (SETUP_MAP_NAME) + sizeof (EFI_HII_VARIABLE_PACK);\r
+        VariableExist = TRUE;\r
+        break;\r
+\r
+      case EFI_IFR_VARSTORE_OP:\r
+        CopyMem (&VariableSize, &((EFI_IFR_VARSTORE *) &RawData[Index])->Size, sizeof (UINT16));\r
+        SizeNeeded = SizeNeeded + VariableSize + sizeof (EFI_HII_VARIABLE_PACK);\r
+        //\r
+        // We will be expanding the stored ASCII name to a Unicode string.  This will cause some memory overhead\r
+        // Since the VARSTORE size already takes in consideration the ASCII size, we need to size it and add another\r
+        // instance of it.  Essentially, 2 ASCII strings == 1 Unicode string in size.\r
+        //\r
+        TempValue     = (UINTN) ((EFI_IFR_VARSTORE *) &RawData[Index])->Header.Length - sizeof (EFI_IFR_VARSTORE);\r
+        SizeNeeded    = SizeNeeded + TempValue * 2;\r
+        VariableExist = TRUE;\r
+        break;\r
+      }\r
+\r
+      Index = RawData[Index + 1] + Index;\r
+    }\r
+    //\r
+    // If a variable exists for this handle, add an additional variable pack overhead to\r
+    // indicate that we will have an extra null Variable Pack to signify the end of the Variable Packs\r
+    //\r
+    if (VariableExist) {\r
+      SizeNeeded = SizeNeeded + sizeof (EFI_HII_VARIABLE_PACK);\r
+    }\r
+  }\r
+\r
+  if (SizeNeeded > *BufferSize) {\r
+    *BufferSize = SizeNeeded;\r
+    return EFI_BUFFER_TOO_SMALL;\r
+  }\r
+  //\r
+  // Zero out the incoming buffer\r
+  //\r
+  ZeroMem (Buffer, *BufferSize);\r
+\r
+  //\r
+  // Cast the Buffer to EFI_HII_EXPORT_TABLE\r
+  //\r
+  ExportTable = (EFI_HII_EXPORT_TABLE *) Buffer;\r
+\r
+  //\r
+  // Set the Revision for the Export Table\r
+  //\r
+  CopyMem (&ExportTable->Revision, &gEfiHiiProtocolGuid, sizeof (EFI_GUID));\r
+\r
+  ExportBuffer    = (UINT8 *) (UINTN) (((UINT8 *) ExportTable) + sizeof (EFI_HII_EXPORT_TABLE));\r
+  HandleDatabase  = HiiData->DatabaseHead;\r
+\r
+  //\r
+  // Check numeric value against the head of the database\r
+  //\r
+  for (; HandleDatabase != NULL; HandleDatabase = HandleDatabase->NextHandleDatabase) {\r
+    DataTable       = (EFI_HII_DATA_TABLE *) ExportBuffer;\r
+    PackageInstance = HandleDatabase->Buffer;\r
+    //\r
+    // If not asking for a specific handle, export the entire database\r
+    //\r
+    if (Handle == 0) {\r
+      ExportTable->NumberOfHiiDataTables = NumberOfHiiDataTables;\r
+      CopyMem (&DataTable->PackageGuid, &PackageInstance->Guid, sizeof (EFI_GUID));\r
+      DataTable->HiiHandle        = PackageInstance->Handle;\r
+      DataTable->DevicePathOffset = (UINT32) (sizeof (EFI_HII_DATA_TABLE));\r
+\r
+      //\r
+      // Start Dumping DevicePath\r
+      //\r
+      ExtractDevicePathData (DataTable, RawData, &ExportBuffer);\r
+\r
+      if (((UINTN) ExportBuffer) == ((UINTN) DataTable)) {\r
+        //\r
+        // If there is no DevicePath information - set offset to 0 to signify the absence of data to parse\r
+        //\r
+        DataTable->DevicePathOffset = 0;\r
+      }\r
+\r
+      DataTable->VariableDataOffset = (UINT32) (((UINTN) ExportBuffer) - ((UINTN) DataTable));\r
+\r
+      if (PackageInstance->IfrSize > 0) {\r
+        FormPack  = (EFI_HII_IFR_PACK *) ((CHAR8 *) (&PackageInstance->IfrData) + sizeof (EFI_HII_PACK_HEADER));\r
+\r
+        RawData   = (UINT8 *) FormPack;\r
+        TempValue = 0;\r
+\r
+        //\r
+        // Start dumping the Variable Data\r
+        //\r
+        ExtractVariableData (DataTable, RawData, &ExportBuffer);\r
+        DataTable->IfrDataOffset = (UINT32) (((UINTN) ExportBuffer) - ((UINTN) DataTable));\r
+\r
+        if (DataTable->VariableDataOffset == DataTable->IfrDataOffset) {\r
+          DataTable->VariableDataOffset = 0;\r
+        }\r
+        //\r
+        // Start dumping the IFR data (Note:  It is in an IFR PACK)\r
+        //\r
+        CopyMem (ExportBuffer, &PackageInstance->IfrData, PackageInstance->IfrSize);\r
+        ExportBuffer                = (UINT8 *) (UINTN) (((UINTN) ExportBuffer) + PackageInstance->IfrSize);\r
+        DataTable->StringDataOffset = (UINT32) (((UINTN) ExportBuffer) - ((UINTN) DataTable));\r
+\r
+        //\r
+        // Start dumping the String data (Note:  It is in a String PACK)\r
+        //\r
+        if (PackageInstance->StringSize > 0) {\r
+          RawData = (UINT8 *) (((UINTN) &PackageInstance->IfrData) + PackageInstance->IfrSize);\r
+          CopyMem (ExportBuffer, RawData, PackageInstance->StringSize);\r
+          DataTable->DataTableSize = (UINT32) (DataTable->StringDataOffset + PackageInstance->StringSize);\r
+\r
+          CopyMem (&TempValue, &((EFI_HII_STRING_PACK *) ExportBuffer)->Header.Length, sizeof (UINT32));\r
+          for (; TempValue != 0;) {\r
+            DataTable->NumberOfLanguages++;\r
+            ExportBuffer = ExportBuffer + ((EFI_HII_STRING_PACK *) ExportBuffer)->Header.Length;\r
+            CopyMem (&TempValue, &((EFI_HII_STRING_PACK *) ExportBuffer)->Header.Length, sizeof (UINT32));\r
+          }\r
+\r
+          ExportBuffer = ExportBuffer + sizeof (EFI_HII_STRING_PACK);\r
+        } else {\r
+          DataTable->StringDataOffset = 0;\r
+        }\r
+      } else {\r
+        //\r
+        // No IFR? No variable information.  If Offset is 0, means there is none.  (Hmm - this might be prunable - no strings to export if no IFR - we always have a stub)\r
+        //\r
+        DataTable->VariableDataOffset = 0;\r
+        DataTable->IfrDataOffset      = 0;\r
+        DataTable->StringDataOffset   = (UINT32) (((UINTN) ExportBuffer) - ((UINTN) DataTable));\r
+\r
+        //\r
+        // Start dumping the String data - NOTE:  It is in String Pack form\r
+        //\r
+        if (PackageInstance->StringSize > 0) {\r
+          RawData = (UINT8 *) (((UINTN) &PackageInstance->IfrData) + PackageInstance->IfrSize);\r
+          CopyMem (ExportBuffer, RawData, PackageInstance->StringSize);\r
+          DataTable->DataTableSize = (UINT32) (DataTable->StringDataOffset + PackageInstance->StringSize);\r
+\r
+          CopyMem (&TempValue, &((EFI_HII_STRING_PACK *) ExportBuffer)->Header.Length, sizeof (UINT32));\r
+          for (; TempValue != 0;) {\r
+            DataTable->NumberOfLanguages++;\r
+            ExportBuffer = ExportBuffer + ((EFI_HII_STRING_PACK *) ExportBuffer)->Header.Length;\r
+            CopyMem (&TempValue, &((EFI_HII_STRING_PACK *) ExportBuffer)->Header.Length, sizeof (UINT32));\r
+          }\r
+\r
+          ExportBuffer = ExportBuffer + sizeof (EFI_HII_STRING_PACK);\r
+        } else {\r
+          DataTable->StringDataOffset = 0;\r
+        }\r
+      }\r
+    } else {\r
+      //\r
+      // Match the numeric value with the database entry - if matched, extract PackageInstance\r
+      //\r
+      if (Handle == HandleDatabase->Handle) {\r
+        PackageInstance                     = HandleDatabase->Buffer;\r
+        ExportTable->NumberOfHiiDataTables  = NumberOfHiiDataTables;\r
+        DataTable->HiiHandle                = PackageInstance->Handle;\r
+        CopyMem (&DataTable->PackageGuid, &PackageInstance->Guid, sizeof (EFI_GUID));\r
+\r
+        //\r
+        // Start Dumping DevicePath\r
+        //\r
+        ExtractDevicePathData (DataTable, RawData, &ExportBuffer);\r
+        DataTable->VariableDataOffset = (UINT32) (((UINTN) ExportBuffer) - ((UINTN) DataTable));\r
+\r
+        if (PackageInstance->IfrSize > 0) {\r
+          FormPack  = (EFI_HII_IFR_PACK *) ((CHAR8 *) (&PackageInstance->IfrData) + sizeof (EFI_HII_PACK_HEADER));\r
+\r
+          RawData   = (UINT8 *) FormPack;\r
+          TempValue = 0;\r
+\r
+          //\r
+          // Start dumping the Variable Data\r
+          //\r
+          ExtractVariableData (DataTable, RawData, &ExportBuffer);\r
+          DataTable->IfrDataOffset = (UINT32) (((UINTN) ExportBuffer) - ((UINTN) DataTable));\r
+\r
+          if (DataTable->VariableDataOffset == DataTable->IfrDataOffset) {\r
+            DataTable->VariableDataOffset = 0;\r
+          }\r
+          //\r
+          // Start dumping the IFR data\r
+          //\r
+          CopyMem (ExportBuffer, &PackageInstance->IfrData, PackageInstance->IfrSize);\r
+          ExportBuffer                = (UINT8 *) (UINTN) (((UINTN) ExportBuffer) + PackageInstance->IfrSize);\r
+          DataTable->StringDataOffset = (UINT32) (((UINTN) ExportBuffer) - ((UINTN) DataTable));\r
+\r
+          //\r
+          // Start dumping the String data - NOTE:  It is in String Pack form\r
+          //\r
+          if (PackageInstance->StringSize > 0) {\r
+            RawData = (UINT8 *) (((UINTN) &PackageInstance->IfrData) + PackageInstance->IfrSize);\r
+            CopyMem (ExportBuffer, RawData, PackageInstance->StringSize);\r
+            DataTable->DataTableSize = (UINT32) (DataTable->StringDataOffset + PackageInstance->StringSize);\r
+\r
+            CopyMem (&TempValue, &((EFI_HII_STRING_PACK *) ExportBuffer)->Header.Length, sizeof (UINT32));\r
+            for (; TempValue != 0;) {\r
+              DataTable->NumberOfLanguages++;\r
+              ExportBuffer = ExportBuffer + ((EFI_HII_STRING_PACK *) ExportBuffer)->Header.Length;\r
+              CopyMem (&TempValue, &((EFI_HII_STRING_PACK *) ExportBuffer)->Header.Length, sizeof (UINT32));\r
+            }\r
+\r
+            ExportBuffer = ExportBuffer + sizeof (EFI_HII_STRING_PACK);\r
+          } else {\r
+            DataTable->StringDataOffset = 0;\r
+          }\r
+        } else {\r
+          //\r
+          // No IFR? No variable information.  If Offset is 0, means there is none.\r
+          //\r
+          DataTable->VariableDataOffset = 0;\r
+          DataTable->IfrDataOffset      = 0;\r
+          DataTable->StringDataOffset   = (UINT32) (((UINTN) ExportBuffer) - ((UINTN) DataTable));\r
+\r
+          //\r
+          // Start dumping the String data - Note:  It is in String Pack form\r
+          //\r
+          if (PackageInstance->StringSize > 0) {\r
+            RawData = (UINT8 *) (((UINTN) &PackageInstance->IfrData) + PackageInstance->IfrSize);\r
+            CopyMem (ExportBuffer, RawData, PackageInstance->StringSize);\r
+            DataTable->DataTableSize = (UINT32) (DataTable->StringDataOffset + PackageInstance->StringSize);\r
+\r
+            CopyMem (&TempValue, &((EFI_HII_STRING_PACK *) ExportBuffer)->Header.Length, sizeof (UINT32));\r
+            for (; TempValue != 0;) {\r
+              DataTable->NumberOfLanguages++;\r
+              ExportBuffer = ExportBuffer + ((EFI_HII_STRING_PACK *) ExportBuffer)->Header.Length;\r
+              CopyMem (&TempValue, &((EFI_HII_STRING_PACK *) ExportBuffer)->Header.Length, sizeof (UINT32));\r
+            }\r
+\r
+            ExportBuffer = ExportBuffer + sizeof (EFI_HII_STRING_PACK);\r
+          } else {\r
+            DataTable->StringDataOffset = 0;\r
+          }\r
+        }\r
+        break;\r
+      }\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiGetForms (\r
+  IN     EFI_HII_PROTOCOL   *This,\r
+  IN     EFI_HII_HANDLE     Handle,\r
+  IN     EFI_FORM_ID        FormId,\r
+  IN OUT UINTN              *BufferLengthTemp,\r
+  OUT    UINT8              *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  \r
+  This function allows a program to extract a form or form package that has \r
+  previously been registered with the EFI HII database.\r
+\r
+Arguments:\r
+  This         - A pointer to the EFI_HII_PROTOCOL instance.\r
+  \r
+  Handle       - Handle on which the form resides. Type EFI_HII_HANDLE is defined in \r
+                 EFI_HII_PROTOCOL.NewPack() in the Packages section.\r
+            \r
+  FormId       - The ID of the form to return. If the ID is zero, the entire form package is returned.\r
+                 Type EFI_FORM_ID is defined in "Related Definitions" below.\r
+            \r
+  BufferLength - On input, the length of the Buffer. On output, the length of the returned buffer, if\r
+                 the length was sufficient and, if it was not, the length that is required to fit the\r
+                 requested form(s).\r
+                  \r
+  Buffer       - The buffer designed to receive the form(s).\r
+\r
+Returns: \r
+\r
+  EFI_SUCCESS           -  Buffer filled with the requested forms. BufferLength\r
+                           was updated.\r
+                           \r
+  EFI_INVALID_PARAMETER -  The handle is unknown.\r
+  \r
+  EFI_NOT_FOUND         -  A form on the requested handle cannot be found with the\r
+                           requested FormId.\r
+                           \r
+  EFI_BUFFER_TOO_SMALL  - The buffer provided was not large enough to allow the form to be stored.\r
+\r
+--*/\r
+{\r
+  EFI_HII_PACKAGE_INSTANCE  *PackageInstance;\r
+  EFI_HII_DATA              *HiiData;\r
+  EFI_HII_HANDLE_DATABASE   *HandleDatabase;\r
+  EFI_HII_IFR_PACK          *FormPack;\r
+  EFI_IFR_FORM              *Form;\r
+  EFI_IFR_OP_HEADER         *Location;\r
+  UINT16                    *BufferLength = (UINT16 *) BufferLengthTemp;\r
+  UINTN                     FormLength;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  HiiData         = EFI_HII_DATA_FROM_THIS (This);\r
+\r
+  HandleDatabase  = HiiData->DatabaseHead;\r
+\r
+  PackageInstance = NULL;\r
+\r
+  FormLength      = 0;\r
+\r
+  //\r
+  // Check numeric value against the head of the database\r
+  //\r
+  for (; HandleDatabase != NULL; HandleDatabase = HandleDatabase->NextHandleDatabase) {\r
+    //\r
+    // Match the numeric value with the database entry - if matched, extract PackageInstance\r
+    //\r
+    if (Handle == HandleDatabase->Handle) {\r
+      PackageInstance = HandleDatabase->Buffer;\r
+      break;\r
+    }\r
+  }\r
+  //\r
+  // No handle was found - error condition\r
+  //\r
+  if (PackageInstance == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  //\r
+  // Based on if there is IFR data in this package instance, determine\r
+  // what the location is of the beginning of the string data.\r
+  //\r
+  if (PackageInstance->IfrSize > 0) {\r
+    FormPack = (EFI_HII_IFR_PACK *) (&PackageInstance->IfrData);\r
+  } else {\r
+    //\r
+    // If there is no IFR data return an error\r
+    //\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  //\r
+  // If requesting the entire Form Package\r
+  //\r
+  if (FormId == 0) {\r
+    //\r
+    // Return an error if buffer is too small\r
+    //\r
+    if (PackageInstance->IfrSize > *BufferLength || Buffer == NULL) {\r
+      *BufferLength = (UINT16) PackageInstance->IfrSize;\r
+      return EFI_BUFFER_TOO_SMALL;\r
+    }\r
+\r
+    CopyMem (Buffer, FormPack, PackageInstance->IfrSize);\r
+    return EFI_SUCCESS;\r
+  } else {\r
+    FormPack  = (EFI_HII_IFR_PACK *) ((CHAR8 *) (&PackageInstance->IfrData) + sizeof (EFI_HII_PACK_HEADER));\r
+    Location  = (EFI_IFR_OP_HEADER *) FormPack;\r
+\r
+    //\r
+    // Look for the FormId requested\r
+    //\r
+    for (; Location->OpCode != EFI_IFR_END_FORM_SET_OP;) {\r
+      switch (Location->OpCode) {\r
+      case EFI_IFR_FORM_OP:\r
+        Form = (EFI_IFR_FORM *) Location;\r
+\r
+        //\r
+        // If we found a Form Op-code and it is of the correct Id, copy it and return\r
+        //\r
+        if (Form->FormId == FormId) {\r
+          //\r
+          // Calculate the total size of form\r
+          //\r
+          for (FormLength = 0; Location->OpCode != EFI_IFR_END_FORM_OP; ) {\r
+            FormLength += Location->Length;\r
+            Location    = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (Location) + Location->Length);\r
+          }\r
+          FormLength += Location->Length;\r
+          Location    = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (Location) + Location->Length);\r
+\r
+          if ((Buffer == NULL) || (FormLength > *BufferLength)) {\r
+            *BufferLengthTemp = FormLength;\r
+            return EFI_BUFFER_TOO_SMALL;\r
+          }\r
+          \r
+          //\r
+          // Rewind to start offset of the found Form\r
+          //\r
+          Location   = (EFI_IFR_OP_HEADER *) ((CHAR8 *)Location - FormLength);\r
+          CopyMem (Buffer, Location, FormLength);\r
+          return EFI_SUCCESS;\r
+        }\r
+\r
+      default:\r
+        break;\r
+      }\r
+      //\r
+      // Go to the next Op-Code\r
+      //\r
+      Location = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (Location) + Location->Length);\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+//\r
+// Helper functions to HiiGetDefaultImage()\r
+//\r
+\r
+STATIC\r
+UINT8*\r
+HiiGetDefaultImageInitPack (\r
+  IN OUT EFI_HII_VARIABLE_PACK_LIST  *VariablePackItem,\r
+  IN     EFI_IFR_VARSTORE            *VarStore\r
+  )\r
+/*++\r
+    \r
+  Routine Description:\r
+\r
+    Initialize the EFI_HII_VARIABLE_PACK_LIST structure and\r
+    prepare it ready to be used by HiiGetDefaultImagePopulateMap ().\r
+      \r
+  Arguments:\r
+\r
+    VariablePackItem     - Variable Package List.\r
+    VarStore             - IFR variable storage.\r
+   \r
+  Returns: \r
+\r
+    Return the pointer to the Map space.\r
+      \r
+--*/\r
+{\r
+  CHAR16                *Name16;\r
+  CHAR8                 *Name8;\r
+  CHAR8                 *Map;\r
+  EFI_HII_VARIABLE_PACK *VariablePack;\r
+\r
+  //\r
+  // Set pointer the pack right after the node\r
+  //\r
+  VariablePackItem->VariablePack = (EFI_HII_VARIABLE_PACK *) (VariablePackItem + 1);\r
+  VariablePack                   = VariablePackItem->VariablePack;\r
+\r
+  //\r
+  // Copy the var name to VariablePackItem from VarStore\r
+  // Needs ASCII->Unicode conversion.\r
+  //\r
+  ASSERT (VarStore->Header.Length > sizeof (*VarStore));\r
+  Name8  = (CHAR8 *) (VarStore + 1);\r
+  Name16 = (CHAR16 *) (VariablePack + 1);\r
+  Ascii2Unicode (Name16, Name8);\r
+\r
+  //\r
+  // Compute the other fields of the VariablePackItem\r
+  //\r
+  VariablePack->VariableId         = VarStore->VarId;\r
+  CopyMem (&VariablePack->VariableGuid, &VarStore->Guid, sizeof (EFI_GUID));\r
+  VariablePack->VariableNameLength = (UINT32) ((StrLen (Name16) + 1) * 2);\r
+  VariablePack->Header.Length      = sizeof (*VariablePack) \r
+                                              + VariablePack->VariableNameLength\r
+                                              + VarStore->Size;\r
+  //\r
+  // Return the pointer to the Map space.\r
+  //\r
+  Map = (CHAR8 *) Name16 + VariablePack->VariableNameLength;\r
+\r
+  return (UINT8 *)Map;\r
+}\r
+\r
+STATIC\r
+VOID\r
+HiiGetDefaultImagePopulateMap (\r
+  IN OUT UINT8                        *Map,  \r
+  IN     EFI_IFR_OP_HEADER            *FormSet,\r
+  IN     EFI_IFR_VARSTORE             *VarStore,\r
+  IN     UINTN                        DefaultMask\r
+  )\r
+/*++\r
+    \r
+  Routine Description:\r
+\r
+   Fill the Map with all the default values either from NV or Hii database.\r
+      \r
+  Arguments:\r
+\r
+   Map         - Memory pointer to hold the default values.\r
+   FormSet     - The starting EFI_IFR_OP_HEADER to begin retriving default values.\r
+   VarStore    - IFR variable storage.\r
+   DefaultMask - The mask used to get the default variable.\r
+   \r
+  Returns: \r
+\r
+   VOID\r
+      \r
+--*/\r
+{\r
+  EFI_STATUS                     Status;\r
+  EFI_IFR_OP_HEADER              *IfrItem;\r
+  UINT16                         VarId;\r
+  EFI_IFR_VARSTORE_SELECT        *VarSelect;\r
+  EFI_IFR_ONE_OF_OPTION          *OneOfOpt;\r
+  EFI_IFR_CHECKBOX               *CheckBox;\r
+  EFI_IFR_NUMERIC                *Numeric;\r
+  UINTN                          Size;\r
+  UINTN                          SizeTmp;\r
+  EFI_IFR_NV_DATA                *IfrNvData;\r
+  EFI_GUID                       Guid;\r
+  CHAR16                         *Name16;\r
+  CHAR8                          *Name8;  \r
+  EFI_HANDLE                      CallbackHandle;\r
+  EFI_FORM_CALLBACK_PROTOCOL     *FormCallbackProt;\r
+\r
+  //\r
+  // Get the Map's Name/Guid/Szie from the Varstore.\r
+  // VARSTORE contains the Name in ASCII format (@#$^&!), must convert it to Unicode.\r
+  //\r
+  ASSERT (VarStore->Header.Length >= sizeof (*VarStore));\r
+  Name8  = (CHAR8 *) (VarStore + 1);\r
+  Name16 = AllocateZeroPool ((VarStore->Header.Length - sizeof (*VarStore)) * sizeof (CHAR16));\r
+  Ascii2Unicode (Name16, Name8);\r
+  CopyMem (&Guid, &VarStore->Guid, sizeof(EFI_GUID));\r
+  Size = VarStore->Size;\r
+\r
+  //\r
+  // First, check if the map exists in the NV. If so, get it from NV and exit.\r
+  //\r
+  if (DefaultMask == EFI_IFR_FLAG_MANUFACTURING) {\r
+    //\r
+    // Check if Manufaturing Defaults exist in the NV.\r
+    //\r
+    Status = EfiLibHiiVariableOverrideBySuffix (\r
+                  HII_VARIABLE_SUFFIX_MANUFACTURING_OVERRIDE,\r
+                  Name16,\r
+                  &Guid,\r
+                  Size,\r
+                  Map\r
+                  );\r
+  } else {\r
+    //\r
+    // All other cases default to Defaults. Check if Defaults exist in the NV.\r
+    //\r
+    Status = EfiLibHiiVariableOverrideBySuffix (\r
+                  HII_VARIABLE_SUFFIX_DEFAULT_OVERRIDE,\r
+                  Name16,\r
+                  &Guid,\r
+                  Size,\r
+                  Map\r
+                  );\r
+  }\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Either Defaults/Manufacturing variable exists and appears to be valid. \r
+    // The map is read, exit w/ success now.\r
+    //\r
+    FreePool (Name16);\r
+    return;\r
+  }\r
+\r
+  //\r
+  // First, prime the map with what already is in the NV.\r
+  // This is needed to cover a situation where the IFR does not contain all the \r
+  // defaults; either deliberately not having appropriate IFR, or in case of IFR_STRING, there is no default.\r
+  // Ignore status. Either it gets read or not. \r
+  //  \r
+  FormCallbackProt = NULL;\r
+  CopyMem (&CallbackHandle, &((EFI_IFR_FORM_SET*) FormSet)->CallbackHandle, sizeof (CallbackHandle));\r
+  if (CallbackHandle != NULL) {\r
+    Status = gBS->HandleProtocol (\r
+                    (EFI_HANDLE) (UINTN) CallbackHandle,\r
+                    &gEfiFormCallbackProtocolGuid,\r
+                    (VOID *) &FormCallbackProt\r
+                    );\r
+  }\r
+  if ((NULL != FormCallbackProt) && (NULL != FormCallbackProt->NvRead)) {\r
+    //\r
+    // Attempt to read using NvRead() callback. Probe first for existence and correct variable size.\r
+    //\r
+    SizeTmp = 0;\r
+    Status = FormCallbackProt->NvRead (\r
+                    FormCallbackProt,\r
+                    Name16,\r
+                    &Guid,\r
+                    0,\r
+                    &SizeTmp,\r
+                    NULL\r
+                    );\r
+    if ((EFI_BUFFER_TOO_SMALL == Status) && (SizeTmp == Size)) {\r
+      Status = FormCallbackProt->NvRead (\r
+                      FormCallbackProt,\r
+                      Name16,\r
+                      &Guid,\r
+                      0,\r
+                      &SizeTmp,\r
+                      Map\r
+                      );\r
+      ASSERT_EFI_ERROR (Status);\r
+      ASSERT (SizeTmp == Size);\r
+    }\r
+  } else {\r
+    //\r
+    // No callback available for this formset, read straight from NV. Deliberately ignore the Status. \r
+    // The buffer will only be written if variable exists nd has correct size.\r
+    //\r
+    Status = EfiLibHiiVariableRetrieveFromNv (\r
+                    Name16,\r
+                    &Guid,\r
+                    Size,\r
+                    (VOID **) &Map\r
+                    );\r
+  }\r
+\r
+  //\r
+  // Iterate all IFR statements and for applicable, retrieve the default into the Map.\r
+  //\r
+  for (IfrItem = FormSet, VarId = 0; \r
+       IfrItem->OpCode != EFI_IFR_END_FORM_SET_OP; \r
+       IfrItem = (EFI_IFR_OP_HEADER *) ((UINT8*) IfrItem + IfrItem->Length)\r
+      ) {\r
+\r
+    //\r
+    // Observe VarStore switch.\r
+    //\r
+    if (EFI_IFR_VARSTORE_SELECT_OP == IfrItem->OpCode) {\r
+      VarSelect = (EFI_IFR_VARSTORE_SELECT *) IfrItem;\r
+      VarId = VarSelect->VarId;\r
+      continue;\r
+    }\r
+\r
+\r
+    //\r
+    // Skip opcodes that reference other VarStore than that specific to current map.\r
+    // \r
+    if (VarId != VarStore->VarId) {\r
+      continue;\r
+    }\r
+    \r
+    //\r
+    // Extract the default value from this opcode if applicable, and apply it to the map.\r
+    //\r
+    IfrNvData = (EFI_IFR_NV_DATA *) IfrItem;\r
+    switch (IfrItem->OpCode) {\r
+\r
+      case EFI_IFR_ONE_OF_OP:\r
+        ASSERT (IfrNvData->QuestionId + IfrNvData->StorageWidth <= VarStore->Size);\r
+        //\r
+        // Get to the first EFI_IFR_ONE_OF_OPTION_OP\r
+        //\r
+        IfrItem = (EFI_IFR_OP_HEADER *) ((UINT8*) IfrItem + IfrItem->Length); \r
+        ASSERT (EFI_IFR_ONE_OF_OPTION_OP == IfrItem->OpCode);\r
+\r
+        OneOfOpt = (EFI_IFR_ONE_OF_OPTION *)IfrItem;\r
+        //\r
+        // In the worst case, the first will be the default.\r
+        //\r
+        CopyMem (Map + IfrNvData->QuestionId, &OneOfOpt->Value, IfrNvData->StorageWidth);\r
+\r
+        while (EFI_IFR_ONE_OF_OPTION_OP == IfrItem->OpCode) {\r
+\r
+          OneOfOpt = (EFI_IFR_ONE_OF_OPTION *)IfrItem;\r
+            if (DefaultMask == EFI_IFR_FLAG_MANUFACTURING) {\r
+              if (0 != (OneOfOpt->Flags & EFI_IFR_FLAG_MANUFACTURING)) {\r
+                //\r
+                // In the worst case, the first will be the default.\r
+                //\r
+                CopyMem (Map + IfrNvData->QuestionId, &OneOfOpt->Value, IfrNvData->StorageWidth);\r
+                break;\r
+              }\r
+            } else {\r
+              if (OneOfOpt->Flags & EFI_IFR_FLAG_DEFAULT) {\r
+                //\r
+                // In the worst case, the first will be the default.\r
+                //\r
+                CopyMem (Map + IfrNvData->QuestionId, &OneOfOpt->Value, IfrNvData->StorageWidth);\r
+                break;\r
+              }\r
+            }\r
+\r
+          IfrItem = (EFI_IFR_OP_HEADER *)((UINT8*)IfrItem + IfrItem->Length);\r
+        }\r
+        continue;\r
+        break;\r
+\r
+      case EFI_IFR_CHECKBOX_OP:\r
+        ASSERT (IfrNvData->QuestionId + IfrNvData->StorageWidth <= VarStore->Size);\r
+        CheckBox = (EFI_IFR_CHECK_BOX *)IfrItem;        \r
+        if (DefaultMask == EFI_IFR_FLAG_MANUFACTURING) {\r
+          if (0 != (CheckBox->Flags & EFI_IFR_FLAG_MANUFACTURING)) {\r
+            *(UINT8 *) (Map + IfrNvData->QuestionId) = TRUE;\r
+          }\r
+        } else {\r
+          if (CheckBox->Flags & EFI_IFR_FLAG_DEFAULT) {\r
+            *(UINT8 *) (Map + IfrNvData->QuestionId) = TRUE;\r
+          }\r
+        }\r
+        break;\r
+\r
+      case EFI_IFR_NUMERIC_OP:\r
+        ASSERT (IfrNvData->QuestionId + IfrNvData->StorageWidth <= VarStore->Size);\r
+        Numeric = (EFI_IFR_NUMERIC *) IfrItem;\r
+        CopyMem (Map + IfrNvData->QuestionId, &Numeric->Default, IfrNvData->StorageWidth);\r
+        break;\r
+\r
+      case EFI_IFR_ORDERED_LIST_OP:\r
+      case EFI_IFR_PASSWORD_OP:\r
+      case EFI_IFR_STRING_OP:\r
+        //\r
+        // No support for default value for these opcodes.\r
+        //\r
+      break;\r
+    }\r
+  }\r
+\r
+  FreePool (Name16);\r
+\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiGetDefaultImage (\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
+  Routine Description:\r
+\r
+  This function allows a program to extract the NV Image \r
+  that represents the default storage image\r
+      \r
+  Arguments:\r
+    This             - A pointer to the EFI_HII_PROTOCOL instance.\r
+    Handle           - The HII handle from which will have default data retrieved.\r
+    UINTN            - Mask used to retrieve the default image.\r
+    VariablePackList - Callee allocated, tightly-packed, link list data \r
+                         structure that contain all default varaible packs\r
+                         from the Hii Database.\r
+    \r
+  Returns: \r
+    EFI_NOT_FOUND         - If Hii database does not contain any default images.\r
+    EFI_INVALID_PARAMETER - Invalid input parameter.\r
+    EFI_SUCCESS           - Operation successful.\r
+      \r
+--*/\r
+{\r
+  EFI_HII_HANDLE_DATABASE        *HandleDatabase;\r
+  EFI_HII_PACKAGE_INSTANCE       *PackageInstance;\r
+  EFI_IFR_OP_HEADER              *FormSet;\r
+  EFI_IFR_OP_HEADER              *IfrItem;\r
+  EFI_IFR_VARSTORE               *VarStore;\r
+  EFI_IFR_VARSTORE               *VarStoreDefault;\r
+  UINTN                          SetupMapNameSize;\r
+  UINTN                          SizeOfMaps;\r
+  EFI_HII_VARIABLE_PACK_LIST     *PackList;\r
+  EFI_HII_VARIABLE_PACK_LIST     *PackListNext;  \r
+  EFI_HII_VARIABLE_PACK_LIST     *PackListLast;\r
+  UINT8                          *Map;\r
+\r
+\r
+  //\r
+  // Find the IFR pack from the handle. Then get the formset from the pack.\r
+  //\r
+  PackageInstance = NULL;\r
+  HandleDatabase  = (EFI_HII_DATA_FROM_THIS (This))->DatabaseHead;\r
+  for ( ; HandleDatabase != NULL; HandleDatabase = HandleDatabase->NextHandleDatabase) {\r
+    if (Handle == HandleDatabase->Handle) {\r
+      PackageInstance = HandleDatabase->Buffer;\r
+      break;\r
+    }\r
+  }\r
+  if (PackageInstance == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  FormSet = (EFI_IFR_OP_HEADER *) ((UINT8 *) &PackageInstance->IfrData + sizeof (EFI_HII_IFR_PACK));\r
+\r
+  //\r
+  // Get the sizes of all the VARSTOREs in this VFR.\r
+  // Then allocate enough space for all of them plus all maps\r
+  //\r
+  SizeOfMaps = 0;\r
+  IfrItem    = FormSet;\r
+  while (EFI_IFR_END_FORM_SET_OP != IfrItem->OpCode) {\r
+\r
+    if (EFI_IFR_VARSTORE_OP == IfrItem->OpCode) {\r
+      VarStore = (EFI_IFR_VARSTORE *) IfrItem;\r
+      //\r
+      // Size of the map\r
+      //\r
+      SizeOfMaps += VarStore->Size; \r
+      //\r
+      // add the size of the string, in Unicode\r
+      //\r
+      SizeOfMaps += (VarStore->Header.Length - sizeof (*VarStore)) * 2; \r
+      //\r
+      // Space for node\r
+      //\r
+      SizeOfMaps += sizeof (EFI_HII_VARIABLE_PACK);      \r
+      //\r
+      // Space for linked list node \r
+      //\r
+      SizeOfMaps += sizeof (EFI_HII_VARIABLE_PACK_LIST); \r
+    }\r
+\r
+    IfrItem = (EFI_IFR_OP_HEADER *) ((UINT8 *) IfrItem + IfrItem->Length);\r
+  }\r
+\r
+  //\r
+  // If the FormSet OpCode has a non-zero NvDataSize. There is a default \r
+  // NvMap with ID=0, GUID that of the formset itself and "Setup" as name.\r
+  //\r
+  SetupMapNameSize = StrLen (SETUP_MAP_NAME) + 1;\r
+  VarStoreDefault  = AllocateZeroPool (sizeof (*VarStoreDefault) + SetupMapNameSize);\r
+\r
+  if (0 != ((EFI_IFR_FORM_SET*)FormSet)->NvDataSize) {\r
+\r
+    VarStoreDefault->Header.OpCode = EFI_IFR_VARSTORE_OP;\r
+    VarStoreDefault->Header.Length = (UINT8) (sizeof (*VarStoreDefault) + SetupMapNameSize);\r
+    Unicode2Ascii ((CHAR8 *) (VarStoreDefault + 1), SETUP_MAP_NAME);\r
+    CopyMem (&VarStoreDefault->Guid, &((EFI_IFR_FORM_SET*) FormSet)->Guid, sizeof (EFI_GUID));\r
+    VarStoreDefault->VarId = 0;\r
+    VarStoreDefault->Size = ((EFI_IFR_FORM_SET*) FormSet)->NvDataSize;\r
+\r
+    //\r
+    // Size of the map\r
+    //\r
+    SizeOfMaps += VarStoreDefault->Size; \r
+    //\r
+    // add the size of the string\r
+    //\r
+    SizeOfMaps += sizeof (SETUP_MAP_NAME); \r
+    //\r
+    // Space for node\r
+    //\r
+    SizeOfMaps += sizeof (EFI_HII_VARIABLE_PACK);      \r
+    //\r
+    // Space for linked list node \r
+    //\r
+    SizeOfMaps += sizeof (EFI_HII_VARIABLE_PACK_LIST); \r
+  }\r
+\r
+  if (0 == SizeOfMaps) {\r
+    //\r
+    // The IFR does not have any explicit or default map(s).\r
+    //\r
+    return EFI_NOT_FOUND; \r
+  }\r
+\r
+  //\r
+  // Allocate the return buffer\r
+  //\r
+  PackList = AllocateZeroPool (SizeOfMaps);\r
+  ASSERT (NULL != PackList); \r
+\r
+  PackListNext = PackList;\r
+  PackListLast = PackList;\r
+\r
+  //\r
+  // Handle the default map first, if any.\r
+  //\r
+  if (0 != VarStoreDefault->Size) {\r
+\r
+    Map = HiiGetDefaultImageInitPack (PackListNext, VarStoreDefault);\r
+\r
+    HiiGetDefaultImagePopulateMap (Map, FormSet, VarStoreDefault, DefaultMask);\r
+\r
+    PackListNext->NextVariablePack = (EFI_HII_VARIABLE_PACK_LIST *) ((UINT8 *) PackListNext->VariablePack + PackListNext->VariablePack->Header.Length);\r
+    PackListLast = PackListNext;\r
+    PackListNext = PackListNext->NextVariablePack;\r
+  }\r
+\r
+\r
+  //\r
+  // Handle the explicit varstore(s)\r
+  //\r
+  IfrItem = FormSet;\r
+  while (EFI_IFR_END_FORM_SET_OP != IfrItem->OpCode) {\r
+\r
+    if (EFI_IFR_VARSTORE_OP == IfrItem->OpCode) {\r
+\r
+      Map = HiiGetDefaultImageInitPack (PackListNext, (EFI_IFR_VARSTORE *) IfrItem);\r
+\r
+      HiiGetDefaultImagePopulateMap (Map, FormSet, (EFI_IFR_VARSTORE *) IfrItem, DefaultMask);\r
+\r
+      PackListNext->NextVariablePack = (EFI_HII_VARIABLE_PACK_LIST *) ((UINT8 *) PackListNext->VariablePack + PackListNext->VariablePack->Header.Length);\r
+      PackListLast = PackListNext;\r
+      PackListNext = PackListNext->NextVariablePack;\r
+    }\r
+\r
+    IfrItem = (EFI_IFR_OP_HEADER *) ((UINT8 *) IfrItem + IfrItem->Length);\r
+  }\r
+\r
+  PackListLast->NextVariablePack = NULL;\r
+  *VariablePackList = PackList;\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiUpdateForm (\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
+Routine Description:\r
+  This function allows the caller to update a form that has \r
+  previously been registered with the EFI HII database.\r
+\r
+Arguments:\r
+  Handle     - Hii Handle associated with the Formset to modify\r
+  Label      - Update information starting immediately after this label in the IFR\r
+  AddData    - If TRUE, add data.  If FALSE, remove data\r
+  Data       - If adding data, this is the pointer to the data to add\r
+\r
+Returns: \r
+  EFI_SUCCESS - Update success.\r
+  Other       - Update fail.\r
+\r
+--*/\r
+{\r
+  EFI_HII_PACKAGE_INSTANCE  *PackageInstance;\r
+  EFI_HII_DATA              *HiiData;\r
+  EFI_HII_HANDLE_DATABASE   *HandleDatabase;\r
+  EFI_HII_IFR_PACK          *FormPack;\r
+  EFI_IFR_OP_HEADER         *Location;\r
+  EFI_IFR_OP_HEADER         *DataLocation;\r
+  UINT8                     *OtherBuffer;\r
+  UINT8                     *TempBuffer;\r
+  UINT8                     *OrigTempBuffer;\r
+  UINTN                     TempBufferSize;\r
+  UINTN                     Index;\r
+\r
+  OtherBuffer = NULL;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  HiiData         = EFI_HII_DATA_FROM_THIS (This);\r
+\r
+  HandleDatabase  = HiiData->DatabaseHead;\r
+\r
+  PackageInstance = NULL;\r
+\r
+  //\r
+  // Check numeric value against the head of the database\r
+  //\r
+  for (; HandleDatabase != NULL; HandleDatabase = HandleDatabase->NextHandleDatabase) {\r
+    //\r
+    // Match the numeric value with the database entry - if matched, extract PackageInstance\r
+    //\r
+    if (Handle == HandleDatabase->Handle) {\r
+      PackageInstance = HandleDatabase->Buffer;\r
+      break;\r
+    }\r
+  }\r
+  //\r
+  // No handle was found - error condition\r
+  //\r
+  if (PackageInstance == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Calculate and allocate space for retrieval of IFR data\r
+  //\r
+  DataLocation    = (EFI_IFR_OP_HEADER *) &Data->Data;\r
+  TempBufferSize  = (CHAR8 *) (&PackageInstance->IfrData) - (CHAR8 *) (PackageInstance);\r
+\r
+  for (Index = 0; Index < Data->DataCount; Index++) {\r
+    TempBufferSize += DataLocation->Length;\r
+    DataLocation = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (DataLocation) + DataLocation->Length);\r
+  }\r
+\r
+  TempBufferSize += PackageInstance->IfrSize + PackageInstance->StringSize;\r
+\r
+  TempBuffer      = AllocateZeroPool (TempBufferSize);\r
+  ASSERT (TempBuffer != NULL);\r
+\r
+  OrigTempBuffer  = TempBuffer;\r
+\r
+  //\r
+  // We update only packages with IFR information in it\r
+  //\r
+  if (PackageInstance->IfrSize == 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  CopyMem (\r
+    TempBuffer,\r
+    PackageInstance,\r
+    ((CHAR8 *) (&PackageInstance->IfrData) + sizeof (EFI_HII_PACK_HEADER) - (CHAR8 *) (PackageInstance))\r
+    );\r
+\r
+  TempBuffer = TempBuffer + ((CHAR8 *) (&PackageInstance->IfrData) + sizeof (EFI_HII_PACK_HEADER) - (CHAR8 *) (PackageInstance));\r
+\r
+  //\r
+  // Based on if there is IFR data in this package instance, determine\r
+  // what the location is of the beginning of the string data.\r
+  //\r
+  FormPack  = (EFI_HII_IFR_PACK *) ((CHAR8 *) (&PackageInstance->IfrData) + sizeof (EFI_HII_PACK_HEADER));\r
+  Location  = (EFI_IFR_OP_HEADER *) FormPack;\r
+\r
+  //\r
+  // Look for the FormId requested\r
+  //\r
+  for (; Location->OpCode != EFI_IFR_END_FORM_SET_OP;) {\r
+    switch (Location->OpCode) {\r
+    case EFI_IFR_FORM_SET_OP:\r
+      //\r
+      // If the FormSet has an update pending, pay attention.\r
+      //\r
+      if (Data->FormSetUpdate) {\r
+        ((EFI_IFR_FORM_SET *) Location)->CallbackHandle = Data->FormCallbackHandle;\r
+      }\r
+\r
+      CopyMem (TempBuffer, Location, Location->Length);\r
+      TempBuffer = TempBuffer + Location->Length;\r
+      break;\r
+\r
+    case EFI_IFR_FORM_OP:\r
+      //\r
+      // If the Form has an update pending, pay attention.\r
+      //\r
+      if (Data->FormUpdate) {\r
+        ((EFI_IFR_FORM *) Location)->FormTitle = Data->FormTitle;\r
+      }\r
+\r
+      CopyMem (TempBuffer, Location, Location->Length);\r
+      TempBuffer = TempBuffer + Location->Length;\r
+      break;\r
+\r
+    case EFI_IFR_LABEL_OP:\r
+      //\r
+      // If the label does not match the requested update point, ignore it\r
+      //\r
+      if (((EFI_IFR_LABEL *) Location)->LabelId != Label) {\r
+        //\r
+        // Copy the label\r
+        //\r
+        CopyMem (TempBuffer, Location, Location->Length);\r
+        TempBuffer = TempBuffer + Location->Length;\r
+\r
+        //\r
+        // Go to the next Op-Code\r
+        //\r
+        Location = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (Location) + Location->Length);\r
+        continue;\r
+      }\r
+\r
+      if (AddData) {\r
+        //\r
+        // Copy the label\r
+        //\r
+        CopyMem (TempBuffer, Location, Location->Length);\r
+        TempBuffer = TempBuffer + Location->Length;\r
+\r
+        //\r
+        // Add the DataCount amount of opcodes to TempBuffer\r
+        //\r
+        DataLocation = (EFI_IFR_OP_HEADER *) &Data->Data;\r
+        for (Index = 0; Index < Data->DataCount; Index++) {\r
+          CopyMem (TempBuffer, DataLocation, DataLocation->Length);\r
+          ((EFI_HII_PACKAGE_INSTANCE *) OrigTempBuffer)->IfrSize += DataLocation->Length;\r
+          OtherBuffer = ((UINT8 *) &((EFI_HII_PACKAGE_INSTANCE *) OrigTempBuffer)->StringSize + sizeof (UINTN));\r
+          CopyMem (OtherBuffer, &((EFI_HII_PACKAGE_INSTANCE *) OrigTempBuffer)->IfrSize, 2);\r
+          TempBuffer    = TempBuffer + DataLocation->Length;\r
+          DataLocation  = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (DataLocation) + DataLocation->Length);\r
+        }\r
+        //\r
+        // Go to the next Op-Code\r
+        //\r
+        Location = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (Location) + Location->Length);\r
+        continue;\r
+      } else {\r
+        //\r
+        // Copy the label\r
+        //\r
+        CopyMem (TempBuffer, Location, Location->Length);\r
+        TempBuffer  = TempBuffer + Location->Length;\r
+        Location    = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (Location) + Location->Length);\r
+\r
+        //\r
+        // Remove the DataCount amount of opcodes unless we run into an end of form or a label\r
+        //\r
+        for (Index = 0; Index < Data->DataCount; Index++) {\r
+          //\r
+          // If we are about to skip an end form - bail out, since that is illegal\r
+          //\r
+          if ((Location->OpCode == EFI_IFR_END_FORM_OP) || (Location->OpCode == EFI_IFR_LABEL_OP)) {\r
+            break;\r
+          }\r
+          //\r
+          // By skipping Location entries, we are in effect not copying what was previously there\r
+          //\r
+          ((EFI_HII_PACKAGE_INSTANCE *) OrigTempBuffer)->IfrSize -= Location->Length;\r
+          OtherBuffer = ((UINT8 *) &((EFI_HII_PACKAGE_INSTANCE *) OrigTempBuffer)->StringSize + sizeof (UINTN));\r
+          CopyMem (OtherBuffer, &((EFI_HII_PACKAGE_INSTANCE *) OrigTempBuffer)->IfrSize, 2);\r
+          Location = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (Location) + Location->Length);\r
+        }\r
+      }\r
+\r
+    default:\r
+      CopyMem (TempBuffer, Location, Location->Length);\r
+      TempBuffer = TempBuffer + Location->Length;\r
+      break;\r
+    }\r
+    //\r
+    // Go to the next Op-Code\r
+    //\r
+    Location = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (Location) + Location->Length);\r
+  }\r
+  //\r
+  // Copy the last op-code left behind from the for loop\r
+  //\r
+  CopyMem (TempBuffer, Location, Location->Length);\r
+\r
+  //\r
+  // Advance to beginning of strings and copy them\r
+  //\r
+  TempBuffer  = TempBuffer + Location->Length;\r
+  Location    = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (Location) + Location->Length);\r
+  CopyMem (TempBuffer, Location, PackageInstance->StringSize);\r
+\r
+  //\r
+  // Free the old buffer, and assign into our database the latest buffer\r
+  //\r
+  FreePool (HandleDatabase->Buffer);\r
+  HandleDatabase->Buffer = OrigTempBuffer;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/HiiDatabase.c b/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/HiiDatabase.c
new file mode 100644 (file)
index 0000000..cac37e5
--- /dev/null
@@ -0,0 +1,412 @@
+/*++\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
+  HiiDatabase.c\r
+\r
+Abstract:\r
+\r
+  This file contains the entry code to the HII database.\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "HiiDatabase.h"\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeHiiDatabase (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Initialize HII Database\r
+  \r
+Arguments:\r
+  (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r
+\r
+Returns: \r
+  EFI_SUCCESS - Setup loaded.\r
+  other       - Setup Error\r
+\r
+--*/\r
+{\r
+  EFI_STATUS          Status;\r
+  EFI_HII_DATA        *HiiData;\r
+  EFI_HII_GLOBAL_DATA *GlobalData;\r
+  EFI_HANDLE          *HandleBuffer;\r
+  EFI_HANDLE          Handle;\r
+  UINTN               HandleCount;\r
+  UINTN               Index;\r
+\r
+  //\r
+  // There will be only one HII Database in the system\r
+  // If there is another out there, someone is trying to install us\r
+  // again.  Fail that scenario.\r
+  //\r
+  Status = gBS->LocateHandleBuffer (\r
+                  ByProtocol,\r
+                  &gEfiHiiProtocolGuid,\r
+                  NULL,\r
+                  &HandleCount,\r
+                  &HandleBuffer\r
+                  );\r
+\r
+  //\r
+  // If there was no error, assume there is an installation and fail to load\r
+  //\r
+  if (!EFI_ERROR (Status)) {\r
+    if (HandleBuffer != NULL) {\r
+      FreePool (HandleBuffer);\r
+    }\r
+\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  HiiData = AllocatePool (sizeof (EFI_HII_DATA));\r
+\r
+  ASSERT (HiiData);\r
+\r
+  GlobalData = AllocateZeroPool (sizeof (EFI_HII_GLOBAL_DATA));\r
+\r
+  ASSERT (GlobalData);\r
+\r
+  //\r
+  // Seed the Font Database with a known non-character glyph\r
+  //\r
+  for (Index = 0; Index <= MAX_GLYPH_COUNT; Index++) {\r
+    //\r
+    // Seeding the UnicodeWeight with 0 signifies that it is uninitialized\r
+    //\r
+    GlobalData->NarrowGlyphs[Index].UnicodeWeight = 0;\r
+    GlobalData->WideGlyphs[Index].UnicodeWeight   = 0;\r
+    GlobalData->NarrowGlyphs[Index].Attributes    = 0;\r
+    GlobalData->WideGlyphs[Index].Attributes      = 0;\r
+    CopyMem (GlobalData->NarrowGlyphs[Index].GlyphCol1, &mUnknownGlyph, NARROW_GLYPH_ARRAY_SIZE);\r
+    CopyMem (GlobalData->WideGlyphs[Index].GlyphCol1, &mUnknownGlyph, WIDE_GLYPH_ARRAY_SIZE);\r
+  }\r
+  //\r
+  // Fill in HII data\r
+  //\r
+  HiiData->Signature                        = EFI_HII_DATA_SIGNATURE;\r
+  HiiData->GlobalData                       = GlobalData;\r
+  HiiData->GlobalData->SystemKeyboardUpdate = FALSE;\r
+  HiiData->DatabaseHead                     = NULL;\r
+  HiiData->Hii.NewPack                      = HiiNewPack;\r
+  HiiData->Hii.RemovePack                   = HiiRemovePack;\r
+  HiiData->Hii.FindHandles                  = HiiFindHandles;\r
+  HiiData->Hii.ExportDatabase               = HiiExportDatabase;\r
+  HiiData->Hii.GetGlyph                     = HiiGetGlyph;\r
+  HiiData->Hii.GetPrimaryLanguages          = HiiGetPrimaryLanguages;\r
+  HiiData->Hii.GetSecondaryLanguages        = HiiGetSecondaryLanguages;\r
+  HiiData->Hii.NewString                    = HiiNewString;\r
+  HiiData->Hii.GetString                    = HiiGetString;\r
+  HiiData->Hii.ResetStrings                 = HiiResetStrings;\r
+  HiiData->Hii.TestString                   = HiiTestString;\r
+  HiiData->Hii.GetLine                      = HiiGetLine;\r
+  HiiData->Hii.GetForms                     = HiiGetForms;\r
+  HiiData->Hii.GetDefaultImage              = HiiGetDefaultImage;\r
+  HiiData->Hii.UpdateForm                   = HiiUpdateForm;\r
+  HiiData->Hii.GetKeyboardLayout            = HiiGetKeyboardLayout;\r
+  HiiData->Hii.GlyphToBlt                   = HiiGlyphToBlt;\r
+\r
+  //\r
+  // Install protocol interface\r
+  //\r
+  Handle = NULL;\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &Handle,\r
+                  &gEfiHiiProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &HiiData->Hii\r
+                  );\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiFindHandles (\r
+  IN     EFI_HII_PROTOCOL *This,\r
+  IN OUT UINT16           *HandleBufferLength,\r
+  OUT    EFI_HII_HANDLE   Handle[1]\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Determines the handles that are currently active in the database.\r
+  \r
+Arguments:\r
+\r
+Returns: \r
+\r
+--*/\r
+{\r
+  EFI_HII_HANDLE_DATABASE *Database;\r
+  EFI_HII_DATA            *HiiData;\r
+  UINTN                   HandleCount;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  HiiData     = EFI_HII_DATA_FROM_THIS (This);\r
+\r
+  Database    = HiiData->DatabaseHead;\r
+\r
+  if (Database == NULL) {\r
+    *HandleBufferLength = 0;\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  for (HandleCount = 0; Database != NULL; HandleCount++) {\r
+    Database = Database->NextHandleDatabase;\r
+  }\r
+  //\r
+  // Is there a sufficient buffer for the data being passed back?\r
+  //\r
+  if (*HandleBufferLength >= (sizeof (EFI_HII_HANDLE) * HandleCount)) {\r
+    Database = HiiData->DatabaseHead;\r
+\r
+    //\r
+    // Copy the Head information\r
+    //\r
+    if (Database->Handle != 0) {\r
+      CopyMem (&Handle[0], &Database->Handle, sizeof (EFI_HII_HANDLE));\r
+      Database = Database->NextHandleDatabase;\r
+    }\r
+    //\r
+    // Copy more data if appropriate\r
+    //\r
+    for (HandleCount = 1; Database != NULL; HandleCount++) {\r
+      CopyMem (&Handle[HandleCount], &Database->Handle, sizeof (EFI_HII_HANDLE));\r
+      Database = Database->NextHandleDatabase;\r
+    }\r
+\r
+    *HandleBufferLength = (UINT16) (sizeof (EFI_HII_HANDLE) * HandleCount);\r
+    return EFI_SUCCESS;\r
+  } else {\r
+    //\r
+    // Insufficient buffer length\r
+    //\r
+    *HandleBufferLength = (UINT16) (sizeof (EFI_HII_HANDLE) * HandleCount);\r
+    return EFI_BUFFER_TOO_SMALL;\r
+  }\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiGetPrimaryLanguages (\r
+  IN  EFI_HII_PROTOCOL      *This,\r
+  IN  EFI_HII_HANDLE        Handle,\r
+  OUT EFI_STRING            *LanguageString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  \r
+  This function allows a program to determine what the primary languages that are supported on a given handle.\r
+\r
+Arguments:\r
+\r
+Returns: \r
+\r
+--*/\r
+{\r
+  UINTN                     Count;\r
+  EFI_HII_PACKAGE_INSTANCE  *PackageInstance;\r
+  EFI_HII_PACKAGE_INSTANCE  *StringPackageInstance;\r
+  EFI_HII_DATA              *HiiData;\r
+  EFI_HII_HANDLE_DATABASE   *HandleDatabase;\r
+  EFI_HII_STRING_PACK       *StringPack;\r
+  EFI_HII_STRING_PACK       *Location;\r
+  UINT32                    Length;\r
+  RELOFST                   Token;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  HiiData         = EFI_HII_DATA_FROM_THIS (This);\r
+\r
+  PackageInstance = NULL;\r
+  //\r
+  // Find matching handle in the handle database. Then get the package instance.\r
+  //\r
+  for (HandleDatabase = HiiData->DatabaseHead;\r
+       HandleDatabase != NULL;\r
+       HandleDatabase = HandleDatabase->NextHandleDatabase\r
+      ) {\r
+    if (Handle == HandleDatabase->Handle) {\r
+      PackageInstance = HandleDatabase->Buffer;\r
+    }\r
+  }\r
+  //\r
+  // No handle was found - error condition\r
+  //\r
+  if (PackageInstance == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  ValidatePack (This, PackageInstance, &StringPackageInstance, NULL);\r
+\r
+  //\r
+  // Based on if there is IFR data in this package instance, determine\r
+  // what the location is of the beginning of the string data.\r
+  //\r
+  if (StringPackageInstance->IfrSize > 0) {\r
+    StringPack = (EFI_HII_STRING_PACK *) ((CHAR8 *) (&StringPackageInstance->IfrData) + StringPackageInstance->IfrSize);\r
+  } else {\r
+    StringPack = (EFI_HII_STRING_PACK *) (&StringPackageInstance->IfrData);\r
+  }\r
+\r
+  Location = StringPack;\r
+  //\r
+  // Remember that the string packages are formed into contiguous blocks of language data.\r
+  //\r
+  CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));\r
+  for (Count = 0; Length != 0; Count = Count + 3) {\r
+    StringPack = (EFI_HII_STRING_PACK *) ((CHAR8 *) (StringPack) + Length);\r
+    CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));\r
+  }\r
+\r
+  *LanguageString = AllocateZeroPool (2 * (Count + 1));\r
+\r
+  ASSERT (*LanguageString);\r
+\r
+  StringPack = (EFI_HII_STRING_PACK *) Location;\r
+\r
+  //\r
+  // Copy the 6 bytes to LanguageString - keep concatenating it.  Shouldn't we just store uint8's since the ISO\r
+  // standard defines the lettering as all US English characters anyway?  Save a few bytes.\r
+  //\r
+  CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));\r
+  for (Count = 0; Length != 0; Count = Count + 3) {\r
+    CopyMem (&Token, &StringPack->LanguageNameString, sizeof (RELOFST));\r
+    CopyMem (*LanguageString + Count, (VOID *) ((CHAR8 *) (StringPack) + Token), 6);\r
+    StringPack = (EFI_HII_STRING_PACK *) ((CHAR8 *) (StringPack) + Length);\r
+    CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiGetSecondaryLanguages (\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
+Routine Description:\r
+  \r
+  This function allows a program to determine which secondary languages are supported \r
+  on a given handle for a given primary language.\r
+\r
+  Arguments:\r
+\r
+Returns: \r
+\r
+--*/\r
+{\r
+  UINTN                     Count;\r
+  EFI_HII_PACKAGE_INSTANCE  *PackageInstance;\r
+  EFI_HII_PACKAGE_INSTANCE  *StringPackageInstance;\r
+  EFI_HII_DATA              *HiiData;\r
+  EFI_HII_HANDLE_DATABASE   *HandleDatabase;\r
+  EFI_HII_STRING_PACK       *StringPack;\r
+  RELOFST                   Token;\r
+  UINT32                    Length;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  HiiData = EFI_HII_DATA_FROM_THIS (This);\r
+  //\r
+  // Check numeric value against the head of the database\r
+  //\r
+  PackageInstance = NULL;\r
+  for (HandleDatabase = HiiData->DatabaseHead;\r
+       HandleDatabase != NULL;\r
+       HandleDatabase = HandleDatabase->NextHandleDatabase\r
+      ) {\r
+    //\r
+    // Match the numeric value with the database entry - if matched, extract PackageInstance\r
+    //\r
+    if (Handle == HandleDatabase->Handle) {\r
+      PackageInstance = HandleDatabase->Buffer;\r
+    }\r
+  }\r
+  //\r
+  // No handle was found - error condition\r
+  //\r
+  if (PackageInstance == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  ValidatePack (This, PackageInstance, &StringPackageInstance, NULL);\r
+\r
+  //\r
+  // Based on if there is IFR data in this package instance, determine\r
+  // what the location is of the beginning of the string data.\r
+  //\r
+  if (StringPackageInstance->IfrSize > 0) {\r
+    StringPack = (EFI_HII_STRING_PACK *) ((CHAR8 *) (&StringPackageInstance->IfrData) + StringPackageInstance->IfrSize);\r
+  } else {\r
+    StringPack = (EFI_HII_STRING_PACK *) (&StringPackageInstance->IfrData);\r
+  }\r
+\r
+  //\r
+  // Remember that the string packages are formed into contiguous blocks of language data.\r
+  //\r
+  for (; StringPack->Header.Length != 0;) {\r
+    //\r
+    // Find the PrimaryLanguage being requested\r
+    //\r
+    Token = StringPack->LanguageNameString;\r
+    if (CompareMem ((VOID *) ((CHAR8 *) (StringPack) + Token), PrimaryLanguage, 3) == 0) {\r
+      //\r
+      // Now that we found the primary, the secondary languages will follow immediately\r
+      // or the next character is a NULL if there are no secondary languages.  We determine\r
+      // the number by getting the stringsize based on the StringPack origination + the LanguageNameString\r
+      // offset + 6 (which is the size of the first 3 letter ISO primary language name).  If we get 2, there\r
+      // are no secondary languages (2 = null-terminator).\r
+      //\r
+      Count           = StrSize ((VOID *) ((CHAR8 *) (StringPack) + Token + 6));\r
+\r
+      *LanguageString = AllocateZeroPool (2 * (Count + 1));\r
+\r
+      ASSERT (*LanguageString);\r
+\r
+      CopyMem (*LanguageString, (VOID *) ((CHAR8 *) (StringPack) + Token + 6), Count);\r
+      break;\r
+    }\r
+\r
+    CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));\r
+    StringPack = (EFI_HII_STRING_PACK *) ((CHAR8 *) (StringPack) + Length);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
diff --git a/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/HiiDatabase.dxs b/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/HiiDatabase.dxs
new file mode 100644 (file)
index 0000000..3e1fa13
--- /dev/null
@@ -0,0 +1,30 @@
+/*++\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
+  HiiDatabase.dxs\r
+\r
+Abstract:\r
+\r
+  Dependency expression source file.\r
+  \r
+--*/\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include <DxeDepex.h>\r
+\r
+DEPENDENCY_START\r
+  TRUE\r
+DEPENDENCY_END\r
diff --git a/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/HiiDatabase.h b/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/HiiDatabase.h
new file mode 100644 (file)
index 0000000..adfc31c
--- /dev/null
@@ -0,0 +1,307 @@
+/*++\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
+  HiiDatabase.h\r
+\r
+Abstract:\r
+\r
+  This file contains global defines and prototype definitions \r
+  for the HII database.\r
+\r
+--*/\r
+\r
+#ifndef _HIIDATABASE_H\r
+#define _HIIDATABASE_H\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+//\r
+// HII Database Global data\r
+//\r
+#define EFI_HII_DATA_SIGNATURE            EFI_SIGNATURE_32 ('H', 'i', 'i', 'P')\r
+\r
+#define MAX_GLYPH_COUNT                   65535\r
+#define NARROW_GLYPH_ARRAY_SIZE           19\r
+#define WIDE_GLYPH_ARRAY_SIZE             38\r
+\r
+#define SETUP_MAP_NAME                              L"Setup"\r
+#define HII_VARIABLE_SUFFIX_USER_DATA               L"UserSavedData"\r
+#define HII_VARIABLE_SUFFIX_DEFAULT_OVERRIDE        L"DefaultOverride"\r
+#define HII_VARIABLE_SUFFIX_MANUFACTURING_OVERRIDE  L"ManufacturingOverride"\r
+\r
+typedef struct _EFI_HII_HANDLE_DATABASE {\r
+  VOID                            *Buffer;        // Actual buffer pointer\r
+  EFI_HII_HANDLE                  Handle;         // Monotonically increasing value to signify the value returned to caller\r
+  UINT32                          NumberOfTokens; // The initial number of tokens when first registered\r
+  struct _EFI_HII_HANDLE_DATABASE *NextHandleDatabase;\r
+} EFI_HII_HANDLE_DATABASE;\r
+\r
+typedef struct {\r
+  EFI_NARROW_GLYPH    NarrowGlyphs[MAX_GLYPH_COUNT];\r
+  EFI_WIDE_GLYPH      WideGlyphs[MAX_GLYPH_COUNT];\r
+  EFI_KEY_DESCRIPTOR  SystemKeyboardLayout[106];\r
+  EFI_KEY_DESCRIPTOR  OverrideKeyboardLayout[106];\r
+  BOOLEAN             SystemKeyboardUpdate;       // Has the SystemKeyboard been updated?\r
+} EFI_HII_GLOBAL_DATA;\r
+\r
+typedef struct {\r
+  UINTN                   Signature;\r
+\r
+  EFI_HII_GLOBAL_DATA     *GlobalData;\r
+  EFI_HII_HANDLE_DATABASE *DatabaseHead;          // Head of the Null-terminated singly-linked list of handles.\r
+  EFI_HII_PROTOCOL        Hii;\r
+} EFI_HII_DATA;\r
+\r
+typedef struct {\r
+  EFI_HII_HANDLE      Handle;\r
+  EFI_GUID            Guid;\r
+  EFI_HII_HANDLE_PACK HandlePack;\r
+  UINTN               IfrSize;\r
+  UINTN               StringSize;\r
+  EFI_HII_IFR_PACK    *IfrData;                   // All the IFR data stored here\r
+  EFI_HII_STRING_PACK *StringData;                // All the String data stored at &IfrData + IfrSize (StringData is just a label - never referenced)\r
+} EFI_HII_PACKAGE_INSTANCE;\r
+\r
+typedef struct {\r
+  EFI_HII_PACK_HEADER   Header;\r
+  EFI_IFR_FORM_SET      FormSet;\r
+  EFI_IFR_END_FORM_SET  EndFormSet;\r
+} EFI_FORM_SET_STUB;\r
+\r
+#define EFI_HII_DATA_FROM_THIS(a) CR (a, EFI_HII_DATA, Hii, EFI_HII_DATA_SIGNATURE)\r
+\r
+#define NARROW_WIDTH              8\r
+#define WIDE_WIDTH                16\r
+\r
+extern UINT8  mUnknownGlyph[38];\r
+\r
+//\r
+// Prototypes\r
+//\r
+EFI_STATUS\r
+GetPackSize (\r
+  IN  VOID                *Pack,\r
+  OUT UINTN               *PackSize,\r
+  OUT UINT32              *NumberOfTokens\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+ValidatePack (\r
+  IN   EFI_HII_PROTOCOL          *This,\r
+  IN   EFI_HII_PACKAGE_INSTANCE  *PackageInstance,\r
+  OUT  EFI_HII_PACKAGE_INSTANCE  **StringPackageInstance,\r
+  OUT  UINT32                    *TotalStringCount\r
+  )\r
+;\r
+\r
+//\r
+// Public Interface Prototypes\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeHiiDatabase (\r
+  IN EFI_HANDLE             ImageHandle,\r
+  IN EFI_SYSTEM_TABLE       *SystemTable\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiNewPack (\r
+  IN  EFI_HII_PROTOCOL      *This,\r
+  IN  EFI_HII_PACKAGES      *PackageList,\r
+  OUT EFI_HII_HANDLE        *Handle\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiRemovePack (\r
+  IN EFI_HII_PROTOCOL    *This,\r
+  IN EFI_HII_HANDLE      Handle\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiFindHandles (\r
+  IN     EFI_HII_PROTOCOL    *This,\r
+  IN OUT UINT16              *HandleBufferLength,\r
+  OUT    EFI_HII_HANDLE      *Handle\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiExportDatabase (\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
+EFI_STATUS\r
+EFIAPI\r
+HiiGetGlyph (\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
+EFI_STATUS\r
+EFIAPI\r
+HiiGlyphToBlt (\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
+EFI_STATUS\r
+EFIAPI\r
+HiiNewString (\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
+EFI_STATUS\r
+EFIAPI\r
+HiiGetString (\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
+EFI_STATUS\r
+EFIAPI\r
+HiiResetStrings (\r
+  IN     EFI_HII_PROTOCOL    *This,\r
+  IN     EFI_HII_HANDLE      Handle\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiTestString (\r
+  IN     EFI_HII_PROTOCOL    *This,\r
+  IN     CHAR16              *StringToTest,\r
+  IN OUT UINT32              *FirstMissing,\r
+  OUT    UINT32              *GlyphBufferSize\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiGetPrimaryLanguages (\r
+  IN  EFI_HII_PROTOCOL      *This,\r
+  IN  EFI_HII_HANDLE        Handle,\r
+  OUT EFI_STRING            *LanguageString\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiGetSecondaryLanguages (\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
+EFI_STATUS\r
+EFIAPI\r
+HiiGetLine (\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
+EFI_STATUS\r
+EFIAPI\r
+HiiGetForms (\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
+EFI_STATUS\r
+EFIAPI\r
+HiiGetDefaultImage (\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
+EFI_STATUS\r
+EFIAPI\r
+HiiUpdateForm (\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
+EFI_STATUS\r
+EFIAPI\r
+HiiGetKeyboardLayout (\r
+  IN     EFI_HII_PROTOCOL    *This,\r
+  OUT    UINT16              *DescriptorCount,\r
+  OUT    EFI_KEY_DESCRIPTOR  *Descriptor\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+HiiCompareLanguage (\r
+  IN  CHAR16                *LanguageStringLocation,\r
+  IN  CHAR16                *Language\r
+  )\r
+;\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/HiiDatabase.inf b/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/HiiDatabase.inf
new file mode 100644 (file)
index 0000000..216a47a
--- /dev/null
@@ -0,0 +1,116 @@
+#/** @file\r
+# Component description file for HiiDatabase module.\r
+#\r
+# This module inits HII database and installs HII protocol.\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                      = HiiDatabase\r
+  FILE_GUID                      = FCD337AB-B1D3-4EF8-957C-8048606FF670\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeHiiDatabase\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
+  HiiDatabase.dxs\r
+  Keyboard.c\r
+  Fonts.c\r
+  Package.c\r
+  Strings.c\r
+  Forms.c\r
+  HiiDatabase.h\r
+  HiiDatabase.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg/Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  IfrSupportLibFramework\r
+  UefiRuntimeServicesTableLib\r
+  UefiBootServicesTableLib\r
+  BaseMemoryLib\r
+  MemoryAllocationLib\r
+  UefiDriverEntryPoint\r
+  DebugLib\r
+  BaseLib\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"Lang"\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
+  gEfiFormCallbackProtocolGuid                  # PROTOCOL SOMETIMES_CONSUMED\r
+  gEfiHiiProtocolGuid                           # PROTOCOL ALWAYS_PRODUCED\r
+\r
diff --git a/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/HiiDatabase.msa b/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/HiiDatabase.msa
new file mode 100644 (file)
index 0000000..f91338d
--- /dev/null
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>HiiDatabase</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>FCD337AB-B1D3-4EF8-957C-8048606FF670</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for HiiDatabase module.</Abstract>\r
+    <Description>This module inits HII database and installs HII protocol.</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>HiiDatabase</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED" RecommendedInstanceGuid="bda39d3a-451b-4350-8266-81ab10fa0523">\r
+      <Keyword>DebugLib</Keyword>\r
+      <HelpText>Recommended libary Instance is PeiDxeDebugLibReportStatusCode instance in MdePkg.</HelpText>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiRuntimeServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>EdkIfrSupportLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>HiiDatabase.c</Filename>\r
+    <Filename>HiiDatabase.h</Filename>\r
+    <Filename>Forms.c</Filename>\r
+    <Filename>Strings.c</Filename>\r
+    <Filename>Package.c</Filename>\r
+    <Filename>Fonts.c</Filename>\r
+    <Filename>Keyboard.c</Filename>\r
+    <Filename>HiiDatabase.dxs</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="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiHiiProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="SOMETIMES_CONSUMED">\r
+      <ProtocolCName>gEfiFormCallbackProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Variables>\r
+    <Variable Usage="SOMETIMES_CONSUMED">\r
+      <VariableName>0x004C 0x0061 0x006E 0x0067</VariableName>\r
+      <GuidC_Name>gEfiGlobalVariableGuid</GuidC_Name>\r
+      <HelpText>L"Lang" global variable is used as system default language.</HelpText>\r
+    </Variable>\r
+  </Variables>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>InitializeHiiDatabase</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/Keyboard.c b/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/Keyboard.c
new file mode 100644 (file)
index 0000000..be91d40
--- /dev/null
@@ -0,0 +1,48 @@
+/*++\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
+  Keyboard.c\r
+\r
+Abstract:\r
+\r
+  This file contains the keyboard processing code to the HII database.\r
+\r
+--*/\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "HiiDatabase.h"\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiGetKeyboardLayout (\r
+  IN     EFI_HII_PROTOCOL   *This,\r
+  OUT    UINT16             *DescriptorCount,\r
+  OUT    EFI_KEY_DESCRIPTOR *Descriptor\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  \r
+Arguments:\r
+\r
+Returns: \r
+\r
+--*/\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/Package.c b/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/Package.c
new file mode 100644 (file)
index 0000000..91f5a3a
--- /dev/null
@@ -0,0 +1,678 @@
+/*++\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
+  Package.c\r
+\r
+Abstract:\r
+\r
+  This file contains the package processing code to the HII database.\r
+\r
+--*/\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "HiiDatabase.h"\r
+\r
+EFI_STATUS\r
+GetPackSize (\r
+  IN  VOID                *Pack,\r
+  OUT UINTN               *PackSize,\r
+  OUT UINT32              *NumberOfTokens\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Determines the passed in Pack's size and returns the value.\r
+  \r
+Arguments:\r
+\r
+Returns: \r
+\r
+--*/\r
+{\r
+  EFI_HII_STRING_PACK *StringPack;\r
+  UINT16              Type;\r
+  UINT32              Length;\r
+\r
+  *PackSize = 0;\r
+\r
+  Type      = EFI_HII_IFR;\r
+  if (!CompareMem (&((EFI_HII_PACK_HEADER *) Pack)->Type, &Type, sizeof (UINT16))) {\r
+    //\r
+    // The header contains the full IFR length\r
+    //\r
+    CopyMem (&Length, &((EFI_HII_PACK_HEADER *) Pack)->Length, sizeof (Length));\r
+    *PackSize = (UINTN) Length;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  Type = EFI_HII_STRING;\r
+  if (!CompareMem (&((EFI_HII_PACK_HEADER *) Pack)->Type, &Type, sizeof (UINT16))) {\r
+    //\r
+    // The header contains the STRING package length\r
+    // The assumption is that the strings for all languages\r
+    // are a contiguous block of data and there is a series of\r
+    // these package instances which will terminate with a NULL package\r
+    // instance.\r
+    //\r
+    StringPack = (EFI_HII_STRING_PACK *) Pack;\r
+\r
+    //\r
+    // There may be multiple instances packed together of strings\r
+    // so we must walk the self describing structures until we encounter\r
+    // the NULL structure to determine the full size.\r
+    //\r
+    CopyMem (&Length, &StringPack->Header.Length, sizeof (Length));\r
+    if (NumberOfTokens != NULL) {\r
+      CopyMem (NumberOfTokens, &StringPack->NumStringPointers, sizeof (UINT32));\r
+    }\r
+\r
+    while (Length != 0) {\r
+      *PackSize   = *PackSize + Length;\r
+      StringPack  = (EFI_HII_STRING_PACK *) ((CHAR8 *) StringPack + Length);\r
+      CopyMem (&Length, &StringPack->Header.Length, sizeof (Length));\r
+    }\r
+    //\r
+    // Encountered a length of 0, so let's add the space for the NULL terminator\r
+    // pack's length and call it done.\r
+    //\r
+    *PackSize = *PackSize + sizeof (EFI_HII_STRING_PACK);\r
+    return EFI_SUCCESS;\r
+  }\r
+  //\r
+  // We only determine the size of the non-global Package types.\r
+  // If neither IFR or STRING data were found, return an error\r
+  //\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+EFI_STATUS\r
+ValidatePack (\r
+  IN   EFI_HII_PROTOCOL          *This,\r
+  IN   EFI_HII_PACKAGE_INSTANCE  *PackageInstance,\r
+  OUT  EFI_HII_PACKAGE_INSTANCE  **StringPackageInstance,\r
+  OUT  UINT32                    *TotalStringCount\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Verifies that the package instance is using the correct handle for string operations.\r
+  \r
+Arguments:\r
+\r
+Returns: \r
+\r
+--*/\r
+{\r
+  EFI_HII_DATA              *HiiData;\r
+  EFI_HII_HANDLE_DATABASE   *HandleDatabase;\r
+  EFI_HII_PACKAGE_INSTANCE  *HandlePackageInstance;\r
+  UINT8                     *RawData;\r
+  EFI_GUID                  Guid;\r
+  EFI_HII_IFR_PACK          *FormPack;\r
+  UINTN                     Index;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  HiiData         = EFI_HII_DATA_FROM_THIS (This);\r
+\r
+  HandleDatabase  = HiiData->DatabaseHead;\r
+  ZeroMem (&Guid, sizeof (EFI_GUID));\r
+\r
+  *StringPackageInstance = PackageInstance;\r
+\r
+  //\r
+  // Based on if there is IFR data in this package instance, determine\r
+  // what the location is of the beginning of the string data.\r
+  //\r
+  if (PackageInstance->IfrSize > 0) {\r
+    FormPack = (EFI_HII_IFR_PACK *) ((CHAR8 *) (&PackageInstance->IfrData) + sizeof (EFI_HII_PACK_HEADER));\r
+  } else {\r
+    //\r
+    // If there is no IFR data assume the caller knows what they are doing.\r
+    //\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  RawData = (UINT8 *) FormPack;\r
+\r
+  for (Index = 0; RawData[Index] != EFI_IFR_END_FORM_SET_OP;) {\r
+    if (RawData[Index] == EFI_IFR_FORM_SET_OP) {\r
+      //\r
+      // Cache the guid for this formset\r
+      //\r
+      CopyMem (&Guid, &((EFI_IFR_FORM_SET *) &RawData[Index])->Guid, sizeof (EFI_GUID));\r
+      break;\r
+    }\r
+\r
+    Index = RawData[Index + 1] + Index;\r
+  }\r
+  //\r
+  // If there is no string package, and the PackageInstance->IfrPack.Guid and PackageInstance->Guid are\r
+  // different, we should return the correct handle for the caller to use for strings.\r
+  //\r
+  if ((PackageInstance->StringSize == 0) && (!CompareGuid (&Guid, &PackageInstance->Guid))) {\r
+    //\r
+    // Search the database for a handle that matches the PackageInstance->Guid\r
+    //\r
+    for (; HandleDatabase != NULL; HandleDatabase = HandleDatabase->NextHandleDatabase) {\r
+      //\r
+      // Get Ifrdata and extract the Guid for it\r
+      //\r
+      HandlePackageInstance = HandleDatabase->Buffer;\r
+\r
+      ASSERT (HandlePackageInstance->IfrSize != 0);\r
+\r
+      FormPack  = (EFI_HII_IFR_PACK *) ((CHAR8 *) (&HandlePackageInstance->IfrData) + sizeof (EFI_HII_PACK_HEADER));\r
+      RawData   = (UINT8 *) FormPack;\r
+\r
+      for (Index = 0; RawData[Index] != EFI_IFR_END_FORM_SET_OP;) {\r
+        if (RawData[Index] == EFI_IFR_FORM_SET_OP) {\r
+          //\r
+          // Cache the guid for this formset\r
+          //\r
+          CopyMem (&Guid, &((EFI_IFR_FORM_SET *) &RawData[Index])->Guid, sizeof (EFI_GUID));\r
+          break;\r
+        }\r
+\r
+        Index = RawData[Index + 1] + Index;\r
+      }\r
+      //\r
+      // If the Guid from the new handle matches the original Guid referenced in the original package data\r
+      // return the appropriate package instance data to use.\r
+      //\r
+      if (CompareGuid (&Guid, &PackageInstance->Guid)) {\r
+        if (TotalStringCount != NULL) {\r
+          *TotalStringCount = HandleDatabase->NumberOfTokens;\r
+        }\r
+\r
+        *StringPackageInstance = HandlePackageInstance;\r
+      }\r
+    }\r
+    //\r
+    // end for\r
+    //\r
+  } else {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiNewPack (\r
+  IN  EFI_HII_PROTOCOL    *This,\r
+  IN  EFI_HII_PACKAGES    *Packages,\r
+  OUT EFI_HII_HANDLE      *Handle\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Extracts the various packs from a package list.\r
+  \r
+Arguments:\r
+\r
+  This      - Pointer of HII protocol.\r
+  Packages  - Pointer of HII packages.\r
+  Handle    - Handle value to be returned.\r
+\r
+Returns: \r
+\r
+  EFI_SUCCESS           - Pacakges has added to HII database successfully.\r
+  EFI_INVALID_PARAMETER - Invalid parameter.\r
+\r
+--*/\r
+{\r
+  EFI_HII_PACKAGE_INSTANCE  *PackageInstance;\r
+  EFI_HII_DATA              *HiiData;\r
+  EFI_HII_HANDLE_DATABASE   *HandleDatabase;\r
+  EFI_HII_HANDLE_DATABASE   *Database;\r
+  EFI_HII_PACK_HEADER       *PackageHeader;\r
+  EFI_HII_GLOBAL_DATA       *GlobalData;\r
+  EFI_HII_IFR_PACK          *IfrPack;\r
+  EFI_HII_STRING_PACK       *StringPack;\r
+  EFI_HII_FONT_PACK         *FontPack;\r
+  EFI_HII_KEYBOARD_PACK     *KeyboardPack;\r
+  EFI_STATUS                Status;\r
+  UINTN                     IfrSize;\r
+  UINTN                     StringSize;\r
+  UINTN                     TotalStringSize;\r
+  UINTN                     InstanceSize;\r
+  UINTN                     Count;\r
+  UINTN                     Index;\r
+  UINT16                    Member;\r
+  EFI_GUID                  Guid;\r
+  EFI_FORM_SET_STUB         FormSetStub;\r
+  UINT8                     *Location;\r
+  UINT16                    Unicode;\r
+  UINT16                    NumWideGlyphs;\r
+  UINT16                    NumNarrowGlyphs;\r
+  UINT32                    NumberOfTokens;\r
+  UINT32                    TotalTokenNumber;\r
+  UINT8                     *Local;\r
+  EFI_NARROW_GLYPH          *NarrowGlyph;\r
+\r
+  if (Packages->NumberOfPackages == 0 || This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  HiiData           = EFI_HII_DATA_FROM_THIS (This);\r
+\r
+  GlobalData        = HiiData->GlobalData;\r
+\r
+  Database          = HiiData->DatabaseHead;\r
+\r
+  PackageInstance   = NULL;\r
+  IfrPack           = NULL;\r
+  StringPack        = NULL;\r
+  InstanceSize      = 0;\r
+  IfrSize           = 0;\r
+  StringSize        = 0;\r
+  TotalStringSize   = 0;\r
+  NumberOfTokens    = 0;\r
+  TotalTokenNumber  = 0;\r
+\r
+  //\r
+  // Search through the passed in Packages for the IfrPack and any StringPack.\r
+  //\r
+  for (Index = 0; Index < Packages->NumberOfPackages; Index++) {\r
+\r
+    PackageHeader = *(EFI_HII_PACK_HEADER **) (((UINT8 *) Packages) + sizeof (EFI_HII_PACKAGES) + Index * sizeof (VOID *));\r
+\r
+    switch (PackageHeader->Type) {\r
+    case EFI_HII_IFR:\r
+      //\r
+      // There shoule be only one Ifr package.\r
+      //\r
+      ASSERT (IfrPack == NULL);\r
+      IfrPack = (EFI_HII_IFR_PACK *) PackageHeader;\r
+      break;\r
+\r
+    case EFI_HII_STRING:\r
+      StringPack = (EFI_HII_STRING_PACK *) PackageHeader;\r
+      //\r
+      // Sending me a String Package. Get its size.\r
+      //\r
+      Status = GetPackSize ((VOID *) StringPack, &StringSize, &NumberOfTokens);\r
+      ASSERT (!EFI_ERROR (Status));\r
+\r
+      //\r
+      // The size which GetPackSize() returns include the null terminator. So if multiple\r
+      // string packages are passed in, merge all these packages, and only pad one null terminator.\r
+      //\r
+      if (TotalStringSize > 0) {\r
+        TotalStringSize -= sizeof (EFI_HII_STRING_PACK);\r
+      }\r
+\r
+      TotalStringSize += StringSize;\r
+      TotalTokenNumber += NumberOfTokens;\r
+      break;\r
+    }\r
+  }\r
+  //\r
+  // If sending a StringPack without an IfrPack, you must include a GuidId\r
+  //\r
+  if ((StringPack != NULL) && (IfrPack == NULL)) {\r
+    if (Packages->GuidId == NULL) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+  //\r
+  // If passing in an IfrPack and a GuidId is provided, ensure they are the same value.\r
+  //\r
+  if ((IfrPack != NULL) && (Packages->GuidId != NULL)) {\r
+    Location  = ((UINT8 *) IfrPack);\r
+    Location  = (UINT8 *) (((UINTN) Location) + sizeof (EFI_HII_PACK_HEADER));\r
+\r
+    //\r
+    // Advance to the Form Set Op-code\r
+    //\r
+    for (Count = 0; ((EFI_IFR_OP_HEADER *) &Location[Count])->OpCode != EFI_IFR_FORM_SET_OP;) {\r
+      Count = Count + ((EFI_IFR_OP_HEADER *) &Location[Count])->Length;\r
+    }\r
+    //\r
+    // Copy to local variable\r
+    //\r
+    CopyMem (&Guid, &((EFI_IFR_FORM_SET *) &Location[Count])->Guid, sizeof (EFI_GUID));\r
+\r
+    //\r
+    // Check to see if IfrPack->Guid != GuidId\r
+    //\r
+    if (!CompareGuid (&Guid, Packages->GuidId)) {\r
+      //\r
+      // If a string package is present, the GUIDs should have agreed.  Return an error\r
+      //\r
+      if (StringPack != NULL) {\r
+        return EFI_INVALID_PARAMETER;\r
+      }\r
+    }\r
+  }\r
+  //\r
+  // If someone is passing in a string only, create a dummy IfrPack with a Guid\r
+  // to enable future searching of this data.\r
+  //\r
+  if ((IfrPack == NULL) && (StringPack != NULL)) {\r
+    ZeroMem (&FormSetStub, sizeof (FormSetStub));\r
+\r
+    FormSetStub.Header.Type           = EFI_HII_IFR;\r
+    FormSetStub.Header.Length         = sizeof (EFI_FORM_SET_STUB);\r
+\r
+    FormSetStub.FormSet.Header.OpCode = EFI_IFR_FORM_SET_OP;\r
+    FormSetStub.FormSet.Header.Length = (UINT8) sizeof (EFI_IFR_FORM_SET);\r
+    //\r
+    // Dummy string\r
+    //\r
+    FormSetStub.FormSet.FormSetTitle  = 0x02;\r
+    CopyMem (&FormSetStub.FormSet.Guid, Packages->GuidId, sizeof (EFI_GUID));\r
+\r
+    FormSetStub.EndFormSet.Header.OpCode  = EFI_IFR_END_FORM_SET_OP;\r
+    FormSetStub.EndFormSet.Header.Length  = (UINT8) sizeof (EFI_IFR_END_FORM_SET);\r
+    IfrPack = (EFI_HII_IFR_PACK *) &FormSetStub;\r
+  }\r
+\r
+  if (IfrPack != NULL) {\r
+    //\r
+    // Sending me an IFR Package. Get its size.\r
+    //\r
+    Status = GetPackSize ((VOID *) IfrPack, &IfrSize, NULL);\r
+    ASSERT (!EFI_ERROR (Status));\r
+  }\r
+  //\r
+  // Prepare the internal package instace buffer to store package data.\r
+  //\r
+  InstanceSize = IfrSize + TotalStringSize;\r
+\r
+  if (InstanceSize != 0) {\r
+    PackageInstance = AllocateZeroPool (InstanceSize + sizeof (EFI_HII_PACKAGE_INSTANCE));\r
+\r
+    ASSERT (PackageInstance);\r
+\r
+    //\r
+    // If there is no DatabaseHead allocated - allocate one\r
+    //\r
+    if (HiiData->DatabaseHead == NULL) {\r
+      HiiData->DatabaseHead = AllocateZeroPool (sizeof (EFI_HII_HANDLE_DATABASE));\r
+      ASSERT (HiiData->DatabaseHead);\r
+    }\r
+    //\r
+    // If the head is being used (Handle is non-zero), allocate next Database and\r
+    // add it to the linked-list\r
+    //\r
+    if (HiiData->DatabaseHead->Handle != 0) {\r
+      HandleDatabase = AllocateZeroPool (sizeof (EFI_HII_HANDLE_DATABASE));\r
+\r
+      ASSERT (HandleDatabase);\r
+\r
+      for (; Database->NextHandleDatabase != NULL; Database = Database->NextHandleDatabase)\r
+        ;\r
+\r
+      //\r
+      // We are sitting on the Database entry which contains the null Next pointer.  Fix it.\r
+      //\r
+      Database->NextHandleDatabase = HandleDatabase;\r
+\r
+    }\r
+\r
+    Database = HiiData->DatabaseHead;\r
+\r
+    //\r
+    // Initialize this instance data\r
+    //\r
+    for (*Handle = 1; Database->NextHandleDatabase != NULL; Database = Database->NextHandleDatabase) {\r
+      //\r
+      // Since the first Database instance will have a passed back handle of 1, we will continue\r
+      // down the linked list of entries until we encounter the end of the linked list.  Each time\r
+      // we go down one level deeper, increment the handle value that will be passed back.\r
+      //\r
+      if (Database->Handle >= *Handle) {\r
+        *Handle = (EFI_HII_HANDLE) (Database->Handle + 1);\r
+      }\r
+    }\r
+\r
+    PackageInstance->Handle     = *Handle;\r
+    PackageInstance->IfrSize    = IfrSize;\r
+    PackageInstance->StringSize = TotalStringSize;\r
+    if (Packages->GuidId != NULL) {\r
+      CopyMem (&PackageInstance->Guid, Packages->GuidId, sizeof (EFI_GUID));\r
+    }\r
+\r
+    Database->Buffer              = PackageInstance;\r
+    Database->Handle              = PackageInstance->Handle;\r
+    Database->NumberOfTokens      = TotalTokenNumber;\r
+    Database->NextHandleDatabase  = NULL;\r
+  }\r
+  //\r
+  // Copy the Ifr package data into package instance.\r
+  //\r
+  if (IfrSize > 0) {\r
+    CopyMem (&PackageInstance->IfrData, IfrPack, IfrSize);\r
+  }\r
+  //\r
+  // Main loop to store package data into HII database.\r
+  //\r
+  StringSize      = 0;\r
+  TotalStringSize = 0;\r
+\r
+  for (Index = 0; Index < Packages->NumberOfPackages; Index++) {\r
+\r
+    PackageHeader = *(EFI_HII_PACK_HEADER **) (((UINT8 *) Packages) + sizeof (EFI_HII_PACKAGES) + Index * sizeof (VOID *));\r
+\r
+    switch (PackageHeader->Type) {\r
+    case EFI_HII_STRING:\r
+      StringPack = (EFI_HII_STRING_PACK *) PackageHeader;\r
+      //\r
+      // The size which GetPackSize() returns include the null terminator. So if multiple\r
+      // string packages are passed in, merge all these packages, and only pad one null terminator.\r
+      //\r
+      if (TotalStringSize > 0) {\r
+        TotalStringSize -= sizeof (EFI_HII_STRING_PACK);\r
+      }\r
+\r
+      GetPackSize ((VOID *) StringPack, &StringSize, &NumberOfTokens);\r
+      CopyMem ((CHAR8 *) (&PackageInstance->IfrData) + IfrSize + TotalStringSize, StringPack, StringSize);\r
+\r
+      TotalStringSize += StringSize;\r
+      break;\r
+\r
+    case EFI_HII_HANDLES:\r
+      CopyMem (&PackageInstance->HandlePack, PackageHeader, sizeof (EFI_HII_HANDLE_PACK));\r
+      break;\r
+\r
+    case EFI_HII_FONT:\r
+      FontPack = (EFI_HII_FONT_PACK *) PackageHeader;\r
+      //\r
+      // Add whatever narrow glyphs were passed to us if undefined\r
+      //\r
+      CopyMem (&NumNarrowGlyphs, &FontPack->NumberOfNarrowGlyphs, sizeof (UINT16));\r
+      for (Count = 0; Count <= NumNarrowGlyphs; Count++) {\r
+        Local       = (UINT8 *) (&FontPack->NumberOfWideGlyphs + sizeof (UINT8)) + (sizeof (EFI_NARROW_GLYPH)) * Count;\r
+        NarrowGlyph = (EFI_NARROW_GLYPH *) Local;\r
+        CopyMem (&Member, &NarrowGlyph->UnicodeWeight, sizeof (UINT16));\r
+        //\r
+        // If the glyph is already defined, do not overwrite it.  It is what it is.\r
+        //\r
+        CopyMem (&Unicode, &GlobalData->NarrowGlyphs[Member].UnicodeWeight, sizeof (UINT16));\r
+        if (Unicode == 0) {\r
+          CopyMem (&GlobalData->NarrowGlyphs[Member], Local, sizeof (EFI_NARROW_GLYPH));\r
+        }\r
+      }\r
+      //\r
+      // Add whatever wide glyphs were passed to us if undefined\r
+      //\r
+      CopyMem (&NumWideGlyphs, &FontPack->NumberOfWideGlyphs, sizeof (UINT16));\r
+      for (Count = 0; Count <= NumWideGlyphs; Count++) {\r
+        Local = (UINT8 *) (&FontPack->NumberOfWideGlyphs + sizeof (UINT8)) +\r
+          (sizeof (EFI_NARROW_GLYPH)) *\r
+          NumNarrowGlyphs;\r
+        CopyMem (\r
+          &Member,\r
+          (UINTN *) (Local + sizeof (EFI_WIDE_GLYPH) * Count),\r
+          sizeof (UINT16)\r
+          );\r
+        //\r
+        // If the glyph is already defined, do not overwrite it.  It is what it is.\r
+        //\r
+        CopyMem (&Unicode, &GlobalData->WideGlyphs[Member].UnicodeWeight, sizeof (UINT16));\r
+        if (Unicode == 0) {\r
+          Local = (UINT8*)(&FontPack->NumberOfWideGlyphs + sizeof(UINT8)) + (sizeof(EFI_NARROW_GLYPH)) * NumNarrowGlyphs;\r
+          CopyMem (\r
+            &GlobalData->WideGlyphs[Member],\r
+            (UINTN *) (Local + sizeof (EFI_WIDE_GLYPH) * Count),\r
+            sizeof (EFI_WIDE_GLYPH)\r
+            );\r
+        }\r
+      }\r
+      break;\r
+\r
+    case EFI_HII_KEYBOARD:\r
+      KeyboardPack = (EFI_HII_KEYBOARD_PACK *) PackageHeader;\r
+      //\r
+      // Sending me a Keyboard Package\r
+      //\r
+      if (KeyboardPack->DescriptorCount > 105) {\r
+        return EFI_INVALID_PARAMETER;\r
+      }\r
+      //\r
+      // If someone updates the Descriptors with a count of 0, blow aware the overrides.\r
+      //\r
+      if (KeyboardPack->DescriptorCount == 0) {\r
+        ZeroMem (GlobalData->OverrideKeyboardLayout, sizeof (EFI_KEY_DESCRIPTOR) * 106);\r
+      }\r
+\r
+      if (KeyboardPack->DescriptorCount < 106 && KeyboardPack->DescriptorCount > 0) {\r
+        //\r
+        // If SystemKeyboard was updated already, then steer changes to the override database\r
+        //\r
+        if (GlobalData->SystemKeyboardUpdate) {\r
+          ZeroMem (GlobalData->OverrideKeyboardLayout, sizeof (EFI_KEY_DESCRIPTOR) * 106);\r
+          for (Count = 0; Count < KeyboardPack->DescriptorCount; Count++) {\r
+            CopyMem (&Member, &KeyboardPack->Descriptor[Count].Key, sizeof (UINT16));\r
+            CopyMem (\r
+              &GlobalData->OverrideKeyboardLayout[Member],\r
+              &KeyboardPack->Descriptor[Count],\r
+              sizeof (EFI_KEY_DESCRIPTOR)\r
+              );\r
+          }\r
+        } else {\r
+          //\r
+          // SystemKeyboard was never updated, so this is likely the keyboard driver setting the System database.\r
+          //\r
+          ZeroMem (GlobalData->SystemKeyboardLayout, sizeof (EFI_KEY_DESCRIPTOR) * 106);\r
+          for (Count = 0; Count < KeyboardPack->DescriptorCount; Count++) {\r
+            CopyMem (&Member, &KeyboardPack->Descriptor->Key, sizeof (UINT16));\r
+            CopyMem (\r
+              &GlobalData->SystemKeyboardLayout[Member],\r
+              &KeyboardPack->Descriptor[Count],\r
+              sizeof (EFI_KEY_DESCRIPTOR)\r
+              );\r
+          }\r
+          //\r
+          // Just updated the system keyboard database, reflect that in the global flag.\r
+          //\r
+          GlobalData->SystemKeyboardUpdate = TRUE;\r
+        }\r
+      }\r
+      break;\r
+\r
+    default:\r
+      break;\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiRemovePack (\r
+  IN EFI_HII_PROTOCOL    *This,\r
+  IN EFI_HII_HANDLE      Handle\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Removes the various packs from a Handle\r
+  \r
+Arguments:\r
+\r
+Returns: \r
+\r
+--*/\r
+{\r
+  EFI_HII_PACKAGE_INSTANCE  *PackageInstance;\r
+  EFI_HII_DATA              *HiiData;\r
+  EFI_HII_HANDLE_DATABASE   *HandleDatabase;\r
+  EFI_HII_HANDLE_DATABASE   *PreviousHandleDatabase;\r
+\r
+  if (This == NULL || Handle == 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  HiiData         = EFI_HII_DATA_FROM_THIS (This);\r
+\r
+  HandleDatabase  = HiiData->DatabaseHead;\r
+  PackageInstance = NULL;\r
+\r
+  //\r
+  // Initialize the Previous with the Head of the Database\r
+  //\r
+  PreviousHandleDatabase = HandleDatabase;\r
+\r
+  for (; HandleDatabase != NULL; HandleDatabase = HandleDatabase->NextHandleDatabase) {\r
+    //\r
+    // Match the numeric value with the database entry - if matched,\r
+    // free the package instance and apply fix-up to database linked list\r
+    //\r
+    if (Handle == HandleDatabase->Handle) {\r
+      PackageInstance = HandleDatabase->Buffer;\r
+\r
+      //\r
+      // Free the Package Instance\r
+      //\r
+      FreePool (PackageInstance);\r
+\r
+      //\r
+      // If this was the only Handle in the database\r
+      //\r
+      if (HiiData->DatabaseHead == HandleDatabase) {\r
+        HiiData->DatabaseHead = NULL;\r
+      }\r
+      //\r
+      // Make the parent->Next point to the current->Next\r
+      //\r
+      PreviousHandleDatabase->NextHandleDatabase = HandleDatabase->NextHandleDatabase;\r
+      FreePool (HandleDatabase);\r
+      return EFI_SUCCESS;\r
+    }\r
+    //\r
+    // If this was not the HandleDatabase entry we were looking for, cache it just in case the next one is\r
+    //\r
+    PreviousHandleDatabase = HandleDatabase;\r
+  }\r
+  //\r
+  // No handle was found - error condition\r
+  //\r
+  if (PackageInstance == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/Strings.c b/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/Strings.c
new file mode 100644 (file)
index 0000000..a8b04c0
--- /dev/null
@@ -0,0 +1,1276 @@
+/*++\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
+  Strings.c\r
+\r
+Abstract:\r
+\r
+  This file contains the string processing code to the HII database.\r
+\r
+--*/\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "HiiDatabase.h"\r
+\r
+STATIC\r
+VOID\r
+AsciiToUnicode (\r
+  IN    UINT8     *Lang,\r
+  IN    UINT16    *Language\r
+  )\r
+{\r
+  UINT8 Count;\r
+\r
+  //\r
+  // Convert the ASCII Lang variable to a Unicode Language variable\r
+  //\r
+  for (Count = 0; Count < 3; Count++) {\r
+    Language[Count] = (CHAR16) Lang[Count];\r
+  }\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiTestString (\r
+  IN     EFI_HII_PROTOCOL   *This,\r
+  IN     CHAR16             *StringToTest,\r
+  IN OUT UINT32             *FirstMissing,\r
+  OUT    UINT32             *GlyphBufferSize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Test if all of the characters in a string have corresponding font characters.\r
+  \r
+Arguments:\r
+\r
+Returns: \r
+\r
+--*/\r
+{\r
+  EFI_HII_GLOBAL_DATA *GlobalData;\r
+  EFI_HII_DATA        *HiiData;\r
+  BOOLEAN             WideChar;\r
+  INT32               Location;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  HiiData     = EFI_HII_DATA_FROM_THIS (This);\r
+  GlobalData  = HiiData->GlobalData;\r
+\r
+  \r
+  //\r
+  // Rewind through the string looking for a glyph width identifier\r
+  // If no width identifier exists, we assume string has narrow width identifier\r
+  //\r
+  for (WideChar = FALSE, Location = (INT32) *FirstMissing; Location >= 0; Location--) {\r
+    if ((StringToTest[Location] == NARROW_CHAR) || (StringToTest[Location] == WIDE_CHAR)) {\r
+      //\r
+      // We found something that identifies what glyph database to look in\r
+      //\r
+      WideChar = (BOOLEAN) (StringToTest[Location] == WIDE_CHAR);\r
+      break;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Walk through the string until you hit the null terminator\r
+  //\r
+  for (*GlyphBufferSize = 0; StringToTest[*FirstMissing] != CHAR_NULL; (*FirstMissing)++) {\r
+    //\r
+    // We found something that identifies what glyph database to look in\r
+    //\r
+    if ((StringToTest[*FirstMissing] == NARROW_CHAR) || (StringToTest[*FirstMissing] == WIDE_CHAR)) {\r
+      WideChar = (BOOLEAN) (StringToTest[*FirstMissing] == WIDE_CHAR);\r
+      continue;\r
+    }\r
+\r
+    if (!WideChar) {\r
+      if (CompareMem (\r
+          GlobalData->NarrowGlyphs[StringToTest[*FirstMissing]].GlyphCol1,\r
+          &mUnknownGlyph,\r
+          NARROW_GLYPH_ARRAY_SIZE\r
+          ) == 0\r
+          ) {\r
+        //\r
+        // Break since this glyph isn't defined\r
+        //\r
+        return EFI_NOT_FOUND;\r
+      }\r
+    } else {\r
+      //\r
+      // Can compare wide glyph against only GlyphCol1 since GlyphCol1 and GlyphCol2 are contiguous - just give correct size\r
+      //\r
+      if (CompareMem (\r
+          GlobalData->WideGlyphs[StringToTest[*FirstMissing]].GlyphCol1,\r
+          &mUnknownGlyph,\r
+          WIDE_GLYPH_ARRAY_SIZE\r
+          ) == 0\r
+          ) {\r
+        //\r
+        // Break since this glyph isn't defined\r
+        //\r
+        return EFI_NOT_FOUND;\r
+      }\r
+    }\r
+\r
+    *GlyphBufferSize += (WideChar ? sizeof (EFI_WIDE_GLYPH) : sizeof (EFI_NARROW_GLYPH));\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+HiiNewString2 (\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
+  IN     BOOLEAN                ResetStrings\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function allows a new String to be added to an already existing String Package.\r
+  We will make a buffer the size of the package + EfiStrSize of the new string.  We will\r
+  copy the string package that first gets changed and the following language packages until\r
+  we encounter the NULL string package.  All this time we will ensure that the offsets have\r
+  been adjusted.  \r
+\r
+Arguments:\r
+  \r
+  This         -  Pointer to the HII protocol.\r
+  Language     -  Pointer to buffer which contains the language code of this NewString.\r
+  Handle       -  Handle of the package instance to be processed.\r
+  Reference    -  The token number for the string. If 0, new string token to be returned through this parameter.\r
+  NewString    -  Buffer pointer for the new string. \r
+  ResetStrings -  Indicate if we are resetting a string.\r
+  \r
+Returns: \r
+\r
+  EFI_SUCCESS            - The string has been added or reset to Hii database.\r
+  EFI_INVALID_PARAMETER  - Some parameter passed in is invalid.\r
+\r
+--*/\r
+{\r
+  EFI_HII_PACKAGE_INSTANCE  *PackageInstance;\r
+  EFI_HII_PACKAGE_INSTANCE  *StringPackageInstance;\r
+  EFI_HII_DATA              *HiiData;\r
+  EFI_HII_STRING_PACK       *StringPack;\r
+  EFI_HII_STRING_PACK       *NewStringPack;\r
+  EFI_HII_HANDLE_DATABASE   *HandleDatabase;\r
+  EFI_HII_PACKAGE_INSTANCE  *NewBuffer;\r
+  UINT8                     *Location;\r
+  UINT8                     *StringLocation;\r
+  RELOFST                   *StringPointer;\r
+  UINTN                     Count;\r
+  UINTN                     Size;\r
+  UINTN                     Index;\r
+  UINTN                     SecondIndex;\r
+  BOOLEAN                   AddString;\r
+  EFI_STATUS                Status;\r
+  UINTN                     Increment;\r
+  UINTN                     StringCount;\r
+  UINT32                    TotalStringCount;\r
+  UINT32                    OriginalStringCount;\r
+  RELOFST                   StringSize;\r
+  UINT32                    Length;\r
+  RELOFST                   Offset;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  HiiData             = EFI_HII_DATA_FROM_THIS (This);\r
+\r
+  HandleDatabase      = HiiData->DatabaseHead;\r
+  PackageInstance     = NULL;\r
+  AddString           = FALSE;\r
+  Increment           = 0;\r
+  StringCount         = 0;\r
+  TotalStringCount    = 0;\r
+  OriginalStringCount = 0;\r
+\r
+  //\r
+  // Check numeric value against the head of the database\r
+  //\r
+  for (; HandleDatabase != NULL; HandleDatabase = HandleDatabase->NextHandleDatabase) {\r
+    //\r
+    // Match the numeric value with the database entry - if matched, extract PackageInstance\r
+    //\r
+    if (Handle == HandleDatabase->Handle) {\r
+      PackageInstance = HandleDatabase->Buffer;\r
+      if (ResetStrings) {\r
+        TotalStringCount = HandleDatabase->NumberOfTokens;\r
+      }\r
+      break;\r
+    }\r
+  }\r
+  //\r
+  // No handle was found - error condition\r
+  //\r
+  if (PackageInstance == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = ValidatePack (This, PackageInstance, &StringPackageInstance, &TotalStringCount);\r
+\r
+  //\r
+  // This sets Count to 0 or the size of the IfrData.  We intend to use Count as an offset value\r
+  //\r
+  Count = StringPackageInstance->IfrSize;\r
+\r
+  //\r
+  // This is the size of the complete series of string packs\r
+  //\r
+  Size = StringPackageInstance->StringSize;\r
+\r
+  //\r
+  // Based on if there is IFR data in this package instance, determine\r
+  // what the location is of the beginning of the string data.\r
+  //\r
+  if (StringPackageInstance->IfrSize > 0) {\r
+    Location = (UINT8 *) (&StringPackageInstance->IfrData) + StringPackageInstance->IfrSize;\r
+  } else {\r
+    Location = (UINT8 *) (&StringPackageInstance->IfrData);\r
+  }\r
+  //\r
+  // We allocate a buffer which is big enough for both adding and resetting string.\r
+  // The size is slightly larger than the real size of the packages when we are resetting a string.\r
+  //\r
+  NewBuffer = AllocateZeroPool (\r
+                sizeof (EFI_HII_PACKAGE_INSTANCE) -\r
+                2 * sizeof (VOID *) +\r
+                StringPackageInstance->IfrSize +\r
+                StringPackageInstance->StringSize +\r
+                sizeof (RELOFST) +\r
+                StrSize (NewString)\r
+                );\r
+  ASSERT (NewBuffer);\r
+\r
+  //\r
+  // Copy data to new buffer\r
+  //\r
+  NewBuffer->Handle   = StringPackageInstance->Handle;\r
+  NewBuffer->IfrSize  = StringPackageInstance->IfrSize;\r
+\r
+  //\r
+  // The worst case scenario for sizing is that we are adding a new string (not replacing one) and there was not a string\r
+  // package to begin with.\r
+  //\r
+  NewBuffer->StringSize = StringPackageInstance->StringSize + StrSize (NewString) + sizeof (EFI_HII_STRING_PACK);\r
+\r
+  if (StringPackageInstance->IfrSize > 0) {\r
+    CopyMem (&NewBuffer->IfrData, &StringPackageInstance->IfrData, StringPackageInstance->IfrSize);\r
+  }\r
+\r
+  StringPack = (EFI_HII_STRING_PACK *) Location;\r
+\r
+  //\r
+  // There may be multiple instances packed together of strings\r
+  // so we must walk the self describing structures until we encounter\r
+  // what we are looking for.  In the meantime, copy everything we encounter\r
+  // to the new buffer.\r
+  //\r
+  CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));\r
+  for (; Length != 0;) {\r
+    //\r
+    // If passed in Language ISO value is in this string pack's language string\r
+    // then we are dealing with the strings we want.\r
+    //\r
+    CopyMem (&Offset, &StringPack->LanguageNameString, sizeof (RELOFST));\r
+    Status = HiiCompareLanguage ((CHAR16 *) ((CHAR8 *) (StringPack) + Offset), Language);\r
+\r
+    if (!EFI_ERROR (Status)) {\r
+      break;\r
+    }\r
+\r
+    CopyMem (((CHAR8 *) (&NewBuffer->IfrData) + Count), StringPack, Length);\r
+\r
+    Count       = Count + Length;\r
+    StringPack  = (EFI_HII_STRING_PACK *) ((CHAR8 *) (StringPack) + Length);\r
+    CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));\r
+  }\r
+  //\r
+  // Found the language pack to update on a particular handle\r
+  // We need to Copy the Contents of this pack and adjust the offset values associated\r
+  // with adding/changing a string.  This is a particular piece of code that screams for\r
+  // it being prone to programming error.\r
+  //\r
+  //\r
+  // Copy the string package up to the string data\r
+  //\r
+  StringPointer = (RELOFST *) (StringPack + 1);\r
+  CopyMem (\r
+    ((CHAR8 *) (&NewBuffer->IfrData) + Count),\r
+    StringPack,\r
+    (UINTN) ((UINTN) (StringPointer) - (UINTN) (StringPack))\r
+    );\r
+\r
+  //\r
+  // Determine the number of StringPointers\r
+  //\r
+  if (!ResetStrings) {\r
+    CopyMem (&TotalStringCount, &StringPack->NumStringPointers, sizeof (RELOFST));\r
+  } else {\r
+    //\r
+    // If we are resetting the strings, use the original value when exported\r
+    //\r
+    CopyMem (&OriginalStringCount, &StringPack->NumStringPointers, sizeof (RELOFST));\r
+    ((EFI_HII_STRING_PACK *) ((CHAR8 *) (&NewBuffer->IfrData) + Count))->LanguageNameString -=\r
+      (\r
+        (RELOFST) (OriginalStringCount - TotalStringCount) *\r
+        sizeof (RELOFST)\r
+      );\r
+    ((EFI_HII_STRING_PACK *) ((CHAR8 *) (&NewBuffer->IfrData) + Count))->PrintableLanguageName -=\r
+      (\r
+        (RELOFST) (OriginalStringCount - TotalStringCount) *\r
+        sizeof (RELOFST)\r
+      );\r
+    ((EFI_HII_STRING_PACK *) ((CHAR8 *) (&NewBuffer->IfrData) + Count))->NumStringPointers  = TotalStringCount;\r
+    *Reference = (STRING_REF) (TotalStringCount);\r
+  }\r
+  //\r
+  // If the token value is not valid, error out\r
+  //\r
+  if ((*Reference >= TotalStringCount) && !ResetStrings) {\r
+    FreePool (NewBuffer);\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // If Reference is 0, update it with what the new token reference will be and turn the AddString flag on\r
+  //\r
+  if (*Reference == 0) {\r
+    *Reference  = (STRING_REF) (TotalStringCount);\r
+    AddString   = TRUE;\r
+  }\r
+\r
+  if (AddString) {\r
+    ((EFI_HII_STRING_PACK *) ((CHAR8 *) (&NewBuffer->IfrData) + Count))->LanguageNameString += sizeof (RELOFST);\r
+    ((EFI_HII_STRING_PACK *) ((CHAR8 *) (&NewBuffer->IfrData) + Count))->PrintableLanguageName += sizeof (RELOFST);\r
+    ((EFI_HII_STRING_PACK *) ((CHAR8 *) (&NewBuffer->IfrData) + Count))->NumStringPointers++;\r
+  }\r
+  //\r
+  // Increment offset by amount of copied data\r
+  //\r
+  Count = Count + ((UINTN) (StringPointer) - (UINTN) StringPack);\r
+\r
+  for (Index = 0; Index < TotalStringCount; Index++) {\r
+    //\r
+    // If we are pointing to the size of the changing string value\r
+    // then cache the old string value so you know what the difference is\r
+    //\r
+    if (Index == *Reference) {\r
+      CopyMem (&Offset, &StringPointer[Index], sizeof (RELOFST));\r
+\r
+      StringLocation = ((UINT8 *) (StringPack) + Offset);\r
+      for (SecondIndex = 0;\r
+           (StringLocation[SecondIndex] != 0) || (StringLocation[SecondIndex + 1] != 0);\r
+           SecondIndex = SecondIndex + 2\r
+          )\r
+        ;\r
+      SecondIndex = SecondIndex + 2;\r
+\r
+      Size        = SecondIndex;\r
+\r
+      //\r
+      // NewString is a passed in local string which is assumed to be aligned\r
+      //\r
+      Size = StrSize (NewString) - Size;\r
+    }\r
+    //\r
+    // If we are about to copy the offset of the string that follows the changed string make\r
+    // sure that the offsets are adjusted accordingly\r
+    //\r
+    if ((Index > *Reference) && !ResetStrings) {\r
+      CopyMem (&Offset, &StringPointer[Index], sizeof (RELOFST));\r
+      Offset = (RELOFST) (Offset + Size);\r
+      CopyMem (&StringPointer[Index], &Offset, sizeof (RELOFST));\r
+    }\r
+    //\r
+    // If we are adding a string that means we will have an extra string pointer that will affect all string offsets\r
+    //\r
+    if (AddString) {\r
+      CopyMem (&Offset, &StringPointer[Index], sizeof (RELOFST));\r
+      Offset = (UINT32) (Offset + sizeof (RELOFST));\r
+      CopyMem (&StringPointer[Index], &Offset, sizeof (RELOFST));\r
+    }\r
+    //\r
+    // If resetting the strings, we need to reduce the offset by the difference in the strings\r
+    //\r
+    if (ResetStrings) {\r
+      CopyMem (&Length, &StringPointer[Index], sizeof (RELOFST));\r
+      Length = Length - ((RELOFST) (OriginalStringCount - TotalStringCount) * sizeof (RELOFST));\r
+      CopyMem (&StringPointer[Index], &Length, sizeof (RELOFST));\r
+    }\r
+    //\r
+    // Notice that if the string was being added as a new token, we don't have to worry about the\r
+    // offsets changing in the other indexes\r
+    //\r
+    CopyMem (((CHAR8 *) (&NewBuffer->IfrData) + Count), &StringPointer[Index], sizeof (RELOFST));\r
+    Count = Count + sizeof (RELOFST);\r
+    StringCount++;\r
+  }\r
+  //\r
+  // If we are adding a new string the above for loop did not copy the offset for us\r
+  //\r
+  if (AddString) {\r
+    //\r
+    // Since the Index is pointing to the beginning of the first string, we need to gather the size of the previous\r
+    // offset's string and create an offset to our new string.\r
+    //\r
+    CopyMem (&Offset, &StringPointer[Index - 1], sizeof (RELOFST));\r
+    StringLocation  = (UINT8 *) StringPack;\r
+    StringLocation  = StringLocation + Offset - sizeof (RELOFST);\r
+\r
+    //\r
+    // Since StringPack is a packed structure, we need to size it carefully (byte-wise) to avoid alignment issues\r
+    //\r
+    for (Length = 0;\r
+         (StringLocation[Length] != 0) || (StringLocation[Length + 1] != 0);\r
+         Length = (RELOFST) (Length + 2)\r
+        )\r
+      ;\r
+    Length      = (RELOFST) (Length + 2);\r
+\r
+    StringSize  = (RELOFST) (Offset + Length);\r
+\r
+    //\r
+    // Copy the new string offset\r
+    //\r
+    CopyMem (((CHAR8 *) (&NewBuffer->IfrData) + Count), &StringSize, sizeof (RELOFST));\r
+    Count = Count + sizeof (RELOFST);\r
+\r
+    CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));\r
+    Length = Length + sizeof (RELOFST);\r
+    CopyMem (&StringPack->Header.Length, &Length, sizeof (UINT32));\r
+  }\r
+  //\r
+  // Set Location to the First String\r
+  //\r
+  if (ResetStrings) {\r
+    Index = OriginalStringCount;\r
+  }\r
+  //\r
+  // Set Location to the First String\r
+  //\r
+  Location  = (UINT8 *) &StringPointer[Index];\r
+  Index     = 0;\r
+\r
+  //\r
+  // Keep copying strings until you run into two CHAR16's in a row that are NULL\r
+  //\r
+  do {\r
+    if ((*Reference == Increment) && !AddString) {\r
+      StringLocation = ((UINT8 *) (&NewBuffer->IfrData) + Count);\r
+      CopyMem (StringLocation, NewString, StrSize (NewString));\r
+\r
+      //\r
+      // Advance the destination location by Count number of bytes\r
+      //\r
+      Count = Count + StrSize (NewString);\r
+\r
+      //\r
+      // Add the difference between the new string and the old string to the length\r
+      //\r
+      CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));\r
+\r
+      //\r
+      // Since StringPack is a packed structure, we need to size it carefully (byte-wise) to avoid alignment issues\r
+      //\r
+      StringLocation = (UINT8 *) &Location[Index];\r
+      for (Offset = 0;\r
+           (StringLocation[Offset] != 0) || (StringLocation[Offset + 1] != 0);\r
+           Offset = (RELOFST) (Offset + 2)\r
+          )\r
+        ;\r
+      Offset  = (RELOFST) (Offset + 2);\r
+\r
+      Length  = Length + (UINT32) StrSize (NewString) - Offset;\r
+\r
+      CopyMem (&StringPack->Header.Length, &Length, sizeof (UINT32));\r
+    } else {\r
+      StringLocation = (UINT8 *) &Location[Index];\r
+      for (Offset = 0;\r
+           (StringLocation[Offset] != 0) || (StringLocation[Offset + 1] != 0);\r
+           Offset = (RELOFST) (Offset + 2)\r
+          )\r
+        ;\r
+      Offset = (RELOFST) (Offset + 2);\r
+\r
+      CopyMem (((CHAR8 *) (&NewBuffer->IfrData) + Count), StringLocation, Offset);\r
+\r
+      //\r
+      // Advance the destination location by Count number of bytes\r
+      //\r
+      Count = Count + Offset;\r
+    }\r
+    //\r
+    // Retrieve the number of characters to advance the index - should land at beginning of next string\r
+    //\r
+    Index = Index + Offset;\r
+    Increment++;\r
+    StringCount--;\r
+    Offset = 0;\r
+  } while (StringCount > 0);\r
+\r
+  //\r
+  // If we are adding a new string, then the above do/while will not suffice\r
+  //\r
+  if (AddString) {\r
+    Offset = (RELOFST) StrSize (NewString);\r
+    CopyMem (((CHAR8 *) (&NewBuffer->IfrData) + Count), NewString, Offset);\r
+\r
+    Count = Count + StrSize (NewString);\r
+    CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));\r
+    Length = Length + (UINT32) StrSize (NewString);\r
+    CopyMem (&StringPack->Header.Length, &Length, sizeof (UINT32));\r
+  }\r
+\r
+  if (ResetStrings) {\r
+    //\r
+    // Skip the remainder of strings in the string package\r
+    //\r
+    StringCount = OriginalStringCount - TotalStringCount;\r
+\r
+    while (StringCount > 0) {\r
+      StringLocation = (UINT8 *) &Location[Index];\r
+      for (Offset = 0;\r
+           (StringLocation[Offset] != 0) || (StringLocation[Offset + 1] != 0);\r
+           Offset = (RELOFST) (Offset + 2)\r
+          )\r
+        ;\r
+      Offset  = (RELOFST) (Offset + 2);\r
+      Index   = Index + Offset;\r
+      StringCount--;\r
+\r
+      //\r
+      // Adjust the size of the string pack by the string size we just skipped.\r
+      // Also reduce the length by the size of a RelativeOffset value since we\r
+      // obviously would have skipped that as well.\r
+      //\r
+      CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));\r
+      Length = Length - Offset - sizeof (RELOFST);\r
+      CopyMem (&StringPack->Header.Length, &Length, sizeof (UINT32));\r
+    }\r
+  }\r
+\r
+  StringPack = (EFI_HII_STRING_PACK *) &Location[Index];\r
+\r
+  CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));\r
+  for (; Length != 0;) {\r
+\r
+    CopyMem (((CHAR8 *) (&NewBuffer->IfrData) + Count), StringPack, Length);\r
+\r
+    Count       = Count + Length;\r
+    StringPack  = (EFI_HII_STRING_PACK *) ((CHAR8 *) (StringPack) + Length);\r
+    CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));\r
+  }\r
+  //\r
+  // Copy the null terminator to the new buffer\r
+  //\r
+  CopyMem (((CHAR8 *) (&NewBuffer->IfrData) + Count), StringPack, sizeof (EFI_HII_STRING_PACK));\r
+\r
+  //\r
+  // Based on if there is IFR data in this package instance, determine\r
+  // what the location is of the beginning of the string data.\r
+  //\r
+  if (StringPackageInstance->IfrSize > 0) {\r
+    Location      = (UINT8 *) (&StringPackageInstance->IfrData) + StringPackageInstance->IfrSize;\r
+    StringPack    = (EFI_HII_STRING_PACK *) Location;\r
+    Location      = (UINT8 *) (&NewBuffer->IfrData) + NewBuffer->IfrSize;\r
+    NewStringPack = (EFI_HII_STRING_PACK *) Location;\r
+  } else {\r
+    StringPack    = (EFI_HII_STRING_PACK *) (&StringPackageInstance->IfrData);\r
+    NewStringPack = (EFI_HII_STRING_PACK *) (&NewBuffer->IfrData);\r
+  }\r
+\r
+  CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));\r
+  for (; Length != 0;) {\r
+    //\r
+    // Since we updated the old version of the string data as we moved things over\r
+    // And we had a chicken-egg problem with the data we copied, let's post-fix the new\r
+    // buffer with accurate length data.\r
+    //\r
+    CopyMem (&Count, &NewStringPack->Header.Length, sizeof (UINT32));\r
+    CopyMem (&NewStringPack->Header.Length, &StringPack->Header.Length, sizeof (UINT32));\r
+    CopyMem (&StringPack->Header.Length, &Count, sizeof (UINT32));\r
+\r
+    CopyMem (&Count, &NewStringPack->Header.Length, sizeof (UINT32));\r
+    NewStringPack = (EFI_HII_STRING_PACK *) ((CHAR8 *) (NewStringPack) + Count);\r
+    CopyMem (&Count, &StringPack->Header.Length, sizeof (UINT32));\r
+    StringPack = (EFI_HII_STRING_PACK *) ((CHAR8 *) (StringPack) + Count);\r
+    CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));\r
+  }\r
+\r
+  GetPackSize ((VOID *) ((CHAR8 *) (&NewBuffer->IfrData) + NewBuffer->IfrSize), &NewBuffer->StringSize, NULL);\r
+\r
+  //\r
+  // Search through the handles until the requested handle is found.\r
+  //\r
+  for (HandleDatabase = HiiData->DatabaseHead;\r
+       HandleDatabase->Handle != 0;\r
+       HandleDatabase = HandleDatabase->NextHandleDatabase\r
+      ) {\r
+    if (HandleDatabase->Handle == StringPackageInstance->Handle) {\r
+      //\r
+      // Free the previous buffer associated with this handle, and assign the new buffer to the handle\r
+      //\r
+      FreePool (HandleDatabase->Buffer);\r
+      HandleDatabase->Buffer = NewBuffer;\r
+      break;\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiNewString (\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
+Routine Description:\r
+  This function allows a new String to be added to an already existing String Package.\r
+  We will make a buffer the size of the package + StrSize of the new string.  We will\r
+  copy the string package that first gets changed and the following language packages until\r
+  we encounter the NULL string package.  All this time we will ensure that the offsets have\r
+  been adjusted.  \r
+\r
+Arguments:\r
+  \r
+Returns: \r
+\r
+--*/\r
+{\r
+  UINTN       Index;\r
+  CHAR16      *LangCodes;\r
+  CHAR16      Lang[4];\r
+  STRING_REF  OriginalValue;\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // To avoid a warning 4 uninitialized variable warning\r
+  //\r
+  Status = EFI_SUCCESS;\r
+\r
+  Status = HiiGetPrimaryLanguages (\r
+            This,\r
+            Handle,\r
+            &LangCodes\r
+            );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    OriginalValue = *Reference;\r
+\r
+    if (Language == NULL) {\r
+      for (Index = 0; LangCodes[Index] != 0; Index += 3) {\r
+        *Reference = OriginalValue;\r
+        CopyMem (Lang, &LangCodes[Index], 6);\r
+        Lang[3] = 0;\r
+        Status = HiiNewString2 (\r
+                  This,\r
+                  Lang,\r
+                  Handle,\r
+                  Reference,\r
+                  NewString,\r
+                  FALSE\r
+                  );\r
+\r
+      }\r
+    } else {\r
+      Status = HiiNewString2 (\r
+                This,\r
+                Language,\r
+                Handle,\r
+                Reference,\r
+                NewString,\r
+                FALSE\r
+                );\r
+    }\r
+\r
+    FreePool (LangCodes);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiResetStrings (\r
+  IN     EFI_HII_PROTOCOL   *This,\r
+  IN     EFI_HII_HANDLE     Handle\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  \r
+    This function removes any new strings that were added after the initial string export for this handle.\r
+\r
+Arguments:\r
+\r
+Returns: \r
+\r
+--*/\r
+{\r
+  UINTN       Index;\r
+  CHAR16      *LangCodes;\r
+  CHAR16      Lang[4];\r
+  STRING_REF  Reference;\r
+  CHAR16      NewString;\r
+  EFI_STATUS  Status;\r
+\r
+  Reference = 1;\r
+  NewString = 0;\r
+\r
+  HiiGetPrimaryLanguages (\r
+    This,\r
+    Handle,\r
+    &LangCodes\r
+    );\r
+\r
+  for (Index = 0; LangCodes[Index] != 0; Index += 3) {\r
+    CopyMem (Lang, &LangCodes[Index], 6);\r
+    Lang[3] = 0;\r
+    Status = HiiNewString2 (\r
+              This,\r
+              Lang,\r
+              Handle,\r
+              &Reference,\r
+              &NewString,\r
+              TRUE\r
+              );\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
+  FreePool (LangCodes);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiGetString (\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               *BufferLengthTemp,\r
+  OUT    EFI_STRING          StringBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  \r
+  This function extracts a string from a package already registered with the EFI HII database.\r
+\r
+Arguments:\r
+  This            - A pointer to the EFI_HII_PROTOCOL instance.\r
+  Handle          - The HII handle on which the string resides.\r
+  Token           - The string token assigned to the string.\r
+  Raw             - If TRUE, the string is returned unedited in the internal storage format described\r
+                    above. If false, the string returned is edited by replacing <cr> with <space> \r
+                    and by removing special characters such as the <wide> prefix.\r
+  LanguageString  - Pointer to a NULL-terminated string containing a single ISO 639-2 language\r
+                    identifier, indicating the language to print. If the LanguageString is empty (starts\r
+                    with a NULL), the default system language will be used to determine the language.\r
+  BufferLength    - Length of the StringBuffer. If the status reports that the buffer width is too\r
+                    small, this parameter is filled with the length of the buffer needed.\r
+  StringBuffer    - The buffer designed to receive the characters in the string. Type EFI_STRING is\r
+                    defined in String.\r
+\r
+Returns: \r
+  EFI_INVALID_PARAMETER - If input parameter is invalid.\r
+  EFI_BUFFER_TOO_SMALL  - If the *BufferLength is too small.\r
+  EFI_SUCCESS           - Operation is successful.\r
+  \r
+--*/\r
+{\r
+  EFI_HII_PACKAGE_INSTANCE  *PackageInstance;\r
+  EFI_HII_PACKAGE_INSTANCE  *StringPackageInstance;\r
+  EFI_HII_DATA              *HiiData;\r
+  EFI_HII_HANDLE_DATABASE   *HandleDatabase;\r
+  EFI_HII_STRING_PACK       *StringPack;\r
+  RELOFST                   *StringPointer;\r
+  EFI_STATUS                Status;\r
+  UINTN                     DataSize;\r
+  CHAR8                     Lang[3];\r
+  CHAR16                    Language[3];\r
+  UINT32                    Length;\r
+  UINTN                     Count;\r
+  RELOFST                   Offset;\r
+  UINT16                    *Local;\r
+  UINT16                    Zero;\r
+  UINT16                    Narrow;\r
+  UINT16                    Wide;\r
+  UINT16                    NoBreak;\r
+  BOOLEAN                   LangFound;\r
+  UINT16                    *BufferLength = (UINT16 *) BufferLengthTemp;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  LangFound       = TRUE;\r
+\r
+  DataSize        = sizeof (Lang);\r
+\r
+  HiiData         = EFI_HII_DATA_FROM_THIS (This);\r
+\r
+  PackageInstance = NULL;\r
+  Zero            = 0;\r
+  Narrow          = NARROW_CHAR;\r
+  Wide            = WIDE_CHAR;\r
+  NoBreak         = NON_BREAKING_CHAR;\r
+\r
+  //\r
+  // Check numeric value against the head of the database\r
+  //\r
+  for (HandleDatabase = HiiData->DatabaseHead;\r
+       HandleDatabase != NULL;\r
+       HandleDatabase = HandleDatabase->NextHandleDatabase\r
+      ) {\r
+    //\r
+    // Match the numeric value with the database entry - if matched, extract PackageInstance\r
+    //\r
+    if (Handle == HandleDatabase->Handle) {\r
+      PackageInstance = HandleDatabase->Buffer;\r
+      break;\r
+    }\r
+  }\r
+  //\r
+  // No handle was found - error condition\r
+  //\r
+  if (PackageInstance == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = ValidatePack (This, PackageInstance, &StringPackageInstance, NULL);\r
+\r
+  //\r
+  // If there is no specified language, assume the system default language\r
+  //\r
+  if (LanguageString == NULL) {\r
+    //\r
+    // Get system default language\r
+    //\r
+    Status = gRT->GetVariable (\r
+                    (CHAR16 *) L"Lang",\r
+                    &gEfiGlobalVariableGuid,\r
+                    NULL,\r
+                    &DataSize,\r
+                    Lang\r
+                    );\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // If Lang doesn't exist, just use the first language you find\r
+      //\r
+      LangFound = FALSE;\r
+      goto LangNotFound;\r
+    }\r
+    //\r
+    // Convert the ASCII Lang variable to a Unicode Language variable\r
+    //\r
+    AsciiToUnicode ((UINT8 *)Lang, Language);\r
+  } else {\r
+    //\r
+    // Copy input ISO value to Language variable\r
+    //\r
+    CopyMem (Language, LanguageString, 6);\r
+  }\r
+  //\r
+  // Based on if there is IFR data in this package instance, determine\r
+  // what the location is of the beginning of the string data.\r
+  //\r
+LangNotFound:\r
+  if (StringPackageInstance->IfrSize > 0) {\r
+    StringPack = (EFI_HII_STRING_PACK *) ((CHAR8 *) (&StringPackageInstance->IfrData) + StringPackageInstance->IfrSize);\r
+  } else {\r
+    StringPack = (EFI_HII_STRING_PACK *) (&StringPackageInstance->IfrData);\r
+  }\r
+  //\r
+  // If Token is 0, extract entire string package\r
+  //\r
+  if (Token == 0) {\r
+    //\r
+    // Compute the entire string pack length, including all languages' and the terminating pack's.\r
+    //\r
+    Length = 0;\r
+    while (0 != StringPack->Header.Length) {\r
+      Length += StringPack->Header.Length;\r
+      StringPack = (VOID*)(((UINT8*)StringPack) + StringPack->Header.Length);\r
+    }\r
+    //\r
+    // Back to the start of package.\r
+    //\r
+    StringPack = (VOID*)(((UINT8*)StringPack) - Length); \r
+    //\r
+    // Terminating zero sub-pack.\r
+    //\r
+    Length += sizeof (EFI_HII_STRING_PACK); \r
+\r
+    //\r
+    // If trying to get the entire string package and have insufficient space.  Return error.\r
+    //\r
+    if (Length > *BufferLength || StringBuffer == NULL) {\r
+      *BufferLength = (UINT16)Length;\r
+      return EFI_BUFFER_TOO_SMALL;\r
+    }\r
+    //\r
+    // Copy the Pack to the caller's buffer.\r
+    //\r
+    *BufferLength = (UINT16)Length;\r
+    CopyMem (StringBuffer, StringPack, Length);\r
+\r
+    return EFI_SUCCESS;\r
+  }\r
+  //\r
+  // There may be multiple instances packed together of strings\r
+  // so we must walk the self describing structures until we encounter\r
+  // what we are looking for, and then extract the string we are looking for\r
+  //\r
+  CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));\r
+  for (; Length != 0;) {\r
+    //\r
+    // If passed in Language ISO value is in this string pack's language string\r
+    // then we are dealing with the strings we want.\r
+    //\r
+    CopyMem (&Offset, &StringPack->LanguageNameString, sizeof (RELOFST));\r
+    Status = HiiCompareLanguage ((CHAR16 *) ((CHAR8 *) (StringPack) + Offset), Language);\r
+\r
+    //\r
+    // If we cannot find the lang variable, we skip this check and use the first language available\r
+    //\r
+    if (LangFound) {\r
+      if (EFI_ERROR (Status)) {\r
+        StringPack = (EFI_HII_STRING_PACK *) ((CHAR8 *) (StringPack) + Length);\r
+        CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));\r
+        continue;\r
+      }\r
+    }\r
+\r
+    StringPointer = (RELOFST *) (StringPack + 1);\r
+\r
+    //\r
+    // We have the right string package - size it, and copy it to the StringBuffer\r
+    //\r
+    if (Token >= StringPack->NumStringPointers) {\r
+      return EFI_INVALID_PARAMETER;\r
+    } else {\r
+      CopyMem (&Offset, &StringPointer[Token], sizeof (RELOFST));\r
+    }\r
+    //\r
+    // Since StringPack is a packed structure, we need to determine the string's\r
+    // size safely, thus byte-wise.  Post-increment the size to include the null-terminator\r
+    //\r
+    Local = (UINT16 *) ((CHAR8 *) (StringPack) + Offset);\r
+    for (Count = 0; CompareMem (&Local[Count], &Zero, 2); Count++)\r
+      ;\r
+    Count++;\r
+\r
+    Count = Count * sizeof (CHAR16);;\r
+\r
+    if (*BufferLength >= Count && StringBuffer != NULL) {\r
+      //\r
+      // Copy the string to the user's buffer\r
+      //\r
+      if (Raw) {\r
+        CopyMem (StringBuffer, Local, Count);\r
+      } else {\r
+        for (Count = 0; CompareMem (Local, &Zero, 2); Local++) {\r
+          //\r
+          // Skip "Narraw, Wide, NoBreak"\r
+          //\r
+          if (CompareMem (Local, &Narrow,  2) &&\r
+              CompareMem (Local, &Wide,    2) && \r
+              CompareMem (Local, &NoBreak, 2)) {          \r
+            CopyMem (&StringBuffer[Count++], Local, 2);          \r
+          }        \r
+        } \r
+        //\r
+        // Add "NULL" at the end.\r
+        //\r
+        CopyMem (&StringBuffer[Count], &Zero, 2);\r
+        Count++;\r
+        Count *= sizeof (CHAR16);\r
+      }\r
+\r
+      *BufferLength = (UINT16) Count;\r
+      return EFI_SUCCESS;\r
+    } else {\r
+      *BufferLength = (UINT16) Count;\r
+      return EFI_BUFFER_TOO_SMALL;\r
+    }\r
+\r
+  }\r
+\r
+  LangFound = FALSE;\r
+  goto LangNotFound;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+HiiGetLine (\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
+Routine Description:\r
+\r
+  This function allows a program to extract a part of a string of not more than a given width.  \r
+  With repeated calls, this allows a calling program to extract "lines" of text that fit inside \r
+  columns.  The effort of measuring the fit of strings inside columns is localized to this call.\r
+\r
+Arguments:\r
+\r
+Returns: \r
+\r
+--*/\r
+{\r
+  UINTN                     Count;\r
+  EFI_HII_PACKAGE_INSTANCE  *PackageInstance;\r
+  EFI_HII_PACKAGE_INSTANCE  *StringPackageInstance;\r
+  EFI_HII_DATA              *HiiData;\r
+  EFI_HII_HANDLE_DATABASE   *HandleDatabase;\r
+  EFI_HII_STRING_PACK       *StringPack;\r
+  RELOFST                   *StringPointer;\r
+  CHAR16                    *Location;\r
+  EFI_STATUS                Status;\r
+  UINTN                     DataSize;\r
+  CHAR8                     Lang[3];\r
+  CHAR16                    Language[3];\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  HiiData         = EFI_HII_DATA_FROM_THIS (This);\r
+\r
+  HandleDatabase  = HiiData->DatabaseHead;\r
+\r
+  PackageInstance = NULL;\r
+  DataSize        = 4;\r
+\r
+  //\r
+  // Check numeric value against the head of the database\r
+  //\r
+  for (; HandleDatabase != NULL; HandleDatabase = HandleDatabase->NextHandleDatabase) {\r
+    //\r
+    // Match the numeric value with the database entry - if matched, extract PackageInstance\r
+    //\r
+    if (Handle == HandleDatabase->Handle) {\r
+      PackageInstance = HandleDatabase->Buffer;\r
+    }\r
+  }\r
+  //\r
+  // No handle was found - error condition\r
+  //\r
+  if (PackageInstance == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = ValidatePack (This, PackageInstance, &StringPackageInstance, NULL);\r
+\r
+  //\r
+  // If there is no specified language, assume the system default language\r
+  //\r
+  if (LanguageString == NULL) {\r
+    //\r
+    // Get system default language\r
+    //\r
+    Status = gRT->GetVariable (\r
+                    (CHAR16 *) L"Lang",\r
+                    &gEfiGlobalVariableGuid,\r
+                    NULL,\r
+                    &DataSize,\r
+                    Lang\r
+                    );\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+    //\r
+    // Convert the ASCII Lang variable to a Unicode Language variable\r
+    //\r
+    AsciiToUnicode ((UINT8 *)Lang, Language);\r
+  } else {\r
+    //\r
+    // Copy input ISO value to Language variable\r
+    //\r
+    CopyMem (Language, LanguageString, 6);\r
+  }\r
+  //\r
+  // Based on if there is IFR data in this package instance, determine\r
+  // what the location is of the beginning of the string data.\r
+  //\r
+  if (StringPackageInstance->IfrSize > 0) {\r
+    StringPack = (EFI_HII_STRING_PACK *) ((CHAR8 *) (&StringPackageInstance->IfrData) + StringPackageInstance->IfrSize);\r
+  } else {\r
+    StringPack = (EFI_HII_STRING_PACK *) (&StringPackageInstance->IfrData);\r
+  }\r
+\r
+  StringPointer = (RELOFST *) (StringPack + 1);\r
+\r
+  //\r
+  // There may be multiple instances packed together of strings\r
+  // so we must walk the self describing structures until we encounter\r
+  // what we are looking for, and then extract the string we are looking for\r
+  //\r
+  for (; StringPack->Header.Length != 0;) {\r
+    //\r
+    // If passed in Language ISO value is in this string pack's language string\r
+    // then we are dealing with the strings we want.\r
+    //\r
+    Status = HiiCompareLanguage ((CHAR16 *) ((CHAR8 *) (StringPack) + StringPack->LanguageNameString), Language);\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      StringPack = (EFI_HII_STRING_PACK *) ((CHAR8 *) (StringPack) + StringPack->Header.Length);\r
+      continue;\r
+    }\r
+\r
+    Location = (CHAR16 *) ((CHAR8 *) (StringPack) + StringPointer[Token] +*Index * 2);\r
+\r
+    //\r
+    // If the size of the remaining string is less than the LineWidth\r
+    // then copy the entire thing\r
+    //\r
+    if (StrSize (Location) <= LineWidth) {\r
+      if (*BufferLength >= StrSize (Location)) {\r
+        StrCpy (StringBuffer, Location);\r
+        return EFI_SUCCESS;\r
+      } else {\r
+        *BufferLength = (UINT16) StrSize (Location);\r
+        return EFI_BUFFER_TOO_SMALL;\r
+      }\r
+    } else {\r
+      //\r
+      // Rewind the string from the maximum size until we see a space the break the line\r
+      //\r
+      for (Count = LineWidth; Location[Count] != 0x0020; Count--)\r
+        ;\r
+\r
+      //\r
+      // Put the index at the next character\r
+      //\r
+      *Index = (UINT16) (Count + 1);\r
+\r
+      if (*BufferLength >= Count) {\r
+        StrnCpy (StringBuffer, Location, Count);\r
+        return EFI_SUCCESS;\r
+      } else {\r
+        *BufferLength = (UINT16) Count;\r
+        return EFI_BUFFER_TOO_SMALL;\r
+      }\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+HiiCompareLanguage (\r
+  IN  CHAR16                *LanguageStringLocation,\r
+  IN  CHAR16                *Language\r
+  )\r
+{\r
+  UINT8   *Local;\r
+  UINTN   Index;\r
+  CHAR16  *InputString;\r
+  CHAR16  *OriginalInputString;\r
+\r
+  //\r
+  // Allocate a temporary buffer for InputString\r
+  //\r
+  InputString = AllocateZeroPool (0x100);\r
+\r
+  ASSERT (InputString);\r
+\r
+  OriginalInputString = InputString;\r
+\r
+  Local               = (UINT8 *) LanguageStringLocation;\r
+\r
+  //\r
+  // Determine the size of this packed string safely (e.g. access by byte), post-increment\r
+  // to include the null-terminator\r
+  //\r
+  for (Index = 0; Local[Index] != 0; Index = Index + 2)\r
+    ;\r
+  //\r
+  // MARMAR  Index = Index + 2;\r
+  //\r
+  // This is a packed structure that this location comes from, so let's make sure\r
+  // the value is aligned by copying it to a local variable and working on it.\r
+  //\r
+  CopyMem (InputString, LanguageStringLocation, Index);\r
+\r
+  for (Index = 0; Index < 3; Index++) {\r
+    InputString[Index]  = (CHAR16) (InputString[Index] | 0x20);\r
+    Language[Index]     = (CHAR16) (Language[Index] | 0x20);\r
+  }\r
+  //\r
+  // If the Language is the same return success\r
+  //\r
+  if (CompareMem (LanguageStringLocation, Language, 6) == 0) {\r
+    FreePool (InputString);\r
+    return EFI_SUCCESS;\r
+  }\r
+  //\r
+  // Skip the first three letters that comprised the primary language,\r
+  // see if what is being compared against is a secondary language\r
+  //\r
+  InputString = InputString + 3;\r
+\r
+  //\r
+  // If the Language is not the same as the Primary language, see if there are any\r
+  // secondary languages, and if there are see if we have a match.  If not, return an error.\r
+  //\r
+  for (Index = 0; InputString[Index] != 0; Index = Index + 3) {\r
+    //\r
+    // Getting in here means we have a secondary language\r
+    //\r
+    if (CompareMem (&InputString[Index], Language, 6) == 0) {\r
+      FreePool (InputString);\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+  //\r
+  // If nothing was found, return the error\r
+  //\r
+  FreePool (OriginalInputString);\r
+  return EFI_NOT_FOUND;\r
+\r
+}\r
diff --git a/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Boolean.c b/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Boolean.c
new file mode 100644 (file)
index 0000000..b0af07e
--- /dev/null
@@ -0,0 +1,1372 @@
+/*++\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
+  Boolean.c\r
+\r
+Abstract:\r
+\r
+  This routine will evaluate the IFR inconsistency data to determine if\r
+  something is a valid entry for a particular expression\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "Setup.h"\r
+#include "Ui.h"\r
+\r
+//\r
+// Global stack used to evaluate boolean expresions\r
+//\r
+BOOLEAN *mBooleanEvaluationStack    = (BOOLEAN) 0;\r
+BOOLEAN *mBooleanEvaluationStackEnd = (BOOLEAN) 0;\r
+\r
+STATIC\r
+VOID\r
+GrowBooleanStack (\r
+  IN OUT BOOLEAN  **Stack,\r
+  IN     UINTN    StackSizeInBoolean\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Grow size of the boolean stack\r
+\r
+Arguments:\r
+\r
+  Stack     - Old stack on the way in and new stack on the way out\r
+\r
+  StackSizeInBoolean - New size of the stack\r
+\r
+Returns:\r
+\r
+  NONE\r
+\r
+--*/\r
+{\r
+  BOOLEAN *NewStack;\r
+\r
+  NewStack = AllocatePool (StackSizeInBoolean * sizeof (BOOLEAN));\r
+  ASSERT (NewStack != NULL);\r
+\r
+  if (*Stack != NULL) {\r
+    //\r
+    // Copy to Old Stack to the New Stack\r
+    //\r
+    CopyMem (\r
+      NewStack,\r
+      mBooleanEvaluationStack,\r
+      (mBooleanEvaluationStackEnd - mBooleanEvaluationStack) * sizeof (BOOLEAN)\r
+      );\r
+\r
+    //\r
+    // Make the Stack pointer point to the old data in the new stack\r
+    //\r
+    *Stack = NewStack + (*Stack - mBooleanEvaluationStack);\r
+\r
+    //\r
+    // Free The Old Stack\r
+    //\r
+    FreePool (mBooleanEvaluationStack);\r
+  }\r
+\r
+  mBooleanEvaluationStack     = NewStack;\r
+  mBooleanEvaluationStackEnd  = NewStack + StackSizeInBoolean;\r
+}\r
+\r
+STATIC\r
+VOID\r
+InitializeBooleanEvaluator (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Allocate a global stack for boolean processing.\r
+\r
+Arguments:\r
+\r
+  NONE\r
+\r
+Returns:\r
+\r
+  NONE\r
+\r
+--*/\r
+{\r
+  BOOLEAN *NullStack;\r
+\r
+  NullStack = NULL;\r
+  GrowBooleanStack (&NullStack, 0x1000);\r
+}\r
+\r
+STATIC\r
+VOID\r
+PushBool (\r
+  IN OUT BOOLEAN  **Stack,\r
+  IN BOOLEAN      BoolResult\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Push an element onto the Boolean Stack\r
+\r
+Arguments:\r
+\r
+  Stack      - Current stack location.\r
+  BoolResult - BOOLEAN to push.\r
+\r
+Returns:\r
+\r
+  None.\r
+\r
+--*/\r
+{\r
+  CopyMem (*Stack, &BoolResult, sizeof (BOOLEAN));\r
+  *Stack += 1;\r
+\r
+  if (*Stack >= mBooleanEvaluationStackEnd) {\r
+    //\r
+    // If we run out of stack space make a new one that is 2X as big. Copy\r
+    // the old data into the new stack and update Stack to point to the old\r
+    // data in the new stack.\r
+    //\r
+    GrowBooleanStack (\r
+      Stack,\r
+      (mBooleanEvaluationStackEnd - mBooleanEvaluationStack) * sizeof (BOOLEAN) * 2\r
+      );\r
+  }\r
+}\r
+\r
+STATIC\r
+BOOLEAN\r
+PopBool (\r
+  IN OUT BOOLEAN **Stack\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Pop an element from the Boolean stack.\r
+\r
+Arguments:\r
+\r
+  Stack - Current stack location\r
+\r
+Returns:\r
+\r
+  Top of the BOOLEAN stack.\r
+\r
+--*/\r
+{\r
+  BOOLEAN ReturnValue;\r
+\r
+  *Stack -= 1;\r
+  CopyMem (&ReturnValue, *Stack, sizeof (BOOLEAN));\r
+  return ReturnValue;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+GrowBooleanExpression (\r
+  IN      EFI_INCONSISTENCY_DATA  *InconsistentTags,\r
+  OUT     VOID                    **BooleanExpression,\r
+  IN OUT  UINTN                   *BooleanExpressionLength\r
+  )\r
+{\r
+  UINT8 *NewExpression;\r
+\r
+  NewExpression = AllocatePool (*BooleanExpressionLength + sizeof (EFI_INCONSISTENCY_DATA));\r
+  ASSERT (NewExpression != NULL);\r
+\r
+  if (*BooleanExpression != NULL) {\r
+    //\r
+    // Copy Old buffer to the New buffer\r
+    //\r
+    CopyMem (NewExpression, *BooleanExpression, *BooleanExpressionLength);\r
+\r
+    CopyMem (&NewExpression[*BooleanExpressionLength], InconsistentTags, sizeof (EFI_INCONSISTENCY_DATA));\r
+\r
+    //\r
+    // Free The Old buffer\r
+    //\r
+    FreePool (*BooleanExpression);\r
+  } else {\r
+    //\r
+    // Copy data into new buffer\r
+    //\r
+    CopyMem (NewExpression, InconsistentTags, sizeof (EFI_INCONSISTENCY_DATA));\r
+  }\r
+\r
+  *BooleanExpressionLength  = *BooleanExpressionLength + sizeof (EFI_INCONSISTENCY_DATA);\r
+  *BooleanExpression        = (VOID *) NewExpression;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+VOID\r
+CreateBooleanExpression (\r
+  IN  EFI_FILE_FORM_TAGS    *FileFormTags,\r
+  IN  UINT16                Value,\r
+  IN  UINT16                Id,\r
+  IN  BOOLEAN               Complex,\r
+  OUT VOID                  **BooleanExpression,\r
+  OUT UINTN                 *BooleanExpressionLength\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  UINTN                   Count;\r
+  EFI_INCONSISTENCY_DATA  *InconsistentTags;\r
+  EFI_INCONSISTENCY_DATA  FakeInconsistentTags;\r
+\r
+  InconsistentTags = FileFormTags->InconsistentTags;\r
+\r
+  //\r
+  // Did we run into a question that contains the Id we are looking for?\r
+  //\r
+  for (Count = 0; InconsistentTags->Operand != 0xFF; Count++) {\r
+\r
+    //\r
+    // Reserve INVALID_OFFSET_VALUE - 1 for TURE and FALSE, because we need to treat them as well\r
+    // as ideqid etc. but they have no coresponding id, so we reserve this value.\r
+    //\r
+    if (InconsistentTags->QuestionId1 == Id ||\r
+        InconsistentTags->QuestionId1 == INVALID_OFFSET_VALUE - 1) {\r
+      //\r
+      // If !Complex - means evaluate a single if/endif expression\r
+      //\r
+      if (!Complex) {\r
+        //\r
+        // If the ConsistencyId does not match the expression we are looking for\r
+        // skip to the next consistency database entry\r
+        //\r
+        if (InconsistentTags->ConsistencyId != Value) {\r
+          goto NextEntry;\r
+        }\r
+      }\r
+      //\r
+      // We need to rewind to the beginning of the Inconsistent expression\r
+      //\r
+      for (;\r
+           (InconsistentTags->Operand != EFI_IFR_INCONSISTENT_IF_OP) &&\r
+             (InconsistentTags->Operand != EFI_IFR_GRAYOUT_IF_OP) &&\r
+             (InconsistentTags->Operand != EFI_IFR_SUPPRESS_IF_OP);\r
+              ) {\r
+        InconsistentTags = InconsistentTags->Previous;\r
+      }\r
+      //\r
+      // Store the consistency check expression, ensure the next for loop starts at the op-code afterwards\r
+      //\r
+      GrowBooleanExpression (InconsistentTags, BooleanExpression, BooleanExpressionLength);\r
+      InconsistentTags = InconsistentTags->Next;\r
+\r
+      //\r
+      // Keep growing until we hit the End expression op-code or we hit the beginning of another\r
+      // consistency check like grayout/suppress\r
+      //\r
+      for (;\r
+           InconsistentTags->Operand != EFI_IFR_END_IF_OP &&\r
+           InconsistentTags->Operand != EFI_IFR_GRAYOUT_IF_OP &&\r
+           InconsistentTags->Operand != EFI_IFR_SUPPRESS_IF_OP;\r
+            ) {\r
+        GrowBooleanExpression (InconsistentTags, BooleanExpression, BooleanExpressionLength);\r
+        InconsistentTags = InconsistentTags->Next;\r
+      }\r
+      //\r
+      // Store the EndExpression Op-code\r
+      //\r
+      GrowBooleanExpression (InconsistentTags, BooleanExpression, BooleanExpressionLength);\r
+    }\r
+\r
+NextEntry:\r
+    if (InconsistentTags->Next != NULL) {\r
+      //\r
+      // Skip to next entry\r
+      //\r
+      InconsistentTags = InconsistentTags->Next;\r
+    }\r
+  }\r
+\r
+  FakeInconsistentTags.Operand = 0;\r
+\r
+  //\r
+  // Add one last expression which will signify we have definitely hit the end\r
+  //\r
+  GrowBooleanExpression (&FakeInconsistentTags, BooleanExpression, BooleanExpressionLength);\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+BooleanVariableWorker (\r
+  IN     CHAR16                   *VariableName,\r
+  IN     EFI_VARIABLE_DEFINITION  *VariableDefinition,\r
+  IN     BOOLEAN                  *StackPtr,\r
+  IN OUT UINTN                    *SizeOfVariable,\r
+  IN OUT VOID                     **VariableData\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  Status = gRT->GetVariable (\r
+                  VariableName,\r
+                  &VariableDefinition->Guid,\r
+                  NULL,\r
+                  SizeOfVariable,\r
+                  *VariableData\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+\r
+    if (Status == EFI_BUFFER_TOO_SMALL) {\r
+      *VariableData = AllocatePool (*SizeOfVariable);\r
+      ASSERT (*VariableData != NULL);\r
+\r
+      Status = gRT->GetVariable (\r
+                      VariableName,\r
+                      &VariableDefinition->Guid,\r
+                      NULL,\r
+                      SizeOfVariable,\r
+                      *VariableData\r
+                      );\r
+    }\r
+\r
+    if (Status == EFI_NOT_FOUND) {\r
+      //\r
+      // This is a serious flaw, we must have some standard result if a variable\r
+      // is not found.  Our default behavior must either be return a TRUE or FALSE\r
+      // since there is nothing else we can really do.  Therefore, my crystal ball\r
+      // says I will return a FALSE\r
+      //\r
+      PushBool (&StackPtr, FALSE);\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+UINT8\r
+PredicateIfrType (\r
+  IN  EFI_INCONSISTENCY_DATA      *Iterator\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  This routine is for the purpose of predicate whether the Ifr is generated by a VfrCompiler greater than or equal to 1.88 or\r
+  less than 1.88 which is legacy.\r
+\r
+Arguments:\r
+  Iterator    - The pointer to inconsistency tags\r
+\r
+Returns:\r
+\r
+  0x2         - If IFR is not legacy\r
+\r
+  0x1         - If IFR is legacy\r
+\r
+--*/\r
+{\r
+  //\r
+  // legacy Ifr cover the states:\r
+  // Not ...\r
+  // Operand Opcode Operand\r
+  //\r
+  // while Operand means ideqval, TRUE, or other what can be evaluated to True or False,\r
+  // and Opcode means AND or OR.\r
+  //\r
+  if (Iterator->Operand == EFI_IFR_NOT_OP   ||\r
+      Iterator->Operand == 0) {\r
+    return 0x1;\r
+  } else if (Iterator->Operand == EFI_IFR_EQ_VAR_VAL_OP ||\r
+             Iterator->Operand == EFI_IFR_EQ_ID_VAL_OP  ||\r
+             Iterator->Operand == EFI_IFR_EQ_ID_ID_OP   ||\r
+             Iterator->Operand == EFI_IFR_EQ_ID_LIST_OP) {\r
+    Iterator++;\r
+    if (Iterator->Operand == EFI_IFR_AND_OP ||\r
+        Iterator->Operand == EFI_IFR_OR_OP) {\r
+      Iterator--;\r
+      return 0x1;\r
+    }\r
+    Iterator--;\r
+  }\r
+  return 0x2;\r
+}\r
+\r
+STATIC\r
+VOID\r
+PostOrderEvaluate (\r
+  IN      EFI_FILE_FORM_TAGS          *FileFormTags,\r
+  IN      UINT16                      Width,\r
+  IN OUT  EFI_INCONSISTENCY_DATA      **PIterator,\r
+  IN OUT  BOOLEAN                     **StackPtr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  PostOrderEvaluate is used for Ifr generated by VfrCompiler greater than or equal to 1.88,\r
+  which generate Operand Operand Opcode type Ifr.\r
+  PostOrderEvaluete only evaluate boolean expression part, not suppressif/grayoutif. TRUE,\r
+  FALSE, >=, >, (, ) are supported.\r
+\r
+Arguments:\r
+\r
+  FileFormTags     - The pointer to the tags of the form\r
+\r
+  Width            - Width of Operand, recognized every iteration\r
+\r
+  PIterator        - The pointer to inconsistency tags\r
+\r
+  StackPtr         - The pointer to the evaluation stack\r
+\r
+Returns:\r
+\r
+  TRUE             - If value is valid\r
+\r
+  FALSE            - If value is not valid\r
+\r
+--*/\r
+{\r
+  BOOLEAN                 Operator;\r
+  BOOLEAN                 Operator2;\r
+  UINT16                  *MapBuffer;\r
+  UINT16                  *MapBuffer2;\r
+  UINT16                  MapValue;\r
+  UINT16                  MapValue2;\r
+  UINTN                   SizeOfVariable;\r
+  CHAR16                  VariableName[MAXIMUM_VALUE_CHARACTERS];\r
+  VOID                    *VariableData;\r
+  EFI_VARIABLE_DEFINITION *VariableDefinition;\r
+  EFI_STATUS              Status;\r
+  UINTN                   Index;\r
+  BOOLEAN                 PushValue;\r
+\r
+  Operator        = FALSE;\r
+  Operator2       = FALSE;\r
+  MapBuffer       = NULL;\r
+  MapBuffer2      = NULL;\r
+  MapValue        = 0;\r
+  MapValue2       = 0;\r
+  VariableData    = NULL;\r
+\r
+  while (TRUE) {\r
+    if ((*PIterator)->Operand == 0) {\r
+      return;\r
+    }\r
+\r
+    Width = (*PIterator)->Width;\r
+\r
+    //\r
+    //  Because INVALID_OFFSET_VALUE - 1 is reserved for TRUE or FALSE, omit them.\r
+    //\r
+    if ((*PIterator)->QuestionId1 != INVALID_OFFSET_VALUE &&\r
+        (*PIterator)->QuestionId1 != INVALID_OFFSET_VALUE - 1) {\r
+      ExtractNvValue (FileFormTags, (*PIterator)->VariableNumber, Width, (*PIterator)->QuestionId1, (VOID **) &MapBuffer);\r
+      ExtractNvValue (FileFormTags, (*PIterator)->VariableNumber2, Width, (*PIterator)->QuestionId2, (VOID **) &MapBuffer2);\r
+      if (MapBuffer != NULL) {\r
+        if (Width == 2) {\r
+          MapValue = *MapBuffer;\r
+        } else {\r
+          MapValue = (UINT8) *MapBuffer;\r
+        }\r
+\r
+        FreePool (MapBuffer);\r
+      }\r
+\r
+      if (MapBuffer2 != NULL) {\r
+        if (Width == 2) {\r
+          MapValue2 = *MapBuffer2;\r
+        } else {\r
+          MapValue2 = (UINT8) *MapBuffer2;\r
+        }\r
+\r
+        FreePool (MapBuffer2);\r
+      }\r
+    }\r
+\r
+    switch ((*PIterator)->Operand) {\r
+    case EFI_IFR_EQ_VAR_VAL_OP:\r
+      UnicodeValueToString (\r
+        VariableName,\r
+        FALSE,\r
+        (UINTN) (*PIterator)->QuestionId1,\r
+        (sizeof (VariableName) / sizeof (VariableName[0])) - 1\r
+        );\r
+\r
+      SizeOfVariable = 0;\r
+\r
+      ExtractRequestedNvMap (FileFormTags, (*PIterator)->VariableNumber, &VariableDefinition);\r
+\r
+      Status = BooleanVariableWorker (\r
+                VariableName,\r
+                VariableDefinition,\r
+                *StackPtr,\r
+                &SizeOfVariable,\r
+                &VariableData\r
+                );\r
+\r
+      if (!EFI_ERROR (Status)) {\r
+        if (SizeOfVariable == 1) {\r
+          CopyMem (&MapValue, VariableData, 1);\r
+        } else {\r
+          CopyMem (&MapValue, VariableData, 2);\r
+        }\r
+\r
+        //\r
+        // Do operation after knowing the compare operator.\r
+        //\r
+        MapValue2 = (*PIterator)->Value;\r
+        (*PIterator)++;\r
+        if ((*PIterator)->Operand == EFI_IFR_GT_OP) {\r
+          PushValue = (BOOLEAN) (MapValue > MapValue2);\r
+        } else if ((*PIterator)->Operand == EFI_IFR_GE_OP) {\r
+          PushValue = (BOOLEAN) (MapValue >= MapValue2);\r
+        } else {\r
+          (*PIterator)--;\r
+          PushValue = (BOOLEAN) (MapValue == MapValue2);\r
+        }\r
+        PushBool (StackPtr, PushValue);\r
+      }\r
+\r
+      break;\r
+\r
+    case EFI_IFR_EQ_ID_VAL_OP:\r
+      //\r
+      // Do operation after knowing the compare operator.\r
+      //\r
+      MapValue2 = (*PIterator)->Value;\r
+      (*PIterator)++;\r
+      if ((*PIterator)->Operand == EFI_IFR_GT_OP) {\r
+        PushValue = (BOOLEAN) (MapValue > MapValue2);\r
+      } else if ((*PIterator)->Operand == EFI_IFR_GE_OP) {\r
+        PushValue = (BOOLEAN) (MapValue >= MapValue2);\r
+      } else {\r
+        (*PIterator)--;\r
+        PushValue = (BOOLEAN) (MapValue == MapValue2);\r
+      }\r
+      PushBool (StackPtr, PushValue);\r
+      break;\r
+\r
+    case EFI_IFR_EQ_ID_ID_OP:\r
+      //\r
+      // Do operation after knowing the compare operator.\r
+      //\r
+      (*PIterator)++;\r
+      if ((*PIterator)->Operand == EFI_IFR_GT_OP) {\r
+        PushValue = (BOOLEAN) (MapValue > MapValue2);\r
+      } else if ((*PIterator)->Operand == EFI_IFR_GE_OP) {\r
+        PushValue = (BOOLEAN) (MapValue >= MapValue2);\r
+      } else {\r
+        (*PIterator)--;\r
+        PushValue = (BOOLEAN) (MapValue == MapValue2);\r
+      }\r
+      PushBool (StackPtr, PushValue);\r
+      break;\r
+\r
+    case EFI_IFR_EQ_ID_LIST_OP:\r
+      for (Index = 0; Index < (*PIterator)->ListLength; Index++) {\r
+        Operator = (BOOLEAN) (MapValue == (*PIterator)->ValueList[Index]);\r
+        if (Operator) {\r
+          break;\r
+        }\r
+      }\r
+\r
+      PushBool (StackPtr, Operator);\r
+      break;\r
+\r
+    case EFI_IFR_TRUE_OP:\r
+      PushBool (StackPtr, TRUE);\r
+      break;\r
+\r
+    case EFI_IFR_FALSE_OP:\r
+      PushBool (StackPtr, FALSE);\r
+      break;\r
+\r
+    case EFI_IFR_AND_OP:\r
+      Operator  = PopBool (StackPtr);\r
+      Operator2 = PopBool (StackPtr);\r
+      PushBool (StackPtr, (BOOLEAN) (Operator && Operator2));\r
+      break;\r
+    case EFI_IFR_OR_OP:\r
+      Operator  = PopBool (StackPtr);\r
+      Operator2 = PopBool (StackPtr);\r
+      PushBool (StackPtr, (BOOLEAN) (Operator || Operator2));\r
+      break;\r
+    case EFI_IFR_NOT_OP:\r
+      Operator  = PopBool (StackPtr);\r
+      PushBool (StackPtr, (BOOLEAN) (!Operator));\r
+      break;\r
+\r
+    case EFI_IFR_SUPPRESS_IF_OP:\r
+    case EFI_IFR_GRAYOUT_IF_OP:\r
+    case EFI_IFR_INCONSISTENT_IF_OP:\r
+    default:\r
+      //\r
+      // Return to the previous tag if runs out of boolean expression.\r
+      //\r
+      (*PIterator)--;\r
+      return;\r
+    }\r
+    (*PIterator)++;\r
+  }\r
+}\r
+\r
+BOOLEAN\r
+ValueIsNotValid (\r
+  IN  BOOLEAN                     Complex,\r
+  IN  UINT16                      Value,\r
+  IN  EFI_TAG                     *Tag,\r
+  IN  EFI_FILE_FORM_TAGS          *FileFormTags,\r
+  IN  STRING_REF                  *PopUp\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  TRUE - If value is valid\r
+\r
+  FALSE - If value is not valid\r
+\r
+--*/\r
+{\r
+  BOOLEAN                 *StackPtr;\r
+  EFI_INCONSISTENCY_DATA  *Iterator;\r
+  BOOLEAN                 Operator;\r
+  BOOLEAN                 Operator2;\r
+  UINTN                   Index;\r
+  VOID                    *BooleanExpression;\r
+  UINTN                   BooleanExpressionLength;\r
+  BOOLEAN                 NotOperator;\r
+  BOOLEAN                 OrOperator;\r
+  BOOLEAN                 AndOperator;\r
+  BOOLEAN                 ArtificialEnd;\r
+  UINT16                  *MapBuffer;\r
+  UINT16                  *MapBuffer2;\r
+  UINT16                  MapValue;\r
+  UINT16                  MapValue2;\r
+  UINTN                   SizeOfVariable;\r
+  CHAR16                  VariableName[MAXIMUM_VALUE_CHARACTERS];\r
+  VOID                    *VariableData;\r
+  EFI_STATUS              Status;\r
+  UINT16                  Id;\r
+  UINT16                  Width;\r
+  EFI_VARIABLE_DEFINITION *VariableDefinition;\r
+  BOOLEAN                 CosmeticConsistency;\r
+  UINT8                   IsLegacy;\r
+\r
+  VariableData            = NULL;\r
+  BooleanExpressionLength = 0;\r
+  BooleanExpression       = NULL;\r
+  Operator                = FALSE;\r
+  ArtificialEnd           = FALSE;\r
+  CosmeticConsistency     = TRUE;\r
+  IsLegacy                = 0;\r
+\r
+  Id                      = Tag->Id;\r
+  if (Tag->StorageWidth == 1) {\r
+    Width = 1;\r
+  } else {\r
+    Width = 2;\r
+  }\r
+  CreateBooleanExpression (FileFormTags, Value, Id, Complex, &BooleanExpression, &BooleanExpressionLength);\r
+\r
+  if (mBooleanEvaluationStack == 0) {\r
+    InitializeBooleanEvaluator ();\r
+  }\r
+\r
+  if (BooleanExpression == NULL) {\r
+    return FALSE;\r
+  }\r
+\r
+  StackPtr    = mBooleanEvaluationStack;\r
+  Iterator    = BooleanExpression;\r
+  MapBuffer   = NULL;\r
+  MapBuffer2  = NULL;\r
+  MapValue    = 0;\r
+  MapValue2   = 0;\r
+\r
+  while (TRUE) {\r
+    NotOperator = FALSE;\r
+    OrOperator  = FALSE;\r
+    AndOperator = FALSE;\r
+\r
+    if (Iterator->Operand == 0) {\r
+      return Operator;\r
+    }\r
+\r
+    //\r
+    //  Because INVALID_OFFSET_VALUE - 1 is reserved for TRUE or FALSE, omit them.\r
+    //\r
+    if (Iterator->QuestionId1 != INVALID_OFFSET_VALUE &&\r
+        Iterator->QuestionId1 != INVALID_OFFSET_VALUE-1) {\r
+      ExtractNvValue (FileFormTags, Iterator->VariableNumber, Width, Iterator->QuestionId1, (VOID **) &MapBuffer);\r
+      ExtractNvValue (FileFormTags, Iterator->VariableNumber2, Width, Iterator->QuestionId2, (VOID **) &MapBuffer2);\r
+      if (MapBuffer != NULL) {\r
+        if (Width == 2) {\r
+          MapValue = *MapBuffer;\r
+        } else {\r
+          MapValue = (UINT8) *MapBuffer;\r
+        }\r
+\r
+        FreePool (MapBuffer);\r
+      }\r
+\r
+      if (MapBuffer2 != NULL) {\r
+        if (Width == 2) {\r
+          MapValue2 = *MapBuffer2;\r
+        } else {\r
+          MapValue2 = (UINT8) *MapBuffer2;\r
+        }\r
+\r
+        FreePool (MapBuffer2);\r
+      }\r
+    }\r
+\r
+    switch (Iterator->Operand) {\r
+    case EFI_IFR_SUPPRESS_IF_OP:\r
+      //\r
+      // Must have hit a suppress followed by a grayout or vice-versa\r
+      //\r
+      if (ArtificialEnd) {\r
+        ArtificialEnd = FALSE;\r
+        Operator      = PopBool (&StackPtr);\r
+        if (Operator) {\r
+          Tag->Suppress = TRUE;\r
+        }\r
+\r
+        return Operator;\r
+      }\r
+\r
+      ArtificialEnd = TRUE;\r
+      *PopUp        = Iterator->Popup;\r
+      break;\r
+\r
+    case EFI_IFR_GRAYOUT_IF_OP:\r
+      //\r
+      // Must have hit a suppress followed by a grayout or vice-versa\r
+      //\r
+      if (ArtificialEnd) {\r
+        ArtificialEnd = FALSE;\r
+        Operator      = PopBool (&StackPtr);\r
+        if (Operator) {\r
+          Tag->GrayOut = TRUE;\r
+        }\r
+\r
+        return Operator;\r
+      }\r
+\r
+      ArtificialEnd = TRUE;\r
+      *PopUp        = Iterator->Popup;\r
+      break;\r
+\r
+    case EFI_IFR_INCONSISTENT_IF_OP:\r
+      CosmeticConsistency = FALSE;\r
+      *PopUp              = Iterator->Popup;\r
+      break;\r
+\r
+    //\r
+    // In the case of external variable values, we must read the variable which is\r
+    // named by the human readable version of the OpCode->VariableId and the guid of the formset\r
+    //\r
+    case EFI_IFR_EQ_VAR_VAL_OP:\r
+      //\r
+      // To check whether Ifr is legacy. Once every boolean expression.\r
+      //\r
+      if (IsLegacy == 0) {\r
+        IsLegacy = PredicateIfrType (Iterator);\r
+      }\r
+      if (IsLegacy == 0x2) {\r
+        PostOrderEvaluate (FileFormTags, Width, &Iterator, &StackPtr);\r
+        break;\r
+      }\r
+\r
+      UnicodeValueToString (\r
+        VariableName,\r
+        FALSE,\r
+        (UINTN) Iterator->QuestionId1,\r
+        (sizeof (VariableName) / sizeof (VariableName[0])) - 1\r
+        );\r
+\r
+      SizeOfVariable = 0;\r
+\r
+      ExtractRequestedNvMap (FileFormTags, Iterator->VariableNumber, &VariableDefinition);\r
+\r
+      Status = BooleanVariableWorker (\r
+                VariableName,\r
+                VariableDefinition,\r
+                StackPtr,\r
+                &SizeOfVariable,\r
+                &VariableData\r
+                );\r
+\r
+      if (!EFI_ERROR (Status)) {\r
+        if (SizeOfVariable == 1) {\r
+          CopyMem (&MapValue, VariableData, 1);\r
+        } else {\r
+          CopyMem (&MapValue, VariableData, 2);\r
+        }\r
+\r
+        PushBool (&StackPtr, (BOOLEAN) (MapValue == Iterator->Value));\r
+      }\r
+\r
+      break;\r
+\r
+    case EFI_IFR_EQ_ID_VAL_OP:\r
+      //\r
+      // To check whether Ifr is legacy. Once every boolean expression.\r
+      //\r
+      if (IsLegacy == 0) {\r
+        IsLegacy = PredicateIfrType (Iterator);\r
+      }\r
+      if (IsLegacy == 0x2) {\r
+        PostOrderEvaluate (FileFormTags, Width, &Iterator, &StackPtr);\r
+        break;\r
+      }\r
+\r
+      PushBool (&StackPtr, (BOOLEAN) (MapValue == Iterator->Value));\r
+      break;\r
+\r
+    case EFI_IFR_EQ_ID_ID_OP:\r
+      //\r
+      // To check whether Ifr is legacy. Once every boolean expression.\r
+      //\r
+      if (IsLegacy == 0) {\r
+        IsLegacy = PredicateIfrType (Iterator);\r
+      }\r
+      if (IsLegacy == 0x2) {\r
+        PostOrderEvaluate (FileFormTags, Width, &Iterator, &StackPtr);\r
+        break;\r
+      }\r
+\r
+      PushBool (&StackPtr, (BOOLEAN) (MapValue == MapValue2));\r
+      break;\r
+\r
+    case EFI_IFR_EQ_ID_LIST_OP:\r
+      //\r
+      // To check whether Ifr is legacy. Once every boolean expression.\r
+      //\r
+      if (IsLegacy == 0) {\r
+        IsLegacy = PredicateIfrType (Iterator);\r
+      }\r
+      if (IsLegacy == 0x2) {\r
+        PostOrderEvaluate (FileFormTags, Width, &Iterator, &StackPtr);\r
+        break;\r
+      }\r
+\r
+      for (Index = 0; Index < Iterator->ListLength; Index++) {\r
+        Operator = (BOOLEAN) (MapValue == Iterator->ValueList[Index]);\r
+        if (Operator) {\r
+          break;\r
+        }\r
+      }\r
+\r
+      PushBool (&StackPtr, Operator);\r
+      break;\r
+\r
+    case EFI_IFR_AND_OP:\r
+      Iterator++;\r
+      if (Iterator->Operand == EFI_IFR_NOT_OP) {\r
+        NotOperator = TRUE;\r
+        Iterator++;\r
+      }\r
+\r
+      if (Iterator->QuestionId1 != INVALID_OFFSET_VALUE) {\r
+        ExtractNvValue (FileFormTags, Iterator->VariableNumber, Width, Iterator->QuestionId1, (VOID **) &MapBuffer);\r
+        ExtractNvValue (FileFormTags, Iterator->VariableNumber2, Width, Iterator->QuestionId2, (VOID **) &MapBuffer2);\r
+        if (MapBuffer != NULL) {\r
+          if (Width == 2) {\r
+            MapValue = *MapBuffer;\r
+          } else {\r
+            MapValue = (UINT8) *MapBuffer;\r
+          }\r
+\r
+          FreePool (MapBuffer);\r
+        }\r
+\r
+        if (MapBuffer2 != NULL) {\r
+          if (Width == 2) {\r
+            MapValue2 = *MapBuffer2;\r
+          } else {\r
+            MapValue2 = (UINT8) *MapBuffer2;\r
+          }\r
+\r
+          FreePool (MapBuffer2);\r
+        }\r
+      }\r
+\r
+      switch (Iterator->Operand) {\r
+      case EFI_IFR_EQ_ID_VAL_OP:\r
+        //\r
+        // If Not - flip the results\r
+        //\r
+        if (NotOperator) {\r
+          Operator = (BOOLEAN)!(MapValue == Iterator->Value);\r
+        } else {\r
+          Operator = (BOOLEAN) (MapValue == Iterator->Value);\r
+        }\r
+\r
+        PushBool (&StackPtr, Operator);\r
+        break;\r
+\r
+      //\r
+      // In the case of external variable values, we must read the variable which is\r
+      // named by the human readable version of the OpCode->VariableId and the guid of the formset\r
+      //\r
+      case EFI_IFR_EQ_VAR_VAL_OP:\r
+        UnicodeValueToString (\r
+          VariableName,\r
+          FALSE,\r
+          (UINTN) Iterator->QuestionId1,\r
+          (sizeof (VariableName) / sizeof (VariableName[0])) - 1\r
+          );\r
+\r
+        SizeOfVariable = 0;\r
+\r
+        ExtractRequestedNvMap (FileFormTags, Iterator->VariableNumber, &VariableDefinition);\r
+\r
+        Status = BooleanVariableWorker (\r
+                  VariableName,\r
+                  VariableDefinition,\r
+                  StackPtr,\r
+                  &SizeOfVariable,\r
+                  &VariableData\r
+                  );\r
+\r
+        if (!EFI_ERROR (Status)) {\r
+          if (SizeOfVariable == 1) {\r
+            CopyMem (&MapValue, VariableData, 1);\r
+          } else {\r
+            CopyMem (&MapValue, VariableData, 2);\r
+          }\r
+          //\r
+          // If Not - flip the results\r
+          //\r
+          if (NotOperator) {\r
+            PushBool (&StackPtr, (BOOLEAN)!(MapValue == Iterator->Value));\r
+          } else {\r
+            PushBool (&StackPtr, (BOOLEAN) (MapValue == Iterator->Value));\r
+          }\r
+        }\r
+        break;\r
+\r
+      case EFI_IFR_EQ_ID_ID_OP:\r
+        //\r
+        // If Not - flip the results\r
+        //\r
+        if (NotOperator) {\r
+          Operator = (BOOLEAN)!(MapValue == MapValue2);\r
+        } else {\r
+          Operator = (BOOLEAN) (MapValue == MapValue2);\r
+        }\r
+\r
+        PushBool (&StackPtr, Operator);\r
+        break;\r
+\r
+      case EFI_IFR_EQ_ID_LIST_OP:\r
+        for (Index = 0; Index < Iterator->ListLength; Index++) {\r
+          //\r
+          // If Not - flip the results\r
+          //\r
+          if (NotOperator) {\r
+            Operator = (BOOLEAN)!(MapValue == Iterator->ValueList[Index]);\r
+          } else {\r
+            Operator = (BOOLEAN) (MapValue == Iterator->ValueList[Index]);\r
+          }\r
+          //\r
+          // If We are trying to make sure that MapValue != Item[x], keep looking through\r
+          // the list to make sure we don't equal any other items\r
+          //\r
+          if (Operator && NotOperator) {\r
+            continue;\r
+          }\r
+          //\r
+          // If MapValue == Item, then we have succeeded (first found is good enough)\r
+          //\r
+          if (Operator) {\r
+            break;\r
+          }\r
+        }\r
+\r
+        PushBool (&StackPtr, Operator);\r
+        break;\r
+\r
+      default:\r
+        return FALSE;\r
+      }\r
+\r
+      Operator  = PopBool (&StackPtr);\r
+      Operator2 = PopBool (&StackPtr);\r
+      PushBool (&StackPtr, (BOOLEAN) (Operator && Operator2));\r
+      break;\r
+\r
+    case EFI_IFR_OR_OP:\r
+      Iterator++;\r
+      if (Iterator->Operand == EFI_IFR_NOT_OP) {\r
+        NotOperator = TRUE;\r
+        Iterator++;\r
+      }\r
+\r
+      if (Iterator->QuestionId1 != INVALID_OFFSET_VALUE) {\r
+        ExtractNvValue (FileFormTags, Iterator->VariableNumber, Width, Iterator->QuestionId1, (VOID **) &MapBuffer);\r
+        ExtractNvValue (FileFormTags, Iterator->VariableNumber2, Width, Iterator->QuestionId2, (VOID **) &MapBuffer2);\r
+        if (MapBuffer != NULL) {\r
+          if (Width == 2) {\r
+            MapValue = *MapBuffer;\r
+          } else {\r
+            MapValue = (UINT8) *MapBuffer;\r
+          }\r
+\r
+          FreePool (MapBuffer);\r
+        }\r
+\r
+        if (MapBuffer2 != NULL) {\r
+          if (Width == 2) {\r
+            MapValue2 = *MapBuffer2;\r
+          } else {\r
+            MapValue2 = (UINT8) *MapBuffer2;\r
+          }\r
+\r
+          FreePool (MapBuffer2);\r
+        }\r
+      }\r
+\r
+      switch (Iterator->Operand) {\r
+      case EFI_IFR_EQ_ID_VAL_OP:\r
+        //\r
+        // If Not - flip the results\r
+        //\r
+        if (NotOperator) {\r
+          Operator = (BOOLEAN)!(MapValue == Iterator->Value);\r
+        } else {\r
+          Operator = (BOOLEAN) (MapValue == Iterator->Value);\r
+        }\r
+\r
+        PushBool (&StackPtr, Operator);\r
+        break;\r
+\r
+      //\r
+      // In the case of external variable values, we must read the variable which is\r
+      // named by the human readable version of the OpCode->VariableId and the guid of the formset\r
+      //\r
+      case EFI_IFR_EQ_VAR_VAL_OP:\r
+        UnicodeValueToString (\r
+          VariableName,\r
+          FALSE,\r
+          (UINTN) Iterator->QuestionId1,\r
+          (sizeof (VariableName) / sizeof (VariableName[0])) - 1\r
+          );\r
+\r
+        SizeOfVariable = 0;\r
+\r
+        ExtractRequestedNvMap (FileFormTags, Iterator->VariableNumber, &VariableDefinition);\r
+\r
+        Status = BooleanVariableWorker (\r
+                  VariableName,\r
+                  VariableDefinition,\r
+                  StackPtr,\r
+                  &SizeOfVariable,\r
+                  &VariableData\r
+                  );\r
+\r
+        if (!EFI_ERROR (Status)) {\r
+          if (SizeOfVariable == 1) {\r
+            CopyMem (&MapValue, VariableData, 1);\r
+          } else {\r
+            CopyMem (&MapValue, VariableData, 2);\r
+          }\r
+          //\r
+          // If Not - flip the results\r
+          //\r
+          if (NotOperator) {\r
+            PushBool (&StackPtr, (BOOLEAN)!(MapValue == Iterator->Value));\r
+          } else {\r
+            PushBool (&StackPtr, (BOOLEAN) (MapValue == Iterator->Value));\r
+          }\r
+        }\r
+        break;\r
+\r
+      case EFI_IFR_EQ_ID_ID_OP:\r
+        //\r
+        // If Not - flip the results\r
+        //\r
+        if (NotOperator) {\r
+          Operator = (BOOLEAN)!(MapValue == MapValue2);\r
+        } else {\r
+          Operator = (BOOLEAN) (MapValue == MapValue2);\r
+        }\r
+\r
+        PushBool (&StackPtr, Operator);\r
+        break;\r
+\r
+      case EFI_IFR_EQ_ID_LIST_OP:\r
+        for (Index = 0; Index < Iterator->ListLength; Index++) {\r
+          //\r
+          // If Not - flip the results\r
+          //\r
+          if (NotOperator) {\r
+            Operator = (BOOLEAN)!(MapValue == Iterator->ValueList[Index]);\r
+          } else {\r
+            Operator = (BOOLEAN) (MapValue == Iterator->ValueList[Index]);\r
+          }\r
+          //\r
+          // If We are trying to make sure that MapValue != Item[x], keep looking through\r
+          // the list to make sure we don't equal any other items\r
+          //\r
+          if (Operator && NotOperator) {\r
+            continue;\r
+          }\r
+          //\r
+          // If MapValue == Item, then we have succeeded (first found is good enough)\r
+          //\r
+          if (Operator) {\r
+            break;\r
+          }\r
+        }\r
+\r
+        PushBool (&StackPtr, Operator);\r
+        break;\r
+\r
+      default:\r
+        return FALSE;\r
+      }\r
+\r
+      Operator  = PopBool (&StackPtr);\r
+      Operator2 = PopBool (&StackPtr);\r
+      PushBool (&StackPtr, (BOOLEAN) (Operator || Operator2));\r
+      break;\r
+\r
+    case EFI_IFR_NOT_OP:\r
+      //\r
+      // To check whether Ifr is legacy. Once every boolean expression.\r
+      //\r
+      if (IsLegacy == 0) {\r
+        IsLegacy = PredicateIfrType (Iterator);\r
+      }\r
+      if (IsLegacy == 0x2) {\r
+        PostOrderEvaluate (FileFormTags, Width, &Iterator, &StackPtr);\r
+        break;\r
+      }\r
+\r
+      //\r
+      // I don't need to set the NotOperator (I know that I have to NOT this in this case\r
+      //\r
+      Iterator++;\r
+\r
+      if (Iterator->Operand == EFI_IFR_OR_OP) {\r
+        OrOperator = TRUE;\r
+        Iterator++;\r
+      }\r
+\r
+      if (Iterator->Operand == EFI_IFR_AND_OP) {\r
+        AndOperator = TRUE;\r
+        Iterator++;\r
+      }\r
+\r
+      if (Iterator->QuestionId1 != INVALID_OFFSET_VALUE) {\r
+        ExtractNvValue (FileFormTags, Iterator->VariableNumber, Width, Iterator->QuestionId1, (VOID **) &MapBuffer);\r
+        ExtractNvValue (FileFormTags, Iterator->VariableNumber2, Width, Iterator->QuestionId2, (VOID **) &MapBuffer2);\r
+        if (MapBuffer != NULL) {\r
+          if (Width == 2) {\r
+            MapValue = *MapBuffer;\r
+          } else {\r
+            MapValue = (UINT8) *MapBuffer;\r
+          }\r
+\r
+          FreePool (MapBuffer);\r
+        }\r
+\r
+        if (MapBuffer2 != NULL) {\r
+          if (Width == 2) {\r
+            MapValue2 = *MapBuffer2;\r
+          } else {\r
+            MapValue2 = (UINT8) *MapBuffer2;\r
+          }\r
+\r
+          FreePool (MapBuffer2);\r
+        }\r
+      }\r
+\r
+      switch (Iterator->Operand) {\r
+      case EFI_IFR_EQ_ID_VAL_OP:\r
+        Operator = (BOOLEAN)!(MapValue == Iterator->Value);\r
+        PushBool (&StackPtr, Operator);\r
+        break;\r
+\r
+      //\r
+      // In the case of external variable values, we must read the variable which is\r
+      // named by the human readable version of the OpCode->VariableId and the guid of the formset\r
+      //\r
+      case EFI_IFR_EQ_VAR_VAL_OP:\r
+        UnicodeValueToString (\r
+          VariableName,\r
+          FALSE,\r
+          (UINTN) Iterator->QuestionId1,\r
+          (sizeof (VariableName) / sizeof (VariableName[0])) - 1\r
+          );\r
+\r
+        SizeOfVariable = 0;\r
+\r
+        ExtractRequestedNvMap (FileFormTags, Iterator->VariableNumber, &VariableDefinition);\r
+\r
+        Status = BooleanVariableWorker (\r
+                  VariableName,\r
+                  VariableDefinition,\r
+                  StackPtr,\r
+                  &SizeOfVariable,\r
+                  &VariableData\r
+                  );\r
+\r
+        if (!EFI_ERROR (Status)) {\r
+          if (SizeOfVariable == 1) {\r
+            CopyMem (&MapValue, VariableData, 1);\r
+          } else {\r
+            CopyMem (&MapValue, VariableData, 2);\r
+          }\r
+\r
+          PushBool (&StackPtr, (BOOLEAN)!(MapValue == Iterator->Value));\r
+        }\r
+        break;\r
+\r
+      case EFI_IFR_EQ_ID_ID_OP:\r
+        Operator = (BOOLEAN)!(MapValue == MapValue2);\r
+        PushBool (&StackPtr, Operator);\r
+        break;\r
+\r
+      case EFI_IFR_EQ_ID_LIST_OP:\r
+        for (Index = 0; Index < Iterator->ListLength; Index++) {\r
+          Operator = (BOOLEAN)!(MapValue == Iterator->ValueList[Index]);\r
+          if (Operator) {\r
+            continue;\r
+          }\r
+        }\r
+\r
+        PushBool (&StackPtr, Operator);\r
+        break;\r
+\r
+      default:\r
+        return FALSE;\r
+      }\r
+\r
+      Operator  = PopBool (&StackPtr);\r
+      Operator2 = PopBool (&StackPtr);\r
+\r
+      if (OrOperator) {\r
+        PushBool (&StackPtr, (BOOLEAN) (Operator || Operator2));\r
+      }\r
+\r
+      if (AndOperator) {\r
+        PushBool (&StackPtr, (BOOLEAN) (Operator && Operator2));\r
+      }\r
+\r
+      if (!OrOperator && !AndOperator) {\r
+        PushBool (&StackPtr, Operator);\r
+      }\r
+      break;\r
+\r
+    case EFI_IFR_TRUE_OP:\r
+      //\r
+      // To check whether Ifr is legacy. Once every boolean expression.\r
+      //\r
+      if (IsLegacy == 0) {\r
+        IsLegacy = PredicateIfrType (Iterator);\r
+      }\r
+      if (IsLegacy == 0x2) {\r
+        PostOrderEvaluate (FileFormTags, Width, &Iterator, &StackPtr);\r
+        break;\r
+      }\r
+      break;\r
+\r
+    case EFI_IFR_FALSE_OP:\r
+      //\r
+      // To check whether Ifr is legacy. Once every boolean expression.\r
+      //\r
+      if (IsLegacy == 0) {\r
+        IsLegacy = PredicateIfrType (Iterator);\r
+      }\r
+      if (IsLegacy == 0x2) {\r
+        PostOrderEvaluate (FileFormTags, Width, &Iterator, &StackPtr);\r
+        break;\r
+      }\r
+      break;\r
+\r
+    case EFI_IFR_END_IF_OP:\r
+      Operator = PopBool (&StackPtr);\r
+      //\r
+      // If there is an error, return, otherwise keep looking - there might\r
+      // be another test that causes an error\r
+      //\r
+      if (Operator) {\r
+        if (Complex && CosmeticConsistency) {\r
+          return EFI_SUCCESS;\r
+        } else {\r
+          return Operator;\r
+        }\r
+      } else {\r
+        //\r
+        // If not doing a global consistency check, the endif is the REAL terminator of this operation\r
+        // This is used for grayout/suppress operations.  InconsistentIf is a global operation so the EndIf is\r
+        // not the end-all be-all of terminators.\r
+        //\r
+        if (!Complex) {\r
+          return Operator;\r
+        }\r
+        break;\r
+      }\r
+\r
+    default:\r
+      //\r
+      // Must have hit a non-consistency related op-code after a suppress/grayout\r
+      //\r
+      if (ArtificialEnd) {\r
+        ArtificialEnd = FALSE;\r
+        Operator      = PopBool (&StackPtr);\r
+        return Operator;\r
+      }\r
+\r
+      goto Done;\r
+    }\r
+\r
+    Iterator++;\r
+  }\r
+\r
+Done:\r
+  return FALSE;\r
+}\r
diff --git a/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Colors.h b/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Colors.h
new file mode 100644 (file)
index 0000000..2ad2aa9
--- /dev/null
@@ -0,0 +1,59 @@
+/*++\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
+  Colors.h\r
+\r
+Abstract:\r
+\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+#ifndef _COLORS_H\r
+#define _COLORS_H\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+//\r
+// Screen Color Settings\r
+//\r
+#define PICKLIST_HIGHLIGHT_TEXT       EFI_WHITE\r
+#define PICKLIST_HIGHLIGHT_BACKGROUND EFI_BACKGROUND_CYAN\r
+#define TITLE_TEXT                    EFI_WHITE\r
+#define TITLE_BACKGROUND              EFI_BACKGROUND_BLUE\r
+#define KEYHELP_TEXT                  EFI_LIGHTGRAY\r
+#define KEYHELP_BACKGROUND            EFI_BACKGROUND_BLACK\r
+#define SUBTITLE_TEXT                 EFI_BLUE\r
+#define SUBTITLE_BACKGROUND           EFI_BACKGROUND_LIGHTGRAY\r
+#define BANNER_TEXT                   EFI_BLUE\r
+#define BANNER_BACKGROUND             EFI_BACKGROUND_LIGHTGRAY\r
+#define FIELD_TEXT                    EFI_BLACK\r
+#define FIELD_TEXT_GRAYED             EFI_DARKGRAY\r
+#define FIELD_BACKGROUND              EFI_BACKGROUND_LIGHTGRAY\r
+#define FIELD_TEXT_HIGHLIGHT          EFI_LIGHTGRAY\r
+#define FIELD_BACKGROUND_HIGHLIGHT    EFI_BACKGROUND_BLACK\r
+#define POPUP_TEXT                    EFI_LIGHTGRAY\r
+#define POPUP_BACKGROUND              EFI_BACKGROUND_BLUE\r
+#define POPUP_INVERSE_TEXT            EFI_LIGHTGRAY\r
+#define POPUP_INVERSE_BACKGROUND      EFI_BACKGROUND_BLACK\r
+#define HELP_TEXT                     EFI_BLUE\r
+#define ERROR_TEXT                    EFI_RED | EFI_BRIGHT\r
+#define INFO_TEXT                     EFI_YELLOW | EFI_BRIGHT\r
+#define ARROW_TEXT                    EFI_RED | EFI_BRIGHT\r
+#define ARROW_BACKGROUND              EFI_BACKGROUND_LIGHTGRAY\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/CommonHeader.h b/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/CommonHeader.h
new file mode 100644 (file)
index 0000000..ab5ebc3
--- /dev/null
@@ -0,0 +1,44 @@
+/**@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 <Protocol/FormCallback.h>\r
+#include <Protocol/FormBrowser.h>\r
+#include <Protocol/FrameworkHii.h>\r
+#include <Protocol/Print.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/HiiLibFramework.h>\r
+#include <Library/GraphicsLib.h>\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/InputHandler.c b/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/InputHandler.c
new file mode 100644 (file)
index 0000000..4c2189c
--- /dev/null
@@ -0,0 +1,1575 @@
+/*++\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
+  InputHandler.C\r
+\r
+Abstract:\r
+\r
+  Implementation for handling user input from the User Interface\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "Setup.h"\r
+#include "Ui.h"\r
+#include "Colors.h"\r
+\r
+#define EFI_MAX(_a, _b) ((_a) > (_b) ? (_a) : (_b))\r
+\r
+EFI_STATUS\r
+ReadString(\r
+  IN  UI_MENU_OPTION              *MenuOption,\r
+  OUT CHAR16                      *StringPtr\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  EFI_INPUT_KEY Key;\r
+  CHAR16        NullCharacter;\r
+  UINTN         ScreenSize;\r
+  EFI_TAG       *Tag;\r
+  CHAR16        Space[2];\r
+  CHAR16        KeyPad[2];\r
+  BOOLEAN       SelectionComplete;\r
+  CHAR16        *TempString;\r
+  CHAR16        *BufferedString;\r
+  UINTN         Index;\r
+  UINTN         Count;\r
+  UINTN         Start;\r
+  UINTN         Top;\r
+  CHAR16        *PromptForDataString;\r
+  UINTN         DimensionsWidth;\r
+  UINTN         DimensionsHeight;\r
+  BOOLEAN       CursorVisible;\r
+\r
+  DimensionsWidth     = gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn;\r
+  DimensionsHeight    = gScreenDimensions.BottomRow - gScreenDimensions.TopRow;\r
+\r
+  PromptForDataString = GetToken (STRING_TOKEN (PROMPT_FOR_DATA), gHiiHandle);\r
+\r
+  NullCharacter       = CHAR_NULL;\r
+  ScreenSize          = GetStringWidth (PromptForDataString) / 2;\r
+  Tag                 = MenuOption->ThisTag;\r
+  Space[0]            = L' ';\r
+  Space[1]            = CHAR_NULL;\r
+  SelectionComplete   = FALSE;\r
+\r
+  TempString          = AllocateZeroPool (MenuOption->ThisTag->Maximum * 2);\r
+  ASSERT (TempString);\r
+\r
+  if (ScreenSize < (Tag->Maximum / (UINTN) 2)) {\r
+    ScreenSize = Tag->Maximum / 2;\r
+  }\r
+\r
+  if ((ScreenSize + 2) > DimensionsWidth) {\r
+    ScreenSize = DimensionsWidth - 2;\r
+  }\r
+\r
+  BufferedString = AllocateZeroPool (ScreenSize * 2);\r
+  ASSERT (BufferedString);\r
+\r
+  Start = (DimensionsWidth - ScreenSize - 2) / 2 + gScreenDimensions.LeftColumn + 1;\r
+  Top   = ((DimensionsHeight - 6) / 2) + gScreenDimensions.TopRow - 1;\r
+\r
+  //\r
+  // Display prompt for string\r
+  //\r
+  CreatePopUp (ScreenSize, 4, &NullCharacter, PromptForDataString, Space, &NullCharacter);\r
+\r
+  FreePool (PromptForDataString);\r
+\r
+  gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_BLACK, EFI_LIGHTGRAY));\r
+\r
+  CursorVisible = gST->ConOut->Mode->CursorVisible;\r
+  gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
+\r
+  do {\r
+    Status = WaitForKeyStroke (&Key);\r
+\r
+    gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_BLACK, EFI_LIGHTGRAY));\r
+    switch (Key.UnicodeChar) {\r
+    case CHAR_NULL:\r
+      switch (Key.ScanCode) {\r
+      case SCAN_LEFT:\r
+        break;\r
+\r
+      case SCAN_RIGHT:\r
+        break;\r
+\r
+      case SCAN_ESC:\r
+        FreePool (TempString);\r
+        FreePool (BufferedString);\r
+        gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
+        gST->ConOut->EnableCursor (gST->ConOut, CursorVisible);\r
+        return EFI_DEVICE_ERROR;\r
+\r
+      default:\r
+        break;\r
+      }\r
+\r
+      break;\r
+\r
+    case CHAR_CARRIAGE_RETURN:\r
+      if (GetStringWidth (StringPtr) >= MenuOption->ThisTag->Minimum) {\r
+        SelectionComplete = TRUE;\r
+        FreePool (TempString);\r
+        FreePool (BufferedString);\r
+        gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
+        gST->ConOut->EnableCursor (gST->ConOut, CursorVisible);\r
+        return EFI_SUCCESS;\r
+      } else {\r
+        ScreenSize = GetStringWidth (gMiniString) / 2;\r
+        CreatePopUp (ScreenSize, 4, &NullCharacter, gMiniString, gPressEnter, &NullCharacter);\r
+        //\r
+        // Simply create a popup to tell the user that they had typed in too few characters.\r
+        // To save code space, we can then treat this as an error and return back to the menu.\r
+        //\r
+        do {\r
+          Status = WaitForKeyStroke (&Key);\r
+        } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
+        FreePool (TempString);\r
+        FreePool (BufferedString);\r
+        gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
+        gST->ConOut->EnableCursor (gST->ConOut, CursorVisible);\r
+        return EFI_DEVICE_ERROR;\r
+      }\r
+\r
+      break;\r
+\r
+    case CHAR_BACKSPACE:\r
+      if (StringPtr[0] != CHAR_NULL) {\r
+        for (Index = 0; StringPtr[Index] != CHAR_NULL; Index++) {\r
+          TempString[Index] = StringPtr[Index];\r
+        }\r
+        //\r
+        // Effectively truncate string by 1 character\r
+        //\r
+        TempString[Index - 1] = CHAR_NULL;\r
+        StrCpy (StringPtr, TempString);\r
+      }\r
+\r
+    default:\r
+      //\r
+      // If it is the beginning of the string, don't worry about checking maximum limits\r
+      //\r
+      if ((StringPtr[0] == CHAR_NULL) && (Key.UnicodeChar != CHAR_BACKSPACE)) {\r
+        StrnCpy (StringPtr, &Key.UnicodeChar, 1);\r
+        StrnCpy (TempString, &Key.UnicodeChar, 1);\r
+      } else if ((GetStringWidth (StringPtr) < MenuOption->ThisTag->Maximum) && (Key.UnicodeChar != CHAR_BACKSPACE)) {\r
+        KeyPad[0] = Key.UnicodeChar;\r
+        KeyPad[1] = CHAR_NULL;\r
+        StrCat (StringPtr, KeyPad);\r
+        StrCat (TempString, KeyPad);\r
+      }\r
+      //\r
+      // If the width of the input string is now larger than the screen, we nee to\r
+      // adjust the index to start printing portions of the string\r
+      //\r
+      SetUnicodeMem (BufferedString, ScreenSize - 1, L' ');\r
+\r
+      PrintStringAt (Start + 1, Top + 3, BufferedString);\r
+\r
+      if ((GetStringWidth (StringPtr) / 2) > (DimensionsWidth - 2)) {\r
+        Index = (GetStringWidth (StringPtr) / 2) - DimensionsWidth + 2;\r
+      } else {\r
+        Index = 0;\r
+      }\r
+\r
+      for (Count = 0; Index + 1 < GetStringWidth (StringPtr) / 2; Index++, Count++) {\r
+        BufferedString[Count] = StringPtr[Index];\r
+      }\r
+\r
+      PrintStringAt (Start + 1, Top + 3, BufferedString);\r
+      break;\r
+    }\r
+\r
+    gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
+    gST->ConOut->SetCursorPosition (gST->ConOut, Start + GetStringWidth (StringPtr) / 2, Top + 3);\r
+  } while (!SelectionComplete);\r
+  gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
+  gST->ConOut->EnableCursor (gST->ConOut, CursorVisible);\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+ReadPassword (\r
+  IN  UI_MENU_OPTION              *MenuOption,\r
+  IN  BOOLEAN                     PromptForPassword,\r
+  IN  EFI_TAG                     *Tag,\r
+  IN  EFI_IFR_DATA_ARRAY          *PageData,\r
+  IN  BOOLEAN                     SecondEntry,\r
+  IN  EFI_FILE_FORM_TAGS          *FileFormTags,\r
+  OUT CHAR16                      *StringPtr\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  UINTN                       ScreenSize;\r
+  CHAR16                      NullCharacter;\r
+  CHAR16                      Space[2];\r
+  EFI_INPUT_KEY               Key;\r
+  CHAR16                      KeyPad[2];\r
+  UINTN                       Index;\r
+  UINTN                       Start;\r
+  UINTN                       Top;\r
+  CHAR16                      *TempString;\r
+  CHAR16                      *TempString2;\r
+  BOOLEAN                     Confirmation;\r
+  BOOLEAN                     ConfirmationComplete;\r
+  EFI_HII_CALLBACK_PACKET     *Packet;\r
+  EFI_FORM_CALLBACK_PROTOCOL  *FormCallback;\r
+  EFI_VARIABLE_DEFINITION     *VariableDefinition;\r
+  UINTN                       DimensionsWidth;\r
+  UINTN                       DimensionsHeight;\r
+  EFI_IFR_DATA_ENTRY          *DataEntry;\r
+  UINTN                       WidthOfString;\r
+\r
+  DimensionsWidth       = gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn;\r
+  DimensionsHeight      = gScreenDimensions.BottomRow - gScreenDimensions.TopRow;\r
+\r
+  VariableDefinition    = NULL;\r
+  NullCharacter         = CHAR_NULL;\r
+  Space[0]              = L' ';\r
+  Space[1]              = CHAR_NULL;\r
+  Confirmation          = FALSE;\r
+  ConfirmationComplete  = FALSE;\r
+  Status                = EFI_SUCCESS;\r
+  FormCallback          = NULL;\r
+  Packet                = NULL;\r
+\r
+  //\r
+  // Remember that dynamic pages in an environment where all pages are not\r
+  // dynamic require us to call back to the user to give them an opportunity\r
+  // to register fresh information in the HII database so that we can extract it.\r
+  //\r
+  Status = gBS->HandleProtocol (\r
+                  (VOID *) (UINTN) MenuOption->Tags[0].CallbackHandle,\r
+                  &gEfiFormCallbackProtocolGuid,\r
+                  (VOID **) &FormCallback\r
+                  );\r
+\r
+  TempString  = AllocateZeroPool (MenuOption->ThisTag->Maximum * 2);\r
+  TempString2 = AllocateZeroPool (MenuOption->ThisTag->Maximum * 2);\r
+\r
+  ASSERT (TempString);\r
+  ASSERT (TempString2);\r
+\r
+  if (Tag->Flags & EFI_IFR_FLAG_INTERACTIVE) {\r
+    //\r
+    // Password requires a callback to determine if a password exists\r
+    //\r
+    DataEntry = (EFI_IFR_DATA_ENTRY *) (PageData + 1);\r
+    DataEntry->OpCode  = EFI_IFR_PASSWORD_OP;\r
+    DataEntry->Length  = 3;\r
+\r
+    ExtractRequestedNvMap (FileFormTags, Tag->VariableNumber, &VariableDefinition);\r
+\r
+    //\r
+    // The user is about to be prompted with a password field, Data = 0 (Return Status determines the type of prompt)\r
+    //\r
+    DataEntry->Data  = (VOID *) (UINTN) (UINT8) (0 + SecondEntry * 2);\r
+    PageData->NvRamMap    = VariableDefinition->NvRamMap;\r
+\r
+    if ((FormCallback != NULL) && (FormCallback->Callback != NULL)) {\r
+      Status = FormCallback->Callback (\r
+                              FormCallback,\r
+                              Tag->Key,\r
+                              PageData,\r
+                              &Packet\r
+                              );\r
+    }\r
+    //\r
+    // If error on return, continue with the reading of a typed in password to verify user knows password\r
+    // If no error, there is no password set, so prompt for new password\r
+    // if the previous callback was to verify the user knew password, and user typed it correctly - should return no error\r
+    //\r
+    if (!EFI_ERROR (Status)) {\r
+      PromptForPassword = FALSE;\r
+\r
+      //\r
+      // Simulate this as the second entry into this routine for an interactive behavior\r
+      //\r
+      SecondEntry = TRUE;\r
+    } else if (Status == EFI_NOT_READY) {\r
+Error:\r
+      if (Packet != NULL) {\r
+        //\r
+        // Upon error, we will likely receive a string to print out\r
+        // Display error popup\r
+        //\r
+        WidthOfString = GetStringWidth (Packet->String);\r
+        ScreenSize = EFI_MAX(WidthOfString, GetStringWidth (gPressEnter)) / 2;\r
+        CreatePopUp (ScreenSize, 4, &NullCharacter, Packet->String, gPressEnter, &NullCharacter);\r
+        FreePool (Packet);\r
+\r
+        do {\r
+          Status = WaitForKeyStroke (&Key);\r
+        } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
+      }\r
+\r
+      Status = EFI_NOT_READY;\r
+      goto Done;\r
+    }\r
+  }\r
+\r
+  do {\r
+    //\r
+    // Display PopUp Screen\r
+    //\r
+    ScreenSize = GetStringWidth (gPromptForNewPassword) / 2;\r
+    if (GetStringWidth (gConfirmPassword) / 2 > ScreenSize) {\r
+      ScreenSize = GetStringWidth (gConfirmPassword) / 2;\r
+    }\r
+\r
+    Start = (DimensionsWidth - ScreenSize - 4) / 2 + gScreenDimensions.LeftColumn + 2;\r
+    Top   = ((DimensionsHeight - 6) / 2) + gScreenDimensions.TopRow - 1;\r
+\r
+    if (!Confirmation) {\r
+      if (PromptForPassword) {\r
+        CreatePopUp (ScreenSize, 4, &NullCharacter, gPromptForPassword, Space, &NullCharacter);\r
+      } else {\r
+        CreatePopUp (ScreenSize, 4, &NullCharacter, gPromptForNewPassword, Space, &NullCharacter);\r
+      }\r
+    } else {\r
+      CreatePopUp (ScreenSize, 4, &NullCharacter, gConfirmPassword, Space, &NullCharacter);\r
+      StringPtr[0] = CHAR_NULL;\r
+    }\r
+\r
+    do {\r
+      Status = WaitForKeyStroke (&Key);\r
+\r
+      switch (Key.UnicodeChar) {\r
+      case CHAR_NULL:\r
+        if (Key.ScanCode == SCAN_ESC) {\r
+          return EFI_NOT_READY;\r
+        }\r
+\r
+        ConfirmationComplete = FALSE;\r
+        break;\r
+\r
+      case CHAR_CARRIAGE_RETURN:\r
+        if (Tag->Flags & EFI_IFR_FLAG_INTERACTIVE) {\r
+          //\r
+          // User just typed a string in\r
+          //\r
+          DataEntry = (EFI_IFR_DATA_ENTRY *) (PageData + 1);\r
+          DataEntry->OpCode = EFI_IFR_PASSWORD_OP;\r
+\r
+          //\r
+          // If the user just typed in a password, Data = 1\r
+          // If the user just typed in a password to confirm the previous password, Data = 2\r
+          //\r
+          if (!Confirmation) {\r
+            DataEntry->Length  = 3;\r
+            DataEntry->Data    = (VOID *) (UINTN) (UINT8) (1 + SecondEntry * 2);\r
+\r
+            if ((FormCallback != NULL) && (FormCallback->Callback != NULL)) {\r
+              Status = FormCallback->Callback (\r
+                                      FormCallback,\r
+                                      Tag->Key,\r
+                                      PageData,\r
+                                      &Packet\r
+                                      );\r
+            }\r
+\r
+            DataEntry->Length  = sizeof (EFI_IFR_DATA_ENTRY);\r
+            DataEntry->Data    = (VOID *) TempString;\r
+          } else {\r
+            DataEntry->Length  = 3;\r
+            DataEntry->Data    = (VOID *) (UINTN) (UINT8) (2 + SecondEntry * 2);\r
+\r
+            if ((FormCallback != NULL) && (FormCallback->Callback != NULL)) {\r
+              Status = FormCallback->Callback (\r
+                                      FormCallback,\r
+                                      Tag->Key,\r
+                                      PageData,\r
+                                      &Packet\r
+                                      );\r
+            }\r
+\r
+            DataEntry->Length  = sizeof (EFI_IFR_DATA_ENTRY);\r
+            DataEntry->Data    = (VOID *) TempString2;\r
+          }\r
+\r
+          if ((FormCallback != NULL) && (FormCallback->Callback != NULL)) {\r
+            Status = FormCallback->Callback (\r
+                                    FormCallback,\r
+                                    Tag->Key,\r
+                                    PageData,\r
+                                    &Packet\r
+                                    );\r
+          }\r
+          //\r
+          // If this was the confirmation round of callbacks\r
+          // and an error comes back, display an error\r
+          //\r
+          if (Confirmation) {\r
+            if (EFI_ERROR (Status)) {\r
+              if (Packet->String == NULL) {\r
+                WidthOfString = GetStringWidth (gConfirmError);\r
+                ScreenSize = EFI_MAX (WidthOfString, GetStringWidth (gPressEnter)) / 2;\r
+                CreatePopUp (ScreenSize, 4, &NullCharacter, gConfirmError, gPressEnter, &NullCharacter);\r
+              } else {\r
+                WidthOfString = GetStringWidth (Packet->String);\r
+                ScreenSize = EFI_MAX (WidthOfString, GetStringWidth (gPressEnter)) / 2;\r
+                CreatePopUp (ScreenSize, 4, &NullCharacter, Packet->String, gPressEnter, &NullCharacter);\r
+                FreePool (Packet);\r
+              }\r
+\r
+              StringPtr[0] = CHAR_NULL;\r
+              do {\r
+                Status = WaitForKeyStroke (&Key);\r
+\r
+                if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
+                  Status = EFI_NOT_READY;\r
+                  goto Done;\r
+                }\r
+              } while (1);\r
+            } else {\r
+                Status = EFI_NOT_READY;\r
+                goto Done;\r
+            }\r
+          } else {\r
+            //\r
+            // User typed a string in and it wasn't valid somehow from the callback\r
+            // For instance, callback may have said that some invalid characters were contained in the string\r
+            //\r
+            if (Status == EFI_NOT_READY) {\r
+              goto Error;\r
+            }\r
+\r
+            if (PromptForPassword && EFI_ERROR (Status)) {\r
+              Status = EFI_DEVICE_ERROR;\r
+              goto Done;\r
+            }\r
+          }\r
+        }\r
+\r
+        if (Confirmation) {\r
+          //\r
+          // Compare tempstring and tempstring2, if the same, return with StringPtr success\r
+          // Otherwise, kick and error box, and return an error\r
+          //\r
+          if (StrCmp (TempString, TempString2) == 0) {\r
+            Status = EFI_SUCCESS;\r
+            goto Done;\r
+          } else {\r
+            WidthOfString = GetStringWidth (gConfirmError);\r
+            ScreenSize = EFI_MAX (WidthOfString, GetStringWidth (gPressEnter)) / 2;\r
+            CreatePopUp (ScreenSize, 4, &NullCharacter, gConfirmError, gPressEnter, &NullCharacter);\r
+            StringPtr[0] = CHAR_NULL;\r
+            do {\r
+              Status = WaitForKeyStroke (&Key);\r
+              if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
+                Status = EFI_DEVICE_ERROR;\r
+                goto Done;\r
+              }\r
+            } while (1);\r
+          }\r
+        }\r
+\r
+        if (PromptForPassword) {\r
+          //\r
+          // I was asked for a password, return it back in StringPtr\r
+          //\r
+          Status = EFI_SUCCESS;\r
+          goto Done;\r
+        } else {\r
+          //\r
+          // If the two passwords were not the same kick an error popup\r
+          //\r
+          Confirmation          = TRUE;\r
+          ConfirmationComplete  = TRUE;\r
+          break;\r
+        }\r
+\r
+      case CHAR_BACKSPACE:\r
+        if (StringPtr[0] != CHAR_NULL) {\r
+          if (!Confirmation) {\r
+            for (Index = 0; StringPtr[Index] != CHAR_NULL; Index++) {\r
+              TempString[Index] = StringPtr[Index];\r
+            }\r
+            //\r
+            // Effectively truncate string by 1 character\r
+            //\r
+            TempString[Index - 1] = CHAR_NULL;\r
+            StrCpy (StringPtr, TempString);\r
+          } else {\r
+            for (Index = 0; StringPtr[Index] != CHAR_NULL; Index++) {\r
+              TempString2[Index] = StringPtr[Index];\r
+            }\r
+            //\r
+            // Effectively truncate string by 1 character\r
+            //\r
+            TempString2[Index - 1] = CHAR_NULL;\r
+            StrCpy (StringPtr, TempString2);\r
+          }\r
+\r
+          ConfirmationComplete = FALSE;\r
+        } else {\r
+          ConfirmationComplete = FALSE;\r
+        }\r
+\r
+      //\r
+      // Must be a character we are interested in!\r
+      //\r
+      default:\r
+        if ((StringPtr[0] == CHAR_NULL) && (Key.UnicodeChar != CHAR_BACKSPACE)) {\r
+          if (!Confirmation) {\r
+            StrnCpy (StringPtr, &Key.UnicodeChar, 1);\r
+            StrnCpy (TempString, &Key.UnicodeChar, 1);\r
+          } else {\r
+            StrnCpy (StringPtr, &Key.UnicodeChar, 1);\r
+            StrnCpy (TempString2, &Key.UnicodeChar, 1);\r
+            ConfirmationComplete = FALSE;\r
+          }\r
+        } else if ((GetStringWidth (StringPtr) / 2 <= (UINTN) (MenuOption->ThisTag->Maximum - 1) / 2) &&\r
+                 (Key.UnicodeChar != CHAR_BACKSPACE)\r
+                ) {\r
+          KeyPad[0] = Key.UnicodeChar;\r
+          KeyPad[1] = CHAR_NULL;\r
+          if (!Confirmation) {\r
+            StrCat (StringPtr, KeyPad);\r
+            StrCat (TempString, KeyPad);\r
+          } else {\r
+            StrCat (StringPtr, KeyPad);\r
+            StrCat (TempString2, KeyPad);\r
+          }\r
+        }\r
+\r
+        gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_BLACK, EFI_LIGHTGRAY));\r
+        for (Index = 1; Index < ScreenSize; Index++) {\r
+          PrintCharAt (Start + Index, Top + 3, L' ');\r
+        }\r
+\r
+        gST->ConOut->SetCursorPosition (\r
+                      gST->ConOut,\r
+                      (DimensionsWidth - GetStringWidth (StringPtr) / 2) / 2 + gScreenDimensions.LeftColumn,\r
+                      Top + 3\r
+                      );\r
+        for (Index = 0; Index + 1 < GetStringWidth (StringPtr) / 2; Index++) {\r
+          PrintChar (L'*');\r
+        }\r
+\r
+        gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
+        break;\r
+      }\r
+      //\r
+      // end switch\r
+      //\r
+    } while (!ConfirmationComplete);\r
+\r
+  } while (1);\r
+\r
+Done:\r
+  FreePool (TempString);\r
+  FreePool (TempString2);\r
+  return Status;\r
+}\r
+\r
+VOID\r
+EncodePassword (\r
+  IN  CHAR16                      *Password,\r
+  IN  UINT8                       MaxSize\r
+  )\r
+{\r
+  UINTN   Index;\r
+  UINTN   Loop;\r
+  CHAR16  *Buffer;\r
+  CHAR16  *Key;\r
+\r
+  Key     = (CHAR16 *) L"MAR10648567";\r
+  Buffer  = AllocateZeroPool (MaxSize);\r
+\r
+  ASSERT (Buffer);\r
+\r
+  for (Index = 0; Key[Index] != 0; Index++) {\r
+    for (Loop = 0; Loop < (UINT8) (MaxSize / 2); Loop++) {\r
+      Buffer[Loop] = (CHAR16) (Password[Loop] ^ Key[Index]);\r
+    }\r
+  }\r
+\r
+  CopyMem (Password, Buffer, MaxSize);\r
+\r
+  FreePool (Buffer);\r
+  return ;\r
+}\r
+\r
+EFI_STATUS\r
+GetNumericInput (\r
+  IN  UI_MENU_OPTION              *MenuOption,\r
+  IN  EFI_FILE_FORM_TAGS          *FileFormTagsHead,\r
+  IN  BOOLEAN                     ManualInput,\r
+  IN  EFI_TAG                     *Tag,\r
+  IN  UINTN                       NumericType,\r
+  OUT UINT16                      *Value\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This routine reads a numeric value from the user input.\r
+\r
+Arguments:\r
+\r
+  MenuOption       -  Pointer to the current input menu.\r
+\r
+  FileFormTagsHead -  Pointer to the root of formset.\r
+\r
+  ManualInput      -  If the input is manual or not.\r
+\r
+  Tag              -  Pointer to all the attributes and values associated with a tag.\r
+\r
+  Value            -  Pointer to the numeric value that is going to be read.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS       - If numerical input is read successfully\r
+  EFI_DEVICE_ERROR  - If operation fails\r
+\r
+--*/\r
+{\r
+  EFI_INPUT_KEY           Key;\r
+  BOOLEAN                 SelectionComplete;\r
+  UINTN                   Column;\r
+  UINTN                   Row;\r
+  CHAR16                  FormattedNumber[6];\r
+  UINTN                   PreviousNumber[6];\r
+  INTN                    Number;\r
+  UINTN                   Count;\r
+  UINT16                  BackupValue;\r
+  STRING_REF              PopUp;\r
+  CHAR16                  NullCharacter;\r
+  CHAR16                  *StringPtr;\r
+  EFI_FILE_FORM_TAGS      *FileFormTags;\r
+  EFI_VARIABLE_DEFINITION *VariableDefinition;\r
+  UINTN                   Loop;\r
+\r
+  NullCharacter     = CHAR_NULL;\r
+  StringPtr         = NULL;\r
+  Column            = MenuOption->OptCol;\r
+  Row               = MenuOption->Row;\r
+  Number            = 0;\r
+  PreviousNumber[0] = 0;\r
+  Count             = 0;\r
+  SelectionComplete = FALSE;\r
+  BackupValue       = Tag->Value;\r
+  FileFormTags      = FileFormTagsHead;\r
+\r
+  if (ManualInput) {\r
+    PrintAt (Column, Row, (CHAR16 *) L"[     ]");\r
+    Column++;\r
+    if (Tag->Operand != EFI_IFR_TIME_OP) {\r
+      *Value = BackupValue;\r
+    }\r
+  }\r
+  //\r
+  // First time we enter this handler, we need to check to see if\r
+  // we were passed an increment or decrement directive\r
+  //\r
+  do {\r
+    Key.UnicodeChar = CHAR_NULL;\r
+    if (gDirection != 0) {\r
+      Key.ScanCode  = gDirection;\r
+      gDirection    = 0;\r
+      goto TheKey2;\r
+    }\r
+\r
+    WaitForKeyStroke (&Key);\r
+\r
+TheKey2:\r
+    switch (Key.UnicodeChar) {\r
+    case '+':\r
+    case '-':\r
+      if ((Tag->Operand == EFI_IFR_DATE_OP) || (Tag->Operand == EFI_IFR_TIME_OP)) {\r
+        Key.UnicodeChar = CHAR_NULL;\r
+        if (Key.UnicodeChar == '+') {\r
+          Key.ScanCode = SCAN_RIGHT;\r
+        } else {\r
+          Key.ScanCode = SCAN_LEFT;\r
+        }\r
+\r
+        goto TheKey2;\r
+      }\r
+      break;\r
+\r
+    case CHAR_NULL:\r
+      switch (Key.ScanCode) {\r
+      case SCAN_LEFT:\r
+      case SCAN_RIGHT:\r
+        if ((Tag->Operand == EFI_IFR_DATE_OP) || (Tag->Operand == EFI_IFR_TIME_OP)) {\r
+          //\r
+          // By setting this value, we will return back to the caller.\r
+          // We need to do this since an auto-refresh will destroy the adjustment\r
+          // based on what the real-time-clock is showing.  So we always commit\r
+          // upon changing the value.\r
+          //\r
+          gDirection = SCAN_DOWN;\r
+        }\r
+\r
+        if (!ManualInput) {\r
+          Tag->Value = *Value;\r
+          if (Key.ScanCode == SCAN_LEFT) {\r
+            Number = *Value - Tag->Step;\r
+            if (Number < Tag->Minimum) {\r
+              Number = Tag->Minimum;\r
+            }\r
+          } else if (Key.ScanCode == SCAN_RIGHT) {\r
+            Number = *Value + Tag->Step;\r
+            if (Number > Tag->Maximum) {\r
+              Number = Tag->Maximum;\r
+            }\r
+          }\r
+\r
+          Tag->Value  = (UINT16) Number;\r
+          *Value      = (UINT16) Number;\r
+          UnicodeValueToString (\r
+            FormattedNumber,\r
+            FALSE,\r
+            (UINTN) Number,\r
+            (sizeof (FormattedNumber) / sizeof (FormattedNumber[0]))\r
+            );\r
+          Number = (UINT16) GetStringWidth (FormattedNumber);\r
+\r
+          gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
+          if ((Tag->Operand == EFI_IFR_DATE_OP) || (Tag->Operand == EFI_IFR_TIME_OP)) {\r
+            for (Loop = 0; Loop < (UINTN) ((Number >= 8) ? 4 : 2); Loop++) {\r
+              PrintAt (MenuOption->OptCol + Loop, MenuOption->Row, (CHAR16 *) L" ");\r
+            }\r
+          } else {\r
+            for (Loop = 0; Loop < gOptionBlockWidth; Loop++) {\r
+              PrintAt (MenuOption->OptCol + Loop, MenuOption->Row, (CHAR16 *) L" ");\r
+            }\r
+          }\r
+\r
+          gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_HIGHLIGHT | FIELD_BACKGROUND_HIGHLIGHT);\r
+\r
+          if ((MenuOption->Col + gPromptBlockWidth + 1) == MenuOption->OptCol) {\r
+            PrintCharAt (MenuOption->OptCol, Row, LEFT_NUMERIC_DELIMITER);\r
+            Column = MenuOption->OptCol + 1;\r
+          }\r
+          //\r
+          // If Number looks like "3", convert it to "03/"\r
+          //\r
+          if (Number == 4 && (NumericType == DATE_NUMERIC)) {\r
+            FormattedNumber[3]  = FormattedNumber[1];\r
+            FormattedNumber[2]  = DATE_SEPARATOR;\r
+            FormattedNumber[1]  = FormattedNumber[0];\r
+            FormattedNumber[0]  = L'0';\r
+            Number              = 8;\r
+          }\r
+          //\r
+          // If Number looks like "13", convert it to "13/"\r
+          //\r
+          if (Number == 6 && (NumericType == DATE_NUMERIC)) {\r
+            FormattedNumber[3]  = FormattedNumber[2];\r
+            FormattedNumber[2]  = DATE_SEPARATOR;\r
+            Number              = 8;\r
+          }\r
+\r
+          if (Number == 4 &&\r
+              (NumericType == TIME_NUMERIC) &&\r
+              (MenuOption->Col + gPromptBlockWidth + 8) != MenuOption->OptCol\r
+              ) {\r
+            FormattedNumber[3]  = FormattedNumber[1];\r
+            FormattedNumber[2]  = TIME_SEPARATOR;\r
+            FormattedNumber[1]  = FormattedNumber[0];\r
+            FormattedNumber[0]  = L'0';\r
+            Number              = 8;\r
+          }\r
+\r
+          if (Number == 4 &&\r
+              (NumericType == TIME_NUMERIC) &&\r
+              (MenuOption->Col + gPromptBlockWidth + 8) == MenuOption->OptCol\r
+              ) {\r
+            FormattedNumber[3]  = FormattedNumber[1];\r
+            FormattedNumber[2]  = RIGHT_NUMERIC_DELIMITER;\r
+            FormattedNumber[1]  = FormattedNumber[0];\r
+            FormattedNumber[0]  = L'0';\r
+            Number              = 8;\r
+          }\r
+\r
+          PrintStringAt (Column, Row, FormattedNumber);\r
+          if (Number == 10 && (NumericType == DATE_NUMERIC)) {\r
+            PrintChar (RIGHT_NUMERIC_DELIMITER);\r
+          }\r
+\r
+          if (NumericType == REGULAR_NUMERIC) {\r
+            PrintChar (RIGHT_NUMERIC_DELIMITER);\r
+          }\r
+        }\r
+        break;\r
+\r
+      case SCAN_UP:\r
+      case SCAN_DOWN:\r
+        goto EnterCarriageReturn;\r
+\r
+      case SCAN_ESC:\r
+        return EFI_DEVICE_ERROR;\r
+\r
+      default:\r
+        break;\r
+      }\r
+\r
+      break;\r
+\r
+EnterCarriageReturn:\r
+\r
+    case CHAR_CARRIAGE_RETURN:\r
+      //\r
+      // Check to see if the Value is something reasonable against consistency limitations.\r
+      // If not, let's kick the error specified.\r
+      //\r
+      //\r
+      // This gives us visibility to the FileFormTags->NvRamMap to check things\r
+      // ActiveIfr is a global maintained by the menuing code to ensure that we\r
+      // are pointing to the correct formset's file data.\r
+      //\r
+      for (Count = 0; Count < gActiveIfr; Count++) {\r
+        FileFormTags = FileFormTags->NextFile;\r
+      }\r
+\r
+      ExtractRequestedNvMap (FileFormTags, Tag->VariableNumber, &VariableDefinition);\r
+\r
+      CopyMem (&VariableDefinition->NvRamMap[Tag->StorageStart], &Tag->Value, Tag->StorageWidth);\r
+\r
+      //\r
+      // Data associated with a NULL device (in the fake NV storage)\r
+      //\r
+      if (Tag->StorageWidth == (UINT16) 0) {\r
+        CopyMem (&VariableDefinition->FakeNvRamMap[Tag->StorageStart], &Tag->Value, 2);\r
+      }\r
+      //\r
+      // If a late check is required save off the information.  This is used when consistency checks\r
+      // are required, but certain values might be bound by an impossible consistency check such as\r
+      // if two questions are bound by consistency checks and each only has two possible choices, there\r
+      // would be no way for a user to switch the values.  Thus we require late checking.\r
+      //\r
+      if (Tag->Flags & EFI_IFR_FLAG_LATE_CHECK) {\r
+        CopyMem (&Tag->OldValue, &BackupValue, Tag->StorageWidth);\r
+      } else {\r
+        //\r
+        // In theory, passing the value and the Id are sufficient to determine what needs\r
+        // to be done.  The Id is the key to look for the entry needed in the Inconsistency\r
+        // database.  That will yields operand and ID data - and since the ID's correspond\r
+        // to the NV storage, we can determine the values for other IDs there.\r
+        //\r
+        if (ValueIsNotValid (TRUE, 0, Tag, FileFormTags, &PopUp)) {\r
+          if (PopUp == 0x0000) {\r
+            SelectionComplete = TRUE;\r
+            break;\r
+          }\r
+\r
+          StringPtr = GetToken (PopUp, MenuOption->Handle);\r
+\r
+          CreatePopUp (GetStringWidth (StringPtr) / 2, 3, &NullCharacter, StringPtr, &NullCharacter);\r
+\r
+          do {\r
+            WaitForKeyStroke (&Key);\r
+\r
+            switch (Key.UnicodeChar) {\r
+\r
+            case CHAR_CARRIAGE_RETURN:\r
+              SelectionComplete = TRUE;\r
+              FreePool (StringPtr);\r
+              break;\r
+\r
+            default:\r
+              break;\r
+            }\r
+          } while (!SelectionComplete);\r
+\r
+          Tag->Value  = BackupValue;\r
+          *Value      = BackupValue;\r
+\r
+          CopyMem (&VariableDefinition->NvRamMap[Tag->StorageStart], &Tag->Value, Tag->StorageWidth);\r
+\r
+          //\r
+          // Data associated with a NULL device (in the fake NV storage)\r
+          //\r
+          if (Tag->StorageWidth == (UINT16) 0) {\r
+            CopyMem (&VariableDefinition->FakeNvRamMap[Tag->StorageStart], &Tag->Value, 2);\r
+          }\r
+\r
+          return EFI_DEVICE_ERROR;\r
+        }\r
+      }\r
+\r
+      return EFI_SUCCESS;\r
+      break;\r
+\r
+    case CHAR_BACKSPACE:\r
+      if (ManualInput) {\r
+        if (Count == 0) {\r
+          break;\r
+        }\r
+        //\r
+        // Remove a character\r
+        //\r
+        Number  = PreviousNumber[Count - 1];\r
+        *Value  = (UINT16) Number;\r
+        UpdateStatusBar (INPUT_ERROR, Tag->Flags, FALSE);\r
+        Count--;\r
+        Column--;\r
+        PrintAt (Column, Row, (CHAR16 *) L" ");\r
+      }\r
+      break;\r
+\r
+    default:\r
+      if (ManualInput) {\r
+        if (Key.UnicodeChar > L'9' || Key.UnicodeChar < L'0') {\r
+          UpdateStatusBar (INPUT_ERROR, Tag->Flags, TRUE);\r
+          break;\r
+        }\r
+        //\r
+        // If Count 0-4 is complete, there is no way more is valid\r
+        //\r
+        if (Count > 4) {\r
+          break;\r
+        }\r
+        //\r
+        // Someone typed something valid!\r
+        //\r
+        if (Count != 0) {\r
+          Number = Number * 10 + (Key.UnicodeChar - L'0');\r
+        } else {\r
+          Number = Key.UnicodeChar - L'0';\r
+        }\r
+\r
+        if (Number > Tag->Maximum) {\r
+          UpdateStatusBar (INPUT_ERROR, Tag->Flags, TRUE);\r
+          Number = PreviousNumber[Count];\r
+          break;\r
+        } else {\r
+          UpdateStatusBar (INPUT_ERROR, Tag->Flags, FALSE);\r
+        }\r
+\r
+        Count++;\r
+\r
+        PreviousNumber[Count] = Number;\r
+        *Value                = (UINT16) Number;\r
+        Tag->Value            = (UINT16) Number;\r
+\r
+        PrintCharAt (Column, Row, Key.UnicodeChar);\r
+        Column++;\r
+      }\r
+      break;\r
+    }\r
+  } while (!SelectionComplete);\r
+  return EFI_SUCCESS;\r
+}\r
+//\r
+// Notice that this is at least needed for the ordered list manipulation.\r
+// Left/Right doesn't make sense for this op-code\r
+//\r
+EFI_STATUS\r
+GetSelectionInputPopUp (\r
+  IN  UI_MENU_OPTION              *MenuOption,\r
+  IN  EFI_TAG                     *Tag,\r
+  IN  UINTN                       ValueCount,\r
+  OUT UINT16                      *Value,\r
+  OUT UINT16                      *KeyValue\r
+  )\r
+{\r
+  EFI_INPUT_KEY Key;\r
+  UINTN         Index;\r
+  UINTN         TempIndex;\r
+  CHAR16        *StringPtr;\r
+  CHAR16        *TempStringPtr;\r
+  UINT16        Token;\r
+  UINTN         Index2;\r
+  UINTN         TopOptionIndex;\r
+  UINTN         HighlightPosition;\r
+  UINTN         Start;\r
+  UINTN         End;\r
+  UINTN         Top;\r
+  UINTN         Bottom;\r
+  UINT16        TempValue;\r
+  UINTN         Count;\r
+  UINTN         PopUpMenuLines;\r
+  UINTN         MenuLinesInView;\r
+  UINTN         PopUpWidth;\r
+  CHAR16        Character;\r
+  BOOLEAN       FirstOptionFoundFlag;\r
+  INT32         SavedAttribute;\r
+  EFI_TAG       TagBackup;\r
+  UINT8         *ValueArray;\r
+  UINT8         *ValueArrayBackup;\r
+  UINT8         ValueBackup;\r
+  BOOLEAN       Initialized;\r
+  BOOLEAN       KeyInitialized;\r
+  BOOLEAN       ShowDownArrow;\r
+  BOOLEAN       ShowUpArrow;\r
+  UINTN         DimensionsWidth;\r
+\r
+  DimensionsWidth   = gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn;\r
+\r
+  TempValue         = 0;\r
+  TempIndex         = 0;\r
+  ValueArray        = (UINT8 *) Value;\r
+  ValueArrayBackup  = NULL;\r
+  Initialized       = FALSE;\r
+  KeyInitialized    = FALSE;\r
+  ShowDownArrow     = FALSE;\r
+  ShowUpArrow       = FALSE;\r
+\r
+  if (Tag->Operand == EFI_IFR_ORDERED_LIST_OP) {\r
+    ValueArrayBackup = AllocateZeroPool (Tag->StorageWidth);\r
+    ASSERT (ValueArrayBackup != NULL);\r
+    CopyMem (ValueArrayBackup, ValueArray, ValueCount);\r
+    TempValue = *(UINT8 *) (ValueArray);\r
+    if (ValueArray[0] != 0x00) {\r
+      Initialized = TRUE;\r
+    }\r
+\r
+    for (Index = 0; ValueArray[Index] != 0x00; Index++)\r
+      ;\r
+    ValueCount = Index;\r
+  } else {\r
+    TempValue = *Value;\r
+  }\r
+\r
+  Count                 = 0;\r
+  PopUpWidth            = 0;\r
+\r
+  FirstOptionFoundFlag  = FALSE;\r
+\r
+  StringPtr             = AllocateZeroPool ((gOptionBlockWidth + 1) * 2);\r
+  ASSERT (StringPtr);\r
+\r
+  //\r
+  // Initialization for "One of" pop-up menu\r
+  //\r
+  //\r
+  // Get the number of one of options present and its size\r
+  //\r
+  for (Index = MenuOption->TagIndex; MenuOption->Tags[Index].Operand != EFI_IFR_END_ONE_OF_OP; Index++) {\r
+    if (MenuOption->Tags[Index].Operand == EFI_IFR_ONE_OF_OPTION_OP &&\r
+        !MenuOption->Tags[Index].Suppress) {\r
+      if (!FirstOptionFoundFlag) {\r
+        FirstOptionFoundFlag  = TRUE;\r
+      }\r
+\r
+      Count++;\r
+      Token = MenuOption->Tags[Index].Text;\r
+\r
+      //\r
+      // If this is an ordered list that is initialized\r
+      //\r
+      if (Initialized) {\r
+        for (ValueBackup = (UINT8) MenuOption->TagIndex;\r
+             MenuOption->Tags[ValueBackup].Operand != EFI_IFR_END_OP;\r
+             ValueBackup++\r
+            ) {\r
+          if (MenuOption->Tags[ValueBackup].Value == ((UINT8 *) ValueArrayBackup)[Index - MenuOption->TagIndex - 1]) {\r
+            StringPtr = GetToken (MenuOption->Tags[ValueBackup].Text, MenuOption->Handle);\r
+            break;\r
+          }\r
+        }\r
+      } else {\r
+        StringPtr = GetToken (Token, MenuOption->Handle);\r
+      }\r
+\r
+      if (StrLen (StringPtr) > PopUpWidth) {\r
+        PopUpWidth = StrLen (StringPtr);\r
+      }\r
+\r
+      FreePool (StringPtr);\r
+    }\r
+  }\r
+  //\r
+  // Perform popup menu initialization.\r
+  //\r
+  PopUpMenuLines  = Count;\r
+  PopUpWidth      = PopUpWidth + POPUP_PAD_SPACE_COUNT;\r
+\r
+  SavedAttribute  = gST->ConOut->Mode->Attribute;\r
+  gST->ConOut->SetAttribute (gST->ConOut, POPUP_TEXT | POPUP_BACKGROUND);\r
+\r
+  if ((PopUpWidth + POPUP_FRAME_WIDTH) > DimensionsWidth) {\r
+    PopUpWidth = DimensionsWidth - POPUP_FRAME_WIDTH;\r
+  }\r
+\r
+  Start           = (DimensionsWidth - PopUpWidth - POPUP_FRAME_WIDTH) / 2 + gScreenDimensions.LeftColumn;\r
+  End             = Start + PopUpWidth + POPUP_FRAME_WIDTH;\r
+  Top             = gScreenDimensions.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT;\r
+  Bottom          = gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT;\r
+\r
+  MenuLinesInView = Bottom - Top - 1;\r
+  if (MenuLinesInView >= PopUpMenuLines) {\r
+    Top     = Top + (MenuLinesInView - PopUpMenuLines) / 2;\r
+    Bottom  = Top + PopUpMenuLines + 1;\r
+  } else {\r
+    TempValue     = MenuOption->Tags[MenuOption->TagIndex + 1].Value;\r
+    ShowDownArrow = TRUE;\r
+  }\r
+\r
+  TopOptionIndex    = 1;\r
+  HighlightPosition = 0;\r
+  do {\r
+    if (Initialized) {\r
+      for (Index = MenuOption->TagIndex, Index2 = 0; Index2 < ValueCount; Index++, Index2++) {\r
+        //\r
+        // Set the value for the item we are looking for\r
+        //\r
+        Count = ValueArrayBackup[Index2];\r
+\r
+        //\r
+        // If we hit the end of the Array, we are complete\r
+        //\r
+        if (Count == 0) {\r
+          break;\r
+        }\r
+\r
+        if (MenuOption->Tags[Index].Operand == EFI_IFR_ONE_OF_OPTION_OP) {\r
+          for (ValueBackup = (UINT8) MenuOption->TagIndex;\r
+               MenuOption->Tags[ValueBackup].Operand != EFI_IFR_END_ONE_OF_OP;\r
+               ValueBackup++\r
+              ) {\r
+            //\r
+            // We just found what we are looking for\r
+            //\r
+            if (MenuOption->Tags[ValueBackup].Value == Count) {\r
+              //\r
+              // As long as the two indexes aren't the same, we have\r
+              // two different op-codes we need to swap internally\r
+              //\r
+              if (Index != ValueBackup) {\r
+                //\r
+                // Backup destination tag, then copy source to destination, then copy backup to source location\r
+                //\r
+                CopyMem (&TagBackup, &MenuOption->Tags[Index], sizeof (EFI_TAG));\r
+                CopyMem (&MenuOption->Tags[Index], &MenuOption->Tags[ValueBackup], sizeof (EFI_TAG));\r
+                CopyMem (&MenuOption->Tags[ValueBackup], &TagBackup, sizeof (EFI_TAG));\r
+              } else {\r
+                //\r
+                // If the indexes are the same, then the op-code is where he belongs\r
+                //\r
+              }\r
+            }\r
+          }\r
+        } else {\r
+          //\r
+          // Since this wasn't an option op-code (likely the ordered list op-code) decerement Index2\r
+          //\r
+          Index2--;\r
+        }\r
+      }\r
+    }\r
+    //\r
+    // Clear that portion of the screen\r
+    //\r
+    ClearLines (Start, End, Top, Bottom, POPUP_TEXT | POPUP_BACKGROUND);\r
+\r
+    //\r
+    // Draw "One of" pop-up menu\r
+    //\r
+    Character = (CHAR16) BOXDRAW_DOWN_RIGHT;\r
+    PrintCharAt (Start, Top, Character);\r
+    for (Index = Start; Index + 2 < End; Index++) {\r
+      if ((ShowUpArrow) && ((Index + 1) == (Start + End) / 2)) {\r
+        Character = (CHAR16) GEOMETRICSHAPE_UP_TRIANGLE;\r
+      } else {\r
+        Character = (CHAR16) BOXDRAW_HORIZONTAL;\r
+      }\r
+\r
+      PrintChar (Character);\r
+    }\r
+\r
+    Character = (CHAR16) BOXDRAW_DOWN_LEFT;\r
+    PrintChar (Character);\r
+    Character = (CHAR16) BOXDRAW_VERTICAL;\r
+    for (Index = Top + 1; Index < Bottom; Index++) {\r
+      PrintCharAt (Start, Index, Character);\r
+      PrintCharAt (End - 1, Index, Character);\r
+    }\r
+    //\r
+    // Display the One of options\r
+    //\r
+    Index2 = Top + 1;\r
+    for (Index = MenuOption->TagIndex + TopOptionIndex;\r
+         (MenuOption->Tags[Index].Operand != EFI_IFR_END_ONE_OF_OP) && (Index2 < Bottom);\r
+         Index++\r
+        ) {\r
+      if (MenuOption->Tags[Index].Operand == EFI_IFR_ONE_OF_OPTION_OP) {\r
+        Token = MenuOption->Tags[Index].Text;\r
+        if (Initialized) {\r
+          for (ValueBackup = (UINT8) MenuOption->TagIndex;\r
+               MenuOption->Tags[ValueBackup].Operand != EFI_IFR_END_ONE_OF_OP;\r
+               ValueBackup++\r
+              ) {\r
+            if (MenuOption->Tags[ValueBackup].Value == ((UINT8 *) ValueArrayBackup)[Index - MenuOption->TagIndex - 1]) {\r
+              StringPtr = GetToken (MenuOption->Tags[ValueBackup].Text, MenuOption->Handle);\r
+              break;\r
+            }\r
+          }\r
+        } else {\r
+          ValueBackup = (UINT8) Index;\r
+          StringPtr   = GetToken (Token, MenuOption->Handle);\r
+        }\r
+        //\r
+        // If the string occupies multiple lines, truncate it to fit in one line,\r
+        // and append a "..." for indication.\r
+        //\r
+        if (StrLen (StringPtr) > (PopUpWidth - 1)) {\r
+          TempStringPtr = AllocateZeroPool (sizeof (CHAR16) * (PopUpWidth - 1));\r
+          ASSERT (TempStringPtr != NULL);\r
+          CopyMem (TempStringPtr, StringPtr, (sizeof (CHAR16) * (PopUpWidth - 5)));\r
+          FreePool (StringPtr);\r
+          StringPtr = TempStringPtr;\r
+          StrCat (StringPtr, (CHAR16 *) L"...");\r
+        }\r
+        //\r
+        // Code to display the text should go here. Follwed by the [*]\r
+        //\r
+        if (MenuOption->Tags[ValueBackup].Suppress == TRUE) {\r
+          //\r
+          // Don't show the one, so decrease the Index2 for balance\r
+          //\r
+          Index2--;\r
+        } else if (MenuOption->Tags[ValueBackup].GrayOut == TRUE) {\r
+          //\r
+          // Gray Out the one\r
+          //\r
+          gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_GRAYED | POPUP_BACKGROUND);\r
+          PrintStringAt (Start + 2, Index2, StringPtr);\r
+          gST->ConOut->SetAttribute (gST->ConOut, POPUP_TEXT | POPUP_BACKGROUND);\r
+        } else if (MenuOption->Tags[ValueBackup].Value == TempValue) {\r
+          //\r
+          // Highlight the selected one\r
+          //\r
+          gST->ConOut->SetAttribute (gST->ConOut, PICKLIST_HIGHLIGHT_TEXT | PICKLIST_HIGHLIGHT_BACKGROUND);\r
+          PrintStringAt (Start + 2, Index2, StringPtr);\r
+          gST->ConOut->SetAttribute (gST->ConOut, POPUP_TEXT | POPUP_BACKGROUND);\r
+          HighlightPosition = Index2;\r
+        } else {\r
+          gST->ConOut->SetAttribute (gST->ConOut, POPUP_TEXT | POPUP_BACKGROUND);\r
+          PrintStringAt (Start + 2, Index2, StringPtr);\r
+        }\r
+\r
+        FreePool (StringPtr);\r
+        Index2 = Index2 + 1;\r
+      }\r
+    }\r
+\r
+    Character = (CHAR16) BOXDRAW_UP_RIGHT;\r
+    PrintCharAt (Start, Bottom, Character);\r
+    for (Index = Start; Index + 2 < End; Index++) {\r
+      if ((ShowDownArrow) && ((Index + 1) == (Start + End) / 2)) {\r
+        Character = (CHAR16) GEOMETRICSHAPE_DOWN_TRIANGLE;\r
+      } else {\r
+        Character = (CHAR16) BOXDRAW_HORIZONTAL;\r
+      }\r
+\r
+      PrintChar (Character);\r
+    }\r
+\r
+    Character = (CHAR16) BOXDRAW_UP_LEFT;\r
+    PrintChar (Character);\r
+    //\r
+    // Get User selection and change TempValue if necessary\r
+    //\r
+    //\r
+    // Stop: One of pop-up menu\r
+    //\r
+    Key.UnicodeChar = CHAR_NULL;\r
+    if ((gDirection == SCAN_UP) || (gDirection == SCAN_DOWN)) {\r
+      Key.ScanCode  = gDirection;\r
+      gDirection    = 0;\r
+      goto TheKey;\r
+    }\r
+\r
+    if (!KeyInitialized) {\r
+      if (MenuOption->ThisTag->Operand == EFI_IFR_ONE_OF_OP) {\r
+        *KeyValue = MenuOption->Tags[MenuOption->TagIndex + 1].Key;\r
+      } else {\r
+        *KeyValue = MenuOption->ThisTag->Key;\r
+      }\r
+\r
+      KeyInitialized = TRUE;\r
+    }\r
+\r
+    WaitForKeyStroke (&Key);\r
+\r
+TheKey:\r
+    switch (Key.UnicodeChar) {\r
+    case '+':\r
+    case '-':\r
+      //\r
+      // If an ordered list op-code, we will allow for a popup of +/- keys\r
+      // to create an ordered list of items\r
+      //\r
+      if (Tag->Operand == EFI_IFR_ORDERED_LIST_OP) {\r
+        if (Key.UnicodeChar == '+') {\r
+          if ((TopOptionIndex > 1) && (HighlightPosition == (Top + 1))) {\r
+            //\r
+            // Highlight reaches the top of the popup window, scroll one menu item.\r
+            //\r
+            TopOptionIndex--;\r
+            ShowDownArrow = TRUE;\r
+          }\r
+\r
+          if (TopOptionIndex == 1) {\r
+            ShowUpArrow = FALSE;\r
+          }\r
+        } else {\r
+          if (((TopOptionIndex + MenuLinesInView) <= PopUpMenuLines) && (HighlightPosition == (Bottom - 1))) {\r
+            //\r
+            // Highlight reaches the bottom of the popup window, scroll one menu item.\r
+            //\r
+            TopOptionIndex++;\r
+            ShowUpArrow = TRUE;\r
+          }\r
+\r
+          if ((TopOptionIndex + MenuLinesInView) == (PopUpMenuLines + 1)) {\r
+            ShowDownArrow = FALSE;\r
+          }\r
+        }\r
+\r
+        for (Index = MenuOption->TagIndex + TopOptionIndex;\r
+             MenuOption->Tags[Index].Operand != EFI_IFR_END_ONE_OF_OP;\r
+             Index++\r
+            ) {\r
+          if (MenuOption->Tags[Index].Operand == EFI_IFR_ORDERED_LIST_OP) {\r
+            continue;\r
+          }\r
+\r
+          if (Key.UnicodeChar == '+') {\r
+            TempIndex = Index - 1;\r
+          } else {\r
+            TempIndex = Index + 1;\r
+          }\r
+          //\r
+          // Is this the current tag we are on?\r
+          //\r
+          if (MenuOption->Tags[Index].Value == TempValue) {\r
+            //\r
+            // Is this prior tag a valid choice?  If not, bail out\r
+            //\r
+            if (MenuOption->Tags[TempIndex].Operand == EFI_IFR_ONE_OF_OPTION_OP) {\r
+              //\r
+              // Copy the destination tag to the local variable\r
+              //\r
+              CopyMem (&TagBackup, &MenuOption->Tags[TempIndex], sizeof (EFI_TAG));\r
+              //\r
+              // Copy the current tag to the tag location before us\r
+              //\r
+              CopyMem (&MenuOption->Tags[TempIndex], &MenuOption->Tags[Index], sizeof (EFI_TAG));\r
+              //\r
+              // Copy the backed up tag to the current location\r
+              //\r
+              CopyMem (&MenuOption->Tags[Index], &TagBackup, sizeof (EFI_TAG));\r
+\r
+              //\r
+              // Adjust the array of values\r
+              //\r
+              for (Index = 0; Index < ValueCount; Index++) {\r
+                if (ValueArrayBackup[Index] == (UINT8) TempValue) {\r
+                  if (Key.UnicodeChar == '+') {\r
+                    if (Index == 0) {\r
+                      //\r
+                      // It is the top of the array already\r
+                      //\r
+                      break;\r
+                    }\r
+\r
+                    TempIndex = Index - 1;\r
+                  } else {\r
+                    if ((Index + 1) == ValueCount) {\r
+                      //\r
+                      // It is the bottom of the array already\r
+                      //\r
+                      break;\r
+                    }\r
+\r
+                    TempIndex = Index + 1;\r
+                  }\r
+\r
+                  ValueBackup                 = ValueArrayBackup[TempIndex];\r
+                  ValueArrayBackup[TempIndex] = ValueArrayBackup[Index];\r
+                  ValueArrayBackup[Index]     = ValueBackup;\r
+                  Initialized                 = TRUE;\r
+                  break;\r
+                }\r
+              }\r
+              break;\r
+            } else {\r
+              break;\r
+            }\r
+          }\r
+        }\r
+      }\r
+      break;\r
+\r
+    case CHAR_NULL:\r
+      switch (Key.ScanCode) {\r
+      case SCAN_UP:\r
+      case SCAN_DOWN:\r
+        if (Key.ScanCode == SCAN_UP) {\r
+          if ((TopOptionIndex > 1) && (HighlightPosition == (Top + 1))) {\r
+            //\r
+            // Highlight reaches the top of the popup window, scroll one menu item.\r
+            //\r
+            TopOptionIndex--;\r
+            ShowDownArrow = TRUE;\r
+          }\r
+\r
+          if (TopOptionIndex == 1) {\r
+            ShowUpArrow = FALSE;\r
+          }\r
+        } else {\r
+          if (((TopOptionIndex + MenuLinesInView) <= PopUpMenuLines) && (HighlightPosition == (Bottom - 1))) {\r
+            //\r
+            // Highlight reaches the bottom of the popup window, scroll one menu item.\r
+            //\r
+            TopOptionIndex++;\r
+            ShowUpArrow = TRUE;\r
+          }\r
+\r
+          if ((TopOptionIndex + MenuLinesInView) == (PopUpMenuLines + 1)) {\r
+            ShowDownArrow = FALSE;\r
+          }\r
+        }\r
+\r
+        for (Index = MenuOption->TagIndex + TopOptionIndex;\r
+             MenuOption->Tags[Index].Operand != EFI_IFR_END_ONE_OF_OP;\r
+             Index++\r
+            ) {\r
+          if (MenuOption->Tags[Index].Operand == EFI_IFR_ONE_OF_OPTION_OP) {\r
+            if (Initialized) {\r
+              for (Index = 0; (ValueArrayBackup[Index] != TempValue) && (Index < ValueCount); Index++)\r
+                ;\r
+\r
+              //\r
+              // Did we hit the end of the array?  Either get the first TempValue or the next one\r
+              //\r
+              if (Key.ScanCode == SCAN_UP) {\r
+                if (Index == 0) {\r
+                  TempValue = ValueArrayBackup[0];\r
+                } else {\r
+                  TempValue = ValueArrayBackup[Index - 1];\r
+                }\r
+              } else {\r
+                if ((Index + 1) == ValueCount) {\r
+                  TempValue = ValueArrayBackup[Index];\r
+                } else {\r
+                  TempValue = ValueArrayBackup[Index + 1];\r
+                }\r
+              }\r
+              break;\r
+            } else {\r
+              if (Key.ScanCode == SCAN_UP) {\r
+                TempIndex = Index - 1;\r
+\r
+                //\r
+                // Keep going until meets meaningful tag.\r
+                //\r
+                while ((MenuOption->Tags[TempIndex].Operand != EFI_IFR_ONE_OF_OPTION_OP  &&\r
+                         MenuOption->Tags[TempIndex].Operand != EFI_IFR_ONE_OF_OP        &&\r
+                         MenuOption->Tags[TempIndex].Operand != EFI_IFR_END_ONE_OF_OP)\r
+                       ||\r
+                       (MenuOption->Tags[TempIndex].Operand == EFI_IFR_ONE_OF_OPTION_OP  &&\r
+                         (MenuOption->Tags[TempIndex].Suppress || MenuOption->Tags[TempIndex].GrayOut))) {\r
+                  TempIndex--;\r
+                }\r
+              } else {\r
+                TempIndex = Index + 1;\r
+\r
+                //\r
+                // Keep going until meets meaningful tag.\r
+                //\r
+                while ((MenuOption->Tags[TempIndex].Operand != EFI_IFR_ONE_OF_OPTION_OP  &&\r
+                         MenuOption->Tags[TempIndex].Operand != EFI_IFR_ONE_OF_OP        &&\r
+                         MenuOption->Tags[TempIndex].Operand != EFI_IFR_END_ONE_OF_OP)\r
+                       ||\r
+                       (MenuOption->Tags[TempIndex].Operand == EFI_IFR_ONE_OF_OPTION_OP  &&\r
+                         (MenuOption->Tags[TempIndex].Suppress || MenuOption->Tags[TempIndex].GrayOut))) {\r
+                  TempIndex++;\r
+                }\r
+              }\r
+              //\r
+              // The option value is the same as what is stored in NV store.  This is where we take action\r
+              //\r
+              if (MenuOption->Tags[Index].Value == TempValue) {\r
+                //\r
+                // Only if the previous op-code is an option can we select it, otherwise we are at the left-most option\r
+                //\r
+                if (MenuOption->Tags[TempIndex].Operand == EFI_IFR_ONE_OF_OPTION_OP) {\r
+                  TempValue = MenuOption->Tags[TempIndex].Value;\r
+                  *KeyValue = MenuOption->Tags[TempIndex].Key;\r
+                } else {\r
+                  TempValue = MenuOption->Tags[Index].Value;\r
+                  *KeyValue = MenuOption->Tags[Index].Key;\r
+                }\r
+                break;\r
+              }\r
+            }\r
+          }\r
+        }\r
+        break;\r
+\r
+      case SCAN_ESC:\r
+        gST->ConOut->SetAttribute (gST->ConOut, SavedAttribute);\r
+        if (ValueArrayBackup != NULL) {\r
+          FreePool (ValueArrayBackup);\r
+        }\r
+\r
+        return EFI_DEVICE_ERROR;\r
+\r
+      default:\r
+        break;\r
+      }\r
+\r
+      break;\r
+\r
+    case CHAR_CARRIAGE_RETURN:\r
+      //\r
+      // return the current selection\r
+      //\r
+      if (Tag->Operand == EFI_IFR_ORDERED_LIST_OP) {\r
+        CopyMem (ValueArray, ValueArrayBackup, ValueCount);\r
+        FreePool (ValueArrayBackup);\r
+      } else {\r
+        *Value = TempValue;\r
+      }\r
+\r
+      goto Done;\r
+\r
+    default:\r
+      break;\r
+    }\r
+  } while (1);\r
+\r
+Done:\r
+  gST->ConOut->SetAttribute (gST->ConOut, SavedAttribute);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+WaitForKeyStroke (\r
+  OUT  EFI_INPUT_KEY           *Key\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  do {\r
+    UiWaitForSingleEvent (gST->ConIn->WaitForKey, 0);\r
+    Status = gST->ConIn->ReadKeyStroke (gST->ConIn, Key);\r
+  } while (EFI_ERROR(Status));\r
+\r
+  return Status;\r
+}\r
diff --git a/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Presentation.c b/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Presentation.c
new file mode 100644 (file)
index 0000000..be5ba57
--- /dev/null
@@ -0,0 +1,1490 @@
+/*++\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
+  Presentation.c\r
+\r
+Abstract:\r
+\r
+  Some presentation routines.\r
+\r
+Revision History:\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "Setup.h"\r
+#include "Ui.h"\r
+#include "Colors.h"\r
+\r
+VOID\r
+ClearLines (\r
+  UINTN                                       LeftColumn,\r
+  UINTN                                       RightColumn,\r
+  UINTN                                       TopRow,\r
+  UINTN                                       BottomRow,\r
+  UINTN                                       TextAttribute\r
+  )\r
+{\r
+  CHAR16  *Buffer;\r
+  UINTN   Row;\r
+\r
+  //\r
+  // For now, allocate an arbitrarily long buffer\r
+  //\r
+  Buffer = AllocateZeroPool (0x10000);\r
+  ASSERT (Buffer != NULL);\r
+\r
+  //\r
+  // Set foreground and background as defined\r
+  //\r
+  gST->ConOut->SetAttribute (gST->ConOut, TextAttribute);\r
+\r
+  //\r
+  // Much faster to buffer the long string instead of print it a character at a time\r
+  //\r
+  SetUnicodeMem (Buffer, RightColumn - LeftColumn, L' ');\r
+\r
+  //\r
+  // Clear the desired area with the appropriate foreground/background\r
+  //\r
+  for (Row = TopRow; Row <= BottomRow; Row++) {\r
+    PrintStringAt (LeftColumn, Row, Buffer);\r
+  }\r
+\r
+  gST->ConOut->SetCursorPosition (gST->ConOut, LeftColumn, TopRow);\r
+\r
+  FreePool (Buffer);\r
+  return ;\r
+}\r
+\r
+VOID\r
+NewStrCat (\r
+  CHAR16                                      *Destination,\r
+  CHAR16                                      *Source\r
+  )\r
+{\r
+  UINTN Length;\r
+\r
+  for (Length = 0; Destination[Length] != 0; Length++)\r
+    ;\r
+\r
+  //\r
+  // We now have the length of the original string\r
+  // We can safely assume for now that we are concatenating a narrow value to this string.\r
+  // For instance, the string is "XYZ" and cat'ing ">"\r
+  // If this assumption changes, we need to make this routine a bit more complex\r
+  //\r
+  Destination[Length] = (CHAR16) NARROW_CHAR;\r
+  Length++;\r
+\r
+  StrCpy (Destination + Length, Source);\r
+}\r
+\r
+UINTN\r
+GetStringWidth (\r
+  CHAR16                                      *String\r
+  )\r
+{\r
+  UINTN Index;\r
+  UINTN Count;\r
+  UINTN IncrementValue;\r
+\r
+  Index           = 0;\r
+  Count           = 0;\r
+  IncrementValue  = 1;\r
+\r
+  do {\r
+    //\r
+    // Advance to the null-terminator or to the first width directive\r
+    //\r
+    for (;\r
+         (String[Index] != NARROW_CHAR) && (String[Index] != WIDE_CHAR) && (String[Index] != 0);\r
+         Index++, Count = Count + IncrementValue\r
+        )\r
+      ;\r
+\r
+    //\r
+    // We hit the null-terminator, we now have a count\r
+    //\r
+    if (String[Index] == 0) {\r
+      break;\r
+    }\r
+    //\r
+    // We encountered a narrow directive - strip it from the size calculation since it doesn't get printed\r
+    // and also set the flag that determines what we increment by.(if narrow, increment by 1, if wide increment by 2)\r
+    //\r
+    if (String[Index] == NARROW_CHAR) {\r
+      //\r
+      // Skip to the next character\r
+      //\r
+      Index++;\r
+      IncrementValue = 1;\r
+    } else {\r
+      //\r
+      // Skip to the next character\r
+      //\r
+      Index++;\r
+      IncrementValue = 2;\r
+    }\r
+  } while (String[Index] != 0);\r
+\r
+  //\r
+  // Increment by one to include the null-terminator in the size\r
+  //\r
+  Count++;\r
+\r
+  return Count * sizeof (CHAR16);\r
+}\r
+\r
+VOID\r
+DisplayPageFrame (\r
+  VOID\r
+  )\r
+{\r
+  UINTN             Index;\r
+  UINT8             Line;\r
+  UINT8             Alignment;\r
+  CHAR16            Character;\r
+  CHAR16            *Buffer;\r
+  CHAR16            *StrFrontPageBanner;\r
+  EFI_SCREEN_DESCRIPTOR LocalScreen;\r
+  UINTN             Row;\r
+\r
+  ZeroMem (&LocalScreen, sizeof (EFI_SCREEN_DESCRIPTOR));\r
+  gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &LocalScreen.RightColumn, &LocalScreen.BottomRow);\r
+  ClearLines (0, LocalScreen.RightColumn, 0, LocalScreen.BottomRow, KEYHELP_BACKGROUND);\r
+\r
+  CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));\r
+\r
+  //\r
+  // For now, allocate an arbitrarily long buffer\r
+  //\r
+  Buffer = AllocateZeroPool (0x10000);\r
+  ASSERT (Buffer != NULL);\r
+\r
+  Character = (CHAR16) BOXDRAW_HORIZONTAL;\r
+\r
+  for (Index = 0; Index + 2 < (LocalScreen.RightColumn - LocalScreen.LeftColumn); Index++) {\r
+    Buffer[Index] = Character;\r
+  }\r
+\r
+  if (gClassOfVfr == EFI_FRONT_PAGE_SUBCLASS) {\r
+    //\r
+    //    ClearLines(0, LocalScreen.RightColumn, 0, BANNER_HEIGHT-1, BANNER_TEXT | BANNER_BACKGROUND);\r
+    //\r
+    ClearLines (\r
+      LocalScreen.LeftColumn,\r
+      LocalScreen.RightColumn,\r
+      LocalScreen.TopRow,\r
+      FRONT_PAGE_HEADER_HEIGHT - 1 + LocalScreen.TopRow,\r
+      BANNER_TEXT | BANNER_BACKGROUND\r
+      );\r
+    //\r
+    //    for (Line = 0; Line < BANNER_HEIGHT; Line++) {\r
+    //\r
+    for (Line = (UINT8) LocalScreen.TopRow; Line < BANNER_HEIGHT + (UINT8) LocalScreen.TopRow; Line++) {\r
+      //\r
+      //      for (Alignment = 0; Alignment < BANNER_COLUMNS; Alignment++) {\r
+      //\r
+      for (Alignment = (UINT8) LocalScreen.LeftColumn;\r
+           Alignment < BANNER_COLUMNS + (UINT8) LocalScreen.LeftColumn;\r
+           Alignment++\r
+          ) {\r
+        if (BannerData->Banner[Line - (UINT8) LocalScreen.TopRow][Alignment - (UINT8) LocalScreen.LeftColumn] != 0x0000) {\r
+          StrFrontPageBanner = GetToken (\r
+                                BannerData->Banner[Line - (UINT8) LocalScreen.TopRow][Alignment - (UINT8) LocalScreen.LeftColumn],\r
+                                FrontPageHandle\r
+                                );\r
+        } else {\r
+          continue;\r
+        }\r
+\r
+        switch (Alignment - LocalScreen.LeftColumn) {\r
+        case 0:\r
+          //\r
+          // Handle left column\r
+          //\r
+          PrintStringAt (LocalScreen.LeftColumn, Line, StrFrontPageBanner);\r
+          break;\r
+\r
+        case 1:\r
+          //\r
+          // Handle center column\r
+          //\r
+          PrintStringAt (\r
+            LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3,\r
+            Line,\r
+            StrFrontPageBanner\r
+            );\r
+          break;\r
+\r
+        case 2:\r
+          //\r
+          // Handle right column\r
+          //\r
+          PrintStringAt (\r
+            LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) * 2 / 3,\r
+            Line,\r
+            StrFrontPageBanner\r
+            );\r
+          break;\r
+        }\r
+\r
+        FreePool (StrFrontPageBanner);\r
+      }\r
+    }\r
+  }\r
+\r
+  ClearLines (\r
+    LocalScreen.LeftColumn,\r
+    LocalScreen.RightColumn,\r
+    LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT,\r
+    LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 1,\r
+    KEYHELP_TEXT | KEYHELP_BACKGROUND\r
+    );\r
+\r
+  if (gClassOfVfr != EFI_FRONT_PAGE_SUBCLASS) {\r
+    ClearLines (\r
+      LocalScreen.LeftColumn,\r
+      LocalScreen.RightColumn,\r
+      LocalScreen.TopRow,\r
+      LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 1,\r
+      TITLE_TEXT | TITLE_BACKGROUND\r
+      );\r
+    //\r
+    // Print Top border line\r
+    // +------------------------------------------------------------------------------+\r
+    // ?                                                                             ?\r
+    // +------------------------------------------------------------------------------+\r
+    //\r
+    Character = (CHAR16) BOXDRAW_DOWN_RIGHT;\r
+\r
+    PrintChar (Character);\r
+    PrintString (Buffer);\r
+\r
+    Character = (CHAR16) BOXDRAW_DOWN_LEFT;\r
+    PrintChar (Character);\r
+\r
+    Character = (CHAR16) BOXDRAW_VERTICAL;\r
+    for (Row = LocalScreen.TopRow + 1; Row <= LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 2; Row++) {\r
+      PrintCharAt (LocalScreen.LeftColumn, Row, Character);\r
+      PrintCharAt (LocalScreen.RightColumn - 1, Row, Character);\r
+    }\r
+\r
+    Character = (CHAR16) BOXDRAW_UP_RIGHT;\r
+    PrintCharAt (LocalScreen.LeftColumn, LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 1, Character);\r
+    PrintString (Buffer);\r
+\r
+    Character = (CHAR16) BOXDRAW_UP_LEFT;\r
+    PrintChar (Character);\r
+\r
+    if (gClassOfVfr == EFI_SETUP_APPLICATION_SUBCLASS) {\r
+      //\r
+      // Print Bottom border line\r
+      // +------------------------------------------------------------------------------+\r
+      // ?                                                                             ?\r
+      // +------------------------------------------------------------------------------+\r
+      //\r
+      Character = (CHAR16) BOXDRAW_DOWN_RIGHT;\r
+      PrintCharAt (LocalScreen.LeftColumn, LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT, Character);\r
+\r
+      PrintString (Buffer);\r
+\r
+      Character = (CHAR16) BOXDRAW_DOWN_LEFT;\r
+      PrintChar (Character);\r
+      Character = (CHAR16) BOXDRAW_VERTICAL;\r
+      for (Row = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT + 1;\r
+           Row <= LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 2;\r
+           Row++\r
+          ) {\r
+        PrintCharAt (LocalScreen.LeftColumn, Row, Character);\r
+        PrintCharAt (LocalScreen.RightColumn - 1, Row, Character);\r
+      }\r
+\r
+      Character = (CHAR16) BOXDRAW_UP_RIGHT;\r
+      PrintCharAt (LocalScreen.LeftColumn, LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 1, Character);\r
+\r
+      PrintString (Buffer);\r
+\r
+      Character = (CHAR16) BOXDRAW_UP_LEFT;\r
+      PrintChar (Character);\r
+    }\r
+  }\r
+\r
+  FreePool (Buffer);\r
+\r
+}\r
+\r
+/*\r
++------------------------------------------------------------------------------+\r
+?F2=Previous Page                 Setup Page                                  ?\r
++------------------------------------------------------------------------------+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
++------------------------------------------------------------------------------+\r
+?F1=Scroll Help                 F9=Reset to Defaults        F10=Save and Exit ?\r
+| ^"=Move Highlight          <Spacebar> Toggles Checkbox   Esc=Discard Changes |\r
++------------------------------------------------------------------------------+\r
+*/\r
+STATIC\r
+UI_MENU_OPTION *\r
+DisplayForm (\r
+  OUT UI_MENU_OPTION              *Selection,\r
+  IN  UINT16                      FormHandle,\r
+  IN  UINT16                      TitleToken,\r
+  IN  EFI_FORM_TAGS               FormTags,\r
+  IN  EFI_FILE_FORM_TAGS          *FileFormTagsHead,\r
+  IN  UINT8                       *CallbackData\r
+  )\r
+{\r
+  CHAR16              *StringPtr;\r
+  UINTN               Index;\r
+  UINTN               Count;\r
+  UINT16              MenuItemCount;\r
+  EFI_HII_HANDLE      Handle;\r
+  UINT16              FormId;\r
+  STRING_REF          String;\r
+  EFI_FILE_FORM_TAGS  *FileFormTags;\r
+  BOOLEAN             SuppressIf;\r
+  BOOLEAN             Suppress;\r
+  BOOLEAN             GrayOut;\r
+  BOOLEAN             Conditional;\r
+  EFI_SCREEN_DESCRIPTOR   LocalScreen;\r
+  UINT16              Width;\r
+  UINTN               ArrayEntry;\r
+  CHAR16              *OutputString;\r
+\r
+  Handle        = Selection->Handle;\r
+  FormId        = 0;\r
+  String        = 0;\r
+  MenuItemCount = 0;\r
+  ArrayEntry    = 0;\r
+  OutputString  = NULL;\r
+\r
+  CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));\r
+\r
+  //\r
+  // If we hit a F2 (previous) we already nuked the menu and are simply carrying around what information we need\r
+  //\r
+  if (Selection->Previous) {\r
+    Selection->Previous = FALSE;\r
+  } else {\r
+    UiFreeMenu ();\r
+    UiInitMenu ();\r
+  }\r
+\r
+  StringPtr = GetToken (TitleToken, Handle);\r
+\r
+  if (gClassOfVfr != EFI_FRONT_PAGE_SUBCLASS) {\r
+    gST->ConOut->SetAttribute (gST->ConOut, TITLE_TEXT | TITLE_BACKGROUND);\r
+    PrintStringAt (\r
+      (LocalScreen.RightColumn + LocalScreen.LeftColumn - GetStringWidth (StringPtr) / 2) / 2,\r
+      LocalScreen.TopRow + 1,\r
+      StringPtr\r
+      );\r
+  }\r
+\r
+  if (gClassOfVfr == EFI_SETUP_APPLICATION_SUBCLASS) {\r
+    gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_TEXT | KEYHELP_BACKGROUND);\r
+\r
+    //\r
+    // Display the infrastructure strings\r
+    //\r
+    if (!IsListEmpty (&gMenuList)) {\r
+      PrintStringAt (LocalScreen.LeftColumn + 2, LocalScreen.TopRow + 1, gFunctionTwoString);\r
+    }\r
+\r
+    PrintStringAt (LocalScreen.LeftColumn + 2, LocalScreen.BottomRow - 4, gFunctionOneString);\r
+    PrintStringAt (\r
+      LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3,\r
+      LocalScreen.BottomRow - 4,\r
+      gFunctionNineString\r
+      );\r
+    PrintStringAt (\r
+      LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) * 2 / 3,\r
+      LocalScreen.BottomRow - 4,\r
+      gFunctionTenString\r
+      );\r
+    PrintAt (LocalScreen.LeftColumn + 2, LocalScreen.BottomRow - 3, (CHAR16 *) L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);\r
+    PrintStringAt (\r
+      LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3,\r
+      LocalScreen.BottomRow - 3,\r
+      gEscapeString\r
+      );\r
+  }\r
+  //\r
+  // Remove Buffer allocated for StringPtr after it has been used.\r
+  //\r
+  FreePool (StringPtr);\r
+\r
+  for (Index = 0; FormTags.Tags[Index].Operand != EFI_IFR_END_FORM_OP; Index++) {\r
+    GrayOut       = FALSE;\r
+    Suppress      = FALSE;\r
+    SuppressIf    = FALSE;\r
+    Conditional   = FALSE;\r
+    FileFormTags  = FileFormTagsHead;\r
+\r
+    if (FormTags.Tags[Index].Operand == EFI_IFR_FORM_OP) {\r
+      FormId = FormTags.Tags[Index].Id;\r
+    }\r
+    //\r
+    // This gives us visibility to the FileFormTags->NvRamMap to check things\r
+    // ActiveIfr is a global maintained by the menuing code to ensure that we\r
+    // are pointing to the correct formset's file data.\r
+    //\r
+    for (Count = 0; Count < gActiveIfr; Count++) {\r
+      FileFormTags = FileFormTags->NextFile;\r
+    }\r
+    //\r
+    //  GrayoutIf [SuppressIf]\r
+    //    <BOOLEANS>\r
+    //      OpCode(s)\r
+    //  EndIf\r
+    //\r
+    //  SuppressIf [GrayoutIf]\r
+    //    <BOOLEANS>\r
+    //      OpCode(s)\r
+    //  EndIf\r
+    //\r
+    Count = 0;\r
+\r
+    do {\r
+      switch (FormTags.Tags[Index].Operand) {\r
+      case EFI_IFR_SUPPRESS_IF_OP:\r
+        SuppressIf = TRUE;\r
+\r
+      case EFI_IFR_GRAYOUT_IF_OP:\r
+\r
+        Conditional = TRUE;\r
+\r
+        //\r
+        // Advance to the next op-code\r
+        //\r
+        Index++;\r
+\r
+        //\r
+        // We are now pointing to the beginning of the consistency checking.  Let's fast forward\r
+        // through the AND/OR/NOT data to come up with some meaningful ID data.\r
+        //\r
+        for (;\r
+             FormTags.Tags[Index].Operand == EFI_IFR_AND_OP   ||\r
+             FormTags.Tags[Index].Operand == EFI_IFR_OR_OP    ||\r
+             FormTags.Tags[Index].Operand == EFI_IFR_GT_OP    ||\r
+             FormTags.Tags[Index].Operand == EFI_IFR_GE_OP    ||\r
+             FormTags.Tags[Index].Operand == EFI_IFR_NOT_OP;\r
+           Index++\r
+            )\r
+          ;\r
+\r
+        //\r
+        // We need to walk through the consistency checks until we hit the end of the consistency\r
+        // FALSE means evaluate this single expression\r
+        // The ConsistencyId refers to which expression in the Consistency database to use\r
+        //\r
+        if (SuppressIf) {\r
+          Suppress = ValueIsNotValid (\r
+                      FALSE,\r
+                      FormTags.Tags[Index].ConsistencyId,\r
+                      &FormTags.Tags[Index],\r
+                      FileFormTags,\r
+                      &String\r
+                      );\r
+          SuppressIf = FALSE;\r
+        } else {\r
+          GrayOut = ValueIsNotValid (\r
+                      FALSE,\r
+                      FormTags.Tags[Index].ConsistencyId,\r
+                      &FormTags.Tags[Index],\r
+                      FileFormTags,\r
+                      &String\r
+                      );\r
+        }\r
+        //\r
+        // Advance to the end of the expression (Will land us at a grayoutif/suppressif or the op-code being affected)\r
+        //\r
+        for (;\r
+             FormTags.Tags[Index].Operand == EFI_IFR_EQ_ID_VAL_OP ||\r
+             FormTags.Tags[Index].Operand == EFI_IFR_EQ_VAR_VAL_OP ||\r
+             FormTags.Tags[Index].Operand == EFI_IFR_EQ_ID_ID_OP ||\r
+             FormTags.Tags[Index].Operand == EFI_IFR_EQ_ID_LIST_OP ||\r
+             FormTags.Tags[Index].Operand == EFI_IFR_NOT_OP ||\r
+             FormTags.Tags[Index].Operand == EFI_IFR_AND_OP ||\r
+             FormTags.Tags[Index].Operand == EFI_IFR_OR_OP ||\r
+             FormTags.Tags[Index].Operand == EFI_IFR_TRUE_OP ||\r
+             FormTags.Tags[Index].Operand == EFI_IFR_FALSE_OP ||\r
+             FormTags.Tags[Index].Operand == EFI_IFR_GT_OP    ||\r
+             FormTags.Tags[Index].Operand == EFI_IFR_GE_OP    ||\r
+             FormTags.Tags[Index].Operand == EFI_IFR_LABEL_OP;\r
+           Index++\r
+            )\r
+          ;\r
+        break;\r
+\r
+      default:\r
+        goto GetOut;\r
+      }\r
+      //\r
+      // Do this two times (at most will see a suppress and grayout combination\r
+      //\r
+      Count++;\r
+    } while (Count < 2);\r
+\r
+GetOut:\r
+    do {\r
+      if (GrayOut) {\r
+        FormTags.Tags[Index].GrayOut = TRUE;\r
+      } else {\r
+        FormTags.Tags[Index].GrayOut = FALSE;\r
+      }\r
+      if (Suppress && FormTags.Tags[Index].Operand == EFI_IFR_ONE_OF_OPTION_OP) {\r
+        //\r
+        // Only need .Suppress field when the tag is a one_of_option. For other cases, omit them directly.\r
+        //\r
+        FormTags.Tags[Index].Suppress = TRUE;\r
+      } else {\r
+        FormTags.Tags[Index].Suppress = FALSE;\r
+      }\r
+\r
+      if ((\r
+            FormTags.Tags[Index].NumberOfLines > 0 ||\r
+            FormTags.Tags[Index].Operand == EFI_IFR_DATE_OP ||\r
+            FormTags.Tags[Index].Operand == EFI_IFR_TIME_OP\r
+          ) &&\r
+          !Suppress\r
+          ) {\r
+\r
+        StringPtr = GetToken (FormTags.Tags[Index].Text, Handle);\r
+\r
+        Width     = GetWidth (&FormTags.Tags[Index], Handle);\r
+\r
+        //\r
+        // This data can be retrieved over and over again.  Therefore, reset to original values\r
+        // before processing otherwise things will start growing linearly\r
+        //\r
+        if (FormTags.Tags[Index].NumberOfLines > 1) {\r
+          FormTags.Tags[Index].NumberOfLines = 1;\r
+        }\r
+\r
+        for (Count = 0; GetLineByWidth (StringPtr, Width, &ArrayEntry, &OutputString) != 0x0000;) {\r
+          //\r
+          // If there is more string to process print on the next row and increment the Skip value\r
+          //\r
+          if (StrLen (&StringPtr[ArrayEntry])) {\r
+            FormTags.Tags[Index].NumberOfLines++;\r
+          }\r
+\r
+          FreePool (OutputString);\r
+        }\r
+\r
+        ArrayEntry = 0;\r
+\r
+        //\r
+        // We are NOT!! removing this StringPtr buffer via FreePool since it is being used in the menuoptions, we will do\r
+        // it in UiFreeMenu.\r
+        //\r
+        UiAddSubMenuOption (StringPtr, Handle, FormTags.Tags, Index, FormId, MenuItemCount);\r
+        MenuItemCount++;\r
+      }\r
+      //\r
+      // Keep processing menu entries based on the resultant suppress/grayout results until we hit an end-if\r
+      //\r
+      Index++;\r
+    } while (FormTags.Tags[Index].Operand != EFI_IFR_END_IF_OP && Conditional);\r
+\r
+    //\r
+    // We advanced the index for the above conditional, rewind it to keep harmony with the for loop logic\r
+    //\r
+    Index--;\r
+  }\r
+\r
+  Selection = UiDisplayMenu (TRUE, FileFormTagsHead, (EFI_IFR_DATA_ARRAY *) CallbackData);\r
+\r
+  return Selection;\r
+}\r
+\r
+VOID\r
+InitializeBrowserStrings (\r
+  VOID\r
+  )\r
+{\r
+  gFunctionOneString    = GetToken (STRING_TOKEN (FUNCTION_ONE_STRING), gHiiHandle);\r
+  gFunctionTwoString    = GetToken (STRING_TOKEN (FUNCTION_TWO_STRING), gHiiHandle);\r
+  gFunctionNineString   = GetToken (STRING_TOKEN (FUNCTION_NINE_STRING), gHiiHandle);\r
+  gFunctionTenString    = GetToken (STRING_TOKEN (FUNCTION_TEN_STRING), gHiiHandle);\r
+  gEnterString          = GetToken (STRING_TOKEN (ENTER_STRING), gHiiHandle);\r
+  gEnterCommitString    = GetToken (STRING_TOKEN (ENTER_COMMIT_STRING), gHiiHandle);\r
+  gEscapeString         = GetToken (STRING_TOKEN (ESCAPE_STRING), gHiiHandle);\r
+  gMoveHighlight        = GetToken (STRING_TOKEN (MOVE_HIGHLIGHT), gHiiHandle);\r
+  gMakeSelection        = GetToken (STRING_TOKEN (MAKE_SELECTION), gHiiHandle);\r
+  gNumericInput         = GetToken (STRING_TOKEN (NUMERIC_INPUT), gHiiHandle);\r
+  gToggleCheckBox       = GetToken (STRING_TOKEN (TOGGLE_CHECK_BOX), gHiiHandle);\r
+  gPromptForPassword    = GetToken (STRING_TOKEN (PROMPT_FOR_PASSWORD), gHiiHandle);\r
+  gPromptForNewPassword = GetToken (STRING_TOKEN (PROMPT_FOR_NEW_PASSWORD), gHiiHandle);\r
+  gConfirmPassword      = GetToken (STRING_TOKEN (CONFIRM_PASSWORD), gHiiHandle);\r
+  gConfirmError         = GetToken (STRING_TOKEN (CONFIRM_ERROR), gHiiHandle);\r
+  gPressEnter           = GetToken (STRING_TOKEN (PRESS_ENTER), gHiiHandle);\r
+  gEmptyString          = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);\r
+  gAreYouSure           = GetToken (STRING_TOKEN (ARE_YOU_SURE), gHiiHandle);\r
+  gYesResponse          = GetToken (STRING_TOKEN (ARE_YOU_SURE_YES), gHiiHandle);\r
+  gNoResponse           = GetToken (STRING_TOKEN (ARE_YOU_SURE_NO), gHiiHandle);\r
+  gMiniString           = GetToken (STRING_TOKEN (MINI_STRING), gHiiHandle);\r
+  gPlusString           = GetToken (STRING_TOKEN (PLUS_STRING), gHiiHandle);\r
+  gMinusString          = GetToken (STRING_TOKEN (MINUS_STRING), gHiiHandle);\r
+  gAdjustNumber         = GetToken (STRING_TOKEN (ADJUST_NUMBER), gHiiHandle);\r
+  return ;\r
+}\r
+\r
+VOID\r
+UpdateKeyHelp (\r
+  IN  UI_MENU_OPTION              *Selection,\r
+  IN  BOOLEAN                     Selected\r
+  )\r
+/*++\r
+Routine Description:\r
+  Update key's help imformation\r
+\r
+Arguments:\r
+  Selection C The form that current display\r
+  Selected C  Whether or not a tag be selected\r
+\r
+Returns:\r
+  None\r
+--*/\r
+{\r
+  UINTN             SecCol;\r
+  UINTN             ThdCol;\r
+  UINTN             LeftColumnOfHelp;\r
+  UINTN             RightColumnOfHelp;\r
+  UINTN             TopRowOfHelp;\r
+  UINTN             BottomRowOfHelp;\r
+  UINTN             StartColumnOfHelp;\r
+  EFI_SCREEN_DESCRIPTOR LocalScreen;\r
+\r
+  CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));\r
+\r
+  SecCol            = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3;\r
+  ThdCol            = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) * 2 / 3;\r
+\r
+  StartColumnOfHelp = LocalScreen.LeftColumn + 2;\r
+  LeftColumnOfHelp  = LocalScreen.LeftColumn + 1;\r
+  RightColumnOfHelp = LocalScreen.RightColumn - 2;\r
+  TopRowOfHelp      = LocalScreen.BottomRow - 4;\r
+  BottomRowOfHelp   = LocalScreen.BottomRow - 3;\r
+\r
+  if (gClassOfVfr == EFI_GENERAL_APPLICATION_SUBCLASS) {\r
+    return ;\r
+  }\r
+\r
+  gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_TEXT | KEYHELP_BACKGROUND);\r
+\r
+  switch (Selection->ThisTag->Operand) {\r
+  case EFI_IFR_ORDERED_LIST_OP:\r
+  case EFI_IFR_ONE_OF_OP:\r
+  case EFI_IFR_NUMERIC_OP:\r
+  case EFI_IFR_TIME_OP:\r
+  case EFI_IFR_DATE_OP:\r
+    ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);\r
+\r
+    if (!Selected) {\r
+      if (gClassOfVfr == EFI_SETUP_APPLICATION_SUBCLASS) {\r
+        PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gFunctionOneString);\r
+        PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);\r
+        PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);\r
+        PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);\r
+\r
+      }\r
+\r
+      if ((Selection->ThisTag->Operand == EFI_IFR_DATE_OP) || (Selection->ThisTag->Operand == EFI_IFR_TIME_OP)) {\r
+        PrintAt (\r
+          StartColumnOfHelp,\r
+          BottomRowOfHelp,\r
+          (CHAR16 *) L"%c%c%c%c%s",\r
+          ARROW_UP,\r
+          ARROW_DOWN,\r
+          ARROW_RIGHT,\r
+          ARROW_LEFT,\r
+          gMoveHighlight\r
+          );\r
+        PrintStringAt (SecCol, BottomRowOfHelp, gAdjustNumber);\r
+      } else {\r
+        PrintAt (StartColumnOfHelp, BottomRowOfHelp, (CHAR16 *) L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);\r
+        PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);\r
+      }\r
+    } else {\r
+      PrintStringAt (SecCol, BottomRowOfHelp, gEnterCommitString);\r
+\r
+      //\r
+      // If it is a selected numeric with manual input, display different message\r
+      //\r
+      if ((Selection->ThisTag->Operand == EFI_IFR_NUMERIC_OP) && (Selection->ThisTag->Step == 0)) {\r
+        PrintStringAt (SecCol, TopRowOfHelp, gNumericInput);\r
+      } else if (Selection->ThisTag->Operand != EFI_IFR_ORDERED_LIST_OP) {\r
+        PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);\r
+      }\r
+\r
+      if (Selection->ThisTag->Operand == EFI_IFR_ORDERED_LIST_OP) {\r
+        PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gPlusString);\r
+        PrintStringAt (ThdCol, TopRowOfHelp, gMinusString);\r
+      }\r
+\r
+      PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);\r
+    }\r
+    break;\r
+\r
+  case EFI_IFR_CHECKBOX_OP:\r
+    ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);\r
+\r
+    if (gClassOfVfr == EFI_SETUP_APPLICATION_SUBCLASS) {\r
+      PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gFunctionOneString);\r
+      PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);\r
+      PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);\r
+      PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);\r
+    }\r
+\r
+    PrintAt (StartColumnOfHelp, BottomRowOfHelp, (CHAR16 *) L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);\r
+    PrintStringAt (SecCol, BottomRowOfHelp, gToggleCheckBox);\r
+    break;\r
+\r
+  case EFI_IFR_REF_OP:\r
+  case EFI_IFR_PASSWORD_OP:\r
+  case EFI_IFR_STRING_OP:\r
+    ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);\r
+\r
+    if (!Selected) {\r
+      if (gClassOfVfr == EFI_SETUP_APPLICATION_SUBCLASS) {\r
+        PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gFunctionOneString);\r
+        PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);\r
+        PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);\r
+        PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);\r
+      }\r
+\r
+      PrintAt (StartColumnOfHelp, BottomRowOfHelp, (CHAR16 *) L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);\r
+      PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);\r
+    } else {\r
+      if (Selection->ThisTag->Operand != EFI_IFR_REF_OP) {\r
+        PrintStringAt (\r
+          (LocalScreen.RightColumn - GetStringWidth (gEnterCommitString) / 2) / 2,\r
+          BottomRowOfHelp,\r
+          gEnterCommitString\r
+          );\r
+        PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);\r
+      }\r
+    }\r
+    break;\r
+  }\r
+\r
+}\r
+\r
+STATIC\r
+VOID\r
+ExtractFormHandle (\r
+  IN  UI_MENU_OPTION              *Selection,\r
+  IN  EFI_FILE_FORM_TAGS          *FileFormTagsHead,\r
+  IN  UINTN                       IdValue,\r
+  OUT UINT16                      *FormHandle,\r
+  OUT UINT16                      *TitleToken,\r
+  OUT EFI_FORM_TAGS               *FormTags\r
+  )\r
+{\r
+  UINTN               Index;\r
+  EFI_FILE_FORM_TAGS  *FileFormTags;\r
+  EFI_FORM_TAGS       LocalTags;\r
+\r
+  FileFormTags = FileFormTagsHead;\r
+\r
+  //\r
+  // Advance FileFormTags to the correct file's tag information.\r
+  // For instance, if Selection->IfrNumber is 3, that means the 4th\r
+  // file (0-based) in the FileFormTags linked-list contains the tag\r
+  // information.\r
+  //\r
+  for (Index = 0; Index < Selection->IfrNumber; Index++) {\r
+    FileFormTags = FileFormTags->NextFile;\r
+  }\r
+\r
+  LocalTags = FileFormTags->FormTags;\r
+\r
+  if (IdValue == 0) {\r
+    //\r
+    // Advance Index to the first FormOp tag information\r
+    //\r
+    for (Index = 0; FileFormTags->FormTags.Tags[Index].Operand != EFI_IFR_FORM_OP; Index++)\r
+      ;\r
+  } else {\r
+    //\r
+    // Advance Index to the FormOp with the correct ID value\r
+    //\r
+    for (; LocalTags.Next != NULL; LocalTags = *LocalTags.Next) {\r
+      for (Index = 0; LocalTags.Tags[Index].Operand != EFI_IFR_FORM_OP; Index++)\r
+        ;\r
+      if (LocalTags.Tags[Index].Id == IdValue) {\r
+        break;\r
+      }\r
+    }\r
+  }\r
+  //\r
+  // return the Form Id, Text, and the File's FormTags structure\r
+  //\r
+  *FormHandle = LocalTags.Tags[Index].Id;\r
+  *TitleToken = LocalTags.Tags[Index].Text;\r
+  *FormTags   = LocalTags;\r
+  return ;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+UpdateNewTagData (\r
+  IN  UINT8                                     *FormData,\r
+  IN  UINT16                                    ConsistencyId,\r
+  IN  UINT16                                    CurrentVariable,\r
+  IN  EFI_FORM_TAGS                             *FormTags,\r
+  OUT EFI_FILE_FORM_TAGS                        *FileFormTags\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT16      Index;\r
+  UINT16      QuestionIndex;\r
+  UINT16      NumberOfTags;\r
+  INT16       CurrTag;\r
+  UINT8       TagLength;\r
+  UINTN       Count;\r
+  BOOLEAN     Finished;\r
+\r
+  //\r
+  // Initialize some Index variable and Status\r
+  //\r
+  Count         = 0;\r
+  QuestionIndex = 0;\r
+  NumberOfTags  = 1;\r
+  Index         = 0;\r
+  Status        = EFI_SUCCESS;\r
+  Finished      = FALSE;\r
+\r
+  //\r
+  // Determine the number of tags for the first form\r
+  //\r
+  GetTagCount (&FormData[Index], &NumberOfTags);\r
+\r
+  //\r
+  // Allocate memory for our tags on the first form\r
+  //\r
+  FormTags->Tags = AllocateZeroPool (NumberOfTags * sizeof (EFI_TAG));\r
+  ASSERT (FormTags->Tags != NULL);\r
+\r
+  for (CurrTag = 0; FormData[Index] != EFI_IFR_END_FORM_SET_OP; CurrTag++) {\r
+    //\r
+    // Operand = IFR OpCode\r
+    //\r
+    FormTags->Tags[CurrTag].Operand = FormData[Index];\r
+\r
+    //\r
+    // Assume for now 0 lines occupied by this OpCode\r
+    //\r
+    FormTags->Tags[CurrTag].NumberOfLines = 0;\r
+\r
+    //\r
+    // Determine the length of the Tag so we can later skip to the next tag in the form\r
+    //\r
+    //\r
+    // get the length\r
+    //\r
+    TagLength = FormData[Index + 1];\r
+    //\r
+    // Operate on the Found OpCode\r
+    //\r
+    switch (FormData[Index]) {\r
+\r
+    case EFI_IFR_FORM_OP:\r
+    case EFI_IFR_SUBTITLE_OP:\r
+    case EFI_IFR_TEXT_OP:\r
+    case EFI_IFR_REF_OP:\r
+      IfrToFormTag (FormData[Index], &FormTags->Tags[CurrTag], (VOID *) &FormData[Index], NULL);\r
+      break;\r
+\r
+    case EFI_IFR_VARSTORE_SELECT_OP:\r
+      IfrToFormTag (FormData[Index], &FormTags->Tags[CurrTag], (VOID *) &FormData[Index], NULL);\r
+      CopyMem (&CurrentVariable, &((EFI_IFR_VARSTORE_SELECT *) &FormData[Index])->VarId, sizeof (UINT16));\r
+      break;\r
+\r
+    case EFI_IFR_END_FORM_OP:\r
+      FormTags->Tags[CurrTag].Operand       = FormData[Index];\r
+      FormTags->Tags[CurrTag].NumberOfLines = 0;\r
+\r
+      Finished = TRUE;\r
+      break;\r
+\r
+    case EFI_IFR_ORDERED_LIST_OP:\r
+    case EFI_IFR_ONE_OF_OP:\r
+      GetQuestionHeader (&FormTags->Tags[CurrTag], FormData, Index, FileFormTags, CurrentVariable);\r
+\r
+      //\r
+      // Store away the CurrTag since what follows will be the answer that we\r
+      // need to place into the appropriate location in the tag array\r
+      //\r
+      //\r
+      // record for setting default later\r
+      //\r
+      QuestionIndex = (UINT16) CurrTag;\r
+      break;\r
+\r
+    case EFI_IFR_ONE_OF_OPTION_OP:\r
+      IfrToFormTag (FormData[Index], &FormTags->Tags[CurrTag], (VOID *) &FormData[Index], NULL);\r
+      FormTags->Tags[QuestionIndex].Key = ((EFI_IFR_ONE_OF_OPTION *) &FormData[Index])->Key;\r
+      FormTags->Tags[QuestionIndex].ResetRequired = (BOOLEAN) (FormTags->Tags[QuestionIndex].Flags & EFI_IFR_FLAG_RESET_REQUIRED);\r
+      break;\r
+\r
+    case EFI_IFR_CHECKBOX_OP:\r
+      GetQuestionHeader (&FormTags->Tags[CurrTag], FormData, Index, FileFormTags, CurrentVariable);\r
+      IfrToFormTag (FormData[Index], &FormTags->Tags[CurrTag], (VOID *) &FormData[Index], NULL);\r
+      break;\r
+\r
+    case EFI_IFR_NUMERIC_OP:\r
+      GetNumericHeader (&FormTags->Tags[CurrTag], FormData, Index, (UINT16) 1, FileFormTags, CurrentVariable);\r
+      IfrToFormTag (FormData[Index], &FormTags->Tags[CurrTag], (VOID *) &FormData[Index], NULL);\r
+      break;\r
+\r
+    case EFI_IFR_DATE_OP:\r
+      //\r
+      // Date elements come in as a Year, Month, Day.  We need to process them as a country-based\r
+      // Order.  It is much easier to do it here than anywhere else.\r
+      //\r
+      // For US standards - we want Month/Day/Year, thus we advance "i" +1, +2, +0 while CurrTag is +0, +1, +2\r
+      //\r
+      GetNumericHeader (\r
+        &FormTags->Tags[CurrTag],\r
+        FormData,\r
+        (UINT16) (Index + TagLength),\r
+        (UINT16) 0,\r
+        FileFormTags,\r
+        CurrentVariable\r
+        );\r
+\r
+      //\r
+      // The current language selected + the Date operand\r
+      //\r
+      FormTags->Tags[CurrTag + 1].Operand = FormData[Index];\r
+      GetNumericHeader (\r
+        &FormTags->Tags[CurrTag + 1],\r
+        FormData,\r
+        (UINT16) (Index + TagLength + FormData[Index + TagLength + 1]),\r
+        (UINT16) 0,\r
+        FileFormTags,\r
+        CurrentVariable\r
+        );\r
+\r
+      //\r
+      // The current language selected + the Date operand\r
+      //\r
+      FormTags->Tags[CurrTag + 2].Operand = FormData[Index];\r
+      GetNumericHeader (&FormTags->Tags[CurrTag + 2], FormData, Index, (UINT16) 1, FileFormTags, CurrentVariable);\r
+\r
+      CurrTag   = (INT16) (CurrTag + 2);\r
+\r
+      Index     = (UINT16) (Index + TagLength);\r
+      //\r
+      // get the length\r
+      //\r
+      TagLength = FormData[Index + 1];\r
+      Index     = (UINT16) (Index + TagLength);\r
+      //\r
+      // get the length\r
+      //\r
+      TagLength = FormData[Index + 1];\r
+      break;\r
+\r
+    case EFI_IFR_TIME_OP:\r
+      GetNumericHeader (&FormTags->Tags[CurrTag], FormData, Index, (UINT16) 0, FileFormTags, CurrentVariable);\r
+\r
+      if (Count == 2) {\r
+        //\r
+        // Override the GetQuestionHeader information - date/time are treated very differently\r
+        //\r
+        FormTags->Tags[CurrTag].NumberOfLines = 1;\r
+        Count = 0;\r
+      } else {\r
+        //\r
+        // The premise is that every date/time op-code have 3 elements, the first 2 have 0 lines\r
+        // associated with them, and the third has 1 line to allow to space beyond the choice.\r
+        //\r
+        Count++;\r
+      }\r
+      break;\r
+\r
+    case EFI_IFR_PASSWORD_OP:\r
+    case EFI_IFR_STRING_OP:\r
+      GetQuestionHeader (&FormTags->Tags[CurrTag], FormData, Index, FileFormTags, CurrentVariable);\r
+      IfrToFormTag (FormData[Index], &FormTags->Tags[CurrTag], (VOID *) &FormData[Index], NULL);\r
+      break;\r
+\r
+    case EFI_IFR_INCONSISTENT_IF_OP:\r
+    case EFI_IFR_SUPPRESS_IF_OP:\r
+    case EFI_IFR_GRAYOUT_IF_OP:\r
+      ConsistencyId++;\r
+      break;\r
+\r
+    case EFI_IFR_EQ_ID_VAL_OP:\r
+      IfrToFormTag (FormData[Index], &FormTags->Tags[CurrTag], (VOID *) &FormData[Index], NULL);\r
+      FormTags->Tags[CurrTag].ConsistencyId = ConsistencyId;\r
+      break;\r
+\r
+    case EFI_IFR_EQ_VAR_VAL_OP:\r
+      IfrToFormTag (FormData[Index], &FormTags->Tags[CurrTag], (VOID *) &FormData[Index], NULL);\r
+      FormTags->Tags[CurrTag].ConsistencyId = ConsistencyId;\r
+      break;\r
+\r
+    case EFI_IFR_EQ_ID_ID_OP:\r
+      IfrToFormTag (FormData[Index], &FormTags->Tags[CurrTag], (VOID *) &FormData[Index], NULL);\r
+      FormTags->Tags[CurrTag].ConsistencyId = ConsistencyId;\r
+      break;\r
+\r
+    case EFI_IFR_AND_OP:\r
+    case EFI_IFR_OR_OP:\r
+    case EFI_IFR_NOT_OP:\r
+    case EFI_IFR_TRUE_OP:\r
+    case EFI_IFR_FALSE_OP:\r
+    case EFI_IFR_GT_OP:\r
+    case EFI_IFR_GE_OP:\r
+      FormTags->Tags[CurrTag].ConsistencyId = ConsistencyId;\r
+      break;\r
+\r
+    case EFI_IFR_EQ_ID_LIST_OP:\r
+      IfrToFormTag (FormData[Index], &FormTags->Tags[CurrTag], (VOID *) &FormData[Index], NULL);\r
+\r
+      FormTags->Tags[CurrTag].ConsistencyId = ConsistencyId;\r
+      break;\r
+\r
+    default:\r
+      break;\r
+    }\r
+    //\r
+    // End of switch\r
+    //\r
+    if (Finished) {\r
+      break;\r
+    }\r
+    //\r
+    // Per spec., we ignore ops that we don't know how to deal with.  Skip to next tag\r
+    //\r
+    Index = (UINT16) (Index + TagLength);\r
+  }\r
+  //\r
+  // End of Index\r
+  //\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+VOID\r
+ExtractDynamicFormHandle (\r
+  IN  UI_MENU_OPTION              *Selection,\r
+  IN  UINT8                       *CallbackData,\r
+  IN  EFI_FILE_FORM_TAGS          *FileFormTagsHead,\r
+  IN  UINTN                       IdValue,\r
+  OUT UINT16                      *FormHandle,\r
+  OUT UINT16                      *TitleToken,\r
+  OUT EFI_FORM_TAGS               *FormTags\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The function does the most of the works when the EFI_TAG that\r
+  user selects on is EFI_IFR_FLAG_INTERACTIVE or EFI_IFR_PASSWORD_OP:\r
+  invoke CallBack, update the new form data.\r
+\r
+Arguments:\r
+\r
+  Selection         - The current selection of the form.\r
+  CallbackData      - The pointer to host the data passed back by the callback function.\r
+  FileFormTagsHead  - Prompt string token of the one-of box\r
+  IdValue           - The current page number.\r
+  FormHandle        - Output the  the handle of the form.\r
+  TitleToken        - Output the  TitleToken of the new page.\r
+  FormTags          - Output the  FormFags of the new page.\r
+\r
+Returns:\r
+  VOID\r
+\r
+--*/\r
+{\r
+  UINTN                       Index;\r
+  UINTN                       BackupIndex;\r
+  EFI_FILE_FORM_TAGS          *FileFormTags;\r
+  EFI_FORM_TAGS               *LocalTags;\r
+  EFI_FORM_CALLBACK_PROTOCOL  *FormCallback;\r
+  EFI_STATUS                  Status;\r
+  UINTN                       Length;\r
+  UINT8                       *Buffer;\r
+  EFI_PHYSICAL_ADDRESS        CallbackHandle;\r
+  EFI_GUID                    TagGuid;\r
+  UINT16                      TargetPage;\r
+  EFI_HII_CALLBACK_PACKET     *Packet;\r
+  UINTN                       ScreenSize;\r
+  CHAR16                      NullCharacter;\r
+  EFI_INPUT_KEY               Key;\r
+  UINT16                      ConsistencyId;\r
+  UINT16                      CurrentVariable;\r
+  EFI_VARIABLE_DEFINITION     *VariableDefinition;\r
+  EFI_IFR_DATA_ENTRY          *DataEntry;\r
+\r
+  VariableDefinition  = NULL;\r
+  NullCharacter       = CHAR_NULL;\r
+\r
+  CurrentVariable     = 0;\r
+  FileFormTags        = FileFormTagsHead;\r
+  Length              = 0;\r
+  CallbackHandle      = 0;\r
+  TargetPage          = (UINT16) IdValue;\r
+  Packet              = NULL;\r
+  ConsistencyId       = 0;\r
+\r
+  //\r
+  // Advance FileFormTags to the correct file's tag information.\r
+  // For instance, if Selection->IfrNumber is 3, that means the 4th\r
+  // file (0-based) in the FileFormTags linked-list contains the tag\r
+  // information.\r
+  //\r
+  for (Index = 0; Index < Selection->IfrNumber; Index++) {\r
+    FileFormTags = FileFormTags->NextFile;\r
+  }\r
+\r
+  LocalTags = &FileFormTags->FormTags;\r
+\r
+  //\r
+  // Advance Index to the FormOp with the correct ID value\r
+  //\r
+  for (; LocalTags->Next != NULL; LocalTags = LocalTags->Next) {\r
+    if ((LocalTags->Tags[0].CallbackHandle != 0) && (CallbackHandle == 0)) {\r
+      CallbackHandle = LocalTags->Tags[0].CallbackHandle;\r
+      CopyMem (&TagGuid, &LocalTags->Tags[0].GuidValue, sizeof (EFI_GUID));\r
+    }\r
+\r
+    for (Index = 0; LocalTags->Tags[Index].Operand != EFI_IFR_FORM_OP; Index++)\r
+      ;\r
+    if (LocalTags->Tags[Index].Id == IdValue) {\r
+      break;\r
+    }\r
+  }\r
+  //\r
+  // If we are going to callback on a non-goto opcode, make sure we don't change pages\r
+  //\r
+  if (Selection->ThisTag->Operand != EFI_IFR_REF_OP) {\r
+    TargetPage = Selection->FormId;\r
+  }\r
+  //\r
+  // The first tag below should be the form op-code.  We need to store away the\r
+  // current variable setting to ensure if we have to reload the page, that we\r
+  // can correctly restore the values for the active variable\r
+  //\r
+  CurrentVariable = Selection->Tags[0].VariableNumber;\r
+\r
+  //\r
+  // Remember that dynamic pages in an environment where all pages are not\r
+  // dynamic require us to call back to the user to give them an opportunity\r
+  // to register fresh information in the HII database so that we can extract it.\r
+  //\r
+  Status = gBS->HandleProtocol (\r
+                  (VOID *) (UINTN) CallbackHandle,\r
+                  &gEfiFormCallbackProtocolGuid,\r
+                  (VOID **) &FormCallback\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (LocalTags->Tags);\r
+    return ;\r
+  }\r
+\r
+  ExtractRequestedNvMap (FileFormTags, CurrentVariable, &VariableDefinition);\r
+\r
+  if (Selection->ThisTag->Flags & (EFI_IFR_FLAG_INTERACTIVE | EFI_IFR_FLAG_NV_ACCESS)) {\r
+    ((EFI_IFR_DATA_ARRAY *) CallbackData)->NvRamMap = VariableDefinition->NvRamMap;\r
+  } else {\r
+    ((EFI_IFR_DATA_ARRAY *) CallbackData)->NvRamMap = NULL;\r
+  }\r
+\r
+  if ((FormCallback != NULL) && (FormCallback->Callback != NULL)) {\r
+    Status = FormCallback->Callback (\r
+                            FormCallback,\r
+                            Selection->ThisTag->Key,\r
+                            (EFI_IFR_DATA_ARRAY *) CallbackData,\r
+                            &Packet\r
+                            );\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Restore Previous Value\r
+    //\r
+    CopyMem (\r
+      &VariableDefinition->NvRamMap[Selection->ThisTag->StorageStart],\r
+      gPreviousValue,\r
+      Selection->ThisTag->StorageWidth\r
+      );\r
+\r
+    if (Packet != NULL) {\r
+      //\r
+      // Upon error, we will likely receive a string to print out\r
+      //\r
+      ScreenSize = GetStringWidth (Packet->String) / 2;\r
+\r
+      //\r
+      // Display error popup\r
+      //\r
+      CreatePopUp (ScreenSize, 3, &NullCharacter, Packet->String, &NullCharacter);\r
+\r
+      do {\r
+        Status = WaitForKeyStroke (&Key);\r
+      } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
+    } else {\r
+      UpdateStatusBar (INPUT_ERROR, (UINT8) 0, TRUE);\r
+    }\r
+\r
+  } else {\r
+    if (Packet != NULL) {\r
+      //\r
+      // We need to on a non-error, look in the outbound Packet for information and update the NVRAM\r
+      // location associated with the op-code specified there.  This is used on single op-code instances\r
+      // and not for when a hyperlink sent us a whole page of data.\r
+      //\r
+      DataEntry = (EFI_IFR_DATA_ENTRY *) (&Packet->DataArray + 1);\r
+      if (Packet->DataArray.EntryCount == 1) {\r
+        switch (DataEntry->OpCode) {\r
+        case EFI_IFR_STRING_OP:\r
+        case EFI_IFR_NUMERIC_OP:\r
+        case EFI_IFR_ORDERED_LIST_OP:\r
+        case EFI_IFR_ONE_OF_OP:\r
+        case EFI_IFR_CHECKBOX_OP:\r
+          CopyMem (\r
+            &VariableDefinition->NvRamMap[Selection->ThisTag->StorageStart],\r
+            &DataEntry->Data,\r
+            Selection->ThisTag->StorageWidth\r
+            );\r
+          break;\r
+\r
+        case EFI_IFR_NV_ACCESS_COMMAND:\r
+          CopyMem (\r
+            &VariableDefinition->NvRamMap[((EFI_IFR_NV_DATA *) Packet)->QuestionId],\r
+            ((EFI_IFR_NV_DATA *) Packet) + 1,\r
+            ((EFI_IFR_NV_DATA *) Packet)->StorageWidth\r
+            );\r
+          break;\r
+\r
+        }\r
+\r
+        if (DataEntry->Flags & RESET_REQUIRED) {\r
+          gResetRequired = TRUE;\r
+        }\r
+\r
+        if (DataEntry->Flags & EXIT_REQUIRED) {\r
+          gExitRequired = TRUE;\r
+        }\r
+\r
+        if (DataEntry->Flags & SAVE_REQUIRED) {\r
+          gSaveRequired = TRUE;\r
+        }\r
+\r
+        if (DataEntry->Flags & NV_CHANGED) {\r
+          gNvUpdateRequired = TRUE;\r
+        }\r
+\r
+        if (DataEntry->Flags & NV_NOT_CHANGED) {\r
+          gNvUpdateRequired = FALSE;\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  if (Packet != NULL) {\r
+    FreePool (Packet);\r
+  }\r
+\r
+  for (BackupIndex = 0; LocalTags->Tags[BackupIndex].Operand != EFI_IFR_END_FORM_OP; BackupIndex++) {\r
+    switch (LocalTags->Tags[BackupIndex].Operand) {\r
+    case EFI_IFR_EQ_VAR_VAL_OP:\r
+    case EFI_IFR_EQ_ID_VAL_OP:\r
+    case EFI_IFR_EQ_ID_ID_OP:\r
+    case EFI_IFR_AND_OP:\r
+    case EFI_IFR_OR_OP:\r
+    case EFI_IFR_NOT_OP:\r
+    case EFI_IFR_TRUE_OP:\r
+    case EFI_IFR_FALSE_OP:\r
+    case EFI_IFR_GT_OP:\r
+    case EFI_IFR_GE_OP:\r
+    case EFI_IFR_EQ_ID_LIST_OP:\r
+      //\r
+      // If we encountered a ConsistencyId value, on this page they will be incremental\r
+      // So register the first value we encounter.  We will pass this in when we re-create this page\r
+      //\r
+      if ((LocalTags->Tags[BackupIndex].ConsistencyId != 0) && (ConsistencyId == 0)) {\r
+        ConsistencyId = (UINT16) (LocalTags->Tags[BackupIndex].ConsistencyId - 1);\r
+      }\r
+      break;\r
+    }\r
+  }\r
+  //\r
+  // Delete the buffer associated with previous dynamic page\r
+  // We will re-allocate a buffer....\r
+  //\r
+  FreePool (LocalTags->Tags);\r
+\r
+  Length  = 0xF000;\r
+  Buffer  = AllocateZeroPool (Length);\r
+  ASSERT (Buffer != NULL);\r
+\r
+  //\r
+  // Get the form that was updated by the callback\r
+  //\r
+  Hii->GetForms (\r
+        Hii,\r
+        Selection->Handle,\r
+        TargetPage,\r
+        &Length,\r
+        Buffer\r
+        );\r
+\r
+  //\r
+  // Ok, we have the new page.....now we must purge the old page and re-allocate\r
+  // the tag page with the new data\r
+  //\r
+  UpdateNewTagData (\r
+    Buffer,\r
+    ConsistencyId,\r
+    CurrentVariable,\r
+    LocalTags,\r
+    FileFormTags\r
+    );\r
+\r
+  //\r
+  // return the Form Id, Text, and the File's FormTags structure\r
+  //\r
+  *FormHandle                       = LocalTags->Tags[0].Id;\r
+  *TitleToken                       = LocalTags->Tags[0].Text;\r
+  *FormTags                         = *LocalTags;\r
+\r
+  FormTags->Tags[0].CallbackHandle  = CallbackHandle;\r
+  CopyMem (&FormTags->Tags[0].GuidValue, &TagGuid, sizeof (EFI_GUID));\r
+\r
+  return ;\r
+}\r
+\r
+UI_MENU_OPTION *\r
+SetupBrowser (\r
+  IN  UI_MENU_OPTION              *Selection,\r
+  IN  BOOLEAN                     Callback,\r
+  IN  EFI_FILE_FORM_TAGS          *FileFormTagsHead,\r
+  IN  UINT8                       *CallbackData\r
+  )\r
+{\r
+  UINT16        FormHandle;\r
+  UINT16        TitleToken;\r
+  EFI_FORM_TAGS FormTags;\r
+\r
+  gEntryNumber  = -1;\r
+  gLastOpr      = FALSE;\r
+  //\r
+  // Displays the Header and Footer borders\r
+  //\r
+  DisplayPageFrame ();\r
+\r
+  //\r
+  // Id of 0 yields the getting of the top form whatever the ID is.  Usually the first form in the IFR\r
+  //\r
+  ExtractFormHandle (Selection, FileFormTagsHead, 0, &FormHandle, &TitleToken, &FormTags);\r
+\r
+  Selection = DisplayForm (Selection, FormHandle, TitleToken, FormTags, FileFormTagsHead, CallbackData);\r
+\r
+  //\r
+  // If selection is null use the former selection\r
+  //\r
+  if (Selection == NULL) {\r
+    return Selection;\r
+  }\r
+\r
+  if (Callback) {\r
+    return Selection;\r
+  }\r
+\r
+  while (Selection->Tags != NULL) {\r
+    if (Selection->Previous) {\r
+      ExtractFormHandle (Selection, FileFormTagsHead, Selection->FormId, &FormHandle, &TitleToken, &FormTags);\r
+    } else {\r
+      //\r
+      // True if a hyperlink/jump is selected\r
+      //\r
+      if (Selection->ThisTag->Operand == EFI_IFR_REF_OP && Selection->ThisTag->Id != 0x0000) {\r
+        if (Selection->ThisTag->Flags & EFI_IFR_FLAG_INTERACTIVE) {\r
+          ExtractDynamicFormHandle (\r
+            Selection,\r
+            CallbackData,\r
+            FileFormTagsHead,\r
+            Selection->ThisTag->Id,\r
+            &FormHandle,\r
+            &TitleToken,\r
+            &FormTags\r
+            );\r
+          goto DisplayPage;\r
+        } else {\r
+          ExtractFormHandle (Selection, FileFormTagsHead, Selection->ThisTag->Id, &FormHandle, &TitleToken, &FormTags);\r
+          goto DisplayPage;\r
+        }\r
+      }\r
+\r
+      if ((Selection->ThisTag->Flags & EFI_IFR_FLAG_INTERACTIVE) &&\r
+          (Selection->ThisTag->Operand != EFI_IFR_PASSWORD_OP)\r
+          ) {\r
+        ExtractDynamicFormHandle (\r
+          Selection,\r
+          CallbackData,\r
+          FileFormTagsHead,\r
+          Selection->FormId,\r
+          &FormHandle,\r
+          &TitleToken,\r
+          &FormTags\r
+          );\r
+      } else {\r
+        ExtractFormHandle (Selection, FileFormTagsHead, Selection->FormId, &FormHandle, &TitleToken, &FormTags);\r
+      }\r
+    }\r
+\r
+DisplayPage:\r
+    //\r
+    // Displays the Header and Footer borders\r
+    //\r
+    DisplayPageFrame ();\r
+\r
+    Selection = DisplayForm (Selection, FormHandle, TitleToken, FormTags, FileFormTagsHead, CallbackData);\r
+\r
+    if (Selection == NULL) {\r
+      break;\r
+    }\r
+  };\r
+\r
+  return Selection;\r
+}\r
diff --git a/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Print.c b/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Print.c
new file mode 100644 (file)
index 0000000..a0143dd
--- /dev/null
@@ -0,0 +1,298 @@
+/*++\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
+  Print.c\r
+\r
+Abstract:\r
+\r
+  Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very\r
+  simple implemenation of SPrint() and Print() to support debug.\r
+\r
+  You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a\r
+  time. This makes the implementation very simple.\r
+\r
+  VSPrint, Print, SPrint format specification has the follwoing form\r
+\r
+  %type\r
+\r
+  type:\r
+    'S','s' - argument is an Unicode string\r
+    'c' - argument is an ascii character\r
+    '%' - Print a %\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "Print.h"\r
+\r
+STATIC\r
+UINTN\r
+_IPrint (\r
+  IN UINTN                            Column,\r
+  IN UINTN                            Row,\r
+  IN EFI_SIMPLE_TEXT_OUT_PROTOCOL     *Out,\r
+  IN CHAR16                           *fmt,\r
+  IN VA_LIST                          args\r
+  )\r
+//\r
+// Display string worker for: Print, PrintAt, IPrint, IPrintAt\r
+//\r
+{\r
+  CHAR16  *Buffer;\r
+  CHAR16  *BackupBuffer;\r
+  UINTN   Index;\r
+  UINTN   PreviousIndex;\r
+\r
+  //\r
+  // For now, allocate an arbitrarily long buffer\r
+  //\r
+  Buffer        = AllocateZeroPool (0x10000);\r
+  BackupBuffer  = AllocateZeroPool (0x10000);\r
+  ASSERT (Buffer);\r
+  ASSERT (BackupBuffer);\r
+\r
+  if (Column != (UINTN) -1) {\r
+    Out->SetCursorPosition (Out, Column, Row);\r
+  }\r
+\r
+  UnicodeVSPrint (Buffer, 0x10000, fmt, args);\r
+\r
+  Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;\r
+\r
+  Out->SetAttribute (Out, Out->Mode->Attribute);\r
+\r
+  Index         = 0;\r
+  PreviousIndex = 0;\r
+\r
+  do {\r
+    for (; (Buffer[Index] != NARROW_CHAR) && (Buffer[Index] != WIDE_CHAR) && (Buffer[Index] != 0); Index++) {\r
+      BackupBuffer[Index] = Buffer[Index];\r
+    }\r
+\r
+    if (Buffer[Index] == 0) {\r
+      break;\r
+    }\r
+    //\r
+    // Null-terminate the temporary string\r
+    //\r
+    BackupBuffer[Index] = 0;\r
+\r
+    //\r
+    // Print this out, we are about to switch widths\r
+    //\r
+    Out->OutputString (Out, &BackupBuffer[PreviousIndex]);\r
+\r
+    //\r
+    // Preserve the current index + 1, since this is where we will start printing from next\r
+    //\r
+    PreviousIndex = Index + 1;\r
+\r
+    //\r
+    // We are at a narrow or wide character directive.  Set attributes and strip it and print it\r
+    //\r
+    if (Buffer[Index] == NARROW_CHAR) {\r
+      //\r
+      // Preserve bits 0 - 6 and zero out the rest\r
+      //\r
+      Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;\r
+      Out->SetAttribute (Out, Out->Mode->Attribute);\r
+    } else {\r
+      //\r
+      // Must be wide, set bit 7 ON\r
+      //\r
+      Out->Mode->Attribute = Out->Mode->Attribute | EFI_WIDE_ATTRIBUTE;\r
+      Out->SetAttribute (Out, Out->Mode->Attribute);\r
+    }\r
+\r
+    Index++;\r
+\r
+  } while (Buffer[Index] != 0);\r
+\r
+  //\r
+  // We hit the end of the string - print it\r
+  //\r
+  Out->OutputString (Out, &BackupBuffer[PreviousIndex]);\r
+\r
+  FreePool (Buffer);\r
+  FreePool (BackupBuffer);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+UINTN\r
+Print (\r
+  IN CHAR16   *fmt,\r
+  ...\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+    Prints a formatted unicode string to the default console\r
+\r
+Arguments:\r
+\r
+    fmt         - Format string\r
+\r
+Returns:\r
+\r
+    Length of string printed to the console\r
+\r
+--*/\r
+{\r
+  VA_LIST args;\r
+\r
+  VA_START (args, fmt);\r
+  return _IPrint ((UINTN) -1, (UINTN) -1, gST->ConOut, fmt, args);\r
+}\r
+\r
+UINTN\r
+PrintString (\r
+  CHAR16       *String\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Prints a unicode string to the default console,\r
+  using L"%s" format.\r
+\r
+Arguments:\r
+\r
+  String      - String pointer.\r
+\r
+Returns:\r
+\r
+  Length of string printed to the console\r
+\r
+--*/\r
+{\r
+  return Print ((CHAR16 *) L"%s", String);\r
+}\r
+\r
+UINTN\r
+PrintChar (\r
+  CHAR16       Character\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Prints a chracter to the default console,\r
+  using L"%c" format.\r
+\r
+Arguments:\r
+\r
+  Character   - Character to print.\r
+\r
+Returns:\r
+\r
+  Length of string printed to the console.\r
+\r
+--*/\r
+{\r
+  return Print ((CHAR16 *) L"%c", Character);\r
+}\r
+\r
+UINTN\r
+PrintAt (\r
+  IN UINTN     Column,\r
+  IN UINTN     Row,\r
+  IN CHAR16    *fmt,\r
+  ...\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Prints a formatted unicode string to the default console, at\r
+  the supplied cursor position\r
+\r
+Arguments:\r
+\r
+  Column, Row - The cursor position to print the string at\r
+\r
+  fmt         - Format string\r
+\r
+Returns:\r
+\r
+  Length of string printed to the console\r
+\r
+--*/\r
+{\r
+  VA_LIST args;\r
+\r
+  VA_START (args, fmt);\r
+  return _IPrint (Column, Row, gST->ConOut, fmt, args);\r
+}\r
+\r
+UINTN\r
+PrintStringAt (\r
+  IN UINTN     Column,\r
+  IN UINTN     Row,\r
+  CHAR16       *String\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Prints a unicode string to the default console, at\r
+  the supplied cursor position, using L"%s" format.\r
+\r
+Arguments:\r
+\r
+  Column, Row - The cursor position to print the string at\r
+\r
+  String      - String pointer.\r
+\r
+Returns:\r
+\r
+  Length of string printed to the console\r
+\r
+--*/\r
+{\r
+  return PrintAt (Column, Row, (CHAR16 *) L"%s", String);\r
+}\r
+\r
+UINTN\r
+PrintCharAt (\r
+  IN UINTN     Column,\r
+  IN UINTN     Row,\r
+  CHAR16       Character\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Prints a chracter to the default console, at\r
+  the supplied cursor position, using L"%c" format.\r
+\r
+Arguments:\r
+\r
+  Column, Row - The cursor position to print the string at\r
+\r
+  Character   - Character to print.\r
+\r
+Returns:\r
+\r
+  Length of string printed to the console.\r
+\r
+--*/\r
+{\r
+  return PrintAt (Column, Row, (CHAR16 *) L"%c", Character);\r
+}\r
+\r
+\r
diff --git a/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Print.h b/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Print.h
new file mode 100644 (file)
index 0000000..8ce993b
--- /dev/null
@@ -0,0 +1,44 @@
+/*++\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
+  Print.h\r
+\r
+Abstract:\r
+\r
+  Private data for Print.c\r
+\r
+--*/\r
+\r
+#ifndef _PRINT_H_\r
+#define _PRINT_H_\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "Setup.h"\r
+\r
+#define LEFT_JUSTIFY  0x01\r
+#define PREFIX_SIGN   0x02\r
+#define PREFIX_BLANK  0x04\r
+#define COMMA_TYPE    0x08\r
+#define LONG_TYPE     0x10\r
+#define PREFIX_ZERO   0x20\r
+\r
+//\r
+// Largest number of characters that can be printed out.\r
+//\r
+#define EFI_DRIVER_LIB_MAX_PRINT_BUFFER (80 * 4)\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/ProcessOptions.c b/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/ProcessOptions.c
new file mode 100644 (file)
index 0000000..fd6addf
--- /dev/null
@@ -0,0 +1,1692 @@
+/**@file\r
+       Implementation for handling the User Interface option processing.\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 "Setup.h"\r
+#include "Ui.h"\r
+\r
+EFI_STATUS\r
+ExtractRequestedNvMap (\r
+  IN  EFI_FILE_FORM_TAGS          *FileFormTags,\r
+  IN  UINT16                      VariableId,\r
+  OUT EFI_VARIABLE_DEFINITION     **VariableDefinition\r
+  )\r
+{\r
+  *VariableDefinition = FileFormTags->VariableDefinitions;\r
+\r
+  //\r
+  // Extract the data from the NV variable - consumer will free the buffer.\r
+  //\r
+  for (; *VariableDefinition != NULL; *VariableDefinition = (*VariableDefinition)->Next) {\r
+    //\r
+    // If there is a variable with this ID return with EFI_SUCCESS\r
+    //\r
+    if (!CompareMem (&(*VariableDefinition)->VariableId, &VariableId, sizeof (UINT16))) {\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+EFI_STATUS\r
+ExtractNvValue (\r
+  IN  EFI_FILE_FORM_TAGS          *FileFormTags,\r
+  IN  UINT16                      VariableId,\r
+  IN  UINT16                      VariableSize,\r
+  IN  UINT16                      OffsetValue,\r
+  OUT VOID                        **Buffer\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_VARIABLE_DEFINITION *VariableDefinition;\r
+\r
+  Status = ExtractRequestedNvMap (FileFormTags, VariableId, &VariableDefinition);\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Allocate sufficient space for the data and copy it into the outgoing buffer\r
+    //\r
+    if (VariableSize != 0) {\r
+      *Buffer = AllocateZeroPool (VariableSize);\r
+      ASSERT (*Buffer != NULL);\r
+      CopyMem (*Buffer, &VariableDefinition->NvRamMap[OffsetValue], VariableSize);\r
+    }\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+VOID\r
+AdjustNvMap (\r
+  IN  EFI_FILE_FORM_TAGS          *FileFormTags,\r
+  IN  UI_MENU_OPTION              *MenuOption\r
+  )\r
+{\r
+  CHAR8                   *NvRamMap;\r
+  UINTN                   SizeRequired;\r
+  UINTN                   Index;\r
+  UINTN                   CachedStart;\r
+  EFI_VARIABLE_DEFINITION *VariableDefinition;\r
+\r
+  CachedStart   = 0;\r
+\r
+  SizeRequired  = MenuOption->ThisTag->StorageStart + MenuOption->ThisTag->StorageWidth;\r
+\r
+  ExtractRequestedNvMap (FileFormTags, MenuOption->Tags->VariableNumber, &VariableDefinition);\r
+\r
+  //\r
+  // We arrived here because the current NvRamMap is too small for the new op-code to store things and\r
+  // we need to adjust the buffer to support this.\r
+  //\r
+  NvRamMap = AllocateZeroPool (SizeRequired + 1);\r
+  ASSERT (NvRamMap != NULL);\r
+\r
+  //\r
+  // Copy current NvRamMap to the new NvRamMap\r
+  //\r
+  CopyMem (NvRamMap, VariableDefinition->NvRamMap, VariableDefinition->VariableFakeSize);\r
+\r
+  //\r
+  // Remember, the only time we come here is because we are in the NVPlus section of the NvRamMap\r
+  //\r
+  for (Index = MenuOption->TagIndex;\r
+       (MenuOption->Tags[Index].Operand != EFI_IFR_END_FORM_OP) && (MenuOption->Tags[Index].Operand != EFI_IFR_END_ONE_OF_OP);\r
+       Index++\r
+      ) {\r
+\r
+    switch (MenuOption->Tags[Index].Operand) {\r
+    case EFI_IFR_ORDERED_LIST_OP:\r
+    case EFI_IFR_ONE_OF_OP:\r
+      CachedStart = MenuOption->Tags[Index].StorageStart;\r
+      break;\r
+\r
+    case EFI_IFR_ONE_OF_OPTION_OP:\r
+      if (MenuOption->Tags[Index].Flags & EFI_IFR_FLAG_DEFAULT) {\r
+        CopyMem (&NvRamMap[CachedStart], &MenuOption->Tags[Index].Value, 2);\r
+      }\r
+      break;\r
+\r
+    case EFI_IFR_CHECKBOX_OP:\r
+      CopyMem (&NvRamMap[MenuOption->Tags[Index].StorageStart], &MenuOption->Tags[Index].Flags, 1);\r
+      break;\r
+\r
+    case EFI_IFR_NUMERIC_OP:\r
+    case EFI_IFR_DATE_OP:\r
+    case EFI_IFR_TIME_OP:\r
+    case EFI_IFR_STRING_OP:\r
+    case EFI_IFR_PASSWORD_OP:\r
+      CopyMem (\r
+        &NvRamMap[MenuOption->Tags[Index].StorageStart],\r
+        &MenuOption->Tags[Index].Value,\r
+        MenuOption->Tags[Index].StorageWidth\r
+        );\r
+      break;\r
+\r
+    }\r
+  }\r
+\r
+  FreePool (VariableDefinition->NvRamMap);\r
+  VariableDefinition->NvRamMap          = NvRamMap;\r
+  VariableDefinition->VariableFakeSize  = (UINT16) SizeRequired;\r
+}\r
+\r
+EFI_STATUS\r
+ProcessOptions (\r
+  IN  UI_MENU_OPTION              *MenuOption,\r
+  IN  BOOLEAN                     Selected,\r
+  IN  EFI_FILE_FORM_TAGS          *FileFormTagsHead,\r
+  IN  EFI_IFR_DATA_ARRAY          *PageData,\r
+  OUT CHAR16                      **OptionString\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  CHAR16                      *StringPtr;\r
+  UINTN                       Index;\r
+  UINTN                       CachedIndex;\r
+  EFI_FILE_FORM_TAGS          *FileFormTags;\r
+  EFI_TAG                     *Tag;\r
+  CHAR16                      FormattedNumber[6];\r
+  UINT16                      Number;\r
+  UINT16                      Value;\r
+  UINT16                      *ValueArray;\r
+  UINT16                      *NvRamMap;\r
+  CHAR8                       *TmpNvRamMap;\r
+  UINTN                       Default;\r
+  UINTN                       StringCount;\r
+  CHAR16                      Character[2];\r
+  UINTN                       Count;\r
+  EFI_TIME                    Time;\r
+  EFI_FORM_CALLBACK_PROTOCOL  *FormCallback;\r
+  STRING_REF                  PopUp;\r
+  CHAR16                      NullCharacter;\r
+  EFI_INPUT_KEY               Key;\r
+  EFI_VARIABLE_DEFINITION     *VariableDefinition;\r
+  BOOLEAN                     OrderedList;\r
+  BOOLEAN                     Initialized;\r
+  UINT16                      KeyValue;\r
+  BOOLEAN                     Skip;\r
+\r
+  FileFormTags = FileFormTagsHead;\r
+\r
+  for (Index = 0; Index < MenuOption->IfrNumber; Index++) {\r
+    FileFormTags = FileFormTags->NextFile;\r
+  }\r
+\r
+  OrderedList         = FALSE;\r
+  Initialized         = FALSE;\r
+  ValueArray          = NULL;\r
+  VariableDefinition  = NULL;\r
+  Skip                = FALSE;\r
+\r
+  ZeroMem (&Time, sizeof (EFI_TIME));\r
+\r
+  StringPtr = (CHAR16 *) L"\0";\r
+  Tag       = MenuOption->ThisTag;\r
+  ExtractRequestedNvMap (FileFormTags, Tag->VariableNumber, &VariableDefinition);\r
+\r
+  if (Tag->StorageStart > VariableDefinition->VariableSize) {\r
+    NvRamMap = (UINT16 *) &VariableDefinition->FakeNvRamMap[Tag->StorageStart];\r
+  } else {\r
+    NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];\r
+  }\r
+\r
+  StringCount   = 0;\r
+  Character[1]  = 0;\r
+  Count         = 0;\r
+  Default       = 0;\r
+  NullCharacter = CHAR_NULL;\r
+  FormCallback  = NULL;\r
+\r
+  if (MenuOption->ThisTag->Operand == EFI_IFR_ORDERED_LIST_OP) {\r
+    OrderedList = TRUE;\r
+    if (((UINT8 *) NvRamMap)[0] != 0x00) {\r
+      Initialized = TRUE;\r
+    }\r
+  }\r
+\r
+  ZeroMem (FormattedNumber, 12);\r
+\r
+  Status = gBS->HandleProtocol (\r
+                  (VOID *) (UINTN) FileFormTags->FormTags.Tags[0].CallbackHandle,\r
+                  &gEfiFormCallbackProtocolGuid,\r
+                  (VOID **) &FormCallback\r
+                  );\r
+\r
+  if (*OptionString != NULL) {\r
+    FreePool (*OptionString);\r
+    *OptionString = NULL;\r
+  }\r
+\r
+  switch (Tag->Operand) {\r
+\r
+  case EFI_IFR_ORDERED_LIST_OP:\r
+  case EFI_IFR_ONE_OF_OP:\r
+    //\r
+    // If the op-code we are looking at is larger than the latest created NvMap - we likely encountered a dynamically\r
+    // created entry which has an expanded NvMap requirement.  We won't save this information - but we need to adjust\r
+    // the NvMap so that we can properly display the information\r
+    //\r
+    if ((UINTN) (Tag->StorageStart + Tag->StorageWidth) > VariableDefinition->VariableFakeSize) {\r
+      AdjustNvMap (FileFormTags, MenuOption);\r
+      NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];\r
+    }\r
+\r
+    CachedIndex = MenuOption->TagIndex;\r
+\r
+    //\r
+    // search for EFI_IFR_ONE_OF_OPTION_OP until you hit the EFI_IFR_END_ONE_OF_OP,\r
+    // each of the .Text in the options are going to be what gets displayed.  Break each into 26 char chunks\r
+    // when hit right/left arrow allows for selection - then repopulate Tag[TagIndex] with the choice\r
+    //\r
+    for (Index = MenuOption->TagIndex; MenuOption->Tags[Index].Operand != EFI_IFR_END_ONE_OF_OP; Index++) {\r
+      //\r
+      // We found an option - which assumedly has a string.  We will eventually have to support\r
+      // wrapping of strings.  For now, let's pretend they don't wrap and code that up.\r
+      //\r
+      // Count how many strings there are\r
+      //\r
+      if (MenuOption->Tags[Index].Operand == EFI_IFR_ONE_OF_OPTION_OP) {\r
+        //\r
+        // If one of the options for the one-of has an interactive flag, back-define the oneof to have one too\r
+        //\r
+        if (MenuOption->Tags[Index].Flags & EFI_IFR_FLAG_INTERACTIVE) {\r
+          MenuOption->Tags[CachedIndex].Flags = (UINT8) (MenuOption->Tags[CachedIndex].Flags | EFI_IFR_FLAG_INTERACTIVE);\r
+        }\r
+\r
+        StringCount++;\r
+      }\r
+    }\r
+    //\r
+    // We now know how many strings we will have, so we can allocate the\r
+    // space required for the array or strings.\r
+    //\r
+    *OptionString = AllocateZeroPool (StringCount * (gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow);\r
+    ASSERT (*OptionString);\r
+\r
+    //\r
+    // Add left delimeter to string\r
+    //\r
+    *OptionString[0] = LEFT_ONEOF_DELIMITER;\r
+\r
+    //\r
+    // Retrieve the current OneOf value\r
+    //\r
+    if (Selected) {\r
+      //\r
+      // Auto selection from list\r
+      //\r
+      Value = 0;\r
+      //\r
+      // Copy current setting to the seed Value\r
+      //\r
+      if (Tag->Operand == EFI_IFR_ORDERED_LIST_OP) {\r
+        ValueArray = AllocateZeroPool (MenuOption->ThisTag->StorageWidth);\r
+        ASSERT (ValueArray != NULL);\r
+        CopyMem (ValueArray, NvRamMap, MenuOption->ThisTag->StorageWidth);\r
+      } else {\r
+        CopyMem (&Value, NvRamMap, MenuOption->ThisTag->StorageWidth);\r
+        CopyMem (gPreviousValue, NvRamMap, MenuOption->ThisTag->StorageWidth);\r
+      }\r
+\r
+      Number = Value;\r
+      if (Tag->Operand == EFI_IFR_ORDERED_LIST_OP) {\r
+        Status = GetSelectionInputPopUp (MenuOption, Tag, MenuOption->ThisTag->StorageWidth, ValueArray, &KeyValue);\r
+      } else {\r
+        Status = GetSelectionInputPopUp (MenuOption, Tag, 1, &Value, &KeyValue);\r
+      }\r
+\r
+      if (!EFI_ERROR (Status)) {\r
+        if (Tag->Operand == EFI_IFR_ORDERED_LIST_OP) {\r
+          CopyMem (NvRamMap, ValueArray, MenuOption->ThisTag->StorageWidth);\r
+          FreePool (ValueArray);\r
+        } else {\r
+          //\r
+          // Since the value can be one byte long or two bytes long, do a CopyMem based on StorageWidth\r
+          //\r
+          CopyMem (NvRamMap, &Value, Tag->StorageWidth);\r
+          MenuOption->ThisTag->Key = KeyValue;\r
+        }\r
+        //\r
+        // If a late check is required save off the information.  This is used when consistency checks\r
+        // are required, but certain values might be bound by an impossible consistency check such as\r
+        // if two questions are bound by consistency checks and each only has two possible choices, there\r
+        // would be no way for a user to switch the values.  Thus we require late checking.\r
+        //\r
+        if (Tag->Flags & EFI_IFR_FLAG_LATE_CHECK) {\r
+          CopyMem (&Tag->OldValue, &Value, Tag->StorageWidth);\r
+        } else {\r
+          //\r
+          // In theory, passing the value and the Id are sufficient to determine what needs\r
+          // to be done.  The Id is the key to look for the entry needed in the Inconsistency\r
+          // database.  That will yields operand and ID data - and since the ID's correspond\r
+          // to the NV storage, we can determine the values for other IDs there.\r
+          //\r
+          if (ValueIsNotValid (TRUE, 0, Tag, FileFormTags, &PopUp)) {\r
+            if (PopUp == 0x0000) {\r
+              //\r
+              // Restore Old Value\r
+              //\r
+              if (!Tag->Suppress && !Tag->GrayOut) {\r
+                CopyMem (NvRamMap, &Number, MenuOption->ThisTag->StorageWidth);\r
+              }\r
+              break;\r
+            }\r
+\r
+            StringPtr = GetToken (PopUp, MenuOption->Handle);\r
+\r
+            CreatePopUp (GetStringWidth (StringPtr) / 2, 3, &NullCharacter, StringPtr, &NullCharacter);\r
+\r
+            do {\r
+              Status = WaitForKeyStroke (&Key);\r
+\r
+              switch (Key.UnicodeChar) {\r
+\r
+              case CHAR_CARRIAGE_RETURN:\r
+                //\r
+                // Since the value can be one byte long or two bytes long, do a CopyMem based on StorageWidth\r
+                //\r
+                CopyMem (NvRamMap, &Number, MenuOption->ThisTag->StorageWidth);\r
+                FreePool (StringPtr);\r
+                break;\r
+\r
+              default:\r
+                break;\r
+              }\r
+            } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
+          }\r
+        }\r
+\r
+        UpdateStatusBar (NV_UPDATE_REQUIRED, Tag->Flags, TRUE);\r
+      } else {\r
+        if (Tag->Operand == EFI_IFR_ORDERED_LIST_OP) {\r
+          FreePool (ValueArray);\r
+        }\r
+\r
+        return EFI_SUCCESS;\r
+      }\r
+    } else {\r
+      for (Index = MenuOption->TagIndex; MenuOption->Tags[Index].Operand != EFI_IFR_END_ONE_OF_OP; Index++) {\r
+        //\r
+        // We found an option - which assumedly has a string.  We will eventually have to support\r
+        // wrapping of strings.  For now, let's pretend they don't wrap and code that up.\r
+        //\r
+        if (MenuOption->Tags[Index].Operand == EFI_IFR_ONE_OF_OPTION_OP) {\r
+          if (OrderedList) {\r
+            if (!Initialized) {\r
+              //\r
+              // If the first entry is invalid, then the "default" settings are based on what is reflected\r
+              // in the order of the op-codes\r
+              //\r
+              ((UINT8 *) NvRamMap)[Index - MenuOption->TagIndex - 1] = (UINT8) MenuOption->Tags[Index].Value;\r
+            }\r
+            //\r
+            // Only display 3 lines of stuff at most\r
+            //\r
+            if ((Index - MenuOption->TagIndex) > ORDERED_LIST_SIZE) {\r
+              break;\r
+            }\r
+\r
+            if (((Index - MenuOption->TagIndex) != 1) && !Skip) {\r
+              Character[0] = LEFT_ONEOF_DELIMITER;\r
+              NewStrCat (OptionString[0], Character);\r
+            }\r
+\r
+            MenuOption->ThisTag->NumberOfLines = (UINT16) (Index - MenuOption->TagIndex);\r
+            if (!Initialized) {\r
+              StringPtr = GetToken (MenuOption->Tags[Index].Text, MenuOption->Handle);\r
+            } else {\r
+              for (Value = (UINT16) (MenuOption->TagIndex + 1);\r
+                   MenuOption->Tags[Value].Operand != EFI_IFR_END_ONE_OF_OP;\r
+                   Value++\r
+                  ) {\r
+                if (MenuOption->Tags[Value].Value == ((UINT8 *) NvRamMap)[Index - MenuOption->TagIndex - 1]) {\r
+                  StringPtr = GetToken (MenuOption->Tags[Value].Text, MenuOption->Handle);\r
+                  break;\r
+                }\r
+              }\r
+\r
+              if (MenuOption->Tags[Value].Operand == EFI_IFR_END_ONE_OF_OP) {\r
+                Skip = TRUE;\r
+                continue;\r
+              }\r
+            }\r
+\r
+            Skip = FALSE;\r
+            NewStrCat (OptionString[0], StringPtr);\r
+            Character[0] = RIGHT_ONEOF_DELIMITER;\r
+            NewStrCat (OptionString[0], Character);\r
+            Character[0] = CHAR_CARRIAGE_RETURN;\r
+            NewStrCat (OptionString[0], Character);\r
+\r
+            //\r
+            // Remove Buffer allocated for StringPtr after it has been used.\r
+            //\r
+            FreePool (StringPtr);\r
+          } else {\r
+            //\r
+            // The option value is the same as what is stored in NV store.  Print this.\r
+            //\r
+            if (!CompareMem (&(MenuOption->Tags[Index].Value), NvRamMap, MenuOption->ThisTag->StorageWidth)) {\r
+              StringPtr = GetToken (MenuOption->Tags[Index].Text, MenuOption->Handle);\r
+              NewStrCat (OptionString[0], StringPtr);\r
+              Character[0] = RIGHT_ONEOF_DELIMITER;\r
+              NewStrCat (OptionString[0], Character);\r
+              //\r
+              // Remove Buffer allocated for StringPtr after it has been used.\r
+              //\r
+              FreePool (StringPtr);\r
+              Default = 0;\r
+              break;\r
+            }\r
+\r
+            if ((MenuOption->Tags[Index].Flags & EFI_IFR_FLAG_DEFAULT) == 1) {\r
+              Default = MenuOption->Tags[Index].Text;\r
+              Value   = MenuOption->Tags[Index].Value;\r
+            };\r
+          }\r
+        }\r
+      }\r
+      //\r
+      // We didn't find a value that matched a setting in the NVRAM Map - display default - set default\r
+      //\r
+      if (Default != 0) {\r
+        //\r
+        // Since the value can be one byte long or two bytes long, do a CopyMem based on StorageWidth\r
+        //\r
+        CopyMem (NvRamMap, &Value, MenuOption->ThisTag->StorageWidth);\r
+\r
+        StringPtr = GetToken ((UINT16) Default, MenuOption->Handle);\r
+        NewStrCat (OptionString[0], StringPtr);\r
+        Character[0] = RIGHT_ONEOF_DELIMITER;\r
+        NewStrCat (OptionString[0], Character);\r
+        //\r
+        // Remove Buffer allocated for StringPtr after it has been used.\r
+        //\r
+        FreePool (StringPtr);\r
+      }\r
+    }\r
+    break;\r
+\r
+  case EFI_IFR_CHECKBOX_OP:\r
+    //\r
+    // If the op-code we are looking at is larger than the latest created NvMap - we likely encountered a dynamically\r
+    // created entry which has an expanded NvMap requirement.  We won't save this information - but we need to adjust\r
+    // the NvMap so that we can properly display the information\r
+    //\r
+    if ((UINTN) (Tag->StorageStart + Tag->StorageWidth) > VariableDefinition->VariableFakeSize) {\r
+      AdjustNvMap (FileFormTags, MenuOption);\r
+      NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];\r
+    }\r
+\r
+    Default = Tag->Flags & 1;\r
+    //\r
+    // If hit spacebar, set or unset Tag[TagIndex].Flags based on it's previous value - BOOLEAN\r
+    //\r
+    *OptionString = AllocateZeroPool ((gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow);\r
+    ASSERT (*OptionString);\r
+\r
+    //\r
+    // Since Checkboxes are BOOLEAN values, bit 0 of the Flags bit defines the default option, therefore, if\r
+    // the default option (only one option for checkboxes) is on, then the default value is on.  Tag.Default is not\r
+    // an active field for Checkboxes.\r
+    //\r
+    StrnCpy (OptionString[0], (CHAR16 *) LEFT_CHECKBOX_DELIMITER, 1);\r
+\r
+    //\r
+    // Since this is a BOOLEAN operation, flip bit 0 upon selection\r
+    //\r
+    if (Selected) {\r
+      Tag->Value          = (UINT16) (Tag->Value ^ 1);\r
+      *(UINT8 *) NvRamMap = (UINT8) (Tag->Value & 1);\r
+      UpdateStatusBar (NV_UPDATE_REQUIRED, Tag->Flags, TRUE);\r
+    }\r
+\r
+    if ((*(UINT8 *) NvRamMap & 1) == 0x01) {\r
+      NewStrCat (OptionString[0], (CHAR16 *) CHECK_ON);\r
+      //\r
+      // If someone reset default variables - we may need to reload from our NvMapping....\r
+      //\r
+      Tag->Value = *(UINT8 *) NvRamMap;\r
+    } else {\r
+      //\r
+      // If someone reset default variables - we may need to reload from our NvMapping....\r
+      //\r
+      NewStrCat (OptionString[0], (CHAR16 *) CHECK_OFF);\r
+      Tag->Value = *(UINT8 *) NvRamMap;\r
+    }\r
+\r
+    NewStrCat (OptionString[0], (CHAR16 *) RIGHT_CHECKBOX_DELIMITER);\r
+    NewStrCat (OptionString[0], StringPtr);\r
+    break;\r
+\r
+  case EFI_IFR_NUMERIC_OP:\r
+    //\r
+    // If the op-code we are looking at is larger than the latest created NvMap - we likely encountered a dynamically\r
+    // created entry which has an expanded NvMap requirement.  We won't save this information - but we need to adjust\r
+    // the NvMap so that we can properly display the information\r
+    //\r
+    if ((UINTN) (Tag->StorageStart + Tag->StorageWidth) > VariableDefinition->VariableFakeSize) {\r
+      AdjustNvMap (FileFormTags, MenuOption);\r
+      NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];\r
+    }\r
+\r
+    *OptionString = AllocateZeroPool ((gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow);\r
+    ASSERT (*OptionString);\r
+\r
+    //\r
+    // Add left delimeter to string\r
+    //\r
+    *OptionString[0] = LEFT_NUMERIC_DELIMITER;\r
+\r
+    //\r
+    // Retrieve the current numeric value\r
+    //\r
+    if (Selected) {\r
+      //\r
+      // Go ask for input\r
+      //\r
+      if (Tag->Step == 0) {\r
+        //\r
+        // Manual Input\r
+        //\r
+        Status = GetNumericInput (MenuOption, FileFormTagsHead, TRUE, Tag, REGULAR_NUMERIC, &Number);\r
+        if (!EFI_ERROR (Status)) {\r
+          CopyMem (gPreviousValue, NvRamMap, MenuOption->ThisTag->StorageWidth);\r
+          UpdateStatusBar (NV_UPDATE_REQUIRED, Tag->Flags, TRUE);\r
+\r
+          //\r
+          // Since the value can be one byte long or two bytes long, do a CopyMem based on StorageWidth\r
+          //\r
+          CopyMem (NvRamMap, &Number, MenuOption->ThisTag->StorageWidth);\r
+        } else {\r
+          return EFI_SUCCESS;\r
+        }\r
+      } else {\r
+        //\r
+        // Auto selection from list\r
+        //\r
+        if ((((Tag->StorageWidth == 1) && (UINT8) (*NvRamMap) > Tag->Maximum) || ((UINT8) (*NvRamMap) < Tag->Minimum)) ||\r
+            (((Tag->StorageWidth == 2) && *NvRamMap > Tag->Maximum) || (*NvRamMap < Tag->Minimum))\r
+            ) {\r
+          //\r
+          // Seed Number with valid value if currently invalid\r
+          //\r
+          Number = Tag->Default;\r
+        } else {\r
+          if (Tag->StorageWidth == 1) {\r
+            Number = (UINT8) (*NvRamMap);\r
+          } else {\r
+            Number = *NvRamMap;\r
+          }\r
+        }\r
+\r
+        Status = GetNumericInput (MenuOption, FileFormTagsHead, FALSE, Tag, REGULAR_NUMERIC, &Number);\r
+        if (!EFI_ERROR (Status)) {\r
+          CopyMem (gPreviousValue, NvRamMap, MenuOption->ThisTag->StorageWidth);\r
+          UpdateStatusBar (NV_UPDATE_REQUIRED, Tag->Flags, TRUE);\r
+\r
+          //\r
+          // Since the value can be one byte long or two bytes long, do a CopyMem based on StorageWidth\r
+          //\r
+          CopyMem (NvRamMap, &Number, MenuOption->ThisTag->StorageWidth);\r
+        } else {\r
+          return EFI_SUCCESS;\r
+        }\r
+      }\r
+    } else {\r
+      if (((Tag->StorageWidth == 1) && (UINT8) (*NvRamMap) <= Tag->Maximum && (UINT8) (*NvRamMap) >= Tag->Minimum) ||\r
+          ((Tag->StorageWidth == 2) && *NvRamMap <= Tag->Maximum && *NvRamMap >= Tag->Minimum)\r
+          ) {\r
+        if (Tag->StorageWidth == 1) {\r
+          Number = (UINT8) (*NvRamMap);\r
+        } else {\r
+          Number = *NvRamMap;\r
+        }\r
+        UnicodeValueToString (\r
+          FormattedNumber,\r
+          FALSE,\r
+          (UINTN) Number,\r
+          (sizeof (FormattedNumber) / sizeof (FormattedNumber[0]))\r
+          );\r
+        Number = (UINT16) GetStringWidth (FormattedNumber);\r
+        StrnCpy (OptionString[0] + 1, FormattedNumber, Number);\r
+      } else {\r
+        //\r
+        // If *NvRamMap isn't within parameters, set it to within parameters\r
+        //\r
+        //\r
+        // Since the value can be one byte long or two bytes long, do a CopyMem based on StorageWidth\r
+        //\r
+        CopyMem (NvRamMap, &Tag->Default, MenuOption->ThisTag->StorageWidth);\r
+        Number = Tag->Default;\r
+\r
+        UnicodeValueToString (\r
+          FormattedNumber,\r
+          FALSE,\r
+          (UINTN) Number,\r
+          (sizeof (FormattedNumber) / sizeof (FormattedNumber[0]))\r
+          );\r
+        Number = (UINT16) GetStringWidth (FormattedNumber);\r
+        StrnCpy (OptionString[0] + 1, FormattedNumber, Number);\r
+      }\r
+\r
+      *(OptionString[0] + Number / 2) = RIGHT_NUMERIC_DELIMITER;\r
+      NewStrCat (OptionString[0] + (Number / 2) + 1, StringPtr);\r
+    }\r
+    break;\r
+\r
+  case EFI_IFR_DATE_OP:\r
+    //\r
+    // If the op-code we are looking at is larger than the latest created NvMap - we likely encountered a dynamically\r
+    // created entry which has an expanded NvMap requirement.  We won't save this information - but we need to adjust\r
+    // the NvMap so that we can properly display the information\r
+    //\r
+    if ((UINTN) (Tag->StorageStart + Tag->StorageWidth) > VariableDefinition->VariableFakeSize) {\r
+      AdjustNvMap (FileFormTags, MenuOption);\r
+      NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];\r
+    }\r
+\r
+    Status = gRT->GetTime (&Time, NULL);\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_SUCCESS;\r
+    }\r
+    //\r
+    // This for loop advances Index till it points immediately after a date entry.  We can then\r
+    // subtract MenuOption->TagIndex from Index and find out relative to the start of the Date\r
+    // structure which field we were in.  For instance, if TagIndex was 52, and we advanced Index\r
+    // to 53 and found it to no longer point to a date operand, we were pointing to the last of 3\r
+    // date operands.\r
+    //\r
+    //\r
+    // This has BUGBUG potential....fix this - if someone wants to ask two DATE questions in a row.....code\r
+    // against such silliness.\r
+    //\r
+    // Also, we want to internationalize the order of the date information.  We need to code for it as well.\r
+    //\r
+    for (Index = MenuOption->TagIndex; MenuOption->Tags[Index].Operand == EFI_IFR_DATE_OP; Index++)\r
+      ;\r
+\r
+    //\r
+    // Count 0 = We entered on the first Date operand\r
+    // Count 1 = We entered on the second Date operand\r
+    // Count 2 = We entered on the third Date operand\r
+    //\r
+    Count = 3 - (Index - MenuOption->TagIndex);\r
+    if (Count > 2) {\r
+      return EFI_SUCCESS;\r
+    }\r
+    //\r
+    // This is similar to numerics, except for the following:\r
+    // We will under normal circumstances get 3 consecutive calls\r
+    // to process this opcodes data.\r
+    //\r
+    *OptionString = AllocateZeroPool ((gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow);\r
+    ASSERT (*OptionString);\r
+\r
+    switch (Count) {\r
+    case 0:\r
+      if (Selected) {\r
+        Number = (UINT16) Time.Month;\r
+\r
+        if (Tag->Step == 0) {\r
+          MenuOption->OptCol++;\r
+          Status = GetNumericInput (MenuOption, FileFormTagsHead, TRUE, Tag, DATE_NUMERIC, &Number);\r
+        } else {\r
+          //\r
+          // Seed value with current setting\r
+          //\r
+          Tag->Value  = (UINT16) Time.Month;\r
+          Status      = GetNumericInput (MenuOption, FileFormTagsHead, FALSE, Tag, DATE_NUMERIC, &Number);\r
+        }\r
+\r
+        if (!EFI_ERROR (Status)) {\r
+          Time.Month = (UINT8) Number;\r
+          gRT->SetTime (&Time);\r
+        }\r
+      }\r
+\r
+      VariableDefinition->FakeNvRamMap[Tag->Id] = Time.Month;\r
+      *OptionString[0]                          = LEFT_NUMERIC_DELIMITER;\r
+\r
+      UnicodeValueToString (\r
+        FormattedNumber,\r
+        FALSE,\r
+        (UINTN) Time.Month,\r
+        (sizeof (FormattedNumber) / sizeof (FormattedNumber[0]))\r
+        );\r
+      Number = (UINT16) GetStringWidth (FormattedNumber);\r
+\r
+      if (Number == 4) {\r
+        FormattedNumber[2]  = FormattedNumber[1];\r
+        FormattedNumber[1]  = FormattedNumber[0];\r
+        FormattedNumber[0]  = L'0';\r
+        Number              = 6;\r
+      }\r
+\r
+      StrnCpy (OptionString[0] + 1, FormattedNumber, Number);\r
+      *(OptionString[0] + Number / 2) = DATE_SEPARATOR;\r
+      StrCat (OptionString[0] + (Number / 2) + 1, StringPtr);\r
+      break;\r
+\r
+    case 1:\r
+      if (Selected) {\r
+        Number = (UINT16) Time.Day;\r
+\r
+        if (Tag->Step == 0) {\r
+          Status = GetNumericInput (MenuOption, FileFormTagsHead, TRUE, Tag, DATE_NUMERIC, &Number);\r
+        } else {\r
+          //\r
+          // Seed value with current setting\r
+          //\r
+          Tag->Value  = (UINT16) Time.Day;\r
+          Status      = GetNumericInput (MenuOption, FileFormTagsHead, FALSE, Tag, DATE_NUMERIC, &Number);\r
+        }\r
+\r
+        if (!EFI_ERROR (Status)) {\r
+          Time.Day = (UINT8) Number;\r
+          gRT->SetTime (&Time);\r
+        }\r
+      }\r
+\r
+      VariableDefinition->FakeNvRamMap[Tag->Id] = Time.Day;\r
+      SetUnicodeMem (OptionString[0], 4, L' ');\r
+\r
+      UnicodeValueToString (\r
+        FormattedNumber,\r
+        FALSE,\r
+        (UINTN) Time.Day,\r
+        (sizeof (FormattedNumber) / sizeof (FormattedNumber[0]))\r
+        );\r
+      Number = (UINT16) GetStringWidth (FormattedNumber);\r
+      if (Number == 4) {\r
+        FormattedNumber[2]  = FormattedNumber[1];\r
+        FormattedNumber[1]  = FormattedNumber[0];\r
+        FormattedNumber[0]  = L'0';\r
+        Number              = 6;\r
+      }\r
+\r
+      StrnCpy (OptionString[0] + 4, FormattedNumber, Number);\r
+      *(OptionString[0] + Number / 2 + 3) = DATE_SEPARATOR;\r
+      StrCat (OptionString[0] + (Number / 2) + 4, StringPtr);\r
+      break;\r
+\r
+    case 2:\r
+      if (Selected) {\r
+        Number = (UINT16) Time.Year;\r
+\r
+        if (Tag->Step == 0) {\r
+          Status = GetNumericInput (MenuOption, FileFormTagsHead, TRUE, Tag, DATE_NUMERIC, &Number);\r
+        } else {\r
+          //\r
+          // Seed value with current setting\r
+          //\r
+          Status = GetNumericInput (MenuOption, FileFormTagsHead, FALSE, Tag, DATE_NUMERIC, &Number);\r
+        }\r
+\r
+        if (!EFI_ERROR (Status)) {\r
+          Time.Year = (UINT16) Number;\r
+          gRT->SetTime (&Time);\r
+        }\r
+      }\r
+\r
+      Tag->Value  = (UINT16) Time.Year;\r
+      VariableDefinition->FakeNvRamMap[Tag->Id]     = (UINT8) Tag->Value;\r
+      VariableDefinition->FakeNvRamMap[Tag->Id + 1] = (UINT8) (Tag->Value >> 8);\r
+      SetUnicodeMem (OptionString[0], 7, L' ');\r
+      UnicodeValueToString (\r
+        FormattedNumber,\r
+        FALSE,\r
+        (UINTN) Time.Year,\r
+        (sizeof (FormattedNumber) / sizeof (FormattedNumber[0]))\r
+        );\r
+      Number = (UINT16) GetStringWidth (FormattedNumber);\r
+      StrnCpy (OptionString[0] + 7, FormattedNumber, Number);\r
+      *(OptionString[0] + Number / 2 + 6) = RIGHT_NUMERIC_DELIMITER;\r
+      StrCat (OptionString[0] + (Number / 2) + 7, StringPtr);\r
+      break;\r
+    }\r
+\r
+    break;\r
+\r
+  //\r
+  // BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG\r
+  // We need to add code to support the NVRam storage version of Date - this is the 1% case where someone\r
+  // might want to set an alarm and actually preserve the data in NVRam so a driver can pick up the instruction\r
+  // BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG\r
+  //\r
+  case EFI_IFR_TIME_OP:\r
+    //\r
+    // If the op-code we are looking at is larger than the latest created NvMap - we likely encountered a dynamically\r
+    // created entry which has an expanded NvMap requirement.  We won't save this information - but we need to adjust\r
+    // the NvMap so that we can properly display the information\r
+    //\r
+    if ((UINTN) (Tag->StorageStart + Tag->StorageWidth) > VariableDefinition->VariableFakeSize) {\r
+      AdjustNvMap (FileFormTags, MenuOption);\r
+      NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];\r
+    }\r
+\r
+    Status = gRT->GetTime (&Time, NULL);\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_SUCCESS;\r
+    }\r
+    //\r
+    // This is similar to numerics, except for the following:\r
+    // We will under normal circumstances get 3 consecutive calls\r
+    // to process this opcodes data.\r
+    //\r
+    *OptionString = AllocateZeroPool ((gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow);\r
+    ASSERT (*OptionString);\r
+\r
+    //\r
+    // This for loop advances Index till it points immediately after a date entry.  We can then\r
+    // subtract MenuOption->TagIndex from Index and find out relative to the start of the Date\r
+    // structure which field we were in.  For instance, if TagIndex was 52, and we advanced Index\r
+    // to 53 and found it to no longer point to a date operand, we were pointing to the last of 3\r
+    // date operands.\r
+    //\r
+    for (Index = MenuOption->TagIndex; MenuOption->Tags[Index].Operand == EFI_IFR_TIME_OP; Index++)\r
+      ;\r
+    //\r
+    // Count 0 = We entered on the first Date operand\r
+    // Count 1 = We entered on the second Date operand\r
+    // Count 2 = We entered on the third Date operand\r
+    //\r
+    Count = 3 - (Index - MenuOption->TagIndex);\r
+    if (Count > 2) {\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    switch (Count) {\r
+    case 0:\r
+      Number = Time.Hour;\r
+      break;\r
+\r
+    case 1:\r
+      Number = Time.Minute;\r
+      break;\r
+\r
+    case 2:\r
+      Number = Time.Second;\r
+    }\r
+    //\r
+    // Retrieve the current numeric value\r
+    //\r
+    if (Selected) {\r
+      //\r
+      // Go ask for input\r
+      //\r
+      if (Tag->Step == 0) {\r
+        //\r
+        // Manual Input\r
+        //\r
+        Status = GetNumericInput (MenuOption, FileFormTagsHead, TRUE, Tag, TIME_NUMERIC, &Number);\r
+        if (!EFI_ERROR (Status)) {\r
+          *NvRamMap       = Number;\r
+          Time.Nanosecond = 0;\r
+          gRT->SetTime (&Time);\r
+        } else {\r
+          return EFI_SUCCESS;\r
+        }\r
+      } else {\r
+        //\r
+        // Auto selection from list\r
+        //\r
+        Status = GetNumericInput (MenuOption, FileFormTagsHead, FALSE, Tag, TIME_NUMERIC, &Number);\r
+        if (!EFI_ERROR (Status)) {\r
+          *NvRamMap = Number;\r
+        } else {\r
+          return EFI_SUCCESS;\r
+        }\r
+      }\r
+\r
+      switch (Count) {\r
+      case 0:\r
+        Time.Hour = (UINT8) Number;\r
+        break;\r
+\r
+      case 1:\r
+        Time.Minute = (UINT8) Number;\r
+        break;\r
+\r
+      case 2:\r
+        Time.Second = (UINT8) Number;\r
+      }\r
+\r
+      Time.Nanosecond = 0;\r
+      gRT->SetTime (&Time);\r
+    } else {\r
+      switch (Count) {\r
+      case 0:\r
+        *OptionString[0] = LEFT_NUMERIC_DELIMITER;\r
+        UnicodeValueToString (\r
+          FormattedNumber,\r
+          FALSE,\r
+          (UINTN) Time.Hour,\r
+          (sizeof (FormattedNumber) / sizeof (FormattedNumber[0]))\r
+          );\r
+        Number = (UINT16) GetStringWidth (FormattedNumber);\r
+        if (Number == 4) {\r
+          FormattedNumber[2]  = FormattedNumber[1];\r
+          FormattedNumber[1]  = FormattedNumber[0];\r
+          FormattedNumber[0]  = L'0';\r
+          Number              = 6;\r
+        }\r
+\r
+        StrnCpy (OptionString[0] + 1, FormattedNumber, Number);\r
+        *(OptionString[0] + Number / 2) = TIME_SEPARATOR;\r
+        StrCat (OptionString[0] + (Number / 2) + 1, StringPtr);\r
+        break;\r
+\r
+      case 1:\r
+        SetUnicodeMem (OptionString[0], 4, L' ');\r
+        UnicodeValueToString (\r
+          FormattedNumber,\r
+          FALSE,\r
+          (UINTN) Time.Minute,\r
+          (sizeof (FormattedNumber) / sizeof (FormattedNumber[0]))\r
+          );\r
+        Number = (UINT16) GetStringWidth (FormattedNumber);\r
+        if (Number == 4) {\r
+          FormattedNumber[2]  = FormattedNumber[1];\r
+          FormattedNumber[1]  = FormattedNumber[0];\r
+          FormattedNumber[0]  = L'0';\r
+          Number              = 6;\r
+        }\r
+\r
+        StrnCpy (OptionString[0] + 4, FormattedNumber, Number);\r
+        *(OptionString[0] + Number / 2 + 3) = TIME_SEPARATOR;\r
+        StrCat (OptionString[0] + (Number / 2) + 4, StringPtr);\r
+        break;\r
+\r
+      case 2:\r
+        SetUnicodeMem (OptionString[0], 7, L' ');\r
+        UnicodeValueToString (\r
+          FormattedNumber,\r
+          FALSE,\r
+          (UINTN) Time.Second,\r
+          (sizeof (FormattedNumber) / sizeof (FormattedNumber[0]))\r
+          );\r
+        Number = (UINT16) GetStringWidth (FormattedNumber);\r
+        if (Number == 4) {\r
+          FormattedNumber[2]  = FormattedNumber[1];\r
+          FormattedNumber[1]  = FormattedNumber[0];\r
+          FormattedNumber[0]  = L'0';\r
+          Number              = 6;\r
+        }\r
+\r
+        StrnCpy (OptionString[0] + 7, FormattedNumber, Number);\r
+        *(OptionString[0] + Number / 2 + 6) = RIGHT_NUMERIC_DELIMITER;\r
+        StrCat (OptionString[0] + (Number / 2) + 7, StringPtr);\r
+        break;\r
+      }\r
+      //\r
+      // BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG\r
+      // We need to add code to support the NVRam storage version of Date - this is the 1% case where someone\r
+      // might want to set an alarm and actually preserve the data in NVRam so a driver can pick up the instruction\r
+      // BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG\r
+      //\r
+    }\r
+    break;\r
+\r
+  case EFI_IFR_STRING_OP:\r
+    //\r
+    // If the op-code we are looking at is larger than the latest created NvMap - we likely encountered a dynamically\r
+    // created entry which has an expanded NvMap requirement.  We won't save this information - but we need to adjust\r
+    // the NvMap so that we can properly display the information\r
+    //\r
+    if ((UINTN) (Tag->StorageStart + Tag->StorageWidth) > VariableDefinition->VariableFakeSize) {\r
+      AdjustNvMap (FileFormTags, MenuOption);\r
+      NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];\r
+    }\r
+\r
+    *OptionString = AllocateZeroPool ((gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow);\r
+    ASSERT (*OptionString);\r
+\r
+    if (Selected) {\r
+      StringPtr = AllocateZeroPool (Tag->Maximum);\r
+      ASSERT (StringPtr);\r
+\r
+      Status = ReadString (MenuOption, StringPtr);\r
+\r
+      if (!EFI_ERROR (Status)) {\r
+        CopyMem (gPreviousValue, NvRamMap, MenuOption->ThisTag->StorageWidth);\r
+        CopyMem (&VariableDefinition->NvRamMap[Tag->StorageStart], StringPtr, Tag->StorageWidth);\r
+\r
+        UpdateStatusBar (NV_UPDATE_REQUIRED, Tag->Flags, TRUE);\r
+      }\r
+\r
+      FreePool (StringPtr);\r
+      return Status;\r
+    } else {\r
+      for (Index = 0; Index < gOptionBlockWidth; Index++) {\r
+        if (VariableDefinition->NvRamMap[Tag->StorageStart + (Index * 2)] != 0x0000) {\r
+          CopyMem (OptionString[0] + Index, &VariableDefinition->NvRamMap[Tag->StorageStart + (Index * 2)], 2);\r
+        } else {\r
+          if (Index == 0) {\r
+            *(OptionString[0] + Index)      = '_';\r
+            *(OptionString[0] + 1 + Index)  = 0;\r
+          }\r
+          break;\r
+        }\r
+      }\r
+\r
+      return Status;\r
+    }\r
+\r
+  case EFI_IFR_PASSWORD_OP:\r
+    //\r
+    // If the op-code we are looking at is larger than the latest created NvMap - we likely encountered a dynamically\r
+    // created entry which has an expanded NvMap requirement.  We won't save this information - but we need to adjust\r
+    // the NvMap so that we can properly display the information\r
+    //\r
+    if ((UINTN) (Tag->StorageStart + Tag->StorageWidth) > VariableDefinition->VariableFakeSize) {\r
+      AdjustNvMap (FileFormTags, MenuOption);\r
+      NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];\r
+    }\r
+\r
+    if (Selected) {\r
+      StringPtr = AllocateZeroPool (Tag->Maximum);\r
+      ASSERT (StringPtr);\r
+\r
+      //\r
+      // If interactive, read the password and do the appropriate callbacks in that routine.\r
+      // Since interactive passwords assume to handle the password data in a separate variable\r
+      // storage, we don't need to do more than what is below for password callbacks\r
+      //\r
+      if (Tag->Flags & EFI_IFR_FLAG_INTERACTIVE) {\r
+        MenuOption->Tags[0].CallbackHandle  = FileFormTags->FormTags.Tags[0].CallbackHandle;\r
+        Status = ReadPassword (MenuOption, TRUE, Tag, PageData, FALSE, FileFormTags, StringPtr);\r
+        ZeroMem (StringPtr, Tag->Maximum);\r
+\r
+        if (EFI_ERROR (Status)) {\r
+          if (Status == EFI_NOT_READY) {\r
+            FreePool (StringPtr);\r
+            return EFI_SUCCESS;\r
+          }\r
+        }\r
+\r
+        Status = ReadPassword (MenuOption, TRUE, Tag, PageData, TRUE, FileFormTags, StringPtr);\r
+        FreePool (StringPtr);\r
+        return EFI_SUCCESS;\r
+      }\r
+\r
+      for (Index = 0; Index < Tag->Maximum; Index++) {\r
+        if (VariableDefinition->NvRamMap[Tag->StorageStart + Index] != 0x00) {\r
+          //\r
+          // There is something there!  Prompt for password\r
+          //\r
+          Status = ReadPassword (MenuOption, TRUE, Tag, PageData, FALSE, FileFormTags, StringPtr);\r
+          if (EFI_ERROR (Status)) {\r
+            FreePool (StringPtr);\r
+            return EFI_SUCCESS;\r
+          }\r
+\r
+          if (Tag->Encoding == 1) {\r
+            EncodePassword (StringPtr, (UINT8) Tag->Maximum);\r
+            Status = CompareMem (StringPtr, &VariableDefinition->NvRamMap[Tag->StorageStart], Tag->Maximum);\r
+          } else {\r
+            Status = CompareMem (StringPtr, &VariableDefinition->NvRamMap[Tag->StorageStart], Tag->Maximum);\r
+          }\r
+\r
+          if (Status != 0) {\r
+            FreePool (StringPtr);\r
+            return EFI_SUCCESS;\r
+          } else {\r
+            break;\r
+          }\r
+        }\r
+      }\r
+      //\r
+      // Clean the string\r
+      //\r
+      ZeroMem (StringPtr, Tag->Maximum);\r
+\r
+      //\r
+      // No password set!  Go ahead and prompt the user for a password.\r
+      //\r
+      Status = ReadPassword (MenuOption, FALSE, Tag, PageData, FALSE, FileFormTags, StringPtr);\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        //\r
+        // User couldn't figure out how to type two identical passwords\r
+        //\r
+        FreePool (StringPtr);\r
+        return EFI_SUCCESS;\r
+      }\r
+      //\r
+      // Very simple example of how one MIGHT do password encoding\r
+      //\r
+      if (Tag->Encoding == 1) {\r
+        EncodePassword (StringPtr, (UINT8) Tag->Maximum);\r
+      }\r
+\r
+      TmpNvRamMap = AllocatePool (VariableDefinition->VariableSize);\r
+      ASSERT (TmpNvRamMap != NULL);\r
+\r
+      Count = VariableDefinition->VariableSize;\r
+\r
+      if ((FormCallback != NULL) && (FormCallback->NvRead != NULL)) {\r
+        Status = FormCallback->NvRead (\r
+                                FormCallback,\r
+                                VariableDefinition->VariableName,\r
+                                &VariableDefinition->Guid,\r
+                                NULL,\r
+                                &Count,\r
+                                (VOID *) TmpNvRamMap\r
+                                );\r
+      } else {\r
+        Status = gRT->GetVariable (\r
+                        VariableDefinition->VariableName,\r
+                        &VariableDefinition->Guid,\r
+                        NULL,\r
+                        &Count,\r
+                        (VOID *) TmpNvRamMap\r
+                        );\r
+      }\r
+\r
+      CopyMem (&VariableDefinition->NvRamMap[Tag->StorageStart], StringPtr, Tag->StorageWidth);\r
+      CopyMem (&TmpNvRamMap[Tag->StorageStart], StringPtr, Tag->StorageWidth);\r
+\r
+      if ((FormCallback != NULL) && (FormCallback->NvWrite != NULL)) {\r
+        Status = FormCallback->NvWrite (\r
+                                FormCallback,\r
+                                VariableDefinition->VariableName,\r
+                                &VariableDefinition->Guid,\r
+                                EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                                VariableDefinition->VariableSize,\r
+                                (VOID *) TmpNvRamMap,\r
+                                &gResetRequired\r
+                                );\r
+      } else {\r
+        Status = gRT->SetVariable (\r
+                        VariableDefinition->VariableName,\r
+                        &VariableDefinition->Guid,\r
+                        EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                        VariableDefinition->VariableSize,\r
+                        (VOID *) TmpNvRamMap\r
+                        );\r
+      }\r
+\r
+      FreePool (TmpNvRamMap);\r
+      FreePool (StringPtr);\r
+      break;\r
+    }\r
+\r
+  default:\r
+    break;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Split StringPtr to several lines of strings stored in FormattedString and the glyph width of\r
+  each line cannot exceed gHelpBlockWidth.\r
+\r
+  @param StringPtr          The pointer of string\r
+  @param FormattedString    The pointer of format string\r
+  @param RowCount           The count of row\r
+\r
+**/\r
+VOID\r
+ProcessHelpString (\r
+  IN  CHAR16  *StringPtr,\r
+  OUT CHAR16  **FormattedString,\r
+  IN  UINTN   RowCount\r
+  )\r
+{\r
+  CONST UINTN BlockWidth = (UINTN) gHelpBlockWidth - 1;\r
+  UINTN AllocateSize;\r
+  //\r
+  // [PrevCurrIndex, CurrIndex) forms a range of a screen-line\r
+  //\r
+  UINTN CurrIndex;\r
+  UINTN PrevCurrIndex;\r
+  UINTN LineCount;\r
+  UINTN VirtualLineCount;\r
+  //\r
+  // GlyphOffset stores glyph width of current screen-line\r
+  //\r
+  UINTN GlyphOffset;\r
+  //\r
+  // GlyphWidth equals to 2 if we meet width directive\r
+  //\r
+  UINTN GlyphWidth;\r
+  //\r
+  // during scanning, we remember the position of last space character\r
+  // in case that if next word cannot put in current line, we could restore back to the position\r
+  // of last space character\r
+  // while we should also remmeber the glyph width of the last space character for restoring\r
+  //\r
+  UINTN LastSpaceIndex;\r
+  UINTN LastSpaceGlyphWidth;\r
+  //\r
+  // every time we begin to form a new screen-line, we should remember glyph width of single character\r
+  // of last line\r
+  //\r
+  UINTN LineStartGlyphWidth;\r
+  UINTN *IndexArray;\r
+  UINTN *OldIndexArray;\r
+\r
+  //\r
+  // every three elements of IndexArray form a screen-line of string:[ IndexArray[i*3], IndexArray[i*3+1] )\r
+  // IndexArray[i*3+2] stores the initial glyph width of single character. to save this is because we want\r
+  // to bring the width directive of the last line to current screen-line.\r
+  // e.g.: "\wideabcde ... fghi", if "fghi" also has width directive but is splitted to the next screen-line\r
+  // different from that of "\wideabcde", we should remember the width directive.\r
+  //\r
+  AllocateSize  = 0x20;\r
+  IndexArray    = AllocatePool (AllocateSize * sizeof (UINTN) * 3);\r
+\r
+  if (*FormattedString != NULL) {\r
+    FreePool (*FormattedString);\r
+    *FormattedString = NULL;\r
+  }\r
+\r
+  for (PrevCurrIndex = 0, CurrIndex  = 0, LineCount   = 0, LastSpaceIndex = 0,\r
+       IndexArray[0] = 0, GlyphWidth = 1, GlyphOffset = 0, LastSpaceGlyphWidth = 1, LineStartGlyphWidth = 1;\r
+       (StringPtr[CurrIndex] != CHAR_NULL);\r
+       CurrIndex ++) {\r
+\r
+    if (LineCount == AllocateSize) {\r
+      AllocateSize   += 0x10;\r
+      OldIndexArray  =  IndexArray;\r
+      IndexArray     =  AllocatePool (AllocateSize * sizeof (UINTN) * 3);\r
+      CopyMem (IndexArray, OldIndexArray, LineCount * sizeof (UINTN) * 3);\r
+      if (OldIndexArray != NULL) {\r
+        FreePool (OldIndexArray);\r
+      }\r
+    }\r
+\r
+    switch (StringPtr[CurrIndex]) {\r
+\r
+      case NARROW_CHAR:\r
+      case WIDE_CHAR:\r
+        GlyphWidth = ((StringPtr[CurrIndex] == WIDE_CHAR) ? 2 : 1);\r
+        if (CurrIndex == 0) {\r
+          LineStartGlyphWidth = GlyphWidth;\r
+        }\r
+        break;\r
+\r
+      //\r
+      // char is '\n'\r
+      // "\r\n" isn't handled here, handled by case CHAR_CARRIAGE_RETURN\r
+      //\r
+      case CHAR_LINEFEED:\r
+        //\r
+        // Store a range of string as a line\r
+        //\r
+        IndexArray[LineCount*3]   = PrevCurrIndex;\r
+        IndexArray[LineCount*3+1] = CurrIndex;\r
+        IndexArray[LineCount*3+2] = LineStartGlyphWidth;\r
+        LineCount ++;\r
+        //\r
+        // Reset offset and save begin position of line\r
+        //\r
+        GlyphOffset = 0;\r
+        LineStartGlyphWidth = GlyphWidth;\r
+        PrevCurrIndex = CurrIndex + 1;\r
+        break;\r
+\r
+      //\r
+      // char is '\r'\r
+      // "\r\n" and "\r" both are handled here\r
+      //\r
+      case CHAR_CARRIAGE_RETURN:\r
+        if (StringPtr[CurrIndex + 1] == CHAR_LINEFEED) {\r
+          //\r
+          // next char is '\n'\r
+          //\r
+          IndexArray[LineCount*3]   = PrevCurrIndex;\r
+          IndexArray[LineCount*3+1] = CurrIndex;\r
+          IndexArray[LineCount*3+2] = LineStartGlyphWidth;\r
+          LineCount ++;\r
+          CurrIndex ++;\r
+        }\r
+        GlyphOffset = 0;\r
+        LineStartGlyphWidth = GlyphWidth;\r
+        PrevCurrIndex = CurrIndex + 1;\r
+        break;\r
+\r
+      //\r
+      // char is space or other char\r
+      //\r
+      default:\r
+        GlyphOffset     += GlyphWidth;\r
+        if (GlyphOffset >= BlockWidth) {\r
+          if (LastSpaceIndex > PrevCurrIndex) {\r
+            //\r
+            // LastSpaceIndex points to space inside current screen-line,\r
+            // restore to LastSpaceIndex\r
+            // (Otherwise the word is too long to fit one screen-line, just cut it)\r
+            //\r
+            CurrIndex  = LastSpaceIndex;\r
+            GlyphWidth = LastSpaceGlyphWidth;\r
+          } else if (GlyphOffset > BlockWidth) {\r
+            //\r
+            // the word is too long to fit one screen-line and we don't get the chance\r
+            // of GlyphOffset == BlockWidth because GlyphWidth = 2\r
+            //\r
+            CurrIndex --;\r
+          }\r
+\r
+          IndexArray[LineCount*3]   = PrevCurrIndex;\r
+          IndexArray[LineCount*3+1] = CurrIndex + 1;\r
+          IndexArray[LineCount*3+2] = LineStartGlyphWidth;\r
+          LineStartGlyphWidth = GlyphWidth;\r
+          LineCount ++;\r
+          //\r
+          // Reset offset and save begin position of line\r
+          //\r
+          GlyphOffset                 = 0;\r
+          PrevCurrIndex               = CurrIndex + 1;\r
+        }\r
+\r
+        //\r
+        // LastSpaceIndex: remember position of last space\r
+        //\r
+        if (StringPtr[CurrIndex] == CHAR_SPACE) {\r
+          LastSpaceIndex      = CurrIndex;\r
+          LastSpaceGlyphWidth = GlyphWidth;\r
+        }\r
+        break;\r
+    }\r
+  }\r
+\r
+  if (GlyphOffset > 0) {\r
+    IndexArray[LineCount*3]   = PrevCurrIndex;\r
+    IndexArray[LineCount*3+1] = CurrIndex;\r
+    IndexArray[LineCount*3+2] = GlyphWidth;\r
+    LineCount ++;\r
+  }\r
+\r
+  if (LineCount == 0) {\r
+    //\r
+    // in case we meet null string\r
+    //\r
+    IndexArray[0] = 0;\r
+    IndexArray[1] = 1;\r
+    //\r
+    // we assume null string's glyph width is 1\r
+    //\r
+    IndexArray[1] = 1;\r
+    LineCount ++;\r
+  }\r
+\r
+  VirtualLineCount = RowCount * (LineCount / RowCount + (LineCount % RowCount > 0));\r
+  *FormattedString = AllocateZeroPool (VirtualLineCount * (BlockWidth + 1) * sizeof (CHAR16) * 2);\r
+\r
+  for (CurrIndex = 0; CurrIndex < LineCount; CurrIndex ++) {\r
+    *(*FormattedString + CurrIndex * 2 * (BlockWidth + 1)) = (CHAR16)((IndexArray[CurrIndex*3+2] == 2) ? WIDE_CHAR : NARROW_CHAR);\r
+    StrnCpy (\r
+      *FormattedString + CurrIndex * 2 * (BlockWidth + 1) + 1,\r
+      StringPtr + IndexArray[CurrIndex*3],\r
+      IndexArray[CurrIndex*3+1]-IndexArray[CurrIndex*3]\r
+      );\r
+  }\r
+\r
+  if (IndexArray != NULL) {\r
+    FreePool (IndexArray);\r
+  }\r
+}\r
+\r
+VOID\r
+IfrToFormTag (\r
+  IN  UINT8               OpCode,\r
+  IN  EFI_TAG             *TargetTag,\r
+  IN  VOID                *FormData,\r
+  EFI_VARIABLE_DEFINITION *VariableDefinitionsHead\r
+  )\r
+{\r
+  UINT16                  TempValue;\r
+  CHAR16                  *VariableName;\r
+  CHAR8                   *AsciiString;\r
+  EFI_VARIABLE_DEFINITION *VariableDefinitions;\r
+  EFI_VARIABLE_DEFINITION *PreviousVariableDefinitions;\r
+  STATIC UINT16           VariableSize;\r
+  EFI_GUID                Guid;\r
+  STATIC UINT16           CurrentVariable;\r
+  STATIC UINT16           CurrentVariable2;\r
+  UINTN                   Index;\r
+\r
+  switch (OpCode) {\r
+  case EFI_IFR_FORM_OP:\r
+    CopyMem (&TargetTag->Id, &((EFI_IFR_FORM *) FormData)->FormId, sizeof (UINT16));\r
+    CopyMem (&TargetTag->Text, &((EFI_IFR_FORM *) FormData)->FormTitle, sizeof (UINT16));\r
+    TargetTag->VariableNumber = CurrentVariable;\r
+    if (VariableDefinitionsHead != NULL) {\r
+      VariableName = AllocateZeroPool (12);\r
+      ASSERT (VariableName != NULL);\r
+      CopyMem (VariableName, L"Setup", 12);\r
+      VariableDefinitionsHead->VariableName = VariableName;\r
+      VariableDefinitionsHead->VariableSize = VariableSize;\r
+      CopyMem (&VariableDefinitionsHead->Guid, &Guid, sizeof (EFI_GUID));\r
+    }\r
+    break;\r
+\r
+  case EFI_IFR_SUBTITLE_OP:\r
+    TargetTag->NumberOfLines = 1;\r
+    CopyMem (&TargetTag->Text, &((EFI_IFR_SUBTITLE *) FormData)->SubTitle, sizeof (UINT16));\r
+    TargetTag->VariableNumber = CurrentVariable;\r
+    break;\r
+\r
+  case EFI_IFR_TEXT_OP:\r
+    TargetTag->NumberOfLines = 1;\r
+    CopyMem (&TargetTag->Text, &((EFI_IFR_TEXT *) FormData)->Text, sizeof (UINT16));\r
+    CopyMem (&TargetTag->Help, &((EFI_IFR_TEXT *) FormData)->Help, sizeof (UINT16));\r
+    TargetTag->VariableNumber = CurrentVariable;\r
+\r
+    //\r
+    // To optimize the encoding size, certain opcodes have optional fields such as those\r
+    // inside the if() statement.  If the encoded length is the complete size, then we\r
+    // know we have valid data encoded that we want to integrate\r
+    //\r
+    if (((EFI_IFR_TEXT *) FormData)->Header.Length == sizeof (EFI_IFR_TEXT)) {\r
+      //\r
+      // Text has no help associated with it, but in case there is a second entry due to\r
+      // dynamic/interactive flags being active, bring this data over.\r
+      //\r
+      CopyMem (&TargetTag->TextTwo, &((EFI_IFR_TEXT *) FormData)->TextTwo, sizeof (UINT16));\r
+      TargetTag->Flags = ((EFI_IFR_TEXT *) FormData)->Flags;\r
+      CopyMem (&TargetTag->Key, &((EFI_IFR_TEXT *) FormData)->Key, sizeof (UINT16));\r
+    }\r
+    break;\r
+\r
+  case EFI_IFR_ONE_OF_OPTION_OP:\r
+    CopyMem (&TargetTag->Text, &((EFI_IFR_ONE_OF_OPTION *) FormData)->Option, sizeof (UINT16));\r
+    CopyMem (&TargetTag->Value, &((EFI_IFR_ONE_OF_OPTION *) FormData)->Value, sizeof (UINT16));\r
+    TargetTag->Flags = ((EFI_IFR_ONE_OF_OPTION *) FormData)->Flags;\r
+    CopyMem (&TargetTag->Key, &((EFI_IFR_ONE_OF_OPTION *) FormData)->Key, sizeof (UINT16));\r
+    TargetTag->VariableNumber = CurrentVariable;\r
+    break;\r
+\r
+  case EFI_IFR_CHECKBOX_OP:\r
+    TargetTag->Flags          = ((EFI_IFR_CHECKBOX *) FormData)->Flags;\r
+    TargetTag->ResetRequired  = (BOOLEAN) (TargetTag->Flags & EFI_IFR_FLAG_RESET_REQUIRED);\r
+    CopyMem (&TargetTag->Key, &((EFI_IFR_CHECKBOX *) FormData)->Key, sizeof (UINT16));\r
+    TargetTag->VariableNumber = CurrentVariable;\r
+    break;\r
+\r
+  case EFI_IFR_NUMERIC_OP:\r
+    TargetTag->Flags = ((EFI_IFR_NUMERIC *) FormData)->Flags;\r
+    CopyMem (&TargetTag->Key, &((EFI_IFR_NUMERIC *) FormData)->Key, sizeof (UINT16));\r
+    TargetTag->VariableNumber = CurrentVariable;\r
+    break;\r
+\r
+  case EFI_IFR_STRING_OP:\r
+    //\r
+    // Convert EFI_IFR_STRING.MinSize and EFI_IFR_STRING.MaxSize to actual minimum and maximum bytes\r
+    // and store to EFI_TAG.Minimum and EFI_TAG.Maximum\r
+    //\r
+    TempValue = 0;\r
+    CopyMem (&TempValue, &((EFI_IFR_STRING *) FormData)->MinSize, sizeof (UINT8));\r
+    TempValue = (UINT16) (TempValue * 2);\r
+    CopyMem (&TargetTag->Minimum, &TempValue, sizeof (UINT16));\r
+\r
+    TempValue = 0;\r
+    CopyMem (&TempValue, &((EFI_IFR_STRING *) FormData)->MaxSize, sizeof (UINT8));\r
+    TempValue = (UINT16) (TempValue * 2);\r
+    CopyMem (&TargetTag->Maximum, &TempValue, sizeof (UINT16));\r
+    CopyMem (&TargetTag->StorageWidth, &TempValue, sizeof (UINT16));\r
+    TargetTag->Flags          = (UINT8) (((EFI_IFR_STRING *) FormData)->Flags);\r
+    TargetTag->ResetRequired  = (BOOLEAN) (TargetTag->Flags & EFI_IFR_FLAG_RESET_REQUIRED);\r
+    CopyMem (&TargetTag->Key, &((EFI_IFR_STRING *) FormData)->Key, sizeof (UINT16));\r
+    TargetTag->VariableNumber = CurrentVariable;\r
+    break;\r
+\r
+  case EFI_IFR_PASSWORD_OP:\r
+    TempValue = 0;\r
+    CopyMem (&TempValue, &((EFI_IFR_PASSWORD *) FormData)->MinSize, sizeof (UINT8));\r
+    TempValue = (UINT16) (TempValue * 2);\r
+    CopyMem (&TargetTag->Minimum, &TempValue, sizeof (UINT16));\r
+\r
+    TempValue = 0;\r
+    CopyMem (&TempValue, &((EFI_IFR_PASSWORD *) FormData)->MaxSize, sizeof (UINT8));\r
+    TempValue = (UINT16) (TempValue * 2);\r
+    CopyMem (&TargetTag->Maximum, &TempValue, sizeof (UINT16));\r
+    CopyMem (&TargetTag->StorageWidth, &TempValue, sizeof (UINT16));\r
+    TargetTag->Flags          = ((EFI_IFR_PASSWORD *) FormData)->Flags;\r
+    TargetTag->ResetRequired  = (BOOLEAN) (TargetTag->Flags & EFI_IFR_FLAG_RESET_REQUIRED);\r
+    CopyMem (&TargetTag->Key, &((EFI_IFR_PASSWORD *) FormData)->Key, sizeof (UINT16));\r
+    CopyMem (&TargetTag->Encoding, &((EFI_IFR_PASSWORD *) FormData)->Encoding, sizeof (UINT16));\r
+    TargetTag->VariableNumber = CurrentVariable;\r
+    break;\r
+\r
+  case EFI_IFR_VARSTORE_OP:\r
+    //\r
+    // It should NEVER be NULL\r
+    //\r
+    if (VariableDefinitionsHead == NULL) {\r
+      break;\r
+    }\r
+\r
+    VariableDefinitions = VariableDefinitionsHead;\r
+\r
+    //\r
+    // Advance VariableDefinitions to the last entry\r
+    //\r
+    for (; VariableDefinitions != NULL; VariableDefinitions = VariableDefinitions->Next) {\r
+      PreviousVariableDefinitions = VariableDefinitions;\r
+      //\r
+      // If there is a variable with this GUID and ID already, we need to bail out\r
+      //\r
+      if (!CompareMem (&VariableDefinitions->Guid, &((EFI_IFR_VARSTORE *) FormData)->Guid, sizeof (EFI_GUID)) &&\r
+          !CompareMem (&VariableDefinitions->VariableId, &((EFI_IFR_VARSTORE *) FormData)->VarId, sizeof (UINT16))\r
+            ) {\r
+        return ;\r
+      }\r
+\r
+      if (VariableDefinitions->Next == NULL) {\r
+        break;\r
+      }\r
+    }\r
+    //\r
+    // If the last entry has a variable in it already, allocate a new entry and use it\r
+    //\r
+    if (VariableDefinitions->VariableName != NULL) {\r
+      VariableDefinitions->Next = AllocateZeroPool (sizeof (EFI_VARIABLE_DEFINITION));\r
+      ASSERT (VariableDefinitions->Next != NULL);\r
+      PreviousVariableDefinitions   = VariableDefinitions;\r
+      VariableDefinitions           = VariableDefinitions->Next;\r
+      VariableDefinitions->Previous = PreviousVariableDefinitions;\r
+    }\r
+    //\r
+    // Copy the Variable data to our linked list\r
+    //\r
+    CopyMem (&VariableDefinitions->VariableId, &((EFI_IFR_VARSTORE *) FormData)->VarId, sizeof (UINT16));\r
+    CopyMem (&VariableDefinitions->VariableSize, &((EFI_IFR_VARSTORE *) FormData)->Size, sizeof (UINT16));\r
+    CopyMem (&VariableDefinitions->Guid, &((EFI_IFR_VARSTORE *) FormData)->Guid, sizeof (EFI_GUID));\r
+\r
+    //\r
+    // The ASCII String which is immediately past the EFI_IFR_VARSTORE is inferred by the structure definition\r
+    // due to it being variable sized.  There are rules preventing it from being > 40 characters long and should\r
+    // be enforced by the compiler.\r
+    //\r
+    AsciiString                       = (CHAR8 *) (&((EFI_IFR_VARSTORE *) FormData)->Size);\r
+    AsciiString                       = AsciiString + 2;\r
+    VariableDefinitions->VariableName = AllocateZeroPool ((AsciiStrLen (AsciiString) + 1) * 2);\r
+    ASSERT (VariableDefinitions->VariableName != NULL);\r
+    for (Index = 0; AsciiString[Index] != 0; Index++) {\r
+      VariableDefinitions->VariableName[Index] = (CHAR16) AsciiString[Index];\r
+    }\r
+\r
+    VariableDefinitions->VariableName[Index] = 0;\r
+\r
+    //\r
+    // Propogate the tag information for this op-code\r
+    //\r
+    CopyMem (&TargetTag->VariableNumber, &((EFI_IFR_VARSTORE *) FormData)->VarId, sizeof (UINT16));\r
+    CopyMem (&TargetTag->GuidValue, &((EFI_IFR_VARSTORE *) FormData)->Guid, sizeof (EFI_GUID));\r
+    CopyMem (&TargetTag->StorageWidth, &((EFI_IFR_VARSTORE *) FormData)->Size, sizeof (UINT16));\r
+    CopyMem (&TargetTag->Maximum, &((EFI_IFR_VARSTORE *) FormData)->Size, sizeof (UINT16));\r
+    break;\r
+\r
+  case EFI_IFR_VARSTORE_SELECT_OP:\r
+    CopyMem (&TargetTag->VariableNumber, &((EFI_IFR_VARSTORE_SELECT *) FormData)->VarId, sizeof (UINT16));\r
+    CopyMem (&CurrentVariable, &((EFI_IFR_VARSTORE_SELECT *) FormData)->VarId, sizeof (UINT16));\r
+    CurrentVariable2 = CurrentVariable;\r
+    break;\r
+\r
+  case EFI_IFR_VARSTORE_SELECT_PAIR_OP:\r
+    CopyMem (&TargetTag->VariableNumber, &((EFI_IFR_VARSTORE_SELECT_PAIR *) FormData)->VarId, sizeof (UINT16));\r
+    CopyMem (\r
+      &TargetTag->VariableNumber2,\r
+      &((EFI_IFR_VARSTORE_SELECT_PAIR *) FormData)->SecondaryVarId,\r
+      sizeof (UINT16)\r
+      );\r
+    CopyMem (&CurrentVariable, &((EFI_IFR_VARSTORE_SELECT_PAIR *) FormData)->VarId, sizeof (UINT16));\r
+    CopyMem (&CurrentVariable2, &((EFI_IFR_VARSTORE_SELECT_PAIR *) FormData)->SecondaryVarId, sizeof (UINT16));\r
+    break;\r
+\r
+  case EFI_IFR_REF_OP:\r
+    TargetTag->NumberOfLines = 1;\r
+    CopyMem (&TargetTag->Id, &((EFI_IFR_REF *) FormData)->FormId, sizeof (UINT16));\r
+    CopyMem (&TargetTag->Key, &((EFI_IFR_REF *) FormData)->Key, sizeof (UINT16));\r
+    CopyMem (&TargetTag->Text, &((EFI_IFR_REF *) FormData)->Prompt, sizeof (UINT16));\r
+    CopyMem (&TargetTag->Help, &((EFI_IFR_REF *) FormData)->Help, sizeof (UINT16));\r
+    TargetTag->Flags          = ((EFI_IFR_REF *) FormData)->Flags;\r
+    TargetTag->VariableNumber = CurrentVariable;\r
+    break;\r
+\r
+  case EFI_IFR_EQ_ID_VAL_OP:\r
+    CopyMem (&TargetTag->Value, &((EFI_IFR_EQ_ID_VAL *) FormData)->Value, sizeof (UINT16));\r
+    CopyMem (&TargetTag->Id, &((EFI_IFR_EQ_ID_VAL *) FormData)->QuestionId, sizeof (UINT16));\r
+    TargetTag->StorageWidth   = ((EFI_IFR_EQ_ID_VAL *) FormData)->Width;\r
+    TargetTag->VariableNumber = CurrentVariable;\r
+    break;\r
+\r
+  case EFI_IFR_EQ_VAR_VAL_OP:\r
+    CopyMem (&TargetTag->Value, &((EFI_IFR_EQ_VAR_VAL *) FormData)->Value, sizeof (UINT16));\r
+    CopyMem (&TargetTag->Id, &((EFI_IFR_EQ_VAR_VAL *) FormData)->VariableId, sizeof (UINT16));\r
+    TargetTag->VariableNumber = CurrentVariable;\r
+    break;\r
+\r
+  case EFI_IFR_EQ_ID_ID_OP:\r
+    CopyMem (&TargetTag->Id, &((EFI_IFR_EQ_ID_ID *) FormData)->QuestionId1, sizeof (UINT16));\r
+    CopyMem (&TargetTag->Id2, &((EFI_IFR_EQ_ID_ID *) FormData)->QuestionId2, sizeof (UINT16));\r
+    TargetTag->StorageWidth   = ((EFI_IFR_EQ_ID_ID *) FormData)->Width;\r
+    TargetTag->VariableNumber = CurrentVariable;\r
+    TargetTag->VariableNumber = CurrentVariable2;\r
+    break;\r
+\r
+  case EFI_IFR_EQ_ID_LIST_OP:\r
+    CopyMem (&TargetTag->Id, &((EFI_IFR_EQ_ID_LIST *) FormData)->QuestionId, sizeof (UINT16));\r
+    CopyMem (&TargetTag->Id2, &((EFI_IFR_EQ_ID_LIST *) FormData)->ListLength, sizeof (UINT16));\r
+    TargetTag->StorageWidth = ((EFI_IFR_EQ_ID_LIST *) FormData)->Width;\r
+\r
+    TargetTag->IntList      = AllocateZeroPool (TargetTag->Id2 * sizeof (UINT16));\r
+    ASSERT (TargetTag->IntList);\r
+\r
+    for (TempValue = 0; TempValue < TargetTag->Id2; TempValue++) {\r
+      CopyMem (\r
+        &TargetTag->IntList[TempValue],\r
+        &((EFI_IFR_EQ_ID_LIST *) FormData)->ValueList[TempValue],\r
+        sizeof (UINT16)\r
+        );\r
+    }\r
+\r
+    TargetTag->VariableNumber = CurrentVariable;\r
+    break;\r
+\r
+  case EFI_IFR_FORM_SET_OP:\r
+    CopyMem (&VariableSize, &((EFI_IFR_FORM_SET *) FormData)->NvDataSize, sizeof (UINT16));\r
+    CopyMem (&Guid, &((EFI_IFR_FORM_SET *) FormData)->Guid, sizeof (EFI_GUID));\r
+    //\r
+    // If there is a size specified in the formste, we will establish a "default" variable\r
+    //\r
+    if (VariableDefinitionsHead != NULL) {\r
+      VariableName = AllocateZeroPool (12);\r
+      ASSERT (VariableName != NULL);\r
+      CopyMem (VariableName, L"Setup", 12);\r
+      VariableDefinitionsHead->VariableName = VariableName;\r
+      VariableDefinitionsHead->VariableSize = VariableSize;\r
+      CopyMem (&VariableDefinitionsHead->Guid, &Guid, sizeof (EFI_GUID));\r
+    }\r
+    break;\r
+\r
+  case EFI_IFR_END_FORM_SET_OP:\r
+    CurrentVariable   = 0;\r
+    CurrentVariable2  = 0;\r
+    break;\r
+  }\r
+\r
+  return ;\r
+}\r
diff --git a/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Setup.c b/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Setup.c
new file mode 100644 (file)
index 0000000..58698c8
--- /dev/null
@@ -0,0 +1,2224 @@
+/**@file\r
+  Entry and initialization module for the browser.\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 "Setup.h"\r
+#include "Ui.h"\r
+\r
+FUNCTIION_KEY_SETTING gFunctionKeySettingTable[] = {\r
+  //\r
+  // Boot Manager\r
+  //\r
+  {\r
+    {\r
+      0x847bc3fe,\r
+      0xb974,\r
+      0x446d,\r
+      {\r
+        0x94,\r
+        0x49,\r
+        0x5a,\r
+        0xd5,\r
+        0x41,\r
+        0x2e,\r
+        0x99,\r
+        0x3b\r
+      }\r
+    },\r
+    NONE_FUNCTION_KEY_SETTING\r
+  },\r
+  //\r
+  // Device Manager\r
+  //\r
+  {\r
+    {\r
+      0x3ebfa8e6,\r
+      0x511d,\r
+      0x4b5b,\r
+      {\r
+        0xa9,\r
+        0x5f,\r
+        0xfb,\r
+        0x38,\r
+        0x26,\r
+        0xf,\r
+        0x1c,\r
+        0x27\r
+      }\r
+    },\r
+    NONE_FUNCTION_KEY_SETTING\r
+  },\r
+  //\r
+  // BMM Formset.\r
+  //\r
+  {\r
+    {\r
+      0x642237c7,\r
+      0x35d4,\r
+      0x472d,\r
+      {\r
+        0x83,\r
+        0x65,\r
+        0x12,\r
+        0xe0,\r
+        0xcc,\r
+        0xf2,\r
+        0x7a,\r
+        0x22\r
+      }\r
+    },\r
+    NONE_FUNCTION_KEY_SETTING\r
+  },\r
+  //\r
+  // BMM File Explorer Formset.\r
+  //\r
+  {\r
+    {\r
+      0x1f2d63e1,\r
+      0xfebd,\r
+      0x4dc7,\r
+      {\r
+        0x9c,\r
+        0xc5,\r
+        0xba,\r
+        0x2b,\r
+        0x1c,\r
+        0xef,\r
+        0x9c,\r
+        0x5b\r
+      }\r
+    },\r
+    NONE_FUNCTION_KEY_SETTING\r
+  },\r
+};\r
+\r
+STATIC\r
+EFI_STATUS\r
+InitializeBinaryStructures (\r
+  IN  EFI_HII_HANDLE                           *Handle,\r
+  IN  BOOLEAN                                  UseDatabase,\r
+  IN  EFI_IFR_PACKET                           *Packet,\r
+  IN  UINT8                                    *NvMapOverride,\r
+  IN  UINTN                                    NumberOfIfrImages,\r
+  EFI_FILE_FORM_TAGS                           **FileFormTagsHead\r
+  );\r
+\r
+STATIC\r
+EFI_STATUS\r
+InitializeTagStructures (\r
+  IN  EFI_IFR_BINARY                            *BinaryData,\r
+  OUT EFI_FILE_FORM_TAGS                        *FileFormTags\r
+  );\r
+\r
+STATIC\r
+UI_MENU_OPTION        *\r
+DisplayHomePage (\r
+  IN UINTN                                    NumberOfIfrImages,\r
+  IN EFI_FILE_FORM_TAGS                       *FileFormTagsHead,\r
+  IN UINT8                                    *CallbackData\r
+  );\r
+\r
+STATIC\r
+EFI_STATUS\r
+GetIfrBinaryData (\r
+  IN EFI_HII_PROTOCOL *Hii,\r
+  IN EFI_HII_HANDLE   HiiHandle,\r
+  IN EFI_IFR_PACKET   *Packet,\r
+  IN EFI_IFR_BINARY   *BinaryData\r
+  );\r
+\r
+STATIC\r
+EFI_STATUS\r
+InstallPrint (\r
+  VOID\r
+  );\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+SendForm (\r
+  IN EFI_FORM_BROWSER_PROTOCOL        * This,\r
+  IN BOOLEAN                          UseDatabase,\r
+  IN EFI_HII_HANDLE                   * Handle,\r
+  IN UINTN                            HandleCount,\r
+  IN EFI_IFR_PACKET                   * Packet,\r
+  IN EFI_HANDLE                       CallbackHandle,\r
+  IN UINT8                            *NvMapOverride,\r
+  IN EFI_SCREEN_DESCRIPTOR            *ScreenDimensions, OPTIONAL\r
+  OUT BOOLEAN                         *ResetRequired OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This is the routine which an external caller uses to direct the browser\r
+  where to obtain it's information.\r
+\r
+Arguments:\r
+\r
+  UseDatabase -     If set to TRUE, then all information is retrieved from the HII database handle specified\r
+                    If set to FALSE, then the passed in Packet and CallbackHandle is used and Handle is ignored\r
+\r
+  Handle -          A pointer to an array of Handles.  If HandleCount > 1 we display a list of the formsets for the handles specified\r
+\r
+  HandleCount -     The number of Handles specified in Handle.\r
+\r
+  Packet -          Valid only if UseDatabase is FALSE.  Packet defines the pages being passed into\r
+                    the browser.  This is composed of IFR data as well as String information.\r
+\r
+  CallbackHandle -  The handle which contains the calling driver's EFI_FORM_CALLBACK_PROTOCOL interface.\r
+\r
+  ScreenDimenions - This allows the browser to be called so that it occupies a portion of the physical screen instead of\r
+                    dynamically determining the screen dimensions.\r
+\r
+  NvMapOverride -   This buffer is used only when there is no NV variable to define the current settings and the caller\r
+                    needs to provide to the browser the current settings for the "fake" NV variable.  If used, no saving\r
+                    of an NV variable will be possible.  This parameter is also ignored if HandleCount > 1.\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  EFI_FORM_CALLBACK_PROTOCOL  *FormCallback;\r
+  EFI_FILE_FORM_TAGS          *FileFormTagsHead;\r
+  UI_MENU_OPTION              *Selection;\r
+  UI_MENU_OPTION              *AltSelection;\r
+  EFI_STATUS                  Status;\r
+  BOOLEAN                     Callback;\r
+  VOID                        *CallbackData;\r
+  EFI_HII_HANDLE              BackupHandle;\r
+\r
+  ZeroMem (&gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));\r
+\r
+  gPreviousValue  = AllocatePool (0x1000);\r
+  CallbackData    = AllocatePool (0x10000);\r
+  ASSERT (gPreviousValue != NULL);\r
+  ASSERT (CallbackData != NULL);\r
+\r
+  do {\r
+    //\r
+    // Seed the dimensions in the global\r
+    //\r
+    gST->ConOut->QueryMode (\r
+                  gST->ConOut,\r
+                  gST->ConOut->Mode->Mode,\r
+                  &gScreenDimensions.RightColumn,\r
+                  &gScreenDimensions.BottomRow\r
+                  );\r
+\r
+    if (ScreenDimensions != NULL) {\r
+      //\r
+      // Check local dimension vs. global dimension.\r
+      //\r
+      if ((gScreenDimensions.RightColumn < ScreenDimensions->RightColumn) ||\r
+          (gScreenDimensions.BottomRow < ScreenDimensions->BottomRow)\r
+          ) {\r
+        return EFI_INVALID_PARAMETER;\r
+      } else {\r
+        //\r
+        // Local dimension validation.\r
+        //\r
+        if ((ScreenDimensions->RightColumn > ScreenDimensions->LeftColumn) &&\r
+            (ScreenDimensions->BottomRow > ScreenDimensions->TopRow) &&\r
+            ((ScreenDimensions->RightColumn - ScreenDimensions->LeftColumn) > 2) &&\r
+            (\r
+              (ScreenDimensions->BottomRow - ScreenDimensions->TopRow) > STATUS_BAR_HEIGHT +\r
+            SCROLL_ARROW_HEIGHT *\r
+            2 +\r
+            FRONT_PAGE_HEADER_HEIGHT +\r
+            FOOTER_HEIGHT +\r
+            1\r
+          )\r
+            ) {\r
+          CopyMem (&gScreenDimensions, ScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));\r
+        } else {\r
+          return EFI_INVALID_PARAMETER;\r
+        }\r
+      }\r
+    }\r
+\r
+    gOptionBlockWidth = (CHAR16) ((gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn) / 3);\r
+    gHelpBlockWidth   = gOptionBlockWidth;\r
+    gPromptBlockWidth = gOptionBlockWidth;\r
+\r
+    //\r
+    // Initialize the strings for the browser, upon exit of the browser, the strings will be freed\r
+    //\r
+    InitializeBrowserStrings ();\r
+\r
+    gFunctionKeySetting = DEFAULT_FUNCTION_KEY_SETTING;\r
+    gClassOfVfr         = EFI_SETUP_APPLICATION_SUBCLASS;\r
+    gResetRequired      = FALSE;\r
+    gExitRequired       = FALSE;\r
+    gSaveRequired       = FALSE;\r
+    gNvUpdateRequired   = FALSE;\r
+    gActiveIfr          = 0;\r
+    gConsistencyId      = 0;\r
+    gPriorMenuEntry     = 0;\r
+    BackupHandle        = *Handle;\r
+    gMenuRefreshHead    = NULL;\r
+    ASSERT (CallbackData);\r
+    ZeroMem (CallbackData, 0x10000);\r
+\r
+    //\r
+    // We can recurse through this and might need to re-allocate this particular buffer\r
+    //\r
+    if (gPreviousValue == NULL) {\r
+      gPreviousValue = AllocatePool (0x1000);\r
+      ASSERT (gPreviousValue != NULL);\r
+    }\r
+\r
+    Callback      = FALSE;\r
+    FormCallback  = NULL;\r
+\r
+    if (CallbackHandle != NULL) {\r
+      //\r
+      // Retrieve the Callback protocol interface\r
+      //\r
+      Status = gBS->HandleProtocol (\r
+                      CallbackHandle,\r
+                      &gEfiFormCallbackProtocolGuid,\r
+                      (VOID **) &FormCallback\r
+                      );\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        FreePool (CallbackData);\r
+        return Status;;\r
+      }\r
+\r
+      Callback = TRUE;\r
+    }\r
+    //\r
+    // Initializes all the internal state structures for all IFR images in system\r
+    //\r
+    Status = InitializeBinaryStructures (Handle, UseDatabase, Packet, NvMapOverride, HandleCount, &FileFormTagsHead);\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      FreePool (CallbackData);\r
+      return Status;\r
+    }\r
+    //\r
+    // Beginning of the Presentation of the Data\r
+    //\r
+    if (UseDatabase && (HandleCount > 1)) {\r
+      Selection = DisplayHomePage (HandleCount, FileFormTagsHead, CallbackData);\r
+    } else {\r
+      //\r
+      // If passing something specific, we know there is only one Ifr\r
+      //\r
+      Selection = AllocateZeroPool (sizeof (UI_MENU_OPTION));\r
+      ASSERT (Selection != NULL);\r
+      Selection->IfrNumber  = 0;\r
+      Selection->Handle     = Handle[0];\r
+      UiInitMenu ();\r
+    }\r
+\r
+    UiInitMenuList ();\r
+\r
+    if (UseDatabase && (HandleCount > 1)) {\r
+      if (Selection == NULL) {\r
+        FreePool (CallbackData);\r
+        return EFI_SUCCESS;\r
+      }\r
+    }\r
+    //\r
+    // Launch the setup browser with the user's selection information\r
+    //\r
+    AltSelection = SetupBrowser (Selection, Callback, FileFormTagsHead, CallbackData);\r
+\r
+    //\r
+    // If the caller cares about Reset status, we can return to the caller if something happened that required a reset\r
+    //\r
+    if (ResetRequired != NULL) {\r
+      *ResetRequired = gResetRequired;\r
+    }\r
+\r
+    if (Callback && (AltSelection != NULL)) {\r
+      if ((FormCallback != NULL) && (FormCallback->Callback != NULL)) {\r
+        Status = FormCallback->Callback (\r
+                                FormCallback,\r
+                                AltSelection->ThisTag->Key,\r
+                                CallbackData,\r
+                                (EFI_HII_CALLBACK_PACKET **) &Packet\r
+                                );\r
+      }\r
+    }\r
+\r
+    *Handle = BackupHandle;\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      FreePool (CallbackData);\r
+      return Status;\r
+    }\r
+\r
+    if (Callback && (AltSelection == NULL)) {\r
+      FreePool (CallbackData);\r
+      return Status;\r
+    }\r
+\r
+    if (UseDatabase && (HandleCount > 1)) {\r
+    } else {\r
+\r
+      if (gBinaryDataHead->UnRegisterOnExit) {\r
+        Hii->RemovePack (Hii, Handle[0]);\r
+      }\r
+\r
+      if (Callback &&\r
+        ((AltSelection->ThisTag->SubClass == EFI_FRONT_PAGE_SUBCLASS) ||\r
+        (AltSelection->ThisTag->SubClass == EFI_SINGLE_USE_SUBCLASS))) {\r
+        //\r
+        // If this is the FrontPage, return after every selection\r
+        //\r
+        FreePool (Selection);\r
+        UiFreeMenu ();\r
+\r
+        //\r
+        // Clean up the allocated data buffers\r
+        //\r
+        FreeData (FileFormTagsHead, NULL, NULL);\r
+\r
+        gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
+        gST->ConOut->ClearScreen (gST->ConOut);\r
+\r
+        FreePool (CallbackData);\r
+        return EFI_SUCCESS;\r
+      }\r
+\r
+      FreePool (Selection);\r
+      UiFreeMenu ();\r
+\r
+      //\r
+      // Clean up the allocated data buffers\r
+      //\r
+      FreeData (FileFormTagsHead, NULL, NULL);\r
+\r
+      gST->ConOut->ClearScreen (gST->ConOut);\r
+\r
+      if (!Callback) {\r
+        FreePool (CallbackData);\r
+        return EFI_SUCCESS;\r
+      }\r
+    }\r
+\r
+  } while (!EFI_ERROR (Status));\r
+\r
+  FreePool (CallbackData);\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeSetup (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Initialize Setup\r
+\r
+Arguments:\r
+  (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r
+\r
+Returns:\r
+  EFI_SUCCESS - Setup loaded.\r
+  other       - Setup Error\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_FORM_CONFIGURATION_DATA *FormData;\r
+  EFI_FORM_BROWSER_PROTOCOL   *FormBrowser;\r
+  EFI_HANDLE                  Handle;\r
+  EFI_HII_PACKAGES            *PackageList;\r
+\r
+  //\r
+  // There will be only one FormConfig in the system\r
+  // If there is another out there, someone is trying to install us\r
+  // again.  Fail that scenario.\r
+  //\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiFormBrowserProtocolGuid,\r
+                  NULL,\r
+                  (VOID **) &FormBrowser\r
+                  );\r
+\r
+  gFirstIn = TRUE;\r
+\r
+  //\r
+  // If there was no error, assume there is an installation and fail to load\r
+  //\r
+  if (!EFI_ERROR (Status)) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  FormData = AllocatePool (sizeof (EFI_FORM_CONFIGURATION_DATA));\r
+\r
+  if (FormData == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  //\r
+  // Fill in HII data\r
+  //\r
+  FormData->Signature               = EFI_FORM_DATA_SIGNATURE;\r
+  FormData->FormConfig.SendForm     = SendForm;\r
+  FormData->FormConfig.CreatePopUp  = CreateDialog;\r
+\r
+  //\r
+  // There should only be one HII image\r
+  //\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiHiiProtocolGuid,\r
+                  NULL,\r
+                  (VOID **) &FormData->Hii\r
+                  );\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Hii         = FormData->Hii;\r
+\r
+  PackageList = PreparePackages (1, &gEfiFormBrowserProtocolGuid, SetupBrowserStrings);\r
+\r
+  Status      = Hii->NewPack (Hii, PackageList, &gHiiHandle);\r
+\r
+  FreePool (PackageList);\r
+\r
+  //\r
+  // Install protocol interface\r
+  //\r
+  Handle = NULL;\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &Handle,\r
+                  &gEfiFormBrowserProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &FormData->FormConfig\r
+                  );\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  BannerData = AllocateZeroPool (sizeof (BANNER_DATA));\r
+  ASSERT (BannerData != NULL);\r
+\r
+  Status = InstallPrint ();\r
+  return Status;\r
+}\r
+\r
+VOID\r
+GetQuestionHeader (\r
+  IN  EFI_TAG             *Tag,\r
+  IN  UINT8               *RawFormSet,\r
+  IN  UINT16              Index,\r
+  IN  EFI_FILE_FORM_TAGS  *FileFormTags,\r
+  IN  UINT16              CurrentVariable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Initialize question tag's members.\r
+\r
+Arguments:\r
+  Tag              - Pointer of the current EFI_TAG structure.\r
+  RawFormSet       - Pointer of the formset raw data.\r
+  Index            - Offset of the current opcode in the Ifr raw data.\r
+  FileFormTags     - Pointer of current EFI_FILE_FORM_TAGS structure.\r
+  CurrentVariable  - Current variable number.\r
+\r
+Returns:\r
+  None.\r
+--*/\r
+{\r
+  EFI_VARIABLE_DEFINITION *VariableDefinition;\r
+\r
+  Tag->NumberOfLines  = 1;\r
+  Tag->VariableNumber = CurrentVariable;\r
+  CopyMem (&Tag->Id, &((EFI_IFR_ONE_OF *) &RawFormSet[Index])->QuestionId, sizeof (UINT16));\r
+  CopyMem (&Tag->StorageStart, &((EFI_IFR_ONE_OF *) &RawFormSet[Index])->QuestionId, sizeof (UINT16));\r
+  CopyMem (&Tag->StorageWidth, &((EFI_IFR_ONE_OF *) &RawFormSet[Index])->Width, sizeof (UINT8));\r
+  CopyMem (&Tag->Text, &((EFI_IFR_ONE_OF *) &RawFormSet[Index])->Prompt, sizeof (UINT16));\r
+  CopyMem (&Tag->Help, &((EFI_IFR_ONE_OF *) &RawFormSet[Index])->Help, sizeof (UINT16));\r
+\r
+  VariableDefinition = FileFormTags->VariableDefinitions;\r
+\r
+  for (; VariableDefinition != NULL; VariableDefinition = VariableDefinition->Next) {\r
+    //\r
+    // Have we found the correct variable for the request?\r
+    //\r
+    if (CurrentVariable == VariableDefinition->VariableId) {\r
+      if (VariableDefinition->VariableSize < (UINTN) (Tag->StorageStart + Tag->StorageWidth)) {\r
+        VariableDefinition->VariableFakeSize = (UINT16) (VariableDefinition->VariableFakeSize + Tag->StorageWidth);\r
+      }\r
+\r
+      if (VariableDefinition->NvRamMap != NULL) {\r
+        //\r
+        // If it is an 8bit or 16bit width, then move it to Tag->Value, otherwise\r
+        // we will never be looking for the data in Tag->Value (e.g. strings, password, etc)\r
+        //\r
+        if (Tag->StorageWidth == (UINT16) 1) {\r
+          CopyMem (&Tag->Value, &VariableDefinition->NvRamMap[Tag->StorageStart], sizeof (UINT16));\r
+        }\r
+\r
+        if (Tag->StorageWidth == (UINT16) 2) {\r
+          Index = (UINT16)\r
+            (\r
+              VariableDefinition->NvRamMap[Tag->StorageStart] +\r
+              (VariableDefinition->NvRamMap[Tag->StorageStart + 1] * 0x100)\r
+            );\r
+          CopyMem (&Tag->Value, &Index, sizeof (UINT16));\r
+        }\r
+      } else {\r
+        Index = 0;\r
+        CopyMem (&Tag->Value, &Index, sizeof (UINT16));\r
+      }\r
+      break;\r
+    }\r
+  }\r
+}\r
+\r
+VOID\r
+GetNumericHeader (\r
+  IN  EFI_TAG             *Tag,\r
+  IN  UINT8               *RawFormSet,\r
+  IN  UINT16              Index,\r
+  IN  UINT16              NumberOfLines,\r
+  IN  EFI_FILE_FORM_TAGS  *FileFormTags,\r
+  IN  UINT16              CurrentVariable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Initialize numeric tag's members.\r
+\r
+Arguments:\r
+  Tag              - Pointer of the current EFI_TAG structure.\r
+  RawFormSet       - Pointer of the formset raw data.\r
+  Index            - Offset of the current opcode in the Ifr raw data.\r
+  NumberOfLines    - Number of lines this opcode occupied.\r
+  FileFormTags     - Pointer of current EFI_FILE_FORM_TAGS structure.\r
+  CurrentVariable  - Current variable number.\r
+\r
+Returns:\r
+  None.\r
+--*/\r
+{\r
+  EFI_VARIABLE_DEFINITION *VariableDefinition;\r
+\r
+  Tag->NumberOfLines  = NumberOfLines;\r
+  Tag->VariableNumber = CurrentVariable;\r
+  CopyMem (&Tag->Id, &((EFI_IFR_ONE_OF *) &RawFormSet[Index])->QuestionId, sizeof (UINT16));\r
+  CopyMem (&Tag->StorageStart, &((EFI_IFR_ONE_OF *) &RawFormSet[Index])->QuestionId, sizeof (UINT16));\r
+  CopyMem (&Tag->StorageWidth, &((EFI_IFR_ONE_OF *) &RawFormSet[Index])->Width, sizeof (UINT8));\r
+  CopyMem (&Tag->Text, &((EFI_IFR_ONE_OF *) &RawFormSet[Index])->Prompt, sizeof (UINT16));\r
+  CopyMem (&Tag->Help, &((EFI_IFR_ONE_OF *) &RawFormSet[Index])->Help, sizeof (UINT16));\r
+  CopyMem (&Tag->Minimum, &((EFI_IFR_NUMERIC *) &RawFormSet[Index])->Minimum, sizeof (UINT16));\r
+  CopyMem (&Tag->Maximum, &((EFI_IFR_NUMERIC *) &RawFormSet[Index])->Maximum, sizeof (UINT16));\r
+  CopyMem (&Tag->Step, &((EFI_IFR_NUMERIC *) &RawFormSet[Index])->Step, sizeof (UINT16));\r
+  CopyMem (&Tag->Default, &((EFI_IFR_NUMERIC *) &RawFormSet[Index])->Default, sizeof (UINT16));\r
+  Tag->ResetRequired  = (BOOLEAN) (((EFI_IFR_NUMERIC *) &RawFormSet[Index])->Flags & EFI_IFR_FLAG_RESET_REQUIRED);\r
+\r
+  VariableDefinition  = FileFormTags->VariableDefinitions;\r
+\r
+  for (; VariableDefinition != NULL; VariableDefinition = VariableDefinition->Next) {\r
+    //\r
+    // Have we found the correct variable for the request?\r
+    //\r
+    if (CurrentVariable == VariableDefinition->VariableId) {\r
+      if (VariableDefinition->VariableSize <= (UINTN) (Tag->StorageStart + Tag->StorageWidth)) {\r
+        if (Tag->StorageWidth == 0) {\r
+          VariableDefinition->VariableFakeSize = (UINT16) (VariableDefinition->VariableFakeSize + 2);\r
+        } else {\r
+          VariableDefinition->VariableFakeSize = (UINT16) (VariableDefinition->VariableFakeSize + Tag->StorageWidth);\r
+        }\r
+      }\r
+\r
+      if (VariableDefinition->NvRamMap != NULL) {\r
+        //\r
+        // If it is an 8bit or 16bit width, then move it to Tag->Value, otherwise\r
+        // we will never be looking for the data in Tag->Value (e.g. strings, password, etc)\r
+        //\r
+        if (Tag->StorageWidth == (UINT16) 1) {\r
+          CopyMem (&Tag->Value, &VariableDefinition->NvRamMap[Tag->StorageStart], sizeof (UINT16));\r
+        }\r
+\r
+        if (Tag->StorageWidth == (UINT16) 2) {\r
+          Index = (UINT16)\r
+            (\r
+              VariableDefinition->NvRamMap[Tag->StorageStart] +\r
+                (VariableDefinition->NvRamMap[Tag->StorageStart + 1] * 0x100)\r
+            );\r
+          CopyMem (&Tag->Value, &Index, sizeof (UINT16));\r
+        }\r
+      } else {\r
+        CopyMem (&Tag->Value, &Tag->Default, sizeof (UINT16));\r
+      }\r
+      break;\r
+    }\r
+  }\r
+}\r
+\r
+VOID\r
+GetTagCount (\r
+  IN      UINT8                                 *RawFormSet,\r
+  IN OUT  UINT16                                *NumberOfTags\r
+  )\r
+{\r
+  UINT16  Index;\r
+\r
+  //\r
+  // Assume on entry we are pointing to an OpCode - reasonably this should\r
+  // be a FormOp since the purpose is to count the tags in a particular Form.\r
+  //\r
+  for (Index = 0; RawFormSet[Index] != EFI_IFR_END_FORM_OP;) {\r
+    //\r
+    // If we encounter the end of a form set, bail out\r
+    //\r
+    if (RawFormSet[Index] == EFI_IFR_END_FORM_SET_OP) {\r
+      break;\r
+    }\r
+    //\r
+    // We treat date/time internally as three op-codes\r
+    //\r
+    if (RawFormSet[Index] == EFI_IFR_DATE_OP || RawFormSet[Index] == EFI_IFR_TIME_OP) {\r
+      *NumberOfTags = (UINT16) (*NumberOfTags + 3);\r
+    } else {\r
+      //\r
+      // Assume that we could have no more tags than op-codes\r
+      //\r
+      (*NumberOfTags)++;\r
+    }\r
+\r
+    Index = (UINT16) (Index + RawFormSet[Index + 1]);\r
+  }\r
+  //\r
+  // Increase the tag count by one so it is inclusive of the end_form_op\r
+  //\r
+  (*NumberOfTags)++;\r
+}\r
+\r
+STATIC\r
+VOID\r
+AddNextInconsistentTag (\r
+  IN OUT  EFI_INCONSISTENCY_DATA  **InconsistentTagsPtr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Initialize the next inconsistent tag data and add it to the inconsistent tag list.\r
+\r
+Arguments:\r
+ InconsistentTagsPtr   - Pointer of the inconsistent tag's pointer.\r
+\r
+Returns:\r
+  None.\r
+\r
+--*/\r
+{\r
+  EFI_INCONSISTENCY_DATA  *PreviousInconsistentTags;\r
+  EFI_INCONSISTENCY_DATA  *InconsistentTags;\r
+\r
+  InconsistentTags = *InconsistentTagsPtr;\r
+  //\r
+  // We just hit the end of an inconsistent expression.  Let's allocate the ->Next structure\r
+  //\r
+  InconsistentTags->Next = AllocatePool (sizeof (EFI_INCONSISTENCY_DATA));\r
+  ASSERT (InconsistentTags->Next != NULL);\r
+\r
+  //\r
+  // Preserve current Tag entry\r
+  //\r
+  PreviousInconsistentTags  = InconsistentTags;\r
+\r
+  InconsistentTags          = InconsistentTags->Next;\r
+\r
+  //\r
+  // This will zero on the entry including the ->Next so I don't have to do it\r
+  //\r
+  ZeroMem (InconsistentTags, sizeof (EFI_INCONSISTENCY_DATA));\r
+\r
+  //\r
+  // Point our Previous field to the previous entry\r
+  //\r
+  InconsistentTags->Previous  = PreviousInconsistentTags;\r
+\r
+  *InconsistentTagsPtr        = InconsistentTags;\r
+\r
+  return ;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+InitializeTagStructures (\r
+  IN  EFI_IFR_BINARY                            *BinaryData,\r
+  OUT EFI_FILE_FORM_TAGS                        *FileFormTags\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  UINT8                   *RawFormSet;\r
+  UINT16                  Index;\r
+  UINT16                  QuestionIndex;\r
+  UINT16                  NumberOfTags;\r
+  INT16                   CurrTag;\r
+  UINT8                   TagLength;\r
+  EFI_FORM_TAGS           *FormTags;\r
+  EFI_FORM_TAGS           *SavedFormTags;\r
+  EFI_INCONSISTENCY_DATA  *InconsistentTags;\r
+  EFI_VARIABLE_DEFINITION *VariableDefinitions;\r
+  UINTN                   Count;\r
+  UINT16                  Class;\r
+  UINT16                  SubClass;\r
+  UINT16                  TempValue;\r
+  UINT16                  CurrentVariable;\r
+  UINT16                  CurrentVariable2;\r
+\r
+  //\r
+  // Initialize some Index variable and Status\r
+  //\r
+  Count             = 0;\r
+  Class             = 0;\r
+  SubClass          = 0;\r
+  CurrentVariable   = 0;\r
+  CurrentVariable2  = 0;\r
+  QuestionIndex     = 0;\r
+  NumberOfTags      = 1;\r
+  Status            = EFI_SUCCESS;\r
+  FormTags          = &FileFormTags->FormTags;\r
+  FormTags->Next    = NULL;\r
+  if (FileFormTags->InconsistentTags == NULL) {\r
+    InconsistentTags = NULL;\r
+  } else {\r
+    InconsistentTags = FileFormTags->InconsistentTags;\r
+  }\r
+\r
+  if (FileFormTags->VariableDefinitions == NULL) {\r
+    VariableDefinitions = NULL;\r
+  } else {\r
+    VariableDefinitions = FileFormTags->VariableDefinitions;\r
+  }\r
+  //\r
+  // RawFormSet now points to the beginning of the forms portion of\r
+  // the specific IFR Binary.\r
+  //\r
+  RawFormSet = (UINT8 *) BinaryData->FormBinary;\r
+\r
+  //\r
+  // Determine the number of tags for the first form\r
+  //\r
+  GetTagCount (&RawFormSet[0], &NumberOfTags);\r
+\r
+  SavedFormTags = FormTags;\r
+\r
+  if (FormTags->Tags != NULL) {\r
+    do {\r
+      //\r
+      // Advance FormTags to the last entry\r
+      //\r
+      for (; FormTags->Next != NULL; FormTags = FormTags->Next)\r
+        ;\r
+\r
+      //\r
+      // Walk through each of the tags and free the IntList allocation\r
+      //\r
+      for (Index = 0; Index < NumberOfTags; Index++) {\r
+        if (FormTags->Tags[Index].IntList != NULL) {\r
+          FreePool (FormTags->Tags[Index].IntList);\r
+        }\r
+      }\r
+\r
+      FreePool (FormTags->Tags);\r
+\r
+      ASSERT (FormTags->Next == NULL);\r
+\r
+      FormTags->Tags  = NULL;\r
+\r
+      FormTags        = SavedFormTags;\r
+\r
+    } while (FormTags->Next != NULL);\r
+  }\r
+\r
+  Index = 0;\r
+\r
+  //\r
+  // Test for an allocated buffer.  If already allocated this is due to having called this routine\r
+  // once for sizing of the NV storage.  We then loaded the NV variable and can correctly initialize\r
+  // the tag structure with current values from the NV\r
+  //\r
+  if (FormTags->Tags == NULL) {\r
+    //\r
+    // Allocate memory for our tags on the first form\r
+    //\r
+    FormTags->Tags = AllocateZeroPool (NumberOfTags * sizeof (EFI_TAG));\r
+    ASSERT (FormTags->Tags);\r
+  }\r
+  //\r
+  // Test for an allocated buffer.  If already allocated this is due to having called this routine\r
+  // once for sizing of the NV storage.  We then loaded the NV variable and can correctly initialize\r
+  // the tag structure with current values from the NV\r
+  //\r
+  if (InconsistentTags == NULL) {\r
+    //\r
+    // We just hit the end of an inconsistent expression.  Let's allocate the ->Next structure\r
+    //\r
+    InconsistentTags = AllocateZeroPool (sizeof (EFI_INCONSISTENCY_DATA));\r
+    ASSERT (InconsistentTags != NULL);\r
+\r
+    FileFormTags->InconsistentTags = InconsistentTags;\r
+  }\r
+\r
+  ZeroMem (FormTags->Tags, NumberOfTags * sizeof (EFI_TAG));\r
+\r
+  for (CurrTag = 0; RawFormSet[Index] != EFI_IFR_END_FORM_SET_OP; CurrTag++) {\r
+    //\r
+    // Operand = IFR OpCode\r
+    //\r
+    FormTags->Tags[CurrTag].Operand = RawFormSet[Index];\r
+\r
+    //\r
+    // Assume for now 0 lines occupied by this OpCode\r
+    //\r
+    FormTags->Tags[CurrTag].NumberOfLines = 0;\r
+\r
+    FormTags->Tags[CurrTag].Class         = Class;\r
+    FormTags->Tags[CurrTag].SubClass      = SubClass;\r
+\r
+    //\r
+    // Determine the length of the Tag so we can later skip to the next tag in the form\r
+    //\r
+    TagLength = RawFormSet[Index + 1];\r
+    //\r
+    // get the length\r
+    //\r
+    // Operate on the Found OpCode\r
+    //\r
+    switch (RawFormSet[Index]) {\r
+\r
+    case EFI_IFR_FORM_OP:\r
+      //\r
+      // If there was no variable op-code defined, create a dummy entry for one\r
+      //\r
+      if (FileFormTags->VariableDefinitions == NULL) {\r
+        FileFormTags->VariableDefinitions = AllocateZeroPool (sizeof (EFI_VARIABLE_DEFINITION));\r
+        ASSERT (FileFormTags->VariableDefinitions != NULL);\r
+        IfrToFormTag (\r
+          RawFormSet[Index],\r
+          &FormTags->Tags[CurrTag],\r
+          (VOID *) &RawFormSet[Index],\r
+          FileFormTags->VariableDefinitions\r
+          );\r
+      } else {\r
+        IfrToFormTag (RawFormSet[Index], &FormTags->Tags[CurrTag], (VOID *) &RawFormSet[Index], NULL);\r
+      }\r
+      break;\r
+\r
+    case EFI_IFR_SUBTITLE_OP:\r
+    case EFI_IFR_TEXT_OP:\r
+    case EFI_IFR_REF_OP:\r
+      IfrToFormTag (RawFormSet[Index], &FormTags->Tags[CurrTag], (VOID *) &RawFormSet[Index], NULL);\r
+      break;\r
+\r
+    case EFI_IFR_VARSTORE_OP:\r
+      if (FileFormTags->VariableDefinitions == NULL) {\r
+        VariableDefinitions = AllocateZeroPool (sizeof (EFI_VARIABLE_DEFINITION));\r
+        ASSERT (VariableDefinitions != NULL);\r
+        FileFormTags->VariableDefinitions = VariableDefinitions;\r
+      }\r
+\r
+      IfrToFormTag (\r
+        RawFormSet[Index],\r
+        &FormTags->Tags[CurrTag],\r
+        (VOID *) &RawFormSet[Index],\r
+        FileFormTags->VariableDefinitions\r
+        );\r
+      break;\r
+\r
+    case EFI_IFR_VARSTORE_SELECT_OP:\r
+      IfrToFormTag (RawFormSet[Index], &FormTags->Tags[CurrTag], (VOID *) &RawFormSet[Index], NULL);\r
+      CopyMem (&CurrentVariable, &((EFI_IFR_VARSTORE_SELECT *) &RawFormSet[Index])->VarId, sizeof (UINT16));\r
+      CurrentVariable2 = CurrentVariable;\r
+      break;\r
+\r
+    case EFI_IFR_VARSTORE_SELECT_PAIR_OP:\r
+      IfrToFormTag (RawFormSet[Index], &FormTags->Tags[CurrTag], (VOID *) &RawFormSet[Index], NULL);\r
+      CopyMem(&CurrentVariable, &((EFI_IFR_VARSTORE_SELECT_PAIR *)&RawFormSet[Index])->VarId, sizeof (UINT16));\r
+      CopyMem (\r
+        &CurrentVariable2,\r
+        &((EFI_IFR_VARSTORE_SELECT_PAIR *) &RawFormSet[Index])->SecondaryVarId,\r
+        sizeof (UINT16)\r
+        );\r
+      break;\r
+\r
+    case EFI_IFR_END_FORM_OP:\r
+      //\r
+      // Test for an allocated buffer.  If already allocated this is due to having called this routine\r
+      // once for sizing of the NV storage.  We then loaded the NV variable and can correctly initialize\r
+      // the tag structure with current values from the NV\r
+      //\r
+      if (FormTags->Next == NULL) {\r
+        //\r
+        // We just hit the end of a form.  Let's allocate the ->Next structure\r
+        //\r
+        FormTags->Next = AllocatePool (sizeof (EFI_FORM_TAGS));\r
+        ASSERT (FormTags->Next);\r
+      }\r
+\r
+      FormTags = FormTags->Next;\r
+      ZeroMem (FormTags, sizeof (EFI_FORM_TAGS));\r
+\r
+      //\r
+      // Reset the tag count to one\r
+      //\r
+      NumberOfTags = 1;\r
+\r
+      //\r
+      // Reset the CurrTag value (it will be incremented, after this case statement\r
+      // so set to a negative one so that we get the desired effect.)  Fish can beat me later.\r
+      //\r
+      CurrTag = -1;\r
+\r
+      //\r
+      // Determine the number of tags after this form.  If this is the last\r
+      // form, then we will count the endformset and preserve that information\r
+      // in the tag structure.\r
+      //\r
+      GetTagCount (&RawFormSet[Index + TagLength], &NumberOfTags);\r
+\r
+      //\r
+      // Allocate memory for our tags\r
+      //\r
+      FormTags->Tags = AllocateZeroPool (NumberOfTags * sizeof (EFI_TAG));\r
+      ASSERT (FormTags->Tags);\r
+      break;\r
+\r
+    //\r
+    // Two types of tags constitute the One Of question: a one-of header and\r
+    // several one-of options.\r
+    //\r
+    case EFI_IFR_ONE_OF_OP:\r
+    case EFI_IFR_ORDERED_LIST_OP:\r
+      GetQuestionHeader (&FormTags->Tags[CurrTag], RawFormSet, Index, FileFormTags, CurrentVariable);\r
+\r
+      //\r
+      // Store away the CurrTag since what follows will be the answer that we\r
+      // need to place into the appropriate location in the tag array\r
+      //\r
+      //\r
+      // record for setting default later\r
+      //\r
+      QuestionIndex = (UINT16) CurrTag;\r
+      break;\r
+\r
+    case EFI_IFR_ONE_OF_OPTION_OP:\r
+      IfrToFormTag (RawFormSet[Index], &FormTags->Tags[CurrTag], (VOID *) &RawFormSet[Index], NULL);\r
+      FormTags->Tags[QuestionIndex].Flags = ((EFI_IFR_ONE_OF_OPTION *) &RawFormSet[Index])->Flags;\r
+      CopyMem (\r
+        &FormTags->Tags[QuestionIndex].Key,\r
+        &((EFI_IFR_ONE_OF_OPTION *) &RawFormSet[Index])->Key,\r
+        sizeof (UINT16)\r
+        );\r
+      FormTags->Tags[QuestionIndex].ResetRequired = (BOOLEAN) (FormTags->Tags[QuestionIndex].Flags & EFI_IFR_FLAG_RESET_REQUIRED);\r
+      break;\r
+\r
+    case EFI_IFR_CHECKBOX_OP:\r
+      GetQuestionHeader (&FormTags->Tags[CurrTag], RawFormSet, Index, FileFormTags, CurrentVariable);\r
+      IfrToFormTag (RawFormSet[Index], &FormTags->Tags[CurrTag], (VOID *) &RawFormSet[Index], NULL);\r
+      break;\r
+\r
+    case EFI_IFR_NUMERIC_OP:\r
+      GetNumericHeader (&FormTags->Tags[CurrTag], RawFormSet, Index, (UINT16) 1, FileFormTags, CurrentVariable);\r
+      IfrToFormTag (RawFormSet[Index], &FormTags->Tags[CurrTag], (VOID *) &RawFormSet[Index], NULL);\r
+      break;\r
+\r
+    case EFI_IFR_DATE_OP:\r
+      //\r
+      // Date elements come in as a Year, Month, Day.  We need to process them as a country-based\r
+      // Order.  It is much easier to do it here than anywhere else.\r
+      //\r
+      // For US standards - we want Month/Day/Year, thus we advance "Index" +1, +2, +0 while CurrTag is +0, +1, +2\r
+      //\r
+      GetNumericHeader (\r
+        &FormTags->Tags[CurrTag],\r
+        RawFormSet,\r
+        (UINT16) (Index + TagLength),\r
+        (UINT16) 0,\r
+        FileFormTags,\r
+        CurrentVariable\r
+        );\r
+\r
+      //\r
+      // The current language selected + the Date operand\r
+      //\r
+      FormTags->Tags[CurrTag + 1].Operand = RawFormSet[Index];\r
+      GetNumericHeader (\r
+        &FormTags->Tags[CurrTag + 1],\r
+        RawFormSet,\r
+        (UINT16) (Index + TagLength + RawFormSet[Index + TagLength + 1]),\r
+        (UINT16) 0,\r
+        FileFormTags,\r
+        CurrentVariable\r
+        );\r
+\r
+      //\r
+      // The current language selected + the Date operand\r
+      //\r
+      FormTags->Tags[CurrTag + 2].Operand = RawFormSet[Index];\r
+      GetNumericHeader (&FormTags->Tags[CurrTag + 2], RawFormSet, Index, (UINT16) 1, FileFormTags, CurrentVariable);\r
+\r
+      CurrTag   = (INT16) (CurrTag + 2);\r
+\r
+      Index     = (UINT16) (Index + TagLength);\r
+      //\r
+      // get the length\r
+      //\r
+      TagLength = RawFormSet[Index + 1];\r
+      Index     = (UINT16) (Index + TagLength);\r
+      //\r
+      // get the length\r
+      //\r
+      TagLength = RawFormSet[Index + 1];\r
+      break;\r
+\r
+    case EFI_IFR_TIME_OP:\r
+      GetNumericHeader (&FormTags->Tags[CurrTag], RawFormSet, Index, (UINT16) 0, FileFormTags, CurrentVariable);\r
+\r
+      if (Count == 2) {\r
+        //\r
+        // Override the GetQuestionHeader information - date/time are treated very differently\r
+        //\r
+        FormTags->Tags[CurrTag].NumberOfLines = 1;\r
+        Count = 0;\r
+      } else {\r
+        //\r
+        // The premise is that every date/time op-code have 3 elements, the first 2 have 0 lines\r
+        // associated with them, and the third has 1 line to allow to space beyond the choice.\r
+        //\r
+        Count++;\r
+      }\r
+      break;\r
+\r
+    case EFI_IFR_PASSWORD_OP:\r
+    case EFI_IFR_STRING_OP:\r
+      GetQuestionHeader (&FormTags->Tags[CurrTag], RawFormSet, Index, FileFormTags, CurrentVariable);\r
+      IfrToFormTag (RawFormSet[Index], &FormTags->Tags[CurrTag], (VOID *) &RawFormSet[Index], NULL);\r
+      break;\r
+\r
+    case EFI_IFR_SUPPRESS_IF_OP:\r
+    case EFI_IFR_GRAYOUT_IF_OP:\r
+      InconsistentTags->Operand = ((EFI_IFR_INCONSISTENT *) &RawFormSet[Index])->Header.OpCode;\r
+      gConsistencyId++;\r
+\r
+      //\r
+      // Since this op-code doesn't use the next field(s), initialize them with something invalid.\r
+      // Unfortunately 0 is a valid offset value for a QuestionId\r
+      //\r
+      InconsistentTags->QuestionId1 = INVALID_OFFSET_VALUE;\r
+      InconsistentTags->QuestionId2 = INVALID_OFFSET_VALUE;\r
+\r
+      //\r
+      // Test for an allocated buffer.  If already allocated this is due to having called this routine\r
+      // once for sizing of the NV storage.  We then loaded the NV variable and can correctly initialize\r
+      // the tag structure with current values from the NV\r
+      //\r
+      if (InconsistentTags->Next == NULL) {\r
+        AddNextInconsistentTag (&InconsistentTags);\r
+        break;\r
+      }\r
+\r
+      InconsistentTags = InconsistentTags->Next;\r
+      break;\r
+\r
+    case EFI_IFR_FORM_SET_OP:\r
+      CopyMem (\r
+        &FormTags->Tags[CurrTag].GuidValue,\r
+        &((EFI_IFR_FORM_SET *) &RawFormSet[Index])->Guid,\r
+        sizeof (EFI_GUID)\r
+        );\r
+      CopyMem (\r
+        &FormTags->Tags[CurrTag].CallbackHandle,\r
+        &((EFI_IFR_FORM_SET *) &RawFormSet[Index])->CallbackHandle,\r
+        sizeof (EFI_PHYSICAL_ADDRESS)\r
+        );\r
+      CopyMem (&FormTags->Tags[CurrTag].Class, &((EFI_IFR_FORM_SET *) &RawFormSet[Index])->Class, sizeof (UINT8));\r
+      CopyMem (\r
+        &FormTags->Tags[CurrTag].SubClass,\r
+        &((EFI_IFR_FORM_SET *) &RawFormSet[Index])->SubClass,\r
+        sizeof (UINT8)\r
+        );\r
+      CopyMem (\r
+        &FormTags->Tags[CurrTag].NvDataSize,\r
+        &((EFI_IFR_FORM_SET *) &RawFormSet[Index])->NvDataSize,\r
+        sizeof (UINT16)\r
+        );\r
+      Class     = ((EFI_IFR_FORM_SET *) &RawFormSet[Index])->Class;\r
+      SubClass  = ((EFI_IFR_FORM_SET *) &RawFormSet[Index])->SubClass;\r
+      //\r
+      // If the formset has a size value, that means someone must be using this, so create a variable\r
+      // We also shall reserve the formid of 0 for this specific purpose.\r
+      //\r
+      if ((FileFormTags->VariableDefinitions == NULL) && (FormTags->Tags[CurrTag].NvDataSize > 0)) {\r
+        FileFormTags->VariableDefinitions = AllocateZeroPool (sizeof (EFI_VARIABLE_DEFINITION));\r
+        ASSERT (FileFormTags->VariableDefinitions != NULL);\r
+        IfrToFormTag (\r
+          RawFormSet[Index],\r
+          &FormTags->Tags[CurrTag],\r
+          (VOID *) &RawFormSet[Index],\r
+          FileFormTags->VariableDefinitions\r
+          );\r
+      } else {\r
+        IfrToFormTag (RawFormSet[Index], &FormTags->Tags[CurrTag], (VOID *) &RawFormSet[Index], NULL);\r
+      }\r
+      break;\r
+\r
+    case EFI_IFR_BANNER_OP:\r
+      if (gClassOfVfr == EFI_FRONT_PAGE_SUBCLASS) {\r
+        TempValue = 0;\r
+        CopyMem (&TempValue, &((EFI_IFR_BANNER *) &RawFormSet[Index])->Alignment, sizeof (UINT8));\r
+        //\r
+        // If this is the special timeout value, we will dynamically figure out where to put it\r
+        // Also the least significant byte refers to the TimeOut desired.\r
+        //\r
+        if (TempValue == EFI_IFR_BANNER_TIMEOUT) {\r
+          CopyMem (&FrontPageTimeOutTitle, &((EFI_IFR_BANNER *) &RawFormSet[Index])->Title, sizeof (UINT16));\r
+          if (FrontPageTimeOutValue != (INT16) -1) {\r
+            CopyMem (&FrontPageTimeOutValue, &((EFI_IFR_BANNER *) &RawFormSet[Index])->LineNumber, sizeof (UINT16));\r
+          }\r
+          break;\r
+        }\r
+\r
+        CopyMem (\r
+          &BannerData->Banner[((EFI_IFR_BANNER *) &RawFormSet[Index])->LineNumber][\r
+          ((EFI_IFR_BANNER *) &RawFormSet[Index])->Alignment],\r
+          &((EFI_IFR_BANNER *) &RawFormSet[Index])->Title,\r
+          sizeof (STRING_REF)\r
+          );\r
+      }\r
+      break;\r
+\r
+    case EFI_IFR_INCONSISTENT_IF_OP:\r
+      CopyMem (\r
+        &FormTags->Tags[CurrTag].Text,\r
+        &((EFI_IFR_INCONSISTENT *) &RawFormSet[Index])->Popup,\r
+        sizeof (UINT16)\r
+        );\r
+      gConsistencyId++;\r
+\r
+      InconsistentTags->Operand = ((EFI_IFR_INCONSISTENT *) &RawFormSet[Index])->Header.OpCode;\r
+      CopyMem (&InconsistentTags->Popup, &((EFI_IFR_INCONSISTENT *) &RawFormSet[Index])->Popup, sizeof (UINT16));\r
+\r
+      //\r
+      // Since this op-code doesn't use the next field(s), initialize them with something invalid.\r
+      // Unfortunately 0 is a valid offset value for a QuestionId\r
+      //\r
+      InconsistentTags->QuestionId1     = INVALID_OFFSET_VALUE;\r
+      InconsistentTags->QuestionId2     = INVALID_OFFSET_VALUE;\r
+\r
+      InconsistentTags->VariableNumber  = CurrentVariable;\r
+\r
+      //\r
+      // Test for an allocated buffer.  If already allocated this is due to having called this routine\r
+      // once for sizing of the NV storage.  We then loaded the NV variable and can correctly initialize\r
+      // the tag structure with current values from the NV\r
+      //\r
+      if (InconsistentTags->Next == NULL) {\r
+        AddNextInconsistentTag (&InconsistentTags);\r
+        break;\r
+      }\r
+\r
+      InconsistentTags = InconsistentTags->Next;\r
+      break;\r
+\r
+    case EFI_IFR_EQ_ID_VAL_OP:\r
+      IfrToFormTag (RawFormSet[Index], &FormTags->Tags[CurrTag], (VOID *) &RawFormSet[Index], NULL);\r
+\r
+      InconsistentTags->Operand = ((EFI_IFR_EQ_ID_VAL *) &RawFormSet[Index])->Header.OpCode;\r
+      CopyMem (&InconsistentTags->Value, &((EFI_IFR_EQ_ID_VAL *) &RawFormSet[Index])->Value, sizeof (UINT16));\r
+      CopyMem (\r
+        &InconsistentTags->QuestionId1,\r
+        &((EFI_IFR_EQ_ID_VAL *) &RawFormSet[Index])->QuestionId,\r
+        sizeof (UINT16)\r
+        );\r
+\r
+      //\r
+      // Since this op-code doesn't use the next field(s), initialize them with something invalid.\r
+      // Unfortunately 0 is a valid offset value for a QuestionId\r
+      //\r
+      InconsistentTags->Width               = FormTags->Tags[CurrTag].StorageWidth;\r
+      InconsistentTags->QuestionId2         = INVALID_OFFSET_VALUE;\r
+      InconsistentTags->ConsistencyId       = gConsistencyId;\r
+      FormTags->Tags[CurrTag].ConsistencyId = gConsistencyId;\r
+\r
+      InconsistentTags->VariableNumber      = CurrentVariable;\r
+\r
+      //\r
+      // Test for an allocated buffer.  If already allocated this is due to having called this routine\r
+      // once for sizing of the NV storage.  We then loaded the NV variable and can correctly initialize\r
+      // the tag structure with current values from the NV\r
+      //\r
+      if (InconsistentTags->Next == NULL) {\r
+        AddNextInconsistentTag (&InconsistentTags);\r
+        break;\r
+      }\r
+\r
+      InconsistentTags = InconsistentTags->Next;\r
+      break;\r
+\r
+    case EFI_IFR_EQ_VAR_VAL_OP:\r
+      IfrToFormTag (RawFormSet[Index], &FormTags->Tags[CurrTag], (VOID *) &RawFormSet[Index], NULL);\r
+\r
+      InconsistentTags->Operand = ((EFI_IFR_EQ_VAR_VAL *) &RawFormSet[Index])->Header.OpCode;\r
+      CopyMem (&InconsistentTags->Value, &((EFI_IFR_EQ_VAR_VAL *) &RawFormSet[Index])->Value, sizeof (UINT16));\r
+      CopyMem (\r
+        &InconsistentTags->QuestionId1,\r
+        &((EFI_IFR_EQ_VAR_VAL *) &RawFormSet[Index])->VariableId,\r
+        sizeof (UINT16)\r
+        );\r
+\r
+      //\r
+      // Since this op-code doesn't use the next field(s), initialize them with something invalid.\r
+      // Unfortunately 0 is a valid offset value for a QuestionId\r
+      //\r
+      InconsistentTags->QuestionId2         = INVALID_OFFSET_VALUE;\r
+      InconsistentTags->ConsistencyId       = gConsistencyId;\r
+      FormTags->Tags[CurrTag].ConsistencyId = gConsistencyId;\r
+\r
+      InconsistentTags->VariableNumber      = CurrentVariable;\r
+\r
+      //\r
+      // Test for an allocated buffer.  If already allocated this is due to having called this routine\r
+      // once for sizing of the NV storage.  We then loaded the NV variable and can correctly initialize\r
+      // the tag structure with current values from the NV\r
+      //\r
+      if (InconsistentTags->Next == NULL) {\r
+        AddNextInconsistentTag (&InconsistentTags);\r
+        break;\r
+      }\r
+\r
+      InconsistentTags = InconsistentTags->Next;\r
+      break;\r
+\r
+    case EFI_IFR_EQ_ID_ID_OP:\r
+      IfrToFormTag (RawFormSet[Index], &FormTags->Tags[CurrTag], (VOID *) &RawFormSet[Index], NULL);\r
+\r
+      InconsistentTags->Operand = ((EFI_IFR_EQ_ID_ID *) &RawFormSet[Index])->Header.OpCode;\r
+      CopyMem (\r
+        &InconsistentTags->QuestionId1,\r
+        &((EFI_IFR_EQ_ID_ID *) &RawFormSet[Index])->QuestionId1,\r
+        sizeof (UINT16)\r
+        );\r
+      CopyMem (\r
+        &InconsistentTags->QuestionId2,\r
+        &((EFI_IFR_EQ_ID_ID *) &RawFormSet[Index])->QuestionId2,\r
+        sizeof (UINT16)\r
+        );\r
+\r
+      InconsistentTags->Width               = FormTags->Tags[CurrTag].StorageWidth;\r
+      InconsistentTags->ConsistencyId       = gConsistencyId;\r
+      FormTags->Tags[CurrTag].ConsistencyId = gConsistencyId;\r
+\r
+      InconsistentTags->VariableNumber      = CurrentVariable;\r
+      InconsistentTags->VariableNumber2     = CurrentVariable2;\r
+\r
+      //\r
+      // Test for an allocated buffer.  If already allocated this is due to having called this routine\r
+      // once for sizing of the NV storage.  We then loaded the NV variable and can correctly initialize\r
+      // the tag structure with current values from the NV\r
+      //\r
+      if (InconsistentTags->Next == NULL) {\r
+        AddNextInconsistentTag (&InconsistentTags);\r
+        break;\r
+      }\r
+\r
+      InconsistentTags = InconsistentTags->Next;\r
+      break;\r
+\r
+    case EFI_IFR_AND_OP:\r
+    case EFI_IFR_OR_OP:\r
+    case EFI_IFR_NOT_OP:\r
+    case EFI_IFR_GT_OP:\r
+    case EFI_IFR_GE_OP:\r
+    case EFI_IFR_TRUE_OP:\r
+    case EFI_IFR_FALSE_OP:\r
+      InconsistentTags->Operand = ((EFI_IFR_NOT *) &RawFormSet[Index])->Header.OpCode;\r
+\r
+      //\r
+      // Since this op-code doesn't use the next field(s), initialize them with something invalid.\r
+      // Unfortunately 0 is a valid offset value for a QuestionId\r
+      //\r
+\r
+      //\r
+      // Reserve INVALID_OFFSET_VALUE - 1 for TRUE or FALSE because they are inconsistency tags also, but\r
+      // have no coresponding id. The examination of id is needed by evaluating boolean expression.\r
+      //\r
+      if (RawFormSet[Index] == EFI_IFR_TRUE_OP ||\r
+          RawFormSet[Index] == EFI_IFR_FALSE_OP) {\r
+        InconsistentTags->QuestionId1         = INVALID_OFFSET_VALUE - 1;\r
+      } else {\r
+        InconsistentTags->QuestionId1         = INVALID_OFFSET_VALUE;\r
+      }\r
+      InconsistentTags->QuestionId2         = INVALID_OFFSET_VALUE;\r
+      InconsistentTags->ConsistencyId       = gConsistencyId;\r
+      FormTags->Tags[CurrTag].ConsistencyId = gConsistencyId;\r
+\r
+      //\r
+      // Test for an allocated buffer.  If already allocated this is due to having called this routine\r
+      // once for sizing of the NV storage.  We then loaded the NV variable and can correctly initialize\r
+      // the tag structure with current values from the NV\r
+      //\r
+      if (InconsistentTags->Next == NULL) {\r
+        AddNextInconsistentTag (&InconsistentTags);\r
+        break;\r
+      }\r
+\r
+      InconsistentTags = InconsistentTags->Next;\r
+      break;\r
+\r
+    case EFI_IFR_EQ_ID_LIST_OP:\r
+      IfrToFormTag (RawFormSet[Index], &FormTags->Tags[CurrTag], (VOID *) &RawFormSet[Index], NULL);\r
+\r
+      InconsistentTags->Operand = ((EFI_IFR_EQ_ID_LIST *) &RawFormSet[Index])->Header.OpCode;\r
+      CopyMem (\r
+        &InconsistentTags->QuestionId1,\r
+        &((EFI_IFR_EQ_ID_LIST *) &RawFormSet[Index])->QuestionId,\r
+        sizeof (UINT16)\r
+        );\r
+      CopyMem (\r
+        &InconsistentTags->ListLength,\r
+        &((EFI_IFR_EQ_ID_LIST *) &RawFormSet[Index])->ListLength,\r
+        sizeof (UINT16)\r
+        );\r
+      InconsistentTags->ValueList = FormTags->Tags[CurrTag].IntList;\r
+\r
+      //\r
+      // Since this op-code doesn't use the next field(s), initialize them with something invalid.\r
+      // Unfortunately 0 is a valid offset value for a QuestionId\r
+      //\r
+      InconsistentTags->Width               = FormTags->Tags[CurrTag].StorageWidth;\r
+      InconsistentTags->QuestionId2         = INVALID_OFFSET_VALUE;\r
+      InconsistentTags->ConsistencyId       = gConsistencyId;\r
+      FormTags->Tags[CurrTag].ConsistencyId = gConsistencyId;\r
+\r
+      //\r
+      // Test for an allocated buffer.  If already allocated this is due to having called this routine\r
+      // once for sizing of the NV storage.  We then loaded the NV variable and can correctly initialize\r
+      // the tag structure with current values from the NV\r
+      //\r
+      if (InconsistentTags->Next == NULL) {\r
+        AddNextInconsistentTag (&InconsistentTags);\r
+        break;\r
+      }\r
+\r
+      InconsistentTags = InconsistentTags->Next;\r
+      break;\r
+\r
+    case EFI_IFR_END_IF_OP:\r
+      InconsistentTags->Operand = ((EFI_IFR_END_EXPR *) &RawFormSet[Index])->Header.OpCode;\r
+\r
+      //\r
+      // Since this op-code doesn't use the next field(s), initialize them with something invalid.\r
+      // Unfortunately 0 is a valid offset value for a QuestionId\r
+      //\r
+      InconsistentTags->QuestionId1 = INVALID_OFFSET_VALUE;\r
+      InconsistentTags->QuestionId2 = INVALID_OFFSET_VALUE;\r
+\r
+      //\r
+      // Test for an allocated buffer.  If already allocated this is due to having called this routine\r
+      // once for sizing of the NV storage.  We then loaded the NV variable and can correctly initialize\r
+      // the tag structure with current values from the NV\r
+      //\r
+      if (InconsistentTags->Next == NULL) {\r
+        AddNextInconsistentTag (&InconsistentTags);\r
+        break;\r
+      }\r
+\r
+      InconsistentTags = InconsistentTags->Next;\r
+      break;\r
+\r
+    case EFI_IFR_END_ONE_OF_OP:\r
+      break;\r
+\r
+    default:\r
+      break;\r
+    }\r
+    //\r
+    // End of switch\r
+    //\r
+    // Per spec., we ignore ops that we don't know how to deal with.  Skip to next tag\r
+    //\r
+    Index = (UINT16) (Index + TagLength);\r
+  }\r
+  //\r
+  // End of Index\r
+  //\r
+  // When we eventually exit, make sure we mark the last tag with an op-code\r
+  //\r
+  FormTags->Tags[CurrTag].Operand = RawFormSet[Index];\r
+\r
+  IfrToFormTag (RawFormSet[Index], &FormTags->Tags[CurrTag], (VOID *) &RawFormSet[Index], NULL);\r
+\r
+  //\r
+  // Place this as an end of the database marker\r
+  //\r
+  InconsistentTags->Operand = 0xFF;\r
+\r
+  //\r
+  // This is the Head of the linked list of pages.  Each page is an array of tags\r
+  //\r
+  FormTags          = &FileFormTags->FormTags;\r
+  InconsistentTags  = FileFormTags->InconsistentTags;\r
+\r
+  for (; InconsistentTags->Operand != 0xFF;) {\r
+    if (InconsistentTags->QuestionId1 != INVALID_OFFSET_VALUE) {\r
+      //\r
+      // Search the tags for the tag which corresponds to this ID\r
+      //\r
+      for (CurrTag = 0; FormTags->Tags[0].Operand != EFI_IFR_END_FORM_SET_OP; CurrTag++) {\r
+        //\r
+        // If we hit the end of a form, go to the next set of Tags.\r
+        // Remember - EndFormSet op-codes sit on their own page after an end form.\r
+        //\r
+        if (FormTags->Tags[CurrTag].Operand == EFI_IFR_END_FORM_OP) {\r
+          //\r
+          // Reset the CurrTag value (it will be incremented, after this case statement\r
+          // so set to a negative one so that we get the desired effect.)  Fish can beat me later.\r
+          //\r
+          CurrTag   = -1;\r
+          FormTags  = FormTags->Next;\r
+          continue;\r
+        }\r
+\r
+        if (FormTags->Tags[CurrTag].Id == InconsistentTags->QuestionId1) {\r
+          FormTags->Tags[CurrTag].Consistency++;\r
+        }\r
+      }\r
+    }\r
+\r
+    FormTags = &FileFormTags->FormTags;\r
+\r
+    if (InconsistentTags->QuestionId2 != INVALID_OFFSET_VALUE) {\r
+      //\r
+      // Search the tags for the tag which corresponds to this ID\r
+      //\r
+      for (CurrTag = 0; FormTags->Tags[CurrTag].Operand != EFI_IFR_END_FORM_SET_OP; CurrTag++) {\r
+        //\r
+        // If we hit the end of a form, go to the next set of Tags.\r
+        // Remember - EndFormSet op-codes sit on their own page after an end form.\r
+        //\r
+        if (FormTags->Tags[CurrTag].Operand == EFI_IFR_END_FORM_OP) {\r
+          //\r
+          // Reset the CurrTag value (it will be incremented, after this case statement\r
+          // so set to a negative one so that we get the desired effect.)  Fish can beat me later.\r
+          //\r
+          CurrTag   = -1;\r
+          FormTags  = FormTags->Next;\r
+          continue;\r
+        }\r
+\r
+        if (FormTags->Tags[CurrTag].Id == InconsistentTags->QuestionId2) {\r
+          FormTags->Tags[CurrTag].Consistency++;\r
+        }\r
+      }\r
+    }\r
+\r
+    InconsistentTags = InconsistentTags->Next;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+VOID\r
+InitPage (\r
+  VOID\r
+  )\r
+{\r
+  CHAR16  *HomePageString;\r
+  CHAR16  *HomeEscapeString;\r
+\r
+  //\r
+  // Displays the Header and Footer borders\r
+  //\r
+  DisplayPageFrame ();\r
+\r
+  HomePageString    = GetToken (STRING_TOKEN (HOME_PAGE_TITLE), gHiiHandle);\r
+  HomeEscapeString  = GetToken (STRING_TOKEN (HOME_ESCAPE_STRING), gHiiHandle);\r
+\r
+  gST->ConOut->SetAttribute (gST->ConOut, EFI_YELLOW | EFI_BRIGHT);\r
+  //\r
+  //  PrintStringAt ((gScreenDimensions.RightColumn - GetStringWidth(HomePageString)/2)/2, 1, HomePageString);\r
+  //\r
+  PrintStringAt (\r
+    (gScreenDimensions.RightColumn + gScreenDimensions.LeftColumn - GetStringWidth (HomePageString) / 2) / 2,\r
+    1,\r
+    HomePageString\r
+    );\r
+  PrintAt (\r
+    gScreenDimensions.LeftColumn + 2,\r
+    gScreenDimensions.BottomRow - 3,\r
+    (CHAR16 *) L"%c%c%s",\r
+    ARROW_UP,\r
+    ARROW_DOWN,\r
+    gMoveHighlight\r
+    );\r
+  PrintAt (\r
+    gScreenDimensions.RightColumn - (GetStringWidth (HomeEscapeString) / 2) - 2,\r
+    gScreenDimensions.BottomRow - 3,\r
+    (CHAR16 *) L" %s",\r
+    HomeEscapeString\r
+    );\r
+  gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
+  FreePool (HomeEscapeString);\r
+  FreePool (HomePageString);\r
+\r
+  return ;\r
+}\r
+\r
+CHAR16 *\r
+GetToken (\r
+  IN  STRING_REF                              Token,\r
+  IN  EFI_HII_HANDLE                          HiiHandle\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get the string based on the TokenID and HII Handle.\r
+\r
+Arguments:\r
+\r
+  Token       - The Token ID.\r
+  HiiHandle   - Handle of Ifr to be fetched.\r
+\r
+Returns:\r
+\r
+  The output string.\r
+\r
+--*/\r
+{\r
+  CHAR16      *Buffer;\r
+  UINTN       BufferLength;\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Set default string size assumption at no more than 256 bytes\r
+  //\r
+  BufferLength  = 0x100;\r
+\r
+  Buffer        = AllocateZeroPool (BufferLength);\r
+  ASSERT (Buffer != NULL);\r
+\r
+  Status = Hii->GetString (Hii, HiiHandle, Token, TRUE, NULL, &BufferLength, Buffer);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    if (Status == EFI_BUFFER_TOO_SMALL) {\r
+      //\r
+      // Free the old pool\r
+      //\r
+      FreePool (Buffer);\r
+\r
+      //\r
+      // Allocate new pool with correct value\r
+      //\r
+      Buffer = AllocatePool (BufferLength);\r
+      ASSERT (Buffer != NULL);\r
+\r
+      Status = Hii->GetString (Hii, HiiHandle, Token, TRUE, NULL, &BufferLength, Buffer);\r
+\r
+      if (!EFI_ERROR (Status)) {\r
+        return Buffer;\r
+      }\r
+    }\r
+\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
+  return Buffer;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+PopulateHomePage (\r
+  IN UINTN                                    NumberOfIfrImages,\r
+  IN EFI_FILE_FORM_TAGS                       *FileFormTagsHead\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  UINTN               Index;\r
+  EFI_IFR_BINARY      *IfrBinary;\r
+  CHAR16              *StringPtr;\r
+  EFI_FILE_FORM_TAGS  *FileFormTags;\r
+  EFI_FORM_TAGS       LocalTags;\r
+\r
+  FileFormTags = FileFormTagsHead;\r
+\r
+  UiInitMenu ();\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
+  //\r
+  // If there are no images\r
+  //\r
+  if (NumberOfIfrImages == 0) {\r
+    Status = EFI_NO_MEDIA;\r
+    return Status;\r
+  }\r
+  //\r
+  // IfrBinary points to the beginning of the Binary data linked-list\r
+  //\r
+  IfrBinary = gBinaryDataHead;\r
+\r
+  //\r
+  // Print the entries which were in the default language.\r
+  //\r
+  for (Index = 0; Index < NumberOfIfrImages; Index++) {\r
+    LocalTags = FileFormTags->FormTags;\r
+\r
+    //\r
+    // Populate the Menu\r
+    //\r
+    StringPtr = GetToken (IfrBinary->TitleToken, IfrBinary->Handle);\r
+\r
+    //\r
+    // If the default language doesn't exist, don't add a menu option yet\r
+    //\r
+    if (StringPtr[0] != CHAR_NULL) {\r
+      //\r
+      // We are NOT!! removing this StringPtr buffer via FreePool since it is being used in the menuoptions, we will do\r
+      // it in UiFreeMenu.\r
+      //\r
+      UiAddMenuOption (StringPtr, IfrBinary->Handle, LocalTags.Tags, IfrBinary->FormBinary, Index);\r
+    }\r
+    //\r
+    // Advance to the next HII handle\r
+    //\r
+    IfrBinary     = IfrBinary->Next;\r
+    FileFormTags  = FileFormTags->NextFile;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+UI_MENU_OPTION *\r
+DisplayHomePage (\r
+  IN UINTN                                    NumberOfIfrImages,\r
+  IN EFI_FILE_FORM_TAGS                       *FileFormTagsHead,\r
+  IN UINT8                                    *CallbackData\r
+  )\r
+{\r
+  EFI_STATUS      Status;\r
+  UI_MENU_OPTION  *Selection;\r
+\r
+  //\r
+  // This prints the basic home page template which the user sees\r
+  //\r
+  InitPage ();\r
+\r
+  Status = PopulateHomePage (NumberOfIfrImages, FileFormTagsHead);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    Selection = NULL;\r
+    return Selection;\r
+  }\r
+\r
+  Selection = UiDisplayMenu (FALSE, FileFormTagsHead, (EFI_IFR_DATA_ARRAY *) CallbackData);\r
+\r
+  return Selection;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+InitializeBinaryStructures (\r
+  IN  EFI_HII_HANDLE                        *Handle,\r
+  IN  BOOLEAN                               UseDatabase,\r
+  IN  EFI_IFR_PACKET                        *Packet,\r
+  IN  UINT8                                 *NvMapOverride,\r
+  IN  UINTN                                 NumberOfIfrImages,\r
+  OUT EFI_FILE_FORM_TAGS                    **FileFormTagsHead\r
+  )\r
+{\r
+  UINTN                       HandleIndex;\r
+  EFI_STATUS                  Status;\r
+  EFI_IFR_BINARY              *BinaryData;\r
+  EFI_FILE_FORM_TAGS          *FileFormTags;\r
+  UINTN                       SizeOfNvStore;\r
+  EFI_FORM_CALLBACK_PROTOCOL  *FormCallback;\r
+  EFI_VARIABLE_DEFINITION     *VariableDefinition;\r
+  EFI_VARIABLE_DEFINITION     *OverrideDefinition;\r
+  VOID                        *NvMap;\r
+  UINTN                       NvMapSize;\r
+  EFI_HII_VARIABLE_PACK_LIST  *NvMapListHead;\r
+  EFI_HII_VARIABLE_PACK_LIST  *NvMapListNode;\r
+\r
+  //\r
+  // Initialize some variables to avoid warnings\r
+  //\r
+  BinaryData        = NULL;\r
+  *FileFormTagsHead = NULL;\r
+  FileFormTags      = NULL;\r
+  gBinaryDataHead   = NULL;\r
+  Status            = EFI_SUCCESS;\r
+  FormCallback      = NULL;\r
+  NvMap             = NULL;\r
+  NvMapSize         = 0;\r
+\r
+  if (NumberOfIfrImages > 1) {\r
+    NvMapOverride = NULL;\r
+  }\r
+\r
+  for (HandleIndex = 0; HandleIndex < NumberOfIfrImages; HandleIndex += 1) {\r
+    //\r
+    // If the buffers are uninitialized, allocate them, otherwise work on the ->Next members\r
+    //\r
+    if ((BinaryData == NULL) || (FileFormTags == NULL)) {\r
+      //\r
+      // Allocate memory for our Binary Data\r
+      //\r
+      BinaryData = AllocateZeroPool (sizeof (EFI_IFR_BINARY));\r
+      ASSERT (BinaryData);\r
+\r
+      //\r
+      // Preserve the Head of what will be a linked-list.\r
+      //\r
+      gBinaryDataHead       = BinaryData;\r
+      gBinaryDataHead->Next = NULL;\r
+\r
+      if (UseDatabase) {\r
+        Status = GetIfrBinaryData (Hii, Handle[HandleIndex], NULL, BinaryData);\r
+      } else {\r
+        Status = GetIfrBinaryData (Hii, Handle[HandleIndex], Packet, BinaryData);\r
+      }\r
+      //\r
+      // Allocate memory for our File Form Tags\r
+      //\r
+      FileFormTags = AllocateZeroPool (sizeof (EFI_FILE_FORM_TAGS));\r
+      ASSERT (FileFormTags);\r
+\r
+      //\r
+      // Preserve the Head of what will be a linked-list.\r
+      //\r
+      *FileFormTagsHead             = FileFormTags;\r
+      (*FileFormTagsHead)->NextFile = NULL;\r
+\r
+    } else {\r
+      //\r
+      // Allocate memory for our Binary Data linked-list\r
+      // Each handle represents a Binary and we will store that data away.\r
+      //\r
+      BinaryData->Next = AllocateZeroPool (sizeof (EFI_IFR_BINARY));\r
+      ASSERT (BinaryData->Next);\r
+\r
+      BinaryData        = BinaryData->Next;\r
+      BinaryData->Next  = NULL;\r
+\r
+      if (UseDatabase) {\r
+        Status = GetIfrBinaryData (Hii, Handle[HandleIndex], NULL, BinaryData);\r
+      } else {\r
+        Status = GetIfrBinaryData (Hii, Handle[HandleIndex], Packet, BinaryData);\r
+      }\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        return EFI_DEVICE_ERROR;\r
+      }\r
+      //\r
+      // Allocate memory for our FileFormTags linked-list\r
+      // Each allocation reserves handle represents a Binary and we will store that data away.\r
+      //\r
+      FileFormTags->NextFile = AllocateZeroPool (sizeof (EFI_FILE_FORM_TAGS));\r
+      ASSERT (FileFormTags->NextFile);\r
+\r
+      FileFormTags = FileFormTags->NextFile;\r
+    }\r
+    //\r
+    // endif\r
+    //\r
+    // Tag Structure Initialization\r
+    //\r
+    Status              = InitializeTagStructures (BinaryData, FileFormTags);\r
+\r
+    VariableDefinition  = FileFormTags->VariableDefinitions;\r
+\r
+    //\r
+    // Allocate memory for our NVRAM Maps for all of our variables\r
+    //\r
+    for (; VariableDefinition != NULL; VariableDefinition = VariableDefinition->Next) {\r
+      //\r
+      // Pad the fake variable size accordingly - this value should reflect the size of information that is not accounted by\r
+      // the mainstream NVRAM variable such as DATE/TIME information that the browser needs to track but is saved to an RTC\r
+      //\r
+      VariableDefinition->VariableFakeSize = (UINT16) (VariableDefinition->VariableSize + VariableDefinition->VariableFakeSize);\r
+\r
+      //\r
+      // In the case where a file has no "real" NV data, we should pad the buffer accordingly\r
+      //\r
+      if (VariableDefinition->VariableSize == 0) {\r
+        if (VariableDefinition->VariableFakeSize != 0) {\r
+          VariableDefinition->NvRamMap = AllocateZeroPool (VariableDefinition->VariableFakeSize);\r
+          ASSERT (VariableDefinition->NvRamMap != NULL);\r
+        }\r
+      } else {\r
+        VariableDefinition->NvRamMap = AllocateZeroPool (VariableDefinition->VariableSize);\r
+        ASSERT (VariableDefinition->NvRamMap != NULL);\r
+      }\r
+\r
+      if (VariableDefinition->VariableFakeSize != 0) {\r
+        VariableDefinition->FakeNvRamMap = AllocateZeroPool (VariableDefinition->VariableFakeSize);\r
+        ASSERT (VariableDefinition->FakeNvRamMap != NULL);\r
+      }\r
+    }\r
+\r
+    Status = gBS->HandleProtocol (\r
+                    (VOID *) (UINTN) FileFormTags->FormTags.Tags[0].CallbackHandle,\r
+                    &gEfiFormCallbackProtocolGuid,\r
+                    (VOID **) &FormCallback\r
+                    );\r
+\r
+    //\r
+    // Since we might have multiple variables, if there is an NvMapOverride we need to use the EFI_VARIABLE_DEFINITION\r
+    // information as the information that we pass back and forth.  NOTE that callbacks that are initiated will only have the\r
+    // NVRAM data refreshed based on the op-code that initiated the callback.  In other words, we will pass to the caller a single\r
+    // NVRAM map for a single variable based on the op-code that the user selected.\r
+    //\r
+    if (NvMapOverride != NULL) {\r
+      VariableDefinition  = FileFormTags->VariableDefinitions;\r
+      OverrideDefinition  = ((EFI_VARIABLE_DEFINITION *) NvMapOverride);\r
+\r
+      //\r
+      // Search through the variable definitions.  There should be sufficient passed in settings for the variable op-codes specified\r
+      //\r
+      for (; VariableDefinition != NULL; VariableDefinition = VariableDefinition->Next) {\r
+        if ((!CompareMem (VariableDefinition->VariableName, L"Setup", 10)) && (VariableDefinition->Next == NULL)) {\r
+          if (VariableDefinition->VariableSize != 0) {\r
+            CopyMem (VariableDefinition->NvRamMap, NvMapOverride, VariableDefinition->VariableSize);\r
+          } else {\r
+            CopyMem (VariableDefinition->NvRamMap, NvMapOverride, VariableDefinition->VariableFakeSize);\r
+          }\r
+          break;\r
+        } else {\r
+          VariableDefinition->NvRamMap = OverrideDefinition->NvRamMap;\r
+        }\r
+        //\r
+        // There should NEVER be a ->Next for VariableDefinition and a NULL ->Next for the OverrideDefinition\r
+        //\r
+        ASSERT (OverrideDefinition->Next);\r
+        OverrideDefinition = OverrideDefinition->Next;\r
+      }\r
+    } else {\r
+      VariableDefinition = FileFormTags->VariableDefinitions;\r
+\r
+      //\r
+      // Search through the variable definitions.  There should be sufficient passed in settings for the variable op-codes specified\r
+      //\r
+      for (; VariableDefinition != NULL; VariableDefinition = VariableDefinition->Next) {\r
+        SizeOfNvStore = VariableDefinition->VariableSize;\r
+\r
+        //\r
+        // Getting the NvStore and placing it into our Global Data\r
+        //\r
+        if ((FormCallback != NULL) && (FormCallback->NvRead != NULL)) {\r
+          Status = FormCallback->NvRead (\r
+                                  FormCallback,\r
+                                  VariableDefinition->VariableName,\r
+                                  &VariableDefinition->Guid,\r
+                                  NULL,\r
+                                  &SizeOfNvStore,\r
+                                  (VOID *) VariableDefinition->NvRamMap\r
+                                  );\r
+        } else {\r
+          Status = gRT->GetVariable (\r
+                          VariableDefinition->VariableName,\r
+                          &VariableDefinition->Guid,\r
+                          NULL,\r
+                          &SizeOfNvStore,\r
+                          (VOID *) VariableDefinition->NvRamMap\r
+                          );\r
+        }\r
+\r
+        if (EFI_ERROR (Status)) {\r
+          //\r
+          // If there is a variable that exists already and it is larger than what we calculated the\r
+          // storage needs to be, we must assume the variable size from GetVariable is correct and not\r
+          // allow the truncation of the variable.  It is very possible that the user who created the IFR\r
+          // we are cracking is not referring to a variable that was in a previous map, however we cannot\r
+          // allow it's truncation.\r
+          //\r
+          if (Status == EFI_BUFFER_TOO_SMALL) {\r
+            //\r
+            // If the buffer was too small, we should have the expanded size requirement in SizeOfNvStore now.\r
+            //\r
+            VariableDefinition->VariableSize = (UINT16) SizeOfNvStore;\r
+\r
+            //\r
+            // Free the buffer that was allocated that was too small\r
+            //\r
+            FreePool (VariableDefinition->NvRamMap);\r
+            FreePool (VariableDefinition->FakeNvRamMap);\r
+\r
+            VariableDefinition->NvRamMap = AllocateZeroPool (SizeOfNvStore);\r
+            VariableDefinition->FakeNvRamMap = AllocateZeroPool (SizeOfNvStore + VariableDefinition->VariableFakeSize);\r
+            ASSERT (VariableDefinition->NvRamMap);\r
+            ASSERT (VariableDefinition->FakeNvRamMap);\r
+\r
+            if ((FormCallback != NULL) && (FormCallback->NvRead != NULL)) {\r
+              Status = FormCallback->NvRead (\r
+                                      FormCallback,\r
+                                      VariableDefinition->VariableName,\r
+                                      &VariableDefinition->Guid,\r
+                                      NULL,\r
+                                      &SizeOfNvStore,\r
+                                      (VOID *) VariableDefinition->NvRamMap\r
+                                      );\r
+            } else {\r
+              Status = gRT->GetVariable (\r
+                              VariableDefinition->VariableName,\r
+                              &VariableDefinition->Guid,\r
+                              NULL,\r
+                              &SizeOfNvStore,\r
+                              (VOID *) VariableDefinition->NvRamMap\r
+                              );\r
+            }\r
+          }\r
+          //\r
+          // if the variable was not found, we will retrieve default values\r
+          //\r
+          if (Status == EFI_NOT_FOUND) {\r
+\r
+            if (0 == CompareMem (VariableDefinition->VariableName, L"Setup", 10)) {\r
+\r
+              NvMapListHead = NULL;\r
+\r
+              Status = Hii->GetDefaultImage (Hii, Handle[HandleIndex], EFI_IFR_FLAG_DEFAULT, &NvMapListHead);\r
+\r
+              if (!EFI_ERROR (Status)) {\r
+                ASSERT_EFI_ERROR (NULL != NvMapListHead);\r
+\r
+                NvMapListNode = NvMapListHead;\r
+\r
+                while (NULL != NvMapListNode) {\r
+                  if (VariableDefinition->VariableId == NvMapListNode->VariablePack->VariableId) {\r
+                    NvMap     = (VOID *) ((CHAR8 *) NvMapListNode->VariablePack + sizeof (EFI_HII_VARIABLE_PACK) + NvMapListNode->VariablePack->VariableNameLength);\r
+                    NvMapSize = NvMapListNode->VariablePack->Header.Length  - sizeof (EFI_HII_VARIABLE_PACK) - NvMapListNode->VariablePack->VariableNameLength;\r
+                    break;\r
+                    }\r
+                  NvMapListNode = NvMapListNode->NextVariablePack;\r
+                }\r
+\r
+                //\r
+                // Free the buffer that was allocated.\r
+                //\r
+                FreePool (VariableDefinition->NvRamMap);\r
+                FreePool (VariableDefinition->FakeNvRamMap);\r
+\r
+                //\r
+                // Allocate, copy the NvRamMap.\r
+                //\r
+                VariableDefinition->VariableFakeSize = (UINT16) (VariableDefinition->VariableFakeSize - VariableDefinition->VariableSize);\r
+                VariableDefinition->VariableSize = (UINT16) NvMapSize;\r
+                VariableDefinition->VariableFakeSize = (UINT16) (VariableDefinition->VariableFakeSize + VariableDefinition->VariableSize);\r
+\r
+                VariableDefinition->NvRamMap = AllocateZeroPool (VariableDefinition->VariableSize);\r
+                VariableDefinition->FakeNvRamMap = AllocateZeroPool (NvMapSize + VariableDefinition->VariableFakeSize);\r
+\r
+                CopyMem (VariableDefinition->NvRamMap, NvMap, NvMapSize);\r
+                FreePool (NvMapListHead);\r
+              }\r
+\r
+            }\r
+            Status = EFI_SUCCESS;\r
+          }\r
+        }\r
+      }\r
+    }\r
+\r
+    InitializeTagStructures (BinaryData, FileFormTags);\r
+  }\r
+  //\r
+  // endfor\r
+  //\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+GetIfrBinaryData (\r
+  IN      EFI_HII_PROTOCOL *Hii,\r
+  IN      EFI_HII_HANDLE   HiiHandle,\r
+  IN      EFI_IFR_PACKET   *Packet,\r
+  IN OUT  EFI_IFR_BINARY   *BinaryData\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Fetch the Ifr binary data.\r
+\r
+Arguments:\r
+  Hii         - Point to HII protocol.\r
+  HiiHandle   - Handle of Ifr to be fetched.\r
+  Packet      - Pointer to IFR packet.\r
+  BinaryData  - Buffer to copy the string into\r
+\r
+Returns:\r
+  Returns the number of CHAR16 characters that were copied into the OutputString buffer.\r
+\r
+\r
+--*/\r
+{\r
+  EFI_STATUS        Status;\r
+  EFI_HII_PACKAGES  *PackageList;\r
+  UINTN             BufferSize;\r
+  VOID              *Buffer;\r
+  UINT8             *RawFormBinary;\r
+  EFI_IFR_FORM_SET  *FormOp;\r
+  UINT16            Index;\r
+  UINT16            Index2;\r
+  UINT16            TitleToken;\r
+\r
+  //\r
+  // Initialize the TitleToken to 0 just in case not found\r
+  //\r
+  TitleToken = 0;\r
+\r
+  //\r
+  // Try for a 32K Buffer\r
+  //\r
+  BufferSize = 0x8000;\r
+\r
+  //\r
+  // Allocate memory for our Form binary\r
+  //\r
+  Buffer = AllocateZeroPool (BufferSize);\r
+  ASSERT (Buffer);\r
+\r
+  if (Packet == NULL) {\r
+    Status = Hii->GetForms (Hii, HiiHandle, 0, &BufferSize, Buffer);\r
+\r
+    if (Status == EFI_BUFFER_TOO_SMALL) {\r
+\r
+      FreePool (Buffer);\r
+\r
+      //\r
+      // Allocate memory for our Form binary\r
+      //\r
+      Buffer = AllocatePool (BufferSize);\r
+      ASSERT (Buffer);\r
+\r
+      Status = Hii->GetForms (Hii, HiiHandle, 0, &BufferSize, Buffer);\r
+    }\r
+  } else {\r
+    //\r
+    // Copies the data to local usable buffer\r
+    //\r
+    CopyMem (Buffer, Packet->IfrData, Packet->IfrData->Header.Length);\r
+\r
+    //\r
+    // Register the string data with HII\r
+    //\r
+    PackageList = PreparePackages (2, NULL, Packet->IfrData, Packet->StringData);\r
+\r
+    Status      = Hii->NewPack (Hii, PackageList, &HiiHandle);\r
+\r
+    FreePool (PackageList);\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // We now have the IFR binary in our Buffer\r
+  //\r
+  BinaryData->IfrPackage  = Buffer;\r
+  RawFormBinary           = (UINT8 *) ((CHAR8 *) (Buffer) + sizeof (EFI_HII_PACK_HEADER));\r
+  BinaryData->FormBinary  = (UINT8 *) ((CHAR8 *) (Buffer) + sizeof (EFI_HII_PACK_HEADER));\r
+  BinaryData->Handle      = HiiHandle;\r
+\r
+  //\r
+  // If a packet was passed in, remove the string data when exiting.\r
+  //\r
+  if (Packet != NULL) {\r
+    BinaryData->UnRegisterOnExit = TRUE;\r
+  } else {\r
+    BinaryData->UnRegisterOnExit = FALSE;\r
+  }\r
+  //\r
+  // Walk through the FormSet Opcodes looking for the FormSet opcode\r
+  // If we hit EFI_IFR_END_SET_OP we know we hit the end of the FormSet.\r
+  //\r
+  for (Index = 0; RawFormBinary[Index] != EFI_IFR_END_FORM_SET_OP;) {\r
+    FormOp  = (EFI_IFR_FORM_SET *) &RawFormBinary[Index];\r
+    Index   = (UINT16) (Index + FormOp->Header.Length);\r
+\r
+    if (FormOp->Header.OpCode == EFI_IFR_FORM_SET_OP) {\r
+      TitleToken = FormOp->FormSetTitle;\r
+      //\r
+      // If displaying FrontPage - set the flag signifying it\r
+      //\r
+      switch (FormOp->SubClass) {\r
+      case EFI_FRONT_PAGE_SUBCLASS:\r
+        FrontPageHandle = HiiHandle;\r
+\r
+      default:\r
+        gClassOfVfr = FormOp->SubClass;\r
+      }\r
+      //\r
+      // Match GUID to find out the function key setting. If match fail, use the default setting.\r
+      //\r
+      for (Index2 = 0; Index2 < sizeof (gFunctionKeySettingTable) / sizeof (FUNCTIION_KEY_SETTING); Index2++) {\r
+        if (CompareGuid ((EFI_GUID *)(UINTN)&FormOp->Guid, &(gFunctionKeySettingTable[Index2].FormSetGuid))) {\r
+          //\r
+          // Update the function key setting.\r
+          //\r
+          gFunctionKeySetting = gFunctionKeySettingTable[Index2].KeySetting;\r
+          //\r
+          // Function key prompt can not be displayed if the function key has been disabled.\r
+          //\r
+          if ((gFunctionKeySetting & FUNCTION_ONE) != FUNCTION_ONE) {\r
+            gFunctionOneString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);\r
+          }\r
+\r
+          if ((gFunctionKeySetting & FUNCTION_TWO) != FUNCTION_TWO) {\r
+            gFunctionTwoString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);\r
+          }\r
+\r
+          if ((gFunctionKeySetting & FUNCTION_NINE) != FUNCTION_NINE) {\r
+            gFunctionNineString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);\r
+          }\r
+\r
+          if ((gFunctionKeySetting & FUNCTION_TEN) != FUNCTION_TEN) {\r
+            gFunctionTenString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);\r
+          }\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  BinaryData->TitleToken = TitleToken;\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_HANDLE          PrintHandle     = NULL;\r
+EFI_PRINT_PROTOCOL  mPrintProtocol  = { UnicodeVSPrint };\r
+\r
+STATIC\r
+EFI_STATUS\r
+InstallPrint (\r
+  VOID\r
+  )\r
+{\r
+  return gBS->InstallProtocolInterface (\r
+                &PrintHandle,\r
+                &gEfiPrintProtocolGuid,\r
+                EFI_NATIVE_INTERFACE,\r
+                &mPrintProtocol\r
+                );\r
+}\r
diff --git a/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Setup.h b/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Setup.h
new file mode 100644 (file)
index 0000000..6cfcf68
--- /dev/null
@@ -0,0 +1,508 @@
+/*++\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
+  Setup.h\r
+\r
+Abstract:\r
+\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+#ifndef _SETUP_H\r
+#define _SETUP_H\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+//\r
+// This is the generated header file which includes whatever needs to be exported (strings + IFR)\r
+//\r
+extern UINT8  SetupBrowserStrings[];\r
+\r
+//\r
+// Screen definitions\r
+//\r
+#define BANNER_HEIGHT                 4\r
+#define BANNER_COLUMNS                3\r
+\r
+#define FRONT_PAGE_HEADER_HEIGHT      4\r
+#define NONE_FRONT_PAGE_HEADER_HEIGHT 3\r
+#define LEFT_SKIPPED_COLUMNS          4\r
+#define FOOTER_HEIGHT                 4\r
+#define STATUS_BAR_HEIGHT             1\r
+#define SCROLL_ARROW_HEIGHT           1\r
+#define POPUP_PAD_SPACE_COUNT         5\r
+#define POPUP_FRAME_WIDTH             2\r
+\r
+\r
+#define EFI_SETUP_APPLICATION_SUBCLASS    0x00\r
+#define EFI_GENERAL_APPLICATION_SUBCLASS  0x01\r
+#define EFI_FRONT_PAGE_SUBCLASS           0x02\r
+#define EFI_SINGLE_USE_SUBCLASS           0x03  // Used to display a single entity and then exit\r
+//\r
+// Definition for function key setting\r
+//\r
+#define NONE_FUNCTION_KEY_SETTING     0\r
+#define DEFAULT_FUNCTION_KEY_SETTING  (FUNCTION_ONE | FUNCTION_TWO | FUNCTION_NINE | FUNCTION_TEN)\r
+\r
+#define FUNCTION_ONE                  (1 << 0)\r
+#define FUNCTION_TWO                  (1 << 1)\r
+#define FUNCTION_NINE                 (1 << 2)\r
+#define FUNCTION_TEN                  (1 << 3)\r
+\r
+typedef struct {\r
+  EFI_GUID  FormSetGuid;\r
+  UINTN     KeySetting;\r
+} FUNCTIION_KEY_SETTING;\r
+\r
+//\r
+// Character definitions\r
+//\r
+#define CHAR_SPACE              0x0020\r
+#define UPPER_LOWER_CASE_OFFSET 0x20\r
+\r
+//\r
+// Time definitions\r
+//\r
+#define ONE_SECOND  10000000\r
+\r
+//\r
+// Display definitions\r
+//\r
+#define LEFT_HYPER_DELIMITER      L'<'\r
+#define RIGHT_HYPER_DELIMITER     L'>'\r
+\r
+#define LEFT_ONEOF_DELIMITER      L'<'\r
+#define RIGHT_ONEOF_DELIMITER     L'>'\r
+\r
+#define LEFT_NUMERIC_DELIMITER    L'['\r
+#define RIGHT_NUMERIC_DELIMITER   L']'\r
+\r
+#define LEFT_CHECKBOX_DELIMITER   L"["\r
+#define RIGHT_CHECKBOX_DELIMITER  L"]"\r
+\r
+#define CHECK_ON                  L"X"\r
+#define CHECK_OFF                 L" "\r
+\r
+#define TIME_SEPARATOR            L':'\r
+#define DATE_SEPARATOR            L'/'\r
+\r
+#define YES_ANSWER                L'Y'\r
+#define NO_ANSWER                 L'N'\r
+\r
+//\r
+// Up to how many lines does the ordered list display\r
+//\r
+#define ORDERED_LIST_SIZE 4\r
+\r
+//\r
+// This is the Input Error Message\r
+//\r
+#define INPUT_ERROR 1\r
+\r
+//\r
+// This is the NV RAM update required Message\r
+//\r
+#define NV_UPDATE_REQUIRED  2\r
+\r
+//\r
+// Refresh the Status Bar with flags\r
+//\r
+#define REFRESH_STATUS_BAR  0xff\r
+\r
+//\r
+// This width is basically the sum of the prompt and option widths\r
+//\r
+#define QUESTION_BLOCK_WIDTH  50\r
+\r
+//\r
+// Width of the Language Description (Using ISO-639-2 3 ASCII letter standard)\r
+//\r
+#define LANG_DESC_WIDTH 3\r
+\r
+//\r
+// Maximum Number of Binaries we can see\r
+//\r
+#define MAX_BINARIES  255\r
+\r
+//\r
+// Invalid Handle\r
+//\r
+#define EFI_HII_INVALID_HANDLE  0xFFFF\r
+\r
+//\r
+// Invalid Offset Value\r
+//\r
+#define INVALID_OFFSET_VALUE  0xFFFF\r
+\r
+struct StringPart {\r
+  struct StringPart *Next;\r
+  CHAR8             String[QUESTION_BLOCK_WIDTH + 2];\r
+};\r
+\r
+//\r
+// The tag definition defines the data associated with a tag (an operation\r
+// in the IFR lingo).  The tag is thus a modified union of all the data\r
+// required for tags.  The user should be careful to only rely upon information\r
+// relevant to that tag as the contents of other fields is undefined.\r
+//\r
+// The intent here is for this to be all of the data associated with a particular tag.\r
+// Some of this data is extracted from the IFR and left alone.  Other data will be derived\r
+// when the page is selected (since that's the first time we really know what language the\r
+// page is to be displayed in) and still other data will vary based on the selection.\r
+// If you'd like to consider alternatives, let me know.  This structure has grown somewhat organically.\r
+// It gets a new item stuffed in it when a new item is needed.  When I finally decided I needed the\r
+// StringPart structure, items got added here, for example.\r
+//\r
+typedef struct {\r
+  UINT8                 Operand;        // The operand (first byte) of the variable length tag.\r
+  EFI_GUID              GuidValue;      // Primarily for FormSet data\r
+  EFI_PHYSICAL_ADDRESS  CallbackHandle;\r
+  UINT16                Class;\r
+  UINT16                SubClass;\r
+  UINT16                NumberOfLines;  // The number of lines the tag takes up on the page.  Adjusted when we display the page as it can change from language to language.\r
+  UINT16                PageLine;\r
+  UINT16                PageColumn;\r
+  UINT16                OptionWidth;    // The option can be wider than the column usually associated with options.  This is the width on the last option line\r
+  STRING_REF            Text;           // Used for title, subtitle, prompt, etc.  This is the string token associated with the string.  This token is language independent.\r
+  STRING_REF            TextTwo;        // Used for title, subtitle, prompt, etc.  This is the string token associated with the string.  This token is language independent.\r
+  STRING_REF            Help;           // Null means no help  Same as above but for languages.\r
+  UINT16                Consistency;    // Do we need to check this opcode against consistency?  If > 0, yes.\r
+  UINT16                Id;\r
+  UINT16                Id2;            // The questions (mainly) have identifiers associated with them.  These are filled in from the IFR tags and used by e.g. the RPN calculations. (com1 is set to, versus com2 is set to)\r
+  //\r
+  // These are the three values that are created to determine where in the variable the data is stored.  This should, in general,\r
+  // be allocated by the build tool.  The one major issue is, once storage is allocated for something, it can't be reallocated or we will get a mess.\r
+  //\r
+  UINT16                StorageStart;\r
+  //\r
+  // These are the three values that are created to determine where in the variable the data is stored.  This should, in general,\r
+  // be allocated by the build tool.  The one major issue is, once storage is allocated for something, it can't be reallocated or we will get a mess.\r
+  //\r
+  UINT8                 StorageWidth;\r
+  //\r
+  // These are the three values that are created to determine where in the variable the data is stored.  This should, in general,\r
+  // be allocated by the build tool.  The one major issue is, once storage is allocated for something, it can't be reallocated or we will get a mess.\r
+  //\r
+  UINT16                Value;\r
+  //\r
+  // (Default or current)\r
+  //\r
+  UINT8                 Flags;\r
+  UINT16                Key;\r
+  //\r
+  // Used to preserve a value during late consistency checking\r
+  //\r
+  UINT16                OldValue;\r
+  UINT16                Minimum;\r
+  UINT16                Maximum;\r
+  UINT16                Step;\r
+  UINT16                Default;\r
+  UINT16                NvDataSize;\r
+  UINT16                ConsistencyId;\r
+  BOOLEAN               GrayOut;\r
+  BOOLEAN               Suppress;\r
+  UINT16                Encoding;     // Data from the tags.  The first three are used by the numeric input.  Encoding is used by the password stuff (a placeholder today - may go away).\r
+  UINT16                *IntList;     // List of the values possible for a list question\r
+  //\r
+  // The string is obtained from the string list and formatted into lines and the lines are held in this linked list.\r
+  // If we have more than a screen's worth of items, we will end up with cases where we have to display the last couple\r
+  // lines of a tag's string above the currently selected one, or, display a few lines of a tag at the bottom of a screen.\r
+  //\r
+  struct StringPart     *StringList;\r
+  BOOLEAN               ResetRequired;    // Primarily used to determine if a reset is required by changing this op-code.\r
+  UINT16                VariableNumber;   // Used to define which variable the StorageStart will be pertinent for (0-based)  For single variable VFR this will always be 0.\r
+  //\r
+  // Used to define which variable the StorageStart will be pertinent for (0-based)  This is used for boolean check of ID versus ID\r
+  // so that a user can compare the value of one variable.field content versus another variable.field content.\r
+  //\r
+  UINT16                VariableNumber2;\r
+} EFI_TAG;\r
+\r
+#define EFI_FORM_DATA_SIGNATURE EFI_SIGNATURE_32 ('F', 'o', 'r', 'm')\r
+\r
+typedef struct {\r
+  UINTN                     Signature;\r
+\r
+  EFI_HII_PROTOCOL          *Hii;\r
+  EFI_FORM_BROWSER_PROTOCOL FormConfig;\r
+} EFI_FORM_CONFIGURATION_DATA;\r
+\r
+#define EFI_FORM_DATA_FROM_THIS(a)  CR (a, EFI_FORM_CONFIGURATION_DATA, FormConfig, EFI_FORM_DATA_SIGNATURE)\r
+\r
+typedef struct _EFI_VARIABLE_DEFINITION {\r
+  CHAR8                           *NvRamMap;\r
+  CHAR8                           *FakeNvRamMap;    // This is where the storage for NULL devices go (e.g. RTC)\r
+  EFI_GUID                        Guid;\r
+  UINT16                          VariableId;\r
+  UINT16                          VariableSize;\r
+  UINT16                          VariableFakeSize; // For dynamically created and NULL device options, this is the latest size\r
+  CHAR16                          *VariableName;\r
+  struct _EFI_VARIABLE_DEFINITION *Next;\r
+  struct _EFI_VARIABLE_DEFINITION *Previous;\r
+} EFI_VARIABLE_DEFINITION;\r
+\r
+typedef struct {\r
+  UINT32      Length;                               // Length in bytes between beginning of struc and end of Strings\r
+  CHAR8       LanguageCode[4];                      // ISO-639-2 language code with a null-terminator\r
+  RELOFST     PrintableLanguageName;                // Translated name of the Language, "English"/"Espanol" etc\r
+  UINT32      Attributes;                           // If on, the language is intended to be printed right to left.  The default (off) is to print left to right.\r
+  RELOFST     StringsPointers[1];                   // Pointing to string offset from beginning of String Binary\r
+  EFI_STRING  Strings[1];                           // Array of String Entries.  Note the number of entries for Strings and StringsPointers will be the same\r
+} EFI_LANGUAGE_SET;\r
+\r
+//\r
+// This encapsulates all the pointers associated with found IFR binaries\r
+//\r
+typedef struct _EFI_IFR_BINARY {\r
+  struct _EFI_IFR_BINARY  *Next;\r
+  VOID                    *IfrPackage;  // Handy for use in freeing the data later since this is the header of the buffer\r
+  VOID                    *FormBinary;\r
+  EFI_HII_HANDLE          Handle;\r
+  STRING_REF              TitleToken;\r
+  BOOLEAN                 UnRegisterOnExit;\r
+} EFI_IFR_BINARY;\r
+\r
+//\r
+// This encapsulates all the questions (tags) for a particular Form Set\r
+//\r
+typedef struct _EFI_FORM_TAGS {\r
+  struct _EFI_FORM_TAGS *Next;\r
+  EFI_TAG               *Tags;\r
+} EFI_FORM_TAGS;\r
+\r
+//\r
+// This is the database of all inconsistency data.  Each op-code associated\r
+// with inconsistency will be tracked here.  This optimizes the search requirement\r
+// since we will back mark the main tag structure with the op-codes that have reference\r
+// to inconsistency data.  This way when parsing the main tag structure and encountering\r
+// the inconsistency mark - we can search this database to know what the inconsistency\r
+// parameters are for that entry.\r
+//\r
+typedef struct _EFI_INCONSISTENCY_DATA {\r
+  struct _EFI_INCONSISTENCY_DATA  *Next;\r
+  struct _EFI_INCONSISTENCY_DATA  *Previous;\r
+  UINT8                           Operand;\r
+  STRING_REF                      Popup;\r
+  UINT16                          QuestionId1;\r
+  UINT16                          QuestionId2;\r
+  UINT16                          Value;\r
+  UINT16                          ListLength;\r
+  UINT16                          ConsistencyId;\r
+  UINT16                          *ValueList;\r
+  UINT16                          VariableNumber;\r
+  UINT16                          VariableNumber2;\r
+  UINT8                           Width;\r
+} EFI_INCONSISTENCY_DATA;\r
+\r
+//\r
+// Encapsulating all found Tag information from all sources\r
+// Each encapsulation also contains the NvRamMap buffer and the Size of the NV store\r
+//\r
+typedef struct _EFI_FILE_FORM_TAGS {\r
+  struct _EFI_FILE_FORM_TAGS  *NextFile;\r
+  EFI_INCONSISTENCY_DATA      *InconsistentTags;\r
+  EFI_VARIABLE_DEFINITION     *VariableDefinitions;\r
+  EFI_FORM_TAGS               FormTags;\r
+} EFI_FILE_FORM_TAGS;\r
+\r
+typedef struct {\r
+  STRING_REF  Banner[BANNER_HEIGHT][BANNER_COLUMNS];\r
+} BANNER_DATA;\r
+\r
+//\r
+// Head of the Binary structures\r
+//\r
+EFI_IFR_BINARY    *gBinaryDataHead;\r
+\r
+//\r
+// The IFR binary that the user chose to run\r
+//\r
+UINTN             gActiveIfr;\r
+\r
+EFI_HII_PROTOCOL  *Hii;\r
+\r
+VOID              *CachedNVEntry;\r
+BANNER_DATA       *BannerData;\r
+EFI_HII_HANDLE    FrontPageHandle;\r
+STRING_REF        FrontPageTimeOutTitle;\r
+INT16             FrontPageTimeOutValue;\r
+UINTN             gClassOfVfr;\r
+UINTN             gFunctionKeySetting;\r
+BOOLEAN           gResetRequired;\r
+BOOLEAN           gExitRequired;\r
+BOOLEAN           gSaveRequired;\r
+BOOLEAN           gNvUpdateRequired;\r
+UINT16            gConsistencyId;\r
+UINTN             gPriorMenuEntry;\r
+EFI_HII_HANDLE    gHiiHandle;\r
+BOOLEAN           gFirstIn;\r
+VOID              *gPreviousValue;\r
+UINT16            gDirection;\r
+EFI_SCREEN_DESCRIPTOR gScreenDimensions;\r
+BOOLEAN           gUpArrow;\r
+BOOLEAN           gDownArrow;\r
+BOOLEAN           gTimeOnScreen;\r
+BOOLEAN           gDateOnScreen;\r
+\r
+//\r
+// Browser Global Strings\r
+//\r
+CHAR16            *gFunctionOneString;\r
+CHAR16            *gFunctionTwoString;\r
+CHAR16            *gFunctionNineString;\r
+CHAR16            *gFunctionTenString;\r
+CHAR16            *gEnterString;\r
+CHAR16            *gEnterCommitString;\r
+CHAR16            *gEscapeString;\r
+CHAR16            *gMoveHighlight;\r
+CHAR16            *gMakeSelection;\r
+CHAR16            *gNumericInput;\r
+CHAR16            *gToggleCheckBox;\r
+CHAR16            *gPromptForPassword;\r
+CHAR16            *gPromptForNewPassword;\r
+CHAR16            *gConfirmPassword;\r
+CHAR16            *gConfirmError;\r
+CHAR16            *gPressEnter;\r
+CHAR16            *gEmptyString;\r
+CHAR16            *gAreYouSure;\r
+CHAR16            *gYesResponse;\r
+CHAR16            *gNoResponse;\r
+CHAR16            *gMiniString;\r
+CHAR16            *gPlusString;\r
+CHAR16            *gMinusString;\r
+CHAR16            *gAdjustNumber;\r
+\r
+CHAR16            gPromptBlockWidth;\r
+CHAR16            gOptionBlockWidth;\r
+CHAR16            gHelpBlockWidth;\r
+\r
+//\r
+// Global Procedure Defines\r
+//\r
+VOID\r
+InitializeBrowserStrings (\r
+  VOID\r
+  )\r
+;\r
+\r
+UINTN\r
+Print (\r
+  IN CHAR16                         *fmt,\r
+  ...\r
+  )\r
+;\r
+\r
+UINTN\r
+PrintString (\r
+  CHAR16       *String\r
+  )\r
+;\r
+\r
+UINTN\r
+PrintChar (\r
+  CHAR16       Character\r
+  )\r
+;\r
+\r
+UINTN\r
+PrintAt (\r
+  IN UINTN     Column,\r
+  IN UINTN     Row,\r
+  IN CHAR16    *fmt,\r
+  ...\r
+  )\r
+;\r
+\r
+UINTN\r
+PrintStringAt (\r
+  IN UINTN     Column,\r
+  IN UINTN     Row,\r
+  CHAR16       *String\r
+  )\r
+;\r
+\r
+UINTN\r
+PrintCharAt (\r
+  IN UINTN     Column,\r
+  IN UINTN     Row,\r
+  CHAR16       Character\r
+  )\r
+;\r
+\r
+VOID\r
+DisplayPageFrame (\r
+  VOID\r
+  )\r
+;\r
+\r
+CHAR16            *\r
+GetToken (\r
+  IN  STRING_REF                              IfrBinaryTitle,\r
+  IN  EFI_HII_HANDLE                          HiiHandle\r
+  )\r
+;\r
+\r
+VOID\r
+GetTagCount (\r
+  IN      UINT8                                 *RawFormSet,\r
+  IN OUT  UINT16                                *NumberOfTags\r
+  )\r
+;\r
+\r
+VOID\r
+GetNumericHeader (\r
+  IN  EFI_TAG             *Tag,\r
+  IN  UINT8               *RawFormSet,\r
+  IN  UINT16              Index,\r
+  IN  UINT16              NumberOfLines,\r
+  IN  EFI_FILE_FORM_TAGS  *FileFormTags,\r
+  IN  UINT16              CurrentVariable\r
+  )\r
+;\r
+\r
+VOID\r
+GetQuestionHeader (\r
+  IN  EFI_TAG             *Tag,\r
+  IN  UINT8               *RawFormSet,\r
+  IN  UINT16              Index,\r
+  IN  EFI_FILE_FORM_TAGS  *FileFormTags,\r
+  IN  UINT16              CurrentVariable\r
+  )\r
+;\r
+\r
+VOID\r
+CreateSharedPopUp (\r
+  IN  UINTN                       RequestedWidth,\r
+  IN  UINTN                       NumberOfLines,\r
+  IN  CHAR16                      **ArrayOfStrings\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+CreateDialog (\r
+  IN  UINTN                       NumberOfLines,\r
+  IN  BOOLEAN                     HotKey,\r
+  IN  UINTN                       MaximumStringSize,\r
+  OUT CHAR16                      *StringBuffer,\r
+  OUT EFI_INPUT_KEY               *KeyValue,\r
+  IN  CHAR16                      *String,\r
+  ...\r
+  )\r
+;\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/SetupBrowser.inf b/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/SetupBrowser.inf
new file mode 100644 (file)
index 0000000..22f65e6
--- /dev/null
@@ -0,0 +1,108 @@
+#/** @file\r
+# Component description file for SetupBrowser module.\r
+#\r
+# This driver initializes Setup for the brower and installs FormBrowser protocol.\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                      = SetupBrowser\r
+  FILE_GUID                      = EBf342FE-B1D3-4EF8-957C-8048606FF670\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeSetup\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
+#  Create Event Guid C Name: EFI_EVENT_TIMER Event Type: EVENT_GROUP_GUID\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
+  Colors.h\r
+  Ui.h\r
+  Ui.c\r
+  ProcessOptions.c\r
+  Presentation.c\r
+  Print.h\r
+  Print.c\r
+  InputHandler.c\r
+  Boolean.c\r
+  Setup.h\r
+  Setup.c\r
+  SetupBrowserStr.uni\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
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.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
+  EdkGraphicsLib\r
+  FrameworkHiiLib\r
+  UefiRuntimeServicesTableLib\r
+  UefiBootServicesTableLib\r
+  PrintLib\r
+  UefiDriverEntryPoint\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  BaseLib\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
+  gEfiPrintProtocolGuid                         # PROTOCOL ALWAYS_PRODUCED\r
+  gEfiFormBrowserProtocolGuid                   # PROTOCOL ALWAYS_PRODUCED\r
+  gEfiFormCallbackProtocolGuid                  # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiHiiProtocolGuid                           # PROTOCOL ALWAYS_CONSUMED\r
+\r
diff --git a/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/SetupBrowser.msa b/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/SetupBrowser.msa
new file mode 100644 (file)
index 0000000..d3a0bd3
--- /dev/null
@@ -0,0 +1,102 @@
+<?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>SetupBrowser</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>EBf342FE-B1D3-4EF8-957C-8048606FF670</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for SetupBrowser module.</Abstract>\r
+    <Description>This driver initializes Setup for the brower and installs FormBrowser protocol.</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>SetupBrowser</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</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>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PrintLib</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>HiiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>EdkGraphicsLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>SetupBrowserStr.uni</Filename>\r
+    <Filename>Setup.c</Filename>\r
+    <Filename>Setup.h</Filename>\r
+    <Filename>Boolean.c</Filename>\r
+    <Filename>InputHandler.c</Filename>\r
+    <Filename>Print.c</Filename>\r
+    <Filename>Print.h</Filename>\r
+    <Filename>Presentation.c</Filename>\r
+    <Filename>ProcessOptions.c</Filename>\r
+    <Filename>Ui.c</Filename>\r
+    <Filename>Ui.h</Filename>\r
+    <Filename>Colors.h</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="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiHiiProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiFormCallbackProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiFormBrowserProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiPrintProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Events>\r
+    <CreateEvents>\r
+      <EventTypes EventGuidCName="EFI_EVENT_TIMER" Usage="ALWAYS_CONSUMED">\r
+        <EventType>EVENT_GROUP_GUID</EventType>\r
+      </EventTypes>\r
+    </CreateEvents>\r
+  </Events>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>InitializeSetup</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/SetupBrowserStr.uni b/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/SetupBrowserStr.uni
new file mode 100644 (file)
index 0000000..feb82c2
Binary files /dev/null and b/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/SetupBrowserStr.uni differ
diff --git a/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Ui.c b/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Ui.c
new file mode 100644 (file)
index 0000000..8a514a0
--- /dev/null
@@ -0,0 +1,3155 @@
+/**@file\r
+  Implementation for UI.\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
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "Setup.h"\r
+#include "Ui.h"\r
+#include "Colors.h"\r
+\r
+//\r
+// Implementation\r
+//\r
+VOID\r
+SetUnicodeMem (\r
+  IN VOID   *Buffer,\r
+  IN UINTN  Size,\r
+  IN CHAR16 Value\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Set Buffer to Value for Size bytes.\r
+\r
+Arguments:\r
+\r
+  Buffer  - Memory to set.\r
+\r
+  Size    - Number of bytes to set\r
+\r
+  Value   - Value of the set operation.\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  CHAR16  *Ptr;\r
+\r
+  Ptr = Buffer;\r
+  while (Size--) {\r
+    *(Ptr++) = Value;\r
+  }\r
+}\r
+\r
+VOID\r
+UiInitMenu (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Initialize Menu option list.\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  InitializeListHead (&Menu);\r
+}\r
+\r
+VOID\r
+UiInitMenuList (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Initialize Menu option list.\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  InitializeListHead (&gMenuList);\r
+}\r
+\r
+VOID\r
+UiRemoveMenuListEntry (\r
+  IN  UI_MENU_OPTION    *Selection,\r
+  OUT UI_MENU_OPTION    **PreviousSelection\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Remove Menu option list.\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  UI_MENU_LIST  *UiMenuList;\r
+\r
+  *PreviousSelection = AllocateZeroPool (sizeof (UI_MENU_OPTION));\r
+  ASSERT (*PreviousSelection != NULL);\r
+\r
+  if (!IsListEmpty (&gMenuList)) {\r
+    UiMenuList                      = CR (gMenuList.ForwardLink, UI_MENU_LIST, MenuLink, UI_MENU_LIST_SIGNATURE);\r
+    (*PreviousSelection)->IfrNumber = UiMenuList->Selection.IfrNumber;\r
+    (*PreviousSelection)->FormId    = UiMenuList->Selection.FormId;\r
+    (*PreviousSelection)->Tags      = UiMenuList->Selection.Tags;\r
+    (*PreviousSelection)->ThisTag   = UiMenuList->Selection.ThisTag;\r
+    (*PreviousSelection)->Handle    = UiMenuList->Selection.Handle;\r
+    gEntryNumber                    = UiMenuList->FormerEntryNumber;\r
+    RemoveEntryList (&UiMenuList->MenuLink);\r
+    FreePool (UiMenuList);\r
+  }\r
+}\r
+\r
+VOID\r
+UiFreeMenuList (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Free Menu option linked list.\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  UI_MENU_LIST  *UiMenuList;\r
+\r
+  while (!IsListEmpty (&gMenuList)) {\r
+    UiMenuList = CR (gMenuList.ForwardLink, UI_MENU_LIST, MenuLink, UI_MENU_LIST_SIGNATURE);\r
+    RemoveEntryList (&UiMenuList->MenuLink);\r
+    FreePool (UiMenuList);\r
+  }\r
+}\r
+\r
+VOID\r
+UiAddMenuListEntry (\r
+  IN UI_MENU_OPTION   *Selection\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Add one menu entry to the linked lst\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  UI_MENU_LIST  *UiMenuList;\r
+\r
+  UiMenuList = AllocateZeroPool (sizeof (UI_MENU_LIST));\r
+  ASSERT (UiMenuList != NULL);\r
+\r
+  UiMenuList->Signature = UI_MENU_LIST_SIGNATURE;\r
+  CopyMem (&UiMenuList->Selection, Selection, sizeof (UI_MENU_OPTION));\r
+\r
+  InsertHeadList (&gMenuList, &UiMenuList->MenuLink);\r
+}\r
+\r
+VOID\r
+UiFreeMenu (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Free Menu option linked list.\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  UI_MENU_OPTION  *MenuOption;\r
+\r
+  while (!IsListEmpty (&Menu)) {\r
+    MenuOption = CR (Menu.ForwardLink, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+    RemoveEntryList (&MenuOption->Link);\r
+\r
+    //\r
+    // We allocated space for this description when we did a GetToken, free it here\r
+    //\r
+    FreePool (MenuOption->Description);\r
+    FreePool (MenuOption);\r
+  }\r
+}\r
+\r
+STATIC\r
+VOID\r
+UpdateDateAndTime (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Refresh screen with current date and/or time based on screen context\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  CHAR16              *OptionString;\r
+  MENU_REFRESH_ENTRY  *MenuRefreshEntry;\r
+  UINTN               Index;\r
+  UINTN               Loop;\r
+\r
+  OptionString = NULL;\r
+\r
+  if (gMenuRefreshHead != NULL) {\r
+\r
+    MenuRefreshEntry = gMenuRefreshHead;\r
+\r
+    do {\r
+      gST->ConOut->SetAttribute (gST->ConOut, MenuRefreshEntry->CurrentAttribute);\r
+      ProcessOptions (MenuRefreshEntry->MenuOption, FALSE, MenuRefreshEntry->FileFormTagsHead, NULL, &OptionString);\r
+\r
+      if (OptionString != NULL) {\r
+        //\r
+        // If leading spaces on OptionString - remove the spaces\r
+        //\r
+        for (Index = 0; OptionString[Index] == L' '; Index++)\r
+          ;\r
+\r
+        for (Loop = 0; OptionString[Index] != CHAR_NULL; Index++) {\r
+          OptionString[Loop] = OptionString[Index];\r
+          Loop++;\r
+        }\r
+\r
+        OptionString[Loop] = CHAR_NULL;\r
+\r
+        PrintStringAt (MenuRefreshEntry->CurrentColumn, MenuRefreshEntry->CurrentRow, OptionString);\r
+      }\r
+\r
+      MenuRefreshEntry = MenuRefreshEntry->Next;\r
+\r
+    } while (MenuRefreshEntry != NULL);\r
+  }\r
+\r
+  if (OptionString != NULL) {\r
+    FreePool (OptionString);\r
+  }\r
+}\r
+\r
+EFI_STATUS\r
+UiWaitForSingleEvent (\r
+  IN EFI_EVENT                Event,\r
+  IN UINT64                   Timeout OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Wait for a given event to fire, or for an optional timeout to expire.\r
+\r
+Arguments:\r
+  Event            - The event to wait for\r
+\r
+  Timeout          - An optional timeout value in 100 ns units.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS      - Event fired before Timeout expired.\r
+  EFI_TIME_OUT     - Timout expired before Event fired.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINTN       Index;\r
+  EFI_EVENT   TimerEvent;\r
+  EFI_EVENT   WaitList[2];\r
+\r
+  if (Timeout) {\r
+    //\r
+    // Create a timer event\r
+    //\r
+    Status = gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimerEvent);\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Set the timer event\r
+      //\r
+      gBS->SetTimer (\r
+            TimerEvent,\r
+            TimerRelative,\r
+            Timeout\r
+            );\r
+\r
+      //\r
+      // Wait for the original event or the timer\r
+      //\r
+      WaitList[0] = Event;\r
+      WaitList[1] = TimerEvent;\r
+      Status      = gBS->WaitForEvent (2, WaitList, &Index);\r
+      gBS->CloseEvent (TimerEvent);\r
+\r
+      //\r
+      // If the timer expired, change the return to timed out\r
+      //\r
+      if (!EFI_ERROR (Status) && Index == 1) {\r
+        Status = EFI_TIMEOUT;\r
+      }\r
+    }\r
+  } else {\r
+    //\r
+    // Update screen every second\r
+    //\r
+    Timeout = ONE_SECOND;\r
+\r
+    do {\r
+      Status = gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimerEvent);\r
+\r
+      //\r
+      // Set the timer event\r
+      //\r
+      gBS->SetTimer (\r
+            TimerEvent,\r
+            TimerRelative,\r
+            Timeout\r
+            );\r
+\r
+      //\r
+      // Wait for the original event or the timer\r
+      //\r
+      WaitList[0] = Event;\r
+      WaitList[1] = TimerEvent;\r
+      Status      = gBS->WaitForEvent (2, WaitList, &Index);\r
+\r
+      //\r
+      // If the timer expired, update anything that needs a refresh and keep waiting\r
+      //\r
+      if (!EFI_ERROR (Status) && Index == 1) {\r
+        Status = EFI_TIMEOUT;\r
+        UpdateDateAndTime ();\r
+      }\r
+\r
+      gBS->CloseEvent (TimerEvent);\r
+    } while (Status == EFI_TIMEOUT);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+VOID\r
+UiAddMenuOption (\r
+  IN CHAR16         *String,\r
+  IN EFI_HII_HANDLE Handle,\r
+  IN EFI_TAG        *Tags,\r
+  IN VOID           *FormBinary,\r
+  IN UINTN          IfrNumber\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Add one menu option by specified description and context.\r
+\r
+Arguments:\r
+  String - String description for this option.\r
+  Context - Context data for entry.\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  UI_MENU_OPTION  *MenuOption;\r
+\r
+  MenuOption = AllocateZeroPool (sizeof (UI_MENU_OPTION));\r
+  ASSERT (MenuOption);\r
+\r
+  MenuOption->Signature   = UI_MENU_OPTION_SIGNATURE;\r
+  MenuOption->Description = String;\r
+  MenuOption->Handle      = Handle;\r
+  MenuOption->FormBinary  = FormBinary;\r
+  MenuOption->IfrNumber   = IfrNumber;\r
+  MenuOption->Skip        = 1;\r
+  MenuOption->Tags        = Tags;\r
+  MenuOption->TagIndex    = 0;\r
+  MenuOption->ThisTag     = &(MenuOption->Tags[MenuOption->TagIndex]);\r
+  MenuOption->EntryNumber = (UINT16) IfrNumber;\r
+\r
+  InsertTailList (&Menu, &MenuOption->Link);\r
+}\r
+\r
+VOID\r
+UiAddSubMenuOption (\r
+  IN CHAR16           *String,\r
+  IN EFI_HII_HANDLE   Handle,\r
+  IN EFI_TAG          *Tags,\r
+  IN UINTN            TagIndex,\r
+  IN UINT16           FormId,\r
+  IN UINT16           MenuItemCount\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Add one menu option by specified description and context.\r
+\r
+Arguments:\r
+  String - String description for this option.\r
+  Context - Context data for entry.\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  UI_MENU_OPTION  *MenuOption;\r
+\r
+  MenuOption = AllocateZeroPool (sizeof (UI_MENU_OPTION));\r
+  ASSERT (MenuOption);\r
+\r
+  MenuOption->Signature   = UI_MENU_OPTION_SIGNATURE;\r
+  MenuOption->Description = String;\r
+  MenuOption->Handle      = Handle;\r
+  MenuOption->Skip        = Tags[TagIndex].NumberOfLines;\r
+  MenuOption->IfrNumber   = gActiveIfr;\r
+  MenuOption->Tags        = Tags;\r
+  MenuOption->TagIndex    = TagIndex;\r
+  MenuOption->ThisTag     = &(MenuOption->Tags[MenuOption->TagIndex]);\r
+  MenuOption->Consistency = Tags[TagIndex].Consistency;\r
+  MenuOption->FormId      = FormId;\r
+  MenuOption->GrayOut     = Tags[TagIndex].GrayOut;\r
+  MenuOption->EntryNumber = MenuItemCount;\r
+\r
+  InsertTailList (&Menu, &MenuOption->Link);\r
+}\r
+\r
+EFI_STATUS\r
+CreateDialog (\r
+  IN  UINTN                       NumberOfLines,\r
+  IN  BOOLEAN                     HotKey,\r
+  IN  UINTN                       MaximumStringSize,\r
+  OUT CHAR16                      *StringBuffer,\r
+  OUT EFI_INPUT_KEY               *KeyValue,\r
+  IN  CHAR16                      *String,\r
+  ...\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Routine used to abstract a generic dialog interface and return the selected key or string\r
+\r
+Arguments:\r
+  NumberOfLines -     The number of lines for the dialog box\r
+  HotKey -            Defines whether a single character is parsed (TRUE) and returned in KeyValue\r
+                      or a string is returned in StringBuffer.  Two special characters are considered when entering a string, a SCAN_ESC and\r
+                      an CHAR_CARRIAGE_RETURN.  SCAN_ESC terminates string input and returns\r
+  MaximumStringSize - The maximum size in bytes of a typed in string (each character is a CHAR16) and the minimum string returned is two bytes\r
+  StringBuffer -      The passed in pointer to the buffer which will hold the typed in string if HotKey is FALSE\r
+  KeyValue -          The EFI_KEY value returned if HotKey is TRUE..\r
+  String -            Pointer to the first string in the list\r
+  ... -               A series of (quantity == NumberOfLines) text strings which will be used to construct the dialog box\r
+\r
+Returns:\r
+  EFI_SUCCESS -           Displayed dialog and received user interaction\r
+  EFI_INVALID_PARAMETER - One of the parameters was invalid (e.g. (StringBuffer == NULL) && (HotKey == FALSE))\r
+  EFI_DEVICE_ERROR -      User typed in an ESC character to exit the routine\r
+\r
+--*/\r
+{\r
+  VA_LIST       Marker;\r
+  UINTN         Count;\r
+  EFI_INPUT_KEY Key;\r
+  UINTN         LargestString;\r
+  CHAR16        *TempString;\r
+  CHAR16        *BufferedString;\r
+  CHAR16        *StackString;\r
+  CHAR16        KeyPad[2];\r
+  UINTN         Start;\r
+  UINTN         Top;\r
+  UINTN         Index;\r
+  BOOLEAN       SelectionComplete;\r
+  UINTN         InputOffset;\r
+  UINTN         CurrentAttribute;\r
+  UINTN         DimensionsWidth;\r
+  UINTN         DimensionsHeight;\r
+\r
+  DimensionsWidth   = gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn;\r
+  DimensionsHeight  = gScreenDimensions.BottomRow - gScreenDimensions.TopRow;\r
+\r
+  SelectionComplete = FALSE;\r
+  InputOffset       = 0;\r
+  TempString        = AllocateZeroPool (MaximumStringSize * 2);\r
+  BufferedString    = AllocateZeroPool (MaximumStringSize * 2);\r
+  CurrentAttribute  = gST->ConOut->Mode->Attribute;\r
+\r
+  ASSERT (TempString);\r
+  ASSERT (BufferedString);\r
+\r
+  VA_START (Marker, String);\r
+\r
+  //\r
+  // Zero the outgoing buffer\r
+  //\r
+  ZeroMem (StringBuffer, MaximumStringSize);\r
+\r
+  if (HotKey) {\r
+    if (KeyValue == NULL) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  } else {\r
+    if (StringBuffer == NULL) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+  //\r
+  // Disable cursor\r
+  //\r
+  gST->ConOut->EnableCursor (gST->ConOut, FALSE);\r
+\r
+  LargestString = (GetStringWidth (String) / 2);\r
+\r
+  if (LargestString == L' ') {\r
+    InputOffset = 1;\r
+  }\r
+  //\r
+  // Determine the largest string in the dialog box\r
+  // Notice we are starting with 1 since String is the first string\r
+  //\r
+  for (Count = 1; Count < NumberOfLines; Count++) {\r
+    StackString = VA_ARG (Marker, CHAR16 *);\r
+\r
+    if (StackString[0] == L' ') {\r
+      InputOffset = Count + 1;\r
+    }\r
+\r
+    if ((GetStringWidth (StackString) / 2) > LargestString) {\r
+      //\r
+      // Size of the string visually and subtract the width by one for the null-terminator\r
+      //\r
+      LargestString = (GetStringWidth (StackString) / 2);\r
+    }\r
+  }\r
+\r
+  Start = (DimensionsWidth - LargestString - 2) / 2 + gScreenDimensions.LeftColumn + 1;\r
+  Top   = ((DimensionsHeight - NumberOfLines - 2) / 2) + gScreenDimensions.TopRow - 1;\r
+\r
+  Count = 0;\r
+\r
+  //\r
+  // Display the Popup\r
+  //\r
+  CreateSharedPopUp (LargestString, NumberOfLines, &String);\r
+\r
+  //\r
+  // Take the first key typed and report it back?\r
+  //\r
+  if (HotKey) {\r
+    WaitForKeyStroke (&Key);\r
+    CopyMem (KeyValue, &Key, sizeof (EFI_INPUT_KEY));\r
+\r
+  } else {\r
+    do {\r
+      WaitForKeyStroke (&Key);\r
+\r
+      switch (Key.UnicodeChar) {\r
+      case CHAR_NULL:\r
+        switch (Key.ScanCode) {\r
+        case SCAN_ESC:\r
+          FreePool (TempString);\r
+          FreePool (BufferedString);\r
+          gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute);\r
+          gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
+          return EFI_DEVICE_ERROR;\r
+\r
+        default:\r
+          break;\r
+        }\r
+\r
+        break;\r
+\r
+      case CHAR_CARRIAGE_RETURN:\r
+        SelectionComplete = TRUE;\r
+        FreePool (TempString);\r
+        FreePool (BufferedString);\r
+        gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute);\r
+        gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
+        return EFI_SUCCESS;\r
+        break;\r
+\r
+      case CHAR_BACKSPACE:\r
+        if (StringBuffer[0] != CHAR_NULL) {\r
+          for (Index = 0; StringBuffer[Index] != CHAR_NULL; Index++) {\r
+            TempString[Index] = StringBuffer[Index];\r
+          }\r
+          //\r
+          // Effectively truncate string by 1 character\r
+          //\r
+          TempString[Index - 1] = CHAR_NULL;\r
+          StrCpy (StringBuffer, TempString);\r
+        }\r
+\r
+      default:\r
+        //\r
+        // If it is the beginning of the string, don't worry about checking maximum limits\r
+        //\r
+        if ((StringBuffer[0] == CHAR_NULL) && (Key.UnicodeChar != CHAR_BACKSPACE)) {\r
+          StrnCpy (StringBuffer, &Key.UnicodeChar, 1);\r
+          StrnCpy (TempString, &Key.UnicodeChar, 1);\r
+        } else if ((GetStringWidth (StringBuffer) < MaximumStringSize) && (Key.UnicodeChar != CHAR_BACKSPACE)) {\r
+          KeyPad[0] = Key.UnicodeChar;\r
+          KeyPad[1] = CHAR_NULL;\r
+          StrCat (StringBuffer, KeyPad);\r
+          StrCat (TempString, KeyPad);\r
+        }\r
+        //\r
+        // If the width of the input string is now larger than the screen, we nee to\r
+        // adjust the index to start printing portions of the string\r
+        //\r
+        SetUnicodeMem (BufferedString, LargestString, L' ');\r
+\r
+        PrintStringAt (Start + 1, Top + InputOffset, BufferedString);\r
+\r
+        if ((GetStringWidth (StringBuffer) / 2) > (DimensionsWidth - 2)) {\r
+          Index = (GetStringWidth (StringBuffer) / 2) - DimensionsWidth + 2;\r
+        } else {\r
+          Index = 0;\r
+        }\r
+\r
+        for (Count = 0; Index + 1 < GetStringWidth (StringBuffer) / 2; Index++, Count++) {\r
+          BufferedString[Count] = StringBuffer[Index];\r
+        }\r
+\r
+        PrintStringAt (Start + 1, Top + InputOffset, BufferedString);\r
+        break;\r
+      }\r
+    } while (!SelectionComplete);\r
+  }\r
+\r
+  gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute);\r
+  gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+VOID\r
+CreateSharedPopUp (\r
+  IN  UINTN                       RequestedWidth,\r
+  IN  UINTN                       NumberOfLines,\r
+  IN  CHAR16                      **ArrayOfStrings\r
+  )\r
+{\r
+  UINTN   Index;\r
+  UINTN   Count;\r
+  CHAR16  Character;\r
+  UINTN   Start;\r
+  UINTN   End;\r
+  UINTN   Top;\r
+  UINTN   Bottom;\r
+  CHAR16  *String;\r
+\r
+  UINTN   DimensionsWidth;\r
+  UINTN   DimensionsHeight;\r
+\r
+  DimensionsWidth   = gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn;\r
+  DimensionsHeight  = gScreenDimensions.BottomRow - gScreenDimensions.TopRow;\r
+\r
+  Count             = 0;\r
+\r
+  gST->ConOut->SetAttribute (gST->ConOut, POPUP_TEXT | POPUP_BACKGROUND);\r
+\r
+  if ((RequestedWidth + 2) > DimensionsWidth) {\r
+    RequestedWidth = DimensionsWidth - 2;\r
+  }\r
+  //\r
+  // Subtract the PopUp width from total Columns, allow for one space extra on\r
+  // each end plus a border.\r
+  //\r
+  Start     = (DimensionsWidth - RequestedWidth - 2) / 2 + gScreenDimensions.LeftColumn + 1;\r
+  End       = Start + RequestedWidth + 1;\r
+\r
+  Top       = ((DimensionsHeight - NumberOfLines - 2) / 2) + gScreenDimensions.TopRow - 1;\r
+  Bottom    = Top + NumberOfLines + 2;\r
+\r
+  Character = (CHAR16) BOXDRAW_DOWN_RIGHT;\r
+  PrintCharAt (Start, Top, Character);\r
+  Character = (CHAR16) BOXDRAW_HORIZONTAL;\r
+  for (Index = Start; Index + 2 < End; Index++) {\r
+    PrintChar (Character);\r
+  }\r
+\r
+  Character = (CHAR16) BOXDRAW_DOWN_LEFT;\r
+  PrintChar (Character);\r
+  Character = (CHAR16) BOXDRAW_VERTICAL;\r
+  for (Index = Top; Index + 2 < Bottom; Index++) {\r
+    String = ArrayOfStrings[Count];\r
+    Count++;\r
+\r
+    //\r
+    // This will clear the background of the line - we never know who might have been\r
+    // here before us.  This differs from the next clear in that it used the non-reverse\r
+    // video for normal printing.\r
+    //\r
+    if (GetStringWidth (String) / 2 > 1) {\r
+      ClearLines (Start, End, Index + 1, Index + 1, POPUP_TEXT | POPUP_BACKGROUND);\r
+    }\r
+    //\r
+    // Passing in a space results in the assumption that this is where typing will occur\r
+    //\r
+    if (String[0] == L' ') {\r
+      ClearLines (Start + 1, End - 1, Index + 1, Index + 1, POPUP_INVERSE_TEXT | POPUP_INVERSE_BACKGROUND);\r
+    }\r
+    //\r
+    // Passing in a NULL results in a blank space\r
+    //\r
+    if (String[0] == CHAR_NULL) {\r
+      ClearLines (Start, End, Index + 1, Index + 1, POPUP_TEXT | POPUP_BACKGROUND);\r
+    }\r
+\r
+    PrintStringAt (\r
+      ((DimensionsWidth - GetStringWidth (String) / 2) / 2) + gScreenDimensions.LeftColumn + 1,\r
+      Index + 1,\r
+      String\r
+      );\r
+    gST->ConOut->SetAttribute (gST->ConOut, POPUP_TEXT | POPUP_BACKGROUND);\r
+    PrintCharAt (Start, Index + 1, Character);\r
+    PrintCharAt (End - 1, Index + 1, Character);\r
+  }\r
+\r
+  Character = (CHAR16) BOXDRAW_UP_RIGHT;\r
+  PrintCharAt (Start, Bottom - 1, Character);\r
+  Character = (CHAR16) BOXDRAW_HORIZONTAL;\r
+  for (Index = Start; Index + 2 < End; Index++) {\r
+    PrintChar (Character);\r
+  }\r
+\r
+  Character = (CHAR16) BOXDRAW_UP_LEFT;\r
+  PrintChar (Character);\r
+}\r
+\r
+VOID\r
+CreatePopUp (\r
+  IN  UINTN                       RequestedWidth,\r
+  IN  UINTN                       NumberOfLines,\r
+  IN  CHAR16                      *ArrayOfStrings,\r
+  ...\r
+  )\r
+{\r
+  CreateSharedPopUp (RequestedWidth, NumberOfLines, &ArrayOfStrings);\r
+}\r
+\r
+VOID\r
+UpdateStatusBar (\r
+  IN  UINTN                       MessageType,\r
+  IN  UINT8                       Flags,\r
+  IN  BOOLEAN                     State\r
+  )\r
+{\r
+  UINTN           Index;\r
+  STATIC BOOLEAN  InputError;\r
+  CHAR16          *NvUpdateMessage;\r
+  CHAR16          *InputErrorMessage;\r
+\r
+  NvUpdateMessage   = GetToken (STRING_TOKEN (NV_UPDATE_MESSAGE), gHiiHandle);\r
+  InputErrorMessage = GetToken (STRING_TOKEN (INPUT_ERROR_MESSAGE), gHiiHandle);\r
+\r
+  switch (MessageType) {\r
+  case INPUT_ERROR:\r
+    if (State) {\r
+      gST->ConOut->SetAttribute (gST->ConOut, ERROR_TEXT);\r
+      PrintStringAt (\r
+        gScreenDimensions.LeftColumn + gPromptBlockWidth,\r
+        gScreenDimensions.BottomRow - 1,\r
+        InputErrorMessage\r
+        );\r
+      InputError = TRUE;\r
+    } else {\r
+      gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_HIGHLIGHT);\r
+      for (Index = 0; Index < (GetStringWidth (InputErrorMessage) - 2) / 2; Index++) {\r
+        PrintAt (gScreenDimensions.LeftColumn + gPromptBlockWidth + Index, gScreenDimensions.BottomRow - 1, (CHAR16 *) L"  ");\r
+      }\r
+\r
+      InputError = FALSE;\r
+    }\r
+    break;\r
+\r
+  case NV_UPDATE_REQUIRED:\r
+    if (gClassOfVfr != EFI_FRONT_PAGE_SUBCLASS) {\r
+      if (State) {\r
+        gST->ConOut->SetAttribute (gST->ConOut, INFO_TEXT);\r
+        PrintStringAt (\r
+          gScreenDimensions.LeftColumn + gPromptBlockWidth + gOptionBlockWidth,\r
+          gScreenDimensions.BottomRow - 1,\r
+          NvUpdateMessage\r
+          );\r
+        gResetRequired    = (BOOLEAN) (gResetRequired | ((Flags & EFI_IFR_FLAG_RESET_REQUIRED) == EFI_IFR_FLAG_RESET_REQUIRED));\r
+\r
+        gNvUpdateRequired = TRUE;\r
+      } else {\r
+        gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_HIGHLIGHT);\r
+        for (Index = 0; Index < (GetStringWidth (NvUpdateMessage) - 2) / 2; Index++) {\r
+          PrintAt (\r
+            (gScreenDimensions.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + Index),\r
+            gScreenDimensions.BottomRow - 1,\r
+            (CHAR16 *) L"  "\r
+            );\r
+        }\r
+\r
+        gNvUpdateRequired = FALSE;\r
+      }\r
+    }\r
+    break;\r
+\r
+  case REFRESH_STATUS_BAR:\r
+    if (InputError) {\r
+      UpdateStatusBar (INPUT_ERROR, Flags, TRUE);\r
+    }\r
+\r
+    if (gNvUpdateRequired) {\r
+      UpdateStatusBar (NV_UPDATE_REQUIRED, Flags, TRUE);\r
+    }\r
+    break;\r
+\r
+  default:\r
+    break;\r
+  }\r
+\r
+  FreePool (InputErrorMessage);\r
+  FreePool (NvUpdateMessage);\r
+  return ;\r
+}\r
+\r
+VOID\r
+FreeData (\r
+  IN EFI_FILE_FORM_TAGS           *FileFormTagsHead,\r
+  IN CHAR16                       *FormattedString,\r
+  IN CHAR16                       *OptionString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Used to remove the allocated data instances\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  EFI_FILE_FORM_TAGS      *FileForm;\r
+  EFI_FILE_FORM_TAGS      *PreviousFileForm;\r
+  EFI_FORM_TAGS           *FormTags;\r
+  EFI_FORM_TAGS           *PreviousFormTags;\r
+  EFI_IFR_BINARY          *IfrBinary;\r
+  EFI_IFR_BINARY          *PreviousIfrBinary;\r
+  EFI_INCONSISTENCY_DATA  *Inconsistent;\r
+  EFI_VARIABLE_DEFINITION *VariableDefinition;\r
+  EFI_VARIABLE_DEFINITION *PreviousVariableDefinition;\r
+  VOID                    *Buffer;\r
+  UINTN                   Index;\r
+\r
+  FileForm = FileFormTagsHead;\r
+\r
+  if (FormattedString != NULL) {\r
+    FreePool (FormattedString);\r
+  }\r
+\r
+  if (OptionString != NULL) {\r
+    FreePool (OptionString);\r
+  }\r
+\r
+  for (; FileForm != NULL;) {\r
+    PreviousFileForm = NULL;\r
+\r
+    //\r
+    // Advance FileForm to the last entry\r
+    //\r
+    for (; FileForm->NextFile != NULL; FileForm = FileForm->NextFile) {\r
+      PreviousFileForm = FileForm;\r
+    }\r
+\r
+    FormTags = &FileForm->FormTags;\r
+\r
+    for (; FormTags != NULL;) {\r
+      FormTags          = &FileForm->FormTags;\r
+      PreviousFormTags  = NULL;\r
+\r
+      //\r
+      // Advance FormTags to the last entry\r
+      //\r
+      for (; FormTags->Next != NULL; FormTags = FormTags->Next) {\r
+        PreviousFormTags = FormTags;\r
+      }\r
+      //\r
+      // Walk through each of the tags and free the IntList allocation\r
+      //\r
+      for (Index = 0; FormTags->Tags[Index].Operand != EFI_IFR_END_FORM_OP; Index++) {\r
+        //\r
+        // It is more than likely that the very last page will contain an end formset\r
+        //\r
+        if (FormTags->Tags[Index].Operand == EFI_IFR_END_FORM_SET_OP) {\r
+          break;\r
+        }\r
+\r
+        if (FormTags->Tags[Index].IntList != NULL) {\r
+          FreePool (FormTags->Tags[Index].IntList);\r
+        }\r
+      }\r
+\r
+      if (PreviousFormTags != NULL) {\r
+        FreePool (FormTags->Tags);\r
+        FormTags = PreviousFormTags;\r
+        FreePool (FormTags->Next);\r
+        FormTags->Next = NULL;\r
+      } else {\r
+        FreePool (FormTags->Tags);\r
+        FormTags = NULL;\r
+      }\r
+    }\r
+    //\r
+    // Last FileForm entry's Inconsistent database\r
+    //\r
+    Inconsistent = FileForm->InconsistentTags;\r
+\r
+    //\r
+    // Advance Inconsistent to the last entry\r
+    //\r
+    for (; Inconsistent->Next != NULL; Inconsistent = Inconsistent->Next)\r
+      ;\r
+\r
+    for (; Inconsistent != NULL;) {\r
+      //\r
+      // Preserve the Previous pointer\r
+      //\r
+      Buffer = (VOID *) Inconsistent->Previous;\r
+\r
+      //\r
+      // Free the current entry\r
+      //\r
+      FreePool (Inconsistent);\r
+\r
+      //\r
+      // Restore the Previous pointer\r
+      //\r
+      Inconsistent = (EFI_INCONSISTENCY_DATA *) Buffer;\r
+    }\r
+\r
+    VariableDefinition = FileForm->VariableDefinitions;\r
+\r
+    for (; VariableDefinition != NULL;) {\r
+      VariableDefinition          = FileForm->VariableDefinitions;\r
+      PreviousVariableDefinition  = NULL;\r
+\r
+      //\r
+      // Advance VariableDefinitions to the last entry\r
+      //\r
+      for (; VariableDefinition->Next != NULL; VariableDefinition = VariableDefinition->Next) {\r
+        PreviousVariableDefinition = VariableDefinition;\r
+      }\r
+\r
+      FreePool (VariableDefinition->VariableName);\r
+\r
+      if (VariableDefinition->NvRamMap != NULL) {\r
+        FreePool (VariableDefinition->NvRamMap);\r
+      }\r
+\r
+      if (VariableDefinition->FakeNvRamMap != NULL) {\r
+        FreePool (VariableDefinition->FakeNvRamMap);\r
+      }\r
+\r
+      if (PreviousVariableDefinition != NULL) {\r
+        VariableDefinition = PreviousVariableDefinition;\r
+        FreePool (VariableDefinition->Next);\r
+        VariableDefinition->Next = NULL;\r
+      } else {\r
+        FreePool (VariableDefinition);\r
+        VariableDefinition = NULL;\r
+      }\r
+    }\r
+\r
+    if (PreviousFileForm != NULL) {\r
+      FileForm = PreviousFileForm;\r
+      FreePool (FileForm->NextFile);\r
+      FileForm->NextFile = NULL;\r
+    } else {\r
+      FreePool (FileForm);\r
+      FileForm = NULL;\r
+    }\r
+  }\r
+\r
+  IfrBinary = gBinaryDataHead;\r
+\r
+  for (; IfrBinary != NULL;) {\r
+    IfrBinary         = gBinaryDataHead;\r
+    PreviousIfrBinary = NULL;\r
+\r
+    //\r
+    // Advance IfrBinary to the last entry\r
+    //\r
+    for (; IfrBinary->Next != NULL; IfrBinary = IfrBinary->Next) {\r
+      PreviousIfrBinary = IfrBinary;\r
+    }\r
+\r
+    FreePool (IfrBinary->IfrPackage);\r
+\r
+    if (PreviousIfrBinary != NULL) {\r
+      IfrBinary = PreviousIfrBinary;\r
+      FreePool (IfrBinary->Next);\r
+      IfrBinary->Next = NULL;\r
+    } else {\r
+      FreePool (IfrBinary);\r
+      IfrBinary = NULL;\r
+    }\r
+  }\r
+\r
+  FreePool (gPreviousValue);\r
+  gPreviousValue = NULL;\r
+\r
+  //\r
+  // Free Browser Strings\r
+  //\r
+  FreePool (gPressEnter);\r
+  FreePool (gConfirmError);\r
+  FreePool (gConfirmPassword);\r
+  FreePool (gPromptForNewPassword);\r
+  FreePool (gPromptForPassword);\r
+  FreePool (gToggleCheckBox);\r
+  FreePool (gNumericInput);\r
+  FreePool (gMakeSelection);\r
+  FreePool (gMoveHighlight);\r
+  FreePool (gEscapeString);\r
+  FreePool (gEnterCommitString);\r
+  FreePool (gEnterString);\r
+  FreePool (gFunctionOneString);\r
+  FreePool (gFunctionTwoString);\r
+  FreePool (gFunctionNineString);\r
+  FreePool (gFunctionTenString);\r
+  return ;\r
+}\r
+\r
+STATIC\r
+BOOLEAN\r
+SelectionsAreValid (\r
+  IN  UI_MENU_OPTION               *MenuOption,\r
+  IN  EFI_FILE_FORM_TAGS           *FileFormTagsHead\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Initiate late consistency checks against the current page.\r
+\r
+Arguments:\r
+  None\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  LIST_ENTRY              *Link;\r
+  EFI_TAG                 *Tag;\r
+  EFI_FILE_FORM_TAGS      *FileFormTags;\r
+  CHAR16                  *StringPtr;\r
+  CHAR16                  NullCharacter;\r
+  UINTN                   Index;\r
+  UINT16                  *NvRamMap;\r
+  STRING_REF              PopUp;\r
+  EFI_INPUT_KEY           Key;\r
+  EFI_VARIABLE_DEFINITION *VariableDefinition;\r
+\r
+  StringPtr     = (CHAR16 *) L"\0";\r
+  NullCharacter = CHAR_NULL;\r
+\r
+  FileFormTags  = FileFormTagsHead;\r
+\r
+  for (Index = 0; Index < MenuOption->IfrNumber; Index++) {\r
+    FileFormTags = FileFormTags->NextFile;\r
+  }\r
+\r
+  for (Link = Menu.ForwardLink; Link != &Menu; Link = Link->ForwardLink) {\r
+    MenuOption  = CR (Link, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+\r
+    Tag         = MenuOption->ThisTag;\r
+\r
+    ExtractRequestedNvMap (FileFormTags, Tag->VariableNumber, &VariableDefinition);\r
+    NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];\r
+\r
+    //\r
+    // If the op-code has a late check, ensure consistency checks are now applied\r
+    //\r
+    if (Tag->Flags & EFI_IFR_FLAG_LATE_CHECK) {\r
+      if (ValueIsNotValid (TRUE, 0, Tag, FileFormTags, &PopUp)) {\r
+        if (PopUp != 0x0000) {\r
+          StringPtr = GetToken (PopUp, MenuOption->Handle);\r
+\r
+          CreatePopUp (GetStringWidth (StringPtr) / 2, 3, &NullCharacter, StringPtr, &NullCharacter);\r
+\r
+          do {\r
+            WaitForKeyStroke (&Key);\r
+\r
+            switch (Key.UnicodeChar) {\r
+\r
+            case CHAR_CARRIAGE_RETURN:\r
+              //\r
+              // Since the value can be one byte long or two bytes long, do a CopyMem based on StorageWidth\r
+              //\r
+              CopyMem (NvRamMap, &Tag->OldValue, Tag->StorageWidth);\r
+              FreePool (StringPtr);\r
+              break;\r
+\r
+            default:\r
+              break;\r
+            }\r
+          } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
+        }\r
+\r
+        return FALSE;\r
+      }\r
+    }\r
+  }\r
+\r
+  return TRUE;\r
+}\r
+\r
+UINT16\r
+GetWidth (\r
+  IN EFI_TAG                        *Tag,\r
+  IN EFI_HII_HANDLE                 Handle\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Get the supported width for a particular op-code\r
+\r
+Arguments:\r
+  Tag - The Tag structure passed in.\r
+  Handle - The handle in the HII database being used\r
+\r
+Returns:\r
+  Returns the number of CHAR16 characters that is support.\r
+\r
+\r
+--*/\r
+{\r
+  CHAR16  *String;\r
+  UINTN   Size;\r
+\r
+  Size = 0x00;\r
+\r
+  //\r
+  // See if the second text parameter is really NULL\r
+  //\r
+  if ((Tag->Operand == EFI_IFR_TEXT_OP) && (Tag->TextTwo != 0)) {\r
+    String  = GetToken (Tag->TextTwo, Handle);\r
+    Size    = StrLen (String);\r
+    FreePool (String);\r
+  }\r
+\r
+  if ((Tag->Operand == EFI_IFR_SUBTITLE_OP) ||\r
+      (Tag->Operand == EFI_IFR_REF_OP) ||\r
+      (Tag->Operand == EFI_IFR_PASSWORD_OP) ||\r
+      (Tag->Operand == EFI_IFR_STRING_OP) ||\r
+      (Tag->Operand == EFI_IFR_INVENTORY_OP) ||\r
+      //\r
+      // Allow a wide display if text op-code and no secondary text op-code\r
+      //\r
+      ((Tag->Operand == EFI_IFR_TEXT_OP) && (Size == 0x0000))\r
+      ) {\r
+    return (UINT16) (gPromptBlockWidth + gOptionBlockWidth);\r
+  } else {\r
+    return (UINT16) gPromptBlockWidth;\r
+  }\r
+}\r
+\r
+UINT16\r
+GetLineByWidth (\r
+  IN      CHAR16                      *InputString,\r
+  IN      UINT16                      LineWidth,\r
+  IN OUT  UINTN                       *Index,\r
+  OUT     CHAR16                      **OutputString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Will copy LineWidth amount of a string in the OutputString buffer and return the\r
+  number of CHAR16 characters that were copied into the OutputString buffer.\r
+\r
+Arguments:\r
+  InputString - String description for this option.\r
+  LineWidth - Width of the desired string to extract in CHAR16 characters\r
+  Index - Where in InputString to start the copy process\r
+  OutputString - Buffer to copy the string into\r
+\r
+Returns:\r
+  Returns the number of CHAR16 characters that were copied into the OutputString buffer.\r
+\r
+\r
+--*/\r
+{\r
+  static BOOLEAN  Finished;\r
+  UINT16          Count;\r
+  UINT16          Count2;\r
+\r
+  if (Finished) {\r
+    Finished = FALSE;\r
+    return (UINT16) 0;\r
+  }\r
+\r
+  Count         = LineWidth;\r
+  Count2        = 0;\r
+\r
+  *OutputString = AllocateZeroPool (((UINTN) (LineWidth + 1) * 2));\r
+\r
+  //\r
+  // Ensure we have got a valid buffer\r
+  //\r
+  if (*OutputString != NULL) {\r
+\r
+    //\r
+    //NARROW_CHAR can not be printed in screen, so if a line only contain  the two CHARs: 'NARROW_CHAR + CHAR_CARRIAGE_RETURN' , it is a empty line  in Screen.\r
+    //To avoid displaying this  empty line in screen,  just skip  the two CHARs here.\r
+    //\r
+   if ((InputString[*Index] == NARROW_CHAR) && (InputString[*Index + 1] == CHAR_CARRIAGE_RETURN)) {\r
+     *Index = *Index + 2;\r
+   }\r
+\r
+    //\r
+    // Fast-forward the string and see if there is a carriage-return in the string\r
+    //\r
+    for (; (InputString[*Index + Count2] != CHAR_CARRIAGE_RETURN) && (Count2 != LineWidth); Count2++)\r
+      ;\r
+\r
+    //\r
+    // Copy the desired LineWidth of data to the output buffer.\r
+    // Also make sure that we don't copy more than the string.\r
+    // Also make sure that if there are linefeeds, we account for them.\r
+    //\r
+    if ((StrSize (&InputString[*Index]) <= ((UINTN) (LineWidth + 1) * 2)) &&\r
+        (StrSize (&InputString[*Index]) <= ((UINTN) (Count2 + 1) * 2))\r
+        ) {\r
+      //\r
+      // Convert to CHAR16 value and show that we are done with this operation\r
+      //\r
+      LineWidth = (UINT16) ((StrSize (&InputString[*Index]) - 2) / 2);\r
+      if (LineWidth != 0) {\r
+        Finished = TRUE;\r
+      }\r
+    } else {\r
+      if (Count2 == LineWidth) {\r
+        //\r
+        // Rewind the string from the maximum size until we see a space to break the line\r
+        //\r
+        for (; (InputString[*Index + LineWidth] != CHAR_SPACE) && (LineWidth != 0); LineWidth--)\r
+          ;\r
+        if (LineWidth == 0) {\r
+          LineWidth = Count;\r
+        }\r
+      } else {\r
+        LineWidth = Count2;\r
+      }\r
+    }\r
+\r
+    CopyMem (*OutputString, &InputString[*Index], LineWidth * 2);\r
+\r
+    //\r
+    // If currently pointing to a space, increment the index to the first non-space character\r
+    //\r
+    for (;\r
+         (InputString[*Index + LineWidth] == CHAR_SPACE) || (InputString[*Index + LineWidth] == CHAR_CARRIAGE_RETURN);\r
+         (*Index)++\r
+        )\r
+      ;\r
+    *Index = (UINT16) (*Index + LineWidth);\r
+    return LineWidth;\r
+  } else {\r
+    return (UINT16) 0;\r
+  }\r
+}\r
+\r
+STATIC\r
+VOID\r
+UpdateOptionSkipLines (\r
+  IN EFI_IFR_DATA_ARRAY           *PageData,\r
+  IN UI_MENU_OPTION               *MenuOption,\r
+  IN EFI_FILE_FORM_TAGS           *FileFormTagsHead,\r
+  IN CHAR16                       **OptionalString,\r
+  IN UINTN                        SkipValue\r
+  )\r
+{\r
+  UINTN   Index;\r
+  UINT16  Width;\r
+  UINTN   Row;\r
+  UINTN   OriginalRow;\r
+  CHAR16  *OutputString;\r
+  CHAR16  *OptionString;\r
+\r
+  Row           = 0;\r
+  OptionString  = *OptionalString;\r
+  OutputString  = NULL;\r
+\r
+  ProcessOptions (MenuOption, FALSE, FileFormTagsHead, PageData, &OptionString);\r
+\r
+  if (OptionString != NULL) {\r
+    Width               = (UINT16) gOptionBlockWidth;\r
+\r
+    OriginalRow         = Row;\r
+\r
+    for (Index = 0; GetLineByWidth (OptionString, Width, &Index, &OutputString) != 0x0000;) {\r
+      //\r
+      // If there is more string to process print on the next row and increment the Skip value\r
+      //\r
+      if (StrLen (&OptionString[Index])) {\r
+        if (SkipValue == 0) {\r
+          Row++;\r
+          //\r
+          // Since the Number of lines for this menu entry may or may not be reflected accurately\r
+          // since the prompt might be 1 lines and option might be many, and vice versa, we need to do\r
+          // some testing to ensure we are keeping this in-sync.\r
+          //\r
+          // If the difference in rows is greater than or equal to the skip value, increase the skip value\r
+          //\r
+          if ((Row - OriginalRow) >= MenuOption->Skip) {\r
+            MenuOption->Skip++;\r
+          }\r
+        }\r
+      }\r
+\r
+      FreePool (OutputString);\r
+      if (SkipValue != 0) {\r
+        SkipValue--;\r
+      }\r
+    }\r
+\r
+    Row = OriginalRow;\r
+  }\r
+\r
+  *OptionalString = OptionString;\r
+}\r
+//\r
+// Search table for UiDisplayMenu()\r
+//\r
+SCAN_CODE_TO_SCREEN_OPERATION     gScanCodeToOperation[] = {\r
+  { SCAN_UP,        UiUp },\r
+  { SCAN_DOWN,      UiDown },\r
+  { SCAN_PAGE_UP,   UiPageUp },\r
+  { SCAN_PAGE_DOWN, UiPageDown},\r
+  { SCAN_ESC,       UiReset},\r
+  { SCAN_F2,        UiPrevious},\r
+  { SCAN_LEFT,      UiLeft },\r
+  { SCAN_RIGHT,     UiRight },\r
+  { SCAN_F9,        UiDefault},\r
+  { SCAN_F10,       UiSave }\r
+};\r
+\r
+SCREEN_OPERATION_T0_CONTROL_FLAG  gScreenOperationToControlFlag[] = {\r
+  { UiNoOperation,  CfUiNoOperation },\r
+  { UiDefault,      CfUiDefault },\r
+  { UiSelect,       CfUiSelect },\r
+  { UiUp,           CfUiUp},\r
+  { UiDown,         CfUiDown },\r
+  { UiLeft,         CfUiLeft },\r
+  { UiRight,        CfUiRight },\r
+  { UiReset,        CfUiReset },\r
+  { UiSave,         CfUiSave },\r
+  { UiPrevious,     CfUiPrevious },\r
+  { UiPageUp,       CfUiPageUp },\r
+  { UiPageDown,     CfUiPageDown }\r
+};\r
+\r
+UI_MENU_OPTION *\r
+UiDisplayMenu (\r
+  IN  BOOLEAN                      SubMenu,\r
+  IN  EFI_FILE_FORM_TAGS           *FileFormTagsHead,\r
+  OUT EFI_IFR_DATA_ARRAY           *PageData\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Display menu and wait for user to select one menu option, then return it.\r
+  If AutoBoot is enabled, then if user doesn't select any option,\r
+  after period of time, it will automatically return the first menu option.\r
+\r
+Arguments:\r
+  SubMenu          - Indicate is sub menu.\r
+  FileFormTagsHead - A pointer to the EFI_FILE_FORM_TAGS structure.\r
+  PageData         - A pointer to the EFI_IFR_DATA_ARRAY.\r
+\r
+Returns:\r
+  Return the pointer of the menu which selected,\r
+  otherwise return NULL.\r
+\r
+--*/\r
+{\r
+  INTN                        SkipValue;\r
+  INTN                        Difference;\r
+  INTN                        OldSkipValue;\r
+  UINTN                       Row;\r
+  UINTN                       Col;\r
+  UINTN                       Temp;\r
+  UINTN                       Temp2;\r
+  UINTN                       TopRow;\r
+  UINTN                       BottomRow;\r
+  UINTN                       OriginalRow;\r
+  UINTN                       Index;\r
+  UINTN                       DataAndTimeLineNumberPad;\r
+  UINT32                      Count;\r
+  INT16                       OriginalTimeOut;\r
+  UINT8                       *Location;\r
+  UINT16                      Width;\r
+  CHAR16                      *StringPtr;\r
+  CHAR16                      *OptionString;\r
+  CHAR16                      *OutputString;\r
+  CHAR16                      *FormattedString;\r
+  CHAR16                      YesResponse;\r
+  CHAR16                      NoResponse;\r
+  BOOLEAN                     NewLine;\r
+  BOOLEAN                     Repaint;\r
+  BOOLEAN                     SavedValue;\r
+  EFI_STATUS                  Status;\r
+  UI_MENU_LIST                *UiMenuList;\r
+  EFI_INPUT_KEY               Key;\r
+  LIST_ENTRY                  *Link;\r
+  LIST_ENTRY                  *NewPos;\r
+  LIST_ENTRY                  *TopOfScreen;\r
+  LIST_ENTRY                  *SavedListEntry;\r
+  UI_MENU_OPTION              *Selection;\r
+  UI_MENU_OPTION              *MenuOption;\r
+  UI_MENU_OPTION              *NextMenuOption;\r
+  UI_MENU_OPTION              *SavedMenuOption;\r
+  UI_MENU_OPTION              *PreviousMenuOption;\r
+  EFI_IFR_BINARY              *IfrBinary;\r
+  UI_CONTROL_FLAG             ControlFlag;\r
+  EFI_SCREEN_DESCRIPTOR       LocalScreen;\r
+  EFI_FILE_FORM_TAGS          *FileFormTags;\r
+  MENU_REFRESH_ENTRY          *MenuRefreshEntry;\r
+  MENU_REFRESH_ENTRY          *OldMenuRefreshEntry;\r
+  UI_SCREEN_OPERATION         ScreenOperation;\r
+  EFI_VARIABLE_DEFINITION     *VariableDefinition;\r
+  EFI_FORM_CALLBACK_PROTOCOL  *FormCallback;\r
+  EFI_HII_VARIABLE_PACK_LIST  *NvMapListHead;\r
+  EFI_HII_VARIABLE_PACK_LIST  *NvMapListNode;\r
+  VOID                        *NvMap;\r
+  UINTN                       NvMapSize;\r
+\r
+  CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));\r
+\r
+  VariableDefinition  = NULL;\r
+  Status              = EFI_SUCCESS;\r
+  FormattedString     = NULL;\r
+  OptionString        = NULL;\r
+  ScreenOperation     = UiNoOperation;\r
+  NewLine             = TRUE;\r
+  FormCallback        = NULL;\r
+  FileFormTags        = NULL;\r
+  OutputString        = NULL;\r
+  gUpArrow            = FALSE;\r
+  gDownArrow          = FALSE;\r
+  SkipValue           = 0;\r
+  OldSkipValue        = 0;\r
+  MenuRefreshEntry    = gMenuRefreshHead;\r
+  OldMenuRefreshEntry = gMenuRefreshHead;\r
+  NextMenuOption      = NULL;\r
+  PreviousMenuOption  = NULL;\r
+  SavedMenuOption     = NULL;\r
+  IfrBinary           = NULL;\r
+  NvMap               = NULL;\r
+  NvMapSize           = 0;\r
+\r
+  ZeroMem (&Key, sizeof (EFI_INPUT_KEY));\r
+\r
+  if (gClassOfVfr == EFI_FRONT_PAGE_SUBCLASS) {\r
+    TopRow  = LocalScreen.TopRow + FRONT_PAGE_HEADER_HEIGHT + SCROLL_ARROW_HEIGHT;\r
+    Row     = LocalScreen.TopRow + FRONT_PAGE_HEADER_HEIGHT + SCROLL_ARROW_HEIGHT;\r
+  } else {\r
+    TopRow  = LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT + SCROLL_ARROW_HEIGHT;\r
+    Row     = LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT + SCROLL_ARROW_HEIGHT;\r
+  }\r
+\r
+  if (SubMenu) {\r
+    Col = LocalScreen.LeftColumn;\r
+  } else {\r
+    Col = LocalScreen.LeftColumn + LEFT_SKIPPED_COLUMNS;\r
+  }\r
+\r
+  BottomRow   = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT - SCROLL_ARROW_HEIGHT - 1;\r
+\r
+  TopOfScreen = Menu.ForwardLink;\r
+  Repaint     = TRUE;\r
+  MenuOption  = NULL;\r
+\r
+  //\r
+  // Get user's selection\r
+  //\r
+  Selection = NULL;\r
+  NewPos    = Menu.ForwardLink;\r
+  gST->ConOut->EnableCursor (gST->ConOut, FALSE);\r
+\r
+  UpdateStatusBar (REFRESH_STATUS_BAR, (UINT8) 0, TRUE);\r
+\r
+  ControlFlag = CfInitialization;\r
+\r
+  while (TRUE) {\r
+    switch (ControlFlag) {\r
+    case CfInitialization:\r
+      ControlFlag = CfCheckSelection;\r
+      if (gExitRequired) {\r
+        ScreenOperation = UiReset;\r
+        ControlFlag     = CfScreenOperation;\r
+      } else if (gSaveRequired) {\r
+        ScreenOperation = UiSave;\r
+        ControlFlag     = CfScreenOperation;\r
+      } else if (IsListEmpty (&Menu)) {\r
+        ControlFlag = CfReadKey;\r
+      }\r
+      break;\r
+\r
+    case CfCheckSelection:\r
+      if (Selection != NULL) {\r
+        ControlFlag = CfExit;\r
+      } else {\r
+        ControlFlag = CfRepaint;\r
+      }\r
+\r
+      FileFormTags = FileFormTagsHead;\r
+      break;\r
+\r
+    case CfRepaint:\r
+      ControlFlag = CfRefreshHighLight;\r
+\r
+      if (Repaint) {\r
+        //\r
+        // Display menu\r
+        //\r
+        SavedMenuOption = MenuOption;\r
+        gDownArrow      = FALSE;\r
+        gUpArrow        = FALSE;\r
+        Row             = TopRow;\r
+\r
+        Temp            = SkipValue;\r
+        Temp2           = SkipValue;\r
+\r
+        ClearLines (\r
+          LocalScreen.LeftColumn,\r
+          LocalScreen.RightColumn,\r
+          TopRow - SCROLL_ARROW_HEIGHT,\r
+          BottomRow + SCROLL_ARROW_HEIGHT,\r
+          FIELD_TEXT | FIELD_BACKGROUND\r
+          );\r
+\r
+        while (gMenuRefreshHead != NULL) {\r
+          OldMenuRefreshEntry = gMenuRefreshHead->Next;\r
+\r
+          FreePool (gMenuRefreshHead);\r
+\r
+          gMenuRefreshHead = OldMenuRefreshEntry;\r
+        }\r
+\r
+        for (Link = TopOfScreen; Link != &Menu; Link = Link->ForwardLink) {\r
+          MenuOption          = CR (Link, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+          MenuOption->Row     = Row;\r
+          OriginalRow         = Row;\r
+          MenuOption->Col     = Col;\r
+          MenuOption->OptCol  = gPromptBlockWidth + 1 + LocalScreen.LeftColumn;\r
+\r
+          if (SubMenu) {\r
+            if (MenuOption->ThisTag->GrayOut) {\r
+              gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_GRAYED | FIELD_BACKGROUND);\r
+            } else {\r
+              if (MenuOption->ThisTag->Operand == EFI_IFR_SUBTITLE_OP) {\r
+                gST->ConOut->SetAttribute (gST->ConOut, SUBTITLE_TEXT | FIELD_BACKGROUND);\r
+              }\r
+            }\r
+\r
+            Width       = GetWidth (MenuOption->ThisTag, MenuOption->Handle);\r
+\r
+            OriginalRow = Row;\r
+\r
+            for (Index = 0; GetLineByWidth (MenuOption->Description, Width, &Index, &OutputString) != 0x0000;) {\r
+              if ((Temp == 0) && (Row <= BottomRow)) {\r
+                PrintStringAt (Col, Row, OutputString);\r
+              }\r
+              //\r
+              // If there is more string to process print on the next row and increment the Skip value\r
+              //\r
+              if (StrLen (&MenuOption->Description[Index])) {\r
+                if (Temp == 0) {\r
+                  Row++;\r
+                }\r
+              }\r
+\r
+              FreePool (OutputString);\r
+              if (Temp != 0) {\r
+                Temp--;\r
+              }\r
+            }\r
+\r
+            Temp  = 0;\r
+\r
+            Row   = OriginalRow;\r
+\r
+            gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
+            ProcessOptions (MenuOption, FALSE, FileFormTagsHead, PageData, &OptionString);\r
+\r
+            if (OptionString != NULL) {\r
+              if (MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP ||\r
+                  MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP\r
+                  ) {\r
+                //\r
+                // If leading spaces on OptionString - remove the spaces\r
+                //\r
+                for (Index = 0; OptionString[Index] == L' '; Index++) {\r
+                  MenuOption->OptCol++;\r
+                }\r
+\r
+                for (Count = 0; OptionString[Index] != CHAR_NULL; Index++) {\r
+                  OptionString[Count] = OptionString[Index];\r
+                  Count++;\r
+                }\r
+\r
+                OptionString[Count] = CHAR_NULL;\r
+              }\r
+\r
+              //\r
+              // If this is a date or time op-code and is used to reflect an RTC, register the op-code\r
+              //\r
+                if ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP ||\r
+                     MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP) &&\r
+                    (MenuOption->ThisTag->StorageStart >= FileFormTags->FormTags.Tags[0].NvDataSize)) {\r
+\r
+                if (gMenuRefreshHead == NULL) {\r
+                  MenuRefreshEntry = AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY));\r
+                  ASSERT (MenuRefreshEntry != NULL);\r
+                  MenuRefreshEntry->MenuOption        = MenuOption;\r
+                  MenuRefreshEntry->FileFormTagsHead  = FileFormTagsHead;\r
+                  MenuRefreshEntry->CurrentColumn     = MenuOption->OptCol;\r
+                  MenuRefreshEntry->CurrentRow        = MenuOption->Row;\r
+                  MenuRefreshEntry->CurrentAttribute  = FIELD_TEXT | FIELD_BACKGROUND;\r
+                  gMenuRefreshHead                    = MenuRefreshEntry;\r
+                } else {\r
+                  //\r
+                  // Advance to the last entry\r
+                  //\r
+                  for (MenuRefreshEntry = gMenuRefreshHead;\r
+                       MenuRefreshEntry->Next != NULL;\r
+                       MenuRefreshEntry = MenuRefreshEntry->Next\r
+                      )\r
+                    ;\r
+                  MenuRefreshEntry->Next = AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY));\r
+                  ASSERT (MenuRefreshEntry->Next != NULL);\r
+                  MenuRefreshEntry                    = MenuRefreshEntry->Next;\r
+                  MenuRefreshEntry->MenuOption        = MenuOption;\r
+                  MenuRefreshEntry->FileFormTagsHead  = FileFormTagsHead;\r
+                  MenuRefreshEntry->CurrentColumn     = MenuOption->OptCol;\r
+                  MenuRefreshEntry->CurrentRow        = MenuOption->Row;\r
+                  MenuRefreshEntry->CurrentAttribute  = FIELD_TEXT | FIELD_BACKGROUND;\r
+                }\r
+              }\r
+\r
+              Width       = (UINT16) gOptionBlockWidth;\r
+\r
+              OriginalRow = Row;\r
+\r
+              for (Index = 0; GetLineByWidth (OptionString, Width, &Index, &OutputString) != 0x0000;) {\r
+                if ((Temp2 == 0) && (Row <= BottomRow)) {\r
+                  PrintStringAt (MenuOption->OptCol, Row, OutputString);\r
+                }\r
+                //\r
+                // If there is more string to process print on the next row and increment the Skip value\r
+                //\r
+                if (StrLen (&OptionString[Index])) {\r
+                  if (Temp2 == 0) {\r
+                    Row++;\r
+                    //\r
+                    // Since the Number of lines for this menu entry may or may not be reflected accurately\r
+                    // since the prompt might be 1 lines and option might be many, and vice versa, we need to do\r
+                    // some testing to ensure we are keeping this in-sync.\r
+                    //\r
+                    // If the difference in rows is greater than or equal to the skip value, increase the skip value\r
+                    //\r
+                    if ((Row - OriginalRow) >= MenuOption->Skip) {\r
+                      MenuOption->Skip++;\r
+                    }\r
+                  }\r
+                }\r
+\r
+                FreePool (OutputString);\r
+                if (Temp2 != 0) {\r
+                  Temp2--;\r
+                }\r
+              }\r
+\r
+              Temp2 = 0;\r
+              Row   = OriginalRow;\r
+            }\r
+            //\r
+            // If this is a text op with secondary text information\r
+            //\r
+            if ((MenuOption->ThisTag->Operand == EFI_IFR_TEXT_OP) && (MenuOption->ThisTag->TextTwo != 0)) {\r
+              StringPtr   = GetToken (MenuOption->ThisTag->TextTwo, MenuOption->Handle);\r
+\r
+              Width       = (UINT16) gOptionBlockWidth;\r
+\r
+              OriginalRow = Row;\r
+\r
+              for (Index = 0; GetLineByWidth (StringPtr, Width, &Index, &OutputString) != 0x0000;) {\r
+                if ((Temp == 0) && (Row <= BottomRow)) {\r
+                  PrintStringAt (MenuOption->OptCol, Row, OutputString);\r
+                }\r
+                //\r
+                // If there is more string to process print on the next row and increment the Skip value\r
+                //\r
+                if (StrLen (&StringPtr[Index])) {\r
+                  if (Temp2 == 0) {\r
+                    Row++;\r
+                    //\r
+                    // Since the Number of lines for this menu entry may or may not be reflected accurately\r
+                    // since the prompt might be 1 lines and option might be many, and vice versa, we need to do\r
+                    // some testing to ensure we are keeping this in-sync.\r
+                    //\r
+                    // If the difference in rows is greater than or equal to the skip value, increase the skip value\r
+                    //\r
+                    if ((Row - OriginalRow) >= MenuOption->Skip) {\r
+                      MenuOption->Skip++;\r
+                    }\r
+                  }\r
+                }\r
+\r
+                FreePool (OutputString);\r
+                if (Temp2 != 0) {\r
+                  Temp2--;\r
+                }\r
+              }\r
+\r
+              Row = OriginalRow;\r
+              FreePool (StringPtr);\r
+            }\r
+          } else {\r
+            //\r
+            // For now, assume left-justified 72 width max setup entries\r
+            //\r
+            PrintStringAt (Col, Row, MenuOption->Description);\r
+          }\r
+          //\r
+          // Tracker 6210 - need to handle the bottom of the display\r
+          //\r
+          if (MenuOption->Skip > 1) {\r
+            Row += MenuOption->Skip - SkipValue;\r
+            SkipValue = 0;\r
+          } else {\r
+            Row += MenuOption->Skip;\r
+          }\r
+\r
+          if (Row > BottomRow) {\r
+            if (!ValueIsScroll (FALSE, Link)) {\r
+              gDownArrow = TRUE;\r
+            }\r
+\r
+            Row = BottomRow + 1;\r
+            break;\r
+          }\r
+        }\r
+\r
+        if (!ValueIsScroll (TRUE, TopOfScreen)) {\r
+          gUpArrow = TRUE;\r
+        }\r
+\r
+        if (gUpArrow) {\r
+          gST->ConOut->SetAttribute (gST->ConOut, ARROW_TEXT | ARROW_BACKGROUND);\r
+          PrintAt (\r
+            LocalScreen.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + 1,\r
+            TopRow - SCROLL_ARROW_HEIGHT,\r
+            (CHAR16 *) L"%c",\r
+            ARROW_UP\r
+            );\r
+          gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
+        }\r
+\r
+        if (gDownArrow) {\r
+          gST->ConOut->SetAttribute (gST->ConOut, ARROW_TEXT | ARROW_BACKGROUND);\r
+          PrintAt (\r
+            LocalScreen.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + 1,\r
+            BottomRow + SCROLL_ARROW_HEIGHT,\r
+            (CHAR16 *) L"%c",\r
+            ARROW_DOWN\r
+            );\r
+          gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
+        }\r
+\r
+        if (SavedMenuOption != NULL) {\r
+          MenuOption = SavedMenuOption;\r
+        }\r
+      }\r
+      break;\r
+\r
+    case CfRefreshHighLight:\r
+      ControlFlag = CfUpdateHelpString;\r
+      //\r
+      // Repaint flag is normally reset when finish processing CfUpdateHelpString. Temporarily\r
+      // reset Repaint flag because we may break halfway and skip CfUpdateHelpString processing.\r
+      //\r
+      SavedValue  = Repaint;\r
+      Repaint     = FALSE;\r
+\r
+      if (NewPos != NULL) {\r
+        gST->ConOut->SetCursorPosition (gST->ConOut, MenuOption->Col, MenuOption->Row);\r
+        if (SubMenu) {\r
+          if (gLastOpr && (gEntryNumber != -1)) {\r
+            MenuOption = CR (NewPos, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+            if (gEntryNumber != MenuOption->EntryNumber) {\r
+              ScreenOperation = UiDown;\r
+              ControlFlag     = CfScreenOperation;\r
+              break;\r
+            } else {\r
+              gLastOpr = FALSE;\r
+            }\r
+          }\r
+\r
+          ProcessOptions (MenuOption, FALSE, FileFormTagsHead, PageData, &OptionString);\r
+          gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
+          if (OptionString != NULL) {\r
+            if (MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP ||\r
+                MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP\r
+                ) {\r
+              //\r
+              // If leading spaces on OptionString - remove the spaces\r
+              //\r
+              for (Index = 0; OptionString[Index] == L' '; Index++)\r
+                ;\r
+\r
+              for (Count = 0; OptionString[Index] != CHAR_NULL; Index++) {\r
+                OptionString[Count] = OptionString[Index];\r
+                Count++;\r
+              }\r
+\r
+              OptionString[Count] = CHAR_NULL;\r
+            }\r
+\r
+            Width               = (UINT16) gOptionBlockWidth;\r
+\r
+            OriginalRow         = MenuOption->Row;\r
+\r
+            for (Index = 0; GetLineByWidth (OptionString, Width, &Index, &OutputString) != 0x0000;) {\r
+              if (MenuOption->Row >= TopRow && MenuOption->Row <= BottomRow) {\r
+                PrintStringAt (MenuOption->OptCol, MenuOption->Row, OutputString);\r
+              }\r
+              //\r
+              // If there is more string to process print on the next row and increment the Skip value\r
+              //\r
+              if (StrLen (&OptionString[Index])) {\r
+                MenuOption->Row++;\r
+              }\r
+\r
+              FreePool (OutputString);\r
+            }\r
+\r
+            MenuOption->Row = OriginalRow;\r
+          } else {\r
+            if (NewLine) {\r
+              if (MenuOption->ThisTag->GrayOut) {\r
+                gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_GRAYED | FIELD_BACKGROUND);\r
+              } else {\r
+                if (MenuOption->ThisTag->Operand == EFI_IFR_SUBTITLE_OP) {\r
+                  gST->ConOut->SetAttribute (gST->ConOut, SUBTITLE_TEXT | FIELD_BACKGROUND);\r
+                }\r
+              }\r
+\r
+              OriginalRow = MenuOption->Row;\r
+              Width       = GetWidth (MenuOption->ThisTag, MenuOption->Handle);\r
+\r
+              for (Index = 0; GetLineByWidth (MenuOption->Description, Width, &Index, &OutputString) != 0x0000;) {\r
+                if (MenuOption->Row >= TopRow && MenuOption->Row <= BottomRow) {\r
+                  PrintStringAt (Col, MenuOption->Row, OutputString);\r
+                }\r
+                //\r
+                // If there is more string to process print on the next row and increment the Skip value\r
+                //\r
+                if (StrLen (&MenuOption->Description[Index])) {\r
+                  MenuOption->Row++;\r
+                }\r
+\r
+                FreePool (OutputString);\r
+              }\r
+\r
+              MenuOption->Row = OriginalRow;\r
+              gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
+            }\r
+          }\r
+        } else {\r
+          gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
+          gST->ConOut->OutputString (gST->ConOut, MenuOption->Description);\r
+        }\r
+\r
+        MenuOption = CR (NewPos, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+\r
+        if ((gPriorMenuEntry != 0) && (MenuOption->EntryNumber != gPriorMenuEntry) && (NewPos->ForwardLink != &Menu)) {\r
+          ScreenOperation = UiDown;\r
+          ControlFlag     = CfScreenOperation;\r
+          break;\r
+        } else {\r
+          gPriorMenuEntry = 0;\r
+        }\r
+        //\r
+        // This is only possible if we entered this page and the first menu option is\r
+        // a "non-menu" item.  In that case, force it UiDown\r
+        //\r
+        if (MenuOption->ThisTag->Operand == EFI_IFR_SUBTITLE_OP || MenuOption->ThisTag->GrayOut) {\r
+          //\r
+          // If we previously hit an UP command and we are still sitting on a text operation\r
+          // we must continue going up\r
+          //\r
+          if (ScreenOperation == UiUp) {\r
+            ControlFlag = CfScreenOperation;\r
+            break;\r
+          } else {\r
+            ScreenOperation = UiDown;\r
+            ControlFlag     = CfScreenOperation;\r
+            break;\r
+          }\r
+        }\r
+        //\r
+        // Set reverse attribute\r
+        //\r
+        gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_HIGHLIGHT | FIELD_BACKGROUND_HIGHLIGHT);\r
+        gST->ConOut->SetCursorPosition (gST->ConOut, MenuOption->Col, MenuOption->Row);\r
+\r
+        //\r
+        // Assuming that we have a refresh linked-list created, lets annotate the\r
+        // appropriate entry that we are highlighting with its new attribute.  Just prior to this\r
+        // lets reset all of the entries' attribute so we do not get multiple highlights in he refresh\r
+        //\r
+        if (gMenuRefreshHead != NULL) {\r
+          for (MenuRefreshEntry = gMenuRefreshHead; MenuRefreshEntry != NULL; MenuRefreshEntry = MenuRefreshEntry->Next) {\r
+            MenuRefreshEntry->CurrentAttribute = FIELD_TEXT | FIELD_BACKGROUND;\r
+            if (MenuRefreshEntry->MenuOption == MenuOption) {\r
+              MenuRefreshEntry->CurrentAttribute = FIELD_TEXT_HIGHLIGHT | FIELD_BACKGROUND_HIGHLIGHT;\r
+            }\r
+          }\r
+        }\r
+\r
+        if (SubMenu) {\r
+          ProcessOptions (MenuOption, FALSE, FileFormTagsHead, PageData, &OptionString);\r
+          if (OptionString != NULL) {\r
+            if (MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP ||\r
+                MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP\r
+                ) {\r
+              //\r
+              // If leading spaces on OptionString - remove the spaces\r
+              //\r
+              for (Index = 0; OptionString[Index] == L' '; Index++)\r
+                ;\r
+\r
+              for (Count = 0; OptionString[Index] != CHAR_NULL; Index++) {\r
+                OptionString[Count] = OptionString[Index];\r
+                Count++;\r
+              }\r
+\r
+              OptionString[Count] = CHAR_NULL;\r
+            }\r
+            Width               = (UINT16) gOptionBlockWidth;\r
+\r
+            OriginalRow         = MenuOption->Row;\r
+\r
+            for (Index = 0; GetLineByWidth (OptionString, Width, &Index, &OutputString) != 0x0000;) {\r
+              if (MenuOption->Row >= TopRow && MenuOption->Row <= BottomRow) {\r
+                PrintStringAt (MenuOption->OptCol, MenuOption->Row, OutputString);\r
+              }\r
+              //\r
+              // If there is more string to process print on the next row and increment the Skip value\r
+              //\r
+              if (StrLen (&OptionString[Index])) {\r
+                MenuOption->Row++;\r
+              }\r
+\r
+              FreePool (OutputString);\r
+            }\r
+\r
+            MenuOption->Row = OriginalRow;\r
+          } else {\r
+            if (NewLine) {\r
+              OriginalRow = MenuOption->Row;\r
+\r
+              Width       = GetWidth (MenuOption->ThisTag, MenuOption->Handle);\r
+\r
+              for (Index = 0; GetLineByWidth (MenuOption->Description, Width, &Index, &OutputString) != 0x0000;) {\r
+                if (MenuOption->Row >= TopRow && MenuOption->Row <= BottomRow) {\r
+                  PrintStringAt (Col, MenuOption->Row, OutputString);\r
+                }\r
+                //\r
+                // If there is more string to process print on the next row and increment the Skip value\r
+                //\r
+                if (StrLen (&MenuOption->Description[Index])) {\r
+                  MenuOption->Row++;\r
+                }\r
+\r
+                FreePool (OutputString);\r
+              }\r
+\r
+              MenuOption->Row = OriginalRow;\r
+\r
+            }\r
+          }\r
+\r
+          if (((NewPos->ForwardLink != &Menu) && (ScreenOperation == UiDown)) ||\r
+              ((NewPos->BackLink != &Menu) && (ScreenOperation == UiUp)) ||\r
+              (ScreenOperation == UiNoOperation)\r
+              ) {\r
+            UpdateKeyHelp (MenuOption, FALSE);\r
+          }\r
+        } else {\r
+          gST->ConOut->OutputString (gST->ConOut, MenuOption->Description);\r
+        }\r
+        //\r
+        // Clear reverse attribute\r
+        //\r
+        gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
+      }\r
+      //\r
+      // Repaint flag will be used when process CfUpdateHelpString, so restore its value\r
+      // if we didn't break halfway when process CfRefreshHighLight.\r
+      //\r
+      Repaint = SavedValue;\r
+      break;\r
+\r
+    case CfUpdateHelpString:\r
+      ControlFlag = CfPrepareToReadKey;\r
+\r
+        if (SubMenu &&\r
+            (Repaint || NewLine ||\r
+             (MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) ||\r
+             (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)) &&\r
+            !(gClassOfVfr == EFI_GENERAL_APPLICATION_SUBCLASS)) {\r
+        //\r
+        // Don't print anything if it is a NULL help token\r
+        //\r
+        if (MenuOption->ThisTag->Help == 0x00000000) {\r
+          StringPtr = (CHAR16 *) L"\0";\r
+        } else {\r
+          StringPtr = GetToken (MenuOption->ThisTag->Help, MenuOption->Handle);\r
+        }\r
+\r
+        ProcessHelpString (StringPtr, &FormattedString, BottomRow - TopRow);\r
+\r
+        gST->ConOut->SetAttribute (gST->ConOut, HELP_TEXT | FIELD_BACKGROUND);\r
+\r
+        for (Index = 0; Index < BottomRow - TopRow; Index++) {\r
+          //\r
+          // Pad String with spaces to simulate a clearing of the previous line\r
+          //\r
+          for (; GetStringWidth (&FormattedString[Index * gHelpBlockWidth * 2]) / 2 < gHelpBlockWidth;) {\r
+            StrCat (&FormattedString[Index * gHelpBlockWidth * 2], (CHAR16 *) L" ");\r
+          }\r
+\r
+          PrintStringAt (\r
+            LocalScreen.RightColumn - gHelpBlockWidth,\r
+            Index + TopRow,\r
+            &FormattedString[Index * gHelpBlockWidth * 2]\r
+            );\r
+        }\r
+      }\r
+      //\r
+      // Reset this flag every time we finish using it.\r
+      //\r
+      Repaint = FALSE;\r
+      NewLine = FALSE;\r
+      break;\r
+\r
+    case CfPrepareToReadKey:\r
+      ControlFlag = CfReadKey;\r
+\r
+      for (Index = 0; Index < MenuOption->IfrNumber; Index++) {\r
+        FileFormTags = FileFormTags->NextFile;\r
+      }\r
+\r
+      ScreenOperation = UiNoOperation;\r
+\r
+      Status = gBS->HandleProtocol (\r
+                      (VOID *) (UINTN) FileFormTags->FormTags.Tags[0].CallbackHandle,\r
+                      &gEfiFormCallbackProtocolGuid,\r
+                      (VOID **) &FormCallback\r
+                      );\r
+\r
+      break;\r
+\r
+    case CfReadKey:\r
+      ControlFlag     = CfScreenOperation;\r
+\r
+      OriginalTimeOut = FrontPageTimeOutValue;\r
+      do {\r
+        if (FrontPageTimeOutValue >= 0 && (gClassOfVfr == EFI_FRONT_PAGE_SUBCLASS) && FrontPageTimeOutValue != (INT16) -1) {\r
+          //\r
+          // Remember that if set to 0, must immediately boot an option\r
+          //\r
+          if (FrontPageTimeOutValue == 0) {\r
+            FrontPageTimeOutValue = 0xFFFF;\r
+            Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
+            if (EFI_ERROR (Status)) {\r
+              Status = EFI_TIMEOUT;\r
+            }\r
+            break;\r
+          }\r
+\r
+          Status = UiWaitForSingleEvent (gST->ConIn->WaitForKey, ONE_SECOND);\r
+          if (Status == EFI_TIMEOUT) {\r
+            EFI_IFR_DATA_ENTRY *DataEntry;\r
+\r
+            DataEntry = (EFI_IFR_DATA_ENTRY *) (PageData + 1);\r
+\r
+            PageData->EntryCount  = 1;\r
+            Count                 = (UINT32) ((OriginalTimeOut - FrontPageTimeOutValue) * 100 / OriginalTimeOut);\r
+            CopyMem (&DataEntry->Data, &Count, sizeof (UINT32));\r
+\r
+            if ((FormCallback != NULL) && (FormCallback->Callback != NULL)) {\r
+              FormCallback->Callback (\r
+                              FormCallback,\r
+                              0xFFFF,\r
+                              (EFI_IFR_DATA_ARRAY *) PageData,\r
+                              NULL\r
+                              );\r
+            }\r
+            //\r
+            // Count down 1 second\r
+            //\r
+            FrontPageTimeOutValue--;\r
+\r
+          } else {\r
+            ASSERT (!EFI_ERROR (Status));\r
+            PageData->EntryCount = 0;\r
+            if ((FormCallback != NULL) && (FormCallback->Callback != NULL)) {\r
+              FormCallback->Callback (\r
+                              FormCallback,\r
+                              0xFFFE,\r
+                              (EFI_IFR_DATA_ARRAY *) PageData,\r
+                              NULL\r
+                              );\r
+            }\r
+\r
+            FrontPageTimeOutValue = 0xFFFF;\r
+          }\r
+        } else {\r
+          //\r
+          // Wait for user's selection, no auto boot\r
+          //\r
+          Status = UiWaitForSingleEvent (gST->ConIn->WaitForKey, 0);\r
+        }\r
+      } while (Status == EFI_TIMEOUT);\r
+\r
+      if (gFirstIn) {\r
+        gFirstIn = FALSE;\r
+        gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
+        DisableQuietBoot ();\r
+      }\r
+\r
+      if (Status == EFI_TIMEOUT) {\r
+        Key.UnicodeChar = CHAR_CARRIAGE_RETURN;\r
+      } else {\r
+        Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
+        //\r
+        // if we encounter error, continue to read another key in.\r
+        //\r
+        if (EFI_ERROR (Status)) {\r
+          ControlFlag = CfReadKey;\r
+          continue;\r
+        }\r
+      }\r
+\r
+      switch (Key.UnicodeChar) {\r
+      case CHAR_CARRIAGE_RETURN:\r
+        Selection       = MenuOption;\r
+        ScreenOperation = UiSelect;\r
+        gDirection      = 0;\r
+        break;\r
+\r
+      //\r
+      // We will push the adjustment of these numeric values directly to the input handler\r
+      //\r
+      case '+':\r
+      case '-':\r
+        if ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) || (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)) {\r
+\r
+          if (Key.UnicodeChar == '+') {\r
+            gDirection = SCAN_RIGHT;\r
+          } else {\r
+            gDirection = SCAN_LEFT;\r
+          }\r
+\r
+          Status = ProcessOptions (MenuOption, TRUE, FileFormTagsHead, NULL, &OptionString);\r
+        }\r
+        break;\r
+\r
+      case '^':\r
+        ScreenOperation = UiUp;\r
+        break;\r
+\r
+      case 'V':\r
+      case 'v':\r
+        ScreenOperation = UiDown;\r
+        break;\r
+\r
+      case ' ':\r
+        if (gClassOfVfr != EFI_FRONT_PAGE_SUBCLASS) {\r
+          if (SubMenu) {\r
+            if (MenuOption->ThisTag->Operand == EFI_IFR_CHECKBOX_OP && !(MenuOption->ThisTag->GrayOut)) {\r
+              gST->ConOut->SetCursorPosition (gST->ConOut, MenuOption->Col, MenuOption->Row);\r
+              gST->ConOut->OutputString (gST->ConOut, MenuOption->Description);\r
+              Selection       = MenuOption;\r
+              ScreenOperation = UiSelect;\r
+            }\r
+          }\r
+        }\r
+        break;\r
+\r
+      case CHAR_NULL:\r
+        if (((Key.ScanCode == SCAN_F1) && ((gFunctionKeySetting & FUNCTION_ONE) != FUNCTION_ONE)) ||\r
+            ((Key.ScanCode == SCAN_F2) && ((gFunctionKeySetting & FUNCTION_TWO) != FUNCTION_TWO)) ||\r
+            ((Key.ScanCode == SCAN_F9) && ((gFunctionKeySetting & FUNCTION_NINE) != FUNCTION_NINE)) ||\r
+            ((Key.ScanCode == SCAN_F10) && ((gFunctionKeySetting & FUNCTION_TEN) != FUNCTION_TEN))\r
+            ) {\r
+          //\r
+          // If the function key has been disabled, just ignore the key.\r
+          //\r
+        } else {\r
+          for (Index = 0; Index < sizeof (gScanCodeToOperation) / sizeof (gScanCodeToOperation[0]); Index++) {\r
+            if (Key.ScanCode == gScanCodeToOperation[Index].ScanCode) {\r
+              if ((Key.ScanCode == SCAN_F9) || (Key.ScanCode == SCAN_F10)) {\r
+                if (SubMenu) {\r
+                  ScreenOperation = gScanCodeToOperation[Index].ScreenOperation;\r
+                }\r
+              } else {\r
+                ScreenOperation = gScanCodeToOperation[Index].ScreenOperation;\r
+              }\r
+            }\r
+          }\r
+        }\r
+        break;\r
+      }\r
+      break;\r
+\r
+    case CfScreenOperation:\r
+      IfrBinary = gBinaryDataHead;\r
+\r
+      //\r
+      // Advance to the Ifr we are using\r
+      //\r
+      for (Index = 0; Index < gActiveIfr; Index++) {\r
+        IfrBinary = IfrBinary->Next;\r
+      }\r
+\r
+      if (ScreenOperation != UiPrevious && ScreenOperation != UiReset) {\r
+        //\r
+        // If the screen has no menu items, and the user didn't select UiPrevious, or UiReset\r
+        // ignore the selection and go back to reading keys.\r
+        //\r
+        if (IsListEmpty (&Menu)) {\r
+          ControlFlag = CfReadKey;\r
+          break;\r
+        }\r
+        //\r
+        // if there is nothing logical to place a cursor on, just move on to wait for a key.\r
+        //\r
+        for (Link = Menu.ForwardLink; Link != &Menu; Link = Link->ForwardLink) {\r
+          NextMenuOption = CR (Link, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+          if (!(NextMenuOption->ThisTag->GrayOut) && (NextMenuOption->ThisTag->Operand != EFI_IFR_SUBTITLE_OP)) {\r
+            break;\r
+          }\r
+        }\r
+\r
+        if (Link == &Menu) {\r
+          ControlFlag = CfPrepareToReadKey;\r
+          break;\r
+        }\r
+      }\r
+\r
+      for (Index = 0;\r
+           Index < sizeof (gScreenOperationToControlFlag) / sizeof (gScreenOperationToControlFlag[0]);\r
+           Index++\r
+          ) {\r
+        if (ScreenOperation == gScreenOperationToControlFlag[Index].ScreenOperation) {\r
+          ControlFlag = gScreenOperationToControlFlag[Index].ControlFlag;\r
+        }\r
+      }\r
+\r
+      break;\r
+\r
+    case CfUiPrevious:\r
+      ControlFlag = CfCheckSelection;\r
+      //\r
+      // Check for tags that might have LATE_CHECK enabled.  If they do, we can't switch pages or save NV data.\r
+      //\r
+      if (MenuOption != NULL) {\r
+        if (!SelectionsAreValid (MenuOption, FileFormTagsHead)) {\r
+          Selection = NULL;\r
+          Repaint   = TRUE;\r
+          break;\r
+        }\r
+      }\r
+\r
+      if (IsListEmpty (&gMenuList)) {\r
+        Selection = NULL;\r
+        if (IsListEmpty (&Menu)) {\r
+          ControlFlag = CfReadKey;\r
+        }\r
+        break;\r
+      }\r
+\r
+      gLastOpr = TRUE;\r
+\r
+      while (gMenuRefreshHead != NULL) {\r
+        OldMenuRefreshEntry = gMenuRefreshHead->Next;\r
+\r
+        FreePool (gMenuRefreshHead);\r
+\r
+        gMenuRefreshHead = OldMenuRefreshEntry;\r
+      }\r
+      //\r
+      // Remove the Cached page entry, free and init the menus, flag Selection as jumping to previous page and a valid Tag\r
+      //\r
+      if (SubMenu) {\r
+        UiRemoveMenuListEntry (MenuOption, &Selection);\r
+        Selection->Previous = TRUE;\r
+        UiFreeMenu ();\r
+        UiInitMenu ();\r
+      }\r
+\r
+      gActiveIfr = Selection->IfrNumber;\r
+      return Selection;\r
+\r
+    case CfUiSelect:\r
+      ControlFlag = CfCheckSelection;\r
+\r
+      ExtractRequestedNvMap (FileFormTags, MenuOption->ThisTag->VariableNumber, &VariableDefinition);\r
+\r
+      if (SubMenu) {\r
+        if ((MenuOption->ThisTag->Operand == EFI_IFR_TEXT_OP &&\r
+            !(MenuOption->ThisTag->Flags & EFI_IFR_FLAG_INTERACTIVE)) ||\r
+            (MenuOption->ThisTag->GrayOut) ||\r
+            (MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) ||\r
+            (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)) {\r
+            Selection = NULL;\r
+            break;\r
+          }\r
+\r
+        NewLine = TRUE;\r
+        UpdateKeyHelp (MenuOption, TRUE);\r
+        Status = ProcessOptions (MenuOption, TRUE, FileFormTagsHead, PageData, &OptionString);\r
+\r
+        if (EFI_ERROR (Status)) {\r
+          Selection = NULL;\r
+          Repaint   = TRUE;\r
+          break;\r
+        }\r
+\r
+        if (OptionString != NULL) {\r
+          PrintStringAt (LocalScreen.LeftColumn + gPromptBlockWidth + 1, MenuOption->Row, OptionString);\r
+        }\r
+\r
+        if (MenuOption->ThisTag->Flags & EFI_IFR_FLAG_INTERACTIVE) {\r
+          Selection = MenuOption;\r
+        }\r
+\r
+        if (Selection == NULL) {\r
+          break;\r
+        }\r
+\r
+        Location = (UINT8 *) &PageData->EntryCount;\r
+\r
+        //\r
+        // If not a goto, dump single piece of data, otherwise dump everything\r
+        //\r
+        if (Selection->ThisTag->Operand == EFI_IFR_REF_OP) {\r
+          //\r
+          // Check for tags that might have LATE_CHECK enabled.  If they do, we can't switch pages or save NV data.\r
+          //\r
+          if (!SelectionsAreValid (MenuOption, FileFormTagsHead)) {\r
+            Selection = NULL;\r
+            Repaint   = TRUE;\r
+            break;\r
+          }\r
+\r
+          UiAddMenuListEntry (Selection);\r
+          gPriorMenuEntry = 0;\r
+\r
+          //\r
+          // Now that we added a menu entry specific to a goto, we can always go back when someone hits the UiPrevious\r
+          //\r
+          UiMenuList                    = CR (gMenuList.ForwardLink, UI_MENU_LIST, MenuLink, UI_MENU_LIST_SIGNATURE);\r
+          UiMenuList->FormerEntryNumber = MenuOption->EntryNumber;\r
+\r
+          gLastOpr                      = FALSE;\r
+\r
+          //\r
+          // Rewind to the beginning of the menu\r
+          //\r
+          for (; NewPos->BackLink != &Menu; NewPos = NewPos->BackLink)\r
+            ;\r
+\r
+          //\r
+          // Get Total Count of Menu entries\r
+          //\r
+          for (Count = 1; NewPos->ForwardLink != &Menu; NewPos = NewPos->ForwardLink) {\r
+            Count++;\r
+          }\r
+          //\r
+          // Rewind to the beginning of the menu\r
+          //\r
+          for (; NewPos->BackLink != &Menu; NewPos = NewPos->BackLink)\r
+            ;\r
+\r
+          //\r
+          // Copy the number of entries being described to the PageData location\r
+          //\r
+          CopyMem (&Location[0], &Count, sizeof (UINT32));\r
+\r
+          for (Index = 4; NewPos->ForwardLink != &Menu; Index = Index + MenuOption->ThisTag->StorageWidth + 2) {\r
+\r
+            MenuOption          = CR (NewPos, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+            Location[Index]     = MenuOption->ThisTag->Operand;\r
+            Location[Index + 1] = (UINT8) (MenuOption->ThisTag->StorageWidth + 4);\r
+            CopyMem (\r
+              &Location[Index + 4],\r
+              &VariableDefinition->NvRamMap[MenuOption->ThisTag->StorageStart],\r
+              MenuOption->ThisTag->StorageWidth\r
+              );\r
+            NewPos = NewPos->ForwardLink;\r
+          }\r
+        } else {\r
+\r
+          gPriorMenuEntry = MenuOption->EntryNumber;\r
+\r
+          Count           = 1;\r
+\r
+          //\r
+          // Copy the number of entries being described to the PageData location\r
+          //\r
+          CopyMem (&Location[0], &Count, sizeof (UINT32));\r
+\r
+          //\r
+          // Start at PageData[4] since the EntryCount is a UINT32\r
+          //\r
+          Index = 4;\r
+\r
+          //\r
+          // Copy data to destination\r
+          //\r
+          Location[Index]     = MenuOption->ThisTag->Operand;\r
+          Location[Index + 1] = (UINT8) (MenuOption->ThisTag->StorageWidth + 4);\r
+          CopyMem (\r
+            &Location[Index + 4],\r
+            &VariableDefinition->NvRamMap[MenuOption->ThisTag->StorageStart],\r
+            MenuOption->ThisTag->StorageWidth\r
+            );\r
+        }\r
+      }\r
+      break;\r
+\r
+    case CfUiReset:\r
+      ControlFlag = CfCheckSelection;\r
+      gLastOpr    = FALSE;\r
+      if (gClassOfVfr == EFI_FRONT_PAGE_SUBCLASS) {\r
+        break;\r
+      }\r
+      //\r
+      // If NV flag is up, prompt user\r
+      //\r
+      if (gNvUpdateRequired) {\r
+        Status      = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
+\r
+        YesResponse = gYesResponse[0];\r
+        NoResponse  = gNoResponse[0];\r
+\r
+        do {\r
+          CreateDialog (3, TRUE, 0, NULL, &Key, gEmptyString, gAreYouSure, gEmptyString);\r
+        } while\r
+        (\r
+          (Key.ScanCode != SCAN_ESC) &&\r
+          ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (NoResponse | UPPER_LOWER_CASE_OFFSET)) &&\r
+          ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (YesResponse | UPPER_LOWER_CASE_OFFSET))\r
+        );\r
+\r
+        //\r
+        // If the user hits the YesResponse key\r
+        //\r
+        if ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) == (YesResponse | UPPER_LOWER_CASE_OFFSET)) {\r
+        } else {\r
+          Repaint = TRUE;\r
+          NewLine = TRUE;\r
+          break;\r
+        }\r
+      }\r
+      //\r
+      // Check for tags that might have LATE_CHECK enabled.  If they do, we can't switch pages or save NV data.\r
+      //\r
+      if (MenuOption != NULL) {\r
+        if (!SelectionsAreValid (MenuOption, FileFormTagsHead)) {\r
+          Selection = NULL;\r
+          Repaint   = TRUE;\r
+          NewLine   = TRUE;\r
+          break;\r
+        }\r
+      }\r
+\r
+      gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
+      gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
+\r
+      if (SubMenu) {\r
+        UiFreeMenuList ();\r
+        gST->ConOut->ClearScreen (gST->ConOut);\r
+        return NULL;\r
+      }\r
+\r
+      UpdateStatusBar (INPUT_ERROR, MenuOption->ThisTag->Flags, FALSE);\r
+      UpdateStatusBar (NV_UPDATE_REQUIRED, MenuOption->ThisTag->Flags, FALSE);\r
+\r
+      if (IfrBinary->UnRegisterOnExit) {\r
+        Hii->RemovePack (Hii, MenuOption->Handle);\r
+      }\r
+\r
+      UiFreeMenu ();\r
+\r
+      //\r
+      // Clean up the allocated data buffers\r
+      //\r
+      FreeData (FileFormTagsHead, FormattedString, OptionString);\r
+\r
+      gST->ConOut->ClearScreen (gST->ConOut);\r
+      return NULL;\r
+\r
+    case CfUiLeft:\r
+      ControlFlag = CfCheckSelection;\r
+      if ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) || (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)) {\r
+        if (MenuOption->Skip == 1) {\r
+          //\r
+          // In the tail of the Date/Time op-code set, go left.\r
+          //\r
+          NewPos = NewPos->BackLink;\r
+        } else {\r
+          //\r
+          // In the middle of the Data/Time op-code set, go left.\r
+          //\r
+          NextMenuOption = CR (NewPos->ForwardLink, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+          if (NextMenuOption->Skip == 1) {\r
+            NewPos = NewPos->BackLink;\r
+          }\r
+        }\r
+      }\r
+      break;\r
+\r
+    case CfUiRight:\r
+      ControlFlag = CfCheckSelection;\r
+      if ((MenuOption->Skip == 0) &&\r
+          ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) || (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP))\r
+          ) {\r
+        //\r
+        // We are in the head or middle of the Date/Time op-code set, advance right.\r
+        //\r
+        NewPos = NewPos->ForwardLink;\r
+      }\r
+      break;\r
+\r
+    case CfUiUp:\r
+      ControlFlag = CfCheckSelection;\r
+\r
+      if (NewPos->BackLink != &Menu) {\r
+        NewLine = TRUE;\r
+        //\r
+        // Adjust Date/Time position before we advance forward.\r
+        //\r
+        AdjustDateAndTimePosition (TRUE, &NewPos);\r
+\r
+        //\r
+        // Caution that we have already rewind to the top, don't go backward in this situation.\r
+        //\r
+        if (NewPos->BackLink != &Menu) {\r
+          NewPos = NewPos->BackLink;\r
+        }\r
+\r
+        PreviousMenuOption = CR (NewPos, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+\r
+        //\r
+        // Since the behavior of hitting the up arrow on a Date/Time op-code is intended\r
+        // to be one that back to the previous set of op-codes, we need to advance to the sencond\r
+        // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate\r
+        // checking can be done.\r
+        //\r
+        DataAndTimeLineNumberPad = AdjustDateAndTimePosition (TRUE, &NewPos);\r
+\r
+        if (SubMenu) {\r
+          //\r
+          // If the previous MenuOption contains a display-only op-code, skip to the next one\r
+          //\r
+          if (PreviousMenuOption->ThisTag->Operand == EFI_IFR_SUBTITLE_OP || PreviousMenuOption->ThisTag->GrayOut) {\r
+            //\r
+            // This is ok as long as not at the end of the list\r
+            //\r
+            if (NewPos->BackLink == &Menu) {\r
+              //\r
+              // If we are at the start of the list, then this list must start with a display only\r
+              // piece of data, so do not allow the backward motion\r
+              //\r
+              ScreenOperation = UiDown;\r
+\r
+              if (PreviousMenuOption->Row <= TopRow) {\r
+                if (TopOfScreen->BackLink != &Menu) {\r
+                  TopOfScreen = TopOfScreen->BackLink;\r
+                  Repaint     = TRUE;\r
+                }\r
+              }\r
+\r
+              UpdateStatusBar (INPUT_ERROR, PreviousMenuOption->ThisTag->Flags, FALSE);\r
+              break;\r
+            }\r
+          }\r
+        }\r
+        //\r
+        // Check the previous menu entry to see if it was a zero-length advance.  If it was,\r
+        // don't worry about a redraw.\r
+        //\r
+        if ((MenuOption->Row - PreviousMenuOption->Skip - DataAndTimeLineNumberPad < TopRow) ||\r
+            (PreviousMenuOption->Skip > MenuOption->Row)\r
+            ) {\r
+          do {\r
+            if (TopOfScreen->BackLink == &Menu) {\r
+              break;\r
+            }\r
+\r
+            Repaint = TRUE;\r
+\r
+            //\r
+            // Is the current top of screen a zero-advance op-code?\r
+            // If so, keep moving forward till we hit a >0 advance op-code\r
+            //\r
+            SavedMenuOption = CR (TopOfScreen->BackLink, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+            TopOfScreen     = TopOfScreen->BackLink;\r
+          } while (SavedMenuOption->Skip == 0);\r
+          //\r
+          // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.\r
+          //\r
+          AdjustDateAndTimePosition (TRUE, &TopOfScreen);\r
+        }\r
+\r
+        UpdateStatusBar (INPUT_ERROR, MenuOption->ThisTag->Flags, FALSE);\r
+      } else {\r
+        if (SubMenu) {\r
+          SavedMenuOption = MenuOption;\r
+          MenuOption      = CR (NewPos, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+          if (MenuOption->ThisTag->Operand == EFI_IFR_SUBTITLE_OP || MenuOption->ThisTag->GrayOut) {\r
+            //\r
+            // If we are at the end of the list and sitting on a text op, we need to more forward\r
+            //\r
+            ScreenOperation = UiDown;\r
+            ControlFlag     = CfScreenOperation;\r
+            break;\r
+          }\r
+\r
+          MenuOption = SavedMenuOption;\r
+        }\r
+      }\r
+      break;\r
+\r
+    case CfUiPageUp:\r
+      ControlFlag     = CfCheckSelection;\r
+\r
+      SavedListEntry  = NewPos;\r
+      Link            = TopOfScreen;\r
+      for (Index = BottomRow; Index >= TopRow + 1; Index -= MenuOption->Skip) {\r
+        if (Link->BackLink == &Menu) {\r
+          TopOfScreen = Link;\r
+          Link        = SavedListEntry;\r
+          MenuOption  = CR (Link, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+          break;\r
+        }\r
+\r
+        NewLine         = TRUE;\r
+        Repaint         = TRUE;\r
+        Link            = Link->BackLink;\r
+        MenuOption      = CR (Link, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+        TopOfScreen     = Link;\r
+        SavedListEntry  = Link;\r
+      }\r
+\r
+      NewPos = Link;\r
+\r
+      //\r
+      // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.\r
+      // Don't do this when we are already in the first page.\r
+      //\r
+      if (Repaint) {\r
+        AdjustDateAndTimePosition (TRUE, &TopOfScreen);\r
+        AdjustDateAndTimePosition (TRUE, &NewPos);\r
+        MenuOption = CR (NewPos, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+      }\r
+      break;\r
+\r
+    case CfUiPageDown:\r
+      ControlFlag     = CfCheckSelection;\r
+\r
+      SavedListEntry  = NewPos;\r
+      Link            = TopOfScreen;\r
+      NewPos          = TopOfScreen;\r
+      for (Index = TopRow; Index <= BottomRow - 1; Index += MenuOption->Skip) {\r
+        if (NewPos->ForwardLink == &Menu) {\r
+          NewPos      = SavedListEntry;\r
+          MenuOption  = CR (NewPos, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+          Link        = TopOfScreen;\r
+          NewLine     = FALSE;\r
+          Repaint     = FALSE;\r
+          break;\r
+        }\r
+\r
+        NewLine     = TRUE;\r
+        Repaint     = TRUE;\r
+        MenuOption  = CR (NewPos, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+        NewPos      = NewPos->ForwardLink;\r
+        Link        = NewPos;\r
+      }\r
+\r
+      TopOfScreen = Link;\r
+\r
+      //\r
+      // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.\r
+      // Don't do this when we are already in the last page.\r
+      //\r
+      if (Repaint) {\r
+        AdjustDateAndTimePosition (TRUE, &TopOfScreen);\r
+        AdjustDateAndTimePosition (TRUE, &NewPos);\r
+        MenuOption = CR (NewPos, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+      }\r
+      break;\r
+\r
+    case CfUiDown:\r
+      ControlFlag = CfCheckSelection;\r
+      //\r
+      // Since the behavior of hitting the down arrow on a Date/Time op-code is intended\r
+      // to be one that progresses to the next set of op-codes, we need to advance to the last\r
+      // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate\r
+      // checking can be done.  The only other logic we need to introduce is that if a Date/Time\r
+      // op-code is the last entry in the menu, we need to rewind back to the first op-code of\r
+      // the Date/Time op-code.\r
+      //\r
+      DataAndTimeLineNumberPad = AdjustDateAndTimePosition (FALSE, &NewPos);\r
+\r
+      if (NewPos->ForwardLink != &Menu) {\r
+        NewLine         = TRUE;\r
+        NewPos          = NewPos->ForwardLink;\r
+        NextMenuOption  = CR (NewPos, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+\r
+        if (SubMenu) {\r
+          //\r
+          // If the next MenuOption contains a display-only op-code, skip to the next one\r
+          // Also if the next MenuOption is date or time,\r
+          //\r
+          if (NextMenuOption->ThisTag->Operand == EFI_IFR_SUBTITLE_OP || NextMenuOption->ThisTag->GrayOut) {\r
+            //\r
+            // This is ok as long as not at the end of the list\r
+            //\r
+            if (NewPos == &Menu) {\r
+              //\r
+              // If we are at the end of the list, then this list must end with a display only\r
+              // piece of data, so do not allow the forward motion\r
+              //\r
+              UpdateStatusBar (INPUT_ERROR, NextMenuOption->ThisTag->Flags, FALSE);\r
+              NewPos          = NewPos->BackLink;\r
+              ScreenOperation = UiUp;\r
+              break;\r
+            }\r
+          }\r
+        }\r
+        //\r
+        // An option might be multi-line, so we need to reflect that data in the overall skip value\r
+        //\r
+        UpdateOptionSkipLines (PageData, NextMenuOption, FileFormTagsHead, &OptionString, SkipValue);\r
+\r
+        if (NextMenuOption->Skip > 1) {\r
+          Temp = MenuOption->Row + MenuOption->Skip + NextMenuOption->Skip - 1;\r
+        } else {\r
+          Temp = MenuOption->Row + MenuOption->Skip + DataAndTimeLineNumberPad;\r
+        }\r
+        //\r
+        // If we are going to scroll\r
+        //\r
+        if (Temp > BottomRow) {\r
+          do {\r
+            //\r
+            // Is the current top of screen a zero-advance op-code?\r
+            // If so, keep moving forward till we hit a >0 advance op-code\r
+            //\r
+            SavedMenuOption = CR (TopOfScreen, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+\r
+            //\r
+            // If bottom op-code is more than one line or top op-code is more than one line\r
+            //\r
+            if ((NextMenuOption->Skip > 1) || (MenuOption->Skip > 1)) {\r
+              //\r
+              // Is the bottom op-code greater than or equal in size to the top op-code?\r
+              //\r
+              if ((Temp - BottomRow) >= (SavedMenuOption->Skip - OldSkipValue)) {\r
+                //\r
+                // Skip the top op-code\r
+                //\r
+                TopOfScreen     = TopOfScreen->ForwardLink;\r
+                Difference      = (Temp - BottomRow) - (SavedMenuOption->Skip - OldSkipValue);\r
+\r
+                OldSkipValue    = Difference;\r
+\r
+                SavedMenuOption = CR (TopOfScreen, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+\r
+                //\r
+                // If we have a remainder, skip that many more op-codes until we drain the remainder\r
+                //\r
+                for (;\r
+                     Difference >= (INTN) SavedMenuOption->Skip;\r
+                     Difference = Difference - (INTN) SavedMenuOption->Skip\r
+                    ) {\r
+                  //\r
+                  // Since the Difference is greater than or equal to this op-code's skip value, skip it\r
+                  //\r
+                  TopOfScreen     = TopOfScreen->ForwardLink;\r
+                  SavedMenuOption = CR (TopOfScreen, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+                  if (Difference < (INTN) SavedMenuOption->Skip) {\r
+                    Difference = SavedMenuOption->Skip - Difference - 1;\r
+                    break;\r
+                  } else {\r
+                    if (Difference == (INTN) SavedMenuOption->Skip) {\r
+                      TopOfScreen     = TopOfScreen->ForwardLink;\r
+                      SavedMenuOption = CR (TopOfScreen, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+                      Difference      = SavedMenuOption->Skip - Difference;\r
+                      break;\r
+                    }\r
+                  }\r
+                }\r
+                //\r
+                // Since we will act on this op-code in the next routine, and increment the\r
+                // SkipValue, set the skips to one less than what is required.\r
+                //\r
+                SkipValue = Difference - 1;\r
+\r
+              } else {\r
+                //\r
+                // Since we will act on this op-code in the next routine, and increment the\r
+                // SkipValue, set the skips to one less than what is required.\r
+                //\r
+                SkipValue = OldSkipValue + (Temp - BottomRow) - 1;\r
+              }\r
+            } else {\r
+              if ((OldSkipValue + 1) == (INTN) SavedMenuOption->Skip) {\r
+                TopOfScreen = TopOfScreen->ForwardLink;\r
+                break;\r
+              } else {\r
+                SkipValue = OldSkipValue;\r
+              }\r
+            }\r
+            //\r
+            // If the op-code at the top of the screen is more than one line, let's not skip it yet\r
+            // Let's set a skip flag to smoothly scroll the top of the screen.\r
+            //\r
+            if (SavedMenuOption->Skip > 1) {\r
+              if (SavedMenuOption == NextMenuOption) {\r
+                SkipValue = 0;\r
+              } else {\r
+                SkipValue++;\r
+              }\r
+            } else {\r
+              SkipValue   = 0;\r
+              TopOfScreen = TopOfScreen->ForwardLink;\r
+            }\r
+          } while (SavedMenuOption->Skip == 0);\r
+\r
+          Repaint       = TRUE;\r
+          OldSkipValue  = SkipValue;\r
+        }\r
+\r
+        UpdateStatusBar (INPUT_ERROR, MenuOption->ThisTag->Flags, FALSE);\r
+\r
+      } else {\r
+        if (SubMenu) {\r
+          SavedMenuOption = MenuOption;\r
+          MenuOption      = CR (NewPos, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+          if (MenuOption->ThisTag->Operand == EFI_IFR_SUBTITLE_OP || MenuOption->ThisTag->GrayOut) {\r
+            //\r
+            // If we are at the end of the list and sitting on a text op, we need to more forward\r
+            //\r
+            ScreenOperation = UiUp;\r
+            ControlFlag     = CfScreenOperation;\r
+            break;\r
+          }\r
+\r
+          MenuOption = SavedMenuOption;\r
+          //\r
+          // If we are at the end of the list and sitting on a Date/Time op, rewind to the head.\r
+          //\r
+          AdjustDateAndTimePosition (TRUE, &NewPos);\r
+        }\r
+      }\r
+      break;\r
+\r
+    case CfUiSave:\r
+      ControlFlag = CfCheckSelection;\r
+      //\r
+      // Check for tags that might have LATE_CHECK enabled.  If they do, we can't switch pages or save NV data.\r
+      //\r
+      if (MenuOption != NULL) {\r
+        if (!SelectionsAreValid (MenuOption, FileFormTagsHead)) {\r
+          Selection = NULL;\r
+          Repaint   = TRUE;\r
+          break;\r
+        }\r
+      }\r
+      //\r
+      // If callbacks are active, and the callback has a Write method, try to use it\r
+      //\r
+      if (FileFormTags->VariableDefinitions->VariableName == NULL) {\r
+        if ((FormCallback != NULL) && (FormCallback->NvWrite != NULL)) {\r
+          Status = FormCallback->NvWrite (\r
+                                  FormCallback,\r
+                                  (CHAR16 *) L"Setup",\r
+                                  &FileFormTags->FormTags.Tags[0].GuidValue,\r
+                                  EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                                  VariableDefinition->VariableSize,\r
+                                  (VOID *) VariableDefinition->NvRamMap,\r
+                                  &gResetRequired\r
+                                  );\r
+\r
+        } else {\r
+          Status = gRT->SetVariable (\r
+                          (CHAR16 *) L"Setup",\r
+                          &FileFormTags->FormTags.Tags[0].GuidValue,\r
+                          EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                          VariableDefinition->VariableSize,\r
+                          (VOID *) VariableDefinition->NvRamMap\r
+                          );\r
+        }\r
+      } else {\r
+        VariableDefinition = FileFormTags->VariableDefinitions;\r
+\r
+        for (; VariableDefinition != NULL; VariableDefinition = VariableDefinition->Next) {\r
+          if ((FormCallback != NULL) && (FormCallback->NvWrite != NULL)) {\r
+            Status = FormCallback->NvWrite (\r
+                                    FormCallback,\r
+                                    VariableDefinition->VariableName,\r
+                                    &VariableDefinition->Guid,\r
+                                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                                    VariableDefinition->VariableSize,\r
+                                    (VOID *) VariableDefinition->NvRamMap,\r
+                                    &gResetRequired\r
+                                    );\r
+\r
+          } else {\r
+            Status = gRT->SetVariable (\r
+                            VariableDefinition->VariableName,\r
+                            &VariableDefinition->Guid,\r
+                            EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                            VariableDefinition->VariableSize,\r
+                            (VOID *) VariableDefinition->NvRamMap\r
+                            );\r
+          }\r
+        }\r
+      }\r
+\r
+      UpdateStatusBar (INPUT_ERROR, MenuOption->ThisTag->Flags, FALSE);\r
+      UpdateStatusBar (NV_UPDATE_REQUIRED, MenuOption->ThisTag->Flags, FALSE);\r
+      break;\r
+\r
+    case CfUiDefault:\r
+      ControlFlag = CfCheckSelection;\r
+\r
+      NvMapListHead = NULL;\r
+\r
+      Status = Hii->GetDefaultImage (Hii, MenuOption->Handle, EFI_IFR_FLAG_DEFAULT, &NvMapListHead);\r
+\r
+      if (!EFI_ERROR (Status)) {\r
+        ASSERT_EFI_ERROR (NULL != NvMapListHead);\r
+\r
+        NvMapListNode = NvMapListHead;\r
+\r
+        while (NULL != NvMapListNode) {\r
+          if (FileFormTags->VariableDefinitions->VariableId == NvMapListNode->VariablePack->VariableId) {\r
+            NvMap     = (VOID *) ((CHAR8 *) NvMapListNode->VariablePack + sizeof (EFI_HII_VARIABLE_PACK) + NvMapListNode->VariablePack->VariableNameLength);\r
+            NvMapSize = NvMapListNode->VariablePack->Header.Length  - sizeof (EFI_HII_VARIABLE_PACK) - NvMapListNode->VariablePack->VariableNameLength;\r
+            break;\r
+            }\r
+          NvMapListNode = NvMapListNode->NextVariablePack;\r
+        }\r
+\r
+        //\r
+        // Free the buffer that was allocated.\r
+        //\r
+        FreePool (FileFormTags->VariableDefinitions->NvRamMap);\r
+        FreePool (FileFormTags->VariableDefinitions->FakeNvRamMap);\r
+\r
+        //\r
+        // Allocate, copy the NvRamMap.\r
+        //\r
+        FileFormTags->VariableDefinitions->VariableFakeSize = (UINT16) (FileFormTags->VariableDefinitions->VariableFakeSize - FileFormTags->VariableDefinitions->VariableSize);\r
+        FileFormTags->VariableDefinitions->VariableSize = (UINT16) NvMapSize;\r
+        FileFormTags->VariableDefinitions->VariableFakeSize = (UINT16) (FileFormTags->VariableDefinitions->VariableFakeSize + FileFormTags->VariableDefinitions->VariableSize);\r
+\r
+        FileFormTags->VariableDefinitions->NvRamMap = AllocateZeroPool (FileFormTags->VariableDefinitions->VariableSize);\r
+        ASSERT (FileFormTags->VariableDefinitions->NvRamMap != NULL);\r
+\r
+        FileFormTags->VariableDefinitions->FakeNvRamMap = AllocateZeroPool (NvMapSize + FileFormTags->VariableDefinitions->VariableFakeSize);\r
+        ASSERT (FileFormTags->VariableDefinitions->FakeNvRamMap != NULL);\r
+\r
+        CopyMem (FileFormTags->VariableDefinitions->NvRamMap, NvMap, NvMapSize);\r
+        FreePool (NvMapListHead);\r
+      }\r
+\r
+      UpdateStatusBar (NV_UPDATE_REQUIRED, MenuOption->ThisTag->Flags, TRUE);\r
+      Repaint = TRUE;\r
+      //\r
+      // After the repaint operation, we should refresh the highlight.\r
+      //\r
+      NewLine = TRUE;\r
+      break;\r
+\r
+    case CfUiNoOperation:\r
+      ControlFlag = CfCheckSelection;\r
+      break;\r
+\r
+    case CfExit:\r
+      while (gMenuRefreshHead != NULL) {\r
+        OldMenuRefreshEntry = gMenuRefreshHead->Next;\r
+\r
+        FreePool (gMenuRefreshHead);\r
+\r
+        gMenuRefreshHead = OldMenuRefreshEntry;\r
+      }\r
+\r
+      gST->ConOut->SetCursorPosition (gST->ConOut, 0, Row + 4);\r
+      gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
+      gST->ConOut->OutputString (gST->ConOut, (CHAR16 *) L"\n");\r
+\r
+      gActiveIfr = MenuOption->IfrNumber;\r
+      return Selection;\r
+\r
+    default:\r
+      break;\r
+    }\r
+  }\r
+}\r
+\r
+BOOLEAN\r
+ValueIsScroll (\r
+  IN  BOOLEAN                 Direction,\r
+  IN  LIST_ENTRY              *CurrentPos\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Determine if the menu is the last menu that can be selected.\r
+\r
+Arguments:\r
+  Direction - the scroll direction. False is down. True is up.\r
+\r
+Returns:\r
+  FALSE -- the menu isn't the last menu that can be selected.\r
+  TRUE  -- the menu is the last menu that can be selected.\r
+--*/\r
+{\r
+  LIST_ENTRY      *Temp;\r
+  UI_MENU_OPTION  *MenuOption;\r
+  MenuOption  = NULL;\r
+\r
+  Temp        = Direction ? CurrentPos->BackLink : CurrentPos->ForwardLink;\r
+\r
+  if (Temp == &Menu) {\r
+    return TRUE;\r
+  }\r
+\r
+  for (; Temp != &Menu; Temp = Direction ? Temp->BackLink : Temp->ForwardLink) {\r
+    MenuOption = CR (Temp, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+    if (!(MenuOption->ThisTag->Operand == EFI_IFR_SUBTITLE_OP || MenuOption->ThisTag->GrayOut)) {\r
+      return FALSE;\r
+    }\r
+  }\r
+\r
+  return TRUE;\r
+}\r
+\r
+UINTN\r
+AdjustDateAndTimePosition (\r
+  IN  BOOLEAN                 DirectionUp,\r
+  IN  LIST_ENTRY              **CurrentPosition\r
+  )\r
+/*++\r
+Routine Description:\r
+  Adjust Data and Time tag position accordingly.\r
+  Data format :      [01/02/2004]      [11:22:33]\r
+  Line number :        0  0    1         0  0  1\r
+\r
+Arguments:\r
+  Direction - the up or down direction. False is down. True is up.\r
+  CurrentPos - Current position.\r
+\r
+Returns:\r
+  Return line number to pad. It is possible that we stand on a zero-advance\r
+  data or time opcode, so pad one line when we judge if we are going to scroll outside.\r
+--*/\r
+{\r
+  UINTN           Count;\r
+  LIST_ENTRY      *NewPosition;\r
+  UI_MENU_OPTION  *MenuOption;\r
+  UINTN           PadLineNumber;\r
+\r
+  PadLineNumber = 0;\r
+  NewPosition   = *CurrentPosition;\r
+  MenuOption    = CR (NewPosition, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+\r
+  if ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) || (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)) {\r
+    //\r
+    // Calculate the distance from current position to the last Date/Time op-code.\r
+    //\r
+    Count = 0;\r
+    while (MenuOption->ThisTag->NumberOfLines == 0) {\r
+      Count++;\r
+      NewPosition   = NewPosition->ForwardLink;\r
+      MenuOption    = CR (NewPosition, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE);\r
+      PadLineNumber = 1;\r
+    }\r
+\r
+    NewPosition = *CurrentPosition;\r
+    if (DirectionUp) {\r
+      //\r
+      // Since the behavior of hitting the up arrow on a Date/Time op-code is intended\r
+      // to be one that back to the previous set of op-codes, we need to advance to the first\r
+      // Date/Time op-code and leave the remaining logic in CfUiUp intact so the appropriate\r
+      // checking can be done.\r
+      //\r
+      while (Count++ < 2) {\r
+        NewPosition = NewPosition->BackLink;\r
+      }\r
+    } else {\r
+      //\r
+      // Since the behavior of hitting the down arrow on a Date/Time op-code is intended\r
+      // to be one that progresses to the next set of op-codes, we need to advance to the last\r
+      // Date/Time op-code and leave the remaining logic in CfUiDown intact so the appropriate\r
+      // checking can be done.\r
+      //\r
+      while (Count-- > 0) {\r
+        NewPosition = NewPosition->ForwardLink;\r
+      }\r
+    }\r
+\r
+    *CurrentPosition = NewPosition;\r
+  }\r
+\r
+  return PadLineNumber;\r
+}\r
diff --git a/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Ui.h b/IntelFrameworkModulePkg/Universal/SetupBrowserDxe/Ui.h
new file mode 100644 (file)
index 0000000..78a51d0
--- /dev/null
@@ -0,0 +1,440 @@
+/*++\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
+  Ui.h \r
+\r
+Abstract:\r
+\r
+  Head file UI\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+#ifndef _UI_H\r
+#define _UI_H\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+//\r
+// Globals\r
+//\r
+#define REGULAR_NUMERIC 0\r
+#define TIME_NUMERIC    1\r
+#define DATE_NUMERIC    2\r
+\r
+typedef enum {\r
+  UiNoOperation,\r
+  UiDefault,\r
+  UiSelect,\r
+  UiUp,\r
+  UiDown,\r
+  UiLeft,\r
+  UiRight,\r
+  UiReset,\r
+  UiSave,\r
+  UiPrevious,\r
+  UiPageUp,\r
+  UiPageDown,\r
+  UiMaxOperation\r
+} UI_SCREEN_OPERATION;\r
+\r
+typedef enum {\r
+  CfInitialization,\r
+  CfCheckSelection,\r
+  CfRepaint,\r
+  CfRefreshHighLight,\r
+  CfUpdateHelpString,\r
+  CfPrepareToReadKey,\r
+  CfReadKey,\r
+  CfScreenOperation,\r
+  CfUiPrevious,\r
+  CfUiSelect,\r
+  CfUiReset,\r
+  CfUiLeft,\r
+  CfUiRight,\r
+  CfUiUp,\r
+  CfUiPageUp,\r
+  CfUiPageDown,\r
+  CfUiDown,\r
+  CfUiSave,\r
+  CfUiDefault,\r
+  CfUiNoOperation,\r
+  CfExit,\r
+  CfMaxControlFlag\r
+} UI_CONTROL_FLAG;\r
+\r
+#define UI_MENU_OPTION_SIGNATURE  EFI_SIGNATURE_32 ('u', 'i', 'm', 'm')\r
+#define UI_MENU_LIST_SIGNATURE    EFI_SIGNATURE_32 ('u', 'i', 'm', 'l')\r
+\r
+typedef struct {\r
+  UINTN           Signature;\r
+  LIST_ENTRY      Link;\r
+\r
+  UINTN           Row;\r
+  UINTN           Col;\r
+  UINTN           OptCol;\r
+  CHAR16          *Description;\r
+  UINTN           Skip;\r
+\r
+  UINTN           IfrNumber;\r
+  VOID            *FormBinary;\r
+  EFI_HII_HANDLE  Handle;\r
+  EFI_TAG         *Tags;\r
+  UINTN           TagIndex;\r
+  EFI_TAG         *ThisTag;\r
+  UINT16          FormId;\r
+  BOOLEAN         Previous;\r
+  UINT16          EntryNumber;\r
+  UINT16          Consistency;\r
+  BOOLEAN         GrayOut;\r
+} UI_MENU_OPTION;\r
+\r
+typedef struct {\r
+  UINTN           Signature;\r
+  LIST_ENTRY      MenuLink;\r
+\r
+  UI_MENU_OPTION  Selection;\r
+  UINTN           FormerEntryNumber;\r
+} UI_MENU_LIST;\r
+\r
+typedef struct _MENU_REFRESH_ENTRY {\r
+  struct _MENU_REFRESH_ENTRY  *Next;\r
+  EFI_FILE_FORM_TAGS          *FileFormTagsHead;\r
+  UINTN                       CurrentColumn;\r
+  UINTN                       CurrentRow;\r
+  UINTN                       CurrentAttribute;\r
+  UI_MENU_OPTION              *MenuOption;  // Describes the entry needing an update\r
+} MENU_REFRESH_ENTRY;\r
+\r
+typedef struct {\r
+  UINT16              ScanCode;\r
+  UI_SCREEN_OPERATION ScreenOperation;\r
+} SCAN_CODE_TO_SCREEN_OPERATION;\r
+\r
+typedef struct {\r
+  UI_SCREEN_OPERATION ScreenOperation;\r
+  UI_CONTROL_FLAG     ControlFlag;\r
+} SCREEN_OPERATION_T0_CONTROL_FLAG;\r
+\r
+LIST_ENTRY          Menu;\r
+LIST_ENTRY          gMenuList;\r
+MENU_REFRESH_ENTRY  *gMenuRefreshHead;\r
+\r
+INTN                gEntryNumber;\r
+BOOLEAN             gLastOpr;\r
+//\r
+// Global Functions\r
+//\r
+VOID\r
+UiInitMenu (\r
+  VOID\r
+  )\r
+;\r
+\r
+VOID\r
+UiInitMenuList (\r
+  VOID\r
+  )\r
+;\r
+\r
+VOID\r
+UiRemoveMenuListEntry (\r
+  IN  UI_MENU_OPTION    *Selection,\r
+  OUT UI_MENU_OPTION    **PreviousSelection\r
+  )\r
+;\r
+\r
+VOID\r
+UiFreeMenuList (\r
+  VOID\r
+  )\r
+;\r
+\r
+VOID\r
+UiAddMenuListEntry (\r
+  IN UI_MENU_OPTION   *Selection\r
+  )\r
+;\r
+\r
+VOID\r
+UiFreeMenu (\r
+  VOID\r
+  )\r
+;\r
+\r
+VOID\r
+UiAddMenuOption (\r
+  IN CHAR16         *String,\r
+  IN EFI_HII_HANDLE Handle,\r
+  IN EFI_TAG        *Tag,\r
+  IN VOID           *FormBinary,\r
+  IN UINTN          IfrNumber\r
+  )\r
+;\r
+\r
+VOID\r
+UiAddSubMenuOption (\r
+  IN CHAR16           *String,\r
+  IN EFI_HII_HANDLE   Handle,\r
+  IN EFI_TAG          *Tag,\r
+  IN UINTN            TagIndex,\r
+  IN UINT16           FormId,\r
+  IN UINT16           MenuItemCount\r
+  )\r
+;\r
+\r
+UI_MENU_OPTION      *\r
+UiDisplayMenu (\r
+  IN  BOOLEAN                      SubMenu,\r
+  IN  EFI_FILE_FORM_TAGS           *FileFormTagsHead,\r
+  OUT EFI_IFR_DATA_ARRAY           *PageData\r
+  )\r
+;\r
+\r
+VOID\r
+InitPage (\r
+  VOID\r
+  )\r
+;\r
+\r
+UI_MENU_OPTION      *\r
+SetupBrowser (\r
+  IN  UI_MENU_OPTION              *Selection,\r
+  IN  BOOLEAN                     Callback,\r
+  IN  EFI_FILE_FORM_TAGS          *FileFormTagsHead,\r
+  IN  UINT8                       *CallbackData\r
+  )\r
+;\r
+\r
+\r
+VOID\r
+SetUnicodeMem (\r
+  IN VOID   *Buffer,\r
+  IN UINTN  Size,\r
+  IN CHAR16 Value\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+UiWaitForSingleEvent (\r
+  IN EFI_EVENT                Event,\r
+  IN UINT64                   Timeout OPTIONAL\r
+  )\r
+;\r
+\r
+VOID\r
+CreatePopUp (\r
+  IN  UINTN                       ScreenWidth,\r
+  IN  UINTN                       NumberOfLines,\r
+  IN  CHAR16                      *ArrayOfStrings,\r
+  ...\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+ReadString (\r
+  IN  UI_MENU_OPTION              *MenuOption,\r
+  OUT CHAR16                      *StringPtr\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+ReadPassword (\r
+  IN  UI_MENU_OPTION              *MenuOption,\r
+  IN  BOOLEAN                     PromptForPassword,\r
+  IN  EFI_TAG                     *Tag,\r
+  IN  EFI_IFR_DATA_ARRAY          *PageData,\r
+  IN  BOOLEAN                     SecondEntry,\r
+  IN  EFI_FILE_FORM_TAGS          *FileFormTags,\r
+  OUT CHAR16                      *StringPtr\r
+  )\r
+;\r
+\r
+VOID\r
+EncodePassword (\r
+  IN  CHAR16                      *Password,\r
+  IN  UINT8                       MaxSize\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+GetSelectionInputPopUp (\r
+  IN  UI_MENU_OPTION              *MenuOption,\r
+  IN  EFI_TAG                     *Tag,\r
+  IN  UINTN                       ValueCount,\r
+  OUT UINT16                      *Value,\r
+  OUT UINT16                      *KeyValue\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+GetSelectionInputLeftRight (\r
+  IN  UI_MENU_OPTION              *MenuOption,\r
+  IN  EFI_TAG                     *Tag,\r
+  IN  UINTN                       ValueCount,\r
+  OUT UINT16                      *Value\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+GetNumericInput (\r
+  IN  UI_MENU_OPTION              *MenuOption,\r
+  IN  EFI_FILE_FORM_TAGS          *FileFormTagsHead,\r
+  IN  BOOLEAN                     ManualInput,\r
+  IN  EFI_TAG                     *Tag,\r
+  IN  UINTN                       NumericType,\r
+  OUT UINT16                      *Value\r
+  )\r
+;\r
+\r
+VOID\r
+UpdateStatusBar (\r
+  IN  UINTN                       MessageType,\r
+  IN  UINT8                       Flags,\r
+  IN  BOOLEAN                     State\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+ProcessOptions (\r
+  IN  UI_MENU_OPTION              *MenuOption,\r
+  IN  BOOLEAN                     Selected,\r
+  IN  EFI_FILE_FORM_TAGS          *FileFormTagsHead,\r
+  IN  EFI_IFR_DATA_ARRAY          *PageData,\r
+  OUT CHAR16                      **OptionString\r
+  )\r
+;\r
+\r
+VOID\r
+ProcessHelpString (\r
+  IN  CHAR16                      *StringPtr,\r
+  OUT CHAR16                      **FormattedString,\r
+  IN  UINTN                       RowCount\r
+  )\r
+;\r
+\r
+VOID\r
+UpdateKeyHelp (\r
+  IN  UI_MENU_OPTION              *Selection,\r
+  IN  BOOLEAN                     Selected\r
+  )\r
+;\r
+\r
+BOOLEAN\r
+ValueIsNotValid (\r
+  IN  BOOLEAN                     Complex,\r
+  IN  UINT16                      Value,\r
+  IN  EFI_TAG                     *Tag,\r
+  IN  EFI_FILE_FORM_TAGS          *FileFormTags,\r
+  IN  STRING_REF                  *PopUp\r
+  )\r
+;\r
+\r
+VOID\r
+FreeData (\r
+  IN EFI_FILE_FORM_TAGS            *FileFormTagsHead,\r
+  IN CHAR16                        *FormattedString,\r
+  IN CHAR16                        *OptionString\r
+  )\r
+;\r
+\r
+VOID\r
+ClearLines (\r
+  UINTN                                       LeftColumn,\r
+  UINTN                                       RightColumn,\r
+  UINTN                                       TopRow,\r
+  UINTN                                       BottomRow,\r
+  UINTN                                       TextAttribute\r
+  )\r
+;\r
+\r
+UINTN\r
+GetStringWidth (\r
+  CHAR16                                      *String\r
+  )\r
+;\r
+\r
+UINT16\r
+GetLineByWidth (\r
+  IN      CHAR16                      *InputString,\r
+  IN      UINT16                      LineWidth,\r
+  IN OUT  UINTN                       *Index,\r
+  OUT     CHAR16                      **OutputString\r
+  )\r
+;\r
+\r
+UINT16\r
+GetWidth (\r
+  IN EFI_TAG                          *Tag,\r
+  IN EFI_HII_HANDLE                   Handle\r
+  )\r
+;\r
+\r
+VOID\r
+NewStrCat (\r
+  CHAR16                                      *Destination,\r
+  CHAR16                                      *Source\r
+  )\r
+;\r
+\r
+VOID\r
+IfrToFormTag (\r
+  IN  UINT8               OpCode,\r
+  IN  EFI_TAG             *TargetTag,\r
+  IN  VOID                *FormData,\r
+  EFI_VARIABLE_DEFINITION *VariableDefinitionsHead\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+ExtractNvValue (\r
+  IN  EFI_FILE_FORM_TAGS          *FileFormTags,\r
+  IN  UINT16                      VariableId,\r
+  IN  UINT16                      VariableSize,\r
+  IN  UINT16                      OffsetValue,\r
+  OUT VOID                        **Buffer\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+ExtractRequestedNvMap (\r
+  IN  EFI_FILE_FORM_TAGS          *FileFormTags,\r
+  IN  UINT16                      VariableId,\r
+  OUT EFI_VARIABLE_DEFINITION     **VariableDefinition\r
+  )\r
+;\r
+\r
+BOOLEAN\r
+ValueIsScroll (\r
+  IN  BOOLEAN                 Direction,\r
+  IN  LIST_ENTRY              *CurrentPos\r
+  )\r
+;\r
+\r
+UINTN\r
+AdjustDateAndTimePosition (\r
+  IN  BOOLEAN                 DirectionUp,\r
+  IN  LIST_ENTRY              **CurrentPosition\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+WaitForKeyStroke (\r
+  OUT  EFI_INPUT_KEY           *Key\r
+  )\r
+;\r
+#endif // _UI_H\r