base_dyn_inst.hh revision 8832
11060SN/A/*
27944SGiacomo.Gabrielli@arm.com * Copyright (c) 2011 ARM Limited
37944SGiacomo.Gabrielli@arm.com * All rights reserved.
47944SGiacomo.Gabrielli@arm.com *
57944SGiacomo.Gabrielli@arm.com * The license below extends only to copyright in the software and shall
67944SGiacomo.Gabrielli@arm.com * not be construed as granting a license to any other intellectual
77944SGiacomo.Gabrielli@arm.com * property including but not limited to intellectual property relating
87944SGiacomo.Gabrielli@arm.com * to a hardware implementation of the functionality of the software
97944SGiacomo.Gabrielli@arm.com * licensed hereunder.  You may use the software subject to the license
107944SGiacomo.Gabrielli@arm.com * terms below provided that you ensure that this notice is replicated
117944SGiacomo.Gabrielli@arm.com * unmodified and in its entirety in all distributions of the software,
127944SGiacomo.Gabrielli@arm.com * modified or unmodified, in source code or in binary form.
137944SGiacomo.Gabrielli@arm.com *
142702Sktlim@umich.edu * Copyright (c) 2004-2006 The Regents of The University of Michigan
156973Stjones1@inf.ed.ac.uk * Copyright (c) 2009 The University of Edinburgh
161060SN/A * All rights reserved.
171060SN/A *
181060SN/A * Redistribution and use in source and binary forms, with or without
191060SN/A * modification, are permitted provided that the following conditions are
201060SN/A * met: redistributions of source code must retain the above copyright
211060SN/A * notice, this list of conditions and the following disclaimer;
221060SN/A * redistributions in binary form must reproduce the above copyright
231060SN/A * notice, this list of conditions and the following disclaimer in the
241060SN/A * documentation and/or other materials provided with the distribution;
251060SN/A * neither the name of the copyright holders nor the names of its
261060SN/A * contributors may be used to endorse or promote products derived from
271060SN/A * this software without specific prior written permission.
281060SN/A *
291060SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
301060SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
311060SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
321060SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
331060SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
341060SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
351060SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
361060SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
371060SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
381060SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
391060SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
402665Ssaidi@eecs.umich.edu *
412665Ssaidi@eecs.umich.edu * Authors: Kevin Lim
426973Stjones1@inf.ed.ac.uk *          Timothy M. Jones
431060SN/A */
441060SN/A
451464SN/A#ifndef __CPU_BASE_DYN_INST_HH__
461464SN/A#define __CPU_BASE_DYN_INST_HH__
471060SN/A
482731Sktlim@umich.edu#include <bitset>
492292SN/A#include <list>
501464SN/A#include <string>
518733Sgeoffrey.blake@arm.com#include <queue>
521060SN/A
537720Sgblack@eecs.umich.edu#include "arch/utility.hh"
541060SN/A#include "base/fast_alloc.hh"
551060SN/A#include "base/trace.hh"
566658Snate@binkert.org#include "config/the_isa.hh"
578733Sgeoffrey.blake@arm.com#include "config/use_checker.hh"
583770Sgblack@eecs.umich.edu#include "cpu/o3/comm.hh"
591464SN/A#include "cpu/exetrace.hh"
601464SN/A#include "cpu/inst_seq.hh"
612669Sktlim@umich.edu#include "cpu/op_class.hh"
621060SN/A#include "cpu/static_inst.hh"
636973Stjones1@inf.ed.ac.uk#include "cpu/translation.hh"
642669Sktlim@umich.edu#include "mem/packet.hh"
657678Sgblack@eecs.umich.edu#include "sim/byteswap.hh"
668817Sgblack@eecs.umich.edu#include "sim/fault_fwd.hh"
672292SN/A#include "sim/system.hh"
686023Snate@binkert.org#include "sim/tlb.hh"
691060SN/A
701060SN/A/**
711060SN/A * @file
721060SN/A * Defines a dynamic instruction context.
731060SN/A */
741060SN/A
751060SN/Atemplate <class Impl>
761061SN/Aclass BaseDynInst : public FastAlloc, public RefCounted
771060SN/A{
781060SN/A  public:
791060SN/A    // Typedef for the CPU.
802733Sktlim@umich.edu    typedef typename Impl::CPUType ImplCPU;
812733Sktlim@umich.edu    typedef typename ImplCPU::ImplState ImplState;
821060SN/A
832292SN/A    // Logical register index type.
842107SN/A    typedef TheISA::RegIndex RegIndex;
852690Sktlim@umich.edu    // Integer register type.
862107SN/A    typedef TheISA::IntReg IntReg;
872690Sktlim@umich.edu    // Floating point register type.
882690Sktlim@umich.edu    typedef TheISA::FloatReg FloatReg;
891060SN/A
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
995543Ssaidi@eecs.umich.edu        MaxInstDestRegs = TheISA::MaxInstDestRegs,      /// Max dest regs
1001060SN/A    };
1011060SN/A
1022292SN/A    /** The StaticInst used by this BaseDynInst. */
1032107SN/A    StaticInstPtr staticInst;
1048502Sgblack@eecs.umich.edu    StaticInstPtr macroop;
1051060SN/A
1061060SN/A    ////////////////////////////////////////////
1071060SN/A    //
1081060SN/A    // INSTRUCTION EXECUTION
1091060SN/A    //
1101060SN/A    ////////////////////////////////////////////
1112292SN/A    /** InstRecord that tracks this instructions. */
1121060SN/A    Trace::InstRecord *traceData;
1131060SN/A
1145358Sgblack@eecs.umich.edu    void demapPage(Addr vaddr, uint64_t asn)
1155358Sgblack@eecs.umich.edu    {
1165358Sgblack@eecs.umich.edu        cpu->demapPage(vaddr, asn);
1175358Sgblack@eecs.umich.edu    }
1185358Sgblack@eecs.umich.edu    void demapInstPage(Addr vaddr, uint64_t asn)
1195358Sgblack@eecs.umich.edu    {
1205358Sgblack@eecs.umich.edu        cpu->demapPage(vaddr, asn);
1215358Sgblack@eecs.umich.edu    }
1225358Sgblack@eecs.umich.edu    void demapDataPage(Addr vaddr, uint64_t asn)
1235358Sgblack@eecs.umich.edu    {
1245358Sgblack@eecs.umich.edu        cpu->demapPage(vaddr, asn);
1255358Sgblack@eecs.umich.edu    }
1265358Sgblack@eecs.umich.edu
1278444Sgblack@eecs.umich.edu    Fault readMem(Addr addr, uint8_t *data, unsigned size, unsigned flags);
1287520Sgblack@eecs.umich.edu
1298444Sgblack@eecs.umich.edu    Fault writeMem(uint8_t *data, unsigned size,
1308444Sgblack@eecs.umich.edu                   Addr addr, unsigned flags, uint64_t *res);
1317520Sgblack@eecs.umich.edu
1326974Stjones1@inf.ed.ac.uk    /** Splits a request in two if it crosses a dcache block. */
1336974Stjones1@inf.ed.ac.uk    void splitRequest(RequestPtr req, RequestPtr &sreqLow,
1346974Stjones1@inf.ed.ac.uk                      RequestPtr &sreqHigh);
1356974Stjones1@inf.ed.ac.uk
1366973Stjones1@inf.ed.ac.uk    /** Initiate a DTB address translation. */
1376974Stjones1@inf.ed.ac.uk    void initiateTranslation(RequestPtr req, RequestPtr sreqLow,
1386974Stjones1@inf.ed.ac.uk                             RequestPtr sreqHigh, uint64_t *res,
1396973Stjones1@inf.ed.ac.uk                             BaseTLB::Mode mode);
1406973Stjones1@inf.ed.ac.uk
1416973Stjones1@inf.ed.ac.uk    /** Finish a DTB address translation. */
1426973Stjones1@inf.ed.ac.uk    void finishTranslation(WholeTranslationState *state);
1431060SN/A
1447944SGiacomo.Gabrielli@arm.com    /** True if the DTB address translation has started. */
1457944SGiacomo.Gabrielli@arm.com    bool translationStarted;
1467944SGiacomo.Gabrielli@arm.com
1477944SGiacomo.Gabrielli@arm.com    /** True if the DTB address translation has completed. */
1487944SGiacomo.Gabrielli@arm.com    bool translationCompleted;
1497944SGiacomo.Gabrielli@arm.com
1508545Ssaidi@eecs.umich.edu    /** True if this address was found to match a previous load and they issued
1518545Ssaidi@eecs.umich.edu     * out of order. If that happend, then it's only a problem if an incoming
1528545Ssaidi@eecs.umich.edu     * snoop invalidate modifies the line, in which case we need to squash.
1538545Ssaidi@eecs.umich.edu     * If nothing modified the line the order doesn't matter.
1548545Ssaidi@eecs.umich.edu     */
1558545Ssaidi@eecs.umich.edu    bool possibleLoadViolation;
1568545Ssaidi@eecs.umich.edu
1578545Ssaidi@eecs.umich.edu    /** True if the address hit a external snoop while sitting in the LSQ.
1588545Ssaidi@eecs.umich.edu     * If this is true and a older instruction sees it, this instruction must
1598545Ssaidi@eecs.umich.edu     * reexecute
1608545Ssaidi@eecs.umich.edu     */
1618545Ssaidi@eecs.umich.edu    bool hitExternalSnoop;
1628545Ssaidi@eecs.umich.edu
1637944SGiacomo.Gabrielli@arm.com    /**
1647944SGiacomo.Gabrielli@arm.com     * Returns true if the DTB address translation is being delayed due to a hw
1657944SGiacomo.Gabrielli@arm.com     * page table walk.
1667944SGiacomo.Gabrielli@arm.com     */
1677944SGiacomo.Gabrielli@arm.com    bool isTranslationDelayed() const
1687944SGiacomo.Gabrielli@arm.com    {
1697944SGiacomo.Gabrielli@arm.com        return (translationStarted && !translationCompleted);
1707944SGiacomo.Gabrielli@arm.com    }
1717944SGiacomo.Gabrielli@arm.com
1727944SGiacomo.Gabrielli@arm.com    /**
1737944SGiacomo.Gabrielli@arm.com     * Saved memory requests (needed when the DTB address translation is
1747944SGiacomo.Gabrielli@arm.com     * delayed due to a hw page table walk).
1757944SGiacomo.Gabrielli@arm.com     */
1767944SGiacomo.Gabrielli@arm.com    RequestPtr savedReq;
1777944SGiacomo.Gabrielli@arm.com    RequestPtr savedSreqLow;
1787944SGiacomo.Gabrielli@arm.com    RequestPtr savedSreqHigh;
1797944SGiacomo.Gabrielli@arm.com
1808733Sgeoffrey.blake@arm.com#if USE_CHECKER
1818733Sgeoffrey.blake@arm.com    // Need a copy of main request pointer to verify on writes.
1828733Sgeoffrey.blake@arm.com    RequestPtr reqToVerify;
1838733Sgeoffrey.blake@arm.com#endif //USE_CHECKER
1848733Sgeoffrey.blake@arm.com
1851684SN/A    /** @todo: Consider making this private. */
1861060SN/A  public:
1871060SN/A    /** The sequence number of the instruction. */
1881060SN/A    InstSeqNum seqNum;
1891060SN/A
1902731Sktlim@umich.edu    enum Status {
1912731Sktlim@umich.edu        IqEntry,                 /// Instruction is in the IQ
1922731Sktlim@umich.edu        RobEntry,                /// Instruction is in the ROB
1932731Sktlim@umich.edu        LsqEntry,                /// Instruction is in the LSQ
1942731Sktlim@umich.edu        Completed,               /// Instruction has completed
1952731Sktlim@umich.edu        ResultReady,             /// Instruction has its result
1962731Sktlim@umich.edu        CanIssue,                /// Instruction can issue and execute
1972731Sktlim@umich.edu        Issued,                  /// Instruction has issued
1982731Sktlim@umich.edu        Executed,                /// Instruction has executed
1992731Sktlim@umich.edu        CanCommit,               /// Instruction can commit
2002731Sktlim@umich.edu        AtCommit,                /// Instruction has reached commit
2012731Sktlim@umich.edu        Committed,               /// Instruction has committed
2022731Sktlim@umich.edu        Squashed,                /// Instruction is squashed
2032731Sktlim@umich.edu        SquashedInIQ,            /// Instruction is squashed in the IQ
2042731Sktlim@umich.edu        SquashedInLSQ,           /// Instruction is squashed in the LSQ
2052731Sktlim@umich.edu        SquashedInROB,           /// Instruction is squashed in the ROB
2062731Sktlim@umich.edu        RecoverInst,             /// Is a recover instruction
2072731Sktlim@umich.edu        BlockingInst,            /// Is a blocking instruction
2082731Sktlim@umich.edu        ThreadsyncWait,          /// Is a thread synchronization instruction
2092731Sktlim@umich.edu        SerializeBefore,         /// Needs to serialize on
2102731Sktlim@umich.edu                                 /// instructions ahead of it
2112731Sktlim@umich.edu        SerializeAfter,          /// Needs to serialize instructions behind it
2122731Sktlim@umich.edu        SerializeHandled,        /// Serialization has been handled
2132731Sktlim@umich.edu        NumStatus
2142731Sktlim@umich.edu    };
2152292SN/A
2162731Sktlim@umich.edu    /** The status of this BaseDynInst.  Several bits can be set. */
2172731Sktlim@umich.edu    std::bitset<NumStatus> status;
2181060SN/A
2191060SN/A    /** The thread this instruction is from. */
2206221Snate@binkert.org    ThreadID threadNumber;
2211060SN/A
2221060SN/A    /** data address space ID, for loads & stores. */
2231060SN/A    short asid;
2241060SN/A
2252292SN/A    /** How many source registers are ready. */
2262292SN/A    unsigned readyRegs;
2272292SN/A
2282733Sktlim@umich.edu    /** Pointer to the Impl's CPU object. */
2292733Sktlim@umich.edu    ImplCPU *cpu;
2301060SN/A
2312680Sktlim@umich.edu    /** Pointer to the thread state. */
2322292SN/A    ImplState *thread;
2331060SN/A
2341060SN/A    /** The kind of fault this instruction has generated. */
2352132SN/A    Fault fault;
2361060SN/A
2372702Sktlim@umich.edu    /** Pointer to the data for the memory access. */
2382669Sktlim@umich.edu    uint8_t *memData;
2392292SN/A
2401060SN/A    /** The effective virtual address (lds & stores only). */
2411060SN/A    Addr effAddr;
2421060SN/A
2438199SAli.Saidi@ARM.com    /** The size of the request */
2448199SAli.Saidi@ARM.com    Addr effSize;
2458199SAli.Saidi@ARM.com
2464032Sktlim@umich.edu    /** Is the effective virtual address valid. */
2474032Sktlim@umich.edu    bool effAddrValid;
2484032Sktlim@umich.edu
2491060SN/A    /** The effective physical address. */
2501060SN/A    Addr physEffAddr;
2511060SN/A
2521060SN/A    /** The memory request flags (from translation). */
2531060SN/A    unsigned memReqFlags;
2541060SN/A
2551464SN/A    union Result {
2561464SN/A        uint64_t integer;
2571464SN/A        double dbl;
2588733Sgeoffrey.blake@arm.com        void set(uint64_t i) { integer = i; }
2598733Sgeoffrey.blake@arm.com        void set(double d) { dbl = d; }
2608733Sgeoffrey.blake@arm.com        void get(uint64_t& i) { i = integer; }
2618733Sgeoffrey.blake@arm.com        void get(double& d) { d = dbl; }
2621464SN/A    };
2631060SN/A
2648733Sgeoffrey.blake@arm.com    /** The result of the instruction; assumes an instruction can have many
2658733Sgeoffrey.blake@arm.com     *  destination registers.
2661464SN/A     */
2678733Sgeoffrey.blake@arm.com    std::queue<Result> instResult;
2681060SN/A
2693326Sktlim@umich.edu    /** Records changes to result? */
2703326Sktlim@umich.edu    bool recordResult;
2713326Sktlim@umich.edu
2727597Sminkyu.jeong@arm.com    /** Did this instruction execute, or is it predicated false */
2737597Sminkyu.jeong@arm.com    bool predicate;
2747597Sminkyu.jeong@arm.com
2753965Sgblack@eecs.umich.edu  protected:
2767720Sgblack@eecs.umich.edu    /** PC state for this instruction. */
2777720Sgblack@eecs.umich.edu    TheISA::PCState pc;
2781060SN/A
2797720Sgblack@eecs.umich.edu    /** Predicted PC state after this instruction. */
2807720Sgblack@eecs.umich.edu    TheISA::PCState predPC;
2814636Sgblack@eecs.umich.edu
2823794Sgblack@eecs.umich.edu    /** If this is a branch that was predicted taken */
2833794Sgblack@eecs.umich.edu    bool predTaken;
2843794Sgblack@eecs.umich.edu
2853965Sgblack@eecs.umich.edu  public:
2863965Sgblack@eecs.umich.edu
2872292SN/A#ifdef DEBUG
2882292SN/A    void dumpSNList();
2892292SN/A#endif
2902292SN/A
2912292SN/A    /** Whether or not the source register is ready.
2922292SN/A     *  @todo: Not sure this should be here vs the derived class.
2931060SN/A     */
2941060SN/A    bool _readySrcRegIdx[MaxInstSrcRegs];
2951060SN/A
2963770Sgblack@eecs.umich.edu  protected:
2973770Sgblack@eecs.umich.edu    /** Flattened register index of the destination registers of this
2983770Sgblack@eecs.umich.edu     *  instruction.
2993770Sgblack@eecs.umich.edu     */
3003770Sgblack@eecs.umich.edu    TheISA::RegIndex _flatDestRegIdx[TheISA::MaxInstDestRegs];
3013770Sgblack@eecs.umich.edu
3023770Sgblack@eecs.umich.edu    /** Flattened register index of the source registers of this
3033770Sgblack@eecs.umich.edu     *  instruction.
3043770Sgblack@eecs.umich.edu     */
3053770Sgblack@eecs.umich.edu    TheISA::RegIndex _flatSrcRegIdx[TheISA::MaxInstSrcRegs];
3063770Sgblack@eecs.umich.edu
3073770Sgblack@eecs.umich.edu    /** Physical register index of the destination registers of this
3083770Sgblack@eecs.umich.edu     *  instruction.
3093770Sgblack@eecs.umich.edu     */
3103770Sgblack@eecs.umich.edu    PhysRegIndex _destRegIdx[TheISA::MaxInstDestRegs];
3113770Sgblack@eecs.umich.edu
3123770Sgblack@eecs.umich.edu    /** Physical register index of the source registers of this
3133770Sgblack@eecs.umich.edu     *  instruction.
3143770Sgblack@eecs.umich.edu     */
3153770Sgblack@eecs.umich.edu    PhysRegIndex _srcRegIdx[TheISA::MaxInstSrcRegs];
3163770Sgblack@eecs.umich.edu
3173770Sgblack@eecs.umich.edu    /** Physical register index of the previous producers of the
3183770Sgblack@eecs.umich.edu     *  architected destinations.
3193770Sgblack@eecs.umich.edu     */
3203770Sgblack@eecs.umich.edu    PhysRegIndex _prevDestRegIdx[TheISA::MaxInstDestRegs];
3213770Sgblack@eecs.umich.edu
3221060SN/A  public:
3233770Sgblack@eecs.umich.edu
3243770Sgblack@eecs.umich.edu    /** Returns the physical register index of the i'th destination
3253770Sgblack@eecs.umich.edu     *  register.
3263770Sgblack@eecs.umich.edu     */
3273770Sgblack@eecs.umich.edu    PhysRegIndex renamedDestRegIdx(int idx) const
3283770Sgblack@eecs.umich.edu    {
3293770Sgblack@eecs.umich.edu        return _destRegIdx[idx];
3303770Sgblack@eecs.umich.edu    }
3313770Sgblack@eecs.umich.edu
3323770Sgblack@eecs.umich.edu    /** Returns the physical register index of the i'th source register. */
3333770Sgblack@eecs.umich.edu    PhysRegIndex renamedSrcRegIdx(int idx) const
3343770Sgblack@eecs.umich.edu    {
3353770Sgblack@eecs.umich.edu        return _srcRegIdx[idx];
3363770Sgblack@eecs.umich.edu    }
3373770Sgblack@eecs.umich.edu
3383770Sgblack@eecs.umich.edu    /** Returns the flattened register index of the i'th destination
3393770Sgblack@eecs.umich.edu     *  register.
3403770Sgblack@eecs.umich.edu     */
3413770Sgblack@eecs.umich.edu    TheISA::RegIndex flattenedDestRegIdx(int idx) const
3423770Sgblack@eecs.umich.edu    {
3433770Sgblack@eecs.umich.edu        return _flatDestRegIdx[idx];
3443770Sgblack@eecs.umich.edu    }
3453770Sgblack@eecs.umich.edu
3463770Sgblack@eecs.umich.edu    /** Returns the flattened register index of the i'th source register */
3473770Sgblack@eecs.umich.edu    TheISA::RegIndex flattenedSrcRegIdx(int idx) const
3483770Sgblack@eecs.umich.edu    {
3493770Sgblack@eecs.umich.edu        return _flatSrcRegIdx[idx];
3503770Sgblack@eecs.umich.edu    }
3513770Sgblack@eecs.umich.edu
3523770Sgblack@eecs.umich.edu    /** Returns the physical register index of the previous physical register
3533770Sgblack@eecs.umich.edu     *  that remapped to the same logical register index.
3543770Sgblack@eecs.umich.edu     */
3553770Sgblack@eecs.umich.edu    PhysRegIndex prevDestRegIdx(int idx) const
3563770Sgblack@eecs.umich.edu    {
3573770Sgblack@eecs.umich.edu        return _prevDestRegIdx[idx];
3583770Sgblack@eecs.umich.edu    }
3593770Sgblack@eecs.umich.edu
3603770Sgblack@eecs.umich.edu    /** Renames a destination register to a physical register.  Also records
3613770Sgblack@eecs.umich.edu     *  the previous physical register that the logical register mapped to.
3623770Sgblack@eecs.umich.edu     */
3633770Sgblack@eecs.umich.edu    void renameDestReg(int idx,
3643770Sgblack@eecs.umich.edu                       PhysRegIndex renamed_dest,
3653770Sgblack@eecs.umich.edu                       PhysRegIndex previous_rename)
3663770Sgblack@eecs.umich.edu    {
3673770Sgblack@eecs.umich.edu        _destRegIdx[idx] = renamed_dest;
3683770Sgblack@eecs.umich.edu        _prevDestRegIdx[idx] = previous_rename;
3693770Sgblack@eecs.umich.edu    }
3703770Sgblack@eecs.umich.edu
3713770Sgblack@eecs.umich.edu    /** Renames a source logical register to the physical register which
3723770Sgblack@eecs.umich.edu     *  has/will produce that logical register's result.
3733770Sgblack@eecs.umich.edu     *  @todo: add in whether or not the source register is ready.
3743770Sgblack@eecs.umich.edu     */
3753770Sgblack@eecs.umich.edu    void renameSrcReg(int idx, PhysRegIndex renamed_src)
3763770Sgblack@eecs.umich.edu    {
3773770Sgblack@eecs.umich.edu        _srcRegIdx[idx] = renamed_src;
3783770Sgblack@eecs.umich.edu    }
3793770Sgblack@eecs.umich.edu
3803770Sgblack@eecs.umich.edu    /** Flattens a source architectural register index into a logical index.
3813770Sgblack@eecs.umich.edu     */
3823770Sgblack@eecs.umich.edu    void flattenSrcReg(int idx, TheISA::RegIndex flattened_src)
3833770Sgblack@eecs.umich.edu    {
3843770Sgblack@eecs.umich.edu        _flatSrcRegIdx[idx] = flattened_src;
3853770Sgblack@eecs.umich.edu    }
3863770Sgblack@eecs.umich.edu
3873770Sgblack@eecs.umich.edu    /** Flattens a destination architectural register index into a logical
3883770Sgblack@eecs.umich.edu     * index.
3893770Sgblack@eecs.umich.edu     */
3903770Sgblack@eecs.umich.edu    void flattenDestReg(int idx, TheISA::RegIndex flattened_dest)
3913770Sgblack@eecs.umich.edu    {
3923770Sgblack@eecs.umich.edu        _flatDestRegIdx[idx] = flattened_dest;
3933770Sgblack@eecs.umich.edu    }
3944636Sgblack@eecs.umich.edu    /** BaseDynInst constructor given a binary instruction.
3954636Sgblack@eecs.umich.edu     *  @param staticInst A StaticInstPtr to the underlying instruction.
3967720Sgblack@eecs.umich.edu     *  @param pc The PC state for the instruction.
3977720Sgblack@eecs.umich.edu     *  @param predPC The predicted next PC state for the instruction.
3984636Sgblack@eecs.umich.edu     *  @param seq_num The sequence number of the instruction.
3994636Sgblack@eecs.umich.edu     *  @param cpu Pointer to the instruction's CPU.
4004636Sgblack@eecs.umich.edu     */
4018502Sgblack@eecs.umich.edu    BaseDynInst(StaticInstPtr staticInst, StaticInstPtr macroop,
4028502Sgblack@eecs.umich.edu                TheISA::PCState pc, TheISA::PCState predPC,
4038502Sgblack@eecs.umich.edu                InstSeqNum seq_num, ImplCPU *cpu);
4043770Sgblack@eecs.umich.edu
4052292SN/A    /** BaseDynInst constructor given a StaticInst pointer.
4062292SN/A     *  @param _staticInst The StaticInst for this BaseDynInst.
4072292SN/A     */
4088502Sgblack@eecs.umich.edu    BaseDynInst(StaticInstPtr staticInst, StaticInstPtr macroop);
4091060SN/A
4101060SN/A    /** BaseDynInst destructor. */
4111060SN/A    ~BaseDynInst();
4121060SN/A
4131464SN/A  private:
4141684SN/A    /** Function to initialize variables in the constructors. */
4151464SN/A    void initVars();
4161060SN/A
4171464SN/A  public:
4181060SN/A    /** Dumps out contents of this BaseDynInst. */
4191060SN/A    void dump();
4201060SN/A
4211060SN/A    /** Dumps out contents of this BaseDynInst into given string. */
4221060SN/A    void dump(std::string &outstring);
4231060SN/A
4243326Sktlim@umich.edu    /** Read this CPU's ID. */
4255712Shsul@eecs.umich.edu    int cpuId() { return cpu->cpuId(); }
4263326Sktlim@umich.edu
4278832SAli.Saidi@ARM.com    /** Read this CPU's data requestor ID */
4288832SAli.Saidi@ARM.com    MasterID masterId() { return cpu->dataMasterId(); }
4298832SAli.Saidi@ARM.com
4305714Shsul@eecs.umich.edu    /** Read this context's system-wide ID **/
4315714Shsul@eecs.umich.edu    int contextId() { return thread->contextId(); }
4325714Shsul@eecs.umich.edu
4331060SN/A    /** Returns the fault type. */
4342132SN/A    Fault getFault() { return fault; }
4351060SN/A
4361060SN/A    /** Checks whether or not this instruction has had its branch target
4371060SN/A     *  calculated yet.  For now it is not utilized and is hacked to be
4381060SN/A     *  always false.
4392292SN/A     *  @todo: Actually use this instruction.
4401060SN/A     */
4411060SN/A    bool doneTargCalc() { return false; }
4421060SN/A
4437720Sgblack@eecs.umich.edu    /** Set the predicted target of this current instruction. */
4447720Sgblack@eecs.umich.edu    void setPredTarg(const TheISA::PCState &_predPC)
4453965Sgblack@eecs.umich.edu    {
4467720Sgblack@eecs.umich.edu        predPC = _predPC;
4473965Sgblack@eecs.umich.edu    }
4482935Sksewell@umich.edu
4497720Sgblack@eecs.umich.edu    const TheISA::PCState &readPredTarg() { return predPC; }
4501060SN/A
4513794Sgblack@eecs.umich.edu    /** Returns the predicted PC immediately after the branch. */
4527720Sgblack@eecs.umich.edu    Addr predInstAddr() { return predPC.instAddr(); }
4533794Sgblack@eecs.umich.edu
4543794Sgblack@eecs.umich.edu    /** Returns the predicted PC two instructions after the branch */
4557720Sgblack@eecs.umich.edu    Addr predNextInstAddr() { return predPC.nextInstAddr(); }
4561060SN/A
4574636Sgblack@eecs.umich.edu    /** Returns the predicted micro PC after the branch */
4587720Sgblack@eecs.umich.edu    Addr predMicroPC() { return predPC.microPC(); }
4594636Sgblack@eecs.umich.edu
4601060SN/A    /** Returns whether the instruction was predicted taken or not. */
4613794Sgblack@eecs.umich.edu    bool readPredTaken()
4623794Sgblack@eecs.umich.edu    {
4633794Sgblack@eecs.umich.edu        return predTaken;
4643794Sgblack@eecs.umich.edu    }
4653794Sgblack@eecs.umich.edu
4663794Sgblack@eecs.umich.edu    void setPredTaken(bool predicted_taken)
4673794Sgblack@eecs.umich.edu    {
4683794Sgblack@eecs.umich.edu        predTaken = predicted_taken;
4693794Sgblack@eecs.umich.edu    }
4701060SN/A
4711060SN/A    /** Returns whether the instruction mispredicted. */
4722935Sksewell@umich.edu    bool mispredicted()
4733794Sgblack@eecs.umich.edu    {
4747720Sgblack@eecs.umich.edu        TheISA::PCState tempPC = pc;
4757720Sgblack@eecs.umich.edu        TheISA::advancePC(tempPC, staticInst);
4767720Sgblack@eecs.umich.edu        return !(tempPC == predPC);
4773794Sgblack@eecs.umich.edu    }
4783794Sgblack@eecs.umich.edu
4791060SN/A    //
4801060SN/A    //  Instruction types.  Forward checks to StaticInst object.
4811060SN/A    //
4825543Ssaidi@eecs.umich.edu    bool isNop()          const { return staticInst->isNop(); }
4835543Ssaidi@eecs.umich.edu    bool isMemRef()       const { return staticInst->isMemRef(); }
4845543Ssaidi@eecs.umich.edu    bool isLoad()         const { return staticInst->isLoad(); }
4855543Ssaidi@eecs.umich.edu    bool isStore()        const { return staticInst->isStore(); }
4862336SN/A    bool isStoreConditional() const
4872336SN/A    { return staticInst->isStoreConditional(); }
4881060SN/A    bool isInstPrefetch() const { return staticInst->isInstPrefetch(); }
4891060SN/A    bool isDataPrefetch() const { return staticInst->isDataPrefetch(); }
4905543Ssaidi@eecs.umich.edu    bool isInteger()      const { return staticInst->isInteger(); }
4915543Ssaidi@eecs.umich.edu    bool isFloating()     const { return staticInst->isFloating(); }
4925543Ssaidi@eecs.umich.edu    bool isControl()      const { return staticInst->isControl(); }
4935543Ssaidi@eecs.umich.edu    bool isCall()         const { return staticInst->isCall(); }
4945543Ssaidi@eecs.umich.edu    bool isReturn()       const { return staticInst->isReturn(); }
4955543Ssaidi@eecs.umich.edu    bool isDirectCtrl()   const { return staticInst->isDirectCtrl(); }
4961060SN/A    bool isIndirectCtrl() const { return staticInst->isIndirectCtrl(); }
4975543Ssaidi@eecs.umich.edu    bool isCondCtrl()     const { return staticInst->isCondCtrl(); }
4985543Ssaidi@eecs.umich.edu    bool isUncondCtrl()   const { return staticInst->isUncondCtrl(); }
4992935Sksewell@umich.edu    bool isCondDelaySlot() const { return staticInst->isCondDelaySlot(); }
5001060SN/A    bool isThreadSync()   const { return staticInst->isThreadSync(); }
5011060SN/A    bool isSerializing()  const { return staticInst->isSerializing(); }
5022292SN/A    bool isSerializeBefore() const
5032731Sktlim@umich.edu    { return staticInst->isSerializeBefore() || status[SerializeBefore]; }
5042292SN/A    bool isSerializeAfter() const
5052731Sktlim@umich.edu    { return staticInst->isSerializeAfter() || status[SerializeAfter]; }
5067784SAli.Saidi@ARM.com    bool isSquashAfter() const { return staticInst->isSquashAfter(); }
5071060SN/A    bool isMemBarrier()   const { return staticInst->isMemBarrier(); }
5081060SN/A    bool isWriteBarrier() const { return staticInst->isWriteBarrier(); }
5091060SN/A    bool isNonSpeculative() const { return staticInst->isNonSpeculative(); }
5102292SN/A    bool isQuiesce() const { return staticInst->isQuiesce(); }
5112336SN/A    bool isIprAccess() const { return staticInst->isIprAccess(); }
5122308SN/A    bool isUnverifiable() const { return staticInst->isUnverifiable(); }
5134828Sgblack@eecs.umich.edu    bool isSyscall() const { return staticInst->isSyscall(); }
5144654Sgblack@eecs.umich.edu    bool isMacroop() const { return staticInst->isMacroop(); }
5154654Sgblack@eecs.umich.edu    bool isMicroop() const { return staticInst->isMicroop(); }
5164636Sgblack@eecs.umich.edu    bool isDelayedCommit() const { return staticInst->isDelayedCommit(); }
5174654Sgblack@eecs.umich.edu    bool isLastMicroop() const { return staticInst->isLastMicroop(); }
5184654Sgblack@eecs.umich.edu    bool isFirstMicroop() const { return staticInst->isFirstMicroop(); }
5194636Sgblack@eecs.umich.edu    bool isMicroBranch() const { return staticInst->isMicroBranch(); }
5202292SN/A
5212292SN/A    /** Temporarily sets this instruction as a serialize before instruction. */
5222731Sktlim@umich.edu    void setSerializeBefore() { status.set(SerializeBefore); }
5232292SN/A
5242292SN/A    /** Clears the serializeBefore part of this instruction. */
5252731Sktlim@umich.edu    void clearSerializeBefore() { status.reset(SerializeBefore); }
5262292SN/A
5272292SN/A    /** Checks if this serializeBefore is only temporarily set. */
5282731Sktlim@umich.edu    bool isTempSerializeBefore() { return status[SerializeBefore]; }
5292292SN/A
5302292SN/A    /** Temporarily sets this instruction as a serialize after instruction. */
5312731Sktlim@umich.edu    void setSerializeAfter() { status.set(SerializeAfter); }
5322292SN/A
5332292SN/A    /** Clears the serializeAfter part of this instruction.*/
5342731Sktlim@umich.edu    void clearSerializeAfter() { status.reset(SerializeAfter); }
5352292SN/A
5362292SN/A    /** Checks if this serializeAfter is only temporarily set. */
5372731Sktlim@umich.edu    bool isTempSerializeAfter() { return status[SerializeAfter]; }
5382292SN/A
5392731Sktlim@umich.edu    /** Sets the serialization part of this instruction as handled. */
5402731Sktlim@umich.edu    void setSerializeHandled() { status.set(SerializeHandled); }
5412292SN/A
5422292SN/A    /** Checks if the serialization part of this instruction has been
5432292SN/A     *  handled.  This does not apply to the temporary serializing
5442292SN/A     *  state; it only applies to this instruction's own permanent
5452292SN/A     *  serializing state.
5462292SN/A     */
5472731Sktlim@umich.edu    bool isSerializeHandled() { return status[SerializeHandled]; }
5481060SN/A
5491464SN/A    /** Returns the opclass of this instruction. */
5501464SN/A    OpClass opClass() const { return staticInst->opClass(); }
5511464SN/A
5521464SN/A    /** Returns the branch target address. */
5537720Sgblack@eecs.umich.edu    TheISA::PCState branchTarget() const
5547720Sgblack@eecs.umich.edu    { return staticInst->branchTarget(pc); }
5551464SN/A
5562292SN/A    /** Returns the number of source registers. */
5575543Ssaidi@eecs.umich.edu    int8_t numSrcRegs() const { return staticInst->numSrcRegs(); }
5581684SN/A
5592292SN/A    /** Returns the number of destination registers. */
5601060SN/A    int8_t numDestRegs() const { return staticInst->numDestRegs(); }
5611060SN/A
5621060SN/A    // the following are used to track physical register usage
5631060SN/A    // for machines with separate int & FP reg files
5641060SN/A    int8_t numFPDestRegs()  const { return staticInst->numFPDestRegs(); }
5651060SN/A    int8_t numIntDestRegs() const { return staticInst->numIntDestRegs(); }
5661060SN/A
5671060SN/A    /** Returns the logical register index of the i'th destination register. */
5682292SN/A    RegIndex destRegIdx(int i) const { return staticInst->destRegIdx(i); }
5691060SN/A
5701060SN/A    /** Returns the logical register index of the i'th source register. */
5712292SN/A    RegIndex srcRegIdx(int i) const { return staticInst->srcRegIdx(i); }
5721060SN/A
5738733Sgeoffrey.blake@arm.com    /** Pops a result off the instResult queue */
5748733Sgeoffrey.blake@arm.com    template <class T>
5758733Sgeoffrey.blake@arm.com    void popResult(T& t)
5768733Sgeoffrey.blake@arm.com    {
5778733Sgeoffrey.blake@arm.com        if (!instResult.empty()) {
5788733Sgeoffrey.blake@arm.com            instResult.front().get(t);
5798733Sgeoffrey.blake@arm.com            instResult.pop();
5808733Sgeoffrey.blake@arm.com        }
5818733Sgeoffrey.blake@arm.com    }
5821684SN/A
5838733Sgeoffrey.blake@arm.com    /** Read the most recent result stored by this instruction */
5848733Sgeoffrey.blake@arm.com    template <class T>
5858733Sgeoffrey.blake@arm.com    void readResult(T& t)
5868733Sgeoffrey.blake@arm.com    {
5878733Sgeoffrey.blake@arm.com        instResult.back().get(t);
5888733Sgeoffrey.blake@arm.com    }
5891684SN/A
5908733Sgeoffrey.blake@arm.com    /** Pushes a result onto the instResult queue */
5918733Sgeoffrey.blake@arm.com    template <class T>
5928733Sgeoffrey.blake@arm.com    void setResult(T t)
5938733Sgeoffrey.blake@arm.com    {
5948733Sgeoffrey.blake@arm.com        if (recordResult) {
5958733Sgeoffrey.blake@arm.com            Result instRes;
5968733Sgeoffrey.blake@arm.com            instRes.set(t);
5978733Sgeoffrey.blake@arm.com            instResult.push(instRes);
5988733Sgeoffrey.blake@arm.com        }
5998733Sgeoffrey.blake@arm.com    }
6001060SN/A
6012702Sktlim@umich.edu    /** Records an integer register being set to a value. */
6023735Sstever@eecs.umich.edu    void setIntRegOperand(const StaticInst *si, int idx, uint64_t val)
6031060SN/A    {
6048733Sgeoffrey.blake@arm.com        setResult<uint64_t>(val);
6051060SN/A    }
6061060SN/A
6072702Sktlim@umich.edu    /** Records an fp register being set to a value. */
6083735Sstever@eecs.umich.edu    void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val,
6093735Sstever@eecs.umich.edu                            int width)
6102690Sktlim@umich.edu    {
6118733Sgeoffrey.blake@arm.com        if (width == 32 || width == 64) {
6128733Sgeoffrey.blake@arm.com            setResult<double>(val);
6138733Sgeoffrey.blake@arm.com        } else {
6148733Sgeoffrey.blake@arm.com            panic("Unsupported width!");
6153326Sktlim@umich.edu        }
6162690Sktlim@umich.edu    }
6172690Sktlim@umich.edu
6182702Sktlim@umich.edu    /** Records an fp register being set to a value. */
6193735Sstever@eecs.umich.edu    void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val)
6201060SN/A    {
6218733Sgeoffrey.blake@arm.com        setResult<double>(val);
6222308SN/A    }
6231060SN/A
6242702Sktlim@umich.edu    /** Records an fp register being set to an integer value. */
6253735Sstever@eecs.umich.edu    void setFloatRegOperandBits(const StaticInst *si, int idx, uint64_t val,
6263735Sstever@eecs.umich.edu                                int width)
6272308SN/A    {
6288733Sgeoffrey.blake@arm.com        setResult<uint64_t>(val);
6292308SN/A    }
6301060SN/A
6312702Sktlim@umich.edu    /** Records an fp register being set to an integer value. */
6323735Sstever@eecs.umich.edu    void setFloatRegOperandBits(const StaticInst *si, int idx, uint64_t val)
6332308SN/A    {
6348733Sgeoffrey.blake@arm.com        setResult<uint64_t>(val);
6351060SN/A    }
6361060SN/A
6372190SN/A    /** Records that one of the source registers is ready. */
6382292SN/A    void markSrcRegReady();
6392190SN/A
6402331SN/A    /** Marks a specific register as ready. */
6412292SN/A    void markSrcRegReady(RegIndex src_idx);
6422190SN/A
6431684SN/A    /** Returns if a source register is ready. */
6441464SN/A    bool isReadySrcRegIdx(int idx) const
6451464SN/A    {
6461464SN/A        return this->_readySrcRegIdx[idx];
6471464SN/A    }
6481464SN/A
6491684SN/A    /** Sets this instruction as completed. */
6502731Sktlim@umich.edu    void setCompleted() { status.set(Completed); }
6511464SN/A
6522292SN/A    /** Returns whether or not this instruction is completed. */
6532731Sktlim@umich.edu    bool isCompleted() const { return status[Completed]; }
6541464SN/A
6552731Sktlim@umich.edu    /** Marks the result as ready. */
6562731Sktlim@umich.edu    void setResultReady() { status.set(ResultReady); }
6572308SN/A
6582731Sktlim@umich.edu    /** Returns whether or not the result is ready. */
6592731Sktlim@umich.edu    bool isResultReady() const { return status[ResultReady]; }
6602308SN/A
6611060SN/A    /** Sets this instruction as ready to issue. */
6622731Sktlim@umich.edu    void setCanIssue() { status.set(CanIssue); }
6631060SN/A
6641060SN/A    /** Returns whether or not this instruction is ready to issue. */
6652731Sktlim@umich.edu    bool readyToIssue() const { return status[CanIssue]; }
6661060SN/A
6674032Sktlim@umich.edu    /** Clears this instruction being able to issue. */
6684032Sktlim@umich.edu    void clearCanIssue() { status.reset(CanIssue); }
6694032Sktlim@umich.edu
6701060SN/A    /** Sets this instruction as issued from the IQ. */
6712731Sktlim@umich.edu    void setIssued() { status.set(Issued); }
6721060SN/A
6731060SN/A    /** Returns whether or not this instruction has issued. */
6742731Sktlim@umich.edu    bool isIssued() const { return status[Issued]; }
6751060SN/A
6764032Sktlim@umich.edu    /** Clears this instruction as being issued. */
6774032Sktlim@umich.edu    void clearIssued() { status.reset(Issued); }
6784032Sktlim@umich.edu
6791060SN/A    /** Sets this instruction as executed. */
6802731Sktlim@umich.edu    void setExecuted() { status.set(Executed); }
6811060SN/A
6821060SN/A    /** Returns whether or not this instruction has executed. */
6832731Sktlim@umich.edu    bool isExecuted() const { return status[Executed]; }
6841060SN/A
6851060SN/A    /** Sets this instruction as ready to commit. */
6862731Sktlim@umich.edu    void setCanCommit() { status.set(CanCommit); }
6871060SN/A
6881061SN/A    /** Clears this instruction as being ready to commit. */
6892731Sktlim@umich.edu    void clearCanCommit() { status.reset(CanCommit); }
6901061SN/A
6911060SN/A    /** Returns whether or not this instruction is ready to commit. */
6922731Sktlim@umich.edu    bool readyToCommit() const { return status[CanCommit]; }
6932731Sktlim@umich.edu
6942731Sktlim@umich.edu    void setAtCommit() { status.set(AtCommit); }
6952731Sktlim@umich.edu
6962731Sktlim@umich.edu    bool isAtCommit() { return status[AtCommit]; }
6971060SN/A
6982292SN/A    /** Sets this instruction as committed. */
6992731Sktlim@umich.edu    void setCommitted() { status.set(Committed); }
7002292SN/A
7012292SN/A    /** Returns whether or not this instruction is committed. */
7022731Sktlim@umich.edu    bool isCommitted() const { return status[Committed]; }
7032292SN/A
7041060SN/A    /** Sets this instruction as squashed. */
7052731Sktlim@umich.edu    void setSquashed() { status.set(Squashed); }
7061060SN/A
7071060SN/A    /** Returns whether or not this instruction is squashed. */
7082731Sktlim@umich.edu    bool isSquashed() const { return status[Squashed]; }
7091060SN/A
7102292SN/A    //Instruction Queue Entry
7112292SN/A    //-----------------------
7122292SN/A    /** Sets this instruction as a entry the IQ. */
7132731Sktlim@umich.edu    void setInIQ() { status.set(IqEntry); }
7142292SN/A
7152292SN/A    /** Sets this instruction as a entry the IQ. */
7162731Sktlim@umich.edu    void clearInIQ() { status.reset(IqEntry); }
7172731Sktlim@umich.edu
7182731Sktlim@umich.edu    /** Returns whether or not this instruction has issued. */
7192731Sktlim@umich.edu    bool isInIQ() const { return status[IqEntry]; }
7202292SN/A
7211060SN/A    /** Sets this instruction as squashed in the IQ. */
7222731Sktlim@umich.edu    void setSquashedInIQ() { status.set(SquashedInIQ); status.set(Squashed);}
7231060SN/A
7241060SN/A    /** Returns whether or not this instruction is squashed in the IQ. */
7252731Sktlim@umich.edu    bool isSquashedInIQ() const { return status[SquashedInIQ]; }
7262292SN/A
7272292SN/A
7282292SN/A    //Load / Store Queue Functions
7292292SN/A    //-----------------------
7302292SN/A    /** Sets this instruction as a entry the LSQ. */
7312731Sktlim@umich.edu    void setInLSQ() { status.set(LsqEntry); }
7322292SN/A
7332292SN/A    /** Sets this instruction as a entry the LSQ. */
7342731Sktlim@umich.edu    void removeInLSQ() { status.reset(LsqEntry); }
7352731Sktlim@umich.edu
7362731Sktlim@umich.edu    /** Returns whether or not this instruction is in the LSQ. */
7372731Sktlim@umich.edu    bool isInLSQ() const { return status[LsqEntry]; }
7382292SN/A
7392292SN/A    /** Sets this instruction as squashed in the LSQ. */
7402731Sktlim@umich.edu    void setSquashedInLSQ() { status.set(SquashedInLSQ);}
7412292SN/A
7422292SN/A    /** Returns whether or not this instruction is squashed in the LSQ. */
7432731Sktlim@umich.edu    bool isSquashedInLSQ() const { return status[SquashedInLSQ]; }
7442292SN/A
7452292SN/A
7462292SN/A    //Reorder Buffer Functions
7472292SN/A    //-----------------------
7482292SN/A    /** Sets this instruction as a entry the ROB. */
7492731Sktlim@umich.edu    void setInROB() { status.set(RobEntry); }
7502292SN/A
7512292SN/A    /** Sets this instruction as a entry the ROB. */
7522731Sktlim@umich.edu    void clearInROB() { status.reset(RobEntry); }
7532731Sktlim@umich.edu
7542731Sktlim@umich.edu    /** Returns whether or not this instruction is in the ROB. */
7552731Sktlim@umich.edu    bool isInROB() const { return status[RobEntry]; }
7562292SN/A
7572292SN/A    /** Sets this instruction as squashed in the ROB. */
7582731Sktlim@umich.edu    void setSquashedInROB() { status.set(SquashedInROB); }
7592292SN/A
7602292SN/A    /** Returns whether or not this instruction is squashed in the ROB. */
7612731Sktlim@umich.edu    bool isSquashedInROB() const { return status[SquashedInROB]; }
7622292SN/A
7637720Sgblack@eecs.umich.edu    /** Read the PC state of this instruction. */
7647720Sgblack@eecs.umich.edu    const TheISA::PCState pcState() const { return pc; }
7657720Sgblack@eecs.umich.edu
7667720Sgblack@eecs.umich.edu    /** Set the PC state of this instruction. */
7677720Sgblack@eecs.umich.edu    const void pcState(const TheISA::PCState &val) { pc = val; }
7687720Sgblack@eecs.umich.edu
7691060SN/A    /** Read the PC of this instruction. */
7707720Sgblack@eecs.umich.edu    const Addr instAddr() const { return pc.instAddr(); }
7717720Sgblack@eecs.umich.edu
7727720Sgblack@eecs.umich.edu    /** Read the PC of the next instruction. */
7737720Sgblack@eecs.umich.edu    const Addr nextInstAddr() const { return pc.nextInstAddr(); }
7741060SN/A
7754636Sgblack@eecs.umich.edu    /**Read the micro PC of this instruction. */
7767720Sgblack@eecs.umich.edu    const Addr microPC() const { return pc.microPC(); }
7774636Sgblack@eecs.umich.edu
7787597Sminkyu.jeong@arm.com    bool readPredicate()
7797597Sminkyu.jeong@arm.com    {
7807597Sminkyu.jeong@arm.com        return predicate;
7817597Sminkyu.jeong@arm.com    }
7827597Sminkyu.jeong@arm.com
7837597Sminkyu.jeong@arm.com    void setPredicate(bool val)
7847597Sminkyu.jeong@arm.com    {
7857597Sminkyu.jeong@arm.com        predicate = val;
7867600Sminkyu.jeong@arm.com
7877600Sminkyu.jeong@arm.com        if (traceData) {
7887600Sminkyu.jeong@arm.com            traceData->setPredicate(val);
7897600Sminkyu.jeong@arm.com        }
7907597Sminkyu.jeong@arm.com    }
7917597Sminkyu.jeong@arm.com
7922702Sktlim@umich.edu    /** Sets the ASID. */
7932292SN/A    void setASID(short addr_space_id) { asid = addr_space_id; }
7942292SN/A
7952702Sktlim@umich.edu    /** Sets the thread id. */
7966221Snate@binkert.org    void setTid(ThreadID tid) { threadNumber = tid; }
7972292SN/A
7982731Sktlim@umich.edu    /** Sets the pointer to the thread state. */
7992702Sktlim@umich.edu    void setThreadState(ImplState *state) { thread = state; }
8001060SN/A
8012731Sktlim@umich.edu    /** Returns the thread context. */
8022680Sktlim@umich.edu    ThreadContext *tcBase() { return thread->getTC(); }
8031464SN/A
8041464SN/A  private:
8051684SN/A    /** Instruction effective address.
8061684SN/A     *  @todo: Consider if this is necessary or not.
8071684SN/A     */
8081464SN/A    Addr instEffAddr;
8092292SN/A
8101684SN/A    /** Whether or not the effective address calculation is completed.
8111684SN/A     *  @todo: Consider if this is necessary or not.
8121684SN/A     */
8131464SN/A    bool eaCalcDone;
8141464SN/A
8154032Sktlim@umich.edu    /** Is this instruction's memory access uncacheable. */
8164032Sktlim@umich.edu    bool isUncacheable;
8174032Sktlim@umich.edu
8184032Sktlim@umich.edu    /** Has this instruction generated a memory request. */
8194032Sktlim@umich.edu    bool reqMade;
8204032Sktlim@umich.edu
8211464SN/A  public:
8221684SN/A    /** Sets the effective address. */
8231464SN/A    void setEA(Addr &ea) { instEffAddr = ea; eaCalcDone = true; }
8241684SN/A
8251684SN/A    /** Returns the effective address. */
8261464SN/A    const Addr &getEA() const { return instEffAddr; }
8271684SN/A
8281684SN/A    /** Returns whether or not the eff. addr. calculation has been completed. */
8291464SN/A    bool doneEACalc() { return eaCalcDone; }
8301684SN/A
8311684SN/A    /** Returns whether or not the eff. addr. source registers are ready. */
8321464SN/A    bool eaSrcsReady();
8331681SN/A
8342292SN/A    /** Whether or not the memory operation is done. */
8352292SN/A    bool memOpDone;
8362292SN/A
8374032Sktlim@umich.edu    /** Is this instruction's memory access uncacheable. */
8384032Sktlim@umich.edu    bool uncacheable() { return isUncacheable; }
8394032Sktlim@umich.edu
8404032Sktlim@umich.edu    /** Has this instruction generated a memory request. */
8414032Sktlim@umich.edu    bool hasRequest() { return reqMade; }
8424032Sktlim@umich.edu
8431681SN/A  public:
8441684SN/A    /** Load queue index. */
8451681SN/A    int16_t lqIdx;
8461684SN/A
8471684SN/A    /** Store queue index. */
8481681SN/A    int16_t sqIdx;
8492292SN/A
8502292SN/A    /** Iterator pointing to this BaseDynInst in the list of all insts. */
8512292SN/A    ListIt instListIt;
8522292SN/A
8532292SN/A    /** Returns iterator to this instruction in the list of all insts. */
8542292SN/A    ListIt &getInstListIt() { return instListIt; }
8552292SN/A
8562292SN/A    /** Sets iterator for this instruction in the list of all insts. */
8572292SN/A    void setInstListIt(ListIt _instListIt) { instListIt = _instListIt; }
8583326Sktlim@umich.edu
8593326Sktlim@umich.edu  public:
8603326Sktlim@umich.edu    /** Returns the number of consecutive store conditional failures. */
8613326Sktlim@umich.edu    unsigned readStCondFailures()
8623326Sktlim@umich.edu    { return thread->storeCondFailures; }
8633326Sktlim@umich.edu
8643326Sktlim@umich.edu    /** Sets the number of consecutive store conditional failures. */
8653326Sktlim@umich.edu    void setStCondFailures(unsigned sc_failures)
8663326Sktlim@umich.edu    { thread->storeCondFailures = sc_failures; }
8671060SN/A};
8681060SN/A
8691060SN/Atemplate<class Impl>
8707520Sgblack@eecs.umich.eduFault
8718444Sgblack@eecs.umich.eduBaseDynInst<Impl>::readMem(Addr addr, uint8_t *data,
8728444Sgblack@eecs.umich.edu                           unsigned size, unsigned flags)
8731060SN/A{
8744032Sktlim@umich.edu    reqMade = true;
8757944SGiacomo.Gabrielli@arm.com    Request *req = NULL;
8766974Stjones1@inf.ed.ac.uk    Request *sreqLow = NULL;
8776974Stjones1@inf.ed.ac.uk    Request *sreqHigh = NULL;
8786974Stjones1@inf.ed.ac.uk
8797944SGiacomo.Gabrielli@arm.com    if (reqMade && translationStarted) {
8807944SGiacomo.Gabrielli@arm.com        req = savedReq;
8817944SGiacomo.Gabrielli@arm.com        sreqLow = savedSreqLow;
8827944SGiacomo.Gabrielli@arm.com        sreqHigh = savedSreqHigh;
8837944SGiacomo.Gabrielli@arm.com    } else {
8848832SAli.Saidi@ARM.com        req = new Request(asid, addr, size, flags, masterId(), this->pc.instAddr(),
8857944SGiacomo.Gabrielli@arm.com                          thread->contextId(), threadNumber);
8864032Sktlim@umich.edu
8877944SGiacomo.Gabrielli@arm.com        // Only split the request if the ISA supports unaligned accesses.
8887944SGiacomo.Gabrielli@arm.com        if (TheISA::HasUnalignedMemAcc) {
8897944SGiacomo.Gabrielli@arm.com            splitRequest(req, sreqLow, sreqHigh);
8907944SGiacomo.Gabrielli@arm.com        }
8917944SGiacomo.Gabrielli@arm.com        initiateTranslation(req, sreqLow, sreqHigh, NULL, BaseTLB::Read);
8921060SN/A    }
8931060SN/A
8947944SGiacomo.Gabrielli@arm.com    if (translationCompleted) {
8957944SGiacomo.Gabrielli@arm.com        if (fault == NoFault) {
8967944SGiacomo.Gabrielli@arm.com            effAddr = req->getVaddr();
8978199SAli.Saidi@ARM.com            effSize = size;
8987944SGiacomo.Gabrielli@arm.com            effAddrValid = true;
8998733Sgeoffrey.blake@arm.com#if USE_CHECKER
9008733Sgeoffrey.blake@arm.com            if (reqToVerify != NULL) {
9018733Sgeoffrey.blake@arm.com                delete reqToVerify;
9028733Sgeoffrey.blake@arm.com            }
9038733Sgeoffrey.blake@arm.com            reqToVerify = new Request(*req);
9048733Sgeoffrey.blake@arm.com#endif //USE_CHECKER
9057944SGiacomo.Gabrielli@arm.com            fault = cpu->read(req, sreqLow, sreqHigh, data, lqIdx);
9067944SGiacomo.Gabrielli@arm.com        } else {
9077944SGiacomo.Gabrielli@arm.com            // Commit will have to clean up whatever happened.  Set this
9087944SGiacomo.Gabrielli@arm.com            // instruction as executed.
9097944SGiacomo.Gabrielli@arm.com            this->setExecuted();
9107944SGiacomo.Gabrielli@arm.com        }
9117944SGiacomo.Gabrielli@arm.com
9127944SGiacomo.Gabrielli@arm.com        if (fault != NoFault) {
9137944SGiacomo.Gabrielli@arm.com            // Return a fixed value to keep simulation deterministic even
9147944SGiacomo.Gabrielli@arm.com            // along misspeculated paths.
9157944SGiacomo.Gabrielli@arm.com            if (data)
9167944SGiacomo.Gabrielli@arm.com                bzero(data, size);
9177944SGiacomo.Gabrielli@arm.com        }
9187577SAli.Saidi@ARM.com    }
9197577SAli.Saidi@ARM.com
9201060SN/A    if (traceData) {
9211060SN/A        traceData->setAddr(addr);
9221060SN/A    }
9231060SN/A
9241060SN/A    return fault;
9251060SN/A}
9261060SN/A
9271060SN/Atemplate<class Impl>
9287520Sgblack@eecs.umich.eduFault
9298444Sgblack@eecs.umich.eduBaseDynInst<Impl>::writeMem(uint8_t *data, unsigned size,
9308444Sgblack@eecs.umich.edu                            Addr addr, unsigned flags, uint64_t *res)
9311060SN/A{
9321060SN/A    if (traceData) {
9331060SN/A        traceData->setAddr(addr);
9341060SN/A    }
9351060SN/A
9364032Sktlim@umich.edu    reqMade = true;
9377944SGiacomo.Gabrielli@arm.com    Request *req = NULL;
9386974Stjones1@inf.ed.ac.uk    Request *sreqLow = NULL;
9396974Stjones1@inf.ed.ac.uk    Request *sreqHigh = NULL;
9406974Stjones1@inf.ed.ac.uk
9417944SGiacomo.Gabrielli@arm.com    if (reqMade && translationStarted) {
9427944SGiacomo.Gabrielli@arm.com        req = savedReq;
9437944SGiacomo.Gabrielli@arm.com        sreqLow = savedSreqLow;
9447944SGiacomo.Gabrielli@arm.com        sreqHigh = savedSreqHigh;
9457944SGiacomo.Gabrielli@arm.com    } else {
9468832SAli.Saidi@ARM.com        req = new Request(asid, addr, size, flags, masterId(), this->pc.instAddr(),
9477944SGiacomo.Gabrielli@arm.com                          thread->contextId(), threadNumber);
9487944SGiacomo.Gabrielli@arm.com
9497944SGiacomo.Gabrielli@arm.com        // Only split the request if the ISA supports unaligned accesses.
9507944SGiacomo.Gabrielli@arm.com        if (TheISA::HasUnalignedMemAcc) {
9517944SGiacomo.Gabrielli@arm.com            splitRequest(req, sreqLow, sreqHigh);
9527944SGiacomo.Gabrielli@arm.com        }
9537944SGiacomo.Gabrielli@arm.com        initiateTranslation(req, sreqLow, sreqHigh, res, BaseTLB::Write);
9546974Stjones1@inf.ed.ac.uk    }
9554032Sktlim@umich.edu
9567944SGiacomo.Gabrielli@arm.com    if (fault == NoFault && translationCompleted) {
9572678Sktlim@umich.edu        effAddr = req->getVaddr();
9588199SAli.Saidi@ARM.com        effSize = size;
9594032Sktlim@umich.edu        effAddrValid = true;
9608733Sgeoffrey.blake@arm.com#if USE_CHECKER
9618733Sgeoffrey.blake@arm.com        if (reqToVerify != NULL) {
9628733Sgeoffrey.blake@arm.com            delete reqToVerify;
9638733Sgeoffrey.blake@arm.com        }
9648733Sgeoffrey.blake@arm.com        reqToVerify = new Request(*req);
9658733Sgeoffrey.blake@arm.com#endif // USE_CHECKER
9666975Stjones1@inf.ed.ac.uk        fault = cpu->write(req, sreqLow, sreqHigh, data, sqIdx);
9671060SN/A    }
9681060SN/A
9691060SN/A    return fault;
9701060SN/A}
9711060SN/A
9726973Stjones1@inf.ed.ac.uktemplate<class Impl>
9736973Stjones1@inf.ed.ac.ukinline void
9746974Stjones1@inf.ed.ac.ukBaseDynInst<Impl>::splitRequest(RequestPtr req, RequestPtr &sreqLow,
9756974Stjones1@inf.ed.ac.uk                                RequestPtr &sreqHigh)
9766974Stjones1@inf.ed.ac.uk{
9776974Stjones1@inf.ed.ac.uk    // Check to see if the request crosses the next level block boundary.
9786974Stjones1@inf.ed.ac.uk    unsigned block_size = cpu->getDcachePort()->peerBlockSize();
9796974Stjones1@inf.ed.ac.uk    Addr addr = req->getVaddr();
9806974Stjones1@inf.ed.ac.uk    Addr split_addr = roundDown(addr + req->getSize() - 1, block_size);
9816974Stjones1@inf.ed.ac.uk    assert(split_addr <= addr || split_addr - addr < block_size);
9826974Stjones1@inf.ed.ac.uk
9836974Stjones1@inf.ed.ac.uk    // Spans two blocks.
9846974Stjones1@inf.ed.ac.uk    if (split_addr > addr) {
9856974Stjones1@inf.ed.ac.uk        req->splitOnVaddr(split_addr, sreqLow, sreqHigh);
9866974Stjones1@inf.ed.ac.uk    }
9876974Stjones1@inf.ed.ac.uk}
9886974Stjones1@inf.ed.ac.uk
9896974Stjones1@inf.ed.ac.uktemplate<class Impl>
9906974Stjones1@inf.ed.ac.ukinline void
9916974Stjones1@inf.ed.ac.ukBaseDynInst<Impl>::initiateTranslation(RequestPtr req, RequestPtr sreqLow,
9926974Stjones1@inf.ed.ac.uk                                       RequestPtr sreqHigh, uint64_t *res,
9936973Stjones1@inf.ed.ac.uk                                       BaseTLB::Mode mode)
9946973Stjones1@inf.ed.ac.uk{
9957944SGiacomo.Gabrielli@arm.com    translationStarted = true;
9967944SGiacomo.Gabrielli@arm.com
9976974Stjones1@inf.ed.ac.uk    if (!TheISA::HasUnalignedMemAcc || sreqLow == NULL) {
9986974Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
9996974Stjones1@inf.ed.ac.uk            new WholeTranslationState(req, NULL, res, mode);
10006974Stjones1@inf.ed.ac.uk
10016974Stjones1@inf.ed.ac.uk        // One translation if the request isn't split.
10028486Sgblack@eecs.umich.edu        DataTranslation<BaseDynInstPtr> *trans =
10038486Sgblack@eecs.umich.edu            new DataTranslation<BaseDynInstPtr>(this, state);
10046974Stjones1@inf.ed.ac.uk        cpu->dtb->translateTiming(req, thread->getTC(), trans, mode);
10057944SGiacomo.Gabrielli@arm.com        if (!translationCompleted) {
10067944SGiacomo.Gabrielli@arm.com            // Save memory requests.
10077944SGiacomo.Gabrielli@arm.com            savedReq = state->mainReq;
10087944SGiacomo.Gabrielli@arm.com            savedSreqLow = state->sreqLow;
10097944SGiacomo.Gabrielli@arm.com            savedSreqHigh = state->sreqHigh;
10107944SGiacomo.Gabrielli@arm.com        }
10116974Stjones1@inf.ed.ac.uk    } else {
10126974Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
10136974Stjones1@inf.ed.ac.uk            new WholeTranslationState(req, sreqLow, sreqHigh, NULL, res, mode);
10146974Stjones1@inf.ed.ac.uk
10156974Stjones1@inf.ed.ac.uk        // Two translations when the request is split.
10168486Sgblack@eecs.umich.edu        DataTranslation<BaseDynInstPtr> *stransLow =
10178486Sgblack@eecs.umich.edu            new DataTranslation<BaseDynInstPtr>(this, state, 0);
10188486Sgblack@eecs.umich.edu        DataTranslation<BaseDynInstPtr> *stransHigh =
10198486Sgblack@eecs.umich.edu            new DataTranslation<BaseDynInstPtr>(this, state, 1);
10206974Stjones1@inf.ed.ac.uk
10216974Stjones1@inf.ed.ac.uk        cpu->dtb->translateTiming(sreqLow, thread->getTC(), stransLow, mode);
10226974Stjones1@inf.ed.ac.uk        cpu->dtb->translateTiming(sreqHigh, thread->getTC(), stransHigh, mode);
10237944SGiacomo.Gabrielli@arm.com        if (!translationCompleted) {
10247944SGiacomo.Gabrielli@arm.com            // Save memory requests.
10257944SGiacomo.Gabrielli@arm.com            savedReq = state->mainReq;
10267944SGiacomo.Gabrielli@arm.com            savedSreqLow = state->sreqLow;
10277944SGiacomo.Gabrielli@arm.com            savedSreqHigh = state->sreqHigh;
10287944SGiacomo.Gabrielli@arm.com        }
10296974Stjones1@inf.ed.ac.uk    }
10306973Stjones1@inf.ed.ac.uk}
10316973Stjones1@inf.ed.ac.uk
10326973Stjones1@inf.ed.ac.uktemplate<class Impl>
10336973Stjones1@inf.ed.ac.ukinline void
10346973Stjones1@inf.ed.ac.ukBaseDynInst<Impl>::finishTranslation(WholeTranslationState *state)
10356973Stjones1@inf.ed.ac.uk{
10366973Stjones1@inf.ed.ac.uk    fault = state->getFault();
10376973Stjones1@inf.ed.ac.uk
10386973Stjones1@inf.ed.ac.uk    if (state->isUncacheable())
10396973Stjones1@inf.ed.ac.uk        isUncacheable = true;
10406973Stjones1@inf.ed.ac.uk
10416973Stjones1@inf.ed.ac.uk    if (fault == NoFault) {
10426973Stjones1@inf.ed.ac.uk        physEffAddr = state->getPaddr();
10436973Stjones1@inf.ed.ac.uk        memReqFlags = state->getFlags();
10446973Stjones1@inf.ed.ac.uk
10456973Stjones1@inf.ed.ac.uk        if (state->mainReq->isCondSwap()) {
10466973Stjones1@inf.ed.ac.uk            assert(state->res);
10476973Stjones1@inf.ed.ac.uk            state->mainReq->setExtraData(*state->res);
10486973Stjones1@inf.ed.ac.uk        }
10496973Stjones1@inf.ed.ac.uk
10506973Stjones1@inf.ed.ac.uk    } else {
10516973Stjones1@inf.ed.ac.uk        state->deleteReqs();
10526973Stjones1@inf.ed.ac.uk    }
10536973Stjones1@inf.ed.ac.uk    delete state;
10547944SGiacomo.Gabrielli@arm.com
10557944SGiacomo.Gabrielli@arm.com    translationCompleted = true;
10566973Stjones1@inf.ed.ac.uk}
10576973Stjones1@inf.ed.ac.uk
10581464SN/A#endif // __CPU_BASE_DYN_INST_HH__
1059