1/*
2 * Copyright (c) 2006-2007 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Gabe Black
29 *          Steve Reinhardt
30 */
31
32#include "arch/sparc/insts/branch.hh"
33
34////////////////////////////////////////////////////////////////////
35//
36// Branch instructions
37//
38
39namespace SparcISA
40{
41
42template class BranchNBits<19>;
43template class BranchNBits<22>;
44template class BranchNBits<30>;
45
46std::string
47Branch::generateDisassembly(Addr pc, const SymbolTable *symtab) const
48{
49    std::stringstream response;
50
51    printMnemonic(response, mnemonic);
52    printRegArray(response, _srcRegIdx, _numSrcRegs);
53    if (_numDestRegs && _numSrcRegs)
54            response << ", ";
55    printDestReg(response, 0);
56
57    return response.str();
58}
59
60std::string
61BranchImm13::generateDisassembly(Addr pc, const SymbolTable *symtab) const
62{
63    std::stringstream response;
64
65    printMnemonic(response, mnemonic);
66    printRegArray(response, _srcRegIdx, _numSrcRegs);
67    if (_numSrcRegs > 0)
68        response << ", ";
69    ccprintf(response, "0x%x", imm);
70    if (_numDestRegs > 0)
71        response << ", ";
72    printDestReg(response, 0);
73
74    return response.str();
75}
76
77std::string
78BranchDisp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
79{
80    std::stringstream response;
81    std::string symbol;
82    Addr symbol_addr;
83
84    Addr target = disp + pc;
85
86    printMnemonic(response, mnemonic);
87    ccprintf(response, "0x%x", target);
88
89    if (symtab && symtab->findNearestSymbol(target, symbol, symbol_addr)) {
90        ccprintf(response, " <%s", symbol);
91        if (symbol_addr != target)
92            ccprintf(response, "+%d>", target - symbol_addr);
93        else
94            ccprintf(response, ">");
95    }
96
97    return response.str();
98}
99
100}
101