forked from pulp-platform/debug_bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug_if.cpp
90 lines (73 loc) · 1.84 KB
/
debug_if.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "debug_if.h"
#include "mem.h"
#include <stdio.h>
DbgIF::DbgIF(MemIF* mem, unsigned int base_addr, LogIF *log) {
this->m_mem = mem;
this->m_base_addr = base_addr;
this->log = log;
// let's discover core id and cluster id
this->halt();
this->csr_read(0xF10, &m_thread_id);
log->debug("Found a core with id %X\n", m_thread_id);
}
void
DbgIF::flush() {
// Write back the value of NPC so that it triggers a flush of the prefetch buffer
uint32_t npc;
read(DBG_NPC_REG, &npc);
write(DBG_NPC_REG, npc);
}
bool
DbgIF::write(uint32_t addr, uint32_t wdata) {
return m_mem->access(1, m_base_addr + addr, 4, (char*)&wdata);
}
bool
DbgIF::read(uint32_t addr, uint32_t* rdata) {
return m_mem->access(0, m_base_addr + addr, 4, (char*)rdata);
}
bool
DbgIF::halt() {
uint32_t data;
if (!this->read(DBG_CTRL_REG, &data)) {
fprintf(stderr, "debug_is_stopped: Reading from CTRL reg failed\n");
return false;
}
data |= 0x1 << 16;
return this->write(DBG_CTRL_REG, data);
}
bool
DbgIF::is_stopped() {
uint32_t data;
if (!this->read(DBG_CTRL_REG, &data)) {
fprintf(stderr, "debug_is_stopped: Reading from CTRL reg failed\n");
return false;
}
if (data & 0x10000)
return true;
else
return false;
}
bool
DbgIF::gpr_read_all(uint32_t *data) {
return m_mem->access(0, m_base_addr + 0x0400, 32 * 4, (char*)data);
}
bool
DbgIF::gpr_read(unsigned int i, uint32_t *data) {
return this->read(0x0400 + i * 4, data);
}
bool
DbgIF::gpr_write(unsigned int i, uint32_t data) {
return this->write(0x0400 + i * 4, data);
}
bool
DbgIF::csr_read(unsigned int i, uint32_t *data) {
return this->read(0x4000 + i * 4, data);
}
bool
DbgIF::csr_write(unsigned int i, uint32_t data) {
return this->write(0x4000 + i * 4, data);
}
void
DbgIF::get_name(char* str, size_t len) {
snprintf(str, len, "Core %08X", this->m_thread_id);
}