| 1 |
3 |
sergeykhbr |
/**
|
| 2 |
|
|
* @file
|
| 3 |
|
|
* @copyright Copyright 2016 GNSS Sensor Ltd. All right reserved.
|
| 4 |
|
|
* @author Sergey Khabarov - sergeykhbr@gmail.com
|
| 5 |
|
|
* @brief SystemC CPU wrapper. To interact with the SoC simulator. */
|
| 6 |
|
|
|
| 7 |
|
|
#ifndef __DEBUGGER_RTL_WRAPPER_H__
|
| 8 |
|
|
#define __DEBUGGER_RTL_WRAPPER_H__
|
| 9 |
|
|
|
| 10 |
|
|
#include "async_tqueue.h"
|
| 11 |
|
|
#include "coreservices/ibus.h"
|
| 12 |
|
|
#include "coreservices/icpuriscv.h"
|
| 13 |
|
|
#include "coreservices/iclklistener.h"
|
| 14 |
|
|
#include "riverlib/river_cfg.h"
|
| 15 |
|
|
#include <systemc.h>
|
| 16 |
|
|
#include "api_utils.h"
|
| 17 |
|
|
|
| 18 |
|
|
namespace debugger {
|
| 19 |
|
|
|
| 20 |
|
|
class RtlWrapper : public sc_module,
|
| 21 |
|
|
public ICpuRiscV {
|
| 22 |
|
|
public:
|
| 23 |
|
|
sc_clock o_clk;
|
| 24 |
|
|
sc_out<bool> o_nrst;
|
| 25 |
|
|
// Timer:
|
| 26 |
|
|
sc_in<sc_uint<RISCV_ARCH>> i_time;
|
| 27 |
|
|
// Memory interface:
|
| 28 |
|
|
sc_out<bool> o_req_mem_ready;
|
| 29 |
|
|
sc_in<bool> i_req_mem_valid;
|
| 30 |
|
|
sc_in<bool> i_req_mem_write;
|
| 31 |
|
|
sc_in<sc_uint<BUS_ADDR_WIDTH>> i_req_mem_addr;
|
| 32 |
|
|
sc_in<sc_uint<BUS_DATA_BYTES>> i_req_mem_strob;
|
| 33 |
|
|
sc_in<sc_uint<BUS_DATA_WIDTH>> i_req_mem_data;
|
| 34 |
|
|
sc_out<bool> o_resp_mem_data_valid;
|
| 35 |
|
|
sc_out<sc_uint<BUS_DATA_WIDTH>> o_resp_mem_data;
|
| 36 |
|
|
/** Interrupt line from external interrupts controller. */
|
| 37 |
|
|
sc_out<bool> o_interrupt;
|
| 38 |
|
|
// Debug interface
|
| 39 |
|
|
sc_out<bool> o_dport_valid; // Debug access from DSU is valid
|
| 40 |
|
|
sc_out<bool> o_dport_write; // Write value
|
| 41 |
|
|
sc_out<sc_uint<2>> o_dport_region; // Registers region ID: 0=CSR; 1=IREGS; 2=Control
|
| 42 |
|
|
sc_out<sc_uint<12>> o_dport_addr; // Register index
|
| 43 |
|
|
sc_out<sc_uint<RISCV_ARCH>> o_dport_wdata; // Write value
|
| 44 |
|
|
sc_in<bool> i_dport_ready; // Response is ready
|
| 45 |
|
|
sc_in<sc_uint<RISCV_ARCH>> i_dport_rdata; // Response value
|
| 46 |
|
|
|
| 47 |
|
|
|
| 48 |
|
|
struct RegistersType {
|
| 49 |
|
|
sc_signal<sc_uint<BUS_DATA_WIDTH>> resp_mem_data;
|
| 50 |
|
|
sc_signal<bool> resp_mem_data_valid;
|
| 51 |
|
|
sc_signal<sc_uint<3>> wait_state_cnt;
|
| 52 |
|
|
sc_signal<sc_bv<5>> nrst;
|
| 53 |
|
|
sc_signal<bool> interrupt;
|
| 54 |
|
|
// Debug port latches:
|
| 55 |
|
|
sc_signal<bool> dport_valid;
|
| 56 |
|
|
sc_signal<bool> dport_write;
|
| 57 |
|
|
sc_signal<sc_uint<2>> dport_region;
|
| 58 |
|
|
sc_signal<sc_uint<12>> dport_addr;
|
| 59 |
|
|
sc_signal<sc_uint<RISCV_ARCH>> dport_wdata;
|
| 60 |
|
|
} r, v;
|
| 61 |
|
|
bool w_nrst;
|
| 62 |
|
|
bool w_interrupt;
|
| 63 |
|
|
|
| 64 |
|
|
void clk_gen();
|
| 65 |
|
|
void comb();
|
| 66 |
|
|
void registers();
|
| 67 |
|
|
void clk_negedge_proc();
|
| 68 |
|
|
|
| 69 |
|
|
SC_HAS_PROCESS(RtlWrapper);
|
| 70 |
|
|
|
| 71 |
|
|
RtlWrapper(IFace *parent, sc_module_name name);
|
| 72 |
|
|
virtual ~RtlWrapper();
|
| 73 |
|
|
|
| 74 |
|
|
public:
|
| 75 |
|
|
void generateRef(bool v) { generate_ref_ = v; }
|
| 76 |
|
|
void generateVCD(sc_trace_file *i_vcd, sc_trace_file *o_vcd);
|
| 77 |
|
|
void setBus(IBus *v) { ibus_ = v; }
|
| 78 |
|
|
/** Default time resolution 1 picosecond. */
|
| 79 |
|
|
void setClockHz(double hz);
|
| 80 |
|
|
|
| 81 |
|
|
/** ICpuRiscV interface */
|
| 82 |
|
|
virtual void registerStepCallback(IClockListener *cb, uint64_t t);
|
| 83 |
|
|
virtual void raiseSignal(int idx);
|
| 84 |
|
|
virtual void lowerSignal(int idx);
|
| 85 |
|
|
virtual void nb_transport_debug_port(DebugPortTransactionType *trans,
|
| 86 |
|
|
IDbgNbResponse *cb);
|
| 87 |
|
|
|
| 88 |
|
|
private:
|
| 89 |
|
|
IFace *getInterface(const char *name) { return iparent_; }
|
| 90 |
|
|
uint64_t mask2offset(uint8_t mask);
|
| 91 |
|
|
uint32_t mask2size(uint8_t mask); // nask with removed offset
|
| 92 |
|
|
|
| 93 |
|
|
private:
|
| 94 |
|
|
IBus *ibus_;
|
| 95 |
|
|
IFace *iparent_; // pointer on parent module object (used for logging)
|
| 96 |
|
|
int clockCycles_; // default in [ps]
|
| 97 |
|
|
AsyncTQueueType step_queue_;
|
| 98 |
|
|
uint64_t step_cnt_z;
|
| 99 |
|
|
bool generate_ref_;
|
| 100 |
|
|
|
| 101 |
|
|
sc_uint<32> t_trans_idx_up;
|
| 102 |
|
|
sc_uint<32> t_trans_idx_down;
|
| 103 |
|
|
|
| 104 |
|
|
struct DebugPortType {
|
| 105 |
|
|
event_def valid;
|
| 106 |
|
|
DebugPortTransactionType *trans;
|
| 107 |
|
|
IDbgNbResponse *cb;
|
| 108 |
|
|
unsigned trans_idx_up;
|
| 109 |
|
|
unsigned trans_idx_down;
|
| 110 |
|
|
unsigned idx_missmatch;
|
| 111 |
|
|
} dport_;
|
| 112 |
|
|
};
|
| 113 |
|
|
|
| 114 |
|
|
} // namespace debugger
|
| 115 |
|
|
|
| 116 |
|
|
#endif // __DEBUGGER_RTL_WRAPPER_H__
|