2 * \file ocsd_c_api_cust_impl.h
3 * \brief OpenCSD : Custom decoder implementation common API definitions
5 * \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved.
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
19 * 3. Neither the name of the copyright holder nor the names of its contributors
20 * may be used to endorse or promote products derived from this software without
21 * specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef ARM_OCSD_C_API_CUST_IMPL_H_INCLUDED
35 #define ARM_OCSD_C_API_CUST_IMPL_H_INCLUDED
37 #include "opencsd/c_api/ocsd_c_api_types.h"
38 #include "opencsd/c_api/ocsd_c_api_custom.h"
40 /** @addtogroup ocsd_ext_dcd
43 /**@name External decoder - Inline utility functions.
44 @brief inline functions used in decoders to call the various library callback functionality.
46 Functions manipulate and use the ocsd_extern_dcd_cb_fns structure to call into the library,
47 with appropriate checking for initialisation and usage flags.
51 static inline ocsd_datapath_resp_t lib_cb_GenElemOp(const ocsd_extern_dcd_cb_fns *callbacks,
52 const ocsd_trc_index_t index_sop,
53 const uint8_t trc_chan_id,
54 const ocsd_generic_trace_elem *elem)
56 if (callbacks->fn_gen_elem_out)
57 return callbacks->fn_gen_elem_out(callbacks->lib_context, index_sop, trc_chan_id, elem);
58 return OCSD_RESP_FATAL_NOT_INIT;
61 static inline ocsd_err_t lib_cb_LogError(const ocsd_extern_dcd_cb_fns *callbacks,
62 const ocsd_err_severity_t filter_level,
63 const ocsd_err_t code,
64 const ocsd_trc_index_t idx,
65 const uint8_t chan_id,
68 if (callbacks->fn_log_error)
70 callbacks->fn_log_error(callbacks->lib_context, filter_level, code, idx, chan_id, pMsg);
73 return OCSD_ERR_NOT_INIT;
76 static inline ocsd_err_t lib_cb_LogMsg(const ocsd_extern_dcd_cb_fns *callbacks,
77 const ocsd_err_severity_t filter_level,
80 if (callbacks->fn_log_msg)
82 callbacks->fn_log_msg(callbacks->lib_context, filter_level, pMsg);
85 return OCSD_ERR_NOT_INIT;
88 static inline ocsd_err_t lib_cb_DecodeArmInst(const ocsd_extern_dcd_cb_fns *callbacks,
89 ocsd_instr_info *instr_info)
91 if (callbacks->fn_arm_instruction_decode)
92 return callbacks->fn_arm_instruction_decode(callbacks->lib_context, instr_info);
93 return OCSD_ERR_NOT_INIT;
96 static inline ocsd_err_t lib_cb_MemAccess(const ocsd_extern_dcd_cb_fns *callbacks,
97 const ocsd_vaddr_t address,
98 const uint8_t cs_trace_id,
99 const ocsd_mem_space_acc_t mem_space,
103 if (callbacks->fn_memory_access)
104 return callbacks->fn_memory_access(callbacks->lib_context, address, cs_trace_id, mem_space, num_bytes, p_buffer);
105 return OCSD_ERR_NOT_INIT;
108 static inline void lib_cb_PktMon(const ocsd_extern_dcd_cb_fns *callbacks,
109 const ocsd_datapath_op_t op,
110 const ocsd_trc_index_t index_sop,
113 const uint8_t *p_data)
115 if (callbacks->packetCBFlags & OCSD_CUST_DCD_PKT_CB_USE_MON)
117 if (callbacks->fn_packet_mon)
118 callbacks->fn_packet_mon(callbacks->lib_context, op, index_sop, pkt, size, p_data);
122 static inline int lib_cb_usePktMon(const ocsd_extern_dcd_cb_fns *callbacks)
124 return (callbacks->packetCBFlags & OCSD_CUST_DCD_PKT_CB_USE_MON);
127 /* callback function to connect to the packet sink interface, on the main decode
128 data path - used if decoder created as packet processor only */
129 static inline ocsd_datapath_resp_t lib_cb_PktDataSink(const ocsd_extern_dcd_cb_fns *callbacks,
130 const ocsd_datapath_op_t op,
131 const ocsd_trc_index_t index_sop,
134 if (callbacks->packetCBFlags & OCSD_CUST_DCD_PKT_CB_USE_SINK)
136 if (callbacks->fn_packet_data_sink)
137 return callbacks->fn_packet_data_sink(callbacks->lib_context, op, index_sop, pkt);
139 return OCSD_RESP_FATAL_NOT_INIT;
141 return OCSD_RESP_CONT;
144 static inline int lib_cb_usePktSink(const ocsd_extern_dcd_cb_fns *callbacks)
146 return (callbacks->packetCBFlags & OCSD_CUST_DCD_PKT_CB_USE_SINK);
149 static inline void lib_cb_updatePktCBFlags(ocsd_extern_dcd_cb_fns *callbacks, const int newFlags)
151 callbacks->packetCBFlags = newFlags;
158 #endif /* ARM_OCSD_C_API_CUST_IMPL_H_INCLUDED */