Loader: Clean up the ELF AppLoader.
This commit is contained in:
parent
84e52a944d
commit
df0d66c7cf
|
@ -130,7 +130,7 @@ static THREEDSX_Error Load3DSXFile(FileUtil::IOFile& file, u32 base_addr)
|
|||
// Read the relocation headers
|
||||
u32* relocs = (u32*)(loadinfo.seg_ptrs[2] + hdr.data_seg_size);
|
||||
|
||||
for (unsigned current_segment = 0; current_segment < 3; current_segment++) {
|
||||
for (unsigned current_segment : {0, 1, 2}) {
|
||||
size_t size = n_reloc_tables * 4;
|
||||
if (file.ReadBytes(&relocs[current_segment * n_reloc_tables], size) != size)
|
||||
return ERROR_READ;
|
||||
|
@ -148,7 +148,7 @@ static THREEDSX_Error Load3DSXFile(FileUtil::IOFile& file, u32 base_addr)
|
|||
memset((char*)loadinfo.seg_ptrs[2] + hdr.data_seg_size - hdr.bss_size, 0, hdr.bss_size);
|
||||
|
||||
// Relocate the segments
|
||||
for (unsigned current_segment = 0; current_segment < 3; current_segment++) {
|
||||
for (unsigned current_segment : {0, 1, 2}) {
|
||||
for (unsigned current_segment_reloc_table = 0; current_segment_reloc_table < n_reloc_tables; current_segment_reloc_table++) {
|
||||
u32 n_relocs = relocs[current_segment * n_reloc_tables + current_segment_reloc_table];
|
||||
if (current_segment_reloc_table >= 2) {
|
||||
|
|
|
@ -54,12 +54,6 @@ enum ElfMachine {
|
|||
#define EI_PAD 7
|
||||
#define EI_NIDENT 16
|
||||
|
||||
// Magic number
|
||||
#define ELFMAG0 0x7F
|
||||
#define ELFMAG1 'E'
|
||||
#define ELFMAG2 'L'
|
||||
#define ELFMAG3 'F'
|
||||
|
||||
// Sections constants
|
||||
|
||||
// Section types
|
||||
|
@ -188,7 +182,6 @@ private:
|
|||
|
||||
public:
|
||||
ElfReader(void *ptr);
|
||||
~ElfReader() { }
|
||||
|
||||
u32 Read32(int off) const { return base32[off >> 2]; }
|
||||
|
||||
|
@ -197,7 +190,7 @@ public:
|
|||
ElfMachine GetMachine() const { return (ElfMachine)(header->e_machine); }
|
||||
u32 GetEntryPoint() const { return entryPoint; }
|
||||
u32 GetFlags() const { return (u32)(header->e_flags); }
|
||||
bool LoadInto(u32 vaddr);
|
||||
void LoadInto(u32 vaddr);
|
||||
bool LoadSymbols();
|
||||
|
||||
int GetNumSegments() const { return (int)(header->e_phnum); }
|
||||
|
@ -245,7 +238,7 @@ const char *ElfReader::GetSectionName(int section) const {
|
|||
return nullptr;
|
||||
|
||||
int name_offset = sections[section].sh_name;
|
||||
char *ptr = (char*)GetSectionDataPtr(header->e_shstrndx);
|
||||
const char* ptr = (char*)GetSectionDataPtr(header->e_shstrndx);
|
||||
|
||||
if (ptr)
|
||||
return ptr + name_offset;
|
||||
|
@ -253,7 +246,7 @@ const char *ElfReader::GetSectionName(int section) const {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool ElfReader::LoadInto(u32 vaddr) {
|
||||
void ElfReader::LoadInto(u32 vaddr) {
|
||||
LOG_DEBUG(Loader, "String section: %i", header->e_shstrndx);
|
||||
|
||||
// Should we relocate?
|
||||
|
@ -271,7 +264,7 @@ bool ElfReader::LoadInto(u32 vaddr) {
|
|||
u32 segment_addr[32];
|
||||
u32 base_addr = relocate ? vaddr : 0;
|
||||
|
||||
for (int i = 0; i < header->e_phnum; i++) {
|
||||
for (unsigned i = 0; i < header->e_phnum; i++) {
|
||||
Elf32_Phdr* p = segments + i;
|
||||
LOG_DEBUG(Loader, "Type: %i Vaddr: %08x Filesz: %i Memsz: %i ", p->p_type, p->p_vaddr,
|
||||
p->p_filesz, p->p_memsz);
|
||||
|
@ -284,7 +277,6 @@ bool ElfReader::LoadInto(u32 vaddr) {
|
|||
}
|
||||
}
|
||||
LOG_DEBUG(Loader, "Done loading.");
|
||||
return true;
|
||||
}
|
||||
|
||||
SectionID ElfReader::GetSectionByName(const char *name, int firstSection) const {
|
||||
|
@ -307,7 +299,7 @@ bool ElfReader::LoadSymbols() {
|
|||
//We have a symbol table!
|
||||
Elf32_Sym* symtab = (Elf32_Sym *)(GetSectionDataPtr(sec));
|
||||
int numSymbols = sections[sec].sh_size / sizeof(Elf32_Sym);
|
||||
for (int sym = 0; sym < numSymbols; sym++) {
|
||||
for (unsigned sym = 0; sym < numSymbols; sym++) {
|
||||
int size = symtab[sym].st_size;
|
||||
if (size == 0)
|
||||
continue;
|
||||
|
@ -354,7 +346,8 @@ ResultStatus AppLoader_ELF::Load() {
|
|||
|
||||
u32 size = static_cast<u32>(file->GetSize());
|
||||
std::unique_ptr<u8[]> buffer(new u8[size]);
|
||||
file->ReadBytes(&buffer[0], size);
|
||||
if (file->ReadBytes(&buffer[0], size) != size)
|
||||
return ResultStatus::Error;
|
||||
|
||||
ElfReader elf_reader(&buffer[0]);
|
||||
elf_reader.LoadInto(0x00100000);
|
||||
|
|
Reference in New Issue