OcsdLibDcdRegister: class to manage the registration and access of named decoders in the library. Creates list of decoder managers
IDecoderMngr: Abstract interface to allow creation, interconnection and clean-up of protocol / type specific macros.
DecoderMngrBase: templated base class to implement generic version of the IDecoderMngr functionality. Type specific decoder managers specialise this with only default constructors/desctructors required making adding new decoder into the mechanism very easy
Signed-off-by: Mike Leach mike.leach@linaro.org --- .../ref_trace_decode_lib.vcxproj | 10 + .../ref_trace_decode_lib.vcxproj.filters | 30 ++ decoder/include/common/ocsd_dcd_mngr.h | 362 +++++++++++++++++++++ decoder/include/common/ocsd_dcd_mngr_i.h | 92 ++++++ decoder/include/common/ocsd_lib_dcd_register.h | 117 +++++++ decoder/include/etmv3/trc_dcd_mngr_etmv3.h | 56 ++++ decoder/include/etmv4/trc_dcd_mngr_etmv4i.h | 30 ++ decoder/include/ocsd_if_types.h | 52 ++- decoder/include/ptm/trc_dcd_mngr_ptm.h | 56 ++++ decoder/include/stm/trc_dcd_mngr_stm.h | 54 +++ decoder/source/ocsd_lib_dcd_register.cpp | 147 +++++++++ 11 files changed, 993 insertions(+), 13 deletions(-) create mode 100644 decoder/include/common/ocsd_dcd_mngr.h create mode 100644 decoder/include/common/ocsd_dcd_mngr_i.h create mode 100644 decoder/include/common/ocsd_lib_dcd_register.h create mode 100644 decoder/include/etmv3/trc_dcd_mngr_etmv3.h create mode 100644 decoder/include/etmv4/trc_dcd_mngr_etmv4i.h create mode 100644 decoder/include/ptm/trc_dcd_mngr_ptm.h create mode 100644 decoder/include/stm/trc_dcd_mngr_stm.h create mode 100644 decoder/source/ocsd_lib_dcd_register.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 929df5a..fa1a912 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 @@ -305,16 +305,20 @@ <ClInclude Include="..\..\..\include\common\comp_attach_notifier_i.h" /> <ClInclude Include="..\..\..\include\common\comp_attach_pt_t.h" /> <ClInclude Include="..\..\..\include\common\ocsd_code_follower.h" /> + <ClInclude Include="..\..\..\include\common\ocsd_dcd_mngr.h" /> + <ClInclude Include="..\..\..\include\common\ocsd_dcd_mngr_i.h" /> <ClInclude Include="..\..\..\include\common\ocsd_dcd_tree.h" /> <ClInclude Include="..\..\..\include\common\ocsd_dcd_tree_elem.h" /> <ClInclude Include="..\..\..\include\common\ocsd_error.h" /> <ClInclude Include="..\..\..\include\common\ocsd_error_logger.h" /> <ClInclude Include="..\..\..\include\common\ocsd_gen_elem_list.h" /> + <ClInclude Include="..\..\..\include\common\ocsd_lib_dcd_register.h" /> <ClInclude Include="..\..\..\include\common\ocsd_msg_logger.h" /> <ClInclude Include="..\..\..\include\common\ocsd_pe_context.h" /> <ClInclude Include="..\..\..\include\common\ocsd_version.h" /> <ClInclude Include="..\..\..\include\common\trc_component.h" /> <ClInclude Include="..\..\..\include\common\trc_core_arch_map.h" /> + <ClInclude Include="..\..\..\include\common\trc_cs_config.h" /> <ClInclude Include="..\..\..\include\common\trc_frame_deformatter.h" /> <ClInclude Include="..\..\..\include\common\trc_gen_elem.h" /> <ClInclude Include="..\..\..\include\common\trc_pkt_decode_base.h" /> @@ -322,17 +326,20 @@ <ClInclude Include="..\..\..\include\common\trc_printable_elem.h" /> <ClInclude Include="..\..\..\include\etmv3\etmv3_decoder.h" /> <ClInclude Include="..\..\..\include\etmv3\trc_cmp_cfg_etmv3.h" /> + <ClInclude Include="..\..\..\include\etmv3\trc_dcd_mngr_etmv3.h" /> <ClInclude Include="..\..\..\include\etmv3\trc_pkt_decode_etmv3.h" /> <ClInclude Include="..\..\..\include\etmv3\trc_pkt_elem_etmv3.h" /> <ClInclude Include="..\..\..\include\etmv3\trc_pkt_proc_etmv3.h" /> <ClInclude Include="..\..\..\include\etmv3\trc_pkt_types_etmv3.h" /> <ClInclude Include="..\..\..\include\etmv4\etmv4_decoder.h" /> <ClInclude Include="..\..\..\include\etmv4\trc_cmp_cfg_etmv4.h" /> + <ClInclude Include="..\..\..\include\etmv4\trc_dcd_mngr_etmv4i.h" /> <ClInclude Include="..\..\..\include\etmv4\trc_pkt_decode_etmv4i.h" /> <ClInclude Include="..\..\..\include\etmv4\trc_pkt_elem_etmv4d.h" /> <ClInclude Include="..\..\..\include\etmv4\trc_pkt_elem_etmv4i.h" /> <ClInclude Include="..\..\..\include\etmv4\trc_pkt_proc_etmv4.h" /> <ClInclude Include="..\..\..\include\etmv4\trc_pkt_types_etmv4.h" /> + <ClInclude Include="..\..\..\include\interfaces\trc_abs_typed_base_i.h" /> <ClInclude Include="..\..\..\include\interfaces\trc_data_rawframe_in_i.h" /> <ClInclude Include="..\..\..\include\interfaces\trc_data_raw_in_i.h" /> <ClInclude Include="..\..\..\include\interfaces\trc_error_log_i.h" /> @@ -356,12 +363,14 @@ <ClInclude Include="..\..\..\include\opencsd.h" /> <ClInclude Include="..\..\..\include\ptm\ptm_decoder.h" /> <ClInclude Include="..\..\..\include\ptm\trc_cmp_cfg_ptm.h" /> + <ClInclude Include="..\..\..\include\ptm\trc_dcd_mngr_ptm.h" /> <ClInclude Include="..\..\..\include\ptm\trc_pkt_decode_ptm.h" /> <ClInclude Include="..\..\..\include\ptm\trc_pkt_elem_ptm.h" /> <ClInclude Include="..\..\..\include\ptm\trc_pkt_proc_ptm.h" /> <ClInclude Include="..\..\..\include\ptm\trc_pkt_types_ptm.h" /> <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_elem_stm.h" /> <ClInclude Include="..\..\..\include\stm\trc_pkt_proc_stm.h" /> <ClInclude Include="..\..\..\include\stm\trc_pkt_types_stm.h" /> @@ -397,6 +406,7 @@ <ClCompile Include="..\..\..\source\ocsd_error.cpp" /> <ClCompile Include="..\..\..\source\ocsd_error_logger.cpp" /> <ClCompile Include="..\..\..\source\ocsd_gen_elem_list.cpp" /> + <ClCompile Include="..\..\..\source\ocsd_lib_dcd_register.cpp" /> <ClCompile Include="..\..\..\source\ocsd_msg_logger.cpp" /> <ClCompile Include="..\..\..\source\ocsd_version.cpp" /> <ClCompile Include="..\..\..\source\ptm\trc_cmp_cfg_ptm.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 efb3183..d267c31 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 @@ -290,6 +290,33 @@ <ClInclude Include="..\..\..\include\common\ocsd_gen_elem_list.h"> <Filter>Header Files\common</Filter> </ClInclude> + <ClInclude Include="..\..\..\include\common\trc_cs_config.h"> + <Filter>Header Files\common</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\common\ocsd_dcd_mngr.h"> + <Filter>Header Files\common</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\common\ocsd_dcd_mngr_i.h"> + <Filter>Header Files\common</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\common\ocsd_lib_dcd_register.h"> + <Filter>Header Files\common</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\interfaces\trc_abs_typed_base_i.h"> + <Filter>interfaces</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\etmv4\trc_dcd_mngr_etmv4i.h"> + <Filter>Header Files\etmv4</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\etmv3\trc_dcd_mngr_etmv3.h"> + <Filter>Source Files\etmv3</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\ptm\trc_dcd_mngr_ptm.h"> + <Filter>Header Files\ptm</Filter> + </ClInclude> + <ClInclude Include="..\..\..\include\stm\trc_dcd_mngr_stm.h"> + <Filter>Header Files\stm</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="..\..\..\source\trc_component.cpp"> @@ -400,5 +427,8 @@ <ClCompile Include="..\..\..\source\ocsd_gen_elem_list.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="..\..\..\source\ocsd_lib_dcd_register.cpp"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> </Project> \ No newline at end of file diff --git a/decoder/include/common/ocsd_dcd_mngr.h b/decoder/include/common/ocsd_dcd_mngr.h new file mode 100644 index 0000000..3b58e60 --- /dev/null +++ b/decoder/include/common/ocsd_dcd_mngr.h @@ -0,0 +1,362 @@ +/* + * \file ocsd_dcd_mngr.h + * \brief OpenCSD : Decoder manager base class. + * + * \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_OCSD_DCD_MNGR_H_INCLUDED +#define ARM_OCSD_DCD_MNGR_H_INCLUDED + +#include "ocsd_if_types.h" +#include "common/ocsd_dcd_mngr_i.h" +#include "common/ocsd_lib_dcd_register.h" +#include "common/trc_pkt_decode_base.h" + + +template <class P, class Pt, class Pc> +class DecoderMngrBase : public IDecoderMngr +{ +public: + DecoderMngrBase(const std::string &decoderTypeName); + virtual ~DecoderMngrBase() {}; + + // create decoder interface. + virtual ocsd_err_t createDecoder(const int create_flags, const int instID, const CSConfig *p_config, TraceComponent **p_component); + virtual ocsd_err_t destroyDecoder(TraceComponent *p_component); + +// common + virtual ocsd_err_t attachErrorLogger(TraceComponent *pComponent, ITraceErrorLog *pIErrorLog); + +// pkt decoder + virtual ocsd_err_t attachInstrDecoder(TraceComponent *pComponent, IInstrDecode *pIInstrDec); + virtual ocsd_err_t attachMemAccessor(TraceComponent *pComponent, ITargetMemAccess *pMemAccessor); + virtual ocsd_err_t attachOutputSink(TraceComponent *pComponent, ITrcGenElemIn *pOutSink); + +// pkt processor + virtual ocsd_err_t attachPktMonitor(TraceComponent *pComponent, ITrcTypedBase *pPktRawDataMon); + virtual ocsd_err_t attachPktIndexer(TraceComponent *pComponent, ITrcTypedBase *pPktIndexer); + virtual ocsd_err_t attachPktSink(TraceComponent *pComponent, ITrcTypedBase *pPktDataInSink); + +// data input connection interface + virtual ocsd_err_t getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn); + +// implemented by decoder handler derived classes + virtual TraceComponent *createPktProc(const bool useInstID, const int instID) = 0; + virtual TraceComponent *createPktDecode(const bool useInstID, const int instID) { return 0; }; +}; + +template <class P, class Pt, class Pc> +DecoderMngrBase<P,Pt,Pc>::DecoderMngrBase(const std::string &decoderTypeName) +{ + OcsdLibDcdRegister *pDcdReg = OcsdLibDcdRegister::getDecoderRegister(); + if(pDcdReg) + pDcdReg->registerDecoderTypeByName(decoderTypeName,this); +} + + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::createDecoder(const int create_flags, const int instID, const CSConfig *pConfig, TraceComponent **ppTrcComp) +{ + ocsd_err_t err = OCSD_OK; + TraceComponent *pkt_proc = 0; + TraceComponent *pkt_dcd = 0; + bool bUseInstID = (create_flags & OCSD_CREATE_FLG_INST_ID) != 0; + bool bDecoder = (create_flags & OCSD_CREATE_FLG_FULL_DECODER) != 0; + bool bUnConfigured = (pConfig == 0); + + const Pc *pConf = dynamic_cast< const Pc * >(pConfig); + + // check inputs valid... + if((pConf == 0) && !bUnConfigured) + return OCSD_ERR_INVALID_PARAM_TYPE; + + if((create_flags & (OCSD_CREATE_FLG_PACKET_PROC | OCSD_CREATE_FLG_FULL_DECODER)) == 0) + return OCSD_ERR_INVALID_PARAM_VAL; + + // always need a packet processor + pkt_proc = createPktProc(bUseInstID, instID); + if(!pkt_proc) + return OCSD_ERR_MEM; + + // set the configuration + TrcPktProcBase<P,Pt,Pc> *pProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> *>(pkt_proc); + if(pProcBase == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + if(!bUnConfigured) + pProcBase->setProtocolConfig(pConf); + + *ppTrcComp = pkt_proc; + + // may need a packet decoder + if(bDecoder) + { + // create the decoder + pkt_dcd = createPktDecode(bUseInstID, instID); + if(!pkt_dcd) + return OCSD_ERR_MEM; + + // get the decoder base + TrcPktDecodeBase<P,Pc> *pBase = dynamic_cast< TrcPktDecodeBase<P,Pc> *>(pkt_dcd); + if(pBase == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + if(!bUnConfigured) + pBase->setProtocolConfig(pConf); + + // associate decoder with packet processor + // -> this means a TraceComponent with an associated component is a packet decoder. + // the associated component is the connected packet processor. + pkt_dcd->setAssocComponent(pkt_proc); + + // connect packet processor and decoder + pProcBase->getPacketOutAttachPt()->attach(pBase); + + *ppTrcComp = pkt_dcd; + } + return OCSD_OK; +} + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::destroyDecoder(TraceComponent *pComponent) +{ + if(pComponent->getAssocComponent() != 0) + delete pComponent->getAssocComponent(); + delete pComponent; + return OCSD_OK; +} + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachErrorLogger(TraceComponent *pComponent, ITraceErrorLog *pIErrorLog) +{ + return pComponent->getErrorLogAttachPt()->replace_first(pIErrorLog); +} + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachInstrDecoder(TraceComponent *pComponent, IInstrDecode *pIInstrDec) +{ + ocsd_err_t err = OCSD_ERR_DCD_INTERFACE_UNUSED; + + if(pComponent->getAssocComponent() == 0) // no associated component - so this is a packet processor + return OCSD_ERR_INVALID_PARAM_TYPE; + + TrcPktDecodeI *pDcdI = dynamic_cast< TrcPktDecodeI * >(pComponent); + if(pDcdI == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + if(pDcdI->getUsesIDecode()) + err = pDcdI->getInstrDecodeAttachPt()->replace_first(pIInstrDec); + + return err; +} + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachMemAccessor(TraceComponent *pComponent, ITargetMemAccess *pMemAccessor) +{ + ocsd_err_t err = OCSD_ERR_DCD_INTERFACE_UNUSED; + + if(pComponent->getAssocComponent() == 0) // no associated component - so this is a packet processor + return OCSD_ERR_INVALID_PARAM_TYPE; + + TrcPktDecodeI *pDcdI = dynamic_cast< TrcPktDecodeI * >(pComponent); + if(pDcdI == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + if(pDcdI->getUsesMemAccess()) + err = pDcdI->getMemoryAccessAttachPt()->replace_first(pMemAccessor); + + return err; +} + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachOutputSink(TraceComponent *pComponent, ITrcGenElemIn *pOutSink) +{ + ocsd_err_t err = OCSD_ERR_INVALID_PARAM_TYPE; + + if(pComponent->getAssocComponent() == 0) // no associated component - so this is a packet processor + return err; + + TrcPktDecodeI *pDcdI = dynamic_cast< TrcPktDecodeI * >(pComponent); + if(pDcdI == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + err = pDcdI->getTraceElemOutAttachPt()->replace_first(pOutSink); + + return err; +} + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn) +{ + // find the packet processor + TraceComponent *pPktProc = pComponent; + if(pComponent->getAssocComponent() != 0) + pPktProc = pComponent->getAssocComponent(); + + TrcPktProcI *pPPI = dynamic_cast< TrcPktProcI * >(pPktProc); + if(pPPI == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + *ppDataIn = pPPI; + + return OCSD_OK; +} + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachPktMonitor(TraceComponent *pComponent, ITrcTypedBase *pPktRawDataMon) +{ + // find the packet processor + TraceComponent *pPktProc = pComponent; + if(pComponent->getAssocComponent() != 0) + pPktProc = pComponent->getAssocComponent(); + + // get the packet processor + TrcPktProcBase<P,Pt,Pc> *pPktProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> * >(pPktProc); + if(pPktProcBase == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + // get the interface + IPktRawDataMon<P> *p_If = dynamic_cast< IPktRawDataMon<P> * >(pPktRawDataMon); + if(p_If == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + return pPktProcBase->getRawPacketMonAttachPt()->replace_first(p_If); +} + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachPktIndexer(TraceComponent *pComponent, ITrcTypedBase *pPktIndexer) +{ + // find the packet processor + TraceComponent *pPktProc = pComponent; + if(pComponent->getAssocComponent() != 0) + pPktProc = pComponent->getAssocComponent(); + + // get the packet processor + TrcPktProcBase<P,Pt,Pc> *pPktProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> * >(pPktProc); + if(pPktProcBase == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + // get the interface + ITrcPktIndexer<Pt> *p_If = dynamic_cast< ITrcPktIndexer<Pt> * >(pPktIndexer); + if(p_If == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + return pPktProcBase->getTraceIDIndexerAttachPt()->replace_first(p_If); +} + +template <class P, class Pt, class Pc> +ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachPktSink(TraceComponent *pComponent, ITrcTypedBase *pPktDataInSink) +{ + // must be solo packet processor + if(pComponent->getAssocComponent() != 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + // interface must be the correct one. + IPktDataIn<P> *pkt_in_i = dynamic_cast< IPktDataIn<P> * >(pPktDataInSink); + if(pkt_in_i == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + // get the packet processor + TrcPktProcBase<P,Pt,Pc> *pPktProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> * >(pComponent); + if(pPktProcBase == 0) + return OCSD_ERR_INVALID_PARAM_TYPE; + + // attach + return pPktProcBase->getPacketOutAttachPt()->replace_first(pkt_in_i); +} + + +/****************************************************************************************************/ +/* Full decoder / packet process pair, templated base for creating decoder objects */ +/****************************************************************************************************/ + +template< class P, // Packet class. + class Pt, // Packet enum type ID. + class Pc, // Processor config class. + class PktProc, // Packet processor class. + class PktDcd> // Packet decoder class. +class DecodeMngrFullDcd : public DecoderMngrBase<P,Pt,Pc> +{ +public: + DecodeMngrFullDcd (const std::string &name) : DecoderMngrBase(name) {}; + virtual ~DecodeMngrFullDcd() {}; + + virtual TraceComponent *createPktProc(const bool useInstID, const int instID) + { + TraceComponent *pComp; + if(useInstID) + pComp = new (std::nothrow) PktProc(instID); + else + pComp = new (std::nothrow) PktProc(); + return pComp; + } + + virtual TraceComponent *createPktDecode(const bool useInstID, const int instID) + { + TraceComponent *pComp; + if(useInstID) + pComp = new (std::nothrow)PktDcd(instID); + else + pComp = new (std::nothrow)PktDcd(); + return pComp; + } +}; + +/****************************************************************************************************/ +/* Packet processor only, templated base for creating decoder objects */ +/****************************************************************************************************/ + +template< class P, // Packet class. + class Pt, // Packet enum type ID. + class Pc, // Processor config class. + class PktProc> // Packet processor class. +class DecodeMngrPktProc : public DecoderMngrBase<P,Pt,Pc> +{ +public: + DecodeMngrPktProc (const std::string &name) : DecoderMngrBase(name) {}; + virtual ~DecodeMngrPktProc() {}; + + virtual TraceComponent *createPktProc(const bool useInstID, const int instID) + { + TraceComponent *pComp; + if(useInstID) + pComp = new (std::nothrow) PktProc(instID); + else + pComp = new (std::nothrow) PktProc(); + return pComp; + } +}; + + + +#endif // ARM_OCSD_DCD_MNGR_H_INCLUDED + +/* End of File ocsd_dcd_mngr.h */ diff --git a/decoder/include/common/ocsd_dcd_mngr_i.h b/decoder/include/common/ocsd_dcd_mngr_i.h new file mode 100644 index 0000000..f7a6720 --- /dev/null +++ b/decoder/include/common/ocsd_dcd_mngr_i.h @@ -0,0 +1,92 @@ +/* + * \file ocsd_dcd_mngr_i.h + * \brief OpenCSD : Decoder manager interface. + * + * \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_OCSD_DCD_MNGR_I_H_INCLUDED +#define ARM_OCSD_DCD_MNGR_I_H_INCLUDED + +#include "ocsd_if_types.h" +#include "common/trc_cs_config.h" +#include "common/trc_component.h" + +#include "interfaces/trc_error_log_i.h" +#include "interfaces/trc_data_raw_in_i.h" +#include "interfaces/trc_instr_decode_i.h" +#include "interfaces/trc_tgt_mem_access_i.h" +#include "interfaces/trc_gen_elem_in_i.h" +#include "interfaces/trc_abs_typed_base_i.h" + +class IDecoderMngr +{ +public: + IDecoderMngr() {}; + virtual ~IDecoderMngr() {}; + +// create and destroy decoders + virtual ocsd_err_t createDecoder(const int create_flags, const int instID, const CSConfig *p_config, TraceComponent **ppComponent) = 0; + virtual ocsd_err_t destroyDecoder(TraceComponent *pComponent) = 0; + +// connect decoders to other components - (replace current / 0 pointer value to detach ); +// compatible with all decoders + //!attach error logger to ptk-processor, or both of pkt processor and pkt decoder pair + virtual ocsd_err_t attachErrorLogger(TraceComponent *pComponent, ITraceErrorLog *pIErrorLog) = 0; + +// pkt decoder only + //! attach instruction decoder to pkt decoder + virtual ocsd_err_t attachInstrDecoder(TraceComponent *pComponent, IInstrDecode *pIInstrDec) = 0; + + //! attach memory accessor to pkt decoder + virtual ocsd_err_t attachMemAccessor(TraceComponent *pComponent, ITargetMemAccess *pMemAccessor) = 0; + + //! attach generic output interface to pkt decoder + virtual ocsd_err_t attachOutputSink(TraceComponent *pComponent, ITrcGenElemIn *pOutSink) = 0; + +// pkt processor only + //! attach a raw packet monitor to pkt processor (solo pkt processor, or pkt processor part of pair) + virtual ocsd_err_t attachPktMonitor(TraceComponent *pComponent, ITrcTypedBase *pPktRawDataMon) = 0; + + //! attach a packet indexer to pkt processor (solo pkt processor, or pkt processor part of pair) + virtual ocsd_err_t attachPktIndexer(TraceComponent *pComponent, ITrcTypedBase *pPktIndexer) = 0; + + //! attach a packet data sink to pkt processor output (solo pkt processor only - instead of decoder when pkt processor only created.) + virtual ocsd_err_t attachPktSink(TraceComponent *pComponent, ITrcTypedBase *pPktDataInSink) = 0; + +// data input connection interface + //! get raw data input interface from packet processor + virtual ocsd_err_t getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn) = 0; + +}; + +#endif // ARM_OCSD_DCD_MNGR_I_H_INCLUDED + +/* End of File ocsd_dcd_mngr.h */ \ No newline at end of file diff --git a/decoder/include/common/ocsd_lib_dcd_register.h b/decoder/include/common/ocsd_lib_dcd_register.h new file mode 100644 index 0000000..dc5fd42 --- /dev/null +++ b/decoder/include/common/ocsd_lib_dcd_register.h @@ -0,0 +1,117 @@ +/* + * \file ocsd_lib_dcd_register.h + * \brief OpenCSD : Library decoder registration and management. + * + * \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved. + */ + +#ifndef ARM_OCSD_LIB_DCD_REGISTER_H_INCLUDED +#define ARM_OCSD_LIB_DCD_REGISTER_H_INCLUDED + + +/* + * 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 <map> + +#include "ocsd_if_types.h" +#include "common/ocsd_dcd_mngr_i.h" + +/*! + * @class OcsdLibDcdRegister : Registers decoders with the library + * + * library decoder register class allows decoders to be registered by name, and the register allows clients to access + * the list of names of registerd decoders. + * + * The decoders in the library are accessed through the decoder manager interface. This provides a set of functions to allow + * the creation, manipulation and destruction of registered decoders + * + */ +class OcsdLibDcdRegister +{ +public: + static OcsdLibDcdRegister *getDecoderRegister(); + + static void deregisterAllDecoders(); //!< library cleanup - deregisters decoder managers and destroys the register object. + + const ocsd_err_t registerDecoderTypeByName(const std::string &name, IDecoderMngr *p_decoder_fact); //!< register a decoder manager interface + const ocsd_err_t getDecoderMngrByName(const std::string &name, IDecoderMngr **p_decoder_mngr); + + const bool isRegisteredDecoder(const std::string &name); + const bool getFirstNamedDecoder(std::string &name); + const bool getNextNamedDecoder(std::string &name); + +private: + void registerBuiltInDecoders(); //!< register the list of build in decoder managers on first access of getDecoderMngrByName. + + std::map<const std::string, IDecoderMngr *> m_decoder_mngrs; //!< map linking names to decoder manager interfaces. + std::map<const std::string, IDecoderMngr *>::const_iterator m_iter; //!< iterator for name search. + + // singleton pattern - need just one of these in the library - ensure all default constructors are private. + OcsdLibDcdRegister(); + OcsdLibDcdRegister(OcsdLibDcdRegister const &) {}; + OcsdLibDcdRegister& operator=(OcsdLibDcdRegister const &){}; + ~OcsdLibDcdRegister(); + + static OcsdLibDcdRegister *m_p_libMngr; + static bool m_b_registeredBuiltins; +}; + +/*! + * Typedef of function signature to create a decoder manager. + * + * @param *name : Registered name of the decoder. + */ +typedef IDecoderMngr *(*CreateMngr)(const std::string &name); + +/*! + * Template function to create a specific decoder manager class object. + * + * @param &name : Registered name of the decoder. + * + * @return IDecoderMngr * : pointer to the decoder manager base class interface. + */ +template <typename T> IDecoderMngr *createManagerInst(const std::string &name) +{ + return new (std::nothrow)T(name); +} + +/*! Structure to contain the information needed to create and register a builtin decoder + * manager with the library + */ +typedef struct built_in_decoder_info { + IDecoderMngr *pMngr; //!< pointer to created decoder manager + CreateMngr PFn; //!< function to create the decoder manager. + const char *name; //!< registered name of the decoder. +} built_in_decoder_info_t; + +//! Define to use to fill in an array of built_in_decoder_info_t structures. +#define CREATE_BUILTIN_ENTRY(C,N) { 0, createManagerInst<C>, N } + +#endif // ARM_OCSD_LIB_DCD_REGISTER_H_INCLUDED + +/* End of File ocsd_lib_dcd_register.h */ diff --git a/decoder/include/etmv3/trc_dcd_mngr_etmv3.h b/decoder/include/etmv3/trc_dcd_mngr_etmv3.h new file mode 100644 index 0000000..cbd1182 --- /dev/null +++ b/decoder/include/etmv3/trc_dcd_mngr_etmv3.h @@ -0,0 +1,56 @@ +/* + * \file trc_dcd_mngr_etmv3.h + * \brief OpenCSD : ETMv3 decoder manager / handler specialisation + * + * \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_DCD_MNGR_ETMV3_H_INCLUDED +#define ARM_TRC_DCD_MNGR_ETMV3_H_INCLUDED + +#include "common/ocsd_dcd_mngr.h" +#include "trc_pkt_decode_etmv3.h" +#include "trc_pkt_proc_etmv3.h" +#include "trc_cmp_cfg_etmv3.h" +#include "trc_pkt_types_etmv3.h" + +class DecoderMngrEtmV3 : public DecodeMngrFullDcd< EtmV3TrcPacket, + ocsd_etmv3_pkt_type, + EtmV3Config, + TrcPktProcEtmV3, + TrcPktDecodeEtmV3> +{ +public: + DecoderMngrEtmV3(const std::string &name) : DecodeMngrFullDcd(name) {}; + virtual ~DecoderMngrEtmV3() {}; +}; + +#endif // ARM_TRC_DCD_MNGR_ETMV3_H_INCLUDED + +/* End of File trc_dcd_mngr_etmv3.h */ diff --git a/decoder/include/etmv4/trc_dcd_mngr_etmv4i.h b/decoder/include/etmv4/trc_dcd_mngr_etmv4i.h new file mode 100644 index 0000000..3aef842 --- /dev/null +++ b/decoder/include/etmv4/trc_dcd_mngr_etmv4i.h @@ -0,0 +1,30 @@ +/* + * \file trc_dcd_mngr_etmv4i.h + * \brief Reference CoreSight Trace Decoder : + * + * \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved. + */ + +#ifndef ARM_TRC_DCD_MNGR_ETMV4I_H_INCLUDED +#define ARM_TRC_DCD_MNGR_ETMV4I_H_INCLUDED + +#include "common/ocsd_dcd_mngr.h" +#include "trc_pkt_decode_etmv4i.h" +#include "trc_pkt_proc_etmv4.h" +#include "trc_cmp_cfg_etmv4.h" +#include "trc_pkt_types_etmv4.h" + +class DecoderMngrEtmV4I : public DecodeMngrFullDcd< EtmV4ITrcPacket, + ocsd_etmv4_i_pkt_type, + EtmV4Config, + TrcPktProcEtmV4I, + TrcPktDecodeEtmV4I> +{ +public: + DecoderMngrEtmV4I(const std::string &name) : DecodeMngrFullDcd(name) {}; + virtual ~DecoderMngrEtmV4I() {}; +}; + +#endif // ARM_TRC_DCD_MNGR_ETMV4I_H_INCLUDED + +/* End of File trc_dcd_mngr_etmv4i.h */ diff --git a/decoder/include/ocsd_if_types.h b/decoder/include/ocsd_if_types.h index 4fb428d..d214f76 100644 --- a/decoder/include/ocsd_if_types.h +++ b/decoder/include/ocsd_if_types.h @@ -86,6 +86,7 @@ typedef enum _ocsd_err_t { OCSD_ERR_INVALID_ID, /**< Invalid CoreSight Trace Source ID. */ OCSD_ERR_BAD_HANDLE, /**< Invalid handle passed to component. */ OCSD_ERR_INVALID_PARAM_VAL, /**< Invalid value parameter passed to component. */ + OCSD_ERR_INVALID_PARAM_TYPE, /**< Type mismatch on abstract interface */ OCSD_ERR_FILE_ERROR, /**< File access error */ OCSD_ERR_NO_PROTOCOL, /**< Trace protocol unsupported */ /* attachment point errors */ @@ -123,6 +124,11 @@ typedef enum _ocsd_err_t { OCSD_ERR_TEST_SNAPSHOT_PARSE_INFO, /**< test snapshot file parse information */ OCSD_ERR_TEST_SNAPSHOT_READ, /**< test snapshot reader error */ OCSD_ERR_TEST_SS_TO_DECODER, /**< test snapshot to decode tree conversion error */ + /* decoder registration */ + OCSD_ERR_DCDREG_NAME_REPEAT, /**< attempted to register a decoder with the same name as another one */ + OCSD_ERR_DCDREG_NAME_UNKNOWN, /**< attempted to find a decoder with a name that is not known in the library */ + /* decoder config */ + OCSD_ERR_DCD_INTERFACE_UNUSED, /**< Attempt to connect or use and inteface not supported by this decoder. */ /* end marker*/ OCSD_ERR_LAST } ocsd_err_t; @@ -202,19 +208,6 @@ typedef enum _ocsd_datapath_resp_t { /** @name Trace Decode component types @{*/
-/*! Trace Protocol Types - used to create appropriate decoder. - */ -typedef enum _ocsd_trace_protocol_t { - OCSD_PROTOCOL_EXTERN, /**< Custom external decoder attached to the decode tree - protocol unknown */ - OCSD_PROTOCOL_ETMV3, /**< ETMV3 instruction and data trace protocol decoder. */ - OCSD_PROTOCOL_ETMV4I, /**< ETMV4 instruction trace protocol decoder. */ - OCSD_PROTOCOL_ETMV4D, /**< ETMV4 data trace protocol decoder. */ - OCSD_PROTOCOL_PTM, /**< PTM program flow instruction trace protocol decoder. */ - OCSD_PROTOCOL_STM, /**< STM system trace protocol decoder. */ - /* others to be added here */ - OCSD_PROTOCOL_END /**< Invalid protocol - protocol types end marker */ -} ocsd_trace_protocol_t; -
/** Raw frame element data types Data blocks types output from ITrcRawFrameIn. @@ -474,6 +467,39 @@ typedef uint32_t (* Fn_MemAcc_CB)(const void *p_context, const ocsd_vaddr_t add
/** @}*/
+/** @name Decoder creation information + + Flags to use when creating decoders by name + + Builtin decoder names. + + Protocol type enum +@{*/ + +#define OCSD_CREATE_FLG_PACKET_PROC 0x01 /**< Create packet processor only. */ +#define OCSD_CREATE_FLG_FULL_DECODER 0x02 /**< Create packet processor + decoder pair */ +#define OCSD_CREATE_FLG_INST_ID 0x04 /**< Use instance ID in decoder instance name */ + +#define OCSD_BUILTIN_DCD_STM "STM" /**< STM decoder */ +#define OCSD_BUILTIN_DCD_ETMV3 "ETMV3" /**< ETMv3 decoder */ +#define OCSD_BUILTIN_DCD_ETMV4I "ETMV4I" /**< ETMv4 instruction decoder */ +#define OCSD_BUILTIN_DCD_ETMV4D "ETMV4D" /**< ETMv4 data decoder */ +#define OCSD_BUILTIN_DCD_PTM "PTM" /**< PTM decoder */ + +/*! Trace Protocol Builtin Types + extern + */ +typedef enum _ocsd_trace_protocol_t { + OCSD_PROTOCOL_EXTERN, /**< Custom external decoder attached to the decode tree - protocol unknown */ + OCSD_PROTOCOL_ETMV3, /**< ETMV3 instruction and data trace protocol decoder. */ + OCSD_PROTOCOL_ETMV4I, /**< ETMV4 instruction trace protocol decoder. */ + OCSD_PROTOCOL_ETMV4D, /**< ETMV4 data trace protocol decoder. */ + OCSD_PROTOCOL_PTM, /**< PTM program flow instruction trace protocol decoder. */ + OCSD_PROTOCOL_STM, /**< STM system trace protocol decoder. */ + /* others to be added here */ + OCSD_PROTOCOL_END /**< Invalid protocol - protocol types end marker */ +} ocsd_trace_protocol_t; + +/** @}*/
/** @}*/ #endif // ARM_OCSD_IF_TYPES_H_INCLUDED diff --git a/decoder/include/ptm/trc_dcd_mngr_ptm.h b/decoder/include/ptm/trc_dcd_mngr_ptm.h new file mode 100644 index 0000000..27fb270 --- /dev/null +++ b/decoder/include/ptm/trc_dcd_mngr_ptm.h @@ -0,0 +1,56 @@ +/* + * \file trc_dcd_mngr_ptm.h + * \brief OpenCSD : PTM decoder manager / handler specialisation + * + * \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_DCD_MNGR_PTM_H_INCLUDED +#define ARM_TRC_DCD_MNGR_PTM_H_INCLUDED + +#include "common/ocsd_dcd_mngr.h" +#include "trc_pkt_decode_ptm.h" +#include "trc_pkt_proc_ptm.h" +#include "trc_cmp_cfg_ptm.h" +#include "trc_pkt_types_ptm.h" + +class DecoderMngrPtm : public DecodeMngrFullDcd< PtmTrcPacket, + ocsd_ptm_pkt_type, + PtmConfig, + TrcPktProcPtm, + TrcPktDecodePtm> +{ +public: + DecoderMngrPtm(const std::string &name) : DecodeMngrFullDcd(name) {}; + virtual ~DecoderMngrPtm() {}; +}; + +#endif // ARM_TRC_DCD_MNGR_PTM_H_INCLUDED + +/* End of File trc_dcd_mngr_ptm.h */ diff --git a/decoder/include/stm/trc_dcd_mngr_stm.h b/decoder/include/stm/trc_dcd_mngr_stm.h new file mode 100644 index 0000000..356ed72 --- /dev/null +++ b/decoder/include/stm/trc_dcd_mngr_stm.h @@ -0,0 +1,54 @@ +/* + * \file trc_dcd_mngr_stm.h + * \brief OpenCSD : STM decoder manager / handler specialisation + * + * \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_DCD_MNGR_STM_H_INCLUDED +#define ARM_TRC_DCD_MNGR_STM_H_INCLUDED + +#include "common/ocsd_dcd_mngr.h" +#include "trc_pkt_proc_stm.h" +#include "trc_cmp_cfg_stm.h" +#include "trc_pkt_types_stm.h" + +class DecoderMngrStm : public DecodeMngrPktProc< StmTrcPacket, + ocsd_stm_pkt_type, + STMConfig, + TrcPktProcStm> +{ +public: + DecoderMngrStm(const std::string &name) : DecodeMngrPktProc(name) {}; + virtual ~DecoderMngrStm() {}; +}; + +#endif // ARM_TRC_DCD_MNGR_STM_H_INCLUDED + +/* End of File trc_dcd_mngr_stm.h */ diff --git a/decoder/source/ocsd_lib_dcd_register.cpp b/decoder/source/ocsd_lib_dcd_register.cpp new file mode 100644 index 0000000..053f256 --- /dev/null +++ b/decoder/source/ocsd_lib_dcd_register.cpp @@ -0,0 +1,147 @@ +/* + * \file ocsd_lib_dcd_register.cpp + * \brief OpenCSD : Library decoder register object + * + * \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 "common/ocsd_lib_dcd_register.h" + +// include built-in decode manager headers +#include "etmv4/trc_dcd_mngr_etmv4i.h" +#include "etmv3/trc_dcd_mngr_etmv3.h" +#include "ptm/trc_dcd_mngr_ptm.h" +#include "stm/trc_dcd_mngr_stm.h" + +// create array of built-in decoders to register with library +static built_in_decoder_info_t sBuiltInArray[] = { + CREATE_BUILTIN_ENTRY(DecoderMngrEtmV4I,OCSD_BUILTIN_DCD_ETMV4I), + CREATE_BUILTIN_ENTRY(DecoderMngrEtmV3, OCSD_BUILTIN_DCD_ETMV3), + CREATE_BUILTIN_ENTRY(DecoderMngrPtm, OCSD_BUILTIN_DCD_PTM), + CREATE_BUILTIN_ENTRY(DecoderMngrStm, OCSD_BUILTIN_DCD_STM) + //{ 0, 0, 0} +}; + +#define NUM_BUILTINS sizeof(sBuiltInArray) / sizeof(built_in_decoder_info_t) + + +OcsdLibDcdRegister *OcsdLibDcdRegister::m_p_libMngr = 0; +bool OcsdLibDcdRegister::m_b_registeredBuiltins = false; + +OcsdLibDcdRegister *OcsdLibDcdRegister::getDecoderRegister() +{ + if(m_p_libMngr == 0) + m_p_libMngr = new (std::nothrow) OcsdLibDcdRegister(); + return m_p_libMngr; +} + +OcsdLibDcdRegister::OcsdLibDcdRegister() +{ + m_iter = m_decoder_mngrs.begin(); +} + +OcsdLibDcdRegister::~OcsdLibDcdRegister() +{ + m_decoder_mngrs.clear(); +} + + +const ocsd_err_t OcsdLibDcdRegister::registerDecoderTypeByName(const std::string &name, IDecoderMngr *p_decoder_fact) +{ + if(isRegisteredDecoder(name)) + return OCSD_ERR_DCDREG_NAME_REPEAT; + m_decoder_mngrs.emplace(std::pair<const std::string, IDecoderMngr *>(name,p_decoder_fact)); + return OCSD_OK; +} + +void OcsdLibDcdRegister::registerBuiltInDecoders() +{ + bool memFail = false; + for(int i = 0; i < NUM_BUILTINS; i++) + { + if(sBuiltInArray[i].PFn) + { + sBuiltInArray[i].pMngr = sBuiltInArray[i].PFn( sBuiltInArray[i].name); + if(!sBuiltInArray[i].pMngr) + memFail=true; + } + } + m_b_registeredBuiltins = !memFail; +} + +void OcsdLibDcdRegister::deregisterAllDecoders() +{ + for(int i = 0; i < NUM_BUILTINS; i++) + delete sBuiltInArray[i].pMngr; + m_b_registeredBuiltins = false; + delete m_p_libMngr; + m_p_libMngr = 0; +} + +const ocsd_err_t OcsdLibDcdRegister::getDecoderMngrByName(const std::string &name, IDecoderMngr **p_decoder_mngr) +{ + if(!m_b_registeredBuiltins) + { + registerBuiltInDecoders(); + if(!m_b_registeredBuiltins) + return OCSD_ERR_MEM; + } + + std::map<const std::string, IDecoderMngr *>::const_iterator iter = m_decoder_mngrs.find(name); + if(iter == m_decoder_mngrs.end()) + return OCSD_ERR_DCDREG_NAME_UNKNOWN; + *p_decoder_mngr = iter->second; + return OCSD_OK; +} + +const bool OcsdLibDcdRegister::isRegisteredDecoder(const std::string &name) +{ + std::map<const std::string, IDecoderMngr *>::const_iterator iter = m_decoder_mngrs.find(name); + if(iter != m_decoder_mngrs.end()) + return true; + return false; +} + +const bool OcsdLibDcdRegister::getFirstNamedDecoder(std::string &name) +{ + m_iter = m_decoder_mngrs.begin(); + return getNextNamedDecoder(name); +} + +const bool OcsdLibDcdRegister::getNextNamedDecoder(std::string &name) +{ + if(m_iter == m_decoder_mngrs.end()) + return false; + name = m_iter->first; + m_iter++; + return true; +} + +/* End of File ocsd_lib_dcd_register.cpp */