-
Notifications
You must be signed in to change notification settings - Fork 1
/
JtagArmAnalyzer.cpp
155 lines (138 loc) · 4.12 KB
/
JtagArmAnalyzer.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
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
/*
* jtaglogic
*
* Copyright (C) 2013-2014 Fredrik Ahlberg
*
* This program 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.
*
* This program 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 this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "JtagArmAnalyzer.h"
#include <cstring>
#include <cstdio>
static const char *DPRegs[] = {"DP0 (invalid)","CTRL/STAT","SELECT","RDBUFF"};
static const char *APRegs[] = {"CSW","TAR","AP08","DRW","BD0","BD1","BD2","BD3"};
JtagArmAnalyzer::JtagArmAnalyzer(JtagAnalyzerSettings *settings)
: mSettings(settings), mLastInstruction(0), mAPBank(0)
{
}
void JtagArmAnalyzer::process(enum JtagState state, U64 in, U64 out, U32 bits,
U64 begin, U64 end, JtagAnalyzerResults *results)
{
in = JtagAnalyzer::FlipWord(in, bits);
out = JtagAnalyzer::FlipWord(out, bits);
if (state == JtagShiftIR) {
mLastInstruction = in & 0x0f;
if (mLastInstruction == ArmBYPASS) {
Frame result_frame;
result_frame.mStartingSampleInclusive = begin;
result_frame.mEndingSampleInclusive = end;
result_frame.mData1 = 0;
result_frame.mData2 = 0;
result_frame.mFlags = mAPBank | mLastInstruction;
results->AddFrame(result_frame);
results->CommitResults();
}
} else if (state == JtagShiftDR) {
Frame result_frame;
result_frame.mStartingSampleInclusive = begin;
result_frame.mEndingSampleInclusive = end;
result_frame.mData1 = in;
result_frame.mData2 = out;
result_frame.mFlags = mAPBank | mLastInstruction;
if (mLastInstruction == ArmDPACC && ((in & 7) == 4)) {
// Write to DP SELECT
mAPBank = (in >> 3) & 0xf0;
}
results->AddFrame(result_frame);
results->CommitResults();
}
}
void JtagArmAnalyzer::generateBubbleText(Frame &frame, Channel &channel,
DisplayBase display_base, char *str)
{
ArmInstruction instr = static_cast<ArmInstruction>(frame.mFlags & 0xf);
U32 APbank = frame.mFlags & 0xf0;
if (channel == mSettings->mTDIChannel) {
switch (instr) {
case ArmABORT:
if (frame.mData1 == 0x08) {
strcpy(str, "ABORT");
} else {
sprintf(str, "Invalid ABORT (%08x)", frame.mData1);
}
break;
case ArmDPACC:
if (frame.mData1 & 1) {
sprintf(str, "Read %s", DPRegs[(frame.mData1 >> 1) & 3]);
} else {
sprintf(str, "Write %s = %08x",
DPRegs[(frame.mData1 >> 1) & 3], frame.mData1 >> 3);
}
break;
case ArmAPACC:
{
U32 APaddr = APbank | ((frame.mData1 << 1) & 0xc);
if (frame.mData1 & 1) {
if (APaddr == 0xfc) {
strcpy(str, "Read IDR");
} else if (APaddr == 0xf8) {
strcpy(str, "Read DBGDRAR");
} else if (APaddr <= 0x1C) {
sprintf(str, "Read %s", APRegs[APaddr >> 2]);
} else {
sprintf(str, "Read AP %x", APaddr);
}
} else {
if (APaddr > 0x1C) {
sprintf(str, "Write AP %x (%x %x) = %08x",
APaddr,
frame.mData1 >> 3);
} else {
sprintf(str, "Write %s = %08x",
APRegs[APaddr >> 2],
frame.mData1 >> 3);
}
}
}
break;
case ArmBYPASS:
strcpy(str, "BYPASS");
break;
default:
sprintf(str, "Unknown %x", instr);
}
} else if (channel == mSettings->mTDOChannel) {
switch (instr) {
case ArmIDCODE:
sprintf(str, "IDCODE %08x", frame.mData2);
break;
case ArmDPACC:
case ArmAPACC:
if ((frame.mData2 & 3) == StatusOkFault) {
sprintf(str, "%cP OK %08x",
instr == ArmDPACC ? 'D' : 'A',
frame.mData2 >> 3);
} else if ((frame.mData2 & 3) == StatusWait) {
sprintf(str, "%cP WAIT",
instr == ArmDPACC ? 'D' : 'A');
} else {
sprintf(str, "%cP Invalid ACK! (%2x)",
instr == ArmDPACC ? 'D' : 'A',
frame.mData2 & 3);
}
break;
}
}
}