Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions lib/src/sailsim_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,9 @@ sailsim_isa_t sailsim_detect_elf_isa(const char* elf_path) {
}

try {
ELF elf = ELF::open(elf_path);
ISA elf_isa = elf.isa();

switch (elf_isa) {
case ISA::RISCV:
return SAILSIM_ISA_RISCV;
case ISA::ARM:
return SAILSIM_ISA_ARM;
default:
return SAILSIM_ISA_UNKNOWN;
}
// throws if the elf isnt RISC-V
ELF _elf = ELF::open(elf_path);
return SAILSIM_ISA_RISCV;
} catch (const std::exception& e) {
return SAILSIM_ISA_UNKNOWN;
}
Expand Down Expand Up @@ -205,15 +197,9 @@ bool sailsim_load_elf(sailsim_context_t* ctx, const char* elf_path) {

try {
// Load ELF file using ELF class from elf_loader.h
// throws if the elf isnt RISC-V
ELF elf = ELF::open(elf_path);

// Validate this is a RISC-V ELF file
ISA elf_isa = elf.isa();
if (elf_isa != ISA::RISCV) {
ctx->last_error = "ELF file is not RISC-V (this library only supports RISC-V)";
return false;
}

// Load segments into memory using RISC-V write_mem
elf.load([](uint64_t addr, const uint8_t* data, uint64_t len) {
for (uint64_t i = 0; i < len; i++) {
Expand Down