branch.cc revision 6253:988a001820f8
11689SN/A/* Copyright (c) 2007-2008 The Florida State University 22329SN/A * All rights reserved. 31689SN/A * 41689SN/A * Redistribution and use in source and binary forms, with or without 51689SN/A * modification, are permitted provided that the following conditions are 61689SN/A * met: redistributions of source code must retain the above copyright 71689SN/A * notice, this list of conditions and the following disclaimer; 81689SN/A * redistributions in binary form must reproduce the above copyright 91689SN/A * notice, this list of conditions and the following disclaimer in the 101689SN/A * documentation and/or other materials provided with the distribution; 111689SN/A * neither the name of the copyright holders nor the names of its 121689SN/A * contributors may be used to endorse or promote products derived from 131689SN/A * this software without specific prior written permission. 141689SN/A * 151689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 161689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 171689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 181689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 191689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 201689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 211689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 221689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 231689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 241689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 251689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 261689SN/A * 272665Ssaidi@eecs.umich.edu * Authors: Stephen Hines 282665Ssaidi@eecs.umich.edu */ 291689SN/A 301061SN/A#include "arch/arm/insts/branch.hh" 311061SN/A#include "base/loader/symtab.hh" 321061SN/A 332292SN/Anamespace ArmISA 341717SN/A{ 351061SN/AAddr 361061SN/ABranch::branchTarget(Addr branchPC) const 373500Sktlim@umich.edu{ 383500Sktlim@umich.edu return branchPC + 8 + disp; 393500Sktlim@umich.edu} 403500Sktlim@umich.edu 413500Sktlim@umich.eduAddr 423500Sktlim@umich.eduJump::branchTarget(ThreadContext *tc) const 433500Sktlim@umich.edu{ 442292SN/A Addr NPC = tc->readPC() + 8; 452292SN/A uint64_t Rb = tc->readIntReg(_srcRegIdx[0]); 462292SN/A return (Rb & ~3) | (NPC & 1); 471061SN/A} 482292SN/A 492292SN/Aconst std::string & 502292SN/APCDependentDisassembly::disassemble(Addr pc, 512292SN/A const SymbolTable *symtab) const 522292SN/A{ 532292SN/A if (!cachedDisassembly || 542292SN/A pc != cachedPC || symtab != cachedSymtab) 552292SN/A { 562292SN/A if (cachedDisassembly) 572292SN/A delete cachedDisassembly; 582292SN/A 592292SN/A cachedDisassembly = 602292SN/A new std::string(generateDisassembly(pc, symtab)); 612292SN/A cachedPC = pc; 622292SN/A cachedSymtab = symtab; 632292SN/A } 642292SN/A 652292SN/A return *cachedDisassembly; 662292SN/A} 672292SN/A 682292SN/Astd::string 692292SN/ABranch::generateDisassembly(Addr pc, const SymbolTable *symtab) const 702292SN/A{ 712678Sktlim@umich.edu std::stringstream ss; 722292SN/A 732678Sktlim@umich.edu ccprintf(ss, "%-10s ", mnemonic); 742292SN/A 752292SN/A Addr target = pc + 8 + disp; 762292SN/A 772292SN/A std::string str; 782292SN/A if (symtab && symtab->findSymbol(target, str)) 792292SN/A ss << str; 802292SN/A else 812292SN/A ccprintf(ss, "0x%x", target); 822292SN/A 832292SN/A return ss.str(); 842292SN/A} 852292SN/A 862292SN/Astd::string 872292SN/ABranchExchange::generateDisassembly(Addr pc, const SymbolTable *symtab) const 882292SN/A{ 892292SN/A std::stringstream ss; 902292SN/A 912292SN/A ccprintf(ss, "%-10s ", mnemonic); 921061SN/A 931061SN/A if (_numSrcRegs > 0) { 941061SN/A printReg(ss, _srcRegIdx[0]); 951061SN/A } 961062SN/A 971062SN/A return ss.str(); 981062SN/A} 991062SN/A 1001062SN/Astd::string 1011062SN/AJump::generateDisassembly(Addr pc, const SymbolTable *symtab) const 1021062SN/A{ 1031062SN/A std::stringstream ss; 1041062SN/A 1051062SN/A ccprintf(ss, "%-10s ", mnemonic); 1061062SN/A 1071062SN/A return ss.str(); 1081062SN/A} 1091062SN/A} 1101062SN/A