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_write.cpp] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 sergeykhbr
/**
2
 * @file
3
 * @copyright  Copyright 2016 GNSS Sensor Ltd. All right reserved.
4
 * @author     Sergey Khabarov - sergeykhbr@gmail.com
5
 * @brief      Write memory.
6
 */
7
 
8
#include "cmd_write.h"
9
 
10
namespace debugger {
11
 
12
CmdWrite::CmdWrite(ITap *tap, ISocInfo *info)
13
    : ICommand ("write", tap, info) {
14
 
15
    briefDescr_.make_string("Write memory");
16
    detailedDescr_.make_string(
17
        "Description:\n"
18
        "    Write memory.\n"
19
        "Usage:\n"
20
        "    write <addr> <bytes> [value 64bits]\n"
21
        "Example:\n"
22
        "    write 0xfffff004 4 0x20160323\n"
23
        "    write 0x10040000 16 [0xaabbccdd00112233, 0xaabbccdd00112233]\n");
24
}
25
 
26
bool CmdWrite::isValid(AttributeType *args) {
27
    if ((*args)[0u].is_equal(cmdName_.to_string()) && args->size() == 4) {
28
        return CMD_VALID;
29
    }
30
    return CMD_INVALID;
31
}
32
 
33
void CmdWrite::exec(AttributeType *args, AttributeType *res) {
34
    res->make_nil();
35
    if (!isValid(args)) {
36
        generateError(res, "Wrong argument list");
37
        return;
38
    }
39
 
40
    uint64_t addr = (*args)[1].to_uint64();
41
    uint64_t val = (*args)[3].to_uint64();
42
    unsigned bytes = static_cast<unsigned>((*args)[2].to_uint64());
43
 
44
    /** aech value 8-bytes (64 bits) add 8 for bullet proofness: */
45
    if (wrData_.size() < (bytes + 8)) {
46
        wrData_.make_data(bytes + 8);
47
    }
48
 
49
    if ((*args)[3].is_integer()) {
50
        reinterpret_cast<uint64_t *>(wrData_.data())[0] = val;
51
    } else if ((*args)[3].is_list()) {
52
        const AttributeType &lst = (*args)[3];
53
        uint64_t *tmpbuf = reinterpret_cast<uint64_t *>(wrData_.data());
54
        for (unsigned i = 0; i < lst.size(); i++) {
55
            val = lst[i].to_uint64();
56
            tmpbuf[i] = val;
57
        }
58
    } else {
59
        generateError(res, "Write value must be i or [i*]");
60
        return;
61
    }
62
    tap_->write(addr, bytes, wrData_.data());
63
}
64
 
65
}  // namespace debugger

powered by: WebSVN 2.1.0

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