From e85cb99c5e042ebce78f64213677a48ee7ba0491 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Mon, 9 Dec 2013 15:55:52 -0800 Subject: [PATCH] New RDCYCLE encoding --- riscv/decode.h | 5 +++-- riscv/disasm.cc | 16 ++++++++-------- riscv/encoding.h | 44 ++++++++++++++++++++++---------------------- riscv/insns/csrrc.h | 2 +- riscv/insns/csrrci.h | 2 +- riscv/insns/csrrs.h | 2 +- riscv/insns/csrrsi.h | 2 +- riscv/insns/csrrw.h | 2 +- riscv/insns/csrrwi.h | 2 +- 9 files changed, 39 insertions(+), 38 deletions(-) diff --git a/riscv/decode.h b/riscv/decode.h index 2229afb..8e506e2 100644 --- a/riscv/decode.h +++ b/riscv/decode.h @@ -62,6 +62,7 @@ public: 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); } @@ -167,8 +168,8 @@ private: } 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); }) diff --git a/riscv/disasm.cc b/riscv/disasm.cc index 7d5a8e2..f81d702 100644 --- a/riscv/disasm.cc +++ b/riscv/disasm.cc @@ -83,7 +83,7 @@ struct : public arg_t { 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" @@ -296,13 +296,13 @@ disassembler_t::disassembler_t() 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); diff --git a/riscv/encoding.h b/riscv/encoding.h index 92accfe..48a0108 100644 --- a/riscv/encoding.h +++ b/riscv/encoding.h @@ -412,32 +412,32 @@ #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) @@ -597,30 +597,30 @@ DECLARE_INSN(fmsub_d, MATCH_FMSUB_D, MASK_FMSUB_D) 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 diff --git a/riscv/insns/csrrc.h b/riscv/insns/csrrc.h index 636c3f8..8ca7c41 100644 --- a/riscv/insns/csrrc.h +++ b/riscv/insns/csrrc.h @@ -1,2 +1,2 @@ -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)); diff --git a/riscv/insns/csrrci.h b/riscv/insns/csrrci.h index d671f3b..fc98056 100644 --- a/riscv/insns/csrrci.h +++ b/riscv/insns/csrrci.h @@ -1,2 +1,2 @@ -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())); diff --git a/riscv/insns/csrrs.h b/riscv/insns/csrrs.h index fff9f23..60ac6b3 100644 --- a/riscv/insns/csrrs.h +++ b/riscv/insns/csrrs.h @@ -1,2 +1,2 @@ -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)); diff --git a/riscv/insns/csrrsi.h b/riscv/insns/csrrsi.h index 99d323b..db6fcd0 100644 --- a/riscv/insns/csrrsi.h +++ b/riscv/insns/csrrsi.h @@ -1,2 +1,2 @@ -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())); diff --git a/riscv/insns/csrrw.h b/riscv/insns/csrrw.h index fbccb77..4b16773 100644 --- a/riscv/insns/csrrw.h +++ b/riscv/insns/csrrw.h @@ -1,2 +1,2 @@ -int csr = validate_csr(insn.i_imm(), true); +int csr = validate_csr(insn.csr(), true); WRITE_RD(p->set_pcr(csr, RS1)); diff --git a/riscv/insns/csrrwi.h b/riscv/insns/csrrwi.h index 840150e..ff20833 100644 --- a/riscv/insns/csrrwi.h +++ b/riscv/insns/csrrwi.h @@ -1,2 +1,2 @@ -int csr = validate_csr(insn.i_imm(), true); +int csr = validate_csr(insn.csr(), true); WRITE_RD(p->set_pcr(csr, insn.rs1())); -- 2.30.2