#include "config.h"
#include "sim.h"
#include "mmu.h"
-#include "htif.h"
#include "disasm.h"
#include "gdbserver.h"
#include <cinttypes>
processor_t::processor_t(const char* isa, sim_t* sim, uint32_t id,
bool halt_on_reset)
- : debug(false), sim(sim), ext(NULL), disassembler(new disassembler_t),
- id(id), run(false), halt_on_reset(halt_on_reset)
+ : debug(false), sim(sim), ext(NULL), id(id), halt_on_reset(halt_on_reset)
{
parse_isa_string(isa);
+ register_base_instructions();
mmu = new mmu_t(sim, this);
+ disassembler = new disassembler_t(max_xlen);
- reset(true);
-
- register_base_instructions();
+ reset();
}
processor_t::~processor_t()
isa_string = "rv" + std::to_string(max_xlen) + p;
isa |= 1L << ('s' - 'a'); // advertise support for supervisor mode
+ isa |= 1L << ('u' - 'a'); // advertise support for user mode
while (*p) {
isa |= 1L << (*p - 'a');
#endif
}
-void processor_t::reset(bool value)
+void processor_t::reset()
{
- if (run == !value)
- return;
- run = !value;
-
state.reset();
state.dcsr.halt = halt_on_reset;
halt_on_reset = false;
raise_interrupt(ctz(enabled_interrupts));
}
-static bool validate_priv(reg_t priv)
-{
- return priv == PRV_U || priv == PRV_S || priv == PRV_M;
-}
-
void processor_t::set_privilege(reg_t prv)
{
- assert(validate_priv(prv));
+ assert(prv <= PRV_M);
+ if (prv == PRV_H)
+ prv = PRV_U;
mmu->flush_tlb();
state.prv = prv;
}
break;
case CSR_MSTATUS: {
if ((val ^ state.mstatus) &
- (MSTATUS_VM | MSTATUS_MPP | MSTATUS_MPRV | MSTATUS_PUM))
+ (MSTATUS_VM | MSTATUS_MPP | MSTATUS_MPRV | MSTATUS_PUM | MSTATUS_MXR))
mmu->flush_tlb();
reg_t mask = MSTATUS_SIE | MSTATUS_SPIE | MSTATUS_MIE | MSTATUS_MPIE
| MSTATUS_SPP | MSTATUS_FS | MSTATUS_MPRV | MSTATUS_PUM
- | (ext ? MSTATUS_XS : 0);
+ | MSTATUS_MPP | MSTATUS_MXR | (ext ? MSTATUS_XS : 0);
if (validate_vm(max_xlen, get_field(val, MSTATUS_VM)))
mask |= MSTATUS_VM;
- if (validate_priv(get_field(val, MSTATUS_MPP)))
- mask |= MSTATUS_MPP;
state.mstatus = (state.mstatus & ~mask) | (val & mask);
std::sort(instructions.begin(), instructions.end(), cmp());
for (size_t i = 0; i < OPCODE_CACHE_SIZE; i++)
- opcode_cache[i] = {1, 0, &illegal_instruction, &illegal_instruction};
+ opcode_cache[i] = {0, 0, &illegal_instruction, &illegal_instruction};
}
void processor_t::register_extension(extension_t* x)