diff options
author | Iman Hosseini <hosseini.iman@yahoo.com> | 2022-09-20 00:05:00 -0400 |
---|---|---|
committer | Iman Hosseini <hosseini.iman@yahoo.com> | 2022-09-20 00:05:00 -0400 |
commit | dfd191367991cb157b53767dcc05824c826b5abd (patch) | |
tree | 8891eff92502ba3d42a9ddf372f0f2f6e5a5e44c /fesvr/elfloader.cc | |
parent | a0972c82d022f6f7c337b06b27c89a60af52202a (diff) | |
download | riscv-isa-sim-dfd191367991cb157b53767dcc05824c826b5abd.zip riscv-isa-sim-dfd191367991cb157b53767dcc05824c826b5abd.tar.gz riscv-isa-sim-dfd191367991cb157b53767dcc05824c826b5abd.tar.bz2 |
detects the loading of isa-incompatible (i.e. 32 bit code to 64bit HART) code and emits an error message to help avoid unintentionally loading wrong elf.
Diffstat (limited to 'fesvr/elfloader.cc')
-rw-r--r-- | fesvr/elfloader.cc | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/fesvr/elfloader.cc b/fesvr/elfloader.cc index 76cd6da..1bdccd3 100644 --- a/fesvr/elfloader.cc +++ b/fesvr/elfloader.cc @@ -16,7 +16,7 @@ #include <vector> #include <map> -std::map<std::string, uint64_t> load_elf(const char* fn, memif_t* memif, reg_t* entry) +std::map<std::string, uint64_t> load_elf(const char* fn, memif_t* memif, reg_t* entry, unsigned required_xlen = 0) { int fd = open(fn, O_RDONLY); struct stat s; @@ -32,6 +32,10 @@ std::map<std::string, uint64_t> load_elf(const char* fn, memif_t* memif, reg_t* assert(size >= sizeof(Elf64_Ehdr)); const Elf64_Ehdr* eh64 = (const Elf64_Ehdr*)buf; assert(IS_ELF32(*eh64) || IS_ELF64(*eh64)); + unsigned xlen = IS_ELF32(*eh64) ? 32 : 64; + if (required_xlen != 0 && required_xlen != xlen) { + throw incompat_xlen(required_xlen, xlen); + } assert(IS_ELFLE(*eh64) || IS_ELFBE(*eh64)); assert(IS_ELF_EXEC(*eh64)); assert(IS_ELF_RISCV(*eh64) || IS_ELF_EM_NONE(*eh64)); |