segments loading (only elf atm)
This commit is contained in:
parent
1ad70366c6
commit
cc471a8535
|
@ -101,6 +101,8 @@ void Linker::LoadModuleToMemory(Module* m)
|
||||||
LOG_INFO_IF(debug_loader, "segment_file_size .....: {}\n", segment_file_size);
|
LOG_INFO_IF(debug_loader, "segment_file_size .....: {}\n", segment_file_size);
|
||||||
LOG_INFO_IF(debug_loader, "segment_memory_size ...: {}\n", segment_memory_size);
|
LOG_INFO_IF(debug_loader, "segment_memory_size ...: {}\n", segment_memory_size);
|
||||||
LOG_INFO_IF(debug_loader, "segment_mode ..........: {}\n", segment_mode);
|
LOG_INFO_IF(debug_loader, "segment_mode ..........: {}\n", segment_mode);
|
||||||
|
|
||||||
|
m->elf->LoadSegment(segment_addr, elf_pheader[i].p_offset, segment_file_size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -111,4 +113,5 @@ void Linker::LoadModuleToMemory(Module* m)
|
||||||
LOG_ERROR_IF(debug_loader, "Unimplemented type {}\n", m->elf->ElfPheaderTypeStr(elf_pheader[i].p_type));
|
LOG_ERROR_IF(debug_loader, "Unimplemented type {}\n", m->elf->ElfPheaderTypeStr(elf_pheader[i].p_type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LOG_INFO_IF(debug_loader, "program entry addr ..........: {:#018x}\n", m->elf->GetElfEntry() + m->base_virtual_addr);
|
||||||
}
|
}
|
|
@ -511,3 +511,21 @@ std::string Elf::ElfPHeaderStr(u16 no)
|
||||||
header += fmt::format("p_align ...: {:#018x}\n", (m_elf_phdr + no)->p_align);
|
header += fmt::format("p_align ...: {:#018x}\n", (m_elf_phdr + no)->p_align);
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
void Elf::LoadSegment(u64 virtual_addr, u64 file_offset, u64 size)
|
||||||
|
{
|
||||||
|
if (m_self!=nullptr)
|
||||||
|
{
|
||||||
|
//it is self file //TODO
|
||||||
|
__debugbreak();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//it's elf file
|
||||||
|
m_f->Seek(file_offset, fsSeekMode::fsSeekSet);
|
||||||
|
m_f->Read(reinterpret_cast<void*>(static_cast<uintptr_t>(virtual_addr)), size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
u64 Elf::GetElfEntry()
|
||||||
|
{
|
||||||
|
return m_elf_header->e_entry;
|
||||||
|
}
|
|
@ -343,6 +343,8 @@ public:
|
||||||
std::string ElfPHeaderStr(u16 no);
|
std::string ElfPHeaderStr(u16 no);
|
||||||
std::string ElfPheaderTypeStr(u32 type);
|
std::string ElfPheaderTypeStr(u32 type);
|
||||||
std::string ElfPheaderFlagsStr(u32 flags);
|
std::string ElfPheaderFlagsStr(u32 flags);
|
||||||
|
void LoadSegment(u64 virtual_addr, u64 file_offset, u64 size);
|
||||||
|
u64 GetElfEntry();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue