OpenCSD - CoreSight Trace Decode Library  0.14.3
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 
38 #include "trc_printable_elem.h"
39 #include "ocsd_pe_context.h"
40 
50 {
51 public:
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 
71  void setExceptionNum(uint32_t excepNum) { exception_number = excepNum; };
72 
73 
74  void setTraceOnReason(const trace_on_reason_t reason);
75  void setUnSyncEOTReason(const unsync_info_t reason);
76 
77  void setAddrRange(const ocsd_vaddr_t st_addr, const ocsd_vaddr_t en_addr, const int num_instr = 1);
78  void setLastInstrInfo(const bool exec, const ocsd_instr_type last_i_type, const ocsd_instr_subtype last_i_subtype, const uint8_t size);
79  void setAddrStart(const ocsd_vaddr_t st_addr) { this->st_addr = st_addr; };
80  void setLastInstrCond(const int is_cond) { this->last_instr_cond = is_cond; };
81 
82  void setSWTInfo(const ocsd_swt_info_t swt_info) { sw_trace_info = swt_info; };
83  void setExtendedDataPtr(const void *data_ptr);
84 
85 // stringize the element
86 
87  virtual void toString(std::string &str) const;
88 
89 // get elements API
90 
92 
93  const ocsd_gen_trc_elem_t getType() const { return elem_type; };
94 
95  // return current context
96  const ocsd_pe_context &getContext() const { return context; };
97 
98  void copyPersistentData(const OcsdTraceElement &src);
99 
100 private:
101  void printSWInfoPkt(std::ostringstream &oss) const;
102  void clearPerPktData();
103 
104 };
105 
107 {
108  elem_type = type;
109 }
110 
112 {
114 }
115 
116 inline void OcsdTraceElement::setCycleCount(const uint32_t cycleCount)
117 {
118  cycle_count = cycleCount;
119  has_cc = 1;
120 }
121 
122 inline void OcsdTraceElement::setEvent(const event_t ev_type, const uint16_t number)
123 {
124  trace_event.ev_type = (uint16_t)ev_type;
125  trace_event.ev_number = ev_type == EVENT_NUMBERED ? number : 0;
126 }
127 
128 inline void OcsdTraceElement::setAddrRange(const ocsd_vaddr_t st_addr, const ocsd_vaddr_t en_addr, const int num_instr /* = 1 */)
129 {
130  this->st_addr = st_addr;
131  this->en_addr = en_addr;
132  this->num_instr_range = num_instr;
133 }
134 
135 inline void OcsdTraceElement::setLastInstrInfo(const bool exec, const ocsd_instr_type last_i_type, const ocsd_instr_subtype last_i_subtype, const uint8_t size)
136 {
137  last_instr_exec = exec ? 1 : 0;
138  last_instr_sz = size & 0x7;
139  this->last_i_type = last_i_type;
140  this->last_i_subtype = last_i_subtype;
141 }
142 
144 {
145  // set the type and clear down the per element flags
146  elem_type = type;
147 
148  clearPerPktData();
149 }
150 
152 {
153  elem_type = type;
154 }
155 
157 {
158  st_addr = en_addr = (ocsd_vaddr_t)-1;
160 
161  cycle_count = 0;
162  timestamp = 0;
163 
165  context.vmid_valid = 0;
166  context.el_valid = 0;
167 
170 
171  clearPerPktData();
172 }
173 
174 inline void OcsdTraceElement::clearPerPktData()
175 {
176  flag_bits = 0; // bit-field with various flags.
177  exception_number = 0; // union with trace_on_reason / trace_event
178  ptr_extended_data = 0; // extended data pointer
179 }
180 
182 {
183  trace_on_reason = reason;
184 }
185 
187 {
188  unsync_eot_info = reason;
189 }
190 
191 inline void OcsdTraceElement::setISA(const ocsd_isa isa_update)
192 {
193  isa = isa_update;
194  if(isa > ocsd_isa_unknown)
196 }
197 
198 inline void OcsdTraceElement::setTS(const uint64_t ts, const bool freqChange /*= false*/)
199 {
200  timestamp = ts;
201  cpu_freq_change = freqChange ? 1 : 0;
202  has_ts = 1;
203 }
204 
205 inline void OcsdTraceElement::setExtendedDataPtr(const void *data_ptr)
206 {
207  extended_data = 1;
208  ptr_extended_data = data_ptr;
209 }
210 
211 // set persistent data between output packets.
213 {
214  isa = src.isa;
215  context = src.context;
216 }
217 
220 #endif // ARM_TRC_GEN_ELEM_H_INCLUDED
221 
222 /* End of File trc_gen_elem.h */
OcsdTraceElement::setSWTInfo
void setSWTInfo(const ocsd_swt_info_t swt_info)
Definition: trc_gen_elem.h:82
ocsd_instr_type
enum _ocsd_instr_type ocsd_instr_type
_ocsd_generic_trace_elem::last_instr_sz
uint32_t last_instr_sz
Definition: trc_gen_elem_types.h:104
OcsdTraceElement::setUnSyncEOTReason
void setUnSyncEOTReason(const unsync_info_t reason)
Definition: trc_gen_elem.h:186
_ocsd_generic_trace_elem::trace_on_reason
trace_on_reason_t trace_on_reason
Definition: trc_gen_elem_types.h:121
_ocsd_generic_trace_elem::unsync_eot_info
unsync_info_t unsync_eot_info
Definition: trc_gen_elem_types.h:124
OcsdTraceElement::setExcepMarker
void setExcepMarker()
Definition: trc_gen_elem.h:70
OcsdTraceElement
Generic trace element class.
Definition: trc_gen_elem.h:50
_ocsd_pe_context::vmid_valid
uint32_t vmid_valid
Definition: ocsd_if_types.h:414
_ocsd_generic_trace_elem::sw_trace_info
ocsd_swt_info_t sw_trace_info
Definition: trc_gen_elem_types.h:122
trc_printable_elem.h
OpenCSD : Standard printable element base class.
_ocsd_generic_trace_elem::ptr_extended_data
const void * ptr_extended_data
Definition: trc_gen_elem_types.h:127
_ocsd_generic_trace_elem::excep_data_marker
uint32_t excep_data_marker
Definition: trc_gen_elem_types.h:108
_ocsd_generic_trace_elem::flag_bits
uint32_t flag_bits
Definition: trc_gen_elem_types.h:114
OcsdTraceElement::getType
const ocsd_gen_trc_elem_t getType() const
Definition: trc_gen_elem.h:93
OcsdTraceElement::setAddrRange
void setAddrRange(const ocsd_vaddr_t st_addr, const ocsd_vaddr_t en_addr, const int num_instr=1)
Definition: trc_gen_elem.h:128
ocsd_pe_context.h
OcsdTraceElement::setEvent
void setEvent(const event_t ev_type, const uint16_t number)
Definition: trc_gen_elem.h:122
OcsdTraceElement::updateType
void updateType(const ocsd_gen_trc_elem_t type)
change type only - no init
Definition: trc_gen_elem.h:151
_ocsd_generic_trace_elem::cpu_freq_change
uint32_t cpu_freq_change
Definition: trc_gen_elem_types.h:106
_ocsd_generic_trace_elem::en_addr
ocsd_vaddr_t en_addr
Definition: trc_gen_elem_types.h:93
_ocsd_pe_context::ctxt_id_valid
uint32_t ctxt_id_valid
Definition: ocsd_if_types.h:413
_ocsd_generic_trace_elem::exception_number
uint32_t exception_number
Definition: trc_gen_elem_types.h:119
_ocsd_pe_context::el_valid
uint32_t el_valid
Definition: ocsd_if_types.h:415
_trace_event_t::ev_type
uint16_t ev_type
Definition: trc_gen_elem_types.h:75
_ocsd_generic_trace_elem::st_addr
ocsd_vaddr_t st_addr
Definition: trc_gen_elem_types.h:92
_ocsd_generic_trace_elem
Definition: trc_gen_elem_types.h:89
_ocsd_generic_trace_elem::num_instr_range
uint32_t num_instr_range
Definition: trc_gen_elem_types.h:123
ocsd_vaddr_t
uint64_t ocsd_vaddr_t
Definition: ocsd_if_types.h:308
event_t
enum _event_t event_t
_ocsd_generic_trace_elem::last_i_subtype
ocsd_instr_subtype last_i_subtype
Definition: trc_gen_elem_types.h:98
_ocsd_swt_info
Definition: ocsd_if_types.h:605
OcsdTraceElement::getContext
const ocsd_pe_context & getContext() const
Definition: trc_gen_elem.h:96
trc_gen_elem_types.h
OpenCSD : Decoder Output Generic Element types.
OcsdTraceElement::setISA
void setISA(const ocsd_isa isa_update)
Definition: trc_gen_elem.h:191
OcsdTraceElement::setContext
void setContext(const ocsd_pe_context &new_context)
Definition: trc_gen_elem.h:63
trcPrintableElem
Class to provide trace element strings for printing.
Definition: trc_printable_elem.h:56
OcsdTraceElement::copyPersistentData
void copyPersistentData(const OcsdTraceElement &src)
Definition: trc_gen_elem.h:212
ocsd_instr_subtype
enum _ocsd_instr_subtype ocsd_instr_subtype
OCSD_INSTR_OTHER
@ OCSD_INSTR_OTHER
Definition: ocsd_if_types.h:357
unsync_info_t
enum _unsync_info_t unsync_info_t
_ocsd_generic_trace_elem::isa
ocsd_isa isa
Definition: trc_gen_elem_types.h:91
_ocsd_generic_trace_elem::has_ts
uint32_t has_ts
Definition: trc_gen_elem_types.h:110
_ocsd_generic_trace_elem::last_instr_exec
uint32_t last_instr_exec
Definition: trc_gen_elem_types.h:103
ocsd_gen_trc_elem_t
enum _ocsd_gen_trc_elem_t ocsd_gen_trc_elem_t
OCSD_GEN_TRC_ELEM_UNKNOWN
@ OCSD_GEN_TRC_ELEM_UNKNOWN
Definition: trc_gen_elem_types.h:49
OcsdTraceElement::setLastInstrCond
void setLastInstrCond(const int is_cond)
Definition: trc_gen_elem.h:80
_ocsd_pe_context
Definition: ocsd_if_types.h:406
ocsd_isa_unknown
@ ocsd_isa_unknown
Definition: ocsd_if_types.h:332
OcsdTraceElement::setTS
void setTS(const uint64_t ts, const bool freqChange=false)
Definition: trc_gen_elem.h:198
OcsdTraceElement::OcsdTraceElement
OcsdTraceElement()
Definition: trc_gen_elem.h:111
OcsdTraceElement::setTraceOnReason
void setTraceOnReason(const trace_on_reason_t reason)
Definition: trc_gen_elem.h:181
OcsdTraceElement::setExceptionNum
void setExceptionNum(uint32_t excepNum)
Definition: trc_gen_elem.h:71
OCSD_S_INSTR_NONE
@ OCSD_S_INSTR_NONE
Definition: ocsd_if_types.h:369
trace_on_reason_t
enum _trace_on_reason_t trace_on_reason_t
_trace_event_t::ev_number
uint16_t ev_number
Definition: trc_gen_elem_types.h:76
_ocsd_generic_trace_elem::last_instr_cond
uint32_t last_instr_cond
Definition: trc_gen_elem_types.h:111
_ocsd_generic_trace_elem::extended_data
uint32_t extended_data
Definition: trc_gen_elem_types.h:109
_ocsd_generic_trace_elem::last_i_type
ocsd_instr_type last_i_type
Definition: trc_gen_elem_types.h:97
OcsdTraceElement::toString
virtual void toString(std::string &str) const
OcsdTraceElement::init
void init()
Definition: trc_gen_elem.h:156
OcsdTraceElement::setType
void setType(const ocsd_gen_trc_elem_t type)
set type and init flags
Definition: trc_gen_elem.h:143
OcsdTraceElement::setExtendedDataPtr
void setExtendedDataPtr(const void *data_ptr)
Definition: trc_gen_elem.h:205
OcsdTraceElement::setCycleCount
void setCycleCount(const uint32_t cycleCount)
Definition: trc_gen_elem.h:116
_ocsd_generic_trace_elem::context
ocsd_pe_context context
Definition: trc_gen_elem_types.h:94
_ocsd_generic_trace_elem::cycle_count
uint32_t cycle_count
Definition: trc_gen_elem_types.h:96
_ocsd_generic_trace_elem::elem_type
ocsd_gen_trc_elem_t elem_type
Definition: trc_gen_elem_types.h:90
EVENT_NUMBERED
@ EVENT_NUMBERED
Definition: trc_gen_elem_types.h:135
_ocsd_generic_trace_elem::timestamp
uint64_t timestamp
Definition: trc_gen_elem_types.h:95
_ocsd_generic_trace_elem::has_cc
uint32_t has_cc
Definition: trc_gen_elem_types.h:105
_ocsd_generic_trace_elem::trace_event
trace_event_t trace_event
Definition: trc_gen_elem_types.h:120
OcsdTraceElement::operator=
OcsdTraceElement & operator=(const ocsd_generic_trace_elem *p_elem)
ocsd_isa
enum _ocsd_isa ocsd_isa
OcsdTraceElement::~OcsdTraceElement
virtual ~OcsdTraceElement()
Definition: trc_gen_elem.h:54
OcsdTraceElement::setLastInstrInfo
void setLastInstrInfo(const bool exec, const ocsd_instr_type last_i_type, const ocsd_instr_subtype last_i_subtype, const uint8_t size)
Definition: trc_gen_elem.h:135
OcsdTraceElement::setAddrStart
void setAddrStart(const ocsd_vaddr_t st_addr)
Definition: trc_gen_elem.h:79