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_read.cpp] - 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      Read/write memory.
6
 */
7
 
8
#include "cmd_read.h"
9
 
10
namespace debugger {
11
 
12
CmdRead::CmdRead(ITap *tap, ISocInfo *info)
13
    : ICommand ("read", tap, info) {
14
 
15
    briefDescr_.make_string("Read memory");
16
    detailedDescr_.make_string(
17
        "Description:\n"
18
        "    32-bits aligned memory reading. Default bytes = 4 bytes.\n"
19
        "Usage:\n"
20
        "    read <addr> <bytes>\n"
21
        "Example:\n"
22
        "    read 0xfffff004 16\n"
23
        "    read 0xfffff004\n");
24
 
25
    rdData_.make_data(1024);
26
}
27
 
28
bool CmdRead::isValid(AttributeType *args) {
29
    if ((*args)[0u].is_equal(cmdName_.to_string())
30
     && (args->size() == 2 || args->size() == 3)) {
31
        return CMD_VALID;
32
    }
33
    return CMD_INVALID;
34
}
35
 
36
void CmdRead::exec(AttributeType *args, AttributeType *res) {
37
    res->make_nil();
38
    if (!isValid(args)) {
39
        generateError(res, "Wrong argument list");
40
        return;
41
    }
42
 
43
    uint64_t addr = (*args)[1].to_uint64();
44
    unsigned bytes = 4;
45
    if (args->size() == 3) {
46
        bytes = static_cast<unsigned>((*args)[2].to_uint64());
47
    }
48
    /** Use 4 x Buffer size to store formatted output */
49
    if (4 * bytes > rdData_.size()) {
50
        rdData_.make_data(4 * bytes);
51
    }
52
 
53
    if (tap_->read(addr, bytes, rdData_.data()) == TAP_ERROR) {
54
        res->make_nil();
55
        return;
56
    }
57
 
58
    res->make_data(bytes, rdData_.data());
59
}
60
 
61
void CmdRead::to_string(AttributeType *args, AttributeType *res, AttributeType *out) {
62
    uint64_t addr = (*args)[1].to_uint64();
63
    int bytes = 4;
64
    if (args->size() == 3) {
65
        bytes = static_cast<int>((*args)[2].to_uint64());
66
    }
67
 
68
    const uint64_t MSK64 = 0x7ull;
69
    uint64_t addr_start, addr_end, inv_i;
70
    addr_start = addr & ~MSK64;
71
    addr_end = (addr + bytes + 7) & ~MSK64;
72
 
73
    int strsz = 0;
74
    int rdBufSz = static_cast<int>(rdData_.size());
75
    char *strbuf = reinterpret_cast<char *>(rdData_.data());
76
    for (uint64_t i = addr_start; i < addr_end; i++) {
77
        if ((i & MSK64) == 0) {
78
            // Output address:
79
            strsz += RISCV_sprintf(&strbuf[strsz], rdBufSz - strsz,
80
                                "[%016" RV_PRI64 "x]: ", i);
81
        }
82
        inv_i = (i & ~MSK64) | (MSK64 - (i & MSK64));
83
        if ((addr <= inv_i) && (inv_i < (addr + bytes))) {
84
            strsz += RISCV_sprintf(&strbuf[strsz], rdBufSz - strsz, " %02x",
85
                                    res->data()[inv_i - addr]);
86
        } else {
87
            strsz += RISCV_sprintf(&strbuf[strsz], rdBufSz - strsz, " ..");
88
        }
89
        if ((i & MSK64) == MSK64) {
90
            strsz += RISCV_sprintf(&strbuf[strsz], rdBufSz - strsz, "\n");
91
        }
92
    }
93
    out->make_string(strbuf);
94
}
95
 
96
}  // namespace debugger

powered by: WebSVN 2.1.0

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