aboutsummaryrefslogtreecommitdiff
path: root/pk/emulation.h
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@cs.berkeley.edu>2016-03-04 21:02:42 -0800
committerAndrew Waterman <waterman@cs.berkeley.edu>2016-03-04 21:02:42 -0800
commitbbc9a65fed7c85ee058d7188a62f0b904c38b77b (patch)
tree004716e7b7a0ff50cd7ca80b0e6e5b035b96df98 /pk/emulation.h
parent82dcccf73c7be17415a7e84fc872c9627ee275fc (diff)
downloadriscv-pk-bbc9a65fed7c85ee058d7188a62f0b904c38b77b.zip
riscv-pk-bbc9a65fed7c85ee058d7188a62f0b904c38b77b.tar.gz
riscv-pk-bbc9a65fed7c85ee058d7188a62f0b904c38b77b.tar.bz2
Begin refactoring emulation code
Diffstat (limited to 'pk/emulation.h')
-rw-r--r--pk/emulation.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/pk/emulation.h b/pk/emulation.h
new file mode 100644
index 0000000..f1a71ec
--- /dev/null
+++ b/pk/emulation.h
@@ -0,0 +1,28 @@
+#ifndef _RISCV_EMULATION_H
+#define _RISCV_EMULATION_H
+
+#include "encoding.h"
+#include "bits.h"
+#include <stdint.h>
+
+typedef uint32_t insn_t;
+typedef void (*emulation_func)(uintptr_t*, uintptr_t, uintptr_t, uintptr_t, insn_t);
+#define DECLARE_EMULATION_FUNC(name) void name(uintptr_t* regs, uintptr_t mcause, uintptr_t mepc, uintptr_t mstatus, insn_t insn)
+
+void misaligned_load_trap(uintptr_t* regs, uintptr_t mcause, uintptr_t mepc);
+void misaligned_store_trap(uintptr_t* regs, uintptr_t mcause, uintptr_t mepc);
+void redirect_trap(uintptr_t epc, uintptr_t mstatus);
+DECLARE_EMULATION_FUNC(truly_illegal_insn);
+
+#define GET_REG(insn, pos, regs) ({ \
+ int mask = (1 << (5+LOG_REGBYTES)) - (1 << LOG_REGBYTES); \
+ (uintptr_t*)((uintptr_t)regs + (((insn) >> ((pos) - LOG_REGBYTES)) & mask)); \
+})
+#define GET_RS1(insn, regs) (*GET_REG(insn, 15, regs))
+#define GET_RS2(insn, regs) (*GET_REG(insn, 20, regs))
+#define SET_RD(insn, regs, val) (*GET_REG(insn, 7, regs) = (val))
+#define IMM_I(insn) ((int32_t)(insn) >> 20)
+#define IMM_S(insn) (((int32_t)(insn) >> 25 << 5) | (int32_t)(((insn) >> 7) & 0x1f))
+#define MASK_FUNCT3 0x7000
+
+#endif