base_dyn_inst.hh revision 2356
12689Sktlim@umich.edu/*
22689Sktlim@umich.edu * Copyright (c) 2004-2005 The Regents of The University of Michigan
32689Sktlim@umich.edu * All rights reserved.
42689Sktlim@umich.edu *
52689Sktlim@umich.edu * Redistribution and use in source and binary forms, with or without
62689Sktlim@umich.edu * modification, are permitted provided that the following conditions are
72689Sktlim@umich.edu * met: redistributions of source code must retain the above copyright
82689Sktlim@umich.edu * notice, this list of conditions and the following disclaimer;
92689Sktlim@umich.edu * redistributions in binary form must reproduce the above copyright
102689Sktlim@umich.edu * notice, this list of conditions and the following disclaimer in the
112689Sktlim@umich.edu * documentation and/or other materials provided with the distribution;
122689Sktlim@umich.edu * neither the name of the copyright holders nor the names of its
132689Sktlim@umich.edu * contributors may be used to endorse or promote products derived from
142689Sktlim@umich.edu * this software without specific prior written permission.
152689Sktlim@umich.edu *
162689Sktlim@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172689Sktlim@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182689Sktlim@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192689Sktlim@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202689Sktlim@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212689Sktlim@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222689Sktlim@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232689Sktlim@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242689Sktlim@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252689Sktlim@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262689Sktlim@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272689Sktlim@umich.edu */
282689Sktlim@umich.edu
292689Sktlim@umich.edu#ifndef __CPU_BASE_DYN_INST_HH__
302689Sktlim@umich.edu#define __CPU_BASE_DYN_INST_HH__
312683Sktlim@umich.edu
323402Sktlim@umich.edu#include <list>
332683Sktlim@umich.edu#include <string>
342683Sktlim@umich.edu
353402Sktlim@umich.edu#include "base/fast_alloc.hh"
363402Sktlim@umich.edu#include "base/trace.hh"
372862Sktlim@umich.edu#include "config/full_system.hh"
382862Sktlim@umich.edu#include "cpu/exetrace.hh"
392862Sktlim@umich.edu#include "cpu/inst_seq.hh"
403565Sgblack@eecs.umich.edu#include "cpu/static_inst.hh"
412862Sktlim@umich.edu#include "encumbered/cpu/full/op_class.hh"
423675Sktlim@umich.edu#include "mem/functional/memory_control.hh"
432862Sktlim@umich.edu#include "sim/system.hh"
442683Sktlim@umich.edu/*
452683Sktlim@umich.edu#include "encumbered/cpu/full/bpred_update.hh"
463402Sktlim@umich.edu#include "encumbered/cpu/full/spec_memory.hh"
473402Sktlim@umich.edu#include "encumbered/cpu/full/spec_state.hh"
482683Sktlim@umich.edu#include "encumbered/mem/functional/main.hh"
493402Sktlim@umich.edu*/
503280Sgblack@eecs.umich.edu
512683Sktlim@umich.edu/**
523402Sktlim@umich.edu * @file
533402Sktlim@umich.edu * Defines a dynamic instruction context.
543402Sktlim@umich.edu */
553402Sktlim@umich.edu
563280Sgblack@eecs.umich.edu// Forward declaration.
572683Sktlim@umich.educlass StaticInstPtr;
582683Sktlim@umich.edu
592699Sktlim@umich.edutemplate <class Impl>
602699Sktlim@umich.educlass BaseDynInst : public FastAlloc, public RefCounted
612683Sktlim@umich.edu{
622683Sktlim@umich.edu  public:
633486Sktlim@umich.edu    // Typedef for the CPU.
643486Sktlim@umich.edu    typedef typename Impl::FullCPU FullCPU;
653486Sktlim@umich.edu    typedef typename FullCPU::ImplState ImplState;
663486Sktlim@umich.edu
673486Sktlim@umich.edu    // Binary machine instruction type.
683486Sktlim@umich.edu    typedef TheISA::MachInst MachInst;
693486Sktlim@umich.edu    // Extended machine instruction type
703486Sktlim@umich.edu    typedef TheISA::ExtMachInst ExtMachInst;
713486Sktlim@umich.edu    // Logical register index type.
723486Sktlim@umich.edu    typedef TheISA::RegIndex RegIndex;
732862Sktlim@umich.edu    // Integer register index type.
742862Sktlim@umich.edu    typedef TheISA::IntReg IntReg;
752862Sktlim@umich.edu
762862Sktlim@umich.edu    // The DynInstPtr type.
772862Sktlim@umich.edu    typedef typename Impl::DynInstPtr DynInstPtr;
782862Sktlim@umich.edu
792862Sktlim@umich.edu    // The list of instructions iterator type.
803442Sgblack@eecs.umich.edu    typedef typename std::list<DynInstPtr>::iterator ListIt;
813442Sgblack@eecs.umich.edu
822862Sktlim@umich.edu    enum {
832862Sktlim@umich.edu        MaxInstSrcRegs = TheISA::MaxInstSrcRegs,	/// Max source regs
842862Sktlim@umich.edu        MaxInstDestRegs = TheISA::MaxInstDestRegs,	/// Max dest regs
852862Sktlim@umich.edu    };
862862Sktlim@umich.edu
872862Sktlim@umich.edu    /** The StaticInst used by this BaseDynInst. */
882862Sktlim@umich.edu    StaticInstPtr staticInst;
892862Sktlim@umich.edu
902862Sktlim@umich.edu    ////////////////////////////////////////////
912862Sktlim@umich.edu    //
922862Sktlim@umich.edu    // INSTRUCTION EXECUTION
932862Sktlim@umich.edu    //
942862Sktlim@umich.edu    ////////////////////////////////////////////
952862Sktlim@umich.edu    /** InstRecord that tracks this instructions. */
962862Sktlim@umich.edu    Trace::InstRecord *traceData;
972862Sktlim@umich.edu
982862Sktlim@umich.edu    /**
992862Sktlim@umich.edu     * Does a read to a given address.
1002862Sktlim@umich.edu     * @param addr The address to read.
1013442Sgblack@eecs.umich.edu     * @param data The read's data is written into this parameter.
1023442Sgblack@eecs.umich.edu     * @param flags The request's flags.
1032862Sktlim@umich.edu     * @return Returns any fault due to the read.
1042862Sktlim@umich.edu     */
1052862Sktlim@umich.edu    template <class T>
1062862Sktlim@umich.edu    Fault read(Addr addr, T &data, unsigned flags);
1072862Sktlim@umich.edu
1082862Sktlim@umich.edu    /**
1092862Sktlim@umich.edu     * Does a write to a given address.
1102862Sktlim@umich.edu     * @param data The data to be written.
1112862Sktlim@umich.edu     * @param addr The address to write to.
1122862Sktlim@umich.edu     * @param flags The request's flags.
1132862Sktlim@umich.edu     * @param res The result of the write (for load locked/store conditionals).
1142683Sktlim@umich.edu     * @return Returns any fault due to the write.
1153675Sktlim@umich.edu     */
1163686Sktlim@umich.edu    template <class T>
1173675Sktlim@umich.edu    Fault write(T data, Addr addr, unsigned flags,
1183686Sktlim@umich.edu                        uint64_t *res);
1193686Sktlim@umich.edu
1203675Sktlim@umich.edu    void prefetch(Addr addr, unsigned flags);
1213675Sktlim@umich.edu    void writeHint(Addr addr, int size, unsigned flags);
1223675Sktlim@umich.edu    Fault copySrcTranslate(Addr src);
1233686Sktlim@umich.edu    Fault copy(Addr dest);
1243675Sktlim@umich.edu
1253686Sktlim@umich.edu    /** @todo: Consider making this private. */
1263686Sktlim@umich.edu  public:
1273686Sktlim@umich.edu    /** The sequence number of the instruction. */
1284190Ssaidi@eecs.umich.edu    InstSeqNum seqNum;
1294190Ssaidi@eecs.umich.edu
1304190Ssaidi@eecs.umich.edu    enum Status {
1314190Ssaidi@eecs.umich.edu        IqEntry,                 /// Instruction is in the IQ
1323675Sktlim@umich.edu        RobEntry,                /// Instruction is in the ROB
1333675Sktlim@umich.edu        LsqEntry,                /// Instruction is in the LSQ
1343675Sktlim@umich.edu        Completed,               /// Instruction has completed
1353675Sktlim@umich.edu        ResultReady,             /// Instruction has its result
1363675Sktlim@umich.edu        CanIssue,                /// Instruction can issue and execute
1373686Sktlim@umich.edu        Issued,                  /// Instruction has issued
1383675Sktlim@umich.edu        Executed,                /// Instruction has executed
1393686Sktlim@umich.edu        CanCommit,               /// Instruction can commit
1403686Sktlim@umich.edu        AtCommit,                /// Instruction has reached commit
1413686Sktlim@umich.edu        Committed,               /// Instruction has committed
1424190Ssaidi@eecs.umich.edu        Squashed,                /// Instruction is squashed
1434190Ssaidi@eecs.umich.edu        SquashedInIQ,            /// Instruction is squashed in the IQ
1444190Ssaidi@eecs.umich.edu        SquashedInLSQ,           /// Instruction is squashed in the LSQ
1454190Ssaidi@eecs.umich.edu        SquashedInROB,           /// Instruction is squashed in the ROB
1463675Sktlim@umich.edu        RecoverInst,             /// Is a recover instruction
1473675Sktlim@umich.edu        BlockingInst,            /// Is a blocking instruction
1483675Sktlim@umich.edu        ThreadsyncWait,          /// Is a thread synchronization instruction
1492683Sktlim@umich.edu        SerializeBefore,         /// Needs to serialize on
1502683Sktlim@umich.edu                                 /// instructions ahead of it
1512683Sktlim@umich.edu        SerializeAfter,          /// Needs to serialize instructions behind it
1522683Sktlim@umich.edu        SerializeHandled,        /// Serialization has been handled
1532683Sktlim@umich.edu        NumStatus
1542683Sktlim@umich.edu    };
1552683Sktlim@umich.edu
1562683Sktlim@umich.edu    /** The status of this BaseDynInst.  Several bits can be set. */
1572683Sktlim@umich.edu    std::bitset<NumStatus> status;
1582683Sktlim@umich.edu
1592683Sktlim@umich.edu    /** The thread this instruction is from. */
1602683Sktlim@umich.edu    short threadNumber;
1612683Sktlim@umich.edu
1622683Sktlim@umich.edu    /** data address space ID, for loads & stores. */
1632683Sktlim@umich.edu    short asid;
1643402Sktlim@umich.edu
1653402Sktlim@umich.edu    /** How many source registers are ready. */
1663402Sktlim@umich.edu    unsigned readyRegs;
1673402Sktlim@umich.edu
1683402Sktlim@umich.edu    /** Pointer to the FullCPU object. */
1693402Sktlim@umich.edu    FullCPU *cpu;
1703402Sktlim@umich.edu
1713402Sktlim@umich.edu    /** Pointer to the exec context. */
1724434Ssaidi@eecs.umich.edu    ImplState *thread;
1734434Ssaidi@eecs.umich.edu
1743402Sktlim@umich.edu    /** The kind of fault this instruction has generated. */
1753675Sktlim@umich.edu    Fault fault;
1763486Sktlim@umich.edu
1773486Sktlim@umich.edu    /** The memory request. */
1783486Sktlim@umich.edu    MemReqPtr req;
1793486Sktlim@umich.edu
1803486Sktlim@umich.edu    /** The effective virtual address (lds & stores only). */
1813675Sktlim@umich.edu    Addr effAddr;
1823675Sktlim@umich.edu
1833486Sktlim@umich.edu    /** The effective physical address. */
1843486Sktlim@umich.edu    Addr physEffAddr;
1853486Sktlim@umich.edu
1863402Sktlim@umich.edu    /** Effective virtual address for a copy source. */
1873402Sktlim@umich.edu    Addr copySrcEffAddr;
1883402Sktlim@umich.edu
1893402Sktlim@umich.edu    /** Effective physical address for a copy source. */
1903402Sktlim@umich.edu    Addr copySrcPhysEffAddr;
1913402Sktlim@umich.edu
1923402Sktlim@umich.edu    /** The memory request flags (from translation). */
1933402Sktlim@umich.edu    unsigned memReqFlags;
1943402Sktlim@umich.edu
1953675Sktlim@umich.edu    /** The size of the data to be stored. */
1963675Sktlim@umich.edu    int storeSize;
1973402Sktlim@umich.edu
198    /** The data to be stored. */
199    IntReg storeData;
200
201    union Result {
202        uint64_t integer;
203//        float fp;
204        double dbl;
205    };
206
207    /** The result of the instruction; assumes for now that there's only one
208     *  destination register.
209     */
210    Result instResult;
211
212    /** PC of this instruction. */
213    Addr PC;
214
215    /** Next non-speculative PC.  It is not filled in at fetch, but rather
216     *  once the target of the branch is truly known (either decode or
217     *  execute).
218     */
219    Addr nextPC;
220
221    /** Predicted next PC. */
222    Addr predPC;
223
224    /** Count of total number of dynamic instructions. */
225    static int instcount;
226
227#ifdef DEBUG
228    void dumpSNList();
229#endif
230
231    /** Whether or not the source register is ready.
232     *  @todo: Not sure this should be here vs the derived class.
233     */
234    bool _readySrcRegIdx[MaxInstSrcRegs];
235
236  public:
237    /** BaseDynInst constructor given a binary instruction.
238     *  @param inst The binary instruction.
239     *  @param PC The PC of the instruction.
240     *  @param pred_PC The predicted next PC.
241     *  @param seq_num The sequence number of the instruction.
242     *  @param cpu Pointer to the instruction's CPU.
243     */
244    BaseDynInst(ExtMachInst inst, Addr PC, Addr pred_PC, InstSeqNum seq_num,
245                FullCPU *cpu);
246
247    /** BaseDynInst constructor given a StaticInst pointer.
248     *  @param _staticInst The StaticInst for this BaseDynInst.
249     */
250    BaseDynInst(StaticInstPtr &_staticInst);
251
252    /** BaseDynInst destructor. */
253    ~BaseDynInst();
254
255  private:
256    /** Function to initialize variables in the constructors. */
257    void initVars();
258
259  public:
260    /**
261     *  @todo: Make this function work; currently it is a dummy function.
262     *  @param fault Last fault.
263     *  @param cmd Last command.
264     *  @param addr Virtual address of access.
265     *  @param p Memory accessed.
266     *  @param nbytes Access size.
267     */
268    void
269    trace_mem(Fault fault,
270              MemCmd cmd,
271              Addr addr,
272              void *p,
273              int nbytes);
274
275    /** Dumps out contents of this BaseDynInst. */
276    void dump();
277
278    /** Dumps out contents of this BaseDynInst into given string. */
279    void dump(std::string &outstring);
280
281    /** Returns the fault type. */
282    Fault getFault() { return fault; }
283
284    /** Checks whether or not this instruction has had its branch target
285     *  calculated yet.  For now it is not utilized and is hacked to be
286     *  always false.
287     *  @todo: Actually use this instruction.
288     */
289    bool doneTargCalc() { return false; }
290
291    /** Returns the next PC.  This could be the speculative next PC if it is
292     *  called prior to the actual branch target being calculated.
293     */
294    Addr readNextPC() { return nextPC; }
295
296    /** Set the predicted target of this current instruction. */
297    void setPredTarg(Addr predicted_PC) { predPC = predicted_PC; }
298
299    /** Returns the predicted target of the branch. */
300    Addr readPredTarg() { return predPC; }
301
302    /** Returns whether the instruction was predicted taken or not. */
303    bool predTaken() { return predPC != (PC + sizeof(MachInst)); }
304
305    /** Returns whether the instruction mispredicted. */
306    bool mispredicted() { return predPC != nextPC; }
307
308    //
309    //  Instruction types.  Forward checks to StaticInst object.
310    //
311    bool isNop()	  const { return staticInst->isNop(); }
312    bool isMemRef()    	  const { return staticInst->isMemRef(); }
313    bool isLoad()	  const { return staticInst->isLoad(); }
314    bool isStore()	  const { return staticInst->isStore(); }
315    bool isStoreConditional() const
316    { return staticInst->isStoreConditional(); }
317    bool isInstPrefetch() const { return staticInst->isInstPrefetch(); }
318    bool isDataPrefetch() const { return staticInst->isDataPrefetch(); }
319    bool isCopy()         const { return staticInst->isCopy(); }
320    bool isInteger()	  const { return staticInst->isInteger(); }
321    bool isFloating()	  const { return staticInst->isFloating(); }
322    bool isControl()	  const { return staticInst->isControl(); }
323    bool isCall()	  const { return staticInst->isCall(); }
324    bool isReturn()	  const { return staticInst->isReturn(); }
325    bool isDirectCtrl()	  const { return staticInst->isDirectCtrl(); }
326    bool isIndirectCtrl() const { return staticInst->isIndirectCtrl(); }
327    bool isCondCtrl()	  const { return staticInst->isCondCtrl(); }
328    bool isUncondCtrl()	  const { return staticInst->isUncondCtrl(); }
329    bool isThreadSync()   const { return staticInst->isThreadSync(); }
330    bool isSerializing()  const { return staticInst->isSerializing(); }
331    bool isSerializeBefore() const
332    { return staticInst->isSerializeBefore() || status[SerializeBefore]; }
333    bool isSerializeAfter() const
334    { return staticInst->isSerializeAfter() || status[SerializeAfter]; }
335    bool isMemBarrier()   const { return staticInst->isMemBarrier(); }
336    bool isWriteBarrier() const { return staticInst->isWriteBarrier(); }
337    bool isNonSpeculative() const { return staticInst->isNonSpeculative(); }
338    bool isQuiesce() const { return staticInst->isQuiesce(); }
339    bool isIprAccess() const { return staticInst->isIprAccess(); }
340    bool isUnverifiable() const { return staticInst->isUnverifiable(); }
341
342    /** Temporarily sets this instruction as a serialize before instruction. */
343    void setSerializeBefore() { status.set(SerializeBefore); }
344
345    /** Clears the serializeBefore part of this instruction. */
346    void clearSerializeBefore() { status.reset(SerializeBefore); }
347
348    /** Checks if this serializeBefore is only temporarily set. */
349    bool isTempSerializeBefore() { return status[SerializeBefore]; }
350
351    /** Temporarily sets this instruction as a serialize after instruction. */
352    void setSerializeAfter() { status.set(SerializeAfter); }
353
354    /** Clears the serializeAfter part of this instruction.*/
355    void clearSerializeAfter() { status.reset(SerializeAfter); }
356
357    /** Checks if this serializeAfter is only temporarily set. */
358    bool isTempSerializeAfter() { return status[SerializeAfter]; }
359
360    /** Sets the serialization part of this instruction as handled. */
361    void setSerializeHandled() { status.set(SerializeHandled); }
362
363    /** Checks if the serialization part of this instruction has been
364     *  handled.  This does not apply to the temporary serializing
365     *  state; it only applies to this instruction's own permanent
366     *  serializing state.
367     */
368    bool isSerializeHandled() { return status[SerializeHandled]; }
369
370    /** Returns the opclass of this instruction. */
371    OpClass opClass() const { return staticInst->opClass(); }
372
373    /** Returns the branch target address. */
374    Addr branchTarget() const { return staticInst->branchTarget(PC); }
375
376    /** Returns the number of source registers. */
377    int8_t numSrcRegs()	const { return staticInst->numSrcRegs(); }
378
379    /** Returns the number of destination registers. */
380    int8_t numDestRegs() const { return staticInst->numDestRegs(); }
381
382    // the following are used to track physical register usage
383    // for machines with separate int & FP reg files
384    int8_t numFPDestRegs()  const { return staticInst->numFPDestRegs(); }
385    int8_t numIntDestRegs() const { return staticInst->numIntDestRegs(); }
386
387    /** Returns the logical register index of the i'th destination register. */
388    RegIndex destRegIdx(int i) const { return staticInst->destRegIdx(i); }
389
390    /** Returns the logical register index of the i'th source register. */
391    RegIndex srcRegIdx(int i) const { return staticInst->srcRegIdx(i); }
392
393    /** Returns the result of an integer instruction. */
394    uint64_t readIntResult() { return instResult.integer; }
395
396    /** Returns the result of a floating point instruction. */
397    float readFloatResult() { return (float)instResult.dbl; }
398
399    /** Returns the result of a floating point (double) instruction. */
400    double readDoubleResult() { return instResult.dbl; }
401
402    void setIntReg(const StaticInst *si, int idx, uint64_t val)
403    {
404        instResult.integer = val;
405    }
406
407    void setFloatRegSingle(const StaticInst *si, int idx, float val)
408    {
409//        instResult.fp = val;
410        instResult.dbl = (double)val;
411    }
412
413    void setFloatRegDouble(const StaticInst *si, int idx, double val)
414    {
415        instResult.dbl = val;
416    }
417
418    void setFloatRegInt(const StaticInst *si, int idx, uint64_t val)
419    {
420        instResult.integer = val;
421    }
422
423    /** Records that one of the source registers is ready. */
424    void markSrcRegReady();
425
426    /** Marks a specific register as ready. */
427    void markSrcRegReady(RegIndex src_idx);
428
429    /** Returns if a source register is ready. */
430    bool isReadySrcRegIdx(int idx) const
431    {
432        return this->_readySrcRegIdx[idx];
433    }
434
435    /** Sets this instruction as completed. */
436    void setCompleted() { status.set(Completed); }
437
438    /** Returns whether or not this instruction is completed. */
439    bool isCompleted() const { return status[Completed]; }
440
441    /** Marks the result as ready. */
442    void setResultReady() { status.set(ResultReady); }
443
444    /** Returns whether or not the result is ready. */
445    bool isResultReady() const { return status[ResultReady]; }
446
447    /** Sets this instruction as ready to issue. */
448    void setCanIssue() { status.set(CanIssue); }
449
450    /** Returns whether or not this instruction is ready to issue. */
451    bool readyToIssue() const { return status[CanIssue]; }
452
453    /** Sets this instruction as issued from the IQ. */
454    void setIssued() { status.set(Issued); }
455
456    /** Returns whether or not this instruction has issued. */
457    bool isIssued() const { return status[Issued]; }
458
459    /** Sets this instruction as executed. */
460    void setExecuted() { status.set(Executed); }
461
462    /** Returns whether or not this instruction has executed. */
463    bool isExecuted() const { return status[Executed]; }
464
465    /** Sets this instruction as ready to commit. */
466    void setCanCommit() { status.set(CanCommit); }
467
468    /** Clears this instruction as being ready to commit. */
469    void clearCanCommit() { status.reset(CanCommit); }
470
471    /** Returns whether or not this instruction is ready to commit. */
472    bool readyToCommit() const { return status[CanCommit]; }
473
474    void setAtCommit() { status.set(AtCommit); }
475
476    bool isAtCommit() { return status[AtCommit]; }
477
478    /** Sets this instruction as committed. */
479    void setCommitted() { status.set(Committed); }
480
481    /** Returns whether or not this instruction is committed. */
482    bool isCommitted() const { return status[Committed]; }
483
484    /** Sets this instruction as squashed. */
485    void setSquashed() { status.set(Squashed); }
486
487    /** Returns whether or not this instruction is squashed. */
488    bool isSquashed() const { return status[Squashed]; }
489
490    //Instruction Queue Entry
491    //-----------------------
492    /** Sets this instruction as a entry the IQ. */
493    void setInIQ() { status.set(IqEntry); }
494
495    /** Sets this instruction as a entry the IQ. */
496    void clearInIQ() { status.reset(IqEntry); }
497
498    /** Returns whether or not this instruction has issued. */
499    bool isInIQ() const { return status[IqEntry]; }
500
501    /** Sets this instruction as squashed in the IQ. */
502    void setSquashedInIQ() { status.set(SquashedInIQ); status.set(Squashed);}
503
504    /** Returns whether or not this instruction is squashed in the IQ. */
505    bool isSquashedInIQ() const { return status[SquashedInIQ]; }
506
507
508    //Load / Store Queue Functions
509    //-----------------------
510    /** Sets this instruction as a entry the LSQ. */
511    void setInLSQ() { status.set(LsqEntry); }
512
513    /** Sets this instruction as a entry the LSQ. */
514    void removeInLSQ() { status.reset(LsqEntry); }
515
516    /** Returns whether or not this instruction is in the LSQ. */
517    bool isInLSQ() const { return status[LsqEntry]; }
518
519    /** Sets this instruction as squashed in the LSQ. */
520    void setSquashedInLSQ() { status.set(SquashedInLSQ);}
521
522    /** Returns whether or not this instruction is squashed in the LSQ. */
523    bool isSquashedInLSQ() const { return status[SquashedInLSQ]; }
524
525
526    //Reorder Buffer Functions
527    //-----------------------
528    /** Sets this instruction as a entry the ROB. */
529    void setInROB() { status.set(RobEntry); }
530
531    /** Sets this instruction as a entry the ROB. */
532    void clearInROB() { status.reset(RobEntry); }
533
534    /** Returns whether or not this instruction is in the ROB. */
535    bool isInROB() const { return status[RobEntry]; }
536
537    /** Sets this instruction as squashed in the ROB. */
538    void setSquashedInROB() { status.set(SquashedInROB); }
539
540    /** Returns whether or not this instruction is squashed in the ROB. */
541    bool isSquashedInROB() const { return status[SquashedInROB]; }
542
543    /** Read the PC of this instruction. */
544    const Addr readPC() const { return PC; }
545
546    /** Set the next PC of this instruction (its actual target). */
547    void setNextPC(uint64_t val)
548    {
549        nextPC = val;
550//        instResult.integer = val;
551    }
552
553    void setASID(short addr_space_id) { asid = addr_space_id; }
554
555    void setThread(unsigned tid) { threadNumber = tid; }
556
557    void setState(ImplState *state) { thread = state; }
558
559    /** Returns the exec context.
560     *  @todo: Remove this once the ExecContext is no longer used.
561     */
562    ExecContext *xcBase() { return thread->getXCProxy(); }
563
564  private:
565    /** Instruction effective address.
566     *  @todo: Consider if this is necessary or not.
567     */
568    Addr instEffAddr;
569
570    /** Whether or not the effective address calculation is completed.
571     *  @todo: Consider if this is necessary or not.
572     */
573    bool eaCalcDone;
574
575  public:
576    /** Sets the effective address. */
577    void setEA(Addr &ea) { instEffAddr = ea; eaCalcDone = true; }
578
579    /** Returns the effective address. */
580    const Addr &getEA() const { return req->vaddr; }
581
582    /** Returns whether or not the eff. addr. calculation has been completed. */
583    bool doneEACalc() { return eaCalcDone; }
584
585    /** Returns whether or not the eff. addr. source registers are ready. */
586    bool eaSrcsReady();
587
588    /** Whether or not the memory operation is done. */
589    bool memOpDone;
590
591  public:
592    /** Load queue index. */
593    int16_t lqIdx;
594
595    /** Store queue index. */
596    int16_t sqIdx;
597
598    /** Iterator pointing to this BaseDynInst in the list of all insts. */
599    ListIt instListIt;
600
601    /** Returns iterator to this instruction in the list of all insts. */
602    ListIt &getInstListIt() { return instListIt; }
603
604    /** Sets iterator for this instruction in the list of all insts. */
605    void setInstListIt(ListIt _instListIt) { instListIt = _instListIt; }
606};
607
608template<class Impl>
609template<class T>
610inline Fault
611BaseDynInst<Impl>::read(Addr addr, T &data, unsigned flags)
612{
613    if (status[Executed]) {
614        fault = cpu->read(req, data, lqIdx);
615        return fault;
616    }
617
618    req = new MemReq(addr, thread->getXCProxy(), sizeof(T), flags);
619    req->asid = asid;
620    req->thread_num = threadNumber;
621    req->pc = this->PC;
622
623    if ((req->vaddr & (TheISA::VMPageSize - 1)) + req->size >
624        TheISA::VMPageSize) {
625        return TheISA::genAlignmentFault();
626    }
627
628    fault = cpu->translateDataReadReq(req);
629
630    effAddr = req->vaddr;
631    physEffAddr = req->paddr;
632    memReqFlags = req->flags;
633
634    if (fault == NoFault) {
635#if FULL_SYSTEM
636        if (cpu->system->memctrl->badaddr(physEffAddr)) {
637            fault = TheISA::genMachineCheckFault();
638            data = (T)-1;
639            this->setExecuted();
640        } else {
641            fault = cpu->read(req, data, lqIdx);
642        }
643#else
644        fault = cpu->read(req, data, lqIdx);
645#endif
646    } else {
647        // Return a fixed value to keep simulation deterministic even
648        // along misspeculated paths.
649        data = (T)-1;
650
651        // Commit will have to clean up whatever happened.  Set this
652        // instruction as executed.
653        this->setExecuted();
654    }
655
656    if (traceData) {
657        traceData->setAddr(addr);
658        traceData->setData(data);
659    }
660
661    return fault;
662}
663
664template<class Impl>
665template<class T>
666inline Fault
667BaseDynInst<Impl>::write(T data, Addr addr, unsigned flags, uint64_t *res)
668{
669    if (traceData) {
670        traceData->setAddr(addr);
671        traceData->setData(data);
672    }
673
674    req = new MemReq(addr, thread->getXCProxy(), sizeof(T), flags);
675
676    req->asid = asid;
677    req->thread_num = threadNumber;
678    req->pc = this->PC;
679
680    if ((req->vaddr & (TheISA::VMPageSize - 1)) + req->size >
681        TheISA::VMPageSize) {
682        return TheISA::genAlignmentFault();
683    }
684
685    fault = cpu->translateDataWriteReq(req);
686
687    effAddr = req->vaddr;
688    physEffAddr = req->paddr;
689    memReqFlags = req->flags;
690
691    if (fault == NoFault) {
692#if FULL_SYSTEM
693        if (cpu->system->memctrl->badaddr(physEffAddr)) {
694            fault = TheISA::genMachineCheckFault();
695        } else {
696            fault = cpu->write(req, data, sqIdx);
697        }
698#else
699        fault = cpu->write(req, data, sqIdx);
700#endif
701    }
702
703    if (res) {
704        // always return some result to keep misspeculated paths
705        // (which will ignore faults) deterministic
706        *res = (fault == NoFault) ? req->result : 0;
707    }
708
709    return fault;
710}
711
712#endif // __CPU_BASE_DYN_INST_HH__
713