]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/opencsd/decoder/source/etmv3/trc_pkt_proc_etmv3_impl.h
Re-add opencsd as a vendor import from the dist directory
[FreeBSD/FreeBSD.git] / contrib / opencsd / decoder / source / etmv3 / trc_pkt_proc_etmv3_impl.h
1 /*
2  * \file       trc_pkt_proc_etmv3_impl.h
3  * \brief      OpenCSD : 
4  * 
5  * \copyright  Copyright (c) 2015, ARM Limited. All Rights Reserved.
6  */
7
8
9 /* 
10  * Redistribution and use in source and binary forms, with or without modification, 
11  * are permitted provided that the following conditions are met:
12  * 
13  * 1. Redistributions of source code must retain the above copyright notice, 
14  * this list of conditions and the following disclaimer.
15  * 
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. 
19  * 
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. 
23  * 
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. 
34  */ 
35
36 #ifndef ARM_TRC_PKT_PROC_ETMV3_IMPL_H_INCLUDED
37 #define ARM_TRC_PKT_PROC_ETMV3_IMPL_H_INCLUDED
38
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"
42
43 #define MAX_PACKET_SIZE 32
44 #define ASYNC_SIZE 6
45
46 class EtmV3PktProcImpl
47 {
48 public:
49     EtmV3PktProcImpl();
50     ~EtmV3PktProcImpl();
51
52     void Initialise(TrcPktProcEtmV3 *p_interface);
53
54     ocsd_err_t Configure(const EtmV3Config *p_config);
55
56
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;
65
66 protected:
67     typedef enum _process_state {
68         WAIT_SYNC,
69         PROC_HDR,
70         PROC_DATA,
71         SEND_PKT, 
72         PROC_ERR,
73     } process_state;
74     
75     process_state m_process_state;
76     
77
78     void InitPacketState();      // clear current packet state.
79     void InitProcessorState();   // clear all previous process state
80
81     // byte processing
82
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);
86
87     // packet handling - main routines
88     void OnBranchAddress();
89     void OnISyncPacket();
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();
95
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.
101
102     // packet output
103     void SendPacket();  // mark state for packet output
104     ocsd_datapath_resp_t outputPacket();   // output a packet
105
106     // bad packets 
107     void throwMalformedPacketErr(const char *pszErrMsg);
108     void throwPacketHeaderErr(const char *pszErrMsg);
109     void throwUnsupportedErr(const char *pszErrMsg);
110
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
115
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.
120
121     // process state
122     bool            m_bStreamSync;          //!< true if we have synced this stream
123     bool            m_bStartOfSync;         //!< true if we have a start of sync.
124     
125     // packet state 
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;
130         int m_IsyncInfoIdx;
131         bool m_bExpectingDataAddress;
132         bool m_bFoundDataAddress;
133
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.
136
137     bool m_isInit;
138     TrcPktProcEtmV3 *m_interface;       /**< The interface to the other decode components */
139     
140     EtmV3Config m_config;
141
142     uint8_t m_chanIDCopy;
143 };
144
145
146 inline void EtmV3PktProcImpl::SendPacket()
147 {
148     m_process_state = SEND_PKT;
149 }
150
151 inline void EtmV3PktProcImpl::throwMalformedPacketErr(const char *pszErrMsg)
152 {
153     throw ocsdError(OCSD_ERR_SEV_ERROR,OCSD_ERR_BAD_PACKET_SEQ,m_packet_index,m_chanIDCopy,pszErrMsg);
154 }
155
156 inline void EtmV3PktProcImpl::throwPacketHeaderErr(const char *pszErrMsg)
157 {
158     throw ocsdError(OCSD_ERR_SEV_ERROR,OCSD_ERR_INVALID_PCKT_HDR,m_packet_index,m_chanIDCopy,pszErrMsg);
159 }
160
161 inline void EtmV3PktProcImpl::throwUnsupportedErr(const char *pszErrMsg)
162 {
163     throw ocsdError(OCSD_ERR_SEV_ERROR,OCSD_ERR_HW_CFG_UNSUPP,m_packet_index,m_chanIDCopy,pszErrMsg);
164 }
165
166
167 inline const bool EtmV3PktProcImpl::isBadPacket() const
168 {
169     return m_curr_packet.isBadPacket();
170 }
171
172
173 #endif // ARM_TRC_PKT_PROC_ETMV3_IMPL_H_INCLUDED
174
175 /* End of File trc_pkt_proc_etmv3_impl.h */