base_dyn_inst_impl.hh revision 13590
11060SN/A/* 27944SGiacomo.Gabrielli@arm.com * Copyright (c) 2011 ARM Limited 37944SGiacomo.Gabrielli@arm.com * All rights reserved. 47944SGiacomo.Gabrielli@arm.com * 57944SGiacomo.Gabrielli@arm.com * The license below extends only to copyright in the software and shall 67944SGiacomo.Gabrielli@arm.com * not be construed as granting a license to any other intellectual 77944SGiacomo.Gabrielli@arm.com * property including but not limited to intellectual property relating 87944SGiacomo.Gabrielli@arm.com * to a hardware implementation of the functionality of the software 97944SGiacomo.Gabrielli@arm.com * licensed hereunder. You may use the software subject to the license 107944SGiacomo.Gabrielli@arm.com * terms below provided that you ensure that this notice is replicated 117944SGiacomo.Gabrielli@arm.com * unmodified and in its entirety in all distributions of the software, 127944SGiacomo.Gabrielli@arm.com * modified or unmodified, in source code or in binary form. 137944SGiacomo.Gabrielli@arm.com * 142702SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan 151060SN/A * All rights reserved. 161060SN/A * 171060SN/A * Redistribution and use in source and binary forms, with or without 181060SN/A * modification, are permitted provided that the following conditions are 191060SN/A * met: redistributions of source code must retain the above copyright 201060SN/A * notice, this list of conditions and the following disclaimer; 211060SN/A * redistributions in binary form must reproduce the above copyright 221060SN/A * notice, this list of conditions and the following disclaimer in the 231060SN/A * documentation and/or other materials provided with the distribution; 241060SN/A * neither the name of the copyright holders nor the names of its 251060SN/A * contributors may be used to endorse or promote products derived from 261060SN/A * this software without specific prior written permission. 271060SN/A * 281060SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 291060SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 301060SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 311060SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 321060SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 331060SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 341060SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 351060SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 361060SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 371060SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 381060SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665SN/A * 402665SN/A * Authors: Kevin Lim 411060SN/A */ 421060SN/A 439944Smatt.horsnell@ARM.com#ifndef __CPU_BASE_DYN_INST_IMPL_HH__ 449944Smatt.horsnell@ARM.com#define __CPU_BASE_DYN_INST_IMPL_HH__ 459944Smatt.horsnell@ARM.com 461060SN/A#include <iostream> 472292SN/A#include <set> 488229Snate@binkert.org#include <sstream> 491060SN/A#include <string> 501060SN/A 511060SN/A#include "base/cprintf.hh" 521061SN/A#include "base/trace.hh" 536658Snate@binkert.org#include "config/the_isa.hh" 546658Snate@binkert.org#include "cpu/base_dyn_inst.hh" 551060SN/A#include "cpu/exetrace.hh" 568232Snate@binkert.org#include "debug/DynInst.hh" 578232Snate@binkert.org#include "debug/IQ.hh" 582669SN/A#include "mem/request.hh" 596658Snate@binkert.org#include "sim/faults.hh" 601060SN/A 611061SN/Atemplate <class Impl> 6210417Sandreas.hansson@arm.comBaseDynInst<Impl>::BaseDynInst(const StaticInstPtr &_staticInst, 6310417Sandreas.hansson@arm.com const StaticInstPtr &_macroop, 647720Sgblack@eecs.umich.edu TheISA::PCState _pc, TheISA::PCState _predPC, 653794Sgblack@eecs.umich.edu InstSeqNum seq_num, ImplCPU *cpu) 6613453Srekai.gonzalezalberquilla@arm.com : staticInst(_staticInst), cpu(cpu), 6713453Srekai.gonzalezalberquilla@arm.com thread(nullptr), 6813453Srekai.gonzalezalberquilla@arm.com traceData(nullptr), 6913453Srekai.gonzalezalberquilla@arm.com macroop(_macroop), 7013453Srekai.gonzalezalberquilla@arm.com memData(nullptr), 7113453Srekai.gonzalezalberquilla@arm.com savedReq(nullptr), 7213453Srekai.gonzalezalberquilla@arm.com reqToVerify(nullptr) 731060SN/A{ 741464SN/A seqNum = seq_num; 751061SN/A 767720Sgblack@eecs.umich.edu pc = _pc; 777720Sgblack@eecs.umich.edu predPC = _predPC; 784636Sgblack@eecs.umich.edu 794636Sgblack@eecs.umich.edu initVars(); 804636Sgblack@eecs.umich.edu} 814636Sgblack@eecs.umich.edu 824636Sgblack@eecs.umich.edutemplate <class Impl> 8310417Sandreas.hansson@arm.comBaseDynInst<Impl>::BaseDynInst(const StaticInstPtr &_staticInst, 8410417Sandreas.hansson@arm.com const StaticInstPtr &_macroop) 859046SAli.Saidi@ARM.com : staticInst(_staticInst), traceData(NULL), macroop(_macroop) 861464SN/A{ 872292SN/A seqNum = 0; 881464SN/A initVars(); 891464SN/A} 901464SN/A 911464SN/Atemplate <class Impl> 921464SN/Avoid 931464SN/ABaseDynInst<Impl>::initVars() 941464SN/A{ 952678SN/A memData = NULL; 962669SN/A effAddr = 0; 9713590Srekai.gonzalezalberquilla@arm.com physEffAddr = 0; 981060SN/A readyRegs = 0; 9910031SAli.Saidi@ARM.com memReqFlags = 0; 1001060SN/A 1012731SN/A status.reset(); 1022731SN/A 1039046SAli.Saidi@ARM.com instFlags.reset(); 1049046SAli.Saidi@ARM.com instFlags[RecordResult] = true; 1059046SAli.Saidi@ARM.com instFlags[Predicate] = true; 1062731SN/A 1072292SN/A lqIdx = -1; 1082292SN/A sqIdx = -1; 1092292SN/A 1101060SN/A // Eventually make this a parameter. 1111060SN/A threadNumber = 0; 1121464SN/A 1131060SN/A // Also make this a parameter, or perhaps get it from xc or cpu. 1141060SN/A asid = 0; 1151060SN/A 1162698SN/A // Initialize the fault to be NoFault. 1172292SN/A fault = NoFault; 1181060SN/A 1195737Scws3k@cs.virginia.edu#ifndef NDEBUG 1205737Scws3k@cs.virginia.edu ++cpu->instcount; 1211060SN/A 1225737Scws3k@cs.virginia.edu if (cpu->instcount > 1500) { 1235375Svilas.sridharan@gmail.com#ifdef DEBUG 1242292SN/A cpu->dumpInsts(); 1252292SN/A dumpSNList(); 1262292SN/A#endif 1275737Scws3k@cs.virginia.edu assert(cpu->instcount <= 1500); 1282292SN/A } 1292292SN/A 1305737Scws3k@cs.virginia.edu DPRINTF(DynInst, 1315737Scws3k@cs.virginia.edu "DynInst: [sn:%lli] Instruction created. Instcount for %s = %i\n", 1325737Scws3k@cs.virginia.edu seqNum, cpu->name(), cpu->instcount); 1335737Scws3k@cs.virginia.edu#endif 1342292SN/A 1352292SN/A#ifdef DEBUG 1362292SN/A cpu->snList.insert(seqNum); 1372292SN/A#endif 1388733Sgeoffrey.blake@arm.com 1391060SN/A} 1401060SN/A 1411061SN/Atemplate <class Impl> 1421060SN/ABaseDynInst<Impl>::~BaseDynInst() 1431060SN/A{ 1442678SN/A if (memData) { 1452678SN/A delete [] memData; 1462292SN/A } 1472292SN/A 1482292SN/A if (traceData) { 1492292SN/A delete traceData; 1502292SN/A } 1512292SN/A 1522348SN/A fault = NoFault; 1532348SN/A 1545737Scws3k@cs.virginia.edu#ifndef NDEBUG 1555737Scws3k@cs.virginia.edu --cpu->instcount; 1562292SN/A 1575737Scws3k@cs.virginia.edu DPRINTF(DynInst, 1585737Scws3k@cs.virginia.edu "DynInst: [sn:%lli] Instruction destroyed. Instcount for %s = %i\n", 1595737Scws3k@cs.virginia.edu seqNum, cpu->name(), cpu->instcount); 1605737Scws3k@cs.virginia.edu#endif 1612292SN/A#ifdef DEBUG 1622292SN/A cpu->snList.erase(seqNum); 1632292SN/A#endif 1648733Sgeoffrey.blake@arm.com 1651060SN/A} 1661464SN/A 1672292SN/A#ifdef DEBUG 1682292SN/Atemplate <class Impl> 1692292SN/Avoid 1702292SN/ABaseDynInst<Impl>::dumpSNList() 1712292SN/A{ 1722292SN/A std::set<InstSeqNum>::iterator sn_it = cpu->snList.begin(); 1732292SN/A 1742292SN/A int count = 0; 1752292SN/A while (sn_it != cpu->snList.end()) { 1762292SN/A cprintf("%i: [sn:%lli] not destroyed\n", count, (*sn_it)); 1772292SN/A count++; 1782292SN/A sn_it++; 1792292SN/A } 1802292SN/A} 1812292SN/A#endif 1822292SN/A 1831061SN/Atemplate <class Impl> 1841060SN/Avoid 1851060SN/ABaseDynInst<Impl>::dump() 1861060SN/A{ 1877720Sgblack@eecs.umich.edu cprintf("T%d : %#08d `", threadNumber, pc.instAddr()); 1887720Sgblack@eecs.umich.edu std::cout << staticInst->disassemble(pc.instAddr()); 1891060SN/A cprintf("'\n"); 1901060SN/A} 1911060SN/A 1921061SN/Atemplate <class Impl> 1931060SN/Avoid 1941060SN/ABaseDynInst<Impl>::dump(std::string &outstring) 1951060SN/A{ 1961060SN/A std::ostringstream s; 1977720Sgblack@eecs.umich.edu s << "T" << threadNumber << " : 0x" << pc.instAddr() << " " 1987720Sgblack@eecs.umich.edu << staticInst->disassemble(pc.instAddr()); 1991060SN/A 2001060SN/A outstring = s.str(); 2011060SN/A} 2021060SN/A 2031464SN/Atemplate <class Impl> 2042292SN/Avoid 2052292SN/ABaseDynInst<Impl>::markSrcRegReady() 2062292SN/A{ 2077599Sminkyu.jeong@arm.com DPRINTF(IQ, "[sn:%lli] has %d ready out of %d sources. RTI %d)\n", 2087599Sminkyu.jeong@arm.com seqNum, readyRegs+1, numSrcRegs(), readyToIssue()); 2092292SN/A if (++readyRegs == numSrcRegs()) { 2104032Sktlim@umich.edu setCanIssue(); 2112292SN/A } 2122292SN/A} 2132292SN/A 2142292SN/Atemplate <class Impl> 2152292SN/Avoid 2162292SN/ABaseDynInst<Impl>::markSrcRegReady(RegIndex src_idx) 2172292SN/A{ 2182292SN/A _readySrcRegIdx[src_idx] = true; 2192292SN/A 2202731SN/A markSrcRegReady(); 2212292SN/A} 2222292SN/A 2232292SN/Atemplate <class Impl> 2241464SN/Abool 22513429Srekai.gonzalezalberquilla@arm.comBaseDynInst<Impl>::eaSrcsReady() const 2261464SN/A{ 2271464SN/A // For now I am assuming that src registers 1..n-1 are the ones that the 2281464SN/A // EA calc depends on. (i.e. src reg 0 is the source of the data to be 2291464SN/A // stored) 2301464SN/A 2312292SN/A for (int i = 1; i < numSrcRegs(); ++i) { 2321464SN/A if (!_readySrcRegIdx[i]) 2331464SN/A return false; 2341464SN/A } 2351464SN/A 2361464SN/A return true; 2371464SN/A} 2389944Smatt.horsnell@ARM.com 2399944Smatt.horsnell@ARM.com#endif//__CPU_BASE_DYN_INST_IMPL_HH__ 240