-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebugutils.cc
159 lines (141 loc) · 3.89 KB
/
debugutils.cc
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
158
159
/* utilities to debug the stacked accelerators
Copyright (c) 2021 Amano laboratory, Keio University.
Author: Takuya Kojima
This file is part of CubeSim, a cycle accurate simulator for 3-D stacked system.
CubeSim is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
CubeSim is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CubeSim. If not, see <https://www.gnu.org/licenses/>.
*/
#include "debugutils.h"
#include "vmips.h"
#include "mapper.h"
#include "cpu.h"
#include <stdio.h>
AcceleratorDebugger::AcceleratorDebugger(DebuggerClient* acdebugger_) :
acdebugger(acdebugger_), DeviceMap (ACDBGR_SIZE)
{
cmd = 0;
arg = 0;
prev_fetch_addr = 0x3;
}
uint32 AcceleratorDebugger::fetch_word(uint32 offset, int mode, DeviceExc *client)
{
switch (offset) {
case RPLY_OFFSET:
return acdebugger->get_dbg_data();
case CMD_OFFSET:
return cmd;
case ARG_OFFSET:
return arg;
case SEND_OFFSET:
return 0;
default:
return 0;
}
}
uint8 AcceleratorDebugger::fetch_byte(uint32 offset, DeviceExc *client)
{
if (prev_fetch_addr != (offset & ~0x3)) {
prev_fetch_addr = offset & ~0x3;
fetch_buf = fetch_word(prev_fetch_addr, DATALOAD, client);
fetch_buf = machine->physmem->host_to_mips_word(fetch_buf);
}
uint32 byte_offset_in_word = (offset & 0x03);
if (!machine->cpu->is_bigendian()) {
byte_offset_in_word = 3 - byte_offset_in_word;
}
uint8 rv;
switch (byte_offset_in_word) {
case 0: rv = (fetch_buf >> 24) & 0xff; break;
case 1: rv = (fetch_buf >> 16) & 0xff; break;
case 2: rv = (fetch_buf >> 8) & 0xff; break;
case 3: rv = fetch_buf & 0xff; break;
default: rv = 0;
}
return rv;
}
void AcceleratorDebugger::store_word(uint32 offset, uint32 data, DeviceExc *client)
{
fprintf(stderr, "sw %X %x\n", offset, data);
switch (offset) {
case CMD_OFFSET:
cmd = data;
break;
case ARG_OFFSET:
arg = data;
break;
case SEND_OFFSET:
acdebugger->send_commnad(cmd, arg);
break;
case RPLY_OFFSET:
//read only
return;
default:
return;
}
}
void AcceleratorDebugger::store_byte(uint32 offset, uint8 data, DeviceExc *client)
{
uint32 word_data;
uint32 store_addr = offset & ~0x3;
word_data = fetch_word(store_addr, DATALOAD, client);
word_data = machine->physmem->host_to_mips_word(word_data);
uint32 byte_offset_in_word = (offset & 0x03);
if (!machine->cpu->is_bigendian()) {
byte_offset_in_word = 3 - byte_offset_in_word;
}
switch (byte_offset_in_word) {
case 0:
word_data = ((data << 24) & 0xff000000) |
(word_data & ~0xff000000);
break;
case 1:
word_data = ((data << 16) & 0x00ff0000) |
(word_data & ~0x00ff0000);
break;
case 2:
word_data = ((data << 8) & 0x0000ff00) |
(word_data & ~0x0000ff00);
break;
case 3:
word_data = (data & 0x000000ff) |
(word_data & ~0x000000ff);
break;
default: return;
}
store_word(store_addr, word_data, client);
}
void DebuggerClient::__cmd_parser(uint32 cmd, uint8 &op,
uint8 &func, uint8 &mod, uint8 &offset)
{
op = (cmd >> 24) & 0xFF;
func = (cmd >> 16) & 0xFF;
mod = (cmd >> 8) & 0xFF;
offset = cmd & 0xFF;
}
bool DebuggerClient::__compare(uint32 a, uint32 b, uint8 comparator)
{
switch (comparator) {
case DBG_CMD_COMPEQ:
return a == b;
case DBG_CMD_COMPNE:
return a != b;
case DBG_CMD_COMPGT:
return a > b;
case DBG_CMD_COMPLT:
return a < b;
case DBG_CMD_COMPGE:
return a >= b;
case DBG_CMD_COMPLE:
return a <= b;
default:
return false;
}
}