+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2006 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-Module Name:\r
-\r
- PeCoffGetEntryPoint.c\r
-\r
-Abstract:\r
-\r
- Tiano PE/COFF loader\r
-\r
-Revision History\r
-\r
---*/\r
-\r
-\r
-RETURN_STATUS\r
-EFIAPI\r
-PeCoffLoaderGetEntryPoint (\r
- IN VOID *Pe32Data,\r
- IN OUT VOID **EntryPoint\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Loads a PE/COFF image into memory, this is not follow the original purpose of \r
- PeCoffGetEntryPoint library class. But it's ok that Unix package not run on a real \r
- platform and this is for source level debug.\r
-\r
-Arguments:\r
-\r
- Pe32Data - Pointer to a PE/COFF Image\r
-\r
- EntryPoint - Pointer to the entry point of the PE/COFF image\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS if the EntryPoint was returned\r
- EFI_INVALID_PARAMETER if the EntryPoint could not be found from Pe32Data\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;\r
- NT_PEI_LOAD_FILE_PPI *PeiNtService;\r
- EFI_PHYSICAL_ADDRESS ImageAddress;\r
- UINT64 ImageSize;\r
- EFI_PHYSICAL_ADDRESS ImageEntryPoint;\r
-\r
- Status = PeiServicesLocatePpi (\r
- &gNtPeiLoadFilePpiGuid,\r
- 0,\r
- &PpiDescriptor,\r
- &PeiNtService\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- Status = PeiNtService->PeiLoadFileService (\r
- Pe32Data,\r
- &ImageAddress,\r
- &ImageSize,\r
- &ImageEntryPoint\r
- );\r
- *EntryPoint = (VOID*)(UINTN)ImageEntryPoint;\r
- return Status;\r
-}\r
-\r
-/**\r
- Returns the machine type of PE/COFF image. \r
- This is copied from MDE BasePeCoffGetEntryPointLib, the code should be sync with it.\r
- The reason is NT32 package needs to load the image to memory to support source\r
- level debug.\r
- \r
-\r
- @param Image Pointer to a PE/COFF header\r
-\r
- @return Machine type or zero if not a valid iamge\r
-\r
-**/\r
-UINT16\r
-EFIAPI\r
-PeCoffLoaderGetMachineType (\r
- IN VOID *Pe32Data\r
- )\r
-{ \r
- EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
- EFI_IMAGE_DOS_HEADER *DosHdr;\r
-\r
- DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
- if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + DosHdr->e_lfanew);\r
- } else {\r
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data);\r
- }\r
-\r
- if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
- return Hdr.Pe32->FileHeader.Machine;\r
- }\r
-\r
- return 0x0000;\r
-}\r
-\r