dyn_inst.cc revision 10259
110259SAndrew.Bardsley@arm.com/* 210259SAndrew.Bardsley@arm.com * Copyright (c) 2013-2014 ARM Limited 310259SAndrew.Bardsley@arm.com * All rights reserved 410259SAndrew.Bardsley@arm.com * 510259SAndrew.Bardsley@arm.com * The license below extends only to copyright in the software and shall 610259SAndrew.Bardsley@arm.com * not be construed as granting a license to any other intellectual 710259SAndrew.Bardsley@arm.com * property including but not limited to intellectual property relating 810259SAndrew.Bardsley@arm.com * to a hardware implementation of the functionality of the software 910259SAndrew.Bardsley@arm.com * licensed hereunder. You may use the software subject to the license 1010259SAndrew.Bardsley@arm.com * terms below provided that you ensure that this notice is replicated 1110259SAndrew.Bardsley@arm.com * unmodified and in its entirety in all distributions of the software, 1210259SAndrew.Bardsley@arm.com * modified or unmodified, in source code or in binary form. 1310259SAndrew.Bardsley@arm.com * 1410259SAndrew.Bardsley@arm.com * Redistribution and use in source and binary forms, with or without 1510259SAndrew.Bardsley@arm.com * modification, are permitted provided that the following conditions are 1610259SAndrew.Bardsley@arm.com * met: redistributions of source code must retain the above copyright 1710259SAndrew.Bardsley@arm.com * notice, this list of conditions and the following disclaimer; 1810259SAndrew.Bardsley@arm.com * redistributions in binary form must reproduce the above copyright 1910259SAndrew.Bardsley@arm.com * notice, this list of conditions and the following disclaimer in the 2010259SAndrew.Bardsley@arm.com * documentation and/or other materials provided with the distribution; 2110259SAndrew.Bardsley@arm.com * neither the name of the copyright holders nor the names of its 2210259SAndrew.Bardsley@arm.com * contributors may be used to endorse or promote products derived from 2310259SAndrew.Bardsley@arm.com * this software without specific prior written permission. 2410259SAndrew.Bardsley@arm.com * 2510259SAndrew.Bardsley@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2610259SAndrew.Bardsley@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2710259SAndrew.Bardsley@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2810259SAndrew.Bardsley@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2910259SAndrew.Bardsley@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3010259SAndrew.Bardsley@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3110259SAndrew.Bardsley@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3210259SAndrew.Bardsley@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3310259SAndrew.Bardsley@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3410259SAndrew.Bardsley@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3510259SAndrew.Bardsley@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3610259SAndrew.Bardsley@arm.com * 3710259SAndrew.Bardsley@arm.com * Authors: Andrew Bardsley 3810259SAndrew.Bardsley@arm.com */ 3910259SAndrew.Bardsley@arm.com 4010259SAndrew.Bardsley@arm.com#include <iomanip> 4110259SAndrew.Bardsley@arm.com#include <sstream> 4210259SAndrew.Bardsley@arm.com 4310259SAndrew.Bardsley@arm.com#include "arch/isa.hh" 4410259SAndrew.Bardsley@arm.com#include "arch/registers.hh" 4510259SAndrew.Bardsley@arm.com#include "cpu/minor/dyn_inst.hh" 4610259SAndrew.Bardsley@arm.com#include "cpu/minor/trace.hh" 4710259SAndrew.Bardsley@arm.com#include "cpu/base.hh" 4810259SAndrew.Bardsley@arm.com#include "cpu/reg_class.hh" 4910259SAndrew.Bardsley@arm.com#include "debug/MinorExecute.hh" 5010259SAndrew.Bardsley@arm.com#include "enums/OpClass.hh" 5110259SAndrew.Bardsley@arm.com 5210259SAndrew.Bardsley@arm.comnamespace Minor 5310259SAndrew.Bardsley@arm.com{ 5410259SAndrew.Bardsley@arm.com 5510259SAndrew.Bardsley@arm.comstd::ostream & 5610259SAndrew.Bardsley@arm.comoperator <<(std::ostream &os, const InstId &id) 5710259SAndrew.Bardsley@arm.com{ 5810259SAndrew.Bardsley@arm.com os << id.threadId << '/' << id.streamSeqNum << '.' 5910259SAndrew.Bardsley@arm.com << id.predictionSeqNum << '/' << id.lineSeqNum; 6010259SAndrew.Bardsley@arm.com 6110259SAndrew.Bardsley@arm.com /* Not all structures have fetch and exec sequence numbers */ 6210259SAndrew.Bardsley@arm.com if (id.fetchSeqNum != 0) { 6310259SAndrew.Bardsley@arm.com os << '/' << id.fetchSeqNum; 6410259SAndrew.Bardsley@arm.com if (id.execSeqNum != 0) 6510259SAndrew.Bardsley@arm.com os << '.' << id.execSeqNum; 6610259SAndrew.Bardsley@arm.com } 6710259SAndrew.Bardsley@arm.com 6810259SAndrew.Bardsley@arm.com return os; 6910259SAndrew.Bardsley@arm.com} 7010259SAndrew.Bardsley@arm.com 7110259SAndrew.Bardsley@arm.comMinorDynInstPtr MinorDynInst::bubbleInst = NULL; 7210259SAndrew.Bardsley@arm.com 7310259SAndrew.Bardsley@arm.comvoid 7410259SAndrew.Bardsley@arm.comMinorDynInst::init() 7510259SAndrew.Bardsley@arm.com{ 7610259SAndrew.Bardsley@arm.com if (!bubbleInst) { 7710259SAndrew.Bardsley@arm.com bubbleInst = new MinorDynInst(); 7810259SAndrew.Bardsley@arm.com assert(bubbleInst->isBubble()); 7910259SAndrew.Bardsley@arm.com /* Make bubbleInst immortal */ 8010259SAndrew.Bardsley@arm.com bubbleInst->incref(); 8110259SAndrew.Bardsley@arm.com } 8210259SAndrew.Bardsley@arm.com} 8310259SAndrew.Bardsley@arm.com 8410259SAndrew.Bardsley@arm.combool 8510259SAndrew.Bardsley@arm.comMinorDynInst::isLastOpInInst() const 8610259SAndrew.Bardsley@arm.com{ 8710259SAndrew.Bardsley@arm.com assert(staticInst); 8810259SAndrew.Bardsley@arm.com return !(staticInst->isMicroop() && !staticInst->isLastMicroop()); 8910259SAndrew.Bardsley@arm.com} 9010259SAndrew.Bardsley@arm.com 9110259SAndrew.Bardsley@arm.combool 9210259SAndrew.Bardsley@arm.comMinorDynInst::isNoCostInst() const 9310259SAndrew.Bardsley@arm.com{ 9410259SAndrew.Bardsley@arm.com return isInst() && staticInst->opClass() == No_OpClass; 9510259SAndrew.Bardsley@arm.com} 9610259SAndrew.Bardsley@arm.com 9710259SAndrew.Bardsley@arm.comvoid 9810259SAndrew.Bardsley@arm.comMinorDynInst::reportData(std::ostream &os) const 9910259SAndrew.Bardsley@arm.com{ 10010259SAndrew.Bardsley@arm.com if (isBubble()) 10110259SAndrew.Bardsley@arm.com os << "-"; 10210259SAndrew.Bardsley@arm.com else if (isFault()) 10310259SAndrew.Bardsley@arm.com os << "F;" << id; 10410259SAndrew.Bardsley@arm.com else 10510259SAndrew.Bardsley@arm.com os << id; 10610259SAndrew.Bardsley@arm.com} 10710259SAndrew.Bardsley@arm.com 10810259SAndrew.Bardsley@arm.comstd::ostream & 10910259SAndrew.Bardsley@arm.comoperator <<(std::ostream &os, const MinorDynInst &inst) 11010259SAndrew.Bardsley@arm.com{ 11110259SAndrew.Bardsley@arm.com os << inst.id << " pc: 0x" 11210259SAndrew.Bardsley@arm.com << std::hex << inst.pc.instAddr() << std::dec << " ("; 11310259SAndrew.Bardsley@arm.com 11410259SAndrew.Bardsley@arm.com if (inst.isFault()) 11510259SAndrew.Bardsley@arm.com os << "fault: \"" << inst.fault->name() << '"'; 11610259SAndrew.Bardsley@arm.com else if (inst.staticInst) 11710259SAndrew.Bardsley@arm.com os << inst.staticInst->getName(); 11810259SAndrew.Bardsley@arm.com else 11910259SAndrew.Bardsley@arm.com os << "bubble"; 12010259SAndrew.Bardsley@arm.com 12110259SAndrew.Bardsley@arm.com os << ')'; 12210259SAndrew.Bardsley@arm.com 12310259SAndrew.Bardsley@arm.com return os; 12410259SAndrew.Bardsley@arm.com} 12510259SAndrew.Bardsley@arm.com 12610259SAndrew.Bardsley@arm.com/** Print a register in the form r<n>, f<n>, m<n>(<name>), z for integer, 12710259SAndrew.Bardsley@arm.com * float, misc and zero registers given an 'architectural register number' */ 12810259SAndrew.Bardsley@arm.comstatic void 12910259SAndrew.Bardsley@arm.comprintRegName(std::ostream &os, TheISA::RegIndex reg) 13010259SAndrew.Bardsley@arm.com{ 13110259SAndrew.Bardsley@arm.com RegClass reg_class = regIdxToClass(reg); 13210259SAndrew.Bardsley@arm.com 13310259SAndrew.Bardsley@arm.com switch (reg_class) 13410259SAndrew.Bardsley@arm.com { 13510259SAndrew.Bardsley@arm.com case MiscRegClass: 13610259SAndrew.Bardsley@arm.com { 13710259SAndrew.Bardsley@arm.com TheISA::RegIndex misc_reg = reg - TheISA::Misc_Reg_Base; 13810259SAndrew.Bardsley@arm.com 13910259SAndrew.Bardsley@arm.com /* This is an ugly test because not all archs. have miscRegName */ 14010259SAndrew.Bardsley@arm.com#if THE_ISA == ARM_ISA 14110259SAndrew.Bardsley@arm.com os << 'm' << misc_reg << '(' << TheISA::miscRegName[misc_reg] << 14210259SAndrew.Bardsley@arm.com ')'; 14310259SAndrew.Bardsley@arm.com#else 14410259SAndrew.Bardsley@arm.com os << 'n' << misc_reg; 14510259SAndrew.Bardsley@arm.com#endif 14610259SAndrew.Bardsley@arm.com } 14710259SAndrew.Bardsley@arm.com break; 14810259SAndrew.Bardsley@arm.com case FloatRegClass: 14910259SAndrew.Bardsley@arm.com os << 'f' << static_cast<unsigned int>(reg - TheISA::FP_Reg_Base); 15010259SAndrew.Bardsley@arm.com break; 15110259SAndrew.Bardsley@arm.com case IntRegClass: 15210259SAndrew.Bardsley@arm.com if (reg == TheISA::ZeroReg) { 15310259SAndrew.Bardsley@arm.com os << 'z'; 15410259SAndrew.Bardsley@arm.com } else { 15510259SAndrew.Bardsley@arm.com os << 'r' << static_cast<unsigned int>(reg); 15610259SAndrew.Bardsley@arm.com } 15710259SAndrew.Bardsley@arm.com break; 15810259SAndrew.Bardsley@arm.com case CCRegClass: 15910259SAndrew.Bardsley@arm.com os << 'c' << static_cast<unsigned int>(reg - TheISA::CC_Reg_Base); 16010259SAndrew.Bardsley@arm.com } 16110259SAndrew.Bardsley@arm.com} 16210259SAndrew.Bardsley@arm.com 16310259SAndrew.Bardsley@arm.comvoid 16410259SAndrew.Bardsley@arm.comMinorDynInst::minorTraceInst(const Named &named_object) const 16510259SAndrew.Bardsley@arm.com{ 16610259SAndrew.Bardsley@arm.com if (isFault()) { 16710259SAndrew.Bardsley@arm.com MINORINST(&named_object, "id=F;%s addr=0x%x fault=\"%s\"\n", 16810259SAndrew.Bardsley@arm.com id, pc.instAddr(), fault->name()); 16910259SAndrew.Bardsley@arm.com } else { 17010259SAndrew.Bardsley@arm.com unsigned int num_src_regs = staticInst->numSrcRegs(); 17110259SAndrew.Bardsley@arm.com unsigned int num_dest_regs = staticInst->numDestRegs(); 17210259SAndrew.Bardsley@arm.com 17310259SAndrew.Bardsley@arm.com std::ostringstream regs_str; 17410259SAndrew.Bardsley@arm.com 17510259SAndrew.Bardsley@arm.com /* Format lists of src and dest registers for microops and 17610259SAndrew.Bardsley@arm.com * 'full' instructions */ 17710259SAndrew.Bardsley@arm.com if (!staticInst->isMacroop()) { 17810259SAndrew.Bardsley@arm.com regs_str << " srcRegs="; 17910259SAndrew.Bardsley@arm.com 18010259SAndrew.Bardsley@arm.com unsigned int src_reg = 0; 18110259SAndrew.Bardsley@arm.com while (src_reg < num_src_regs) { 18210259SAndrew.Bardsley@arm.com printRegName(regs_str, staticInst->srcRegIdx(src_reg)); 18310259SAndrew.Bardsley@arm.com 18410259SAndrew.Bardsley@arm.com src_reg++; 18510259SAndrew.Bardsley@arm.com if (src_reg != num_src_regs) 18610259SAndrew.Bardsley@arm.com regs_str << ','; 18710259SAndrew.Bardsley@arm.com } 18810259SAndrew.Bardsley@arm.com 18910259SAndrew.Bardsley@arm.com regs_str << " destRegs="; 19010259SAndrew.Bardsley@arm.com 19110259SAndrew.Bardsley@arm.com unsigned int dest_reg = 0; 19210259SAndrew.Bardsley@arm.com while (dest_reg < num_dest_regs) { 19310259SAndrew.Bardsley@arm.com printRegName(regs_str, staticInst->destRegIdx(dest_reg)); 19410259SAndrew.Bardsley@arm.com 19510259SAndrew.Bardsley@arm.com dest_reg++; 19610259SAndrew.Bardsley@arm.com if (dest_reg != num_dest_regs) 19710259SAndrew.Bardsley@arm.com regs_str << ','; 19810259SAndrew.Bardsley@arm.com } 19910259SAndrew.Bardsley@arm.com 20010259SAndrew.Bardsley@arm.com#if THE_ISA == ARM_ISA 20110259SAndrew.Bardsley@arm.com regs_str << " extMachInst=" << std::hex << std::setw(16) 20210259SAndrew.Bardsley@arm.com << std::setfill('0') << staticInst->machInst << std::dec; 20310259SAndrew.Bardsley@arm.com#endif 20410259SAndrew.Bardsley@arm.com } 20510259SAndrew.Bardsley@arm.com 20610259SAndrew.Bardsley@arm.com std::ostringstream flags; 20710259SAndrew.Bardsley@arm.com staticInst->printFlags(flags, " "); 20810259SAndrew.Bardsley@arm.com 20910259SAndrew.Bardsley@arm.com MINORINST(&named_object, "id=%s addr=0x%x inst=\"%s\" class=%s" 21010259SAndrew.Bardsley@arm.com " flags=\"%s\"%s%s\n", 21110259SAndrew.Bardsley@arm.com id, pc.instAddr(), 21210259SAndrew.Bardsley@arm.com (staticInst->opClass() == No_OpClass ? 21310259SAndrew.Bardsley@arm.com "(invalid)" : staticInst->disassemble(0,NULL)), 21410259SAndrew.Bardsley@arm.com Enums::OpClassStrings[staticInst->opClass()], 21510259SAndrew.Bardsley@arm.com flags.str(), 21610259SAndrew.Bardsley@arm.com regs_str.str(), 21710259SAndrew.Bardsley@arm.com (predictedTaken ? " predictedTaken" : "")); 21810259SAndrew.Bardsley@arm.com } 21910259SAndrew.Bardsley@arm.com} 22010259SAndrew.Bardsley@arm.com 22110259SAndrew.Bardsley@arm.comMinorDynInst::~MinorDynInst() 22210259SAndrew.Bardsley@arm.com{ 22310259SAndrew.Bardsley@arm.com if (traceData) 22410259SAndrew.Bardsley@arm.com delete traceData; 22510259SAndrew.Bardsley@arm.com} 22610259SAndrew.Bardsley@arm.com 22710259SAndrew.Bardsley@arm.com} 228