15 changed files with 104 additions and 40 deletions
@ -0,0 +1,7 @@ |
|||
dummy_rocc_subproject_deps = \
|
|||
spike \
|
|||
riscv \
|
|||
softfloat \
|
|||
|
|||
dummy_rocc_srcs = \
|
|||
dummy_rocc.cc \
|
|||
@ -1,7 +1,7 @@ |
|||
// The following is a RISC-V program to test the functionality of the
|
|||
// dummy RoCC accelerator.
|
|||
// Compile with riscv-gcc dummy-rocc-test.c
|
|||
// Run with spike --extension=dummy pk a.out
|
|||
// Compile with riscv64-unknown-elf-gcc dummy_rocc_test.c
|
|||
// Run with spike --extension=dummy_rocc pk a.out
|
|||
|
|||
#include <assert.h> |
|||
#include <stdio.h> |
|||
@ -1,14 +1,35 @@ |
|||
#include "extension.h" |
|||
#include "hwacha.h" |
|||
#include "dummy-rocc.h" |
|||
#include <string> |
|||
#include <map> |
|||
#include <dlfcn.h> |
|||
|
|||
REGISTER_EXTENSION(dummy, []() { return new dummy_rocc_t; }) |
|||
REGISTER_EXTENSION(hwacha, []() { return new hwacha_t; }) |
|||
|
|||
// Static constructors want to make use of the extensions map, so we
|
|||
// access it through a function call to guarantee initialization order.
|
|||
std::map<std::string, std::function<extension_t*()>>& extensions() |
|||
static std::map<std::string, std::function<extension_t*()>>& extensions() |
|||
{ |
|||
static std::map<std::string, std::function<extension_t*()>> v; |
|||
return v; |
|||
} |
|||
|
|||
void register_extension(const char* name, std::function<extension_t*()> f) |
|||
{ |
|||
extensions()[name] = f; |
|||
} |
|||
|
|||
std::function<extension_t*()> find_extension(const char* name) |
|||
{ |
|||
if (!extensions().count(name)) { |
|||
// try to find extension xyz by loading libxyz.so
|
|||
std::string libname = std::string("lib") + name + ".so"; |
|||
if (!dlopen(libname.c_str(), RTLD_LAZY)) { |
|||
fprintf(stderr, "couldn't find extension '%s' (or library '%s')\n", |
|||
name, libname.c_str()); |
|||
exit(-1); |
|||
} |
|||
if (!extensions().count(name)) { |
|||
fprintf(stderr, "couldn't find extension '%s' in shared library '%s'\n", |
|||
name, libname.c_str()); |
|||
exit(-1); |
|||
} |
|||
} |
|||
|
|||
return extensions()[name]; |
|||
} |
|||
|
|||
Loading…
Reference in new issue