gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
branch.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 The University of Edinburgh
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * Authors: Timothy M. Jones
29  */
30 
32 
33 #include "base/loader/symtab.hh"
34 #include "cpu/thread_context.hh"
35 
36 using namespace PowerISA;
37 
38 const std::string &
40 {
41  if (!cachedDisassembly ||
42  pc != cachedPC || symtab != cachedSymtab)
43  {
45  delete cachedDisassembly;
46 
48  new std::string(generateDisassembly(pc, symtab));
49  cachedPC = pc;
50  cachedSymtab = symtab;
51  }
52 
53  return *cachedDisassembly;
54 }
55 
58 {
59  return (uint32_t)(pc.pc() + disp);
60 }
61 
62 std::string
64 {
65  std::stringstream ss;
66 
67  ccprintf(ss, "%-10s ", mnemonic);
68 
69  Addr target = pc + disp;
70 
71  std::string str;
72  if (symtab && symtab->findSymbol(target, str))
73  ss << str;
74  else
75  ccprintf(ss, "0x%x", target);
76 
77  return ss.str();
78 }
79 
82 {
83  return targetAddr;
84 }
85 
86 std::string
88 {
89  std::stringstream ss;
90 
91  ccprintf(ss, "%-10s ", mnemonic);
92 
93  std::string str;
94  if (symtab && symtab->findSymbol(targetAddr, str))
95  ss << str;
96  else
97  ccprintf(ss, "0x%x", targetAddr);
98 
99  return ss.str();
100 }
101 
104 {
105  return (uint32_t)(pc.pc() + disp);
106 }
107 
108 std::string
110 {
111  std::stringstream ss;
112 
113  ccprintf(ss, "%-10s ", mnemonic);
114 
115  ss << bo << ", " << bi << ", ";
116 
117  Addr target = pc + disp;
118 
119  std::string str;
120  if (symtab && symtab->findSymbol(target, str))
121  ss << str;
122  else
123  ccprintf(ss, "0x%x", target);
124 
125  return ss.str();
126 }
127 
130 {
131  return targetAddr;
132 }
133 
134 std::string
136  const SymbolTable *symtab) const
137 {
138  std::stringstream ss;
139 
140  ccprintf(ss, "%-10s ", mnemonic);
141 
142  ss << bo << ", " << bi << ", ";
143 
144  std::string str;
145  if (symtab && symtab->findSymbol(targetAddr, str))
146  ss << str;
147  else
148  ccprintf(ss, "0x%x", targetAddr);
149 
150  return ss.str();
151 }
152 
155 {
156  uint32_t regVal = tc->readIntReg(_srcRegIdx[_numSrcRegs - 1]);
157  return regVal & 0xfffffffc;
158 }
159 
160 std::string
162  const SymbolTable *symtab) const
163 {
164  std::stringstream ss;
165 
166  ccprintf(ss, "%-10s ", mnemonic);
167 
168  ss << bo << ", " << bi << ", ";
169 
170  return ss.str();
171 }
void ccprintf(cp::Print &print)
Definition: cprintf.hh:130
uint32_t bo
Fields needed for conditions.
Definition: branch.hh:134
PowerISA::PCState branchTarget(const PowerISA::PCState &pc) const
Definition: branch.cc:103
std::string * cachedDisassembly
String representation of disassembly (lazily evaluated via disassemble()).
Definition: static_inst.hh:239
int8_t _numSrcRegs
See numSrcRegs().
Definition: static_inst.hh:90
const std::string & disassemble(Addr pc, const SymbolTable *symtab) const
Return string representation of disassembled instruction.
Definition: branch.cc:39
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: branch.cc:87
const char * mnemonic
Base mnemonic (e.g., "add").
Definition: static_inst.hh:233
PowerISA::PCState branchTarget(ThreadContext *tc) const
Return the target address for an indirect branch (jump).
Definition: branch.cc:154
ThreadContext is the external interface to all thread state for anything outside of the CPU...
const SymbolTable * cachedSymtab
Cached symbol table pointer from last disassembly.
Definition: branch.hh:54
virtual uint64_t readIntReg(int reg_idx)=0
uint32_t disp
Displacement.
Definition: branch.hh:76
RegIndex _srcRegIdx[MaxInstSrcRegs]
See srcRegIdx().
Definition: static_inst.hh:225
Bitfield< 21 > ss
Definition: miscregs.hh:1371
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: branch.cc:109
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: static_inst.cc:65
PowerISA::PCState branchTarget(const PowerISA::PCState &pc) const
Definition: branch.cc:129
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: branch.cc:135
PowerISA::PCState branchTarget(const PowerISA::PCState &pc) const
Definition: branch.cc:81
GenericISA::SimplePCState< MachInst > PCState
Definition: types.hh:43
bool findSymbol(Addr address, std::string &symbol) const
Definition: symtab.hh:84
Addr cachedPC
Cached program counter from last disassembly.
Definition: branch.hh:52
IntReg pc
Definition: remote_gdb.hh:91
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: branch.cc:161
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: branch.cc:63
uint32_t targetAddr
Target address.
Definition: branch.hh:212
uint32_t targetAddr
Target address.
Definition: branch.hh:105
uint32_t disp
Displacement.
Definition: branch.hh:183
PowerISA::PCState branchTarget(const PowerISA::PCState &pc) const
Definition: branch.cc:57

Generated on Fri Jun 9 2017 13:03:39 for gem5 by doxygen 1.8.6