2 * Copyright (c) 2011 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2004-2006 The Regents of The University of Michigan
15 * Copyright (c) 2009 The University of Edinburgh
16 * All rights reserved.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 #ifndef __CPU_BASE_DYN_INST_HH__
46 #define __CPU_BASE_DYN_INST_HH__
52 #include "arch/faults.hh"
53 #include "arch/utility.hh"
54 #include "base/fast_alloc.hh"
55 #include "base/trace.hh"
56 #include "config/full_system.hh"
57 #include "config/the_isa.hh"
58 #include "cpu/o3/comm.hh"
59 #include "cpu/exetrace.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 "mem/packet.hh"
65 #include "sim/byteswap.hh"
66 #include "sim/system.hh"
71 * Defines a dynamic instruction context.
74 // Forward declaration.
78 class BaseDynInst : public FastAlloc, public RefCounted
81 // Typedef for the CPU.
82 typedef typename Impl::CPUType ImplCPU;
83 typedef typename ImplCPU::ImplState ImplState;
85 // Logical register index type.
86 typedef TheISA::RegIndex RegIndex;
87 // Integer register type.
88 typedef TheISA::IntReg IntReg;
89 // Floating point register type.
90 typedef TheISA::FloatReg FloatReg;
92 // The DynInstPtr type.
93 typedef typename Impl::DynInstPtr DynInstPtr;
95 // The list of instructions iterator type.
96 typedef typename std::list<DynInstPtr>::iterator ListIt;
99 MaxInstSrcRegs = TheISA::MaxInstSrcRegs, /// Max source regs
100 MaxInstDestRegs = TheISA::MaxInstDestRegs, /// Max dest regs
103 /** The StaticInst used by this BaseDynInst. */
104 StaticInstPtr staticInst;
106 ////////////////////////////////////////////
108 // INSTRUCTION EXECUTION
110 ////////////////////////////////////////////
111 /** InstRecord that tracks this instructions. */
112 Trace::InstRecord *traceData;
114 void demapPage(Addr vaddr, uint64_t asn)
116 cpu->demapPage(vaddr, asn);
118 void demapInstPage(Addr vaddr, uint64_t asn)
120 cpu->demapPage(vaddr, asn);
122 void demapDataPage(Addr vaddr, uint64_t asn)
124 cpu->demapPage(vaddr, asn);
128 * Does a read to a given address.
129 * @param addr The address to read.
130 * @param data The read's data is written into this parameter.
131 * @param flags The request's flags.
132 * @return Returns any fault due to the read.
135 Fault read(Addr addr, T &data, unsigned flags);
137 Fault readBytes(Addr addr, uint8_t *data, unsigned size, unsigned flags);
140 * Does a write to a given address.
141 * @param data The data to be written.
142 * @param addr The address to write to.
143 * @param flags The request's flags.
144 * @param res The result of the write (for load locked/store conditionals).
145 * @return Returns any fault due to the write.
148 Fault write(T data, Addr addr, unsigned flags, uint64_t *res);
150 Fault writeBytes(uint8_t *data, unsigned size,
151 Addr addr, unsigned flags, uint64_t *res);
153 /** Splits a request in two if it crosses a dcache block. */
154 void splitRequest(RequestPtr req, RequestPtr &sreqLow,
155 RequestPtr &sreqHigh);
157 /** Initiate a DTB address translation. */
158 void initiateTranslation(RequestPtr req, RequestPtr sreqLow,
159 RequestPtr sreqHigh, uint64_t *res,
162 /** Finish a DTB address translation. */
163 void finishTranslation(WholeTranslationState *state);
165 /** True if the DTB address translation has started. */
166 bool translationStarted;
168 /** True if the DTB address translation has completed. */
169 bool translationCompleted;
172 * Returns true if the DTB address translation is being delayed due to a hw
175 bool isTranslationDelayed() const
177 return (translationStarted && !translationCompleted);
181 * Saved memory requests (needed when the DTB address translation is
182 * delayed due to a hw page table walk).
185 RequestPtr savedSreqLow;
186 RequestPtr savedSreqHigh;
188 /** @todo: Consider making this private. */
190 /** The sequence number of the instruction. */
194 IqEntry, /// Instruction is in the IQ
195 RobEntry, /// Instruction is in the ROB
196 LsqEntry, /// Instruction is in the LSQ
197 Completed, /// Instruction has completed
198 ResultReady, /// Instruction has its result
199 CanIssue, /// Instruction can issue and execute
200 Issued, /// Instruction has issued
201 Executed, /// Instruction has executed
202 CanCommit, /// Instruction can commit
203 AtCommit, /// Instruction has reached commit
204 Committed, /// Instruction has committed
205 Squashed, /// Instruction is squashed
206 SquashedInIQ, /// Instruction is squashed in the IQ
207 SquashedInLSQ, /// Instruction is squashed in the LSQ
208 SquashedInROB, /// Instruction is squashed in the ROB
209 RecoverInst, /// Is a recover instruction
210 BlockingInst, /// Is a blocking instruction
211 ThreadsyncWait, /// Is a thread synchronization instruction
212 SerializeBefore, /// Needs to serialize on
213 /// instructions ahead of it
214 SerializeAfter, /// Needs to serialize instructions behind it
215 SerializeHandled, /// Serialization has been handled
219 /** The status of this BaseDynInst. Several bits can be set. */
220 std::bitset<NumStatus> status;
222 /** The thread this instruction is from. */
223 ThreadID threadNumber;
225 /** data address space ID, for loads & stores. */
228 /** How many source registers are ready. */
231 /** Pointer to the Impl's CPU object. */
234 /** Pointer to the thread state. */
237 /** The kind of fault this instruction has generated. */
240 /** Pointer to the data for the memory access. */
243 /** The effective virtual address (lds & stores only). */
246 /** The size of the request */
249 /** Is the effective virtual address valid. */
252 /** The effective physical address. */
255 /** Effective virtual address for a copy source. */
258 /** Effective physical address for a copy source. */
259 Addr copySrcPhysEffAddr;
261 /** The memory request flags (from translation). */
262 unsigned memReqFlags;
270 /** The result of the instruction; assumes for now that there's only one
271 * destination register.
275 /** Records changes to result? */
278 /** Did this instruction execute, or is it predicated false */
282 /** PC state for this instruction. */
285 /** Predicted PC state after this instruction. */
286 TheISA::PCState predPC;
288 /** If this is a branch that was predicted taken */
297 /** Whether or not the source register is ready.
298 * @todo: Not sure this should be here vs the derived class.
300 bool _readySrcRegIdx[MaxInstSrcRegs];
303 /** Flattened register index of the destination registers of this
306 TheISA::RegIndex _flatDestRegIdx[TheISA::MaxInstDestRegs];
308 /** Flattened register index of the source registers of this
311 TheISA::RegIndex _flatSrcRegIdx[TheISA::MaxInstSrcRegs];
313 /** Physical register index of the destination registers of this
316 PhysRegIndex _destRegIdx[TheISA::MaxInstDestRegs];
318 /** Physical register index of the source registers of this
321 PhysRegIndex _srcRegIdx[TheISA::MaxInstSrcRegs];
323 /** Physical register index of the previous producers of the
324 * architected destinations.
326 PhysRegIndex _prevDestRegIdx[TheISA::MaxInstDestRegs];
330 /** Returns the physical register index of the i'th destination
333 PhysRegIndex renamedDestRegIdx(int idx) const
335 return _destRegIdx[idx];
338 /** Returns the physical register index of the i'th source register. */
339 PhysRegIndex renamedSrcRegIdx(int idx) const
341 return _srcRegIdx[idx];
344 /** Returns the flattened register index of the i'th destination
347 TheISA::RegIndex flattenedDestRegIdx(int idx) const
349 return _flatDestRegIdx[idx];
352 /** Returns the flattened register index of the i'th source register */
353 TheISA::RegIndex flattenedSrcRegIdx(int idx) const
355 return _flatSrcRegIdx[idx];
358 /** Returns the physical register index of the previous physical register
359 * that remapped to the same logical register index.
361 PhysRegIndex prevDestRegIdx(int idx) const
363 return _prevDestRegIdx[idx];
366 /** Renames a destination register to a physical register. Also records
367 * the previous physical register that the logical register mapped to.
369 void renameDestReg(int idx,
370 PhysRegIndex renamed_dest,
371 PhysRegIndex previous_rename)
373 _destRegIdx[idx] = renamed_dest;
374 _prevDestRegIdx[idx] = previous_rename;
377 /** Renames a source logical register to the physical register which
378 * has/will produce that logical register's result.
379 * @todo: add in whether or not the source register is ready.
381 void renameSrcReg(int idx, PhysRegIndex renamed_src)
383 _srcRegIdx[idx] = renamed_src;
386 /** Flattens a source architectural register index into a logical index.
388 void flattenSrcReg(int idx, TheISA::RegIndex flattened_src)
390 _flatSrcRegIdx[idx] = flattened_src;
393 /** Flattens a destination architectural register index into a logical
396 void flattenDestReg(int idx, TheISA::RegIndex flattened_dest)
398 _flatDestRegIdx[idx] = flattened_dest;
400 /** BaseDynInst constructor given a binary instruction.
401 * @param staticInst A StaticInstPtr to the underlying instruction.
402 * @param pc The PC state for the instruction.
403 * @param predPC The predicted next PC state for the instruction.
404 * @param seq_num The sequence number of the instruction.
405 * @param cpu Pointer to the instruction's CPU.
407 BaseDynInst(StaticInstPtr staticInst, TheISA::PCState pc,
408 TheISA::PCState predPC, InstSeqNum seq_num, ImplCPU *cpu);
410 /** BaseDynInst constructor given a binary instruction.
411 * @param inst The binary instruction.
412 * @param _pc The PC state for the instruction.
413 * @param _predPC The predicted next PC state for the instruction.
414 * @param seq_num The sequence number of the instruction.
415 * @param cpu Pointer to the instruction's CPU.
417 BaseDynInst(TheISA::ExtMachInst inst, TheISA::PCState pc,
418 TheISA::PCState predPC, InstSeqNum seq_num, ImplCPU *cpu);
420 /** BaseDynInst constructor given a StaticInst pointer.
421 * @param _staticInst The StaticInst for this BaseDynInst.
423 BaseDynInst(StaticInstPtr &_staticInst);
425 /** BaseDynInst destructor. */
429 /** Function to initialize variables in the constructors. */
433 /** Dumps out contents of this BaseDynInst. */
436 /** Dumps out contents of this BaseDynInst into given string. */
437 void dump(std::string &outstring);
439 /** Read this CPU's ID. */
440 int cpuId() { return cpu->cpuId(); }
442 /** Read this context's system-wide ID **/
443 int contextId() { return thread->contextId(); }
445 /** Returns the fault type. */
446 Fault getFault() { return fault; }
448 /** Checks whether or not this instruction has had its branch target
449 * calculated yet. For now it is not utilized and is hacked to be
451 * @todo: Actually use this instruction.
453 bool doneTargCalc() { return false; }
455 /** Set the predicted target of this current instruction. */
456 void setPredTarg(const TheISA::PCState &_predPC)
461 const TheISA::PCState &readPredTarg() { return predPC; }
463 /** Returns the predicted PC immediately after the branch. */
464 Addr predInstAddr() { return predPC.instAddr(); }
466 /** Returns the predicted PC two instructions after the branch */
467 Addr predNextInstAddr() { return predPC.nextInstAddr(); }
469 /** Returns the predicted micro PC after the branch */
470 Addr predMicroPC() { return predPC.microPC(); }
472 /** Returns whether the instruction was predicted taken or not. */
478 void setPredTaken(bool predicted_taken)
480 predTaken = predicted_taken;
483 /** Returns whether the instruction mispredicted. */
486 TheISA::PCState tempPC = pc;
487 TheISA::advancePC(tempPC, staticInst);
488 return !(tempPC == predPC);
492 // Instruction types. Forward checks to StaticInst object.
494 bool isNop() const { return staticInst->isNop(); }
495 bool isMemRef() const { return staticInst->isMemRef(); }
496 bool isLoad() const { return staticInst->isLoad(); }
497 bool isStore() const { return staticInst->isStore(); }
498 bool isStoreConditional() const
499 { return staticInst->isStoreConditional(); }
500 bool isInstPrefetch() const { return staticInst->isInstPrefetch(); }
501 bool isDataPrefetch() const { return staticInst->isDataPrefetch(); }
502 bool isCopy() const { return staticInst->isCopy(); }
503 bool isInteger() const { return staticInst->isInteger(); }
504 bool isFloating() const { return staticInst->isFloating(); }
505 bool isControl() const { return staticInst->isControl(); }
506 bool isCall() const { return staticInst->isCall(); }
507 bool isReturn() const { return staticInst->isReturn(); }
508 bool isDirectCtrl() const { return staticInst->isDirectCtrl(); }
509 bool isIndirectCtrl() const { return staticInst->isIndirectCtrl(); }
510 bool isCondCtrl() const { return staticInst->isCondCtrl(); }
511 bool isUncondCtrl() const { return staticInst->isUncondCtrl(); }
512 bool isCondDelaySlot() const { return staticInst->isCondDelaySlot(); }
513 bool isThreadSync() const { return staticInst->isThreadSync(); }
514 bool isSerializing() const { return staticInst->isSerializing(); }
515 bool isSerializeBefore() const
516 { return staticInst->isSerializeBefore() || status[SerializeBefore]; }
517 bool isSerializeAfter() const
518 { return staticInst->isSerializeAfter() || status[SerializeAfter]; }
519 bool isSquashAfter() const { return staticInst->isSquashAfter(); }
520 bool isMemBarrier() const { return staticInst->isMemBarrier(); }
521 bool isWriteBarrier() const { return staticInst->isWriteBarrier(); }
522 bool isNonSpeculative() const { return staticInst->isNonSpeculative(); }
523 bool isQuiesce() const { return staticInst->isQuiesce(); }
524 bool isIprAccess() const { return staticInst->isIprAccess(); }
525 bool isUnverifiable() const { return staticInst->isUnverifiable(); }
526 bool isSyscall() const { return staticInst->isSyscall(); }
527 bool isMacroop() const { return staticInst->isMacroop(); }
528 bool isMicroop() const { return staticInst->isMicroop(); }
529 bool isDelayedCommit() const { return staticInst->isDelayedCommit(); }
530 bool isLastMicroop() const { return staticInst->isLastMicroop(); }
531 bool isFirstMicroop() const { return staticInst->isFirstMicroop(); }
532 bool isMicroBranch() const { return staticInst->isMicroBranch(); }
534 /** Temporarily sets this instruction as a serialize before instruction. */
535 void setSerializeBefore() { status.set(SerializeBefore); }
537 /** Clears the serializeBefore part of this instruction. */
538 void clearSerializeBefore() { status.reset(SerializeBefore); }
540 /** Checks if this serializeBefore is only temporarily set. */
541 bool isTempSerializeBefore() { return status[SerializeBefore]; }
543 /** Temporarily sets this instruction as a serialize after instruction. */
544 void setSerializeAfter() { status.set(SerializeAfter); }
546 /** Clears the serializeAfter part of this instruction.*/
547 void clearSerializeAfter() { status.reset(SerializeAfter); }
549 /** Checks if this serializeAfter is only temporarily set. */
550 bool isTempSerializeAfter() { return status[SerializeAfter]; }
552 /** Sets the serialization part of this instruction as handled. */
553 void setSerializeHandled() { status.set(SerializeHandled); }
555 /** Checks if the serialization part of this instruction has been
556 * handled. This does not apply to the temporary serializing
557 * state; it only applies to this instruction's own permanent
560 bool isSerializeHandled() { return status[SerializeHandled]; }
562 /** Returns the opclass of this instruction. */
563 OpClass opClass() const { return staticInst->opClass(); }
565 /** Returns the branch target address. */
566 TheISA::PCState branchTarget() const
567 { return staticInst->branchTarget(pc); }
569 /** Returns the number of source registers. */
570 int8_t numSrcRegs() const { return staticInst->numSrcRegs(); }
572 /** Returns the number of destination registers. */
573 int8_t numDestRegs() const { return staticInst->numDestRegs(); }
575 // the following are used to track physical register usage
576 // for machines with separate int & FP reg files
577 int8_t numFPDestRegs() const { return staticInst->numFPDestRegs(); }
578 int8_t numIntDestRegs() const { return staticInst->numIntDestRegs(); }
580 /** Returns the logical register index of the i'th destination register. */
581 RegIndex destRegIdx(int i) const { return staticInst->destRegIdx(i); }
583 /** Returns the logical register index of the i'th source register. */
584 RegIndex srcRegIdx(int i) const { return staticInst->srcRegIdx(i); }
586 /** Returns the result of an integer instruction. */
587 uint64_t readIntResult() { return instResult.integer; }
589 /** Returns the result of a floating point instruction. */
590 float readFloatResult() { return (float)instResult.dbl; }
592 /** Returns the result of a floating point (double) instruction. */
593 double readDoubleResult() { return instResult.dbl; }
595 /** Records an integer register being set to a value. */
596 void setIntRegOperand(const StaticInst *si, int idx, uint64_t val)
599 instResult.integer = val;
602 /** Records an fp register being set to a value. */
603 void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val,
608 instResult.dbl = (double)val;
609 else if (width == 64)
610 instResult.dbl = val;
612 panic("Unsupported width!");
616 /** Records an fp register being set to a value. */
617 void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val)
620 instResult.dbl = (double)val;
623 /** Records an fp register being set to an integer value. */
624 void setFloatRegOperandBits(const StaticInst *si, int idx, uint64_t val,
628 instResult.integer = val;
631 /** Records an fp register being set to an integer value. */
632 void setFloatRegOperandBits(const StaticInst *si, int idx, uint64_t val)
635 instResult.integer = val;
638 /** Records that one of the source registers is ready. */
639 void markSrcRegReady();
641 /** Marks a specific register as ready. */
642 void markSrcRegReady(RegIndex src_idx);
644 /** Returns if a source register is ready. */
645 bool isReadySrcRegIdx(int idx) const
647 return this->_readySrcRegIdx[idx];
650 /** Sets this instruction as completed. */
651 void setCompleted() { status.set(Completed); }
653 /** Returns whether or not this instruction is completed. */
654 bool isCompleted() const { return status[Completed]; }
656 /** Marks the result as ready. */
657 void setResultReady() { status.set(ResultReady); }
659 /** Returns whether or not the result is ready. */
660 bool isResultReady() const { return status[ResultReady]; }
662 /** Sets this instruction as ready to issue. */
663 void setCanIssue() { status.set(CanIssue); }
665 /** Returns whether or not this instruction is ready to issue. */
666 bool readyToIssue() const { return status[CanIssue]; }
668 /** Clears this instruction being able to issue. */
669 void clearCanIssue() { status.reset(CanIssue); }
671 /** Sets this instruction as issued from the IQ. */
672 void setIssued() { status.set(Issued); }
674 /** Returns whether or not this instruction has issued. */
675 bool isIssued() const { return status[Issued]; }
677 /** Clears this instruction as being issued. */
678 void clearIssued() { status.reset(Issued); }
680 /** Sets this instruction as executed. */
681 void setExecuted() { status.set(Executed); }
683 /** Returns whether or not this instruction has executed. */
684 bool isExecuted() const { return status[Executed]; }
686 /** Sets this instruction as ready to commit. */
687 void setCanCommit() { status.set(CanCommit); }
689 /** Clears this instruction as being ready to commit. */
690 void clearCanCommit() { status.reset(CanCommit); }
692 /** Returns whether or not this instruction is ready to commit. */
693 bool readyToCommit() const { return status[CanCommit]; }
695 void setAtCommit() { status.set(AtCommit); }
697 bool isAtCommit() { return status[AtCommit]; }
699 /** Sets this instruction as committed. */
700 void setCommitted() { status.set(Committed); }
702 /** Returns whether or not this instruction is committed. */
703 bool isCommitted() const { return status[Committed]; }
705 /** Sets this instruction as squashed. */
706 void setSquashed() { status.set(Squashed); }
708 /** Returns whether or not this instruction is squashed. */
709 bool isSquashed() const { return status[Squashed]; }
711 //Instruction Queue Entry
712 //-----------------------
713 /** Sets this instruction as a entry the IQ. */
714 void setInIQ() { status.set(IqEntry); }
716 /** Sets this instruction as a entry the IQ. */
717 void clearInIQ() { status.reset(IqEntry); }
719 /** Returns whether or not this instruction has issued. */
720 bool isInIQ() const { return status[IqEntry]; }
722 /** Sets this instruction as squashed in the IQ. */
723 void setSquashedInIQ() { status.set(SquashedInIQ); status.set(Squashed);}
725 /** Returns whether or not this instruction is squashed in the IQ. */
726 bool isSquashedInIQ() const { return status[SquashedInIQ]; }
729 //Load / Store Queue Functions
730 //-----------------------
731 /** Sets this instruction as a entry the LSQ. */
732 void setInLSQ() { status.set(LsqEntry); }
734 /** Sets this instruction as a entry the LSQ. */
735 void removeInLSQ() { status.reset(LsqEntry); }
737 /** Returns whether or not this instruction is in the LSQ. */
738 bool isInLSQ() const { return status[LsqEntry]; }
740 /** Sets this instruction as squashed in the LSQ. */
741 void setSquashedInLSQ() { status.set(SquashedInLSQ);}
743 /** Returns whether or not this instruction is squashed in the LSQ. */
744 bool isSquashedInLSQ() const { return status[SquashedInLSQ]; }
747 //Reorder Buffer Functions
748 //-----------------------
749 /** Sets this instruction as a entry the ROB. */
750 void setInROB() { status.set(RobEntry); }
752 /** Sets this instruction as a entry the ROB. */
753 void clearInROB() { status.reset(RobEntry); }
755 /** Returns whether or not this instruction is in the ROB. */
756 bool isInROB() const { return status[RobEntry]; }
758 /** Sets this instruction as squashed in the ROB. */
759 void setSquashedInROB() { status.set(SquashedInROB); }
761 /** Returns whether or not this instruction is squashed in the ROB. */
762 bool isSquashedInROB() const { return status[SquashedInROB]; }
764 /** Read the PC state of this instruction. */
765 const TheISA::PCState pcState() const { return pc; }
767 /** Set the PC state of this instruction. */
768 const void pcState(const TheISA::PCState &val) { pc = val; }
770 /** Read the PC of this instruction. */
771 const Addr instAddr() const { return pc.instAddr(); }
773 /** Read the PC of the next instruction. */
774 const Addr nextInstAddr() const { return pc.nextInstAddr(); }
776 /**Read the micro PC of this instruction. */
777 const Addr microPC() const { return pc.microPC(); }
784 void setPredicate(bool val)
789 traceData->setPredicate(val);
793 /** Sets the ASID. */
794 void setASID(short addr_space_id) { asid = addr_space_id; }
796 /** Sets the thread id. */
797 void setTid(ThreadID tid) { threadNumber = tid; }
799 /** Sets the pointer to the thread state. */
800 void setThreadState(ImplState *state) { thread = state; }
802 /** Returns the thread context. */
803 ThreadContext *tcBase() { return thread->getTC(); }
806 /** Instruction effective address.
807 * @todo: Consider if this is necessary or not.
811 /** Whether or not the effective address calculation is completed.
812 * @todo: Consider if this is necessary or not.
816 /** Is this instruction's memory access uncacheable. */
819 /** Has this instruction generated a memory request. */
823 /** Sets the effective address. */
824 void setEA(Addr &ea) { instEffAddr = ea; eaCalcDone = true; }
826 /** Returns the effective address. */
827 const Addr &getEA() const { return instEffAddr; }
829 /** Returns whether or not the eff. addr. calculation has been completed. */
830 bool doneEACalc() { return eaCalcDone; }
832 /** Returns whether or not the eff. addr. source registers are ready. */
835 /** Whether or not the memory operation is done. */
838 /** Is this instruction's memory access uncacheable. */
839 bool uncacheable() { return isUncacheable; }
841 /** Has this instruction generated a memory request. */
842 bool hasRequest() { return reqMade; }
845 /** Load queue index. */
848 /** Store queue index. */
851 /** Iterator pointing to this BaseDynInst in the list of all insts. */
854 /** Returns iterator to this instruction in the list of all insts. */
855 ListIt &getInstListIt() { return instListIt; }
857 /** Sets iterator for this instruction in the list of all insts. */
858 void setInstListIt(ListIt _instListIt) { instListIt = _instListIt; }
861 /** Returns the number of consecutive store conditional failures. */
862 unsigned readStCondFailures()
863 { return thread->storeCondFailures; }
865 /** Sets the number of consecutive store conditional failures. */
866 void setStCondFailures(unsigned sc_failures)
867 { thread->storeCondFailures = sc_failures; }
872 BaseDynInst<Impl>::readBytes(Addr addr, uint8_t *data,
873 unsigned size, unsigned flags)
877 Request *sreqLow = NULL;
878 Request *sreqHigh = NULL;
880 if (reqMade && translationStarted) {
882 sreqLow = savedSreqLow;
883 sreqHigh = savedSreqHigh;
885 req = new Request(asid, addr, size, flags, this->pc.instAddr(),
886 thread->contextId(), threadNumber);
888 // Only split the request if the ISA supports unaligned accesses.
889 if (TheISA::HasUnalignedMemAcc) {
890 splitRequest(req, sreqLow, sreqHigh);
892 initiateTranslation(req, sreqLow, sreqHigh, NULL, BaseTLB::Read);
895 if (translationCompleted) {
896 if (fault == NoFault) {
897 effAddr = req->getVaddr();
900 fault = cpu->read(req, sreqLow, sreqHigh, data, lqIdx);
902 // Commit will have to clean up whatever happened. Set this
903 // instruction as executed.
907 if (fault != NoFault) {
908 // Return a fixed value to keep simulation deterministic even
909 // along misspeculated paths.
916 traceData->setAddr(addr);
925 BaseDynInst<Impl>::read(Addr addr, T &data, unsigned flags)
927 Fault fault = readBytes(addr, (uint8_t *)&data, sizeof(T), flags);
929 data = TheISA::gtoh(data);
932 traceData->setData(data);
940 BaseDynInst<Impl>::writeBytes(uint8_t *data, unsigned size,
941 Addr addr, unsigned flags, uint64_t *res)
944 traceData->setAddr(addr);
949 Request *sreqLow = NULL;
950 Request *sreqHigh = NULL;
952 if (reqMade && translationStarted) {
954 sreqLow = savedSreqLow;
955 sreqHigh = savedSreqHigh;
957 req = new Request(asid, addr, size, flags, this->pc.instAddr(),
958 thread->contextId(), threadNumber);
960 // Only split the request if the ISA supports unaligned accesses.
961 if (TheISA::HasUnalignedMemAcc) {
962 splitRequest(req, sreqLow, sreqHigh);
964 initiateTranslation(req, sreqLow, sreqHigh, res, BaseTLB::Write);
967 if (fault == NoFault && translationCompleted) {
968 effAddr = req->getVaddr();
971 fault = cpu->write(req, sreqLow, sreqHigh, data, sqIdx);
980 BaseDynInst<Impl>::write(T data, Addr addr, unsigned flags, uint64_t *res)
983 traceData->setData(data);
985 data = TheISA::htog(data);
986 return writeBytes((uint8_t *)&data, sizeof(T), addr, flags, res);
991 BaseDynInst<Impl>::splitRequest(RequestPtr req, RequestPtr &sreqLow,
992 RequestPtr &sreqHigh)
994 // Check to see if the request crosses the next level block boundary.
995 unsigned block_size = cpu->getDcachePort()->peerBlockSize();
996 Addr addr = req->getVaddr();
997 Addr split_addr = roundDown(addr + req->getSize() - 1, block_size);
998 assert(split_addr <= addr || split_addr - addr < block_size);
1000 // Spans two blocks.
1001 if (split_addr > addr) {
1002 req->splitOnVaddr(split_addr, sreqLow, sreqHigh);
1006 template<class Impl>
1008 BaseDynInst<Impl>::initiateTranslation(RequestPtr req, RequestPtr sreqLow,
1009 RequestPtr sreqHigh, uint64_t *res,
1012 translationStarted = true;
1014 if (!TheISA::HasUnalignedMemAcc || sreqLow == NULL) {
1015 WholeTranslationState *state =
1016 new WholeTranslationState(req, NULL, res, mode);
1018 // One translation if the request isn't split.
1019 DataTranslation<BaseDynInst<Impl> > *trans =
1020 new DataTranslation<BaseDynInst<Impl> >(this, state);
1021 cpu->dtb->translateTiming(req, thread->getTC(), trans, mode);
1022 if (!translationCompleted) {
1023 // Save memory requests.
1024 savedReq = state->mainReq;
1025 savedSreqLow = state->sreqLow;
1026 savedSreqHigh = state->sreqHigh;
1029 WholeTranslationState *state =
1030 new WholeTranslationState(req, sreqLow, sreqHigh, NULL, res, mode);
1032 // Two translations when the request is split.
1033 DataTranslation<BaseDynInst<Impl> > *stransLow =
1034 new DataTranslation<BaseDynInst<Impl> >(this, state, 0);
1035 DataTranslation<BaseDynInst<Impl> > *stransHigh =
1036 new DataTranslation<BaseDynInst<Impl> >(this, state, 1);
1038 cpu->dtb->translateTiming(sreqLow, thread->getTC(), stransLow, mode);
1039 cpu->dtb->translateTiming(sreqHigh, thread->getTC(), stransHigh, mode);
1040 if (!translationCompleted) {
1041 // Save memory requests.
1042 savedReq = state->mainReq;
1043 savedSreqLow = state->sreqLow;
1044 savedSreqHigh = state->sreqHigh;
1049 template<class Impl>
1051 BaseDynInst<Impl>::finishTranslation(WholeTranslationState *state)
1053 fault = state->getFault();
1055 if (state->isUncacheable())
1056 isUncacheable = true;
1058 if (fault == NoFault) {
1059 physEffAddr = state->getPaddr();
1060 memReqFlags = state->getFlags();
1062 if (state->mainReq->isCondSwap()) {
1064 state->mainReq->setExtraData(*state->res);
1068 state->deleteReqs();
1072 translationCompleted = true;
1075 #endif // __CPU_BASE_DYN_INST_HH__