Add files using upload-large-folder tool
Browse files- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/context.cc +115 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/device.cc +155 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/dtm.h +115 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/dummy.cc +4 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/elfloader.cc +89 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/encoding.h +0 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/fesvr.pc.in +26 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/htif.h +114 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/htif_hexwriter.cc +76 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/htif_hexwriter.h +32 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/htif_pthread.cc +66 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/htif_pthread.h +38 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/memif.cc +183 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/memif.h +62 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/rfb.h +53 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/syscall.cc +394 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/term.cc +53 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/tsi.cc +115 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/tsi.h +57 -0
- snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/tests/testlib.py +116 -0
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/context.cc
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "context.h"
|
| 2 |
+
#include <assert.h>
|
| 3 |
+
#include <sched.h>
|
| 4 |
+
#include <stdlib.h>
|
| 5 |
+
|
| 6 |
+
static __thread context_t* cur;
|
| 7 |
+
|
| 8 |
+
context_t::context_t()
|
| 9 |
+
: creator(NULL), func(NULL), arg(NULL),
|
| 10 |
+
#ifndef USE_UCONTEXT
|
| 11 |
+
mutex(PTHREAD_MUTEX_INITIALIZER),
|
| 12 |
+
cond(PTHREAD_COND_INITIALIZER), flag(0)
|
| 13 |
+
#else
|
| 14 |
+
context(new ucontext_t)
|
| 15 |
+
#endif
|
| 16 |
+
{
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
#ifdef USE_UCONTEXT
|
| 20 |
+
#ifndef GLIBC_64BIT_PTR_BUG
|
| 21 |
+
void context_t::wrapper(context_t* ctx)
|
| 22 |
+
{
|
| 23 |
+
#else
|
| 24 |
+
void context_t::wrapper(unsigned int hi, unsigned int lo)
|
| 25 |
+
{
|
| 26 |
+
context_t* ctx = reinterpret_cast<context_t*>(static_cast<unsigned long>(lo) | (static_cast<unsigned long>(hi) << 32));
|
| 27 |
+
#endif
|
| 28 |
+
ctx->creator->switch_to();
|
| 29 |
+
ctx->func(ctx->arg);
|
| 30 |
+
}
|
| 31 |
+
#else
|
| 32 |
+
void* context_t::wrapper(void* a)
|
| 33 |
+
{
|
| 34 |
+
context_t* ctx = static_cast<context_t*>(a);
|
| 35 |
+
cur = ctx;
|
| 36 |
+
ctx->creator->switch_to();
|
| 37 |
+
|
| 38 |
+
ctx->func(ctx->arg);
|
| 39 |
+
return NULL;
|
| 40 |
+
}
|
| 41 |
+
#endif
|
| 42 |
+
|
| 43 |
+
void context_t::init(void (*f)(void*), void* a)
|
| 44 |
+
{
|
| 45 |
+
func = f;
|
| 46 |
+
arg = a;
|
| 47 |
+
creator = current();
|
| 48 |
+
|
| 49 |
+
#ifdef USE_UCONTEXT
|
| 50 |
+
getcontext(context.get());
|
| 51 |
+
context->uc_link = creator->context.get();
|
| 52 |
+
context->uc_stack.ss_size = 64*1024;
|
| 53 |
+
context->uc_stack.ss_sp = new void*[context->uc_stack.ss_size/sizeof(void*)];
|
| 54 |
+
#ifndef GLIBC_64BIT_PTR_BUG
|
| 55 |
+
makecontext(context.get(), (void(*)(void))&context_t::wrapper, 1, this);
|
| 56 |
+
#else
|
| 57 |
+
unsigned int hi(reinterpret_cast<unsigned long>(this) >> 32);
|
| 58 |
+
unsigned int lo(reinterpret_cast<unsigned long>(this));
|
| 59 |
+
makecontext(context.get(), (void(*)(void))&context_t::wrapper, 2, hi, lo);
|
| 60 |
+
#endif
|
| 61 |
+
switch_to();
|
| 62 |
+
#else
|
| 63 |
+
assert(flag == 0);
|
| 64 |
+
|
| 65 |
+
pthread_mutex_lock(&creator->mutex);
|
| 66 |
+
creator->flag = 0;
|
| 67 |
+
if (pthread_create(&thread, NULL, &context_t::wrapper, this) != 0)
|
| 68 |
+
abort();
|
| 69 |
+
pthread_detach(thread);
|
| 70 |
+
while (!creator->flag)
|
| 71 |
+
pthread_cond_wait(&creator->cond, &creator->mutex);
|
| 72 |
+
pthread_mutex_unlock(&creator->mutex);
|
| 73 |
+
#endif
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
context_t::~context_t()
|
| 77 |
+
{
|
| 78 |
+
assert(this != cur);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
void context_t::switch_to()
|
| 82 |
+
{
|
| 83 |
+
assert(this != cur);
|
| 84 |
+
#ifdef USE_UCONTEXT
|
| 85 |
+
context_t* prev = cur;
|
| 86 |
+
cur = this;
|
| 87 |
+
if (swapcontext(prev->context.get(), context.get()) != 0)
|
| 88 |
+
abort();
|
| 89 |
+
#else
|
| 90 |
+
cur->flag = 0;
|
| 91 |
+
this->flag = 1;
|
| 92 |
+
pthread_mutex_lock(&this->mutex);
|
| 93 |
+
pthread_cond_signal(&this->cond);
|
| 94 |
+
pthread_mutex_unlock(&this->mutex);
|
| 95 |
+
pthread_mutex_lock(&cur->mutex);
|
| 96 |
+
while (!cur->flag)
|
| 97 |
+
pthread_cond_wait(&cur->cond, &cur->mutex);
|
| 98 |
+
pthread_mutex_unlock(&cur->mutex);
|
| 99 |
+
#endif
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
context_t* context_t::current()
|
| 103 |
+
{
|
| 104 |
+
if (cur == NULL)
|
| 105 |
+
{
|
| 106 |
+
cur = new context_t;
|
| 107 |
+
#ifdef USE_UCONTEXT
|
| 108 |
+
getcontext(cur->context.get());
|
| 109 |
+
#else
|
| 110 |
+
cur->thread = pthread_self();
|
| 111 |
+
cur->flag = 1;
|
| 112 |
+
#endif
|
| 113 |
+
}
|
| 114 |
+
return cur;
|
| 115 |
+
}
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/device.cc
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "device.h"
|
| 2 |
+
#include "term.h"
|
| 3 |
+
#include "memif.h"
|
| 4 |
+
#include <cassert>
|
| 5 |
+
#include <algorithm>
|
| 6 |
+
#include <climits>
|
| 7 |
+
#include <iostream>
|
| 8 |
+
#include <thread>
|
| 9 |
+
#include <fcntl.h>
|
| 10 |
+
#include <unistd.h>
|
| 11 |
+
#include <sys/stat.h>
|
| 12 |
+
using namespace std::placeholders;
|
| 13 |
+
|
| 14 |
+
device_t::device_t()
|
| 15 |
+
: command_handlers(command_t::MAX_COMMANDS),
|
| 16 |
+
command_names(command_t::MAX_COMMANDS)
|
| 17 |
+
{
|
| 18 |
+
for (size_t cmd = 0; cmd < command_t::MAX_COMMANDS; cmd++)
|
| 19 |
+
register_command(cmd, std::bind(&device_t::handle_null_command, this, _1), "");
|
| 20 |
+
register_command(command_t::MAX_COMMANDS-1, std::bind(&device_t::handle_identify, this, _1), "identity");
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
void device_t::register_command(size_t cmd, command_func_t handler, const char* name)
|
| 24 |
+
{
|
| 25 |
+
assert(cmd < command_t::MAX_COMMANDS);
|
| 26 |
+
assert(strlen(name) < IDENTITY_SIZE);
|
| 27 |
+
command_handlers[cmd] = handler;
|
| 28 |
+
command_names[cmd] = name;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
void device_t::handle_command(command_t cmd)
|
| 32 |
+
{
|
| 33 |
+
command_handlers[cmd.cmd()](cmd);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
void device_t::handle_null_command(command_t cmd)
|
| 37 |
+
{
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
void device_t::handle_identify(command_t cmd)
|
| 41 |
+
{
|
| 42 |
+
size_t what = cmd.payload() % command_t::MAX_COMMANDS;
|
| 43 |
+
uint64_t addr = cmd.payload() / command_t::MAX_COMMANDS;
|
| 44 |
+
assert(addr % IDENTITY_SIZE == 0);
|
| 45 |
+
|
| 46 |
+
char id[IDENTITY_SIZE] = {0};
|
| 47 |
+
if (what == command_t::MAX_COMMANDS-1)
|
| 48 |
+
{
|
| 49 |
+
assert(strlen(identity()) < IDENTITY_SIZE);
|
| 50 |
+
strcpy(id, identity());
|
| 51 |
+
}
|
| 52 |
+
else
|
| 53 |
+
strcpy(id, command_names[what].c_str());
|
| 54 |
+
|
| 55 |
+
cmd.memif().write(addr, IDENTITY_SIZE, id);
|
| 56 |
+
cmd.respond(1);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
bcd_t::bcd_t()
|
| 60 |
+
{
|
| 61 |
+
register_command(0, std::bind(&bcd_t::handle_read, this, _1), "read");
|
| 62 |
+
register_command(1, std::bind(&bcd_t::handle_write, this, _1), "write");
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
void bcd_t::handle_read(command_t cmd)
|
| 66 |
+
{
|
| 67 |
+
pending_reads.push(cmd);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
void bcd_t::handle_write(command_t cmd)
|
| 71 |
+
{
|
| 72 |
+
canonical_terminal_t::write(cmd.payload());
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
void bcd_t::tick()
|
| 76 |
+
{
|
| 77 |
+
int ch;
|
| 78 |
+
if (!pending_reads.empty() && (ch = canonical_terminal_t::read()) != -1)
|
| 79 |
+
{
|
| 80 |
+
pending_reads.front().respond(0x100 | ch);
|
| 81 |
+
pending_reads.pop();
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
disk_t::disk_t(const char* fn)
|
| 86 |
+
{
|
| 87 |
+
fd = ::open(fn, O_RDWR);
|
| 88 |
+
if (fd < 0)
|
| 89 |
+
throw std::runtime_error("could not open " + std::string(fn));
|
| 90 |
+
|
| 91 |
+
register_command(0, std::bind(&disk_t::handle_read, this, _1), "read");
|
| 92 |
+
register_command(1, std::bind(&disk_t::handle_write, this, _1), "write");
|
| 93 |
+
|
| 94 |
+
struct stat st;
|
| 95 |
+
if (fstat(fd, &st) < 0)
|
| 96 |
+
throw std::runtime_error("could not stat " + std::string(fn));
|
| 97 |
+
|
| 98 |
+
size = st.st_size;
|
| 99 |
+
id = "disk size=" + std::to_string(size);
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
disk_t::~disk_t()
|
| 103 |
+
{
|
| 104 |
+
close(fd);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
void disk_t::handle_read(command_t cmd)
|
| 108 |
+
{
|
| 109 |
+
request_t req;
|
| 110 |
+
cmd.memif().read(cmd.payload(), sizeof(req), &req);
|
| 111 |
+
|
| 112 |
+
std::vector<uint8_t> buf(req.size);
|
| 113 |
+
if ((size_t)::pread(fd, &buf[0], buf.size(), req.offset) != req.size)
|
| 114 |
+
throw std::runtime_error("could not read " + id + " @ " + std::to_string(req.offset));
|
| 115 |
+
|
| 116 |
+
cmd.memif().write(req.addr, buf.size(), &buf[0]);
|
| 117 |
+
cmd.respond(req.tag);
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
void disk_t::handle_write(command_t cmd)
|
| 121 |
+
{
|
| 122 |
+
request_t req;
|
| 123 |
+
cmd.memif().read(cmd.payload(), sizeof(req), &req);
|
| 124 |
+
|
| 125 |
+
std::vector<uint8_t> buf(req.size);
|
| 126 |
+
cmd.memif().read(req.addr, buf.size(), &buf[0]);
|
| 127 |
+
|
| 128 |
+
if ((size_t)::pwrite(fd, &buf[0], buf.size(), req.offset) != req.size)
|
| 129 |
+
throw std::runtime_error("could not write " + id + " @ " + std::to_string(req.offset));
|
| 130 |
+
|
| 131 |
+
cmd.respond(req.tag);
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
device_list_t::device_list_t()
|
| 135 |
+
: devices(command_t::MAX_COMMANDS, &null_device), num_devices(0)
|
| 136 |
+
{
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
void device_list_t::register_device(device_t* dev)
|
| 140 |
+
{
|
| 141 |
+
num_devices++;
|
| 142 |
+
assert(num_devices < command_t::MAX_DEVICES);
|
| 143 |
+
devices[num_devices-1] = dev;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
void device_list_t::handle_command(command_t cmd)
|
| 147 |
+
{
|
| 148 |
+
devices[cmd.device()]->handle_command(cmd);
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
void device_list_t::tick()
|
| 152 |
+
{
|
| 153 |
+
for (size_t i = 0; i < num_devices; i++)
|
| 154 |
+
devices[i]->tick();
|
| 155 |
+
}
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/dtm.h
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef _ROCKET_DTM_H
|
| 2 |
+
#define _ROCKET_DTM_H
|
| 3 |
+
|
| 4 |
+
#include "htif.h"
|
| 5 |
+
#include "context.h"
|
| 6 |
+
#include <stdint.h>
|
| 7 |
+
#include <queue>
|
| 8 |
+
#include <semaphore.h>
|
| 9 |
+
#include <vector>
|
| 10 |
+
#include <string>
|
| 11 |
+
#include <stdlib.h>
|
| 12 |
+
|
| 13 |
+
// abstract debug transport module
|
| 14 |
+
class dtm_t : public htif_t
|
| 15 |
+
{
|
| 16 |
+
public:
|
| 17 |
+
dtm_t(int argc, char**argv);
|
| 18 |
+
~dtm_t();
|
| 19 |
+
|
| 20 |
+
struct req {
|
| 21 |
+
uint32_t addr;
|
| 22 |
+
uint32_t op;
|
| 23 |
+
uint32_t data;
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
struct resp {
|
| 27 |
+
uint32_t resp;
|
| 28 |
+
uint32_t data;
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
void tick(
|
| 32 |
+
bool req_ready,
|
| 33 |
+
bool resp_valid,
|
| 34 |
+
resp resp_bits
|
| 35 |
+
);
|
| 36 |
+
// Akin to tick, but the target thread returns a response on every invocation
|
| 37 |
+
void return_resp(
|
| 38 |
+
resp resp_bits
|
| 39 |
+
);
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
bool req_valid() { return req_wait; }
|
| 43 |
+
req req_bits() { return req_buf; }
|
| 44 |
+
bool resp_ready() { return true; }
|
| 45 |
+
|
| 46 |
+
uint32_t read(uint32_t addr);
|
| 47 |
+
uint32_t write(uint32_t addr, uint32_t data);
|
| 48 |
+
void nop();
|
| 49 |
+
|
| 50 |
+
uint64_t read_csr(unsigned which);
|
| 51 |
+
uint64_t write_csr(unsigned which, uint64_t data);
|
| 52 |
+
uint64_t clear_csr(unsigned which, uint64_t data);
|
| 53 |
+
uint64_t set_csr(unsigned which, uint64_t data);
|
| 54 |
+
void fence_i();
|
| 55 |
+
|
| 56 |
+
void producer_thread();
|
| 57 |
+
|
| 58 |
+
protected:
|
| 59 |
+
virtual void read_chunk(addr_t taddr, size_t len, void* dst) override;
|
| 60 |
+
virtual void write_chunk(addr_t taddr, size_t len, const void* src) override;
|
| 61 |
+
virtual void clear_chunk(addr_t taddr, size_t len) override;
|
| 62 |
+
virtual size_t chunk_align() override;
|
| 63 |
+
virtual size_t chunk_max_size() override;
|
| 64 |
+
virtual void reset() override;
|
| 65 |
+
virtual void idle() override;
|
| 66 |
+
|
| 67 |
+
private:
|
| 68 |
+
context_t host;
|
| 69 |
+
context_t* target;
|
| 70 |
+
pthread_t producer;
|
| 71 |
+
sem_t req_produce;
|
| 72 |
+
sem_t req_consume;
|
| 73 |
+
sem_t resp_produce;
|
| 74 |
+
sem_t resp_consume;
|
| 75 |
+
req req_buf;
|
| 76 |
+
resp resp_buf;
|
| 77 |
+
bool running;
|
| 78 |
+
|
| 79 |
+
uint32_t run_abstract_command(uint32_t command, const uint32_t program[], size_t program_n,
|
| 80 |
+
uint32_t data[], size_t data_n);
|
| 81 |
+
|
| 82 |
+
void die(uint32_t cmderr);
|
| 83 |
+
void halt(int);
|
| 84 |
+
int enumerate_harts();
|
| 85 |
+
void select_hart(int);
|
| 86 |
+
void resume(int);
|
| 87 |
+
uint64_t save_reg(unsigned regno);
|
| 88 |
+
void restore_reg(unsigned regno, uint64_t val);
|
| 89 |
+
|
| 90 |
+
uint64_t modify_csr(unsigned which, uint64_t data, uint32_t type);
|
| 91 |
+
|
| 92 |
+
bool req_wait;
|
| 93 |
+
bool resp_wait;
|
| 94 |
+
uint32_t data_base;
|
| 95 |
+
|
| 96 |
+
uint32_t xlen;
|
| 97 |
+
|
| 98 |
+
static const int max_idle_cycles = 10000;
|
| 99 |
+
|
| 100 |
+
size_t ram_words;
|
| 101 |
+
size_t data_words;
|
| 102 |
+
int num_harts;
|
| 103 |
+
int current_hart;
|
| 104 |
+
|
| 105 |
+
uint32_t get_xlen();
|
| 106 |
+
uint32_t do_command(dtm_t::req r);
|
| 107 |
+
|
| 108 |
+
void parse_args(const std::vector<std::string>& args);
|
| 109 |
+
void register_devices();
|
| 110 |
+
void start_host_thread();
|
| 111 |
+
|
| 112 |
+
friend class memif_t;
|
| 113 |
+
};
|
| 114 |
+
|
| 115 |
+
#endif
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/dummy.cc
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// See LICENSE for license details.
|
| 2 |
+
|
| 3 |
+
// help out poor, C-centric autoconf
|
| 4 |
+
extern "C" void libfesvr_is_present() {}
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/elfloader.cc
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// See LICENSE for license details.
|
| 2 |
+
|
| 3 |
+
#include "elf.h"
|
| 4 |
+
#include "memif.h"
|
| 5 |
+
#include <cstring>
|
| 6 |
+
#include <string>
|
| 7 |
+
#include <sys/stat.h>
|
| 8 |
+
#include <fcntl.h>
|
| 9 |
+
#include <sys/mman.h>
|
| 10 |
+
#include <assert.h>
|
| 11 |
+
#include <unistd.h>
|
| 12 |
+
#include <stdlib.h>
|
| 13 |
+
#include <stdio.h>
|
| 14 |
+
#include <vector>
|
| 15 |
+
#include <map>
|
| 16 |
+
|
| 17 |
+
std::map<std::string, uint64_t> load_elf(const char* fn, memif_t* memif, reg_t* entry)
|
| 18 |
+
{
|
| 19 |
+
int fd = open(fn, O_RDONLY);
|
| 20 |
+
struct stat s;
|
| 21 |
+
assert(fd != -1);
|
| 22 |
+
if (fstat(fd, &s) < 0)
|
| 23 |
+
abort();
|
| 24 |
+
size_t size = s.st_size;
|
| 25 |
+
|
| 26 |
+
char* buf = (char*)mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
|
| 27 |
+
assert(buf != MAP_FAILED);
|
| 28 |
+
close(fd);
|
| 29 |
+
|
| 30 |
+
assert(size >= sizeof(Elf64_Ehdr));
|
| 31 |
+
const Elf64_Ehdr* eh64 = (const Elf64_Ehdr*)buf;
|
| 32 |
+
assert(IS_ELF32(*eh64) || IS_ELF64(*eh64));
|
| 33 |
+
|
| 34 |
+
std::vector<uint8_t> zeros;
|
| 35 |
+
std::map<std::string, uint64_t> symbols;
|
| 36 |
+
|
| 37 |
+
#define LOAD_ELF(ehdr_t, phdr_t, shdr_t, sym_t) do { \
|
| 38 |
+
ehdr_t* eh = (ehdr_t*)buf; \
|
| 39 |
+
phdr_t* ph = (phdr_t*)(buf + eh->e_phoff); \
|
| 40 |
+
*entry = eh->e_entry; \
|
| 41 |
+
assert(size >= eh->e_phoff + eh->e_phnum*sizeof(*ph)); \
|
| 42 |
+
for (unsigned i = 0; i < eh->e_phnum; i++) { \
|
| 43 |
+
if(ph[i].p_type == PT_LOAD && ph[i].p_memsz) { \
|
| 44 |
+
if (ph[i].p_filesz) { \
|
| 45 |
+
assert(size >= ph[i].p_offset + ph[i].p_filesz); \
|
| 46 |
+
memif->write(ph[i].p_paddr, ph[i].p_filesz, (uint8_t*)buf + ph[i].p_offset); \
|
| 47 |
+
} \
|
| 48 |
+
zeros.resize(ph[i].p_memsz - ph[i].p_filesz); \
|
| 49 |
+
memif->write(ph[i].p_paddr + ph[i].p_filesz, ph[i].p_memsz - ph[i].p_filesz, &zeros[0]); \
|
| 50 |
+
} \
|
| 51 |
+
} \
|
| 52 |
+
shdr_t* sh = (shdr_t*)(buf + eh->e_shoff); \
|
| 53 |
+
assert(size >= eh->e_shoff + eh->e_shnum*sizeof(*sh)); \
|
| 54 |
+
assert(eh->e_shstrndx < eh->e_shnum); \
|
| 55 |
+
assert(size >= sh[eh->e_shstrndx].sh_offset + sh[eh->e_shstrndx].sh_size); \
|
| 56 |
+
char *shstrtab = buf + sh[eh->e_shstrndx].sh_offset; \
|
| 57 |
+
unsigned strtabidx = 0, symtabidx = 0; \
|
| 58 |
+
for (unsigned i = 0; i < eh->e_shnum; i++) { \
|
| 59 |
+
unsigned max_len = sh[eh->e_shstrndx].sh_size - sh[i].sh_name; \
|
| 60 |
+
assert(sh[i].sh_name < sh[eh->e_shstrndx].sh_size); \
|
| 61 |
+
assert(strnlen(shstrtab + sh[i].sh_name, max_len) < max_len); \
|
| 62 |
+
if (sh[i].sh_type & SHT_NOBITS) continue; \
|
| 63 |
+
assert(size >= sh[i].sh_offset + sh[i].sh_size); \
|
| 64 |
+
if (strcmp(shstrtab + sh[i].sh_name, ".strtab") == 0) \
|
| 65 |
+
strtabidx = i; \
|
| 66 |
+
if (strcmp(shstrtab + sh[i].sh_name, ".symtab") == 0) \
|
| 67 |
+
symtabidx = i; \
|
| 68 |
+
} \
|
| 69 |
+
if (strtabidx && symtabidx) { \
|
| 70 |
+
char* strtab = buf + sh[strtabidx].sh_offset; \
|
| 71 |
+
sym_t* sym = (sym_t*)(buf + sh[symtabidx].sh_offset); \
|
| 72 |
+
for (unsigned i = 0; i < sh[symtabidx].sh_size/sizeof(sym_t); i++) { \
|
| 73 |
+
unsigned max_len = sh[strtabidx].sh_size - sym[i].st_name; \
|
| 74 |
+
assert(sym[i].st_name < sh[strtabidx].sh_size); \
|
| 75 |
+
assert(strnlen(strtab + sym[i].st_name, max_len) < max_len); \
|
| 76 |
+
symbols[strtab + sym[i].st_name] = sym[i].st_value; \
|
| 77 |
+
} \
|
| 78 |
+
} \
|
| 79 |
+
} while(0)
|
| 80 |
+
|
| 81 |
+
if (IS_ELF32(*eh64))
|
| 82 |
+
LOAD_ELF(Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Sym);
|
| 83 |
+
else
|
| 84 |
+
LOAD_ELF(Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Sym);
|
| 85 |
+
|
| 86 |
+
munmap(buf, size);
|
| 87 |
+
|
| 88 |
+
return symbols;
|
| 89 |
+
}
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/encoding.h
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/fesvr.pc.in
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#=========================================================================
|
| 2 |
+
# Modular C++ Build System Subproject Package Config
|
| 3 |
+
#=========================================================================
|
| 4 |
+
# Please read the documenation in 'mcppbs-uguide.txt' for more details
|
| 5 |
+
# on how the Modular C++ Build System works.
|
| 6 |
+
|
| 7 |
+
#-------------------------------------------------------------------------
|
| 8 |
+
# Generic variables
|
| 9 |
+
#-------------------------------------------------------------------------
|
| 10 |
+
|
| 11 |
+
prefix=@prefix@
|
| 12 |
+
include_dir=${prefix}/include/fesvr
|
| 13 |
+
lib_dir=${prefix}/lib
|
| 14 |
+
|
| 15 |
+
#-------------------------------------------------------------------------
|
| 16 |
+
# Keywords
|
| 17 |
+
#-------------------------------------------------------------------------
|
| 18 |
+
|
| 19 |
+
Name : fesvr
|
| 20 |
+
Version : @PACKAGE_VERSION@
|
| 21 |
+
Description : Frontend Server C/C++ API
|
| 22 |
+
Requires : @fesvr_pkcdeps@
|
| 23 |
+
Cflags : -I${include_dir} @CPPFLAGS@ @fesvr_extra_cppflags@
|
| 24 |
+
Libs : -L${lib_dir} @LDFLAGS@ @fesvr_extra_ldflags@ \
|
| 25 |
+
-lfesvr @fesvr_extra_libs@
|
| 26 |
+
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/htif.h
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// See LICENSE for license details.
|
| 2 |
+
|
| 3 |
+
#ifndef __HTIF_H
|
| 4 |
+
#define __HTIF_H
|
| 5 |
+
|
| 6 |
+
#include "memif.h"
|
| 7 |
+
#include "syscall.h"
|
| 8 |
+
#include "device.h"
|
| 9 |
+
#include <string.h>
|
| 10 |
+
#include <vector>
|
| 11 |
+
|
| 12 |
+
class htif_t : public chunked_memif_t
|
| 13 |
+
{
|
| 14 |
+
public:
|
| 15 |
+
htif_t();
|
| 16 |
+
htif_t(int argc, char** argv);
|
| 17 |
+
htif_t(const std::vector<std::string>& args);
|
| 18 |
+
virtual ~htif_t();
|
| 19 |
+
|
| 20 |
+
virtual void start();
|
| 21 |
+
virtual void stop();
|
| 22 |
+
|
| 23 |
+
int run();
|
| 24 |
+
bool done();
|
| 25 |
+
int exit_code();
|
| 26 |
+
|
| 27 |
+
virtual memif_t& memif() { return mem; }
|
| 28 |
+
|
| 29 |
+
protected:
|
| 30 |
+
virtual void reset() = 0;
|
| 31 |
+
|
| 32 |
+
virtual void read_chunk(addr_t taddr, size_t len, void* dst) = 0;
|
| 33 |
+
virtual void write_chunk(addr_t taddr, size_t len, const void* src) = 0;
|
| 34 |
+
virtual void clear_chunk(addr_t taddr, size_t len);
|
| 35 |
+
|
| 36 |
+
virtual size_t chunk_align() = 0;
|
| 37 |
+
virtual size_t chunk_max_size() = 0;
|
| 38 |
+
|
| 39 |
+
virtual void load_program();
|
| 40 |
+
virtual void idle() {}
|
| 41 |
+
|
| 42 |
+
const std::vector<std::string>& host_args() { return hargs; }
|
| 43 |
+
|
| 44 |
+
reg_t get_entry_point() { return entry; }
|
| 45 |
+
|
| 46 |
+
// indicates that the initial program load can skip writing this address
|
| 47 |
+
// range to memory, because it has already been loaded through a sideband
|
| 48 |
+
virtual bool is_address_preloaded(addr_t taddr, size_t len) { return false; }
|
| 49 |
+
|
| 50 |
+
private:
|
| 51 |
+
void parse_arguments(int argc, char ** argv);
|
| 52 |
+
void register_devices();
|
| 53 |
+
void usage(const char * program_name);
|
| 54 |
+
|
| 55 |
+
memif_t mem;
|
| 56 |
+
reg_t entry;
|
| 57 |
+
bool writezeros;
|
| 58 |
+
std::vector<std::string> hargs;
|
| 59 |
+
std::vector<std::string> targs;
|
| 60 |
+
std::string sig_file;
|
| 61 |
+
addr_t sig_addr; // torture
|
| 62 |
+
addr_t sig_len; // torture
|
| 63 |
+
addr_t tohost_addr;
|
| 64 |
+
addr_t fromhost_addr;
|
| 65 |
+
int exitcode;
|
| 66 |
+
bool stopped;
|
| 67 |
+
|
| 68 |
+
device_list_t device_list;
|
| 69 |
+
syscall_t syscall_proxy;
|
| 70 |
+
bcd_t bcd;
|
| 71 |
+
std::vector<device_t*> dynamic_devices;
|
| 72 |
+
|
| 73 |
+
const std::vector<std::string>& target_args() { return targs; }
|
| 74 |
+
|
| 75 |
+
friend class memif_t;
|
| 76 |
+
friend class syscall_t;
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
/* Alignment guide for emulator.cc options:
|
| 80 |
+
-x, --long-option Description with max 80 characters --------------->\n\
|
| 81 |
+
+plus-arg-equivalent\n\
|
| 82 |
+
*/
|
| 83 |
+
#define HTIF_USAGE_OPTIONS \
|
| 84 |
+
"HOST OPTIONS\n\
|
| 85 |
+
-h, --help Display this help and exit\n\
|
| 86 |
+
+permissive The host will ignore any unparsed options up until\n\
|
| 87 |
+
+permissive-off (Only needed for VCS)\n\
|
| 88 |
+
+permissive-off Stop ignoring options. This is mandatory if using\n\
|
| 89 |
+
+permissive (Only needed for VCS)\n\
|
| 90 |
+
--rfb=DISPLAY Add new remote frame buffer on display DISPLAY\n\
|
| 91 |
+
+rfb=DISPLAY to be accessible on 5900 + DISPLAY (default = 0)\n\
|
| 92 |
+
--signature=FILE Write torture test signature to FILE\n\
|
| 93 |
+
+signature=FILE\n\
|
| 94 |
+
--chroot=PATH Use PATH as location of syscall-servicing binaries\n\
|
| 95 |
+
+chroot=PATH\n\
|
| 96 |
+
\n\
|
| 97 |
+
HOST OPTIONS (currently unsupported)\n\
|
| 98 |
+
--disk=DISK Add DISK device. Use a ramdisk since this isn't\n\
|
| 99 |
+
+disk=DISK supported\n\
|
| 100 |
+
\n\
|
| 101 |
+
TARGET (RISC-V BINARY) OPTIONS\n\
|
| 102 |
+
These are the options passed to the program executing on the emulated RISC-V\n\
|
| 103 |
+
microprocessor.\n"
|
| 104 |
+
|
| 105 |
+
#define HTIF_LONG_OPTIONS_OPTIND 1024
|
| 106 |
+
#define HTIF_LONG_OPTIONS \
|
| 107 |
+
{"help", no_argument, 0, 'h' }, \
|
| 108 |
+
{"rfb", optional_argument, 0, HTIF_LONG_OPTIONS_OPTIND }, \
|
| 109 |
+
{"disk", required_argument, 0, HTIF_LONG_OPTIONS_OPTIND + 1 }, \
|
| 110 |
+
{"signature", required_argument, 0, HTIF_LONG_OPTIONS_OPTIND + 2 }, \
|
| 111 |
+
{"chroot", required_argument, 0, HTIF_LONG_OPTIONS_OPTIND + 3 }, \
|
| 112 |
+
{0, 0, 0, 0}
|
| 113 |
+
|
| 114 |
+
#endif // __HTIF_H
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/htif_hexwriter.cc
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// See LICENSE for license details.
|
| 2 |
+
|
| 3 |
+
#include <iostream>
|
| 4 |
+
#include <assert.h>
|
| 5 |
+
#include "htif_hexwriter.h"
|
| 6 |
+
|
| 7 |
+
htif_hexwriter_t::htif_hexwriter_t(size_t b, size_t w, size_t d)
|
| 8 |
+
: base(b), width(w), depth(d)
|
| 9 |
+
{
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
void htif_hexwriter_t::read_chunk(addr_t taddr, size_t len, void* vdst)
|
| 13 |
+
{
|
| 14 |
+
taddr -= base;
|
| 15 |
+
|
| 16 |
+
assert(len % chunk_align() == 0);
|
| 17 |
+
assert(taddr < width*depth);
|
| 18 |
+
assert(taddr+len <= width*depth);
|
| 19 |
+
|
| 20 |
+
uint8_t* dst = (uint8_t*)vdst;
|
| 21 |
+
while(len)
|
| 22 |
+
{
|
| 23 |
+
if(mem[taddr/width].size() == 0)
|
| 24 |
+
mem[taddr/width].resize(width,0);
|
| 25 |
+
|
| 26 |
+
for(size_t j = 0; j < width; j++)
|
| 27 |
+
dst[j] = mem[taddr/width][j];
|
| 28 |
+
|
| 29 |
+
len -= width;
|
| 30 |
+
taddr += width;
|
| 31 |
+
dst += width;
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
void htif_hexwriter_t::write_chunk(addr_t taddr, size_t len, const void* vsrc)
|
| 36 |
+
{
|
| 37 |
+
taddr -= base;
|
| 38 |
+
|
| 39 |
+
assert(len % chunk_align() == 0);
|
| 40 |
+
assert(taddr < width*depth);
|
| 41 |
+
assert(taddr+len <= width*depth);
|
| 42 |
+
|
| 43 |
+
const uint8_t* src = (const uint8_t*)vsrc;
|
| 44 |
+
while(len)
|
| 45 |
+
{
|
| 46 |
+
if(mem[taddr/width].size() == 0)
|
| 47 |
+
mem[taddr/width].resize(width,0);
|
| 48 |
+
|
| 49 |
+
for(size_t j = 0; j < width; j++)
|
| 50 |
+
mem[taddr/width][j] = src[j];
|
| 51 |
+
|
| 52 |
+
len -= width;
|
| 53 |
+
taddr += width;
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
std::ostream& operator<< (std::ostream& o, const htif_hexwriter_t& h)
|
| 58 |
+
{
|
| 59 |
+
std::ios_base::fmtflags flags = o.setf(std::ios::hex,std::ios::basefield);
|
| 60 |
+
|
| 61 |
+
for(size_t addr = 0; addr < h.depth; addr++)
|
| 62 |
+
{
|
| 63 |
+
std::map<addr_t,std::vector<char> >::const_iterator i = h.mem.find(addr);
|
| 64 |
+
if(i == h.mem.end())
|
| 65 |
+
for(size_t j = 0; j < h.width; j++)
|
| 66 |
+
o << "00";
|
| 67 |
+
else
|
| 68 |
+
for(size_t j = 0; j < h.width; j++)
|
| 69 |
+
o << ((i->second[h.width-j-1] >> 4) & 0xF) << (i->second[h.width-j-1] & 0xF);
|
| 70 |
+
o << std::endl;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
o.setf(flags);
|
| 74 |
+
|
| 75 |
+
return o;
|
| 76 |
+
}
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/htif_hexwriter.h
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// See LICENSE for license details.
|
| 2 |
+
|
| 3 |
+
#ifndef __HTIF_HEXWRITER_H
|
| 4 |
+
#define __HTIF_HEXWRITER_H
|
| 5 |
+
|
| 6 |
+
#include <map>
|
| 7 |
+
#include <vector>
|
| 8 |
+
#include <stdlib.h>
|
| 9 |
+
#include "memif.h"
|
| 10 |
+
|
| 11 |
+
class htif_hexwriter_t : public chunked_memif_t
|
| 12 |
+
{
|
| 13 |
+
public:
|
| 14 |
+
htif_hexwriter_t(size_t b, size_t w, size_t d);
|
| 15 |
+
|
| 16 |
+
protected:
|
| 17 |
+
size_t base;
|
| 18 |
+
size_t width;
|
| 19 |
+
size_t depth;
|
| 20 |
+
std::map<addr_t,std::vector<char> > mem;
|
| 21 |
+
|
| 22 |
+
void read_chunk(addr_t taddr, size_t len, void* dst);
|
| 23 |
+
void write_chunk(addr_t taddr, size_t len, const void* src);
|
| 24 |
+
void clear_chunk(addr_t taddr, size_t len) {}
|
| 25 |
+
|
| 26 |
+
size_t chunk_max_size() { return width; }
|
| 27 |
+
size_t chunk_align() { return width; }
|
| 28 |
+
|
| 29 |
+
friend std::ostream& operator<< (std::ostream&, const htif_hexwriter_t&);
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
#endif // __HTIF_HEXWRITER_H
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/htif_pthread.cc
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// See LICENSE for license details.
|
| 2 |
+
|
| 3 |
+
#include "htif_pthread.h"
|
| 4 |
+
#include <algorithm>
|
| 5 |
+
#include <stdio.h>
|
| 6 |
+
|
| 7 |
+
void htif_pthread_t::thread_main(void* arg)
|
| 8 |
+
{
|
| 9 |
+
htif_pthread_t* htif = static_cast<htif_pthread_t*>(arg);
|
| 10 |
+
htif->run();
|
| 11 |
+
while (true)
|
| 12 |
+
htif->target->switch_to();
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
htif_pthread_t::htif_pthread_t(int argc, char** argv)
|
| 16 |
+
: htif_t(argc, argv)
|
| 17 |
+
{
|
| 18 |
+
target = context_t::current();
|
| 19 |
+
host.init(thread_main, this);
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
htif_pthread_t::~htif_pthread_t()
|
| 23 |
+
{
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
ssize_t htif_pthread_t::read(void* buf, size_t max_size)
|
| 27 |
+
{
|
| 28 |
+
while (th_data.size() == 0)
|
| 29 |
+
target->switch_to();
|
| 30 |
+
|
| 31 |
+
size_t s = std::min(max_size, th_data.size());
|
| 32 |
+
std::copy(th_data.begin(), th_data.begin() + s, (char*)buf);
|
| 33 |
+
th_data.erase(th_data.begin(), th_data.begin() + s);
|
| 34 |
+
|
| 35 |
+
return s;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
ssize_t htif_pthread_t::write(const void* buf, size_t size)
|
| 39 |
+
{
|
| 40 |
+
ht_data.insert(ht_data.end(), (const char*)buf, (const char*)buf + size);
|
| 41 |
+
return size;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
void htif_pthread_t::send(const void* buf, size_t size)
|
| 45 |
+
{
|
| 46 |
+
th_data.insert(th_data.end(), (const char*)buf, (const char*)buf + size);
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
void htif_pthread_t::recv(void* buf, size_t size)
|
| 50 |
+
{
|
| 51 |
+
while (!this->recv_nonblocking(buf, size))
|
| 52 |
+
;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
bool htif_pthread_t::recv_nonblocking(void* buf, size_t size)
|
| 56 |
+
{
|
| 57 |
+
if (ht_data.size() < size)
|
| 58 |
+
{
|
| 59 |
+
host.switch_to();
|
| 60 |
+
return false;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
std::copy(ht_data.begin(), ht_data.begin() + size, (char*)buf);
|
| 64 |
+
ht_data.erase(ht_data.begin(), ht_data.begin() + size);
|
| 65 |
+
return true;
|
| 66 |
+
}
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/htif_pthread.h
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// See LICENSE for license details.
|
| 2 |
+
|
| 3 |
+
#ifndef _HTIF_PTHREAD_H
|
| 4 |
+
#define _HTIF_PTHREAD_H
|
| 5 |
+
|
| 6 |
+
#include "htif.h"
|
| 7 |
+
#include "context.h"
|
| 8 |
+
#include <deque>
|
| 9 |
+
|
| 10 |
+
class htif_pthread_t : public htif_t
|
| 11 |
+
{
|
| 12 |
+
public:
|
| 13 |
+
htif_pthread_t(int argc, char** argv);
|
| 14 |
+
virtual ~htif_pthread_t();
|
| 15 |
+
|
| 16 |
+
// target inteface
|
| 17 |
+
void send(const void* buf, size_t size);
|
| 18 |
+
void recv(void* buf, size_t size);
|
| 19 |
+
bool recv_nonblocking(void* buf, size_t size);
|
| 20 |
+
|
| 21 |
+
protected:
|
| 22 |
+
// host interface
|
| 23 |
+
virtual ssize_t read(void* buf, size_t max_size);
|
| 24 |
+
virtual ssize_t write(const void* buf, size_t size);
|
| 25 |
+
|
| 26 |
+
virtual size_t chunk_align() { return 64; }
|
| 27 |
+
virtual size_t chunk_max_size() { return 1024; }
|
| 28 |
+
|
| 29 |
+
private:
|
| 30 |
+
context_t host;
|
| 31 |
+
context_t* target;
|
| 32 |
+
std::deque<char> th_data;
|
| 33 |
+
std::deque<char> ht_data;
|
| 34 |
+
|
| 35 |
+
static void thread_main(void* htif);
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
#endif
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/memif.cc
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// See LICENSE for license details.
|
| 2 |
+
|
| 3 |
+
#include <algorithm>
|
| 4 |
+
#include <stdlib.h>
|
| 5 |
+
#include <string.h>
|
| 6 |
+
#include <stdexcept>
|
| 7 |
+
#include "memif.h"
|
| 8 |
+
|
| 9 |
+
void memif_t::read(addr_t addr, size_t len, void* bytes)
|
| 10 |
+
{
|
| 11 |
+
size_t align = cmemif->chunk_align();
|
| 12 |
+
if (len && (addr & (align-1)))
|
| 13 |
+
{
|
| 14 |
+
size_t this_len = std::min(len, align - size_t(addr & (align-1)));
|
| 15 |
+
uint8_t chunk[align];
|
| 16 |
+
|
| 17 |
+
cmemif->read_chunk(addr & ~(align-1), align, chunk);
|
| 18 |
+
memcpy(bytes, chunk + (addr & (align-1)), this_len);
|
| 19 |
+
|
| 20 |
+
bytes = (char*)bytes + this_len;
|
| 21 |
+
addr += this_len;
|
| 22 |
+
len -= this_len;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
if (len & (align-1))
|
| 26 |
+
{
|
| 27 |
+
size_t this_len = len & (align-1);
|
| 28 |
+
size_t start = len - this_len;
|
| 29 |
+
uint8_t chunk[align];
|
| 30 |
+
|
| 31 |
+
cmemif->read_chunk(addr + start, align, chunk);
|
| 32 |
+
memcpy((char*)bytes + start, chunk, this_len);
|
| 33 |
+
|
| 34 |
+
len -= this_len;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
// now we're aligned
|
| 38 |
+
for (size_t pos = 0; pos < len; pos += cmemif->chunk_max_size())
|
| 39 |
+
cmemif->read_chunk(addr + pos, std::min(cmemif->chunk_max_size(), len - pos), (char*)bytes + pos);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
void memif_t::write(addr_t addr, size_t len, const void* bytes)
|
| 43 |
+
{
|
| 44 |
+
size_t align = cmemif->chunk_align();
|
| 45 |
+
if (len && (addr & (align-1)))
|
| 46 |
+
{
|
| 47 |
+
size_t this_len = std::min(len, align - size_t(addr & (align-1)));
|
| 48 |
+
uint8_t chunk[align];
|
| 49 |
+
|
| 50 |
+
cmemif->read_chunk(addr & ~(align-1), align, chunk);
|
| 51 |
+
memcpy(chunk + (addr & (align-1)), bytes, this_len);
|
| 52 |
+
cmemif->write_chunk(addr & ~(align-1), align, chunk);
|
| 53 |
+
|
| 54 |
+
bytes = (char*)bytes + this_len;
|
| 55 |
+
addr += this_len;
|
| 56 |
+
len -= this_len;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
if (len & (align-1))
|
| 60 |
+
{
|
| 61 |
+
size_t this_len = len & (align-1);
|
| 62 |
+
size_t start = len - this_len;
|
| 63 |
+
uint8_t chunk[align];
|
| 64 |
+
|
| 65 |
+
cmemif->read_chunk(addr + start, align, chunk);
|
| 66 |
+
memcpy(chunk, (char*)bytes + start, this_len);
|
| 67 |
+
cmemif->write_chunk(addr + start, align, chunk);
|
| 68 |
+
|
| 69 |
+
len -= this_len;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
// now we're aligned
|
| 73 |
+
bool all_zero = len != 0;
|
| 74 |
+
for (size_t i = 0; i < len; i++)
|
| 75 |
+
all_zero &= ((const char*)bytes)[i] == 0;
|
| 76 |
+
|
| 77 |
+
if (all_zero) {
|
| 78 |
+
cmemif->clear_chunk(addr, len);
|
| 79 |
+
} else {
|
| 80 |
+
size_t max_chunk = cmemif->chunk_max_size();
|
| 81 |
+
for (size_t pos = 0; pos < len; pos += max_chunk)
|
| 82 |
+
cmemif->write_chunk(addr + pos, std::min(max_chunk, len - pos), (char*)bytes + pos);
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
#define MEMIF_READ_FUNC \
|
| 87 |
+
if(addr & (sizeof(val)-1)) \
|
| 88 |
+
throw std::runtime_error("misaligned address"); \
|
| 89 |
+
this->read(addr, sizeof(val), &val); \
|
| 90 |
+
return val
|
| 91 |
+
|
| 92 |
+
#define MEMIF_WRITE_FUNC \
|
| 93 |
+
if(addr & (sizeof(val)-1)) \
|
| 94 |
+
throw std::runtime_error("misaligned address"); \
|
| 95 |
+
this->write(addr, sizeof(val), &val)
|
| 96 |
+
|
| 97 |
+
uint8_t memif_t::read_uint8(addr_t addr)
|
| 98 |
+
{
|
| 99 |
+
uint8_t val;
|
| 100 |
+
MEMIF_READ_FUNC;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
int8_t memif_t::read_int8(addr_t addr)
|
| 104 |
+
{
|
| 105 |
+
int8_t val;
|
| 106 |
+
MEMIF_READ_FUNC;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
void memif_t::write_uint8(addr_t addr, uint8_t val)
|
| 110 |
+
{
|
| 111 |
+
MEMIF_WRITE_FUNC;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
void memif_t::write_int8(addr_t addr, int8_t val)
|
| 115 |
+
{
|
| 116 |
+
MEMIF_WRITE_FUNC;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
uint16_t memif_t::read_uint16(addr_t addr)
|
| 120 |
+
{
|
| 121 |
+
uint16_t val;
|
| 122 |
+
MEMIF_READ_FUNC;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
int16_t memif_t::read_int16(addr_t addr)
|
| 126 |
+
{
|
| 127 |
+
int16_t val;
|
| 128 |
+
MEMIF_READ_FUNC;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
void memif_t::write_uint16(addr_t addr, uint16_t val)
|
| 132 |
+
{
|
| 133 |
+
MEMIF_WRITE_FUNC;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
void memif_t::write_int16(addr_t addr, int16_t val)
|
| 137 |
+
{
|
| 138 |
+
MEMIF_WRITE_FUNC;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
uint32_t memif_t::read_uint32(addr_t addr)
|
| 142 |
+
{
|
| 143 |
+
uint32_t val;
|
| 144 |
+
MEMIF_READ_FUNC;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
int32_t memif_t::read_int32(addr_t addr)
|
| 148 |
+
{
|
| 149 |
+
int32_t val;
|
| 150 |
+
MEMIF_READ_FUNC;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
void memif_t::write_uint32(addr_t addr, uint32_t val)
|
| 154 |
+
{
|
| 155 |
+
MEMIF_WRITE_FUNC;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
void memif_t::write_int32(addr_t addr, int32_t val)
|
| 159 |
+
{
|
| 160 |
+
MEMIF_WRITE_FUNC;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
uint64_t memif_t::read_uint64(addr_t addr)
|
| 164 |
+
{
|
| 165 |
+
uint64_t val;
|
| 166 |
+
MEMIF_READ_FUNC;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
int64_t memif_t::read_int64(addr_t addr)
|
| 170 |
+
{
|
| 171 |
+
int64_t val;
|
| 172 |
+
MEMIF_READ_FUNC;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
void memif_t::write_uint64(addr_t addr, uint64_t val)
|
| 176 |
+
{
|
| 177 |
+
MEMIF_WRITE_FUNC;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
void memif_t::write_int64(addr_t addr, int64_t val)
|
| 181 |
+
{
|
| 182 |
+
MEMIF_WRITE_FUNC;
|
| 183 |
+
}
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/memif.h
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// See LICENSE for license details.
|
| 2 |
+
|
| 3 |
+
#ifndef __MEMIF_H
|
| 4 |
+
#define __MEMIF_H
|
| 5 |
+
|
| 6 |
+
#include <stdint.h>
|
| 7 |
+
#include <stddef.h>
|
| 8 |
+
|
| 9 |
+
typedef uint64_t reg_t;
|
| 10 |
+
typedef int64_t sreg_t;
|
| 11 |
+
typedef reg_t addr_t;
|
| 12 |
+
|
| 13 |
+
class chunked_memif_t
|
| 14 |
+
{
|
| 15 |
+
public:
|
| 16 |
+
virtual void read_chunk(addr_t taddr, size_t len, void* dst) = 0;
|
| 17 |
+
virtual void write_chunk(addr_t taddr, size_t len, const void* src) = 0;
|
| 18 |
+
virtual void clear_chunk(addr_t taddr, size_t len) = 0;
|
| 19 |
+
|
| 20 |
+
virtual size_t chunk_align() = 0;
|
| 21 |
+
virtual size_t chunk_max_size() = 0;
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
class memif_t
|
| 25 |
+
{
|
| 26 |
+
public:
|
| 27 |
+
memif_t(chunked_memif_t* _cmemif) : cmemif(_cmemif) {}
|
| 28 |
+
virtual ~memif_t(){}
|
| 29 |
+
|
| 30 |
+
// read and write byte arrays
|
| 31 |
+
virtual void read(addr_t addr, size_t len, void* bytes);
|
| 32 |
+
virtual void write(addr_t addr, size_t len, const void* bytes);
|
| 33 |
+
|
| 34 |
+
// read and write 8-bit words
|
| 35 |
+
virtual uint8_t read_uint8(addr_t addr);
|
| 36 |
+
virtual int8_t read_int8(addr_t addr);
|
| 37 |
+
virtual void write_uint8(addr_t addr, uint8_t val);
|
| 38 |
+
virtual void write_int8(addr_t addr, int8_t val);
|
| 39 |
+
|
| 40 |
+
// read and write 16-bit words
|
| 41 |
+
virtual uint16_t read_uint16(addr_t addr);
|
| 42 |
+
virtual int16_t read_int16(addr_t addr);
|
| 43 |
+
virtual void write_uint16(addr_t addr, uint16_t val);
|
| 44 |
+
virtual void write_int16(addr_t addr, int16_t val);
|
| 45 |
+
|
| 46 |
+
// read and write 32-bit words
|
| 47 |
+
virtual uint32_t read_uint32(addr_t addr);
|
| 48 |
+
virtual int32_t read_int32(addr_t addr);
|
| 49 |
+
virtual void write_uint32(addr_t addr, uint32_t val);
|
| 50 |
+
virtual void write_int32(addr_t addr, int32_t val);
|
| 51 |
+
|
| 52 |
+
// read and write 64-bit words
|
| 53 |
+
virtual uint64_t read_uint64(addr_t addr);
|
| 54 |
+
virtual int64_t read_int64(addr_t addr);
|
| 55 |
+
virtual void write_uint64(addr_t addr, uint64_t val);
|
| 56 |
+
virtual void write_int64(addr_t addr, int64_t val);
|
| 57 |
+
|
| 58 |
+
protected:
|
| 59 |
+
chunked_memif_t* cmemif;
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
#endif // __MEMIF_H
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/rfb.h
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef _RFB_H
|
| 2 |
+
#define _RFB_H
|
| 3 |
+
|
| 4 |
+
#include "device.h"
|
| 5 |
+
#include "memif.h"
|
| 6 |
+
#include <pthread.h>
|
| 7 |
+
|
| 8 |
+
// remote frame buffer
|
| 9 |
+
class rfb_t : public device_t
|
| 10 |
+
{
|
| 11 |
+
public:
|
| 12 |
+
rfb_t(int display = 0);
|
| 13 |
+
~rfb_t();
|
| 14 |
+
void tick();
|
| 15 |
+
std::string name() { return "RISC-V"; }
|
| 16 |
+
const char* identity() { return "rfb"; }
|
| 17 |
+
|
| 18 |
+
private:
|
| 19 |
+
template <typename T>
|
| 20 |
+
std::string str(T x)
|
| 21 |
+
{
|
| 22 |
+
return std::string((char*)&x, sizeof(x));
|
| 23 |
+
}
|
| 24 |
+
size_t fb_bytes() { return size_t(width) * height * bpp/8; }
|
| 25 |
+
void thread_main();
|
| 26 |
+
friend void* rfb_thread_main(void*);
|
| 27 |
+
std::string pixel_format();
|
| 28 |
+
void fb_update(const std::string& s);
|
| 29 |
+
void set_encodings(const std::string& s);
|
| 30 |
+
void set_pixel_format(const std::string& s);
|
| 31 |
+
void write(const std::string& s);
|
| 32 |
+
std::string read();
|
| 33 |
+
void handle_configure(command_t cmd);
|
| 34 |
+
void handle_set_address(command_t cmd);
|
| 35 |
+
|
| 36 |
+
int sockfd;
|
| 37 |
+
int afd;
|
| 38 |
+
memif_t* memif;
|
| 39 |
+
reg_t addr;
|
| 40 |
+
uint16_t width;
|
| 41 |
+
uint16_t height;
|
| 42 |
+
uint16_t bpp;
|
| 43 |
+
int display;
|
| 44 |
+
pthread_t thread;
|
| 45 |
+
volatile char* volatile fb1;
|
| 46 |
+
volatile char* volatile fb2;
|
| 47 |
+
size_t read_pos;
|
| 48 |
+
pthread_mutex_t lock;
|
| 49 |
+
|
| 50 |
+
static const int FB_ALIGN = 256;
|
| 51 |
+
};
|
| 52 |
+
|
| 53 |
+
#endif
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/syscall.cc
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// See LICENSE for license details.
|
| 2 |
+
|
| 3 |
+
#include "syscall.h"
|
| 4 |
+
#include "htif.h"
|
| 5 |
+
#include <unistd.h>
|
| 6 |
+
#include <fcntl.h>
|
| 7 |
+
#include <sys/stat.h>
|
| 8 |
+
#include <limits.h>
|
| 9 |
+
#include <errno.h>
|
| 10 |
+
#include <stdlib.h>
|
| 11 |
+
#include <assert.h>
|
| 12 |
+
#include <termios.h>
|
| 13 |
+
#include <sstream>
|
| 14 |
+
#include <iostream>
|
| 15 |
+
using namespace std::placeholders;
|
| 16 |
+
|
| 17 |
+
#define RISCV_AT_FDCWD -100
|
| 18 |
+
|
| 19 |
+
struct riscv_stat
|
| 20 |
+
{
|
| 21 |
+
uint64_t dev;
|
| 22 |
+
uint64_t ino;
|
| 23 |
+
uint32_t mode;
|
| 24 |
+
uint32_t nlink;
|
| 25 |
+
uint32_t uid;
|
| 26 |
+
uint32_t gid;
|
| 27 |
+
uint64_t rdev;
|
| 28 |
+
uint64_t __pad1;
|
| 29 |
+
uint64_t size;
|
| 30 |
+
uint32_t blksize;
|
| 31 |
+
uint32_t __pad2;
|
| 32 |
+
uint64_t blocks;
|
| 33 |
+
uint64_t atime;
|
| 34 |
+
uint64_t __pad3;
|
| 35 |
+
uint64_t mtime;
|
| 36 |
+
uint64_t __pad4;
|
| 37 |
+
uint64_t ctime;
|
| 38 |
+
uint64_t __pad5;
|
| 39 |
+
uint32_t __unused4;
|
| 40 |
+
uint32_t __unused5;
|
| 41 |
+
|
| 42 |
+
riscv_stat(const struct stat& s)
|
| 43 |
+
: dev(s.st_dev), ino(s.st_ino), mode(s.st_mode), nlink(s.st_nlink),
|
| 44 |
+
uid(s.st_uid), gid(s.st_gid), rdev(s.st_rdev), __pad1(0),
|
| 45 |
+
size(s.st_size), blksize(s.st_blksize), __pad2(0),
|
| 46 |
+
blocks(s.st_blocks), atime(s.st_atime), __pad3(0),
|
| 47 |
+
mtime(s.st_mtime), __pad4(0), ctime(s.st_ctime), __pad5(0),
|
| 48 |
+
__unused4(0), __unused5(0) {}
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
syscall_t::syscall_t(htif_t* htif)
|
| 52 |
+
: htif(htif), memif(&htif->memif()), table(2048)
|
| 53 |
+
{
|
| 54 |
+
table[17] = &syscall_t::sys_getcwd;
|
| 55 |
+
table[25] = &syscall_t::sys_fcntl;
|
| 56 |
+
table[34] = &syscall_t::sys_mkdirat;
|
| 57 |
+
table[35] = &syscall_t::sys_unlinkat;
|
| 58 |
+
table[37] = &syscall_t::sys_linkat;
|
| 59 |
+
table[38] = &syscall_t::sys_renameat;
|
| 60 |
+
table[46] = &syscall_t::sys_ftruncate;
|
| 61 |
+
table[48] = &syscall_t::sys_faccessat;
|
| 62 |
+
table[49] = &syscall_t::sys_chdir;
|
| 63 |
+
table[56] = &syscall_t::sys_openat;
|
| 64 |
+
table[57] = &syscall_t::sys_close;
|
| 65 |
+
table[62] = &syscall_t::sys_lseek;
|
| 66 |
+
table[63] = &syscall_t::sys_read;
|
| 67 |
+
table[64] = &syscall_t::sys_write;
|
| 68 |
+
table[67] = &syscall_t::sys_pread;
|
| 69 |
+
table[68] = &syscall_t::sys_pwrite;
|
| 70 |
+
table[79] = &syscall_t::sys_fstatat;
|
| 71 |
+
table[80] = &syscall_t::sys_fstat;
|
| 72 |
+
table[93] = &syscall_t::sys_exit;
|
| 73 |
+
table[1039] = &syscall_t::sys_lstat;
|
| 74 |
+
table[2011] = &syscall_t::sys_getmainvars;
|
| 75 |
+
|
| 76 |
+
register_command(0, std::bind(&syscall_t::handle_syscall, this, _1), "syscall");
|
| 77 |
+
|
| 78 |
+
int stdin_fd = dup(0), stdout_fd0 = dup(1), stdout_fd1 = dup(1);
|
| 79 |
+
if (stdin_fd < 0 || stdout_fd0 < 0 || stdout_fd1 < 0)
|
| 80 |
+
throw std::runtime_error("could not dup stdin/stdout");
|
| 81 |
+
|
| 82 |
+
fds.alloc(stdin_fd); // stdin -> stdin
|
| 83 |
+
fds.alloc(stdout_fd0); // stdout -> stdout
|
| 84 |
+
fds.alloc(stdout_fd1); // stderr -> stdout
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
std::string syscall_t::do_chroot(const char* fn)
|
| 88 |
+
{
|
| 89 |
+
if (!chroot.empty() && *fn == '/')
|
| 90 |
+
return chroot + fn;
|
| 91 |
+
return fn;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
std::string syscall_t::undo_chroot(const char* fn)
|
| 95 |
+
{
|
| 96 |
+
if (chroot.empty())
|
| 97 |
+
return fn;
|
| 98 |
+
if (strncmp(fn, chroot.c_str(), chroot.size()) == 0
|
| 99 |
+
&& (chroot.back() == '/' || fn[chroot.size()] == '/'))
|
| 100 |
+
return fn + chroot.size() - (chroot.back() == '/');
|
| 101 |
+
return "/";
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
void syscall_t::handle_syscall(command_t cmd)
|
| 105 |
+
{
|
| 106 |
+
if (cmd.payload() & 1) // test pass/fail
|
| 107 |
+
{
|
| 108 |
+
htif->exitcode = cmd.payload();
|
| 109 |
+
if (htif->exit_code())
|
| 110 |
+
std::cerr << "*** FAILED *** (tohost = " << htif->exit_code() << ")" << std::endl;
|
| 111 |
+
return;
|
| 112 |
+
}
|
| 113 |
+
else // proxied system call
|
| 114 |
+
dispatch(cmd.payload());
|
| 115 |
+
|
| 116 |
+
cmd.respond(1);
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
reg_t syscall_t::sys_exit(reg_t code, reg_t a1, reg_t a2, reg_t a3, reg_t a4, reg_t a5, reg_t a6)
|
| 120 |
+
{
|
| 121 |
+
htif->exitcode = code << 1 | 1;
|
| 122 |
+
return 0;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
static reg_t sysret_errno(sreg_t ret)
|
| 126 |
+
{
|
| 127 |
+
return ret == -1 ? -errno : ret;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
reg_t syscall_t::sys_read(reg_t fd, reg_t pbuf, reg_t len, reg_t a3, reg_t a4, reg_t a5, reg_t a6)
|
| 131 |
+
{
|
| 132 |
+
std::vector<char> buf(len);
|
| 133 |
+
ssize_t ret = read(fds.lookup(fd), &buf[0], len);
|
| 134 |
+
reg_t ret_errno = sysret_errno(ret);
|
| 135 |
+
if (ret > 0)
|
| 136 |
+
memif->write(pbuf, ret, &buf[0]);
|
| 137 |
+
return ret_errno;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
reg_t syscall_t::sys_pread(reg_t fd, reg_t pbuf, reg_t len, reg_t off, reg_t a4, reg_t a5, reg_t a6)
|
| 141 |
+
{
|
| 142 |
+
std::vector<char> buf(len);
|
| 143 |
+
ssize_t ret = pread(fds.lookup(fd), &buf[0], len, off);
|
| 144 |
+
reg_t ret_errno = sysret_errno(ret);
|
| 145 |
+
if (ret > 0)
|
| 146 |
+
memif->write(pbuf, ret, &buf[0]);
|
| 147 |
+
return ret_errno;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
reg_t syscall_t::sys_write(reg_t fd, reg_t pbuf, reg_t len, reg_t a3, reg_t a4, reg_t a5, reg_t a6)
|
| 151 |
+
{
|
| 152 |
+
std::vector<char> buf(len);
|
| 153 |
+
memif->read(pbuf, len, &buf[0]);
|
| 154 |
+
reg_t ret = sysret_errno(write(fds.lookup(fd), &buf[0], len));
|
| 155 |
+
return ret;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
reg_t syscall_t::sys_pwrite(reg_t fd, reg_t pbuf, reg_t len, reg_t off, reg_t a4, reg_t a5, reg_t a6)
|
| 159 |
+
{
|
| 160 |
+
std::vector<char> buf(len);
|
| 161 |
+
memif->read(pbuf, len, &buf[0]);
|
| 162 |
+
reg_t ret = sysret_errno(pwrite(fds.lookup(fd), &buf[0], len, off));
|
| 163 |
+
return ret;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
reg_t syscall_t::sys_close(reg_t fd, reg_t a1, reg_t a2, reg_t a3, reg_t a4, reg_t a5, reg_t a6)
|
| 167 |
+
{
|
| 168 |
+
if (close(fds.lookup(fd)) < 0)
|
| 169 |
+
return sysret_errno(-1);
|
| 170 |
+
fds.dealloc(fd);
|
| 171 |
+
return 0;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
reg_t syscall_t::sys_lseek(reg_t fd, reg_t ptr, reg_t dir, reg_t a3, reg_t a4, reg_t a5, reg_t a6)
|
| 175 |
+
{
|
| 176 |
+
return sysret_errno(lseek(fds.lookup(fd), ptr, dir));
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
reg_t syscall_t::sys_fstat(reg_t fd, reg_t pbuf, reg_t a2, reg_t a3, reg_t a4, reg_t a5, reg_t a6)
|
| 180 |
+
{
|
| 181 |
+
struct stat buf;
|
| 182 |
+
reg_t ret = sysret_errno(fstat(fds.lookup(fd), &buf));
|
| 183 |
+
if (ret != (reg_t)-1)
|
| 184 |
+
{
|
| 185 |
+
riscv_stat rbuf(buf);
|
| 186 |
+
memif->write(pbuf, sizeof(rbuf), &rbuf);
|
| 187 |
+
}
|
| 188 |
+
return ret;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
reg_t syscall_t::sys_fcntl(reg_t fd, reg_t cmd, reg_t arg, reg_t a3, reg_t a4, reg_t a5, reg_t a6)
|
| 192 |
+
{
|
| 193 |
+
return sysret_errno(fcntl(fds.lookup(fd), cmd, arg));
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
reg_t syscall_t::sys_ftruncate(reg_t fd, reg_t len, reg_t a2, reg_t a3, reg_t a4, reg_t a5, reg_t a6)
|
| 197 |
+
{
|
| 198 |
+
return sysret_errno(ftruncate(fds.lookup(fd), len));
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
reg_t syscall_t::sys_lstat(reg_t pname, reg_t len, reg_t pbuf, reg_t a3, reg_t a4, reg_t a5, reg_t a6)
|
| 202 |
+
{
|
| 203 |
+
std::vector<char> name(len);
|
| 204 |
+
memif->read(pname, len, &name[0]);
|
| 205 |
+
|
| 206 |
+
struct stat buf;
|
| 207 |
+
reg_t ret = sysret_errno(lstat(do_chroot(&name[0]).c_str(), &buf));
|
| 208 |
+
riscv_stat rbuf(buf);
|
| 209 |
+
if (ret != (reg_t)-1)
|
| 210 |
+
{
|
| 211 |
+
riscv_stat rbuf(buf);
|
| 212 |
+
memif->write(pbuf, sizeof(rbuf), &rbuf);
|
| 213 |
+
}
|
| 214 |
+
return ret;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
#define AT_SYSCALL(syscall, fd, name, ...) \
|
| 218 |
+
(syscall(fds.lookup(fd), int(fd) == RISCV_AT_FDCWD ? do_chroot(name).c_str() : (name), __VA_ARGS__))
|
| 219 |
+
|
| 220 |
+
reg_t syscall_t::sys_openat(reg_t dirfd, reg_t pname, reg_t len, reg_t flags, reg_t mode, reg_t a5, reg_t a6)
|
| 221 |
+
{
|
| 222 |
+
std::vector<char> name(len);
|
| 223 |
+
memif->read(pname, len, &name[0]);
|
| 224 |
+
int fd = sysret_errno(AT_SYSCALL(openat, dirfd, &name[0], flags, mode));
|
| 225 |
+
if (fd < 0)
|
| 226 |
+
return sysret_errno(-1);
|
| 227 |
+
return fds.alloc(fd);
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
reg_t syscall_t::sys_fstatat(reg_t dirfd, reg_t pname, reg_t len, reg_t pbuf, reg_t flags, reg_t a5, reg_t a6)
|
| 231 |
+
{
|
| 232 |
+
std::vector<char> name(len);
|
| 233 |
+
memif->read(pname, len, &name[0]);
|
| 234 |
+
|
| 235 |
+
struct stat buf;
|
| 236 |
+
reg_t ret = sysret_errno(AT_SYSCALL(fstatat, dirfd, &name[0], &buf, flags));
|
| 237 |
+
if (ret != (reg_t)-1)
|
| 238 |
+
{
|
| 239 |
+
riscv_stat rbuf(buf);
|
| 240 |
+
memif->write(pbuf, sizeof(rbuf), &rbuf);
|
| 241 |
+
}
|
| 242 |
+
return ret;
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
reg_t syscall_t::sys_faccessat(reg_t dirfd, reg_t pname, reg_t len, reg_t mode, reg_t a4, reg_t a5, reg_t a6)
|
| 246 |
+
{
|
| 247 |
+
std::vector<char> name(len);
|
| 248 |
+
memif->read(pname, len, &name[0]);
|
| 249 |
+
return sysret_errno(AT_SYSCALL(faccessat, dirfd, &name[0], mode, 0));
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
reg_t syscall_t::sys_renameat(reg_t odirfd, reg_t popath, reg_t olen, reg_t ndirfd, reg_t pnpath, reg_t nlen, reg_t a6)
|
| 253 |
+
{
|
| 254 |
+
std::vector<char> opath(olen), npath(nlen);
|
| 255 |
+
memif->read(popath, olen, &opath[0]);
|
| 256 |
+
memif->read(pnpath, nlen, &npath[0]);
|
| 257 |
+
return sysret_errno(renameat(fds.lookup(odirfd), int(odirfd) == RISCV_AT_FDCWD ? do_chroot(&opath[0]).c_str() : &opath[0],
|
| 258 |
+
fds.lookup(ndirfd), int(ndirfd) == RISCV_AT_FDCWD ? do_chroot(&npath[0]).c_str() : &npath[0]));
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
reg_t syscall_t::sys_linkat(reg_t odirfd, reg_t poname, reg_t olen, reg_t ndirfd, reg_t pnname, reg_t nlen, reg_t flags)
|
| 262 |
+
{
|
| 263 |
+
std::vector<char> oname(olen), nname(nlen);
|
| 264 |
+
memif->read(poname, olen, &oname[0]);
|
| 265 |
+
memif->read(pnname, nlen, &nname[0]);
|
| 266 |
+
return sysret_errno(linkat(fds.lookup(odirfd), int(odirfd) == RISCV_AT_FDCWD ? do_chroot(&oname[0]).c_str() : &oname[0],
|
| 267 |
+
fds.lookup(ndirfd), int(ndirfd) == RISCV_AT_FDCWD ? do_chroot(&nname[0]).c_str() : &nname[0],
|
| 268 |
+
flags));
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
reg_t syscall_t::sys_unlinkat(reg_t dirfd, reg_t pname, reg_t len, reg_t flags, reg_t a4, reg_t a5, reg_t a6)
|
| 272 |
+
{
|
| 273 |
+
std::vector<char> name(len);
|
| 274 |
+
memif->read(pname, len, &name[0]);
|
| 275 |
+
return sysret_errno(AT_SYSCALL(unlinkat, dirfd, &name[0], flags));
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
reg_t syscall_t::sys_mkdirat(reg_t dirfd, reg_t pname, reg_t len, reg_t mode, reg_t a4, reg_t a5, reg_t a6)
|
| 279 |
+
{
|
| 280 |
+
std::vector<char> name(len);
|
| 281 |
+
memif->read(pname, len, &name[0]);
|
| 282 |
+
return sysret_errno(AT_SYSCALL(mkdirat, dirfd, &name[0], mode));
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
reg_t syscall_t::sys_getcwd(reg_t pbuf, reg_t size, reg_t a2, reg_t a3, reg_t a4, reg_t a5, reg_t a6)
|
| 286 |
+
{
|
| 287 |
+
std::vector<char> buf(size);
|
| 288 |
+
char* ret = getcwd(&buf[0], size);
|
| 289 |
+
if (ret == NULL)
|
| 290 |
+
return sysret_errno(-1);
|
| 291 |
+
std::string tmp = undo_chroot(&buf[0]);
|
| 292 |
+
if (size <= tmp.size())
|
| 293 |
+
return -ENOMEM;
|
| 294 |
+
memif->write(pbuf, tmp.size() + 1, &tmp[0]);
|
| 295 |
+
return tmp.size() + 1;
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
reg_t syscall_t::sys_getmainvars(reg_t pbuf, reg_t limit, reg_t a2, reg_t a3, reg_t a4, reg_t a5, reg_t a6)
|
| 299 |
+
{
|
| 300 |
+
std::vector<std::string> args = htif->target_args();
|
| 301 |
+
std::vector<uint64_t> words(args.size() + 3);
|
| 302 |
+
words[0] = args.size();
|
| 303 |
+
words[args.size()+1] = 0; // argv[argc] = NULL
|
| 304 |
+
words[args.size()+2] = 0; // envp[0] = NULL
|
| 305 |
+
|
| 306 |
+
size_t sz = (args.size() + 3) * sizeof(words[0]);
|
| 307 |
+
for (size_t i = 0; i < args.size(); i++)
|
| 308 |
+
{
|
| 309 |
+
words[i+1] = sz + pbuf;
|
| 310 |
+
sz += args[i].length() + 1;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
std::vector<char> bytes(sz);
|
| 314 |
+
memcpy(&bytes[0], &words[0], sizeof(words[0]) * words.size());
|
| 315 |
+
for (size_t i = 0; i < args.size(); i++)
|
| 316 |
+
strcpy(&bytes[words[i+1] - pbuf], args[i].c_str());
|
| 317 |
+
|
| 318 |
+
if (bytes.size() > limit)
|
| 319 |
+
return -ENOMEM;
|
| 320 |
+
|
| 321 |
+
memif->write(pbuf, bytes.size(), &bytes[0]);
|
| 322 |
+
return 0;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
reg_t syscall_t::sys_chdir(reg_t path, reg_t a1, reg_t a2, reg_t a3, reg_t a4, reg_t a5, reg_t a6)
|
| 326 |
+
{
|
| 327 |
+
size_t size = 0;
|
| 328 |
+
while (memif->read_uint8(path + size++))
|
| 329 |
+
;
|
| 330 |
+
std::vector<char> buf(size);
|
| 331 |
+
for (size_t offset = 0;; offset++)
|
| 332 |
+
{
|
| 333 |
+
buf[offset] = memif->read_uint8(path + offset);
|
| 334 |
+
if (!buf[offset])
|
| 335 |
+
break;
|
| 336 |
+
}
|
| 337 |
+
return sysret_errno(chdir(buf.data()));
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
void syscall_t::dispatch(reg_t mm)
|
| 341 |
+
{
|
| 342 |
+
reg_t magicmem[8];
|
| 343 |
+
memif->read(mm, sizeof(magicmem), magicmem);
|
| 344 |
+
|
| 345 |
+
reg_t n = magicmem[0];
|
| 346 |
+
if (n >= table.size() || !table[n])
|
| 347 |
+
throw std::runtime_error("bad syscall #" + std::to_string(n));
|
| 348 |
+
|
| 349 |
+
magicmem[0] = (this->*table[n])(magicmem[1], magicmem[2], magicmem[3], magicmem[4], magicmem[5], magicmem[6], magicmem[7]);
|
| 350 |
+
|
| 351 |
+
memif->write(mm, sizeof(magicmem), magicmem);
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
reg_t fds_t::alloc(int fd)
|
| 355 |
+
{
|
| 356 |
+
reg_t i;
|
| 357 |
+
for (i = 0; i < fds.size(); i++)
|
| 358 |
+
if (fds[i] == -1)
|
| 359 |
+
break;
|
| 360 |
+
|
| 361 |
+
if (i == fds.size())
|
| 362 |
+
fds.resize(i+1);
|
| 363 |
+
|
| 364 |
+
fds[i] = fd;
|
| 365 |
+
return i;
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
void fds_t::dealloc(reg_t fd)
|
| 369 |
+
{
|
| 370 |
+
fds[fd] = -1;
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
int fds_t::lookup(reg_t fd)
|
| 374 |
+
{
|
| 375 |
+
if (int(fd) == RISCV_AT_FDCWD)
|
| 376 |
+
return AT_FDCWD;
|
| 377 |
+
return fd >= fds.size() ? -1 : fds[fd];
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
void syscall_t::set_chroot(const char* where)
|
| 381 |
+
{
|
| 382 |
+
char buf1[PATH_MAX], buf2[PATH_MAX];
|
| 383 |
+
|
| 384 |
+
if (getcwd(buf1, sizeof(buf1)) == NULL
|
| 385 |
+
|| chdir(where) != 0
|
| 386 |
+
|| getcwd(buf2, sizeof(buf2)) == NULL
|
| 387 |
+
|| chdir(buf1) != 0)
|
| 388 |
+
{
|
| 389 |
+
fprintf(stderr, "could not chroot to %s\n", where);
|
| 390 |
+
exit(-1);
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
chroot = buf2;
|
| 394 |
+
}
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/term.cc
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "term.h"
|
| 2 |
+
#include <termios.h>
|
| 3 |
+
#include <unistd.h>
|
| 4 |
+
#include <poll.h>
|
| 5 |
+
#include <signal.h>
|
| 6 |
+
#include <stdlib.h>
|
| 7 |
+
|
| 8 |
+
class canonical_termios_t
|
| 9 |
+
{
|
| 10 |
+
public:
|
| 11 |
+
canonical_termios_t()
|
| 12 |
+
: restore_tios(false)
|
| 13 |
+
{
|
| 14 |
+
if (tcgetattr(0, &old_tios) == 0)
|
| 15 |
+
{
|
| 16 |
+
struct termios new_tios = old_tios;
|
| 17 |
+
new_tios.c_lflag &= ~(ICANON | ECHO);
|
| 18 |
+
if (tcsetattr(0, TCSANOW, &new_tios) == 0)
|
| 19 |
+
restore_tios = true;
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
~canonical_termios_t()
|
| 24 |
+
{
|
| 25 |
+
if (restore_tios)
|
| 26 |
+
tcsetattr(0, TCSANOW, &old_tios);
|
| 27 |
+
}
|
| 28 |
+
private:
|
| 29 |
+
struct termios old_tios;
|
| 30 |
+
bool restore_tios;
|
| 31 |
+
};
|
| 32 |
+
|
| 33 |
+
static canonical_termios_t tios; // exit() will clean up for us
|
| 34 |
+
|
| 35 |
+
int canonical_terminal_t::read()
|
| 36 |
+
{
|
| 37 |
+
struct pollfd pfd;
|
| 38 |
+
pfd.fd = 0;
|
| 39 |
+
pfd.events = POLLIN;
|
| 40 |
+
int ret = poll(&pfd, 1, 0);
|
| 41 |
+
if (ret <= 0 || !(pfd.revents & POLLIN))
|
| 42 |
+
return -1;
|
| 43 |
+
|
| 44 |
+
unsigned char ch;
|
| 45 |
+
ret = ::read(0, &ch, 1);
|
| 46 |
+
return ret <= 0 ? -1 : ch;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
void canonical_terminal_t::write(char ch)
|
| 50 |
+
{
|
| 51 |
+
if (::write(1, &ch, 1) != 1)
|
| 52 |
+
abort();
|
| 53 |
+
}
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/tsi.cc
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "tsi.h"
|
| 2 |
+
#include <cstdio>
|
| 3 |
+
#include <cstdlib>
|
| 4 |
+
|
| 5 |
+
#define NHARTS_MAX 16
|
| 6 |
+
|
| 7 |
+
void tsi_t::host_thread(void *arg)
|
| 8 |
+
{
|
| 9 |
+
tsi_t *tsi = static_cast<tsi_t*>(arg);
|
| 10 |
+
tsi->run();
|
| 11 |
+
|
| 12 |
+
while (true)
|
| 13 |
+
tsi->target->switch_to();
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
tsi_t::tsi_t(int argc, char** argv) : htif_t(argc, argv)
|
| 17 |
+
{
|
| 18 |
+
target = context_t::current();
|
| 19 |
+
host.init(host_thread, this);
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
tsi_t::~tsi_t(void)
|
| 23 |
+
{
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
#define MSIP_BASE 0x2000000
|
| 27 |
+
|
| 28 |
+
// Interrupt core 0 to make it start executing the program in DRAM
|
| 29 |
+
void tsi_t::reset()
|
| 30 |
+
{
|
| 31 |
+
uint32_t one = 1;
|
| 32 |
+
|
| 33 |
+
write_chunk(MSIP_BASE, sizeof(uint32_t), &one);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
void tsi_t::push_addr(addr_t addr)
|
| 37 |
+
{
|
| 38 |
+
for (int i = 0; i < SAI_ADDR_CHUNKS; i++) {
|
| 39 |
+
in_data.push_back(addr & 0xffffffff);
|
| 40 |
+
addr = addr >> 32;
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
void tsi_t::push_len(addr_t len)
|
| 45 |
+
{
|
| 46 |
+
for (int i = 0; i < SAI_LEN_CHUNKS; i++) {
|
| 47 |
+
in_data.push_back(len & 0xffffffff);
|
| 48 |
+
len = len >> 32;
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
void tsi_t::read_chunk(addr_t taddr, size_t nbytes, void* dst)
|
| 53 |
+
{
|
| 54 |
+
uint32_t *result = static_cast<uint32_t*>(dst);
|
| 55 |
+
size_t len = nbytes / sizeof(uint32_t);
|
| 56 |
+
|
| 57 |
+
in_data.push_back(SAI_CMD_READ);
|
| 58 |
+
push_addr(taddr);
|
| 59 |
+
push_len(len - 1);
|
| 60 |
+
|
| 61 |
+
for (size_t i = 0; i < len; i++) {
|
| 62 |
+
while (out_data.empty())
|
| 63 |
+
switch_to_target();
|
| 64 |
+
result[i] = out_data.front();
|
| 65 |
+
out_data.pop_front();
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
void tsi_t::write_chunk(addr_t taddr, size_t nbytes, const void* src)
|
| 70 |
+
{
|
| 71 |
+
const uint32_t *src_data = static_cast<const uint32_t*>(src);
|
| 72 |
+
size_t len = nbytes / sizeof(uint32_t);
|
| 73 |
+
|
| 74 |
+
in_data.push_back(SAI_CMD_WRITE);
|
| 75 |
+
push_addr(taddr);
|
| 76 |
+
push_len(len - 1);
|
| 77 |
+
|
| 78 |
+
in_data.insert(in_data.end(), src_data, src_data + len);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
void tsi_t::send_word(uint32_t word)
|
| 82 |
+
{
|
| 83 |
+
out_data.push_back(word);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
uint32_t tsi_t::recv_word(void)
|
| 87 |
+
{
|
| 88 |
+
uint32_t word = in_data.front();
|
| 89 |
+
in_data.pop_front();
|
| 90 |
+
return word;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
bool tsi_t::data_available(void)
|
| 94 |
+
{
|
| 95 |
+
return !in_data.empty();
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
void tsi_t::switch_to_host(void)
|
| 99 |
+
{
|
| 100 |
+
host.switch_to();
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
void tsi_t::switch_to_target(void)
|
| 104 |
+
{
|
| 105 |
+
target->switch_to();
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
void tsi_t::tick(bool out_valid, uint32_t out_bits, bool in_ready)
|
| 109 |
+
{
|
| 110 |
+
if (out_valid && out_ready())
|
| 111 |
+
out_data.push_back(out_bits);
|
| 112 |
+
|
| 113 |
+
if (in_valid() && in_ready)
|
| 114 |
+
in_data.pop_front();
|
| 115 |
+
}
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/fesvr/tsi.h
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef __SAI_H
|
| 2 |
+
#define __SAI_H
|
| 3 |
+
|
| 4 |
+
#include "htif.h"
|
| 5 |
+
#include "context.h"
|
| 6 |
+
|
| 7 |
+
#include <string>
|
| 8 |
+
#include <vector>
|
| 9 |
+
#include <deque>
|
| 10 |
+
#include <stdint.h>
|
| 11 |
+
|
| 12 |
+
#define SAI_CMD_READ 0
|
| 13 |
+
#define SAI_CMD_WRITE 1
|
| 14 |
+
|
| 15 |
+
#define SAI_ADDR_CHUNKS 2
|
| 16 |
+
#define SAI_LEN_CHUNKS 2
|
| 17 |
+
|
| 18 |
+
class tsi_t : public htif_t
|
| 19 |
+
{
|
| 20 |
+
public:
|
| 21 |
+
tsi_t(int argc, char** argv);
|
| 22 |
+
virtual ~tsi_t();
|
| 23 |
+
|
| 24 |
+
bool data_available();
|
| 25 |
+
void send_word(uint32_t word);
|
| 26 |
+
uint32_t recv_word();
|
| 27 |
+
void switch_to_host();
|
| 28 |
+
|
| 29 |
+
uint32_t in_bits() { return in_data.front(); }
|
| 30 |
+
bool in_valid() { return !in_data.empty(); }
|
| 31 |
+
bool out_ready() { return true; }
|
| 32 |
+
void tick(bool out_valid, uint32_t out_bits, bool in_ready);
|
| 33 |
+
|
| 34 |
+
protected:
|
| 35 |
+
void reset() override;
|
| 36 |
+
void read_chunk(addr_t taddr, size_t nbytes, void* dst) override;
|
| 37 |
+
void write_chunk(addr_t taddr, size_t nbytes, const void* src) override;
|
| 38 |
+
void switch_to_target();
|
| 39 |
+
|
| 40 |
+
size_t chunk_align() { return 4; }
|
| 41 |
+
size_t chunk_max_size() { return 1024; }
|
| 42 |
+
|
| 43 |
+
int get_ipi_addrs(addr_t *addrs);
|
| 44 |
+
|
| 45 |
+
private:
|
| 46 |
+
context_t host;
|
| 47 |
+
context_t* target;
|
| 48 |
+
std::deque<uint32_t> in_data;
|
| 49 |
+
std::deque<uint32_t> out_data;
|
| 50 |
+
|
| 51 |
+
void push_addr(addr_t addr);
|
| 52 |
+
void push_len(addr_t len);
|
| 53 |
+
|
| 54 |
+
static void host_thread(void *tsi);
|
| 55 |
+
};
|
| 56 |
+
|
| 57 |
+
#endif
|
snapshots/pulp-platform_snitch_pr436/sw/vendor/riscv-isa-sim/tests/testlib.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os.path
|
| 2 |
+
import pexpect
|
| 3 |
+
import subprocess
|
| 4 |
+
import tempfile
|
| 5 |
+
import testlib
|
| 6 |
+
import unittest
|
| 7 |
+
|
| 8 |
+
# Note that gdb comes with its own testsuite. I was unable to figure out how to
|
| 9 |
+
# run that testsuite against the spike simulator.
|
| 10 |
+
|
| 11 |
+
def find_file(path):
|
| 12 |
+
for directory in (os.getcwd(), os.path.dirname(testlib.__file__)):
|
| 13 |
+
fullpath = os.path.join(directory, path)
|
| 14 |
+
if os.path.exists(fullpath):
|
| 15 |
+
return fullpath
|
| 16 |
+
return None
|
| 17 |
+
|
| 18 |
+
def compile(*args):
|
| 19 |
+
"""Compile a single .c file into a binary."""
|
| 20 |
+
dst = os.path.splitext(args[0])[0]
|
| 21 |
+
cc = os.path.expandvars("$RISCV/bin/riscv64-unknown-elf-gcc")
|
| 22 |
+
cmd = [cc, "-g", "-O", "-o", dst]
|
| 23 |
+
for arg in args:
|
| 24 |
+
found = find_file(arg)
|
| 25 |
+
if found:
|
| 26 |
+
cmd.append(found)
|
| 27 |
+
else:
|
| 28 |
+
cmd.append(arg)
|
| 29 |
+
cmd = " ".join(cmd)
|
| 30 |
+
result = os.system(cmd)
|
| 31 |
+
assert result == 0, "%r failed" % cmd
|
| 32 |
+
return dst
|
| 33 |
+
|
| 34 |
+
def unused_port():
|
| 35 |
+
# http://stackoverflow.com/questions/2838244/get-open-tcp-port-in-python/2838309#2838309
|
| 36 |
+
import socket
|
| 37 |
+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 38 |
+
s.bind(("",0))
|
| 39 |
+
port = s.getsockname()[1]
|
| 40 |
+
s.close()
|
| 41 |
+
return port
|
| 42 |
+
|
| 43 |
+
class Spike(object):
|
| 44 |
+
def __init__(self, binary, halted=False, with_gdb=True, timeout=None):
|
| 45 |
+
"""Launch spike. Return tuple of its process and the port it's running on."""
|
| 46 |
+
cmd = []
|
| 47 |
+
if timeout:
|
| 48 |
+
cmd += ["timeout", str(timeout)]
|
| 49 |
+
|
| 50 |
+
cmd += [find_file("spike")]
|
| 51 |
+
if halted:
|
| 52 |
+
cmd.append('-H')
|
| 53 |
+
if with_gdb:
|
| 54 |
+
self.port = unused_port()
|
| 55 |
+
cmd += ['--gdb-port', str(self.port)]
|
| 56 |
+
cmd.append('pk')
|
| 57 |
+
if binary:
|
| 58 |
+
cmd.append(binary)
|
| 59 |
+
logfile = open("spike.log", "w")
|
| 60 |
+
self.process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=logfile,
|
| 61 |
+
stderr=logfile)
|
| 62 |
+
|
| 63 |
+
def __del__(self):
|
| 64 |
+
try:
|
| 65 |
+
self.process.kill()
|
| 66 |
+
self.process.wait()
|
| 67 |
+
except OSError:
|
| 68 |
+
pass
|
| 69 |
+
|
| 70 |
+
def wait(self, *args, **kwargs):
|
| 71 |
+
return self.process.wait(*args, **kwargs)
|
| 72 |
+
|
| 73 |
+
class Gdb(object):
|
| 74 |
+
def __init__(self):
|
| 75 |
+
path = os.path.expandvars("$RISCV/bin/riscv64-unknown-elf-gdb")
|
| 76 |
+
self.child = pexpect.spawn(path)
|
| 77 |
+
self.child.logfile = file("gdb.log", "w")
|
| 78 |
+
self.wait()
|
| 79 |
+
self.command("set width 0")
|
| 80 |
+
self.command("set height 0")
|
| 81 |
+
# Force consistency.
|
| 82 |
+
self.command("set print entry-values no")
|
| 83 |
+
|
| 84 |
+
def wait(self):
|
| 85 |
+
"""Wait for prompt."""
|
| 86 |
+
self.child.expect("\(gdb\)")
|
| 87 |
+
|
| 88 |
+
def command(self, command, timeout=-1):
|
| 89 |
+
self.child.sendline(command)
|
| 90 |
+
self.child.expect("\n", timeout=timeout)
|
| 91 |
+
self.child.expect("\(gdb\)", timeout=timeout)
|
| 92 |
+
return self.child.before.strip()
|
| 93 |
+
|
| 94 |
+
def c(self, wait=True):
|
| 95 |
+
if wait:
|
| 96 |
+
return self.command("c")
|
| 97 |
+
else:
|
| 98 |
+
self.child.sendline("c")
|
| 99 |
+
self.child.expect("Continuing")
|
| 100 |
+
|
| 101 |
+
def interrupt(self):
|
| 102 |
+
self.child.send("\003");
|
| 103 |
+
self.child.expect("\(gdb\)")
|
| 104 |
+
|
| 105 |
+
def x(self, address, size='w'):
|
| 106 |
+
output = self.command("x/%s %s" % (size, address))
|
| 107 |
+
value = int(output.split(':')[1].strip(), 0)
|
| 108 |
+
return value
|
| 109 |
+
|
| 110 |
+
def p(self, obj):
|
| 111 |
+
output = self.command("p %s" % obj)
|
| 112 |
+
value = int(output.split('=')[-1].strip())
|
| 113 |
+
return value
|
| 114 |
+
|
| 115 |
+
def stepi(self):
|
| 116 |
+
return self.command("stepi")
|