2 * \file trc_ret_stack.cpp
3 * \brief OpenCSD : trace decoder return stack feature.
5 * \copyright Copyright (c) 2017, 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 #include "common/trc_ret_stack.h"
36 #ifdef TRC_RET_STACK_DEBUG
39 #include "common/trc_component.h"
41 #define LOG_POP(A,O,I) LogOp("Pop",A,O,I)
42 #define LOG_PUSH(A,O,I) LogOp("Push",A,O,I)
43 #define LOG_FLUSH() LogOp("Flush",0,-1000,(const ocsd_isa)0)
45 // uncomment for forced std::cout log, bypassing normal library debug logger.
46 // useful perhaps when perf is decoding w/o printing.
47 // #define FORCE_STD_COUT
50 #define LOG_POP(A,O,I)
51 #define LOG_PUSH(A,O,I)
55 TrcAddrReturnStack::TrcAddrReturnStack() :
61 #ifdef TRC_RET_STACK_DEBUG
66 void TrcAddrReturnStack::push(const ocsd_vaddr_t addr, const ocsd_isa isa)
72 m_stack[head_idx].ret_addr = addr;
73 m_stack[head_idx].ret_isa = isa;
78 m_pop_pending = false;
82 ocsd_vaddr_t TrcAddrReturnStack::pop(ocsd_isa &isa)
84 ocsd_vaddr_t addr = (ocsd_vaddr_t)-1;
89 addr = m_stack[head_idx].ret_addr;
90 isa = m_stack[head_idx].ret_isa;
96 m_pop_pending = false;
102 void TrcAddrReturnStack::flush()
105 m_pop_pending = false;
109 #ifdef TRC_RET_STACK_DEBUG
110 void TrcAddrReturnStack::LogOp(const char * pszOpString, ocsd_vaddr_t addr, int head_off, ocsd_isa isa)
112 static const char *isa_names[] =
114 "A32", /**< V7 ARM 32, V8 AArch32 */
115 "T32", /**< Thumb2 -> 16/32 bit instructions */
116 "A64", /**< V8 AArch64 */
117 "TEE", /**< Thumb EE - unsupported */
118 "JZL", /**< Jazelle - unsupported in trace */
119 "custom", /**< Instruction set - custom arch decoder */
120 "unknown" /**< ISA not yet known */
123 if (m_p_debug_logger)
125 std::ostringstream oss;
126 if(head_off == -1000)
128 oss << "Return stack " << pszOpString << "\n";
132 int name_idx = (int)isa;
135 oss << "Return stack " << pszOpString << "[" << std::dec << (head_idx+head_off) << "](0x" << std::hex << addr << "), " << isa_names[name_idx] << ";";
136 oss << "current entries = " << std::dec << num_entries << ";";
137 oss << "new head idx = " << head_idx << ";";
138 oss << "pop pend (pre op) = " << (m_pop_pending ? "true\n" : "false\n");
140 #ifdef FORCE_STD_COUT
141 std::cout << oss.str();
144 m_p_debug_logger->LogDefMessage(oss.str());
149 /* End of File trc_ret_stack.cpp */