2 * \file trc_pkt_proc_ptm.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_PTM_H_INCLUDED
37 #define ARM_TRC_PKT_PROC_PTM_H_INCLUDED
39 #include "trc_pkt_types_ptm.h"
40 #include "common/trc_pkt_proc_base.h"
41 #include "trc_pkt_elem_ptm.h"
42 #include "trc_cmp_cfg_ptm.h"
47 /** @addtogroup ocsd_pkt_proc
52 class TrcPktProcPtm : public TrcPktProcBase< PtmTrcPacket, ocsd_ptm_pkt_type, PtmConfig>
56 TrcPktProcPtm(int instIDNum);
57 virtual ~TrcPktProcPtm();
60 /* implementation packet processing interface */
61 virtual ocsd_datapath_resp_t processData( const ocsd_trc_index_t index,
62 const uint32_t dataBlockSize,
63 const uint8_t *pDataBlock,
64 uint32_t *numBytesProcessed);
65 virtual ocsd_datapath_resp_t onEOT();
66 virtual ocsd_datapath_resp_t onReset();
67 virtual ocsd_datapath_resp_t onFlush();
68 virtual ocsd_err_t onProtocolConfig();
69 virtual const bool isBadPacket() const;
71 void InitPacketState(); // clear current packet state.
72 void InitProcessorState(); // clear all previous process state
74 ocsd_datapath_resp_t outputPacket();
76 typedef enum _process_state {
83 process_state m_process_state; // process algorithm state.
85 std::vector<uint8_t> m_currPacketData; // raw data
86 uint32_t m_currPktIdx; // index into packet when expanding
87 PtmTrcPacket m_curr_packet; // expanded packet
88 ocsd_trc_index_t m_curr_pkt_index; // trace index at start of packet.
90 const bool readByte(uint8_t &currByte);
91 const bool readByte(); // just read into buffer, don't need the value
92 void unReadByte(); // remove last byte from the buffer.
96 // current data block being processed.
97 const uint8_t *m_pDataIn;
99 uint32_t m_dataInProcessed;
100 ocsd_trc_index_t m_block_idx; // index start for current block
102 // processor synchronisation
103 const bool isSync() const;
104 ocsd_datapath_resp_t waitASync(); //!< look for first synchronisation point in the packet stream
105 bool m_waitASyncSOPkt;
107 bool m_bOPNotSyncPkt; //!< true if output not sync packet when waiting for ASYNC
109 // ** packet processing functions.
113 void pktWPointUpdate();
119 void pktExceptionRet();
120 void pktBranchAddr();
124 typedef enum _async_result {
125 ASYNC, //!< pattern confirmed async 0x00 x 5, 0x80
126 NOT_ASYNC, //!< pattern confirmed not async
127 ASYNC_EXTRA_0, //!< pattern confirmed 0x00 x N + ASYNC
128 THROW_0, //!< long pattern of 0x00 - throw some away.
129 ASYNC_INCOMPLETE, //!< not enough input data.
132 async_result_t findAsync();
134 int m_async_0; // number of current consecutive async 0s
138 // number of extra 0s before we throw 0 on async detect.
139 #define ASYNC_PAD_0_LIMIT 11
140 // number of 0s minimum to form an async
141 #define ASYNC_REQ_0 5
143 // extraction sub-routines
144 void extractCtxtID(int idx, uint32_t &ctxtID);
145 void extractCycleCount(int idx, uint32_t &cycleCount);
146 int extractTS(uint64_t &tsVal, uint8_t &tsUpdateBits);
147 uint32_t extractAddress(const int offset,uint8_t &total_bits);
149 // number of bytes required for a complete packet - used in some multi byte packets
150 int m_numPktBytesReq;
152 // packet processing state
153 bool m_needCycleCount;
154 bool m_gotCycleCount;
155 int m_gotCCBytes; // number of CC bytes read so far
157 int m_numCtxtIDBytes;
158 int m_gotCtxtIDBytes;
160 bool m_gotTSBytes; //!< got all TS bytes
161 int m_tsByteMax; //!< max size for TS portion of TS packet.
163 // branch address state
164 bool m_gotAddrBytes; //!< got all Addr bytes in branch packet
165 int m_numAddrBytes; //!< number of address bytes
166 bool m_gotExcepBytes; //!< got all needed exception bytes
167 int m_numExcepBytes; //!< got 1st exception byte
168 ocsd_isa m_addrPktIsa; //!< ISA of the branch address packet
169 int m_excepAltISA; //!< Alt ISA bit iff exception bytes
172 void throwMalformedPacketErr(const char *pszErrMsg);
173 void throwPacketHeaderErr(const char *pszErrMsg);
176 // packet processing function table
177 typedef void (TrcPktProcPtm::*PPKTFN)(void);
180 struct _pkt_i_table_t {
181 ocsd_ptm_pkt_type pkt_type;
185 void BuildIPacketTable();
189 inline const bool TrcPktProcPtm::isSync() const
191 return (bool)(m_curr_packet.getType() == PTM_PKT_NOTSYNC);
194 inline void TrcPktProcPtm::throwMalformedPacketErr(const char *pszErrMsg)
196 m_curr_packet.SetErrType(PTM_PKT_BAD_SEQUENCE);
197 throw ocsdError(OCSD_ERR_SEV_ERROR,OCSD_ERR_BAD_PACKET_SEQ,m_curr_pkt_index,m_chanIDCopy,pszErrMsg);
200 inline void TrcPktProcPtm::throwPacketHeaderErr(const char *pszErrMsg)
202 throw ocsdError(OCSD_ERR_SEV_ERROR,OCSD_ERR_INVALID_PCKT_HDR,m_curr_pkt_index,m_chanIDCopy,pszErrMsg);
205 inline const bool TrcPktProcPtm::readByte()
208 return readByte(currByte);
213 #endif // ARM_TRC_PKT_PROC_PTM_H_INCLUDED
215 /* End of File trc_pkt_proc_ptm.h */