• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * \file       ocsd_c_api_cust_impl.h
3 * \brief      OpenCSD : Custom decoder implementation common API definitions
4 *
5 * \copyright  Copyright (c) 2016, ARM Limited. All Rights Reserved.
6 */
7 
8 /*
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * 3. Neither the name of the copyright holder nor the names of its contributors
20 * may be used to endorse or promote products derived from this software without
21 * specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34 #ifndef ARM_OCSD_C_API_CUST_IMPL_H_INCLUDED
35 #define ARM_OCSD_C_API_CUST_IMPL_H_INCLUDED
36 
37 #include "opencsd/c_api/ocsd_c_api_types.h"
38 #include "opencsd/c_api/ocsd_c_api_custom.h"
39 
40 /** @addtogroup ocsd_ext_dcd
41 @{*/
42 
43 /**@name External decoder - Inline utility functions.
44    @brief inline functions used in decoders to call the various library callback functionality.
45 
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.
48 
49 @{*/
50 
lib_cb_GenElemOp(const ocsd_extern_dcd_cb_fns * callbacks,const ocsd_trc_index_t index_sop,const uint8_t trc_chan_id,const ocsd_generic_trace_elem * elem)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)
55 {
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;
59 }
60 
lib_cb_LogError(const ocsd_extern_dcd_cb_fns * callbacks,const ocsd_err_severity_t filter_level,const ocsd_err_t code,const ocsd_trc_index_t idx,const uint8_t chan_id,const char * pMsg)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,
66     const char *pMsg)
67 {
68     if (callbacks->fn_log_error)
69     {
70         callbacks->fn_log_error(callbacks->lib_context, filter_level, code, idx, chan_id, pMsg);
71         return OCSD_OK;
72     }
73     return OCSD_ERR_NOT_INIT;
74 }
75 
lib_cb_LogMsg(const ocsd_extern_dcd_cb_fns * callbacks,const ocsd_err_severity_t filter_level,const char * pMsg)76 static inline ocsd_err_t lib_cb_LogMsg(const ocsd_extern_dcd_cb_fns *callbacks,
77     const ocsd_err_severity_t filter_level,
78     const char *pMsg)
79 {
80     if (callbacks->fn_log_msg)
81     {
82         callbacks->fn_log_msg(callbacks->lib_context, filter_level, pMsg);
83         return OCSD_OK;
84     }
85     return OCSD_ERR_NOT_INIT;
86 }
87 
lib_cb_DecodeArmInst(const ocsd_extern_dcd_cb_fns * callbacks,ocsd_instr_info * instr_info)88 static inline ocsd_err_t lib_cb_DecodeArmInst(const ocsd_extern_dcd_cb_fns *callbacks,
89     ocsd_instr_info *instr_info)
90 {
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;
94 }
95 
lib_cb_MemAccess(const ocsd_extern_dcd_cb_fns * callbacks,const ocsd_vaddr_t address,const uint8_t cs_trace_id,const ocsd_mem_space_acc_t mem_space,uint32_t * num_bytes,uint8_t * p_buffer)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,
100     uint32_t *num_bytes,
101     uint8_t *p_buffer)
102 {
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;
106 }
107 
lib_cb_PktMon(const ocsd_extern_dcd_cb_fns * callbacks,const ocsd_datapath_op_t op,const ocsd_trc_index_t index_sop,const void * pkt,const uint32_t size,const uint8_t * p_data)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,
111     const void *pkt,
112     const uint32_t size,
113     const uint8_t *p_data)
114 {
115     if (callbacks->packetCBFlags & OCSD_CUST_DCD_PKT_CB_USE_MON)
116     {
117         if (callbacks->fn_packet_mon)
118             callbacks->fn_packet_mon(callbacks->lib_context, op, index_sop, pkt, size, p_data);
119     }
120 }
121 
lib_cb_usePktMon(const ocsd_extern_dcd_cb_fns * callbacks)122 static inline int lib_cb_usePktMon(const ocsd_extern_dcd_cb_fns *callbacks)
123 {
124     return (callbacks->packetCBFlags & OCSD_CUST_DCD_PKT_CB_USE_MON);
125 }
126 
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 */
lib_cb_PktDataSink(const ocsd_extern_dcd_cb_fns * callbacks,const ocsd_datapath_op_t op,const ocsd_trc_index_t index_sop,const void * pkt)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,
132     const void *pkt)
133 {
134     if (callbacks->packetCBFlags & OCSD_CUST_DCD_PKT_CB_USE_SINK)
135     {
136         if (callbacks->fn_packet_data_sink)
137             return callbacks->fn_packet_data_sink(callbacks->lib_context, op, index_sop, pkt);
138         else
139             return OCSD_RESP_FATAL_NOT_INIT;
140     }
141     return OCSD_RESP_CONT;
142 }
143 
lib_cb_usePktSink(const ocsd_extern_dcd_cb_fns * callbacks)144 static inline int lib_cb_usePktSink(const ocsd_extern_dcd_cb_fns *callbacks)
145 {
146     return (callbacks->packetCBFlags & OCSD_CUST_DCD_PKT_CB_USE_SINK);
147 }
148 
lib_cb_updatePktCBFlags(ocsd_extern_dcd_cb_fns * callbacks,const int newFlags)149 static inline void lib_cb_updatePktCBFlags(ocsd_extern_dcd_cb_fns *callbacks, const int newFlags)
150 {
151     callbacks->packetCBFlags = newFlags;
152 }
153 
154 /** @}*/
155 
156 /** @}*/
157 
158 #endif /* ARM_OCSD_C_API_CUST_IMPL_H_INCLUDED */
159