OpenCSD - CoreSight Trace Decode Library  0.12.1
trc_pkt_decode_base.h
Go to the documentation of this file.
1 
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 "trc_component.h"
39 #include "comp_attach_pt_t.h"
40 
45 
62 {
63 public:
64  TrcPktDecodeI(const char *component_name);
65  TrcPktDecodeI(const char *component_name, int instIDNum);
66  virtual ~TrcPktDecodeI() {};
67 
71 
72  void setUsesMemAccess(bool bUsesMemaccess) { m_uses_memaccess = bUsesMemaccess; };
73  const bool getUsesMemAccess() const { return m_uses_memaccess; };
74 
75  void setUsesIDecode(bool bUsesIDecode) { m_uses_idecode = bUsesIDecode; };
76  const bool getUsesIDecode() const { return m_uses_idecode; };
77 
78 protected:
79 
80  /* implementation packet decoding interface */
81  virtual ocsd_datapath_resp_t processPacket() = 0;
82  virtual ocsd_datapath_resp_t onEOT() = 0;
83  virtual ocsd_datapath_resp_t onReset() = 0;
84  virtual ocsd_datapath_resp_t onFlush() = 0;
85  virtual ocsd_err_t onProtocolConfig() = 0;
86  virtual const uint8_t getCoreSightTraceID() = 0;
87 
88  const bool checkInit();
89 
90  /* data output */
91  ocsd_datapath_resp_t outputTraceElement(const OcsdTraceElement &elem); // use current index
92  ocsd_datapath_resp_t outputTraceElementIdx(ocsd_trc_index_t idx, const OcsdTraceElement &elem); // use supplied index (where decoder caches elements)
93 
94  /* target access */
95  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);
96 
97  /* instruction decode */
99 
103 
105 
108 
109  std::string init_err_msg;
110 
113 
114 };
115 
116 inline TrcPktDecodeI::TrcPktDecodeI(const char *component_name) :
117  TraceComponent(component_name),
118  m_index_curr_pkt(0),
119  m_decode_init_ok(false),
120  m_config_init_ok(false),
121  m_uses_memaccess(true),
122  m_uses_idecode(true)
123 {
124 }
125 
126 inline TrcPktDecodeI::TrcPktDecodeI(const char *component_name, int instIDNum) :
127  TraceComponent(component_name, instIDNum),
128  m_index_curr_pkt(0),
129  m_decode_init_ok(false),
130  m_config_init_ok(false),
131  m_uses_memaccess(true),
132  m_uses_idecode(true)
133 {
134 }
135 
136 inline const bool TrcPktDecodeI::checkInit()
137 {
138  if(!m_decode_init_ok)
139  {
140  if(!m_config_init_ok)
141  init_err_msg = "No decoder configuration information";
143  init_err_msg = "No element output interface attached and enabled";
145  init_err_msg = "No memory access interface attached and enabled";
147  init_err_msg = "No instruction decoder interface attached and enabled";
148  else
149  m_decode_init_ok = true;
150  }
151  return m_decode_init_ok;
152 }
153 
155 {
157 }
158 
160 {
161  return m_trace_elem_out.first()->TraceElemIn(idx, getCoreSightTraceID(), elem);
162 }
163 
165 {
166  if(m_uses_idecode)
167  return m_instr_decode.first()->DecodeInstruction(instr_info);
169 }
170 
171 inline 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)
172 {
173  if(m_uses_memaccess)
174  return m_mem_access.first()->ReadTargetMemory(address,getCoreSightTraceID(),mem_space, num_bytes,p_buffer);
176 }
177 
178 /**********************************************************************/
179 template <class P, class Pc>
180 class TrcPktDecodeBase : public TrcPktDecodeI, public IPktDataIn<P>
181 {
182 public:
183  TrcPktDecodeBase(const char *component_name);
184  TrcPktDecodeBase(const char *component_name, int instIDNum);
185  virtual ~TrcPktDecodeBase();
186 
188  const ocsd_trc_index_t index_sop,
189  const P *p_packet_in);
190 
191 
192  /* protocol configuration */
193  ocsd_err_t setProtocolConfig(const Pc *config);
194  const Pc * getProtocolConfig() const { return m_config; };
195 
196 protected:
197  void ClearConfigObj();
198 
199  /* the protocol configuration */
200  Pc * m_config;
201  /* the current input packet */
202  const P * m_curr_packet_in;
203 
204 };
205 
206 
207 template <class P, class Pc> TrcPktDecodeBase<P, Pc>::TrcPktDecodeBase(const char *component_name) :
208  TrcPktDecodeI(component_name),
209  m_config(0)
210 {
211 }
212 
213 template <class P, class Pc> TrcPktDecodeBase<P, Pc>::TrcPktDecodeBase(const char *component_name, int instIDNum) :
214  TrcPktDecodeI(component_name,instIDNum),
215  m_config(0)
216 {
217 }
218 
219 template <class P, class Pc> TrcPktDecodeBase<P, Pc>::~TrcPktDecodeBase()
220 {
221  ClearConfigObj();
222 }
223 
225  const ocsd_trc_index_t index_sop,
226  const P *p_packet_in)
227 {
229  if(!checkInit())
230  {
231  LogError(ocsdError(OCSD_ERR_SEV_ERROR,OCSD_ERR_NOT_INIT,init_err_msg));
233  }
234 
235  switch(op)
236  {
237  case OCSD_OP_DATA:
238  if(p_packet_in == 0)
239  {
242  }
243  else
244  {
245  m_curr_packet_in = p_packet_in;
246  m_index_curr_pkt = index_sop;
247  resp = processPacket();
248  }
249  break;
250 
251  case OCSD_OP_EOT:
252  resp = onEOT();
253  break;
254 
255  case OCSD_OP_FLUSH:
256  resp = onFlush();
257  break;
258 
259  case OCSD_OP_RESET:
260  resp = onReset();
261  break;
262 
263  default:
266  break;
267  }
268  return resp;
269 }
270 
271  /* protocol configuration */
272 template <class P, class Pc> ocsd_err_t TrcPktDecodeBase<P, Pc>::setProtocolConfig(const Pc *config)
273 {
275  if(config != 0)
276  {
277  ClearConfigObj(); // remove any current config
278  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.
279  if(m_config != 0)
280  {
281  err = onProtocolConfig();
282  if(err == OCSD_OK)
283  m_config_init_ok = true;
284  }
285  else
286  err = OCSD_ERR_MEM;
287  }
288  return err;
289 }
290 
291 template <class P, class Pc> void TrcPktDecodeBase<P, Pc>::ClearConfigObj()
292 {
293  if(m_config)
294  {
295  delete m_config;
296  m_config = 0;
297  }
298 }
299 
301 #endif // ARM_TRC_PKT_DECODE_BASE_H_INCLUDED
302 
303 /* End of File trc_pkt_decode_base.h */
TrcPktDecodeI
Definition: trc_pkt_decode_base.h:61
TrcPktDecodeI::onProtocolConfig
virtual ocsd_err_t onProtocolConfig()=0
TrcPktDecodeI::onEOT
virtual ocsd_datapath_resp_t onEOT()=0
ocsd_datapath_resp_t
enum _ocsd_datapath_resp_t ocsd_datapath_resp_t
TrcPktDecodeBase::ClearConfigObj
void ClearConfigObj()
Definition: trc_pkt_decode_base.h:291
ITargetMemAccess::ReadTargetMemory
virtual ocsd_err_t ReadTargetMemory(const ocsd_vaddr_t address, const uint8_t cs_trace_id, const ocsd_mem_space_acc_t mem_space, uint32_t *num_bytes, uint8_t *p_buffer)=0
_ocsd_instr_info
Definition: ocsd_if_types.h:382
OCSD_OK
@ OCSD_OK
Definition: ocsd_if_types.h:88
OcsdTraceElement
Generic trace element class.
Definition: trc_gen_elem.h:49
OCSD_OP_RESET
@ OCSD_OP_RESET
Definition: ocsd_if_types.h:184
trc_pkt_in_i.h
TrcPktDecodeBase::m_curr_packet_in
const P * m_curr_packet_in
Definition: trc_pkt_decode_base.h:202
TrcPktDecodeI::onReset
virtual ocsd_datapath_resp_t onReset()=0
ocsdError
Definition: ocsd_error.h:58
TrcPktDecodeI::outputTraceElementIdx
ocsd_datapath_resp_t outputTraceElementIdx(ocsd_trc_index_t idx, const OcsdTraceElement &elem)
Definition: trc_pkt_decode_base.h:159
TrcPktDecodeI::getUsesMemAccess
const bool getUsesMemAccess() const
Definition: trc_pkt_decode_base.h:73
ITrcGenElemIn::TraceElemIn
virtual ocsd_datapath_resp_t TraceElemIn(const ocsd_trc_index_t index_sop, const uint8_t trc_chan_id, const OcsdTraceElement &elem)=0
TrcPktDecodeI::getUsesIDecode
const bool getUsesIDecode() const
Definition: trc_pkt_decode_base.h:76
TrcPktDecodeBase::TrcPktDecodeBase
TrcPktDecodeBase(const char *component_name)
Definition: trc_pkt_decode_base.h:207
TrcPktDecodeI::getMemoryAccessAttachPt
componentAttachPt< ITargetMemAccess > * getMemoryAccessAttachPt()
Definition: trc_pkt_decode_base.h:69
TrcPktDecodeI::m_config_init_ok
bool m_config_init_ok
set true if config set.
Definition: trc_pkt_decode_base.h:107
TrcPktDecodeBase
Definition: trc_pkt_decode_base.h:180
componentAttachPt::hasAttachedAndEnabled
const bool hasAttachedAndEnabled() const
Definition: comp_attach_pt_t.h:142
IPktDataIn
Interface class providing an input for discrete protocol packets.
Definition: trc_pkt_in_i.h:54
TrcPktDecodeI::getTraceElemOutAttachPt
componentAttachPt< ITrcGenElemIn > * getTraceElemOutAttachPt()
Definition: trc_pkt_decode_base.h:68
TrcPktDecodeI::accessMemory
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)
Definition: trc_pkt_decode_base.h:171
TrcPktDecodeI::checkInit
const bool checkInit()
Definition: trc_pkt_decode_base.h:136
IInstrDecode::DecodeInstruction
virtual ocsd_err_t DecodeInstruction(ocsd_instr_info *instr_info)=0
ocsd_vaddr_t
uint64_t ocsd_vaddr_t
Definition: ocsd_if_types.h:308
TrcPktDecodeI::m_decode_init_ok
bool m_decode_init_ok
set true if all attachments in place for decode. (remove checks in main throughput paths)
Definition: trc_pkt_decode_base.h:106
TrcPktDecodeBase::getProtocolConfig
const Pc * getProtocolConfig() const
Definition: trc_pkt_decode_base.h:194
TrcPktDecodeI::instrDecode
ocsd_err_t instrDecode(ocsd_instr_info *instr_info)
Definition: trc_pkt_decode_base.h:164
ocsd_err_t
enum _ocsd_err_t ocsd_err_t
trc_gen_elem_in_i.h
OCSD_RESP_FATAL_INVALID_OP
@ OCSD_RESP_FATAL_INVALID_OP
Definition: ocsd_if_types.h:198
TrcPktDecodeBase::setProtocolConfig
ocsd_err_t setProtocolConfig(const Pc *config)
Definition: trc_pkt_decode_base.h:272
ocsd_datapath_op_t
enum _ocsd_datapath_op_t ocsd_datapath_op_t
componentAttachPt::first
virtual T * first()
Definition: comp_attach_pt_t.h:198
TraceComponent
Base class for all decode components in the library.
Definition: trc_component.h:56
trc_component.h
OpenCSD : Base trace decode component.
TrcPktDecodeI::getCoreSightTraceID
virtual const uint8_t getCoreSightTraceID()=0
OCSD_ERR_MEM
@ OCSD_ERR_MEM
Definition: ocsd_if_types.h:90
TrcPktDecodeI::outputTraceElement
ocsd_datapath_resp_t outputTraceElement(const OcsdTraceElement &elem)
Definition: trc_pkt_decode_base.h:154
TrcPktDecodeI::getInstrDecodeAttachPt
componentAttachPt< IInstrDecode > * getInstrDecodeAttachPt()
Definition: trc_pkt_decode_base.h:70
TrcPktDecodeI::m_trace_elem_out
componentAttachPt< ITrcGenElemIn > m_trace_elem_out
Definition: trc_pkt_decode_base.h:100
TrcPktDecodeI::init_err_msg
std::string init_err_msg
error message for init error
Definition: trc_pkt_decode_base.h:109
TrcPktDecodeBase::m_config
Pc * m_config
Definition: trc_pkt_decode_base.h:200
OCSD_ERR_INVALID_PARAM_VAL
@ OCSD_ERR_INVALID_PARAM_VAL
Definition: ocsd_if_types.h:94
ocsd_trc_index_t
uint32_t ocsd_trc_index_t
Definition: ocsd_if_types.h:67
TrcPktDecodeI::m_index_curr_pkt
ocsd_trc_index_t m_index_curr_pkt
Definition: trc_pkt_decode_base.h:104
componentAttachPt< ITrcGenElemIn >
TrcPktDecodeI::m_mem_access
componentAttachPt< ITargetMemAccess > m_mem_access
Definition: trc_pkt_decode_base.h:101
OCSD_RESP_CONT
@ OCSD_RESP_CONT
Definition: ocsd_if_types.h:191
TrcPktDecodeI::processPacket
virtual ocsd_datapath_resp_t processPacket()=0
comp_attach_pt_t.h
OpenCSD : Component attachment point interface class.
TrcPktDecodeI::TrcPktDecodeI
TrcPktDecodeI(const char *component_name)
Definition: trc_pkt_decode_base.h:116
TrcPktDecodeBase::~TrcPktDecodeBase
virtual ~TrcPktDecodeBase()
Definition: trc_pkt_decode_base.h:219
ocsd_mem_space_acc_t
enum _ocsd_mem_space_acc_t ocsd_mem_space_acc_t
OCSD_OP_DATA
@ OCSD_OP_DATA
Definition: ocsd_if_types.h:181
OCSD_OP_EOT
@ OCSD_OP_EOT
Definition: ocsd_if_types.h:182
TrcPktDecodeI::~TrcPktDecodeI
virtual ~TrcPktDecodeI()
Definition: trc_pkt_decode_base.h:66
TrcPktDecodeI::setUsesMemAccess
void setUsesMemAccess(bool bUsesMemaccess)
Definition: trc_pkt_decode_base.h:72
OCSD_ERR_NOT_INIT
@ OCSD_ERR_NOT_INIT
Definition: ocsd_if_types.h:91
OCSD_OP_FLUSH
@ OCSD_OP_FLUSH
Definition: ocsd_if_types.h:183
OCSD_RESP_FATAL_NOT_INIT
@ OCSD_RESP_FATAL_NOT_INIT
Definition: ocsd_if_types.h:197
TrcPktDecodeI::onFlush
virtual ocsd_datapath_resp_t onFlush()=0
TrcPktDecodeBase::PacketDataIn
virtual ocsd_datapath_resp_t PacketDataIn(const ocsd_datapath_op_t op, const ocsd_trc_index_t index_sop, const P *p_packet_in)
Definition: trc_pkt_decode_base.h:224
OCSD_RESP_FATAL_INVALID_PARAM
@ OCSD_RESP_FATAL_INVALID_PARAM
Definition: ocsd_if_types.h:199
TrcPktDecodeI::setUsesIDecode
void setUsesIDecode(bool bUsesIDecode)
Definition: trc_pkt_decode_base.h:75
trc_tgt_mem_access_i.h
TrcPktDecodeI::m_uses_idecode
bool m_uses_idecode
Definition: trc_pkt_decode_base.h:112
trc_instr_decode_i.h
TrcPktDecodeI::m_uses_memaccess
bool m_uses_memaccess
Definition: trc_pkt_decode_base.h:111
TrcPktDecodeI::m_instr_decode
componentAttachPt< IInstrDecode > m_instr_decode
Definition: trc_pkt_decode_base.h:102
OCSD_ERR_SEV_ERROR
@ OCSD_ERR_SEV_ERROR
Definition: ocsd_if_types.h:168
OCSD_ERR_DCD_INTERFACE_UNUSED
@ OCSD_ERR_DCD_INTERFACE_UNUSED
Definition: ocsd_if_types.h:142