gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
branch.hh
Go to the documentation of this file.
1 /* Copyright (c) 2007-2008 The Florida State University
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 
31 #ifndef __ARCH_POWER_INSTS_BRANCH_HH__
32 #define __ARCH_POWER_INSTS_BRANCH_HH__
33 
35 
36 namespace PowerISA
37 {
38 
49 {
50  protected:
52  mutable Addr cachedPC;
54  mutable const SymbolTable *cachedSymtab;
55 
57  PCDependentDisassembly(const char *mnem, ExtMachInst _machInst,
58  OpClass __opClass)
59  : PowerStaticInst(mnem, _machInst, __opClass),
60  cachedPC(0), cachedSymtab(0)
61  {
62  }
63 
64  const std::string &
65  disassemble(Addr pc, const SymbolTable *symtab) const;
66 };
67 
72 {
73  protected:
74 
76  uint32_t disp;
77 
79  BranchPCRel(const char *mnem, MachInst _machInst, OpClass __opClass)
80  : PCDependentDisassembly(mnem, _machInst, __opClass),
81  disp(machInst.li << 2)
82  {
83  // If bit 26 is 1 then sign extend
84  if (disp & 0x2000000) {
85  disp |= 0xfc000000;
86  }
87  }
88 
90 
93 
94  std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
95 };
96 
101 {
102  protected:
103 
105  uint32_t targetAddr;
106 
108  BranchNonPCRel(const char *mnem, MachInst _machInst, OpClass __opClass)
109  : PCDependentDisassembly(mnem, _machInst, __opClass),
110  targetAddr(machInst.li << 2)
111  {
112  // If bit 26 is 1 then sign extend
113  if (targetAddr & 0x2000000) {
114  targetAddr |= 0xfc000000;
115  }
116  }
117 
119 
122 
123  std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
124 };
125 
130 {
131  protected:
132 
134  uint32_t bo;
135  uint32_t bi;
136 
138  BranchCond(const char *mnem, MachInst _machInst, OpClass __opClass)
139  : PCDependentDisassembly(mnem, _machInst, __opClass),
140  bo(machInst.bo),
141  bi(machInst.bi)
142  {
143  }
144 
145  inline bool
146  ctrOk(uint32_t& ctr) const
147  {
148  bool ctr_ok;
149  if (bo & 4) {
150  ctr_ok = true;
151  } else {
152  ctr--;
153  if (ctr != 0) {
154  ctr_ok = ((bo & 2) == 0);
155  } else {
156  ctr_ok = ((bo & 2) != 0);
157  }
158  }
159  return ctr_ok;
160  }
161 
162  inline bool
163  condOk(uint32_t cr) const
164  {
165  bool cond_ok;
166  if (bo & 16) {
167  cond_ok = true;
168  } else {
169  cond_ok = (((cr >> (31 - bi)) & 1) == ((bo >> 3) & 1));
170  }
171  return cond_ok;
172  }
173 };
174 
179 {
180  protected:
181 
183  uint32_t disp;
184 
186  BranchPCRelCond(const char *mnem, MachInst _machInst, OpClass __opClass)
187  : BranchCond(mnem, _machInst, __opClass),
188  disp(machInst.bd << 2)
189  {
190  // If bit 16 is 1 then sign extend
191  if (disp & 0x8000) {
192  disp |= 0xffff0000;
193  }
194  }
195 
197 
200 
201  std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
202 };
203 
208 {
209  protected:
210 
212  uint32_t targetAddr;
213 
215  BranchNonPCRelCond(const char *mnem, MachInst _machInst, OpClass __opClass)
216  : BranchCond(mnem, _machInst, __opClass),
217  targetAddr(machInst.bd << 2)
218  {
219  // If bit 16 is 1 then sign extend
220  if (targetAddr & 0x8000) {
221  targetAddr |= 0xffff0000;
222  }
223  }
224 
226 
229 
230  std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
231 };
232 
236 class BranchRegCond : public BranchCond
237 {
238  protected:
239 
241  BranchRegCond(const char *mnem, MachInst _machInst, OpClass __opClass)
242  : BranchCond(mnem, _machInst, __opClass)
243  {
244  }
245 
247 
250 
251  std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
252 };
253 
254 } // namespace PowerISA
255 
256 #endif //__ARCH_POWER_INSTS_BRANCH_HH__
uint32_t bo
Fields needed for conditions.
Definition: branch.hh:134
PowerISA::PCState branchTarget(const PowerISA::PCState &pc) const
Definition: branch.cc:103
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
Base class for unconditional, non PC-relative branches.
Definition: branch.hh:100
bool condOk(uint32_t cr) const
Definition: branch.hh:163
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...
Base class for unconditional, PC-relative branches.
Definition: branch.hh:71
BranchPCRel(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition: branch.hh:79
const SymbolTable * cachedSymtab
Cached symbol table pointer from last disassembly.
Definition: branch.hh:54
const ExtMachInst machInst
The binary machine instruction.
Definition: static_inst.hh:218
Base class for conditional, non PC-relative branches.
Definition: branch.hh:207
uint32_t disp
Displacement.
Definition: branch.hh:76
Base class for conditional branches.
Definition: branch.hh:129
uint32_t MachInst
Definition: types.hh:41
BranchCond(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition: branch.hh:138
BranchPCRelCond(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition: branch.hh:186
bool ctrOk(uint32_t &ctr) const
Definition: branch.hh:146
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
Base class for conditional, PC-relative branches.
Definition: branch.hh:178
Bitfield< 15, 2 > bd
Definition: types.hh:63
Bitfield< 25, 2 > li
Definition: types.hh:60
Base class for conditional, register-based branches.
Definition: branch.hh:236
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
BranchRegCond(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition: branch.hh:241
Addr cachedPC
Cached program counter from last disassembly.
Definition: branch.hh:52
TheISA::ExtMachInst ExtMachInst
Binary extended machine instruction type.
Definition: static_inst.hh:72
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
Base class for instructions whose disassembly is not purely a function of the machine instruction (i...
Definition: branch.hh:48
uint32_t targetAddr
Target address.
Definition: branch.hh:105
uint32_t disp
Displacement.
Definition: branch.hh:183
BranchNonPCRel(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition: branch.hh:108
PCDependentDisassembly(const char *mnem, ExtMachInst _machInst, OpClass __opClass)
Constructor.
Definition: branch.hh:57
BranchNonPCRelCond(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition: branch.hh:215
virtual TheISA::PCState branchTarget(const TheISA::PCState &pc) const
Return the target address for a PC-relative branch.
Definition: static_inst.cc:73
PowerISA::PCState branchTarget(const PowerISA::PCState &pc) const
Definition: branch.cc:57

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