base_dyn_inst_impl.hh revision 8232
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 431060SN/A#include <iostream> 442292SN/A#include <set> 458229Snate@binkert.org#include <sstream> 461060SN/A#include <string> 471060SN/A 481060SN/A#include "base/cprintf.hh" 491061SN/A#include "base/trace.hh" 506658Snate@binkert.org#include "config/the_isa.hh" 516658Snate@binkert.org#include "cpu/base_dyn_inst.hh" 521060SN/A#include "cpu/exetrace.hh" 538232Snate@binkert.org#include "debug/DynInst.hh" 548232Snate@binkert.org#include "debug/IQ.hh" 552669SN/A#include "mem/request.hh" 566658Snate@binkert.org#include "sim/faults.hh" 571060SN/A 581060SN/A#define NOHASH 591060SN/A#ifndef NOHASH 601060SN/A 611060SN/A#include "base/hashmap.hh" 621060SN/A 631060SN/Aunsigned int MyHashFunc(const BaseDynInst *addr) 641060SN/A{ 652292SN/A unsigned a = (unsigned)addr; 662292SN/A unsigned hash = (((a >> 14) ^ ((a >> 2) & 0xffff))) & 0x7FFFFFFF; 671060SN/A 682292SN/A return hash; 691060SN/A} 701060SN/A 712292SN/Atypedef m5::hash_map<const BaseDynInst *, const BaseDynInst *, MyHashFunc> 722292SN/Amy_hash_t; 732292SN/A 741060SN/Amy_hash_t thishash; 751060SN/A#endif 761060SN/A 771061SN/Atemplate <class Impl> 784636Sgblack@eecs.umich.eduBaseDynInst<Impl>::BaseDynInst(StaticInstPtr _staticInst, 797720Sgblack@eecs.umich.edu TheISA::PCState _pc, TheISA::PCState _predPC, 803794Sgblack@eecs.umich.edu InstSeqNum seq_num, ImplCPU *cpu) 814636Sgblack@eecs.umich.edu : staticInst(_staticInst), traceData(NULL), cpu(cpu) 821060SN/A{ 831464SN/A seqNum = seq_num; 841061SN/A 857720Sgblack@eecs.umich.edu pc = _pc; 867720Sgblack@eecs.umich.edu predPC = _predPC; 874636Sgblack@eecs.umich.edu predTaken = false; 884636Sgblack@eecs.umich.edu 894636Sgblack@eecs.umich.edu initVars(); 904636Sgblack@eecs.umich.edu} 914636Sgblack@eecs.umich.edu 924636Sgblack@eecs.umich.edutemplate <class Impl> 934636Sgblack@eecs.umich.eduBaseDynInst<Impl>::BaseDynInst(TheISA::ExtMachInst inst, 947720Sgblack@eecs.umich.edu TheISA::PCState _pc, TheISA::PCState _predPC, 954636Sgblack@eecs.umich.edu InstSeqNum seq_num, ImplCPU *cpu) 967720Sgblack@eecs.umich.edu : staticInst(inst, _pc.instAddr()), traceData(NULL), cpu(cpu) 974636Sgblack@eecs.umich.edu{ 984636Sgblack@eecs.umich.edu seqNum = seq_num; 994636Sgblack@eecs.umich.edu 1007720Sgblack@eecs.umich.edu pc = _pc; 1017720Sgblack@eecs.umich.edu predPC = _predPC; 1023794Sgblack@eecs.umich.edu predTaken = false; 1031464SN/A 1041464SN/A initVars(); 1051464SN/A} 1061464SN/A 1071464SN/Atemplate <class Impl> 1082107SN/ABaseDynInst<Impl>::BaseDynInst(StaticInstPtr &_staticInst) 1091464SN/A : staticInst(_staticInst), traceData(NULL) 1101464SN/A{ 1112292SN/A seqNum = 0; 1121464SN/A initVars(); 1131464SN/A} 1141464SN/A 1151464SN/Atemplate <class Impl> 1161464SN/Avoid 1171464SN/ABaseDynInst<Impl>::initVars() 1181464SN/A{ 1192678SN/A memData = NULL; 1202669SN/A effAddr = 0; 1214032Sktlim@umich.edu effAddrValid = false; 1222669SN/A physEffAddr = 0; 1231060SN/A 1247944SGiacomo.Gabrielli@arm.com translationStarted = false; 1257944SGiacomo.Gabrielli@arm.com translationCompleted = false; 1267944SGiacomo.Gabrielli@arm.com 1274032Sktlim@umich.edu isUncacheable = false; 1284032Sktlim@umich.edu reqMade = false; 1291060SN/A readyRegs = 0; 1301060SN/A 1312702SN/A instResult.integer = 0; 1323326Sktlim@umich.edu recordResult = true; 1332702SN/A 1342731SN/A status.reset(); 1352731SN/A 1361464SN/A eaCalcDone = false; 1372292SN/A memOpDone = false; 1387597Sminkyu.jeong@arm.com predicate = true; 1392731SN/A 1402292SN/A lqIdx = -1; 1412292SN/A sqIdx = -1; 1422292SN/A 1431060SN/A // Eventually make this a parameter. 1441060SN/A threadNumber = 0; 1451464SN/A 1461060SN/A // Also make this a parameter, or perhaps get it from xc or cpu. 1471060SN/A asid = 0; 1481060SN/A 1492698SN/A // Initialize the fault to be NoFault. 1502292SN/A fault = NoFault; 1511060SN/A 1525737Scws3k@cs.virginia.edu#ifndef NDEBUG 1535737Scws3k@cs.virginia.edu ++cpu->instcount; 1541060SN/A 1555737Scws3k@cs.virginia.edu if (cpu->instcount > 1500) { 1565375Svilas.sridharan@gmail.com#ifdef DEBUG 1572292SN/A cpu->dumpInsts(); 1582292SN/A dumpSNList(); 1592292SN/A#endif 1605737Scws3k@cs.virginia.edu assert(cpu->instcount <= 1500); 1612292SN/A } 1622292SN/A 1635737Scws3k@cs.virginia.edu DPRINTF(DynInst, 1645737Scws3k@cs.virginia.edu "DynInst: [sn:%lli] Instruction created. Instcount for %s = %i\n", 1655737Scws3k@cs.virginia.edu seqNum, cpu->name(), cpu->instcount); 1665737Scws3k@cs.virginia.edu#endif 1672292SN/A 1682292SN/A#ifdef DEBUG 1692292SN/A cpu->snList.insert(seqNum); 1702292SN/A#endif 1711060SN/A} 1721060SN/A 1731061SN/Atemplate <class Impl> 1741060SN/ABaseDynInst<Impl>::~BaseDynInst() 1751060SN/A{ 1762678SN/A if (memData) { 1772678SN/A delete [] memData; 1782292SN/A } 1792292SN/A 1802292SN/A if (traceData) { 1812292SN/A delete traceData; 1822292SN/A } 1832292SN/A 1842348SN/A fault = NoFault; 1852348SN/A 1865737Scws3k@cs.virginia.edu#ifndef NDEBUG 1875737Scws3k@cs.virginia.edu --cpu->instcount; 1882292SN/A 1895737Scws3k@cs.virginia.edu DPRINTF(DynInst, 1905737Scws3k@cs.virginia.edu "DynInst: [sn:%lli] Instruction destroyed. Instcount for %s = %i\n", 1915737Scws3k@cs.virginia.edu seqNum, cpu->name(), cpu->instcount); 1925737Scws3k@cs.virginia.edu#endif 1932292SN/A#ifdef DEBUG 1942292SN/A cpu->snList.erase(seqNum); 1952292SN/A#endif 1961060SN/A} 1971464SN/A 1982292SN/A#ifdef DEBUG 1992292SN/Atemplate <class Impl> 2002292SN/Avoid 2012292SN/ABaseDynInst<Impl>::dumpSNList() 2022292SN/A{ 2032292SN/A std::set<InstSeqNum>::iterator sn_it = cpu->snList.begin(); 2042292SN/A 2052292SN/A int count = 0; 2062292SN/A while (sn_it != cpu->snList.end()) { 2072292SN/A cprintf("%i: [sn:%lli] not destroyed\n", count, (*sn_it)); 2082292SN/A count++; 2092292SN/A sn_it++; 2102292SN/A } 2112292SN/A} 2122292SN/A#endif 2132292SN/A 2141061SN/Atemplate <class Impl> 2151060SN/Avoid 2161060SN/ABaseDynInst<Impl>::dump() 2171060SN/A{ 2187720Sgblack@eecs.umich.edu cprintf("T%d : %#08d `", threadNumber, pc.instAddr()); 2197720Sgblack@eecs.umich.edu std::cout << staticInst->disassemble(pc.instAddr()); 2201060SN/A cprintf("'\n"); 2211060SN/A} 2221060SN/A 2231061SN/Atemplate <class Impl> 2241060SN/Avoid 2251060SN/ABaseDynInst<Impl>::dump(std::string &outstring) 2261060SN/A{ 2271060SN/A std::ostringstream s; 2287720Sgblack@eecs.umich.edu s << "T" << threadNumber << " : 0x" << pc.instAddr() << " " 2297720Sgblack@eecs.umich.edu << staticInst->disassemble(pc.instAddr()); 2301060SN/A 2311060SN/A outstring = s.str(); 2321060SN/A} 2331060SN/A 2341464SN/Atemplate <class Impl> 2352292SN/Avoid 2362292SN/ABaseDynInst<Impl>::markSrcRegReady() 2372292SN/A{ 2387599Sminkyu.jeong@arm.com DPRINTF(IQ, "[sn:%lli] has %d ready out of %d sources. RTI %d)\n", 2397599Sminkyu.jeong@arm.com seqNum, readyRegs+1, numSrcRegs(), readyToIssue()); 2402292SN/A if (++readyRegs == numSrcRegs()) { 2414032Sktlim@umich.edu setCanIssue(); 2422292SN/A } 2432292SN/A} 2442292SN/A 2452292SN/Atemplate <class Impl> 2462292SN/Avoid 2472292SN/ABaseDynInst<Impl>::markSrcRegReady(RegIndex src_idx) 2482292SN/A{ 2492292SN/A _readySrcRegIdx[src_idx] = true; 2502292SN/A 2512731SN/A markSrcRegReady(); 2522292SN/A} 2532292SN/A 2542292SN/Atemplate <class Impl> 2551464SN/Abool 2561464SN/ABaseDynInst<Impl>::eaSrcsReady() 2571464SN/A{ 2581464SN/A // For now I am assuming that src registers 1..n-1 are the ones that the 2591464SN/A // EA calc depends on. (i.e. src reg 0 is the source of the data to be 2601464SN/A // stored) 2611464SN/A 2622292SN/A for (int i = 1; i < numSrcRegs(); ++i) { 2631464SN/A if (!_readySrcRegIdx[i]) 2641464SN/A return false; 2651464SN/A } 2661464SN/A 2671464SN/A return true; 2681464SN/A} 269