112288Sgabeblack@google.com/*
212288Sgabeblack@google.com * Copyright (c) 2006-2007 The Regents of The University of Michigan
312288Sgabeblack@google.com * All rights reserved.
412288Sgabeblack@google.com *
512288Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
612288Sgabeblack@google.com * modification, are permitted provided that the following conditions are
712288Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
812288Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
912288Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1012288Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1112288Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1212288Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1312288Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1412288Sgabeblack@google.com * this software without specific prior written permission.
1512288Sgabeblack@google.com *
1612288Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712288Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812288Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912288Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012288Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112288Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212288Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312288Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412288Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512288Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612288Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712288Sgabeblack@google.com *
2812288Sgabeblack@google.com * Authors: Gabe Black
2912288Sgabeblack@google.com *          Steve Reinhardt
3012288Sgabeblack@google.com */
3112288Sgabeblack@google.com
3212288Sgabeblack@google.com#include "arch/sparc/insts/branch.hh"
3312288Sgabeblack@google.com
3412288Sgabeblack@google.com////////////////////////////////////////////////////////////////////
3512288Sgabeblack@google.com//
3612288Sgabeblack@google.com// Branch instructions
3712288Sgabeblack@google.com//
3812288Sgabeblack@google.com
3912288Sgabeblack@google.comnamespace SparcISA
4012288Sgabeblack@google.com{
4112288Sgabeblack@google.com
4212288Sgabeblack@google.comtemplate class BranchNBits<19>;
4312288Sgabeblack@google.comtemplate class BranchNBits<22>;
4412288Sgabeblack@google.comtemplate class BranchNBits<30>;
4512288Sgabeblack@google.com
4612288Sgabeblack@google.comstd::string
4712288Sgabeblack@google.comBranch::generateDisassembly(Addr pc, const SymbolTable *symtab) const
4812288Sgabeblack@google.com{
4912288Sgabeblack@google.com    std::stringstream response;
5012288Sgabeblack@google.com
5112288Sgabeblack@google.com    printMnemonic(response, mnemonic);
5212288Sgabeblack@google.com    printRegArray(response, _srcRegIdx, _numSrcRegs);
5312288Sgabeblack@google.com    if (_numDestRegs && _numSrcRegs)
5412288Sgabeblack@google.com            response << ", ";
5512288Sgabeblack@google.com    printDestReg(response, 0);
5612288Sgabeblack@google.com
5712288Sgabeblack@google.com    return response.str();
5812288Sgabeblack@google.com}
5912288Sgabeblack@google.com
6012288Sgabeblack@google.comstd::string
6112288Sgabeblack@google.comBranchImm13::generateDisassembly(Addr pc, const SymbolTable *symtab) const
6212288Sgabeblack@google.com{
6312288Sgabeblack@google.com    std::stringstream response;
6412288Sgabeblack@google.com
6512288Sgabeblack@google.com    printMnemonic(response, mnemonic);
6612288Sgabeblack@google.com    printRegArray(response, _srcRegIdx, _numSrcRegs);
6712288Sgabeblack@google.com    if (_numSrcRegs > 0)
6812288Sgabeblack@google.com        response << ", ";
6912288Sgabeblack@google.com    ccprintf(response, "0x%x", imm);
7012288Sgabeblack@google.com    if (_numDestRegs > 0)
7112288Sgabeblack@google.com        response << ", ";
7212288Sgabeblack@google.com    printDestReg(response, 0);
7312288Sgabeblack@google.com
7412288Sgabeblack@google.com    return response.str();
7512288Sgabeblack@google.com}
7612288Sgabeblack@google.com
7712288Sgabeblack@google.comstd::string
7812288Sgabeblack@google.comBranchDisp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
7912288Sgabeblack@google.com{
8012288Sgabeblack@google.com    std::stringstream response;
8112288Sgabeblack@google.com    std::string symbol;
8212288Sgabeblack@google.com    Addr symbol_addr;
8312288Sgabeblack@google.com
8412288Sgabeblack@google.com    Addr target = disp + pc;
8512288Sgabeblack@google.com
8612288Sgabeblack@google.com    printMnemonic(response, mnemonic);
8712288Sgabeblack@google.com    ccprintf(response, "0x%x", target);
8812288Sgabeblack@google.com
8912288Sgabeblack@google.com    if (symtab && symtab->findNearestSymbol(target, symbol, symbol_addr)) {
9012288Sgabeblack@google.com        ccprintf(response, " <%s", symbol);
9112288Sgabeblack@google.com        if (symbol_addr != target)
9212288Sgabeblack@google.com            ccprintf(response, "+%d>", target - symbol_addr);
9312288Sgabeblack@google.com        else
9412288Sgabeblack@google.com            ccprintf(response, ">");
9512288Sgabeblack@google.com    }
9612288Sgabeblack@google.com
9712288Sgabeblack@google.com    return response.str();
9812288Sgabeblack@google.com}
9912288Sgabeblack@google.com
10012288Sgabeblack@google.com}
101