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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [gui_plugin/] [CpuWidgets/] [MemArea.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      Memory Editor area.
6
 */
7
 
8
#include "MemArea.h"
9
#include "moc_MemArea.h"
10
 
11
#include <memory>
12
#include <string.h>
13
#include <QtWidgets/QBoxLayout>
14
#include <QtWidgets/QLabel>
15
 
16
namespace debugger {
17
 
18
MemArea::MemArea(IGui *gui, QWidget *parent, uint64_t addr, uint64_t sz)
19
    : QPlainTextEdit(parent) {
20
    igui_ = gui;
21
    reqAddr_ = addr;
22
    reqBytes_ = sz;
23
    cmdRead_.make_string("read 0x80000000 20");
24
    data_.make_data(0);
25
    tmpBuf_.make_data(1024);
26
    dataText_.make_string("");
27
    waitingResponse_ = false;
28
 
29
    clear();
30
    QFont font("Courier");
31
    font.setStyleHint(QFont::Monospace);
32
    font.setPointSize(8);
33
    font.setFixedPitch(true);
34
    setFont(font);
35
    QFontMetrics fm(font);
36
    setMinimumWidth(20 + fm.width(tr("[0011223344556677]: 11 22 33 44 55 66 77 88 ")));
37
 
38
    ensureCursorVisible();
39
 
40
    connect(this, SIGNAL(signalUpdateData()), this, SLOT(slotUpdateData()));
41
    slotUpdateByTimer();
42
}
43
 
44
MemArea::~MemArea() {
45
    igui_->removeFromQueue(static_cast<IGuiCmdHandler *>(this));
46
}
47
 
48
void MemArea::slotAddressChanged(AttributeType *cmd) {
49
    reqAddr_ = (*cmd)[0u].to_uint64();
50
    reqBytes_ = static_cast<unsigned>((*cmd)[1].to_int());
51
}
52
 
53
void MemArea::slotUpdateByTimer() {
54
    char tstr[128];
55
    if (waitingResponse_) {
56
        waitingResponse_ = true;
57
    }
58
    RISCV_sprintf(tstr, sizeof(tstr), "read 0x%08" RV_PRI64 "x %d",
59
                                        reqAddr_, reqBytes_);
60
    cmdRead_.make_string(tstr);
61
 
62
    reqAddrZ_ = reqAddr_;
63
    reqBytesZ_ = reqBytes_;
64
    igui_->registerCommand(static_cast<IGuiCmdHandler *>(this),
65
                            &cmdRead_, true);
66
}
67
 
68
void MemArea::slotUpdateData() {
69
    moveCursor(QTextCursor::End);
70
    moveCursor(QTextCursor::Start, QTextCursor::KeepAnchor);
71
    QTextCursor cursor = textCursor();
72
    cursor.insertText(tr(dataText_.to_string()));
73
    update();
74
}
75
 
76
void MemArea::handleResponse(AttributeType *req, AttributeType *resp) {
77
    bool changed = false;
78
    waitingResponse_ = false;
79
    if (resp->is_nil()) {
80
        return;
81
    }
82
    if (resp->size() != data_.size()) {
83
        changed = true;
84
    } else {
85
        for (unsigned i = 0; i < resp->size(); i++) {
86
            if ((*resp)(i) != data_(i)) {
87
                changed = true;
88
                break;
89
            }
90
        }
91
    }
92
    if (!changed) {
93
        return;
94
    }
95
 
96
    data_ = *resp;
97
    to_string(reqAddrZ_, data_.size(), &dataText_);
98
    emit signalUpdateData();
99
}
100
 
101
void MemArea::to_string(uint64_t addr, unsigned bytes, AttributeType *out) {
102
    const uint64_t MSK64 = 0x7ull;
103
    uint64_t addr_start, addr_end, inv_i;
104
    addr_start = addr & ~MSK64;
105
    addr_end = (addr + bytes + 7) & ~MSK64;
106
 
107
    /** Each 8 bytes of data requires 44 bytes in string [addr]: .. ..
108
        Let it be 64 bytes per 8 bytes of data
109
     */
110
    if (tmpBuf_.size() < 8 * data_.size()) {
111
        tmpBuf_.make_data(8 * data_.size());
112
    }
113
    int strsz = 0;
114
 
115
    int  bufsz = tmpBuf_.size();
116
    char *strbuf = reinterpret_cast<char *>(tmpBuf_.data());
117
    for (uint64_t i = addr_start; i < addr_end; i++) {
118
        if ((i & MSK64) == 0) {
119
            // Output address:
120
            strsz += RISCV_sprintf(&strbuf[strsz], bufsz - strsz,
121
                                "[%016" RV_PRI64 "x]: ", i);
122
        }
123
        inv_i = (i & ~MSK64) | (MSK64 - (i & MSK64));
124
        if ((addr <= inv_i) && (inv_i < (addr + bytes))) {
125
            strsz += RISCV_sprintf(&strbuf[strsz], bufsz - strsz,
126
                                    " %02x", data_(inv_i - addr));
127
        } else {
128
            strsz += RISCV_sprintf(&strbuf[strsz], bufsz - strsz, " ..");
129
        }
130
        if ((i & MSK64) == MSK64) {
131
            strsz += RISCV_sprintf(&strbuf[strsz], bufsz - strsz, "\n");
132
        }
133
    }
134
    out->make_string(strbuf);
135
}
136
 
137
 
138
}  // namespace debugger

powered by: WebSVN 2.1.0

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