]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/opencsd/decoder/include/opencsd/etmv4/trc_etmv4_stack_elem.h
Re-add opencsd as a vendor import from the dist directory
[FreeBSD/FreeBSD.git] / contrib / opencsd / decoder / include / opencsd / etmv4 / trc_etmv4_stack_elem.h
1 /*
2  * \file       trc_etmv4_stack_elem.h
3  * \brief      OpenCSD : 
4  * 
5  * \copyright  Copyright (c) 2015, ARM Limited. All Rights Reserved.
6  */
7 /* 
8  * Redistribution and use in source and binary forms, with or without modification, 
9  * are permitted provided that the following conditions are met:
10  * 
11  * 1. Redistributions of source code must retain the above copyright notice, 
12  * this list of conditions and the following disclaimer.
13  * 
14  * 2. Redistributions in binary form must reproduce the above copyright notice, 
15  * this list of conditions and the following disclaimer in the documentation 
16  * and/or other materials provided with the distribution. 
17  * 
18  * 3. Neither the name of the copyright holder nor the names of its contributors 
19  * may be used to endorse or promote products derived from this software without 
20  * specific prior written permission. 
21  * 
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND 
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
24  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
25  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
26  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
27  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 
29  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
32  */ 
33 #ifndef ARM_TRC_ETMV4_STACK_ELEM_H_INCLUDED
34 #define ARM_TRC_ETMV4_STACK_ELEM_H_INCLUDED
35
36 #include "opencsd/etmv4/trc_pkt_types_etmv4.h"
37
38 #include <deque>
39 #include <vector>
40
41 /* ETMv4 I trace stack elements  
42     Speculation requires that we stack certain elements till they are committed or 
43     cancelled. (P0 elements + other associated parts.)
44 */
45
46 typedef enum _p0_elem_t 
47 {
48     P0_UNKNOWN,
49     P0_ATOM,
50     P0_ADDR,
51     P0_CTXT,
52     P0_TRC_ON,
53     P0_EXCEP,
54     P0_EXCEP_RET,
55     P0_EVENT,
56     P0_TS,
57     P0_CC,
58     P0_TS_CC,
59     P0_OVERFLOW,
60     P0_FUNC_RET,
61 } p0_elem_t;
62
63
64 /************************************************************/
65 /***Trace stack element base class - 
66     record originating packet type and index in buffer*/ 
67
68 class TrcStackElem {
69 public:
70      TrcStackElem(const p0_elem_t p0_type, const bool isP0, const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index);
71      virtual ~TrcStackElem() {};
72
73      const p0_elem_t getP0Type() const { return m_P0_type; };
74      const ocsd_etmv4_i_pkt_type getRootPkt() const { return m_root_pkt; };
75      const ocsd_trc_index_t getRootIndex() const  { return m_root_idx; };
76      const bool isP0() const { return m_is_P0; };
77
78 private:
79      ocsd_etmv4_i_pkt_type m_root_pkt;
80      ocsd_trc_index_t m_root_idx;
81      p0_elem_t m_P0_type;
82
83 protected:
84      bool m_is_P0;  // true if genuine P0 - commit / cancellable, false otherwise
85
86 };
87
88 inline TrcStackElem::TrcStackElem(p0_elem_t p0_type, const bool isP0, ocsd_etmv4_i_pkt_type root_pkt, ocsd_trc_index_t root_index) :
89     m_root_pkt(root_pkt),
90     m_root_idx(root_index),
91     m_P0_type(p0_type),
92     m_is_P0(isP0)
93 {
94 }
95
96 /************************************************************/
97 /** Address element */
98
99 class TrcStackElemAddr : public TrcStackElem
100 {
101 protected:
102     TrcStackElemAddr(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index);
103     virtual ~TrcStackElemAddr() {};
104
105     friend class EtmV4P0Stack;
106
107 public:
108     void setAddr(const etmv4_addr_val_t &addr_val) { m_addr_val = addr_val; };
109     const etmv4_addr_val_t &getAddr() const { return m_addr_val; };
110
111 private:
112     etmv4_addr_val_t m_addr_val;
113 };
114
115 inline TrcStackElemAddr::TrcStackElemAddr(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index) :
116     TrcStackElem(P0_ADDR, false, root_pkt,root_index)
117 {
118     m_addr_val.val = 0;
119     m_addr_val.isa = 0;
120 }
121
122 /************************************************************/
123 /** Context element */
124     
125 class TrcStackElemCtxt : public TrcStackElem
126 {
127 protected:
128     TrcStackElemCtxt(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index);
129     virtual ~TrcStackElemCtxt() {};
130
131     friend class EtmV4P0Stack;
132
133 public:
134     void setContext(const  etmv4_context_t &ctxt) { m_context = ctxt; };
135     const  etmv4_context_t &getContext() const  { return m_context; }; 
136
137 private:
138      etmv4_context_t m_context;
139 };
140
141 inline TrcStackElemCtxt::TrcStackElemCtxt(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index) :
142     TrcStackElem(P0_CTXT, false, root_pkt,root_index)
143 {
144 }
145
146 /************************************************************/
147 /** Exception element */
148
149 class TrcStackElemExcept : public TrcStackElem
150 {
151 protected:
152     TrcStackElemExcept(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index);
153     virtual ~TrcStackElemExcept() {};
154
155     friend class EtmV4P0Stack;
156
157 public:
158     void setPrevSame(bool bSame) { m_prev_addr_same = bSame; };
159     const bool getPrevSame() const { return m_prev_addr_same; };
160
161     void setExcepNum(const uint16_t num) { m_excep_num = num; };
162     const uint16_t getExcepNum() const { return m_excep_num; };
163
164 private:
165     bool m_prev_addr_same;
166     uint16_t m_excep_num;
167 };
168
169 inline TrcStackElemExcept::TrcStackElemExcept(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index) :
170     TrcStackElem(P0_EXCEP, true, root_pkt,root_index),
171         m_prev_addr_same(false)
172 {
173 }
174
175 /************************************************************/
176 /** Atom element */
177     
178 class TrcStackElemAtom : public TrcStackElem
179 {
180 protected:
181     TrcStackElemAtom(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index);
182     virtual ~TrcStackElemAtom() {};
183
184     friend class EtmV4P0Stack;
185
186 public:
187     void setAtom(const ocsd_pkt_atom &atom) { m_atom = atom; };
188
189     const ocsd_atm_val commitOldest();
190     int cancelNewest(const int nCancel);
191     const bool isEmpty() const { return (m_atom.num == 0); };
192
193 private:
194     ocsd_pkt_atom m_atom;
195 };
196
197 inline TrcStackElemAtom::TrcStackElemAtom(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index) :
198     TrcStackElem(P0_ATOM, true, root_pkt,root_index)
199 {
200     m_atom.num = 0;
201 }
202
203 // commit oldest - get value and remove it from pattern
204 inline const ocsd_atm_val TrcStackElemAtom::commitOldest()
205 {
206     ocsd_atm_val val = (m_atom.En_bits & 0x1) ? ATOM_E : ATOM_N;
207     m_atom.num--;
208     m_atom.En_bits >>= 1;
209     return val;
210 }
211
212 // cancel newest - just reduce the atom count.
213 inline int TrcStackElemAtom::cancelNewest(const int nCancel)
214 {
215     int nRemove = (nCancel <= m_atom.num) ? nCancel : m_atom.num;
216     m_atom.num -= nRemove;
217     return nRemove;
218 }
219
220 /************************************************************/
221 /** Generic param element */
222
223 class TrcStackElemParam : public TrcStackElem
224 {
225 protected:
226     TrcStackElemParam(const p0_elem_t p0_type, const bool isP0, const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index);
227     virtual ~TrcStackElemParam() {};
228
229     friend class EtmV4P0Stack;
230
231 public:
232     void setParam(const uint32_t param, const int nParamNum) { m_param[(nParamNum & 0x3)] = param; };
233     const uint32_t &getParam(const int nParamNum) const { return m_param[(nParamNum & 0x3)]; };
234
235 private:
236     uint32_t m_param[4];    
237 };
238
239 inline TrcStackElemParam::TrcStackElemParam(const p0_elem_t p0_type, const bool isP0, const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index) :
240     TrcStackElem(p0_type, isP0, root_pkt,root_index)
241 {
242 }
243
244 /************************************************************/
245 /* P0 element stack that allows push of elements, and deletion of elements when done.
246 */
247 class EtmV4P0Stack
248 {
249 public:
250     EtmV4P0Stack() {};
251     ~EtmV4P0Stack();
252
253     void push_front(TrcStackElem *pElem);
254     void push_back(TrcStackElem *pElem);        // insert element when processing
255     void pop_back();
256     TrcStackElem *back();
257     size_t size();
258
259     void delete_all();
260     void delete_back();
261     void delete_popped();
262
263     // creation functions - create and push if successful.
264     TrcStackElemParam *createParamElem(const p0_elem_t p0_type, const bool isP0, const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index, const std::vector<uint32_t> &params);
265     TrcStackElem *createParamElemNoParam(const p0_elem_t p0_type, const bool isP0, const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index, bool back = false);
266     TrcStackElemAtom *createAtomElem (const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index, const ocsd_pkt_atom &atom);
267     TrcStackElemExcept *createExceptElem(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index, const bool bSame, const uint16_t excepNum);
268     TrcStackElemCtxt *createContextElem(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index, const etmv4_context_t &context);
269     TrcStackElemAddr *createAddrElem(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index, const etmv4_addr_val_t &addr_val);
270
271 private:
272     std::deque<TrcStackElem *> m_P0_stack;  //!< P0 decode element stack
273     std::vector<TrcStackElem *> m_popped_elem;  //!< save list of popped but not deleted elements.
274
275 };
276
277 inline EtmV4P0Stack::~EtmV4P0Stack()
278 {
279     delete_all();
280     delete_popped();
281 }
282
283 // put an element on the front of the stack
284 inline void EtmV4P0Stack::push_front(TrcStackElem *pElem)
285 {
286     m_P0_stack.push_front(pElem);
287 }
288
289 // put an element on the back of the stack
290 inline void EtmV4P0Stack::push_back(TrcStackElem *pElem)
291 {
292     m_P0_stack.push_back(pElem);
293 }
294
295 // pop last element pointer off the stack and stash it for later deletion
296 inline void EtmV4P0Stack::pop_back()
297 {
298     m_popped_elem.push_back(m_P0_stack.back());
299     m_P0_stack.pop_back();
300 }
301
302 // pop last element pointer off the stack and delete immediately
303 inline void EtmV4P0Stack::delete_back()
304 {
305     if (m_P0_stack.size() > 0)
306     {
307         TrcStackElem* pElem = m_P0_stack.back();
308         delete pElem;
309         m_P0_stack.pop_back();
310     }
311 }
312
313 // get a pointer to the last element on the stack
314 inline TrcStackElem *EtmV4P0Stack::back()
315 {
316     return m_P0_stack.back();
317 }
318
319 // remove and delete all the elements left on the stack
320 inline void EtmV4P0Stack::delete_all()
321 {
322     while (m_P0_stack.size() > 0)
323         delete_back();
324     m_P0_stack.clear();
325 }
326
327 // delete list of popped elements.
328 inline void EtmV4P0Stack::delete_popped()
329 {
330     while (m_popped_elem.size() > 0)
331     {
332         delete m_popped_elem.back();
333         m_popped_elem.pop_back();
334     }
335     m_popped_elem.clear();
336 }
337
338 // get current number of elements on the stack
339 inline size_t EtmV4P0Stack::size()
340 {
341     return m_P0_stack.size();
342 }
343
344 #endif // ARM_TRC_ETMV4_STACK_ELEM_H_INCLUDED
345
346 /* End of File trc_etmv4_stack_elem.h */