-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMemoryAccessPort.cpp
96 lines (88 loc) · 2.89 KB
/
MemoryAccessPort.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
91
92
93
94
95
96
#include "MemoryAccessPort.hpp"
#include "DebugPort.hpp"
#include <iostream>
MemoryAccessPort::MemoryAccessPort(DebugPort *debugPort, unsigned int apSel)
: debugPort(debugPort), apSel(apSel) {
// Default: 32-bit auto-incrementing
csw(1, 2);
}
MemoryAccessPort::~MemoryAccessPort() {
// TODO
}
uint32_t MemoryAccessPort::getIdCode() {
debugPort->readAP(apSel, 0xfc);
return debugPort->readRB();
}
uint32_t MemoryAccessPort::readWord(uint32_t address) {
debugPort->writeAP(apSel, 0x04, address);
debugPort->readAP(apSel, 0x0c);
return debugPort->readRB();
}
uint32_t MemoryAccessPort::writeWord(uint32_t address, uint32_t value) {
debugPort->writeAP(apSel, 0x04, address);
debugPort->writeAP(apSel, 0x0c, value);
return debugPort->readRB();
}
uint32_t MemoryAccessPort::readHalf(uint32_t address) {
csw(0, 1);
debugPort->writeAP(apSel, 0x04, address);
debugPort->readAP(apSel, 0x0c);
csw(1, 2);
return debugPort->readRB();
}
uint32_t MemoryAccessPort::writeHalf(uint32_t address, uint32_t value) {
csw(1, 1);
debugPort->writeAP(apSel, 0x04, address);
debugPort->writeAP(apSel, 0x0c, value);
debugPort->writeAP(apSel, 0x0c, value);
csw(1, 2);
return debugPort->readRB();
}
void MemoryAccessPort::readBlock(uint32_t address,
uint32_t count,
uint32_t *buffer) {
debugPort->writeAP(apSel, 0x04, address);
debugPort->readAP(apSel, 0x0c);
for (unsigned int i = 0; i < count - 1; i++) {
buffer[i] = debugPort->readAP(apSel, 0x0c);
}
buffer[count - 1] = debugPort->readRB();
}
void MemoryAccessPort::writeBlock(uint32_t address,
uint32_t count,
const uint32_t *buffer) {
debugPort->writeAP(apSel, 0x04, address);
for (unsigned int i = 0; i < count; i++) {
debugPort->writeAP(apSel, 0x0c, buffer[i]);
}
}
void MemoryAccessPort::writeBlockNonInc(uint32_t address,
uint32_t count,
const uint32_t *buffer) {
// 32-bit non-incrementing addressing
csw(0, 2);
writeBlock(address, count, buffer);
// 32-bit auto-incrementing addressing
csw(1, 2);
}
void MemoryAccessPort::writeHalfs(uint32_t address,
uint32_t count,
const uint32_t *buffer) {
// 16-bit auto-incrementing addressing
csw(1, 1);
debugPort->writeAP(apSel, 0x04, address);
for (unsigned int i = 0; i < count; i++) {
debugPort->writeAP(apSel, 0x0c, buffer[i]);
debugPort->writeAP(apSel, 0x0c, buffer[i]);
}
/*// 16-bit packed-incrementing addressing
csw(2, 1);
writeBlock(address, count, buffer);*/
// 32-bit auto-incrementing addressing
csw(1, 2);
}
void MemoryAccessPort::csw(unsigned int addrInc, unsigned int size) {
debugPort->readAP(apSel, 0x00);
uint32_t csw = debugPort->readRB() & 0xFFFFFF00;
debugPort->writeAP(apSel, 0x00, csw + (addrInc << 4) + size);
}