diff options
Diffstat (limited to 'base/loader')
-rw-r--r-- | base/loader/elf_object.cc | 49 | ||||
-rw-r--r-- | base/loader/exec_aout.h | 2 | ||||
-rw-r--r-- | base/loader/exec_ecoff.h | 2 | ||||
-rw-r--r-- | base/loader/object_file.hh | 11 |
4 files changed, 53 insertions, 11 deletions
diff --git a/base/loader/elf_object.cc b/base/loader/elf_object.cc index b74d537af..fd69c9e56 100644 --- a/base/loader/elf_object.cc +++ b/base/loader/elf_object.cc @@ -38,8 +38,8 @@ #define __LIBELF_NEED_LINK_H 0 #define __LIBELF_SYMBOL_VERSIONS 0 -#include <libelf/libelf.h> -#include <libelf/gelf.h> +#include "libelf/libelf.h" +#include "libelf/gelf.h" #include "base/loader/elf_object.hh" @@ -56,6 +56,8 @@ ElfObject::tryFile(const string &fname, int fd, size_t len, uint8_t *data) { Elf *elf; GElf_Ehdr ehdr; + Arch arch = UnknownArch; + OpSys opSys = UnknownOpSys; // check that header matches library version if (elf_version(EV_CURRENT) == EV_NONE) @@ -73,8 +75,8 @@ ElfObject::tryFile(const string &fname, int fd, size_t len, uint8_t *data) return NULL; } else { - if (ehdr.e_ident[EI_CLASS] == ELFCLASS32) - panic("32 bit ELF Binary, Not Supported"); +// if (ehdr.e_ident[EI_CLASS] == ELFCLASS32) +// panic("32 bit ELF Binary, Not Supported"); /* @todo this emachine value isn't offical yet. * so we probably shouldn't check it. */ // if (ehdr.e_machine != EM_ALPHA) @@ -82,8 +84,43 @@ ElfObject::tryFile(const string &fname, int fd, size_t len, uint8_t *data) elf_end(elf); - return new ElfObject(fname, fd, len, data, - ObjectFile::Alpha, ObjectFile::Linux); + //Detect the architecture + //Versioning issues in libelf need to be resolved to get the correct + //SPARC constants. + //If MIPS supports 32 bit executables, this may need to be changed. + //Also, there are other MIPS constants which may be used, like + //EM_MIPS_RS3_LE and EM_MIPS_X + //Since we don't know how to check for alpha right now, we'll + //just assume if it wasn't something else and it's 64 bit, that's + //what it must be. + if (ehdr.e_machine == EM_SPARC64 || + ehdr.e_machine == EM_SPARC || + ehdr.e_machine == EM_SPARCV9) { + arch = ObjectFile::SPARC; + } else if (ehdr.e_machine == EM_MIPS + && ehdr.e_ident[EI_CLASS] == ELFCLASS32) { + arch = ObjectFile::MIPS; + } else if (ehdr.e_ident[EI_CLASS] == ELFCLASS64) { + arch = ObjectFile::Alpha; + } else { + arch = ObjectFile::UnknownArch; + } + + //Detect the operating system + switch (ehdr.e_ident[EI_OSABI]) + { + case ELFOSABI_LINUX: + opSys = ObjectFile::Linux; + break; + case ELFOSABI_SOLARIS: + opSys = ObjectFile::Solaris; + case ELFOSABI_TRU64: + opSys = ObjectFile::Tru64; + default: + opSys = ObjectFile::UnknownOpSys; + } + + return new ElfObject(fname, fd, len, data, arch, opSys); } } diff --git a/base/loader/exec_aout.h b/base/loader/exec_aout.h index 76ebe9bb5..3863a92fb 100644 --- a/base/loader/exec_aout.h +++ b/base/loader/exec_aout.h @@ -55,6 +55,6 @@ (N_GETMAGIC(ex) != NMAGIC && N_GETMAGIC(ex) != OMAGIC && \ N_GETMAGIC(ex) != ZMAGIC) -#include "targetarch/aout_machdep.h" +#include "arch/aout_machdep.h" #endif /* !_SYS_EXEC_AOUT_H_ */ diff --git a/base/loader/exec_ecoff.h b/base/loader/exec_ecoff.h index 4eece4318..79cd22a6e 100644 --- a/base/loader/exec_ecoff.h +++ b/base/loader/exec_ecoff.h @@ -37,7 +37,7 @@ #ifndef _SYS_EXEC_ECOFF_H_ #define _SYS_EXEC_ECOFF_H_ -#include "targetarch/ecoff_machdep.h" +#include "arch/ecoff_machdep.h" struct ecoff_filehdr { coff_ushort f_magic; /* magic number */ diff --git a/base/loader/object_file.hh b/base/loader/object_file.hh index 3c8659e18..1b44ae14f 100644 --- a/base/loader/object_file.hh +++ b/base/loader/object_file.hh @@ -29,7 +29,9 @@ #ifndef __OBJECT_FILE_HH__ #define __OBJECT_FILE_HH__ -#include "arch/isa_traits.hh" // for Addr +#include <string> + +#include "sim/host.hh" // for Addr class FunctionalMemory; class SymbolTable; @@ -40,13 +42,16 @@ class ObjectFile enum Arch { UnknownArch, - Alpha + Alpha, + SPARC, + MIPS }; enum OpSys { UnknownOpSys, Tru64, - Linux + Linux, + Solaris }; protected: |