OpenCSD - CoreSight Trace Decode Library  0.12.1
trc_etmv4_stack_elem.h
Go to the documentation of this file.
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 
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 {
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 /************************************************************/
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 
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 /************************************************************/
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  void setIS(const uint8_t IS) { m_IS = IS; };
137  const uint8_t getIS() const { return m_IS; };
138 
139 private:
140  etmv4_context_t m_context;
141  uint8_t m_IS;
142 };
143 
145  TrcStackElem(P0_CTXT, false, root_pkt,root_index)
146 {
147 }
148 
149 /************************************************************/
153 {
154 protected:
155  TrcStackElemExcept(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index);
156  virtual ~TrcStackElemExcept() {};
157 
158  friend class EtmV4P0Stack;
159 
160 public:
161  void setPrevSame(bool bSame) { m_prev_addr_same = bSame; };
162  const bool getPrevSame() const { return m_prev_addr_same; };
163 
164  void setExcepNum(const uint16_t num) { m_excep_num = num; };
165  const uint16_t getExcepNum() const { return m_excep_num; };
166 
167 private:
168  bool m_prev_addr_same;
169  uint16_t m_excep_num;
170 };
171 
173  TrcStackElem(P0_EXCEP, true, root_pkt,root_index),
174  m_prev_addr_same(false)
175 {
176 }
177 
178 /************************************************************/
182 {
183 protected:
184  TrcStackElemAtom(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index);
185  virtual ~TrcStackElemAtom() {};
186 
187  friend class EtmV4P0Stack;
188 
189 public:
190  void setAtom(const ocsd_pkt_atom &atom) { m_atom = atom; };
191 
192  const ocsd_atm_val commitOldest();
193  int cancelNewest(const int nCancel);
194  const bool isEmpty() const { return (m_atom.num == 0); };
195 
196 private:
197  ocsd_pkt_atom m_atom;
198 };
199 
201  TrcStackElem(P0_ATOM, true, root_pkt,root_index)
202 {
203  m_atom.num = 0;
204 }
205 
206 // commit oldest - get value and remove it from pattern
208 {
209  ocsd_atm_val val = (m_atom.En_bits & 0x1) ? ATOM_E : ATOM_N;
210  m_atom.num--;
211  m_atom.En_bits >>= 1;
212  return val;
213 }
214 
215 // cancel newest - just reduce the atom count.
216 inline int TrcStackElemAtom::cancelNewest(const int nCancel)
217 {
218  int nRemove = (nCancel <= m_atom.num) ? nCancel : m_atom.num;
219  m_atom.num -= nRemove;
220  return nRemove;
221 }
222 
223 /************************************************************/
227 {
228 protected:
229  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);
230  virtual ~TrcStackElemParam() {};
231 
232  friend class EtmV4P0Stack;
233 
234 public:
235  void setParam(const uint32_t param, const int nParamNum) { m_param[(nParamNum & 0x3)] = param; };
236  const uint32_t &getParam(const int nParamNum) const { return m_param[(nParamNum & 0x3)]; };
237 
238 private:
239  uint32_t m_param[4];
240 };
241 
242 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) :
243  TrcStackElem(p0_type, isP0, root_pkt,root_index)
244 {
245 }
246 
247 /************************************************************/
248 /* P0 element stack that allows push of elements, and deletion of elements when done.
249 */
251 {
252 public:
254  ~EtmV4P0Stack();
255 
256  void push_front(TrcStackElem *pElem);
257  void push_back(TrcStackElem *pElem); // insert element when processing
258  void pop_back();
259  TrcStackElem *back();
260  size_t size();
261 
262  void delete_all();
263  void delete_back();
264  void delete_popped();
265 
266  // creation functions - create and push if successful.
267  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);
268  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);
269  TrcStackElemAtom *createAtomElem (const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index, const ocsd_pkt_atom &atom);
270  TrcStackElemExcept *createExceptElem(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index, const bool bSame, const uint16_t excepNum);
271  TrcStackElemCtxt *createContextElem(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index, const etmv4_context_t &context, const uint8_t IS);
272  TrcStackElemAddr *createAddrElem(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index, const etmv4_addr_val_t &addr_val);
273 
274 private:
275  std::deque<TrcStackElem *> m_P0_stack;
276  std::vector<TrcStackElem *> m_popped_elem;
277 
278 };
279 
281 {
282  delete_all();
283  delete_popped();
284 }
285 
286 // put an element on the front of the stack
288 {
289  m_P0_stack.push_front(pElem);
290 }
291 
292 // put an element on the back of the stack
294 {
295  m_P0_stack.push_back(pElem);
296 }
297 
298 // pop last element pointer off the stack and stash it for later deletion
300 {
301  m_popped_elem.push_back(m_P0_stack.back());
302  m_P0_stack.pop_back();
303 }
304 
305 // pop last element pointer off the stack and delete immediately
307 {
308  if (m_P0_stack.size() > 0)
309  {
310  TrcStackElem* pElem = m_P0_stack.back();
311  delete pElem;
312  m_P0_stack.pop_back();
313  }
314 }
315 
316 // get a pointer to the last element on the stack
318 {
319  return m_P0_stack.back();
320 }
321 
322 // remove and delete all the elements left on the stack
324 {
325  while (m_P0_stack.size() > 0)
326  delete_back();
327  m_P0_stack.clear();
328 }
329 
330 // delete list of popped elements.
332 {
333  while (m_popped_elem.size() > 0)
334  {
335  delete m_popped_elem.back();
336  m_popped_elem.pop_back();
337  }
338  m_popped_elem.clear();
339 }
340 
341 // get current number of elements on the stack
342 inline size_t EtmV4P0Stack::size()
343 {
344  return m_P0_stack.size();
345 }
346 
347 #endif // ARM_TRC_ETMV4_STACK_ELEM_H_INCLUDED
348 
349 /* End of File trc_etmv4_stack_elem.h */
void push_front(TrcStackElem *pElem)
const etmv4_context_t & getContext() const
virtual ~TrcStackElem()
void push_back(TrcStackElem *pElem)
const bool isP0() const
enum _ocsd_etmv4_i_pkt_type ocsd_etmv4_i_pkt_type
void setPrevSame(bool bSame)
void setExcepNum(const uint16_t num)
void setAddr(const etmv4_addr_val_t &addr_val)
const etmv4_addr_val_t & getAddr() const
enum _ocsd_atm_val ocsd_atm_val
TrcStackElemExcept(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index)
void setParam(const uint32_t param, const int nParamNum)
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)
TrcStackElemAtom(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index)
void setContext(const etmv4_context_t &ctxt)
const ocsd_etmv4_i_pkt_type getRootPkt() const
TrcStackElemCtxt(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index)
const bool isEmpty() const
const ocsd_atm_val commitOldest()
const ocsd_trc_index_t getRootIndex() const
TrcStackElemAddr(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index)
enum _p0_elem_t p0_elem_t
const uint8_t getIS() const
void setAtom(const ocsd_pkt_atom &atom)
uint32_t ocsd_trc_index_t
Definition: ocsd_if_types.h:67
const uint16_t getExcepNum() const
ocsd_vaddr_t val
Address value.
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)
const p0_elem_t getP0Type() const
const bool getPrevSame() const
uint32_t En_bits
Definition: trc_pkt_types.h:90
uint8_t isa
instruction set.
TrcStackElem * back()
const uint32_t & getParam(const int nParamNum) const
void setIS(const uint8_t IS)
int cancelNewest(const int nCancel)