From c25a9402ca2f4fcef00ebd4f577103f627d69cb9 Mon Sep 17 00:00:00 2001 From: Brian Drum Date: Mon, 15 Dec 2014 23:59:27 -0500 Subject: [PATCH] Add flat binary loading support --- fesvr/fesvr.mk.in | 2 ++ fesvr/flatloader.cc | 25 +++++++++++++++++++++++++ fesvr/flatloader.h | 9 +++++++++ fesvr/htif.cc | 14 +++++++++++++- fesvr/htif.h | 2 ++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 fesvr/flatloader.cc create mode 100644 fesvr/flatloader.h diff --git a/fesvr/fesvr.mk.in b/fesvr/fesvr.mk.in index 97266fd..8195e20 100644 --- a/fesvr/fesvr.mk.in +++ b/fesvr/fesvr.mk.in @@ -1,6 +1,7 @@ fesvr_hdrs = \ elf.h \ elfloader.h \ + flatloader.h \ htif.h \ memif.h \ syscall.h \ @@ -18,6 +19,7 @@ fesvr_hdrs = \ fesvr_srcs = \ elfloader.cc \ + flatloader.cc \ htif.cc \ packet.cc \ memif.cc \ diff --git a/fesvr/flatloader.cc b/fesvr/flatloader.cc new file mode 100644 index 0000000..d1eb36c --- /dev/null +++ b/fesvr/flatloader.cc @@ -0,0 +1,25 @@ +// See LICENSE for license details. + +#include +#include +#include +#include +#include +#include"memif.h" + +void load_flat(const char *fn, memif_t* memif) +{ + int fd = open(fn, O_RDONLY); + struct stat s; + assert(fd != -1); + assert(fstat(fd, &s) != -1); + size_t size = s.st_size; + + void *buf = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); + assert(buf != MAP_FAILED); + close(fd); + + memif->write(0x2000, size, buf); + + munmap(buf, size); +} diff --git a/fesvr/flatloader.h b/fesvr/flatloader.h new file mode 100644 index 0000000..b61388e --- /dev/null +++ b/fesvr/flatloader.h @@ -0,0 +1,9 @@ +// See LICENSE for license details + +#ifndef _FLATLOADER_H +#define _FLATLOADER_H + +class memif_t; +void load_flat(const char* fn, memif_t* memif); + +#endif diff --git a/fesvr/htif.cc b/fesvr/htif.cc index 5a74b9b..4288282 100644 --- a/fesvr/htif.cc +++ b/fesvr/htif.cc @@ -3,6 +3,7 @@ #include "htif.h" #include "rfb.h" #include "elfloader.h" +#include "flatloader.h" #include #include #include @@ -39,7 +40,7 @@ static void handle_signal(int sig) htif_t::htif_t(const std::vector& args) : exitcode(0), mem(this), seqno(1), started(false), stopped(false), - _mem_mb(0), _num_cores(0), sig_addr(0), sig_len(0), + loadflat(false), _mem_mb(0), _num_cores(0), sig_addr(0), sig_len(0), syscall_proxy(this) { signal(SIGINT, &handle_signal); @@ -149,6 +150,12 @@ void htif_t::load_program() if (path.empty()) throw std::runtime_error("could not open " + targs[0]); + if(loadflat) + { + load_flat(path.c_str(), &mem); + return; + } + std::map symbols = load_elf(path.c_str(), &mem); // detect torture tests so we can print the memory signature at the end @@ -321,3 +328,8 @@ int htif_t::exit_code() { return exitcode >> 1; } + +void htif_t::set_loadflat(bool value) +{ + loadflat = value; +} diff --git a/fesvr/htif.h b/fesvr/htif.h index 6266e1f..4f51a9b 100644 --- a/fesvr/htif.h +++ b/fesvr/htif.h @@ -21,6 +21,7 @@ class htif_t int run(); bool done(); int exit_code(); + void set_loadflat(bool value); virtual reg_t read_cr(uint32_t coreid, uint16_t regnum); virtual reg_t write_cr(uint32_t coreid, uint16_t regnum, reg_t val); @@ -52,6 +53,7 @@ class htif_t seqno_t seqno; bool started; bool stopped; + bool loadflat; uint32_t _mem_mb; uint32_t _num_cores; std::vector hargs;