xref: /freebsd/contrib/opencsd/decoder/include/common/trc_ret_stack.h (revision c120c5646da1a1d2c4d90fd069a7e2a8d559eb46)
1*c120c564SAndrew Turner /*
2*c120c564SAndrew Turner * \file       trc_ret_stack.h
3*c120c564SAndrew Turner * \brief      OpenCSD : trace decoder return stack feature.
4*c120c564SAndrew Turner *
5*c120c564SAndrew Turner * \copyright  Copyright (c) 2017, ARM Limited. All Rights Reserved.
6*c120c564SAndrew Turner */
7*c120c564SAndrew Turner 
8*c120c564SAndrew Turner /*
9*c120c564SAndrew Turner * Redistribution and use in source and binary forms, with or without modification,
10*c120c564SAndrew Turner * are permitted provided that the following conditions are met:
11*c120c564SAndrew Turner *
12*c120c564SAndrew Turner * 1. Redistributions of source code must retain the above copyright notice,
13*c120c564SAndrew Turner * this list of conditions and the following disclaimer.
14*c120c564SAndrew Turner *
15*c120c564SAndrew Turner * 2. Redistributions in binary form must reproduce the above copyright notice,
16*c120c564SAndrew Turner * this list of conditions and the following disclaimer in the documentation
17*c120c564SAndrew Turner * and/or other materials provided with the distribution.
18*c120c564SAndrew Turner *
19*c120c564SAndrew Turner * 3. Neither the name of the copyright holder nor the names of its contributors
20*c120c564SAndrew Turner * may be used to endorse or promote products derived from this software without
21*c120c564SAndrew Turner * specific prior written permission.
22*c120c564SAndrew Turner *
23*c120c564SAndrew Turner * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24*c120c564SAndrew Turner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25*c120c564SAndrew Turner * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26*c120c564SAndrew Turner * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27*c120c564SAndrew Turner * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28*c120c564SAndrew Turner * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29*c120c564SAndrew Turner * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30*c120c564SAndrew Turner * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31*c120c564SAndrew Turner * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32*c120c564SAndrew Turner * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33*c120c564SAndrew Turner */
34*c120c564SAndrew Turner 
35*c120c564SAndrew Turner #ifndef ARM_TRC_RET_STACK_H_INCLUDED
36*c120c564SAndrew Turner #define ARM_TRC_RET_STACK_H_INCLUDED
37*c120c564SAndrew Turner 
38*c120c564SAndrew Turner #include "opencsd/ocsd_if_types.h"
39*c120c564SAndrew Turner 
40*c120c564SAndrew Turner // uncomment below for return stack logging
41*c120c564SAndrew Turner // #define TRC_RET_STACK_DEBUG
42*c120c564SAndrew Turner 
43*c120c564SAndrew Turner #ifdef TRC_RET_STACK_DEBUG
44*c120c564SAndrew Turner class TraceComponent;
45*c120c564SAndrew Turner #endif
46*c120c564SAndrew Turner 
47*c120c564SAndrew Turner typedef struct _retStackElement
48*c120c564SAndrew Turner {
49*c120c564SAndrew Turner     ocsd_vaddr_t ret_addr;
50*c120c564SAndrew Turner     ocsd_isa ret_isa;
51*c120c564SAndrew Turner } retStackElement;
52*c120c564SAndrew Turner 
53*c120c564SAndrew Turner class TrcAddrReturnStack
54*c120c564SAndrew Turner {
55*c120c564SAndrew Turner public:
56*c120c564SAndrew Turner     TrcAddrReturnStack();
~TrcAddrReturnStack()57*c120c564SAndrew Turner     ~TrcAddrReturnStack() {};
58*c120c564SAndrew Turner 
set_active(bool active)59*c120c564SAndrew Turner     void set_active(bool active)
60*c120c564SAndrew Turner     {
61*c120c564SAndrew Turner         m_active = active;
62*c120c564SAndrew Turner     };
63*c120c564SAndrew Turner 
is_active()64*c120c564SAndrew Turner     bool is_active() const
65*c120c564SAndrew Turner     {
66*c120c564SAndrew Turner         return m_active;
67*c120c564SAndrew Turner     };
68*c120c564SAndrew Turner 
69*c120c564SAndrew Turner     void push(const ocsd_vaddr_t addr, const ocsd_isa isa);
70*c120c564SAndrew Turner     ocsd_vaddr_t pop(ocsd_isa &isa);
71*c120c564SAndrew Turner     void flush();
72*c120c564SAndrew Turner 
overflow()73*c120c564SAndrew Turner     bool overflow() const
74*c120c564SAndrew Turner     {
75*c120c564SAndrew Turner         return (bool)(num_entries < 0);
76*c120c564SAndrew Turner     };
77*c120c564SAndrew Turner 
set_pop_pending()78*c120c564SAndrew Turner     void set_pop_pending()
79*c120c564SAndrew Turner     {
80*c120c564SAndrew Turner         if (m_active)
81*c120c564SAndrew Turner             m_pop_pending = true;
82*c120c564SAndrew Turner     }
83*c120c564SAndrew Turner 
clear_pop_pending()84*c120c564SAndrew Turner     void clear_pop_pending()
85*c120c564SAndrew Turner     {
86*c120c564SAndrew Turner         m_pop_pending = false;
87*c120c564SAndrew Turner     }
88*c120c564SAndrew Turner 
pop_pending()89*c120c564SAndrew Turner     bool pop_pending() const
90*c120c564SAndrew Turner     {
91*c120c564SAndrew Turner         return m_pop_pending;
92*c120c564SAndrew Turner     };
93*c120c564SAndrew Turner 
94*c120c564SAndrew Turner private:
95*c120c564SAndrew Turner     bool m_active;
96*c120c564SAndrew Turner     bool m_pop_pending; // flag for decoder to indicate a pop might be needed depending on the next packet (ETMv4)
97*c120c564SAndrew Turner 
98*c120c564SAndrew Turner     int head_idx;
99*c120c564SAndrew Turner     int num_entries;
100*c120c564SAndrew Turner     retStackElement m_stack[16];
101*c120c564SAndrew Turner 
102*c120c564SAndrew Turner #ifdef TRC_RET_STACK_DEBUG
103*c120c564SAndrew Turner public:
set_dbg_logger(TraceComponent * pLogger)104*c120c564SAndrew Turner     void set_dbg_logger(TraceComponent *pLogger) { m_p_debug_logger = pLogger;  };
105*c120c564SAndrew Turner private:
106*c120c564SAndrew Turner     void LogOp(const char *pszOpString, ocsd_vaddr_t addr, int head_off, ocsd_isa isa);
107*c120c564SAndrew Turner 
108*c120c564SAndrew Turner     TraceComponent *m_p_debug_logger;
109*c120c564SAndrew Turner #endif  // TRC_RET_STACK_DEBUG
110*c120c564SAndrew Turner };
111*c120c564SAndrew Turner 
112*c120c564SAndrew Turner #endif // ARM_TRC_RET_STACK_H_INCLUDED
113*c120c564SAndrew Turner 
114*c120c564SAndrew Turner /* End of File trc_ret_stack.h */
115