2 * \file trc_pkt_proc_etmv4i_impl.h
3 * \brief OpenCSD : Implementation of ETMv4 packet processing
5 * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved.
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
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.
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.
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.
35 #ifndef ARM_TRC_PKT_PROC_ETMV4I_IMPL_H_INCLUDED
36 #define ARM_TRC_PKT_PROC_ETMV4I_IMPL_H_INCLUDED
38 #include "opencsd/etmv4/trc_pkt_proc_etmv4.h"
39 #include "opencsd/etmv4/trc_cmp_cfg_etmv4.h"
40 #include "opencsd/etmv4/trc_pkt_elem_etmv4i.h"
42 class EtmV4IPktProcImpl
48 void Initialise(TrcPktProcEtmV4I *p_interface);
50 ocsd_err_t Configure(const EtmV4Config *p_config);
53 ocsd_datapath_resp_t processData( const ocsd_trc_index_t index,
54 const uint32_t dataBlockSize,
55 const uint8_t *pDataBlock,
56 uint32_t *numBytesProcessed);
57 ocsd_datapath_resp_t onEOT();
58 ocsd_datapath_resp_t onReset();
59 ocsd_datapath_resp_t onFlush();
60 const bool isBadPacket() const;
63 typedef enum _process_state {
71 process_state m_process_state;
73 void InitPacketState(); // clear current packet state.
74 void InitProcessorState(); // clear all previous process state
76 /** packet processor configuration **/
78 TrcPktProcEtmV4I *m_interface; /**< The interface to the other decode components */
80 // etmv4 hardware configuration
84 std::vector<uint8_t> m_currPacketData; // raw data
85 int m_currPktIdx; // index into raw packet when expanding
86 EtmV4ITrcPacket m_curr_packet; // expanded packet
87 ocsd_trc_index_t m_packet_index; // index of the start of the current packet
88 uint32_t m_blockBytesProcessed; // number of bytes processed in the current data block
89 ocsd_trc_index_t m_blockIndex; // index at the start of the current data block being processed
92 bool m_is_sync; //!< seen first sync packet
93 bool m_first_trace_info; //!< seen first trace info packet after sync
94 bool m_sent_notsync_packet; //!< send one not sync packet if we see any unsynced data on the channel
95 unsigned m_dump_unsynced_bytes; //!< number of unsynced bytes to send
96 ocsd_trc_index_t m_update_on_unsync_packet_index;
100 // current processing state data - counts and flags to determine if a packet is complete.
103 // flags to indicate processing progress for these sections is complete.
104 struct _t_info_pkt_prog {
109 #define TINFO_INFO_SECT 0x01
110 #define TINFO_KEY_SECT 0x02
111 #define TINFO_SPEC_SECT 0x04
112 #define TINFO_CYCT_SECT 0x08
113 #define TINFO_CTRL 0x10
114 #define TINFO_ALL_SECT 0x0F
115 #define TINFO_ALL 0x1F
118 // address and context packets
122 int m_vmidBytes; // bytes still to find
123 int m_ctxtidBytes; // bytes still to find
124 bool m_bCtxtInfoDone;
128 bool m_ccount_done; // done or not needed
141 bool m_F1P1_done; // F1 payload 1 done
142 bool m_F1P2_done; // F1 payload 2 done
143 bool m_F1has_P2; // F1 has a payload 2
145 // Q packets (use some from above too)
152 ocsd_datapath_resp_t outputPacket();
153 ocsd_datapath_resp_t outputUnsyncedRawPacket();
155 void iNotSync(); // not synced yet
156 void iPktNoPayload(); // process a single byte packet
157 void iPktReserved(); // deal with reserved header value
158 void iPktExtension();
160 void iPktTraceInfo();
161 void iPktTimestamp();
162 void iPktException();
163 void iPktCycleCntF123();
165 void iPktCondInstr();
166 void iPktCondResult();
169 void iPktShortAddr();
174 unsigned extractContField(const std::vector<uint8_t> &buffer, const unsigned st_idx, uint32_t &value, const unsigned byte_limit = 5);
175 unsigned extractContField64(const std::vector<uint8_t> &buffer, const unsigned st_idx, uint64_t &value, const unsigned byte_limit = 9);
176 unsigned extractCondResult(const std::vector<uint8_t> &buffer, const unsigned st_idx, uint32_t& key, uint8_t &result);
177 void extractAndSetContextInfo(const std::vector<uint8_t> &buffer, const int st_idx);
178 int extract64BitLongAddr(const std::vector<uint8_t> &buffer, const int st_idx, const uint8_t IS, uint64_t &value);
179 int extract32BitLongAddr(const std::vector<uint8_t> &buffer, const int st_idx, const uint8_t IS, uint32_t &value);
180 int extractShortAddr(const std::vector<uint8_t> &buffer, const int st_idx, const uint8_t IS, uint32_t &value, int &bits);
182 // packet processing is table driven.
183 typedef void (EtmV4IPktProcImpl::*PPKTFN)(void);
186 struct _pkt_i_table_t {
187 ocsd_etmv4_i_pkt_type pkt_type;
191 void BuildIPacketTable();
193 void throwBadSequenceError(const char *pszExtMsg);
197 inline const bool EtmV4IPktProcImpl::isBadPacket() const
199 return m_curr_packet.isBadPacket();
202 #endif // ARM_TRC_PKT_PROC_ETMV4I_IMPL_H_INCLUDED
204 /* End of File trc_pkt_proc_etmv4i_impl.h */