| Line 6... | Line 6... | 
      
        |  */
 |  */
 | 
      
        |  
 |  
 | 
      
        | #ifndef __DEBUGGER_CPU_RISCV_FUNCTIONAL_H__
 | #ifndef __DEBUGGER_CPU_RISCV_FUNCTIONAL_H__
 | 
      
        | #define __DEBUGGER_CPU_RISCV_FUNCTIONAL_H__
 | #define __DEBUGGER_CPU_RISCV_FUNCTIONAL_H__
 | 
      
        |  
 |  
 | 
      
        | #include "iclass.h"
 | #include <riscv-isa.h>
 | 
      
        | #include "iservice.h"
 |   | 
      
        | #include "ihap.h"
 |   | 
      
        | #include "async_tqueue.h"
 |   | 
      
        | #include "coreservices/ithread.h"
 |   | 
      
        | #include "coreservices/icpuriscv.h"
 |   | 
      
        | #include "coreservices/imemop.h"
 |   | 
      
        | #include "coreservices/iclock.h"
 |   | 
      
        | #include "coreservices/iclklistener.h"
 |   | 
      
        | #include "instructions.h"
 | #include "instructions.h"
 | 
      
        |   | #include "generic/cpu_generic.h"
 | 
      
        |   | #include "coreservices/icpuriscv.h"
 | 
      
        |   | #include "coreservices/isocinfo.h"
 | 
      
        |  
 |  
 | 
      
        | namespace debugger {
 | namespace debugger {
 | 
      
        |  
 |  
 | 
      
        | class CpuRiscV_Functional : public IService,
 | class CpuRiver_Functional : public CpuGeneric,
 | 
      
        |                  public IThread,
 |                             public ICpuRiscV {
 | 
      
        |                  public ICpuRiscV,
 |   | 
      
        |                  public IClock,
 |   | 
      
        |                  public IHap {
 |   | 
      
        | public:
 | public:
 | 
      
        |     CpuRiscV_Functional(const char *name);
 |     explicit CpuRiver_Functional(const char *name);
 | 
      
        |     virtual ~CpuRiscV_Functional();
 |     virtual ~CpuRiver_Functional();
 | 
      
        |  
 |  
 | 
      
        |     /** IService interface */
 |     /** IService interface */
 | 
      
        |     virtual void postinitService();
 |     virtual void postinitService();
 | 
      
        |  
 |  
 | 
      
        |     /** ICpuRiscV interface */
 |     /** IResetListener itnterface */
 | 
      
        |   |     virtual void reset(bool active);
 | 
      
        |   |  
 | 
      
        |   |     /** ICpuGeneric interface */
 | 
      
        |     virtual void raiseSignal(int idx);
 |     virtual void raiseSignal(int idx);
 | 
      
        |     virtual void lowerSignal(int idx);
 |     virtual void lowerSignal(int idx);
 | 
      
        |     virtual void nb_transport_debug_port(DebugPortTransactionType *trans,
 |     virtual void raiseSoftwareIrq() {}
 | 
      
        |                                          IDbgNbResponse *cb);
 |     virtual uint64_t getIrqAddress(int idx) { return readCSR(CSR_mtvec); }
 | 
      
        |  
 |  
 | 
      
        |     /** IClock */
 |     // Common River methods shared with instructions:
 | 
      
        |     virtual uint64_t getStepCounter() { return cpu_context_.step_cnt; }
 |     uint64_t *getpRegs() { return portRegs_.getpR64(); }
 | 
      
        |     virtual void registerStepCallback(IClockListener *cb, uint64_t t);
 |     uint64_t readCSR(int idx);
 | 
      
        |  
 |     void writeCSR(int idx, uint64_t val);
 | 
      
        |     /** IHap */
 |   | 
      
        |     virtual void hapTriggered(IFace *isrc, EHapType type, const char *descr);
 |   | 
      
        |  
 |  
 | 
      
        | protected:
 | protected:
 | 
      
        |     /** IThread interface */
 |     /** CpuGeneric common methods */
 | 
      
        |     virtual void busyLoop();
 |     virtual EEndianessType endianess() { return LittleEndian; }
 | 
      
        |  
 |     virtual GenericInstruction *decodeInstruction(Reg64Type *cache);
 | 
      
        | private:
 |     virtual void generateIllegalOpcode();
 | 
      
        |     bool isHalt() { return dbg_state_ == STATE_Halted; }
 |     virtual void handleTrap();
 | 
      
        |     void halt(const char *descr=NULL);
 |     /** Tack Registers changes during execution */
 | 
      
        |     void go();
 |     virtual void trackContextStart();
 | 
      
        |     void step(uint64_t cnt);
 |     /** // Stop tracking and write trace file */
 | 
      
        |     uint64_t getReg(uint64_t idx);
 |     virtual void trackContextEnd();
 | 
      
        |     void setReg(uint64_t idx, uint64_t val);
 |  
 | 
      
        |     uint64_t getPC();
 |     void addIsaUserRV64I();
 | 
      
        |     void setPC(uint64_t val);
 |     void addIsaPrivilegedRV64I();
 | 
      
        |     uint64_t getNPC();
 |     void addIsaExtensionA();
 | 
      
        |     void setNPC(uint64_t val);
 |     void addIsaExtensionC();
 | 
      
        |     void addBreakpoint(uint64_t addr);
 |     void addIsaExtensionF();
 | 
      
        |     void removeBreakpoint(uint64_t addr);
 |     void addIsaExtensionM();
 | 
      
        |     void hitBreakpoint(uint64_t addr);
 |     unsigned addSupportedInstruction(RiscvInstruction *instr);
 | 
      
        |  
 |   | 
      
        |     CpuContextType *getpContext() { return &cpu_context_; }
 |   | 
      
        |     uint32_t hash32(uint32_t val) { return (val >> 2) & 0x1f; }
 |     uint32_t hash32(uint32_t val) { return (val >> 2) & 0x1f; }
 | 
      
        |  
 |     /** Compressed instruction */
 | 
      
        |     void updatePipeline();
 |     uint32_t hash16(uint16_t val) {
 | 
      
        |     void updateState();
 |         uint32_t t1 = val & 0x3;
 | 
      
        |     void updateDebugPort();
 |         return 0x20 | ((val >> 13) << 2) | t1;
 | 
      
        |     void updateQueue();
 |     }
 | 
      
        |  
 |   | 
      
        |     bool isRunning();
 |   | 
      
        |     void reset();
 |   | 
      
        |     void handleTrap();
 |   | 
      
        |     void fetchInstruction();
 |   | 
      
        |     IInstruction *decodeInstruction(uint32_t *rpayload);
 |   | 
      
        |     void executeInstruction(IInstruction *instr, uint32_t *rpayload);
 |   | 
      
        |     void debugRegOutput(const char *marker, CpuContextType *pContext);
 |   | 
      
        |  
 |  
 | 
      
        | private:
 | private:
 | 
      
        |     static const int INSTR_HASH_TABLE_SIZE = 1 << 5;
 |   | 
      
        |  
 |   | 
      
        |     AttributeType isEnable_;
 |   | 
      
        |     AttributeType bus_;
 |   | 
      
        |     AttributeType listExtISA_;
 |     AttributeType listExtISA_;
 | 
      
        |     AttributeType freqHz_;
 |     AttributeType vendorID_;
 | 
      
        |     AttributeType generateRegTraceFile_;
 |     AttributeType vectorTable_;
 | 
      
        |     AttributeType generateMemTraceFile_;
 |   | 
      
        |     AttributeType resetVector_;
 |   | 
      
        |     event_def config_done_;
 |   | 
      
        |  
 |   | 
      
        |     AsyncTQueueType queue_;
 |   | 
      
        |     uint64_t last_hit_breakpoint_;
 |   | 
      
        |  
 |   | 
      
        |     Axi4TransactionType trans_;
 |   | 
      
        |     uint32_t cacheline_[512/4];
 |   | 
      
        |  
 |  
 | 
      
        |     // Registers:
 |     static const int INSTR_HASH_TABLE_SIZE = 1 << 6;
 | 
      
        |     AttributeType listInstr_[INSTR_HASH_TABLE_SIZE];
 |     AttributeType listInstr_[INSTR_HASH_TABLE_SIZE];
 | 
      
        |     CpuContextType cpu_context_;
 |   | 
      
        |  
 |  
 | 
      
        |     enum EDebugState {
 |     GenericReg64Bank portRegs_;
 | 
      
        |         STATE_Halted,
 |     GenericReg64Bank portSavedRegs_;
 | 
      
        |         STATE_Normal,
 |     GenericReg64Bank portCSR_;
 | 
      
        |         STATE_Stepping
 |   | 
      
        |     } dbg_state_;
 |   | 
      
        |     uint64_t dbg_step_cnt_;
 |   | 
      
        |  
 |   | 
      
        |     char tstr[1024];
 |   | 
      
        |     uint64_t iregs_prev[32]; // to detect changes
 |   | 
      
        |     struct DebugPortType {
 |   | 
      
        |         bool valid;
 |   | 
      
        |         DebugPortTransactionType *trans;
 |   | 
      
        |         IDbgNbResponse *cb;
 |   | 
      
        |  
 |   | 
      
        |         // local registers
 |   | 
      
        |         uint64_t stepping_mode_steps;
 |   | 
      
        |     } dport;
 |   | 
      
        | };
 | };
 | 
      
        |  
 |  
 | 
      
        | DECLARE_CLASS(CpuRiscV_Functional)
 | DECLARE_CLASS(CpuRiver_Functional)
 | 
      
        |  
 |  
 | 
      
        | }  // namespace debugger
 | }  // namespace debugger
 | 
      
        |  
 |  
 | 
      
        | #endif  // __DEBUGGER_CPU_RISCV_FUNCTIONAL_H__
 | #endif  // __DEBUGGER_CPU_RISCV_FUNCTIONAL_H__
 | 
      
        |  
 |  
 | 
      
        |  No newline at end of file
 |  No newline at end of file
 |