Browse Source

Factor out the dummy RoCC accelerator

pull/11/head
Andrew Waterman 12 years ago
parent
commit
590417bec9
  1. 3
      config.h.in
  2. 46
      configure
  3. 2
      configure.ac
  4. 0
      dummy_rocc/dummy_rocc.ac
  5. 16
      dummy_rocc/dummy_rocc.cc
  6. 7
      dummy_rocc/dummy_rocc.mk.in
  7. 4
      dummy_rocc/dummy_rocc_test.c
  8. 2
      hwacha/hwacha.cc
  9. 1
      hwacha/hwacha.mk.in
  10. 7
      riscv/extension.h
  11. 1
      riscv/riscv.mk.in
  12. 37
      spike/extensions.cc
  13. 9
      spike/riscv-dis.cc
  14. 6
      spike/spike.cc
  15. 3
      spike/spike.mk.in

3
config.h.in

@ -1,5 +1,8 @@
/* config.h.in. Generated from configure.ac by autoheader. */
/* Define if subproject MCPPBS_SPROJ_NORM is enabled */
#undef DUMMY_ROCC_ENABLED
/* Define to 1 if you have the `dl' library (-ldl). */
#undef HAVE_LIBDL

46
configure

@ -4301,6 +4301,51 @@ $as_echo "#define HWACHA_ENABLED /**/" >>confdefs.h
# Add subproject to our running list
subprojects="$subprojects dummy_rocc"
# Process the subproject appropriately. If enabled add it to the
# $enabled_subprojects running shell variable, set a
# SUBPROJECT_ENABLED C define, and include the appropriate
# 'subproject.ac'.
{ $as_echo "$as_me:${as_lineno-$LINENO}: configuring default subproject : dummy_rocc" >&5
$as_echo "$as_me: configuring default subproject : dummy_rocc" >&6;}
ac_config_files="$ac_config_files dummy_rocc.mk:dummy_rocc/dummy_rocc.mk.in"
enable_dummy_rocc_sproj="yes"
subprojects_enabled="$subprojects_enabled dummy_rocc"
$as_echo "#define DUMMY_ROCC_ENABLED /**/" >>confdefs.h
# Determine if this is a required or an optional subproject
# Determine if there is a group with the same name
# Create variations of the subproject name suitable for use as a CPP
# enabled define, a shell enabled variable, and a shell function
# Add subproject to our running list
subprojects="$subprojects softfloat"
@ -5147,6 +5192,7 @@ do
case $ac_config_target in
"riscv.mk") CONFIG_FILES="$CONFIG_FILES riscv.mk:riscv/riscv.mk.in" ;;
"hwacha.mk") CONFIG_FILES="$CONFIG_FILES hwacha.mk:hwacha/hwacha.mk.in" ;;
"dummy_rocc.mk") CONFIG_FILES="$CONFIG_FILES dummy_rocc.mk:dummy_rocc/dummy_rocc.mk.in" ;;
"softfloat.mk") CONFIG_FILES="$CONFIG_FILES softfloat.mk:softfloat/softfloat.mk.in" ;;
"spike.mk") CONFIG_FILES="$CONFIG_FILES spike.mk:spike/spike.mk.in" ;;
"config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;

2
configure.ac

@ -82,7 +82,7 @@ AC_SUBST([CXXFLAGS],["-Wall -Wno-unused -O2 -std=c++11"])
# The '*' suffix indicates an optional subproject. The '**' suffix
# indicates an optional subproject which is also the name of a group.
MCPPBS_SUBPROJECTS([ riscv, hwacha, softfloat, spike ])
MCPPBS_SUBPROJECTS([ riscv, hwacha, dummy_rocc, softfloat, spike ])
#-------------------------------------------------------------------------
# MCPPBS subproject groups

0
dummy_rocc/dummy_rocc.ac

16
riscv/dummy-rocc.h → dummy_rocc/dummy_rocc.cc

@ -1,19 +1,17 @@
#ifndef _RISCV_DUMMY_ROCC_H
#define _RISCV_DUMMY_ROCC_H
#include "rocc.h"
#include "mmu.h"
#include <cstring>
class dummy_rocc_t : public rocc_t
{
public:
const char* name() { return "dummy"; }
const char* name() { return "dummy_rocc"; }
reg_t custom0(rocc_insn_t insn, reg_t xs1, reg_t xs2)
{
reg_t prev_acc = acc[insn.rs2];
if (insn.rs2 > num_acc)
if (insn.rs2 >= num_acc)
illegal_instruction();
switch (insn.funct)
@ -35,10 +33,10 @@ class dummy_rocc_t : public rocc_t
return prev_acc; // in all cases, xd <- previous value of acc[rs2]
}
void reset()
dummy_rocc_t()
{
for(int i = 0; i < num_acc; i++) acc[i] = 0;
memset(acc, 0, sizeof(acc));
}
private:
@ -46,4 +44,4 @@ class dummy_rocc_t : public rocc_t
reg_t acc[num_acc];
};
#endif
REGISTER_EXTENSION(dummy_rocc, []() { return new dummy_rocc_t; })

7
dummy_rocc/dummy_rocc.mk.in

@ -0,0 +1,7 @@
dummy_rocc_subproject_deps = \
spike \
riscv \
softfloat \
dummy_rocc_srcs = \
dummy_rocc.cc \

4
riscv/dummy-rocc-test.c → dummy_rocc/dummy_rocc_test.c

@ -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>

2
hwacha/hwacha.cc

@ -4,6 +4,8 @@
#include "trap.h"
#include <stdexcept>
REGISTER_EXTENSION(hwacha, []() { return new hwacha_t; })
void ct_state_t::reset()
{
nxpr = 32;

1
hwacha/hwacha.mk.in

@ -1,4 +1,5 @@
hwacha_subproject_deps = \
spike \
riscv \
softfloat \

7
riscv/extension.h

@ -3,8 +3,6 @@
#include "processor.h"
#include "disasm.h"
#include <map>
#include <string>
#include <vector>
#include <functional>
@ -27,11 +25,12 @@ class extension_t
void clear_interrupt();
};
std::map<std::string, std::function<extension_t*()>>& extensions();
std::function<extension_t*()> find_extension(const char* name);
void register_extension(const char* name, std::function<extension_t*()> f);
#define REGISTER_EXTENSION(name, constructor) \
class register_##name { \
public: register_##name() { extensions()[#name] = constructor; } \
public: register_##name() { register_extension(#name, constructor); } \
}; static register_##name dummy_##name;
#endif

1
riscv/riscv.mk.in

@ -19,7 +19,6 @@ riscv_hdrs = \
memtracer.h \
extension.h \
rocc.h \
dummy-rocc.h \
insn_template.h \
mulhi.h \

37
spike/extensions.cc

@ -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];
}

9
riscv/riscv-dis.cc → spike/riscv-dis.cc

@ -21,14 +21,7 @@ int main(int argc, char** argv)
std::function<extension_t*()> extension;
option_parser_t parser;
parser.option(0, "extension", 1, [&](const char* s){
if (!extensions().count(s))
fprintf(stderr, "unknown extension %s!\n", s), exit(-1);
extension = extensions()[s];
for (auto disasm_insn : extension()->get_disasms())
d.add_insn(disasm_insn);
});
parser.option(0, "extension", 1, [&](const char* s){extension = find_extension(s);});
while (getline(cin, s))
{

6
spike/spike.cc

@ -51,11 +51,7 @@ int main(int argc, char** argv)
parser.option(0, "ic", 1, [&](const char* s){ic.reset(new icache_sim_t(s));});
parser.option(0, "dc", 1, [&](const char* s){dc.reset(new dcache_sim_t(s));});
parser.option(0, "l2", 1, [&](const char* s){l2.reset(cache_sim_t::construct(s, "L2$"));});
parser.option(0, "extension", 1, [&](const char* s){
if (!extensions().count(s))
fprintf(stderr, "unknown extension %s!\n", s), exit(-1);
extension = extensions()[s];
});
parser.option(0, "extension", 1, [&](const char* s){extension = find_extension(s);});
parser.option(0, "extlib", 1, [&](const char *s){
void *lib = dlopen(s, RTLD_NOW | RTLD_GLOBAL);
if (lib == NULL) {

3
spike/spike.mk.in

@ -1,7 +1,6 @@
spike_subproject_deps = \
softfloat \
riscv \
hwacha \
softfloat \
spike_install_prog_srcs = \
spike.cc \

Loading…
Cancel
Save