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
;
56 BranchPCRel::branchTarget(const PowerISA::PCState
&pc
) const
58 return (uint32_t)(pc
.pc() + disp
);
62 BranchPCRel::generateDisassembly(
63 Addr pc
, const Loader::SymbolTable
*symtab
) const
67 ccprintf(ss
, "%-10s ", mnemonic
);
69 Addr target
= pc
+ disp
;
71 Loader::SymbolTable::const_iterator it
;
72 if (symtab
&& (it
= symtab
->find(target
)) != symtab
->end())
75 ccprintf(ss
, "%#x", target
);
81 BranchNonPCRel::branchTarget(const PowerISA::PCState
&pc
) const
87 BranchNonPCRel::generateDisassembly(
88 Addr pc
, const Loader::SymbolTable
*symtab
) const
92 ccprintf(ss
, "%-10s ", mnemonic
);
94 Loader::SymbolTable::const_iterator it
;
95 if (symtab
&& (it
= symtab
->find(targetAddr
)) != symtab
->end())
98 ccprintf(ss
, "%#x", targetAddr
);
104 BranchPCRelCond::branchTarget(const PowerISA::PCState
&pc
) const
106 return (uint32_t)(pc
.pc() + disp
);
110 BranchPCRelCond::generateDisassembly(
111 Addr pc
, const Loader::SymbolTable
*symtab
) const
113 std::stringstream ss
;
115 ccprintf(ss
, "%-10s ", mnemonic
);
117 ss
<< bo
<< ", " << bi
<< ", ";
119 Addr target
= pc
+ disp
;
121 Loader::SymbolTable::const_iterator it
;
122 if (symtab
&& (it
= symtab
->find(target
)) != symtab
->end())
125 ccprintf(ss
, "%#x", target
);
131 BranchNonPCRelCond::branchTarget(const PowerISA::PCState
&pc
) const
137 BranchNonPCRelCond::generateDisassembly(
138 Addr pc
, const Loader::SymbolTable
*symtab
) const
140 std::stringstream ss
;
142 ccprintf(ss
, "%-10s ", mnemonic
);
144 ss
<< bo
<< ", " << bi
<< ", ";
146 Loader::SymbolTable::const_iterator it
;
147 if (symtab
&& (it
= symtab
->find(targetAddr
)) != symtab
->end())
150 ccprintf(ss
, "%#x", targetAddr
);
156 BranchRegCond::branchTarget(ThreadContext
*tc
) const
158 uint32_t regVal
= tc
->readIntReg(_srcRegIdx
[_numSrcRegs
- 1].index());
159 return regVal
& 0xfffffffc;
163 BranchRegCond::generateDisassembly(
164 Addr pc
, const Loader::SymbolTable
*symtab
) const
166 std::stringstream ss
;
168 ccprintf(ss
, "%-10s ", mnemonic
);
170 ss
<< bo
<< ", " << bi
<< ", ";