]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Porting SecMain module for Nt32Pkg, but not enable PI, so it currently dependent...
authorklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 3 Jul 2007 09:18:19 +0000 (09:18 +0000)
committerklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 3 Jul 2007 09:18:19 +0000 (09:18 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2998 6f19259b-4bc3-4df7-8a09-765794883524

14 files changed:
IntelFrameworkPkg/Include/FrameworkPei.h
MdeModulePkg/Include/Guid/PeiPeCoffLoader.h [new file with mode: 0644]
MdeModulePkg/MdeModulePkg.dec
MdePkg/Include/Pi/PiFirmwareFile.h
Nt32Pkg/Nt32Pkg.dec
Nt32Pkg/Nt32Pkg.dsc
Nt32Pkg/Sec/FwVol.c [new file with mode: 0644]
Nt32Pkg/Sec/Makefile [new file with mode: 0644]
Nt32Pkg/Sec/SecMain.c [new file with mode: 0644]
Nt32Pkg/Sec/SecMain.h [new file with mode: 0644]
Nt32Pkg/Sec/SecMain.inf [new file with mode: 0644]
Nt32Pkg/Sec/SecMain.msa [new file with mode: 0644]
Nt32Pkg/Sec/SecMain_build.xml [new file with mode: 0644]
Nt32Pkg/Sec/WinNtThunk.c [new file with mode: 0644]

index 0f630da726b597d312646259ef255b54a97d2e47..7f61e8147504cbfafbd86fa9520119e4c8f413d5 100644 (file)
 #define _FRAMEWORK_PEI_H_\r
 \r
 #include <PiPei.h>\r
+\r
+typedef struct {\r
+  UINTN                   BootFirmwareVolume;\r
+  UINTN                   SizeOfCacheAsRam;\r
+  EFI_PEI_PPI_DESCRIPTOR  *DispatchTable;\r
+} EFI_PEI_STARTUP_DESCRIPTOR;\r
+\r
 #include <Common/FrameworkFirmwareFileSystem.h>\r
 #include <Common/FrameworkHob.h>\r
 #include <Common/FrameworkLegacy16.h>\r
diff --git a/MdeModulePkg/Include/Guid/PeiPeCoffLoader.h b/MdeModulePkg/Include/Guid/PeiPeCoffLoader.h
new file mode 100644 (file)
index 0000000..95ee354
--- /dev/null
@@ -0,0 +1,71 @@
+/*++\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
+    PeiPeCoffLoader.h\r
+    \r
+Abstract:\r
+  GUID for the PE/COFF Loader APIs shared between PEI and DXE\r
+\r
+--*/\r
+\r
+#ifndef __PEI_PE_COFF_LOADER_H__\r
+#define __PEI_PE_COFF_LOADER_H__\r
+\r
+//\r
+// MdePkg/Include/Common/PeCoffLoaderImageContext.h\r
+//\r
+#include <Library/PeCoffLib.h>\r
+\r
+#define EFI_PEI_PE_COFF_LOADER_GUID  \\r
+  { 0xd8117cff, 0x94a6, 0x11d4, {0x9a, 0x3a, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } }\r
+\r
+typedef struct _EFI_PEI_PE_COFF_LOADER_PROTOCOL   EFI_PEI_PE_COFF_LOADER_PROTOCOL;\r
+\r
+\r
+typedef \r
+EFI_STATUS\r
+(EFIAPI *EFI_PEI_PE_COFF_LOADER_GET_IMAGE_INFO) (\r
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL          *This,\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  );\r
+\r
+typedef \r
+EFI_STATUS\r
+(EFIAPI *EFI_PEI_PE_COFF_LOADER_LOAD_IMAGE) (\r
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL          *This,\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  );\r
+\r
+typedef \r
+EFI_STATUS\r
+(EFIAPI *EFI_PEI_PE_COFF_LOADER_RELOCATE_IMAGE) (\r
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL          *This,\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  );\r
+\r
+typedef \r
+EFI_STATUS\r
+(EFIAPI *EFI_PEI_PE_COFF_LOADER_UNLOAD_IMAGE) (\r
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL          *This,\r
+  IN PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  );\r
+\r
+struct _EFI_PEI_PE_COFF_LOADER_PROTOCOL {\r
+  EFI_PEI_PE_COFF_LOADER_GET_IMAGE_INFO  GetImageInfo;\r
+  EFI_PEI_PE_COFF_LOADER_LOAD_IMAGE      LoadImage;\r
+  EFI_PEI_PE_COFF_LOADER_RELOCATE_IMAGE  RelocateImage;\r
+  EFI_PEI_PE_COFF_LOADER_UNLOAD_IMAGE    UnloadImage;\r
+};\r
+\r
+extern EFI_GUID gEfiPeiPeCoffLoaderGuid;\r
+\r
+#endif\r
index aaeb416537ead87f8e66ecad890f362a32f78d9a..ac6e2cfe90eb41cf4b477c0e0973cec0e1c8c7ed 100644 (file)
@@ -64,7 +64,8 @@
   gPcdPeiCallbackFnTableHobGuid  = { 0xC625F4B2, 0xEA09, 0x4675, { 0x82, 0xD7, 0xBA, 0x36, 0x82, 0x15, 0x7A, 0x14 }}\r
   gPcdDataBaseHobGuid            = { 0xEA296D92, 0x0B69, 0x423C, { 0x8C, 0x28, 0x33, 0xB4, 0xE0, 0xA9, 0x12, 0x68 }}\r
   gEfiMdePkgTokenSpaceGuid       = { 0xA1AFF049, 0xFDEB, 0x442a, { 0xB3, 0x20, 0x13, 0xAB, 0x4C, 0xB7, 0x2B, 0xBC }}\r
-\r
+  ##gEfiPeiPeCoffLoaderGuid will be removed in future\r
+  gEfiPeiPeCoffLoaderGuid        = { 0xd8117cff, 0x94a6, 0x11d4, {0x9a, 0x3a, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } }\r
 \r
 ################################################################################\r
 #\r
index 740fbf13469d8f99b881648353c919a9534a040b..b84e9828c92a758c495c5ed453b1a5999606a1c2 100644 (file)
@@ -30,6 +30,22 @@ typedef union {
 } EFI_FFS_INTEGRITY_CHECK;\r
 \r
 typedef UINT8 EFI_FV_FILETYPE;\r
+\r
+#define EFI_FV_FILETYPE_ALL                   0x00\r
+#define EFI_FV_FILETYPE_RAW                   0x01\r
+#define EFI_FV_FILETYPE_FREEFORM              0x02\r
+#define EFI_FV_FILETYPE_SECURITY_CORE         0x03\r
+#define EFI_FV_FILETYPE_PEI_CORE              0x04\r
+#define EFI_FV_FILETYPE_DXE_CORE              0x05\r
+#define EFI_FV_FILETYPE_PEIM                  0x06\r
+#define EFI_FV_FILETYPE_DRIVER                0x07\r
+#define EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER  0x08\r
+#define EFI_FV_FILETYPE_APPLICATION           0x09\r
+//\r
+// File type 0x0A is reserved and should not be used\r
+//\r
+#define EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE 0x0B\r
+\r
 typedef UINT8 EFI_FFS_FILE_ATTRIBUTES;\r
 typedef UINT8 EFI_FFS_FILE_STATE;\r
 \r
index 92eabddb96fe0884f5eb41b4797168d1aa411c68..5cd2b2e50e65cd1d7a59c2bd884247d19706e1ee 100644 (file)
@@ -70,7 +70,7 @@
   gEfiWinNtPhysicalDisksGuid     = { 0x0C95A92F, 0xA006, 0x11D4, { 0xBC, 0xFA, 0x00, 0x80, 0xC7, 0x3C, 0x88, 0x81 }}\r
   gEfiWinNtVirtualDisksGuid      = { 0x0C95A928, 0xA006, 0x11D4, { 0xBC, 0xFA, 0x00, 0x80, 0xC7, 0x3C, 0x88, 0x81 }}\r
   gEfiNt32PkgTokenSpaceGuid      = { 0x0D79A645, 0x1D91, 0x40a6, { 0xA8, 0x1F, 0x61, 0xE6, 0x98, 0x2B, 0x32, 0xB4 }}\r
-\r
+  \r
 \r
 ################################################################################\r
 #\r
@@ -93,7 +93,9 @@
   gPeiNtThunkPpiGuid             = { 0x98c281e5, 0xf906, 0x43dd, { 0xa9, 0x2b, 0xb0, 0x03, 0xbf, 0x27, 0x65, 0xda }}\r
   gPeiNtAutoScanPpiGuid          = { 0x0dce384d, 0x007c, 0x4ba5, { 0x94, 0xbd, 0x0f, 0x6e, 0xb6, 0x4d, 0x2a, 0xa9 }}\r
        gEfiPeiMemoryDiscoveredPpiGuid = { 0xF894643D, 0xC449, 0x42D1, { 0x8E, 0xA8, 0x85, 0xBD, 0xD8, 0xC6, 0x5B, 0xDE }}\r
-\r
+  gNtPeiLoadFilePpiGuid          = { 0xfd0c65eb, 0x0405, 0x4cd2, { 0x8a, 0xee, 0xf4, 0x0, 0xef, 0x13, 0xba, 0xc2 }}\r
+  gNtFwhPpiGuid                  = { 0x4e76928f, 0x50ad, 0x4334, {0xb0, 0x6b, 0xa8, 0x42, 0x13, 0x10, 0x8a, 0x57 }}\r
+  \r
 ################################################################################\r
 #\r
 # PCD Declarations section - list of all PCDs Declared by this Package\r
index 7d69125fad2a8285219ce8c0e29ace7ef956318d..cd86168cd68587fd568d01da8d5d3e3e8d176db3 100644 (file)
   PcdStatusCodeRuntimeMemorySize|gEfiIntelFrameworkModulePkgTokenSpaceGuid|128\r
 \r
 [PcdsFixedAtBuild.IA32]\r
-  PcdWinNtMemorySizeForSecMain|gEfiNt32PkgTokenSpaceGuid|L"64!64"|VOID*|10\r
-  PcdWinNtFirmwareVolume|gEfiNt32PkgTokenSpaceGuid|L"..\\Fv\\Fv_Recovery.fd"|VOID*|52\r
+  PcdWinNtMemorySizeForSecMain|gEfiNt32PkgTokenSpaceGuid|L"64!64"|10\r
+  PcdWinNtFirmwareVolume|gEfiNt32PkgTokenSpaceGuid|L"..\\Fv\\Fv_Recovery.fd"|52\r
   PcdWinNtBootMode|gEfiNt32PkgTokenSpaceGuid|1\r
   PcdMaximumUnicodeStringLength|gEfiMdePkgTokenSpaceGuid|1000000\r
   PcdMaximumAsciiStringLength|gEfiMdePkgTokenSpaceGuid|1000000\r
   $(WORKSPACE)/IntelFrameworkModulePkg/Universal/DriverSampleDxe/DriverSample.inf\r
   $(WORKSPACE)/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.inf     ##This driver follows UEFI specification definition\r
   $(WORKSPACE)/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.inf    ##This driver follows UEFI specification definition\r
+  $(WORKSPACE)/Nt32Pkg/Sec/SecMain.inf
\ No newline at end of file
diff --git a/Nt32Pkg/Sec/FwVol.c b/Nt32Pkg/Sec/FwVol.c
new file mode 100644 (file)
index 0000000..3e94bcb
--- /dev/null
@@ -0,0 +1,314 @@
+/*++\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
+  FwVol.c\r
+\r
+Abstract:\r
+  A simple FV stack so the SEC can extract the SEC Core from an\r
+  FV.\r
+\r
+--*/\r
+\r
+#include "SecMain.h"\r
+\r
+#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \\r
+  (ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1))\r
+\r
+EFI_FFS_FILE_STATE\r
+GetFileState (\r
+  IN UINT8                ErasePolarity,\r
+  IN EFI_FFS_FILE_HEADER  *FfsHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Returns the highest bit set of the State field\r
+\r
+Arguments:\r
+  ErasePolarity   - Erase Polarity  as defined by EFI_FVB_ERASE_POLARITY\r
+                    in the Attributes field.\r
+  FfsHeader       - Pointer to FFS File Header.\r
+\r
+Returns:\r
+  Returns the highest bit in the State field\r
+\r
+--*/\r
+{\r
+  EFI_FFS_FILE_STATE  FileState;\r
+  EFI_FFS_FILE_STATE  HighestBit;\r
+\r
+  FileState = FfsHeader->State;\r
+\r
+  if (ErasePolarity != 0) {\r
+    FileState = (EFI_FFS_FILE_STATE)~FileState;\r
+  }\r
+\r
+  HighestBit = 0x80;\r
+  while (HighestBit != 0 && (HighestBit & FileState) == 0) {\r
+    HighestBit >>= 1;\r
+  }\r
+\r
+  return HighestBit;\r
+}\r
+\r
+UINT8\r
+CalculateHeaderChecksum (\r
+  IN EFI_FFS_FILE_HEADER  *FileHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Calculates the checksum of the header of a file.\r
+\r
+Arguments:\r
+  FileHeader       - Pointer to FFS File Header.\r
+\r
+Returns:\r
+  Checksum of the header.\r
+  \r
+--*/\r
+{\r
+  UINT8 *ptr;\r
+  UINTN Index;\r
+  UINT8 Sum;\r
+\r
+  Sum = 0;\r
+  ptr = (UINT8 *) FileHeader;\r
+\r
+  for (Index = 0; Index < sizeof (EFI_FFS_FILE_HEADER) - 3; Index += 4) {\r
+    Sum = (UINT8) (Sum + ptr[Index]);\r
+    Sum = (UINT8) (Sum + ptr[Index + 1]);\r
+    Sum = (UINT8) (Sum + ptr[Index + 2]);\r
+    Sum = (UINT8) (Sum + ptr[Index + 3]);\r
+  }\r
+\r
+  for (; Index < sizeof (EFI_FFS_FILE_HEADER); Index++) {\r
+    Sum = (UINT8) (Sum + ptr[Index]);\r
+  }\r
+  //\r
+  // State field (since this indicates the different state of file).\r
+  //\r
+  Sum = (UINT8) (Sum - FileHeader->State);\r
+  //\r
+  // Checksum field of the file is not part of the header checksum.\r
+  //\r
+  Sum = (UINT8) (Sum - FileHeader->IntegrityCheck.Checksum.File);\r
+\r
+  return Sum;\r
+}\r
+\r
+EFI_STATUS\r
+SecFfsFindNextFile (\r
+  IN EFI_FV_FILETYPE             SearchType,\r
+  IN EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader,\r
+  IN OUT EFI_FFS_FILE_HEADER     **FileHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+    Given the input file pointer, search for the next matching file in the\r
+    FFS volume as defined by SearchType. The search starts from FileHeader inside\r
+    the Firmware Volume defined by FwVolHeader.\r
+\r
+Arguments:\r
+    SearchType - Filter to find only files of this type.\r
+                 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r
+    FwVolHeader - Pointer to the FV header of the volume to search.\r
+                  This parameter must point to a valid FFS volume.\r
+    FileHeader  - Pointer to the current file from which to begin searching.\r
+                  This pointer will be updated upon return to reflect the file\r
+                  found.\r
+\r
+Returns:\r
+    EFI_NOT_FOUND - No files matching the search criteria were found\r
+    EFI_SUCCESS\r
+\r
+--*/\r
+{\r
+  EFI_FFS_FILE_HEADER *FfsFileHeader;\r
+  UINT32              FileLength;\r
+  UINT32              FileOccupiedSize;\r
+  UINT32              FileOffset;\r
+  UINT64              FvLength;\r
+  UINT8               ErasePolarity;\r
+  UINT8               FileState;\r
+\r
+  FvLength = FwVolHeader->FvLength;\r
+  if (FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) {\r
+    ErasePolarity = 1;\r
+  } else {\r
+    ErasePolarity = 0;\r
+  }\r
+  //\r
+  // If FileHeader is not specified (NULL) start with the first file in the\r
+  // firmware volume.  Otherwise, start from the FileHeader.\r
+  //\r
+  if (*FileHeader == NULL) {\r
+    FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FwVolHeader + FwVolHeader->HeaderLength);\r
+  } else {\r
+    //\r
+    // Length is 24 bits wide so mask upper 8 bits\r
+    // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.\r
+    //\r
+    FileLength        = *(UINT32 *) (*FileHeader)->Size & 0x00FFFFFF;\r
+    FileOccupiedSize  = GET_OCCUPIED_SIZE (FileLength, 8);\r
+    FfsFileHeader     = (EFI_FFS_FILE_HEADER *) ((UINT8 *) *FileHeader + FileOccupiedSize);\r
+  }\r
+\r
+  FileOffset = (UINT32) ((UINT8 *) FfsFileHeader - (UINT8 *) FwVolHeader);\r
+\r
+  while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) {\r
+    //\r
+    // Get FileState which is the highest bit of the State\r
+    //\r
+    FileState = GetFileState (ErasePolarity, FfsFileHeader);\r
+\r
+    switch (FileState) {\r
+\r
+    case EFI_FILE_HEADER_INVALID:\r
+      FileOffset += sizeof (EFI_FFS_FILE_HEADER);\r
+      FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER));\r
+      break;\r
+\r
+    case EFI_FILE_DATA_VALID:\r
+    case EFI_FILE_MARKED_FOR_UPDATE:\r
+      if (CalculateHeaderChecksum (FfsFileHeader) == 0) {\r
+        FileLength        = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF;\r
+        FileOccupiedSize  = GET_OCCUPIED_SIZE (FileLength, 8);\r
+\r
+        if ((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) {\r
+\r
+          *FileHeader = FfsFileHeader;\r
+\r
+          return EFI_SUCCESS;\r
+        }\r
+\r
+        FileOffset += FileOccupiedSize;\r
+        FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize);\r
+      } else {\r
+        return EFI_NOT_FOUND;\r
+      }\r
+      break;\r
+\r
+    case EFI_FILE_DELETED:\r
+      FileLength        = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF;\r
+      FileOccupiedSize  = GET_OCCUPIED_SIZE (FileLength, 8);\r
+      FileOffset += FileOccupiedSize;\r
+      FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize);\r
+      break;\r
+\r
+    default:\r
+      return EFI_NOT_FOUND;\r
+\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+EFI_STATUS\r
+SecFfsFindSectionData (\r
+  IN EFI_SECTION_TYPE      SectionType,\r
+  IN EFI_FFS_FILE_HEADER   *FfsFileHeader,\r
+  IN OUT VOID              **SectionData\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+    Given the input file pointer, search for the next matching section in the\r
+    FFS volume.\r
+\r
+Arguments:\r
+    SearchType    - Filter to find only sections of this type.\r
+    FfsFileHeader - Pointer to the current file to search.\r
+    SectionData   - Pointer to the Section matching SectionType in FfsFileHeader.\r
+                     NULL if section not found\r
+\r
+Returns:\r
+    EFI_NOT_FOUND - No files matching the search criteria were found\r
+    EFI_SUCCESS\r
+\r
+--*/\r
+{\r
+  UINT32                    FileSize;\r
+  EFI_COMMON_SECTION_HEADER *Section;\r
+  UINT32                    SectionLength;\r
+  UINT32                    ParsedLength;\r
+\r
+  //\r
+  // Size is 24 bits wide so mask upper 8 bits.\r
+  //    Does not include FfsFileHeader header size\r
+  // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned.\r
+  //\r
+  Section   = (EFI_COMMON_SECTION_HEADER *) (FfsFileHeader + 1);\r
+  FileSize  = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF;\r
+  FileSize -= sizeof (EFI_FFS_FILE_HEADER);\r
+\r
+  *SectionData  = NULL;\r
+  ParsedLength  = 0;\r
+  while (ParsedLength < FileSize) {\r
+    if (Section->Type == SectionType) {\r
+      *SectionData = (VOID *) (Section + 1);\r
+      return EFI_SUCCESS;\r
+    }\r
+    //\r
+    // Size is 24 bits wide so mask upper 8 bits.\r
+    // SectionLength is adjusted it is 4 byte aligned.\r
+    // Go to the next section\r
+    //\r
+    SectionLength = *(UINT32 *) Section->Size & 0x00FFFFFF;\r
+    SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);\r
+\r
+    ParsedLength += SectionLength;\r
+    Section = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) Section + SectionLength);\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+EFI_STATUS\r
+SecFfsFindPeiCore (\r
+  IN  EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader,\r
+  OUT VOID                        **Pe32Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Given the pointer to the Firmware Volume Header find the SEC\r
+  core and return it's PE32 image.\r
+\r
+Arguments:\r
+  FwVolHeader - Pointer to memory mapped FV\r
+  Pe32Data - Pointer to SEC PE32 iamge.\r
\r
+Returns:  \r
+  EFI_SUCCESS - Pe32Data is valid\r
+  other       - Failure\r
+\r
+--*/\r
+{\r
+  EFI_STATUS          Status;\r
+  EFI_FFS_FILE_HEADER *FileHeader;\r
+  EFI_FV_FILETYPE     SearchType;\r
+\r
+  SearchType  = EFI_FV_FILETYPE_PEI_CORE;\r
+  FileHeader  = NULL;\r
+  do {\r
+    Status = SecFfsFindNextFile (SearchType, FwVolHeader, &FileHeader);\r
+    if (!EFI_ERROR (Status)) {\r
+      Status = SecFfsFindSectionData (EFI_SECTION_PE32, FileHeader, Pe32Data);\r
+      return Status;\r
+    }\r
+  } while (!EFI_ERROR (Status));\r
+\r
+  return Status;\r
+}\r
diff --git a/Nt32Pkg/Sec/Makefile b/Nt32Pkg/Sec/Makefile
new file mode 100644 (file)
index 0000000..99c18d4
--- /dev/null
@@ -0,0 +1,74 @@
+SOURCE_FILES = $(DEBUG_DIR)\AutoGen.c                 \\r
+               $(MODULE_DIR)\Nt32Pkg\Sec\WinNtThunk.c \\r
+               $(MODULE_DIR)\Nt32Pkg\Sec\FwVol.c      \\r
+               $(MODULE_DIR)\Nt32Pkg\Sec\SecMain.c\r
+               \r
+INC = -I$(WORKSPACE)\Nt32Pkg\Sec            \\r
+      -I$(DEBUG_DIR)                        \\r
+      -I$(WORKSPACE)\Nt32Pkg                \\r
+      -I$(WORKSPACE)\Nt32Pkg\Include        \\r
+      -I$(WORKSPACE)\MdePkg                 \\r
+      -I$(WORKSPACE)\MdePkg\Include\Ia32    \\r
+      -I$(WORKSPACE)\MdePkg\Include         \\r
+      -I$(WORKSPACE)\MdeModulePkg\Include   \\r
+      -I$(WORKSPACE)\IntelFrameworkPkg\Include\r
+\r
+OBJECTS = $(OUTPUT_DIR)\.\AutoGen.obj       \\r
+          $(OUTPUT_DIR)\.\WinNtThunk.obj    \\r
+          $(OUTPUT_DIR)\.\FwVol.obj         \\r
+          $(OUTPUT_DIR)\.\SecMain.obj\r
+          \r
+LIBS = $(LIB_DIR)\BaseDebugLibNull.lib      \\r
+       $(LIB_DIR)\BasePrintLib.lib          \\r
+       $(LIB_DIR)\BaseMemoryLib.lib         \\r
+       $(LIB_DIR)\BaseLib.lib               \\r
+       $(LIB_DIR)\BasePeCoffLib.lib \r
+\r
+MSVS_LINK_LIBPATHS =  /LIBPATH:"$(VCINSTALLDIR)\Lib" /LIBPATH:"$(VCINSTALLDIR)\PlatformSdk\Lib"\r
+LINK_FLAGS_EXE = /NOLOGO /SUBSYSTEM:CONSOLE /NODEFAULTLIB /IGNORE:4086 /MAP /OPT:REF /DEBUG /MACHINE:I386 /LTCG \\r
+                 Kernel32.lib MSVCRTD.lib Gdi32.lib User32.lib Winmm.lib\r
+\r
+COMMON_DEPS = $(DEBUG_DIR)\AutoGen.h\r
+\r
+all : $(BIN_DIR)\SecMain.exe\r
+\r
+$(BIN_DIR)\SecMain.exe : $(OBJECTS)\r
+  "$(DLINK)"                        \\r
+    $(MSVS_LINK_LIBPATHS)           \\r
+    $(LINK_FLAGS_EXE)               \\r
+    $(OBJECTS)                      \\r
+    $(LIBS)                         \\r
+    /base:0x10000000                \\r
+    /out:"$(BIN_DIR)\SecMain.exe"   \\r
+    /pdb:"$(BIN_DIR)\SecMain.pdb"\r
+  \r
+#\r
+# Individual Object Build Targets\r
+#\r
+$(OUTPUT_DIR)\.\AutoGen.obj : $(COMMON_DEPS)\r
+$(OUTPUT_DIR)\.\AutoGen.obj : $(DEBUG_DIR)\AutoGen.c\r
+       "$(CC)" $(CC_FLAGS) $(INC) /Fo$@ $(DEBUG_DIR)\AutoGen.c\r
+\r
+$(OUTPUT_DIR)\.\WinNtThunk.obj : $(COMMON_DEPS)\r
+$(OUTPUT_DIR)\.\WinNtThunk.obj : $(MODULE_DIR)\WinNtThunk.c\r
+       "$(CC)" $(CC_FLAGS) $(INC) /Fo$@ $(MODULE_DIR)\WinNtThunk.c\r
+\r
+$(OUTPUT_DIR)\.\FwVol.obj : $(COMMON_DEPS)\r
+$(OUTPUT_DIR)\.\FwVol.obj : $(MODULE_DIR)\FwVol.c\r
+       "$(CC)" $(CC_FLAGS) $(INC) /Fo$@ $(MODULE_DIR)\FwVol.c\r
+       \r
+$(OUTPUT_DIR)\.\SecMain.obj : $(COMMON_DEPS)\r
+$(OUTPUT_DIR)\.\SecMain.obj : $(MODULE_DIR)\SecMain.c\r
+       "$(CC)" $(CC_FLAGS) $(INC) /Fo$@ $(MODULE_DIR)\SecMain.c\r
+       \r
+clean:\r
+  - @if exist $(DEBUG_DIR)\AutoGen.c del $(DEBUG_DIR)\AutoGen.c > NUL\r
+  del $(DEBUG_DIR)\AutoGen.h > NUL\r
+  del $(OUTPUT_DIR)\.\*.obj > NUL\r
+  del $(MODULE_BUILD_DIR)\makefile > NUL\r
+  del $(MODULE_BUILD_DIR)\*.idb > NUL\r
+  del $(MODULE_BUILD_DIR)\*.pdb > NUL\r
+  del $(BIN_DIR)\SecMain.exe > NUL\r
+  del $(BIN_DIR)\SecMain.pdb > NUL\r
+  \r
+  
\ No newline at end of file
diff --git a/Nt32Pkg/Sec/SecMain.c b/Nt32Pkg/Sec/SecMain.c
new file mode 100644 (file)
index 0000000..3d2d427
--- /dev/null
@@ -0,0 +1,1236 @@
+/*++\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
+  SecMain.c\r
+\r
+Abstract:\r
+  WinNt emulator of SEC phase. It's really a Win32 application, but this is\r
+  Ok since all the other modules for NT32 are NOT Win32 applications.\r
+\r
+  This program processes Windows environment variables and figures out\r
+  what the memory layout will be, how may FD's will be loaded and also\r
+  what the boot mode is.\r
+\r
+  The SEC registers a set of services with the SEC core. gPrivateDispatchTable\r
+  is a list of PPI's produced by the SEC that are availble for usage in PEI.\r
+\r
+  This code produces 128 K of temporary memory for the PEI stack by opening a\r
+  Windows file and mapping it directly to memory addresses.\r
+\r
+  The system.cmd script is used to set windows environment variables that drive\r
+  the configuration opitons of the SEC.\r
+\r
+--*/\r
+\r
+#include "SecMain.h"\r
+#pragma warning(disable : 4996)\r
+\r
+//\r
+// Globals\r
+//\r
+EFI_PEI_PE_COFF_LOADER_PROTOCOL_INSTANCE  mPeiEfiPeiPeCoffLoaderInstance = {\r
+  {\r
+    SecNt32PeCoffGetImageInfo,\r
+    SecNt32PeCoffLoadImage,\r
+    SecNt32PeCoffRelocateImage,\r
+    SecNt32PeCoffUnloadimage\r
+  },\r
+  NULL\r
+};\r
+\r
+\r
+\r
+EFI_PEI_PE_COFF_LOADER_PROTOCOL           *gPeiEfiPeiPeCoffLoader = &mPeiEfiPeiPeCoffLoaderInstance.PeCoff;\r
+\r
+NT_PEI_LOAD_FILE_PPI                      mSecNtLoadFilePpi     = { SecWinNtPeiLoadFile };\r
+\r
+PEI_NT_AUTOSCAN_PPI                       mSecNtAutoScanPpi     = { SecWinNtPeiAutoScan };\r
+\r
+PEI_NT_THUNK_PPI                          mSecWinNtThunkPpi     = { SecWinNtWinNtThunkAddress };\r
+\r
+EFI_PEI_PROGRESS_CODE_PPI                 mSecStatusCodePpi     = { SecPeiReportStatusCode };\r
+\r
+NT_FWH_PPI                                mSecFwhInformationPpi = { SecWinNtFdAddress };\r
+\r
+\r
+EFI_PEI_PPI_DESCRIPTOR  gPrivateDispatchTable[] = {\r
+  {\r
+    EFI_PEI_PPI_DESCRIPTOR_PPI,\r
+    &gEfiPeiPeCoffLoaderGuid,\r
+    NULL\r
+  },\r
+  {\r
+    EFI_PEI_PPI_DESCRIPTOR_PPI,\r
+    &gNtPeiLoadFilePpiGuid,\r
+    &mSecNtLoadFilePpi\r
+  },\r
+  {\r
+    EFI_PEI_PPI_DESCRIPTOR_PPI,\r
+    &gPeiNtAutoScanPpiGuid,\r
+    &mSecNtAutoScanPpi\r
+  },\r
+  {\r
+    EFI_PEI_PPI_DESCRIPTOR_PPI,\r
+    &gPeiNtThunkPpiGuid,\r
+    &mSecWinNtThunkPpi\r
+  },\r
+  {\r
+    EFI_PEI_PPI_DESCRIPTOR_PPI,\r
+    &gEfiPeiStatusCodePpiGuid,\r
+    &mSecStatusCodePpi\r
+  },\r
+  {\r
+    EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
+    &gNtFwhPpiGuid,\r
+    &mSecFwhInformationPpi\r
+  }\r
+};\r
+\r
+\r
+//\r
+// Default information about where the FD is located.\r
+//  This array gets filled in with information from EFI_FIRMWARE_VOLUMES\r
+//  EFI_FIRMWARE_VOLUMES is a Windows environment variable set by system.cmd.\r
+//  The number of array elements is allocated base on parsing\r
+//  EFI_FIRMWARE_VOLUMES and the memory is never freed.\r
+//\r
+UINTN                                     gFdInfoCount = 0;\r
+NT_FD_INFO                                *gFdInfo;\r
+\r
+//\r
+// Array that supports seperate memory rantes.\r
+//  The memory ranges are set in system.cmd via the EFI_MEMORY_SIZE variable.\r
+//  The number of array elements is allocated base on parsing\r
+//  EFI_MEMORY_SIZE and the memory is never freed.\r
+//\r
+UINTN                                     gSystemMemoryCount = 0;\r
+NT_SYSTEM_MEMORY                          *gSystemMemory;\r
+\r
+\r
+UINTN                   mPdbNameModHandleArraySize = 0;\r
+PDB_NAME_TO_MOD_HANDLE  *mPdbNameModHandleArray = NULL;\r
+\r
+\r
+\r
+\r
+INTN\r
+EFIAPI\r
+main (\r
+  IN  INTN  Argc,\r
+  IN  CHAR8 **Argv,\r
+  IN  CHAR8 **Envp\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Main entry point to SEC for WinNt. This is a Windows program\r
+\r
+Arguments:\r
+  Argc - Number of command line arguments\r
+  Argv - Array of command line argument strings\r
+  Envp - Array of environmemt variable strings\r
+\r
+Returns:\r
+  0 - Normal exit\r
+  1 - Abnormal exit\r
+\r
+--*/\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_PHYSICAL_ADDRESS  InitialStackMemory;\r
+  UINT64                InitialStackMemorySize;\r
+  UINTN                 Index;\r
+  UINTN                 Index1;\r
+  UINTN                 Index2;\r
+  UINTN                 PeiIndex;\r
+  CHAR16                *FileName;\r
+  CHAR16                *FileNamePtr;\r
+  BOOLEAN               Done;\r
+  VOID                  *PeiCoreFile;\r
+  CHAR16                *MemorySizeStr;\r
+  CHAR16                *FirmwareVolumesStr;\r
+\r
+  MemorySizeStr      = (CHAR16 *)L"64!64";\r
+  FirmwareVolumesStr = (CHAR16 *)L"..\\Fv\\Fv_Recovery.fd";\r
+\r
+  printf ("\nEDK SEC Main NT Emulation Environment from www.TianoCore.org\n");\r
+\r
+  //\r
+  // Make some Windows calls to Set the process to the highest priority in the\r
+  //  idle class. We need this to have good performance.\r
+  //\r
+  SetPriorityClass (GetCurrentProcess (), IDLE_PRIORITY_CLASS);\r
+  SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_HIGHEST);\r
+\r
+  //\r
+  // Allocate space for gSystemMemory Array\r
+  //\r
+  gSystemMemoryCount  = CountSeperatorsInString (MemorySizeStr, '!') + 1;\r
+  gSystemMemory       = calloc (gSystemMemoryCount, sizeof (NT_SYSTEM_MEMORY));\r
+  if (gSystemMemory == NULL) {\r
+    printf ("ERROR : Can not allocate memory for %s.  Exiting.\n", MemorySizeStr);\r
+    exit (1);\r
+  }\r
+  //\r
+  // Allocate space for gSystemMemory Array\r
+  //\r
+  gFdInfoCount  = CountSeperatorsInString (FirmwareVolumesStr, '!') + 1;\r
+  gFdInfo       = calloc (gFdInfoCount, sizeof (NT_FD_INFO));\r
+  if (gFdInfo == NULL) {\r
+    printf ("ERROR : Can not allocate memory for %s.  Exiting.\n", FirmwareVolumesStr);\r
+    exit (1);\r
+  }\r
+  //\r
+  // Setup Boot Mode. If BootModeStr == "" then BootMode = 0 (BOOT_WITH_FULL_CONFIGURATION)\r
+  //\r
+  printf ("  BootMode 0x%02x\n", FixedPcdGet32 (PcdWinNtBootMode));\r
+\r
+  //\r
+  // Open up a 128K file to emulate temp memory for PEI.\r
+  //  on a real platform this would be SRAM, or using the cache as RAM.\r
+  //  Set InitialStackMemory to zero so WinNtOpenFile will allocate a new mapping\r
+  //\r
+  InitialStackMemory      = 0;\r
+  InitialStackMemorySize  = 0x20000;\r
+  Status = WinNtOpenFile (\r
+            L"SecStack",\r
+            (UINT32) InitialStackMemorySize,\r
+            OPEN_ALWAYS,\r
+            &InitialStackMemory,\r
+            &InitialStackMemorySize\r
+            );\r
+  if (EFI_ERROR (Status)) {\r
+    printf ("ERROR : Can not open SecStack Exiting\n");\r
+    exit (1);\r
+  }\r
+\r
+  printf ("  SEC passing in %d bytes of temp RAM to PEI\n", InitialStackMemorySize);\r
+\r
+  //\r
+  // Open All the firmware volumes and remember the info in the gFdInfo global\r
+  //\r
+  FileNamePtr = (CHAR16 *)malloc (StrLen ((CHAR16 *)FirmwareVolumesStr) * sizeof(CHAR16));\r
+  if (FileNamePtr == NULL) {\r
+    printf ("ERROR : Can not allocate memory for firmware volume string\n");\r
+    exit (1);\r
+  }\r
+\r
+  StrCpy (FileNamePtr, (CHAR16*)FirmwareVolumesStr);\r
+\r
+  for (Done = FALSE, Index = 0, PeiIndex = 0, PeiCoreFile = NULL; !Done; Index++) {\r
+    FileName = FileNamePtr;\r
+    for (Index1 = 0; (FileNamePtr[Index1] != '!') && (FileNamePtr[Index1] != 0); Index1++)\r
+      ;\r
+    if (FileNamePtr[Index1] == 0) {\r
+      Done = TRUE;\r
+    } else {\r
+      FileNamePtr[Index1]  = '\0';\r
+      FileNamePtr = FileNamePtr + Index1 + 1;\r
+    }\r
+\r
+    //\r
+    // Open the FD and remmeber where it got mapped into our processes address space\r
+    //\r
+    Status = WinNtOpenFile (\r
+              FileName,\r
+              0,\r
+              OPEN_EXISTING,\r
+              &gFdInfo[Index].Address,\r
+              &gFdInfo[Index].Size\r
+              );\r
+    if (EFI_ERROR (Status)) {\r
+      printf ("ERROR : Can not open Firmware Device File %S (%r).  Exiting.\n", FileName, Status);\r
+      exit (1);\r
+    }\r
+\r
+    printf ("  FD loaded from");\r
+    //\r
+    // printf can't print filenames directly as the \ gets interperted as an\r
+    //  escape character.\r
+    //\r
+    for (Index2 = 0; FileName[Index2] != '\0'; Index2++) {\r
+      printf ("%c", FileName[Index2]);\r
+    }\r
+\r
+    if (PeiCoreFile == NULL) {\r
+      //\r
+      // Assume the beginning of the FD is an FV and look for the PEI Core.\r
+      // Load the first one we find.\r
+      //\r
+      Status = SecFfsFindPeiCore ((EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) gFdInfo[Index].Address, &PeiCoreFile);\r
+      if (!EFI_ERROR (Status)) {\r
+        PeiIndex = Index;\r
+        printf (" contains SEC Core");\r
+      }\r
+    }\r
+\r
+    printf ("\n");\r
+  }\r
+  //\r
+  // Calculate memory regions and store the information in the gSystemMemory\r
+  //  global for later use. The autosizing code will use this data to\r
+  //  map this memory into the SEC process memory space.\r
+  //\r
+  for (Index = 0, Done = FALSE; !Done; Index++) {\r
+    //\r
+    // Save the size of the memory and make a Unicode filename SystemMemory00, ...\r
+    //\r
+    gSystemMemory[Index].Size = _wtoi (MemorySizeStr) * 0x100000;\r
+    _snwprintf (gSystemMemory[Index].FileName, NT_SYSTEM_MEMORY_FILENAME_SIZE, L"SystemMemory%02d", Index);\r
+\r
+    //\r
+    // Find the next region\r
+    //\r
+    for (Index1 = 0; MemorySizeStr[Index1] != '!' && MemorySizeStr[Index1] != 0; Index1++)\r
+      ;\r
+    if (MemorySizeStr[Index1] == 0) {\r
+      Done = TRUE;\r
+    }\r
+\r
+    MemorySizeStr = MemorySizeStr + Index1 + 1;\r
+  }\r
+\r
+  printf ("\n");\r
+\r
+  //\r
+  // Hand off to PEI Core\r
+  //\r
+  SecLoadFromCore ((UINTN) InitialStackMemory, (UINTN) InitialStackMemorySize, (UINTN) gFdInfo[0].Address, PeiCoreFile);\r
+\r
+  //\r
+  // If we get here, then the PEI Core returned. This is an error as PEI should\r
+  //  always hand off to DXE.\r
+  //\r
+  printf ("ERROR : PEI Core returned\n");\r
+  exit (1);\r
+}\r
+\r
+EFI_STATUS\r
+WinNtOpenFile (\r
+  IN  CHAR16                    *FileName,\r
+  IN  UINT32                    MapSize,\r
+  IN  DWORD                     CreationDisposition,\r
+  IN OUT  EFI_PHYSICAL_ADDRESS  *BaseAddress,\r
+  OUT UINT64                    *Length\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Opens and memory maps a file using WinNt services. If BaseAddress is non zero\r
+  the process will try and allocate the memory starting at BaseAddress.\r
+\r
+Arguments:\r
+  FileName            - The name of the file to open and map\r
+  MapSize             - The amount of the file to map in bytes\r
+  CreationDisposition - The flags to pass to CreateFile().  Use to create new files for\r
+                        memory emulation, and exiting files for firmware volume emulation\r
+  BaseAddress         - The base address of the mapped file in the user address space.\r
+                         If passed in as NULL the a new memory region is used.\r
+                         If passed in as non NULL the request memory region is used for\r
+                          the mapping of the file into the process space.\r
+  Length              - The size of the mapped region in bytes\r
+\r
+Returns:\r
+  EFI_SUCCESS      - The file was opened and mapped.\r
+  EFI_NOT_FOUND    - FileName was not found in the current directory\r
+  EFI_DEVICE_ERROR - An error occured attempting to map the opened file\r
+\r
+--*/\r
+{\r
+  HANDLE  NtFileHandle;\r
+  HANDLE  NtMapHandle;\r
+  VOID    *VirtualAddress;\r
+  UINTN   FileSize;\r
+\r
+  //\r
+  // Use Win API to open/create a file\r
+  //\r
+  NtFileHandle = CreateFile (\r
+                  FileName,\r
+                  GENERIC_READ | GENERIC_WRITE,\r
+                  FILE_SHARE_READ,\r
+                  NULL,\r
+                  CreationDisposition,\r
+                  FILE_ATTRIBUTE_NORMAL,\r
+                  NULL\r
+                  );\r
+  if (NtFileHandle == INVALID_HANDLE_VALUE) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  //\r
+  // Map the open file into a memory range\r
+  //\r
+  NtMapHandle = CreateFileMapping (\r
+                  NtFileHandle,\r
+                  NULL,\r
+                  PAGE_READWRITE,\r
+                  0,\r
+                  MapSize,\r
+                  NULL\r
+                  );\r
+  if (NtMapHandle == NULL) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+  //\r
+  // Get the virtual address (address in the emulator) of the mapped file\r
+  //\r
+  VirtualAddress = MapViewOfFileEx (\r
+                    NtMapHandle,\r
+                    FILE_MAP_ALL_ACCESS,\r
+                    0,\r
+                    0,\r
+                    MapSize,\r
+                    (LPVOID) (UINTN) *BaseAddress\r
+                    );\r
+  if (VirtualAddress == NULL) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (MapSize == 0) {\r
+    //\r
+    // Seek to the end of the file to figure out the true file size.\r
+    //\r
+    FileSize = SetFilePointer (\r
+                NtFileHandle,\r
+                0,\r
+                NULL,\r
+                FILE_END\r
+                );\r
+    if (FileSize == -1) {\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+\r
+    *Length = (UINT64) FileSize;\r
+  } else {\r
+    *Length = (UINT64) MapSize;\r
+  }\r
+\r
+  *BaseAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) VirtualAddress;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+#define BYTES_PER_RECORD  512\r
+\r
+/**\r
+  Extracts ASSERT() information from a status code structure.\r
+\r
+  Converts the status code specified by CodeType, Value, and Data to the ASSERT()\r
+  arguments specified by Filename, Description, and LineNumber.  If CodeType is \r
+  an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and \r
+  Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract \r
+  Filename, Description, and LineNumber from the optional data area of the \r
+  status code buffer specified by Data.  The optional data area of Data contains \r
+  a Null-terminated ASCII string for the FileName, followed by a Null-terminated \r
+  ASCII string for the Description, followed by a 32-bit LineNumber.  If the \r
+  ASSERT() information could be extracted from Data, then return TRUE.  \r
+  Otherwise, FALSE is returned.  \r
+\r
+  If Data is NULL, then ASSERT().\r
+  If Filename is NULL, then ASSERT().\r
+  If Description is NULL, then ASSERT().\r
+  If LineNumber is NULL, then ASSERT().\r
+\r
+  @param  CodeType     The type of status code being converted.\r
+  @param  Value        The status code value being converted.\r
+  @param  Data         Pointer to status code data buffer. \r
+  @param  Filename     Pointer to the source file name that generated the ASSERT().\r
+  @param  Description  Pointer to the description of the ASSERT().\r
+  @param  LineNumber   Pointer to source line number that generated the ASSERT().\r
+\r
+  @retval  TRUE   The status code specified by CodeType, Value, and Data was \r
+                  converted ASSERT() arguments specified by Filename, Description, \r
+                  and LineNumber.\r
+  @retval  FALSE  The status code specified by CodeType, Value, and Data could \r
+                  not be converted to ASSERT() arguments.\r
+\r
+**/\r
+STATIC\r
+BOOLEAN\r
+ReportStatusCodeExtractAssertInfo (\r
+  IN EFI_STATUS_CODE_TYPE        CodeType,\r
+  IN EFI_STATUS_CODE_VALUE       Value,  \r
+  IN CONST EFI_STATUS_CODE_DATA  *Data, \r
+  OUT CHAR8                      **Filename,\r
+  OUT CHAR8                      **Description,\r
+  OUT UINT32                     *LineNumber\r
+  )\r
+{\r
+  EFI_DEBUG_ASSERT_DATA  *AssertData;\r
+\r
+  ASSERT (Data        != NULL);\r
+  ASSERT (Filename    != NULL);\r
+  ASSERT (Description != NULL);\r
+  ASSERT (LineNumber  != NULL);\r
+\r
+  if (((CodeType & EFI_STATUS_CODE_TYPE_MASK)      == EFI_ERROR_CODE) && \r
+      ((CodeType & EFI_STATUS_CODE_SEVERITY_MASK)  == EFI_ERROR_UNRECOVERED) &&\r
+      ((Value    & EFI_STATUS_CODE_OPERATION_MASK) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE)) {\r
+    AssertData   = (EFI_DEBUG_ASSERT_DATA *)(Data + 1);\r
+    *Filename    = (CHAR8 *)(AssertData + 1);\r
+    *Description = *Filename + AsciiStrLen (*Filename) + 1;\r
+    *LineNumber  = AssertData->LineNumber;\r
+    return TRUE;\r
+  }\r
+  return FALSE;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecPeiReportStatusCode (\r
+  IN EFI_PEI_SERVICES           **PeiServices,\r
+  IN EFI_STATUS_CODE_TYPE       CodeType,\r
+  IN EFI_STATUS_CODE_VALUE      Value,\r
+  IN UINT32                     Instance,\r
+  IN EFI_GUID                   * CallerId,\r
+  IN EFI_STATUS_CODE_DATA       * Data OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This routine produces the ReportStatusCode PEI service. It's passed\r
+  up to the PEI Core via a PPI. T\r
+\r
+  This code currently uses the NT clib printf. This does not work the same way\r
+  as the EFI Print (), as %t, %g, %s as Unicode are not supported.\r
+\r
+Arguments:\r
+  (see EFI_PEI_REPORT_STATUS_CODE)\r
+\r
+Returns:\r
+  EFI_SUCCESS - Always return success\r
+\r
+--*/\r
+// TODO:    PeiServices - add argument and description to function comment\r
+// TODO:    CodeType - add argument and description to function comment\r
+// TODO:    Value - add argument and description to function comment\r
+// TODO:    Instance - add argument and description to function comment\r
+// TODO:    CallerId - add argument and description to function comment\r
+// TODO:    Data - add argument and description to function comment\r
+{\r
+  CHAR8           *Format;\r
+  EFI_DEBUG_INFO  *DebugInfo;\r
+  VA_LIST         Marker;\r
+  CHAR8           PrintBuffer[BYTES_PER_RECORD * 2];\r
+  CHAR8           *Filename;\r
+  CHAR8           *Description;\r
+  UINT32          LineNumber;\r
+\r
+  if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {\r
+    //\r
+    // This supports DEBUG () marcos\r
+    // Data format\r
+    //  EFI_STATUS_CODE_DATA\r
+    //  EFI_DEBUG_INFO\r
+    //\r
+    // The first 12 * UINT64 bytes of the string are really an\r
+    // arguement stack to support varargs on the Format string.\r
+    //\r
+    if (Data != NULL) {\r
+      DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);\r
+      Marker    = (VA_LIST) (DebugInfo + 1);\r
+      Format    = (CHAR8 *) (((UINT64 *) Marker) + 12);\r
+\r
+      AsciiVSPrint (PrintBuffer, BYTES_PER_RECORD, Format, Marker);\r
+      printf (PrintBuffer);\r
+    } else {\r
+      printf ("DEBUG <null>\n");\r
+    }\r
+  }\r
+\r
+  if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) &&\r
+      ((CodeType & EFI_STATUS_CODE_SEVERITY_MASK) == EFI_ERROR_UNRECOVERED)\r
+      ) {\r
+    if (Data != NULL && ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {\r
+      //\r
+      // Support ASSERT () macro\r
+      //\r
+      printf ("ASSERT %s(%d): %s\n", Filename, LineNumber, Description);\r
+    } else {\r
+      printf ("ASSERT <null>\n");\r
+    }\r
+    CpuBreakpoint ();\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+VOID\r
+SecLoadFromCore (\r
+  IN  UINTN   LargestRegion,\r
+  IN  UINTN   LargestRegionSize,\r
+  IN  UINTN   BootFirmwareVolumeBase,\r
+  IN  VOID    *PeiCorePe32File\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  This is the service to load the PEI Core from the Firmware Volume\r
+\r
+Arguments:\r
+  LargestRegion           - Memory to use for PEI.\r
+  LargestRegionSize       - Size of Memory to use for PEI\r
+  BootFirmwareVolumeBase  - Start of the Boot FV\r
+  PeiCorePe32File         - PEI Core PE32\r
+\r
+Returns:\r
+  Success means control is transfered and thus we should never return\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_PHYSICAL_ADDRESS        TopOfMemory;\r
+  VOID                        *TopOfStack;\r
+  UINT64                      PeiCoreSize;\r
+  EFI_PHYSICAL_ADDRESS        PeiCoreEntryPoint;\r
+  EFI_PHYSICAL_ADDRESS        PeiImageAddress;\r
+  EFI_PEI_STARTUP_DESCRIPTOR  *PeiStartup;\r
+\r
+  //\r
+  // Compute Top Of Memory for Stack and PEI Core Allocations\r
+  //\r
+  TopOfMemory = LargestRegion + LargestRegionSize;\r
+\r
+  //\r
+  // Allocate 128KB for the Stack\r
+  //\r
+  TopOfStack  = (VOID *)((UINTN)TopOfMemory - sizeof (EFI_PEI_STARTUP_DESCRIPTOR) - CPU_STACK_ALIGNMENT);\r
+  TopOfStack  = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
+  TopOfMemory = TopOfMemory - STACK_SIZE;\r
+\r
+  //\r
+  // Patch value in dispatch table values\r
+  //\r
+  gPrivateDispatchTable[0].Ppi = gPeiEfiPeiPeCoffLoader;\r
+\r
+  //\r
+  // Bind this information into the SEC hand-off state\r
+  //\r
+  PeiStartup = (EFI_PEI_STARTUP_DESCRIPTOR *) (UINTN) TopOfStack;\r
+  PeiStartup->DispatchTable      = (EFI_PEI_PPI_DESCRIPTOR *) &gPrivateDispatchTable;\r
+  PeiStartup->SizeOfCacheAsRam   = STACK_SIZE;\r
+  PeiStartup->BootFirmwareVolume = BootFirmwareVolumeBase;\r
+\r
+  //\r
+  // Load the PEI Core from a Firmware Volume\r
+  //\r
+  Status = SecWinNtPeiLoadFile (\r
+            PeiCorePe32File,\r
+            &PeiImageAddress,\r
+            &PeiCoreSize,\r
+            &PeiCoreEntryPoint\r
+            );\r
+  if (EFI_ERROR (Status)) {\r
+    return ;\r
+  }\r
+  //\r
+  // Transfer control to the PEI Core\r
+  //\r
+  SwitchStack (\r
+    (SWITCH_STACK_ENTRY_POINT) (UINTN) PeiCoreEntryPoint,\r
+    PeiStartup,\r
+    NULL,\r
+    TopOfStack\r
+    );\r
+  //\r
+  // If we get here, then the PEI Core returned.  This is an error\r
+  //\r
+  return ;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecWinNtPeiAutoScan (\r
+  IN  UINTN                 Index,\r
+  OUT EFI_PHYSICAL_ADDRESS  *MemoryBase,\r
+  OUT UINT64                *MemorySize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  This service is called from Index == 0 until it returns EFI_UNSUPPORTED.\r
+  It allows discontiguous memory regions to be supported by the emulator.\r
+  It uses gSystemMemory[] and gSystemMemoryCount that were created by\r
+  parsing the Windows environment variable EFI_MEMORY_SIZE.\r
+  The size comes from the varaible and the address comes from the call to\r
+  WinNtOpenFile.\r
+\r
+Arguments:\r
+  Index      - Which memory region to use\r
+  MemoryBase - Return Base address of memory region\r
+  MemorySize - Return size in bytes of the memory region\r
+\r
+Returns:\r
+  EFI_SUCCESS - If memory region was mapped\r
+  EFI_UNSUPPORTED - If Index is not supported\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  if (Index >= gSystemMemoryCount) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  *MemoryBase = 0;\r
+  Status = WinNtOpenFile (\r
+            gSystemMemory[Index].FileName,\r
+            (UINT32) gSystemMemory[Index].Size,\r
+            OPEN_ALWAYS,\r
+            MemoryBase,\r
+            MemorySize\r
+            );\r
+\r
+  gSystemMemory[Index].Memory = *MemoryBase;\r
+\r
+  return Status;\r
+}\r
+\r
+VOID *\r
+EFIAPI\r
+SecWinNtWinNtThunkAddress (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Since the SEC is the only Windows program in stack it must export\r
+  an interface to do Win API calls. That's what the WinNtThunk address\r
+  is for. gWinNt is initailized in WinNtThunk.c.\r
+\r
+Arguments:\r
+  InterfaceSize - sizeof (EFI_WIN_NT_THUNK_PROTOCOL);\r
+  InterfaceBase - Address of the gWinNt global\r
+\r
+Returns:\r
+  EFI_SUCCESS - Data returned\r
+\r
+--*/\r
+{\r
+  return gWinNt;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecWinNtPeiLoadFile (\r
+  IN  VOID                    *Pe32Data,\r
+  IN  EFI_PHYSICAL_ADDRESS    *ImageAddress,\r
+  IN  UINT64                  *ImageSize,\r
+  IN  EFI_PHYSICAL_ADDRESS    *EntryPoint\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Loads and relocates a PE/COFF image into memory.\r
+\r
+Arguments:\r
+  Pe32Data         - The base address of the PE/COFF file that is to be loaded and relocated\r
+  ImageAddress     - The base address of the relocated PE/COFF image\r
+  ImageSize        - The size of the relocated PE/COFF image\r
+  EntryPoint       - The entry point of the relocated PE/COFF image\r
+\r
+Returns:\r
+  EFI_SUCCESS   - The file was loaded and relocated\r
+  EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                            Status;\r
+  PE_COFF_LOADER_IMAGE_CONTEXT          ImageContext;\r
+\r
+  ZeroMem (&ImageContext, sizeof (ImageContext));\r
+  ImageContext.Handle     = Pe32Data;\r
+\r
+  ImageContext.ImageRead  = (PE_COFF_LOADER_READ_FILE) SecImageRead;\r
+\r
+  Status                  = gPeiEfiPeiPeCoffLoader->GetImageInfo (gPeiEfiPeiPeCoffLoader, &ImageContext);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Allocate space in NT (not emulator) memory. Extra space is for alignment\r
+  //\r
+  ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) malloc ((UINTN) (ImageContext.ImageSize + (ImageContext.SectionAlignment * 2)));\r
+  if (ImageContext.ImageAddress == 0) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  //\r
+  // Align buffer on section boundry\r
+  //\r
+  ImageContext.ImageAddress += ImageContext.SectionAlignment;\r
+  ImageContext.ImageAddress &= ~(ImageContext.SectionAlignment - 1);\r
+\r
+  Status = gPeiEfiPeiPeCoffLoader->LoadImage (gPeiEfiPeiPeCoffLoader, &ImageContext);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = gPeiEfiPeiPeCoffLoader->RelocateImage (gPeiEfiPeiPeCoffLoader, &ImageContext);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // BugBug: Flush Instruction Cache Here when CPU Lib is ready\r
+  //\r
+\r
+  *ImageAddress = ImageContext.ImageAddress;\r
+  *ImageSize    = ImageContext.ImageSize;\r
+  *EntryPoint   = ImageContext.EntryPoint;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecWinNtFdAddress (\r
+  IN     UINTN                 Index,\r
+  IN OUT EFI_PHYSICAL_ADDRESS  *FdBase,\r
+  IN OUT UINT64                *FdSize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Return the FD Size and base address. Since the FD is loaded from a\r
+  file into Windows memory only the SEC will know it's address.\r
+\r
+Arguments:\r
+  Index  - Which FD, starts at zero.\r
+  FdSize - Size of the FD in bytes\r
+  FdBase - Start address of the FD. Assume it points to an FV Header\r
+\r
+Returns:\r
+  EFI_SUCCESS     - Return the Base address and size of the FV\r
+  EFI_UNSUPPORTED - Index does nto map to an FD in the system\r
+\r
+--*/\r
+{\r
+  if (Index >= gFdInfoCount) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  *FdBase = gFdInfo[Index].Address;\r
+  *FdSize = gFdInfo[Index].Size;\r
+\r
+  if (*FdBase == 0 && *FdSize == 0) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecImageRead (\r
+  IN     VOID    *FileHandle,\r
+  IN     UINTN   FileOffset,\r
+  IN OUT UINTN   *ReadSize,\r
+  OUT    VOID    *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file\r
+\r
+Arguments:\r
+  FileHandle - The handle to the PE/COFF file\r
+  FileOffset - The offset, in bytes, into the file to read\r
+  ReadSize   - The number of bytes to read from the file starting at FileOffset\r
+  Buffer     - A pointer to the buffer to read the data into.\r
+\r
+Returns:\r
+  EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset\r
+\r
+--*/\r
+{\r
+  CHAR8 *Destination8;\r
+  CHAR8 *Source8;\r
+  UINTN Length;\r
+\r
+  Destination8  = Buffer;\r
+  Source8       = (CHAR8 *) ((UINTN) FileHandle + FileOffset);\r
+  Length        = *ReadSize;\r
+  while (Length--) {\r
+    *(Destination8++) = *(Source8++);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+CHAR16 *\r
+AsciiToUnicode (\r
+  IN  CHAR8   *Ascii,\r
+  IN  UINTN   *StrLen OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Convert the passed in Ascii string to Unicode.\r
+  Optionally return the length of the strings.\r
+\r
+Arguments:\r
+  Ascii   - Ascii string to convert\r
+  StrLen  - Length of string\r
+\r
+Returns:\r
+  Pointer to malloc'ed Unicode version of Ascii\r
+\r
+--*/\r
+{\r
+  UINTN   Index;\r
+  CHAR16  *Unicode;\r
+\r
+  //\r
+  // Allocate a buffer for unicode string\r
+  //\r
+  for (Index = 0; Ascii[Index] != '\0'; Index++)\r
+    ;\r
+  Unicode = malloc ((Index + 1) * sizeof (CHAR16));\r
+  if (Unicode == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  for (Index = 0; Ascii[Index] != '\0'; Index++) {\r
+    Unicode[Index] = (CHAR16) Ascii[Index];\r
+  }\r
+\r
+  Unicode[Index] = '\0';\r
+\r
+  if (StrLen != NULL) {\r
+    *StrLen = Index;\r
+  }\r
+\r
+  return Unicode;\r
+}\r
+\r
+UINTN\r
+CountSeperatorsInString (\r
+  IN  const CHAR16   *String,\r
+  IN  CHAR16         Seperator\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Count the number of seperators in String\r
+\r
+Arguments:\r
+  String    - String to process\r
+  Seperator - Item to count\r
+\r
+Returns:\r
+  Number of Seperator in String\r
+\r
+--*/\r
+{\r
+  UINTN Count;\r
+\r
+  for (Count = 0; *String != '\0'; String++) {\r
+    if (*String == Seperator) {\r
+      Count++;\r
+    }\r
+  }\r
+\r
+  return Count;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+AddModHandle (\r
+  IN  PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext,\r
+  IN  VOID                                 *ModHandle\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Store the ModHandle in an array indexed by the Pdb File name.\r
+  The ModHandle is needed to unload the image. \r
+\r
+Arguments:\r
+  ImageContext - Input data returned from PE Laoder Library. Used to find the \r
+                 .PDB file name of the PE Image.\r
+  ModHandle    - Returned from LoadLibraryEx() and stored for call to \r
+                 FreeLibrary().\r
+\r
+Returns:\r
+  EFI_SUCCESS - ModHandle was stored. \r
+\r
+--*/\r
+{\r
+  UINTN                   Index;\r
+  PDB_NAME_TO_MOD_HANDLE  *Array;\r
+  UINTN                   PreviousSize;\r
+\r
+\r
+  Array = mPdbNameModHandleArray;\r
+  for (Index = 0; Index < mPdbNameModHandleArraySize; Index++, Array++) {\r
+    if (Array->PdbPointer == NULL) {\r
+      //\r
+      // Make a copy of the stirng and store the ModHandle\r
+      //\r
+      Array->PdbPointer = malloc (strlen (ImageContext->PdbPointer) + 1);\r
+      ASSERT (Array->PdbPointer != NULL);\r
+\r
+      strcpy (Array->PdbPointer, ImageContext->PdbPointer);\r
+      Array->ModHandle = ModHandle;\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+  \r
+  //\r
+  // No free space in mPdbNameModHandleArray so grow it by \r
+  // MAX_PDB_NAME_TO_MOD_HANDLE_ARRAY_SIZE entires. realloc will\r
+  // copy the old values to the new locaiton. But it does\r
+  // not zero the new memory area.\r
+  //\r
+  PreviousSize = mPdbNameModHandleArraySize * sizeof (PDB_NAME_TO_MOD_HANDLE);\r
+  mPdbNameModHandleArraySize += MAX_PDB_NAME_TO_MOD_HANDLE_ARRAY_SIZE;\r
+\r
+  mPdbNameModHandleArray = realloc (mPdbNameModHandleArray, mPdbNameModHandleArraySize * sizeof (PDB_NAME_TO_MOD_HANDLE));\r
+  if (mPdbNameModHandleArray == NULL) {\r
+    ASSERT (FALSE);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  \r
+  memset (mPdbNameModHandleArray + PreviousSize, 0, MAX_PDB_NAME_TO_MOD_HANDLE_ARRAY_SIZE * sizeof (PDB_NAME_TO_MOD_HANDLE));\r
\r
+  return AddModHandle (ImageContext, ModHandle);\r
+}\r
+\r
+\r
+VOID *\r
+RemoveModeHandle (\r
+  IN  PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Return the ModHandle and delete the entry in the array.\r
+\r
+Arguments:\r
+  ImageContext - Input data returned from PE Laoder Library. Used to find the \r
+                 .PDB file name of the PE Image.\r
+\r
+Returns:\r
+  ModHandle - ModHandle assoicated with ImageContext is returned\r
+  NULL      - No ModHandle associated with ImageContext\r
+\r
+--*/\r
+{\r
+  UINTN                   Index;\r
+  PDB_NAME_TO_MOD_HANDLE  *Array;\r
+\r
+  if (ImageContext->PdbPointer == NULL) {\r
+    //\r
+    // If no PDB pointer there is no ModHandle so return NULL\r
+    //\r
+    return NULL;\r
+  }\r
+\r
+  Array = mPdbNameModHandleArray;\r
+  for (Index = 0; Index < mPdbNameModHandleArraySize; Index++, Array++) {\r
+    if ((Array->PdbPointer != NULL) && (strcmp(Array->PdbPointer, ImageContext->PdbPointer) == 0)) {\r
+      //\r
+      // If you find a match return it and delete the entry\r
+      //\r
+      free (Array->PdbPointer);\r
+      Array->PdbPointer = NULL;\r
+      return Array->ModHandle;\r
+    }\r
+  }\r
+\r
+  return NULL;\r
+}\r
+\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecNt32PeCoffGetImageInfo (\r
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL          *This,\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  Status = PeCoffLoaderGetImageInfo (ImageContext);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  switch (ImageContext->ImageType) {\r
+\r
+  case EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION:\r
+    ImageContext->ImageCodeMemoryType = EfiLoaderCode;\r
+    ImageContext->ImageDataMemoryType = EfiLoaderData;\r
+    break;\r
+\r
+  case EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:\r
+    ImageContext->ImageCodeMemoryType = EfiBootServicesCode;\r
+    ImageContext->ImageDataMemoryType = EfiBootServicesData;\r
+    break;\r
+\r
+  case EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:\r
+  case EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER:\r
+    ImageContext->ImageCodeMemoryType = EfiRuntimeServicesCode;\r
+    ImageContext->ImageDataMemoryType = EfiRuntimeServicesData;\r
+    break;\r
+\r
+  default:\r
+    ImageContext->ImageError = IMAGE_ERROR_INVALID_SUBSYSTEM;\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecNt32PeCoffLoadImage (\r
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL          *This,\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  Status = PeCoffLoaderLoadImage (ImageContext);\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecNt32PeCoffRelocateImage (\r
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL          *This,\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  )\r
+{\r
+  EFI_STATUS        Status;\r
+  VOID              *DllEntryPoint;\r
+  CHAR16            *DllFileName;\r
+  HMODULE           Library;\r
+  UINTN             Index;\r
+\r
+\r
+  Status = PeCoffLoaderRelocateImage (ImageContext);\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // We could not relocated the image in memory properly\r
+    //\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // If we load our own PE COFF images the Windows debugger can not source\r
+  //  level debug our code. If a valid PDB pointer exists usw it to load\r
+  //  the *.dll file as a library using Windows* APIs. This allows \r
+  //  source level debug. The image is still loaded and reloaced\r
+  //  in the Framework memory space like on a real system (by the code above),\r
+  //  but the entry point points into the DLL loaded by the code bellow. \r
+  //\r
+\r
+  DllEntryPoint = NULL;\r
+\r
+  //\r
+  // Load the DLL if it's not an EBC image.\r
+  //\r
+  if ((ImageContext->PdbPointer != NULL) &&\r
+      (ImageContext->Machine != EFI_IMAGE_MACHINE_EBC)) {\r
+    //\r
+    // Convert filename from ASCII to Unicode\r
+    //\r
+    DllFileName = AsciiToUnicode (ImageContext->PdbPointer, &Index);\r
+\r
+    //\r
+    // Check that we have a valid filename\r
+    //\r
+    if (Index < 5 || DllFileName[Index - 4] != '.') {\r
+      free (DllFileName);\r
+\r
+      //\r
+      // Never return an error if PeCoffLoaderRelocateImage() succeeded.\r
+      // The image will run, but we just can't source level debug. If we\r
+      // return an error the image will not run.\r
+      //\r
+      return EFI_SUCCESS;\r
+    }\r
+    //\r
+    // Replace .PDB with .DLL on the filename\r
+    //\r
+    DllFileName[Index - 3]  = 'D';\r
+    DllFileName[Index - 2]  = 'L';\r
+    DllFileName[Index - 1]  = 'L';\r
+\r
+    //\r
+    // Load the .DLL file into the user process's address space for source \r
+    // level debug\r
+    //\r
+    Library = LoadLibraryEx (DllFileName, NULL, DONT_RESOLVE_DLL_REFERENCES);\r
+    if (Library != NULL) {\r
+      //\r
+      // InitializeDriver is the entry point we put in all our EFI DLL's. The\r
+      // DONT_RESOLVE_DLL_REFERENCES argument to LoadLIbraryEx() supresses the \r
+      // normal DLL entry point of DllMain, and prevents other modules that are\r
+      // referenced in side the DllFileName from being loaded. There is no error \r
+      // checking as the we can point to the PE32 image loaded by Tiano. This \r
+      // step is only needed for source level debuging\r
+      //\r
+      DllEntryPoint = (VOID *) (UINTN) GetProcAddress (Library, "InitializeDriver");\r
+\r
+    }\r
+\r
+    if ((Library != NULL) && (DllEntryPoint != NULL)) {\r
+      AddModHandle (ImageContext, Library);\r
+      ImageContext->EntryPoint  = (EFI_PHYSICAL_ADDRESS) (UINTN) DllEntryPoint;\r
+      wprintf (L"LoadLibraryEx (%s,\n               NULL, DONT_RESOLVE_DLL_REFERENCES)\n", DllFileName);\r
+    } else {\r
+      wprintf (L"WARNING: No source level debug %s. \n", DllFileName);\r
+    }\r
+\r
+    free (DllFileName);\r
+  }\r
+\r
+  //\r
+  // Never return an error if PeCoffLoaderRelocateImage() succeeded.\r
+  // The image will run, but we just can't source level debug. If we\r
+  // return an error the image will not run.\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecNt32PeCoffUnloadimage (\r
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL      *This,\r
+  IN PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  )\r
+{\r
+  VOID *ModHandle;\r
+\r
+  ModHandle = RemoveModeHandle (ImageContext);\r
+  if (ModHandle != NULL) {\r
+    FreeLibrary (ModHandle);\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+VOID\r
+_ModuleEntryPoint (\r
+  VOID\r
+  )\r
+{\r
+}\r
+\r
+#pragma warning(default : 4996)\r
diff --git a/Nt32Pkg/Sec/SecMain.h b/Nt32Pkg/Sec/SecMain.h
new file mode 100644 (file)
index 0000000..7862dcd
--- /dev/null
@@ -0,0 +1,585 @@
+/*++\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
+\r
+Module Name:\r
+  SecMain.h\r
+\r
+Abstract:\r
+  Include file for Windows API based SEC\r
+\r
+--*/\r
+\r
+#include <stdio.h>\r
+#include <Base.h>\r
+#include <PiPei.h>\r
+#include <FrameworkPei.h>\r
+#include <WinNtPeim.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Guid/PeiPeCoffLoader.h>\r
+#include <Ppi/NtPeiLoadFile.h>\r
+#include <Ppi/NtAutoscan.h>\r
+#include <Ppi/NtThunk.h>\r
+#include <Ppi/StatusCode.h>\r
+#include <Ppi/NtFwh.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+\r
+#define STACK_SIZE                0x20000      \r
+\r
+typedef struct {\r
+  EFI_PHYSICAL_ADDRESS  Address;\r
+  UINT64                Size;\r
+} NT_FD_INFO;\r
+\r
+#define NT_SYSTEM_MEMORY_FILENAME_SIZE  40\r
+\r
+typedef struct {\r
+  CHAR16                FileName[NT_SYSTEM_MEMORY_FILENAME_SIZE];\r
+  EFI_PHYSICAL_ADDRESS  Memory;\r
+  UINT64                Size;\r
+} NT_SYSTEM_MEMORY;\r
+\r
+\r
+#define MAX_PDB_NAME_TO_MOD_HANDLE_ARRAY_SIZE 0x100\r
+\r
+typedef struct {\r
+  CHAR8   *PdbPointer;\r
+  VOID    *ModHandle;\r
+} PDB_NAME_TO_MOD_HANDLE;\r
+\r
+\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecWinNtPeiLoadFile (\r
+  VOID                  *Pe32Data,  // TODO: add IN/OUT modifier to Pe32Data\r
+  EFI_PHYSICAL_ADDRESS  *ImageAddress,  // TODO: add IN/OUT modifier to ImageAddress\r
+  UINT64                *ImageSize,  // TODO: add IN/OUT modifier to ImageSize\r
+  EFI_PHYSICAL_ADDRESS  *EntryPoint  // TODO: add IN/OUT modifier to EntryPoint\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Pe32Data      - TODO: add argument description\r
+  ImageAddress  - TODO: add argument description\r
+  ImageSize     - TODO: add argument description\r
+  EntryPoint    - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecWinNtPeiAutoScan (\r
+  IN  UINTN                 Index,\r
+  OUT EFI_PHYSICAL_ADDRESS  *MemoryBase,\r
+  OUT UINT64                *MemorySize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Index       - TODO: add argument description\r
+  MemoryBase  - TODO: add argument description\r
+  MemorySize  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+VOID *\r
+EFIAPI\r
+SecWinNtWinNtThunkAddress (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  InterfaceSize - TODO: add argument description\r
+  InterfaceBase - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecWinNtWinNtFwhAddress (\r
+  IN OUT UINT64                *FwhSize,\r
+  IN OUT EFI_PHYSICAL_ADDRESS  *FwhBase\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  FwhSize - TODO: add argument description\r
+  FwhBase - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecPeiReportStatusCode (\r
+  IN EFI_PEI_SERVICES         **PeiServices,\r
+  IN EFI_STATUS_CODE_TYPE     CodeType,\r
+  IN EFI_STATUS_CODE_VALUE    Value,\r
+  IN UINT32                   Instance,\r
+  IN EFI_GUID                 * CallerId,\r
+  IN EFI_STATUS_CODE_DATA     * Data OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  PeiServices - TODO: add argument description\r
+  CodeType    - TODO: add argument description\r
+  Value       - TODO: add argument description\r
+  Instance    - TODO: add argument description\r
+  CallerId    - TODO: add argument description\r
+  Data        - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+INTN\r
+EFIAPI\r
+main (\r
+  IN  INTN  Argc,\r
+  IN  CHAR8 **Argv,\r
+  IN  CHAR8 **Envp\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Argc  - TODO: add argument description\r
+  Argv  - TODO: add argument description\r
+  Envp  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+WinNtOpenFile (\r
+  CHAR16                *FileName,\r
+  UINT32                MapSize,\r
+  DWORD                 CreationDispostion,\r
+  EFI_PHYSICAL_ADDRESS  *BaseAddress,\r
+  UINT64                *Length\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  FileName            - TODO: add argument description\r
+  MapSize             - TODO: add argument description\r
+  CreationDispostion  - TODO: add argument description\r
+  BaseAddress         - TODO: add argument description\r
+  Length              - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+VOID\r
+SecLoadFromCore (\r
+  IN  UINTN   LargestRegion,\r
+  IN  UINTN   LargestRegionSize,\r
+  IN  UINTN   BootFirmwareVolumeBase,\r
+  IN  VOID    *PeiCoreFile\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  LargestRegion           - TODO: add argument description\r
+  LargestRegionSize       - TODO: add argument description\r
+  BootFirmwareVolumeBase  - TODO: add argument description\r
+  PeiCoreFile             - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+SecLoadFile (\r
+  IN  VOID                    *Pe32Data,\r
+  IN  EFI_PHYSICAL_ADDRESS    *ImageAddress,\r
+  IN  UINT64                  *ImageSize,\r
+  IN  EFI_PHYSICAL_ADDRESS    *EntryPoint\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Pe32Data      - TODO: add argument description\r
+  ImageAddress  - TODO: add argument description\r
+  ImageSize     - TODO: add argument description\r
+  EntryPoint    - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+SecFfsFindPeiCore (\r
+  IN  EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader,\r
+  OUT VOID                        **Pe32Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  FwVolHeader - TODO: add argument description\r
+  Pe32Data    - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+SecFfsFindNextFile (\r
+  IN EFI_FV_FILETYPE             SearchType,\r
+  IN EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader,\r
+  IN OUT EFI_FFS_FILE_HEADER     **FileHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  SearchType  - TODO: add argument description\r
+  FwVolHeader - TODO: add argument description\r
+  FileHeader  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+SecFfsFindSectionData (\r
+  IN EFI_SECTION_TYPE      SectionType,\r
+  IN EFI_FFS_FILE_HEADER   *FfsFileHeader,\r
+  IN OUT VOID              **SectionData\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  SectionType   - TODO: add argument description\r
+  FfsFileHeader - TODO: add argument description\r
+  SectionData   - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecWinNtPeCoffLoaderLoadAsDll (\r
+  IN CHAR8    *PdbFileName,\r
+  IN VOID     **ImageEntryPoint,\r
+  OUT VOID    **ModHandle\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  PdbFileName     - TODO: add argument description\r
+  ImageEntryPoint - TODO: add argument description\r
+  ModHandle       - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecWinNtPeCoffLoaderFreeLibrary (\r
+  OUT VOID    *ModHandle\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ModHandle - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecWinNtFdAddress (\r
+  IN     UINTN                 Index,\r
+  IN OUT EFI_PHYSICAL_ADDRESS  *FdBase,\r
+  IN OUT UINT64                *FdSize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Index   - TODO: add argument description\r
+  FdBase  - TODO: add argument description\r
+  FdSize  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+GetImageReadFunction (\r
+  IN PE_COFF_LOADER_IMAGE_CONTEXT          *ImageContext,\r
+  IN EFI_PHYSICAL_ADDRESS                  *TopOfMemory\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ImageContext  - TODO: add argument description\r
+  TopOfMemory   - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecImageRead (\r
+  IN     VOID    *FileHandle,\r
+  IN     UINTN   FileOffset,\r
+  IN OUT UINTN   *ReadSize,\r
+  OUT    VOID    *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  FileHandle  - TODO: add argument description\r
+  FileOffset  - TODO: add argument description\r
+  ReadSize    - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+CHAR16                            *\r
+AsciiToUnicode (\r
+  IN  CHAR8   *Ascii,\r
+  IN  UINTN   *StrLen OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Ascii   - TODO: add argument description\r
+  StrLen  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+UINTN\r
+CountSeperatorsInString (\r
+  IN  const CHAR16   *String,\r
+  IN  CHAR16   Seperator\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  String    - TODO: add argument description\r
+  Seperator - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecNt32PeCoffGetImageInfo (\r
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL          *This,\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecNt32PeCoffLoadImage (\r
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL          *This,\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecNt32PeCoffRelocateImage (\r
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL          *This,\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecNt32PeCoffUnloadimage (\r
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL      *This,\r
+  IN PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  );\r
+\r
+\r
+typedef struct {\r
+  EFI_PEI_PE_COFF_LOADER_PROTOCOL PeCoff;\r
+  VOID                            *ModHandle;\r
+} EFI_PEI_PE_COFF_LOADER_PROTOCOL_INSTANCE;\r
+\r
+extern EFI_WIN_NT_THUNK_PROTOCOL  *gWinNt;\r
diff --git a/Nt32Pkg/Sec/SecMain.inf b/Nt32Pkg/Sec/SecMain.inf
new file mode 100644 (file)
index 0000000..66a6133
--- /dev/null
@@ -0,0 +1,137 @@
+#/** @file\r
+# Entry Point of NT32 Emulator\r
+#\r
+# Main executable file of NT32 Emulator that loads PEI core after initialization finished.\r
+# Copyright (c) 2007 - 2007, Intel Corporation\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = SecMain\r
+  FILE_GUID                      = 4b837b03-6587-4d19-b82b-edfad836c0a0\r
+  MODULE_TYPE                    = SEC\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+  CUSTOM_MAKEFILE                = MSFT|Makefile\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32\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
+  OldDefinition.h\r
+  SecMain.h\r
+  WinNtThunk.c\r
+  FwVol.c\r
+  SecMain.c\r
+  SecMain_build.xml\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
+  Nt32Pkg/Nt32Pkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\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
+  DebugLib\r
+  PcdLib\r
+  PrintLib\r
+  BaseMemoryLib\r
+  BaseLib\r
+  PeCoffLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Guid C Name Section - list of Guids that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Guids]\r
+  gEfiPeiPeCoffLoaderGuid                       # ALWAYS_PRODUCED\r
+\r
+\r
+################################################################################\r
+#\r
+# PPI C Name Section - list of PPI and PPI Notify C Names that this module\r
+#                      uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Ppis]\r
+  gNtPeiLoadFilePpiGuid                         # PPI ALWAYS_PRODUCED\r
+  gEfiPeiStatusCodePpiGuid                      # PPI ALWAYS_PRODUCED\r
+  gNtFwhPpiGuid                                 # PPI ALWAYS_PRODUCED\r
+  gPeiNtAutoScanPpiGuid                         # PPI ALWAYS_PRODUCED\r
+  gPeiNtThunkPpiGuid                            # PPI ALWAYS_PRODUCED\r
+\r
+\r
+################################################################################\r
+#\r
+# Pcd FIXED_AT_BUILD - list of PCDs that this module is coded for.\r
+#\r
+################################################################################\r
+\r
+[PcdsFixedAtBuild.common]\r
+  PcdWinNtBootMode|gEfiNt32PkgTokenSpaceGuid\r
+\r
+  \r
+################################################################################\r
+#\r
+# Pcd DYNAMIC - list of PCDs that this module is coded for.\r
+#\r
+################################################################################\r
+\r
+[PcdsDynamic.common]\r
+  #PcdWinNtMemorySizeForSecMain|gEfiNt32PkgTokenSpaceGuid\r
+  #PcdWinNtFirmwareVolume|gEfiNt32PkgTokenSpaceGuid\r
+  \r
+\r
diff --git a/Nt32Pkg/Sec/SecMain.msa b/Nt32Pkg/Sec/SecMain.msa
new file mode 100644 (file)
index 0000000..28e8d15
--- /dev/null
@@ -0,0 +1,112 @@
+<?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>SecMain</ModuleName>\r
+    <ModuleType>SEC</ModuleType>\r
+    <GuidValue>4b837b03-6587-4d19-b82b-edfad836c0a0</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Entry Point of NT32 Emulator</Abstract>\r
+    <Description>Main executable file of NT32 Emulator that loads PEI core after initialization finished.</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</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>SecMain</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeCoffLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PrintLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PcdLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename ToolCode="DUMMY">SecMain_build.xml</Filename>\r
+    <Filename>SecMain.c</Filename>\r
+    <Filename>FwVol.c</Filename>\r
+    <Filename>WinNtThunk.c</Filename>\r
+    <Filename>SecMain.h</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="0fb2aa2d-10d5-40a5-a9dc-060c12a4a3f3"/>\r
+  </PackageDependencies>\r
+  <PPIs>\r
+    <Ppi Usage="ALWAYS_PRODUCED">\r
+      <PpiCName>gPeiNtThunkPpiGuid</PpiCName>\r
+    </Ppi>\r
+    <Ppi Usage="ALWAYS_PRODUCED">\r
+      <PpiCName>gPeiNtAutoScanPpiGuid</PpiCName>\r
+    </Ppi>\r
+    <Ppi Usage="ALWAYS_PRODUCED">\r
+      <PpiCName>gNtFwhPpiGuid</PpiCName>\r
+    </Ppi>\r
+    <Ppi Usage="ALWAYS_PRODUCED">\r
+      <PpiCName>gEfiPeiStatusCodePpiGuid</PpiCName>\r
+    </Ppi>\r
+    <Ppi Usage="ALWAYS_PRODUCED">\r
+      <PpiCName>gNtPeiLoadFilePpiGuid</PpiCName>\r
+    </Ppi>\r
+  </PPIs>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_PRODUCED">\r
+      <GuidCName>gEfiPeiPeCoffLoaderGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+  <PcdCoded>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdWinNtMemorySizeForSecMain</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkNt32PkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>This PCD defines the memory size of simulated machine. Simulator will allocate\r
+        the size of PcdWinNtMemorySizeForSecMain in windows platform.</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdWinNtFirmwareVolume</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkNt32PkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>This PCD defines the FD file windows path string. Simulator will load the FD file and execute.</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="FIXED_AT_BUILD">\r
+      <C_Name>PcdWinNtBootMode</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkNt32PkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>This PCD defines the boot mode for simualtor.\r
+        The boot mode can be set as following value:\r
+          0x0: Boot with full configuration.\r
+          0x1: Boot with minimal configuration.\r
+          0x2: Boot assume no configuration changes.\r
+          0x3: Boot with full configuration plus diagnostics.\r
+          0x4: Boot with default settings.\r
+          0x5: Boot on S4 resume.\r
+          0x6: Boot on S5 resume.\r
+          0x10: Boot on S2 resume.\r
+          0x11: Boot on S3 resume.\r
+          0x12: Boot on flash update.\r
+          0x20: Boot in reovery mode.</HelpText>\r
+    </PcdEntry>\r
+  </PcdCoded>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/Nt32Pkg/Sec/SecMain_build.xml b/Nt32Pkg/Sec/SecMain_build.xml
new file mode 100644 (file)
index 0000000..fc26a10
--- /dev/null
@@ -0,0 +1,141 @@
+<?xml version="1.0" ?>\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
+<project name="SecMain" default="main" basedir="." >\r
+  <!-- Apply external ANT task -->\r
+  <taskdef resource="frameworktasks.tasks" /> \r
+  <taskdef resource="cpptasks.tasks" /> \r
+  <typedef resource="cpptasks.types" /> \r
+  <taskdef resource="net/sf/antcontrib/antlib.xml" />\r
+  <property environment="env" />\r
+  <!-- All Properties --> \r
+  <property name="BASE_NAME" value="SecMain" /> \r
+  \r
+  <!-- Default target --> \r
+  <target name="main" depends="libraries, sourcefiles, sections, output" /> \r
+  <!-- Compile all dependency Library instances. --> \r
+\r
+  <target name="libraries">\r
+    <GenBuild type="build">\r
+      <property name="ARCH" value="${ARCH}"/>\r
+      <property name="MODULE_GUID" value="27d67720-ea68-48ae-93da-a3a074c90e30"/>\r
+      <property name="MODULE_VERSION" value=""/>\r
+      <property name="PLATFORM" value="${PLATFORM}"/>\r
+      <property name="PACKAGE_GUID" value="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+      <property name="PACKAGE_VERSION" value=""/>\r
+    </GenBuild>\r
+    <GenBuild type="build">\r
+      <property name="ARCH" value="${ARCH}"/>\r
+      <property name="MODULE_GUID" value="fd44e603-002a-4b29-9f5f-529e815b6165"/>\r
+      <property name="MODULE_VERSION" value=""/>\r
+      <property name="PLATFORM" value="${PLATFORM}"/>\r
+      <property name="PACKAGE_GUID" value="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+      <property name="PACKAGE_VERSION" value=""/>\r
+    </GenBuild>\r
+    <GenBuild type="build">\r
+      <property name="ARCH" value="${ARCH}"/>\r
+      <property name="MODULE_GUID" value="a86fbfca-0183-4eeb-aa8a-762e3b7da1f3"/>\r
+      <property name="MODULE_VERSION" value=""/>\r
+      <property name="PLATFORM" value="${PLATFORM}"/>\r
+      <property name="PACKAGE_GUID" value="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+      <property name="PACKAGE_VERSION" value=""/>\r
+    </GenBuild>\r
+    <GenBuild type="build">\r
+      <property name="ARCH" value="${ARCH}"/>\r
+      <property name="MODULE_GUID" value="556f5d10-7309-4af4-b80a-8196bd60946f"/>\r
+      <property name="MODULE_VERSION" value=""/>\r
+      <property name="PLATFORM" value="${PLATFORM}"/>\r
+      <property name="PACKAGE_GUID" value="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+      <property name="PACKAGE_VERSION" value=""/>\r
+    </GenBuild>\r
+    <GenBuild type="build">\r
+      <property name="ARCH" value="${ARCH}"/>\r
+      <property name="MODULE_GUID" value="9ba1d976-0624-41a3-8650-28165e8d9ae8"/>\r
+      <property name="MODULE_VERSION" value=""/>\r
+      <property name="PLATFORM" value="${PLATFORM}"/>\r
+      <property name="PACKAGE_GUID" value="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+      <property name="PACKAGE_VERSION" value=""/>\r
+    </GenBuild>\r
+  </target>\r
+  <target name="sourcefiles">\r
+      <Build_Init>\r
+        <EXTRA.INC>\r
+          <includepath path="${INCLUDE_PATHS}"/>\r
+        </EXTRA.INC>\r
+      </Build_Init>\r
+      <Build_AUTOGEN FILEEXT="c" FILENAME="AutoGen" FILEPATH=".">\r
+         <EXTRA.INC>\r
+            <includepath path="${INCLUDE_PATHS}"/>\r
+         </EXTRA.INC>\r
+       </Build_AUTOGEN>\r
+      <Build_CCode FILEEXT="c" FILENAME="FwVol" FILEPATH=".">\r
+         <EXTRA.INC>\r
+            <includepath path="${INCLUDE_PATHS}"/>\r
+         </EXTRA.INC>\r
+      </Build_CCode>\r
+      <Build_CCode FILEEXT="c" FILENAME="WinNtThunk" FILEPATH=".">\r
+         <EXTRA.INC>\r
+            <includepath path="${INCLUDE_PATHS}"/>\r
+         </EXTRA.INC>\r
+      </Build_CCode>\r
+      <Build_CCode FILEEXT="c" FILENAME="SecMain" FILEPATH=".">\r
+         <EXTRA.INC>\r
+            <includepath path="${INCLUDE_PATHS}"/>\r
+         </EXTRA.INC>\r
+      </Build_CCode>\r
+    </target>\r
+\r
+    <target name="sections" />\r
+\r
+    <target name="output" >\r
+      <if>\r
+        <available type="file" file="${DEST_DIR_OUTPUT}/AutoGen.h.obj"/>\r
+        <then>\r
+          <var name="SLINK_FLAGS" value="${SLINK_FLAGS} ${DEST_DIR_OUTPUT}/AutoGen.h.obj"/>\r
+        </then>\r
+      </if>\r
+      <OnDependency>\r
+        <sourcefiles>\r
+          <fileset dir="${DEST_DIR_OUTPUT}" includes="${OBJECTS}" />\r
+          <file list="${LIBS}"/>\r
+        </sourcefiles>\r
+        <targetfiles>\r
+          <file name="${BIN_DIR}\SecMain.exe"/>\r
+        </targetfiles>\r
+        \r
+        <sequential>\r
+          <cc userdefine="on">\r
+            <command type="SLINK" cmd="${SLINK}" family="${SLINK_FAMILY}"\r
+                outputFile="${DEST_DIR_OUTPUT}/SecMainLocal.lib" dpath="${SLINK_DPATH}">\r
+                \r
+              <argument value="${SLINK_FLAGS}"/>\r
+\r
+              <fileset dir="${DEST_DIR_OUTPUT}" includes="${OBJECTS}"/>\r
+            </command>\r
+          </cc>\r
+\r
+          <var name="LIBS" value="${LIBS} ${DEST_DIR_OUTPUT}/SecMainLocal.lib" />\r
+         \r
+          <shellscript shell="cmd.exe" tmpsuffix=".cmd" >\r
+            <arg line="/q"/>\r
+            <arg line="/c"/>\r
+            <arg line="call"/>\r
+            PATH ${DLINK_DPATH};%path%\r
+            "${DLINK}" /LIBPATH:"${env.MSVCDir}\Lib" /LIBPATH:"${env.MSVCDir}\PlatformSdk\Lib" /NOLOGO /SUBSYSTEM:CONSOLE /NODEFAULTLIB /IGNORE:4086 /MAP /OPT:REF /DEBUG /MACHINE:I386 /LTCG Kernel32.lib MSVCRTD.lib Gdi32.lib User32.lib Winmm.lib ${LIBS} /base:0x10000000 /out:${BIN_DIR}\SecMain.exe /pdb:${DEST_DIR_DEBUG}\SecMain.pdb\r
+          </shellscript>\r
+        </sequential>\r
+      </OnDependency>\r
+  </target>\r
+  \r
+  <target name="clean" ></target>\r
+\r
+  <target name="cleanAll"></target>\r
+</project>\r
diff --git a/Nt32Pkg/Sec/WinNtThunk.c b/Nt32Pkg/Sec/WinNtThunk.c
new file mode 100644 (file)
index 0000000..2832e13
--- /dev/null
@@ -0,0 +1,180 @@
+/*++\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
+  WinNtThunk.c\r
+\r
+Abstract:\r
+\r
+  Since the SEC is the only windows program in our emulation we \r
+  must use a Tiano mechanism to export Win32 APIs to other modules.\r
+  This is the role of the EFI_WIN_NT_THUNK_PROTOCOL.\r
+\r
+  The mWinNtThunkTable exists so that a change to EFI_WIN_NT_THUNK_PROTOCOL\r
+  will cause an error in initializing the array if all the member functions\r
+  are not added. It looks like adding a element to end and not initializing\r
+  it may cause the table to be initaliized with the members at the end being\r
+  set to zero. This is bad as jumping to zero will case the NT32 to crash.\r
+  \r
+  All the member functions in mWinNtThunkTable are Win32\r
+  API calls, so please reference Microsoft documentation. \r
+\r
+\r
+  gWinNt is a a public exported global that contains the initialized\r
+  data.\r
+\r
+--*/\r
+\r
+#include "SecMain.h"\r
+\r
+//\r
+// This pragma is needed for all the DLL entry points to be asigned to the array.\r
+//  if warning 4232 is not dissabled a warning will be generated as a DLL entry\r
+//  point could be modified dynamically. The SEC does not do that, so we must\r
+//  disable the warning so we can compile the SEC. The previous method was to\r
+//  asign each element in code. The disadvantage to that approach is it's harder\r
+//  to tell if all the elements have been initailized properly.\r
+//\r
+#pragma warning(disable : 4232)\r
+#pragma warning(disable : 4996)\r
+\r
+EFI_WIN_NT_THUNK_PROTOCOL mWinNtThunkTable = {\r
+  EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE,\r
+  GetProcAddress,\r
+  GetTickCount,\r
+  LoadLibraryEx,\r
+  FreeLibrary,\r
+  SetPriorityClass,\r
+  SetThreadPriority,\r
+  Sleep,\r
+  SuspendThread,\r
+  GetCurrentThread,\r
+  GetCurrentThreadId,\r
+  GetCurrentProcess,\r
+  CreateThread,\r
+  TerminateThread,\r
+  SendMessage,\r
+  ExitThread,\r
+  ResumeThread,\r
+  DuplicateHandle,\r
+  InitializeCriticalSection,\r
+  EnterCriticalSection,\r
+  LeaveCriticalSection,\r
+  DeleteCriticalSection,\r
+  TlsAlloc,\r
+  TlsFree,\r
+  TlsSetValue,\r
+  TlsGetValue,\r
+  CreateSemaphore,\r
+  WaitForSingleObject,\r
+  ReleaseSemaphore,\r
+  CreateConsoleScreenBuffer,\r
+  FillConsoleOutputAttribute,\r
+  FillConsoleOutputCharacter,\r
+  GetConsoleCursorInfo,\r
+  GetNumberOfConsoleInputEvents,\r
+  PeekConsoleInput,\r
+  ScrollConsoleScreenBuffer,\r
+  ReadConsoleInput,\r
+  SetConsoleActiveScreenBuffer,\r
+  SetConsoleCursorInfo,\r
+  SetConsoleCursorPosition,\r
+  SetConsoleScreenBufferSize,\r
+  SetConsoleTitleW,\r
+  WriteConsoleInput,\r
+  WriteConsoleOutput,\r
+  CreateFile,\r
+  DeviceIoControl,\r
+  CreateDirectory,\r
+  RemoveDirectory,\r
+  GetFileAttributes,\r
+  SetFileAttributes,\r
+  CreateFileMapping,\r
+  CloseHandle,\r
+  DeleteFile,\r
+  FindFirstFile,\r
+  FindNextFile,\r
+  FindClose,\r
+  FlushFileBuffers,\r
+  GetEnvironmentVariable,\r
+  GetLastError,\r
+  SetErrorMode,\r
+  GetStdHandle,\r
+  MapViewOfFileEx,\r
+  ReadFile,\r
+  SetEndOfFile,\r
+  SetFilePointer,\r
+  WriteFile,\r
+  GetFileInformationByHandle,\r
+  GetDiskFreeSpace,\r
+  GetDiskFreeSpaceEx,\r
+  MoveFile,\r
+  SetFileTime,\r
+  SystemTimeToFileTime,\r
+  FileTimeToLocalFileTime,\r
+  FileTimeToSystemTime,\r
+  GetSystemTime,\r
+  SetSystemTime,\r
+  GetLocalTime,\r
+  SetLocalTime,\r
+  GetTimeZoneInformation,\r
+  SetTimeZoneInformation,\r
+  timeSetEvent,\r
+  timeKillEvent,\r
+  ClearCommError,\r
+  EscapeCommFunction,\r
+  GetCommModemStatus,\r
+  GetCommState,\r
+  SetCommState,\r
+  PurgeComm,\r
+  SetCommTimeouts,\r
+  ExitProcess,\r
+  _snwprintf,\r
+  GetDesktopWindow,\r
+  GetForegroundWindow,\r
+  CreateWindowEx,\r
+  ShowWindow,\r
+  UpdateWindow,\r
+  DestroyWindow,\r
+  InvalidateRect,\r
+  GetWindowDC,\r
+  GetClientRect,\r
+  AdjustWindowRect,\r
+  SetDIBitsToDevice,\r
+  BitBlt,\r
+  GetDC,\r
+  ReleaseDC,\r
+  RegisterClassEx,\r
+  UnregisterClass,\r
+  BeginPaint,\r
+  EndPaint,\r
+  PostQuitMessage,\r
+  DefWindowProc,\r
+  LoadIcon,\r
+  LoadCursor,\r
+  GetStockObject,\r
+  SetViewportOrgEx,\r
+  SetWindowOrgEx,\r
+  MoveWindow,\r
+  GetWindowRect,\r
+  GetMessage,\r
+  TranslateMessage,\r
+  DispatchMessage,\r
+  GetProcessHeap,\r
+  HeapAlloc,\r
+  HeapFree\r
+};\r
+\r
+#pragma warning(default : 4996)\r
+#pragma warning(default : 4232)\r
+\r
+EFI_WIN_NT_THUNK_PROTOCOL *gWinNt = &mWinNtThunkTable;\r