branch.cc revision 7144:097e00bcf084
12405SN/A/* Copyright (c) 2007-2008 The Florida State University
210713Sandreas.hansson@arm.com * All rights reserved.
38922Swilliam.wang@arm.com *
48922Swilliam.wang@arm.com * Redistribution and use in source and binary forms, with or without
58922Swilliam.wang@arm.com * modification, are permitted provided that the following conditions are
68922Swilliam.wang@arm.com * met: redistributions of source code must retain the above copyright
78922Swilliam.wang@arm.com * notice, this list of conditions and the following disclaimer;
88922Swilliam.wang@arm.com * redistributions in binary form must reproduce the above copyright
98922Swilliam.wang@arm.com * notice, this list of conditions and the following disclaimer in the
108922Swilliam.wang@arm.com * documentation and/or other materials provided with the distribution;
118922Swilliam.wang@arm.com * neither the name of the copyright holders nor the names of its
128922Swilliam.wang@arm.com * contributors may be used to endorse or promote products derived from
138922Swilliam.wang@arm.com * this software without specific prior written permission.
142405SN/A *
152405SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
162405SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
172405SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
182405SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
192405SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
202405SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
212405SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
222405SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
232405SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
242405SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
252405SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
262405SN/A *
272405SN/A * Authors: Stephen Hines
282405SN/A */
292405SN/A
302405SN/A#include "arch/arm/insts/branch.hh"
312405SN/A#include "base/loader/symtab.hh"
322405SN/A
332405SN/Anamespace ArmISA
342405SN/A{
352405SN/AAddr
362405SN/ABranch::branchTarget(Addr branchPC) const
372405SN/A{
382405SN/A    return branchPC + 8 + disp;
392665Ssaidi@eecs.umich.edu}
402665Ssaidi@eecs.umich.edu
418922Swilliam.wang@arm.comconst std::string &
428922Swilliam.wang@arm.comPCDependentDisassembly::disassemble(Addr pc,
432405SN/A                                    const SymbolTable *symtab) const
442405SN/A{
452405SN/A    if (!cachedDisassembly ||
462982Sstever@eecs.umich.edu        pc != cachedPC || symtab != cachedSymtab)
472982Sstever@eecs.umich.edu    {
482405SN/A        if (cachedDisassembly)
492642Sstever@eecs.umich.edu            delete cachedDisassembly;
504190Ssaidi@eecs.umich.edu
512405SN/A        cachedDisassembly =
522405SN/A            new std::string(generateDisassembly(pc, symtab));
539031Sandreas.hansson@arm.com        cachedPC = pc;
549087Sandreas.hansson@arm.com        cachedSymtab = symtab;
555476Snate@binkert.org    }
565476Snate@binkert.org
575476Snate@binkert.org    return *cachedDisassembly;
585476Snate@binkert.org}
595283Sgblack@eecs.umich.edu
605283Sgblack@eecs.umich.edustd::string
615283Sgblack@eecs.umich.eduBranch::generateDisassembly(Addr pc, const SymbolTable *symtab) const
629294Sandreas.hansson@arm.com{
639294Sandreas.hansson@arm.com    std::stringstream ss;
649294Sandreas.hansson@arm.com
659294Sandreas.hansson@arm.com    printMnemonic(ss);
669294Sandreas.hansson@arm.com    ss << "\t";
679294Sandreas.hansson@arm.com
689294Sandreas.hansson@arm.com    Addr target = pc + 8 + disp;
699294Sandreas.hansson@arm.com    ccprintf(ss, "%#x", target);
709294Sandreas.hansson@arm.com    printMemSymbol(ss, symtab, " <", target, ">");
719294Sandreas.hansson@arm.com
729294Sandreas.hansson@arm.com    return ss.str();
739294Sandreas.hansson@arm.com}
749294Sandreas.hansson@arm.com
7511321Ssteve.reinhardt@amd.comstd::string
769294Sandreas.hansson@arm.comBranchExchange::generateDisassembly(Addr pc, const SymbolTable *symtab) const
779294Sandreas.hansson@arm.com{
789294Sandreas.hansson@arm.com    std::stringstream ss;
799294Sandreas.hansson@arm.com    printMnemonic(ss);
809294Sandreas.hansson@arm.com    if (_numSrcRegs > 0) {
819294Sandreas.hansson@arm.com        printReg(ss, _srcRegIdx[0]);
829294Sandreas.hansson@arm.com    }
839294Sandreas.hansson@arm.com    return ss.str();
849294Sandreas.hansson@arm.com}
859294Sandreas.hansson@arm.com}
869294Sandreas.hansson@arm.com