base_dyn_inst.hh revision 2733
11060SN/A/*
22702Sktlim@umich.edu * Copyright (c) 2004-2006 The Regents of The University of Michigan
31060SN/A * All rights reserved.
41060SN/A *
51060SN/A * Redistribution and use in source and binary forms, with or without
61060SN/A * modification, are permitted provided that the following conditions are
71060SN/A * met: redistributions of source code must retain the above copyright
81060SN/A * notice, this list of conditions and the following disclaimer;
91060SN/A * redistributions in binary form must reproduce the above copyright
101060SN/A * notice, this list of conditions and the following disclaimer in the
111060SN/A * documentation and/or other materials provided with the distribution;
121060SN/A * neither the name of the copyright holders nor the names of its
131060SN/A * contributors may be used to endorse or promote products derived from
141060SN/A * this software without specific prior written permission.
151060SN/A *
161060SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
171060SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
181060SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
191060SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
201060SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
211060SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
221060SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231060SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241060SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251060SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
261060SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Kevin Lim
291060SN/A */
301060SN/A
311464SN/A#ifndef __CPU_BASE_DYN_INST_HH__
321464SN/A#define __CPU_BASE_DYN_INST_HH__
331060SN/A
342731Sktlim@umich.edu#include <bitset>
352292SN/A#include <list>
361464SN/A#include <string>
371060SN/A
382669Sktlim@umich.edu#include "arch/faults.hh"
391060SN/A#include "base/fast_alloc.hh"
401060SN/A#include "base/trace.hh"
411858SN/A#include "config/full_system.hh"
421464SN/A#include "cpu/exetrace.hh"
431464SN/A#include "cpu/inst_seq.hh"
442669Sktlim@umich.edu#include "cpu/op_class.hh"
451060SN/A#include "cpu/static_inst.hh"
462669Sktlim@umich.edu#include "mem/packet.hh"
472292SN/A#include "sim/system.hh"
481060SN/A
491060SN/A/**
501060SN/A * @file
511060SN/A * Defines a dynamic instruction context.
521060SN/A */
531060SN/A
541061SN/A// Forward declaration.
551061SN/Aclass StaticInstPtr;
561060SN/A
571060SN/Atemplate <class Impl>
581061SN/Aclass BaseDynInst : public FastAlloc, public RefCounted
591060SN/A{
601060SN/A  public:
611060SN/A    // Typedef for the CPU.
622733Sktlim@umich.edu    typedef typename Impl::CPUType ImplCPU;
632733Sktlim@umich.edu    typedef typename ImplCPU::ImplState ImplState;
641060SN/A
652292SN/A    // Binary machine instruction type.
662107SN/A    typedef TheISA::MachInst MachInst;
672292SN/A    // Extended machine instruction type
682292SN/A    typedef TheISA::ExtMachInst ExtMachInst;
692292SN/A    // Logical register index type.
702107SN/A    typedef TheISA::RegIndex RegIndex;
712690Sktlim@umich.edu    // Integer register type.
722107SN/A    typedef TheISA::IntReg IntReg;
732690Sktlim@umich.edu    // Floating point register type.
742690Sktlim@umich.edu    typedef TheISA::FloatReg FloatReg;
751060SN/A
762292SN/A    // The DynInstPtr type.
772292SN/A    typedef typename Impl::DynInstPtr DynInstPtr;
782292SN/A
792292SN/A    // The list of instructions iterator type.
802292SN/A    typedef typename std::list<DynInstPtr>::iterator ListIt;
812292SN/A
821060SN/A    enum {
832292SN/A        MaxInstSrcRegs = TheISA::MaxInstSrcRegs,	/// Max source regs
842292SN/A        MaxInstDestRegs = TheISA::MaxInstDestRegs,	/// Max dest regs
851060SN/A    };
861060SN/A
872292SN/A    /** The StaticInst used by this BaseDynInst. */
882107SN/A    StaticInstPtr staticInst;
891060SN/A
901060SN/A    ////////////////////////////////////////////
911060SN/A    //
921060SN/A    // INSTRUCTION EXECUTION
931060SN/A    //
941060SN/A    ////////////////////////////////////////////
952292SN/A    /** InstRecord that tracks this instructions. */
961060SN/A    Trace::InstRecord *traceData;
971060SN/A
982292SN/A    /**
992292SN/A     * Does a read to a given address.
1002292SN/A     * @param addr The address to read.
1012292SN/A     * @param data The read's data is written into this parameter.
1022292SN/A     * @param flags The request's flags.
1032292SN/A     * @return Returns any fault due to the read.
1042292SN/A     */
1051060SN/A    template <class T>
1062132SN/A    Fault read(Addr addr, T &data, unsigned flags);
1071060SN/A
1082292SN/A    /**
1092292SN/A     * Does a write to a given address.
1102292SN/A     * @param data The data to be written.
1112292SN/A     * @param addr The address to write to.
1122292SN/A     * @param flags The request's flags.
1132292SN/A     * @param res The result of the write (for load locked/store conditionals).
1142292SN/A     * @return Returns any fault due to the write.
1152292SN/A     */
1161060SN/A    template <class T>
1172132SN/A    Fault write(T data, Addr addr, unsigned flags,
1181060SN/A                        uint64_t *res);
1191060SN/A
1201060SN/A    void prefetch(Addr addr, unsigned flags);
1211060SN/A    void writeHint(Addr addr, int size, unsigned flags);
1222132SN/A    Fault copySrcTranslate(Addr src);
1232132SN/A    Fault copy(Addr dest);
1241060SN/A
1251684SN/A    /** @todo: Consider making this private. */
1261060SN/A  public:
1271060SN/A    /** The sequence number of the instruction. */
1281060SN/A    InstSeqNum seqNum;
1291060SN/A
1302731Sktlim@umich.edu    enum Status {
1312731Sktlim@umich.edu        IqEntry,                 /// Instruction is in the IQ
1322731Sktlim@umich.edu        RobEntry,                /// Instruction is in the ROB
1332731Sktlim@umich.edu        LsqEntry,                /// Instruction is in the LSQ
1342731Sktlim@umich.edu        Completed,               /// Instruction has completed
1352731Sktlim@umich.edu        ResultReady,             /// Instruction has its result
1362731Sktlim@umich.edu        CanIssue,                /// Instruction can issue and execute
1372731Sktlim@umich.edu        Issued,                  /// Instruction has issued
1382731Sktlim@umich.edu        Executed,                /// Instruction has executed
1392731Sktlim@umich.edu        CanCommit,               /// Instruction can commit
1402731Sktlim@umich.edu        AtCommit,                /// Instruction has reached commit
1412731Sktlim@umich.edu        Committed,               /// Instruction has committed
1422731Sktlim@umich.edu        Squashed,                /// Instruction is squashed
1432731Sktlim@umich.edu        SquashedInIQ,            /// Instruction is squashed in the IQ
1442731Sktlim@umich.edu        SquashedInLSQ,           /// Instruction is squashed in the LSQ
1452731Sktlim@umich.edu        SquashedInROB,           /// Instruction is squashed in the ROB
1462731Sktlim@umich.edu        RecoverInst,             /// Is a recover instruction
1472731Sktlim@umich.edu        BlockingInst,            /// Is a blocking instruction
1482731Sktlim@umich.edu        ThreadsyncWait,          /// Is a thread synchronization instruction
1492731Sktlim@umich.edu        SerializeBefore,         /// Needs to serialize on
1502731Sktlim@umich.edu                                 /// instructions ahead of it
1512731Sktlim@umich.edu        SerializeAfter,          /// Needs to serialize instructions behind it
1522731Sktlim@umich.edu        SerializeHandled,        /// Serialization has been handled
1532731Sktlim@umich.edu        NumStatus
1542731Sktlim@umich.edu    };
1552292SN/A
1562731Sktlim@umich.edu    /** The status of this BaseDynInst.  Several bits can be set. */
1572731Sktlim@umich.edu    std::bitset<NumStatus> status;
1581060SN/A
1591060SN/A    /** The thread this instruction is from. */
1601060SN/A    short threadNumber;
1611060SN/A
1621060SN/A    /** data address space ID, for loads & stores. */
1631060SN/A    short asid;
1641060SN/A
1652292SN/A    /** How many source registers are ready. */
1662292SN/A    unsigned readyRegs;
1672292SN/A
1682733Sktlim@umich.edu    /** Pointer to the Impl's CPU object. */
1692733Sktlim@umich.edu    ImplCPU *cpu;
1701060SN/A
1712680Sktlim@umich.edu    /** Pointer to the thread state. */
1722292SN/A    ImplState *thread;
1731060SN/A
1741060SN/A    /** The kind of fault this instruction has generated. */
1752132SN/A    Fault fault;
1761060SN/A
1772292SN/A    /** The memory request. */
1782669Sktlim@umich.edu    Request *req;
1792669Sktlim@umich.edu
1802702Sktlim@umich.edu    /** Pointer to the data for the memory access. */
1812669Sktlim@umich.edu    uint8_t *memData;
1822292SN/A
1831060SN/A    /** The effective virtual address (lds & stores only). */
1841060SN/A    Addr effAddr;
1851060SN/A
1861060SN/A    /** The effective physical address. */
1871060SN/A    Addr physEffAddr;
1881060SN/A
1891060SN/A    /** Effective virtual address for a copy source. */
1901060SN/A    Addr copySrcEffAddr;
1911060SN/A
1921060SN/A    /** Effective physical address for a copy source. */
1931060SN/A    Addr copySrcPhysEffAddr;
1941060SN/A
1951060SN/A    /** The memory request flags (from translation). */
1961060SN/A    unsigned memReqFlags;
1971060SN/A
1981464SN/A    union Result {
1991464SN/A        uint64_t integer;
2001464SN/A        float fp;
2011464SN/A        double dbl;
2021464SN/A    };
2031060SN/A
2041464SN/A    /** The result of the instruction; assumes for now that there's only one
2051464SN/A     *  destination register.
2061464SN/A     */
2071464SN/A    Result instResult;
2081060SN/A
2091060SN/A    /** PC of this instruction. */
2101060SN/A    Addr PC;
2111060SN/A
2121060SN/A    /** Next non-speculative PC.  It is not filled in at fetch, but rather
2131060SN/A     *  once the target of the branch is truly known (either decode or
2141060SN/A     *  execute).
2151060SN/A     */
2161060SN/A    Addr nextPC;
2171060SN/A
2181060SN/A    /** Predicted next PC. */
2191060SN/A    Addr predPC;
2201060SN/A
2211060SN/A    /** Count of total number of dynamic instructions. */
2221060SN/A    static int instcount;
2231060SN/A
2242292SN/A#ifdef DEBUG
2252292SN/A    void dumpSNList();
2262292SN/A#endif
2272292SN/A
2282292SN/A    /** Whether or not the source register is ready.
2292292SN/A     *  @todo: Not sure this should be here vs the derived class.
2301060SN/A     */
2311060SN/A    bool _readySrcRegIdx[MaxInstSrcRegs];
2321060SN/A
2331060SN/A  public:
2342292SN/A    /** BaseDynInst constructor given a binary instruction.
2352292SN/A     *  @param inst The binary instruction.
2362292SN/A     *  @param PC The PC of the instruction.
2372292SN/A     *  @param pred_PC The predicted next PC.
2382292SN/A     *  @param seq_num The sequence number of the instruction.
2392292SN/A     *  @param cpu Pointer to the instruction's CPU.
2402292SN/A     */
2412292SN/A    BaseDynInst(ExtMachInst inst, Addr PC, Addr pred_PC, InstSeqNum seq_num,
2422733Sktlim@umich.edu                ImplCPU *cpu);
2431060SN/A
2442292SN/A    /** BaseDynInst constructor given a StaticInst pointer.
2452292SN/A     *  @param _staticInst The StaticInst for this BaseDynInst.
2462292SN/A     */
2472107SN/A    BaseDynInst(StaticInstPtr &_staticInst);
2481060SN/A
2491060SN/A    /** BaseDynInst destructor. */
2501060SN/A    ~BaseDynInst();
2511060SN/A
2521464SN/A  private:
2531684SN/A    /** Function to initialize variables in the constructors. */
2541464SN/A    void initVars();
2551060SN/A
2561464SN/A  public:
2571060SN/A    /** Dumps out contents of this BaseDynInst. */
2581060SN/A    void dump();
2591060SN/A
2601060SN/A    /** Dumps out contents of this BaseDynInst into given string. */
2611060SN/A    void dump(std::string &outstring);
2621060SN/A
2631060SN/A    /** Returns the fault type. */
2642132SN/A    Fault getFault() { return fault; }
2651060SN/A
2661060SN/A    /** Checks whether or not this instruction has had its branch target
2671060SN/A     *  calculated yet.  For now it is not utilized and is hacked to be
2681060SN/A     *  always false.
2692292SN/A     *  @todo: Actually use this instruction.
2701060SN/A     */
2711060SN/A    bool doneTargCalc() { return false; }
2721060SN/A
2731684SN/A    /** Returns the next PC.  This could be the speculative next PC if it is
2741684SN/A     *  called prior to the actual branch target being calculated.
2751684SN/A     */
2761060SN/A    Addr readNextPC() { return nextPC; }
2771060SN/A
2781060SN/A    /** Set the predicted target of this current instruction. */
2791060SN/A    void setPredTarg(Addr predicted_PC) { predPC = predicted_PC; }
2801060SN/A
2811060SN/A    /** Returns the predicted target of the branch. */
2821060SN/A    Addr readPredTarg() { return predPC; }
2831060SN/A
2841060SN/A    /** Returns whether the instruction was predicted taken or not. */
2852292SN/A    bool predTaken() { return predPC != (PC + sizeof(MachInst)); }
2861060SN/A
2871060SN/A    /** Returns whether the instruction mispredicted. */
2882292SN/A    bool mispredicted() { return predPC != nextPC; }
2891060SN/A
2901060SN/A    //
2911060SN/A    //  Instruction types.  Forward checks to StaticInst object.
2921060SN/A    //
2931060SN/A    bool isNop()	  const { return staticInst->isNop(); }
2941060SN/A    bool isMemRef()    	  const { return staticInst->isMemRef(); }
2951060SN/A    bool isLoad()	  const { return staticInst->isLoad(); }
2961060SN/A    bool isStore()	  const { return staticInst->isStore(); }
2972336SN/A    bool isStoreConditional() const
2982336SN/A    { return staticInst->isStoreConditional(); }
2991060SN/A    bool isInstPrefetch() const { return staticInst->isInstPrefetch(); }
3001060SN/A    bool isDataPrefetch() const { return staticInst->isDataPrefetch(); }
3011060SN/A    bool isCopy()         const { return staticInst->isCopy(); }
3021060SN/A    bool isInteger()	  const { return staticInst->isInteger(); }
3031060SN/A    bool isFloating()	  const { return staticInst->isFloating(); }
3041060SN/A    bool isControl()	  const { return staticInst->isControl(); }
3051060SN/A    bool isCall()	  const { return staticInst->isCall(); }
3061060SN/A    bool isReturn()	  const { return staticInst->isReturn(); }
3071060SN/A    bool isDirectCtrl()	  const { return staticInst->isDirectCtrl(); }
3081060SN/A    bool isIndirectCtrl() const { return staticInst->isIndirectCtrl(); }
3091060SN/A    bool isCondCtrl()	  const { return staticInst->isCondCtrl(); }
3101060SN/A    bool isUncondCtrl()	  const { return staticInst->isUncondCtrl(); }
3111060SN/A    bool isThreadSync()   const { return staticInst->isThreadSync(); }
3121060SN/A    bool isSerializing()  const { return staticInst->isSerializing(); }
3132292SN/A    bool isSerializeBefore() const
3142731Sktlim@umich.edu    { return staticInst->isSerializeBefore() || status[SerializeBefore]; }
3152292SN/A    bool isSerializeAfter() const
3162731Sktlim@umich.edu    { return staticInst->isSerializeAfter() || status[SerializeAfter]; }
3171060SN/A    bool isMemBarrier()   const { return staticInst->isMemBarrier(); }
3181060SN/A    bool isWriteBarrier() const { return staticInst->isWriteBarrier(); }
3191060SN/A    bool isNonSpeculative() const { return staticInst->isNonSpeculative(); }
3202292SN/A    bool isQuiesce() const { return staticInst->isQuiesce(); }
3212336SN/A    bool isIprAccess() const { return staticInst->isIprAccess(); }
3222308SN/A    bool isUnverifiable() const { return staticInst->isUnverifiable(); }
3232292SN/A
3242292SN/A    /** Temporarily sets this instruction as a serialize before instruction. */
3252731Sktlim@umich.edu    void setSerializeBefore() { status.set(SerializeBefore); }
3262292SN/A
3272292SN/A    /** Clears the serializeBefore part of this instruction. */
3282731Sktlim@umich.edu    void clearSerializeBefore() { status.reset(SerializeBefore); }
3292292SN/A
3302292SN/A    /** Checks if this serializeBefore is only temporarily set. */
3312731Sktlim@umich.edu    bool isTempSerializeBefore() { return status[SerializeBefore]; }
3322292SN/A
3332292SN/A    /** Temporarily sets this instruction as a serialize after instruction. */
3342731Sktlim@umich.edu    void setSerializeAfter() { status.set(SerializeAfter); }
3352292SN/A
3362292SN/A    /** Clears the serializeAfter part of this instruction.*/
3372731Sktlim@umich.edu    void clearSerializeAfter() { status.reset(SerializeAfter); }
3382292SN/A
3392292SN/A    /** Checks if this serializeAfter is only temporarily set. */
3402731Sktlim@umich.edu    bool isTempSerializeAfter() { return status[SerializeAfter]; }
3412292SN/A
3422731Sktlim@umich.edu    /** Sets the serialization part of this instruction as handled. */
3432731Sktlim@umich.edu    void setSerializeHandled() { status.set(SerializeHandled); }
3442292SN/A
3452292SN/A    /** Checks if the serialization part of this instruction has been
3462292SN/A     *  handled.  This does not apply to the temporary serializing
3472292SN/A     *  state; it only applies to this instruction's own permanent
3482292SN/A     *  serializing state.
3492292SN/A     */
3502731Sktlim@umich.edu    bool isSerializeHandled() { return status[SerializeHandled]; }
3511060SN/A
3521464SN/A    /** Returns the opclass of this instruction. */
3531464SN/A    OpClass opClass() const { return staticInst->opClass(); }
3541464SN/A
3551464SN/A    /** Returns the branch target address. */
3561464SN/A    Addr branchTarget() const { return staticInst->branchTarget(PC); }
3571464SN/A
3582292SN/A    /** Returns the number of source registers. */
3592292SN/A    int8_t numSrcRegs()	const { return staticInst->numSrcRegs(); }
3601684SN/A
3612292SN/A    /** Returns the number of destination registers. */
3621060SN/A    int8_t numDestRegs() const { return staticInst->numDestRegs(); }
3631060SN/A
3641060SN/A    // the following are used to track physical register usage
3651060SN/A    // for machines with separate int & FP reg files
3661060SN/A    int8_t numFPDestRegs()  const { return staticInst->numFPDestRegs(); }
3671060SN/A    int8_t numIntDestRegs() const { return staticInst->numIntDestRegs(); }
3681060SN/A
3691060SN/A    /** Returns the logical register index of the i'th destination register. */
3702292SN/A    RegIndex destRegIdx(int i) const { return staticInst->destRegIdx(i); }
3711060SN/A
3721060SN/A    /** Returns the logical register index of the i'th source register. */
3732292SN/A    RegIndex srcRegIdx(int i) const { return staticInst->srcRegIdx(i); }
3741060SN/A
3751684SN/A    /** Returns the result of an integer instruction. */
3761464SN/A    uint64_t readIntResult() { return instResult.integer; }
3771684SN/A
3781684SN/A    /** Returns the result of a floating point instruction. */
3791464SN/A    float readFloatResult() { return instResult.fp; }
3801684SN/A
3811684SN/A    /** Returns the result of a floating point (double) instruction. */
3821464SN/A    double readDoubleResult() { return instResult.dbl; }
3831060SN/A
3842702Sktlim@umich.edu    /** Records an integer register being set to a value. */
3852308SN/A    void setIntReg(const StaticInst *si, int idx, uint64_t val)
3861060SN/A    {
3872308SN/A        instResult.integer = val;
3881060SN/A    }
3891060SN/A
3902702Sktlim@umich.edu    /** Records an fp register being set to a value. */
3912690Sktlim@umich.edu    void setFloatReg(const StaticInst *si, int idx, FloatReg val, int width)
3922690Sktlim@umich.edu    {
3932690Sktlim@umich.edu        if (width == 32)
3942690Sktlim@umich.edu            instResult.fp = val;
3952690Sktlim@umich.edu        else if (width == 64)
3962690Sktlim@umich.edu            instResult.dbl = val;
3972690Sktlim@umich.edu        else
3982690Sktlim@umich.edu            panic("Unsupported width!");
3992690Sktlim@umich.edu    }
4002690Sktlim@umich.edu
4012702Sktlim@umich.edu    /** Records an fp register being set to a value. */
4022690Sktlim@umich.edu    void setFloatReg(const StaticInst *si, int idx, FloatReg val)
4031060SN/A    {
4042308SN/A        instResult.fp = val;
4052308SN/A    }
4061060SN/A
4072702Sktlim@umich.edu    /** Records an fp register being set to an integer value. */
4082690Sktlim@umich.edu    void setFloatRegBits(const StaticInst *si, int idx, uint64_t val, int width)
4092308SN/A    {
4102690Sktlim@umich.edu        instResult.integer = val;
4112308SN/A    }
4121060SN/A
4132702Sktlim@umich.edu    /** Records an fp register being set to an integer value. */
4142690Sktlim@umich.edu    void setFloatRegBits(const StaticInst *si, int idx, uint64_t val)
4152308SN/A    {
4162308SN/A        instResult.integer = val;
4171060SN/A    }
4181060SN/A
4192190SN/A    /** Records that one of the source registers is ready. */
4202292SN/A    void markSrcRegReady();
4212190SN/A
4222331SN/A    /** Marks a specific register as ready. */
4232292SN/A    void markSrcRegReady(RegIndex src_idx);
4242190SN/A
4251684SN/A    /** Returns if a source register is ready. */
4261464SN/A    bool isReadySrcRegIdx(int idx) const
4271464SN/A    {
4281464SN/A        return this->_readySrcRegIdx[idx];
4291464SN/A    }
4301464SN/A
4311684SN/A    /** Sets this instruction as completed. */
4322731Sktlim@umich.edu    void setCompleted() { status.set(Completed); }
4331464SN/A
4342292SN/A    /** Returns whether or not this instruction is completed. */
4352731Sktlim@umich.edu    bool isCompleted() const { return status[Completed]; }
4361464SN/A
4372731Sktlim@umich.edu    /** Marks the result as ready. */
4382731Sktlim@umich.edu    void setResultReady() { status.set(ResultReady); }
4392308SN/A
4402731Sktlim@umich.edu    /** Returns whether or not the result is ready. */
4412731Sktlim@umich.edu    bool isResultReady() const { return status[ResultReady]; }
4422308SN/A
4431060SN/A    /** Sets this instruction as ready to issue. */
4442731Sktlim@umich.edu    void setCanIssue() { status.set(CanIssue); }
4451060SN/A
4461060SN/A    /** Returns whether or not this instruction is ready to issue. */
4472731Sktlim@umich.edu    bool readyToIssue() const { return status[CanIssue]; }
4481060SN/A
4491060SN/A    /** Sets this instruction as issued from the IQ. */
4502731Sktlim@umich.edu    void setIssued() { status.set(Issued); }
4511060SN/A
4521060SN/A    /** Returns whether or not this instruction has issued. */
4532731Sktlim@umich.edu    bool isIssued() const { return status[Issued]; }
4541060SN/A
4551060SN/A    /** Sets this instruction as executed. */
4562731Sktlim@umich.edu    void setExecuted() { status.set(Executed); }
4571060SN/A
4581060SN/A    /** Returns whether or not this instruction has executed. */
4592731Sktlim@umich.edu    bool isExecuted() const { return status[Executed]; }
4601060SN/A
4611060SN/A    /** Sets this instruction as ready to commit. */
4622731Sktlim@umich.edu    void setCanCommit() { status.set(CanCommit); }
4631060SN/A
4641061SN/A    /** Clears this instruction as being ready to commit. */
4652731Sktlim@umich.edu    void clearCanCommit() { status.reset(CanCommit); }
4661061SN/A
4671060SN/A    /** Returns whether or not this instruction is ready to commit. */
4682731Sktlim@umich.edu    bool readyToCommit() const { return status[CanCommit]; }
4692731Sktlim@umich.edu
4702731Sktlim@umich.edu    void setAtCommit() { status.set(AtCommit); }
4712731Sktlim@umich.edu
4722731Sktlim@umich.edu    bool isAtCommit() { return status[AtCommit]; }
4731060SN/A
4742292SN/A    /** Sets this instruction as committed. */
4752731Sktlim@umich.edu    void setCommitted() { status.set(Committed); }
4762292SN/A
4772292SN/A    /** Returns whether or not this instruction is committed. */
4782731Sktlim@umich.edu    bool isCommitted() const { return status[Committed]; }
4792292SN/A
4801060SN/A    /** Sets this instruction as squashed. */
4812731Sktlim@umich.edu    void setSquashed() { status.set(Squashed); }
4821060SN/A
4831060SN/A    /** Returns whether or not this instruction is squashed. */
4842731Sktlim@umich.edu    bool isSquashed() const { return status[Squashed]; }
4851060SN/A
4862292SN/A    //Instruction Queue Entry
4872292SN/A    //-----------------------
4882292SN/A    /** Sets this instruction as a entry the IQ. */
4892731Sktlim@umich.edu    void setInIQ() { status.set(IqEntry); }
4902292SN/A
4912292SN/A    /** Sets this instruction as a entry the IQ. */
4922731Sktlim@umich.edu    void clearInIQ() { status.reset(IqEntry); }
4932731Sktlim@umich.edu
4942731Sktlim@umich.edu    /** Returns whether or not this instruction has issued. */
4952731Sktlim@umich.edu    bool isInIQ() const { return status[IqEntry]; }
4962292SN/A
4971060SN/A    /** Sets this instruction as squashed in the IQ. */
4982731Sktlim@umich.edu    void setSquashedInIQ() { status.set(SquashedInIQ); status.set(Squashed);}
4991060SN/A
5001060SN/A    /** Returns whether or not this instruction is squashed in the IQ. */
5012731Sktlim@umich.edu    bool isSquashedInIQ() const { return status[SquashedInIQ]; }
5022292SN/A
5032292SN/A
5042292SN/A    //Load / Store Queue Functions
5052292SN/A    //-----------------------
5062292SN/A    /** Sets this instruction as a entry the LSQ. */
5072731Sktlim@umich.edu    void setInLSQ() { status.set(LsqEntry); }
5082292SN/A
5092292SN/A    /** Sets this instruction as a entry the LSQ. */
5102731Sktlim@umich.edu    void removeInLSQ() { status.reset(LsqEntry); }
5112731Sktlim@umich.edu
5122731Sktlim@umich.edu    /** Returns whether or not this instruction is in the LSQ. */
5132731Sktlim@umich.edu    bool isInLSQ() const { return status[LsqEntry]; }
5142292SN/A
5152292SN/A    /** Sets this instruction as squashed in the LSQ. */
5162731Sktlim@umich.edu    void setSquashedInLSQ() { status.set(SquashedInLSQ);}
5172292SN/A
5182292SN/A    /** Returns whether or not this instruction is squashed in the LSQ. */
5192731Sktlim@umich.edu    bool isSquashedInLSQ() const { return status[SquashedInLSQ]; }
5202292SN/A
5212292SN/A
5222292SN/A    //Reorder Buffer Functions
5232292SN/A    //-----------------------
5242292SN/A    /** Sets this instruction as a entry the ROB. */
5252731Sktlim@umich.edu    void setInROB() { status.set(RobEntry); }
5262292SN/A
5272292SN/A    /** Sets this instruction as a entry the ROB. */
5282731Sktlim@umich.edu    void clearInROB() { status.reset(RobEntry); }
5292731Sktlim@umich.edu
5302731Sktlim@umich.edu    /** Returns whether or not this instruction is in the ROB. */
5312731Sktlim@umich.edu    bool isInROB() const { return status[RobEntry]; }
5322292SN/A
5332292SN/A    /** Sets this instruction as squashed in the ROB. */
5342731Sktlim@umich.edu    void setSquashedInROB() { status.set(SquashedInROB); }
5352292SN/A
5362292SN/A    /** Returns whether or not this instruction is squashed in the ROB. */
5372731Sktlim@umich.edu    bool isSquashedInROB() const { return status[SquashedInROB]; }
5382292SN/A
5391060SN/A    /** Read the PC of this instruction. */
5401464SN/A    const Addr readPC() const { return PC; }
5411060SN/A
5421060SN/A    /** Set the next PC of this instruction (its actual target). */
5432308SN/A    void setNextPC(uint64_t val)
5442308SN/A    {
5452308SN/A        nextPC = val;
5462308SN/A    }
5472190SN/A
5482702Sktlim@umich.edu    /** Sets the ASID. */
5492292SN/A    void setASID(short addr_space_id) { asid = addr_space_id; }
5502292SN/A
5512702Sktlim@umich.edu    /** Sets the thread id. */
5522702Sktlim@umich.edu    void setTid(unsigned tid) { threadNumber = tid; }
5532292SN/A
5542731Sktlim@umich.edu    /** Sets the pointer to the thread state. */
5552702Sktlim@umich.edu    void setThreadState(ImplState *state) { thread = state; }
5561060SN/A
5572731Sktlim@umich.edu    /** Returns the thread context. */
5582680Sktlim@umich.edu    ThreadContext *tcBase() { return thread->getTC(); }
5591464SN/A
5601464SN/A  private:
5611684SN/A    /** Instruction effective address.
5621684SN/A     *  @todo: Consider if this is necessary or not.
5631684SN/A     */
5641464SN/A    Addr instEffAddr;
5652292SN/A
5661684SN/A    /** Whether or not the effective address calculation is completed.
5671684SN/A     *  @todo: Consider if this is necessary or not.
5681684SN/A     */
5691464SN/A    bool eaCalcDone;
5701464SN/A
5711464SN/A  public:
5721684SN/A    /** Sets the effective address. */
5731464SN/A    void setEA(Addr &ea) { instEffAddr = ea; eaCalcDone = true; }
5741684SN/A
5751684SN/A    /** Returns the effective address. */
5761464SN/A    const Addr &getEA() const { return instEffAddr; }
5771684SN/A
5781684SN/A    /** Returns whether or not the eff. addr. calculation has been completed. */
5791464SN/A    bool doneEACalc() { return eaCalcDone; }
5801684SN/A
5811684SN/A    /** Returns whether or not the eff. addr. source registers are ready. */
5821464SN/A    bool eaSrcsReady();
5831681SN/A
5842292SN/A    /** Whether or not the memory operation is done. */
5852292SN/A    bool memOpDone;
5862292SN/A
5871681SN/A  public:
5881684SN/A    /** Load queue index. */
5891681SN/A    int16_t lqIdx;
5901684SN/A
5911684SN/A    /** Store queue index. */
5921681SN/A    int16_t sqIdx;
5932292SN/A
5942292SN/A    /** Iterator pointing to this BaseDynInst in the list of all insts. */
5952292SN/A    ListIt instListIt;
5962292SN/A
5972292SN/A    /** Returns iterator to this instruction in the list of all insts. */
5982292SN/A    ListIt &getInstListIt() { return instListIt; }
5992292SN/A
6002292SN/A    /** Sets iterator for this instruction in the list of all insts. */
6012292SN/A    void setInstListIt(ListIt _instListIt) { instListIt = _instListIt; }
6021060SN/A};
6031060SN/A
6041060SN/Atemplate<class Impl>
6051060SN/Atemplate<class T>
6062132SN/Ainline Fault
6071060SN/ABaseDynInst<Impl>::read(Addr addr, T &data, unsigned flags)
6081060SN/A{
6092695Sktlim@umich.edu    // Sometimes reads will get retried, so they may come through here
6102695Sktlim@umich.edu    // twice.
6112695Sktlim@umich.edu    if (!req) {
6122695Sktlim@umich.edu        req = new Request();
6132695Sktlim@umich.edu        req->setVirt(asid, addr, sizeof(T), flags, this->PC);
6142695Sktlim@umich.edu        req->setThreadContext(thread->readCpuId(), threadNumber);
6152695Sktlim@umich.edu    } else {
6162695Sktlim@umich.edu        assert(addr == req->getVaddr());
6172292SN/A    }
6182292SN/A
6192669Sktlim@umich.edu    if ((req->getVaddr() & (TheISA::VMPageSize - 1)) + req->getSize() >
6202292SN/A        TheISA::VMPageSize) {
6212292SN/A        return TheISA::genAlignmentFault();
6222292SN/A    }
6231060SN/A
6242690Sktlim@umich.edu    fault = cpu->translateDataReadReq(req, thread);
6251060SN/A
6262678Sktlim@umich.edu    if (fault == NoFault) {
6272678Sktlim@umich.edu        effAddr = req->getVaddr();
6282678Sktlim@umich.edu        physEffAddr = req->getPaddr();
6292678Sktlim@umich.edu        memReqFlags = req->getFlags();
6301060SN/A
6312690Sktlim@umich.edu#if 0
6322292SN/A        if (cpu->system->memctrl->badaddr(physEffAddr)) {
6332292SN/A            fault = TheISA::genMachineCheckFault();
6342292SN/A            data = (T)-1;
6352292SN/A            this->setExecuted();
6362292SN/A        } else {
6372292SN/A            fault = cpu->read(req, data, lqIdx);
6382292SN/A        }
6392292SN/A#else
6401681SN/A        fault = cpu->read(req, data, lqIdx);
6412632Sstever@eecs.umich.edu#endif
6421684SN/A    } else {
6431060SN/A        // Return a fixed value to keep simulation deterministic even
6441060SN/A        // along misspeculated paths.
6451060SN/A        data = (T)-1;
6462292SN/A
6472292SN/A        // Commit will have to clean up whatever happened.  Set this
6482292SN/A        // instruction as executed.
6492292SN/A        this->setExecuted();
6501060SN/A    }
6511060SN/A
6521060SN/A    if (traceData) {
6531060SN/A        traceData->setAddr(addr);
6541060SN/A        traceData->setData(data);
6551060SN/A    }
6561060SN/A
6571060SN/A    return fault;
6581060SN/A}
6591060SN/A
6601060SN/Atemplate<class Impl>
6611060SN/Atemplate<class T>
6622132SN/Ainline Fault
6631060SN/ABaseDynInst<Impl>::write(T data, Addr addr, unsigned flags, uint64_t *res)
6641060SN/A{
6651060SN/A    if (traceData) {
6661060SN/A        traceData->setAddr(addr);
6671060SN/A        traceData->setData(data);
6681060SN/A    }
6691060SN/A
6702695Sktlim@umich.edu    assert(req == NULL);
6712695Sktlim@umich.edu
6722669Sktlim@umich.edu    req = new Request();
6732669Sktlim@umich.edu    req->setVirt(asid, addr, sizeof(T), flags, this->PC);
6742683Sktlim@umich.edu    req->setThreadContext(thread->readCpuId(), threadNumber);
6751060SN/A
6762669Sktlim@umich.edu    if ((req->getVaddr() & (TheISA::VMPageSize - 1)) + req->getSize() >
6772292SN/A        TheISA::VMPageSize) {
6782292SN/A        return TheISA::genAlignmentFault();
6792292SN/A    }
6801060SN/A
6812690Sktlim@umich.edu    fault = cpu->translateDataWriteReq(req, thread);
6821060SN/A
6832090SN/A    if (fault == NoFault) {
6842678Sktlim@umich.edu        effAddr = req->getVaddr();
6852678Sktlim@umich.edu        physEffAddr = req->getPaddr();
6862678Sktlim@umich.edu        memReqFlags = req->getFlags();
6872690Sktlim@umich.edu#if 0
6882292SN/A        if (cpu->system->memctrl->badaddr(physEffAddr)) {
6892292SN/A            fault = TheISA::genMachineCheckFault();
6902292SN/A        } else {
6912292SN/A            fault = cpu->write(req, data, sqIdx);
6922292SN/A        }
6932292SN/A#else
6941681SN/A        fault = cpu->write(req, data, sqIdx);
6952632Sstever@eecs.umich.edu#endif
6961060SN/A    }
6971060SN/A
6981060SN/A    if (res) {
6991060SN/A        // always return some result to keep misspeculated paths
7001060SN/A        // (which will ignore faults) deterministic
7012669Sktlim@umich.edu        *res = (fault == NoFault) ? req->getScResult() : 0;
7021060SN/A    }
7031060SN/A
7041060SN/A    return fault;
7051060SN/A}
7061060SN/A
7071464SN/A#endif // __CPU_BASE_DYN_INST_HH__
708