base_dyn_inst.hh revision 14297:b4519e586f5e
14680Sgblack@eecs.umich.edu/* 25442Sgblack@eecs.umich.edu * Copyright (c) 2011, 2013, 2016-2019 ARM Limited 34680Sgblack@eecs.umich.edu * Copyright (c) 2013 Advanced Micro Devices, Inc. 44680Sgblack@eecs.umich.edu * All rights reserved. 54680Sgblack@eecs.umich.edu * 64680Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall 74680Sgblack@eecs.umich.edu * not be construed as granting a license to any other intellectual 84680Sgblack@eecs.umich.edu * property including but not limited to intellectual property relating 94680Sgblack@eecs.umich.edu * to a hardware implementation of the functionality of the software 104680Sgblack@eecs.umich.edu * licensed hereunder. You may use the software subject to the license 114680Sgblack@eecs.umich.edu * terms below provided that you ensure that this notice is replicated 124680Sgblack@eecs.umich.edu * unmodified and in its entirety in all distributions of the software, 134680Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form. 144680Sgblack@eecs.umich.edu * 154680Sgblack@eecs.umich.edu * Copyright (c) 2004-2006 The Regents of The University of Michigan 164680Sgblack@eecs.umich.edu * Copyright (c) 2009 The University of Edinburgh 174680Sgblack@eecs.umich.edu * All rights reserved. 184680Sgblack@eecs.umich.edu * 194680Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 204680Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 214680Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 224680Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 234680Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 244680Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 254680Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 264680Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 274680Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 284680Sgblack@eecs.umich.edu * this software without specific prior written permission. 294680Sgblack@eecs.umich.edu * 304680Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 314680Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 324680Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 334680Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3412450Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3512450Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3612450Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 374680Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 384680Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 395543Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 404680Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 414680Sgblack@eecs.umich.edu * 424680Sgblack@eecs.umich.edu * Authors: Kevin Lim 434680Sgblack@eecs.umich.edu * Timothy M. Jones 444680Sgblack@eecs.umich.edu */ 454680Sgblack@eecs.umich.edu 464680Sgblack@eecs.umich.edu#ifndef __CPU_BASE_DYN_INST_HH__ 4712450Sgabeblack@google.com#define __CPU_BASE_DYN_INST_HH__ 4812450Sgabeblack@google.com 4912450Sgabeblack@google.com#include <array> 5012450Sgabeblack@google.com#include <bitset> 5112450Sgabeblack@google.com#include <deque> 5212450Sgabeblack@google.com#include <list> 5312450Sgabeblack@google.com#include <string> 5412450Sgabeblack@google.com 5512450Sgabeblack@google.com#include "arch/generic/tlb.hh" 5612450Sgabeblack@google.com#include "arch/utility.hh" 5712450Sgabeblack@google.com#include "base/trace.hh" 5812450Sgabeblack@google.com#include "config/the_isa.hh" 5912450Sgabeblack@google.com#include "cpu/checker/cpu.hh" 6012450Sgabeblack@google.com#include "cpu/exec_context.hh" 6112450Sgabeblack@google.com#include "cpu/exetrace.hh" 6212450Sgabeblack@google.com#include "cpu/inst_res.hh" 6312450Sgabeblack@google.com#include "cpu/inst_seq.hh" 6412450Sgabeblack@google.com#include "cpu/op_class.hh" 6512450Sgabeblack@google.com#include "cpu/static_inst.hh" 6612450Sgabeblack@google.com#include "cpu/translation.hh" 6712450Sgabeblack@google.com#include "mem/packet.hh" 6812450Sgabeblack@google.com#include "mem/request.hh" 6912450Sgabeblack@google.com#include "sim/byteswap.hh" 7012450Sgabeblack@google.com#include "sim/system.hh" 7112450Sgabeblack@google.com 7212450Sgabeblack@google.com/** 7312450Sgabeblack@google.com * @file 7412450Sgabeblack@google.com * Defines a dynamic instruction context. 7512450Sgabeblack@google.com */ 7612450Sgabeblack@google.com 7712450Sgabeblack@google.comtemplate <class Impl> 7812450Sgabeblack@google.comclass BaseDynInst : public ExecContext, public RefCounted 7912450Sgabeblack@google.com{ 8012450Sgabeblack@google.com public: 8112450Sgabeblack@google.com // Typedef for the CPU. 8212450Sgabeblack@google.com typedef typename Impl::CPUType ImplCPU; 8312450Sgabeblack@google.com typedef typename ImplCPU::ImplState ImplState; 8412450Sgabeblack@google.com using VecRegContainer = TheISA::VecRegContainer; 8512450Sgabeblack@google.com 8612450Sgabeblack@google.com using LSQRequestPtr = typename Impl::CPUPol::LSQ::LSQRequest*; 8712450Sgabeblack@google.com using LQIterator = typename Impl::CPUPol::LSQUnit::LQIterator; 8812450Sgabeblack@google.com using SQIterator = typename Impl::CPUPol::LSQUnit::SQIterator; 8912450Sgabeblack@google.com 9012450Sgabeblack@google.com // The DynInstPtr type. 9112450Sgabeblack@google.com typedef typename Impl::DynInstPtr DynInstPtr; 9212450Sgabeblack@google.com typedef RefCountingPtr<BaseDynInst<Impl> > BaseDynInstPtr; 9312450Sgabeblack@google.com 9412450Sgabeblack@google.com // The list of instructions iterator type. 9512450Sgabeblack@google.com typedef typename std::list<DynInstPtr>::iterator ListIt; 9612450Sgabeblack@google.com 9712450Sgabeblack@google.com enum { 9812450Sgabeblack@google.com MaxInstSrcRegs = TheISA::MaxInstSrcRegs, /// Max source regs 9912450Sgabeblack@google.com MaxInstDestRegs = TheISA::MaxInstDestRegs /// Max dest regs 10012450Sgabeblack@google.com }; 10112450Sgabeblack@google.com 10212450Sgabeblack@google.com protected: 10312450Sgabeblack@google.com enum Status { 10412450Sgabeblack@google.com IqEntry, /// Instruction is in the IQ 10512450Sgabeblack@google.com RobEntry, /// Instruction is in the ROB 10612450Sgabeblack@google.com LsqEntry, /// Instruction is in the LSQ 10712450Sgabeblack@google.com Completed, /// Instruction has completed 10812450Sgabeblack@google.com ResultReady, /// Instruction has its result 10912450Sgabeblack@google.com CanIssue, /// Instruction can issue and execute 11012450Sgabeblack@google.com Issued, /// Instruction has issued 11112450Sgabeblack@google.com Executed, /// Instruction has executed 11212450Sgabeblack@google.com CanCommit, /// Instruction can commit 11312450Sgabeblack@google.com AtCommit, /// Instruction has reached commit 11412450Sgabeblack@google.com Committed, /// Instruction has committed 11512450Sgabeblack@google.com Squashed, /// Instruction is squashed 11612450Sgabeblack@google.com SquashedInIQ, /// Instruction is squashed in the IQ 11712450Sgabeblack@google.com SquashedInLSQ, /// Instruction is squashed in the LSQ 11812450Sgabeblack@google.com SquashedInROB, /// Instruction is squashed in the ROB 11912450Sgabeblack@google.com PinnedRegsRenamed, /// Pinned registers are renamed 12012450Sgabeblack@google.com PinnedRegsWritten, /// Pinned registers are written back 12112450Sgabeblack@google.com PinnedRegsSquashDone, /// Regs pinning status updated after squash 12212450Sgabeblack@google.com RecoverInst, /// Is a recover instruction 12312450Sgabeblack@google.com BlockingInst, /// Is a blocking instruction 12412450Sgabeblack@google.com ThreadsyncWait, /// Is a thread synchronization instruction 12512450Sgabeblack@google.com SerializeBefore, /// Needs to serialize on 12612450Sgabeblack@google.com /// instructions ahead of it 12712450Sgabeblack@google.com SerializeAfter, /// Needs to serialize instructions behind it 12812450Sgabeblack@google.com SerializeHandled, /// Serialization has been handled 12912450Sgabeblack@google.com NumStatus 13012450Sgabeblack@google.com }; 13112450Sgabeblack@google.com 13212450Sgabeblack@google.com enum Flags { 13312450Sgabeblack@google.com NotAnInst, 13412450Sgabeblack@google.com TranslationStarted, 13512450Sgabeblack@google.com TranslationCompleted, 13612450Sgabeblack@google.com PossibleLoadViolation, 13712450Sgabeblack@google.com HitExternalSnoop, 13812450Sgabeblack@google.com EffAddrValid, 13912450Sgabeblack@google.com RecordResult, 14012450Sgabeblack@google.com Predicate, 14112450Sgabeblack@google.com MemAccPredicate, 14212450Sgabeblack@google.com PredTaken, 14312450Sgabeblack@google.com IsStrictlyOrdered, 14412450Sgabeblack@google.com ReqMade, 14512450Sgabeblack@google.com MemOpDone, 14612450Sgabeblack@google.com MaxFlags 14712450Sgabeblack@google.com }; 14812450Sgabeblack@google.com 14912450Sgabeblack@google.com public: 1504680Sgblack@eecs.umich.edu /** The sequence number of the instruction. */ 15112450Sgabeblack@google.com InstSeqNum seqNum; 1524680Sgblack@eecs.umich.edu 1534680Sgblack@eecs.umich.edu /** The StaticInst used by this BaseDynInst. */ 15412450Sgabeblack@google.com const StaticInstPtr staticInst; 15512450Sgabeblack@google.com 1564680Sgblack@eecs.umich.edu /** Pointer to the Impl's CPU object. */ 15712450Sgabeblack@google.com ImplCPU *cpu; 15812450Sgabeblack@google.com 15912450Sgabeblack@google.com BaseCPU *getCpuPtr() { return cpu; } 1604680Sgblack@eecs.umich.edu 16112450Sgabeblack@google.com /** Pointer to the thread state. */ 16212450Sgabeblack@google.com ImplState *thread; 1634680Sgblack@eecs.umich.edu 16412450Sgabeblack@google.com /** The kind of fault this instruction has generated. */ 1654680Sgblack@eecs.umich.edu Fault fault; 1664680Sgblack@eecs.umich.edu 16712450Sgabeblack@google.com /** InstRecord that tracks this instructions. */ 16812450Sgabeblack@google.com Trace::InstRecord *traceData; 1694680Sgblack@eecs.umich.edu 17012450Sgabeblack@google.com protected: 1714680Sgblack@eecs.umich.edu /** The result of the instruction; assumes an instruction can have many 1724680Sgblack@eecs.umich.edu * destination registers. 1734680Sgblack@eecs.umich.edu */ 17412450Sgabeblack@google.com std::queue<InstResult> instResult; 17512450Sgabeblack@google.com 17612450Sgabeblack@google.com /** PC state for this instruction. */ 17712450Sgabeblack@google.com TheISA::PCState pc; 17812450Sgabeblack@google.com 17912450Sgabeblack@google.com private: 18012450Sgabeblack@google.com /* An amalgamation of a lot of boolean values into one */ 18112450Sgabeblack@google.com std::bitset<MaxFlags> instFlags; 18212450Sgabeblack@google.com 18312450Sgabeblack@google.com /** The status of this BaseDynInst. Several bits can be set. */ 18412450Sgabeblack@google.com std::bitset<NumStatus> status; 18512450Sgabeblack@google.com 18612450Sgabeblack@google.com protected: 18712450Sgabeblack@google.com /** Whether or not the source register is ready. 18812450Sgabeblack@google.com * @todo: Not sure this should be here vs the derived class. 18912450Sgabeblack@google.com */ 19012450Sgabeblack@google.com std::bitset<MaxInstSrcRegs> _readySrcRegIdx; 19112450Sgabeblack@google.com 19212450Sgabeblack@google.com public: 19312450Sgabeblack@google.com /** The thread this instruction is from. */ 19412450Sgabeblack@google.com ThreadID threadNumber; 19512450Sgabeblack@google.com 19612450Sgabeblack@google.com /** Iterator pointing to this BaseDynInst in the list of all insts. */ 19712450Sgabeblack@google.com ListIt instListIt; 19812450Sgabeblack@google.com 1994680Sgblack@eecs.umich.edu ////////////////////// Branch Data /////////////// 2004680Sgblack@eecs.umich.edu /** Predicted PC state after this instruction. */ 20112450Sgabeblack@google.com TheISA::PCState predPC; 2024680Sgblack@eecs.umich.edu 20312450Sgabeblack@google.com /** The Macroop if one exists */ 20412450Sgabeblack@google.com const StaticInstPtr macroop; 20512450Sgabeblack@google.com 20612450Sgabeblack@google.com /** How many source registers are ready. */ 20712450Sgabeblack@google.com uint8_t readyRegs; 20812450Sgabeblack@google.com 20912450Sgabeblack@google.com public: 21010289SAndreas.Sandberg@ARM.com /////////////////////// Load Store Data ////////////////////// 2114680Sgblack@eecs.umich.edu /** The effective virtual address (lds & stores only). */ 21212450Sgabeblack@google.com Addr effAddr; 21312450Sgabeblack@google.com 2144680Sgblack@eecs.umich.edu /** The effective physical address. */ 21512450Sgabeblack@google.com Addr physEffAddr; 21612450Sgabeblack@google.com 21712450Sgabeblack@google.com /** The memory request flags (from translation). */ 21812450Sgabeblack@google.com unsigned memReqFlags; 21912450Sgabeblack@google.com 2204680Sgblack@eecs.umich.edu /** data address space ID, for loads & stores. */ 2214680Sgblack@eecs.umich.edu short asid; 2224680Sgblack@eecs.umich.edu 2234680Sgblack@eecs.umich.edu /** The size of the request */ 2244680Sgblack@eecs.umich.edu unsigned effSize; 2254680Sgblack@eecs.umich.edu 2264680Sgblack@eecs.umich.edu /** Pointer to the data for the memory access. */ 2274680Sgblack@eecs.umich.edu uint8_t *memData; 22812450Sgabeblack@google.com 2294680Sgblack@eecs.umich.edu /** Load queue index. */ 2304680Sgblack@eecs.umich.edu int16_t lqIdx; 23112450Sgabeblack@google.com LQIterator lqIt; 23212450Sgabeblack@google.com 23312450Sgabeblack@google.com /** Store queue index. */ 2344680Sgblack@eecs.umich.edu int16_t sqIdx; 23512450Sgabeblack@google.com SQIterator sqIt; 2364681Sgblack@eecs.umich.edu 23712450Sgabeblack@google.com 2384681Sgblack@eecs.umich.edu /////////////////////// TLB Miss ////////////////////// 2394681Sgblack@eecs.umich.edu /** 2404681Sgblack@eecs.umich.edu * Saved memory request (needed when the DTB address translation is 2414681Sgblack@eecs.umich.edu * delayed due to a hw page table walk). 24212450Sgabeblack@google.com */ 2434680Sgblack@eecs.umich.edu LSQRequestPtr savedReq; 24412450Sgabeblack@google.com 2454680Sgblack@eecs.umich.edu /////////////////////// Checker ////////////////////// 2464680Sgblack@eecs.umich.edu // Need a copy of main request pointer to verify on writes. 24712450Sgabeblack@google.com RequestPtr reqToVerify; 24812450Sgabeblack@google.com 2494680Sgblack@eecs.umich.edu protected: 25012450Sgabeblack@google.com /** Flattened register index of the destination registers of this 25112450Sgabeblack@google.com * instruction. 2524680Sgblack@eecs.umich.edu */ 2534680Sgblack@eecs.umich.edu std::array<RegId, TheISA::MaxInstDestRegs> _flatDestRegIdx; 25412450Sgabeblack@google.com 25512450Sgabeblack@google.com /** Physical register index of the destination registers of this 25610640Sgabeblack@google.com * instruction. 25712450Sgabeblack@google.com */ 25812450Sgabeblack@google.com std::array<PhysRegIdPtr, TheISA::MaxInstDestRegs> _destRegIdx; 25910640Sgabeblack@google.com 26010640Sgabeblack@google.com /** Physical register index of the source registers of this 2614680Sgblack@eecs.umich.edu * instruction. 26212450Sgabeblack@google.com */ 2634680Sgblack@eecs.umich.edu std::array<PhysRegIdPtr, TheISA::MaxInstSrcRegs> _srcRegIdx; 26412450Sgabeblack@google.com 2654680Sgblack@eecs.umich.edu /** Physical register index of the previous producers of the 2664680Sgblack@eecs.umich.edu * architected destinations. 2674680Sgblack@eecs.umich.edu */ 26812450Sgabeblack@google.com std::array<PhysRegIdPtr, TheISA::MaxInstDestRegs> _prevDestRegIdx; 2694680Sgblack@eecs.umich.edu 27012450Sgabeblack@google.com 2714680Sgblack@eecs.umich.edu public: 2724680Sgblack@eecs.umich.edu /** Records changes to result? */ 2734680Sgblack@eecs.umich.edu void recordResult(bool f) { instFlags[RecordResult] = f; } 2744680Sgblack@eecs.umich.edu 2754680Sgblack@eecs.umich.edu /** Is the effective virtual address valid. */ 2764680Sgblack@eecs.umich.edu bool effAddrValid() const { return instFlags[EffAddrValid]; } 2774680Sgblack@eecs.umich.edu void effAddrValid(bool b) { instFlags[EffAddrValid] = b; } 2784680Sgblack@eecs.umich.edu 2794680Sgblack@eecs.umich.edu /** Whether or not the memory operation is done. */ 2804680Sgblack@eecs.umich.edu bool memOpDone() const { return instFlags[MemOpDone]; } 2814680Sgblack@eecs.umich.edu void memOpDone(bool f) { instFlags[MemOpDone] = f; } 28212450Sgabeblack@google.com 2834680Sgblack@eecs.umich.edu bool notAnInst() const { return instFlags[NotAnInst]; } 2844680Sgblack@eecs.umich.edu void setNotAnInst() { instFlags[NotAnInst] = true; } 2854680Sgblack@eecs.umich.edu 2864680Sgblack@eecs.umich.edu 28712450Sgabeblack@google.com //////////////////////////////////////////// 2884680Sgblack@eecs.umich.edu // 2894680Sgblack@eecs.umich.edu // INSTRUCTION EXECUTION 2904680Sgblack@eecs.umich.edu // 2915442Sgblack@eecs.umich.edu //////////////////////////////////////////// 2924680Sgblack@eecs.umich.edu 2934680Sgblack@eecs.umich.edu void demapPage(Addr vaddr, uint64_t asn) 2944680Sgblack@eecs.umich.edu { 29512450Sgabeblack@google.com cpu->demapPage(vaddr, asn); 2964680Sgblack@eecs.umich.edu } 29712450Sgabeblack@google.com void demapInstPage(Addr vaddr, uint64_t asn) 2984680Sgblack@eecs.umich.edu { 2994680Sgblack@eecs.umich.edu cpu->demapPage(vaddr, asn); 3004680Sgblack@eecs.umich.edu } 3014680Sgblack@eecs.umich.edu void demapDataPage(Addr vaddr, uint64_t asn) 3024680Sgblack@eecs.umich.edu { 3034680Sgblack@eecs.umich.edu cpu->demapPage(vaddr, asn); 3044680Sgblack@eecs.umich.edu } 3054680Sgblack@eecs.umich.edu 3064680Sgblack@eecs.umich.edu Fault initiateMemRead(Addr addr, unsigned size, Request::Flags flags, 3075442Sgblack@eecs.umich.edu const std::vector<bool>& byteEnable = std::vector<bool>()); 3084680Sgblack@eecs.umich.edu 3094680Sgblack@eecs.umich.edu Fault writeMem(uint8_t *data, unsigned size, Addr addr, 31012450Sgabeblack@google.com Request::Flags flags, uint64_t *res, 3114680Sgblack@eecs.umich.edu const std::vector<bool>& byteEnable = std::vector<bool>()); 3124680Sgblack@eecs.umich.edu 3134680Sgblack@eecs.umich.edu Fault initiateMemAMO(Addr addr, unsigned size, Request::Flags flags, 31412450Sgabeblack@google.com AtomicOpFunctorPtr amo_op); 31512450Sgabeblack@google.com 3164680Sgblack@eecs.umich.edu /** True if the DTB address translation has started. */ 3174680Sgblack@eecs.umich.edu bool translationStarted() const { return instFlags[TranslationStarted]; } 3184680Sgblack@eecs.umich.edu void translationStarted(bool f) { instFlags[TranslationStarted] = f; } 31912450Sgabeblack@google.com 3204680Sgblack@eecs.umich.edu /** True if the DTB address translation has completed. */ 3214680Sgblack@eecs.umich.edu bool translationCompleted() const { return instFlags[TranslationCompleted]; } 3224680Sgblack@eecs.umich.edu void translationCompleted(bool f) { instFlags[TranslationCompleted] = f; } 3234680Sgblack@eecs.umich.edu 3244680Sgblack@eecs.umich.edu /** True if this address was found to match a previous load and they issued 3254680Sgblack@eecs.umich.edu * out of order. If that happend, then it's only a problem if an incoming 3264680Sgblack@eecs.umich.edu * snoop invalidate modifies the line, in which case we need to squash. 3274680Sgblack@eecs.umich.edu * If nothing modified the line the order doesn't matter. 32812450Sgabeblack@google.com */ 32912450Sgabeblack@google.com bool possibleLoadViolation() const { return instFlags[PossibleLoadViolation]; } 3304680Sgblack@eecs.umich.edu void possibleLoadViolation(bool f) { instFlags[PossibleLoadViolation] = f; } 33112450Sgabeblack@google.com 33212450Sgabeblack@google.com /** True if the address hit a external snoop while sitting in the LSQ. 3334680Sgblack@eecs.umich.edu * If this is true and a older instruction sees it, this instruction must 3344680Sgblack@eecs.umich.edu * reexecute 3354680Sgblack@eecs.umich.edu */ 3364680Sgblack@eecs.umich.edu bool hitExternalSnoop() const { return instFlags[HitExternalSnoop]; } 3374680Sgblack@eecs.umich.edu void hitExternalSnoop(bool f) { instFlags[HitExternalSnoop] = f; } 33812450Sgabeblack@google.com 3394680Sgblack@eecs.umich.edu /** 3404680Sgblack@eecs.umich.edu * Returns true if the DTB address translation is being delayed due to a hw 3414680Sgblack@eecs.umich.edu * page table walk. 3424680Sgblack@eecs.umich.edu */ 34312450Sgabeblack@google.com bool isTranslationDelayed() const 3444680Sgblack@eecs.umich.edu { 3454680Sgblack@eecs.umich.edu return (translationStarted() && !translationCompleted()); 3464680Sgblack@eecs.umich.edu } 3474680Sgblack@eecs.umich.edu 3484680Sgblack@eecs.umich.edu public: 3494680Sgblack@eecs.umich.edu#ifdef DEBUG 3504680Sgblack@eecs.umich.edu void dumpSNList(); 3514680Sgblack@eecs.umich.edu#endif 3524680Sgblack@eecs.umich.edu 3534680Sgblack@eecs.umich.edu /** Returns the physical register index of the i'th destination 3544680Sgblack@eecs.umich.edu * register. 355 */ 356 PhysRegIdPtr renamedDestRegIdx(int idx) const 357 { 358 return _destRegIdx[idx]; 359 } 360 361 /** Returns the physical register index of the i'th source register. */ 362 PhysRegIdPtr renamedSrcRegIdx(int idx) const 363 { 364 assert(TheISA::MaxInstSrcRegs > idx); 365 return _srcRegIdx[idx]; 366 } 367 368 /** Returns the flattened register index of the i'th destination 369 * register. 370 */ 371 const RegId& flattenedDestRegIdx(int idx) const 372 { 373 return _flatDestRegIdx[idx]; 374 } 375 376 /** Returns the physical register index of the previous physical register 377 * that remapped to the same logical register index. 378 */ 379 PhysRegIdPtr prevDestRegIdx(int idx) const 380 { 381 return _prevDestRegIdx[idx]; 382 } 383 384 /** Renames a destination register to a physical register. Also records 385 * the previous physical register that the logical register mapped to. 386 */ 387 void renameDestReg(int idx, 388 PhysRegIdPtr renamed_dest, 389 PhysRegIdPtr previous_rename) 390 { 391 _destRegIdx[idx] = renamed_dest; 392 _prevDestRegIdx[idx] = previous_rename; 393 if (renamed_dest->isPinned()) 394 setPinnedRegsRenamed(); 395 } 396 397 /** Renames a source logical register to the physical register which 398 * has/will produce that logical register's result. 399 * @todo: add in whether or not the source register is ready. 400 */ 401 void renameSrcReg(int idx, PhysRegIdPtr renamed_src) 402 { 403 _srcRegIdx[idx] = renamed_src; 404 } 405 406 /** Flattens a destination architectural register index into a logical 407 * index. 408 */ 409 void flattenDestReg(int idx, const RegId& flattened_dest) 410 { 411 _flatDestRegIdx[idx] = flattened_dest; 412 } 413 /** BaseDynInst constructor given a binary instruction. 414 * @param staticInst A StaticInstPtr to the underlying instruction. 415 * @param pc The PC state for the instruction. 416 * @param predPC The predicted next PC state for the instruction. 417 * @param seq_num The sequence number of the instruction. 418 * @param cpu Pointer to the instruction's CPU. 419 */ 420 BaseDynInst(const StaticInstPtr &staticInst, const StaticInstPtr ¯oop, 421 TheISA::PCState pc, TheISA::PCState predPC, 422 InstSeqNum seq_num, ImplCPU *cpu); 423 424 /** BaseDynInst constructor given a StaticInst pointer. 425 * @param _staticInst The StaticInst for this BaseDynInst. 426 */ 427 BaseDynInst(const StaticInstPtr &staticInst, const StaticInstPtr ¯oop); 428 429 /** BaseDynInst destructor. */ 430 ~BaseDynInst(); 431 432 private: 433 /** Function to initialize variables in the constructors. */ 434 void initVars(); 435 436 public: 437 /** Dumps out contents of this BaseDynInst. */ 438 void dump(); 439 440 /** Dumps out contents of this BaseDynInst into given string. */ 441 void dump(std::string &outstring); 442 443 /** Read this CPU's ID. */ 444 int cpuId() const { return cpu->cpuId(); } 445 446 /** Read this CPU's Socket ID. */ 447 uint32_t socketId() const { return cpu->socketId(); } 448 449 /** Read this CPU's data requestor ID */ 450 MasterID masterId() const { return cpu->dataMasterId(); } 451 452 /** Read this context's system-wide ID **/ 453 ContextID contextId() const { return thread->contextId(); } 454 455 /** Returns the fault type. */ 456 Fault getFault() const { return fault; } 457 /** TODO: This I added for the LSQRequest side to be able to modify the 458 * fault. There should be a better mechanism in place. */ 459 Fault& getFault() { return fault; } 460 461 /** Checks whether or not this instruction has had its branch target 462 * calculated yet. For now it is not utilized and is hacked to be 463 * always false. 464 * @todo: Actually use this instruction. 465 */ 466 bool doneTargCalc() { return false; } 467 468 /** Set the predicted target of this current instruction. */ 469 void setPredTarg(const TheISA::PCState &_predPC) 470 { 471 predPC = _predPC; 472 } 473 474 const TheISA::PCState &readPredTarg() { return predPC; } 475 476 /** Returns the predicted PC immediately after the branch. */ 477 Addr predInstAddr() { return predPC.instAddr(); } 478 479 /** Returns the predicted PC two instructions after the branch */ 480 Addr predNextInstAddr() { return predPC.nextInstAddr(); } 481 482 /** Returns the predicted micro PC after the branch */ 483 Addr predMicroPC() { return predPC.microPC(); } 484 485 /** Returns whether the instruction was predicted taken or not. */ 486 bool readPredTaken() 487 { 488 return instFlags[PredTaken]; 489 } 490 491 void setPredTaken(bool predicted_taken) 492 { 493 instFlags[PredTaken] = predicted_taken; 494 } 495 496 /** Returns whether the instruction mispredicted. */ 497 bool mispredicted() 498 { 499 TheISA::PCState tempPC = pc; 500 TheISA::advancePC(tempPC, staticInst); 501 return !(tempPC == predPC); 502 } 503 504 // 505 // Instruction types. Forward checks to StaticInst object. 506 // 507 bool isNop() const { return staticInst->isNop(); } 508 bool isMemRef() const { return staticInst->isMemRef(); } 509 bool isLoad() const { return staticInst->isLoad(); } 510 bool isStore() const { return staticInst->isStore(); } 511 bool isAtomic() const { return staticInst->isAtomic(); } 512 bool isStoreConditional() const 513 { return staticInst->isStoreConditional(); } 514 bool isInstPrefetch() const { return staticInst->isInstPrefetch(); } 515 bool isDataPrefetch() const { return staticInst->isDataPrefetch(); } 516 bool isInteger() const { return staticInst->isInteger(); } 517 bool isFloating() const { return staticInst->isFloating(); } 518 bool isVector() const { return staticInst->isVector(); } 519 bool isControl() const { return staticInst->isControl(); } 520 bool isCall() const { return staticInst->isCall(); } 521 bool isReturn() const { return staticInst->isReturn(); } 522 bool isDirectCtrl() const { return staticInst->isDirectCtrl(); } 523 bool isIndirectCtrl() const { return staticInst->isIndirectCtrl(); } 524 bool isCondCtrl() const { return staticInst->isCondCtrl(); } 525 bool isUncondCtrl() const { return staticInst->isUncondCtrl(); } 526 bool isCondDelaySlot() const { return staticInst->isCondDelaySlot(); } 527 bool isThreadSync() const { return staticInst->isThreadSync(); } 528 bool isSerializing() const { return staticInst->isSerializing(); } 529 bool isSerializeBefore() const 530 { return staticInst->isSerializeBefore() || status[SerializeBefore]; } 531 bool isSerializeAfter() const 532 { return staticInst->isSerializeAfter() || status[SerializeAfter]; } 533 bool isSquashAfter() const { return staticInst->isSquashAfter(); } 534 bool isMemBarrier() const { return staticInst->isMemBarrier(); } 535 bool isWriteBarrier() const { return staticInst->isWriteBarrier(); } 536 bool isNonSpeculative() const { return staticInst->isNonSpeculative(); } 537 bool isQuiesce() const { return staticInst->isQuiesce(); } 538 bool isIprAccess() const { return staticInst->isIprAccess(); } 539 bool isUnverifiable() const { return staticInst->isUnverifiable(); } 540 bool isSyscall() const { return staticInst->isSyscall(); } 541 bool isMacroop() const { return staticInst->isMacroop(); } 542 bool isMicroop() const { return staticInst->isMicroop(); } 543 bool isDelayedCommit() const { return staticInst->isDelayedCommit(); } 544 bool isLastMicroop() const { return staticInst->isLastMicroop(); } 545 bool isFirstMicroop() const { return staticInst->isFirstMicroop(); } 546 bool isMicroBranch() const { return staticInst->isMicroBranch(); } 547 548 /** Temporarily sets this instruction as a serialize before instruction. */ 549 void setSerializeBefore() { status.set(SerializeBefore); } 550 551 /** Clears the serializeBefore part of this instruction. */ 552 void clearSerializeBefore() { status.reset(SerializeBefore); } 553 554 /** Checks if this serializeBefore is only temporarily set. */ 555 bool isTempSerializeBefore() { return status[SerializeBefore]; } 556 557 /** Temporarily sets this instruction as a serialize after instruction. */ 558 void setSerializeAfter() { status.set(SerializeAfter); } 559 560 /** Clears the serializeAfter part of this instruction.*/ 561 void clearSerializeAfter() { status.reset(SerializeAfter); } 562 563 /** Checks if this serializeAfter is only temporarily set. */ 564 bool isTempSerializeAfter() { return status[SerializeAfter]; } 565 566 /** Sets the serialization part of this instruction as handled. */ 567 void setSerializeHandled() { status.set(SerializeHandled); } 568 569 /** Checks if the serialization part of this instruction has been 570 * handled. This does not apply to the temporary serializing 571 * state; it only applies to this instruction's own permanent 572 * serializing state. 573 */ 574 bool isSerializeHandled() { return status[SerializeHandled]; } 575 576 /** Returns the opclass of this instruction. */ 577 OpClass opClass() const { return staticInst->opClass(); } 578 579 /** Returns the branch target address. */ 580 TheISA::PCState branchTarget() const 581 { return staticInst->branchTarget(pc); } 582 583 /** Returns the number of source registers. */ 584 int8_t numSrcRegs() const { return staticInst->numSrcRegs(); } 585 586 /** Returns the number of destination registers. */ 587 int8_t numDestRegs() const { return staticInst->numDestRegs(); } 588 589 // the following are used to track physical register usage 590 // for machines with separate int & FP reg files 591 int8_t numFPDestRegs() const { return staticInst->numFPDestRegs(); } 592 int8_t numIntDestRegs() const { return staticInst->numIntDestRegs(); } 593 int8_t numCCDestRegs() const { return staticInst->numCCDestRegs(); } 594 int8_t numVecDestRegs() const { return staticInst->numVecDestRegs(); } 595 int8_t numVecElemDestRegs() const 596 { 597 return staticInst->numVecElemDestRegs(); 598 } 599 int8_t 600 numVecPredDestRegs() const 601 { 602 return staticInst->numVecPredDestRegs(); 603 } 604 605 /** Returns the logical register index of the i'th destination register. */ 606 const RegId& destRegIdx(int i) const { return staticInst->destRegIdx(i); } 607 608 /** Returns the logical register index of the i'th source register. */ 609 const RegId& srcRegIdx(int i) const { return staticInst->srcRegIdx(i); } 610 611 /** Return the size of the instResult queue. */ 612 uint8_t resultSize() { return instResult.size(); } 613 614 /** Pops a result off the instResult queue. 615 * If the result stack is empty, return the default value. 616 * */ 617 InstResult popResult(InstResult dflt = InstResult()) 618 { 619 if (!instResult.empty()) { 620 InstResult t = instResult.front(); 621 instResult.pop(); 622 return t; 623 } 624 return dflt; 625 } 626 627 /** Pushes a result onto the instResult queue. */ 628 /** @{ */ 629 /** Scalar result. */ 630 template<typename T> 631 void setScalarResult(T&& t) 632 { 633 if (instFlags[RecordResult]) { 634 instResult.push(InstResult(std::forward<T>(t), 635 InstResult::ResultType::Scalar)); 636 } 637 } 638 639 /** Full vector result. */ 640 template<typename T> 641 void setVecResult(T&& t) 642 { 643 if (instFlags[RecordResult]) { 644 instResult.push(InstResult(std::forward<T>(t), 645 InstResult::ResultType::VecReg)); 646 } 647 } 648 649 /** Vector element result. */ 650 template<typename T> 651 void setVecElemResult(T&& t) 652 { 653 if (instFlags[RecordResult]) { 654 instResult.push(InstResult(std::forward<T>(t), 655 InstResult::ResultType::VecElem)); 656 } 657 } 658 659 /** Predicate result. */ 660 template<typename T> 661 void setVecPredResult(T&& t) 662 { 663 if (instFlags[RecordResult]) { 664 instResult.push(InstResult(std::forward<T>(t), 665 InstResult::ResultType::VecPredReg)); 666 } 667 } 668 /** @} */ 669 670 /** Records an integer register being set to a value. */ 671 void setIntRegOperand(const StaticInst *si, int idx, RegVal val) 672 { 673 setScalarResult(val); 674 } 675 676 /** Records a CC register being set to a value. */ 677 void setCCRegOperand(const StaticInst *si, int idx, RegVal val) 678 { 679 setScalarResult(val); 680 } 681 682 /** Record a vector register being set to a value */ 683 void setVecRegOperand(const StaticInst *si, int idx, 684 const VecRegContainer& val) 685 { 686 setVecResult(val); 687 } 688 689 /** Records an fp register being set to an integer value. */ 690 void 691 setFloatRegOperandBits(const StaticInst *si, int idx, RegVal val) 692 { 693 setScalarResult(val); 694 } 695 696 /** Record a vector register being set to a value */ 697 void setVecElemOperand(const StaticInst *si, int idx, const VecElem val) 698 { 699 setVecElemResult(val); 700 } 701 702 /** Record a vector register being set to a value */ 703 void setVecPredRegOperand(const StaticInst *si, int idx, 704 const VecPredRegContainer& val) 705 { 706 setVecPredResult(val); 707 } 708 709 /** Records that one of the source registers is ready. */ 710 void markSrcRegReady(); 711 712 /** Marks a specific register as ready. */ 713 void markSrcRegReady(RegIndex src_idx); 714 715 /** Returns if a source register is ready. */ 716 bool isReadySrcRegIdx(int idx) const 717 { 718 return this->_readySrcRegIdx[idx]; 719 } 720 721 /** Sets this instruction as completed. */ 722 void setCompleted() { status.set(Completed); } 723 724 /** Returns whether or not this instruction is completed. */ 725 bool isCompleted() const { return status[Completed]; } 726 727 /** Marks the result as ready. */ 728 void setResultReady() { status.set(ResultReady); } 729 730 /** Returns whether or not the result is ready. */ 731 bool isResultReady() const { return status[ResultReady]; } 732 733 /** Sets this instruction as ready to issue. */ 734 void setCanIssue() { status.set(CanIssue); } 735 736 /** Returns whether or not this instruction is ready to issue. */ 737 bool readyToIssue() const { return status[CanIssue]; } 738 739 /** Clears this instruction being able to issue. */ 740 void clearCanIssue() { status.reset(CanIssue); } 741 742 /** Sets this instruction as issued from the IQ. */ 743 void setIssued() { status.set(Issued); } 744 745 /** Returns whether or not this instruction has issued. */ 746 bool isIssued() const { return status[Issued]; } 747 748 /** Clears this instruction as being issued. */ 749 void clearIssued() { status.reset(Issued); } 750 751 /** Sets this instruction as executed. */ 752 void setExecuted() { status.set(Executed); } 753 754 /** Returns whether or not this instruction has executed. */ 755 bool isExecuted() const { return status[Executed]; } 756 757 /** Sets this instruction as ready to commit. */ 758 void setCanCommit() { status.set(CanCommit); } 759 760 /** Clears this instruction as being ready to commit. */ 761 void clearCanCommit() { status.reset(CanCommit); } 762 763 /** Returns whether or not this instruction is ready to commit. */ 764 bool readyToCommit() const { return status[CanCommit]; } 765 766 void setAtCommit() { status.set(AtCommit); } 767 768 bool isAtCommit() { return status[AtCommit]; } 769 770 /** Sets this instruction as committed. */ 771 void setCommitted() { status.set(Committed); } 772 773 /** Returns whether or not this instruction is committed. */ 774 bool isCommitted() const { return status[Committed]; } 775 776 /** Sets this instruction as squashed. */ 777 void setSquashed(); 778 779 /** Returns whether or not this instruction is squashed. */ 780 bool isSquashed() const { return status[Squashed]; } 781 782 //Instruction Queue Entry 783 //----------------------- 784 /** Sets this instruction as a entry the IQ. */ 785 void setInIQ() { status.set(IqEntry); } 786 787 /** Sets this instruction as a entry the IQ. */ 788 void clearInIQ() { status.reset(IqEntry); } 789 790 /** Returns whether or not this instruction has issued. */ 791 bool isInIQ() const { return status[IqEntry]; } 792 793 /** Sets this instruction as squashed in the IQ. */ 794 void setSquashedInIQ() { status.set(SquashedInIQ); status.set(Squashed);} 795 796 /** Returns whether or not this instruction is squashed in the IQ. */ 797 bool isSquashedInIQ() const { return status[SquashedInIQ]; } 798 799 800 //Load / Store Queue Functions 801 //----------------------- 802 /** Sets this instruction as a entry the LSQ. */ 803 void setInLSQ() { status.set(LsqEntry); } 804 805 /** Sets this instruction as a entry the LSQ. */ 806 void removeInLSQ() { status.reset(LsqEntry); } 807 808 /** Returns whether or not this instruction is in the LSQ. */ 809 bool isInLSQ() const { return status[LsqEntry]; } 810 811 /** Sets this instruction as squashed in the LSQ. */ 812 void setSquashedInLSQ() { status.set(SquashedInLSQ); status.set(Squashed);} 813 814 /** Returns whether or not this instruction is squashed in the LSQ. */ 815 bool isSquashedInLSQ() const { return status[SquashedInLSQ]; } 816 817 818 //Reorder Buffer Functions 819 //----------------------- 820 /** Sets this instruction as a entry the ROB. */ 821 void setInROB() { status.set(RobEntry); } 822 823 /** Sets this instruction as a entry the ROB. */ 824 void clearInROB() { status.reset(RobEntry); } 825 826 /** Returns whether or not this instruction is in the ROB. */ 827 bool isInROB() const { return status[RobEntry]; } 828 829 /** Sets this instruction as squashed in the ROB. */ 830 void setSquashedInROB() { status.set(SquashedInROB); } 831 832 /** Returns whether or not this instruction is squashed in the ROB. */ 833 bool isSquashedInROB() const { return status[SquashedInROB]; } 834 835 /** Returns whether pinned registers are renamed */ 836 bool isPinnedRegsRenamed() const { return status[PinnedRegsRenamed]; } 837 838 /** Sets the destination registers as renamed */ 839 void 840 setPinnedRegsRenamed() 841 { 842 assert(!status[PinnedRegsSquashDone]); 843 assert(!status[PinnedRegsWritten]); 844 status.set(PinnedRegsRenamed); 845 } 846 847 /** Returns whether destination registers are written */ 848 bool isPinnedRegsWritten() const { return status[PinnedRegsWritten]; } 849 850 /** Sets destination registers as written */ 851 void 852 setPinnedRegsWritten() 853 { 854 assert(!status[PinnedRegsSquashDone]); 855 assert(status[PinnedRegsRenamed]); 856 status.set(PinnedRegsWritten); 857 } 858 859 /** Return whether dest registers' pinning status updated after squash */ 860 bool 861 isPinnedRegsSquashDone() const { return status[PinnedRegsSquashDone]; } 862 863 /** Sets dest registers' status updated after squash */ 864 void 865 setPinnedRegsSquashDone() { 866 assert(!status[PinnedRegsSquashDone]); 867 status.set(PinnedRegsSquashDone); 868 } 869 870 /** Read the PC state of this instruction. */ 871 TheISA::PCState pcState() const { return pc; } 872 873 /** Set the PC state of this instruction. */ 874 void pcState(const TheISA::PCState &val) { pc = val; } 875 876 /** Read the PC of this instruction. */ 877 Addr instAddr() const { return pc.instAddr(); } 878 879 /** Read the PC of the next instruction. */ 880 Addr nextInstAddr() const { return pc.nextInstAddr(); } 881 882 /**Read the micro PC of this instruction. */ 883 Addr microPC() const { return pc.microPC(); } 884 885 bool readPredicate() const 886 { 887 return instFlags[Predicate]; 888 } 889 890 void setPredicate(bool val) 891 { 892 instFlags[Predicate] = val; 893 894 if (traceData) { 895 traceData->setPredicate(val); 896 } 897 } 898 899 bool 900 readMemAccPredicate() const 901 { 902 return instFlags[MemAccPredicate]; 903 } 904 905 void 906 setMemAccPredicate(bool val) 907 { 908 instFlags[MemAccPredicate] = val; 909 } 910 911 /** Sets the ASID. */ 912 void setASID(short addr_space_id) { asid = addr_space_id; } 913 short getASID() { return asid; } 914 915 /** Sets the thread id. */ 916 void setTid(ThreadID tid) { threadNumber = tid; } 917 918 /** Sets the pointer to the thread state. */ 919 void setThreadState(ImplState *state) { thread = state; } 920 921 /** Returns the thread context. */ 922 ThreadContext *tcBase() { return thread->getTC(); } 923 924 public: 925 /** Returns whether or not the eff. addr. source registers are ready. */ 926 bool eaSrcsReady() const; 927 928 /** Is this instruction's memory access strictly ordered? */ 929 bool strictlyOrdered() const { return instFlags[IsStrictlyOrdered]; } 930 void strictlyOrdered(bool so) { instFlags[IsStrictlyOrdered] = so; } 931 932 /** Has this instruction generated a memory request. */ 933 bool hasRequest() const { return instFlags[ReqMade]; } 934 /** Assert this instruction has generated a memory request. */ 935 void setRequest() { instFlags[ReqMade] = true; } 936 937 /** Returns iterator to this instruction in the list of all insts. */ 938 ListIt &getInstListIt() { return instListIt; } 939 940 /** Sets iterator for this instruction in the list of all insts. */ 941 void setInstListIt(ListIt _instListIt) { instListIt = _instListIt; } 942 943 public: 944 /** Returns the number of consecutive store conditional failures. */ 945 unsigned int readStCondFailures() const 946 { return thread->storeCondFailures; } 947 948 /** Sets the number of consecutive store conditional failures. */ 949 void setStCondFailures(unsigned int sc_failures) 950 { thread->storeCondFailures = sc_failures; } 951 952 public: 953 // monitor/mwait funtions 954 void armMonitor(Addr address) { cpu->armMonitor(threadNumber, address); } 955 bool mwait(PacketPtr pkt) { return cpu->mwait(threadNumber, pkt); } 956 void mwaitAtomic(ThreadContext *tc) 957 { return cpu->mwaitAtomic(threadNumber, tc, cpu->dtb); } 958 AddressMonitor *getAddrMonitor() 959 { return cpu->getCpuAddrMonitor(threadNumber); } 960}; 961 962template<class Impl> 963Fault 964BaseDynInst<Impl>::initiateMemRead(Addr addr, unsigned size, 965 Request::Flags flags, 966 const std::vector<bool>& byteEnable) 967{ 968 return cpu->pushRequest( 969 dynamic_cast<typename DynInstPtr::PtrType>(this), 970 /* ld */ true, nullptr, size, addr, flags, nullptr, nullptr, 971 byteEnable); 972} 973 974template<class Impl> 975Fault 976BaseDynInst<Impl>::writeMem(uint8_t *data, unsigned size, Addr addr, 977 Request::Flags flags, uint64_t *res, 978 const std::vector<bool>& byteEnable) 979{ 980 return cpu->pushRequest( 981 dynamic_cast<typename DynInstPtr::PtrType>(this), 982 /* st */ false, data, size, addr, flags, res, nullptr, byteEnable); 983} 984 985template<class Impl> 986Fault 987BaseDynInst<Impl>::initiateMemAMO(Addr addr, unsigned size, 988 Request::Flags flags, 989 AtomicOpFunctorPtr amo_op) 990{ 991 // atomic memory instructions do not have data to be written to memory yet 992 // since the atomic operations will be executed directly in cache/memory. 993 // Therefore, its `data` field is nullptr. 994 // Atomic memory requests need to carry their `amo_op` fields to cache/ 995 // memory 996 return cpu->pushRequest( 997 dynamic_cast<typename DynInstPtr::PtrType>(this), 998 /* atomic */ false, nullptr, size, addr, flags, nullptr, 999 std::move(amo_op)); 1000} 1001 1002#endif // __CPU_BASE_DYN_INST_HH__ 1003