aboutsummaryrefslogtreecommitdiff
path: root/customext/dummy_rocc.cc
diff options
context:
space:
mode:
authorChih-Min Chao <chihmin.chao@sifive.com>2020-06-08 00:36:37 -0700
committerChih-Min Chao <chihmin.chao@sifive.com>2020-06-10 11:40:57 -0700
commitfefd356697bbbe732c22b0e6dc6121b8aeca2946 (patch)
tree71eb390d092e7615e3ddcbd204a5760372fbe35a /customext/dummy_rocc.cc
parent33a6eb57564c257037780ddd2691ca621c44a55b (diff)
downloadriscv-isa-sim-fefd356697bbbe732c22b0e6dc6121b8aeca2946.zip
riscv-isa-sim-fefd356697bbbe732c22b0e6dc6121b8aeca2946.tar.gz
riscv-isa-sim-fefd356697bbbe732c22b0e6dc6121b8aeca2946.tar.bz2
ext: rename libdummy_rocc by libcustomext
make library name general for multiple custom extension built in one shared library. Signed-off-by: Chih-Min Chao <chihmin.chao@sifive.com>
Diffstat (limited to 'customext/dummy_rocc.cc')
-rw-r--r--customext/dummy_rocc.cc47
1 files changed, 47 insertions, 0 deletions
diff --git a/customext/dummy_rocc.cc b/customext/dummy_rocc.cc
new file mode 100644
index 0000000..85ab7aa
--- /dev/null
+++ b/customext/dummy_rocc.cc
@@ -0,0 +1,47 @@
+#include "rocc.h"
+#include "mmu.h"
+#include <cstring>
+
+class dummy_rocc_t : public rocc_t
+{
+ public:
+ 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)
+ illegal_instruction();
+
+ switch (insn.funct)
+ {
+ case 0: // acc <- xs1
+ acc[insn.rs2] = xs1;
+ break;
+ case 1: // xd <- acc (the only real work is the return statement below)
+ break;
+ case 2: // acc[rs2] <- Mem[xs1]
+ acc[insn.rs2] = p->get_mmu()->load_uint64(xs1);
+ break;
+ case 3: // acc[rs2] <- accX + xs1
+ acc[insn.rs2] += xs1;
+ break;
+ default:
+ illegal_instruction();
+ }
+
+ return prev_acc; // in all cases, xd <- previous value of acc[rs2]
+ }
+
+ dummy_rocc_t()
+ {
+ memset(acc, 0, sizeof(acc));
+ }
+
+ private:
+ static const int num_acc = 4;
+ reg_t acc[num_acc];
+};
+
+REGISTER_EXTENSION(dummy_rocc, []() { return new dummy_rocc_t; })