OpenCSD - CoreSight Trace Decode Library  0.14.4
trc_pkt_proc_etmv4i.h
Go to the documentation of this file.
1 /*
2  * \file trc_pkt_proc_etmv4i.h
3  * \brief OpenCSD : Implementation of ETMv4 packet processing
4  *
5  * \copyright Copyright (c) 2015, 2019 ARM Limited. All Rights Reserved.
6  */
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_PROC_ETMV4I_IMPL_H_INCLUDED
36 #define ARM_TRC_PKT_PROC_ETMV4I_IMPL_H_INCLUDED
37 
38 #include "trc_pkt_types_etmv4.h"
42 #include "common/trc_raw_buffer.h"
44 
45 class EtmV4ITrcPacket;
46 class EtmV4Config;
47 
51 class TrcPktProcEtmV4I : public TrcPktProcBase< EtmV4ITrcPacket, ocsd_etmv4_i_pkt_type, EtmV4Config>
52 {
53 public:
55  TrcPktProcEtmV4I(int instIDNum);
56  virtual ~TrcPktProcEtmV4I();
57 
58 protected:
59  /* implementation packet processing interface */
61  const uint32_t dataBlockSize,
62  const uint8_t *pDataBlock,
63  uint32_t *numBytesProcessed);
68  virtual const bool isBadPacket() const;
69 
70 protected:
71  typedef enum _process_state {
78 
80 
81  void InitPacketState(); // clear current packet state.
82  void InitProcessorState(); // clear all previous process state
83 
85  bool m_isInit;
86 
87  // etmv4 hardware configuration
89 
91  TraceRawBuffer m_trcIn; // trace data in buffer
92  std::vector<uint8_t> m_currPacketData; // raw data packet
93  int m_currPktIdx; // index into raw packet when expanding
94  EtmV4ITrcPacket m_curr_packet; // expanded packet
95  ocsd_trc_index_t m_packet_index; // index of the start of the current packet
96  ocsd_trc_index_t m_blockIndex; // index at the start of the current data block being processed
97 
98  // searching for sync
99  bool m_is_sync;
104 
105 
106 private:
107  // current processing state data - counts and flags to determine if a packet is complete.
108 
109  // TraceInfo Packet
110  // flags to indicate processing progress for these sections is complete.
111  struct _t_info_pkt_prog {
112  uint8_t sectFlags;
113  uint8_t ctrlBytes;
114  } m_tinfo_sections;
115 
116  #define TINFO_INFO_SECT 0x01
117  #define TINFO_KEY_SECT 0x02
118  #define TINFO_SPEC_SECT 0x04
119  #define TINFO_CYCT_SECT 0x08
120  #define TINFO_CTRL 0x20
121  #define TINFO_ALL_SECT 0x1F
122  #define TINFO_ALL 0x3F
123 
124 
125  // address and context packets
126  int m_addrBytes;
127  uint8_t m_addrIS;
128  bool m_bAddr64bit;
129  int m_vmidBytes; // bytes still to find
130  int m_ctxtidBytes; // bytes still to find
131  bool m_bCtxtInfoDone;
132  bool m_addr_done;
133 
134  // timestamp
135  bool m_ccount_done; // done or not needed
136  bool m_ts_done;
137  int m_ts_bytes;
138 
139  // exception
140  int m_excep_size;
141 
142  // cycle count
143  bool m_has_count;
144  bool m_count_done;
145  bool m_commit_done;
146 
147  // cond result
148  bool m_F1P1_done; // F1 payload 1 done
149  bool m_F1P2_done; // F1 payload 2 done
150  bool m_F1has_P2; // F1 has a payload 2
151 
152  // Q packets (use some from above too)
153  bool m_has_addr;
154  bool m_addr_short;
155  bool m_addr_match;
156  uint8_t m_Q_type;
157  uint8_t m_QE;
158 
159  ocsd_datapath_resp_t outputPacket();
160  ocsd_datapath_resp_t outputUnsyncedRawPacket();
161 
162  void iNotSync(const uint8_t lastByte); // not synced yet
163  void iPktNoPayload(const uint8_t lastByte); // process a single byte packet
164  void iPktReserved(const uint8_t lastByte); // deal with reserved header value
165  void iPktExtension(const uint8_t lastByte);
166  void iPktASync(const uint8_t lastByte);
167  void iPktTraceInfo(const uint8_t lastByte);
168  void iPktTimestamp(const uint8_t lastByte);
169  void iPktException(const uint8_t lastByte);
170  void iPktCycleCntF123(const uint8_t lastByte);
171  void iPktSpeclRes(const uint8_t lastByte);
172  void iPktCondInstr(const uint8_t lastByte);
173  void iPktCondResult(const uint8_t lastByte);
174  void iPktContext(const uint8_t lastByte);
175  void iPktAddrCtxt(const uint8_t lastByte);
176  void iPktShortAddr(const uint8_t lastByte);
177  void iPktLongAddr(const uint8_t lastByte);
178  void iPktQ(const uint8_t lastByte);
179  void iAtom(const uint8_t lastByte);
180  void iPktInvalidCfg(const uint8_t lastByte); // packet invalid in current config.
181 
182  unsigned extractContField(const std::vector<uint8_t> &buffer, const unsigned st_idx, uint32_t &value, const unsigned byte_limit = 5);
183  unsigned extractContField64(const std::vector<uint8_t> &buffer, const unsigned st_idx, uint64_t &value, const unsigned byte_limit = 9);
184  unsigned extractCondResult(const std::vector<uint8_t> &buffer, const unsigned st_idx, uint32_t& key, uint8_t &result);
185  void extractAndSetContextInfo(const std::vector<uint8_t> &buffer, const int st_idx);
186  int extract64BitLongAddr(const std::vector<uint8_t> &buffer, const int st_idx, const uint8_t IS, uint64_t &value);
187  int extract32BitLongAddr(const std::vector<uint8_t> &buffer, const int st_idx, const uint8_t IS, uint32_t &value);
188  int extractShortAddr(const std::vector<uint8_t> &buffer, const int st_idx, const uint8_t IS, uint32_t &value, int &bits);
189 
190  // packet processing is table driven.
191  typedef void (TrcPktProcEtmV4I::*PPKTFN)(uint8_t);
192  PPKTFN m_pIPktFn;
193 
194  struct _pkt_i_table_t {
195  ocsd_etmv4_i_pkt_type pkt_type;
196  PPKTFN pptkFn;
197  } m_i_table[256];
198 
199  void BuildIPacketTable();
200 
201  void throwBadSequenceError(const char *pszExtMsg);
202 };
203 
204 
205 inline const bool TrcPktProcEtmV4I::isBadPacket() const
206 {
207  return m_curr_packet.isBadPacket();
208 }
209 
212 #endif // ARM_TRC_PKT_PROC_ETMV4I_IMPL_H_INCLUDED
213 
214 /* End of File trc_pkt_proc_etmv4i_impl.h */
ocsd_datapath_resp_t
enum _ocsd_datapath_resp_t ocsd_datapath_resp_t
TrcPktProcEtmV4I::onEOT
virtual ocsd_datapath_resp_t onEOT()
Implementation function for the OCSD_OP_EOT operation.
TrcPktProcEtmV4I::InitPacketState
void InitPacketState()
TrcPktProcEtmV4I::m_update_on_unsync_packet_index
ocsd_trc_index_t m_update_on_unsync_packet_index
Definition: trc_pkt_proc_etmv4i.h:103
trc_raw_buffer.h
TraceRawBuffer
Definition: trc_raw_buffer.h:41
TrcPktProcEtmV4I::PROC_HDR
@ PROC_HDR
Definition: trc_pkt_proc_etmv4i.h:72
TrcPktProcEtmV4I::m_config
EtmV4Config m_config
Definition: trc_pkt_proc_etmv4i.h:88
TrcPktProcEtmV4I::process_state
enum TrcPktProcEtmV4I::_process_state process_state
TrcPktProcEtmV4I::m_currPktIdx
int m_currPktIdx
Definition: trc_pkt_proc_etmv4i.h:93
trc_pkt_proc_etmv4.h
TrcPktProcEtmV4I::PROC_DATA
@ PROC_DATA
Definition: trc_pkt_proc_etmv4i.h:73
TrcPktProcEtmV4I::m_is_sync
bool m_is_sync
seen first sync packet
Definition: trc_pkt_proc_etmv4i.h:99
TrcPktProcEtmV4I::m_packet_index
ocsd_trc_index_t m_packet_index
Definition: trc_pkt_proc_etmv4i.h:95
TrcPktProcEtmV4I::SEND_UNSYNCED
@ SEND_UNSYNCED
Definition: trc_pkt_proc_etmv4i.h:75
EtmV4ITrcPacket::isBadPacket
const bool isBadPacket() const
Definition: trc_pkt_elem_etmv4i.h:522
TrcPktProcEtmV4I::InitProcessorState
void InitProcessorState()
EtmV4ITrcPacket
ETMv4 Instuction Trace Protocol Packet.
Definition: trc_pkt_elem_etmv4i.h:111
TrcPktProcEtmV4I::m_trcIn
TraceRawBuffer m_trcIn
Definition: trc_pkt_proc_etmv4i.h:91
trc_pkt_types_etmv4.h
ocsd_err_t
enum _ocsd_err_t ocsd_err_t
EtmV4Config
Interpreter class for etm v4 config structure.
Definition: trc_cmp_cfg_etmv4.h:57
TrcPktProcEtmV4I::_process_state
_process_state
Definition: trc_pkt_proc_etmv4i.h:71
TrcPktProcEtmV4I::onProtocolConfig
virtual ocsd_err_t onProtocolConfig()
Called when the configuration object is passed to the decoder.
TrcPktProcEtmV4I::onReset
virtual ocsd_datapath_resp_t onReset()
Implementation function for the OCSD_OP_RESET operation.
TrcPktProcEtmV4I::isBadPacket
virtual const bool isBadPacket() const
check if the current packet is an error / bad packet
Definition: trc_pkt_proc_etmv4i.h:205
TrcPktProcEtmV4I::processData
virtual ocsd_datapath_resp_t processData(const ocsd_trc_index_t index, const uint32_t dataBlockSize, const uint8_t *pDataBlock, uint32_t *numBytesProcessed)
Implementation function for the OCSD_OP_DATA operation.
trc_cmp_cfg_etmv4.h
TrcPktProcEtmV4I::m_process_state
process_state m_process_state
Definition: trc_pkt_proc_etmv4i.h:79
ocsd_trc_index_t
uint32_t ocsd_trc_index_t
Definition: ocsd_if_types.h:67
TrcPktProcEtmV4I::onFlush
virtual ocsd_datapath_resp_t onFlush()
Implementation function for the OCSD_OP_FLUSH operation.
TrcPktProcEtmV4I::m_dump_unsynced_bytes
unsigned m_dump_unsynced_bytes
number of unsynced bytes to send
Definition: trc_pkt_proc_etmv4i.h:102
ocsd_etmv4_i_pkt_type
enum _ocsd_etmv4_i_pkt_type ocsd_etmv4_i_pkt_type
TrcPktProcEtmV4I::m_currPacketData
std::vector< uint8_t > m_currPacketData
Definition: trc_pkt_proc_etmv4i.h:92
TrcPktProcEtmV4I::PROC_ERR
@ PROC_ERR
Definition: trc_pkt_proc_etmv4i.h:76
TrcPktProcEtmV4I::SEND_PKT
@ SEND_PKT
Definition: trc_pkt_proc_etmv4i.h:74
trc_pkt_proc_base.h
OpenCSD : Trace packet processor base class.
TrcPktProcEtmV4I::m_isInit
bool m_isInit
Definition: trc_pkt_proc_etmv4i.h:85
TrcPktProcBase
Packet Processor base class. Provides common infrastructure and interconnections for packet processor...
Definition: trc_pkt_proc_base.h:124
TrcPktProcEtmV4I
Definition: trc_pkt_proc_etmv4i.h:52
TrcPktProcEtmV4I::~TrcPktProcEtmV4I
virtual ~TrcPktProcEtmV4I()
TrcPktProcEtmV4I::m_first_trace_info
bool m_first_trace_info
seen first trace info packet after sync
Definition: trc_pkt_proc_etmv4i.h:100
TrcPktProcEtmV4I::TrcPktProcEtmV4I
TrcPktProcEtmV4I(int instIDNum)
TrcPktProcEtmV4I::m_blockIndex
ocsd_trc_index_t m_blockIndex
Definition: trc_pkt_proc_etmv4i.h:96
TrcPktProcEtmV4I::m_sent_notsync_packet
bool m_sent_notsync_packet
send one not sync packet if we see any unsynced data on the channel
Definition: trc_pkt_proc_etmv4i.h:101
TrcPktProcEtmV4I::m_curr_packet
EtmV4ITrcPacket m_curr_packet
Definition: trc_pkt_proc_etmv4i.h:94
trc_pkt_elem_etmv4i.h
TrcPktProcEtmV4I::TrcPktProcEtmV4I
TrcPktProcEtmV4I()