gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
89  PowerISA::PCState branchTarget(const PowerISA::PCState &pc) const override;
90 
93 
94  std::string generateDisassembly(
95  Addr pc, const SymbolTable *symtab) const override;
96 };
97 
102 {
103  protected:
104 
106  uint32_t targetAddr;
107 
109  BranchNonPCRel(const char *mnem, MachInst _machInst, OpClass __opClass)
110  : PCDependentDisassembly(mnem, _machInst, __opClass),
111  targetAddr(machInst.li << 2)
112  {
113  // If bit 26 is 1 then sign extend
114  if (targetAddr & 0x2000000) {
115  targetAddr |= 0xfc000000;
116  }
117  }
118 
119  PowerISA::PCState branchTarget(const PowerISA::PCState &pc) const override;
120 
123 
124  std::string generateDisassembly(
125  Addr pc, const SymbolTable *symtab) const override;
126 };
127 
132 {
133  protected:
134 
136  uint32_t bo;
137  uint32_t bi;
138 
140  BranchCond(const char *mnem, MachInst _machInst, OpClass __opClass)
141  : PCDependentDisassembly(mnem, _machInst, __opClass),
142  bo(machInst.bo),
143  bi(machInst.bi)
144  {
145  }
146 
147  inline bool
148  ctrOk(uint32_t& ctr) const
149  {
150  bool ctr_ok;
151  if (bo & 4) {
152  ctr_ok = true;
153  } else {
154  ctr--;
155  if (ctr != 0) {
156  ctr_ok = ((bo & 2) == 0);
157  } else {
158  ctr_ok = ((bo & 2) != 0);
159  }
160  }
161  return ctr_ok;
162  }
163 
164  inline bool
165  condOk(uint32_t cr) const
166  {
167  bool cond_ok;
168  if (bo & 16) {
169  cond_ok = true;
170  } else {
171  cond_ok = (((cr >> (31 - bi)) & 1) == ((bo >> 3) & 1));
172  }
173  return cond_ok;
174  }
175 };
176 
181 {
182  protected:
183 
185  uint32_t disp;
186 
188  BranchPCRelCond(const char *mnem, MachInst _machInst, OpClass __opClass)
189  : BranchCond(mnem, _machInst, __opClass),
190  disp(machInst.bd << 2)
191  {
192  // If bit 16 is 1 then sign extend
193  if (disp & 0x8000) {
194  disp |= 0xffff0000;
195  }
196  }
197 
198  PowerISA::PCState branchTarget(const PowerISA::PCState &pc) const override;
199 
202 
203  std::string generateDisassembly(
204  Addr pc, const SymbolTable *symtab) const override;
205 };
206 
211 {
212  protected:
213 
215  uint32_t targetAddr;
216 
218  BranchNonPCRelCond(const char *mnem, MachInst _machInst, OpClass __opClass)
219  : BranchCond(mnem, _machInst, __opClass),
220  targetAddr(machInst.bd << 2)
221  {
222  // If bit 16 is 1 then sign extend
223  if (targetAddr & 0x8000) {
224  targetAddr |= 0xffff0000;
225  }
226  }
227 
228  PowerISA::PCState branchTarget(const PowerISA::PCState &pc) const override;
229 
232 
233  std::string generateDisassembly(
234  Addr pc, const SymbolTable *symtab) const override;
235 };
236 
240 class BranchRegCond : public BranchCond
241 {
242  protected:
243 
245  BranchRegCond(const char *mnem, MachInst _machInst, OpClass __opClass)
246  : BranchCond(mnem, _machInst, __opClass)
247  {
248  }
249 
250  PowerISA::PCState branchTarget(ThreadContext *tc) const override;
251 
254 
255  std::string generateDisassembly(
256  Addr pc, const SymbolTable *symtab) const override;
257 };
258 
259 } // namespace PowerISA
260 
261 #endif //__ARCH_POWER_INSTS_BRANCH_HH__
uint32_t bo
Fields needed for conditions.
Definition: branch.hh:136
Base class for unconditional, non PC-relative branches.
Definition: branch.hh:101
Bitfield< 20, 16 > bi
Definition: types.hh:65
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: static_inst.cc:59
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:229
bool condOk(uint32_t cr) const
Definition: branch.hh:165
Base class for conditional, non PC-relative branches.
Definition: branch.hh:210
Bitfield< 4 > pc
uint32_t disp
Displacement.
Definition: branch.hh:76
Base class for conditional branches.
Definition: branch.hh:131
uint32_t MachInst
Definition: types.hh:41
BranchCond(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition: branch.hh:140
BranchPCRelCond(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition: branch.hh:188
const std::string & disassemble(Addr pc, const SymbolTable *symtab) const
Return string representation of disassembled instruction.
Definition: branch.cc:39
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Base class for conditional, PC-relative branches.
Definition: branch.hh:180
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:240
virtual TheISA::PCState branchTarget(const TheISA::PCState &pc) const
Return the target address for a PC-relative branch.
Definition: static_inst.cc:107
bool ctrOk(uint32_t &ctr) const
Definition: branch.hh:148
GenericISA::SimplePCState< MachInst > PCState
Definition: types.hh:43
BranchRegCond(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition: branch.hh:245
Addr cachedPC
Cached program counter from last disassembly.
Definition: branch.hh:52
TheISA::ExtMachInst ExtMachInst
Binary extended machine instruction type.
Definition: static_inst.hh:87
uint32_t targetAddr
Target address.
Definition: branch.hh:215
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:106
uint32_t disp
Displacement.
Definition: branch.hh:185
BranchNonPCRel(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition: branch.hh:109
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:218

Generated on Fri Feb 28 2020 16:26:57 for gem5 by doxygen 1.8.13