This allows the implementation of an alternative top-level simulator class.
#include "processor.h"
#include "mmu.h"
-#include "sim.h"
#include <cassert>
throw trap_interactive();
processor_t *p = get_core(args[0]);
- return p->state.pc;
+ return p->get_state()->pc;
}
void sim_t::interactive_pc(const std::string& cmd, const std::vector<std::string>& args)
if (r >= NXPR)
throw trap_interactive();
- return p->state.XPR[r];
+ return p->get_state()->XPR[r];
}
freg_t sim_t::get_freg(const std::vector<std::string>& args)
if (r >= NFPR)
throw trap_interactive();
- return p->state.FPR[r];
+ return p->get_state()->FPR[r];
}
void sim_t::interactive_reg(const std::string& cmd, const std::vector<std::string>& args)
processor_t *p = get_core(args[0]);
for (int r = 0; r < NXPR; ++r) {
- fprintf(stderr, "%-4s: 0x%016" PRIx64 " ", xpr_name[r], p->state.XPR[r]);
+ fprintf(stderr, "%-4s: 0x%016" PRIx64 " ", xpr_name[r], p->get_state()->XPR[r]);
if ((r + 1) % 4 == 0)
fprintf(stderr, "\n");
}
#include "sim.h"
#include "processor.h"
-mmu_t::mmu_t(sim_t* sim, processor_t* proc)
+mmu_t::mmu_t(simif_t* sim, processor_t* proc)
: sim(sim), proc(proc),
check_triggers_fetch(false),
check_triggers_load(false),
class mmu_t
{
public:
- mmu_t(sim_t* sim, processor_t* proc);
+ mmu_t(simif_t* sim, processor_t* proc);
~mmu_t();
inline reg_t misaligned_load(reg_t addr, size_t size)
void register_memtracer(memtracer_t*);
private:
- sim_t* sim;
+ simif_t* sim;
processor_t* proc;
memtracer_list_t tracer;
uint16_t fetch_temp;
#undef STATE
#define STATE state
-processor_t::processor_t(const char* isa, sim_t* sim, uint32_t id,
+processor_t::processor_t(const char* isa, simif_t* sim, uint32_t id,
bool halt_on_reset)
: debug(false), halt_request(false), sim(sim), ext(NULL), id(id),
halt_on_reset(halt_on_reset), last_pc(1), executions(1)
class processor_t;
class mmu_t;
typedef reg_t (*insn_func_t)(processor_t*, insn_t, reg_t);
-class sim_t;
+class simif_t;
class trap_t;
class extension_t;
class disassembler_t;
class processor_t : public abstract_device_t
{
public:
- processor_t(const char* isa, sim_t* sim, uint32_t id, bool halt_on_reset=false);
+ processor_t(const char* isa, simif_t* sim, uint32_t id, bool halt_on_reset=false);
~processor_t();
void set_debug(bool value);
mmu_t* get_mmu() { return mmu; }
state_t* get_state() { return &state; }
unsigned get_xlen() { return xlen; }
+ unsigned get_max_xlen() { return max_xlen; }
+ std::string get_isa_string() { return isa_string; }
unsigned get_flen() {
return supports_extension('Q') ? 128 :
supports_extension('D') ? 64 :
void trigger_updated();
private:
- sim_t* sim;
+ simif_t* sim;
mmu_t* mmu; // main memory is always accessed via the mmu
extension_t* ext;
disassembler_t* disassembler;
void enter_debug_mode(uint8_t cause);
- friend class sim_t;
friend class mmu_t;
friend class clint_t;
friend class extension_t;
0x297, // auipc t0,0x0
0x28593 + (reset_vec_size * 4 << 20), // addi a1, t0, &dtb
0xf1402573, // csrr a0, mhartid
- get_core(0)->xlen == 32 ?
+ get_core(0)->get_xlen() == 32 ?
0x0182a283u : // lw t0,24(t0)
0x0182b283u, // ld t0,24(t0)
0x28067, // jr t0
" reg = <" << i << ">;\n"
" status = \"okay\";\n"
" compatible = \"riscv\";\n"
- " riscv,isa = \"" << procs[i]->isa_string << "\";\n"
- " mmu-type = \"riscv," << (procs[i]->max_xlen <= 32 ? "sv32" : "sv48") << "\";\n"
+ " riscv,isa = \"" << procs[i]->get_isa_string() << "\";\n"
+ " mmu-type = \"riscv," << (procs[i]->get_max_xlen() <= 32 ? "sv32" : "sv48") << "\";\n"
" clock-frequency = <" << CPU_HZ << ">;\n"
" CPU" << i << "_intc: interrupt-controller {\n"
" #interrupt-cells = <1>;\n"
class mmu_t;
class remote_bitbang_t;
+// this is the interface to the simulator used by the processors and memory
+class simif_t
+{
+public:
+ // should return NULL for MMIO addresses
+ virtual char* addr_to_mem(reg_t addr) = 0;
+ // used for MMIO addresses
+ virtual bool mmio_load(reg_t addr, size_t len, uint8_t* bytes) = 0;
+ virtual bool mmio_store(reg_t addr, size_t len, const uint8_t* bytes) = 0;
+};
+
// this class encapsulates the processors and memory in a RISC-V machine.
-class sim_t : public htif_t
+class sim_t : public htif_t, public simif_t
{
public:
sim_t(const char* isa, size_t _nprocs, bool halted, reg_t start_pc,