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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [libdbg64g/] [services/] [exec/] [cmd/] [cmd_reg.cpp] - Blame information for rev 5

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

Line No. Rev Author Line
1 4 sergeykhbr
/*
2
 *  Copyright 2018 Sergey Khabarov, sergeykhbr@gmail.com
3
 *
4
 *  Licensed under the Apache License, Version 2.0 (the "License");
5
 *  you may not use this file except in compliance with the License.
6
 *  You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *  Unless required by applicable law or agreed to in writing, software
11
 *  distributed under the License is distributed on an "AS IS" BASIS,
12
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *  See the License for the specific language governing permissions and
14
 *  limitations under the License.
15 3 sergeykhbr
 */
16
 
17
#include "cmd_reg.h"
18
 
19
namespace debugger {
20
 
21
CmdReg::CmdReg(ITap *tap, ISocInfo *info)
22
    : ICommand ("reg", tap, info) {
23
 
24
    briefDescr_.make_string("Read/write register value");
25
    detailedDescr_.make_string(
26
        "Description:\n"
27
        "    Read or modify the specific CPU's register.\n"
28
        "Usage:\n"
29
        "    reg name\n"
30
        "    reg name wrvalue\n"
31
        "Example:\n"
32
        "    reg\n"
33
        "    reg pc\n"
34
        "    reg sp 0x10007fc0\n");
35
}
36
 
37
bool CmdReg::isValid(AttributeType *args) {
38
    if ((*args)[0u].is_equal(cmdName_.to_string())
39
     && (args->size() == 2 || args->size() == 3)) {
40
        return CMD_VALID;
41
    }
42
    return CMD_INVALID;
43
}
44
 
45
void CmdReg::exec(AttributeType *args, AttributeType *res) {
46
    if (!isValid(args)) {
47
        generateError(res, "Wrong argument list");
48
        return;
49
    }
50
    res->make_nil();
51
 
52
    uint64_t val;
53
    const char *reg_name = (*args)[1].to_string();
54
    uint64_t addr = info_->reg2addr(reg_name);
55
    if (addr == REG_ADDR_ERROR) {
56
        char tstr[128];
57
        RISCV_sprintf(tstr, sizeof(tstr), "%s not found", reg_name);
58
        generateError(res, tstr);
59
        return;
60
    }
61
 
62
    if (args->size() == 2) {
63
        int err = tap_->read(addr, 8, reinterpret_cast<uint8_t *>(&val));
64
        if (err == TAP_ERROR) {
65
            return;
66
        }
67
        res->make_uint64(val);
68
    } else {
69
        val = (*args)[2].to_uint64();
70
        tap_->write(addr, 8, reinterpret_cast<uint8_t *>(&val));
71
    }
72
}
73
 
74
}  // namespace debugger

powered by: WebSVN 2.1.0

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