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/htif.cc | |
parent | a0972c82d022f6f7c337b06b27c89a60af52202a (diff) | |
download | spike-dfd191367991cb157b53767dcc05824c826b5abd.zip spike-dfd191367991cb157b53767dcc05824c826b5abd.tar.gz spike-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/htif.cc')
-rw-r--r-- | fesvr/htif.cc | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/fesvr/htif.cc b/fesvr/htif.cc index ead309c..29eb7d8 100644 --- a/fesvr/htif.cc +++ b/fesvr/htif.cc @@ -82,8 +82,14 @@ htif_t::~htif_t() void htif_t::start() { - if (!targs.empty() && targs[0] != "none") + if (!targs.empty() && targs[0] != "none") { + try { load_program(); + } catch (const incompat_xlen & err) { + fprintf(stderr, "Error: cannot execute %d-bit program on RV%d hart\n", err.actual_xlen, err.expected_xlen); + exit(1); + } + } reset(); } @@ -129,7 +135,7 @@ std::map<std::string, uint64_t> htif_t::load_payload(const std::string& payload, } preload_aware_memif(this); try { - return load_elf(path.c_str(), &preload_aware_memif, entry); + return load_elf(path.c_str(), &preload_aware_memif, entry, expected_xlen); } catch (mem_trap_t& t) { bad_address("loading payload " + payload, t.get_tval()); abort(); |