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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
|
/*
* \file ocsd_dcd_mngr.h
* \brief OpenCSD : Decoder manager base class.
*
* \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved.
*/
/*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ARM_OCSD_DCD_MNGR_H_INCLUDED
#define ARM_OCSD_DCD_MNGR_H_INCLUDED
#include "opencsd/ocsd_if_types.h"
#include "common/ocsd_dcd_mngr_i.h"
#include "common/ocsd_lib_dcd_register.h"
#include "common/trc_pkt_decode_base.h"
#include "common/trc_pkt_proc_base.h"
template <class P, class Pt, class Pc>
class DecoderMngrBase : public IDecoderMngr
{
public:
DecoderMngrBase(const std::string &decoderTypeName, ocsd_trace_protocol_t builtInProtocol);
virtual ~DecoderMngrBase() {};
// create decoder interface.
virtual ocsd_err_t createDecoder(const int create_flags, const int instID, const CSConfig *p_config, TraceComponent **p_component);
virtual ocsd_err_t destroyDecoder(TraceComponent *p_component);
virtual const ocsd_trace_protocol_t getProtocolType() const { return m_builtInProtocol; }
// common
virtual ocsd_err_t attachErrorLogger(TraceComponent *pComponent, ITraceErrorLog *pIErrorLog);
// pkt decoder
virtual ocsd_err_t attachInstrDecoder(TraceComponent *pComponent, IInstrDecode *pIInstrDec);
virtual ocsd_err_t attachMemAccessor(TraceComponent *pComponent, ITargetMemAccess *pMemAccessor);
virtual ocsd_err_t attachOutputSink(TraceComponent *pComponent, ITrcGenElemIn *pOutSink);
// pkt processor
virtual ocsd_err_t attachPktMonitor(TraceComponent *pComponent, ITrcTypedBase *pPktRawDataMon);
virtual ocsd_err_t attachPktIndexer(TraceComponent *pComponent, ITrcTypedBase *pPktIndexer);
virtual ocsd_err_t attachPktSink(TraceComponent *pComponent, ITrcTypedBase *pPktDataInSink);
// data input connection interface
virtual ocsd_err_t getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn);
// generate a Config object from opaque config struct pointer.
virtual ocsd_err_t createConfigFromDataStruct(CSConfig **pConfigBase, const void *pDataStruct);
// implemented by decoder handler derived classes
virtual TraceComponent *createPktProc(const bool useInstID, const int instID) = 0;
virtual TraceComponent *createPktDecode(const bool useInstID, const int instID) { return 0; };
virtual CSConfig *createConfig(const void *pDataStruct) = 0;
private:
const ocsd_trace_protocol_t m_builtInProtocol; //!< Protocol ID if built in type.
};
template <class P, class Pt, class Pc>
DecoderMngrBase<P,Pt,Pc>::DecoderMngrBase(const std::string &decoderTypeName, ocsd_trace_protocol_t builtInProtocol) :
m_builtInProtocol(builtInProtocol)
{
OcsdLibDcdRegister *pDcdReg = OcsdLibDcdRegister::getDecoderRegister();
if(pDcdReg)
pDcdReg->registerDecoderTypeByName(decoderTypeName,this);
}
template <class P, class Pt, class Pc>
ocsd_err_t DecoderMngrBase<P,Pt,Pc>::createDecoder(const int create_flags, const int instID, const CSConfig *pConfig, TraceComponent **ppTrcComp)
{
TraceComponent *pkt_proc = 0;
TraceComponent *pkt_dcd = 0;
bool bUseInstID = (create_flags & OCSD_CREATE_FLG_INST_ID) != 0;
bool bDecoder = (create_flags & OCSD_CREATE_FLG_FULL_DECODER) != 0;
bool bUnConfigured = (pConfig == 0);
const Pc *pConf = dynamic_cast< const Pc * >(pConfig);
// check inputs valid...
if((pConf == 0) && !bUnConfigured)
return OCSD_ERR_INVALID_PARAM_TYPE;
if((create_flags & (OCSD_CREATE_FLG_PACKET_PROC | OCSD_CREATE_FLG_FULL_DECODER)) == 0)
return OCSD_ERR_INVALID_PARAM_VAL;
// always need a packet processor
pkt_proc = createPktProc(bUseInstID, instID);
if(!pkt_proc)
return OCSD_ERR_MEM;
// set the op mode flags
pkt_proc->setComponentOpMode(create_flags & (OCSD_OPFLG_COMP_MODE_MASK | OCSD_OPFLG_PKTPROC_COMMON));
// set the configuration
TrcPktProcBase<P,Pt,Pc> *pProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> *>(pkt_proc);
if(pProcBase == 0)
return OCSD_ERR_INVALID_PARAM_TYPE;
if(!bUnConfigured)
pProcBase->setProtocolConfig(pConf);
*ppTrcComp = pkt_proc;
// may need a packet decoder
if(bDecoder)
{
// create the decoder
pkt_dcd = createPktDecode(bUseInstID, instID);
if(!pkt_dcd)
return OCSD_ERR_MEM;
// set the op mode flags
pkt_dcd->setComponentOpMode(create_flags & (OCSD_OPFLG_COMP_MODE_MASK | OCSD_OPFLG_PKTDEC_COMMON));
// get the decoder base
TrcPktDecodeBase<P,Pc> *pBase = dynamic_cast< TrcPktDecodeBase<P,Pc> *>(pkt_dcd);
if(pBase == 0)
return OCSD_ERR_INVALID_PARAM_TYPE;
if(!bUnConfigured)
pBase->setProtocolConfig(pConf);
// associate decoder with packet processor
// -> this means a TraceComponent with an associated component is a packet decoder.
// the associated component is the connected packet processor.
pkt_dcd->setAssocComponent(pkt_proc);
// connect packet processor and decoder
pProcBase->getPacketOutAttachPt()->attach(pBase);
*ppTrcComp = pkt_dcd;
}
return OCSD_OK;
}
template <class P, class Pt, class Pc>
ocsd_err_t DecoderMngrBase<P,Pt,Pc>::destroyDecoder(TraceComponent *pComponent)
{
if(pComponent->getAssocComponent() != 0)
delete pComponent->getAssocComponent();
delete pComponent;
return OCSD_OK;
}
template <class P, class Pt, class Pc>
ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachErrorLogger(TraceComponent *pComponent, ITraceErrorLog *pIErrorLog)
{
return pComponent->getErrorLogAttachPt()->replace_first(pIErrorLog);
}
template <class P, class Pt, class Pc>
ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachInstrDecoder(TraceComponent *pComponent, IInstrDecode *pIInstrDec)
{
ocsd_err_t err = OCSD_ERR_DCD_INTERFACE_UNUSED;
if(pComponent->getAssocComponent() == 0) // no associated component - so this is a packet processor
return OCSD_ERR_INVALID_PARAM_TYPE;
TrcPktDecodeI *pDcdI = dynamic_cast< TrcPktDecodeI * >(pComponent);
if(pDcdI == 0)
return OCSD_ERR_INVALID_PARAM_TYPE;
if(pDcdI->getUsesIDecode())
err = pDcdI->getInstrDecodeAttachPt()->replace_first(pIInstrDec);
return err;
}
template <class P, class Pt, class Pc>
ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachMemAccessor(TraceComponent *pComponent, ITargetMemAccess *pMemAccessor)
{
ocsd_err_t err = OCSD_ERR_DCD_INTERFACE_UNUSED;
if(pComponent->getAssocComponent() == 0) // no associated component - so this is a packet processor
return OCSD_ERR_INVALID_PARAM_TYPE;
TrcPktDecodeI *pDcdI = dynamic_cast< TrcPktDecodeI * >(pComponent);
if(pDcdI == 0)
return OCSD_ERR_INVALID_PARAM_TYPE;
if(pDcdI->getUsesMemAccess())
err = pDcdI->getMemoryAccessAttachPt()->replace_first(pMemAccessor);
return err;
}
template <class P, class Pt, class Pc>
ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachOutputSink(TraceComponent *pComponent, ITrcGenElemIn *pOutSink)
{
ocsd_err_t err = OCSD_ERR_INVALID_PARAM_TYPE;
if(pComponent->getAssocComponent() == 0) // no associated component - so this is a packet processor
return err;
TrcPktDecodeI *pDcdI = dynamic_cast< TrcPktDecodeI * >(pComponent);
if(pDcdI == 0)
return OCSD_ERR_INVALID_PARAM_TYPE;
err = pDcdI->getTraceElemOutAttachPt()->replace_first(pOutSink);
return err;
}
template <class P, class Pt, class Pc>
ocsd_err_t DecoderMngrBase<P,Pt,Pc>::getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn)
{
// find the packet processor
TraceComponent *pPktProc = pComponent;
if(pComponent->getAssocComponent() != 0)
pPktProc = pComponent->getAssocComponent();
TrcPktProcI *pPPI = dynamic_cast< TrcPktProcI * >(pPktProc);
if(pPPI == 0)
return OCSD_ERR_INVALID_PARAM_TYPE;
*ppDataIn = pPPI;
return OCSD_OK;
}
template <class P, class Pt, class Pc>
ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachPktMonitor(TraceComponent *pComponent, ITrcTypedBase *pPktRawDataMon)
{
// find the packet processor
TraceComponent *pPktProc = pComponent;
if(pComponent->getAssocComponent() != 0)
pPktProc = pComponent->getAssocComponent();
// get the packet processor
TrcPktProcBase<P,Pt,Pc> *pPktProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> * >(pPktProc);
if(pPktProcBase == 0)
return OCSD_ERR_INVALID_PARAM_TYPE;
// get the interface
IPktRawDataMon<P> *p_If = dynamic_cast< IPktRawDataMon<P> * >(pPktRawDataMon);
if(p_If == 0)
return OCSD_ERR_INVALID_PARAM_TYPE;
return pPktProcBase->getRawPacketMonAttachPt()->replace_first(p_If);
}
template <class P, class Pt, class Pc>
ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachPktIndexer(TraceComponent *pComponent, ITrcTypedBase *pPktIndexer)
{
// find the packet processor
TraceComponent *pPktProc = pComponent;
if(pComponent->getAssocComponent() != 0)
pPktProc = pComponent->getAssocComponent();
// get the packet processor
TrcPktProcBase<P,Pt,Pc> *pPktProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> * >(pPktProc);
if(pPktProcBase == 0)
return OCSD_ERR_INVALID_PARAM_TYPE;
// get the interface
ITrcPktIndexer<Pt> *p_If = dynamic_cast< ITrcPktIndexer<Pt> * >(pPktIndexer);
if(p_If == 0)
return OCSD_ERR_INVALID_PARAM_TYPE;
return pPktProcBase->getTraceIDIndexerAttachPt()->replace_first(p_If);
}
template <class P, class Pt, class Pc>
ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachPktSink(TraceComponent *pComponent, ITrcTypedBase *pPktDataInSink)
{
// must be solo packet processor
if(pComponent->getAssocComponent() != 0)
return OCSD_ERR_INVALID_PARAM_TYPE;
// interface must be the correct one.
IPktDataIn<P> *pkt_in_i = dynamic_cast< IPktDataIn<P> * >(pPktDataInSink);
if(pkt_in_i == 0)
return OCSD_ERR_INVALID_PARAM_TYPE;
// get the packet processor
TrcPktProcBase<P,Pt,Pc> *pPktProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> * >(pComponent);
if(pPktProcBase == 0)
return OCSD_ERR_INVALID_PARAM_TYPE;
// attach
return pPktProcBase->getPacketOutAttachPt()->replace_first(pkt_in_i);
}
template <class P, class Pt, class Pc>
ocsd_err_t DecoderMngrBase<P,Pt,Pc>::createConfigFromDataStruct(CSConfig **pConfigBase, const void *pDataStruct)
{
CSConfig *pConfig = createConfig(pDataStruct);
if(!pConfig)
return OCSD_ERR_MEM;
*pConfigBase = pConfig;
return OCSD_OK;
}
/****************************************************************************************************/
/* Full decoder / packet process pair, templated base for creating decoder objects */
/****************************************************************************************************/
template< class P, // Packet class.
class Pt, // Packet enum type ID.
class Pc, // Processor config class.
class PcSt, // Processor config struct type
class PktProc, // Packet processor class.
class PktDcd> // Packet decoder class.
class DecodeMngrFullDcd : public DecoderMngrBase<P,Pt,Pc>
{
public:
DecodeMngrFullDcd (const std::string &name, ocsd_trace_protocol_t builtInProtocol)
: DecoderMngrBase<P,Pt,Pc>(name,builtInProtocol) {};
virtual ~DecodeMngrFullDcd() {};
virtual TraceComponent *createPktProc(const bool useInstID, const int instID)
{
TraceComponent *pComp;
if(useInstID)
pComp = new (std::nothrow) PktProc(instID);
else
pComp = new (std::nothrow) PktProc();
return pComp;
}
virtual TraceComponent *createPktDecode(const bool useInstID, const int instID)
{
TraceComponent *pComp;
if(useInstID)
pComp = new (std::nothrow)PktDcd(instID);
else
pComp = new (std::nothrow)PktDcd();
return pComp;
}
virtual CSConfig *createConfig(const void *pDataStruct)
{
return new (std::nothrow) Pc((PcSt *)pDataStruct);
}
};
/* full decode - extended config object - base + derived. */
template< class P, // Packet class.
class Pt, // Packet enum type ID.
class Pc, // Processor config base class.
class PcEx, // Processor config derived class
class PcSt, // Processor config struct type
class PktProc, // Packet processor class.
class PktDcd> // Packet decoder class.
class DecodeMngrFullDcdExCfg : public DecoderMngrBase<P, Pt, Pc>
{
public:
DecodeMngrFullDcdExCfg(const std::string &name, ocsd_trace_protocol_t builtInProtocol)
: DecoderMngrBase<P, Pt, Pc>(name, builtInProtocol) {};
virtual ~DecodeMngrFullDcdExCfg() {};
virtual TraceComponent *createPktProc(const bool useInstID, const int instID)
{
TraceComponent *pComp;
if (useInstID)
pComp = new (std::nothrow) PktProc(instID);
else
pComp = new (std::nothrow) PktProc();
return pComp;
}
virtual TraceComponent *createPktDecode(const bool useInstID, const int instID)
{
TraceComponent *pComp;
if (useInstID)
pComp = new (std::nothrow)PktDcd(instID);
else
pComp = new (std::nothrow)PktDcd();
return pComp;
}
virtual CSConfig *createConfig(const void *pDataStruct)
{
return new (std::nothrow) PcEx((PcSt *)pDataStruct);
}
};
/****************************************************************************************************/
/* Packet processor only, templated base for creating decoder objects */
/****************************************************************************************************/
template< class P, // Packet class.
class Pt, // Packet enum type ID.
class Pc, // Processor config class.
class PcSt, // Processor config struct type
class PktProc> // Packet processor class.
class DecodeMngrPktProc : public DecoderMngrBase<P,Pt,Pc>
{
public:
DecodeMngrPktProc (const std::string &name, ocsd_trace_protocol_t builtInProtocol)
: DecoderMngrBase<P,Pt,Pc>(name,builtInProtocol) {};
virtual ~DecodeMngrPktProc() {};
virtual TraceComponent *createPktProc(const bool useInstID, const int instID)
{
TraceComponent *pComp;
if(useInstID)
pComp = new (std::nothrow) PktProc(instID);
else
pComp = new (std::nothrow) PktProc();
return pComp;
}
virtual CSConfig *createConfig(const void *pDataStruct)
{
return new (std::nothrow) Pc((PcSt *)pDataStruct);
}
};
#endif // ARM_OCSD_DCD_MNGR_H_INCLUDED
/* End of File ocsd_dcd_mngr.h */
|