| 1 |
2 |
sergeykhbr |
/**
|
| 2 |
|
|
* @file
|
| 3 |
|
|
* @copyright Copyright 2016 GNSS Sensor Ltd. All right reserved.
|
| 4 |
|
|
* @author Sergey Khabarov - sergeykhbr@gmail.com
|
| 5 |
|
|
* @brief CSR registers module.
|
| 6 |
|
|
*/
|
| 7 |
|
|
|
| 8 |
|
|
#ifndef __DEBUGGER_RIVERLIB_CSR_H__
|
| 9 |
|
|
#define __DEBUGGER_RIVERLIB_CSR_H__
|
| 10 |
|
|
|
| 11 |
|
|
#include <systemc.h>
|
| 12 |
|
|
#include "../river_cfg.h"
|
| 13 |
|
|
|
| 14 |
|
|
namespace debugger {
|
| 15 |
|
|
|
| 16 |
|
|
SC_MODULE(CsrRegs) {
|
| 17 |
|
|
sc_in<bool> i_clk; // Clock signal
|
| 18 |
|
|
sc_in<bool> i_nrst; // Reset (active low)
|
| 19 |
|
|
sc_in<bool> i_xret; // XRet instruction signals mode switching
|
| 20 |
|
|
sc_in<sc_uint<12>> i_addr; // CSR address, if xret=1 switch mode accordingly
|
| 21 |
|
|
sc_in<bool> i_wena; // Write enable
|
| 22 |
|
|
sc_in<sc_uint<RISCV_ARCH>> i_wdata; // CSR writing value
|
| 23 |
|
|
sc_out<sc_uint<RISCV_ARCH>> o_rdata; // CSR read value
|
| 24 |
|
|
sc_in<bool> i_break_mode; // Behaviour on EBREAK instruction: 0 = halt; 1 = generate trap
|
| 25 |
|
|
sc_in<bool> i_breakpoint; // Breakpoint (Trap or not depends of mode)
|
| 26 |
|
|
sc_in<bool> i_trap_ena; // Trap pulse
|
| 27 |
|
|
sc_in<sc_uint<5>> i_trap_code; // bit[4] : 1=interrupt; 0=exception; bits[3:0]=code
|
| 28 |
|
|
sc_in<sc_uint<BUS_ADDR_WIDTH>> i_trap_pc;// trap on pc
|
| 29 |
|
|
|
| 30 |
|
|
sc_out<bool> o_ie; // Interrupt enable bit
|
| 31 |
|
|
sc_out<sc_uint<2>> o_mode; // CPU mode
|
| 32 |
|
|
sc_out<sc_uint<BUS_ADDR_WIDTH>> o_mtvec;// Interrupt descriptors table
|
| 33 |
|
|
|
| 34 |
|
|
sc_in<bool> i_dport_ena; // Debug port request is enabled
|
| 35 |
|
|
sc_in<bool> i_dport_write; // Debug port Write enable
|
| 36 |
|
|
sc_in<sc_uint<12>> i_dport_addr; // Debug port CSR address
|
| 37 |
|
|
sc_in<sc_uint<RISCV_ARCH>> i_dport_wdata; // Debug port CSR writing value
|
| 38 |
|
|
sc_out<sc_uint<RISCV_ARCH>> o_dport_rdata;// Debug port CSR read value
|
| 39 |
|
|
|
| 40 |
|
|
void comb();
|
| 41 |
|
|
void registers();
|
| 42 |
|
|
|
| 43 |
|
|
SC_HAS_PROCESS(CsrRegs);
|
| 44 |
|
|
|
| 45 |
|
|
CsrRegs(sc_module_name name_);
|
| 46 |
|
|
|
| 47 |
|
|
void generateVCD(sc_trace_file *i_vcd, sc_trace_file *o_vcd);
|
| 48 |
|
|
|
| 49 |
|
|
private:
|
| 50 |
|
|
struct RegistersType {
|
| 51 |
|
|
sc_signal<sc_uint<RISCV_ARCH>> mtvec;
|
| 52 |
|
|
sc_signal<sc_uint<RISCV_ARCH>> mscratch;
|
| 53 |
|
|
sc_signal<sc_uint<BUS_ADDR_WIDTH>> mbadaddr;
|
| 54 |
|
|
sc_signal<sc_uint<2>> mode;
|
| 55 |
|
|
sc_signal<bool> uie; // User level interrupts ena for current priv. mode
|
| 56 |
|
|
sc_signal<bool> mie; // Machine level interrupts ena for current priv. mode
|
| 57 |
|
|
sc_signal<bool> mpie; // Previous MIE value
|
| 58 |
|
|
sc_signal<sc_uint<2>> mpp; // Previous mode
|
| 59 |
|
|
sc_signal<sc_uint<RISCV_ARCH>> mepc;
|
| 60 |
|
|
|
| 61 |
|
|
sc_signal<bool> trap_irq;
|
| 62 |
|
|
sc_signal<sc_uint<4>> trap_code;
|
| 63 |
|
|
} v, r;
|
| 64 |
|
|
|
| 65 |
|
|
void procedure_RegAccess(uint64_t iaddr, bool iwena,
|
| 66 |
|
|
sc_uint<RISCV_ARCH> iwdata,
|
| 67 |
|
|
RegistersType &ir, RegistersType *ov,
|
| 68 |
|
|
sc_uint<RISCV_ARCH> *ordata);
|
| 69 |
|
|
};
|
| 70 |
|
|
|
| 71 |
|
|
|
| 72 |
|
|
} // namespace debugger
|
| 73 |
|
|
|
| 74 |
|
|
#endif // __DEBUGGER_RIVERLIB_CSR_H__
|