forked from pulp-platform/debug_bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbridge.cpp
More file actions
157 lines (127 loc) · 3.25 KB
/
bridge.cpp
File metadata and controls
157 lines (127 loc) · 3.25 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "bridge.h"
#include <stdarg.h>
Platforms platform_detect(MemIF* mem) {
uint32_t info;
mem->access(0, 0x10000000, 4, (char*)&info);
if (info == 0xDEADBEEF) {
printf ("Detected PULPino\n");
return PULPino;
} else {
info = 1 << 16;
mem->access(1, 0x1B220000 + 0x0, 4, (char*)&info);
mem->access(0, 0x1B220000 + 0x4000 + 0xF10 * 4, 4, (char*)&info);
if (info >> 5 == 32) {
printf ("Detected GAP\n");
return GAP;
} else {
printf ("Detected PULP\n");
return PULP;
}
}
}
bool platform_pulp(MemIF* mem, std::list<DbgIF*>* p_list, LogIF *log) {
uint32_t info;
unsigned int ncores;
mem->access(0, 0x1A103010, 4, (char*)&info);
ncores = info >> 16;
for(int i = 0; i < ncores; i++) {
p_list->push_back(new DbgIF(mem, 0x10300000 + i * 0x8000, log));
}
// set all-stop mode, so that all cores go to debug when one enters debug mode
info = 0xFFFFFFFF;
return mem->access(1, 0x10200038, 4, (char*)&info);
}
bool platform_gap(MemIF* mem, std::list<DbgIF*>* p_list, LogIF *log) {
platform_pulp(mem, p_list, log);
p_list->push_back(new DbgIF(mem, 0x1B220000, log));
return true;
}
bool platform_pulpino(MemIF* mem, std::list<DbgIF*>* p_list, LogIF *log) {
p_list->push_back(new DbgIF(mem, 0x1A110000, log));
return true;
}
Bridge::Bridge(Platforms platform, int portNumber, LogIF *log) {
initBridge(platform, portNumber, NULL, log);
}
Bridge::Bridge(Platforms platform, MemIF *memIF, LogIF *log) {
initBridge(platform, -1, memIF, log);
}
void Bridge::initBridge(Platforms platform, int portNumber, MemIF *memIF, LogIF *log) {
// initialization
if (log == NULL)
this->log = this;
else
this->log = log;
#ifdef FPGA
#ifdef PULPEMU
mem = new ZynqAPBSPIIF();
#else
mem = new FpgaIF();
#endif
#else
if (portNumber != -1) mem = new SimIF("localhost", portNumber);
else if (memIF != NULL) mem = memIF;
else {
fprintf(stderr, "Either a memory interface or a port number must be provided\n");
exit (-1);
}
#endif
if (platform == unknown) {
printf ("Unknown platform, trying auto-detect\n");
platform = platform_detect(mem);
}
switch(platform) {
case GAP:
platform_gap(mem, &dbgifs, this->log);
cache = new GAPCache(mem, &dbgifs, 0x10201400, 0x1B200000);
break;
case PULP:
platform_pulp(mem, &dbgifs, this->log);
cache = new PulpCache(mem, &dbgifs, 0x10201400);
break;
case PULPino:
platform_pulpino(mem, &dbgifs, this->log);
cache = new Cache(mem, &dbgifs);
break;
default:
printf ("ERROR: Unsupported platform found!\n");
return;
}
bp = new BreakPoints(mem, cache);
rsp = new Rsp(1234, mem, this->log, dbgifs, bp);
}
void Bridge::mainLoop()
{
// main loop
while (1) {
rsp->open();
while(!rsp->wait_client());
rsp->loop();
rsp->close();
}
}
Bridge::~Bridge()
{
// cleanup
delete rsp;
for (std::list<DbgIF*>::iterator it = dbgifs.begin(); it != dbgifs.end(); it++) {
delete (*it);
}
delete bp;
delete cache;
delete mem;
}
void Bridge::user(char *str, ...)
{
va_list va;
va_start(va, str);
vprintf(str, va);
va_end(va);
}
void Bridge::debug(char *str, ...)
{
va_list va;
va_start(va, str);
vprintf(str, va);
va_end(va);
}