Cleanup of ELF structures and typo fixes
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
#include <elf.h>
|
||||
|
||||
/* ELF_O module information */
|
||||
/* ELF module information */
|
||||
XTBL_MODINFO = L"ELF executable file format support";
|
||||
|
||||
/* EFI XT Loader Protocol */
|
||||
@@ -153,7 +153,7 @@ ElfLoadImage(IN PEFI_FILE_HANDLE FileHandle,
|
||||
}
|
||||
|
||||
/* Allocate memory for storing image data */
|
||||
Status = XtLdrProtocol->Memory.AllocatePool(sizeof(PECOFF_IMAGE_CONTEXT), (PVOID *)&ImageData);
|
||||
Status = XtLdrProtocol->Memory.AllocatePool(sizeof(ELF_IMAGE_CONTEXT), (PVOID *)&ImageData);
|
||||
if(Status != STATUS_EFI_SUCCESS)
|
||||
{
|
||||
/* Memory allocation failure */
|
||||
@@ -194,8 +194,19 @@ ElfLoadImage(IN PEFI_FILE_HANDLE FileHandle,
|
||||
}
|
||||
|
||||
/* Extract header */
|
||||
ImageData->Header32 = (PELF32_HEADER)Data;
|
||||
ImageData->Header64 = (PELF64_HEADER)Data;
|
||||
ImageData->Header32 = (PELF_IMAGE_HEADER32)Data;
|
||||
ImageData->Header64 = (PELF_IMAGE_HEADER64)Data;
|
||||
|
||||
/* Set physical and virtual addresses */
|
||||
ImageData->PhysicalAddress = (PVOID)(UINT_PTR)Address;
|
||||
if(VirtualAddress)
|
||||
{
|
||||
ImageData->VirtualAddress = VirtualAddress;
|
||||
}
|
||||
else
|
||||
{
|
||||
ImageData->VirtualAddress = (PVOID)(UINT_PTR)Address;
|
||||
}
|
||||
|
||||
/* Validate ELF file */
|
||||
if(ImageData->Header32->e_ident[EI_MAG0] != 0x7F ||
|
||||
@@ -211,12 +222,13 @@ ElfLoadImage(IN PEFI_FILE_HANDLE FileHandle,
|
||||
if(ImageData->Header32->e_ident[EI_CLASS] == 1)
|
||||
{
|
||||
/* 32-bit executable */
|
||||
XtLdrProtocol->Debug.Print(L"Kernel is a 32-bit executable\n");
|
||||
|
||||
/* Set entry point */
|
||||
ImageData->EntryPoint = (PVOID)(UINT_PTR)ImageData->Header32->e_entry;
|
||||
|
||||
/* Load individual segments according to program headers */
|
||||
PELF32_PROGRAM_HEADER ProgramHeaders = (PELF32_PROGRAM_HEADER)(Data + ImageData->Header32->e_phoff);
|
||||
PELF_IMAGE_PROGRAM_HEADER32 ProgramHeaders = (PELF_IMAGE_PROGRAM_HEADER32)(Data + ImageData->Header32->e_phoff);
|
||||
for (UINT Count = 0; Count < ImageData->Header32->e_phnum; Count++)
|
||||
{
|
||||
/* PT_DYNAMIC will be used for relocations */
|
||||
@@ -256,26 +268,19 @@ ElfLoadImage(IN PEFI_FILE_HANDLE FileHandle,
|
||||
else if(ImageData->Header32->e_ident[EI_CLASS] == 2)
|
||||
{
|
||||
/* 64-bit executable */
|
||||
XtLdrProtocol->Debug.Print(L"Kernel is a 64-bit executable\n");
|
||||
|
||||
/* Set entry point */
|
||||
ImageData->EntryPoint = (PVOID)(UINT_PTR)ImageData->Header64->e_entry;
|
||||
XtLdrProtocol->Debug.Print(L"Entry point: 0x%lx (0x%lx)\n", ImageData->EntryPoint, ImageData->Header64->e_entry);
|
||||
|
||||
/* Load individual segments according to program headers */
|
||||
PELF64_PROGRAM_HEADER ProgramHeaders = (PELF64_PROGRAM_HEADER)(Data + ImageData->Header64->e_phoff);
|
||||
PELF_IMAGE_PROGRAM_HEADER64 ProgramHeaders = (PELF_IMAGE_PROGRAM_HEADER64)(Data + ImageData->Header64->e_phoff);
|
||||
for (UINT Count = 0; Count < ImageData->Header64->e_phnum; Count++)
|
||||
{
|
||||
/* PT_DYNAMIC will be used for relocations */
|
||||
if(ProgramHeaders[Count].p_type == PT_LOAD)
|
||||
{
|
||||
/* Set PhysicalAddress and VirtualAddress to the lowest address present */
|
||||
ImageData->PhysicalAddress = (UINT_PTR)ImageData->PhysicalAddress < ProgramHeaders[Count].p_paddr ?
|
||||
ImageData->PhysicalAddress :
|
||||
(PVOID)(UINT_PTR)(UINT64)ProgramHeaders[Count].p_paddr;
|
||||
|
||||
ImageData->VirtualAddress = (UINT_PTR)ImageData->VirtualAddress < ProgramHeaders[Count].p_vaddr ?
|
||||
ImageData->VirtualAddress :
|
||||
(PVOID)(UINT_PTR)(UINT64)ProgramHeaders[Count].p_vaddr;
|
||||
|
||||
/* Allocate memory for the program headers */
|
||||
UINT32 PageCount = EFI_SIZE_TO_PAGES((UINT32)ProgramHeaders[Count].p_memsz);
|
||||
|
||||
@@ -289,7 +294,7 @@ ElfLoadImage(IN PEFI_FILE_HANDLE FileHandle,
|
||||
|
||||
/* Read segment into memory */
|
||||
Status = FileHandle->SetPosition(FileHandle, (UINT64)&ProgramHeaders[Count].p_offset);
|
||||
Status = FileHandle->Read(FileHandle, (PUINT_PTR)&ProgramHeaders[Count].p_filesz, &ProgramHeaders[Count].p_paddr);
|
||||
Status = FileHandle->Read(FileHandle, (PUINT_PTR)&ProgramHeaders[Count].p_filesz, (PVOID)(UINT_PTR)ProgramHeaders[Count].p_paddr);
|
||||
if(Status != STATUS_EFI_SUCCESS)
|
||||
{
|
||||
/* Failed to read data */
|
||||
|
@@ -6,8 +6,8 @@
|
||||
* DEVELOPERS: Jozef Nagy <schkwve@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef __XTLDR_MODULES_ELF_O_H
|
||||
#define __XTLDR_MODULES_ELF_O_H
|
||||
#ifndef __XTLDR_MODULES_ELF_H
|
||||
#define __XTLDR_MODULES_ELF_H
|
||||
|
||||
#include <xtblapi.h>
|
||||
|
||||
@@ -44,4 +44,4 @@ EFI_STATUS
|
||||
BlXtLdrModuleMain(IN EFI_HANDLE ImageHandle,
|
||||
IN PEFI_SYSTEM_TABLE SystemTable);
|
||||
|
||||
#endif /* __XTLDR_MODULES_ELF_O_H */
|
||||
#endif /* __XTLDR_MODULES_ELF_H */
|
||||
|
Reference in New Issue
Block a user