fix: pass remaining riscv isa tests

This commit is contained in:
abnerhexu
2026-06-27 07:07:07 +00:00
parent a2e0126199
commit a32db39c80
38 changed files with 81187 additions and 19321 deletions

View File

@@ -5,8 +5,9 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <vector>
Memory::Memory() : base_addr(MEM_BASE), entry_point(MEM_BASE) {
Memory::Memory() : base_addr(MEM_BASE), entry_point(MEM_BASE), tohost_addr(TOHOST_ADDR) {
mem.resize(MEM_SIZE, 0);
}
@@ -105,6 +106,44 @@ bool Memory::load_elf(const std::string& filename) {
}
}
if (ehdr.e_shoff != 0 && ehdr.e_shnum != 0) {
std::vector<Elf64_Shdr> shdrs(ehdr.e_shnum);
lseek(fd, ehdr.e_shoff, SEEK_SET);
if (read(fd, shdrs.data(), ehdr.e_shnum * sizeof(Elf64_Shdr)) == (ssize_t)(ehdr.e_shnum * sizeof(Elf64_Shdr))) {
for (int i = 0; i < ehdr.e_shnum; i++) {
const Elf64_Shdr& symtab = shdrs[i];
if (symtab.sh_type != SHT_SYMTAB || symtab.sh_entsize == 0 ||
symtab.sh_link >= ehdr.e_shnum) {
continue;
}
const Elf64_Shdr& strtab = shdrs[symtab.sh_link];
std::vector<char> strings(strtab.sh_size);
lseek(fd, strtab.sh_offset, SEEK_SET);
if (read(fd, strings.data(), strtab.sh_size) != (ssize_t)strtab.sh_size) {
continue;
}
size_t nsyms = symtab.sh_size / symtab.sh_entsize;
std::vector<Elf64_Sym> symbols(nsyms);
lseek(fd, symtab.sh_offset, SEEK_SET);
if (read(fd, symbols.data(), symtab.sh_size) != (ssize_t)symtab.sh_size) {
continue;
}
for (const Elf64_Sym& sym : symbols) {
if (sym.st_name >= strings.size()) {
continue;
}
if (strcmp(&strings[sym.st_name], "tohost") == 0) {
tohost_addr = sym.st_value;
break;
}
}
}
}
}
close(fd);
printf("ELF loaded: entry=0x%lx\n", entry_point);
return true;