OpenCSD - CoreSight Trace Decode Library 1.8.3
Loading...
Searching...
No Matches
trc_pkt_decode_base.h
Go to the documentation of this file.
1
7
8/*
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * 3. Neither the name of the copyright holder nor the names of its contributors
20 * may be used to endorse or promote products derived from this software without
21 * specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#ifndef ARM_TRC_PKT_DECODE_BASE_H_INCLUDED
36#define ARM_TRC_PKT_DECODE_BASE_H_INCLUDED
37
38#include <new>
39
40#include "trc_component.h"
41#include "comp_attach_pt_t.h"
42
47
61
62
64{
65public:
66 TrcPktDecodeI(const char *component_name);
67 TrcPktDecodeI(const char *component_name, int instIDNum);
68 virtual ~TrcPktDecodeI() {};
69
73
74 void setUsesMemAccess(bool bUsesMemaccess) { m_uses_memaccess = bUsesMemaccess; };
75 const bool getUsesMemAccess() const { return m_uses_memaccess; };
76
77 void setUsesIDecode(bool bUsesIDecode) { m_uses_idecode = bUsesIDecode; };
78 const bool getUsesIDecode() const { return m_uses_idecode; };
79
80protected:
81
82 /* implementation packet decoding interface */
88 virtual const uint8_t getCoreSightTraceID() = 0;
89
90 /* init handling */
91 const bool checkInit();
92 /* Called on first init confirmation */
93 virtual void onFirstInitOK() {};
94
95 /* data output */
96 ocsd_datapath_resp_t outputTraceElement(const OcsdTraceElement &elem); // use current index
97 ocsd_datapath_resp_t outputTraceElementIdx(ocsd_trc_index_t idx, const OcsdTraceElement &elem); // use supplied index (where decoder caches elements)
98
99 /* target access */
100 ocsd_err_t accessMemory(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, uint32_t *num_bytes, uint8_t *p_buffer);
102
103 /* instruction decode */
105
109
111
114
115 std::string init_err_msg;
116
119
120};
121
122inline TrcPktDecodeI::TrcPktDecodeI(const char *component_name) :
123 TraceComponent(component_name),
125 m_decode_init_ok(false),
126 m_config_init_ok(false),
127 m_uses_memaccess(true),
128 m_uses_idecode(true)
129{
130}
131
132inline TrcPktDecodeI::TrcPktDecodeI(const char *component_name, int instIDNum) :
133 TraceComponent(component_name, instIDNum),
135 m_decode_init_ok(false),
136 m_config_init_ok(false),
137 m_uses_memaccess(true),
138 m_uses_idecode(true)
139{
140}
141
142inline const bool TrcPktDecodeI::checkInit()
143{
145 {
147 init_err_msg = "No decoder configuration information";
148 else if(!m_trace_elem_out.hasAttachedAndEnabled())
149 init_err_msg = "No element output interface attached and enabled";
150 else if(m_uses_memaccess && !m_mem_access.hasAttachedAndEnabled())
151 init_err_msg = "No memory access interface attached and enabled";
152 else if(m_uses_idecode && !m_instr_decode.hasAttachedAndEnabled())
153 init_err_msg = "No instruction decoder interface attached and enabled";
154 else
155 m_decode_init_ok = true;
158 }
159 return m_decode_init_ok;
160}
161
166
168{
169 return m_trace_elem_out.first()->TraceElemIn(idx, getCoreSightTraceID(), elem);
170}
171
173{
175 return m_instr_decode.first()->DecodeInstruction(instr_info);
177}
178
179inline ocsd_err_t TrcPktDecodeI::accessMemory(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, uint32_t *num_bytes, uint8_t *p_buffer)
180{
182 return m_mem_access.first()->ReadTargetMemory(address,getCoreSightTraceID(),mem_space, num_bytes,p_buffer);
184}
185
187{
188 if (!m_uses_memaccess)
190 m_mem_access.first()->InvalidateMemAccCache(getCoreSightTraceID());
191 return OCSD_OK;
192}
193
194/**********************************************************************/
195template <class P, class Pc>
197{
198public:
199 TrcPktDecodeBase(const char *component_name);
200 TrcPktDecodeBase(const char *component_name, int instIDNum);
202
204 const ocsd_trc_index_t index_sop,
205 const P *p_packet_in);
206
207
208 /* protocol configuration */
209 ocsd_err_t setProtocolConfig(const Pc *config);
210 const Pc * getProtocolConfig() const { return m_config; };
211
212protected:
214
215 /* the protocol configuration */
217 /* the current input packet */
219
220};
221
222
223template <class P, class Pc> TrcPktDecodeBase<P, Pc>::TrcPktDecodeBase(const char *component_name) :
224 TrcPktDecodeI(component_name),
225 m_config(0)
226{
227}
228
229template <class P, class Pc> TrcPktDecodeBase<P, Pc>::TrcPktDecodeBase(const char *component_name, int instIDNum) :
230 TrcPktDecodeI(component_name,instIDNum),
231 m_config(0)
232{
233}
234
235template <class P, class Pc> TrcPktDecodeBase<P, Pc>::~TrcPktDecodeBase()
236{
238}
239
241 const ocsd_trc_index_t index_sop,
242 const P *p_packet_in)
243{
245 if(!checkInit())
246 {
249 }
250
251 switch(op)
252 {
253 case OCSD_OP_DATA:
254 if(p_packet_in == 0)
255 {
258 }
259 else
260 {
261 m_curr_packet_in = p_packet_in;
262 m_index_curr_pkt = index_sop;
263 resp = processPacket();
264 }
265 break;
266
267 case OCSD_OP_EOT:
268 resp = onEOT();
269 break;
270
271 case OCSD_OP_FLUSH:
272 resp = onFlush();
273 break;
274
275 case OCSD_OP_RESET:
276 resp = onReset();
277 break;
278
279 default:
282 break;
283 }
284 return resp;
285}
286
287 /* protocol configuration */
288template <class P, class Pc> ocsd_err_t TrcPktDecodeBase<P, Pc>::setProtocolConfig(const Pc *config)
289{
291 if(config != 0)
292 {
293 ClearConfigObj(); // remove any current config
294 m_config = new (std::nothrow) Pc(*config); // make a copy of the config - don't rely on the object passed in being valid outside the context of the call.
295 if(m_config != 0)
296 {
297 err = onProtocolConfig();
298 if(err == OCSD_OK)
299 m_config_init_ok = true;
300 }
301 else
302 err = OCSD_ERR_MEM;
303 }
304 return err;
305}
306
307template <class P, class Pc> void TrcPktDecodeBase<P, Pc>::ClearConfigObj()
308{
309 if(m_config)
310 {
311 delete m_config;
312 m_config = 0;
313 }
314}
315
317#endif // ARM_TRC_PKT_DECODE_BASE_H_INCLUDED
318
319/* End of File trc_pkt_decode_base.h */
Generic trace element class.
TraceComponent(const std::string &name)
void LogError(const ocsdError &Error)
const Pc * getProtocolConfig() const
componentAttachPt< ITargetMemAccess > m_mem_access
virtual void onFirstInitOK()
virtual ocsd_datapath_resp_t processPacket()=0
componentAttachPt< ITrcGenElemIn > m_trace_elem_out
componentAttachPt< ITargetMemAccess > * getMemoryAccessAttachPt()
componentAttachPt< IInstrDecode > m_instr_decode
const bool getUsesIDecode() const
ocsd_trc_index_t m_index_curr_pkt
void setUsesMemAccess(bool bUsesMemaccess)
const bool getUsesMemAccess() const
void setUsesIDecode(bool bUsesIDecode)
componentAttachPt< ITrcGenElemIn > * getTraceElemOutAttachPt()
virtual ocsd_err_t onProtocolConfig()=0
std::string init_err_msg
error message for init error
virtual ocsd_datapath_resp_t onFlush()=0
virtual const uint8_t getCoreSightTraceID()=0
virtual ocsd_datapath_resp_t onReset()=0
bool m_decode_init_ok
set true if all attachments in place for decode. (remove checks in main throughput paths)
virtual ocsd_datapath_resp_t onEOT()=0
componentAttachPt< IInstrDecode > * getInstrDecodeAttachPt()
bool m_config_init_ok
set true if config set.
Single component interface pointer attachment point.
OpenCSD : Component attachment point interface class.
uint32_t ocsd_trc_index_t
enum _ocsd_datapath_resp_t ocsd_datapath_resp_t
enum _ocsd_mem_space_acc_t ocsd_mem_space_acc_t
enum _ocsd_datapath_op_t ocsd_datapath_op_t
struct _ocsd_instr_info ocsd_instr_info
enum _ocsd_err_t ocsd_err_t
uint64_t ocsd_vaddr_t
@ OCSD_ERR_DCD_INTERFACE_UNUSED
@ OCSD_OK
@ OCSD_ERR_INVALID_PARAM_VAL
@ OCSD_ERR_NOT_INIT
@ OCSD_ERR_MEM
@ OCSD_RESP_CONT
@ OCSD_RESP_FATAL_NOT_INIT
@ OCSD_RESP_FATAL_INVALID_PARAM
@ OCSD_RESP_FATAL_INVALID_OP
@ OCSD_OP_EOT
@ OCSD_OP_FLUSH
@ OCSD_OP_DATA
@ OCSD_OP_RESET
@ OCSD_ERR_SEV_ERROR
ocsd_err_t accessMemory(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, uint32_t *num_bytes, uint8_t *p_buffer)
TrcPktDecodeBase(const char *component_name)
virtual ocsd_datapath_resp_t PacketDataIn(const ocsd_datapath_op_t op, const ocsd_trc_index_t index_sop, const P *p_packet_in)
TrcPktDecodeI(const char *component_name)
ocsd_datapath_resp_t outputTraceElement(const OcsdTraceElement &elem)
ocsd_err_t instrDecode(ocsd_instr_info *instr_info)
ocsd_err_t setProtocolConfig(const Pc *config)
ocsd_datapath_resp_t outputTraceElementIdx(ocsd_trc_index_t idx, const OcsdTraceElement &elem)
ocsd_err_t invalidateMemAccCache()
const bool checkInit()
OpenCSD : Base trace decode component.