From dfd191367991cb157b53767dcc05824c826b5abd Mon Sep 17 00:00:00 2001 From: Iman Hosseini Date: Tue, 20 Sep 2022 00:05:00 -0400 Subject: 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. --- fesvr/htif.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'fesvr/htif.cc') 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 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(); -- cgit v1.1