Skip to content
This repository has been archived by the owner on Apr 2, 2019. It is now read-only.

Add flat binary loading support #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions fesvr/fesvr.mk.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
fesvr_hdrs = \
elf.h \
elfloader.h \
flatloader.h \
htif.h \
memif.h \
syscall.h \
Expand All @@ -18,6 +19,7 @@ fesvr_hdrs = \

fesvr_srcs = \
elfloader.cc \
flatloader.cc \
htif.cc \
packet.cc \
memif.cc \
Expand Down
25 changes: 25 additions & 0 deletions fesvr/flatloader.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// See LICENSE for license details.

#include<sys/mman.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<assert.h>
#include<unistd.h>
#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);
}
9 changes: 9 additions & 0 deletions fesvr/flatloader.h
Original file line number Diff line number Diff line change
@@ -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
14 changes: 13 additions & 1 deletion fesvr/htif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "htif.h"
#include "rfb.h"
#include "elfloader.h"
#include "flatloader.h"
#include <algorithm>
#include <assert.h>
#include <vector>
Expand Down Expand Up @@ -39,7 +40,7 @@ static void handle_signal(int sig)

htif_t::htif_t(const std::vector<std::string>& 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);
Expand Down Expand Up @@ -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<std::string, uint64_t> symbols = load_elf(path.c_str(), &mem);

// detect torture tests so we can print the memory signature at the end
Expand Down Expand Up @@ -321,3 +328,8 @@ int htif_t::exit_code()
{
return exitcode >> 1;
}

void htif_t::set_loadflat(bool value)
{
loadflat = value;
}
2 changes: 2 additions & 0 deletions fesvr/htif.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<std::string> hargs;
Expand Down