From owner-svn-src-head@freebsd.org Thu Oct 10 13:30:18 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B2BD9137921; Thu, 10 Oct 2019 13:30:18 +0000 (UTC) (envelope-from br@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46psQf52VFz3yK8; Thu, 10 Oct 2019 13:30:18 +0000 (UTC) (envelope-from br@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 77FB728BB; Thu, 10 Oct 2019 13:30:18 +0000 (UTC) (envelope-from br@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x9ADUIx5018869; Thu, 10 Oct 2019 13:30:18 GMT (envelope-from br@FreeBSD.org) Received: (from br@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x9ADUEFS018844; Thu, 10 Oct 2019 13:30:14 GMT (envelope-from br@FreeBSD.org) Message-Id: <201910101330.x9ADUEFS018844@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: br set sender to br@FreeBSD.org using -f From: Ruslan Bukin Date: Thu, 10 Oct 2019 13:30:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r353393 - in head: contrib/opencsd/decoder/include/common contrib/opencsd/decoder/include/i_dec contrib/opencsd/decoder/include/interfaces contrib/opencsd/decoder/include/mem_acc contri... X-SVN-Group: head X-SVN-Commit-Author: br X-SVN-Commit-Paths: in head: contrib/opencsd/decoder/include/common contrib/opencsd/decoder/include/i_dec contrib/opencsd/decoder/include/interfaces contrib/opencsd/decoder/include/mem_acc contrib/opencsd/decoder/include... X-SVN-Commit-Revision: 353393 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Oct 2019 13:30:18 -0000 Author: br Date: Thu Oct 10 13:30:13 2019 New Revision: 353393 URL: https://svnweb.freebsd.org/changeset/base/353393 Log: Update ARM CoreSight trace decoder library. Its latest version merged from: ^/vendor/opencsd/a1961c91b02a92f3c6ed8b145c636ac4c5565aca Sponsored by: DARPA, AFRL Added: head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_cache.h (contents, props changed) head/contrib/opencsd/decoder/include/opencsd/ocsd_if_version.h (contents, props changed) head/contrib/opencsd/decoder/source/mem_acc/trc_mem_acc_cache.cpp (contents, props changed) Modified: head/contrib/opencsd/decoder/include/common/ocsd_code_follower.h head/contrib/opencsd/decoder/include/common/ocsd_dcd_tree.h head/contrib/opencsd/decoder/include/common/ocsd_error_logger.h head/contrib/opencsd/decoder/include/common/ocsd_msg_logger.h head/contrib/opencsd/decoder/include/common/trc_gen_elem.h head/contrib/opencsd/decoder/include/i_dec/trc_i_decode.h head/contrib/opencsd/decoder/include/i_dec/trc_idec_arminst.h head/contrib/opencsd/decoder/include/interfaces/trc_error_log_i.h head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_base.h head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_bufptr.h head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_cb.h head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_file.h head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_mapper.h head/contrib/opencsd/decoder/include/opencsd/c_api/ocsd_c_api_types.h head/contrib/opencsd/decoder/include/opencsd/c_api/opencsd_c_api.h head/contrib/opencsd/decoder/include/opencsd/etmv4/trc_cmp_cfg_etmv4.h head/contrib/opencsd/decoder/include/opencsd/etmv4/trc_etmv4_stack_elem.h head/contrib/opencsd/decoder/include/opencsd/etmv4/trc_pkt_decode_etmv4i.h head/contrib/opencsd/decoder/include/opencsd/etmv4/trc_pkt_elem_etmv4i.h head/contrib/opencsd/decoder/include/opencsd/etmv4/trc_pkt_types_etmv4.h head/contrib/opencsd/decoder/include/opencsd/ocsd_if_types.h head/contrib/opencsd/decoder/include/opencsd/trc_gen_elem_types.h head/contrib/opencsd/decoder/include/pkt_printers/pkt_printer_t.h head/contrib/opencsd/decoder/source/c_api/ocsd_c_api.cpp head/contrib/opencsd/decoder/source/etmv3/trc_pkt_decode_etmv3.cpp head/contrib/opencsd/decoder/source/etmv4/trc_cmp_cfg_etmv4.cpp head/contrib/opencsd/decoder/source/etmv4/trc_etmv4_stack_elem.cpp head/contrib/opencsd/decoder/source/etmv4/trc_pkt_decode_etmv4i.cpp head/contrib/opencsd/decoder/source/etmv4/trc_pkt_elem_etmv4i.cpp head/contrib/opencsd/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.cpp head/contrib/opencsd/decoder/source/etmv4/trc_pkt_proc_etmv4i_impl.h head/contrib/opencsd/decoder/source/i_dec/trc_i_decode.cpp head/contrib/opencsd/decoder/source/i_dec/trc_idec_arminst.cpp head/contrib/opencsd/decoder/source/mem_acc/trc_mem_acc_bufptr.cpp head/contrib/opencsd/decoder/source/mem_acc/trc_mem_acc_cb.cpp head/contrib/opencsd/decoder/source/mem_acc/trc_mem_acc_file.cpp head/contrib/opencsd/decoder/source/mem_acc/trc_mem_acc_mapper.cpp head/contrib/opencsd/decoder/source/ocsd_code_follower.cpp head/contrib/opencsd/decoder/source/ocsd_dcd_tree.cpp head/contrib/opencsd/decoder/source/ocsd_error.cpp head/contrib/opencsd/decoder/source/ocsd_error_logger.cpp head/contrib/opencsd/decoder/source/ocsd_version.cpp head/contrib/opencsd/decoder/source/ptm/trc_pkt_decode_ptm.cpp head/contrib/opencsd/decoder/source/trc_core_arch_map.cpp head/contrib/opencsd/decoder/source/trc_frame_deformatter.cpp head/contrib/opencsd/decoder/source/trc_gen_elem.cpp head/contrib/opencsd/decoder/source/trc_printable_elem.cpp head/lib/libopencsd/Makefile Modified: head/contrib/opencsd/decoder/include/common/ocsd_code_follower.h ============================================================================== --- head/contrib/opencsd/decoder/include/common/ocsd_code_follower.h Thu Oct 10 13:23:23 2019 (r353392) +++ head/contrib/opencsd/decoder/include/common/ocsd_code_follower.h Thu Oct 10 13:30:13 2019 (r353393) @@ -95,6 +95,7 @@ class OcsdCodeFollower (public) const bool isLink() const; //!< is a link (branch with link etc) const bool ISAChanged() const; //!< next ISA different from input ISA. const ocsd_isa nextISA() const; //!< ISA for next instruction + const uint8_t getInstrSize() const; //!< Get the last instruction size. // information on error conditions const bool isNacc() const; //!< true if Memory Not Accessible (nacc) error occurred @@ -190,6 +191,11 @@ inline const ocsd_instr_type OcsdCodeFollower::getInst inline const ocsd_instr_subtype OcsdCodeFollower::getInstrSubType() const { return m_instr_info.sub_type; +} + +inline const uint8_t OcsdCodeFollower::getInstrSize() const +{ + return m_instr_info.instr_size; } inline const bool OcsdCodeFollower::isCondInstr() const Modified: head/contrib/opencsd/decoder/include/common/ocsd_dcd_tree.h ============================================================================== --- head/contrib/opencsd/decoder/include/common/ocsd_dcd_tree.h Thu Oct 10 13:23:23 2019 (r353392) +++ head/contrib/opencsd/decoder/include/common/ocsd_dcd_tree.h Thu Oct 10 13:30:13 2019 (r353393) @@ -313,7 +313,23 @@ class DecodeTree : public ITrcDataIn (public) */ ocsd_err_t addBinFileRegionMemAcc(const ocsd_file_mem_region_t *region_array, const int num_regions, const ocsd_mem_space_acc_t mem_space, const std::string &filepath); + /*! + * Updates/adds to a memory accessor for a memory block supplied as a one or more memory regions in a binary file. + * Region structures are created that describe the memory start address, the offset within the binary file + * for that address, and the length of the region. This accessor can be used to point to the code section + * in a program file for example. + * + * @param *region_array : array of valid memory regions in the file. + * @param num_regions : number of regions + * @param mem_space : Memory space + * @param &filepath : Path to the binary data file + * + * @return ocsd_err_t : Library error code or OCSD_OK if successful. + */ + ocsd_err_t updateBinFileRegionMemAcc(const ocsd_file_mem_region_t *region_array, const int num_regions, const ocsd_mem_space_acc_t mem_space, const std::string &filepath); + + /*! * This memory accessor allows the client to supply a callback function for the region * defined by the start and end addresses. This can be used to supply a custom memory accessor, * or to directly access memory if the decode is running live on a target system. @@ -327,7 +343,8 @@ class DecodeTree : public ITrcDataIn (public) * @return ocsd_err_t : Library error code or OCSD_OK if successful. */ ocsd_err_t addCallbackMemAcc(const ocsd_vaddr_t st_address, const ocsd_vaddr_t en_address, const ocsd_mem_space_acc_t mem_space, Fn_MemAcc_CB p_cb_func, const void *p_context); - + ocsd_err_t addCallbackIDMemAcc(const ocsd_vaddr_t st_address, const ocsd_vaddr_t en_address, const ocsd_mem_space_acc_t mem_space, Fn_MemAccID_CB p_cb_func, const void *p_context); + /*! * Remove the memory accessor from the map, that begins at the given address, for the memory space provided. * @@ -368,6 +385,9 @@ class DecodeTree : public ITrcDataIn (public) ocsd_err_t createDecodeElement(const uint8_t CSID); void destroyDecodeElement(const uint8_t CSID); void destroyMemAccMapper(); + ocsd_err_t initCallbackMemAcc(const ocsd_vaddr_t st_address, const ocsd_vaddr_t en_address, + const ocsd_mem_space_acc_t mem_space, void *p_cb_func, bool IDfn, const void *p_context); + ocsd_dcd_tree_src_t m_dcd_tree_type; Modified: head/contrib/opencsd/decoder/include/common/ocsd_error_logger.h ============================================================================== --- head/contrib/opencsd/decoder/include/common/ocsd_error_logger.h Thu Oct 10 13:23:23 2019 (r353392) +++ head/contrib/opencsd/decoder/include/common/ocsd_error_logger.h Thu Oct 10 13:30:13 2019 (r353393) @@ -37,7 +37,7 @@ #include #include -#include +//#include #include "interfaces/trc_error_log_i.h" #include "ocsd_error.h" @@ -49,7 +49,7 @@ class ocsdDefaultErrorLogger : public ITraceErrorLog ( ocsdDefaultErrorLogger(); virtual ~ocsdDefaultErrorLogger(); - bool initErrorLogger(const ocsd_err_severity_t verbosity, bool bCreateOutputLogger = false); + bool initErrorLogger(const ocsd_err_severity_t verbosity, bool bCreateOutputLogger = false); //!< Initialise the error logger with a severity filter, optionally create an output logger on stderr. virtual ocsdMsgLogger *getOutputLogger() { return m_output_logger; }; virtual void setOutputLogger(ocsdMsgLogger *pLogger); Modified: head/contrib/opencsd/decoder/include/common/ocsd_msg_logger.h ============================================================================== --- head/contrib/opencsd/decoder/include/common/ocsd_msg_logger.h Thu Oct 10 13:23:23 2019 (r353392) +++ head/contrib/opencsd/decoder/include/common/ocsd_msg_logger.h Thu Oct 10 13:30:13 2019 (r353393) @@ -53,23 +53,26 @@ class ocsdMsgLogger (public) ocsdMsgLogger(); ~ocsdMsgLogger(); + /** Typedef enum providing flags to define the output methods for the message logger. + */ typedef enum { - OUT_NONE = 0, - OUT_FILE = 1, - OUT_STDERR = 2, - OUT_STDOUT = 4, - OUT_STR_CB = 8 /* output to external string callback interface */ + OUT_NONE = 0, /*!< No output from logger*/ + OUT_FILE = 1, /*!< Output to file */ + OUT_STDERR = 2, /*!< Output to stderr */ + OUT_STDOUT = 4, /*!< Output to stdout */ + OUT_STR_CB = 8 /*!< output to external string callback interface */ } output_dest; - void setLogOpts(int logOpts); - const int getLogOpts() const { return m_outFlags; }; + void setLogOpts(int logOpts); //!< set the output logging flags. + const int getLogOpts() const //! get the current output logging flags value. + { return m_outFlags; }; - void setLogFileName(const char *fileName); - void setStrOutFn(ocsdMsgLogStrOutI *p_IstrOut); + void setLogFileName(const char *fileName); //!< Set the output log filename, and enable logging to file. + void setStrOutFn(ocsdMsgLogStrOutI *p_IstrOut); //!< Set the output log string callback and enable logging to callback. - void LogMsg(const std::string &msg); + void LogMsg(const std::string &msg); //!< Log a message to the current set output channels. - const bool isLogging() const; + const bool isLogging() const; //!< true if logging active private: int m_outFlags; Modified: head/contrib/opencsd/decoder/include/common/trc_gen_elem.h ============================================================================== --- head/contrib/opencsd/decoder/include/common/trc_gen_elem.h Thu Oct 10 13:23:23 2019 (r353392) +++ head/contrib/opencsd/decoder/include/common/trc_gen_elem.h Thu Oct 10 13:30:13 2019 (r353393) @@ -73,9 +73,10 @@ class OcsdTraceElement : public trcPrintableElem, publ void setTraceOnReason(const trace_on_reason_t reason); - void setAddrRange(const ocsd_vaddr_t st_addr, const ocsd_vaddr_t en_addr); - void setLastInstrInfo(const bool exec, const ocsd_instr_type last_i_type, const ocsd_instr_subtype last_i_subtype); + void setAddrRange(const ocsd_vaddr_t st_addr, const ocsd_vaddr_t en_addr, const int num_instr = 1); + void setLastInstrInfo(const bool exec, const ocsd_instr_type last_i_type, const ocsd_instr_subtype last_i_subtype, const uint8_t size); void setAddrStart(const ocsd_vaddr_t st_addr) { this->st_addr = st_addr; }; + void setLastInstrCond(const int is_cond) { this->last_instr_cond = is_cond; }; void setSWTInfo(const ocsd_swt_info_t swt_info) { sw_trace_info = swt_info; }; void setExtendedDataPtr(const void *data_ptr); @@ -122,15 +123,17 @@ inline void OcsdTraceElement::setEvent(const event_t e trace_event.ev_number = ev_type == EVENT_NUMBERED ? number : 0; } -inline void OcsdTraceElement::setAddrRange(const ocsd_vaddr_t st_addr, const ocsd_vaddr_t en_addr) +inline void OcsdTraceElement::setAddrRange(const ocsd_vaddr_t st_addr, const ocsd_vaddr_t en_addr, const int num_instr /* = 1 */) { this->st_addr = st_addr; this->en_addr = en_addr; + this->num_instr_range = num_instr; } -inline void OcsdTraceElement::setLastInstrInfo(const bool exec, const ocsd_instr_type last_i_type, const ocsd_instr_subtype last_i_subtype) +inline void OcsdTraceElement::setLastInstrInfo(const bool exec, const ocsd_instr_type last_i_type, const ocsd_instr_subtype last_i_subtype, const uint8_t size) { last_instr_exec = exec ? 1 : 0; + last_instr_sz = size & 0x7; this->last_i_type = last_i_type; this->last_i_subtype = last_i_subtype; } Modified: head/contrib/opencsd/decoder/include/i_dec/trc_i_decode.h ============================================================================== --- head/contrib/opencsd/decoder/include/i_dec/trc_i_decode.h Thu Oct 10 13:23:23 2019 (r353392) +++ head/contrib/opencsd/decoder/include/i_dec/trc_i_decode.h Thu Oct 10 13:30:13 2019 (r353393) @@ -49,6 +49,7 @@ class TrcIDecode : public IInstrDecode (private) ocsd_err_t DecodeA32(ocsd_instr_info *instr_info); ocsd_err_t DecodeA64(ocsd_instr_info *instr_info); ocsd_err_t DecodeT32(ocsd_instr_info *instr_info); + void SetArchVersion(ocsd_instr_info *instr_info); }; #endif // ARM_TRC_I_DECODE_H_INCLUDED Modified: head/contrib/opencsd/decoder/include/i_dec/trc_idec_arminst.h ============================================================================== --- head/contrib/opencsd/decoder/include/i_dec/trc_idec_arminst.h Thu Oct 10 13:23:23 2019 (r353392) +++ head/contrib/opencsd/decoder/include/i_dec/trc_idec_arminst.h Thu Oct 10 13:30:13 2019 (r353393) @@ -73,7 +73,9 @@ Performance event 0x0D counts these. */ int inst_ARM_is_direct_branch(uint32_t inst); int inst_Thumb_is_direct_branch(uint32_t inst); +int inst_Thumb_is_direct_branch_link(uint32_t inst, uint8_t *is_link, uint8_t *is_cond); int inst_A64_is_direct_branch(uint32_t inst); +int inst_A64_is_direct_branch_link(uint32_t inst, uint8_t *is_link); /* Get branch destination for a direct branch. @@ -83,7 +85,9 @@ int inst_Thumb_branch_destination(uint32_t addr, uint3 int inst_A64_branch_destination(uint64_t addr, uint32_t inst, uint64_t *pnpc); int inst_ARM_is_indirect_branch(uint32_t inst); +int inst_Thumb_is_indirect_branch_link(uint32_t inst, uint8_t *is_link); int inst_Thumb_is_indirect_branch(uint32_t inst); +int inst_A64_is_indirect_branch_link(uint32_t inst, uint8_t *is_link); int inst_A64_is_indirect_branch(uint32_t inst); int inst_ARM_is_branch_and_link(uint32_t inst); @@ -109,6 +113,10 @@ arm_barrier_t inst_ARM_barrier(uint32_t inst); arm_barrier_t inst_Thumb_barrier(uint32_t inst); arm_barrier_t inst_A64_barrier(uint32_t inst); +int inst_ARM_wfiwfe(uint32_t inst); +int inst_Thumb_wfiwfe(uint32_t inst); +int inst_A64_wfiwfe(uint32_t inst); + /* Test whether an instruction is definitely undefined, e.g. because allocated to a "permanently UNDEFINED" space (UDF mnemonic). @@ -124,6 +132,9 @@ int inst_A64_is_UDF(uint32_t inst); /* access sub-type information */ ocsd_instr_subtype get_instr_subtype(); void clear_instr_subtype(); + +/* set arch version info. */ +void set_arch_version(uint16_t version); #endif // ARM_TRC_IDEC_ARMINST_H_INCLUDED Modified: head/contrib/opencsd/decoder/include/interfaces/trc_error_log_i.h ============================================================================== --- head/contrib/opencsd/decoder/include/interfaces/trc_error_log_i.h Thu Oct 10 13:23:23 2019 (r353392) +++ head/contrib/opencsd/decoder/include/interfaces/trc_error_log_i.h Thu Oct 10 13:30:13 2019 (r353393) @@ -56,8 +56,8 @@ class ocsdMsgLogger; class ITraceErrorLog { public: - ITraceErrorLog() {}; /**< default constructor */ - virtual ~ITraceErrorLog() {}; /**< default destructor */ + ITraceErrorLog() {}; + virtual ~ITraceErrorLog() {}; /*! * Register a named component error source. Allows the logger to associate errors with components. @@ -111,7 +111,7 @@ class ITraceErrorLog (public) * Get the last error associated with the given Trace source channel ID. * returns a pointer to the error or 0 if no errors associated with the ID. * - * @param chan_id : ID. + * @param chan_id : Trace Source Channel ID (CoreSight Trace ID). * * @return ocsdError *: last error pointer for ID or 0. */ Modified: head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_base.h ============================================================================== --- head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_base.h Thu Oct 10 13:23:23 2019 (r353392) +++ head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_base.h Thu Oct 10 13:30:13 2019 (r353393) @@ -123,12 +123,13 @@ class TrcMemAccessorBase (public) * * @param s_address : Start address of the read. * @param memSpace : memory space for this access. + * @param trcID : Trace ID of trace source. * @param reqBytes : Number of bytes required. * @param *byteBuffer : Buffer to copy the bytes into. * * @return uint32_t : Number of bytes read, 0 if s_address out of range, or mem space not accessible. */ - virtual const uint32_t readBytes(const ocsd_vaddr_t s_address, const ocsd_mem_space_acc_t memSpace, const uint32_t reqBytes, uint8_t *byteBuffer) = 0; + virtual const uint32_t readBytes(const ocsd_vaddr_t s_address, const ocsd_mem_space_acc_t memSpace, const uint8_t trcID, const uint32_t reqBytes, uint8_t *byteBuffer) = 0; /*! * Validate the address range - ensure addresses aligned, different, st < en etc. Modified: head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_bufptr.h ============================================================================== --- head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_bufptr.h Thu Oct 10 13:23:23 2019 (r353392) +++ head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_bufptr.h Thu Oct 10 13:30:13 2019 (r353393) @@ -64,7 +64,7 @@ class TrcMemAccBufPtr: public TrcMemAccessorBase (publ virtual ~TrcMemAccBufPtr() {}; /**< default destructor */ /** Memory access override - allow decoder to read bytes from the buffer. */ - virtual const uint32_t readBytes(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t memSpace, const uint32_t reqBytes, uint8_t *byteBuffer); + virtual const uint32_t readBytes(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t memSpace, const uint8_t trcID, const uint32_t reqBytes, uint8_t *byteBuffer); private: const uint8_t *m_p_buffer; /**< pointer to the memory buffer */ Added: head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_cache.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_cache.h Thu Oct 10 13:30:13 2019 (r353393) @@ -0,0 +1,149 @@ +/*! +* \file trc_mem_acc_cache.h +* \brief OpenCSD : Memory accessor cache. +* +* \copyright Copyright (c) 2018, 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_MEM_ACC_CACHE_H_INCLUDED +#define ARM_TRC_MEM_ACC_CACHE_H_INCLUDED + +#include +#include "opencsd/ocsd_if_types.h" + +#define MEM_ACC_CACHE_PAGE_SIZE 256 +#define MEM_ACC_CACHE_MRU_SIZE 12 + +class TrcMemAccessorBase; +class ITraceErrorLog; + +typedef struct cache_block { + ocsd_vaddr_t st_addr; + uint32_t valid_len; + uint8_t data[MEM_ACC_CACHE_PAGE_SIZE]; +} cache_block_t; + +// enable define to collect stats for debugging / cache performance tests +//#define LOG_CACHE_STATS + + +/** class TrcMemAccCache - cache small amounts of data from accessors to speed up decode. */ +class TrcMemAccCache +{ +public: + TrcMemAccCache(); + ~TrcMemAccCache() {}; + + void enableCaching(bool bEnable) { m_bCacheEnabled = bEnable; }; + void invalidateAll(); + const bool enabled() const { return m_bCacheEnabled; }; + const bool enabled_for_size(const uint32_t reqSize) const + { + return (m_bCacheEnabled && (reqSize <= MEM_ACC_CACHE_PAGE_SIZE)); + } + + + /** read bytes from cache if possible - load new page if needed, bail out if data not available */ + ocsd_err_t readBytesFromCache(TrcMemAccessorBase *p_accessor, const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint8_t trcID, uint32_t *numBytes, uint8_t *byteBuffer); + + void setErrorLog(ITraceErrorLog *log); + void logAndClearCounts(); + +private: + bool blockInCache(const ocsd_vaddr_t address, const uint32_t reqBytes); // run through each page to look for data. + bool blockInPage(const ocsd_vaddr_t address, const uint32_t reqBytes); + void logMsg(const std::string &szMsg); + + cache_block_t m_mru[MEM_ACC_CACHE_MRU_SIZE]; + int m_mru_idx = 0; // in use index + int m_mru_next_new = 0; // next new page at this index. + bool m_bCacheEnabled = false; + +#ifdef LOG_CACHE_STATS + uint32_t m_hits = 0; + uint32_t m_misses = 0; + uint32_t m_pages = 0; + uint32_t m_hit_rl[MEM_ACC_CACHE_MRU_SIZE]; + uint32_t m_hit_rl_max[MEM_ACC_CACHE_MRU_SIZE]; +#endif + + ITraceErrorLog *m_err_log = 0; +}; + +inline TrcMemAccCache::TrcMemAccCache() +{ + for (int i = 0; i < MEM_ACC_CACHE_MRU_SIZE; i++) + { + m_mru[i].st_addr = 0; + m_mru[i].valid_len = 0; +#ifdef LOG_CACHE_STATS + m_hit_rl[i] = 0; + m_hit_rl_max[i] = 0; +#endif + } +} + +inline bool TrcMemAccCache::blockInPage(const ocsd_vaddr_t address, const uint32_t reqBytes) +{ + if ((m_mru[m_mru_idx].st_addr <= address) && + m_mru[m_mru_idx].st_addr + m_mru[m_mru_idx].valid_len >= (address + reqBytes)) + return true; + return false; +} + +inline bool TrcMemAccCache::blockInCache(const ocsd_vaddr_t address, const uint32_t reqBytes) +{ + int tests = MEM_ACC_CACHE_MRU_SIZE; + while (tests) + { + if (blockInPage(address, reqBytes)) + return true; // found address in page + tests--; + m_mru_idx++; + if (m_mru_idx == MEM_ACC_CACHE_MRU_SIZE) + m_mru_idx = 0; + } + return false; +} + +inline void TrcMemAccCache::invalidateAll() +{ + for (int i = 0; i < MEM_ACC_CACHE_MRU_SIZE; i++) + { + m_mru[i].valid_len = 0; + m_mru[i].st_addr = 0; + } + m_mru_idx = 0; + m_mru_next_new = 0; +} + +#endif // ARM_TRC_MEM_ACC_CACHE_H_INCLUDED + +/* End of File trc_mem_acc_cache.h */ Modified: head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_cb.h ============================================================================== --- head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_cb.h Thu Oct 10 13:23:23 2019 (r353392) +++ head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_cb.h Thu Oct 10 13:30:13 2019 (r353393) @@ -49,32 +49,47 @@ class TrcMemAccCB : public TrcMemAccessorBase (public) virtual ~TrcMemAccCB() {}; /** Memory access override - allow decoder to read bytes from the buffer. */ - virtual const uint32_t readBytes(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t memSpace, const uint32_t reqBytes, uint8_t *byteBuffer); + virtual const uint32_t readBytes(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t memSpace, const uint8_t trcID, const uint32_t reqBytes, uint8_t *byteBuffer); void setCBIfClass(TrcMemAccCBIF *p_if); void setCBIfFn(Fn_MemAcc_CB p_fn, const void *p_context); + void setCBIDIfFn(Fn_MemAccID_CB p_fn, const void *p_context); private: + void clearCBptrs(); TrcMemAccCBIF *m_p_CBclass; //m_startAddress < rhs.m_startAddress; }; // not going to use these objects to read bytes - defer to the file class for that. - virtual const uint32_t readBytes(const ocsd_vaddr_t s_address, const ocsd_mem_space_acc_t memSpace, const uint32_t reqBytes, uint8_t *byteBuffer) { return 0; }; + virtual const uint32_t readBytes(const ocsd_vaddr_t s_address, const ocsd_mem_space_acc_t memSpace, const uint8_t trcID, const uint32_t reqBytes, uint8_t *byteBuffer) { return 0; }; const ocsd_vaddr_t regionStartAddress() const { return m_startAddress; }; @@ -77,7 +77,7 @@ class TrcMemAccessorFile : public TrcMemAccessorBase { public: /** read bytes override - reads from file */ - virtual const uint32_t readBytes(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t memSpace, const uint32_t reqBytes, uint8_t *byteBuffer); + virtual const uint32_t readBytes(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t memSpace, const uint8_t trcID, const uint32_t reqBytes, uint8_t *byteBuffer); protected: TrcMemAccessorFile(); /**< protected default constructor */ Modified: head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_mapper.h ============================================================================== --- head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_mapper.h Thu Oct 10 13:23:23 2019 (r353392) +++ head/contrib/opencsd/decoder/include/mem_acc/trc_mem_acc_mapper.h Thu Oct 10 13:30:13 2019 (r353393) @@ -41,6 +41,7 @@ #include "interfaces/trc_tgt_mem_access_i.h" #include "interfaces/trc_error_log_i.h" #include "mem_acc/trc_mem_acc_base.h" +#include "mem_acc/trc_mem_acc_cache.h" typedef enum _memacc_mapper_t { MEMACC_MAP_GLOBAL, @@ -76,7 +77,7 @@ class TrcMemAccMapper : public ITargetMemAccess (publi ocsd_err_t RemoveAccessorByAddress(const ocsd_vaddr_t st_address, const ocsd_mem_space_acc_t mem_space, const uint8_t cs_trace_id = 0); // set the error log. - void setErrorLog(ITraceErrorLog *err_log_i) { m_err_log = err_log_i; }; + void setErrorLog(ITraceErrorLog *err_log_i); // print out the ranges in this mapper. virtual void logMappedRanges() = 0; @@ -89,11 +90,13 @@ class TrcMemAccMapper : public ITargetMemAccess (publi virtual void clearAccessorList() = 0; void LogMessage(const std::string &msg); + void LogWarn(const ocsd_err_t err, const std::string &msg); TrcMemAccessorBase *m_acc_curr; // most recently used - try this first. uint8_t m_trace_id_curr; // trace ID for the current accessor const bool m_using_trace_id; // true if we are using separate memory spaces by TraceID. ITraceErrorLog *m_err_log; // error log to print out mappings on request. + TrcMemAccCache m_cache; // memory accessor caching. }; Modified: head/contrib/opencsd/decoder/include/opencsd/c_api/ocsd_c_api_types.h ============================================================================== --- head/contrib/opencsd/decoder/include/opencsd/c_api/ocsd_c_api_types.h Thu Oct 10 13:23:23 2019 (r353392) +++ head/contrib/opencsd/decoder/include/opencsd/c_api/ocsd_c_api_types.h Thu Oct 10 13:30:13 2019 (r353393) @@ -37,6 +37,7 @@ /* select the library types that are C compatible - the interface data types */ #include "opencsd/ocsd_if_types.h" +#include "opencsd/ocsd_if_version.h" #include "opencsd/trc_gen_elem_types.h" #include "opencsd/trc_pkt_types.h" Modified: head/contrib/opencsd/decoder/include/opencsd/c_api/opencsd_c_api.h ============================================================================== --- head/contrib/opencsd/decoder/include/opencsd/c_api/opencsd_c_api.h Thu Oct 10 13:23:23 2019 (r353392) +++ head/contrib/opencsd/decoder/include/opencsd/c_api/opencsd_c_api.h Thu Oct 10 13:30:13 2019 (r353393) @@ -84,7 +84,7 @@ /** @name Library Version API @{*/ -/** Get Library version. Return a 32 bit version in form MMMMnnpp - MMMM = major verison, nn = minor version, pp = patch version */ +/** Get Library version. Return a 32 bit version in form MMMMnnpp - MMMM = major version, nn = minor version, pp = patch version */ OCSD_C_API uint32_t ocsd_get_version(void); /** Get library version string */ @@ -285,6 +285,23 @@ OCSD_C_API ocsd_err_t ocsd_dt_add_buffer_mem_acc(const * @return OCSD_C_API ocsd_err_t : Library error code - RCDTL_OK if successful. */ OCSD_C_API ocsd_err_t ocsd_dt_add_callback_mem_acc(const dcd_tree_handle_t handle, const ocsd_vaddr_t st_address, const ocsd_vaddr_t en_address, const ocsd_mem_space_acc_t mem_space, Fn_MemAcc_CB p_cb_func, const void *p_context); + + +/*! + * Add a memory access callback function. The decoder will call the function for opcode addresses in the + * address range supplied for the memory spaces covered. + * + * @param handle : Handle to decode tree. + * @param st_address : Start address of memory area covered by the callback. + * @param en_address : End address of the memory area covered by the callback. (inclusive) + * @param mem_space : Memory space(s) covered by the callback. + * @param p_cb_func : Callback function - Signature for CB with Trace ID passed to client. + * @param p_context : opaque context pointer value used in callback function. + * + * @return OCSD_C_API ocsd_err_t : Library error code - RCDTL_OK if successful. + */ +OCSD_C_API ocsd_err_t ocsd_dt_add_callback_trcid_mem_acc(const dcd_tree_handle_t handle, const ocsd_vaddr_t st_address, const ocsd_vaddr_t en_address, const ocsd_mem_space_acc_t mem_space, Fn_MemAccID_CB p_cb_func, const void *p_context); + /*! * Remove a memory accessor by address and memory space. Modified: head/contrib/opencsd/decoder/include/opencsd/etmv4/trc_cmp_cfg_etmv4.h ============================================================================== --- head/contrib/opencsd/decoder/include/opencsd/etmv4/trc_cmp_cfg_etmv4.h Thu Oct 10 13:23:23 2019 (r353392) +++ head/contrib/opencsd/decoder/include/opencsd/etmv4/trc_cmp_cfg_etmv4.h Thu Oct 10 13:30:13 2019 (r353393) @@ -108,6 +108,7 @@ class EtmV4Config : public CSConfig // public ocsd_etm /* idr 1 */ const uint8_t MajVersion() const; const uint8_t MinVersion() const; + const uint8_t FullVersion() const; /* idr 2 */ const uint32_t iaSizeMax() const; @@ -117,6 +118,7 @@ class EtmV4Config : public CSConfig // public ocsd_etm const uint32_t dvSize() const; const uint32_t ccSize() const; const bool vmidOpt() const; + const bool wfiwfeBranch() const; /* id regs 8-13*/ const uint32_t MaxSpecDepth() const; @@ -180,7 +182,11 @@ class EtmV4Config : public CSConfig // public ocsd_etm bool m_condTraceCalc; CondITrace_t m_CondTrace; +protected: ocsd_etmv4_cfg m_cfg; + uint8_t m_MajVer; + uint8_t m_MinVer; + }; /* idr 0 */ @@ -265,14 +271,18 @@ inline const bool EtmV4Config::commitOpt1() const /* idr 1 */ inline const uint8_t EtmV4Config::MajVersion() const { - return (uint8_t)((m_cfg.reg_idr1 >> 8) & 0xF); + return m_MajVer; } inline const uint8_t EtmV4Config::MinVersion() const { - return (uint8_t)((m_cfg.reg_idr1 >> 4) & 0xF); + return m_MinVer; } +inline const uint8_t EtmV4Config::FullVersion() const +{ + return (m_MajVer << 4) | m_MinVer; +} /* idr 2 */ inline const uint32_t EtmV4Config::iaSizeMax() const @@ -319,6 +329,12 @@ inline const bool EtmV4Config::vmidOpt() const { return (bool)((m_cfg.reg_idr2 & 0x20000000) == 0x20000000) && (MinVersion() > 0); } + +inline const bool EtmV4Config::wfiwfeBranch() const +{ + return (bool)((m_cfg.reg_idr2 & 0x80000000) && (FullVersion() >= 0x43)); +} + /* id regs 8-13*/ Modified: head/contrib/opencsd/decoder/include/opencsd/etmv4/trc_etmv4_stack_elem.h ============================================================================== --- head/contrib/opencsd/decoder/include/opencsd/etmv4/trc_etmv4_stack_elem.h Thu Oct 10 13:23:23 2019 (r353392) +++ head/contrib/opencsd/decoder/include/opencsd/etmv4/trc_etmv4_stack_elem.h Thu Oct 10 13:30:13 2019 (r353393) @@ -56,7 +56,8 @@ typedef enum _p0_elem_t P0_TS, P0_CC, P0_TS_CC, - P0_OVERFLOW + P0_OVERFLOW, + P0_FUNC_RET, } p0_elem_t; @@ -250,6 +251,7 @@ class EtmV4P0Stack (public) ~EtmV4P0Stack(); void push_front(TrcStackElem *pElem); + void push_back(TrcStackElem *pElem); // insert element when processing void pop_back(); TrcStackElem *back(); size_t size(); @@ -260,7 +262,7 @@ class EtmV4P0Stack (public) // creation functions - create and push if successful. TrcStackElemParam *createParamElem(const p0_elem_t p0_type, const bool isP0, const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index, const std::vector ¶ms); - TrcStackElemParam *createParamElemNoParam(const p0_elem_t p0_type, const bool isP0, const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index); + TrcStackElem *createParamElemNoParam(const p0_elem_t p0_type, const bool isP0, const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index, bool back = false); TrcStackElemAtom *createAtomElem (const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index, const ocsd_pkt_atom &atom); TrcStackElemExcept *createExceptElem(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index, const bool bSame, const uint16_t excepNum); TrcStackElemCtxt *createContextElem(const ocsd_etmv4_i_pkt_type root_pkt, const ocsd_trc_index_t root_index, const etmv4_context_t &context); @@ -282,6 +284,12 @@ inline EtmV4P0Stack::~EtmV4P0Stack() inline void EtmV4P0Stack::push_front(TrcStackElem *pElem) { m_P0_stack.push_front(pElem); +} + +// put an element on the back of the stack +inline void EtmV4P0Stack::push_back(TrcStackElem *pElem) +{ + m_P0_stack.push_back(pElem); } // pop last element pointer off the stack and stash it for later deletion Modified: head/contrib/opencsd/decoder/include/opencsd/etmv4/trc_pkt_decode_etmv4i.h ============================================================================== --- head/contrib/opencsd/decoder/include/opencsd/etmv4/trc_pkt_decode_etmv4i.h Thu Oct 10 13:23:23 2019 (r353392) +++ head/contrib/opencsd/decoder/include/opencsd/etmv4/trc_pkt_decode_etmv4i.h Thu Oct 10 13:30:13 2019 (r353393) @@ -93,6 +93,8 @@ class TrcPktDecodeEtmV4I : public TrcPktDecodeBase