gem5 v24.0.0.0
Loading...
Searching...
No Matches
branch.cc
Go to the documentation of this file.
1/*
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
33
34#include "base/loader/symtab.hh"
35#include "cpu/thread_context.hh"
36
37namespace gem5
38{
39
40using namespace PowerISA;
41
42const std::string &
44 Addr pc, const loader::SymbolTable *symtab) const
45{
46 if (!cachedDisassembly || pc != cachedPC || symtab != cachedSymtab) {
48 cachedDisassembly.reset(new std::string);
49
51 cachedPC = pc;
52 cachedSymtab = symtab;
53 }
54
55 return *cachedDisassembly;
56}
57
58
59std::unique_ptr<PCStateBase>
61{
62 Msr msr = tc->getReg(int_reg::Msr);
63 Addr addr;
64
65 if (aa)
66 addr = li;
67 else
68 addr = tc->pcState().instAddr() + li;
69
70 return std::make_unique<PowerISA::PCState>(
71 msr.sf ? addr : addr & UINT32_MAX);
72}
73
74
75std::string
77 Addr pc, const loader::SymbolTable *symtab) const
78{
79 std::stringstream ss;
80 Addr target;
81
82 // Generate correct mnemonic
83 std::string myMnemonic(mnemonic);
84 std::string suffix;
85
86 // Additional characters depending on isa bits being set
87 if (lk)
88 suffix += "l";
89 if (aa)
90 suffix += "a";
91 ccprintf(ss, "%-10s ", myMnemonic + suffix);
92
93 if (aa)
94 target = li;
95 else
96 target = pc + li;
97
99 if (symtab && (it = symtab->find(target)) != symtab->end())
100 ss << it->name();
101 else
102 ccprintf(ss, "%#x", target);
103
104 return ss.str();
105}
106
107
108std::unique_ptr<PCStateBase>
110{
111 Msr msr = tc->getReg(int_reg::Msr);
112 Addr addr;
113
114 if (aa)
115 addr = bd;
116 else
117 addr = tc->pcState().instAddr() + bd;
118
119 return std::make_unique<PowerISA::PCState>(
120 msr.sf ? addr : addr & UINT32_MAX);
121}
122
123
124std::string
126 Addr pc, const loader::SymbolTable *symtab) const
127{
128 std::stringstream ss;
129 Addr target;
130
131 // Generate the correct mnemonic
132 std::string myMnemonic(mnemonic);
133 std::string suffix;
134
135 // Additional characters depending on isa bits being set
136 if (lk)
137 suffix += "l";
138 if (aa)
139 suffix += "a";
140 ccprintf(ss, "%-10s ", myMnemonic + suffix);
141
142 // Print BI and BO fields
143 ss << (int) bi << ", " << (int) bo << ", ";
144
145 if (aa)
146 target = bd;
147 else
148 target = pc + bd;
149
151 if (symtab && (it = symtab->find(target)) != symtab->end())
152 ss << it->name();
153 else
154 ccprintf(ss, "%#x", target);
155
156 return ss.str();
157}
158
159
160std::unique_ptr<PCStateBase>
162{
163 Msr msr = tc->getReg(int_reg::Msr);
164 Addr addr = tc->getReg(srcRegIdx(_numSrcRegs - 1)) & -4ULL;
165 return std::make_unique<PowerISA::PCState>(
166 msr.sf ? addr : addr & UINT32_MAX);
167}
168
169
170std::string
172 Addr pc, const loader::SymbolTable *symtab) const
173{
174 std::stringstream ss;
175
176 // Generate the correct mnemonic
177 std::string myMnemonic(mnemonic);
178 std::string suffix;
179
180 // Additional characters depending on isa bits being set
181 if (lk)
182 suffix += "l";
183 ccprintf(ss, "%-10s ", myMnemonic + suffix);
184
185 // Print the BI and BO fields
186 ss << (int) bi << ", " << (int) bo;
187
188 return ss.str();
189}
190
191} // namespace gem5
Addr instAddr() const
Returns the memory address of the instruction this PC points to.
Definition pcstate.hh:108
std::unique_ptr< PCStateBase > branchTarget(ThreadContext *tc) const override
Return the target address for an indirect branch (jump).
Definition branch.cc:109
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition branch.cc:125
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition branch.cc:76
std::unique_ptr< PCStateBase > branchTarget(ThreadContext *tc) const override
Return the target address for an indirect branch (jump).
Definition branch.cc:60
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition branch.cc:171
std::unique_ptr< PCStateBase > branchTarget(ThreadContext *tc) const override
Return the target address for an indirect branch (jump).
Definition branch.cc:161
const loader::SymbolTable * cachedSymtab
Cached symbol table pointer from last disassembly.
Definition branch.hh:56
Addr cachedPC
Cached program counter from last disassembly.
Definition branch.hh:54
const std::string & disassemble(Addr pc, const loader::SymbolTable *symtab) const
Return string representation of disassembled instruction.
Definition branch.cc:43
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
std::unique_ptr< std::string > cachedDisassembly
String representation of disassembly (lazily evaluated via disassemble()).
uint8_t _numSrcRegs
See numSrcRegs().
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.
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual RegVal getReg(const RegId &reg) const
virtual const PCStateBase & pcState() const =0
SymbolVector::const_iterator const_iterator
Definition symtab.hh:272
const_iterator end() const
Definition symtab.hh:278
const_iterator find(Addr address) const
Search for a symbol by its address.
Definition symtab.hh:435
Bitfield< 21 > ss
Definition misc_types.hh:60
Bitfield< 4 > pc
constexpr RegId Msr
Definition int.hh:144
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria 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 Tue Jun 18 2024 16:23:57 for gem5 by doxygen 1.11.0