gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
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#include "base/loader/symtab.hh"
31
33//
34// Branch instructions
35//
36
37namespace gem5
38{
39
40namespace SparcISA
41{
42
43template class BranchNBits<19>;
44template class BranchNBits<22>;
45template class BranchNBits<30>;
46
47std::string
49{
50 std::stringstream response;
51
52 printMnemonic(response, mnemonic);
53 printRegArray(response, &srcRegIdx(0), _numSrcRegs);
55 response << ", ";
56 printDestReg(response, 0);
57
58 return response.str();
59}
60
61std::string
63 Addr pc, const loader::SymbolTable *symtab) const
64{
65 std::stringstream response;
66
67 printMnemonic(response, mnemonic);
68 printRegArray(response, &srcRegIdx(0), _numSrcRegs);
69 if (_numSrcRegs > 0)
70 response << ", ";
71 ccprintf(response, "0x%x", imm);
72 if (_numDestRegs > 0)
73 response << ", ";
74 printDestReg(response, 0);
75
76 return response.str();
77}
78
79std::string
81 Addr pc, const loader::SymbolTable *symtab) const
82{
83 std::stringstream response;
84
85 Addr target = disp + pc;
86
87 printMnemonic(response, mnemonic);
88 ccprintf(response, "%#x", target);
89
91 if (symtab && (it = symtab->findNearest(target)) != symtab->end()) {
92 ccprintf(response, " <%s", it->name());
93 if (it->address() != target)
94 ccprintf(response, "+%d>", target - it->address());
95 else
96 ccprintf(response, ">");
97 }
98
99 return response.str();
100}
101
102} // namespace SparcISA
103} // namespace gem5
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition branch.cc:80
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition branch.cc:62
Base class for branches with n bit displacements.
Definition branch.hh:79
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition branch.cc:48
void printRegArray(std::ostream &os, const RegId *indexArray, int num) const
static void printMnemonic(std::ostream &os, const char *mnemonic)
void printDestReg(std::ostream &os, int reg) const
uint8_t _numSrcRegs
See numSrcRegs().
uint8_t _numDestRegs
See numDestRegs().
const char * mnemonic
Base mnemonic (e.g., "add").
const RegId & srcRegIdx(int i) const
Return logical index (architectural reg num) of i'th source reg.
SymbolVector::const_iterator const_iterator
Definition symtab.hh:272
const_iterator end() const
Definition symtab.hh:278
const_iterator findNearest(Addr addr, Addr &next_addr) const
Find the nearest symbol equal to or less than the supplied address (e.g., the label for the enclosing...
Definition symtab.hh:474
Bitfield< 4 > pc
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
void ccprintf(cp::Print &print)
Definition cprintf.hh:130

Generated on Mon Oct 27 2025 04:12:58 for gem5 by doxygen 1.14.0