OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [cpu_fnc_plugin/] [cpu_riscv_func.h] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sergeykhbr
/**
2
 * @file
3
 * @copyright  Copyright 2016 GNSS Sensor Ltd. All right reserved.
4
 * @author     Sergey Khabarov - sergeykhbr@gmail.com
5
 * @brief      CPU functional simlator class definition.
6
 */
7
 
8
#ifndef __DEBUGGER_CPU_RISCV_FUNCTIONAL_H__
9
#define __DEBUGGER_CPU_RISCV_FUNCTIONAL_H__
10
 
11
#include "iclass.h"
12
#include "iservice.h"
13
#include "ihap.h"
14
#include "async_tqueue.h"
15
#include "coreservices/ithread.h"
16
#include "coreservices/icpuriscv.h"
17
#include "coreservices/imemop.h"
18
#include "coreservices/iclock.h"
19
#include "coreservices/iclklistener.h"
20
#include "instructions.h"
21
 
22
namespace debugger {
23
 
24
class CpuRiscV_Functional : public IService,
25
                 public IThread,
26
                 public ICpuRiscV,
27
                 public IClock,
28
                 public IHap {
29
public:
30
    CpuRiscV_Functional(const char *name);
31
    virtual ~CpuRiscV_Functional();
32
 
33
    /** IService interface */
34
    virtual void postinitService();
35
 
36
    /** ICpuRiscV interface */
37
    virtual void raiseSignal(int idx);
38
    virtual void lowerSignal(int idx);
39
    virtual void nb_transport_debug_port(DebugPortTransactionType *trans,
40
                                         IDbgNbResponse *cb);
41
 
42
    /** IClock */
43
    virtual uint64_t getStepCounter() { return cpu_context_.step_cnt; }
44
    virtual void registerStepCallback(IClockListener *cb, uint64_t t);
45
 
46
    /** IHap */
47
    virtual void hapTriggered(IFace *isrc, EHapType type, const char *descr);
48
 
49
protected:
50
    /** IThread interface */
51
    virtual void busyLoop();
52
 
53
private:
54
    bool isHalt() { return dbg_state_ == STATE_Halted; }
55
    void halt(const char *descr=NULL);
56
    void go();
57
    void step(uint64_t cnt);
58
    uint64_t getReg(uint64_t idx);
59
    void setReg(uint64_t idx, uint64_t val);
60
    uint64_t getPC();
61
    void setPC(uint64_t val);
62
    uint64_t getNPC();
63
    void setNPC(uint64_t val);
64
    void addBreakpoint(uint64_t addr);
65
    void removeBreakpoint(uint64_t addr);
66
    void hitBreakpoint(uint64_t addr);
67
 
68
    CpuContextType *getpContext() { return &cpu_context_; }
69
    uint32_t hash32(uint32_t val) { return (val >> 2) & 0x1f; }
70
 
71
    void updatePipeline();
72
    void updateState();
73
    void updateDebugPort();
74
    void updateQueue();
75
 
76
    bool isRunning();
77
    void reset();
78
    void handleTrap();
79
    void fetchInstruction();
80
    IInstruction *decodeInstruction(uint32_t *rpayload);
81
    void executeInstruction(IInstruction *instr, uint32_t *rpayload);
82
    void debugRegOutput(const char *marker, CpuContextType *pContext);
83
 
84
private:
85
    static const int INSTR_HASH_TABLE_SIZE = 1 << 5;
86
 
87
    AttributeType isEnable_;
88
    AttributeType bus_;
89
    AttributeType listExtISA_;
90
    AttributeType freqHz_;
91
    AttributeType generateRegTraceFile_;
92
    AttributeType generateMemTraceFile_;
93
    AttributeType resetVector_;
94
    event_def config_done_;
95
 
96
    AsyncTQueueType queue_;
97
    uint64_t last_hit_breakpoint_;
98
 
99
    Axi4TransactionType trans_;
100
    uint32_t cacheline_[512/4];
101
 
102
    // Registers:
103
    AttributeType listInstr_[INSTR_HASH_TABLE_SIZE];
104
    CpuContextType cpu_context_;
105
 
106
    enum EDebugState {
107
        STATE_Halted,
108
        STATE_Normal,
109
        STATE_Stepping
110
    } dbg_state_;
111
    uint64_t dbg_step_cnt_;
112
 
113
    char tstr[1024];
114
    uint64_t iregs_prev[32]; // to detect changes
115
    struct DebugPortType {
116
        bool valid;
117
        DebugPortTransactionType *trans;
118
        IDbgNbResponse *cb;
119
 
120
        // local registers
121
        uint64_t stepping_mode_steps;
122
    } dport;
123
};
124
 
125
DECLARE_CLASS(CpuRiscV_Functional)
126
 
127
}  // namespace debugger
128
 
129
#endif  // __DEBUGGER_CPU_RISCV_FUNCTIONAL_H__

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.