1 /* 2 * \file trc_pkt_elem_etmv3.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 #ifndef ARM_TRC_PKT_ELEM_ETMV3_H_INCLUDED 37 #define ARM_TRC_PKT_ELEM_ETMV3_H_INCLUDED 38 39 #include "trc_pkt_types_etmv3.h" 40 #include "common/trc_printable_elem.h" 41 #include "common/trc_pkt_elem_base.h" 42 43 /** @addtogroup trc_pkts 44 @{*/ 45 46 /*! 47 * @class EtmV3TrcPacket 48 * @brief ETMv3 Trace Protocol Packet. 49 * 50 * This class represents a single ETMv3 trace packet, along with intra packet state. 51 * 52 */ 53 class EtmV3TrcPacket : public TrcPacketBase, public trcPrintableElem 54 { 55 public: 56 EtmV3TrcPacket(); 57 ~EtmV3TrcPacket(); 58 59 // conversions between C-API struct and C++ object types 60 // assign from C-API struct 61 EtmV3TrcPacket &operator =(const ocsd_etmv3_pkt* p_pkt); 62 63 // allow const cast to C-API struct to pass C++ object 64 operator const ocsd_etmv3_pkt*() const { return &m_pkt_data; }; 65 operator const ocsd_etmv3_pkt&() const { return m_pkt_data; }; 66 67 // override c_pkt to pass out the packet data struct. 68 virtual const void *c_pkt() const { return &m_pkt_data; }; 69 70 // update interface - set packet values 71 void Clear(); //!< clear update data in packet ready for new one. 72 void ResetState(); //!< reset intra packet state data -on full decoder reset. 73 74 void SetType(const ocsd_etmv3_pkt_type p_type); 75 void SetErrType(const ocsd_etmv3_pkt_type e_type); 76 void UpdateAddress(const ocsd_vaddr_t partAddrVal, const int updateBits); 77 void SetException( const ocsd_armv7_exception type, 78 const uint16_t number, 79 const bool cancel, 80 const bool cm_type, 81 const int irq_n = 0, 82 const int resume = 0); 83 void UpdateNS(const int NS); 84 void UpdateAltISA(const int AltISA); 85 void UpdateHyp(const int Hyp); 86 void UpdateISA(const ocsd_isa isa); 87 void UpdateContextID(const uint32_t contextID); 88 void UpdateVMID(const uint8_t VMID); 89 void UpdateTimestamp(const uint64_t tsVal, const uint8_t updateBits); 90 91 bool UpdateAtomFromPHdr(const uint8_t pHdr, const bool cycleAccurate); //!< Interpret P Hdr, return true if valid, false if not. 92 93 void SetDataOOOTag(const uint8_t tag); 94 void SetDataValue(const uint32_t value); 95 void UpdateDataAddress(const uint32_t value, const uint8_t valid_bits); 96 void UpdateDataEndian(const uint8_t BE_Val); 97 void SetCycleCount(const uint32_t cycleCount); 98 void SetISyncReason(const ocsd_iSync_reason reason); 99 void SetISyncHasCC(); 100 void SetISyncIsLSiP(); 101 void SetISyncNoAddr(); 102 103 // packet status interface - get packet info. 104 const ocsd_etmv3_pkt_type getType() const { return m_pkt_data.type; }; 105 const bool isBadPacket() const; 106 107 const int AltISA() const { return m_pkt_data.context.curr_alt_isa; }; 108 const ocsd_isa ISA() const { return m_pkt_data.curr_isa; }; 109 const bool changedISA() const { return m_pkt_data.curr_isa != m_pkt_data.prev_isa; }; 110 111 // any of the context elements updated? 112 const bool isCtxtUpdated() const; 113 const bool isCtxtFlagsUpdated() const { return (m_pkt_data.context.updated == 1); }; 114 const bool isNS() const { return m_pkt_data.context.curr_NS; }; 115 const bool isHyp() const { return m_pkt_data.context.curr_Hyp; }; 116 117 const bool isCtxtIDUpdated() const { return (m_pkt_data.context.updated_c == 1); } 118 const uint32_t getCtxtID() const { return m_pkt_data.context.ctxtID; }; 119 const bool isVMIDUpdated() const { return (m_pkt_data.context.updated_v == 1); } 120 const uint32_t getVMID() const { return m_pkt_data.context.VMID; }; 121 122 const uint32_t getCycleCount() const { return m_pkt_data.cycle_count; }; 123 const uint64_t getTS() const { return m_pkt_data.timestamp; }; 124 125 const bool isExcepPkt() const { return (m_pkt_data.exception.bits.present == 1); }; 126 const ocsd_armv7_exception excepType() const { return m_pkt_data.exception.type; }; 127 const uint16_t excepNum() const { return m_pkt_data.exception.number; }; 128 const bool isExcepCancel() const { return (m_pkt_data.exception.bits.present == 1) && (m_pkt_data.exception.bits.cancel == 1); }; 129 130 const ocsd_iSync_reason getISyncReason() const { return m_pkt_data.isync_info.reason; }; 131 const bool getISyncHasCC() const { return m_pkt_data.isync_info.has_cycle_count; }; 132 const bool getISyncIsLSiPAddr() const { return m_pkt_data.isync_info.has_LSipAddress; }; 133 const bool getISyncNoAddr() const { return m_pkt_data.isync_info.no_address; }; 134 135 const ocsd_vaddr_t getAddr() const { return m_pkt_data.addr.val; }; 136 const ocsd_vaddr_t getDataAddr() const { return m_pkt_data.data.addr.val; }; 137 138 const ocsd_pkt_atom &getAtom() const { return m_pkt_data.atom; }; 139 const uint8_t getPHdrFmt() const { return m_pkt_data.p_hdr_fmt; }; 140 141 142 // printing 143 virtual void toString(std::string &str) const; 144 virtual void toStringFmt(const uint32_t fmtFlags, std::string &str) const; 145 146 private: 147 const char *packetTypeName(const ocsd_etmv3_pkt_type type, const char **ppDesc) const; 148 void getBranchAddressStr(std::string &valStr) const; 149 void getAtomStr(std::string &valStr) const; 150 void getISyncStr(std::string &valStr) const; 151 void getISAStr(std::string &isaStr) const; 152 void getExcepStr(std::string &excepStr) const; 153 154 ocsd_etmv3_pkt m_pkt_data; 155 }; 156 157 inline void EtmV3TrcPacket::UpdateNS(const int NS) 158 { 159 m_pkt_data.context.curr_NS = NS; 160 m_pkt_data.context.updated = 1; 161 }; 162 163 inline void EtmV3TrcPacket::UpdateAltISA(const int AltISA) 164 { 165 m_pkt_data.context.curr_alt_isa = AltISA; 166 m_pkt_data.context.updated = 1; 167 } 168 169 inline void EtmV3TrcPacket::UpdateHyp(const int Hyp) 170 { 171 m_pkt_data.context.curr_Hyp = Hyp; 172 m_pkt_data.context.updated = 1; 173 } 174 175 inline void EtmV3TrcPacket::UpdateISA(const ocsd_isa isa) 176 { 177 m_pkt_data.prev_isa = m_pkt_data.curr_isa; 178 m_pkt_data.curr_isa = isa; 179 } 180 181 inline void EtmV3TrcPacket::SetType(const ocsd_etmv3_pkt_type p_type) 182 { 183 m_pkt_data.type = p_type; 184 } 185 186 inline void EtmV3TrcPacket::SetErrType(const ocsd_etmv3_pkt_type e_type) 187 { 188 m_pkt_data.err_type = m_pkt_data.type; 189 m_pkt_data.type = e_type; 190 } 191 192 inline const bool EtmV3TrcPacket::isBadPacket() const 193 { 194 return (m_pkt_data.type >= ETM3_PKT_BAD_SEQUENCE); 195 } 196 197 inline void EtmV3TrcPacket::SetDataOOOTag(const uint8_t tag) 198 { 199 m_pkt_data.data.ooo_tag = tag; 200 } 201 202 inline void EtmV3TrcPacket::SetDataValue(const uint32_t value) 203 { 204 m_pkt_data.data.value = value; 205 m_pkt_data.data.update_dval = 1; 206 } 207 208 inline void EtmV3TrcPacket::UpdateContextID(const uint32_t contextID) 209 { 210 m_pkt_data.context.updated_c = 1; 211 m_pkt_data.context.ctxtID = contextID; 212 } 213 214 inline void EtmV3TrcPacket::UpdateVMID(const uint8_t VMID) 215 { 216 m_pkt_data.context.updated_v = 1; 217 m_pkt_data.context.VMID = VMID; 218 } 219 220 inline void EtmV3TrcPacket::UpdateDataEndian(const uint8_t BE_Val) 221 { 222 m_pkt_data.data.be = BE_Val; 223 m_pkt_data.data.update_be = 1; 224 } 225 226 inline void EtmV3TrcPacket::SetCycleCount(const uint32_t cycleCount) 227 { 228 m_pkt_data.cycle_count = cycleCount; 229 } 230 231 inline void EtmV3TrcPacket::SetISyncReason(const ocsd_iSync_reason reason) 232 { 233 m_pkt_data.isync_info.reason = reason; 234 } 235 236 inline void EtmV3TrcPacket::SetISyncHasCC() 237 { 238 m_pkt_data.isync_info.has_cycle_count = 1; 239 } 240 241 inline void EtmV3TrcPacket::SetISyncIsLSiP() 242 { 243 m_pkt_data.isync_info.has_LSipAddress = 1; 244 } 245 246 inline void EtmV3TrcPacket::SetISyncNoAddr() 247 { 248 m_pkt_data.isync_info.no_address = 1; 249 } 250 251 inline const bool EtmV3TrcPacket::isCtxtUpdated() const 252 { 253 return (m_pkt_data.context.updated_v == 1) || 254 (m_pkt_data.context.updated == 1) || 255 (m_pkt_data.context.updated_c == 1); 256 } 257 258 /** @}*/ 259 #endif // ARM_TRC_PKT_ELEM_ETMV3_H_INCLUDED 260 261 /* End of File trc_pkt_elem_etmv3.h */ 262