Loading...
Searching...
No Matches
trc_pkt_decode_etmv4i.h
Go to the documentation of this file.
/*
* \file trc_pkt_decode_etmv4i.h
* \brief OpenCSD : ETMv4 instruction decoder
*
* \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved.
*/
/*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ARM_TRC_PKT_DECODE_ETMV4I_H_INCLUDED
#define ARM_TRC_PKT_DECODE_ETMV4I_H_INCLUDED
#include "common/trc_pkt_decode_base.h"
#include "opencsd/etmv4/trc_pkt_elem_etmv4i.h"
#include "opencsd/etmv4/trc_cmp_cfg_etmv4.h"
#include "common/trc_gen_elem.h"
#include "common/trc_ret_stack.h"
#include "common/ocsd_gen_elem_stack.h"
#include "opencsd/etmv4/trc_etmv4_stack_elem.h"
#define OCSD_ENV_INSTR_RANGE_LIMIT "OPENCSD_INSTR_RANGE_LIMIT"
class TrcStackElem;
class TrcStackElemParam;
class TrcStackElemCtxt;
class TrcPktDecodeEtmV4I : public TrcPktDecodeBase<EtmV4ITrcPacket, EtmV4Config>
{
public:
TrcPktDecodeEtmV4I();
TrcPktDecodeEtmV4I(int instIDNum);
virtual ~TrcPktDecodeEtmV4I();
protected:
/* implementation packet decoding interface */
virtual ocsd_datapath_resp_t processPacket();
virtual ocsd_datapath_resp_t onEOT();
virtual ocsd_datapath_resp_t onReset();
virtual ocsd_datapath_resp_t onFlush();
virtual ocsd_err_t onProtocolConfig();
virtual const uint8_t getCoreSightTraceID() { return m_CSID; };
/* local decode methods */
void initDecoder(); // initial state on creation (zeros all config)
void resetDecoder(); // reset state to start of decode. (moves state, retains config)
virtual void onFirstInitOK(); // override to set init related info.
ocsd_err_t decodePacket(); // decode packet into trace elements. return true to indicate decode complete - can change FSM to commit state - return is false.
ocsd_datapath_resp_t resolveElements(); // commit/cancel trace elements generated from latest / prior packets & send to output - may get wait response, or flag completion.
ocsd_err_t commitElements(); // commit elements - process element stack to generate output packets.
ocsd_err_t commitElemOnEOT();
ocsd_err_t cancelElements(); // cancel elements. These not output
ocsd_err_t mispredictAtom(); // mispredict an atom
ocsd_err_t discardElements(); // discard elements and flush
void doTraceInfoPacket();
void updateContext(TrcStackElemCtxt *pCtxtElem, OcsdTraceElement &elem);
// process atom will create instruction trace, or no memory access trace output elements.
ocsd_err_t processAtom(const ocsd_atm_val atom);
// process an exception element - output instruction trace + exception generic type.
ocsd_err_t processException();
// process Q element
ocsd_err_t processQElement();
// process a source address element
ocsd_err_t processSourceAddress();
// process an element that cannot be cancelled / discarded
ocsd_err_t processTS_CC_EventElem(TrcStackElem *pElem);
// process marker elements
ocsd_err_t processMarkerElem(TrcStackElem *pElem);
// process a transaction element
ocsd_err_t processTransElem(TrcStackElem *pElem);
// process an Instrumentation element
ocsd_err_t processITEElem(TrcStackElem *pElem);
// process a bad packet
ocsd_err_t handleBadPacket(const char *reason, ocsd_trc_index_t index = OCSD_BAD_TRC_INDEX);
// sequencing error on packet processing - optionally continue
ocsd_err_t handlePacketSeqErr(ocsd_err_t err, ocsd_trc_index_t index, const char *reason);
// inconsistent image for decode - optionally reset and continue
ocsd_err_t handleBadImageError(ocsd_trc_index_t index, const char* reason);
// common packet error routine
ocsd_err_t handlePacketErr(ocsd_err_t err, ocsd_err_severity_t sev, ocsd_trc_index_t index, const char *reason, const unsync_info_t unsync_reason);
ocsd_err_t addElemCC(TrcStackElemParam *pParamElem);
ocsd_err_t addElemTS(TrcStackElemParam *pParamElem, bool withCC);
ocsd_err_t addElemEvent(TrcStackElemParam *pParamElem);
private:
void SetInstrInfoInAddrISA(const ocsd_vaddr_t addr_val, const uint8_t isa);
const ocsd_isa calcISA(const bool SF, const uint8_t IS) const
{
if (SF)
return ocsd_isa_aarch64;
return (IS == 0) ? ocsd_isa_arm : ocsd_isa_thumb2;
}
typedef enum {
WP_NOT_FOUND,
WP_FOUND,
WP_NACC
} WP_res_t;
/* Optional run limit for decoded instruction range.
* Throw error if limit exceeded. Set by env var - use for debugging decode runs
* which may be running away due to bad data
*/
int m_num_instr_range_limit;
typedef struct {
ocsd_vaddr_t st_addr;
ocsd_vaddr_t en_addr;
uint32_t num_instr;
} instr_range_t;
ocsd_err_t traceInstrToWP(instr_range_t &instr_range, WP_res_t &WPRes, const bool traceToAddrNext = false, const ocsd_vaddr_t nextAddrMatch = 0);
inline const bool WPFound(WP_res_t res) const { return (res == WP_FOUND); };
inline const bool WPNacc(WP_res_t res) const { return (res == WP_NACC); };
ocsd_err_t returnStackPop(); // pop return stack and update instruction address.
void setElemTraceRange(OcsdTraceElement &elemIn, const instr_range_t &addr_range, const bool executed, ocsd_trc_index_t index);
void setElemTraceRangeInstr(OcsdTraceElement &elemIn, const instr_range_t &addr_range,
const bool executed, ocsd_trc_index_t index, ocsd_instr_info &instr);
// true if we are ETE configured.
inline bool isETEConfig() {
return (m_config->MajVersion() >= ETE_ARCH_VERSION);
}
ocsd_mem_space_acc_t getCurrMemSpace();
//** intra packet state (see ETMv4 spec 6.2.1);
// timestamping
uint64_t m_timestamp; // last broadcast global Timestamp.
bool m_ete_first_ts_marker;
// state and context
uint32_t m_context_id; // most recent context ID
uint32_t m_vmid_id; // most recent VMID
bool m_is_secure; // true if Secure
bool m_is_64bit; // true if 64 bit
uint8_t m_last_IS; // last instruction set value from address packet.
// cycle counts
int m_cc_threshold;
// speculative trace
int m_curr_spec_depth;
int m_max_spec_depth; // nax depth - from ID reg, beyond which auto-commit occurs
int m_unseen_spec_elem; // speculative elements at decode start
#ifdef DATA_TRACE_SUPPORTED
// data trace associative elements (unsupported at present in the decoder).
int m_p0_key;
int m_p0_key_max;
// conditional non-branch trace - when data trace active (unsupported at present in the decoder)
int m_cond_c_key;
int m_cond_r_key;
int m_cond_key_max_incr;
#endif
uint8_t m_CSID;
bool m_IASize64;
//** Other processor state;
// trace decode FSM
typedef enum {
NO_SYNC,
WAIT_SYNC,
WAIT_TINFO,
DECODE_PKTS,
RESOLVE_ELEM,
} processor_state_t;
processor_state_t m_curr_state;
unsync_info_t m_unsync_eot_info;
//** P0 element stack
EtmV4P0Stack m_P0_stack;
// element resolution
struct {
int P0_commit;
int P0_cancel;
bool mispredict;
bool discard;
} m_elem_res;
const bool isElemForRes() const {
return (m_elem_res.P0_commit || m_elem_res.P0_cancel ||
m_elem_res.mispredict || m_elem_res.discard);
}
void clearElemRes() {
m_elem_res.P0_commit = 0;
m_elem_res.P0_cancel = 0;
m_elem_res.mispredict = false;
m_elem_res.discard = false;
}
// packet decode state
bool m_need_ctxt;
bool m_need_addr;
bool m_elem_pending_addr;
ocsd_instr_info m_instr_info;
etmv4_trace_info_t m_trace_info;
bool m_prev_overflow;
TrcAddrReturnStack m_return_stack;
// range address check to look for possible incorrect input code memory images.
struct {
ocsd_vaddr_t next_st_addr; // expected address for next range
bool valid;
} m_next_range_check;
void nextRangeCheckClear() {
m_next_range_check.valid = false;
};
void nextRangeCheckSet(const ocsd_vaddr_t addr) {
m_next_range_check.valid = true;
m_next_range_check.next_st_addr = addr;
};
bool nextRangeCheckOK(const ocsd_vaddr_t addr) {
if (m_next_range_check.valid) {
return (bool)(m_next_range_check.next_st_addr == addr);
}
// no check info - just return OK
return true;
};
// consistency check flags
bool m_direct_br_chk;
bool m_strict_br_chk;
bool m_range_cont_chk;
//** output element handling
OcsdGenElemStack m_out_elem;
OcsdTraceElement &outElem() { return m_out_elem.getCurrElem(); };
};
#endif // ARM_TRC_PKT_DECODE_ETMV4I_H_INCLUDED
/* End of File trc_pkt_decode_etmv4i.h */
OcsdTraceElement
Generic trace element class.
Definition trc_gen_elem.h:50
TrcPktDecodeBase< EtmV4ITrcPacket, EtmV4Config >::m_config
EtmV4Config * m_config
Definition trc_pkt_decode_base.h:214
TrcPktDecodeEtmV4I::mispredictAtom
ocsd_err_t mispredictAtom()
TrcPktDecodeEtmV4I::handleBadPacket
ocsd_err_t handleBadPacket(const char *reason, ocsd_trc_index_t index=OCSD_BAD_TRC_INDEX)
TrcPktDecodeEtmV4I::handlePacketSeqErr
ocsd_err_t handlePacketSeqErr(ocsd_err_t err, ocsd_trc_index_t index, const char *reason)
TrcPktDecodeEtmV4I::handleBadImageError
ocsd_err_t handleBadImageError(ocsd_trc_index_t index, const char *reason)
TrcPktDecodeEtmV4I::P0_commit
int P0_commit
number of elements to commit
Definition trc_pkt_decode_etmv4i.h:225
TrcPktDecodeEtmV4I::TrcPktDecodeEtmV4I
TrcPktDecodeEtmV4I(int instIDNum)
TrcPktDecodeEtmV4I::cancelElements
ocsd_err_t cancelElements()
TrcPktDecodeEtmV4I::handlePacketErr
ocsd_err_t handlePacketErr(ocsd_err_t err, ocsd_err_severity_t sev, ocsd_trc_index_t index, const char *reason, const unsync_info_t unsync_reason)
TrcPktDecodeEtmV4I::initDecoder
void initDecoder()
TrcPktDecodeEtmV4I::commitElemOnEOT
ocsd_err_t commitElemOnEOT()
TrcPktDecodeEtmV4I::processAtom
ocsd_err_t processAtom(const ocsd_atm_val atom)
TrcPktDecodeEtmV4I::onEOT
virtual ocsd_datapath_resp_t onEOT()
TrcPktDecodeEtmV4I::processTransElem
ocsd_err_t processTransElem(TrcStackElem *pElem)
TrcPktDecodeEtmV4I::processTS_CC_EventElem
ocsd_err_t processTS_CC_EventElem(TrcStackElem *pElem)
TrcPktDecodeEtmV4I::addElemCC
ocsd_err_t addElemCC(TrcStackElemParam *pParamElem)
TrcPktDecodeEtmV4I::discardElements
ocsd_err_t discardElements()
TrcPktDecodeEtmV4I::commitElements
ocsd_err_t commitElements()
TrcPktDecodeEtmV4I::processQElement
ocsd_err_t processQElement()
TrcPktDecodeEtmV4I::discard
bool discard
discard elements
Definition trc_pkt_decode_etmv4i.h:228
TrcPktDecodeEtmV4I::getCoreSightTraceID
virtual const uint8_t getCoreSightTraceID()
Definition trc_pkt_decode_etmv4i.h:66
TrcPktDecodeEtmV4I::resetDecoder
void resetDecoder()
TrcPktDecodeEtmV4I::processITEElem
ocsd_err_t processITEElem(TrcStackElem *pElem)
TrcPktDecodeEtmV4I::next_st_addr
ocsd_vaddr_t next_st_addr
Definition trc_pkt_decode_etmv4i.h:259
TrcPktDecodeEtmV4I::mispredict
bool mispredict
mispredict latest atom
Definition trc_pkt_decode_etmv4i.h:227
TrcPktDecodeEtmV4I::onReset
virtual ocsd_datapath_resp_t onReset()
TrcPktDecodeEtmV4I::TrcPktDecodeEtmV4I
TrcPktDecodeEtmV4I()
TrcPktDecodeEtmV4I::valid
bool valid
Definition trc_pkt_decode_etmv4i.h:260
TrcPktDecodeEtmV4I::decodePacket
ocsd_err_t decodePacket()
TrcPktDecodeEtmV4I::resolveElements
ocsd_datapath_resp_t resolveElements()
TrcPktDecodeEtmV4I::doTraceInfoPacket
void doTraceInfoPacket()
TrcPktDecodeEtmV4I::onFlush
virtual ocsd_datapath_resp_t onFlush()
TrcPktDecodeEtmV4I::onProtocolConfig
virtual ocsd_err_t onProtocolConfig()
TrcPktDecodeEtmV4I::onFirstInitOK
virtual void onFirstInitOK()
TrcPktDecodeEtmV4I::processMarkerElem
ocsd_err_t processMarkerElem(TrcStackElem *pElem)
TrcPktDecodeEtmV4I::processSourceAddress
ocsd_err_t processSourceAddress()
TrcPktDecodeEtmV4I::updateContext
void updateContext(TrcStackElemCtxt *pCtxtElem, OcsdTraceElement &elem)
TrcPktDecodeEtmV4I::P0_cancel
int P0_cancel
elements to cancel
Definition trc_pkt_decode_etmv4i.h:226
TrcPktDecodeEtmV4I::addElemTS
ocsd_err_t addElemTS(TrcStackElemParam *pParamElem, bool withCC)
TrcPktDecodeEtmV4I::processException
ocsd_err_t processException()
TrcPktDecodeEtmV4I::addElemEvent
ocsd_err_t addElemEvent(TrcStackElemParam *pParamElem)
TrcPktDecodeEtmV4I::~TrcPktDecodeEtmV4I
virtual ~TrcPktDecodeEtmV4I()
TrcPktDecodeEtmV4I::processPacket
virtual ocsd_datapath_resp_t processPacket()
TrcStackElemCtxt
Definition trc_etmv4_stack_elem.h:182
TrcStackElem
Definition trc_etmv4_stack_elem.h:77
TrcStackElemParam
Definition trc_etmv4_stack_elem.h:294
unsync_info_t
enum _unsync_info_t unsync_info_t
ocsd_trc_index_t
uint32_t ocsd_trc_index_t
Definition ocsd_if_types.h:59
ocsd_datapath_resp_t
enum _ocsd_datapath_resp_t ocsd_datapath_resp_t
OCSD_BAD_TRC_INDEX
#define OCSD_BAD_TRC_INDEX
Definition ocsd_if_types.h:64
ocsd_mem_space_acc_t
enum _ocsd_mem_space_acc_t ocsd_mem_space_acc_t
ocsd_err_severity_t
enum _ocsd_err_severity_t ocsd_err_severity_t
ocsd_instr_info
struct _ocsd_instr_info ocsd_instr_info
ocsd_err_t
enum _ocsd_err_t ocsd_err_t
ocsd_isa
enum _ocsd_isa ocsd_isa
ocsd_vaddr_t
uint64_t ocsd_vaddr_t
Definition ocsd_if_types.h:306
ocsd_isa_arm
@ ocsd_isa_arm
Definition ocsd_if_types.h:324
ocsd_isa_aarch64
@ ocsd_isa_aarch64
Definition ocsd_if_types.h:326
ocsd_isa_thumb2
@ ocsd_isa_thumb2
Definition ocsd_if_types.h:325
TrcPktDecodeBase< EtmV4ITrcPacket, EtmV4Config >::TrcPktDecodeBase
TrcPktDecodeBase(const char *component_name)
Definition trc_pkt_decode_base.h:221
ocsd_atm_val
enum _ocsd_atm_val ocsd_atm_val
ETE_ARCH_VERSION
#define ETE_ARCH_VERSION
Definition trc_pkt_types_etmv4.h:388
etmv4_trace_info_t
union _etmv4_trace_info_t etmv4_trace_info_t
ocsd_gen_elem_stack.h
trc_cmp_cfg_etmv4.h
trc_etmv4_stack_elem.h
trc_gen_elem.h
OpenCSD : Decoder Generic trace element output class.
trc_pkt_decode_base.h
OpenCSD : Trace Packet decoder base class.
trc_pkt_elem_etmv4i.h
trc_ret_stack.h