Adds in STM packet decoder initial types and decoder object. Decoder will output generic SW trace packets as Master + Chan + payload + timestamp.
Signed-off-by: Mike Leach mike.leach@linaro.org --- .../ref_trace_decode_lib.vcxproj | 2 + .../ref_trace_decode_lib.vcxproj.filters | 6 ++ decoder/include/common/trc_gen_elem.h | 4 +- decoder/include/ocsd_if_types.h | 41 +++++++- decoder/include/stm/trc_pkt_decode_stm.h | 95 ++++++++++++++++++ decoder/include/trc_gen_elem_types.h | 17 ++-- decoder/source/stm/trc_pkt_decode_stm.cpp | 111 +++++++++++++++++++++ 7 files changed, 266 insertions(+), 10 deletions(-) create mode 100644 decoder/include/stm/trc_pkt_decode_stm.h create mode 100644 decoder/source/stm/trc_pkt_decode_stm.cpp
diff --git a/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj b/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj index 1b68ed7..09133ce 100644 --- a/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj +++ b/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj @@ -373,6 +373,7 @@ <ClInclude Include="..\..\..\include\stm\stm_decoder.h" /> <ClInclude Include="..\..\..\include\stm\trc_cmp_cfg_stm.h" /> <ClInclude Include="..\..\..\include\stm\trc_dcd_mngr_stm.h" /> + <ClInclude Include="..\..\..\include\stm\trc_pkt_decode_stm.h" /> <ClInclude Include="..\..\..\include\stm\trc_pkt_elem_stm.h" /> <ClInclude Include="..\..\..\include\stm\trc_pkt_proc_stm.h" /> <ClInclude Include="..\..\..\include\stm\trc_pkt_types_stm.h" /> @@ -415,6 +416,7 @@ <ClCompile Include="..\..\..\source\ptm\trc_pkt_decode_ptm.cpp" /> <ClCompile Include="..\..\..\source\ptm\trc_pkt_elem_ptm.cpp" /> <ClCompile Include="..\..\..\source\ptm\trc_pkt_proc_ptm.cpp" /> + <ClCompile Include="..\..\..\source\stm\trc_pkt_decode_stm.cpp" /> <ClCompile Include="..\..\..\source\stm\trc_pkt_elem_stm.cpp" /> <ClCompile Include="..\..\..\source\stm\trc_pkt_proc_stm.cpp" /> <ClCompile Include="..\..\..\source\trc_component.cpp" /> diff --git a/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters b/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters index bbd98f2..11acc41 100644 --- a/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters +++ b/decoder/build/win/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters @@ -323,6 +323,9 @@ <ClInclude Include="..\..\..\include\common\trc_pkt_elem_base.h"> <Filter>Header Files\common</Filter> </ClInclude> + <ClInclude Include="..\..\..\include\stm\trc_pkt_decode_stm.h"> + <Filter>Header Files\stm</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="..\..\..\source\trc_component.cpp"> @@ -436,5 +439,8 @@ <ClCompile Include="..\..\..\source\ocsd_lib_dcd_register.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="..\..\..\source\stm\trc_pkt_decode_stm.cpp"> + <Filter>Source Files\stm</Filter> + </ClCompile> </ItemGroup> </Project> \ No newline at end of file diff --git a/decoder/include/common/trc_gen_elem.h b/decoder/include/common/trc_gen_elem.h index c9c5299..97c3a45 100644 --- a/decoder/include/common/trc_gen_elem.h +++ b/decoder/include/common/trc_gen_elem.h @@ -77,7 +77,9 @@ public: void setLastInstrInfo(const bool exec, const ocsd_instr_type last_i_type, const ocsd_instr_subtype last_i_subtype); void setAddrStart(const ocsd_vaddr_t st_addr) { this->st_addr = st_addr; };
- + void setSWTMaster(const uint16_t master_id) { sw_trace_info.swt_master_id = master_id; }; + void setSWTChannel(const uint16_t chan_id) { sw_trace_info.swt_channel_id = chan_id; }; + void setSWTErrPkt(const bool m_err = false);
// stringize the element
diff --git a/decoder/include/ocsd_if_types.h b/decoder/include/ocsd_if_types.h index b28382b..13fce2e 100644 --- a/decoder/include/ocsd_if_types.h +++ b/decoder/include/ocsd_if_types.h @@ -285,7 +285,8 @@ typedef enum _ocsd_dcd_tree_src_t { typedef enum _ocsd_arch_version { ARCH_UNKNOWN, /**< unknown architecture */ ARCH_V7, /**< V7 architecture */ - ARCH_V8 /**< V8 architecture */ + ARCH_V8, /**< V8 architecture */ + ARCH_CUSTOM, /**< None ARM, custom architecture */ } ocsd_arch_version_t;
/** Core Profile */ @@ -293,7 +294,8 @@ typedef enum _ocsd_core_profile { profile_Unknown, /**< Unknown profile */ profile_CortexM, /**< Cortex-M profile */ profile_CortexR, /**< Cortex-R profile */ - profile_CortexA /**< Cortex-A profile */ + profile_CortexA, /**< Cortex-A profile */ + profile_Custom, /**< None ARM, custom arch profile */ } ocsd_core_profile_t;
/** Combined architecture and profile descriptor for a core */ @@ -331,6 +333,7 @@ typedef enum _ocsd_isa ocsd_isa_aarch64, /**< V8 AArch64 */ ocsd_isa_tee, /**< Thumb EE - unsupported */ ocsd_isa_jazelle, /**< Jazelle - unsupported in trace */ + ocsd_isa_custom, /**< Instruction set - custom arch decoder */ ocsd_isa_unknown /**< ISA not yet known */ } ocsd_isa;
@@ -503,7 +506,7 @@ typedef struct _ocsd_file_mem_region {
Builtin decoder names.
- Protocol type enum + Protocol type enum. @{*/
#define OCSD_CREATE_FLG_PACKET_PROC 0x01 /**< Create packet processor only. */ @@ -554,6 +557,38 @@ typedef enum _ocsd_trace_protocol_t {
/** @}*/
+ +/** @name Software Trace Packets Info + + Contains the information for the generic software trace output packet. + + Software trace packet master and channel data. + Payload info: + size - packet payload size in bits; + marker - if this packet has a marker/flag + timestamp - if this packet has a timestamp associated + number of packets - packet processor can optionally correlate identically + sized packets on the same master / channel to be output as a single generic packet + + Payload output as separate LE buffer, of sufficient bytes to hold all the packets. +@{*/ + +typedef struct _ocsd_swt_info { + uint16_t swt_master_id; + uint16_t swt_channel_id; + struct { + uint32_t swt_payload_pkt_bitsize:8; /**< Packet size in bits of the payload packets */ + uint32_t swt_payload_num_packets:8; /**< number of consecutive packets of this type in the payload data */ + uint32_t swt_marker_packet:1; /**< packet is marker / flag packet */ + uint32_t swt_has_timestamp:1; /**< packet has timestamp. */ + uint32_t swt_marker_first:1; /**< for multiple packet payloads, this indicates if any marker is on first or last packet */ + uint32_t swt_master_err:1; /**< current master has error */ + uint32_t swt_global_err:1; /**< global error */ + }; +} ocsd_swt_info_t; + +/** @}*/ + /** @}*/ #endif // ARM_OCSD_IF_TYPES_H_INCLUDED
diff --git a/decoder/include/stm/trc_pkt_decode_stm.h b/decoder/include/stm/trc_pkt_decode_stm.h new file mode 100644 index 0000000..eb113ce --- /dev/null +++ b/decoder/include/stm/trc_pkt_decode_stm.h @@ -0,0 +1,95 @@ +/* + * \file trc_pkt_decode_stm.h + * \brief OpenCSD : STM packet decoder + * + * Convert the incoming indidvidual STM packets to + * + * \copyright Copyright (c) 2016, 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_STM_H_INCLUDED +#define ARM_TRC_PKT_DECODE_STM_H_INCLUDED + + +#include "common/trc_pkt_decode_base.h" +#include "stm/trc_pkt_elem_stm.h" +#include "stm/trc_cmp_cfg_stm.h" +#include "common/trc_gen_elem.h" + +class TrcPktDecodeStm : public TrcPktDecodeBase<StmTrcPacket, STMConfig> +{ +public: + TrcPktDecodeStm(); + TrcPktDecodeStm(int instIDNum); + virtual ~TrcPktDecodeStm(); + +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 */ + +private: + void initDecoder(); + void resetDecoder(); + void initPayloadBuffer(); + + typedef enum { + NO_SYNC, //!< pre start trace - init state or after reset or overflow, loss of sync. + WAIT_SYNC, //!< waiting for sync packet. + DECODE_PKTS, //!< processing input packet + } processor_state_t; + + processor_state_t m_curr_state; + + uint8_t m_curr_master; //!< current active master ID + uint16_t m_curr_channel; //!< current active channel ID + + uint8_t *m_payload_buffer; //!< payload buffer - allocated for one of multiple packets according to config + int m_payload_used; //!< payload used in bytes + int m_payload_size; //!< payload size in bytes + bool m_payload_odd_nibble; //!< last used byte in payload contains a single 4 bit packet. + + uint8_t m_CSID; //!< Coresight trace ID for this decoder. + +//** output element + OcsdTraceElement m_output_elem; //!< output packet +}; + +#endif // ARM_TRC_PKT_DECODE_STM_H_INCLUDED + +/* End of File trc_pkt_decode_stm.h */ diff --git a/decoder/include/trc_gen_elem_types.h b/decoder/include/trc_gen_elem_types.h index 66d8d79..22ed7dc 100644 --- a/decoder/include/trc_gen_elem_types.h +++ b/decoder/include/trc_gen_elem_types.h @@ -58,7 +58,9 @@ typedef enum _ocsd_gen_trc_elem_t OCSD_GEN_TRC_ELEM_EXCEPTION_RET, /*!< expection return */ OCSD_GEN_TRC_ELEM_TIMESTAMP, /*!< Timestamp - preceding elements happeded before this time. */ OCSD_GEN_TRC_ELEM_CYCLE_COUNT, /*!< Cycle count - cycles since last cycle count value - associated with a preceding instruction range. */ - OCSD_GEN_TRC_ELEM_EVENT, /*!< Event - trigger, (TBC - perhaps have a set of event types - cut down additional processing?) */ + OCSD_GEN_TRC_ELEM_EVENT, /*!< Event - trigger, (TBC - perhaps have a set of event types - cut down additional processing?) */ + OCSD_GEN_TRC_ELEM_SWTRACE, /*!< Software trace packet - may contain data payload. */ + OCSD_GEN_TRC_ELEM_CUSTOM, /*!< Fully custom packet type - used by none-ARM architecture decoders */ } ocsd_gen_trc_elem_t;
@@ -73,15 +75,14 @@ typedef struct _trace_event_t { uint16_t ev_number; /**< event number if numbered event type */ } trace_event_t;
- typedef struct _ocsd_generic_trace_elem { ocsd_gen_trc_elem_t elem_type; /**< Element type - remaining data interpreted according to this value */ ocsd_isa isa; /**< instruction set for executed instructions */ ocsd_vaddr_t st_addr; /**< start address for instruction execution range / inaccessible code address / data address */ ocsd_vaddr_t en_addr; /**< end address (exclusive) for instruction execution range. */ ocsd_pe_context context; /**< PE Context */ - uint64_t timestamp; /**< timestamp value for TS element type */ - uint32_t cycle_count; /**< cycle count for explicit cycle count element, or count for element with associated cycle count */ + uint64_t timestamp; /**< timestamp value for TS element type */ + uint32_t cycle_count; /**< cycle count for explicit cycle count element, or count for element with associated cycle count */ ocsd_instr_type last_i_type; /**< Last instruction type if instruction execution range */ ocsd_instr_subtype last_i_subtype; /**< sub type for last instruction in range */
@@ -92,15 +93,19 @@ typedef struct _ocsd_generic_trace_elem { uint32_t cpu_freq_change:1; /**< 1 if this packet indicates a change in CPU frequency */ uint32_t excep_ret_addr:1; /**< 1 if en_addr is the preferred exception return address on exception packet type */ uint32_t excep_data_marker:1; /**< 1 if the exception entry packet is a data push marker only, with no address information (used typically in v7M trace for marking data pushed onto stack) */ + uint32_t extended_data:1; /**< 1 if the packet extended data pointer is valid. Allows packet extensions for custom decoders, or additional data payloads for data trace. */ + uint32_t has_ts:1; /**< 1 if the packet has an associated timestamp - e.g. SW/STM trace TS+Payload as a single packet */ };
//! packet specific payloads union { - uint32_t exception_number; /**< exception number for exception type packets */ - trace_event_t trace_event; /**< Trace event - trigger etc */ + uint32_t exception_number; /**< exception number for exception type packets */ + trace_event_t trace_event; /**< Trace event - trigger etc */ trace_on_reason_t trace_on_reason; /**< reason for the trace on packet */ + ocsd_swt_info_t sw_trace_info; /**< software trace packet info */ };
+ void *ptr_extended_data; /**< pointer to extended data buffer (data trace, sw trace payload) / custom structure */
} ocsd_generic_trace_elem;
diff --git a/decoder/source/stm/trc_pkt_decode_stm.cpp b/decoder/source/stm/trc_pkt_decode_stm.cpp new file mode 100644 index 0000000..9185b6c --- /dev/null +++ b/decoder/source/stm/trc_pkt_decode_stm.cpp @@ -0,0 +1,111 @@ +/* + * \file trc_pkt_decode_stm.cpp + * \brief OpenCSD : + * + * \copyright Copyright (c) 2016, 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. + */ + +#include "stm/trc_pkt_decode_stm.h" +#define DCD_NAME "DCD_STM" + +TrcPktDecodeStm::TrcPktDecodeStm() + : TrcPktDecodeBase(DCD_NAME) +{ + initDecoder(); +} + +TrcPktDecodeStm::TrcPktDecodeStm(int instIDNum) + : TrcPktDecodeBase(DCD_NAME, instIDNum) +{ + initDecoder(); +} + +TrcPktDecodeStm::~TrcPktDecodeStm() +{ + if(m_payload_buffer) + delete [] m_payload_buffer; + m_payload_buffer = 0; +} + +/* implementation packet decoding interface */ +ocsd_datapath_resp_t TrcPktDecodeStm::processPacket() +{ +} + +ocsd_datapath_resp_t TrcPktDecodeStm::onEOT() +{ +} + +ocsd_datapath_resp_t TrcPktDecodeStm::onReset() +{ +} + +ocsd_datapath_resp_t TrcPktDecodeStm::onFlush() +{ +} + +ocsd_err_t TrcPktDecodeStm::onProtocolConfig() +{ + if(m_config == 0) + return OCSD_ERR_NOT_INIT; + + // static config - copy of CSID for easy reference + m_CSID = m_config->getTraceID(); + return OCSD_OK; +} + +void TrcPktDecodeStm::initDecoder() +{ + m_payload_buffer = 0; + m_payload_used = 0; + resetDecoder(); +} + +void TrcPktDecodeStm::resetDecoder() +{ + m_curr_state = NO_SYNC; + m_curr_master = 0; + m_curr_channel = 0; + m_payload_size = 0; + m_payload_odd_nibble = false; + m_CSID = 0; + m_output_elem.init(); +} + +void TrcPktDecodeStm::initPayloadBuffer() +{ + // set up the payload buffer. If we are correlating indentical packets then + // need a buffer that is a multiple of 64bit packets. + // otherwise a single packet length will do. + + +} + +/* End of File trc_pkt_decode_stm.cpp */