UINT32 EntryPoint;\r
UINT32 BaseOfCode;\r
UINT16 MachineType;\r
- EFI_TE_IMAGE_HEADER *TeHdr;\r
\r
- TeHdr = NULL;\r
//\r
// Verify input parameters.\r
//\r
//\r
if (Status == EFI_NOT_FOUND) {\r
Status = GetSectionByType (FfsFile, EFI_SECTION_TE, 1, &Pe32Section);\r
- if (Status == EFI_NOT_FOUND) {\r
- BaseOfCode = 0x60;\r
- } else {\r
- TeHdr = (EFI_TE_IMAGE_HEADER *) ((UINTN) Pe32Section.Pe32Section + sizeof (EFI_COMMON_SECTION_HEADER));\r
- BaseOfCode = TeHdr->BaseOfCode - TeHdr->StrippedSize;\r
- }\r
- } else if (EFI_ERROR (Status)) {\r
- Error (NULL, 0, 0, "could not parse a PE32 section from the PEI file", NULL);\r
- return Status;\r
- } else {\r
+ }\r
+\r
+ if (Status == EFI_SUCCESS) {\r
Status = GetPe32Info (\r
(VOID *) ((UINTN) Pe32Section.Pe32Section + sizeof (EFI_SECTION_PE32)),\r
&EntryPoint,\r
&BaseOfCode,\r
&MachineType\r
);\r
- if (EFI_ERROR (Status)) {\r
- Error (NULL, 0, 0, "GetPe32Info() could not get PE32 entry point for PEI file", NULL);\r
- return Status;\r
- }\r
+ } else if (Status == EFI_NOT_FOUND) {\r
+ //\r
+ // For PIC, hardcode.\r
+ //\r
+ BaseOfCode = 0x60;\r
+ Status = EFI_SUCCESS;\r
+ } else {\r
+ Error (NULL, 0, 0, "could not parse a PE32 section from the PEI file", NULL);\r
+ return Status;\r
}\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ Error (NULL, 0, 0, "GetPe32Info() could not get PE32 entry point for PEI file", NULL);\r
+ return Status;\r
+ }\r
+\r
//\r
// Open the source file\r
//\r
TokenAddress += BaseAddress;\r
\r
//\r
- // If PE32 then find the start of code. For PIC it is hardcoded.\r
+ // If PE32 or TE section then find the start of code. For PIC it is hardcoded.\r
//\r
- if (TeHdr == NULL && Pe32Section.Pe32Section) {\r
+ if (Pe32Section.Pe32Section) {\r
//\r
// Add the offset of the PE32 section\r
//\r
// Add the size of the PE32 section header\r
//\r
TokenAddress += sizeof (EFI_PE32_SECTION);\r
- } else if (TeHdr != NULL) {\r
- //\r
- // Add the Te section and FfsHeader\r
- //\r
- //\r
- // BUGBUG: Don't know why this is 0x28 bytes.\r
- //\r
- TokenAddress += (UINTN) TeHdr - (UINTN) FfsFile + 0x28;\r
} else {\r
//\r
- // BUGBUG: Don't know why this is 0x28 bytes.\r
+ // For PIC hardcoded.\r
//\r
TokenAddress += 0x28;\r
}\r
+\r
//\r
// Add the beginning of the code\r
//\r
Error (NULL, 0, 0, "could not find the PEI core in the FV", NULL);\r
return EFI_ABORTED;\r
}\r
+\r
//\r
- // PEI Core found, now find PE32 section\r
+ // PEI Core found, now find PE32 or TE section\r
//\r
Status = GetSectionByType (PeiCoreFile, EFI_SECTION_PE32, 1, &Pe32Section);\r
+ if (Status == EFI_NOT_FOUND) {\r
+ Status = GetSectionByType (PeiCoreFile, EFI_SECTION_TE, 1, &Pe32Section);\r
+ }\r
+\r
if (EFI_ERROR (Status)) {\r
- Error (NULL, 0, 0, "could not find PE32 section in PEI core file", NULL);\r
+ Error (NULL, 0, 0, "could not find PE32 or TE section in PEI core file", NULL);\r
return EFI_ABORTED;\r
}\r
\r
&BaseOfCode,\r
&MachineType\r
);\r
+\r
if (EFI_ERROR (Status)) {\r
Error (NULL, 0, 0, "could not get PE32 entry point for PEI core", NULL);\r
return EFI_ABORTED;\r
\r
Routine Description:\r
\r
- Retrieves the PE32 entry point offset and machine type. See EfiImage.h for\r
- machine types. The entry point offset is from the beginning of the PE32\r
- buffer passed in.\r
+ Retrieves the PE32 entry point offset and machine type from PE image or TeImage. \r
+ See EfiImage.h for machine types. The entry point offset is from the beginning \r
+ of the PE32 buffer passed in.\r
\r
Arguments:\r
\r
{\r
EFI_IMAGE_DOS_HEADER *DosHeader;\r
EFI_IMAGE_NT_HEADERS *NtHeader;\r
+ EFI_TE_IMAGE_HEADER *TeHeader;\r
\r
//\r
// Verify input parameters\r
if (Pe32 == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
- //\r
- // First is the DOS header\r
- //\r
- DosHeader = (EFI_IMAGE_DOS_HEADER *) Pe32;\r
-\r
- //\r
- // Verify DOS header is expected\r
- //\r
- if (DosHeader->e_magic != EFI_IMAGE_DOS_SIGNATURE) {\r
- printf ("ERROR: Unknown magic number in the DOS header, 0x%04X.\n", DosHeader->e_magic);\r
- return EFI_UNSUPPORTED;\r
- }\r
- //\r
- // Immediately following is the NT header.\r
- //\r
- NtHeader = (EFI_IMAGE_NT_HEADERS *) ((UINTN) Pe32 + DosHeader->e_lfanew);\r
\r
//\r
- // Verify NT header is expected\r
+ // First check whether it is one TE Image.\r
//\r
- if (NtHeader->Signature != EFI_IMAGE_NT_SIGNATURE) {\r
- printf ("ERROR: Unrecognized image signature 0x%08X.\n", NtHeader->Signature);\r
- return EFI_UNSUPPORTED;\r
+ TeHeader = (EFI_TE_IMAGE_HEADER *) Pe32;\r
+ if (TeHeader->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
+ //\r
+ // By TeImage Header to get output\r
+ //\r
+ *EntryPoint = TeHeader->AddressOfEntryPoint + sizeof (EFI_TE_IMAGE_HEADER) - TeHeader->StrippedSize;\r
+ *BaseOfCode = TeHeader->BaseOfCode + sizeof (EFI_TE_IMAGE_HEADER) - TeHeader->StrippedSize;\r
+ *MachineType = TeHeader->Machine;\r
+ } else {\r
+ \r
+ //\r
+ // Then check whether \r
+ // First is the DOS header\r
+ //\r
+ DosHeader = (EFI_IMAGE_DOS_HEADER *) Pe32;\r
+ \r
+ //\r
+ // Verify DOS header is expected\r
+ //\r
+ if (DosHeader->e_magic != EFI_IMAGE_DOS_SIGNATURE) {\r
+ printf ("ERROR: Unknown magic number in the DOS header, 0x%04X.\n", DosHeader->e_magic);\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ //\r
+ // Immediately following is the NT header.\r
+ //\r
+ NtHeader = (EFI_IMAGE_NT_HEADERS *) ((UINTN) Pe32 + DosHeader->e_lfanew);\r
+ \r
+ //\r
+ // Verify NT header is expected\r
+ //\r
+ if (NtHeader->Signature != EFI_IMAGE_NT_SIGNATURE) {\r
+ printf ("ERROR: Unrecognized image signature 0x%08X.\n", NtHeader->Signature);\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ //\r
+ // Get output\r
+ //\r
+ *EntryPoint = NtHeader->OptionalHeader.AddressOfEntryPoint;\r
+ *BaseOfCode = NtHeader->OptionalHeader.BaseOfCode;\r
+ *MachineType = NtHeader->FileHeader.Machine;\r
}\r
- //\r
- // Get output\r
- //\r
- *EntryPoint = NtHeader->OptionalHeader.AddressOfEntryPoint;\r
- *BaseOfCode = NtHeader->OptionalHeader.BaseOfCode;\r
- *MachineType = NtHeader->FileHeader.Machine;\r
\r
//\r
// Verify machine type is supported\r