]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - decoder/include/opencsd/ptm/trc_pkt_elem_ptm.h
Import OpenCSD -- an ARM CoreSight Trace Decode library.
[FreeBSD/FreeBSD.git] / decoder / include / opencsd / ptm / trc_pkt_elem_ptm.h
1 /*
2  * \file       trc_pkt_elem_ptm.h
3  * \brief      OpenCSD : 
4  * 
5  * \copyright  Copyright (c) 2015, ARM Limited. All Rights Reserved.
6  */
7
8
9 /* 
10  * Redistribution and use in source and binary forms, with or without modification, 
11  * are permitted provided that the following conditions are met:
12  * 
13  * 1. Redistributions of source code must retain the above copyright notice, 
14  * this list of conditions and the following disclaimer.
15  * 
16  * 2. Redistributions in binary form must reproduce the above copyright notice, 
17  * this list of conditions and the following disclaimer in the documentation 
18  * and/or other materials provided with the distribution. 
19  * 
20  * 3. Neither the name of the copyright holder nor the names of its contributors 
21  * may be used to endorse or promote products derived from this software without 
22  * specific prior written permission. 
23  * 
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND 
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
27  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
28  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 
31  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
34  */ 
35
36
37 #ifndef ARM_TRC_PKT_ELEM_PTM_H_INCLUDED
38 #define ARM_TRC_PKT_ELEM_PTM_H_INCLUDED
39
40 #include "trc_pkt_types_ptm.h"
41 #include "common/trc_printable_elem.h"
42 #include "common/trc_pkt_elem_base.h"
43
44 /** @addtogroup trc_pkts
45 @{*/
46
47
48 class PtmTrcPacket :  public TrcPacketBase, public ocsd_ptm_pkt, trcPrintableElem
49 {
50 public:
51     PtmTrcPacket();
52     ~PtmTrcPacket();
53
54     PtmTrcPacket &operator =(const ocsd_ptm_pkt* p_pkt);
55
56     virtual const void *c_pkt() const { return (const ocsd_ptm_pkt *)this; };
57
58     // update interface - set packet values
59
60     void Clear();       //!< clear update data in packet ready for new one.
61     void ResetState();  //!< reset intra packet state data - on full decoder reset.
62
63     void SetType(const ocsd_ptm_pkt_type p_type);
64     void SetErrType(const ocsd_ptm_pkt_type e_type);
65
66     void SetException(  const ocsd_armv7_exception type, 
67                         const uint16_t number);
68     void SetISyncReason(const ocsd_iSync_reason reason);
69     void SetCycleCount(const uint32_t cycleCount);
70     void SetAtomFromPHdr(const uint8_t pHdr);
71     void SetCycleAccAtomFromPHdr(const uint8_t pHdr);
72     
73     void UpdateAddress(const ocsd_vaddr_t partAddrVal, const int updateBits);
74     void UpdateNS(const int NS);
75     void UpdateAltISA(const int AltISA);
76     void UpdateHyp(const int Hyp);
77     void UpdateISA(const ocsd_isa isa);
78     void UpdateContextID(const uint32_t contextID);
79     void UpdateVMID(const uint8_t VMID);
80     void UpdateTimestamp(const uint64_t tsVal, const uint8_t updateBits);
81
82     // packet status interface 
83     
84     //  get packet info.
85     const bool isBadPacket() const;
86     const ocsd_ptm_pkt_type getType() const;
87
88     // isa
89     const ocsd_isa getISA() const;
90     const bool ISAChanged() const { return (bool)(curr_isa != prev_isa); };
91     const uint8_t getAltISA() const { return context.curr_alt_isa; };
92     const uint8_t getNS() const { return context.curr_NS; };
93     const uint8_t getHyp() const { return context.curr_Hyp; };
94
95     // address 
96     const ocsd_vaddr_t getAddrVal() const { return addr.val; }; 
97
98     // pe context information
99     const bool CtxtIDUpdated() const { return (bool)(context.updated_c == 1); };
100     const bool VMIDUpdated() const { return (bool)(context.updated_v == 1); };
101     const uint32_t getCtxtID() const { return context.ctxtID; };
102     const uint8_t getVMID() const { return context.VMID; };
103     const bool PEContextUpdated() const { return context.updated; };
104
105     // atom info
106     const ocsd_pkt_atom &getAtom() const { return atom; };
107
108     // branch address info
109     const bool isBranchExcepPacket() const { return (exception.bits.present == 1); };
110     const ocsd_armv7_exception excepType() const { return exception.type; };
111     const uint16_t excepNum() const { return exception.number;  };
112
113     // isync 
114     const ocsd_iSync_reason iSyncReason() const { return i_sync_reason; };
115
116     // cycle count 
117     const bool hasCC() const { return (cc_valid == 1); };
118     const uint32_t getCCVal() const { return cycle_count; };
119
120     // printing
121     virtual void toString(std::string &str) const;
122     virtual void toStringFmt(const  uint32_t fmtFlags, std::string &str) const;
123
124 private:
125     void packetTypeName(const ocsd_ptm_pkt_type pkt_type, std::string &name, std::string &desc) const;
126     void getAtomStr(std::string &valStr) const;
127     void getBranchAddressStr(std::string &valStr) const;
128     void getExcepStr(std::string &excepStr) const;
129     void getISAStr(std::string &isaStr) const;
130     void getCycleCountStr(std::string &subStr) const;
131     void getISyncStr(std::string &valStr) const;
132     void getTSStr(std::string &valStr) const;
133 };
134
135
136 //*** update interface - set packet values
137 inline void PtmTrcPacket::SetType(const ocsd_ptm_pkt_type p_type)
138 {
139     type = p_type;
140 }
141
142 inline void PtmTrcPacket::SetErrType(const ocsd_ptm_pkt_type e_type)
143 {
144     err_type = type;
145     type = e_type;
146 }
147
148 inline void PtmTrcPacket::UpdateNS(const int NS)
149 {
150     context.curr_NS = NS;
151     context.updated = 1;
152 };
153
154 inline void PtmTrcPacket::UpdateAltISA(const int AltISA)
155 {
156     context.curr_alt_isa = AltISA;
157     context.updated = 1;
158 }
159
160 inline void PtmTrcPacket::UpdateHyp(const int Hyp)
161 {
162     context.curr_Hyp = Hyp;
163     context.updated = 1;
164 }
165
166 inline void PtmTrcPacket::UpdateISA(const ocsd_isa isa)
167 {
168     prev_isa = curr_isa;
169     curr_isa = isa;
170 }
171
172 inline void PtmTrcPacket::UpdateContextID(const uint32_t contextID)
173 {
174     context.ctxtID = contextID;
175     context.updated_c = 1;
176 }
177
178 inline void PtmTrcPacket::UpdateVMID(const uint8_t VMID)
179 {
180     context.VMID = VMID;
181     context.updated_v = 1;
182 }
183
184 inline void PtmTrcPacket::SetException(  const ocsd_armv7_exception type, const uint16_t number)
185 {
186     exception.bits.present = 1;
187     exception.number = number;
188     exception.type = type;
189 }
190
191 inline void PtmTrcPacket::SetISyncReason(const ocsd_iSync_reason reason)
192 {
193     i_sync_reason = reason;
194 }
195
196 inline void PtmTrcPacket::SetCycleCount(const uint32_t cycleCount)
197 {
198     cycle_count = cycleCount;
199     cc_valid = 1;
200 }
201
202 //*** packet status interface - get packet info.
203 inline const bool PtmTrcPacket::isBadPacket() const
204 {
205     return (bool)(type >= PTM_PKT_BAD_SEQUENCE);
206 }
207
208 inline const ocsd_ptm_pkt_type PtmTrcPacket::getType() const
209 {
210     return type;
211 }
212
213 inline const ocsd_isa PtmTrcPacket::getISA() const
214 {
215     return curr_isa;
216 }
217
218 /** @}*/
219 #endif // ARM_TRC_PKT_ELEM_PTM_H_INCLUDED
220
221 /* End of File trc_pkt_elem_ptm.h */