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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [simple_plugin/] [simple_plugin.cpp] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 sergeykhbr
/**
2
 * @file
3
 * @copyright  Copyright 2016 GNSS Sensor Ltd. All right reserved.
4
 * @author     Sergey Khabarov - sergeykhbr@gmail.com
5
 * @brief      Demo plugin for the RISC-V debugger library.
6
 */
7
 
8
#include "api_core.h"
9
#include "iclass.h"
10
#include "iservice.h"
11
#include "isimple_plugin.h"
12
#include "coreservices/icommand.h"
13
#include "coreservices/icmdexec.h"
14
 
15
namespace debugger {
16
 
17
class CmdDemo : public ICommand  {
18
public:
19
    explicit CmdDemo(ITap *tap, ISocInfo *info)
20
        : ICommand ("democmd", tap, info) {
21
 
22
        briefDescr_.make_string("Example of custom command implementation");
23
        detailedDescr_.make_string(
24
            "Description:\n"
25
            "    Demonstration command example.\n"
26
            "Example:\n"
27
            "    democmd\n");
28
    }
29
 
30
    /** ICommand */
31
    virtual bool isValid(AttributeType *args) {
32
        if ((*args)[0u].is_equal("democmd")) {
33
            return CMD_VALID;
34
        }
35
        return CMD_INVALID;
36
    }
37
    virtual void exec(AttributeType *args, AttributeType *res) {
38
        Reg64Type t1;
39
        tap_->read(0xFFFFF000, 4, t1.buf);
40
        res->make_list(2);
41
        (*res)[0u].make_string("Reading 0xfffff000");
42
        (*res)[1].make_uint64(t1.buf32[0]);
43
    }
44
 
45
private:
46
};
47
 
48
class SimplePlugin : public IService,
49
                     public ISimplePlugin {
50
public:
51
    SimplePlugin(const char *name) : IService(name) {
52
        /// Interface registration
53
        registerInterface(static_cast<ISimplePlugin *>(this));
54
        /// Test attribute that will be saved/restored by core
55
        registerAttribute("attr1", &attr1_);
56
        attr1_.make_string("This is test attr value");
57
    }
58
    ~SimplePlugin() {}
59
 
60
    /** IService interface */
61
    virtual void postinitService() {
62
        RISCV_printf(this, LOG_INFO, "Plugin post-init example: attr1_='%s'",
63
                                        attr1_.to_string());
64
        AttributeType taplist, soclist, execlist;
65
        RISCV_get_services_with_iface(IFACE_TAP, &taplist);
66
        if (taplist.size() == 0) {
67
            return;
68
        }
69
        RISCV_get_services_with_iface(IFACE_SOC_INFO, &soclist);
70
        if (soclist.size() == 0) {
71
            return;
72
        }
73
        RISCV_get_services_with_iface(IFACE_CMD_EXECUTOR, &execlist);
74
        if (execlist.size() == 0) {
75
            return;
76
        }
77
        IService *iserv;
78
        iserv = static_cast<IService *>(taplist[0u].to_iface());
79
        ITap * itap = static_cast<ITap *>(iserv->getInterface(IFACE_TAP));
80
 
81
        iserv = static_cast<IService *>(soclist[0u].to_iface());
82
        ISocInfo *info =
83
            static_cast<ISocInfo *>(iserv->getInterface(IFACE_SOC_INFO));
84
 
85
        iserv = static_cast<IService *>(execlist[0u].to_iface());
86
        exec_ = static_cast<ICmdExecutor *>(
87
            iserv->getInterface(IFACE_CMD_EXECUTOR));
88
        pcmd_ = new CmdDemo(itap, info);
89
        exec_->registerCommand(pcmd_);
90
    }
91
    virtual void predeleteService() {
92
        exec_->unregisterCommand(pcmd_);
93
        delete pcmd_;
94
    }
95
 
96
    /** ISimplePlugin interface */
97
    virtual int exampleAction(int val) {
98
        RISCV_info("This is exampleAction(): val=%08x", val);
99
        return 0x555;
100
    }
101
 
102
private:
103
    AttributeType attr1_;
104
    ICmdExecutor *exec_;
105
    CmdDemo *pcmd_;
106
};
107
 
108
DECLARE_CLASS(SimplePlugin)
109
 
110
extern "C" void plugin_init(void) {
111
    REGISTER_CLASS(SimplePlugin);
112
}
113
 
114
}  // namespace debugger

powered by: WebSVN 2.1.0

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