FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
orbuculum/Src/msgDecoder.c at main · orbcode/orbuculum · GitHub
orbcode
orbuculum
Repository navigation
Code
Issues
3
(3)
Pull requests
4
(4)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
orbuculum
/
Src
/
msgDecoder.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
280 lines (231 loc) · 9.22 KB
Breadcrumbs
orbuculum
/
Src
/
msgDecoder.c
Copy path
File metadata and controls
280 lines (231 loc) · 9.22 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Msg Decoder Module
* ==================
*
* Decoding of individual messages from the decoded stream according to the
* specification in Appendix D4 of the ARMv7-M Architecture Refrence Manual
* document available from https://static.docs.arm.com/ddi0403/e/DDI0403E_B_armv7m_arm.pdf
*/
#include
<string.h>
#include
<assert.h>
#include
"itmDecoder.h"
#include
"msgDecoder.h"
#include
"generics.h"
// ====================================================================================================
// ====================================================================================================
// ====================================================================================================
// Internal routines
// ====================================================================================================
// ====================================================================================================
// ====================================================================================================
static
bool
_handleException
(
struct
ITMPacket
*
packet
,
struct
excMsg
*
decoded
)
{
decoded
->
msgtype
=
MSG_EXCEPTION
;
decoded
->
exceptionNumber
=
( (
packet
->
d
[
1
]
&
0x01
) <<
8
) |
packet
->
d
[
0
];
decoded
->
eventType
=
packet
->
d
[
1
] >>
4
;
return
true;
}
// ====================================================================================================
static
bool
_handleDWTEvent
(
struct
ITMPacket
*
packet
,
struct
dwtMsg
*
decoded
)
{
decoded
->
msgtype
=
MSG_DWT_EVENT
;
decoded
->
event
=
packet
->
d
[
0
]
&
0x2F
;
return
true;
}
// ====================================================================================================
static
bool
_handlePCSample
(
struct
ITMPacket
*
packet
,
struct
pcSampleMsg
*
decoded
)
/* We got a sample of the PC */
{
decoded
->
msgtype
=
MSG_PC_SAMPLE
;
if
(
packet
->
len
==
1
)
{
decoded
->
sleep
=
true;
}
else
{
decoded
->
sleep
=
false;
decoded
->
pc
=
(
packet
->
d
[
3
] <<
24
) | (
packet
->
d
[
2
] <<
16
) | (
packet
->
d
[
1
] <<
8
) | (
packet
->
d
[
0
] );
}
return
true;
}
// ====================================================================================================
static
bool
_handleDataRWWP
(
struct
ITMPacket
*
packet
,
struct
watchMsg
*
decoded
)
/* We got an alert due to a watch pointer */
{
decoded
->
msgtype
=
MSG_DATA_RWWP
;
decoded
->
comp
=
(
packet
->
srcAddr
>>
1
)
&
0x3
;
decoded
->
isWrite
=
( (
packet
->
srcAddr
&
0x01
)
!=
0
);
switch
(
packet
->
len
)
{
case
1
:
decoded
->
data
=
packet
->
d
[
0
];
break
;
case
2
:
decoded
->
data
=
(
packet
->
d
[
0
] ) | ( (
packet
->
d
[
1
] ) <<
8
);
break
;
default
:
decoded
->
data
=
(
packet
->
d
[
0
] ) | ( (
packet
->
d
[
1
] ) <<
8
) | ( (
packet
->
d
[
2
] ) <<
16
) | ( (
packet
->
d
[
3
] ) <<
24
);
break
;
}
return
true;
}
// ====================================================================================================
static
bool
_handleDataAccessWP
(
struct
ITMPacket
*
packet
,
struct
wptMsg
*
decoded
)
/* We got an alert due to a watchpoint */
{
decoded
->
msgtype
=
MSG_DATA_ACCESS_WP
;
decoded
->
comp
=
(
packet
->
srcAddr
>>
1
)
&
0x3
;
decoded
->
data
=
(
packet
->
d
[
0
] ) | ( (
packet
->
d
[
1
] ) <<
8
) | ( (
packet
->
d
[
2
] ) <<
16
) | ( (
packet
->
d
[
3
] ) <<
24
);
return
true;
}
// ====================================================================================================
static
bool
_handleDataOffsetWP
(
struct
ITMPacket
*
packet
,
struct
oswMsg
*
decoded
)
/* We got an alert due to an offset write event */
{
decoded
->
msgtype
=
MSG_OSW
;
decoded
->
comp
=
(
packet
->
srcAddr
>>
1
)
&
0x3
;
decoded
->
offset
=
(
packet
->
d
[
0
] ) | ( (
packet
->
d
[
1
] ) <<
8
);
return
true;
}
// ====================================================================================================
static
bool
_handleHW
(
struct
ITMPacket
*
packet
,
struct
msg
*
decoded
)
/* ... a hardware event has been received, dispatch it */
{
bool
wasDecoded
=
false;
decoded
->
genericMsg
.
msgtype
=
MSG_NONE
;
switch
(
packet
->
srcAddr
)
{
// --------------
case
0
:
/* DWT Event */
wasDecoded
=
_handleDWTEvent
(
packet
, (
struct
dwtMsg
*
)
decoded
);
break
;
// --------------
case
1
:
/* Exception */
wasDecoded
=
_handleException
(
packet
, (
struct
excMsg
*
)
decoded
);
break
;
// --------------
case
2
:
/* PC Counter Sample */
wasDecoded
=
_handlePCSample
(
packet
, (
struct
pcSampleMsg
*
)
decoded
);
break
;
// --------------
default
:
if
( ( (
packet
->
srcAddr
&
0x19
)
==
0x10
)
||
( (
packet
->
srcAddr
&
0x19
)
==
0x11
) )
{
wasDecoded
=
_handleDataRWWP
(
packet
, (
struct
watchMsg
*
)
decoded
);
}
else
if
( (
packet
->
srcAddr
&
0x19
)
==
0x08
)
{
wasDecoded
=
_handleDataAccessWP
(
packet
, (
struct
wptMsg
*
)
decoded
);
}
else
if
( (
packet
->
srcAddr
&
0x19
)
==
0x09
)
{
wasDecoded
=
_handleDataOffsetWP
(
packet
, (
struct
oswMsg
*
)
decoded
);
}
break
;
// --------------
}
return
wasDecoded
;
}
// ====================================================================================================
static
bool
_handleSW
(
struct
ITMPacket
*
packet
,
struct
swMsg
*
decoded
)
{
decoded
->
msgtype
=
MSG_SOFTWARE
;
decoded
->
srcAddr
=
packet
->
srcAddr
;
decoded
->
len
=
packet
->
len
;
/* Build 32 bit value the long way around to avoid type-punning issues */
decoded
->
value
=
(
packet
->
d
[
3
] <<
24
) |
(
packet
->
d
[
2
] <<
16
) |
(
packet
->
d
[
1
] <<
8
) |
(
packet
->
d
[
0
] );
return
true;
}
// ====================================================================================================
static
bool
_handleNISYNC
(
struct
ITMPacket
*
packet
,
struct
nisyncMsg
*
decoded
)
{
decoded
->
msgtype
=
MSG_NISYNC
;
decoded
->
type
=
packet
->
d
[
0
];
decoded
->
addr
=
(
packet
->
d
[
1
]
&
0xFE
) |
(
packet
->
d
[
2
] <<
8
) |
(
packet
->
d
[
3
] <<
16
) |
(
packet
->
d
[
4
] <<
24
);
return
true;
}
// ====================================================================================================
static
bool
_handleTS
(
struct
ITMPacket
*
packet
,
struct
TSMsg
*
decoded
)
/* ... a timestamp */
{
decoded
->
msgtype
=
MSG_TS
;
uint32_t
stamp
=
0
;
if
( !( (
packet
->
d
[
0
] )
&
0x80
) )
{
/* This is packet format 2 ... just a simple increment */
stamp
=
packet
->
d
[
0
] >>
4
;
}
else
{
/* This is packet format 1 ... full decode needed */
decoded
->
timeStatus
=
(
packet
->
d
[
0
]
&
0x30
) >>
4
;
stamp
=
(
packet
->
d
[
1
] )
&
0x7f
;
if
(
packet
->
len
>
2
)
{
stamp
|= (
packet
->
d
[
2
]
&
0x7F
) <<
7
;
}
if
(
packet
->
len
>
3
)
{
stamp
|= (
packet
->
d
[
3
]
&
0x7F
) <<
14
;
}
if
(
packet
->
len
>
4
)
{
stamp
|= (
packet
->
d
[
4
]
&
0x7f
) <<
21
;
}
}
decoded
->
timeInc
=
stamp
;
return
true;
}
// ====================================================================================================
// ====================================================================================================
// ====================================================================================================
// Publically available routines
// ====================================================================================================
// ====================================================================================================
// ====================================================================================================
bool
msgDecoder
(
struct
ITMPacket
*
packet
,
struct
msg
*
decoded
)
{
bool
wasDecoded
=
false;
decoded
->
genericMsg
.
msgtype
=
MSG_NONE
;
decoded
->
genericMsg
.
ts
=
genericsTimestampuS
();
/* Stamp as early as possible, even if its not real */
switch
(
packet
->
type
)
{
case
ITM_PT_NONE
:
decoded
->
genericMsg
.
msgtype
=
MSG_NONE
;
break
;
case
ITM_PT_TS
:
wasDecoded
=
_handleTS
(
packet
, (
struct
TSMsg
*
)
decoded
);
break
;
case
ITM_PT_SW
:
wasDecoded
=
_handleSW
(
packet
, (
struct
swMsg
*
)
decoded
);
break
;
case
ITM_PT_HW
:
wasDecoded
=
_handleHW
(
packet
,
decoded
);
break
;
case
ITM_PT_NISYNC
:
wasDecoded
=
_handleNISYNC
(
packet
, (
struct
nisyncMsg
*
)
decoded
);
break
;
case
ITM_PT_XTN
:
genericsReport
(
V_INFO
,
"Unknown Extension Packet Received"
EOL
);
decoded
->
genericMsg
.
msgtype
=
MSG_UNKNOWN
;
break
;
case
ITM_PT_RSRVD
:
genericsReport
(
V_INFO
,
"Reserved Packet Received"
EOL
);
decoded
->
genericMsg
.
msgtype
=
MSG_RESERVED
;
break
;
default
:
decoded
->
genericMsg
.
msgtype
=
MSG_ERROR
;
break
;
}
return
wasDecoded
;
}
// ====================================================================================================
Back
|
FazBrowse Home
|
New Git URL