gem5  v20.1.0.0
branch.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006-2007 The Regents of The University of Michigan
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 
30 
32 //
33 // Branch instructions
34 //
35 
36 namespace SparcISA
37 {
38 
39 template class BranchNBits<19>;
40 template class BranchNBits<22>;
41 template class BranchNBits<30>;
42 
43 std::string
45 {
46  std::stringstream response;
47 
48  printMnemonic(response, mnemonic);
51  response << ", ";
52  printDestReg(response, 0);
53 
54  return response.str();
55 }
56 
57 std::string
59  Addr pc, const Loader::SymbolTable *symtab) const
60 {
61  std::stringstream response;
62 
63  printMnemonic(response, mnemonic);
65  if (_numSrcRegs > 0)
66  response << ", ";
67  ccprintf(response, "0x%x", imm);
68  if (_numDestRegs > 0)
69  response << ", ";
70  printDestReg(response, 0);
71 
72  return response.str();
73 }
74 
75 std::string
77  Addr pc, const Loader::SymbolTable *symtab) const
78 {
79  std::stringstream response;
80 
81  Addr target = disp + pc;
82 
83  printMnemonic(response, mnemonic);
84  ccprintf(response, "%#x", target);
85 
87  if (symtab && (it = symtab->findNearest(target)) != symtab->end()) {
88  ccprintf(response, " <%s", it->name);
89  if (it->address != target)
90  ccprintf(response, "+%d>", target - it->address);
91  else
92  ccprintf(response, ">");
93  }
94 
95  return response.str();
96 }
97 
98 }
Loader::SymbolTable::findNearest
const_iterator findNearest(Addr addr, Addr &nextaddr) const
Find the nearest symbol equal to or less than the supplied address (e.g., the label for the enclosing...
Definition: symtab.hh:209
SparcISA::BranchDisp::disp
int32_t disp
Definition: branch.hh:68
SparcISA::SparcStaticInst::printDestReg
void printDestReg(std::ostream &os, int reg) const
Definition: static_inst.cc:88
Loader::SymbolTable
Definition: symtab.hh:59
SparcISA::Branch::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: branch.cc:44
SparcISA::BranchImm13::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: branch.cc:58
SparcISA
Definition: asi.cc:31
SparcISA::BranchDisp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: branch.cc:76
SparcISA::BranchImm13::imm
int32_t imm
Definition: branch.hh:115
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
StaticInst::_srcRegIdx
RegId _srcRegIdx[MaxInstSrcRegs]
See srcRegIdx().
Definition: static_inst.hh:250
SparcISA::SparcStaticInst::printRegArray
void printRegArray(std::ostream &os, const RegId indexArray[], int num) const
Definition: static_inst.cc:62
StaticInst::mnemonic
const char * mnemonic
Base mnemonic (e.g., "add").
Definition: static_inst.hh:258
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Loader::SymbolTable::end
const_iterator end() const
Definition: symtab.hh:126
SparcISA::SparcStaticInst::printMnemonic
static void printMnemonic(std::ostream &os, const char *mnemonic)
Definition: static_inst.cc:56
Loader::SymbolTable::const_iterator
SymbolVector::const_iterator const_iterator
Definition: symtab.hh:123
ccprintf
void ccprintf(cp::Print &print)
Definition: cprintf.hh:127
branch.hh
StaticInst::_numSrcRegs
int8_t _numSrcRegs
See numSrcRegs().
Definition: static_inst.hh:105
StaticInst::_numDestRegs
int8_t _numDestRegs
See numDestRegs().
Definition: static_inst.hh:108

Generated on Wed Sep 30 2020 14:02:00 for gem5 by doxygen 1.8.17