1 // See LICENSE for license details.
3 #ifndef _RISCV_PROCESSOR_H
4 #define _RISCV_PROCESSOR_H
13 typedef reg_t (*insn_func_t
)(processor_t
*, insn_t
, reg_t
);
17 // architectural state of a RISC-V hart
24 regfile_t
<reg_t
, NXPR
, true> XPR
;
25 regfile_t
<freg_t
, NFPR
, false> FPR
;
28 // privileged control registers
38 uint32_t sr
; // only modify the status register using set_pcr()
43 reg_t load_reservation
;
46 // this class represents one processor in a RISC-V machine.
50 processor_t(sim_t
* _sim
, mmu_t
* _mmu
, uint32_t _id
);
53 void reset(bool value
);
54 void step(size_t n
, bool noisy
); // run for n cycles
55 void deliver_ipi(); // register an interprocessor interrupt
56 bool running() { return run
; }
57 reg_t
set_pcr(int which
, reg_t val
);
58 uint32_t set_fsr(uint32_t val
); // set the floating-point status register
59 void set_interrupt(int which
, bool on
);
60 reg_t
get_pcr(int which
);
61 uint32_t get_fsr() { return state
.fsr
; }
62 mmu_t
* get_mmu() { return &mmu
; }
63 state_t
* get_state() { return &state
; }
64 void yield_load_reservation() { state
.load_reservation
= (reg_t
)-1; }
66 void register_insn(uint32_t match
, uint32_t mask
, insn_func_t rv32
, insn_func_t rv64
);
70 mmu_t
& mmu
; // main memory is always accessed via the mmu
75 struct opcode_map_entry_t
83 std::multimap
<uint32_t, opcode_map_entry_t
> opcode_map
;
85 void take_interrupt(); // take a trap if any interrupts are pending
86 void take_trap(reg_t pc
, trap_t
& t
, bool noisy
); // take an exception
87 void disasm(insn_t insn
, reg_t pc
); // disassemble and print an instruction
91 friend class htif_isasim_t
;
93 insn_func_t
decode_insn(insn_t insn
);