}\r
\r
//\r
- // Run the relocation information and apply the fixups\r
+ // If Adjust is not zero, then apply fix ups to the image\r
//\r
- FixupData = ImageContext->FixupData;\r
- while (RelocBase < RelocBaseEnd) {\r
-\r
- Reloc = (UINT16 *) ((CHAR8 *) RelocBase + sizeof (EFI_IMAGE_BASE_RELOCATION));\r
- RelocEnd = (UINT16 *) ((CHAR8 *) RelocBase + RelocBase->SizeOfBlock);\r
- \r
+ if (Adjust != 0) {\r
//\r
- // Make sure RelocEnd is in the Image range.\r
+ // Run the relocation information and apply the fixups\r
//\r
- if ((CHAR8 *) RelocEnd < (CHAR8 *)((UINTN) ImageContext->ImageAddress) ||\r
- (CHAR8 *) RelocEnd > (CHAR8 *)((UINTN)ImageContext->ImageAddress + (UINTN)ImageContext->ImageSize)) {\r
- ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;\r
- return RETURN_LOAD_ERROR;\r
- }\r
+ FixupData = ImageContext->FixupData;\r
+ while (RelocBase < RelocBaseEnd) {\r
\r
- if (!(ImageContext->IsTeImage)) {\r
- FixupBase = PeCoffLoaderImageAddress (ImageContext, RelocBase->VirtualAddress);\r
- if (FixupBase == NULL) {\r
+ Reloc = (UINT16 *) ((CHAR8 *) RelocBase + sizeof (EFI_IMAGE_BASE_RELOCATION));\r
+ RelocEnd = (UINT16 *) ((CHAR8 *) RelocBase + RelocBase->SizeOfBlock);\r
+ \r
+ //\r
+ // Make sure RelocEnd is in the Image range.\r
+ //\r
+ if ((CHAR8 *) RelocEnd < (CHAR8 *)((UINTN) ImageContext->ImageAddress) ||\r
+ (CHAR8 *) RelocEnd > (CHAR8 *)((UINTN)ImageContext->ImageAddress + (UINTN)ImageContext->ImageSize)) {\r
+ ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;\r
return RETURN_LOAD_ERROR;\r
}\r
- } else {\r
- FixupBase = (CHAR8 *)(UINTN)(ImageContext->ImageAddress +\r
- RelocBase->VirtualAddress +\r
- sizeof(EFI_TE_IMAGE_HEADER) -\r
- Hdr.Te->StrippedSize\r
- );\r
- } \r
\r
- //\r
- // Run this relocation record\r
- //\r
- while (Reloc < RelocEnd) {\r
+ if (!(ImageContext->IsTeImage)) {\r
+ FixupBase = PeCoffLoaderImageAddress (ImageContext, RelocBase->VirtualAddress);\r
+ if (FixupBase == NULL) {\r
+ return RETURN_LOAD_ERROR;\r
+ }\r
+ } else {\r
+ FixupBase = (CHAR8 *)(UINTN)(ImageContext->ImageAddress +\r
+ RelocBase->VirtualAddress +\r
+ sizeof(EFI_TE_IMAGE_HEADER) -\r
+ Hdr.Te->StrippedSize\r
+ );\r
+ } \r
\r
- Fixup = FixupBase + (*Reloc & 0xFFF);\r
- switch ((*Reloc) >> 12) {\r
- case EFI_IMAGE_REL_BASED_ABSOLUTE:\r
- break;\r
+ //\r
+ // Run this relocation record\r
+ //\r
+ while (Reloc < RelocEnd) {\r
\r
- case EFI_IMAGE_REL_BASED_HIGH:\r
- Fixup16 = (UINT16 *) Fixup;\r
- *Fixup16 = (UINT16) (*Fixup16 + ((UINT16) ((UINT32) Adjust >> 16)));\r
- if (FixupData != NULL) {\r
- *(UINT16 *) FixupData = *Fixup16;\r
- FixupData = FixupData + sizeof (UINT16);\r
- }\r
- break;\r
+ Fixup = FixupBase + (*Reloc & 0xFFF);\r
+ switch ((*Reloc) >> 12) {\r
+ case EFI_IMAGE_REL_BASED_ABSOLUTE:\r
+ break;\r
\r
- case EFI_IMAGE_REL_BASED_LOW:\r
- Fixup16 = (UINT16 *) Fixup;\r
- *Fixup16 = (UINT16) (*Fixup16 + (UINT16) Adjust);\r
- if (FixupData != NULL) {\r
- *(UINT16 *) FixupData = *Fixup16;\r
- FixupData = FixupData + sizeof (UINT16);\r
- }\r
- break;\r
+ case EFI_IMAGE_REL_BASED_HIGH:\r
+ Fixup16 = (UINT16 *) Fixup;\r
+ *Fixup16 = (UINT16) (*Fixup16 + ((UINT16) ((UINT32) Adjust >> 16)));\r
+ if (FixupData != NULL) {\r
+ *(UINT16 *) FixupData = *Fixup16;\r
+ FixupData = FixupData + sizeof (UINT16);\r
+ }\r
+ break;\r
\r
- case EFI_IMAGE_REL_BASED_HIGHLOW:\r
- Fixup32 = (UINT32 *) Fixup;\r
- *Fixup32 = *Fixup32 + (UINT32) Adjust;\r
- if (FixupData != NULL) {\r
- FixupData = ALIGN_POINTER (FixupData, sizeof (UINT32));\r
- *(UINT32 *)FixupData = *Fixup32;\r
- FixupData = FixupData + sizeof (UINT32);\r
- }\r
- break;\r
+ case EFI_IMAGE_REL_BASED_LOW:\r
+ Fixup16 = (UINT16 *) Fixup;\r
+ *Fixup16 = (UINT16) (*Fixup16 + (UINT16) Adjust);\r
+ if (FixupData != NULL) {\r
+ *(UINT16 *) FixupData = *Fixup16;\r
+ FixupData = FixupData + sizeof (UINT16);\r
+ }\r
+ break;\r
\r
- case EFI_IMAGE_REL_BASED_DIR64:\r
- Fixup64 = (UINT64 *) Fixup;\r
- *Fixup64 = *Fixup64 + (UINT64) Adjust;\r
- if (FixupData != NULL) {\r
- FixupData = ALIGN_POINTER (FixupData, sizeof(UINT64));\r
- *(UINT64 *)(FixupData) = *Fixup64;\r
- FixupData = FixupData + sizeof(UINT64);\r
+ case EFI_IMAGE_REL_BASED_HIGHLOW:\r
+ Fixup32 = (UINT32 *) Fixup;\r
+ *Fixup32 = *Fixup32 + (UINT32) Adjust;\r
+ if (FixupData != NULL) {\r
+ FixupData = ALIGN_POINTER (FixupData, sizeof (UINT32));\r
+ *(UINT32 *)FixupData = *Fixup32;\r
+ FixupData = FixupData + sizeof (UINT32);\r
+ }\r
+ break;\r
+\r
+ case EFI_IMAGE_REL_BASED_DIR64:\r
+ Fixup64 = (UINT64 *) Fixup;\r
+ *Fixup64 = *Fixup64 + (UINT64) Adjust;\r
+ if (FixupData != NULL) {\r
+ FixupData = ALIGN_POINTER (FixupData, sizeof(UINT64));\r
+ *(UINT64 *)(FixupData) = *Fixup64;\r
+ FixupData = FixupData + sizeof(UINT64);\r
+ }\r
+ break;\r
+\r
+ default:\r
+ //\r
+ // The common code does not handle some of the stranger IPF relocations\r
+ // PeCoffLoaderRelocateImageEx () adds support for these complex fixups\r
+ // on IPF and is a No-Op on other architectures.\r
+ //\r
+ Status = PeCoffLoaderRelocateImageEx (Reloc, Fixup, &FixupData, Adjust);\r
+ if (RETURN_ERROR (Status)) {\r
+ ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;\r
+ return Status;\r
+ }\r
}\r
- break;\r
\r
- default:\r
//\r
- // The common code does not handle some of the stranger IPF relocations\r
- // PeCoffLoaderRelocateImageEx () adds support for these complex fixups\r
- // on IPF and is a No-Op on other architectures.\r
+ // Next relocation record\r
//\r
- Status = PeCoffLoaderRelocateImageEx (Reloc, Fixup, &FixupData, Adjust);\r
- if (RETURN_ERROR (Status)) {\r
- ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;\r
- return Status;\r
- }\r
+ Reloc += 1;\r
}\r
\r
//\r
- // Next relocation record\r
+ // Next reloc block\r
//\r
- Reloc += 1;\r
+ RelocBase = (EFI_IMAGE_BASE_RELOCATION *) RelocEnd;\r
}\r
\r
//\r
- // Next reloc block\r
+ // Adjust the EntryPoint to match the linked-to address\r
//\r
- RelocBase = (EFI_IMAGE_BASE_RELOCATION *) RelocEnd;\r
- }\r
-\r
- //\r
- // Adjust the EntryPoint to match the linked-to address\r
- //\r
- if (ImageContext->DestinationAddress != 0) {\r
- ImageContext->EntryPoint -= (UINT64) ImageContext->ImageAddress;\r
- ImageContext->EntryPoint += (UINT64) ImageContext->DestinationAddress;\r
+ if (ImageContext->DestinationAddress != 0) {\r
+ ImageContext->EntryPoint -= (UINT64) ImageContext->ImageAddress;\r
+ ImageContext->EntryPoint += (UINT64) ImageContext->DestinationAddress;\r
+ }\r
}\r
\r
// Applies additional environment specific actions to relocate fixups \r