2 * \file trc_pkt_proc_etmv3_impl.h
5 * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved.
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
20 * 3. Neither the name of the copyright holder nor the names of its contributors
21 * may be used to endorse or promote products derived from this software without
22 * specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #ifndef ARM_TRC_PKT_PROC_ETMV3_IMPL_H_INCLUDED
37 #define ARM_TRC_PKT_PROC_ETMV3_IMPL_H_INCLUDED
39 #include "opencsd/etmv3/trc_pkt_proc_etmv3.h"
40 #include "opencsd/etmv3/trc_cmp_cfg_etmv3.h"
41 #include "opencsd/etmv3/trc_pkt_elem_etmv3.h"
43 #define MAX_PACKET_SIZE 32
46 class EtmV3PktProcImpl
52 void Initialise(TrcPktProcEtmV3 *p_interface);
54 ocsd_err_t Configure(const EtmV3Config *p_config);
57 ocsd_datapath_resp_t processData( const ocsd_trc_index_t index,
58 const uint32_t dataBlockSize,
59 const uint8_t *pDataBlock,
60 uint32_t *numBytesProcessed);
61 ocsd_datapath_resp_t onEOT();
62 ocsd_datapath_resp_t onReset();
63 ocsd_datapath_resp_t onFlush();
64 const bool isBadPacket() const;
67 typedef enum _process_state {
75 process_state m_process_state;
78 void InitPacketState(); // clear current packet state.
79 void InitProcessorState(); // clear all previous process state
83 uint32_t waitForSync(const uint32_t dataBlockSize, const uint8_t *pDataBlock); //!< look for sync, return none-sync bytes processed.
84 ocsd_err_t processHeaderByte(uint8_t by);
85 ocsd_err_t processPayloadByte(uint8_t by);
87 // packet handling - main routines
88 void OnBranchAddress();
90 uint32_t extractCtxtID();
91 uint64_t extractTimestamp(uint8_t &tsBits);
92 uint32_t extractDataAddress(uint8_t &bits, bool &updateBE, uint8_t &beVal);
93 uint32_t extractDataValue(const int dataByteSize);
94 uint32_t extractCycleCount();
96 // packet handling - helper routines
97 uint32_t extractBrAddrPkt(int &nBitsOut);
98 void extractExceptionData();
99 void checkPktLimits();
100 void setBytesPartPkt(const int numBytes, const process_state nextState, const ocsd_etmv3_pkt_type nextType); // set first n bytes from current packet to be sent via alt packet.
103 void SendPacket(); // mark state for packet output
104 ocsd_datapath_resp_t outputPacket(); // output a packet
107 void throwMalformedPacketErr(const char *pszErrMsg);
108 void throwPacketHeaderErr(const char *pszErrMsg);
109 void throwUnsupportedErr(const char *pszErrMsg);
111 uint32_t m_bytesProcessed; // bytes processed by the process data routine (index into input buffer)
112 std::vector<uint8_t> m_currPacketData; // raw data
113 uint32_t m_currPktIdx; // index into packet when expanding
114 EtmV3TrcPacket m_curr_packet; // expanded packet
116 std::vector<uint8_t> m_partPktData; // raw data when we need to split a packet.
117 bool m_bSendPartPkt; // mark the part packet as the one we send.
118 process_state m_post_part_pkt_state; // state to set after part packet set
119 ocsd_etmv3_pkt_type m_post_part_pkt_type; // reset the packet type.
122 bool m_bStreamSync; //!< true if we have synced this stream
123 bool m_bStartOfSync; //!< true if we have a start of sync.
126 uint32_t m_bytesExpectedThisPkt; // used by some of the variable packet length types.
127 bool m_BranchPktNeedsException;
128 bool m_bIsync_got_cycle_cnt;
129 bool m_bIsync_get_LSiP_addr;
131 bool m_bExpectingDataAddress;
132 bool m_bFoundDataAddress;
134 ocsd_trc_index_t m_packet_index; // index of the start of the current packet
135 ocsd_trc_index_t m_packet_curr_byte_index; // index of the current byte.
138 TrcPktProcEtmV3 *m_interface; /**< The interface to the other decode components */
140 EtmV3Config m_config;
142 uint8_t m_chanIDCopy;
146 inline void EtmV3PktProcImpl::SendPacket()
148 m_process_state = SEND_PKT;
151 inline void EtmV3PktProcImpl::throwMalformedPacketErr(const char *pszErrMsg)
153 throw ocsdError(OCSD_ERR_SEV_ERROR,OCSD_ERR_BAD_PACKET_SEQ,m_packet_index,m_chanIDCopy,pszErrMsg);
156 inline void EtmV3PktProcImpl::throwPacketHeaderErr(const char *pszErrMsg)
158 throw ocsdError(OCSD_ERR_SEV_ERROR,OCSD_ERR_INVALID_PCKT_HDR,m_packet_index,m_chanIDCopy,pszErrMsg);
161 inline void EtmV3PktProcImpl::throwUnsupportedErr(const char *pszErrMsg)
163 throw ocsdError(OCSD_ERR_SEV_ERROR,OCSD_ERR_HW_CFG_UNSUPP,m_packet_index,m_chanIDCopy,pszErrMsg);
167 inline const bool EtmV3PktProcImpl::isBadPacket() const
169 return m_curr_packet.isBadPacket();
173 #endif // ARM_TRC_PKT_PROC_ETMV3_IMPL_H_INCLUDED
175 /* End of File trc_pkt_proc_etmv3_impl.h */