OpenCSD - CoreSight Trace Decode Library  0.5
trc_gen_elem.h
Go to the documentation of this file.
1 
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 #ifndef ARM_TRC_GEN_ELEM_H_INCLUDED
35 #define ARM_TRC_GEN_ELEM_H_INCLUDED
36 
37 #include "opencsd/trc_gen_elem_types.h"
38 #include "trc_printable_elem.h"
39 #include "ocsd_pe_context.h"
40 
49 class OcsdTraceElement : public trcPrintableElem, public ocsd_generic_trace_elem
50 {
51 public:
53  OcsdTraceElement(ocsd_gen_trc_elem_t type);
54  virtual ~OcsdTraceElement() {};
55 
56  void init();
57 
58 // set elements API
59 
60  void setType(const ocsd_gen_trc_elem_t type);
61  void updateType(const ocsd_gen_trc_elem_t type);
62 
63  void setContext(const ocsd_pe_context &new_context) { context = new_context; };
64  void setISA(const ocsd_isa isa_update);
65 
66  void setCycleCount(const uint32_t cycleCount);
67  void setEvent(const event_t ev_type, const uint16_t number);
68  void setTS(const uint64_t ts, const bool freqChange = false);
69 
70  void setExcepMarker() { excep_data_marker = 1; };
71  void setExceptionNum(uint32_t excepNum) { exception_number = excepNum; };
72 
73 
74  void setTraceOnReason(const trace_on_reason_t reason);
75 
76  void setAddrRange(const ocsd_vaddr_t st_addr, const ocsd_vaddr_t en_addr);
77  void setLastInstrInfo(const bool exec, const ocsd_instr_type last_i_type, const ocsd_instr_subtype last_i_subtype);
78  void setAddrStart(const ocsd_vaddr_t st_addr) { this->st_addr = st_addr; };
79 
80  void setSWTInfo(const ocsd_swt_info_t swt_info) { sw_trace_info = swt_info; };
81  void setExtendedDataPtr(const void *data_ptr);
82 
83 // stringize the element
84 
85  virtual void toString(std::string &str) const;
86 
87 // get elements API
88 
89  OcsdTraceElement &operator =(const ocsd_generic_trace_elem* p_elem);
90 
91  const ocsd_gen_trc_elem_t getType() const { return elem_type; };
92 
93  // return current context
94  const ocsd_pe_context &getContext() const { return context; };
95 
96 
97 private:
98  void printSWInfoPkt(std::ostringstream &oss) const;
99  void clearPerPktData();
100 
101 };
102 
103 inline OcsdTraceElement::OcsdTraceElement(ocsd_gen_trc_elem_t type)
104 {
105  elem_type = type;
106 }
107 
109 {
110  elem_type = OCSD_GEN_TRC_ELEM_UNKNOWN;
111 }
112 
113 inline void OcsdTraceElement::setCycleCount(const uint32_t cycleCount)
114 {
115  cycle_count = cycleCount;
116  has_cc = 1;
117 }
118 
119 inline void OcsdTraceElement::setEvent(const event_t ev_type, const uint16_t number)
120 {
121  trace_event.ev_type = (uint16_t)ev_type;
122  trace_event.ev_number = ev_type == EVENT_NUMBERED ? number : 0;
123 }
124 
125 inline void OcsdTraceElement::setAddrRange(const ocsd_vaddr_t st_addr, const ocsd_vaddr_t en_addr)
126 {
127  this->st_addr = st_addr;
128  this->en_addr = en_addr;
129 }
130 
131 inline void OcsdTraceElement::setLastInstrInfo(const bool exec, const ocsd_instr_type last_i_type, const ocsd_instr_subtype last_i_subtype)
132 {
133  last_instr_exec = exec ? 1 : 0;
134  this->last_i_type = last_i_type;
135  this->last_i_subtype = last_i_subtype;
136 }
137 
138 inline void OcsdTraceElement::setType(const ocsd_gen_trc_elem_t type)
139 {
140  // set the type and clear down the per element flags
141  elem_type = type;
142 
143  clearPerPktData();
144 }
145 
146 inline void OcsdTraceElement::updateType(const ocsd_gen_trc_elem_t type)
147 {
148  elem_type = type;
149 }
150 
152 {
153  st_addr = en_addr = (ocsd_vaddr_t)-1;
154  isa = ocsd_isa_unknown;
155 
156  cycle_count = 0;
157  timestamp = 0;
158 
159  context.ctxt_id_valid = 0;
160  context.vmid_valid = 0;
161  context.el_valid = 0;
162 
163  last_i_type = OCSD_INSTR_OTHER;
164  last_i_subtype = OCSD_S_INSTR_NONE;
165 
166  clearPerPktData();
167 }
168 
169 inline void OcsdTraceElement::clearPerPktData()
170 {
171  flag_bits = 0; // union with trace_on_reason / trace_event
172 
173  ptr_extended_data = 0; // extended data pointer
174 }
175 
176 inline void OcsdTraceElement::setTraceOnReason(const trace_on_reason_t reason)
177 {
178  trace_on_reason = reason;
179 }
180 
181 inline void OcsdTraceElement::setISA(const ocsd_isa isa_update)
182 {
183  isa = isa_update;
184  if(isa > ocsd_isa_unknown)
185  isa = ocsd_isa_unknown;
186 }
187 
188 inline void OcsdTraceElement::setTS(const uint64_t ts, const bool freqChange /*= false*/)
189 {
190  timestamp = ts;
191  cpu_freq_change = freqChange ? 1 : 0;
192  has_ts = 1;
193 }
194 
195 inline void OcsdTraceElement::setExtendedDataPtr(const void *data_ptr)
196 {
197  extended_data = 1;
198  ptr_extended_data = data_ptr;
199 }
200 
201 
204 #endif // ARM_TRC_GEN_ELEM_H_INCLUDED
205 
206 /* End of File trc_gen_elem.h */
void setAddrStart(const ocsd_vaddr_t st_addr)
Definition: trc_gen_elem.h:78
void setEvent(const event_t ev_type, const uint16_t number)
Definition: trc_gen_elem.h:119
const ocsd_pe_context & getContext() const
Definition: trc_gen_elem.h:94
void setContext(const ocsd_pe_context &new_context)
Definition: trc_gen_elem.h:63
void updateType(const ocsd_gen_trc_elem_t type)
change type only - no init
Definition: trc_gen_elem.h:146
void setExceptionNum(uint32_t excepNum)
Definition: trc_gen_elem.h:71
OpenCSD : Standard printable element base class.
OcsdTraceElement & operator=(const ocsd_generic_trace_elem *p_elem)
virtual ~OcsdTraceElement()
Definition: trc_gen_elem.h:54
void setLastInstrInfo(const bool exec, const ocsd_instr_type last_i_type, const ocsd_instr_subtype last_i_subtype)
Definition: trc_gen_elem.h:131
void setAddrRange(const ocsd_vaddr_t st_addr, const ocsd_vaddr_t en_addr)
Definition: trc_gen_elem.h:125
void setExcepMarker()
Definition: trc_gen_elem.h:70
void setISA(const ocsd_isa isa_update)
Definition: trc_gen_elem.h:181
void setSWTInfo(const ocsd_swt_info_t swt_info)
Definition: trc_gen_elem.h:80
void setTS(const uint64_t ts, const bool freqChange=false)
Definition: trc_gen_elem.h:188
Generic trace element class.
Definition: trc_gen_elem.h:49
Class to provide trace element strings for printing.
void setTraceOnReason(const trace_on_reason_t reason)
Definition: trc_gen_elem.h:176
void setCycleCount(const uint32_t cycleCount)
Definition: trc_gen_elem.h:113
void setExtendedDataPtr(const void *data_ptr)
Definition: trc_gen_elem.h:195
virtual void toString(std::string &str) const
void setType(const ocsd_gen_trc_elem_t type)
set type and init flags
Definition: trc_gen_elem.h:138
const ocsd_gen_trc_elem_t getType() const
Definition: trc_gen_elem.h:91