]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/opencsd/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.h
Re-add opencsd as a vendor import from the dist directory
[FreeBSD/FreeBSD.git] / contrib / opencsd / decoder / source / etmv4 / trc_pkt_proc_etmv4i_impl.h
1 /*
2  * \file       trc_pkt_proc_etmv4i_impl.h
3  * \brief      OpenCSD : Implementation of ETMv4 packet processing
4  * 
5  * \copyright  Copyright (c) 2015, 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 "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"
41
42 class TraceRawBuffer
43 {
44 public:
45     TraceRawBuffer();
46     ~TraceRawBuffer() {};
47
48     // init the buffer
49     void init(const uint32_t size, const uint8_t *rawtrace, std::vector<uint8_t> *out_packet);
50     void copyByteToPkt();   // move a byte to the packet buffer     
51     uint8_t peekNextByte(); // value of next byte in buffer.
52
53     bool empty() { return m_bufProcessed == m_bufSize; };
54     // bytes processed.
55     uint32_t processed() { return m_bufProcessed; }; 
56     // buffer size;
57     uint32_t size() { return m_bufSize; } 
58
59 private:
60     uint32_t m_bufSize;
61     uint32_t m_bufProcessed;
62     const uint8_t *m_pBuffer;
63     std::vector<uint8_t> *pkt;
64
65 };
66
67 class EtmV4IPktProcImpl
68 {
69 public:
70     EtmV4IPktProcImpl();
71     ~EtmV4IPktProcImpl();
72
73     void Initialise(TrcPktProcEtmV4I *p_interface);
74
75     ocsd_err_t Configure(const EtmV4Config *p_config);
76
77
78     ocsd_datapath_resp_t processData(  const ocsd_trc_index_t index,
79                                         const uint32_t dataBlockSize,
80                                         const uint8_t *pDataBlock,
81                                         uint32_t *numBytesProcessed);
82     ocsd_datapath_resp_t onEOT();
83     ocsd_datapath_resp_t onReset();
84     ocsd_datapath_resp_t onFlush();
85     const bool isBadPacket() const;
86
87 protected:
88     typedef enum _process_state {
89         PROC_HDR,
90         PROC_DATA,
91         SEND_PKT,
92         SEND_UNSYNCED,
93         PROC_ERR,
94     } process_state;
95     
96     process_state m_process_state;
97
98     void InitPacketState();      // clear current packet state.
99     void InitProcessorState();   // clear all previous process state
100
101     /** packet processor configuration **/
102     bool m_isInit;
103     TrcPktProcEtmV4I *m_interface;       /**< The interface to the other decode components */
104
105     // etmv4 hardware configuration
106     EtmV4Config m_config;
107
108     /** packet data **/
109     TraceRawBuffer m_trcIn;    // trace data in buffer
110     std::vector<uint8_t> m_currPacketData;  // raw data packet
111     int m_currPktIdx;   // index into raw packet when expanding
112     EtmV4ITrcPacket m_curr_packet;  // expanded packet
113     ocsd_trc_index_t m_packet_index;   // index of the start of the current packet
114 //    uint32_t m_blockBytesProcessed;     // number of bytes processed in the current data block
115     ocsd_trc_index_t m_blockIndex;     // index at the start of the current data block being processed
116
117     // searching for sync
118     bool m_is_sync;             //!< seen first sync packet
119     bool m_first_trace_info;    //!< seen first trace info packet after sync
120     bool m_sent_notsync_packet; //!< send one not sync packet if we see any unsynced data on the channel 
121     unsigned m_dump_unsynced_bytes;  //!< number of unsynced bytes to send
122     ocsd_trc_index_t m_update_on_unsync_packet_index;
123
124
125 private:
126     // current processing state data - counts and flags to determine if a packet is complete.
127
128     // TraceInfo Packet
129     // flags to indicate processing progress for these sections is complete.
130     struct _t_info_pkt_prog {
131         uint8_t sectFlags;
132         uint8_t ctrlBytes;                 
133     }  m_tinfo_sections;
134
135     #define TINFO_INFO_SECT 0x01
136     #define TINFO_KEY_SECT  0x02 
137     #define TINFO_SPEC_SECT 0x04
138     #define TINFO_CYCT_SECT 0x08
139     #define TINFO_CTRL      0x20
140     #define TINFO_ALL_SECT  0x1F
141     #define TINFO_ALL       0x3F
142
143
144     // address and context packets 
145     int m_addrBytes;
146     uint8_t m_addrIS;
147     bool m_bAddr64bit;
148     int m_vmidBytes;    // bytes still to find
149     int m_ctxtidBytes;  // bytes still to find
150     bool m_bCtxtInfoDone;
151     bool m_addr_done;
152
153     // timestamp
154     bool m_ccount_done; // done or not needed 
155     bool m_ts_done;
156     int m_ts_bytes;
157
158     // exception
159     int m_excep_size;
160
161     // cycle count
162     bool m_has_count;
163     bool m_count_done;
164     bool m_commit_done;
165
166     // cond result
167     bool m_F1P1_done;  // F1 payload 1 done
168     bool m_F1P2_done;  // F1 payload 2 done
169     bool m_F1has_P2;   // F1 has a payload 2
170
171     // Q packets (use some from above too)
172     bool m_has_addr;
173     bool m_addr_short;
174     bool m_addr_match;
175     uint8_t m_Q_type;
176     uint8_t m_QE;
177
178     ocsd_datapath_resp_t outputPacket();
179     ocsd_datapath_resp_t outputUnsyncedRawPacket(); 
180
181     void iNotSync(const uint8_t lastByte);      // not synced yet
182     void iPktNoPayload(const uint8_t lastByte); // process a single byte packet
183     void iPktReserved(const uint8_t lastByte);  // deal with reserved header value
184     void iPktExtension(const uint8_t lastByte);
185     void iPktASync(const uint8_t lastByte);
186     void iPktTraceInfo(const uint8_t lastByte);
187     void iPktTimestamp(const uint8_t lastByte);
188     void iPktException(const uint8_t lastByte);
189     void iPktCycleCntF123(const uint8_t lastByte);
190     void iPktSpeclRes(const uint8_t lastByte);
191     void iPktCondInstr(const uint8_t lastByte);
192     void iPktCondResult(const uint8_t lastByte);
193     void iPktContext(const uint8_t lastByte);
194     void iPktAddrCtxt(const uint8_t lastByte);
195     void iPktShortAddr(const uint8_t lastByte);
196     void iPktLongAddr(const uint8_t lastByte);
197     void iPktQ(const uint8_t lastByte);
198     void iAtom(const uint8_t lastByte);
199     void iPktInvalidCfg(const uint8_t lastByte);  // packet invalid in current config.
200
201     unsigned extractContField(const std::vector<uint8_t> &buffer, const unsigned st_idx, uint32_t &value, const unsigned byte_limit = 5);
202     unsigned extractContField64(const std::vector<uint8_t> &buffer, const unsigned st_idx, uint64_t &value, const unsigned byte_limit = 9);
203     unsigned extractCondResult(const std::vector<uint8_t> &buffer, const unsigned st_idx, uint32_t& key, uint8_t &result);
204     void extractAndSetContextInfo(const std::vector<uint8_t> &buffer, const int st_idx);
205     int extract64BitLongAddr(const std::vector<uint8_t> &buffer, const int st_idx, const uint8_t IS, uint64_t &value);
206     int extract32BitLongAddr(const std::vector<uint8_t> &buffer, const int st_idx, const uint8_t IS, uint32_t &value);
207     int extractShortAddr(const std::vector<uint8_t> &buffer, const int st_idx, const uint8_t IS, uint32_t &value, int &bits);
208
209     // packet processing is table driven.    
210     typedef void (EtmV4IPktProcImpl::*PPKTFN)(uint8_t);
211     PPKTFN m_pIPktFn;
212
213     struct _pkt_i_table_t {
214         ocsd_etmv4_i_pkt_type pkt_type;
215         PPKTFN pptkFn;
216     } m_i_table[256];
217
218     void BuildIPacketTable();
219
220     void throwBadSequenceError(const char *pszExtMsg);
221 };
222
223
224 inline const bool EtmV4IPktProcImpl::isBadPacket() const
225 {
226     return m_curr_packet.isBadPacket();
227 }
228
229 #endif // ARM_TRC_PKT_PROC_ETMV4I_IMPL_H_INCLUDED
230
231 /* End of File trc_pkt_proc_etmv4i_impl.h */