From 54e20dad0f8efe01152d00fe41bf6aa2c44f5bba Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Mon, 4 Feb 2019 22:04:37 +0100 Subject: Setup initial PC according executable entry form ELF file if it is non zero. Signed-off-by: Pavel Pisa --- qtmips_machine/programloader.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'qtmips_machine/programloader.cpp') diff --git a/qtmips_machine/programloader.cpp b/qtmips_machine/programloader.cpp index 5a907c8..7722774 100644 --- a/qtmips_machine/programloader.cpp +++ b/qtmips_machine/programloader.cpp @@ -44,6 +44,7 @@ using namespace machine; ProgramLoader::ProgramLoader(const char *file) { + const GElf_Ehdr *elf_ehdr; // Initialize elf library if (elf_version(EV_CURRENT) == EV_NONE) throw QTMIPS_EXCEPTION(Input, "Elf library initialization failed", elf_errmsg(-1)); @@ -57,8 +58,10 @@ ProgramLoader::ProgramLoader(const char *file) { if (elf_kind(this->elf) != ELF_K_ELF) throw QTMIPS_EXCEPTION(Input, "Invalid input file elf format, plain elf file expected", ""); - if (!gelf_getehdr(this->elf, &this->hdr)) + elf_ehdr = gelf_getehdr(this->elf, &this->hdr); + if (!elf_ehdr) throw QTMIPS_EXCEPTION(Input, "Getting elf file header failed", elf_errmsg(-1)); + executable_entry = elf_ehdr->e_entry; // Check elf file format, executable expected, nothing else. if (this->hdr.e_type != ET_EXEC) throw QTMIPS_EXCEPTION(Input, "Invalid input file type", ""); @@ -119,3 +122,7 @@ std::uint32_t ProgramLoader::end() { } return last + 0x10; // We add offset so we are sure that also pipeline is empty } + +std::uint32_t ProgramLoader::get_executable_entry() { + return executable_entry; +} -- cgit v1.2.3