uint32_t rs2() { return x(20, 5); }
uint32_t rs3() { return x(27, 5); }
uint32_t rm() { return x(12, 3); }
+ reg_t csr() { return x(20, 12); }
private:
uint32_t b;
reg_t x(int lo, int len) { return b << (32-lo-len) >> (32-len); }
} while(0)
#define validate_csr(which, write) ({ \
- int read_priv = ((which) >> 10) & 3; \
- int write_priv = ((which) >> 8) & 3; \
+ int write_priv = ((which) >> 10) & 3; \
+ int read_priv = ((which) >> 8) & 3; \
if (read_priv > 0 || (write_priv > 0 && (write))) require_supervisor; \
(which); })
struct : public arg_t {
std::string to_string(insn_t insn) const {
- switch (insn.i_imm())
+ switch (insn.csr())
{
#define DECLARE_CSR(name, num) case num: return #name;
#include "encoding.h"
DEFINE_NOARG(fence_i);
add_insn(new disasm_insn_t("csrr", match_csrrs, mask_csrrs | mask_rs1, {&xrd, &csr}));
- add_insn(new disasm_insn_t("csrw", match_csrrw, mask_csrrw | mask_rd, {&xrs1, &csr}));
- add_insn(new disasm_insn_t("csrrw", match_csrrw, mask_csrrw, {&xrd, &xrs1, &csr}));
- add_insn(new disasm_insn_t("csrrs", match_csrrs, mask_csrrs, {&xrd, &xrs1, &csr}));
- add_insn(new disasm_insn_t("csrrc", match_csrrc, mask_csrrc, {&xrd, &xrs1, &csr}));
- add_insn(new disasm_insn_t("csrrwi", match_csrrwi, mask_csrrwi, {&xrd, &zimm5, &csr}));
- add_insn(new disasm_insn_t("csrrsi", match_csrrsi, mask_csrrsi, {&xrd, &zimm5, &csr}));
- add_insn(new disasm_insn_t("csrrci", match_csrrci, mask_csrrci, {&xrd, &zimm5, &csr}));
+ add_insn(new disasm_insn_t("csrw", match_csrrw, mask_csrrw | mask_rd, {&csr, &xrs1}));
+ add_insn(new disasm_insn_t("csrrw", match_csrrw, mask_csrrw, {&xrd, &csr, &xrs1}));
+ add_insn(new disasm_insn_t("csrrs", match_csrrs, mask_csrrs, {&xrd, &csr, &xrs1}));
+ add_insn(new disasm_insn_t("csrrc", match_csrrc, mask_csrrc, {&xrd, &csr, &xrs1}));
+ add_insn(new disasm_insn_t("csrrwi", match_csrrwi, mask_csrrwi, {&xrd, &csr, &zimm5}));
+ add_insn(new disasm_insn_t("csrrsi", match_csrrsi, mask_csrrsi, {&xrd, &csr, &zimm5}));
+ add_insn(new disasm_insn_t("csrrci", match_csrrci, mask_csrrci, {&xrd, &csr, &zimm5}));
DEFINE_NOARG(sret)
DEFINE_FRTYPE(fadd_s);
#define MASK_FMSUB_D 0x600007f
#define MATCH_SD 0x3023
#define MASK_SD 0x707f
-#define CSR_SUP0 0x500
#define CSR_FFLAGS 0x1
#define CSR_FRM 0x2
#define CSR_FCSR 0x3
-#define CSR_CYCLE 0x4
-#define CSR_TIME 0x5
-#define CSR_INSTRET 0x6
+#define CSR_SUP0 0x500
#define CSR_SUP1 0x501
+#define CSR_EPC 0x502
+#define CSR_BADVADDR 0x503
+#define CSR_PTBR 0x504
+#define CSR_ASID 0x505
+#define CSR_COUNT 0x506
+#define CSR_COMPARE 0x507
#define CSR_EVEC 0x508
#define CSR_CAUSE 0x509
#define CSR_STATUS 0x50a
#define CSR_HARTID 0x50b
#define CSR_IMPL 0x50c
-#define CSR_EPC 0x502
+#define CSR_FATC 0x50d
#define CSR_SEND_IPI 0x50e
#define CSR_CLEAR_IPI 0x50f
-#define CSR_BADVADDR 0x503
-#define CSR_PTBR 0x504
#define CSR_STATS 0x51c
#define CSR_RESET 0x51d
#define CSR_TOHOST 0x51e
-#define CSR_ASID 0x505
-#define CSR_COUNT 0x506
-#define CSR_COMPARE 0x507
#define CSR_FROMHOST 0x51f
-#define CSR_FATC 0x50d
+#define CSR_CYCLE 0xc00
+#define CSR_TIME 0xc01
+#define CSR_INSTRET 0xc02
#endif
#ifdef DECLARE_INSN
DECLARE_INSN(fmv_s_x, MATCH_FMV_S_X, MASK_FMV_S_X)
DECLARE_INSN(sd, MATCH_SD, MASK_SD)
#endif
#ifdef DECLARE_CSR
-DECLARE_CSR(sup0, CSR_SUP0)
DECLARE_CSR(fflags, CSR_FFLAGS)
DECLARE_CSR(frm, CSR_FRM)
DECLARE_CSR(fcsr, CSR_FCSR)
-DECLARE_CSR(cycle, CSR_CYCLE)
-DECLARE_CSR(time, CSR_TIME)
-DECLARE_CSR(instret, CSR_INSTRET)
+DECLARE_CSR(sup0, CSR_SUP0)
DECLARE_CSR(sup1, CSR_SUP1)
+DECLARE_CSR(epc, CSR_EPC)
+DECLARE_CSR(badvaddr, CSR_BADVADDR)
+DECLARE_CSR(ptbr, CSR_PTBR)
+DECLARE_CSR(asid, CSR_ASID)
+DECLARE_CSR(count, CSR_COUNT)
+DECLARE_CSR(compare, CSR_COMPARE)
DECLARE_CSR(evec, CSR_EVEC)
DECLARE_CSR(cause, CSR_CAUSE)
DECLARE_CSR(status, CSR_STATUS)
DECLARE_CSR(hartid, CSR_HARTID)
DECLARE_CSR(impl, CSR_IMPL)
-DECLARE_CSR(epc, CSR_EPC)
+DECLARE_CSR(fatc, CSR_FATC)
DECLARE_CSR(send_ipi, CSR_SEND_IPI)
DECLARE_CSR(clear_ipi, CSR_CLEAR_IPI)
-DECLARE_CSR(badvaddr, CSR_BADVADDR)
-DECLARE_CSR(ptbr, CSR_PTBR)
DECLARE_CSR(stats, CSR_STATS)
DECLARE_CSR(reset, CSR_RESET)
DECLARE_CSR(tohost, CSR_TOHOST)
-DECLARE_CSR(asid, CSR_ASID)
-DECLARE_CSR(count, CSR_COUNT)
-DECLARE_CSR(compare, CSR_COMPARE)
DECLARE_CSR(fromhost, CSR_FROMHOST)
-DECLARE_CSR(fatc, CSR_FATC)
+DECLARE_CSR(cycle, CSR_CYCLE)
+DECLARE_CSR(time, CSR_TIME)
+DECLARE_CSR(instret, CSR_INSTRET)
#endif
-int csr = validate_csr(insn.i_imm(), true);
+int csr = validate_csr(insn.csr(), true);
WRITE_RD(p->set_pcr(csr, p->get_pcr(csr) & ~RS1));
-int csr = validate_csr(insn.i_imm(), true);
+int csr = validate_csr(insn.csr(), true);
WRITE_RD(p->set_pcr(csr, p->get_pcr(csr) & ~(reg_t)insn.rs1()));
-int csr = validate_csr(insn.i_imm(), insn.rs1() != 0);
+int csr = validate_csr(insn.csr(), insn.rs1() != 0);
WRITE_RD(p->set_pcr(csr, p->get_pcr(csr) | RS1));
-int csr = validate_csr(insn.i_imm(), true);
+int csr = validate_csr(insn.csr(), true);
WRITE_RD(p->set_pcr(csr, p->get_pcr(csr) | insn.rs1()));
-int csr = validate_csr(insn.i_imm(), true);
+int csr = validate_csr(insn.csr(), true);
WRITE_RD(p->set_pcr(csr, RS1));
-int csr = validate_csr(insn.i_imm(), true);
+int csr = validate_csr(insn.csr(), true);
WRITE_RD(p->set_pcr(csr, insn.rs1()));