11060SN/A/*
214025Sgiacomo.gabrielli@arm.com * Copyright (c) 2011, 2013, 2016-2019 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>
5112109SRekai.GonzalezAlberquilla@arm.com#include <deque>
522292SN/A#include <list>
531464SN/A#include <string>
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"
6010319SAndreas.Sandberg@ARM.com#include "cpu/exec_context.hh"
611464SN/A#include "cpu/exetrace.hh"
6212107SRekai.GonzalezAlberquilla@arm.com#include "cpu/inst_res.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;
8412109SRekai.GonzalezAlberquilla@arm.com    using VecRegContainer = TheISA::VecRegContainer;
851060SN/A
8613590Srekai.gonzalezalberquilla@arm.com    using LSQRequestPtr = typename Impl::CPUPol::LSQ::LSQRequest*;
8713590Srekai.gonzalezalberquilla@arm.com    using LQIterator = typename Impl::CPUPol::LSQUnit::LQIterator;
8813590Srekai.gonzalezalberquilla@arm.com    using SQIterator = typename Impl::CPUPol::LSQUnit::SQIterator;
8913590Srekai.gonzalezalberquilla@arm.com
902292SN/A    // The DynInstPtr type.
912292SN/A    typedef typename Impl::DynInstPtr DynInstPtr;
928486Sgblack@eecs.umich.edu    typedef RefCountingPtr<BaseDynInst<Impl> > BaseDynInstPtr;
932292SN/A
942292SN/A    // The list of instructions iterator type.
952292SN/A    typedef typename std::list<DynInstPtr>::iterator ListIt;
962292SN/A
971060SN/A    enum {
985543Ssaidi@eecs.umich.edu        MaxInstSrcRegs = TheISA::MaxInstSrcRegs,        /// Max source regs
998902Sandreas.hansson@arm.com        MaxInstDestRegs = TheISA::MaxInstDestRegs       /// Max dest regs
1001060SN/A    };
1011060SN/A
1029046SAli.Saidi@ARM.com  protected:
1039046SAli.Saidi@ARM.com    enum Status {
1049046SAli.Saidi@ARM.com        IqEntry,                 /// Instruction is in the IQ
1059046SAli.Saidi@ARM.com        RobEntry,                /// Instruction is in the ROB
1069046SAli.Saidi@ARM.com        LsqEntry,                /// Instruction is in the LSQ
1079046SAli.Saidi@ARM.com        Completed,               /// Instruction has completed
1089046SAli.Saidi@ARM.com        ResultReady,             /// Instruction has its result
1099046SAli.Saidi@ARM.com        CanIssue,                /// Instruction can issue and execute
1109046SAli.Saidi@ARM.com        Issued,                  /// Instruction has issued
1119046SAli.Saidi@ARM.com        Executed,                /// Instruction has executed
1129046SAli.Saidi@ARM.com        CanCommit,               /// Instruction can commit
1139046SAli.Saidi@ARM.com        AtCommit,                /// Instruction has reached commit
1149046SAli.Saidi@ARM.com        Committed,               /// Instruction has committed
1159046SAli.Saidi@ARM.com        Squashed,                /// Instruction is squashed
1169046SAli.Saidi@ARM.com        SquashedInIQ,            /// Instruction is squashed in the IQ
1179046SAli.Saidi@ARM.com        SquashedInLSQ,           /// Instruction is squashed in the LSQ
1189046SAli.Saidi@ARM.com        SquashedInROB,           /// Instruction is squashed in the ROB
11914025Sgiacomo.gabrielli@arm.com        PinnedRegsRenamed,       /// Pinned registers are renamed
12014025Sgiacomo.gabrielli@arm.com        PinnedRegsWritten,       /// Pinned registers are written back
12114025Sgiacomo.gabrielli@arm.com        PinnedRegsSquashDone,    /// Regs pinning status updated after squash
1229046SAli.Saidi@ARM.com        RecoverInst,             /// Is a recover instruction
1239046SAli.Saidi@ARM.com        BlockingInst,            /// Is a blocking instruction
1249046SAli.Saidi@ARM.com        ThreadsyncWait,          /// Is a thread synchronization instruction
1259046SAli.Saidi@ARM.com        SerializeBefore,         /// Needs to serialize on
1269046SAli.Saidi@ARM.com                                 /// instructions ahead of it
1279046SAli.Saidi@ARM.com        SerializeAfter,          /// Needs to serialize instructions behind it
1289046SAli.Saidi@ARM.com        SerializeHandled,        /// Serialization has been handled
1299046SAli.Saidi@ARM.com        NumStatus
1309046SAli.Saidi@ARM.com    };
1319046SAli.Saidi@ARM.com
1329046SAli.Saidi@ARM.com    enum Flags {
13312421Sgabeblack@google.com        NotAnInst,
1349046SAli.Saidi@ARM.com        TranslationStarted,
1359046SAli.Saidi@ARM.com        TranslationCompleted,
1369046SAli.Saidi@ARM.com        PossibleLoadViolation,
1379046SAli.Saidi@ARM.com        HitExternalSnoop,
1389046SAli.Saidi@ARM.com        EffAddrValid,
1399046SAli.Saidi@ARM.com        RecordResult,
1409046SAli.Saidi@ARM.com        Predicate,
14113953Sgiacomo.gabrielli@arm.com        MemAccPredicate,
1429046SAli.Saidi@ARM.com        PredTaken,
14310824SAndreas.Sandberg@ARM.com        IsStrictlyOrdered,
1449046SAli.Saidi@ARM.com        ReqMade,
1459046SAli.Saidi@ARM.com        MemOpDone,
1469046SAli.Saidi@ARM.com        MaxFlags
1479046SAli.Saidi@ARM.com    };
1489046SAli.Saidi@ARM.com
1499046SAli.Saidi@ARM.com  public:
1509046SAli.Saidi@ARM.com    /** The sequence number of the instruction. */
1519046SAli.Saidi@ARM.com    InstSeqNum seqNum;
1529046SAli.Saidi@ARM.com
1532292SN/A    /** The StaticInst used by this BaseDynInst. */
15410417Sandreas.hansson@arm.com    const StaticInstPtr staticInst;
1559046SAli.Saidi@ARM.com
1569046SAli.Saidi@ARM.com    /** Pointer to the Impl's CPU object. */
1579046SAli.Saidi@ARM.com    ImplCPU *cpu;
1589046SAli.Saidi@ARM.com
15910030SAli.Saidi@ARM.com    BaseCPU *getCpuPtr() { return cpu; }
16010030SAli.Saidi@ARM.com
1619046SAli.Saidi@ARM.com    /** Pointer to the thread state. */
1629046SAli.Saidi@ARM.com    ImplState *thread;
1639046SAli.Saidi@ARM.com
1649046SAli.Saidi@ARM.com    /** The kind of fault this instruction has generated. */
1659046SAli.Saidi@ARM.com    Fault fault;
1669046SAli.Saidi@ARM.com
1679046SAli.Saidi@ARM.com    /** InstRecord that tracks this instructions. */
1689046SAli.Saidi@ARM.com    Trace::InstRecord *traceData;
1699046SAli.Saidi@ARM.com
1709046SAli.Saidi@ARM.com  protected:
1719046SAli.Saidi@ARM.com    /** The result of the instruction; assumes an instruction can have many
1729046SAli.Saidi@ARM.com     *  destination registers.
1739046SAli.Saidi@ARM.com     */
17412107SRekai.GonzalezAlberquilla@arm.com    std::queue<InstResult> instResult;
1759046SAli.Saidi@ARM.com
1769046SAli.Saidi@ARM.com    /** PC state for this instruction. */
1779046SAli.Saidi@ARM.com    TheISA::PCState pc;
1789046SAli.Saidi@ARM.com
17914025Sgiacomo.gabrielli@arm.com  private:
1809046SAli.Saidi@ARM.com    /* An amalgamation of a lot of boolean values into one */
1819046SAli.Saidi@ARM.com    std::bitset<MaxFlags> instFlags;
1829046SAli.Saidi@ARM.com
1839046SAli.Saidi@ARM.com    /** The status of this BaseDynInst.  Several bits can be set. */
1849046SAli.Saidi@ARM.com    std::bitset<NumStatus> status;
1859046SAli.Saidi@ARM.com
18614025Sgiacomo.gabrielli@arm.com  protected:
1879046SAli.Saidi@ARM.com     /** Whether or not the source register is ready.
1889046SAli.Saidi@ARM.com     *  @todo: Not sure this should be here vs the derived class.
1899046SAli.Saidi@ARM.com     */
1909046SAli.Saidi@ARM.com    std::bitset<MaxInstSrcRegs> _readySrcRegIdx;
1919046SAli.Saidi@ARM.com
1929046SAli.Saidi@ARM.com  public:
1939046SAli.Saidi@ARM.com    /** The thread this instruction is from. */
1949046SAli.Saidi@ARM.com    ThreadID threadNumber;
1959046SAli.Saidi@ARM.com
1969046SAli.Saidi@ARM.com    /** Iterator pointing to this BaseDynInst in the list of all insts. */
1979046SAli.Saidi@ARM.com    ListIt instListIt;
1989046SAli.Saidi@ARM.com
1999046SAli.Saidi@ARM.com    ////////////////////// Branch Data ///////////////
2009046SAli.Saidi@ARM.com    /** Predicted PC state after this instruction. */
2019046SAli.Saidi@ARM.com    TheISA::PCState predPC;
2029046SAli.Saidi@ARM.com
2039046SAli.Saidi@ARM.com    /** The Macroop if one exists */
20410417Sandreas.hansson@arm.com    const StaticInstPtr macroop;
2051060SN/A
2069046SAli.Saidi@ARM.com    /** How many source registers are ready. */
2079046SAli.Saidi@ARM.com    uint8_t readyRegs;
2089046SAli.Saidi@ARM.com
2099046SAli.Saidi@ARM.com  public:
2109046SAli.Saidi@ARM.com    /////////////////////// Load Store Data //////////////////////
2119046SAli.Saidi@ARM.com    /** The effective virtual address (lds & stores only). */
2129046SAli.Saidi@ARM.com    Addr effAddr;
2139046SAli.Saidi@ARM.com
2149046SAli.Saidi@ARM.com    /** The effective physical address. */
21513590Srekai.gonzalezalberquilla@arm.com    Addr physEffAddr;
2169046SAli.Saidi@ARM.com
2179046SAli.Saidi@ARM.com    /** The memory request flags (from translation). */
2189046SAli.Saidi@ARM.com    unsigned memReqFlags;
2199046SAli.Saidi@ARM.com
2209046SAli.Saidi@ARM.com    /** data address space ID, for loads & stores. */
2219046SAli.Saidi@ARM.com    short asid;
2229046SAli.Saidi@ARM.com
2239046SAli.Saidi@ARM.com    /** The size of the request */
22414112Sgabor.dozsa@arm.com    unsigned effSize;
2259046SAli.Saidi@ARM.com
2269046SAli.Saidi@ARM.com    /** Pointer to the data for the memory access. */
2279046SAli.Saidi@ARM.com    uint8_t *memData;
2289046SAli.Saidi@ARM.com
2299046SAli.Saidi@ARM.com    /** Load queue index. */
2309046SAli.Saidi@ARM.com    int16_t lqIdx;
23113590Srekai.gonzalezalberquilla@arm.com    LQIterator lqIt;
2329046SAli.Saidi@ARM.com
2339046SAli.Saidi@ARM.com    /** Store queue index. */
2349046SAli.Saidi@ARM.com    int16_t sqIdx;
23513590Srekai.gonzalezalberquilla@arm.com    SQIterator sqIt;
2369046SAli.Saidi@ARM.com
2379046SAli.Saidi@ARM.com
2389046SAli.Saidi@ARM.com    /////////////////////// TLB Miss //////////////////////
2399046SAli.Saidi@ARM.com    /**
24013590Srekai.gonzalezalberquilla@arm.com     * Saved memory request (needed when the DTB address translation is
2419046SAli.Saidi@ARM.com     * delayed due to a hw page table walk).
2429046SAli.Saidi@ARM.com     */
24313590Srekai.gonzalezalberquilla@arm.com    LSQRequestPtr savedReq;
2449046SAli.Saidi@ARM.com
2459046SAli.Saidi@ARM.com    /////////////////////// Checker //////////////////////
2469046SAli.Saidi@ARM.com    // Need a copy of main request pointer to verify on writes.
2479046SAli.Saidi@ARM.com    RequestPtr reqToVerify;
2489046SAli.Saidi@ARM.com
2499046SAli.Saidi@ARM.com  protected:
2509046SAli.Saidi@ARM.com    /** Flattened register index of the destination registers of this
2519046SAli.Saidi@ARM.com     *  instruction.
2529046SAli.Saidi@ARM.com     */
25312104Snathanael.premillieu@arm.com    std::array<RegId, TheISA::MaxInstDestRegs> _flatDestRegIdx;
2549046SAli.Saidi@ARM.com
2559046SAli.Saidi@ARM.com    /** Physical register index of the destination registers of this
2569046SAli.Saidi@ARM.com     *  instruction.
2579046SAli.Saidi@ARM.com     */
25812105Snathanael.premillieu@arm.com    std::array<PhysRegIdPtr, TheISA::MaxInstDestRegs> _destRegIdx;
2599046SAli.Saidi@ARM.com
2609046SAli.Saidi@ARM.com    /** Physical register index of the source registers of this
2619046SAli.Saidi@ARM.com     *  instruction.
2629046SAli.Saidi@ARM.com     */
26312105Snathanael.premillieu@arm.com    std::array<PhysRegIdPtr, TheISA::MaxInstSrcRegs> _srcRegIdx;
2649046SAli.Saidi@ARM.com
2659046SAli.Saidi@ARM.com    /** Physical register index of the previous producers of the
2669046SAli.Saidi@ARM.com     *  architected destinations.
2679046SAli.Saidi@ARM.com     */
26812105Snathanael.premillieu@arm.com    std::array<PhysRegIdPtr, TheISA::MaxInstDestRegs> _prevDestRegIdx;
2699046SAli.Saidi@ARM.com
2709046SAli.Saidi@ARM.com
2719046SAli.Saidi@ARM.com  public:
2729046SAli.Saidi@ARM.com    /** Records changes to result? */
2739046SAli.Saidi@ARM.com    void recordResult(bool f) { instFlags[RecordResult] = f; }
2749046SAli.Saidi@ARM.com
2759046SAli.Saidi@ARM.com    /** Is the effective virtual address valid. */
2769046SAli.Saidi@ARM.com    bool effAddrValid() const { return instFlags[EffAddrValid]; }
27713590Srekai.gonzalezalberquilla@arm.com    void effAddrValid(bool b) { instFlags[EffAddrValid] = b; }
2789046SAli.Saidi@ARM.com
2799046SAli.Saidi@ARM.com    /** Whether or not the memory operation is done. */
2809046SAli.Saidi@ARM.com    bool memOpDone() const { return instFlags[MemOpDone]; }
2819046SAli.Saidi@ARM.com    void memOpDone(bool f) { instFlags[MemOpDone] = f; }
2829046SAli.Saidi@ARM.com
28312421Sgabeblack@google.com    bool notAnInst() const { return instFlags[NotAnInst]; }
28412421Sgabeblack@google.com    void setNotAnInst() { instFlags[NotAnInst] = true; }
28512421Sgabeblack@google.com
2869046SAli.Saidi@ARM.com
2871060SN/A    ////////////////////////////////////////////
2881060SN/A    //
2891060SN/A    // INSTRUCTION EXECUTION
2901060SN/A    //
2911060SN/A    ////////////////////////////////////////////
2921060SN/A
2935358Sgblack@eecs.umich.edu    void demapPage(Addr vaddr, uint64_t asn)
2945358Sgblack@eecs.umich.edu    {
2955358Sgblack@eecs.umich.edu        cpu->demapPage(vaddr, asn);
2965358Sgblack@eecs.umich.edu    }
2975358Sgblack@eecs.umich.edu    void demapInstPage(Addr vaddr, uint64_t asn)
2985358Sgblack@eecs.umich.edu    {
2995358Sgblack@eecs.umich.edu        cpu->demapPage(vaddr, asn);
3005358Sgblack@eecs.umich.edu    }
3015358Sgblack@eecs.umich.edu    void demapDataPage(Addr vaddr, uint64_t asn)
3025358Sgblack@eecs.umich.edu    {
3035358Sgblack@eecs.umich.edu        cpu->demapPage(vaddr, asn);
3045358Sgblack@eecs.umich.edu    }
3055358Sgblack@eecs.umich.edu
30613954Sgiacomo.gabrielli@arm.com    Fault initiateMemRead(Addr addr, unsigned size, Request::Flags flags,
30713954Sgiacomo.gabrielli@arm.com            const std::vector<bool>& byteEnable = std::vector<bool>());
3087520Sgblack@eecs.umich.edu
30911608Snikos.nikoleris@arm.com    Fault writeMem(uint8_t *data, unsigned size, Addr addr,
31013954Sgiacomo.gabrielli@arm.com                   Request::Flags flags, uint64_t *res,
31113954Sgiacomo.gabrielli@arm.com                   const std::vector<bool>& byteEnable = std::vector<bool>());
3127520Sgblack@eecs.umich.edu
31313652Sqtt2@cornell.edu    Fault initiateMemAMO(Addr addr, unsigned size, Request::Flags flags,
31414297Sjordi.vaquero@metempsy.com                         AtomicOpFunctorPtr amo_op);
31513652Sqtt2@cornell.edu
3167944SGiacomo.Gabrielli@arm.com    /** True if the DTB address translation has started. */
3179046SAli.Saidi@ARM.com    bool translationStarted() const { return instFlags[TranslationStarted]; }
3189046SAli.Saidi@ARM.com    void translationStarted(bool f) { instFlags[TranslationStarted] = f; }
3197944SGiacomo.Gabrielli@arm.com
3207944SGiacomo.Gabrielli@arm.com    /** True if the DTB address translation has completed. */
3219046SAli.Saidi@ARM.com    bool translationCompleted() const { return instFlags[TranslationCompleted]; }
3229046SAli.Saidi@ARM.com    void translationCompleted(bool f) { instFlags[TranslationCompleted] = f; }
3237944SGiacomo.Gabrielli@arm.com
3248545Ssaidi@eecs.umich.edu    /** True if this address was found to match a previous load and they issued
3258545Ssaidi@eecs.umich.edu     * out of order. If that happend, then it's only a problem if an incoming
3268545Ssaidi@eecs.umich.edu     * snoop invalidate modifies the line, in which case we need to squash.
3278545Ssaidi@eecs.umich.edu     * If nothing modified the line the order doesn't matter.
3288545Ssaidi@eecs.umich.edu     */
3299046SAli.Saidi@ARM.com    bool possibleLoadViolation() const { return instFlags[PossibleLoadViolation]; }
3309046SAli.Saidi@ARM.com    void possibleLoadViolation(bool f) { instFlags[PossibleLoadViolation] = f; }
3318545Ssaidi@eecs.umich.edu
3328545Ssaidi@eecs.umich.edu    /** True if the address hit a external snoop while sitting in the LSQ.
3338545Ssaidi@eecs.umich.edu     * If this is true and a older instruction sees it, this instruction must
3348545Ssaidi@eecs.umich.edu     * reexecute
3358545Ssaidi@eecs.umich.edu     */
3369046SAli.Saidi@ARM.com    bool hitExternalSnoop() const { return instFlags[HitExternalSnoop]; }
3379046SAli.Saidi@ARM.com    void hitExternalSnoop(bool f) { instFlags[HitExternalSnoop] = f; }
3388545Ssaidi@eecs.umich.edu
3397944SGiacomo.Gabrielli@arm.com    /**
3407944SGiacomo.Gabrielli@arm.com     * Returns true if the DTB address translation is being delayed due to a hw
3417944SGiacomo.Gabrielli@arm.com     * page table walk.
3427944SGiacomo.Gabrielli@arm.com     */
3437944SGiacomo.Gabrielli@arm.com    bool isTranslationDelayed() const
3447944SGiacomo.Gabrielli@arm.com    {
3459046SAli.Saidi@ARM.com        return (translationStarted() && !translationCompleted());
3467944SGiacomo.Gabrielli@arm.com    }
3477944SGiacomo.Gabrielli@arm.com
3481060SN/A  public:
3492292SN/A#ifdef DEBUG
3502292SN/A    void dumpSNList();
3512292SN/A#endif
3522292SN/A
3533770Sgblack@eecs.umich.edu    /** Returns the physical register index of the i'th destination
3543770Sgblack@eecs.umich.edu     *  register.
3553770Sgblack@eecs.umich.edu     */
35612105Snathanael.premillieu@arm.com    PhysRegIdPtr renamedDestRegIdx(int idx) const
3573770Sgblack@eecs.umich.edu    {
3583770Sgblack@eecs.umich.edu        return _destRegIdx[idx];
3593770Sgblack@eecs.umich.edu    }
3603770Sgblack@eecs.umich.edu
3613770Sgblack@eecs.umich.edu    /** Returns the physical register index of the i'th source register. */
36212105Snathanael.premillieu@arm.com    PhysRegIdPtr renamedSrcRegIdx(int idx) const
3633770Sgblack@eecs.umich.edu    {
3649046SAli.Saidi@ARM.com        assert(TheISA::MaxInstSrcRegs > idx);
3653770Sgblack@eecs.umich.edu        return _srcRegIdx[idx];
3663770Sgblack@eecs.umich.edu    }
3673770Sgblack@eecs.umich.edu
3683770Sgblack@eecs.umich.edu    /** Returns the flattened register index of the i'th destination
3693770Sgblack@eecs.umich.edu     *  register.
3703770Sgblack@eecs.umich.edu     */
37112106SRekai.GonzalezAlberquilla@arm.com    const RegId& flattenedDestRegIdx(int idx) const
3723770Sgblack@eecs.umich.edu    {
3733770Sgblack@eecs.umich.edu        return _flatDestRegIdx[idx];
3743770Sgblack@eecs.umich.edu    }
3753770Sgblack@eecs.umich.edu
3763770Sgblack@eecs.umich.edu    /** Returns the physical register index of the previous physical register
3773770Sgblack@eecs.umich.edu     *  that remapped to the same logical register index.
3783770Sgblack@eecs.umich.edu     */
37912105Snathanael.premillieu@arm.com    PhysRegIdPtr prevDestRegIdx(int idx) const
3803770Sgblack@eecs.umich.edu    {
3813770Sgblack@eecs.umich.edu        return _prevDestRegIdx[idx];
3823770Sgblack@eecs.umich.edu    }
3833770Sgblack@eecs.umich.edu
3843770Sgblack@eecs.umich.edu    /** Renames a destination register to a physical register.  Also records
3853770Sgblack@eecs.umich.edu     *  the previous physical register that the logical register mapped to.
3863770Sgblack@eecs.umich.edu     */
3873770Sgblack@eecs.umich.edu    void renameDestReg(int idx,
38812105Snathanael.premillieu@arm.com                       PhysRegIdPtr renamed_dest,
38912105Snathanael.premillieu@arm.com                       PhysRegIdPtr previous_rename)
3903770Sgblack@eecs.umich.edu    {
3913770Sgblack@eecs.umich.edu        _destRegIdx[idx] = renamed_dest;
3923770Sgblack@eecs.umich.edu        _prevDestRegIdx[idx] = previous_rename;
39314025Sgiacomo.gabrielli@arm.com        if (renamed_dest->isPinned())
39414025Sgiacomo.gabrielli@arm.com            setPinnedRegsRenamed();
3953770Sgblack@eecs.umich.edu    }
3963770Sgblack@eecs.umich.edu
3973770Sgblack@eecs.umich.edu    /** Renames a source logical register to the physical register which
3983770Sgblack@eecs.umich.edu     *  has/will produce that logical register's result.
3993770Sgblack@eecs.umich.edu     *  @todo: add in whether or not the source register is ready.
4003770Sgblack@eecs.umich.edu     */
40112105Snathanael.premillieu@arm.com    void renameSrcReg(int idx, PhysRegIdPtr renamed_src)
4023770Sgblack@eecs.umich.edu    {
4033770Sgblack@eecs.umich.edu        _srcRegIdx[idx] = renamed_src;
4043770Sgblack@eecs.umich.edu    }
4053770Sgblack@eecs.umich.edu
4063770Sgblack@eecs.umich.edu    /** Flattens a destination architectural register index into a logical
4073770Sgblack@eecs.umich.edu     * index.
4083770Sgblack@eecs.umich.edu     */
40912106SRekai.GonzalezAlberquilla@arm.com    void flattenDestReg(int idx, const RegId& flattened_dest)
4103770Sgblack@eecs.umich.edu    {
4113770Sgblack@eecs.umich.edu        _flatDestRegIdx[idx] = flattened_dest;
4123770Sgblack@eecs.umich.edu    }
4134636Sgblack@eecs.umich.edu    /** BaseDynInst constructor given a binary instruction.
4144636Sgblack@eecs.umich.edu     *  @param staticInst A StaticInstPtr to the underlying instruction.
4157720Sgblack@eecs.umich.edu     *  @param pc The PC state for the instruction.
4167720Sgblack@eecs.umich.edu     *  @param predPC The predicted next PC state for the instruction.
4174636Sgblack@eecs.umich.edu     *  @param seq_num The sequence number of the instruction.
4184636Sgblack@eecs.umich.edu     *  @param cpu Pointer to the instruction's CPU.
4194636Sgblack@eecs.umich.edu     */
42010417Sandreas.hansson@arm.com    BaseDynInst(const StaticInstPtr &staticInst, const StaticInstPtr &macroop,
4218502Sgblack@eecs.umich.edu                TheISA::PCState pc, TheISA::PCState predPC,
4228502Sgblack@eecs.umich.edu                InstSeqNum seq_num, ImplCPU *cpu);
4233770Sgblack@eecs.umich.edu
4242292SN/A    /** BaseDynInst constructor given a StaticInst pointer.
4252292SN/A     *  @param _staticInst The StaticInst for this BaseDynInst.
4262292SN/A     */
42710417Sandreas.hansson@arm.com    BaseDynInst(const StaticInstPtr &staticInst, const StaticInstPtr &macroop);
4281060SN/A
4291060SN/A    /** BaseDynInst destructor. */
4301060SN/A    ~BaseDynInst();
4311060SN/A
4321464SN/A  private:
4331684SN/A    /** Function to initialize variables in the constructors. */
4341464SN/A    void initVars();
4351060SN/A
4361464SN/A  public:
4371060SN/A    /** Dumps out contents of this BaseDynInst. */
4381060SN/A    void dump();
4391060SN/A
4401060SN/A    /** Dumps out contents of this BaseDynInst into given string. */
4411060SN/A    void dump(std::string &outstring);
4421060SN/A
4433326Sktlim@umich.edu    /** Read this CPU's ID. */
44410110Sandreas.hansson@arm.com    int cpuId() const { return cpu->cpuId(); }
4453326Sktlim@umich.edu
44610190Sakash.bagdia@arm.com    /** Read this CPU's Socket ID. */
44710190Sakash.bagdia@arm.com    uint32_t socketId() const { return cpu->socketId(); }
44810190Sakash.bagdia@arm.com
4498832SAli.Saidi@ARM.com    /** Read this CPU's data requestor ID */
45010110Sandreas.hansson@arm.com    MasterID masterId() const { return cpu->dataMasterId(); }
4518832SAli.Saidi@ARM.com
4525714Shsul@eecs.umich.edu    /** Read this context's system-wide ID **/
45311005Sandreas.sandberg@arm.com    ContextID contextId() const { return thread->contextId(); }
4545714Shsul@eecs.umich.edu
4551060SN/A    /** Returns the fault type. */
45610110Sandreas.hansson@arm.com    Fault getFault() const { return fault; }
45713590Srekai.gonzalezalberquilla@arm.com    /** TODO: This I added for the LSQRequest side to be able to modify the
45813590Srekai.gonzalezalberquilla@arm.com     * fault. There should be a better mechanism in place. */
45913590Srekai.gonzalezalberquilla@arm.com    Fault& getFault() { return fault; }
4601060SN/A
4611060SN/A    /** Checks whether or not this instruction has had its branch target
4621060SN/A     *  calculated yet.  For now it is not utilized and is hacked to be
4631060SN/A     *  always false.
4642292SN/A     *  @todo: Actually use this instruction.
4651060SN/A     */
4661060SN/A    bool doneTargCalc() { return false; }
4671060SN/A
4687720Sgblack@eecs.umich.edu    /** Set the predicted target of this current instruction. */
4697720Sgblack@eecs.umich.edu    void setPredTarg(const TheISA::PCState &_predPC)
4703965Sgblack@eecs.umich.edu    {
4717720Sgblack@eecs.umich.edu        predPC = _predPC;
4723965Sgblack@eecs.umich.edu    }
4732935Sksewell@umich.edu
4747720Sgblack@eecs.umich.edu    const TheISA::PCState &readPredTarg() { return predPC; }
4751060SN/A
4763794Sgblack@eecs.umich.edu    /** Returns the predicted PC immediately after the branch. */
4777720Sgblack@eecs.umich.edu    Addr predInstAddr() { return predPC.instAddr(); }
4783794Sgblack@eecs.umich.edu
4793794Sgblack@eecs.umich.edu    /** Returns the predicted PC two instructions after the branch */
4807720Sgblack@eecs.umich.edu    Addr predNextInstAddr() { return predPC.nextInstAddr(); }
4811060SN/A
4824636Sgblack@eecs.umich.edu    /** Returns the predicted micro PC after the branch */
4837720Sgblack@eecs.umich.edu    Addr predMicroPC() { return predPC.microPC(); }
4844636Sgblack@eecs.umich.edu
4851060SN/A    /** Returns whether the instruction was predicted taken or not. */
4863794Sgblack@eecs.umich.edu    bool readPredTaken()
4873794Sgblack@eecs.umich.edu    {
4889046SAli.Saidi@ARM.com        return instFlags[PredTaken];
4893794Sgblack@eecs.umich.edu    }
4903794Sgblack@eecs.umich.edu
4913794Sgblack@eecs.umich.edu    void setPredTaken(bool predicted_taken)
4923794Sgblack@eecs.umich.edu    {
4939046SAli.Saidi@ARM.com        instFlags[PredTaken] = predicted_taken;
4943794Sgblack@eecs.umich.edu    }
4951060SN/A
4961060SN/A    /** Returns whether the instruction mispredicted. */
4972935Sksewell@umich.edu    bool mispredicted()
4983794Sgblack@eecs.umich.edu    {
4997720Sgblack@eecs.umich.edu        TheISA::PCState tempPC = pc;
5007720Sgblack@eecs.umich.edu        TheISA::advancePC(tempPC, staticInst);
5017720Sgblack@eecs.umich.edu        return !(tempPC == predPC);
5023794Sgblack@eecs.umich.edu    }
5033794Sgblack@eecs.umich.edu
5041060SN/A    //
5051060SN/A    //  Instruction types.  Forward checks to StaticInst object.
5061060SN/A    //
5075543Ssaidi@eecs.umich.edu    bool isNop()          const { return staticInst->isNop(); }
5085543Ssaidi@eecs.umich.edu    bool isMemRef()       const { return staticInst->isMemRef(); }
5095543Ssaidi@eecs.umich.edu    bool isLoad()         const { return staticInst->isLoad(); }
5105543Ssaidi@eecs.umich.edu    bool isStore()        const { return staticInst->isStore(); }
51112768Sqtt2@cornell.edu    bool isAtomic()       const { return staticInst->isAtomic(); }
5122336SN/A    bool isStoreConditional() const
5132336SN/A    { return staticInst->isStoreConditional(); }
5141060SN/A    bool isInstPrefetch() const { return staticInst->isInstPrefetch(); }
5151060SN/A    bool isDataPrefetch() const { return staticInst->isDataPrefetch(); }
5165543Ssaidi@eecs.umich.edu    bool isInteger()      const { return staticInst->isInteger(); }
5175543Ssaidi@eecs.umich.edu    bool isFloating()     const { return staticInst->isFloating(); }
51812110SRekai.GonzalezAlberquilla@arm.com    bool isVector()       const { return staticInst->isVector(); }
5195543Ssaidi@eecs.umich.edu    bool isControl()      const { return staticInst->isControl(); }
5205543Ssaidi@eecs.umich.edu    bool isCall()         const { return staticInst->isCall(); }
5215543Ssaidi@eecs.umich.edu    bool isReturn()       const { return staticInst->isReturn(); }
5225543Ssaidi@eecs.umich.edu    bool isDirectCtrl()   const { return staticInst->isDirectCtrl(); }
5231060SN/A    bool isIndirectCtrl() const { return staticInst->isIndirectCtrl(); }
5245543Ssaidi@eecs.umich.edu    bool isCondCtrl()     const { return staticInst->isCondCtrl(); }
5255543Ssaidi@eecs.umich.edu    bool isUncondCtrl()   const { return staticInst->isUncondCtrl(); }
5262935Sksewell@umich.edu    bool isCondDelaySlot() const { return staticInst->isCondDelaySlot(); }
5271060SN/A    bool isThreadSync()   const { return staticInst->isThreadSync(); }
5281060SN/A    bool isSerializing()  const { return staticInst->isSerializing(); }
5292292SN/A    bool isSerializeBefore() const
5302731Sktlim@umich.edu    { return staticInst->isSerializeBefore() || status[SerializeBefore]; }
5312292SN/A    bool isSerializeAfter() const
5322731Sktlim@umich.edu    { return staticInst->isSerializeAfter() || status[SerializeAfter]; }
5337784SAli.Saidi@ARM.com    bool isSquashAfter() const { return staticInst->isSquashAfter(); }
5341060SN/A    bool isMemBarrier()   const { return staticInst->isMemBarrier(); }
5351060SN/A    bool isWriteBarrier() const { return staticInst->isWriteBarrier(); }
5361060SN/A    bool isNonSpeculative() const { return staticInst->isNonSpeculative(); }
5372292SN/A    bool isQuiesce() const { return staticInst->isQuiesce(); }
5382336SN/A    bool isIprAccess() const { return staticInst->isIprAccess(); }
5392308SN/A    bool isUnverifiable() const { return staticInst->isUnverifiable(); }
5404828Sgblack@eecs.umich.edu    bool isSyscall() const { return staticInst->isSyscall(); }
5414654Sgblack@eecs.umich.edu    bool isMacroop() const { return staticInst->isMacroop(); }
5424654Sgblack@eecs.umich.edu    bool isMicroop() const { return staticInst->isMicroop(); }
5434636Sgblack@eecs.umich.edu    bool isDelayedCommit() const { return staticInst->isDelayedCommit(); }
5444654Sgblack@eecs.umich.edu    bool isLastMicroop() const { return staticInst->isLastMicroop(); }
5454654Sgblack@eecs.umich.edu    bool isFirstMicroop() const { return staticInst->isFirstMicroop(); }
5464636Sgblack@eecs.umich.edu    bool isMicroBranch() const { return staticInst->isMicroBranch(); }
5472292SN/A
5482292SN/A    /** Temporarily sets this instruction as a serialize before instruction. */
5492731Sktlim@umich.edu    void setSerializeBefore() { status.set(SerializeBefore); }
5502292SN/A
5512292SN/A    /** Clears the serializeBefore part of this instruction. */
5522731Sktlim@umich.edu    void clearSerializeBefore() { status.reset(SerializeBefore); }
5532292SN/A
5542292SN/A    /** Checks if this serializeBefore is only temporarily set. */
5552731Sktlim@umich.edu    bool isTempSerializeBefore() { return status[SerializeBefore]; }
5562292SN/A
5572292SN/A    /** Temporarily sets this instruction as a serialize after instruction. */
5582731Sktlim@umich.edu    void setSerializeAfter() { status.set(SerializeAfter); }
5592292SN/A
5602292SN/A    /** Clears the serializeAfter part of this instruction.*/
5612731Sktlim@umich.edu    void clearSerializeAfter() { status.reset(SerializeAfter); }
5622292SN/A
5632292SN/A    /** Checks if this serializeAfter is only temporarily set. */
5642731Sktlim@umich.edu    bool isTempSerializeAfter() { return status[SerializeAfter]; }
5652292SN/A
5662731Sktlim@umich.edu    /** Sets the serialization part of this instruction as handled. */
5672731Sktlim@umich.edu    void setSerializeHandled() { status.set(SerializeHandled); }
5682292SN/A
5692292SN/A    /** Checks if the serialization part of this instruction has been
5702292SN/A     *  handled.  This does not apply to the temporary serializing
5712292SN/A     *  state; it only applies to this instruction's own permanent
5722292SN/A     *  serializing state.
5732292SN/A     */
5742731Sktlim@umich.edu    bool isSerializeHandled() { return status[SerializeHandled]; }
5751060SN/A
5761464SN/A    /** Returns the opclass of this instruction. */
5771464SN/A    OpClass opClass() const { return staticInst->opClass(); }
5781464SN/A
5791464SN/A    /** Returns the branch target address. */
5807720Sgblack@eecs.umich.edu    TheISA::PCState branchTarget() const
5817720Sgblack@eecs.umich.edu    { return staticInst->branchTarget(pc); }
5821464SN/A
5832292SN/A    /** Returns the number of source registers. */
5845543Ssaidi@eecs.umich.edu    int8_t numSrcRegs() const { return staticInst->numSrcRegs(); }
5851684SN/A
5862292SN/A    /** Returns the number of destination registers. */
5871060SN/A    int8_t numDestRegs() const { return staticInst->numDestRegs(); }
5881060SN/A
5891060SN/A    // the following are used to track physical register usage
5901060SN/A    // for machines with separate int & FP reg files
5911060SN/A    int8_t numFPDestRegs()  const { return staticInst->numFPDestRegs(); }
5921060SN/A    int8_t numIntDestRegs() const { return staticInst->numIntDestRegs(); }
59310715SRekai.GonzalezAlberquilla@arm.com    int8_t numCCDestRegs() const { return staticInst->numCCDestRegs(); }
59412109SRekai.GonzalezAlberquilla@arm.com    int8_t numVecDestRegs() const { return staticInst->numVecDestRegs(); }
59513590Srekai.gonzalezalberquilla@arm.com    int8_t numVecElemDestRegs() const
59613590Srekai.gonzalezalberquilla@arm.com    {
59712109SRekai.GonzalezAlberquilla@arm.com        return staticInst->numVecElemDestRegs();
59812109SRekai.GonzalezAlberquilla@arm.com    }
59913610Sgiacomo.gabrielli@arm.com    int8_t
60013610Sgiacomo.gabrielli@arm.com    numVecPredDestRegs() const
60113610Sgiacomo.gabrielli@arm.com    {
60213610Sgiacomo.gabrielli@arm.com        return staticInst->numVecPredDestRegs();
60313610Sgiacomo.gabrielli@arm.com    }
6041060SN/A
6051060SN/A    /** Returns the logical register index of the i'th destination register. */
60612106SRekai.GonzalezAlberquilla@arm.com    const RegId& destRegIdx(int i) const { return staticInst->destRegIdx(i); }
6071060SN/A
6081060SN/A    /** Returns the logical register index of the i'th source register. */
60912106SRekai.GonzalezAlberquilla@arm.com    const RegId& srcRegIdx(int i) const { return staticInst->srcRegIdx(i); }
6101060SN/A
61112107SRekai.GonzalezAlberquilla@arm.com    /** Return the size of the instResult queue. */
61212107SRekai.GonzalezAlberquilla@arm.com    uint8_t resultSize() { return instResult.size(); }
61312107SRekai.GonzalezAlberquilla@arm.com
61412107SRekai.GonzalezAlberquilla@arm.com    /** Pops a result off the instResult queue.
61512107SRekai.GonzalezAlberquilla@arm.com     * If the result stack is empty, return the default value.
61612107SRekai.GonzalezAlberquilla@arm.com     * */
61712107SRekai.GonzalezAlberquilla@arm.com    InstResult popResult(InstResult dflt = InstResult())
6188733Sgeoffrey.blake@arm.com    {
6198733Sgeoffrey.blake@arm.com        if (!instResult.empty()) {
62012107SRekai.GonzalezAlberquilla@arm.com            InstResult t = instResult.front();
6218733Sgeoffrey.blake@arm.com            instResult.pop();
62212107SRekai.GonzalezAlberquilla@arm.com            return t;
6238733Sgeoffrey.blake@arm.com        }
62412107SRekai.GonzalezAlberquilla@arm.com        return dflt;
6258733Sgeoffrey.blake@arm.com    }
6261684SN/A
62712107SRekai.GonzalezAlberquilla@arm.com    /** Pushes a result onto the instResult queue. */
62812109SRekai.GonzalezAlberquilla@arm.com    /** @{ */
62912109SRekai.GonzalezAlberquilla@arm.com    /** Scalar result. */
63012107SRekai.GonzalezAlberquilla@arm.com    template<typename T>
63112107SRekai.GonzalezAlberquilla@arm.com    void setScalarResult(T&& t)
6328733Sgeoffrey.blake@arm.com    {
6339046SAli.Saidi@ARM.com        if (instFlags[RecordResult]) {
63412107SRekai.GonzalezAlberquilla@arm.com            instResult.push(InstResult(std::forward<T>(t),
63512107SRekai.GonzalezAlberquilla@arm.com                        InstResult::ResultType::Scalar));
6368733Sgeoffrey.blake@arm.com        }
6378733Sgeoffrey.blake@arm.com    }
6381060SN/A
63912109SRekai.GonzalezAlberquilla@arm.com    /** Full vector result. */
64012109SRekai.GonzalezAlberquilla@arm.com    template<typename T>
64112109SRekai.GonzalezAlberquilla@arm.com    void setVecResult(T&& t)
64212109SRekai.GonzalezAlberquilla@arm.com    {
64312109SRekai.GonzalezAlberquilla@arm.com        if (instFlags[RecordResult]) {
64412109SRekai.GonzalezAlberquilla@arm.com            instResult.push(InstResult(std::forward<T>(t),
64512109SRekai.GonzalezAlberquilla@arm.com                        InstResult::ResultType::VecReg));
64612109SRekai.GonzalezAlberquilla@arm.com        }
64712109SRekai.GonzalezAlberquilla@arm.com    }
64812109SRekai.GonzalezAlberquilla@arm.com
64912109SRekai.GonzalezAlberquilla@arm.com    /** Vector element result. */
65012109SRekai.GonzalezAlberquilla@arm.com    template<typename T>
65112109SRekai.GonzalezAlberquilla@arm.com    void setVecElemResult(T&& t)
65212109SRekai.GonzalezAlberquilla@arm.com    {
65312109SRekai.GonzalezAlberquilla@arm.com        if (instFlags[RecordResult]) {
65412109SRekai.GonzalezAlberquilla@arm.com            instResult.push(InstResult(std::forward<T>(t),
65512109SRekai.GonzalezAlberquilla@arm.com                        InstResult::ResultType::VecElem));
65612109SRekai.GonzalezAlberquilla@arm.com        }
65712109SRekai.GonzalezAlberquilla@arm.com    }
65813610Sgiacomo.gabrielli@arm.com
65913610Sgiacomo.gabrielli@arm.com    /** Predicate result. */
66013610Sgiacomo.gabrielli@arm.com    template<typename T>
66113610Sgiacomo.gabrielli@arm.com    void setVecPredResult(T&& t)
66213610Sgiacomo.gabrielli@arm.com    {
66313610Sgiacomo.gabrielli@arm.com        if (instFlags[RecordResult]) {
66413610Sgiacomo.gabrielli@arm.com            instResult.push(InstResult(std::forward<T>(t),
66513610Sgiacomo.gabrielli@arm.com                            InstResult::ResultType::VecPredReg));
66613610Sgiacomo.gabrielli@arm.com        }
66713610Sgiacomo.gabrielli@arm.com    }
66812109SRekai.GonzalezAlberquilla@arm.com    /** @} */
66912109SRekai.GonzalezAlberquilla@arm.com
6702702Sktlim@umich.edu    /** Records an integer register being set to a value. */
67113557Sgabeblack@google.com    void setIntRegOperand(const StaticInst *si, int idx, RegVal val)
6721060SN/A    {
67312107SRekai.GonzalezAlberquilla@arm.com        setScalarResult(val);
6741060SN/A    }
6751060SN/A
6769920Syasuko.eckert@amd.com    /** Records a CC register being set to a value. */
67713622Sgabeblack@google.com    void setCCRegOperand(const StaticInst *si, int idx, RegVal val)
6789920Syasuko.eckert@amd.com    {
67912107SRekai.GonzalezAlberquilla@arm.com        setScalarResult(val);
6809920Syasuko.eckert@amd.com    }
6819920Syasuko.eckert@amd.com
68212109SRekai.GonzalezAlberquilla@arm.com    /** Record a vector register being set to a value */
68312109SRekai.GonzalezAlberquilla@arm.com    void setVecRegOperand(const StaticInst *si, int idx,
68412109SRekai.GonzalezAlberquilla@arm.com            const VecRegContainer& val)
68512109SRekai.GonzalezAlberquilla@arm.com    {
68612109SRekai.GonzalezAlberquilla@arm.com        setVecResult(val);
68712109SRekai.GonzalezAlberquilla@arm.com    }
68812109SRekai.GonzalezAlberquilla@arm.com
6892702Sktlim@umich.edu    /** Records an fp register being set to an integer value. */
69012107SRekai.GonzalezAlberquilla@arm.com    void
69113557Sgabeblack@google.com    setFloatRegOperandBits(const StaticInst *si, int idx, RegVal val)
6922308SN/A    {
69312107SRekai.GonzalezAlberquilla@arm.com        setScalarResult(val);
6941060SN/A    }
6951060SN/A
69612109SRekai.GonzalezAlberquilla@arm.com    /** Record a vector register being set to a value */
69712109SRekai.GonzalezAlberquilla@arm.com    void setVecElemOperand(const StaticInst *si, int idx, const VecElem val)
69812109SRekai.GonzalezAlberquilla@arm.com    {
69912109SRekai.GonzalezAlberquilla@arm.com        setVecElemResult(val);
70012109SRekai.GonzalezAlberquilla@arm.com    }
70112109SRekai.GonzalezAlberquilla@arm.com
70213610Sgiacomo.gabrielli@arm.com    /** Record a vector register being set to a value */
70313610Sgiacomo.gabrielli@arm.com    void setVecPredRegOperand(const StaticInst *si, int idx,
70413610Sgiacomo.gabrielli@arm.com                              const VecPredRegContainer& val)
70513610Sgiacomo.gabrielli@arm.com    {
70613610Sgiacomo.gabrielli@arm.com        setVecPredResult(val);
70713610Sgiacomo.gabrielli@arm.com    }
70813610Sgiacomo.gabrielli@arm.com
7092190SN/A    /** Records that one of the source registers is ready. */
7102292SN/A    void markSrcRegReady();
7112190SN/A
7122331SN/A    /** Marks a specific register as ready. */
7132292SN/A    void markSrcRegReady(RegIndex src_idx);
7142190SN/A
7151684SN/A    /** Returns if a source register is ready. */
7161464SN/A    bool isReadySrcRegIdx(int idx) const
7171464SN/A    {
7181464SN/A        return this->_readySrcRegIdx[idx];
7191464SN/A    }
7201464SN/A
7211684SN/A    /** Sets this instruction as completed. */
7222731Sktlim@umich.edu    void setCompleted() { status.set(Completed); }
7231464SN/A
7242292SN/A    /** Returns whether or not this instruction is completed. */
7252731Sktlim@umich.edu    bool isCompleted() const { return status[Completed]; }
7261464SN/A
7272731Sktlim@umich.edu    /** Marks the result as ready. */
7282731Sktlim@umich.edu    void setResultReady() { status.set(ResultReady); }
7292308SN/A
7302731Sktlim@umich.edu    /** Returns whether or not the result is ready. */
7312731Sktlim@umich.edu    bool isResultReady() const { return status[ResultReady]; }
7322308SN/A
7331060SN/A    /** Sets this instruction as ready to issue. */
7342731Sktlim@umich.edu    void setCanIssue() { status.set(CanIssue); }
7351060SN/A
7361060SN/A    /** Returns whether or not this instruction is ready to issue. */
7372731Sktlim@umich.edu    bool readyToIssue() const { return status[CanIssue]; }
7381060SN/A
7394032Sktlim@umich.edu    /** Clears this instruction being able to issue. */
7404032Sktlim@umich.edu    void clearCanIssue() { status.reset(CanIssue); }
7414032Sktlim@umich.edu
7421060SN/A    /** Sets this instruction as issued from the IQ. */
7432731Sktlim@umich.edu    void setIssued() { status.set(Issued); }
7441060SN/A
7451060SN/A    /** Returns whether or not this instruction has issued. */
7462731Sktlim@umich.edu    bool isIssued() const { return status[Issued]; }
7471060SN/A
7484032Sktlim@umich.edu    /** Clears this instruction as being issued. */
7494032Sktlim@umich.edu    void clearIssued() { status.reset(Issued); }
7504032Sktlim@umich.edu
7511060SN/A    /** Sets this instruction as executed. */
7522731Sktlim@umich.edu    void setExecuted() { status.set(Executed); }
7531060SN/A
7541060SN/A    /** Returns whether or not this instruction has executed. */
7552731Sktlim@umich.edu    bool isExecuted() const { return status[Executed]; }
7561060SN/A
7571060SN/A    /** Sets this instruction as ready to commit. */
7582731Sktlim@umich.edu    void setCanCommit() { status.set(CanCommit); }
7591060SN/A
7601061SN/A    /** Clears this instruction as being ready to commit. */
7612731Sktlim@umich.edu    void clearCanCommit() { status.reset(CanCommit); }
7621061SN/A
7631060SN/A    /** Returns whether or not this instruction is ready to commit. */
7642731Sktlim@umich.edu    bool readyToCommit() const { return status[CanCommit]; }
7652731Sktlim@umich.edu
7662731Sktlim@umich.edu    void setAtCommit() { status.set(AtCommit); }
7672731Sktlim@umich.edu
7682731Sktlim@umich.edu    bool isAtCommit() { return status[AtCommit]; }
7691060SN/A
7702292SN/A    /** Sets this instruction as committed. */
7712731Sktlim@umich.edu    void setCommitted() { status.set(Committed); }
7722292SN/A
7732292SN/A    /** Returns whether or not this instruction is committed. */
7742731Sktlim@umich.edu    bool isCommitted() const { return status[Committed]; }
7752292SN/A
7761060SN/A    /** Sets this instruction as squashed. */
77714025Sgiacomo.gabrielli@arm.com    void setSquashed();
7781060SN/A
7791060SN/A    /** Returns whether or not this instruction is squashed. */
7802731Sktlim@umich.edu    bool isSquashed() const { return status[Squashed]; }
7811060SN/A
7822292SN/A    //Instruction Queue Entry
7832292SN/A    //-----------------------
7842292SN/A    /** Sets this instruction as a entry the IQ. */
7852731Sktlim@umich.edu    void setInIQ() { status.set(IqEntry); }
7862292SN/A
7872292SN/A    /** Sets this instruction as a entry the IQ. */
7882731Sktlim@umich.edu    void clearInIQ() { status.reset(IqEntry); }
7892731Sktlim@umich.edu
7902731Sktlim@umich.edu    /** Returns whether or not this instruction has issued. */
7912731Sktlim@umich.edu    bool isInIQ() const { return status[IqEntry]; }
7922292SN/A
7931060SN/A    /** Sets this instruction as squashed in the IQ. */
7942731Sktlim@umich.edu    void setSquashedInIQ() { status.set(SquashedInIQ); status.set(Squashed);}
7951060SN/A
7961060SN/A    /** Returns whether or not this instruction is squashed in the IQ. */
7972731Sktlim@umich.edu    bool isSquashedInIQ() const { return status[SquashedInIQ]; }
7982292SN/A
7992292SN/A
8002292SN/A    //Load / Store Queue Functions
8012292SN/A    //-----------------------
8022292SN/A    /** Sets this instruction as a entry the LSQ. */
8032731Sktlim@umich.edu    void setInLSQ() { status.set(LsqEntry); }
8042292SN/A
8052292SN/A    /** Sets this instruction as a entry the LSQ. */
8062731Sktlim@umich.edu    void removeInLSQ() { status.reset(LsqEntry); }
8072731Sktlim@umich.edu
8082731Sktlim@umich.edu    /** Returns whether or not this instruction is in the LSQ. */
8092731Sktlim@umich.edu    bool isInLSQ() const { return status[LsqEntry]; }
8102292SN/A
8112292SN/A    /** Sets this instruction as squashed in the LSQ. */
81214025Sgiacomo.gabrielli@arm.com    void setSquashedInLSQ() { status.set(SquashedInLSQ); status.set(Squashed);}
8132292SN/A
8142292SN/A    /** Returns whether or not this instruction is squashed in the LSQ. */
8152731Sktlim@umich.edu    bool isSquashedInLSQ() const { return status[SquashedInLSQ]; }
8162292SN/A
8172292SN/A
8182292SN/A    //Reorder Buffer Functions
8192292SN/A    //-----------------------
8202292SN/A    /** Sets this instruction as a entry the ROB. */
8212731Sktlim@umich.edu    void setInROB() { status.set(RobEntry); }
8222292SN/A
8232292SN/A    /** Sets this instruction as a entry the ROB. */
8242731Sktlim@umich.edu    void clearInROB() { status.reset(RobEntry); }
8252731Sktlim@umich.edu
8262731Sktlim@umich.edu    /** Returns whether or not this instruction is in the ROB. */
8272731Sktlim@umich.edu    bool isInROB() const { return status[RobEntry]; }
8282292SN/A
8292292SN/A    /** Sets this instruction as squashed in the ROB. */
8302731Sktlim@umich.edu    void setSquashedInROB() { status.set(SquashedInROB); }
8312292SN/A
8322292SN/A    /** Returns whether or not this instruction is squashed in the ROB. */
8332731Sktlim@umich.edu    bool isSquashedInROB() const { return status[SquashedInROB]; }
8342292SN/A
83514025Sgiacomo.gabrielli@arm.com    /** Returns whether pinned registers are renamed */
83614025Sgiacomo.gabrielli@arm.com    bool isPinnedRegsRenamed() const { return status[PinnedRegsRenamed]; }
83714025Sgiacomo.gabrielli@arm.com
83814025Sgiacomo.gabrielli@arm.com    /** Sets the destination registers as renamed */
83914025Sgiacomo.gabrielli@arm.com    void
84014025Sgiacomo.gabrielli@arm.com    setPinnedRegsRenamed()
84114025Sgiacomo.gabrielli@arm.com    {
84214025Sgiacomo.gabrielli@arm.com        assert(!status[PinnedRegsSquashDone]);
84314025Sgiacomo.gabrielli@arm.com        assert(!status[PinnedRegsWritten]);
84414025Sgiacomo.gabrielli@arm.com        status.set(PinnedRegsRenamed);
84514025Sgiacomo.gabrielli@arm.com    }
84614025Sgiacomo.gabrielli@arm.com
84714025Sgiacomo.gabrielli@arm.com    /** Returns whether destination registers are written */
84814025Sgiacomo.gabrielli@arm.com    bool isPinnedRegsWritten() const { return status[PinnedRegsWritten]; }
84914025Sgiacomo.gabrielli@arm.com
85014025Sgiacomo.gabrielli@arm.com    /** Sets destination registers as written */
85114025Sgiacomo.gabrielli@arm.com    void
85214025Sgiacomo.gabrielli@arm.com    setPinnedRegsWritten()
85314025Sgiacomo.gabrielli@arm.com    {
85414025Sgiacomo.gabrielli@arm.com        assert(!status[PinnedRegsSquashDone]);
85514025Sgiacomo.gabrielli@arm.com        assert(status[PinnedRegsRenamed]);
85614025Sgiacomo.gabrielli@arm.com        status.set(PinnedRegsWritten);
85714025Sgiacomo.gabrielli@arm.com    }
85814025Sgiacomo.gabrielli@arm.com
85914025Sgiacomo.gabrielli@arm.com    /** Return whether dest registers' pinning status updated after squash */
86014025Sgiacomo.gabrielli@arm.com    bool
86114025Sgiacomo.gabrielli@arm.com    isPinnedRegsSquashDone() const { return status[PinnedRegsSquashDone]; }
86214025Sgiacomo.gabrielli@arm.com
86314025Sgiacomo.gabrielli@arm.com    /** Sets dest registers' status updated after squash */
86414025Sgiacomo.gabrielli@arm.com    void
86514025Sgiacomo.gabrielli@arm.com    setPinnedRegsSquashDone() {
86614025Sgiacomo.gabrielli@arm.com        assert(!status[PinnedRegsSquashDone]);
86714025Sgiacomo.gabrielli@arm.com        status.set(PinnedRegsSquashDone);
86814025Sgiacomo.gabrielli@arm.com    }
86914025Sgiacomo.gabrielli@arm.com
8707720Sgblack@eecs.umich.edu    /** Read the PC state of this instruction. */
87110319SAndreas.Sandberg@ARM.com    TheISA::PCState pcState() const { return pc; }
8727720Sgblack@eecs.umich.edu
8737720Sgblack@eecs.umich.edu    /** Set the PC state of this instruction. */
87410319SAndreas.Sandberg@ARM.com    void pcState(const TheISA::PCState &val) { pc = val; }
8757720Sgblack@eecs.umich.edu
8761060SN/A    /** Read the PC of this instruction. */
87711294Sandreas.hansson@arm.com    Addr instAddr() const { return pc.instAddr(); }
8787720Sgblack@eecs.umich.edu
8797720Sgblack@eecs.umich.edu    /** Read the PC of the next instruction. */
88011294Sandreas.hansson@arm.com    Addr nextInstAddr() const { return pc.nextInstAddr(); }
8811060SN/A
8824636Sgblack@eecs.umich.edu    /**Read the micro PC of this instruction. */
88311294Sandreas.hansson@arm.com    Addr microPC() const { return pc.microPC(); }
8844636Sgblack@eecs.umich.edu
88513429Srekai.gonzalezalberquilla@arm.com    bool readPredicate() const
8867597Sminkyu.jeong@arm.com    {
8879046SAli.Saidi@ARM.com        return instFlags[Predicate];
8887597Sminkyu.jeong@arm.com    }
8897597Sminkyu.jeong@arm.com
8907597Sminkyu.jeong@arm.com    void setPredicate(bool val)
8917597Sminkyu.jeong@arm.com    {
8929046SAli.Saidi@ARM.com        instFlags[Predicate] = val;
8937600Sminkyu.jeong@arm.com
8947600Sminkyu.jeong@arm.com        if (traceData) {
8957600Sminkyu.jeong@arm.com            traceData->setPredicate(val);
8967600Sminkyu.jeong@arm.com        }
8977597Sminkyu.jeong@arm.com    }
8987597Sminkyu.jeong@arm.com
89913953Sgiacomo.gabrielli@arm.com    bool
90013953Sgiacomo.gabrielli@arm.com    readMemAccPredicate() const
90113953Sgiacomo.gabrielli@arm.com    {
90213953Sgiacomo.gabrielli@arm.com        return instFlags[MemAccPredicate];
90313953Sgiacomo.gabrielli@arm.com    }
90413953Sgiacomo.gabrielli@arm.com
90513953Sgiacomo.gabrielli@arm.com    void
90613953Sgiacomo.gabrielli@arm.com    setMemAccPredicate(bool val)
90713953Sgiacomo.gabrielli@arm.com    {
90813953Sgiacomo.gabrielli@arm.com        instFlags[MemAccPredicate] = val;
90913953Sgiacomo.gabrielli@arm.com    }
91013953Sgiacomo.gabrielli@arm.com
9112702Sktlim@umich.edu    /** Sets the ASID. */
9122292SN/A    void setASID(short addr_space_id) { asid = addr_space_id; }
91313590Srekai.gonzalezalberquilla@arm.com    short getASID() { return asid; }
9142292SN/A
9152702Sktlim@umich.edu    /** Sets the thread id. */
9166221Snate@binkert.org    void setTid(ThreadID tid) { threadNumber = tid; }
9172292SN/A
9182731Sktlim@umich.edu    /** Sets the pointer to the thread state. */
9192702Sktlim@umich.edu    void setThreadState(ImplState *state) { thread = state; }
9201060SN/A
9212731Sktlim@umich.edu    /** Returns the thread context. */
9222680Sktlim@umich.edu    ThreadContext *tcBase() { return thread->getTC(); }
9231464SN/A
9241464SN/A  public:
9251684SN/A    /** Returns whether or not the eff. addr. source registers are ready. */
92613429Srekai.gonzalezalberquilla@arm.com    bool eaSrcsReady() const;
9271681SN/A
92810824SAndreas.Sandberg@ARM.com    /** Is this instruction's memory access strictly ordered? */
92910824SAndreas.Sandberg@ARM.com    bool strictlyOrdered() const { return instFlags[IsStrictlyOrdered]; }
93013590Srekai.gonzalezalberquilla@arm.com    void strictlyOrdered(bool so) { instFlags[IsStrictlyOrdered] = so; }
9314032Sktlim@umich.edu
9324032Sktlim@umich.edu    /** Has this instruction generated a memory request. */
93313429Srekai.gonzalezalberquilla@arm.com    bool hasRequest() const { return instFlags[ReqMade]; }
93413590Srekai.gonzalezalberquilla@arm.com    /** Assert this instruction has generated a memory request. */
93513590Srekai.gonzalezalberquilla@arm.com    void setRequest() { instFlags[ReqMade] = true; }
9362292SN/A
9372292SN/A    /** Returns iterator to this instruction in the list of all insts. */
9382292SN/A    ListIt &getInstListIt() { return instListIt; }
9392292SN/A
9402292SN/A    /** Sets iterator for this instruction in the list of all insts. */
9412292SN/A    void setInstListIt(ListIt _instListIt) { instListIt = _instListIt; }
9423326Sktlim@umich.edu
9433326Sktlim@umich.edu  public:
9443326Sktlim@umich.edu    /** Returns the number of consecutive store conditional failures. */
94510319SAndreas.Sandberg@ARM.com    unsigned int readStCondFailures() const
9463326Sktlim@umich.edu    { return thread->storeCondFailures; }
9473326Sktlim@umich.edu
9483326Sktlim@umich.edu    /** Sets the number of consecutive store conditional failures. */
94910319SAndreas.Sandberg@ARM.com    void setStCondFailures(unsigned int sc_failures)
9503326Sktlim@umich.edu    { thread->storeCondFailures = sc_failures; }
95110529Smorr@cs.wisc.edu
95210529Smorr@cs.wisc.edu  public:
95310529Smorr@cs.wisc.edu    // monitor/mwait funtions
95411148Smitch.hayenga@arm.com    void armMonitor(Addr address) { cpu->armMonitor(threadNumber, address); }
95511148Smitch.hayenga@arm.com    bool mwait(PacketPtr pkt) { return cpu->mwait(threadNumber, pkt); }
95610529Smorr@cs.wisc.edu    void mwaitAtomic(ThreadContext *tc)
95711148Smitch.hayenga@arm.com    { return cpu->mwaitAtomic(threadNumber, tc, cpu->dtb); }
95811148Smitch.hayenga@arm.com    AddressMonitor *getAddrMonitor()
95911148Smitch.hayenga@arm.com    { return cpu->getCpuAddrMonitor(threadNumber); }
9601060SN/A};
9611060SN/A
9621060SN/Atemplate<class Impl>
9637520Sgblack@eecs.umich.eduFault
96411608Snikos.nikoleris@arm.comBaseDynInst<Impl>::initiateMemRead(Addr addr, unsigned size,
96513954Sgiacomo.gabrielli@arm.com                                   Request::Flags flags,
96613954Sgiacomo.gabrielli@arm.com                                   const std::vector<bool>& byteEnable)
9671060SN/A{
96813590Srekai.gonzalezalberquilla@arm.com    return cpu->pushRequest(
96913590Srekai.gonzalezalberquilla@arm.com            dynamic_cast<typename DynInstPtr::PtrType>(this),
97013954Sgiacomo.gabrielli@arm.com            /* ld */ true, nullptr, size, addr, flags, nullptr, nullptr,
97113954Sgiacomo.gabrielli@arm.com            byteEnable);
9721060SN/A}
9731060SN/A
9741060SN/Atemplate<class Impl>
9757520Sgblack@eecs.umich.eduFault
97611608Snikos.nikoleris@arm.comBaseDynInst<Impl>::writeMem(uint8_t *data, unsigned size, Addr addr,
97713954Sgiacomo.gabrielli@arm.com                            Request::Flags flags, uint64_t *res,
97813954Sgiacomo.gabrielli@arm.com                            const std::vector<bool>& byteEnable)
9791060SN/A{
98013590Srekai.gonzalezalberquilla@arm.com    return cpu->pushRequest(
98113590Srekai.gonzalezalberquilla@arm.com            dynamic_cast<typename DynInstPtr::PtrType>(this),
98213954Sgiacomo.gabrielli@arm.com            /* st */ false, data, size, addr, flags, res, nullptr, byteEnable);
9836973Stjones1@inf.ed.ac.uk}
9846973Stjones1@inf.ed.ac.uk
98513652Sqtt2@cornell.edutemplate<class Impl>
98613652Sqtt2@cornell.eduFault
98713652Sqtt2@cornell.eduBaseDynInst<Impl>::initiateMemAMO(Addr addr, unsigned size,
98813652Sqtt2@cornell.edu                                  Request::Flags flags,
98914297Sjordi.vaquero@metempsy.com                                  AtomicOpFunctorPtr amo_op)
99013652Sqtt2@cornell.edu{
99113652Sqtt2@cornell.edu    // atomic memory instructions do not have data to be written to memory yet
99213652Sqtt2@cornell.edu    // since the atomic operations will be executed directly in cache/memory.
99313652Sqtt2@cornell.edu    // Therefore, its `data` field is nullptr.
99413652Sqtt2@cornell.edu    // Atomic memory requests need to carry their `amo_op` fields to cache/
99513652Sqtt2@cornell.edu    // memory
99613652Sqtt2@cornell.edu    return cpu->pushRequest(
99713652Sqtt2@cornell.edu            dynamic_cast<typename DynInstPtr::PtrType>(this),
99814297Sjordi.vaquero@metempsy.com            /* atomic */ false, nullptr, size, addr, flags, nullptr,
99914297Sjordi.vaquero@metempsy.com            std::move(amo_op));
100013652Sqtt2@cornell.edu}
100113652Sqtt2@cornell.edu
10021464SN/A#endif // __CPU_BASE_DYN_INST_HH__
1003