From d9170d6002c684acdfca1ba124dba2235081b578 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Mon, 9 Aug 2010 17:04:30 -0700 Subject: [PATCH] [sim] removed unused elf loader --- riscv/load_elf.cc | 48 ----------------------------------------------- riscv/load_elf.h | 13 ------------- riscv/riscv.mk.in | 2 -- riscv/sim.cc | 25 ------------------------ riscv/sim.h | 1 - 5 files changed, 89 deletions(-) delete mode 100644 riscv/load_elf.cc delete mode 100644 riscv/load_elf.h diff --git a/riscv/load_elf.cc b/riscv/load_elf.cc deleted file mode 100644 index 0161e42..0000000 --- a/riscv/load_elf.cc +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include -#include -#include -#include "common.h" -#include "load_elf.h" - -void load_elf(const char* buf, size_t size, loader_t* loader) -{ - demand(size >= sizeof(Elf64_Ehdr), "truncated ELF!"); - const Elf64_Ehdr* eh = (const Elf64_Ehdr*)buf; - - const uint32_t* magic = (const uint32_t*)eh->e_ident; - demand(*magic == *(const uint32_t*)ELFMAG, "not a host-endian ELF!"); - demand(size >= eh->e_phoff + eh->e_phnum*sizeof(Elf64_Phdr), "bad ELF!"); - const Elf64_Phdr* phs = (const Elf64_Phdr*)(buf+eh->e_phoff); - - for(int i = 0; i < eh->e_phnum; i++) - { - const Elf64_Phdr* ph = &phs[i]; - if(ph->p_type == SHT_PROGBITS && ph->p_memsz) - { - demand(size >= ph->p_offset + ph->p_filesz, "truncated ELF!"); - demand(ph->p_memsz >= ph->p_filesz, "bad ELF!"); - - loader->write(ph->p_vaddr, ph->p_filesz, buf + ph->p_offset); - loader->write(ph->p_vaddr + ph->p_filesz, ph->p_memsz - ph->p_filesz); - - printf("%d\n", ph->p_vaddr); - } - } -} - -void load_elf(const char* fn, loader_t* loader) -{ - int fd = open(fn, O_RDONLY); - demand(fd != -1, "couldn't open %s", fn); - - struct stat s; - demand(fstat(fd,&s) != -1, "couldn't stat %s", fn); - - char* addr = (char*)mmap(NULL, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0); - demand(addr != MAP_FAILED, "couldn't mmap %s", fn); - - close(fd); - - load_elf(addr, s.st_size, loader); -} diff --git a/riscv/load_elf.h b/riscv/load_elf.h deleted file mode 100644 index 8371591..0000000 --- a/riscv/load_elf.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _RISCV_LOAD_ELF_H -#define _RISCV_LOAD_ELF_H - -class loader_t -{ -public: - virtual void write(size_t addr, size_t bytes, const void* src = NULL) = 0; -}; - -void load_elf(const char* buf, size_t size, loader_t* loader); -void load_elf(const char* fn, loader_t* loader); - -#endif diff --git a/riscv/riscv.mk.in b/riscv/riscv.mk.in index 54fc380..bd806cc 100644 --- a/riscv/riscv.mk.in +++ b/riscv/riscv.mk.in @@ -5,7 +5,6 @@ riscv_hdrs = \ common.h \ decode.h \ execute.h \ - load_elf.h \ mmu.h \ processor.h \ sim.h \ @@ -14,7 +13,6 @@ riscv_hdrs = \ riscv_srcs = \ applink.cc \ - load_elf.cc \ processor.cc \ sim.cc \ trap.cc \ diff --git a/riscv/sim.cc b/riscv/sim.cc index 50fa899..668d23a 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -1,30 +1,10 @@ #include "sim.h" #include "applink.h" #include "common.h" -#include "load_elf.h" #include #include #include -class memory_t : public loader_t -{ -public: - memory_t(char* _mem, size_t _size) : mem(_mem), size(_size) {} - - void write(size_t addr, size_t bytes, const void* src = NULL) - { - demand(addr < size && addr + bytes <= size, "out of bounds!"); - if(src) - memcpy(mem+addr, src, bytes); - else - memset(mem+addr, 0, bytes); - } - -private: - char* mem; - size_t size; -}; - sim_t::sim_t(int _nprocs, size_t _memsz, appserver_link_t* _applink) : applink(_applink), memsz(_memsz), @@ -43,11 +23,6 @@ sim_t::~sim_t() { } -void sim_t::load_elf(const char* fn) -{ - memory_t loader(mem, memsz); - ::load_elf(fn,&loader); -} void sim_t::set_tohost(reg_t val) { fromhost = 0; diff --git a/riscv/sim.h b/riscv/sim.h index 59795d9..c8faa0c 100644 --- a/riscv/sim.h +++ b/riscv/sim.h @@ -14,7 +14,6 @@ class sim_t public: sim_t(int _nprocs, size_t _memsz, appserver_link_t* _applink); ~sim_t(); - void load_elf(const char* fn); void run(bool debug); void set_tohost(reg_t val); -- 2.30.2