gem5  v21.2.1.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  * Copyright (c) 2021 IBM Corporation
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef __ARCH_POWER_INSTS_BRANCH_HH__
31 #define __ARCH_POWER_INSTS_BRANCH_HH__
32 
34 
35 namespace gem5
36 {
37 
38 namespace PowerISA
39 {
40 
51 {
52  protected:
54  mutable Addr cachedPC;
57 
59  PCDependentDisassembly(const char *mnem, ExtMachInst _machInst,
60  OpClass __opClass)
61  : PowerStaticInst(mnem, _machInst, __opClass),
62  cachedPC(0), cachedSymtab(0)
63  {
64  }
65 
66  const std::string &
67  disassemble(Addr pc, const loader::SymbolTable *symtab) const;
68 };
69 
70 
75 {
76  protected:
77 
78  bool aa;
79  bool lk;
80  int64_t li;
81 
83  BranchOp(const char *mnem, MachInst _machInst, OpClass __opClass)
84  : PCDependentDisassembly(mnem, _machInst, __opClass),
85  aa(machInst.aa),
86  lk(machInst.lk),
87  li(sext<26>(machInst.li << 2))
88  {
89  }
90 
91  std::unique_ptr<PCStateBase> branchTarget(
92  ThreadContext *tc) const override;
93 
96 
97  std::string generateDisassembly(
98  Addr pc, const loader::SymbolTable *symtab) const override;
99 };
100 
101 
106 {
107  protected:
108 
109  bool lk;
110  uint8_t bi;
111  uint8_t bo;
112 
114  BranchCondOp(const char *mnem, MachInst _machInst, OpClass __opClass)
115  : PCDependentDisassembly(mnem, _machInst, __opClass),
116  lk(machInst.lk),
117  bi(machInst.bi),
118  bo(machInst.bo)
119  {
120  }
121 
122  inline bool
123  ctrOk(uint64_t& ctr) const
124  {
125  if (bits(bo, 2)) {
126  return true;
127  }
128 
129  ctr--;
130  return !((ctr != 0) ^ (bits(bo, 1) == 0));
131  }
132 
133  inline bool
134  condOk(uint32_t cr) const
135  {
136  if (bits(bo, 4)) {
137  return true;
138  }
139 
140  return bits(cr >> (31 - bi), 0) == bits(bo >> 3, 0);
141  }
142 };
143 
144 
149 {
150  protected:
151 
152  bool aa;
153  int64_t bd;
154 
156  BranchDispCondOp(const char *mnem, MachInst _machInst, OpClass __opClass)
157  : BranchCondOp(mnem, _machInst, __opClass),
158  aa(machInst.aa),
159  bd(sext<16>(machInst.bd << 2))
160  {
161  }
162 
163  std::unique_ptr<PCStateBase> branchTarget(
164  ThreadContext *tc) const override;
165 
168 
169  std::string generateDisassembly(
170  Addr pc, const loader::SymbolTable *symtab) const override;
171 };
172 
173 
178 {
179  protected:
180 
182  uint8_t bh;
183 
185  BranchRegCondOp(const char *mnem, MachInst _machInst, OpClass __opClass)
186  : BranchCondOp(mnem, _machInst, __opClass),
187  bh(machInst.bh)
188  {
189  }
190 
191  std::unique_ptr<PCStateBase> branchTarget(
192  ThreadContext *tc) const override;
193 
196 
197  std::string generateDisassembly(
198  Addr pc, const loader::SymbolTable *symtab) const override;
199 };
200 
201 } // namespace PowerISA
202 } // namespace gem5
203 
204 #endif //__ARCH_POWER_INSTS_BRANCH_HH__
gem5::PowerISA::PowerStaticInst::machInst
ExtMachInst machInst
Definition: static_inst.hh:47
gem5::PowerISA::PCDependentDisassembly::disassemble
const std::string & disassemble(Addr pc, const loader::SymbolTable *symtab) const
Return string representation of disassembled instruction.
Definition: branch.cc:43
gem5::PowerISA::BranchDispCondOp
Base class for conditional, PC-relative or absolute address branches.
Definition: branch.hh:148
gem5::sext
constexpr uint64_t sext(uint64_t val)
Sign-extend an N-bit value to 64 bits.
Definition: bitfield.hh:126
gem5::PowerISA::BranchOp::BranchOp
BranchOp(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition: branch.hh:83
gem5::PowerISA::BranchCondOp::ctrOk
bool ctrOk(uint64_t &ctr) const
Definition: branch.hh:123
gem5::PowerISA::BranchDispCondOp::branchTarget
std::unique_ptr< PCStateBase > branchTarget(ThreadContext *tc) const override
Return the target address for an indirect branch (jump).
Definition: branch.cc:109
gem5::PowerISA::PCDependentDisassembly
Base class for instructions whose disassembly is not purely a function of the machine instruction (i....
Definition: branch.hh:50
gem5::loader::SymbolTable
Definition: symtab.hh:65
gem5::PowerISA::PCDependentDisassembly::cachedSymtab
const loader::SymbolTable * cachedSymtab
Cached symbol table pointer from last disassembly.
Definition: branch.hh:56
gem5::PowerISA::BranchCondOp::bo
uint8_t bo
Definition: branch.hh:111
gem5::PowerISA::BranchCondOp::condOk
bool condOk(uint32_t cr) const
Definition: branch.hh:134
gem5::PowerISA::BranchDispCondOp::bd
int64_t bd
Definition: branch.hh:153
gem5::PowerISA::BranchOp::generateDisassembly
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: branch.cc:76
gem5::PowerISA::BranchCondOp::bi
uint8_t bi
Definition: branch.hh:110
gem5::PowerISA::BranchRegCondOp::generateDisassembly
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: branch.cc:171
gem5::PowerISA::BranchRegCondOp::BranchRegCondOp
BranchRegCondOp(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition: branch.hh:185
gem5::PowerISA::BranchDispCondOp::aa
bool aa
Definition: branch.hh:152
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:94
gem5::PowerISA::BranchOp::aa
bool aa
Definition: branch.hh:78
gem5::PowerISA::BranchCondOp::lk
bool lk
Definition: branch.hh:109
gem5::bits
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:76
gem5::PowerISA::BranchRegCondOp
Base class for conditional, register-based branches.
Definition: branch.hh:177
gem5::PowerISA::BranchCondOp::BranchCondOp
BranchCondOp(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition: branch.hh:114
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::PowerISA::BranchOp::lk
bool lk
Definition: branch.hh:79
gem5::PowerISA::BranchOp
Base class for unconditional, PC-relative or absolute address branches.
Definition: branch.hh:74
gem5::X86ISA::ExtMachInst
Definition: types.hh:206
gem5::PowerISA::BranchDispCondOp::BranchDispCondOp
BranchDispCondOp(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition: branch.hh:156
gem5::PowerISA::BranchRegCondOp::bh
uint8_t bh
TODO: Branch hints are currently ignored.
Definition: branch.hh:182
gem5::PowerISA::MachInst
uint32_t MachInst
Definition: types.hh:44
gem5::PowerISA::PCDependentDisassembly::PCDependentDisassembly
PCDependentDisassembly(const char *mnem, ExtMachInst _machInst, OpClass __opClass)
Constructor.
Definition: branch.hh:59
gem5::MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:243
gem5::StaticInst::branchTarget
virtual std::unique_ptr< PCStateBase > branchTarget(const PCStateBase &pc) const
Return the target address for a PC-relative branch.
Definition: static_inst.cc:46
gem5::PowerISA::BranchOp::li
int64_t li
Definition: branch.hh:80
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: tlb.cc:60
gem5::PowerISA::BranchCondOp
Base class for conditional branches.
Definition: branch.hh:105
static_inst.hh
gem5::PowerISA::BranchOp::branchTarget
std::unique_ptr< PCStateBase > branchTarget(ThreadContext *tc) const override
Return the target address for an indirect branch (jump).
Definition: branch.cc:60
gem5::PowerISA::PowerStaticInst
Definition: static_inst.hh:44
gem5::PowerISA::BranchRegCondOp::branchTarget
std::unique_ptr< PCStateBase > branchTarget(ThreadContext *tc) const override
Return the target address for an indirect branch (jump).
Definition: branch.cc:161
gem5::PowerISA::BranchDispCondOp::generateDisassembly
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: branch.cc:125
gem5::PowerISA::PCDependentDisassembly::cachedPC
Addr cachedPC
Cached program counter from last disassembly.
Definition: branch.hh:54

Generated on Tue Feb 8 2022 11:46:56 for gem5 by doxygen 1.8.17