2 * Copyright (c) 2011, 2013, 2016-2020 ARM Limited
3 * Copyright (c) 2013 Advanced Micro Devices, Inc.
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
15 * Copyright (c) 2004-2006 The Regents of The University of Michigan
16 * Copyright (c) 2009 The University of Edinburgh
17 * All rights reserved.
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions are
21 * met: redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer;
23 * redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution;
26 * neither the name of the copyright holders nor the names of its
27 * contributors may be used to endorse or promote products derived from
28 * this software without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 #ifndef __CPU_BASE_DYN_INST_HH__
44 #define __CPU_BASE_DYN_INST_HH__
52 #include "arch/generic/tlb.hh"
53 #include "arch/utility.hh"
54 #include "base/trace.hh"
55 #include "config/the_isa.hh"
56 #include "cpu/checker/cpu.hh"
57 #include "cpu/exec_context.hh"
58 #include "cpu/exetrace.hh"
59 #include "cpu/inst_res.hh"
60 #include "cpu/inst_seq.hh"
61 #include "cpu/op_class.hh"
62 #include "cpu/static_inst.hh"
63 #include "cpu/translation.hh"
64 #include "debug/HtmCpu.hh"
65 #include "mem/packet.hh"
66 #include "mem/request.hh"
67 #include "sim/byteswap.hh"
68 #include "sim/system.hh"
72 * Defines a dynamic instruction context.
76 class BaseDynInst : public ExecContext, public RefCounted
79 // Typedef for the CPU.
80 typedef typename Impl::CPUType ImplCPU;
81 typedef typename ImplCPU::ImplState ImplState;
82 using VecRegContainer = TheISA::VecRegContainer;
84 using LSQRequestPtr = typename Impl::CPUPol::LSQ::LSQRequest*;
85 using LQIterator = typename Impl::CPUPol::LSQUnit::LQIterator;
86 using SQIterator = typename Impl::CPUPol::LSQUnit::SQIterator;
88 // The DynInstPtr type.
89 typedef typename Impl::DynInstPtr DynInstPtr;
90 typedef RefCountingPtr<BaseDynInst<Impl> > BaseDynInstPtr;
92 // The list of instructions iterator type.
93 typedef typename std::list<DynInstPtr>::iterator ListIt;
96 MaxInstSrcRegs = TheISA::MaxInstSrcRegs, /// Max source regs
97 MaxInstDestRegs = TheISA::MaxInstDestRegs /// Max dest regs
102 IqEntry, /// Instruction is in the IQ
103 RobEntry, /// Instruction is in the ROB
104 LsqEntry, /// Instruction is in the LSQ
105 Completed, /// Instruction has completed
106 ResultReady, /// Instruction has its result
107 CanIssue, /// Instruction can issue and execute
108 Issued, /// Instruction has issued
109 Executed, /// Instruction has executed
110 CanCommit, /// Instruction can commit
111 AtCommit, /// Instruction has reached commit
112 Committed, /// Instruction has committed
113 Squashed, /// Instruction is squashed
114 SquashedInIQ, /// Instruction is squashed in the IQ
115 SquashedInLSQ, /// Instruction is squashed in the LSQ
116 SquashedInROB, /// Instruction is squashed in the ROB
117 PinnedRegsRenamed, /// Pinned registers are renamed
118 PinnedRegsWritten, /// Pinned registers are written back
119 PinnedRegsSquashDone, /// Regs pinning status updated after squash
120 RecoverInst, /// Is a recover instruction
121 BlockingInst, /// Is a blocking instruction
122 ThreadsyncWait, /// Is a thread synchronization instruction
123 SerializeBefore, /// Needs to serialize on
124 /// instructions ahead of it
125 SerializeAfter, /// Needs to serialize instructions behind it
126 SerializeHandled, /// Serialization has been handled
133 TranslationCompleted,
134 PossibleLoadViolation,
149 /** The sequence number of the instruction. */
152 /** The StaticInst used by this BaseDynInst. */
153 const StaticInstPtr staticInst;
155 /** Pointer to the Impl's CPU object. */
158 BaseCPU *getCpuPtr() { return cpu; }
160 /** Pointer to the thread state. */
163 /** The kind of fault this instruction has generated. */
166 /** InstRecord that tracks this instructions. */
167 Trace::InstRecord *traceData;
170 /** The result of the instruction; assumes an instruction can have many
171 * destination registers.
173 std::queue<InstResult> instResult;
175 /** PC state for this instruction. */
179 /* An amalgamation of a lot of boolean values into one */
180 std::bitset<MaxFlags> instFlags;
182 /** The status of this BaseDynInst. Several bits can be set. */
183 std::bitset<NumStatus> status;
186 /** Whether or not the source register is ready.
187 * @todo: Not sure this should be here vs the derived class.
189 std::bitset<MaxInstSrcRegs> _readySrcRegIdx;
192 /** The thread this instruction is from. */
193 ThreadID threadNumber;
195 /** Iterator pointing to this BaseDynInst in the list of all insts. */
198 ////////////////////// Branch Data ///////////////
199 /** Predicted PC state after this instruction. */
200 TheISA::PCState predPC;
202 /** The Macroop if one exists */
203 const StaticInstPtr macroop;
205 /** How many source registers are ready. */
209 /////////////////////// Load Store Data //////////////////////
210 /** The effective virtual address (lds & stores only). */
213 /** The effective physical address. */
216 /** The memory request flags (from translation). */
217 unsigned memReqFlags;
219 /** The size of the request */
222 /** Pointer to the data for the memory access. */
225 /** Load queue index. */
229 /** Store queue index. */
234 /////////////////////// TLB Miss //////////////////////
236 * Saved memory request (needed when the DTB address translation is
237 * delayed due to a hw page table walk).
239 LSQRequestPtr savedReq;
241 /////////////////////// Checker //////////////////////
242 // Need a copy of main request pointer to verify on writes.
243 RequestPtr reqToVerify;
246 // hardware transactional memory
251 /** Flattened register index of the destination registers of this
254 std::array<RegId, TheISA::MaxInstDestRegs> _flatDestRegIdx;
256 /** Physical register index of the destination registers of this
259 std::array<PhysRegIdPtr, TheISA::MaxInstDestRegs> _destRegIdx;
261 /** Physical register index of the source registers of this
264 std::array<PhysRegIdPtr, TheISA::MaxInstSrcRegs> _srcRegIdx;
266 /** Physical register index of the previous producers of the
267 * architected destinations.
269 std::array<PhysRegIdPtr, TheISA::MaxInstDestRegs> _prevDestRegIdx;
273 /** Records changes to result? */
274 void recordResult(bool f) { instFlags[RecordResult] = f; }
276 /** Is the effective virtual address valid. */
277 bool effAddrValid() const { return instFlags[EffAddrValid]; }
278 void effAddrValid(bool b) { instFlags[EffAddrValid] = b; }
280 /** Whether or not the memory operation is done. */
281 bool memOpDone() const { return instFlags[MemOpDone]; }
282 void memOpDone(bool f) { instFlags[MemOpDone] = f; }
284 bool notAnInst() const { return instFlags[NotAnInst]; }
285 void setNotAnInst() { instFlags[NotAnInst] = true; }
288 ////////////////////////////////////////////
290 // INSTRUCTION EXECUTION
292 ////////////////////////////////////////////
295 demapPage(Addr vaddr, uint64_t asn) override
297 cpu->demapPage(vaddr, asn);
300 demapInstPage(Addr vaddr, uint64_t asn)
302 cpu->demapPage(vaddr, asn);
305 demapDataPage(Addr vaddr, uint64_t asn)
307 cpu->demapPage(vaddr, asn);
310 Fault initiateMemRead(Addr addr, unsigned size, Request::Flags flags,
311 const std::vector<bool> &byte_enable=std::vector<bool>()) override;
313 Fault initiateHtmCmd(Request::Flags flags) override;
315 Fault writeMem(uint8_t *data, unsigned size, Addr addr,
316 Request::Flags flags, uint64_t *res,
317 const std::vector<bool> &byte_enable=std::vector<bool>())
320 Fault initiateMemAMO(Addr addr, unsigned size, Request::Flags flags,
321 AtomicOpFunctorPtr amo_op) override;
323 /** True if the DTB address translation has started. */
324 bool translationStarted() const { return instFlags[TranslationStarted]; }
325 void translationStarted(bool f) { instFlags[TranslationStarted] = f; }
327 /** True if the DTB address translation has completed. */
328 bool translationCompleted() const { return instFlags[TranslationCompleted]; }
329 void translationCompleted(bool f) { instFlags[TranslationCompleted] = f; }
331 /** True if this address was found to match a previous load and they issued
332 * out of order. If that happend, then it's only a problem if an incoming
333 * snoop invalidate modifies the line, in which case we need to squash.
334 * If nothing modified the line the order doesn't matter.
337 possibleLoadViolation() const
339 return instFlags[PossibleLoadViolation];
342 possibleLoadViolation(bool f)
344 instFlags[PossibleLoadViolation] = f;
347 /** True if the address hit a external snoop while sitting in the LSQ.
348 * If this is true and a older instruction sees it, this instruction must
351 bool hitExternalSnoop() const { return instFlags[HitExternalSnoop]; }
352 void hitExternalSnoop(bool f) { instFlags[HitExternalSnoop] = f; }
355 * Returns true if the DTB address translation is being delayed due to a hw
359 isTranslationDelayed() const
361 return (translationStarted() && !translationCompleted());
369 /** Returns the physical register index of the i'th destination
373 renamedDestRegIdx(int idx) const
375 return _destRegIdx[idx];
378 /** Returns the physical register index of the i'th source register. */
380 renamedSrcRegIdx(int idx) const
382 assert(TheISA::MaxInstSrcRegs > idx);
383 return _srcRegIdx[idx];
386 /** Returns the flattened register index of the i'th destination
390 flattenedDestRegIdx(int idx) const
392 return _flatDestRegIdx[idx];
395 /** Returns the physical register index of the previous physical register
396 * that remapped to the same logical register index.
399 prevDestRegIdx(int idx) const
401 return _prevDestRegIdx[idx];
404 /** Renames a destination register to a physical register. Also records
405 * the previous physical register that the logical register mapped to.
408 renameDestReg(int idx, PhysRegIdPtr renamed_dest,
409 PhysRegIdPtr previous_rename)
411 _destRegIdx[idx] = renamed_dest;
412 _prevDestRegIdx[idx] = previous_rename;
413 if (renamed_dest->isPinned())
414 setPinnedRegsRenamed();
417 /** Renames a source logical register to the physical register which
418 * has/will produce that logical register's result.
419 * @todo: add in whether or not the source register is ready.
422 renameSrcReg(int idx, PhysRegIdPtr renamed_src)
424 _srcRegIdx[idx] = renamed_src;
427 /** Flattens a destination architectural register index into a logical
431 flattenDestReg(int idx, const RegId &flattened_dest)
433 _flatDestRegIdx[idx] = flattened_dest;
435 /** BaseDynInst constructor given a binary instruction.
436 * @param staticInst A StaticInstPtr to the underlying instruction.
437 * @param pc The PC state for the instruction.
438 * @param predPC The predicted next PC state for the instruction.
439 * @param seq_num The sequence number of the instruction.
440 * @param cpu Pointer to the instruction's CPU.
442 BaseDynInst(const StaticInstPtr &staticInst, const StaticInstPtr ¯oop,
443 TheISA::PCState pc, TheISA::PCState predPC,
444 InstSeqNum seq_num, ImplCPU *cpu);
446 /** BaseDynInst constructor given a StaticInst pointer.
447 * @param _staticInst The StaticInst for this BaseDynInst.
449 BaseDynInst(const StaticInstPtr &staticInst, const StaticInstPtr ¯oop);
451 /** BaseDynInst destructor. */
455 /** Function to initialize variables in the constructors. */
459 /** Dumps out contents of this BaseDynInst. */
462 /** Dumps out contents of this BaseDynInst into given string. */
463 void dump(std::string &outstring);
465 /** Read this CPU's ID. */
466 int cpuId() const { return cpu->cpuId(); }
468 /** Read this CPU's Socket ID. */
469 uint32_t socketId() const { return cpu->socketId(); }
471 /** Read this CPU's data requestor ID */
472 RequestorID requestorId() const { return cpu->dataRequestorId(); }
474 /** Read this context's system-wide ID **/
475 ContextID contextId() const { return thread->contextId(); }
477 /** Returns the fault type. */
478 Fault getFault() const { return fault; }
479 /** TODO: This I added for the LSQRequest side to be able to modify the
480 * fault. There should be a better mechanism in place. */
481 Fault& getFault() { return fault; }
483 /** Checks whether or not this instruction has had its branch target
484 * calculated yet. For now it is not utilized and is hacked to be
486 * @todo: Actually use this instruction.
488 bool doneTargCalc() { return false; }
490 /** Set the predicted target of this current instruction. */
491 void setPredTarg(const TheISA::PCState &_predPC) { predPC = _predPC; }
493 const TheISA::PCState &readPredTarg() { return predPC; }
495 /** Returns the predicted PC immediately after the branch. */
496 Addr predInstAddr() { return predPC.instAddr(); }
498 /** Returns the predicted PC two instructions after the branch */
499 Addr predNextInstAddr() { return predPC.nextInstAddr(); }
501 /** Returns the predicted micro PC after the branch */
502 Addr predMicroPC() { return predPC.microPC(); }
504 /** Returns whether the instruction was predicted taken or not. */
505 bool readPredTaken() { return instFlags[PredTaken]; }
508 setPredTaken(bool predicted_taken)
510 instFlags[PredTaken] = predicted_taken;
513 /** Returns whether the instruction mispredicted. */
517 TheISA::PCState tempPC = pc;
518 TheISA::advancePC(tempPC, staticInst);
519 return !(tempPC == predPC);
523 // Instruction types. Forward checks to StaticInst object.
525 bool isNop() const { return staticInst->isNop(); }
526 bool isMemRef() const { return staticInst->isMemRef(); }
527 bool isLoad() const { return staticInst->isLoad(); }
528 bool isStore() const { return staticInst->isStore(); }
529 bool isAtomic() const { return staticInst->isAtomic(); }
530 bool isStoreConditional() const
531 { return staticInst->isStoreConditional(); }
532 bool isInstPrefetch() const { return staticInst->isInstPrefetch(); }
533 bool isDataPrefetch() const { return staticInst->isDataPrefetch(); }
534 bool isInteger() const { return staticInst->isInteger(); }
535 bool isFloating() const { return staticInst->isFloating(); }
536 bool isVector() const { return staticInst->isVector(); }
537 bool isControl() const { return staticInst->isControl(); }
538 bool isCall() const { return staticInst->isCall(); }
539 bool isReturn() const { return staticInst->isReturn(); }
540 bool isDirectCtrl() const { return staticInst->isDirectCtrl(); }
541 bool isIndirectCtrl() const { return staticInst->isIndirectCtrl(); }
542 bool isCondCtrl() const { return staticInst->isCondCtrl(); }
543 bool isUncondCtrl() const { return staticInst->isUncondCtrl(); }
544 bool isSerializing() const { return staticInst->isSerializing(); }
546 isSerializeBefore() const
548 return staticInst->isSerializeBefore() || status[SerializeBefore];
551 isSerializeAfter() const
553 return staticInst->isSerializeAfter() || status[SerializeAfter];
555 bool isSquashAfter() const { return staticInst->isSquashAfter(); }
556 bool isMemBarrier() const { return staticInst->isMemBarrier(); }
557 bool isWriteBarrier() const { return staticInst->isWriteBarrier(); }
558 bool isNonSpeculative() const { return staticInst->isNonSpeculative(); }
559 bool isQuiesce() const { return staticInst->isQuiesce(); }
560 bool isIprAccess() const { return staticInst->isIprAccess(); }
561 bool isUnverifiable() const { return staticInst->isUnverifiable(); }
562 bool isSyscall() const { return staticInst->isSyscall(); }
563 bool isMacroop() const { return staticInst->isMacroop(); }
564 bool isMicroop() const { return staticInst->isMicroop(); }
565 bool isDelayedCommit() const { return staticInst->isDelayedCommit(); }
566 bool isLastMicroop() const { return staticInst->isLastMicroop(); }
567 bool isFirstMicroop() const { return staticInst->isFirstMicroop(); }
568 bool isMicroBranch() const { return staticInst->isMicroBranch(); }
569 // hardware transactional memory
570 bool isHtmStart() const { return staticInst->isHtmStart(); }
571 bool isHtmStop() const { return staticInst->isHtmStop(); }
572 bool isHtmCancel() const { return staticInst->isHtmCancel(); }
573 bool isHtmCmd() const { return staticInst->isHtmCmd(); }
576 getHtmTransactionUid() const override
578 assert(instFlags[HtmFromTransaction]);
583 newHtmTransactionUid() const override
585 panic("Not yet implemented\n");
590 inHtmTransactionalState() const override
592 return instFlags[HtmFromTransaction];
596 getHtmTransactionalDepth() const override
598 if (inHtmTransactionalState())
599 return this->htmDepth;
605 setHtmTransactionalState(uint64_t htm_uid, uint64_t htm_depth)
607 instFlags.set(HtmFromTransaction);
609 htmDepth = htm_depth;
613 clearHtmTransactionalState()
615 if (inHtmTransactionalState()) {
617 "clearing instuction's transactional state htmUid=%u\n",
618 getHtmTransactionUid());
620 instFlags.reset(HtmFromTransaction);
626 /** Temporarily sets this instruction as a serialize before instruction. */
627 void setSerializeBefore() { status.set(SerializeBefore); }
629 /** Clears the serializeBefore part of this instruction. */
630 void clearSerializeBefore() { status.reset(SerializeBefore); }
632 /** Checks if this serializeBefore is only temporarily set. */
633 bool isTempSerializeBefore() { return status[SerializeBefore]; }
635 /** Temporarily sets this instruction as a serialize after instruction. */
636 void setSerializeAfter() { status.set(SerializeAfter); }
638 /** Clears the serializeAfter part of this instruction.*/
639 void clearSerializeAfter() { status.reset(SerializeAfter); }
641 /** Checks if this serializeAfter is only temporarily set. */
642 bool isTempSerializeAfter() { return status[SerializeAfter]; }
644 /** Sets the serialization part of this instruction as handled. */
645 void setSerializeHandled() { status.set(SerializeHandled); }
647 /** Checks if the serialization part of this instruction has been
648 * handled. This does not apply to the temporary serializing
649 * state; it only applies to this instruction's own permanent
652 bool isSerializeHandled() { return status[SerializeHandled]; }
654 /** Returns the opclass of this instruction. */
655 OpClass opClass() const { return staticInst->opClass(); }
657 /** Returns the branch target address. */
658 TheISA::PCState branchTarget() const
659 { return staticInst->branchTarget(pc); }
661 /** Returns the number of source registers. */
662 int8_t numSrcRegs() const { return staticInst->numSrcRegs(); }
664 /** Returns the number of destination registers. */
665 int8_t numDestRegs() const { return staticInst->numDestRegs(); }
667 // the following are used to track physical register usage
668 // for machines with separate int & FP reg files
669 int8_t numFPDestRegs() const { return staticInst->numFPDestRegs(); }
670 int8_t numIntDestRegs() const { return staticInst->numIntDestRegs(); }
671 int8_t numCCDestRegs() const { return staticInst->numCCDestRegs(); }
672 int8_t numVecDestRegs() const { return staticInst->numVecDestRegs(); }
674 numVecElemDestRegs() const
676 return staticInst->numVecElemDestRegs();
679 numVecPredDestRegs() const
681 return staticInst->numVecPredDestRegs();
684 /** Returns the logical register index of the i'th destination register. */
685 const RegId& destRegIdx(int i) const { return staticInst->destRegIdx(i); }
687 /** Returns the logical register index of the i'th source register. */
688 const RegId& srcRegIdx(int i) const { return staticInst->srcRegIdx(i); }
690 /** Return the size of the instResult queue. */
691 uint8_t resultSize() { return instResult.size(); }
693 /** Pops a result off the instResult queue.
694 * If the result stack is empty, return the default value.
697 popResult(InstResult dflt=InstResult())
699 if (!instResult.empty()) {
700 InstResult t = instResult.front();
707 /** Pushes a result onto the instResult queue. */
709 /** Scalar result. */
712 setScalarResult(T &&t)
714 if (instFlags[RecordResult]) {
715 instResult.push(InstResult(std::forward<T>(t),
716 InstResult::ResultType::Scalar));
720 /** Full vector result. */
725 if (instFlags[RecordResult]) {
726 instResult.push(InstResult(std::forward<T>(t),
727 InstResult::ResultType::VecReg));
731 /** Vector element result. */
734 setVecElemResult(T &&t)
736 if (instFlags[RecordResult]) {
737 instResult.push(InstResult(std::forward<T>(t),
738 InstResult::ResultType::VecElem));
742 /** Predicate result. */
745 setVecPredResult(T &&t)
747 if (instFlags[RecordResult]) {
748 instResult.push(InstResult(std::forward<T>(t),
749 InstResult::ResultType::VecPredReg));
754 /** Records an integer register being set to a value. */
756 setIntRegOperand(const StaticInst *si, int idx, RegVal val) override
758 setScalarResult(val);
761 /** Records a CC register being set to a value. */
763 setCCRegOperand(const StaticInst *si, int idx, RegVal val) override
765 setScalarResult(val);
768 /** Record a vector register being set to a value */
770 setVecRegOperand(const StaticInst *si, int idx,
771 const VecRegContainer &val) override
776 /** Records an fp register being set to an integer value. */
778 setFloatRegOperandBits(const StaticInst *si, int idx, RegVal val) override
780 setScalarResult(val);
783 /** Record a vector register being set to a value */
785 setVecElemOperand(const StaticInst *si, int idx,
786 const VecElem val) override
788 setVecElemResult(val);
791 /** Record a vector register being set to a value */
793 setVecPredRegOperand(const StaticInst *si, int idx,
794 const VecPredRegContainer &val) override
796 setVecPredResult(val);
799 /** Records that one of the source registers is ready. */
800 void markSrcRegReady();
802 /** Marks a specific register as ready. */
803 void markSrcRegReady(RegIndex src_idx);
805 /** Returns if a source register is ready. */
807 isReadySrcRegIdx(int idx) const
809 return this->_readySrcRegIdx[idx];
812 /** Sets this instruction as completed. */
813 void setCompleted() { status.set(Completed); }
815 /** Returns whether or not this instruction is completed. */
816 bool isCompleted() const { return status[Completed]; }
818 /** Marks the result as ready. */
819 void setResultReady() { status.set(ResultReady); }
821 /** Returns whether or not the result is ready. */
822 bool isResultReady() const { return status[ResultReady]; }
824 /** Sets this instruction as ready to issue. */
825 void setCanIssue() { status.set(CanIssue); }
827 /** Returns whether or not this instruction is ready to issue. */
828 bool readyToIssue() const { return status[CanIssue]; }
830 /** Clears this instruction being able to issue. */
831 void clearCanIssue() { status.reset(CanIssue); }
833 /** Sets this instruction as issued from the IQ. */
834 void setIssued() { status.set(Issued); }
836 /** Returns whether or not this instruction has issued. */
837 bool isIssued() const { return status[Issued]; }
839 /** Clears this instruction as being issued. */
840 void clearIssued() { status.reset(Issued); }
842 /** Sets this instruction as executed. */
843 void setExecuted() { status.set(Executed); }
845 /** Returns whether or not this instruction has executed. */
846 bool isExecuted() const { return status[Executed]; }
848 /** Sets this instruction as ready to commit. */
849 void setCanCommit() { status.set(CanCommit); }
851 /** Clears this instruction as being ready to commit. */
852 void clearCanCommit() { status.reset(CanCommit); }
854 /** Returns whether or not this instruction is ready to commit. */
855 bool readyToCommit() const { return status[CanCommit]; }
857 void setAtCommit() { status.set(AtCommit); }
859 bool isAtCommit() { return status[AtCommit]; }
861 /** Sets this instruction as committed. */
862 void setCommitted() { status.set(Committed); }
864 /** Returns whether or not this instruction is committed. */
865 bool isCommitted() const { return status[Committed]; }
867 /** Sets this instruction as squashed. */
870 /** Returns whether or not this instruction is squashed. */
871 bool isSquashed() const { return status[Squashed]; }
873 //Instruction Queue Entry
874 //-----------------------
875 /** Sets this instruction as a entry the IQ. */
876 void setInIQ() { status.set(IqEntry); }
878 /** Sets this instruction as a entry the IQ. */
879 void clearInIQ() { status.reset(IqEntry); }
881 /** Returns whether or not this instruction has issued. */
882 bool isInIQ() const { return status[IqEntry]; }
884 /** Sets this instruction as squashed in the IQ. */
885 void setSquashedInIQ() { status.set(SquashedInIQ); status.set(Squashed);}
887 /** Returns whether or not this instruction is squashed in the IQ. */
888 bool isSquashedInIQ() const { return status[SquashedInIQ]; }
891 //Load / Store Queue Functions
892 //-----------------------
893 /** Sets this instruction as a entry the LSQ. */
894 void setInLSQ() { status.set(LsqEntry); }
896 /** Sets this instruction as a entry the LSQ. */
897 void removeInLSQ() { status.reset(LsqEntry); }
899 /** Returns whether or not this instruction is in the LSQ. */
900 bool isInLSQ() const { return status[LsqEntry]; }
902 /** Sets this instruction as squashed in the LSQ. */
903 void setSquashedInLSQ() { status.set(SquashedInLSQ); status.set(Squashed);}
905 /** Returns whether or not this instruction is squashed in the LSQ. */
906 bool isSquashedInLSQ() const { return status[SquashedInLSQ]; }
909 //Reorder Buffer Functions
910 //-----------------------
911 /** Sets this instruction as a entry the ROB. */
912 void setInROB() { status.set(RobEntry); }
914 /** Sets this instruction as a entry the ROB. */
915 void clearInROB() { status.reset(RobEntry); }
917 /** Returns whether or not this instruction is in the ROB. */
918 bool isInROB() const { return status[RobEntry]; }
920 /** Sets this instruction as squashed in the ROB. */
921 void setSquashedInROB() { status.set(SquashedInROB); }
923 /** Returns whether or not this instruction is squashed in the ROB. */
924 bool isSquashedInROB() const { return status[SquashedInROB]; }
926 /** Returns whether pinned registers are renamed */
927 bool isPinnedRegsRenamed() const { return status[PinnedRegsRenamed]; }
929 /** Sets the destination registers as renamed */
931 setPinnedRegsRenamed()
933 assert(!status[PinnedRegsSquashDone]);
934 assert(!status[PinnedRegsWritten]);
935 status.set(PinnedRegsRenamed);
938 /** Returns whether destination registers are written */
939 bool isPinnedRegsWritten() const { return status[PinnedRegsWritten]; }
941 /** Sets destination registers as written */
943 setPinnedRegsWritten()
945 assert(!status[PinnedRegsSquashDone]);
946 assert(status[PinnedRegsRenamed]);
947 status.set(PinnedRegsWritten);
950 /** Return whether dest registers' pinning status updated after squash */
952 isPinnedRegsSquashDone() const { return status[PinnedRegsSquashDone]; }
954 /** Sets dest registers' status updated after squash */
956 setPinnedRegsSquashDone() {
957 assert(!status[PinnedRegsSquashDone]);
958 status.set(PinnedRegsSquashDone);
961 /** Read the PC state of this instruction. */
962 TheISA::PCState pcState() const override { return pc; }
964 /** Set the PC state of this instruction. */
965 void pcState(const TheISA::PCState &val) override { pc = val; }
967 /** Read the PC of this instruction. */
968 Addr instAddr() const { return pc.instAddr(); }
970 /** Read the PC of the next instruction. */
971 Addr nextInstAddr() const { return pc.nextInstAddr(); }
973 /**Read the micro PC of this instruction. */
974 Addr microPC() const { return pc.microPC(); }
976 bool readPredicate() const override { return instFlags[Predicate]; }
979 setPredicate(bool val) override
981 instFlags[Predicate] = val;
984 traceData->setPredicate(val);
989 readMemAccPredicate() const override
991 return instFlags[MemAccPredicate];
995 setMemAccPredicate(bool val) override
997 instFlags[MemAccPredicate] = val;
1000 /** Sets the thread id. */
1001 void setTid(ThreadID tid) { threadNumber = tid; }
1003 /** Sets the pointer to the thread state. */
1004 void setThreadState(ImplState *state) { thread = state; }
1006 /** Returns the thread context. */
1007 ThreadContext *tcBase() const override { return thread->getTC(); }
1010 /** Returns whether or not the eff. addr. source registers are ready. */
1011 bool eaSrcsReady() const;
1013 /** Is this instruction's memory access strictly ordered? */
1014 bool strictlyOrdered() const { return instFlags[IsStrictlyOrdered]; }
1015 void strictlyOrdered(bool so) { instFlags[IsStrictlyOrdered] = so; }
1017 /** Has this instruction generated a memory request. */
1018 bool hasRequest() const { return instFlags[ReqMade]; }
1019 /** Assert this instruction has generated a memory request. */
1020 void setRequest() { instFlags[ReqMade] = true; }
1022 /** Returns iterator to this instruction in the list of all insts. */
1023 ListIt &getInstListIt() { return instListIt; }
1025 /** Sets iterator for this instruction in the list of all insts. */
1026 void setInstListIt(ListIt _instListIt) { instListIt = _instListIt; }
1029 /** Returns the number of consecutive store conditional failures. */
1031 readStCondFailures() const override
1033 return thread->storeCondFailures;
1036 /** Sets the number of consecutive store conditional failures. */
1038 setStCondFailures(unsigned int sc_failures) override
1040 thread->storeCondFailures = sc_failures;
1044 // monitor/mwait funtions
1046 armMonitor(Addr address) override
1048 cpu->armMonitor(threadNumber, address);
1051 mwait(PacketPtr pkt) override
1053 return cpu->mwait(threadNumber, pkt);
1056 mwaitAtomic(ThreadContext *tc) override
1058 return cpu->mwaitAtomic(threadNumber, tc, cpu->dtb);
1061 getAddrMonitor() override
1063 return cpu->getCpuAddrMonitor(threadNumber);
1067 template<class Impl>
1069 BaseDynInst<Impl>::initiateMemRead(Addr addr, unsigned size,
1070 Request::Flags flags,
1071 const std::vector<bool> &byte_enable)
1073 assert(byte_enable.empty() || byte_enable.size() == size);
1074 return cpu->pushRequest(
1075 dynamic_cast<typename DynInstPtr::PtrType>(this),
1076 /* ld */ true, nullptr, size, addr, flags, nullptr, nullptr,
1080 template<class Impl>
1082 BaseDynInst<Impl>::initiateHtmCmd(Request::Flags flags)
1084 return cpu->pushRequest(
1085 dynamic_cast<typename DynInstPtr::PtrType>(this),
1086 /* ld */ true, nullptr, 8, 0x0ul, flags, nullptr, nullptr);
1089 template<class Impl>
1091 BaseDynInst<Impl>::writeMem(uint8_t *data, unsigned size, Addr addr,
1092 Request::Flags flags, uint64_t *res,
1093 const std::vector<bool> &byte_enable)
1095 assert(byte_enable.empty() || byte_enable.size() == size);
1096 return cpu->pushRequest(
1097 dynamic_cast<typename DynInstPtr::PtrType>(this),
1098 /* st */ false, data, size, addr, flags, res, nullptr,
1102 template<class Impl>
1104 BaseDynInst<Impl>::initiateMemAMO(Addr addr, unsigned size,
1105 Request::Flags flags,
1106 AtomicOpFunctorPtr amo_op)
1108 // atomic memory instructions do not have data to be written to memory yet
1109 // since the atomic operations will be executed directly in cache/memory.
1110 // Therefore, its `data` field is nullptr.
1111 // Atomic memory requests need to carry their `amo_op` fields to cache/
1113 return cpu->pushRequest(
1114 dynamic_cast<typename DynInstPtr::PtrType>(this),
1115 /* atomic */ false, nullptr, size, addr, flags, nullptr,
1119 #endif // __CPU_BASE_DYN_INST_HH__