• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2  * \file       trc_gen_elem.h
3  * \brief      OpenCSD : Decoder Generic trace element output class.
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 #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 
41 /** @addtogroup gen_trc_elem
42 @{*/
43 
44 /*!
45  * @class OcsdTraceElement
46  * @brief Generic trace element class
47  *
48  */
49 class OcsdTraceElement : public trcPrintableElem, public ocsd_generic_trace_elem
50 {
51 public:
52     OcsdTraceElement();
53     OcsdTraceElement(ocsd_gen_trc_elem_t type);
~OcsdTraceElement()54     virtual ~OcsdTraceElement() {};
55 
56     void init();
57 
58 // set elements API
59 
60     void setType(const ocsd_gen_trc_elem_t type);       //!< set type and init flags
61     void updateType(const ocsd_gen_trc_elem_t type);    //!< change type only - no init
62 
setContext(const ocsd_pe_context & new_context)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 
setExcepMarker()70     void setExcepMarker() { excep_data_marker = 1; };
setExceptionNum(uint32_t excepNum)71     void setExceptionNum(uint32_t excepNum) { exception_number = excepNum; };
72     void setTraceOnReason(const trace_on_reason_t reason);
73     void setUnSyncEOTReason(const unsync_info_t reason);
setTransactionType(const trace_memtrans_t trans)74     void setTransactionType(const trace_memtrans_t trans) { mem_trans = trans; };
75 
76     void setAddrRange(const ocsd_vaddr_t  st_addr, const ocsd_vaddr_t en_addr, const int num_instr = 1);
77     void setLastInstrInfo(const bool exec, const ocsd_instr_type last_i_type, const ocsd_instr_subtype last_i_subtype, const uint8_t size);
setAddrStart(const ocsd_vaddr_t st_addr)78     void setAddrStart(const ocsd_vaddr_t st_addr) { this->st_addr = st_addr; };
setLastInstrCond(const int is_cond)79     void setLastInstrCond(const int is_cond) { this->last_instr_cond = is_cond; };
80 
setSWTInfo(const ocsd_swt_info_t swt_info)81     void setSWTInfo(const ocsd_swt_info_t swt_info) { sw_trace_info = swt_info; };
82     void setExtendedDataPtr(const void *data_ptr);
83 
setITEInfo(const trace_sw_ite_t sw_instrumentation)84     void setITEInfo(const trace_sw_ite_t sw_instrumentation) { sw_ite = sw_instrumentation; };
85 
86     void setSyncMarker(const trace_marker_payload_t &marker);
87 
88 // stringize the element
89 
90     virtual void toString(std::string &str) const;
91 
92 // get elements API
93 
94     OcsdTraceElement &operator =(const ocsd_generic_trace_elem* p_elem);
95 
getType()96     const ocsd_gen_trc_elem_t getType() const { return elem_type; };
97 
98     // return current context
getContext()99     const ocsd_pe_context &getContext() const {  return context; };
100 
101     void copyPersistentData(const OcsdTraceElement &src);
102 
103 private:
104     void printSWInfoPkt(std::ostringstream &oss) const;
105     void clearPerPktData(); //!< clear flags that indicate validity / have values on a per packet basis
106 
107 };
108 
OcsdTraceElement(ocsd_gen_trc_elem_t type)109 inline OcsdTraceElement::OcsdTraceElement(ocsd_gen_trc_elem_t type)
110 {
111     elem_type = type;
112 }
113 
OcsdTraceElement()114 inline OcsdTraceElement::OcsdTraceElement()
115 {
116     elem_type = OCSD_GEN_TRC_ELEM_UNKNOWN;
117 }
118 
setCycleCount(const uint32_t cycleCount)119 inline void OcsdTraceElement::setCycleCount(const uint32_t cycleCount)
120 {
121     cycle_count = cycleCount;
122     has_cc = 1;
123 }
124 
setEvent(const event_t ev_type,const uint16_t number)125 inline void OcsdTraceElement::setEvent(const event_t ev_type, const uint16_t number)
126 {
127     trace_event.ev_type = (uint16_t)ev_type;
128     trace_event.ev_number = ev_type == EVENT_NUMBERED ? number : 0;
129 }
130 
setAddrRange(const ocsd_vaddr_t st_addr,const ocsd_vaddr_t en_addr,const int num_instr)131 inline void OcsdTraceElement::setAddrRange(const ocsd_vaddr_t  st_addr, const ocsd_vaddr_t en_addr, const int num_instr /* = 1 */)
132 {
133     this->st_addr = st_addr;
134     this->en_addr = en_addr;
135     this->num_instr_range = num_instr;
136 }
137 
setLastInstrInfo(const bool exec,const ocsd_instr_type last_i_type,const ocsd_instr_subtype last_i_subtype,const uint8_t size)138 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)
139 {
140     last_instr_exec = exec ? 1 : 0;
141     last_instr_sz = size & 0x7;
142     this->last_i_type = last_i_type;
143     this->last_i_subtype = last_i_subtype;
144 }
145 
setType(const ocsd_gen_trc_elem_t type)146 inline void OcsdTraceElement::setType(const ocsd_gen_trc_elem_t type)
147 {
148     // set the type and clear down the per element flags
149     elem_type = type;
150 
151     clearPerPktData();
152 }
153 
updateType(const ocsd_gen_trc_elem_t type)154 inline void OcsdTraceElement::updateType(const ocsd_gen_trc_elem_t type)
155 {
156     elem_type = type;
157 }
158 
init()159 inline void OcsdTraceElement::init()
160 {
161     st_addr = en_addr = (ocsd_vaddr_t)-1;
162     isa = ocsd_isa_unknown;
163 
164     cycle_count = 0;
165     timestamp = 0;
166 
167     context.ctxt_id_valid = 0;
168     context.vmid_valid = 0;
169     context.el_valid = 0;
170 
171     last_i_type = OCSD_INSTR_OTHER;
172     last_i_subtype = OCSD_S_INSTR_NONE;
173 
174     clearPerPktData();
175 }
176 
clearPerPktData()177 inline void OcsdTraceElement::clearPerPktData()
178 {
179     flag_bits = 0;          // bit-field with various flags.
180     exception_number = 0;   // union with trace_on_reason / trace_event
181     ptr_extended_data = 0;  // extended data pointer
182 }
183 
setTraceOnReason(const trace_on_reason_t reason)184 inline void OcsdTraceElement::setTraceOnReason(const trace_on_reason_t reason)
185 {
186     trace_on_reason = reason;
187 }
188 
setUnSyncEOTReason(const unsync_info_t reason)189 inline void OcsdTraceElement::setUnSyncEOTReason(const unsync_info_t reason)
190 {
191     unsync_eot_info = reason;
192 }
193 
setISA(const ocsd_isa isa_update)194 inline void OcsdTraceElement::setISA(const ocsd_isa isa_update)
195 {
196     isa = isa_update;
197     if(isa > ocsd_isa_unknown)
198         isa = ocsd_isa_unknown;
199 }
200 
setTS(const uint64_t ts,const bool freqChange)201 inline void OcsdTraceElement::setTS(const uint64_t ts, const bool freqChange /*= false*/)
202 {
203     timestamp = ts;
204     cpu_freq_change = freqChange ? 1 : 0;
205     has_ts = 1;
206 }
207 
setExtendedDataPtr(const void * data_ptr)208 inline void OcsdTraceElement::setExtendedDataPtr(const void *data_ptr)
209 {
210     extended_data = 1;
211     ptr_extended_data = data_ptr;
212 }
213 
setSyncMarker(const trace_marker_payload_t & marker)214 inline void OcsdTraceElement::setSyncMarker(const trace_marker_payload_t &marker)
215 {
216     sync_marker = marker;
217 }
218 
219 // set persistent data between output packets.
copyPersistentData(const OcsdTraceElement & src)220 inline void OcsdTraceElement::copyPersistentData(const OcsdTraceElement &src)
221 {
222     isa = src.isa;
223     context = src.context;
224 }
225 
226 /** @}*/
227 
228 #endif // ARM_TRC_GEN_ELEM_H_INCLUDED
229 
230 /* End of File trc_gen_elem.h */
231