uint32_t bits;
};
-#if 0
#include <stdio.h>
-class trace_writeback
+class do_writeback
{
public:
- trace_writeback(reg_t* _rf, int _rd) : rf(_rf), rd(_rd) {}
+ do_writeback(reg_t* _rf, int _rd) : rf(_rf), rd(_rd) {}
- reg_t operator = (reg_t rhs)
+ const do_writeback& operator = (reg_t rhs)
{
+#if 0
printf("R[%x] <= %llx\n",rd,(long long)rhs);
+#endif
rf[rd] = rhs;
- return rhs;
+ rf[0] = 0;
+ return *this;
}
+ operator reg_t() { return rf[rd]; }
+
private:
reg_t* rf;
int rd;
};
-#define do_writeback(rf,rd) trace_writeback(rf,rd)
-#else
-#define do_writeback(rf,rd) rf[rd]
-#endif
-
#define throw_illegal_instruction \
({ if (utmode) throw trap_vector_illegal_instruction; \
else throw trap_illegal_instruction; })
#include "trap.h"
#include "icsim.h"
#include "common.h"
+#include "processor.h"
class processor_t;
*(type##_t*)paddr = val; \
}
- insn_t __attribute__((always_inline)) load_insn(reg_t addr, bool rvc)
+ insn_t __attribute__((always_inline)) load_insn(reg_t addr, bool rvc,
+ insn_func_t* func)
{
insn_t insn;
void* addr_lo = translate(addr, false, true);
insn.bits = *(uint16_t*)addr_lo;
+ *func = processor_t::dispatch_table
+ [insn.bits % processor_t::DISPATCH_TABLE_SIZE];
+
if(!INSN_IS_RVC(insn.bits))
{
void* addr_hi = translate(addr+2, false, true);
#endif
{
reg_t idx = (addr/sizeof(insn_t)) % ICACHE_ENTRIES;
- bool hit = icache_tag[idx] == addr;
- if(likely(hit))
- return icache_data[idx];
+ insn_t data = icache_data[idx];
+ *func = icache_func[idx];
+ if(likely(icache_tag[idx] == addr))
+ return data;
// the processor guarantees alignment based upon rvc mode
void* paddr = translate(addr, false, true);
icache_tag[idx] = addr;
icache_data[idx] = insn;
+ icache_func[idx] = *func = processor_t::dispatch_table
+ [insn.bits % processor_t::DISPATCH_TABLE_SIZE];
}
#ifdef RISCV_ENABLE_ICSIM
static const reg_t ICACHE_ENTRIES = 256;
insn_t icache_data[ICACHE_ENTRIES];
+ insn_func_t icache_func[ICACHE_ENTRIES];
reg_t icache_tag[ICACHE_ENTRIES];
icsim_t* icsim;
{
take_interrupt();
+ mmu_t& _mmu = mmu;
+ insn_t insn;
+ insn_func_t func;
+ reg_t npc = pc;
#define execute_insn(noisy) \
- do { insn_t insn = mmu.load_insn(pc, sr & SR_EC); \
- if(noisy) disasm(insn,pc); \
- pc = dispatch_table[insn.bits % DISPATCH_TABLE_SIZE](this, insn, pc); \
- XPR[0] = 0; } while(0)
+ do { \
+ insn = _mmu.load_insn(npc, sr & SR_EC, &func); \
+ if(noisy) disasm(insn,pc); \
+ npc = func(this, insn, npc); \
+ pc = npc; \
+ } while(0)
if(noisy) for( ; i < n; i++)
execute_insn(true);