xref: /freebsd/contrib/opencsd/decoder/include/common/trc_gen_elem.h (revision 46e6e290975f19ea62d03f90ac3e523af4dae557)
1c120c564SAndrew Turner /*!
2c120c564SAndrew Turner  * \file       trc_gen_elem.h
3c120c564SAndrew Turner  * \brief      OpenCSD : Decoder Generic trace element output class.
4c120c564SAndrew Turner  *
5c120c564SAndrew Turner  * \copyright  Copyright (c) 2015, ARM Limited. All Rights Reserved.
6c120c564SAndrew Turner  */
7c120c564SAndrew Turner 
8c120c564SAndrew Turner /*
9c120c564SAndrew Turner  * Redistribution and use in source and binary forms, with or without modification,
10c120c564SAndrew Turner  * are permitted provided that the following conditions are met:
11c120c564SAndrew Turner  *
12c120c564SAndrew Turner  * 1. Redistributions of source code must retain the above copyright notice,
13c120c564SAndrew Turner  * this list of conditions and the following disclaimer.
14c120c564SAndrew Turner  *
15c120c564SAndrew Turner  * 2. Redistributions in binary form must reproduce the above copyright notice,
16c120c564SAndrew Turner  * this list of conditions and the following disclaimer in the documentation
17c120c564SAndrew Turner  * and/or other materials provided with the distribution.
18c120c564SAndrew Turner  *
19c120c564SAndrew Turner  * 3. Neither the name of the copyright holder nor the names of its contributors
20c120c564SAndrew Turner  * may be used to endorse or promote products derived from this software without
21c120c564SAndrew Turner  * specific prior written permission.
22c120c564SAndrew Turner  *
23c120c564SAndrew Turner  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24c120c564SAndrew Turner  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25c120c564SAndrew Turner  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26c120c564SAndrew Turner  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27c120c564SAndrew Turner  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28c120c564SAndrew Turner  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29c120c564SAndrew Turner  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30c120c564SAndrew Turner  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31c120c564SAndrew Turner  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32c120c564SAndrew Turner  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33c120c564SAndrew Turner  */
34c120c564SAndrew Turner #ifndef ARM_TRC_GEN_ELEM_H_INCLUDED
35c120c564SAndrew Turner #define ARM_TRC_GEN_ELEM_H_INCLUDED
36c120c564SAndrew Turner 
37c120c564SAndrew Turner #include "opencsd/trc_gen_elem_types.h"
38c120c564SAndrew Turner #include "trc_printable_elem.h"
39c120c564SAndrew Turner #include "ocsd_pe_context.h"
40c120c564SAndrew Turner 
41c120c564SAndrew Turner /** @addtogroup gen_trc_elem
42c120c564SAndrew Turner @{*/
43c120c564SAndrew Turner 
44c120c564SAndrew Turner /*!
45c120c564SAndrew Turner  * @class OcsdTraceElement
46c120c564SAndrew Turner  * @brief Generic trace element class
47c120c564SAndrew Turner  *
48c120c564SAndrew Turner  */
49c120c564SAndrew Turner class OcsdTraceElement : public trcPrintableElem, public ocsd_generic_trace_elem
50c120c564SAndrew Turner {
51c120c564SAndrew Turner public:
52c120c564SAndrew Turner     OcsdTraceElement();
53c120c564SAndrew Turner     OcsdTraceElement(ocsd_gen_trc_elem_t type);
~OcsdTraceElement()54c120c564SAndrew Turner     virtual ~OcsdTraceElement() {};
55c120c564SAndrew Turner 
56c120c564SAndrew Turner     void init();
57c120c564SAndrew Turner 
58c120c564SAndrew Turner // set elements API
59c120c564SAndrew Turner 
60c120c564SAndrew Turner     void setType(const ocsd_gen_trc_elem_t type);       //!< set type and init flags
61c120c564SAndrew Turner     void updateType(const ocsd_gen_trc_elem_t type);    //!< change type only - no init
62c120c564SAndrew Turner 
setContext(const ocsd_pe_context & new_context)63c120c564SAndrew Turner     void setContext(const ocsd_pe_context &new_context) { context = new_context; };
64c120c564SAndrew Turner     void setISA(const ocsd_isa isa_update);
65c120c564SAndrew Turner 
66c120c564SAndrew Turner     void setCycleCount(const uint32_t cycleCount);
67c120c564SAndrew Turner     void setEvent(const event_t ev_type, const uint16_t number);
68c120c564SAndrew Turner     void setTS(const uint64_t ts, const bool freqChange = false);
69c120c564SAndrew Turner 
setExcepMarker()70c120c564SAndrew Turner     void setExcepMarker() { excep_data_marker = 1; };
setExceptionNum(uint32_t excepNum)71c120c564SAndrew Turner     void setExceptionNum(uint32_t excepNum) { exception_number = excepNum; };
72c120c564SAndrew Turner     void setTraceOnReason(const trace_on_reason_t reason);
73b6aadd18SAndrew Turner     void setUnSyncEOTReason(const unsync_info_t reason);
setTransactionType(const trace_memtrans_t trans)74*46e6e290SRuslan Bukin     void setTransactionType(const trace_memtrans_t trans) { mem_trans = trans; };
75c120c564SAndrew Turner 
76c120c564SAndrew Turner     void setAddrRange(const ocsd_vaddr_t  st_addr, const ocsd_vaddr_t en_addr, const int num_instr = 1);
77c120c564SAndrew Turner     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)78c120c564SAndrew Turner     void setAddrStart(const ocsd_vaddr_t st_addr) { this->st_addr = st_addr; };
setLastInstrCond(const int is_cond)79c120c564SAndrew Turner     void setLastInstrCond(const int is_cond) { this->last_instr_cond = is_cond; };
80c120c564SAndrew Turner 
setSWTInfo(const ocsd_swt_info_t swt_info)81c120c564SAndrew Turner     void setSWTInfo(const ocsd_swt_info_t swt_info) { sw_trace_info = swt_info; };
82c120c564SAndrew Turner     void setExtendedDataPtr(const void *data_ptr);
83c120c564SAndrew Turner 
setITEInfo(const trace_sw_ite_t sw_instrumentation)84*46e6e290SRuslan Bukin     void setITEInfo(const trace_sw_ite_t sw_instrumentation) { sw_ite = sw_instrumentation; };
85*46e6e290SRuslan Bukin 
86*46e6e290SRuslan Bukin     void setSyncMarker(const trace_marker_payload_t &marker);
87*46e6e290SRuslan Bukin 
88c120c564SAndrew Turner // stringize the element
89c120c564SAndrew Turner 
90c120c564SAndrew Turner     virtual void toString(std::string &str) const;
91c120c564SAndrew Turner 
92c120c564SAndrew Turner // get elements API
93c120c564SAndrew Turner 
94c120c564SAndrew Turner     OcsdTraceElement &operator =(const ocsd_generic_trace_elem* p_elem);
95c120c564SAndrew Turner 
getType()96c120c564SAndrew Turner     const ocsd_gen_trc_elem_t getType() const { return elem_type; };
97c120c564SAndrew Turner 
98c120c564SAndrew Turner     // return current context
getContext()99c120c564SAndrew Turner     const ocsd_pe_context &getContext() const {  return context; };
100c120c564SAndrew Turner 
101b6aadd18SAndrew Turner     void copyPersistentData(const OcsdTraceElement &src);
102c120c564SAndrew Turner 
103c120c564SAndrew Turner private:
104c120c564SAndrew Turner     void printSWInfoPkt(std::ostringstream &oss) const;
105c120c564SAndrew Turner     void clearPerPktData(); //!< clear flags that indicate validity / have values on a per packet basis
106c120c564SAndrew Turner 
107c120c564SAndrew Turner };
108c120c564SAndrew Turner 
OcsdTraceElement(ocsd_gen_trc_elem_t type)109c120c564SAndrew Turner inline OcsdTraceElement::OcsdTraceElement(ocsd_gen_trc_elem_t type)
110c120c564SAndrew Turner {
111c120c564SAndrew Turner     elem_type = type;
112c120c564SAndrew Turner }
113c120c564SAndrew Turner 
OcsdTraceElement()114c120c564SAndrew Turner inline OcsdTraceElement::OcsdTraceElement()
115c120c564SAndrew Turner {
116c120c564SAndrew Turner     elem_type = OCSD_GEN_TRC_ELEM_UNKNOWN;
117c120c564SAndrew Turner }
118c120c564SAndrew Turner 
setCycleCount(const uint32_t cycleCount)119c120c564SAndrew Turner inline void OcsdTraceElement::setCycleCount(const uint32_t cycleCount)
120c120c564SAndrew Turner {
121c120c564SAndrew Turner     cycle_count = cycleCount;
122c120c564SAndrew Turner     has_cc = 1;
123c120c564SAndrew Turner }
124c120c564SAndrew Turner 
setEvent(const event_t ev_type,const uint16_t number)125c120c564SAndrew Turner inline void OcsdTraceElement::setEvent(const event_t ev_type, const uint16_t number)
126c120c564SAndrew Turner {
127c120c564SAndrew Turner     trace_event.ev_type = (uint16_t)ev_type;
128c120c564SAndrew Turner     trace_event.ev_number = ev_type == EVENT_NUMBERED ? number : 0;
129c120c564SAndrew Turner }
130c120c564SAndrew Turner 
setAddrRange(const ocsd_vaddr_t st_addr,const ocsd_vaddr_t en_addr,const int num_instr)131c120c564SAndrew Turner inline void OcsdTraceElement::setAddrRange(const ocsd_vaddr_t  st_addr, const ocsd_vaddr_t en_addr, const int num_instr /* = 1 */)
132c120c564SAndrew Turner {
133c120c564SAndrew Turner     this->st_addr = st_addr;
134c120c564SAndrew Turner     this->en_addr = en_addr;
135c120c564SAndrew Turner     this->num_instr_range = num_instr;
136c120c564SAndrew Turner }
137c120c564SAndrew Turner 
setLastInstrInfo(const bool exec,const ocsd_instr_type last_i_type,const ocsd_instr_subtype last_i_subtype,const uint8_t size)138c120c564SAndrew Turner 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)
139c120c564SAndrew Turner {
140c120c564SAndrew Turner     last_instr_exec = exec ? 1 : 0;
141c120c564SAndrew Turner     last_instr_sz = size & 0x7;
142c120c564SAndrew Turner     this->last_i_type = last_i_type;
143c120c564SAndrew Turner     this->last_i_subtype = last_i_subtype;
144c120c564SAndrew Turner }
145c120c564SAndrew Turner 
setType(const ocsd_gen_trc_elem_t type)146c120c564SAndrew Turner inline void OcsdTraceElement::setType(const ocsd_gen_trc_elem_t type)
147c120c564SAndrew Turner {
148c120c564SAndrew Turner     // set the type and clear down the per element flags
149c120c564SAndrew Turner     elem_type = type;
150c120c564SAndrew Turner 
151c120c564SAndrew Turner     clearPerPktData();
152c120c564SAndrew Turner }
153c120c564SAndrew Turner 
updateType(const ocsd_gen_trc_elem_t type)154c120c564SAndrew Turner inline void OcsdTraceElement::updateType(const ocsd_gen_trc_elem_t type)
155c120c564SAndrew Turner {
156c120c564SAndrew Turner     elem_type = type;
157c120c564SAndrew Turner }
158c120c564SAndrew Turner 
init()159c120c564SAndrew Turner inline void OcsdTraceElement::init()
160c120c564SAndrew Turner {
161c120c564SAndrew Turner     st_addr = en_addr = (ocsd_vaddr_t)-1;
162c120c564SAndrew Turner     isa = ocsd_isa_unknown;
163c120c564SAndrew Turner 
164c120c564SAndrew Turner     cycle_count = 0;
165c120c564SAndrew Turner     timestamp = 0;
166c120c564SAndrew Turner 
167c120c564SAndrew Turner     context.ctxt_id_valid = 0;
168c120c564SAndrew Turner     context.vmid_valid = 0;
169c120c564SAndrew Turner     context.el_valid = 0;
170c120c564SAndrew Turner 
171c120c564SAndrew Turner     last_i_type = OCSD_INSTR_OTHER;
172c120c564SAndrew Turner     last_i_subtype = OCSD_S_INSTR_NONE;
173c120c564SAndrew Turner 
174c120c564SAndrew Turner     clearPerPktData();
175c120c564SAndrew Turner }
176c120c564SAndrew Turner 
clearPerPktData()177c120c564SAndrew Turner inline void OcsdTraceElement::clearPerPktData()
178c120c564SAndrew Turner {
179b6aadd18SAndrew Turner     flag_bits = 0;          // bit-field with various flags.
180b6aadd18SAndrew Turner     exception_number = 0;   // union with trace_on_reason / trace_event
181c120c564SAndrew Turner     ptr_extended_data = 0;  // extended data pointer
182c120c564SAndrew Turner }
183c120c564SAndrew Turner 
setTraceOnReason(const trace_on_reason_t reason)184c120c564SAndrew Turner inline void OcsdTraceElement::setTraceOnReason(const trace_on_reason_t reason)
185c120c564SAndrew Turner {
186c120c564SAndrew Turner     trace_on_reason = reason;
187c120c564SAndrew Turner }
188c120c564SAndrew Turner 
setUnSyncEOTReason(const unsync_info_t reason)189b6aadd18SAndrew Turner inline void OcsdTraceElement::setUnSyncEOTReason(const unsync_info_t reason)
190b6aadd18SAndrew Turner {
191b6aadd18SAndrew Turner     unsync_eot_info = reason;
192b6aadd18SAndrew Turner }
193b6aadd18SAndrew Turner 
setISA(const ocsd_isa isa_update)194c120c564SAndrew Turner inline void OcsdTraceElement::setISA(const ocsd_isa isa_update)
195c120c564SAndrew Turner {
196c120c564SAndrew Turner     isa = isa_update;
197c120c564SAndrew Turner     if(isa > ocsd_isa_unknown)
198c120c564SAndrew Turner         isa = ocsd_isa_unknown;
199c120c564SAndrew Turner }
200c120c564SAndrew Turner 
setTS(const uint64_t ts,const bool freqChange)201c120c564SAndrew Turner inline void OcsdTraceElement::setTS(const uint64_t ts, const bool freqChange /*= false*/)
202c120c564SAndrew Turner {
203c120c564SAndrew Turner     timestamp = ts;
204c120c564SAndrew Turner     cpu_freq_change = freqChange ? 1 : 0;
205c120c564SAndrew Turner     has_ts = 1;
206c120c564SAndrew Turner }
207c120c564SAndrew Turner 
setExtendedDataPtr(const void * data_ptr)208c120c564SAndrew Turner inline void OcsdTraceElement::setExtendedDataPtr(const void *data_ptr)
209c120c564SAndrew Turner {
210c120c564SAndrew Turner     extended_data = 1;
211c120c564SAndrew Turner     ptr_extended_data = data_ptr;
212c120c564SAndrew Turner }
213c120c564SAndrew Turner 
setSyncMarker(const trace_marker_payload_t & marker)214*46e6e290SRuslan Bukin inline void OcsdTraceElement::setSyncMarker(const trace_marker_payload_t &marker)
215*46e6e290SRuslan Bukin {
216*46e6e290SRuslan Bukin     sync_marker = marker;
217*46e6e290SRuslan Bukin }
218*46e6e290SRuslan Bukin 
219b6aadd18SAndrew Turner // set persistent data between output packets.
copyPersistentData(const OcsdTraceElement & src)220b6aadd18SAndrew Turner inline void OcsdTraceElement::copyPersistentData(const OcsdTraceElement &src)
221b6aadd18SAndrew Turner {
222b6aadd18SAndrew Turner     isa = src.isa;
223b6aadd18SAndrew Turner     context = src.context;
224b6aadd18SAndrew Turner }
225c120c564SAndrew Turner 
226c120c564SAndrew Turner /** @}*/
227c120c564SAndrew Turner 
228c120c564SAndrew Turner #endif // ARM_TRC_GEN_ELEM_H_INCLUDED
229c120c564SAndrew Turner 
230c120c564SAndrew Turner /* End of File trc_gen_elem.h */
231