Simplify the relocation calculation.

Calculation assumes that the STM is under 1MB in size and
the MSEG will always be on 1 MB boundries.

Signed-off-by: Eugene D. Myers <edmyers@tycho.nsa.gov>
This commit is contained in:
Eugene D. Myers 2020-10-15 12:12:30 -04:00 committed by Eugene D Myers
parent 5f5a40712f
commit 9751de174c
1 changed files with 7 additions and 8 deletions

View File

@ -216,19 +216,17 @@ extern UINT64 _ElfRelocTablesEnd, _ElfRelocTablesStart;
static int elf_process_reloc_table(UINT64 BaseLocation, UINT64 RelativeLocation ) {
int size;
int idx;
Elf64_Rela * reloc_table = (Elf64_Rela *) ((UINT64)&_ElfRelocTablesStart);
// The following conditional is necessary because of differences in compler behaviors
// in handling the "&"
// Depending on the compiler and in some instances the version the "&" can be
// interpeted either as a LEA or as a relative address (where a base address has
// to be added)
if((((UINT64) reloc_table) & BaseLocation) == 0)
{
Elf64_Rela * reloc_table = (Elf64_Rela *) ((UINT64)&_ElfRelocTablesStart + (UINT64)BaseLocation);
}
// the following code works by assuming that the STM image is always less
// than 1MB in size and the MSEG boundry is at 1MB increments
Elf64_Rela * reloc_table = (Elf64_Rela *) ((UINT64)&_ElfRelocTablesStart | (UINT64)BaseLocation);
DEBUG((EFI_D_INFO, "ELF Relocation in progress Base %x Reloc tables %x\n", BaseLocation, &_ElfRelocTablesStart));
size = (UINT64)((UINT64)&_ElfRelocTablesEnd - (UINT64)&_ElfRelocTablesStart)/ sizeof(Elf64_Rela);
@ -321,6 +319,7 @@ RelocateStmImage (
// Not a valid PE image so Exit
//
elf_process_reloc_table(StmImage, StmImage );
AsmWbinvd ();
return ;
}