fce3d3f64827706fb570354327e77cb548416a0d
2 * Copyright (c) 2009 The University of Edinburgh
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.
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.
29 #include "arch/power/insts/branch.hh"
31 #include "base/loader/symtab.hh"
32 #include "cpu/thread_context.hh"
34 using namespace PowerISA
;
37 PCDependentDisassembly::disassemble(
38 Addr pc
, const Loader::SymbolTable
*symtab
) const
40 if (!cachedDisassembly
||
41 pc
!= cachedPC
|| symtab
!= cachedSymtab
)
43 if (cachedDisassembly
)
44 delete cachedDisassembly
;
47 new std::string(generateDisassembly(pc
, symtab
));
49 cachedSymtab
= symtab
;
52 return *cachedDisassembly
;
57 BranchOp::branchTarget(const PowerISA::PCState
&pc
) const
62 return pc
.pc() + disp
;
68 BranchOp::generateDisassembly(Addr pc
, const SymbolTable
*symtab
) const
73 // Generate correct mnemonic
74 std::string
myMnemonic(mnemonic
);
76 // Additional characters depending on isa bits being set
77 if (lkSet
) myMnemonic
= myMnemonic
+ "l";
78 if (aaSet
) myMnemonic
= myMnemonic
+ "a";
79 ccprintf(ss
, "%-10s ", myMnemonic
);
87 Loader::SymbolTable::const_iterator it
;
88 if (symtab
&& (it
= symtab
->find(target
)) != symtab
->end())
91 ccprintf(ss
, "%#x", target
);
98 BranchDispCondOp::branchTarget(const PowerISA::PCState
&pc
) const
103 return pc
.pc() + disp
;
109 BranchDispCondOp::generateDisassembly(Addr pc
, const SymbolTable
*symtab
) const
111 std::stringstream ss
;
114 // Generate the correct mnemonic
115 std::string
myMnemonic(mnemonic
);
117 // Additional characters depending on isa bits being set
118 if (lkSet
) myMnemonic
= myMnemonic
+ "l";
119 if (aaSet
) myMnemonic
= myMnemonic
+ "a";
120 ccprintf(ss
, "%-10s ", myMnemonic
);
122 // Print BI and BO fields
123 ss
<< crBit
<< ", " << opts
<< ", ";
131 Loader::SymbolTable::const_iterator it
;
132 if (symtab
&& (it
= symtab
->find(target
)) != symtab
->end())
135 ccprintf(ss
, "%#x", target
);
142 BranchRegCondOp::branchTarget(ThreadContext
*tc
) const
144 Addr addr
= tc
->readIntReg(_srcRegIdx
[_numSrcRegs
- 1].index());
150 BranchRegCondOp::generateDisassembly(Addr pc
, const SymbolTable
*symtab
) const
152 std::stringstream ss
;
154 // Generate the correct mnemonic
155 std::string
myMnemonic(mnemonic
);
157 // Additional characters depending on isa bits being set
158 if (lkSet
) myMnemonic
= myMnemonic
+ "l";
159 ccprintf(ss
, "%-10s ", mnemonic
);
161 // Print the BI and BO fields
162 ss
<< crBit
<< ", " << opts
;