add zedboard support (via the -z flag)
This commit is contained in:
parent
dfe719726a
commit
8e573ba99f
|
@ -73,12 +73,6 @@ MCPPBS_ALWAYS_USE_CXX
|
||||||
|
|
||||||
MCPPBS_PROG_INSTALL
|
MCPPBS_PROG_INSTALL
|
||||||
|
|
||||||
# Check for an isa simulator with the name host-isa-run or host-run.
|
|
||||||
# This simulator will be used for running unit test programs in
|
|
||||||
# non-native builds.
|
|
||||||
|
|
||||||
MCPPBS_PROG_RUN
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
# MCPPBS subproject includes
|
# MCPPBS subproject includes
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "htif_csim.h"
|
#include "htif_csim.h"
|
||||||
#include "htif_rs232.h"
|
#include "htif_rs232.h"
|
||||||
#include "htif_eth.h"
|
#include "htif_eth.h"
|
||||||
|
#include "htif_zedboard.h"
|
||||||
#include "memif.h"
|
#include "memif.h"
|
||||||
#include "elf.h"
|
#include "elf.h"
|
||||||
#include "syscall.h"
|
#include "syscall.h"
|
||||||
|
@ -40,7 +41,8 @@ int main(int argc, char** argv)
|
||||||
SIMTYPE_ISA,
|
SIMTYPE_ISA,
|
||||||
SIMTYPE_RS232,
|
SIMTYPE_RS232,
|
||||||
SIMTYPE_ETH,
|
SIMTYPE_ETH,
|
||||||
SIMTYPE_CSIM
|
SIMTYPE_CSIM,
|
||||||
|
SIMTYPE_ZEDBOARD,
|
||||||
} simtype = SIMTYPE_ISA;
|
} simtype = SIMTYPE_ISA;
|
||||||
|
|
||||||
std::vector<char*> htif_args;
|
std::vector<char*> htif_args;
|
||||||
|
@ -58,6 +60,8 @@ int main(int argc, char** argv)
|
||||||
simtype = SIMTYPE_RS232;
|
simtype = SIMTYPE_RS232;
|
||||||
else if (s == "-eth")
|
else if (s == "-eth")
|
||||||
simtype = SIMTYPE_ETH;
|
simtype = SIMTYPE_ETH;
|
||||||
|
else if (s == "-z")
|
||||||
|
simtype = SIMTYPE_ZEDBOARD;
|
||||||
else if (s.substr(0,2) == "-c")
|
else if (s.substr(0,2) == "-c")
|
||||||
{
|
{
|
||||||
simtype = SIMTYPE_CSIM;
|
simtype = SIMTYPE_CSIM;
|
||||||
|
@ -96,6 +100,7 @@ int main(int argc, char** argv)
|
||||||
case SIMTYPE_RS232: htif = new htif_rs232_t(ncores, htif_args); break;
|
case SIMTYPE_RS232: htif = new htif_rs232_t(ncores, htif_args); break;
|
||||||
case SIMTYPE_ETH: htif = new htif_eth_t(ncores, htif_args); break;
|
case SIMTYPE_ETH: htif = new htif_eth_t(ncores, htif_args); break;
|
||||||
case SIMTYPE_CSIM: htif = new htif_csim_t(ncores, csim_name, htif_args); break;
|
case SIMTYPE_CSIM: htif = new htif_csim_t(ncores, csim_name, htif_args); break;
|
||||||
|
case SIMTYPE_ZEDBOARD: htif = new htif_zedboard_t(ncores, htif_args); break;
|
||||||
default: abort();
|
default: abort();
|
||||||
}
|
}
|
||||||
htif->assume0init(assume0init);
|
htif->assume0init(assume0init);
|
||||||
|
|
|
@ -19,6 +19,7 @@ fesvr_hdrs = \
|
||||||
htif_rs232.h \
|
htif_rs232.h \
|
||||||
htif_hexwriter.h \
|
htif_hexwriter.h \
|
||||||
htif_eth.h \
|
htif_eth.h \
|
||||||
|
htif_zedboard.h \
|
||||||
|
|
||||||
fesvr_srcs = \
|
fesvr_srcs = \
|
||||||
elf.cc \
|
elf.cc \
|
||||||
|
@ -31,6 +32,7 @@ fesvr_srcs = \
|
||||||
htif_rs232.cc \
|
htif_rs232.cc \
|
||||||
htif_hexwriter.cc \
|
htif_hexwriter.cc \
|
||||||
htif_eth.cc \
|
htif_eth.cc \
|
||||||
|
htif_zedboard.cc \
|
||||||
|
|
||||||
fesvr_install_prog_srcs = \
|
fesvr_install_prog_srcs = \
|
||||||
elf2hex.cc \
|
elf2hex.cc \
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
#include "htif_zedboard.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define read_reg(r) (dev_vaddr[r])
|
||||||
|
#define write_reg(r, v) (dev_vaddr[r] = v)
|
||||||
|
|
||||||
|
htif_zedboard_t::htif_zedboard_t(int ncores, std::vector<char*> args)
|
||||||
|
: htif_t(ncores)
|
||||||
|
{
|
||||||
|
mem = (uintptr_t*)mmap(0, mem_mb() << 20, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
|
||||||
|
assert(mem != MAP_FAILED);
|
||||||
|
|
||||||
|
int fd = open("/dev/mem", O_RDWR|O_SYNC);
|
||||||
|
assert(fd != -1);
|
||||||
|
dev_vaddr = (uintptr_t*)mmap(0, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, dev_paddr);
|
||||||
|
assert(dev_vaddr != MAP_FAILED);
|
||||||
|
write_reg(31, 0); // reset
|
||||||
|
}
|
||||||
|
|
||||||
|
htif_zedboard_t::~htif_zedboard_t()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t htif_zedboard_t::write(const void* buf, size_t size)
|
||||||
|
{
|
||||||
|
poll_mem();
|
||||||
|
const uint16_t* x = (const uint16_t*)buf;
|
||||||
|
for (size_t i = 0; i < size/sizeof(x[0]); i++)
|
||||||
|
write_reg(0, x[i]);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t htif_zedboard_t::read(void* buf, size_t max_size)
|
||||||
|
{
|
||||||
|
uint16_t* x = (uint16_t*)buf;
|
||||||
|
for (size_t i = 0; ; )
|
||||||
|
{
|
||||||
|
uintptr_t v = read_reg(0);
|
||||||
|
if (v & 1)
|
||||||
|
{
|
||||||
|
assert((i+1)*sizeof(x[0]) <= max_size);
|
||||||
|
x[i++] = v >> 1;
|
||||||
|
}
|
||||||
|
else if (i == 0)
|
||||||
|
poll_mem();
|
||||||
|
else
|
||||||
|
return i*sizeof(x[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void htif_zedboard_t::poll_mem()
|
||||||
|
{
|
||||||
|
uintptr_t cmd = read_reg(1);
|
||||||
|
if (cmd & 1)
|
||||||
|
{
|
||||||
|
bool read = (cmd & 2) == 0;
|
||||||
|
uintptr_t addr = (cmd >> 2)*chunk_align();
|
||||||
|
assert(addr < (mem_mb() << 20));
|
||||||
|
|
||||||
|
for (size_t i = 0; i < chunk_align()/sizeof(uintptr_t); i++)
|
||||||
|
{
|
||||||
|
uintptr_t* x = mem + addr/sizeof(uintptr_t) + i;
|
||||||
|
if (read)
|
||||||
|
write_reg(1, *x);
|
||||||
|
else
|
||||||
|
*x = read_reg(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef __HTIF_ZEDBOARD_H
|
||||||
|
#define __HTIF_ZEDBOARD_H
|
||||||
|
|
||||||
|
#include "htif.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class htif_zedboard_t : public htif_t
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
htif_zedboard_t(int ncores, std::vector<char*> args);
|
||||||
|
~htif_zedboard_t();
|
||||||
|
|
||||||
|
uint32_t mem_mb() { return 256; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
ssize_t read(void* buf, size_t max_size);
|
||||||
|
ssize_t write(const void* buf, size_t size);
|
||||||
|
|
||||||
|
size_t chunk_max_size() { return 64; }
|
||||||
|
size_t chunk_align() { return 64; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void poll_mem();
|
||||||
|
unsigned memsize_mb;
|
||||||
|
uintptr_t* mem;
|
||||||
|
volatile uintptr_t* dev_vaddr;
|
||||||
|
|
||||||
|
const static uintptr_t dev_paddr = 0x40000000;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // __HTIF_ZEDBOARD_H
|
Loading…
Reference in New Issue