aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@cs.berkeley.edu>2013-07-26 04:15:57 -0700
committerAndrew Waterman <waterman@cs.berkeley.edu>2013-07-26 04:15:57 -0700
commit5a97139eeecac32b8127393be7fcdb23a8e98ff6 (patch)
tree610f3be4d6d45ddc02f7df9f6cc0545094b0f79f
parent0de1489e8ab4a527fbcb1440a8fd5b2d4c8c9260 (diff)
downloadriscv-isa-sim-5a97139eeecac32b8127393be7fcdb23a8e98ff6.zip
riscv-isa-sim-5a97139eeecac32b8127393be7fcdb23a8e98ff6.tar.gz
riscv-isa-sim-5a97139eeecac32b8127393be7fcdb23a8e98ff6.tar.bz2
Rip out RVC for now
-rw-r--r--riscv/decode.h38
-rw-r--r--riscv/mmu.h59
-rw-r--r--riscv/opcodes.h34
-rw-r--r--riscv/processor.cc2
-rw-r--r--riscv/processor.h14
-rw-r--r--rvc/README2
-rw-r--r--rvc/insns/c_add.h (renamed from riscv/insns/c_add.h)0
-rw-r--r--rvc/insns/c_add3.h (renamed from riscv/insns/c_add3.h)0
-rw-r--r--rvc/insns/c_addi.h (renamed from riscv/insns/c_addi.h)0
-rw-r--r--rvc/insns/c_addiw.h (renamed from riscv/insns/c_addiw.h)0
-rw-r--r--rvc/insns/c_and3.h (renamed from riscv/insns/c_and3.h)0
-rw-r--r--rvc/insns/c_beq.h (renamed from riscv/insns/c_beq.h)0
-rw-r--r--rvc/insns/c_bne.h (renamed from riscv/insns/c_bne.h)0
-rw-r--r--rvc/insns/c_fld.h (renamed from riscv/insns/c_fld.h)0
-rw-r--r--rvc/insns/c_flw.h (renamed from riscv/insns/c_flw.h)0
-rw-r--r--rvc/insns/c_fsd.h (renamed from riscv/insns/c_fsd.h)0
-rw-r--r--rvc/insns/c_fsw.h (renamed from riscv/insns/c_fsw.h)0
-rw-r--r--rvc/insns/c_j.h (renamed from riscv/insns/c_j.h)0
-rw-r--r--rvc/insns/c_ld.h (renamed from riscv/insns/c_ld.h)0
-rw-r--r--rvc/insns/c_ld0.h (renamed from riscv/insns/c_ld0.h)0
-rw-r--r--rvc/insns/c_ldsp.h (renamed from riscv/insns/c_ldsp.h)0
-rw-r--r--rvc/insns/c_li.h (renamed from riscv/insns/c_li.h)0
-rw-r--r--rvc/insns/c_lw.h (renamed from riscv/insns/c_lw.h)0
-rw-r--r--rvc/insns/c_lw0.h (renamed from riscv/insns/c_lw0.h)0
-rw-r--r--rvc/insns/c_lwsp.h (renamed from riscv/insns/c_lwsp.h)0
-rw-r--r--rvc/insns/c_move.h (renamed from riscv/insns/c_move.h)0
-rw-r--r--rvc/insns/c_or3.h (renamed from riscv/insns/c_or3.h)0
-rw-r--r--rvc/insns/c_sd.h (renamed from riscv/insns/c_sd.h)0
-rw-r--r--rvc/insns/c_sdsp.h (renamed from riscv/insns/c_sdsp.h)0
-rw-r--r--rvc/insns/c_slli.h (renamed from riscv/insns/c_slli.h)0
-rw-r--r--rvc/insns/c_slli32.h (renamed from riscv/insns/c_slli32.h)0
-rw-r--r--rvc/insns/c_slliw.h (renamed from riscv/insns/c_slliw.h)0
-rw-r--r--rvc/insns/c_srai.h (renamed from riscv/insns/c_srai.h)0
-rw-r--r--rvc/insns/c_srai32.h (renamed from riscv/insns/c_srai32.h)0
-rw-r--r--rvc/insns/c_srli.h (renamed from riscv/insns/c_srli.h)0
-rw-r--r--rvc/insns/c_srli32.h (renamed from riscv/insns/c_srli32.h)0
-rw-r--r--rvc/insns/c_sub.h (renamed from riscv/insns/c_sub.h)0
-rw-r--r--rvc/insns/c_sub3.h (renamed from riscv/insns/c_sub3.h)0
-rw-r--r--rvc/insns/c_sw.h (renamed from riscv/insns/c_sw.h)0
-rw-r--r--rvc/insns/c_swsp.h (renamed from riscv/insns/c_swsp.h)0
-rw-r--r--rvc/rvc.h30
41 files changed, 61 insertions, 118 deletions
diff --git a/riscv/decode.h b/riscv/decode.h
index be7d64d..7c99581 100644
--- a/riscv/decode.h
+++ b/riscv/decode.h
@@ -223,33 +223,17 @@ private:
#define sext_xprlen(x) (((sreg_t)(x) << (64-xprlen)) >> (64-xprlen))
#define zext_xprlen(x) (((reg_t)(x) << (64-xprlen)) >> (64-xprlen))
-// RVC stuff
-
-#define INSN_IS_RVC(x) (((x) & 0x3) < 0x3)
-#define insn_length(x) (INSN_IS_RVC(x) ? 2 : 4)
-#define require_rvc if(!(sr & SR_EC)) throw_illegal_instruction
-
-#define CRD_REGNUM ((insn.bits >> 5) & 0x1f)
-#define CRD XPR.write_port(CRD_REGNUM)
-#define CRS1 XPR[(insn.bits >> 10) & 0x1f]
-#define CRS2 XPR[(insn.bits >> 5) & 0x1f]
-#define CIMM6 ((int32_t)((insn.bits >> 10) & 0x3f) << 26 >> 26)
-#define CIMM5U ((insn.bits >> 5) & 0x1f)
-#define CIMM5 ((int32_t)CIMM5U << 27 >> 27)
-#define CIMM10 ((int32_t)((insn.bits >> 5) & 0x3ff) << 22 >> 22)
-#define CBRANCH_TARGET (pc + (CIMM5 << BRANCH_ALIGN_BITS))
-#define CJUMP_TARGET (pc + (CIMM10 << JUMP_ALIGN_BITS))
-
-static const int rvc_rs1_regmap[8] = { 20, 21, 2, 3, 4, 5, 6, 7 };
-#define rvc_rd_regmap rvc_rs1_regmap
-#define rvc_rs2b_regmap rvc_rs1_regmap
-static const int rvc_rs2_regmap[8] = { 20, 21, 2, 3, 4, 5, 6, 0 };
-#define CRDS XPR.write_port(rvc_rd_regmap[(insn.bits >> 13) & 0x7])
-#define FCRDS FPR.write_port(rvc_rd_regmap[(insn.bits >> 13) & 0x7])
-#define CRS1S XPR[rvc_rs1_regmap[(insn.bits >> 10) & 0x7]]
-#define CRS2S XPR[rvc_rs2_regmap[(insn.bits >> 13) & 0x7]]
-#define CRS2BS XPR[rvc_rs2b_regmap[(insn.bits >> 5) & 0x7]]
-#define FCRS2S FPR[rvc_rs2_regmap[(insn.bits >> 13) & 0x7]]
+#define insn_length(x) \
+ (((x) & 0x03) < 0x03 ? 2 : \
+ ((x) & 0x1f) < 0x1f ? 4 : \
+ ((x) & 0x3f) < 0x3f ? 6 : \
+ 8)
+
+#define set_pc(x) \
+ do { if ((x) & 3 /* For now... */) \
+ throw trap_instruction_address_misaligned; \
+ npc = (x); \
+ } while(0)
// vector stuff
#define VL vl
diff --git a/riscv/mmu.h b/riscv/mmu.h
index 9e1218c..49a5f0b 100644
--- a/riscv/mmu.h
+++ b/riscv/mmu.h
@@ -102,54 +102,30 @@ public:
};
// load instruction from memory at aligned address.
- // (needed because instruction alignment requirement is variable
- // if RVC is supported)
- // returns the instruction at the specified address, given the current
- // RVC mode. func is set to a pointer to a function that knows how to
- // execute the returned instruction.
- inline insn_fetch_t load_insn(reg_t addr, bool rvc)
+ inline insn_fetch_t load_insn(reg_t addr)
{
- #ifdef RISCV_ENABLE_RVC
- if(addr % 4 == 2 && rvc) // fetch across word boundary
+#ifdef RISCV_ENABLE_RVC
+# error TODO: Make MMU instruction cache support 2-byte alignment
+#endif
+ reg_t idx = (addr/sizeof(insn_t::itype)) % ICACHE_ENTRIES;
+ if (unlikely(icache_tag[idx] != addr))
{
- reg_t addr_lo = translate(addr, 2, false, true);
+ reg_t paddr = translate(addr, sizeof(insn_t::itype), false, true);
insn_fetch_t fetch;
- fetch.insn.bits = *(uint16_t*)(mem + addr_lo);
+ fetch.insn.itype = *(decltype(insn_t::itype)*)(mem + paddr);
fetch.func = proc->decode_insn(fetch.insn);
- if(!INSN_IS_RVC(fetch.insn.bits))
- {
- reg_t addr_hi = translate(addr+2, 2, false, true);
- fetch.insn.bits |= (uint32_t)*(uint16_t*)(mem + addr_hi) << 16;
- }
- return fetch;
- }
- else
- #endif
- {
- reg_t idx = (addr/sizeof(insn_t::itype)) % ICACHE_ENTRIES;
- insn_fetch_t fetch;
- if (unlikely(icache_tag[idx] != addr))
+ reg_t idx = (paddr/sizeof(insn_t::itype)) % ICACHE_ENTRIES;
+ icache_tag[idx] = addr;
+ icache_data[idx] = fetch;
+
+ if (tracer.interested_in_range(paddr, paddr + sizeof(insn_t::itype), false, true))
{
- reg_t paddr = translate(addr, sizeof(insn_t::itype), false, true);
- fetch.insn.itype = *(decltype(insn_t::itype)*)(mem + paddr);
- fetch.func = proc->decode_insn(fetch.insn);
-
- reg_t idx = (paddr/sizeof(insn_t::itype)) % ICACHE_ENTRIES;
- icache_tag[idx] = addr;
- icache_data[idx] = fetch.insn;
- icache_func[idx] = fetch.func;
-
- if (tracer.interested_in_range(paddr, paddr + sizeof(insn_t::itype), false, true))
- {
- icache_tag[idx] = -1;
- tracer.trace(paddr, sizeof(insn_t::itype), false, true);
- }
+ icache_tag[idx] = -1;
+ tracer.trace(paddr, sizeof(insn_t::itype), false, true);
}
- fetch.insn = icache_data[idx];
- fetch.func = icache_func[idx];
- return fetch;
}
+ return icache_data[idx];
}
reg_t get_badvaddr() { return badvaddr; }
@@ -174,8 +150,7 @@ private:
// implement an instruction cache for simulator performance
static const reg_t ICACHE_ENTRIES = 256;
- insn_t icache_data[ICACHE_ENTRIES];
- insn_func_t icache_func[ICACHE_ENTRIES];
+ insn_fetch_t icache_data[ICACHE_ENTRIES];
// implement a TLB for simulator performance
static const reg_t TLB_ENTRIES = 256;
diff --git a/riscv/opcodes.h b/riscv/opcodes.h
index aaf8e67..f18aebd 100644
--- a/riscv/opcodes.h
+++ b/riscv/opcodes.h
@@ -8,10 +8,7 @@ DECLARE_INSN(bltu, 0x363, 0x3ff)
DECLARE_INSN(vlsegstwu, 0xb0b, 0xfff)
DECLARE_INSN(vvcfg, 0x473, 0xf801ffff)
DECLARE_INSN(movz, 0x2f7, 0x1ffff)
-DECLARE_INSN(c_ld, 0x9, 0x1f)
-DECLARE_INSN(c_srli32, 0xc19, 0x1c1f)
DECLARE_INSN(fmin_s, 0x18053, 0x1ffff)
-DECLARE_INSN(c_lw0, 0x12, 0x801f)
DECLARE_INSN(slliw, 0x9b, 0x3f83ff)
DECLARE_INSN(lb, 0x3, 0x3ff)
DECLARE_INSN(vlwu, 0x30b, 0x3fffff)
@@ -23,7 +20,6 @@ DECLARE_INSN(lw, 0x103, 0x3ff)
DECLARE_INSN(add, 0x33, 0x1ffff)
DECLARE_INSN(fcvt_d_s, 0x100d3, 0x3ff1ff)
DECLARE_INSN(mfpcr, 0x17b, 0x3fffff)
-DECLARE_INSN(c_fsd, 0x18, 0x1f)
DECLARE_INSN(fmax_d, 0x190d3, 0x1ffff)
DECLARE_INSN(bne, 0xe3, 0x3ff)
DECLARE_INSN(rdcycle, 0x277, 0x7ffffff)
@@ -31,30 +27,22 @@ DECLARE_INSN(fcvt_s_d, 0x11053, 0x3ff1ff)
DECLARE_INSN(vlh, 0x8b, 0x3fffff)
DECLARE_INSN(bgeu, 0x3e3, 0x3ff)
DECLARE_INSN(vflstd, 0x158b, 0x1ffff)
-DECLARE_INSN(c_li, 0x0, 0x1f)
DECLARE_INSN(fadd_d, 0xd3, 0x1f1ff)
DECLARE_INSN(sltiu, 0x193, 0x3ff)
DECLARE_INSN(mtpcr, 0x1fb, 0x1ffff)
DECLARE_INSN(vlb, 0xb, 0x3fffff)
DECLARE_INSN(stop, 0x177, 0xffffffff)
DECLARE_INSN(vld, 0x18b, 0x3fffff)
-DECLARE_INSN(c_slli, 0x19, 0x1c1f)
DECLARE_INSN(break, 0xf7, 0xffffffff)
DECLARE_INSN(fcvt_s_w, 0xe053, 0x3ff1ff)
DECLARE_INSN(vflstw, 0x150b, 0x1ffff)
DECLARE_INSN(mul, 0x433, 0x1ffff)
-DECLARE_INSN(c_lw, 0xa, 0x1f)
DECLARE_INSN(vxcptevac, 0x237b, 0xf83fffff)
DECLARE_INSN(vlw, 0x10b, 0x3fffff)
DECLARE_INSN(vssegstw, 0x90f, 0xfff)
DECLARE_INSN(amominu_d, 0x19ab, 0x1ffff)
-DECLARE_INSN(c_sdsp, 0x6, 0x1f)
DECLARE_INSN(mftx_d, 0x1c0d3, 0x3fffff)
DECLARE_INSN(srli, 0x293, 0x3f03ff)
-DECLARE_INSN(c_srli, 0x819, 0x1c1f)
-DECLARE_INSN(c_ldsp, 0x4, 0x1f)
-DECLARE_INSN(c_flw, 0x14, 0x1f)
-DECLARE_INSN(c_srai32, 0x1419, 0x1c1f)
DECLARE_INSN(amominu_w, 0x192b, 0x1ffff)
DECLARE_INSN(divuw, 0x6bb, 0x1ffff)
DECLARE_INSN(mulw, 0x43b, 0x1ffff)
@@ -118,10 +106,8 @@ DECLARE_INSN(amoand_w, 0x92b, 0x1ffff)
DECLARE_INSN(feq_s, 0x15053, 0x1ffff)
DECLARE_INSN(fsgnjx_d, 0x70d3, 0x1ffff)
DECLARE_INSN(sra, 0x102b3, 0x1ffff)
-DECLARE_INSN(c_lwsp, 0x5, 0x1f)
DECLARE_INSN(bge, 0x2e3, 0x3ff)
DECLARE_INSN(venqimm2, 0x337b, 0xf801ffff)
-DECLARE_INSN(c_add3, 0x1c, 0x31f)
DECLARE_INSN(sraiw, 0x1029b, 0x3f83ff)
DECLARE_INSN(vssegd, 0x218f, 0x1ffff)
DECLARE_INSN(srl, 0x2b3, 0x1ffff)
@@ -139,11 +125,8 @@ DECLARE_INSN(or, 0x333, 0x1ffff)
DECLARE_INSN(rdinstret, 0xa77, 0x7ffffff)
DECLARE_INSN(fcvt_wu_d, 0xb0d3, 0x3ff1ff)
DECLARE_INSN(subw, 0x1003b, 0x1ffff)
-DECLARE_INSN(c_swsp, 0x8, 0x1f)
DECLARE_INSN(fmax_s, 0x19053, 0x1ffff)
DECLARE_INSN(amomaxu_d, 0x1dab, 0x1ffff)
-DECLARE_INSN(c_slliw, 0x1819, 0x1c1f)
-DECLARE_INSN(c_fld, 0x15, 0x1f)
DECLARE_INSN(vlstw, 0x110b, 0x1ffff)
DECLARE_INSN(vlsth, 0x108b, 0x1ffff)
DECLARE_INSN(xori, 0x213, 0x3ff)
@@ -152,7 +135,6 @@ DECLARE_INSN(amomaxu_w, 0x1d2b, 0x1ffff)
DECLARE_INSN(fcvt_wu_s, 0xb053, 0x3ff1ff)
DECLARE_INSN(vlstb, 0x100b, 0x1ffff)
DECLARE_INSN(vlstd, 0x118b, 0x1ffff)
-DECLARE_INSN(c_ld0, 0x8012, 0x801f)
DECLARE_INSN(rdtime, 0x677, 0x7ffffff)
DECLARE_INSN(andi, 0x393, 0x3ff)
DECLARE_INSN(clearpcr, 0x7b, 0x3ff)
@@ -162,26 +144,19 @@ DECLARE_INSN(fnmadd_s, 0x4f, 0x1ff)
DECLARE_INSN(jal, 0x6f, 0x7f)
DECLARE_INSN(lwu, 0x303, 0x3ff)
DECLARE_INSN(vlsegstbu, 0xa0b, 0xfff)
-DECLARE_INSN(c_beq, 0x10, 0x1f)
DECLARE_INSN(vlhu, 0x28b, 0x3fffff)
DECLARE_INSN(vfsstd, 0x158f, 0x1ffff)
DECLARE_INSN(fnmadd_d, 0xcf, 0x1ff)
DECLARE_INSN(amoadd_d, 0x1ab, 0x1ffff)
-DECLARE_INSN(c_sw, 0xd, 0x1f)
DECLARE_INSN(lr_d, 0x101ab, 0x3fffff)
-DECLARE_INSN(c_move, 0x2, 0x801f)
DECLARE_INSN(fcvt_w_s, 0xa053, 0x3ff1ff)
-DECLARE_INSN(c_fsw, 0x16, 0x1f)
-DECLARE_INSN(c_j, 0x8002, 0x801f)
DECLARE_INSN(mulhsu, 0x533, 0x1ffff)
-DECLARE_INSN(c_sd, 0xc, 0x1f)
DECLARE_INSN(amoadd_w, 0x12b, 0x1ffff)
DECLARE_INSN(fcvt_d_lu, 0xd0d3, 0x3ff1ff)
DECLARE_INSN(amomax_d, 0x15ab, 0x1ffff)
DECLARE_INSN(fsd, 0x1a7, 0x3ff)
DECLARE_INSN(fcvt_w_d, 0xa0d3, 0x3ff1ff)
DECLARE_INSN(fmovz, 0xaf7, 0x1ffff)
-DECLARE_INSN(c_or3, 0x21c, 0x31f)
DECLARE_INSN(vmvv, 0x73, 0x3fffff)
DECLARE_INSN(vfssegstw, 0xd0f, 0xfff)
DECLARE_INSN(slt, 0x133, 0x1ffff)
@@ -194,7 +169,6 @@ DECLARE_INSN(flw, 0x107, 0x3ff)
DECLARE_INSN(remw, 0x73b, 0x1ffff)
DECLARE_INSN(sltu, 0x1b3, 0x1ffff)
DECLARE_INSN(slli, 0x93, 0x3f03ff)
-DECLARE_INSN(c_and3, 0x31c, 0x31f)
DECLARE_INSN(vssegw, 0x210f, 0x1ffff)
DECLARE_INSN(amoor_w, 0xd2b, 0x1ffff)
DECLARE_INSN(vsd, 0x18f, 0x3fffff)
@@ -209,10 +183,8 @@ DECLARE_INSN(vf, 0x3f3, 0xf80003ff)
DECLARE_INSN(vlsegstw, 0x90b, 0xfff)
DECLARE_INSN(syscall, 0x77, 0xffffffff)
DECLARE_INSN(fsgnj_s, 0x5053, 0x1ffff)
-DECLARE_INSN(c_addi, 0x1, 0x1f)
DECLARE_INSN(vfmvv, 0x173, 0x3fffff)
DECLARE_INSN(vlstwu, 0x130b, 0x1ffff)
-DECLARE_INSN(c_sub3, 0x11c, 0x31f)
DECLARE_INSN(vsh, 0x8f, 0x3fffff)
DECLARE_INSN(vlsegstb, 0x80b, 0xfff)
DECLARE_INSN(vxcptsave, 0x37b, 0xf83fffff)
@@ -223,7 +195,6 @@ DECLARE_INSN(vlsegsth, 0x88b, 0xfff)
DECLARE_INSN(amomax_w, 0x152b, 0x1ffff)
DECLARE_INSN(fsgnj_d, 0x50d3, 0x1ffff)
DECLARE_INSN(vflsegstw, 0xd0b, 0xfff)
-DECLARE_INSN(c_sub, 0x801a, 0x801f)
DECLARE_INSN(mulhu, 0x5b3, 0x1ffff)
DECLARE_INSN(fence_v_g, 0x2af, 0x3ff)
DECLARE_INSN(vmsv, 0x873, 0x3fffff)
@@ -234,7 +205,6 @@ DECLARE_INSN(vxcpthold, 0x277b, 0xffffffff)
DECLARE_INSN(fcvt_s_l, 0xc053, 0x3ff1ff)
DECLARE_INSN(vflsegstd, 0xd8b, 0xfff)
DECLARE_INSN(auipc, 0x17, 0x7f)
-DECLARE_INSN(c_add, 0x1a, 0x801f)
DECLARE_INSN(fcvt_lu_d, 0x90d3, 0x3ff1ff)
DECLARE_INSN(vfld, 0x58b, 0x3fffff)
DECLARE_INSN(sc_d, 0x105ab, 0x1ffff)
@@ -243,16 +213,13 @@ DECLARE_INSN(fmovn, 0xef7, 0x1ffff)
DECLARE_INSN(vssegh, 0x208f, 0x1ffff)
DECLARE_INSN(fsqrt_s, 0x4053, 0x3ff1ff)
DECLARE_INSN(vxcptkill, 0xb7b, 0xffffffff)
-DECLARE_INSN(c_srai, 0x1019, 0x1c1f)
DECLARE_INSN(amomin_w, 0x112b, 0x1ffff)
DECLARE_INSN(fsgnjn_s, 0x6053, 0x1ffff)
-DECLARE_INSN(c_slli32, 0x419, 0x1c1f)
DECLARE_INSN(vlsegwu, 0x230b, 0x1ffff)
DECLARE_INSN(vfsw, 0x50f, 0x3fffff)
DECLARE_INSN(amoswap_d, 0x5ab, 0x1ffff)
DECLARE_INSN(fsqrt_d, 0x40d3, 0x3ff1ff)
DECLARE_INSN(vflw, 0x50b, 0x3fffff)
-DECLARE_INSN(c_bne, 0x11, 0x1f)
DECLARE_INSN(fmadd_d, 0xc3, 0x1ff)
DECLARE_INSN(divw, 0x63b, 0x1ffff)
DECLARE_INSN(amomin_d, 0x11ab, 0x1ffff)
@@ -268,7 +235,6 @@ DECLARE_INSN(vlsegh, 0x208b, 0x1ffff)
DECLARE_INSN(sw, 0x123, 0x3ff)
DECLARE_INSN(fmsub_s, 0x47, 0x1ff)
DECLARE_INSN(vfssegw, 0x250f, 0x1ffff)
-DECLARE_INSN(c_addiw, 0x1d, 0x1f)
DECLARE_INSN(lhu, 0x283, 0x3ff)
DECLARE_INSN(sh, 0xa3, 0x3ff)
DECLARE_INSN(vlsegw, 0x210b, 0x1ffff)
diff --git a/riscv/processor.cc b/riscv/processor.cc
index 5d82937..3bd4a19 100644
--- a/riscv/processor.cc
+++ b/riscv/processor.cc
@@ -132,7 +132,7 @@ void processor_t::step(size_t n, bool noisy)
// execute_insn fetches and executes one instruction
#define execute_insn(noisy) \
do { \
- mmu_t::insn_fetch_t fetch = _mmu.load_insn(npc, sr & SR_EC); \
+ mmu_t::insn_fetch_t fetch = _mmu.load_insn(npc); \
if(noisy) disasm(fetch.insn, npc); \
npc = fetch.func(this, fetch.insn, npc); \
pc = npc; \
diff --git a/riscv/processor.h b/riscv/processor.h
index c2d0ea5..08c3672 100644
--- a/riscv/processor.h
+++ b/riscv/processor.h
@@ -109,18 +109,4 @@ private:
reg_t illegal_instruction(insn_t insn, reg_t pc);
};
-#ifndef RISCV_ENABLE_RVC
-# define set_pc(x) \
- do { if ((x) & 3) \
- throw trap_instruction_address_misaligned; \
- npc = (x); \
- } while(0)
-#else
-# define set_pc(x) \
- do { if ((x) & ((sr & SR_EC) ? 1 : 3)) \
- throw trap_instruction_address_misaligned; \
- npc = (x); \
- } while(0)
-#endif
-
#endif
diff --git a/rvc/README b/rvc/README
new file mode 100644
index 0000000..feabcd3
--- /dev/null
+++ b/rvc/README
@@ -0,0 +1,2 @@
+This directory contains work in progress on RISC-V Compressed (RVC), a 16-bit
+instruction encoding for reduced code size. It is not currently usable.
diff --git a/riscv/insns/c_add.h b/rvc/insns/c_add.h
index 2170d69..2170d69 100644
--- a/riscv/insns/c_add.h
+++ b/rvc/insns/c_add.h
diff --git a/riscv/insns/c_add3.h b/rvc/insns/c_add3.h
index 914c85d..914c85d 100644
--- a/riscv/insns/c_add3.h
+++ b/rvc/insns/c_add3.h
diff --git a/riscv/insns/c_addi.h b/rvc/insns/c_addi.h
index 448e31a..448e31a 100644
--- a/riscv/insns/c_addi.h
+++ b/rvc/insns/c_addi.h
diff --git a/riscv/insns/c_addiw.h b/rvc/insns/c_addiw.h
index 6a1e0a3..6a1e0a3 100644
--- a/riscv/insns/c_addiw.h
+++ b/rvc/insns/c_addiw.h
diff --git a/riscv/insns/c_and3.h b/rvc/insns/c_and3.h
index b506d6a..b506d6a 100644
--- a/riscv/insns/c_and3.h
+++ b/rvc/insns/c_and3.h
diff --git a/riscv/insns/c_beq.h b/rvc/insns/c_beq.h
index 031d96d..031d96d 100644
--- a/riscv/insns/c_beq.h
+++ b/rvc/insns/c_beq.h
diff --git a/riscv/insns/c_bne.h b/rvc/insns/c_bne.h
index caf9229..caf9229 100644
--- a/riscv/insns/c_bne.h
+++ b/rvc/insns/c_bne.h
diff --git a/riscv/insns/c_fld.h b/rvc/insns/c_fld.h
index a726039..a726039 100644
--- a/riscv/insns/c_fld.h
+++ b/rvc/insns/c_fld.h
diff --git a/riscv/insns/c_flw.h b/rvc/insns/c_flw.h
index cdb7221..cdb7221 100644
--- a/riscv/insns/c_flw.h
+++ b/rvc/insns/c_flw.h
diff --git a/riscv/insns/c_fsd.h b/rvc/insns/c_fsd.h
index 20814fd..20814fd 100644
--- a/riscv/insns/c_fsd.h
+++ b/rvc/insns/c_fsd.h
diff --git a/riscv/insns/c_fsw.h b/rvc/insns/c_fsw.h
index 1d21629..1d21629 100644
--- a/riscv/insns/c_fsw.h
+++ b/rvc/insns/c_fsw.h
diff --git a/riscv/insns/c_j.h b/rvc/insns/c_j.h
index 5ba9c73..5ba9c73 100644
--- a/riscv/insns/c_j.h
+++ b/rvc/insns/c_j.h
diff --git a/riscv/insns/c_ld.h b/rvc/insns/c_ld.h
index f9c07af..f9c07af 100644
--- a/riscv/insns/c_ld.h
+++ b/rvc/insns/c_ld.h
diff --git a/riscv/insns/c_ld0.h b/rvc/insns/c_ld0.h
index f51a966..f51a966 100644
--- a/riscv/insns/c_ld0.h
+++ b/rvc/insns/c_ld0.h
diff --git a/riscv/insns/c_ldsp.h b/rvc/insns/c_ldsp.h
index 1fbd9bd..1fbd9bd 100644
--- a/riscv/insns/c_ldsp.h
+++ b/rvc/insns/c_ldsp.h
diff --git a/riscv/insns/c_li.h b/rvc/insns/c_li.h
index e65614e..e65614e 100644
--- a/riscv/insns/c_li.h
+++ b/rvc/insns/c_li.h
diff --git a/riscv/insns/c_lw.h b/rvc/insns/c_lw.h
index 4796ab8..4796ab8 100644
--- a/riscv/insns/c_lw.h
+++ b/rvc/insns/c_lw.h
diff --git a/riscv/insns/c_lw0.h b/rvc/insns/c_lw0.h
index d263a80..d263a80 100644
--- a/riscv/insns/c_lw0.h
+++ b/rvc/insns/c_lw0.h
diff --git a/riscv/insns/c_lwsp.h b/rvc/insns/c_lwsp.h
index 318342a..318342a 100644
--- a/riscv/insns/c_lwsp.h
+++ b/rvc/insns/c_lwsp.h
diff --git a/riscv/insns/c_move.h b/rvc/insns/c_move.h
index b0aef33..b0aef33 100644
--- a/riscv/insns/c_move.h
+++ b/rvc/insns/c_move.h
diff --git a/riscv/insns/c_or3.h b/rvc/insns/c_or3.h
index 143e2ae..143e2ae 100644
--- a/riscv/insns/c_or3.h
+++ b/rvc/insns/c_or3.h
diff --git a/riscv/insns/c_sd.h b/rvc/insns/c_sd.h
index b2eb456..b2eb456 100644
--- a/riscv/insns/c_sd.h
+++ b/rvc/insns/c_sd.h
diff --git a/riscv/insns/c_sdsp.h b/rvc/insns/c_sdsp.h
index ca97d51..ca97d51 100644
--- a/riscv/insns/c_sdsp.h
+++ b/rvc/insns/c_sdsp.h
diff --git a/riscv/insns/c_slli.h b/rvc/insns/c_slli.h
index 5026767..5026767 100644
--- a/riscv/insns/c_slli.h
+++ b/rvc/insns/c_slli.h
diff --git a/riscv/insns/c_slli32.h b/rvc/insns/c_slli32.h
index 1e3e958..1e3e958 100644
--- a/riscv/insns/c_slli32.h
+++ b/rvc/insns/c_slli32.h
diff --git a/riscv/insns/c_slliw.h b/rvc/insns/c_slliw.h
index 9e428f5..9e428f5 100644
--- a/riscv/insns/c_slliw.h
+++ b/rvc/insns/c_slliw.h
diff --git a/riscv/insns/c_srai.h b/rvc/insns/c_srai.h
index aa33424..aa33424 100644
--- a/riscv/insns/c_srai.h
+++ b/rvc/insns/c_srai.h
diff --git a/riscv/insns/c_srai32.h b/rvc/insns/c_srai32.h
index ca7b024..ca7b024 100644
--- a/riscv/insns/c_srai32.h
+++ b/rvc/insns/c_srai32.h
diff --git a/riscv/insns/c_srli.h b/rvc/insns/c_srli.h
index 56e0681..56e0681 100644
--- a/riscv/insns/c_srli.h
+++ b/rvc/insns/c_srli.h
diff --git a/riscv/insns/c_srli32.h b/rvc/insns/c_srli32.h
index 4f5b8ea..4f5b8ea 100644
--- a/riscv/insns/c_srli32.h
+++ b/rvc/insns/c_srli32.h
diff --git a/riscv/insns/c_sub.h b/rvc/insns/c_sub.h
index 9fd8932..9fd8932 100644
--- a/riscv/insns/c_sub.h
+++ b/rvc/insns/c_sub.h
diff --git a/riscv/insns/c_sub3.h b/rvc/insns/c_sub3.h
index 53afc84..53afc84 100644
--- a/riscv/insns/c_sub3.h
+++ b/rvc/insns/c_sub3.h
diff --git a/riscv/insns/c_sw.h b/rvc/insns/c_sw.h
index f604adf..f604adf 100644
--- a/riscv/insns/c_sw.h
+++ b/rvc/insns/c_sw.h
diff --git a/riscv/insns/c_swsp.h b/rvc/insns/c_swsp.h
index 0508f12..0508f12 100644
--- a/riscv/insns/c_swsp.h
+++ b/rvc/insns/c_swsp.h
diff --git a/rvc/rvc.h b/rvc/rvc.h
new file mode 100644
index 0000000..997ffc6
--- /dev/null
+++ b/rvc/rvc.h
@@ -0,0 +1,30 @@
+#ifndef _RVC_H
+#define _RVC_H
+
+#define INSN_IS_RVC(x) (((x) & 0x3) < 0x3)
+#define insn_length(x) (INSN_IS_RVC(x) ? 2 : 4)
+#define require_rvc if(!(sr & SR_EC)) throw_illegal_instruction
+
+#define CRD_REGNUM ((insn.bits >> 5) & 0x1f)
+#define CRD XPR.write_port(CRD_REGNUM)
+#define CRS1 XPR[(insn.bits >> 10) & 0x1f]
+#define CRS2 XPR[(insn.bits >> 5) & 0x1f]
+#define CIMM6 ((int32_t)((insn.bits >> 10) & 0x3f) << 26 >> 26)
+#define CIMM5U ((insn.bits >> 5) & 0x1f)
+#define CIMM5 ((int32_t)CIMM5U << 27 >> 27)
+#define CIMM10 ((int32_t)((insn.bits >> 5) & 0x3ff) << 22 >> 22)
+#define CBRANCH_TARGET (pc + (CIMM5 << BRANCH_ALIGN_BITS))
+#define CJUMP_TARGET (pc + (CIMM10 << JUMP_ALIGN_BITS))
+
+static const int rvc_rs1_regmap[8] = { 20, 21, 2, 3, 4, 5, 6, 7 };
+#define rvc_rd_regmap rvc_rs1_regmap
+#define rvc_rs2b_regmap rvc_rs1_regmap
+static const int rvc_rs2_regmap[8] = { 20, 21, 2, 3, 4, 5, 6, 0 };
+#define CRDS XPR.write_port(rvc_rd_regmap[(insn.bits >> 13) & 0x7])
+#define FCRDS FPR.write_port(rvc_rd_regmap[(insn.bits >> 13) & 0x7])
+#define CRS1S XPR[rvc_rs1_regmap[(insn.bits >> 10) & 0x7]]
+#define CRS2S XPR[rvc_rs2_regmap[(insn.bits >> 13) & 0x7]]
+#define CRS2BS XPR[rvc_rs2b_regmap[(insn.bits >> 5) & 0x7]]
+#define FCRS2S FPR[rvc_rs2_regmap[(insn.bits >> 13) & 0x7]]
+
+#endif