add hwacha exception support
[riscv-isa-sim.git] / hwacha / decode_hwacha_ut.h
index 675f77cc7e8a1a6ea47efae5e2dc0d03358c37c0..daad217a32e164468dd9e7ef02b8d0b2bfde4959 100644 (file)
@@ -1,7 +1,10 @@
 #ifndef _DECODE_HWACHA_UT_H
 #define _DECODE_HWACHA_UT_H
 
+#include "decode.h"
 #include "decode_hwacha.h"
+#include "hwacha.h"
+#include "hwacha_xcpt.h"
 
 #define UTIDX (i)
 
 #undef RS2
 #undef WRITE_RD
 
-#define RS1 UT_RS1(UTIDX)
-#define RS2 UT_RS2(UTIDX)
-#define WRITE_RD(value) UT_WRITE_RD(UTIDX, value)
+static inline reg_t read_rs1(hwacha_t* h, insn_t insn, uint32_t idx)
+{
+  if (INSN_RS1 >= h->get_ct_state()->nxpr)
+    h->take_exception(HWACHA_CAUSE_VF_ILLEGAL_REGID, VF_PC);
+  return UT_RS1(idx);
+}
+
+static inline reg_t read_rs2(hwacha_t* h, insn_t insn, uint32_t idx)
+{
+  if (INSN_RS2 >= h->get_ct_state()->nxpr)
+    h->take_exception(HWACHA_CAUSE_VF_ILLEGAL_REGID, VF_PC);
+  return UT_RS2(idx);
+}
+
+static inline void write_rd(hwacha_t* h, insn_t insn, uint32_t idx, reg_t value)
+{
+  if (INSN_RD >= h->get_ct_state()->nxpr)
+    h->take_exception(HWACHA_CAUSE_VF_ILLEGAL_REGID, VF_PC);
+  UT_WRITE_RD(idx, value);
+}
+
+#define RS1 read_rs1(h, insn, UTIDX)
+#define RS2 read_rs2(h, insn, UTIDX)
+#define WRITE_RD(value) write_rd(h, insn, UTIDX, value)
 
 #undef FRS1
 #undef FRS2
 #undef FRS3
 #undef WRITE_FRD
 
-#define FRS1 UT_FRS1(UTIDX)
-#define FRS2 UT_FRS2(UTIDX)
-#define FRS3 UT_FRS3(UTIDX)
-#define WRITE_FRD(value) UT_WRITE_FRD(UTIDX, value)
+static inline reg_t read_frs1(hwacha_t* h, insn_t insn, uint32_t idx)
+{
+  if (INSN_RS1 >= h->get_ct_state()->nfpr)
+    h->take_exception(HWACHA_CAUSE_VF_ILLEGAL_REGID, VF_PC);
+  return UT_FRS1(idx);
+}
+
+static inline reg_t read_frs2(hwacha_t* h, insn_t insn, uint32_t idx)
+{
+  if (INSN_RS2 >= h->get_ct_state()->nfpr)
+    h->take_exception(HWACHA_CAUSE_VF_ILLEGAL_REGID, VF_PC);
+  return UT_FRS2(idx);
+}
+
+static inline reg_t read_frs3(hwacha_t* h, insn_t insn, uint32_t idx)
+{
+  if (INSN_RS3 >= h->get_ct_state()->nfpr)
+    h->take_exception(HWACHA_CAUSE_VF_ILLEGAL_REGID, VF_PC);
+  return UT_FRS3(idx);
+}
+
+static inline void write_frd(hwacha_t* h, insn_t insn, uint32_t idx, reg_t value)
+{
+  if (INSN_RD >= h->get_ct_state()->nfpr)
+    h->take_exception(HWACHA_CAUSE_VF_ILLEGAL_REGID, VF_PC);
+  UT_WRITE_FRD(idx, value);
+}
+
+#define FRS1 read_frs1(h, insn, UTIDX)
+#define FRS2 read_frs2(h, insn, UTIDX)
+#define FRS3 read_frs3(h, insn, UTIDX)
+#define WRITE_FRD(value) write_frd(h, insn, UTIDX, value)
 
 // we assume the vector unit has floating-point alus
 #undef require_fp