OpenCSD - CoreSight Trace Decode Library  1.0.0
trc_pkt_decode_etmv4i.h
Go to the documentation of this file.
1 /*
2  * \file trc_pkt_decode_etmv4i.h
3  * \brief OpenCSD : ETMv4 instruction decoder
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 
35 #ifndef ARM_TRC_PKT_DECODE_ETMV4I_H_INCLUDED
36 #define ARM_TRC_PKT_DECODE_ETMV4I_H_INCLUDED
37 
41 #include "common/trc_gen_elem.h"
42 #include "common/trc_ret_stack.h"
45 
46 class TrcStackElem;
47 class TrcStackElemParam;
48 class TrcStackElemCtxt;
49 
50 class TrcPktDecodeEtmV4I : public TrcPktDecodeBase<EtmV4ITrcPacket, EtmV4Config>
51 {
52 public:
54  TrcPktDecodeEtmV4I(int instIDNum);
56 
57 protected:
58  /* implementation packet decoding interface */
64  virtual const uint8_t getCoreSightTraceID() { return m_CSID; };
65 
66  /* local decode methods */
67  void initDecoder(); // initial state on creation (zeros all config)
68  void resetDecoder(); // reset state to start of decode. (moves state, retains config)
69  virtual void onFirstInitOK(); // override to set init related info.
70 
71  ocsd_err_t decodePacket(); // decode packet into trace elements. return true to indicate decode complete - can change FSM to commit state - return is false.
72  ocsd_datapath_resp_t resolveElements(); // commit/cancel trace elements generated from latest / prior packets & send to output - may get wait response, or flag completion.
73  ocsd_err_t commitElements(); // commit elements - process element stack to generate output packets.
75  ocsd_err_t cancelElements(); // cancel elements. These not output
76  ocsd_err_t mispredictAtom(); // mispredict an atom
77  ocsd_err_t discardElements(); // discard elements and flush
78 
81 
82  // process atom will create instruction trace, or no memory access trace output elements.
84 
85  // process an exception element - output instruction trace + exception generic type.
87 
88  // process Q element
90 
91  // process a source address element
93 
94  // process an element that cannot be cancelled / discarded
96 
97  // process marker elements
99 
100  // process a transaction element
102 
103  // process a bad packet
104  ocsd_err_t handleBadPacket(const char *reason);
105 
107  ocsd_err_t addElemTS(TrcStackElemParam *pParamElem, bool withCC);
109 
110 private:
111  void SetInstrInfoInAddrISA(const ocsd_vaddr_t addr_val, const uint8_t isa);
112  const ocsd_isa calcISA(const bool SF, const uint8_t IS) const
113  {
114  if (SF)
115  return ocsd_isa_aarch64;
116  return (IS == 0) ? ocsd_isa_arm : ocsd_isa_thumb2;
117  }
118  typedef enum {
119  WP_NOT_FOUND,
120  WP_FOUND,
121  WP_NACC
122  } WP_res_t;
123 
124  typedef struct {
125  ocsd_vaddr_t st_addr;
126  ocsd_vaddr_t en_addr;
127  uint32_t num_instr;
128  } instr_range_t;
129 
131  ocsd_err_t traceInstrToWP(instr_range_t &instr_range, WP_res_t &WPRes, const bool traceToAddrNext = false, const ocsd_vaddr_t nextAddrMatch = 0);
132 
133  inline const bool WPFound(WP_res_t res) const { return (res == WP_FOUND); };
134  inline const bool WPNacc(WP_res_t res) const { return (res == WP_NACC); };
135 
136  ocsd_err_t returnStackPop(); // pop return stack and update instruction address.
137 
138  void setElemTraceRange(OcsdTraceElement &elemIn, const instr_range_t &addr_range, const bool executed, ocsd_trc_index_t index);
139  void setElemTraceRangeInstr(OcsdTraceElement &elemIn, const instr_range_t &addr_range,
140  const bool executed, ocsd_trc_index_t index, ocsd_instr_info &instr);
141 
142  // true if we are ETE configured.
143  inline bool isETEConfig() {
144  return (m_config->MajVersion() >= ETE_ARCH_VERSION);
145  }
146 
147  ocsd_mem_space_acc_t getCurrMemSpace();
148 
149 //** intra packet state (see ETMv4 spec 6.2.1);
150 
151  // timestamping
152  uint64_t m_timestamp; // last broadcast global Timestamp.
153  bool m_ete_first_ts_marker;
154 
155  // state and context
156  uint32_t m_context_id; // most recent context ID
157  uint32_t m_vmid_id; // most recent VMID
158  bool m_is_secure; // true if Secure
159  bool m_is_64bit; // true if 64 bit
160  uint8_t m_last_IS; // last instruction set value from address packet.
161 
162  // cycle counts
163  int m_cc_threshold;
164 
165  // speculative trace
166  int m_curr_spec_depth;
167  int m_max_spec_depth; // nax depth - from ID reg, beyond which auto-commit occurs
168  int m_unseen_spec_elem; // speculative elements at decode start
169 
171 #ifdef DATA_TRACE_SUPPORTED
172  // data trace associative elements (unsupported at present in the decoder).
173  int m_p0_key;
174  int m_p0_key_max;
175 
176  // conditional non-branch trace - when data trace active (unsupported at present in the decoder)
177  int m_cond_c_key;
178  int m_cond_r_key;
179  int m_cond_key_max_incr;
180 #endif
181 
182  uint8_t m_CSID;
183 
184  bool m_IASize64;
185 
186 //** Other processor state;
187 
188  // trace decode FSM
189  typedef enum {
190  NO_SYNC,
191  WAIT_SYNC,
192  WAIT_TINFO,
193  DECODE_PKTS,
194  RESOLVE_ELEM,
195  } processor_state_t;
196 
197  processor_state_t m_curr_state;
198  unsync_info_t m_unsync_eot_info;
199 
200 //** P0 element stack
201  EtmV4P0Stack m_P0_stack;
202 
203  // element resolution
204  struct {
205  int P0_commit;
206  int P0_cancel;
207  bool mispredict;
208  bool discard;
209  } m_elem_res;
210 
212  const bool isElemForRes() const {
213  return (m_elem_res.P0_commit || m_elem_res.P0_cancel ||
214  m_elem_res.mispredict || m_elem_res.discard);
215  }
216 
217  void clearElemRes() {
218  m_elem_res.P0_commit = 0;
219  m_elem_res.P0_cancel = 0;
220  m_elem_res.mispredict = false;
221  m_elem_res.discard = false;
222  }
223 
224  // packet decode state
225  bool m_need_ctxt;
226  bool m_need_addr;
227  bool m_elem_pending_addr;
228 
229  ocsd_instr_info m_instr_info;
230 
231  etmv4_trace_info_t m_trace_info;
232 
233  bool m_prev_overflow;
234 
235  TrcAddrReturnStack m_return_stack;
236 
237 //** output element handling
238  OcsdGenElemStack m_out_elem;
239  OcsdTraceElement &outElem() { return m_out_elem.getCurrElem(); };
240 };
241 
242 #endif // ARM_TRC_PKT_DECODE_ETMV4I_H_INCLUDED
243 
244 /* End of File trc_pkt_decode_etmv4i.h */
OcsdTraceElement & getCurrElem()
get the current element.
Generic trace element class.
Definition: trc_gen_elem.h:50
ocsd_err_t mispredictAtom()
int P0_commit
number of elements to commit
TrcPktDecodeEtmV4I(int instIDNum)
ocsd_err_t cancelElements()
ocsd_err_t commitElemOnEOT()
ocsd_err_t processAtom(const ocsd_atm_val atom)
virtual ocsd_datapath_resp_t onEOT()
ocsd_err_t processTransElem(TrcStackElem *pElem)
ocsd_err_t processTS_CC_EventElem(TrcStackElem *pElem)
ocsd_err_t addElemCC(TrcStackElemParam *pParamElem)
ocsd_err_t discardElements()
ocsd_err_t commitElements()
ocsd_err_t processQElement()
bool discard
discard elements
virtual const uint8_t getCoreSightTraceID()
bool mispredict
mispredict latest atom
ocsd_err_t handleBadPacket(const char *reason)
virtual ocsd_datapath_resp_t onReset()
ocsd_err_t decodePacket()
ocsd_datapath_resp_t resolveElements()
virtual ocsd_datapath_resp_t onFlush()
virtual ocsd_err_t onProtocolConfig()
virtual void onFirstInitOK()
ocsd_err_t processMarkerElem(TrcStackElem *pElem)
ocsd_err_t processSourceAddress()
void updateContext(TrcStackElemCtxt *pCtxtElem, OcsdTraceElement &elem)
int P0_cancel
elements to cancel
ocsd_err_t addElemTS(TrcStackElemParam *pParamElem, bool withCC)
ocsd_err_t processException()
ocsd_err_t addElemEvent(TrcStackElemParam *pParamElem)
virtual ~TrcPktDecodeEtmV4I()
virtual ocsd_datapath_resp_t processPacket()
enum _unsync_info_t unsync_info_t
uint32_t ocsd_trc_index_t
Definition: ocsd_if_types.h:67
enum _ocsd_datapath_resp_t ocsd_datapath_resp_t
enum _ocsd_mem_space_acc_t ocsd_mem_space_acc_t
enum _ocsd_err_t ocsd_err_t
enum _ocsd_isa ocsd_isa
uint64_t ocsd_vaddr_t
@ ocsd_isa_arm
@ ocsd_isa_aarch64
@ ocsd_isa_thumb2
const uint8_t MajVersion() const
enum _ocsd_atm_val ocsd_atm_val
#define ETE_ARCH_VERSION
OpenCSD : Decoder Generic trace element output class.
OpenCSD : Trace Packet decoder base class.