base_dyn_inst.hh revision 11608
11060SN/A/* 29814Sandreas.hansson@arm.com * Copyright (c) 2011,2013 ARM Limited 39920Syasuko.eckert@amd.com * Copyright (c) 2013 Advanced Micro Devices, Inc. 47944SGiacomo.Gabrielli@arm.com * All rights reserved. 57944SGiacomo.Gabrielli@arm.com * 67944SGiacomo.Gabrielli@arm.com * The license below extends only to copyright in the software and shall 77944SGiacomo.Gabrielli@arm.com * not be construed as granting a license to any other intellectual 87944SGiacomo.Gabrielli@arm.com * property including but not limited to intellectual property relating 97944SGiacomo.Gabrielli@arm.com * to a hardware implementation of the functionality of the software 107944SGiacomo.Gabrielli@arm.com * licensed hereunder. You may use the software subject to the license 117944SGiacomo.Gabrielli@arm.com * terms below provided that you ensure that this notice is replicated 127944SGiacomo.Gabrielli@arm.com * unmodified and in its entirety in all distributions of the software, 137944SGiacomo.Gabrielli@arm.com * modified or unmodified, in source code or in binary form. 147944SGiacomo.Gabrielli@arm.com * 152702Sktlim@umich.edu * Copyright (c) 2004-2006 The Regents of The University of Michigan 166973Stjones1@inf.ed.ac.uk * Copyright (c) 2009 The University of Edinburgh 171060SN/A * All rights reserved. 181060SN/A * 191060SN/A * Redistribution and use in source and binary forms, with or without 201060SN/A * modification, are permitted provided that the following conditions are 211060SN/A * met: redistributions of source code must retain the above copyright 221060SN/A * notice, this list of conditions and the following disclaimer; 231060SN/A * redistributions in binary form must reproduce the above copyright 241060SN/A * notice, this list of conditions and the following disclaimer in the 251060SN/A * documentation and/or other materials provided with the distribution; 261060SN/A * neither the name of the copyright holders nor the names of its 271060SN/A * contributors may be used to endorse or promote products derived from 281060SN/A * this software without specific prior written permission. 291060SN/A * 301060SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 311060SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 321060SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 331060SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 341060SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 351060SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 361060SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 371060SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 381060SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 391060SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 401060SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 412665Ssaidi@eecs.umich.edu * 422665Ssaidi@eecs.umich.edu * Authors: Kevin Lim 436973Stjones1@inf.ed.ac.uk * Timothy M. Jones 441060SN/A */ 451060SN/A 461464SN/A#ifndef __CPU_BASE_DYN_INST_HH__ 471464SN/A#define __CPU_BASE_DYN_INST_HH__ 481060SN/A 4910835Sandreas.hansson@arm.com#include <array> 502731Sktlim@umich.edu#include <bitset> 512292SN/A#include <list> 521464SN/A#include <string> 538733Sgeoffrey.blake@arm.com#include <queue> 541060SN/A 5510687SAndreas.Sandberg@ARM.com#include "arch/generic/tlb.hh" 567720Sgblack@eecs.umich.edu#include "arch/utility.hh" 571060SN/A#include "base/trace.hh" 586658Snate@binkert.org#include "config/the_isa.hh" 598887Sgeoffrey.blake@arm.com#include "cpu/checker/cpu.hh" 603770Sgblack@eecs.umich.edu#include "cpu/o3/comm.hh" 6110319SAndreas.Sandberg@ARM.com#include "cpu/exec_context.hh" 621464SN/A#include "cpu/exetrace.hh" 631464SN/A#include "cpu/inst_seq.hh" 642669Sktlim@umich.edu#include "cpu/op_class.hh" 651060SN/A#include "cpu/static_inst.hh" 666973Stjones1@inf.ed.ac.uk#include "cpu/translation.hh" 672669Sktlim@umich.edu#include "mem/packet.hh" 6811608Snikos.nikoleris@arm.com#include "mem/request.hh" 697678Sgblack@eecs.umich.edu#include "sim/byteswap.hh" 702292SN/A#include "sim/system.hh" 711060SN/A 721060SN/A/** 731060SN/A * @file 741060SN/A * Defines a dynamic instruction context. 751060SN/A */ 761060SN/A 771060SN/Atemplate <class Impl> 7810319SAndreas.Sandberg@ARM.comclass BaseDynInst : public ExecContext, public RefCounted 791060SN/A{ 801060SN/A public: 811060SN/A // Typedef for the CPU. 822733Sktlim@umich.edu typedef typename Impl::CPUType ImplCPU; 832733Sktlim@umich.edu typedef typename ImplCPU::ImplState ImplState; 841060SN/A 852292SN/A // Logical register index type. 862107SN/A typedef TheISA::RegIndex RegIndex; 871060SN/A 882292SN/A // The DynInstPtr type. 892292SN/A typedef typename Impl::DynInstPtr DynInstPtr; 908486Sgblack@eecs.umich.edu typedef RefCountingPtr<BaseDynInst<Impl> > BaseDynInstPtr; 912292SN/A 922292SN/A // The list of instructions iterator type. 932292SN/A typedef typename std::list<DynInstPtr>::iterator ListIt; 942292SN/A 951060SN/A enum { 965543Ssaidi@eecs.umich.edu MaxInstSrcRegs = TheISA::MaxInstSrcRegs, /// Max source regs 978902Sandreas.hansson@arm.com MaxInstDestRegs = TheISA::MaxInstDestRegs /// Max dest regs 981060SN/A }; 991060SN/A 1009046SAli.Saidi@ARM.com union Result { 1019046SAli.Saidi@ARM.com uint64_t integer; 1029046SAli.Saidi@ARM.com double dbl; 1039046SAli.Saidi@ARM.com void set(uint64_t i) { integer = i; } 1049046SAli.Saidi@ARM.com void set(double d) { dbl = d; } 1059046SAli.Saidi@ARM.com void get(uint64_t& i) { i = integer; } 1069046SAli.Saidi@ARM.com void get(double& d) { d = dbl; } 1079046SAli.Saidi@ARM.com }; 1089046SAli.Saidi@ARM.com 1099046SAli.Saidi@ARM.com protected: 1109046SAli.Saidi@ARM.com enum Status { 1119046SAli.Saidi@ARM.com IqEntry, /// Instruction is in the IQ 1129046SAli.Saidi@ARM.com RobEntry, /// Instruction is in the ROB 1139046SAli.Saidi@ARM.com LsqEntry, /// Instruction is in the LSQ 1149046SAli.Saidi@ARM.com Completed, /// Instruction has completed 1159046SAli.Saidi@ARM.com ResultReady, /// Instruction has its result 1169046SAli.Saidi@ARM.com CanIssue, /// Instruction can issue and execute 1179046SAli.Saidi@ARM.com Issued, /// Instruction has issued 1189046SAli.Saidi@ARM.com Executed, /// Instruction has executed 1199046SAli.Saidi@ARM.com CanCommit, /// Instruction can commit 1209046SAli.Saidi@ARM.com AtCommit, /// Instruction has reached commit 1219046SAli.Saidi@ARM.com Committed, /// Instruction has committed 1229046SAli.Saidi@ARM.com Squashed, /// Instruction is squashed 1239046SAli.Saidi@ARM.com SquashedInIQ, /// Instruction is squashed in the IQ 1249046SAli.Saidi@ARM.com SquashedInLSQ, /// Instruction is squashed in the LSQ 1259046SAli.Saidi@ARM.com SquashedInROB, /// Instruction is squashed in the ROB 1269046SAli.Saidi@ARM.com RecoverInst, /// Is a recover instruction 1279046SAli.Saidi@ARM.com BlockingInst, /// Is a blocking instruction 1289046SAli.Saidi@ARM.com ThreadsyncWait, /// Is a thread synchronization instruction 1299046SAli.Saidi@ARM.com SerializeBefore, /// Needs to serialize on 1309046SAli.Saidi@ARM.com /// instructions ahead of it 1319046SAli.Saidi@ARM.com SerializeAfter, /// Needs to serialize instructions behind it 1329046SAli.Saidi@ARM.com SerializeHandled, /// Serialization has been handled 1339046SAli.Saidi@ARM.com NumStatus 1349046SAli.Saidi@ARM.com }; 1359046SAli.Saidi@ARM.com 1369046SAli.Saidi@ARM.com enum Flags { 1379046SAli.Saidi@ARM.com TranslationStarted, 1389046SAli.Saidi@ARM.com TranslationCompleted, 1399046SAli.Saidi@ARM.com PossibleLoadViolation, 1409046SAli.Saidi@ARM.com HitExternalSnoop, 1419046SAli.Saidi@ARM.com EffAddrValid, 1429046SAli.Saidi@ARM.com RecordResult, 1439046SAli.Saidi@ARM.com Predicate, 1449046SAli.Saidi@ARM.com PredTaken, 1459046SAli.Saidi@ARM.com /** Whether or not the effective address calculation is completed. 1469046SAli.Saidi@ARM.com * @todo: Consider if this is necessary or not. 1479046SAli.Saidi@ARM.com */ 1489046SAli.Saidi@ARM.com EACalcDone, 14910824SAndreas.Sandberg@ARM.com IsStrictlyOrdered, 1509046SAli.Saidi@ARM.com ReqMade, 1519046SAli.Saidi@ARM.com MemOpDone, 1529046SAli.Saidi@ARM.com MaxFlags 1539046SAli.Saidi@ARM.com }; 1549046SAli.Saidi@ARM.com 1559046SAli.Saidi@ARM.com public: 1569046SAli.Saidi@ARM.com /** The sequence number of the instruction. */ 1579046SAli.Saidi@ARM.com InstSeqNum seqNum; 1589046SAli.Saidi@ARM.com 1592292SN/A /** The StaticInst used by this BaseDynInst. */ 16010417Sandreas.hansson@arm.com const StaticInstPtr staticInst; 1619046SAli.Saidi@ARM.com 1629046SAli.Saidi@ARM.com /** Pointer to the Impl's CPU object. */ 1639046SAli.Saidi@ARM.com ImplCPU *cpu; 1649046SAli.Saidi@ARM.com 16510030SAli.Saidi@ARM.com BaseCPU *getCpuPtr() { return cpu; } 16610030SAli.Saidi@ARM.com 1679046SAli.Saidi@ARM.com /** Pointer to the thread state. */ 1689046SAli.Saidi@ARM.com ImplState *thread; 1699046SAli.Saidi@ARM.com 1709046SAli.Saidi@ARM.com /** The kind of fault this instruction has generated. */ 1719046SAli.Saidi@ARM.com Fault fault; 1729046SAli.Saidi@ARM.com 1739046SAli.Saidi@ARM.com /** InstRecord that tracks this instructions. */ 1749046SAli.Saidi@ARM.com Trace::InstRecord *traceData; 1759046SAli.Saidi@ARM.com 1769046SAli.Saidi@ARM.com protected: 1779046SAli.Saidi@ARM.com /** The result of the instruction; assumes an instruction can have many 1789046SAli.Saidi@ARM.com * destination registers. 1799046SAli.Saidi@ARM.com */ 1809046SAli.Saidi@ARM.com std::queue<Result> instResult; 1819046SAli.Saidi@ARM.com 1829046SAli.Saidi@ARM.com /** PC state for this instruction. */ 1839046SAli.Saidi@ARM.com TheISA::PCState pc; 1849046SAli.Saidi@ARM.com 1859046SAli.Saidi@ARM.com /* An amalgamation of a lot of boolean values into one */ 1869046SAli.Saidi@ARM.com std::bitset<MaxFlags> instFlags; 1879046SAli.Saidi@ARM.com 1889046SAli.Saidi@ARM.com /** The status of this BaseDynInst. Several bits can be set. */ 1899046SAli.Saidi@ARM.com std::bitset<NumStatus> status; 1909046SAli.Saidi@ARM.com 1919046SAli.Saidi@ARM.com /** Whether or not the source register is ready. 1929046SAli.Saidi@ARM.com * @todo: Not sure this should be here vs the derived class. 1939046SAli.Saidi@ARM.com */ 1949046SAli.Saidi@ARM.com std::bitset<MaxInstSrcRegs> _readySrcRegIdx; 1959046SAli.Saidi@ARM.com 1969046SAli.Saidi@ARM.com public: 1979046SAli.Saidi@ARM.com /** The thread this instruction is from. */ 1989046SAli.Saidi@ARM.com ThreadID threadNumber; 1999046SAli.Saidi@ARM.com 2009046SAli.Saidi@ARM.com /** Iterator pointing to this BaseDynInst in the list of all insts. */ 2019046SAli.Saidi@ARM.com ListIt instListIt; 2029046SAli.Saidi@ARM.com 2039046SAli.Saidi@ARM.com ////////////////////// Branch Data /////////////// 2049046SAli.Saidi@ARM.com /** Predicted PC state after this instruction. */ 2059046SAli.Saidi@ARM.com TheISA::PCState predPC; 2069046SAli.Saidi@ARM.com 2079046SAli.Saidi@ARM.com /** The Macroop if one exists */ 20810417Sandreas.hansson@arm.com const StaticInstPtr macroop; 2091060SN/A 2109046SAli.Saidi@ARM.com /** How many source registers are ready. */ 2119046SAli.Saidi@ARM.com uint8_t readyRegs; 2129046SAli.Saidi@ARM.com 2139046SAli.Saidi@ARM.com public: 2149046SAli.Saidi@ARM.com /////////////////////// Load Store Data ////////////////////// 2159046SAli.Saidi@ARM.com /** The effective virtual address (lds & stores only). */ 2169046SAli.Saidi@ARM.com Addr effAddr; 2179046SAli.Saidi@ARM.com 2189046SAli.Saidi@ARM.com /** The effective physical address. */ 21911097Songal@cs.wisc.edu Addr physEffAddrLow; 22011097Songal@cs.wisc.edu 22111097Songal@cs.wisc.edu /** The effective physical address 22211097Songal@cs.wisc.edu * of the second request for a split request 22311097Songal@cs.wisc.edu */ 22411097Songal@cs.wisc.edu Addr physEffAddrHigh; 2259046SAli.Saidi@ARM.com 2269046SAli.Saidi@ARM.com /** The memory request flags (from translation). */ 2279046SAli.Saidi@ARM.com unsigned memReqFlags; 2289046SAli.Saidi@ARM.com 2299046SAli.Saidi@ARM.com /** data address space ID, for loads & stores. */ 2309046SAli.Saidi@ARM.com short asid; 2319046SAli.Saidi@ARM.com 2329046SAli.Saidi@ARM.com /** The size of the request */ 2339046SAli.Saidi@ARM.com uint8_t effSize; 2349046SAli.Saidi@ARM.com 2359046SAli.Saidi@ARM.com /** Pointer to the data for the memory access. */ 2369046SAli.Saidi@ARM.com uint8_t *memData; 2379046SAli.Saidi@ARM.com 2389046SAli.Saidi@ARM.com /** Load queue index. */ 2399046SAli.Saidi@ARM.com int16_t lqIdx; 2409046SAli.Saidi@ARM.com 2419046SAli.Saidi@ARM.com /** Store queue index. */ 2429046SAli.Saidi@ARM.com int16_t sqIdx; 2439046SAli.Saidi@ARM.com 2449046SAli.Saidi@ARM.com 2459046SAli.Saidi@ARM.com /////////////////////// TLB Miss ////////////////////// 2469046SAli.Saidi@ARM.com /** 2479046SAli.Saidi@ARM.com * Saved memory requests (needed when the DTB address translation is 2489046SAli.Saidi@ARM.com * delayed due to a hw page table walk). 2499046SAli.Saidi@ARM.com */ 2509046SAli.Saidi@ARM.com RequestPtr savedReq; 2519046SAli.Saidi@ARM.com RequestPtr savedSreqLow; 2529046SAli.Saidi@ARM.com RequestPtr savedSreqHigh; 2539046SAli.Saidi@ARM.com 2549046SAli.Saidi@ARM.com /////////////////////// Checker ////////////////////// 2559046SAli.Saidi@ARM.com // Need a copy of main request pointer to verify on writes. 2569046SAli.Saidi@ARM.com RequestPtr reqToVerify; 2579046SAli.Saidi@ARM.com 2589046SAli.Saidi@ARM.com private: 2599046SAli.Saidi@ARM.com /** Instruction effective address. 2609046SAli.Saidi@ARM.com * @todo: Consider if this is necessary or not. 2619046SAli.Saidi@ARM.com */ 2629046SAli.Saidi@ARM.com Addr instEffAddr; 2639046SAli.Saidi@ARM.com 2649046SAli.Saidi@ARM.com protected: 2659046SAli.Saidi@ARM.com /** Flattened register index of the destination registers of this 2669046SAli.Saidi@ARM.com * instruction. 2679046SAli.Saidi@ARM.com */ 26810835Sandreas.hansson@arm.com std::array<TheISA::RegIndex, TheISA::MaxInstDestRegs> _flatDestRegIdx; 2699046SAli.Saidi@ARM.com 2709046SAli.Saidi@ARM.com /** Physical register index of the destination registers of this 2719046SAli.Saidi@ARM.com * instruction. 2729046SAli.Saidi@ARM.com */ 27310835Sandreas.hansson@arm.com std::array<PhysRegIndex, TheISA::MaxInstDestRegs> _destRegIdx; 2749046SAli.Saidi@ARM.com 2759046SAli.Saidi@ARM.com /** Physical register index of the source registers of this 2769046SAli.Saidi@ARM.com * instruction. 2779046SAli.Saidi@ARM.com */ 27810835Sandreas.hansson@arm.com std::array<PhysRegIndex, TheISA::MaxInstSrcRegs> _srcRegIdx; 2799046SAli.Saidi@ARM.com 2809046SAli.Saidi@ARM.com /** Physical register index of the previous producers of the 2819046SAli.Saidi@ARM.com * architected destinations. 2829046SAli.Saidi@ARM.com */ 28310835Sandreas.hansson@arm.com std::array<PhysRegIndex, TheISA::MaxInstDestRegs> _prevDestRegIdx; 2849046SAli.Saidi@ARM.com 2859046SAli.Saidi@ARM.com 2869046SAli.Saidi@ARM.com public: 2879046SAli.Saidi@ARM.com /** Records changes to result? */ 2889046SAli.Saidi@ARM.com void recordResult(bool f) { instFlags[RecordResult] = f; } 2899046SAli.Saidi@ARM.com 2909046SAli.Saidi@ARM.com /** Is the effective virtual address valid. */ 2919046SAli.Saidi@ARM.com bool effAddrValid() const { return instFlags[EffAddrValid]; } 2929046SAli.Saidi@ARM.com 2939046SAli.Saidi@ARM.com /** Whether or not the memory operation is done. */ 2949046SAli.Saidi@ARM.com bool memOpDone() const { return instFlags[MemOpDone]; } 2959046SAli.Saidi@ARM.com void memOpDone(bool f) { instFlags[MemOpDone] = f; } 2969046SAli.Saidi@ARM.com 2979046SAli.Saidi@ARM.com 2981060SN/A //////////////////////////////////////////// 2991060SN/A // 3001060SN/A // INSTRUCTION EXECUTION 3011060SN/A // 3021060SN/A //////////////////////////////////////////// 3031060SN/A 3045358Sgblack@eecs.umich.edu void demapPage(Addr vaddr, uint64_t asn) 3055358Sgblack@eecs.umich.edu { 3065358Sgblack@eecs.umich.edu cpu->demapPage(vaddr, asn); 3075358Sgblack@eecs.umich.edu } 3085358Sgblack@eecs.umich.edu void demapInstPage(Addr vaddr, uint64_t asn) 3095358Sgblack@eecs.umich.edu { 3105358Sgblack@eecs.umich.edu cpu->demapPage(vaddr, asn); 3115358Sgblack@eecs.umich.edu } 3125358Sgblack@eecs.umich.edu void demapDataPage(Addr vaddr, uint64_t asn) 3135358Sgblack@eecs.umich.edu { 3145358Sgblack@eecs.umich.edu cpu->demapPage(vaddr, asn); 3155358Sgblack@eecs.umich.edu } 3165358Sgblack@eecs.umich.edu 31711608Snikos.nikoleris@arm.com Fault initiateMemRead(Addr addr, unsigned size, Request::Flags flags); 3187520Sgblack@eecs.umich.edu 31911608Snikos.nikoleris@arm.com Fault writeMem(uint8_t *data, unsigned size, Addr addr, 32011608Snikos.nikoleris@arm.com Request::Flags flags, uint64_t *res); 3217520Sgblack@eecs.umich.edu 3226974Stjones1@inf.ed.ac.uk /** Splits a request in two if it crosses a dcache block. */ 3236974Stjones1@inf.ed.ac.uk void splitRequest(RequestPtr req, RequestPtr &sreqLow, 3246974Stjones1@inf.ed.ac.uk RequestPtr &sreqHigh); 3256974Stjones1@inf.ed.ac.uk 3266973Stjones1@inf.ed.ac.uk /** Initiate a DTB address translation. */ 3276974Stjones1@inf.ed.ac.uk void initiateTranslation(RequestPtr req, RequestPtr sreqLow, 3286974Stjones1@inf.ed.ac.uk RequestPtr sreqHigh, uint64_t *res, 3296973Stjones1@inf.ed.ac.uk BaseTLB::Mode mode); 3306973Stjones1@inf.ed.ac.uk 3316973Stjones1@inf.ed.ac.uk /** Finish a DTB address translation. */ 3326973Stjones1@inf.ed.ac.uk void finishTranslation(WholeTranslationState *state); 3331060SN/A 3347944SGiacomo.Gabrielli@arm.com /** True if the DTB address translation has started. */ 3359046SAli.Saidi@ARM.com bool translationStarted() const { return instFlags[TranslationStarted]; } 3369046SAli.Saidi@ARM.com void translationStarted(bool f) { instFlags[TranslationStarted] = f; } 3377944SGiacomo.Gabrielli@arm.com 3387944SGiacomo.Gabrielli@arm.com /** True if the DTB address translation has completed. */ 3399046SAli.Saidi@ARM.com bool translationCompleted() const { return instFlags[TranslationCompleted]; } 3409046SAli.Saidi@ARM.com void translationCompleted(bool f) { instFlags[TranslationCompleted] = f; } 3417944SGiacomo.Gabrielli@arm.com 3428545Ssaidi@eecs.umich.edu /** True if this address was found to match a previous load and they issued 3438545Ssaidi@eecs.umich.edu * out of order. If that happend, then it's only a problem if an incoming 3448545Ssaidi@eecs.umich.edu * snoop invalidate modifies the line, in which case we need to squash. 3458545Ssaidi@eecs.umich.edu * If nothing modified the line the order doesn't matter. 3468545Ssaidi@eecs.umich.edu */ 3479046SAli.Saidi@ARM.com bool possibleLoadViolation() const { return instFlags[PossibleLoadViolation]; } 3489046SAli.Saidi@ARM.com void possibleLoadViolation(bool f) { instFlags[PossibleLoadViolation] = f; } 3498545Ssaidi@eecs.umich.edu 3508545Ssaidi@eecs.umich.edu /** True if the address hit a external snoop while sitting in the LSQ. 3518545Ssaidi@eecs.umich.edu * If this is true and a older instruction sees it, this instruction must 3528545Ssaidi@eecs.umich.edu * reexecute 3538545Ssaidi@eecs.umich.edu */ 3549046SAli.Saidi@ARM.com bool hitExternalSnoop() const { return instFlags[HitExternalSnoop]; } 3559046SAli.Saidi@ARM.com void hitExternalSnoop(bool f) { instFlags[HitExternalSnoop] = f; } 3568545Ssaidi@eecs.umich.edu 3577944SGiacomo.Gabrielli@arm.com /** 3587944SGiacomo.Gabrielli@arm.com * Returns true if the DTB address translation is being delayed due to a hw 3597944SGiacomo.Gabrielli@arm.com * page table walk. 3607944SGiacomo.Gabrielli@arm.com */ 3617944SGiacomo.Gabrielli@arm.com bool isTranslationDelayed() const 3627944SGiacomo.Gabrielli@arm.com { 3639046SAli.Saidi@ARM.com return (translationStarted() && !translationCompleted()); 3647944SGiacomo.Gabrielli@arm.com } 3657944SGiacomo.Gabrielli@arm.com 3661060SN/A public: 3672292SN/A#ifdef DEBUG 3682292SN/A void dumpSNList(); 3692292SN/A#endif 3702292SN/A 3713770Sgblack@eecs.umich.edu /** Returns the physical register index of the i'th destination 3723770Sgblack@eecs.umich.edu * register. 3733770Sgblack@eecs.umich.edu */ 3743770Sgblack@eecs.umich.edu PhysRegIndex renamedDestRegIdx(int idx) const 3753770Sgblack@eecs.umich.edu { 3763770Sgblack@eecs.umich.edu return _destRegIdx[idx]; 3773770Sgblack@eecs.umich.edu } 3783770Sgblack@eecs.umich.edu 3793770Sgblack@eecs.umich.edu /** Returns the physical register index of the i'th source register. */ 3803770Sgblack@eecs.umich.edu PhysRegIndex renamedSrcRegIdx(int idx) const 3813770Sgblack@eecs.umich.edu { 3829046SAli.Saidi@ARM.com assert(TheISA::MaxInstSrcRegs > idx); 3833770Sgblack@eecs.umich.edu return _srcRegIdx[idx]; 3843770Sgblack@eecs.umich.edu } 3853770Sgblack@eecs.umich.edu 3863770Sgblack@eecs.umich.edu /** Returns the flattened register index of the i'th destination 3873770Sgblack@eecs.umich.edu * register. 3883770Sgblack@eecs.umich.edu */ 3893770Sgblack@eecs.umich.edu TheISA::RegIndex flattenedDestRegIdx(int idx) const 3903770Sgblack@eecs.umich.edu { 3913770Sgblack@eecs.umich.edu return _flatDestRegIdx[idx]; 3923770Sgblack@eecs.umich.edu } 3933770Sgblack@eecs.umich.edu 3943770Sgblack@eecs.umich.edu /** Returns the physical register index of the previous physical register 3953770Sgblack@eecs.umich.edu * that remapped to the same logical register index. 3963770Sgblack@eecs.umich.edu */ 3973770Sgblack@eecs.umich.edu PhysRegIndex prevDestRegIdx(int idx) const 3983770Sgblack@eecs.umich.edu { 3993770Sgblack@eecs.umich.edu return _prevDestRegIdx[idx]; 4003770Sgblack@eecs.umich.edu } 4013770Sgblack@eecs.umich.edu 4023770Sgblack@eecs.umich.edu /** Renames a destination register to a physical register. Also records 4033770Sgblack@eecs.umich.edu * the previous physical register that the logical register mapped to. 4043770Sgblack@eecs.umich.edu */ 4053770Sgblack@eecs.umich.edu void renameDestReg(int idx, 4063770Sgblack@eecs.umich.edu PhysRegIndex renamed_dest, 4073770Sgblack@eecs.umich.edu PhysRegIndex previous_rename) 4083770Sgblack@eecs.umich.edu { 4093770Sgblack@eecs.umich.edu _destRegIdx[idx] = renamed_dest; 4103770Sgblack@eecs.umich.edu _prevDestRegIdx[idx] = previous_rename; 4113770Sgblack@eecs.umich.edu } 4123770Sgblack@eecs.umich.edu 4133770Sgblack@eecs.umich.edu /** Renames a source logical register to the physical register which 4143770Sgblack@eecs.umich.edu * has/will produce that logical register's result. 4153770Sgblack@eecs.umich.edu * @todo: add in whether or not the source register is ready. 4163770Sgblack@eecs.umich.edu */ 4173770Sgblack@eecs.umich.edu void renameSrcReg(int idx, PhysRegIndex renamed_src) 4183770Sgblack@eecs.umich.edu { 4193770Sgblack@eecs.umich.edu _srcRegIdx[idx] = renamed_src; 4203770Sgblack@eecs.umich.edu } 4213770Sgblack@eecs.umich.edu 4223770Sgblack@eecs.umich.edu /** Flattens a destination architectural register index into a logical 4233770Sgblack@eecs.umich.edu * index. 4243770Sgblack@eecs.umich.edu */ 4253770Sgblack@eecs.umich.edu void flattenDestReg(int idx, TheISA::RegIndex flattened_dest) 4263770Sgblack@eecs.umich.edu { 4273770Sgblack@eecs.umich.edu _flatDestRegIdx[idx] = flattened_dest; 4283770Sgblack@eecs.umich.edu } 4294636Sgblack@eecs.umich.edu /** BaseDynInst constructor given a binary instruction. 4304636Sgblack@eecs.umich.edu * @param staticInst A StaticInstPtr to the underlying instruction. 4317720Sgblack@eecs.umich.edu * @param pc The PC state for the instruction. 4327720Sgblack@eecs.umich.edu * @param predPC The predicted next PC state for the instruction. 4334636Sgblack@eecs.umich.edu * @param seq_num The sequence number of the instruction. 4344636Sgblack@eecs.umich.edu * @param cpu Pointer to the instruction's CPU. 4354636Sgblack@eecs.umich.edu */ 43610417Sandreas.hansson@arm.com BaseDynInst(const StaticInstPtr &staticInst, const StaticInstPtr ¯oop, 4378502Sgblack@eecs.umich.edu TheISA::PCState pc, TheISA::PCState predPC, 4388502Sgblack@eecs.umich.edu InstSeqNum seq_num, ImplCPU *cpu); 4393770Sgblack@eecs.umich.edu 4402292SN/A /** BaseDynInst constructor given a StaticInst pointer. 4412292SN/A * @param _staticInst The StaticInst for this BaseDynInst. 4422292SN/A */ 44310417Sandreas.hansson@arm.com BaseDynInst(const StaticInstPtr &staticInst, const StaticInstPtr ¯oop); 4441060SN/A 4451060SN/A /** BaseDynInst destructor. */ 4461060SN/A ~BaseDynInst(); 4471060SN/A 4481464SN/A private: 4491684SN/A /** Function to initialize variables in the constructors. */ 4501464SN/A void initVars(); 4511060SN/A 4521464SN/A public: 4531060SN/A /** Dumps out contents of this BaseDynInst. */ 4541060SN/A void dump(); 4551060SN/A 4561060SN/A /** Dumps out contents of this BaseDynInst into given string. */ 4571060SN/A void dump(std::string &outstring); 4581060SN/A 4593326Sktlim@umich.edu /** Read this CPU's ID. */ 46010110Sandreas.hansson@arm.com int cpuId() const { return cpu->cpuId(); } 4613326Sktlim@umich.edu 46210190Sakash.bagdia@arm.com /** Read this CPU's Socket ID. */ 46310190Sakash.bagdia@arm.com uint32_t socketId() const { return cpu->socketId(); } 46410190Sakash.bagdia@arm.com 4658832SAli.Saidi@ARM.com /** Read this CPU's data requestor ID */ 46610110Sandreas.hansson@arm.com MasterID masterId() const { return cpu->dataMasterId(); } 4678832SAli.Saidi@ARM.com 4685714Shsul@eecs.umich.edu /** Read this context's system-wide ID **/ 46911005Sandreas.sandberg@arm.com ContextID contextId() const { return thread->contextId(); } 4705714Shsul@eecs.umich.edu 4711060SN/A /** Returns the fault type. */ 47210110Sandreas.hansson@arm.com Fault getFault() const { return fault; } 4731060SN/A 4741060SN/A /** Checks whether or not this instruction has had its branch target 4751060SN/A * calculated yet. For now it is not utilized and is hacked to be 4761060SN/A * always false. 4772292SN/A * @todo: Actually use this instruction. 4781060SN/A */ 4791060SN/A bool doneTargCalc() { return false; } 4801060SN/A 4817720Sgblack@eecs.umich.edu /** Set the predicted target of this current instruction. */ 4827720Sgblack@eecs.umich.edu void setPredTarg(const TheISA::PCState &_predPC) 4833965Sgblack@eecs.umich.edu { 4847720Sgblack@eecs.umich.edu predPC = _predPC; 4853965Sgblack@eecs.umich.edu } 4862935Sksewell@umich.edu 4877720Sgblack@eecs.umich.edu const TheISA::PCState &readPredTarg() { return predPC; } 4881060SN/A 4893794Sgblack@eecs.umich.edu /** Returns the predicted PC immediately after the branch. */ 4907720Sgblack@eecs.umich.edu Addr predInstAddr() { return predPC.instAddr(); } 4913794Sgblack@eecs.umich.edu 4923794Sgblack@eecs.umich.edu /** Returns the predicted PC two instructions after the branch */ 4937720Sgblack@eecs.umich.edu Addr predNextInstAddr() { return predPC.nextInstAddr(); } 4941060SN/A 4954636Sgblack@eecs.umich.edu /** Returns the predicted micro PC after the branch */ 4967720Sgblack@eecs.umich.edu Addr predMicroPC() { return predPC.microPC(); } 4974636Sgblack@eecs.umich.edu 4981060SN/A /** Returns whether the instruction was predicted taken or not. */ 4993794Sgblack@eecs.umich.edu bool readPredTaken() 5003794Sgblack@eecs.umich.edu { 5019046SAli.Saidi@ARM.com return instFlags[PredTaken]; 5023794Sgblack@eecs.umich.edu } 5033794Sgblack@eecs.umich.edu 5043794Sgblack@eecs.umich.edu void setPredTaken(bool predicted_taken) 5053794Sgblack@eecs.umich.edu { 5069046SAli.Saidi@ARM.com instFlags[PredTaken] = predicted_taken; 5073794Sgblack@eecs.umich.edu } 5081060SN/A 5091060SN/A /** Returns whether the instruction mispredicted. */ 5102935Sksewell@umich.edu bool mispredicted() 5113794Sgblack@eecs.umich.edu { 5127720Sgblack@eecs.umich.edu TheISA::PCState tempPC = pc; 5137720Sgblack@eecs.umich.edu TheISA::advancePC(tempPC, staticInst); 5147720Sgblack@eecs.umich.edu return !(tempPC == predPC); 5153794Sgblack@eecs.umich.edu } 5163794Sgblack@eecs.umich.edu 5171060SN/A // 5181060SN/A // Instruction types. Forward checks to StaticInst object. 5191060SN/A // 5205543Ssaidi@eecs.umich.edu bool isNop() const { return staticInst->isNop(); } 5215543Ssaidi@eecs.umich.edu bool isMemRef() const { return staticInst->isMemRef(); } 5225543Ssaidi@eecs.umich.edu bool isLoad() const { return staticInst->isLoad(); } 5235543Ssaidi@eecs.umich.edu bool isStore() const { return staticInst->isStore(); } 5242336SN/A bool isStoreConditional() const 5252336SN/A { return staticInst->isStoreConditional(); } 5261060SN/A bool isInstPrefetch() const { return staticInst->isInstPrefetch(); } 5271060SN/A bool isDataPrefetch() const { return staticInst->isDataPrefetch(); } 5285543Ssaidi@eecs.umich.edu bool isInteger() const { return staticInst->isInteger(); } 5295543Ssaidi@eecs.umich.edu bool isFloating() const { return staticInst->isFloating(); } 5305543Ssaidi@eecs.umich.edu bool isControl() const { return staticInst->isControl(); } 5315543Ssaidi@eecs.umich.edu bool isCall() const { return staticInst->isCall(); } 5325543Ssaidi@eecs.umich.edu bool isReturn() const { return staticInst->isReturn(); } 5335543Ssaidi@eecs.umich.edu bool isDirectCtrl() const { return staticInst->isDirectCtrl(); } 5341060SN/A bool isIndirectCtrl() const { return staticInst->isIndirectCtrl(); } 5355543Ssaidi@eecs.umich.edu bool isCondCtrl() const { return staticInst->isCondCtrl(); } 5365543Ssaidi@eecs.umich.edu bool isUncondCtrl() const { return staticInst->isUncondCtrl(); } 5372935Sksewell@umich.edu bool isCondDelaySlot() const { return staticInst->isCondDelaySlot(); } 5381060SN/A bool isThreadSync() const { return staticInst->isThreadSync(); } 5391060SN/A bool isSerializing() const { return staticInst->isSerializing(); } 5402292SN/A bool isSerializeBefore() const 5412731Sktlim@umich.edu { return staticInst->isSerializeBefore() || status[SerializeBefore]; } 5422292SN/A bool isSerializeAfter() const 5432731Sktlim@umich.edu { return staticInst->isSerializeAfter() || status[SerializeAfter]; } 5447784SAli.Saidi@ARM.com bool isSquashAfter() const { return staticInst->isSquashAfter(); } 5451060SN/A bool isMemBarrier() const { return staticInst->isMemBarrier(); } 5461060SN/A bool isWriteBarrier() const { return staticInst->isWriteBarrier(); } 5471060SN/A bool isNonSpeculative() const { return staticInst->isNonSpeculative(); } 5482292SN/A bool isQuiesce() const { return staticInst->isQuiesce(); } 5492336SN/A bool isIprAccess() const { return staticInst->isIprAccess(); } 5502308SN/A bool isUnverifiable() const { return staticInst->isUnverifiable(); } 5514828Sgblack@eecs.umich.edu bool isSyscall() const { return staticInst->isSyscall(); } 5524654Sgblack@eecs.umich.edu bool isMacroop() const { return staticInst->isMacroop(); } 5534654Sgblack@eecs.umich.edu bool isMicroop() const { return staticInst->isMicroop(); } 5544636Sgblack@eecs.umich.edu bool isDelayedCommit() const { return staticInst->isDelayedCommit(); } 5554654Sgblack@eecs.umich.edu bool isLastMicroop() const { return staticInst->isLastMicroop(); } 5564654Sgblack@eecs.umich.edu bool isFirstMicroop() const { return staticInst->isFirstMicroop(); } 5574636Sgblack@eecs.umich.edu bool isMicroBranch() const { return staticInst->isMicroBranch(); } 5582292SN/A 5592292SN/A /** Temporarily sets this instruction as a serialize before instruction. */ 5602731Sktlim@umich.edu void setSerializeBefore() { status.set(SerializeBefore); } 5612292SN/A 5622292SN/A /** Clears the serializeBefore part of this instruction. */ 5632731Sktlim@umich.edu void clearSerializeBefore() { status.reset(SerializeBefore); } 5642292SN/A 5652292SN/A /** Checks if this serializeBefore is only temporarily set. */ 5662731Sktlim@umich.edu bool isTempSerializeBefore() { return status[SerializeBefore]; } 5672292SN/A 5682292SN/A /** Temporarily sets this instruction as a serialize after instruction. */ 5692731Sktlim@umich.edu void setSerializeAfter() { status.set(SerializeAfter); } 5702292SN/A 5712292SN/A /** Clears the serializeAfter part of this instruction.*/ 5722731Sktlim@umich.edu void clearSerializeAfter() { status.reset(SerializeAfter); } 5732292SN/A 5742292SN/A /** Checks if this serializeAfter is only temporarily set. */ 5752731Sktlim@umich.edu bool isTempSerializeAfter() { return status[SerializeAfter]; } 5762292SN/A 5772731Sktlim@umich.edu /** Sets the serialization part of this instruction as handled. */ 5782731Sktlim@umich.edu void setSerializeHandled() { status.set(SerializeHandled); } 5792292SN/A 5802292SN/A /** Checks if the serialization part of this instruction has been 5812292SN/A * handled. This does not apply to the temporary serializing 5822292SN/A * state; it only applies to this instruction's own permanent 5832292SN/A * serializing state. 5842292SN/A */ 5852731Sktlim@umich.edu bool isSerializeHandled() { return status[SerializeHandled]; } 5861060SN/A 5871464SN/A /** Returns the opclass of this instruction. */ 5881464SN/A OpClass opClass() const { return staticInst->opClass(); } 5891464SN/A 5901464SN/A /** Returns the branch target address. */ 5917720Sgblack@eecs.umich.edu TheISA::PCState branchTarget() const 5927720Sgblack@eecs.umich.edu { return staticInst->branchTarget(pc); } 5931464SN/A 5942292SN/A /** Returns the number of source registers. */ 5955543Ssaidi@eecs.umich.edu int8_t numSrcRegs() const { return staticInst->numSrcRegs(); } 5961684SN/A 5972292SN/A /** Returns the number of destination registers. */ 5981060SN/A int8_t numDestRegs() const { return staticInst->numDestRegs(); } 5991060SN/A 6001060SN/A // the following are used to track physical register usage 6011060SN/A // for machines with separate int & FP reg files 6021060SN/A int8_t numFPDestRegs() const { return staticInst->numFPDestRegs(); } 6031060SN/A int8_t numIntDestRegs() const { return staticInst->numIntDestRegs(); } 60410715SRekai.GonzalezAlberquilla@arm.com int8_t numCCDestRegs() const { return staticInst->numCCDestRegs(); } 6051060SN/A 6061060SN/A /** Returns the logical register index of the i'th destination register. */ 6072292SN/A RegIndex destRegIdx(int i) const { return staticInst->destRegIdx(i); } 6081060SN/A 6091060SN/A /** Returns the logical register index of the i'th source register. */ 6102292SN/A RegIndex srcRegIdx(int i) const { return staticInst->srcRegIdx(i); } 6111060SN/A 6128733Sgeoffrey.blake@arm.com /** Pops a result off the instResult queue */ 6138733Sgeoffrey.blake@arm.com template <class T> 6148733Sgeoffrey.blake@arm.com void popResult(T& t) 6158733Sgeoffrey.blake@arm.com { 6168733Sgeoffrey.blake@arm.com if (!instResult.empty()) { 6178733Sgeoffrey.blake@arm.com instResult.front().get(t); 6188733Sgeoffrey.blake@arm.com instResult.pop(); 6198733Sgeoffrey.blake@arm.com } 6208733Sgeoffrey.blake@arm.com } 6211684SN/A 6228733Sgeoffrey.blake@arm.com /** Read the most recent result stored by this instruction */ 6238733Sgeoffrey.blake@arm.com template <class T> 6248733Sgeoffrey.blake@arm.com void readResult(T& t) 6258733Sgeoffrey.blake@arm.com { 6268733Sgeoffrey.blake@arm.com instResult.back().get(t); 6278733Sgeoffrey.blake@arm.com } 6281684SN/A 6298733Sgeoffrey.blake@arm.com /** Pushes a result onto the instResult queue */ 6308733Sgeoffrey.blake@arm.com template <class T> 6318733Sgeoffrey.blake@arm.com void setResult(T t) 6328733Sgeoffrey.blake@arm.com { 6339046SAli.Saidi@ARM.com if (instFlags[RecordResult]) { 6348733Sgeoffrey.blake@arm.com Result instRes; 6358733Sgeoffrey.blake@arm.com instRes.set(t); 6368733Sgeoffrey.blake@arm.com instResult.push(instRes); 6378733Sgeoffrey.blake@arm.com } 6388733Sgeoffrey.blake@arm.com } 6391060SN/A 6402702Sktlim@umich.edu /** Records an integer register being set to a value. */ 64110319SAndreas.Sandberg@ARM.com void setIntRegOperand(const StaticInst *si, int idx, IntReg val) 6421060SN/A { 6438733Sgeoffrey.blake@arm.com setResult<uint64_t>(val); 6441060SN/A } 6451060SN/A 6469920Syasuko.eckert@amd.com /** Records a CC register being set to a value. */ 64710319SAndreas.Sandberg@ARM.com void setCCRegOperand(const StaticInst *si, int idx, CCReg val) 6489920Syasuko.eckert@amd.com { 6499920Syasuko.eckert@amd.com setResult<uint64_t>(val); 6509920Syasuko.eckert@amd.com } 6519920Syasuko.eckert@amd.com 6522702Sktlim@umich.edu /** Records an fp register being set to a value. */ 6533735Sstever@eecs.umich.edu void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val) 6541060SN/A { 6558733Sgeoffrey.blake@arm.com setResult<double>(val); 6562308SN/A } 6571060SN/A 6582702Sktlim@umich.edu /** Records an fp register being set to an integer value. */ 65910319SAndreas.Sandberg@ARM.com void setFloatRegOperandBits(const StaticInst *si, int idx, FloatRegBits val) 6602308SN/A { 6618733Sgeoffrey.blake@arm.com setResult<uint64_t>(val); 6621060SN/A } 6631060SN/A 6642190SN/A /** Records that one of the source registers is ready. */ 6652292SN/A void markSrcRegReady(); 6662190SN/A 6672331SN/A /** Marks a specific register as ready. */ 6682292SN/A void markSrcRegReady(RegIndex src_idx); 6692190SN/A 6701684SN/A /** Returns if a source register is ready. */ 6711464SN/A bool isReadySrcRegIdx(int idx) const 6721464SN/A { 6731464SN/A return this->_readySrcRegIdx[idx]; 6741464SN/A } 6751464SN/A 6761684SN/A /** Sets this instruction as completed. */ 6772731Sktlim@umich.edu void setCompleted() { status.set(Completed); } 6781464SN/A 6792292SN/A /** Returns whether or not this instruction is completed. */ 6802731Sktlim@umich.edu bool isCompleted() const { return status[Completed]; } 6811464SN/A 6822731Sktlim@umich.edu /** Marks the result as ready. */ 6832731Sktlim@umich.edu void setResultReady() { status.set(ResultReady); } 6842308SN/A 6852731Sktlim@umich.edu /** Returns whether or not the result is ready. */ 6862731Sktlim@umich.edu bool isResultReady() const { return status[ResultReady]; } 6872308SN/A 6881060SN/A /** Sets this instruction as ready to issue. */ 6892731Sktlim@umich.edu void setCanIssue() { status.set(CanIssue); } 6901060SN/A 6911060SN/A /** Returns whether or not this instruction is ready to issue. */ 6922731Sktlim@umich.edu bool readyToIssue() const { return status[CanIssue]; } 6931060SN/A 6944032Sktlim@umich.edu /** Clears this instruction being able to issue. */ 6954032Sktlim@umich.edu void clearCanIssue() { status.reset(CanIssue); } 6964032Sktlim@umich.edu 6971060SN/A /** Sets this instruction as issued from the IQ. */ 6982731Sktlim@umich.edu void setIssued() { status.set(Issued); } 6991060SN/A 7001060SN/A /** Returns whether or not this instruction has issued. */ 7012731Sktlim@umich.edu bool isIssued() const { return status[Issued]; } 7021060SN/A 7034032Sktlim@umich.edu /** Clears this instruction as being issued. */ 7044032Sktlim@umich.edu void clearIssued() { status.reset(Issued); } 7054032Sktlim@umich.edu 7061060SN/A /** Sets this instruction as executed. */ 7072731Sktlim@umich.edu void setExecuted() { status.set(Executed); } 7081060SN/A 7091060SN/A /** Returns whether or not this instruction has executed. */ 7102731Sktlim@umich.edu bool isExecuted() const { return status[Executed]; } 7111060SN/A 7121060SN/A /** Sets this instruction as ready to commit. */ 7132731Sktlim@umich.edu void setCanCommit() { status.set(CanCommit); } 7141060SN/A 7151061SN/A /** Clears this instruction as being ready to commit. */ 7162731Sktlim@umich.edu void clearCanCommit() { status.reset(CanCommit); } 7171061SN/A 7181060SN/A /** Returns whether or not this instruction is ready to commit. */ 7192731Sktlim@umich.edu bool readyToCommit() const { return status[CanCommit]; } 7202731Sktlim@umich.edu 7212731Sktlim@umich.edu void setAtCommit() { status.set(AtCommit); } 7222731Sktlim@umich.edu 7232731Sktlim@umich.edu bool isAtCommit() { return status[AtCommit]; } 7241060SN/A 7252292SN/A /** Sets this instruction as committed. */ 7262731Sktlim@umich.edu void setCommitted() { status.set(Committed); } 7272292SN/A 7282292SN/A /** Returns whether or not this instruction is committed. */ 7292731Sktlim@umich.edu bool isCommitted() const { return status[Committed]; } 7302292SN/A 7311060SN/A /** Sets this instruction as squashed. */ 7322731Sktlim@umich.edu void setSquashed() { status.set(Squashed); } 7331060SN/A 7341060SN/A /** Returns whether or not this instruction is squashed. */ 7352731Sktlim@umich.edu bool isSquashed() const { return status[Squashed]; } 7361060SN/A 7372292SN/A //Instruction Queue Entry 7382292SN/A //----------------------- 7392292SN/A /** Sets this instruction as a entry the IQ. */ 7402731Sktlim@umich.edu void setInIQ() { status.set(IqEntry); } 7412292SN/A 7422292SN/A /** Sets this instruction as a entry the IQ. */ 7432731Sktlim@umich.edu void clearInIQ() { status.reset(IqEntry); } 7442731Sktlim@umich.edu 7452731Sktlim@umich.edu /** Returns whether or not this instruction has issued. */ 7462731Sktlim@umich.edu bool isInIQ() const { return status[IqEntry]; } 7472292SN/A 7481060SN/A /** Sets this instruction as squashed in the IQ. */ 7492731Sktlim@umich.edu void setSquashedInIQ() { status.set(SquashedInIQ); status.set(Squashed);} 7501060SN/A 7511060SN/A /** Returns whether or not this instruction is squashed in the IQ. */ 7522731Sktlim@umich.edu bool isSquashedInIQ() const { return status[SquashedInIQ]; } 7532292SN/A 7542292SN/A 7552292SN/A //Load / Store Queue Functions 7562292SN/A //----------------------- 7572292SN/A /** Sets this instruction as a entry the LSQ. */ 7582731Sktlim@umich.edu void setInLSQ() { status.set(LsqEntry); } 7592292SN/A 7602292SN/A /** Sets this instruction as a entry the LSQ. */ 7612731Sktlim@umich.edu void removeInLSQ() { status.reset(LsqEntry); } 7622731Sktlim@umich.edu 7632731Sktlim@umich.edu /** Returns whether or not this instruction is in the LSQ. */ 7642731Sktlim@umich.edu bool isInLSQ() const { return status[LsqEntry]; } 7652292SN/A 7662292SN/A /** Sets this instruction as squashed in the LSQ. */ 7672731Sktlim@umich.edu void setSquashedInLSQ() { status.set(SquashedInLSQ);} 7682292SN/A 7692292SN/A /** Returns whether or not this instruction is squashed in the LSQ. */ 7702731Sktlim@umich.edu bool isSquashedInLSQ() const { return status[SquashedInLSQ]; } 7712292SN/A 7722292SN/A 7732292SN/A //Reorder Buffer Functions 7742292SN/A //----------------------- 7752292SN/A /** Sets this instruction as a entry the ROB. */ 7762731Sktlim@umich.edu void setInROB() { status.set(RobEntry); } 7772292SN/A 7782292SN/A /** Sets this instruction as a entry the ROB. */ 7792731Sktlim@umich.edu void clearInROB() { status.reset(RobEntry); } 7802731Sktlim@umich.edu 7812731Sktlim@umich.edu /** Returns whether or not this instruction is in the ROB. */ 7822731Sktlim@umich.edu bool isInROB() const { return status[RobEntry]; } 7832292SN/A 7842292SN/A /** Sets this instruction as squashed in the ROB. */ 7852731Sktlim@umich.edu void setSquashedInROB() { status.set(SquashedInROB); } 7862292SN/A 7872292SN/A /** Returns whether or not this instruction is squashed in the ROB. */ 7882731Sktlim@umich.edu bool isSquashedInROB() const { return status[SquashedInROB]; } 7892292SN/A 7907720Sgblack@eecs.umich.edu /** Read the PC state of this instruction. */ 79110319SAndreas.Sandberg@ARM.com TheISA::PCState pcState() const { return pc; } 7927720Sgblack@eecs.umich.edu 7937720Sgblack@eecs.umich.edu /** Set the PC state of this instruction. */ 79410319SAndreas.Sandberg@ARM.com void pcState(const TheISA::PCState &val) { pc = val; } 7957720Sgblack@eecs.umich.edu 7961060SN/A /** Read the PC of this instruction. */ 79711294Sandreas.hansson@arm.com Addr instAddr() const { return pc.instAddr(); } 7987720Sgblack@eecs.umich.edu 7997720Sgblack@eecs.umich.edu /** Read the PC of the next instruction. */ 80011294Sandreas.hansson@arm.com Addr nextInstAddr() const { return pc.nextInstAddr(); } 8011060SN/A 8024636Sgblack@eecs.umich.edu /**Read the micro PC of this instruction. */ 80311294Sandreas.hansson@arm.com Addr microPC() const { return pc.microPC(); } 8044636Sgblack@eecs.umich.edu 8057597Sminkyu.jeong@arm.com bool readPredicate() 8067597Sminkyu.jeong@arm.com { 8079046SAli.Saidi@ARM.com return instFlags[Predicate]; 8087597Sminkyu.jeong@arm.com } 8097597Sminkyu.jeong@arm.com 8107597Sminkyu.jeong@arm.com void setPredicate(bool val) 8117597Sminkyu.jeong@arm.com { 8129046SAli.Saidi@ARM.com instFlags[Predicate] = val; 8137600Sminkyu.jeong@arm.com 8147600Sminkyu.jeong@arm.com if (traceData) { 8157600Sminkyu.jeong@arm.com traceData->setPredicate(val); 8167600Sminkyu.jeong@arm.com } 8177597Sminkyu.jeong@arm.com } 8187597Sminkyu.jeong@arm.com 8192702Sktlim@umich.edu /** Sets the ASID. */ 8202292SN/A void setASID(short addr_space_id) { asid = addr_space_id; } 8212292SN/A 8222702Sktlim@umich.edu /** Sets the thread id. */ 8236221Snate@binkert.org void setTid(ThreadID tid) { threadNumber = tid; } 8242292SN/A 8252731Sktlim@umich.edu /** Sets the pointer to the thread state. */ 8262702Sktlim@umich.edu void setThreadState(ImplState *state) { thread = state; } 8271060SN/A 8282731Sktlim@umich.edu /** Returns the thread context. */ 8292680Sktlim@umich.edu ThreadContext *tcBase() { return thread->getTC(); } 8301464SN/A 8311464SN/A public: 8321684SN/A /** Sets the effective address. */ 83310319SAndreas.Sandberg@ARM.com void setEA(Addr ea) { instEffAddr = ea; instFlags[EACalcDone] = true; } 8341684SN/A 8351684SN/A /** Returns the effective address. */ 83610319SAndreas.Sandberg@ARM.com Addr getEA() const { return instEffAddr; } 8371684SN/A 8381684SN/A /** Returns whether or not the eff. addr. calculation has been completed. */ 8399046SAli.Saidi@ARM.com bool doneEACalc() { return instFlags[EACalcDone]; } 8401684SN/A 8411684SN/A /** Returns whether or not the eff. addr. source registers are ready. */ 8421464SN/A bool eaSrcsReady(); 8431681SN/A 84410824SAndreas.Sandberg@ARM.com /** Is this instruction's memory access strictly ordered? */ 84510824SAndreas.Sandberg@ARM.com bool strictlyOrdered() const { return instFlags[IsStrictlyOrdered]; } 8464032Sktlim@umich.edu 8474032Sktlim@umich.edu /** Has this instruction generated a memory request. */ 8489046SAli.Saidi@ARM.com bool hasRequest() { return instFlags[ReqMade]; } 8492292SN/A 8502292SN/A /** Returns iterator to this instruction in the list of all insts. */ 8512292SN/A ListIt &getInstListIt() { return instListIt; } 8522292SN/A 8532292SN/A /** Sets iterator for this instruction in the list of all insts. */ 8542292SN/A void setInstListIt(ListIt _instListIt) { instListIt = _instListIt; } 8553326Sktlim@umich.edu 8563326Sktlim@umich.edu public: 8573326Sktlim@umich.edu /** Returns the number of consecutive store conditional failures. */ 85810319SAndreas.Sandberg@ARM.com unsigned int readStCondFailures() const 8593326Sktlim@umich.edu { return thread->storeCondFailures; } 8603326Sktlim@umich.edu 8613326Sktlim@umich.edu /** Sets the number of consecutive store conditional failures. */ 86210319SAndreas.Sandberg@ARM.com void setStCondFailures(unsigned int sc_failures) 8633326Sktlim@umich.edu { thread->storeCondFailures = sc_failures; } 86410529Smorr@cs.wisc.edu 86510529Smorr@cs.wisc.edu public: 86610529Smorr@cs.wisc.edu // monitor/mwait funtions 86711148Smitch.hayenga@arm.com void armMonitor(Addr address) { cpu->armMonitor(threadNumber, address); } 86811148Smitch.hayenga@arm.com bool mwait(PacketPtr pkt) { return cpu->mwait(threadNumber, pkt); } 86910529Smorr@cs.wisc.edu void mwaitAtomic(ThreadContext *tc) 87011148Smitch.hayenga@arm.com { return cpu->mwaitAtomic(threadNumber, tc, cpu->dtb); } 87111148Smitch.hayenga@arm.com AddressMonitor *getAddrMonitor() 87211148Smitch.hayenga@arm.com { return cpu->getCpuAddrMonitor(threadNumber); } 8731060SN/A}; 8741060SN/A 8751060SN/Atemplate<class Impl> 8767520Sgblack@eecs.umich.eduFault 87711608Snikos.nikoleris@arm.comBaseDynInst<Impl>::initiateMemRead(Addr addr, unsigned size, 87811608Snikos.nikoleris@arm.com Request::Flags flags) 8791060SN/A{ 8809046SAli.Saidi@ARM.com instFlags[ReqMade] = true; 8817944SGiacomo.Gabrielli@arm.com Request *req = NULL; 8826974Stjones1@inf.ed.ac.uk Request *sreqLow = NULL; 8836974Stjones1@inf.ed.ac.uk Request *sreqHigh = NULL; 8846974Stjones1@inf.ed.ac.uk 8859046SAli.Saidi@ARM.com if (instFlags[ReqMade] && translationStarted()) { 8867944SGiacomo.Gabrielli@arm.com req = savedReq; 8877944SGiacomo.Gabrielli@arm.com sreqLow = savedSreqLow; 8887944SGiacomo.Gabrielli@arm.com sreqHigh = savedSreqHigh; 8897944SGiacomo.Gabrielli@arm.com } else { 8908832SAli.Saidi@ARM.com req = new Request(asid, addr, size, flags, masterId(), this->pc.instAddr(), 89111435Smitch.hayenga@arm.com thread->contextId()); 8924032Sktlim@umich.edu 89310024Sdam.sunwoo@arm.com req->taskId(cpu->taskId()); 89410024Sdam.sunwoo@arm.com 8957944SGiacomo.Gabrielli@arm.com // Only split the request if the ISA supports unaligned accesses. 8967944SGiacomo.Gabrielli@arm.com if (TheISA::HasUnalignedMemAcc) { 8977944SGiacomo.Gabrielli@arm.com splitRequest(req, sreqLow, sreqHigh); 8987944SGiacomo.Gabrielli@arm.com } 8997944SGiacomo.Gabrielli@arm.com initiateTranslation(req, sreqLow, sreqHigh, NULL, BaseTLB::Read); 9001060SN/A } 9011060SN/A 9029046SAli.Saidi@ARM.com if (translationCompleted()) { 9037944SGiacomo.Gabrielli@arm.com if (fault == NoFault) { 9047944SGiacomo.Gabrielli@arm.com effAddr = req->getVaddr(); 9058199SAli.Saidi@ARM.com effSize = size; 9069046SAli.Saidi@ARM.com instFlags[EffAddrValid] = true; 9078887Sgeoffrey.blake@arm.com 9088887Sgeoffrey.blake@arm.com if (cpu->checker) { 9098887Sgeoffrey.blake@arm.com if (reqToVerify != NULL) { 9108887Sgeoffrey.blake@arm.com delete reqToVerify; 9118887Sgeoffrey.blake@arm.com } 9128887Sgeoffrey.blake@arm.com reqToVerify = new Request(*req); 9138733Sgeoffrey.blake@arm.com } 91411302Ssteve.reinhardt@amd.com fault = cpu->read(req, sreqLow, sreqHigh, lqIdx); 9157944SGiacomo.Gabrielli@arm.com } else { 9167944SGiacomo.Gabrielli@arm.com // Commit will have to clean up whatever happened. Set this 9177944SGiacomo.Gabrielli@arm.com // instruction as executed. 9187944SGiacomo.Gabrielli@arm.com this->setExecuted(); 9197944SGiacomo.Gabrielli@arm.com } 9207577SAli.Saidi@ARM.com } 9217577SAli.Saidi@ARM.com 92210665SAli.Saidi@ARM.com if (traceData) 92310665SAli.Saidi@ARM.com traceData->setMem(addr, size, flags); 9241060SN/A 9251060SN/A return fault; 9261060SN/A} 9271060SN/A 9281060SN/Atemplate<class Impl> 9297520Sgblack@eecs.umich.eduFault 93011608Snikos.nikoleris@arm.comBaseDynInst<Impl>::writeMem(uint8_t *data, unsigned size, Addr addr, 93111608Snikos.nikoleris@arm.com Request::Flags flags, uint64_t *res) 9321060SN/A{ 93310665SAli.Saidi@ARM.com if (traceData) 93410665SAli.Saidi@ARM.com traceData->setMem(addr, size, flags); 9351060SN/A 9369046SAli.Saidi@ARM.com instFlags[ReqMade] = true; 9377944SGiacomo.Gabrielli@arm.com Request *req = NULL; 9386974Stjones1@inf.ed.ac.uk Request *sreqLow = NULL; 9396974Stjones1@inf.ed.ac.uk Request *sreqHigh = NULL; 9406974Stjones1@inf.ed.ac.uk 9419046SAli.Saidi@ARM.com if (instFlags[ReqMade] && translationStarted()) { 9427944SGiacomo.Gabrielli@arm.com req = savedReq; 9437944SGiacomo.Gabrielli@arm.com sreqLow = savedSreqLow; 9447944SGiacomo.Gabrielli@arm.com sreqHigh = savedSreqHigh; 9457944SGiacomo.Gabrielli@arm.com } else { 9468832SAli.Saidi@ARM.com req = new Request(asid, addr, size, flags, masterId(), this->pc.instAddr(), 94711435Smitch.hayenga@arm.com thread->contextId()); 9487944SGiacomo.Gabrielli@arm.com 94910024Sdam.sunwoo@arm.com req->taskId(cpu->taskId()); 95010024Sdam.sunwoo@arm.com 9517944SGiacomo.Gabrielli@arm.com // Only split the request if the ISA supports unaligned accesses. 9527944SGiacomo.Gabrielli@arm.com if (TheISA::HasUnalignedMemAcc) { 9537944SGiacomo.Gabrielli@arm.com splitRequest(req, sreqLow, sreqHigh); 9547944SGiacomo.Gabrielli@arm.com } 9557944SGiacomo.Gabrielli@arm.com initiateTranslation(req, sreqLow, sreqHigh, res, BaseTLB::Write); 9566974Stjones1@inf.ed.ac.uk } 9574032Sktlim@umich.edu 9589046SAli.Saidi@ARM.com if (fault == NoFault && translationCompleted()) { 9592678Sktlim@umich.edu effAddr = req->getVaddr(); 9608199SAli.Saidi@ARM.com effSize = size; 9619046SAli.Saidi@ARM.com instFlags[EffAddrValid] = true; 9628887Sgeoffrey.blake@arm.com 9638887Sgeoffrey.blake@arm.com if (cpu->checker) { 9648887Sgeoffrey.blake@arm.com if (reqToVerify != NULL) { 9658887Sgeoffrey.blake@arm.com delete reqToVerify; 9668887Sgeoffrey.blake@arm.com } 9678887Sgeoffrey.blake@arm.com reqToVerify = new Request(*req); 9688733Sgeoffrey.blake@arm.com } 9696975Stjones1@inf.ed.ac.uk fault = cpu->write(req, sreqLow, sreqHigh, data, sqIdx); 9701060SN/A } 9711060SN/A 9721060SN/A return fault; 9731060SN/A} 9741060SN/A 9756973Stjones1@inf.ed.ac.uktemplate<class Impl> 9766973Stjones1@inf.ed.ac.ukinline void 9776974Stjones1@inf.ed.ac.ukBaseDynInst<Impl>::splitRequest(RequestPtr req, RequestPtr &sreqLow, 9786974Stjones1@inf.ed.ac.uk RequestPtr &sreqHigh) 9796974Stjones1@inf.ed.ac.uk{ 9806974Stjones1@inf.ed.ac.uk // Check to see if the request crosses the next level block boundary. 9819814Sandreas.hansson@arm.com unsigned block_size = cpu->cacheLineSize(); 9826974Stjones1@inf.ed.ac.uk Addr addr = req->getVaddr(); 9836974Stjones1@inf.ed.ac.uk Addr split_addr = roundDown(addr + req->getSize() - 1, block_size); 9846974Stjones1@inf.ed.ac.uk assert(split_addr <= addr || split_addr - addr < block_size); 9856974Stjones1@inf.ed.ac.uk 9866974Stjones1@inf.ed.ac.uk // Spans two blocks. 9876974Stjones1@inf.ed.ac.uk if (split_addr > addr) { 9886974Stjones1@inf.ed.ac.uk req->splitOnVaddr(split_addr, sreqLow, sreqHigh); 9896974Stjones1@inf.ed.ac.uk } 9906974Stjones1@inf.ed.ac.uk} 9916974Stjones1@inf.ed.ac.uk 9926974Stjones1@inf.ed.ac.uktemplate<class Impl> 9936974Stjones1@inf.ed.ac.ukinline void 9946974Stjones1@inf.ed.ac.ukBaseDynInst<Impl>::initiateTranslation(RequestPtr req, RequestPtr sreqLow, 9956974Stjones1@inf.ed.ac.uk RequestPtr sreqHigh, uint64_t *res, 9966973Stjones1@inf.ed.ac.uk BaseTLB::Mode mode) 9976973Stjones1@inf.ed.ac.uk{ 9989046SAli.Saidi@ARM.com translationStarted(true); 9997944SGiacomo.Gabrielli@arm.com 10006974Stjones1@inf.ed.ac.uk if (!TheISA::HasUnalignedMemAcc || sreqLow == NULL) { 10016974Stjones1@inf.ed.ac.uk WholeTranslationState *state = 10026974Stjones1@inf.ed.ac.uk new WholeTranslationState(req, NULL, res, mode); 10036974Stjones1@inf.ed.ac.uk 10046974Stjones1@inf.ed.ac.uk // One translation if the request isn't split. 10058486Sgblack@eecs.umich.edu DataTranslation<BaseDynInstPtr> *trans = 10068486Sgblack@eecs.umich.edu new DataTranslation<BaseDynInstPtr>(this, state); 10079932SAli.Saidi@ARM.com 10086974Stjones1@inf.ed.ac.uk cpu->dtb->translateTiming(req, thread->getTC(), trans, mode); 10099932SAli.Saidi@ARM.com 10109046SAli.Saidi@ARM.com if (!translationCompleted()) { 10119932SAli.Saidi@ARM.com // The translation isn't yet complete, so we can't possibly have a 10129932SAli.Saidi@ARM.com // fault. Overwrite any existing fault we might have from a previous 10139932SAli.Saidi@ARM.com // execution of this instruction (e.g. an uncachable load that 10149932SAli.Saidi@ARM.com // couldn't execute because it wasn't at the head of the ROB). 10159932SAli.Saidi@ARM.com fault = NoFault; 10169932SAli.Saidi@ARM.com 10177944SGiacomo.Gabrielli@arm.com // Save memory requests. 10187944SGiacomo.Gabrielli@arm.com savedReq = state->mainReq; 10197944SGiacomo.Gabrielli@arm.com savedSreqLow = state->sreqLow; 10207944SGiacomo.Gabrielli@arm.com savedSreqHigh = state->sreqHigh; 10217944SGiacomo.Gabrielli@arm.com } 10226974Stjones1@inf.ed.ac.uk } else { 10236974Stjones1@inf.ed.ac.uk WholeTranslationState *state = 10246974Stjones1@inf.ed.ac.uk new WholeTranslationState(req, sreqLow, sreqHigh, NULL, res, mode); 10256974Stjones1@inf.ed.ac.uk 10266974Stjones1@inf.ed.ac.uk // Two translations when the request is split. 10278486Sgblack@eecs.umich.edu DataTranslation<BaseDynInstPtr> *stransLow = 10288486Sgblack@eecs.umich.edu new DataTranslation<BaseDynInstPtr>(this, state, 0); 10298486Sgblack@eecs.umich.edu DataTranslation<BaseDynInstPtr> *stransHigh = 10308486Sgblack@eecs.umich.edu new DataTranslation<BaseDynInstPtr>(this, state, 1); 10316974Stjones1@inf.ed.ac.uk 10326974Stjones1@inf.ed.ac.uk cpu->dtb->translateTiming(sreqLow, thread->getTC(), stransLow, mode); 10336974Stjones1@inf.ed.ac.uk cpu->dtb->translateTiming(sreqHigh, thread->getTC(), stransHigh, mode); 10349932SAli.Saidi@ARM.com 10359046SAli.Saidi@ARM.com if (!translationCompleted()) { 10369932SAli.Saidi@ARM.com // The translation isn't yet complete, so we can't possibly have a 10379932SAli.Saidi@ARM.com // fault. Overwrite any existing fault we might have from a previous 10389932SAli.Saidi@ARM.com // execution of this instruction (e.g. an uncachable load that 10399932SAli.Saidi@ARM.com // couldn't execute because it wasn't at the head of the ROB). 10409932SAli.Saidi@ARM.com fault = NoFault; 10419932SAli.Saidi@ARM.com 10427944SGiacomo.Gabrielli@arm.com // Save memory requests. 10437944SGiacomo.Gabrielli@arm.com savedReq = state->mainReq; 10447944SGiacomo.Gabrielli@arm.com savedSreqLow = state->sreqLow; 10457944SGiacomo.Gabrielli@arm.com savedSreqHigh = state->sreqHigh; 10467944SGiacomo.Gabrielli@arm.com } 10476974Stjones1@inf.ed.ac.uk } 10486973Stjones1@inf.ed.ac.uk} 10496973Stjones1@inf.ed.ac.uk 10506973Stjones1@inf.ed.ac.uktemplate<class Impl> 10516973Stjones1@inf.ed.ac.ukinline void 10526973Stjones1@inf.ed.ac.ukBaseDynInst<Impl>::finishTranslation(WholeTranslationState *state) 10536973Stjones1@inf.ed.ac.uk{ 10546973Stjones1@inf.ed.ac.uk fault = state->getFault(); 10556973Stjones1@inf.ed.ac.uk 105610824SAndreas.Sandberg@ARM.com instFlags[IsStrictlyOrdered] = state->isStrictlyOrdered(); 10576973Stjones1@inf.ed.ac.uk 10586973Stjones1@inf.ed.ac.uk if (fault == NoFault) { 105911097Songal@cs.wisc.edu // save Paddr for a single req 106011097Songal@cs.wisc.edu physEffAddrLow = state->getPaddr(); 106111097Songal@cs.wisc.edu 106211097Songal@cs.wisc.edu // case for the request that has been split 106311097Songal@cs.wisc.edu if (state->isSplit) { 106411097Songal@cs.wisc.edu physEffAddrLow = state->sreqLow->getPaddr(); 106511097Songal@cs.wisc.edu physEffAddrHigh = state->sreqHigh->getPaddr(); 106611097Songal@cs.wisc.edu } 106711097Songal@cs.wisc.edu 10686973Stjones1@inf.ed.ac.uk memReqFlags = state->getFlags(); 10696973Stjones1@inf.ed.ac.uk 10706973Stjones1@inf.ed.ac.uk if (state->mainReq->isCondSwap()) { 10716973Stjones1@inf.ed.ac.uk assert(state->res); 10726973Stjones1@inf.ed.ac.uk state->mainReq->setExtraData(*state->res); 10736973Stjones1@inf.ed.ac.uk } 10746973Stjones1@inf.ed.ac.uk 10756973Stjones1@inf.ed.ac.uk } else { 10766973Stjones1@inf.ed.ac.uk state->deleteReqs(); 10776973Stjones1@inf.ed.ac.uk } 10786973Stjones1@inf.ed.ac.uk delete state; 10797944SGiacomo.Gabrielli@arm.com 10809046SAli.Saidi@ARM.com translationCompleted(true); 10816973Stjones1@inf.ed.ac.uk} 10826973Stjones1@inf.ed.ac.uk 10831464SN/A#endif // __CPU_BASE_DYN_INST_HH__ 1084