8e88fc583b6a112ee82beb61bb7e78fdd45d1043
[gem5.git] / src / cpu / inorder / inorder_dyn_inst.hh
1 /*
2 * Copyright (c) 2007 MIPS Technologies, Inc.
3 * Copyright (c) 2004-2006 The Regents of The University of Michigan
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Authors: Kevin Lim
30 * Korey Sewell
31 */
32
33 #ifndef __CPU_INORDER_DYN_INST_HH__
34 #define __CPU_INORDER_DYN_INST_HH__
35
36 #include <bitset>
37 #include <list>
38 #include <string>
39
40 #include "arch/isa_traits.hh"
41 #include "arch/faults.hh"
42 #include "arch/types.hh"
43 #include "arch/mt.hh"
44 #include "base/fast_alloc.hh"
45 #include "base/trace.hh"
46 #include "cpu/inorder/inorder_trace.hh"
47 #include "config/full_system.hh"
48 #include "cpu/thread_context.hh"
49 #include "cpu/exetrace.hh"
50 #include "cpu/inst_seq.hh"
51 #include "cpu/op_class.hh"
52 #include "cpu/static_inst.hh"
53 #include "cpu/inorder/thread_state.hh"
54 #include "cpu/inorder/resource.hh"
55 #include "cpu/inorder/pipeline_traits.hh"
56 #include "mem/packet.hh"
57 #include "sim/system.hh"
58
59 /**
60 * @file
61 * Defines a dynamic instruction context for a inorder CPU model.
62 */
63
64 // Forward declaration.
65 class StaticInstPtr;
66 class ResourceRequest;
67
68 class InOrderDynInst : public FastAlloc, public RefCounted
69 {
70 public:
71 // Binary machine instruction type.
72 typedef TheISA::MachInst MachInst;
73 // Extended machine instruction type
74 typedef TheISA::ExtMachInst ExtMachInst;
75 // Logical register index type.
76 typedef TheISA::RegIndex RegIndex;
77 // Integer register type.
78 typedef TheISA::IntReg IntReg;
79 // Floating point register type.
80 typedef TheISA::FloatReg FloatReg;
81 // Floating point register type.
82 typedef TheISA::MiscReg MiscReg;
83
84 typedef short int PhysRegIndex;
85
86 /** The refcounted DynInst pointer to be used. In most cases this is
87 * what should be used, and not DynInst*.
88 */
89 typedef RefCountingPtr<InOrderDynInst> DynInstPtr;
90
91 // The list of instructions iterator type.
92 typedef std::list<DynInstPtr>::iterator ListIt;
93
94 enum {
95 MaxInstSrcRegs = TheISA::MaxInstSrcRegs, /// Max source regs
96 MaxInstDestRegs = TheISA::MaxInstDestRegs, /// Max dest regs
97 };
98
99 public:
100 /** BaseDynInst constructor given a binary instruction.
101 * @param inst The binary instruction.
102 * @param PC The PC of the instruction.
103 * @param pred_PC The predicted next PC.
104 * @param seq_num The sequence number of the instruction.
105 * @param cpu Pointer to the instruction's CPU.
106 */
107 InOrderDynInst(ExtMachInst inst, Addr PC, Addr pred_PC, InstSeqNum seq_num,
108 InOrderCPU *cpu);
109
110 /** BaseDynInst constructor given a binary instruction.
111 * @param seq_num The sequence number of the instruction.
112 * @param cpu Pointer to the instruction's CPU.
113 * NOTE: Must set Binary Instrution through Member Function
114 */
115 InOrderDynInst(InOrderCPU *cpu, InOrderThreadState *state, InstSeqNum seq_num,
116 unsigned tid);
117
118 /** BaseDynInst constructor given a StaticInst pointer.
119 * @param _staticInst The StaticInst for this BaseDynInst.
120 */
121 InOrderDynInst(StaticInstPtr &_staticInst);
122
123 /** Skeleton Constructor. */
124 InOrderDynInst();
125
126 /** InOrderDynInst destructor. */
127 ~InOrderDynInst();
128
129 public:
130 /** The sequence number of the instruction. */
131 InstSeqNum seqNum;
132
133 /** The sequence number of the instruction. */
134 InstSeqNum bdelaySeqNum;
135
136 enum Status {
137 RegDepMapEntry, /// Instruction has been entered onto the RegDepMap
138 IqEntry, /// Instruction is in the IQ
139 RobEntry, /// Instruction is in the ROB
140 LsqEntry, /// Instruction is in the LSQ
141 Completed, /// Instruction has completed
142 ResultReady, /// Instruction has its result
143 CanIssue, /// Instruction can issue and execute
144 Issued, /// Instruction has issued
145 Executed, /// Instruction has executed
146 CanCommit, /// Instruction can commit
147 AtCommit, /// Instruction has reached commit
148 Committed, /// Instruction has committed
149 Squashed, /// Instruction is squashed
150 SquashedInIQ, /// Instruction is squashed in the IQ
151 SquashedInLSQ, /// Instruction is squashed in the LSQ
152 SquashedInROB, /// Instruction is squashed in the ROB
153 RecoverInst, /// Is a recover instruction
154 BlockingInst, /// Is a blocking instruction
155 ThreadsyncWait, /// Is a thread synchronization instruction
156 SerializeBefore, /// Needs to serialize on
157 /// instructions ahead of it
158 SerializeAfter, /// Needs to serialize instructions behind it
159 SerializeHandled, /// Serialization has been handled
160 NumStatus
161 };
162
163 /** The status of this BaseDynInst. Several bits can be set. */
164 std::bitset<NumStatus> status;
165
166 /** The thread this instruction is from. */
167 short threadNumber;
168
169 /** data address space ID, for loads & stores. */
170 short asid;
171
172 /** The virtual processor number */
173 short virtProcNumber;
174
175 /** The StaticInst used by this BaseDynInst. */
176 StaticInstPtr staticInst;
177
178 /** InstRecord that tracks this instructions. */
179 Trace::InOrderTraceRecord *traceData;
180
181 /** Pointer to the Impl's CPU object. */
182 InOrderCPU *cpu;
183
184 /** Pointer to the thread state. */
185 InOrderThreadState *thread;
186
187 /** The kind of fault this instruction has generated. */
188 Fault fault;
189
190 /** The memory request. */
191 Request *req;
192
193 /** Pointer to the data for the memory access. */
194 uint8_t *memData;
195
196 /** Data used for a store for operation. */
197 uint64_t loadData;
198
199 /** Data used for a store for operation. */
200 uint64_t storeData;
201
202 /** The resource schedule for this inst */
203 ThePipeline::ResSchedule resSched;
204
205 /** List of active resource requests for this instruction */
206 std::list<ResourceRequest*> reqList;
207
208 /** The effective virtual address (lds & stores only). */
209 Addr effAddr;
210
211 /** The effective physical address. */
212 Addr physEffAddr;
213
214 /** Effective virtual address for a copy source. */
215 Addr copySrcEffAddr;
216
217 /** Effective physical address for a copy source. */
218 Addr copySrcPhysEffAddr;
219
220 /** The memory request flags (from translation). */
221 unsigned memReqFlags;
222
223 /** How many source registers are ready. */
224 unsigned readyRegs;
225
226 /** An instruction src/dest has to be one of these types */
227 union InstValue {
228 uint64_t integer;
229 float fp;
230 double dbl;
231 };
232
233 /** Result of an instruction execution */
234 struct InstResult {
235 InstValue val;
236 Tick tick;
237 };
238
239 /** The source of the instruction; assumes for now that there's only one
240 * destination register.
241 */
242 InstValue instSrc[MaxInstSrcRegs];
243
244 /** The result of the instruction; assumes for now that there's only one
245 * destination register.
246 */
247 InstResult instResult[MaxInstDestRegs];
248
249 /** PC of this instruction. */
250 Addr PC;
251
252 /** Next non-speculative PC. It is not filled in at fetch, but rather
253 * once the target of the branch is truly known (either decode or
254 * execute).
255 */
256 Addr nextPC;
257
258 /** Next next non-speculative PC. It is not filled in at fetch, but rather
259 * once the target of the branch is truly known (either decode or
260 * execute).
261 */
262 Addr nextNPC;
263
264 /** Predicted next PC. */
265 Addr predPC;
266
267 /** Predicted next NPC. */
268 Addr predNPC;
269
270 /** Predicted next microPC */
271 Addr predMicroPC;
272
273 /** Address to fetch from */
274 Addr fetchAddr;
275
276 /** Address to get/write data from/to */
277 Addr memAddr;
278
279 /** Whether or not the source register is ready.
280 * @todo: Not sure this should be here vs the derived class.
281 */
282 bool _readySrcRegIdx[MaxInstSrcRegs];
283
284 /** Physical register index of the destination registers of this
285 * instruction.
286 */
287 PhysRegIndex _destRegIdx[MaxInstDestRegs];
288
289 /** Physical register index of the source registers of this
290 * instruction.
291 */
292 PhysRegIndex _srcRegIdx[MaxInstSrcRegs];
293
294 /** Physical register index of the previous producers of the
295 * architected destinations.
296 */
297 PhysRegIndex _prevDestRegIdx[MaxInstDestRegs];
298
299 int nextStage;
300
301 /* vars to keep track of InstStage's - used for resource sched defn */
302 int nextInstStageNum;
303 ThePipeline::InstStage *currentInstStage;
304 std::list<ThePipeline::InstStage*> instStageList;
305
306 private:
307 /** Function to initialize variables in the constructors. */
308 void initVars();
309
310 public:
311 Tick memTime;
312
313 ////////////////////////////////////////////////////////////
314 //
315 // BASE INSTRUCTION INFORMATION.
316 //
317 ////////////////////////////////////////////////////////////
318 void setMachInst(ExtMachInst inst);
319
320 /** Sets the StaticInst. */
321 void setStaticInst(StaticInstPtr &static_inst);
322
323 /** Sets the sequence number. */
324 void setSeqNum(InstSeqNum seq_num) { seqNum = seq_num; }
325
326 /** Sets the ASID. */
327 void setASID(short addr_space_id) { asid = addr_space_id; }
328
329 /** Reads the thread id. */
330 short readTid() { return threadNumber; }
331
332 /** Sets the thread id. */
333 void setTid(unsigned tid) { threadNumber = tid; }
334
335 void setVpn(int id) { virtProcNumber = id; }
336
337 int readVpn() { return virtProcNumber; }
338
339 /** Sets the pointer to the thread state. */
340 void setThreadState(InOrderThreadState *state) { thread = state; }
341
342 /** Returns the thread context. */
343 ThreadContext *tcBase() { return thread->getTC(); }
344
345 /** Returns the fault type. */
346 Fault getFault() { return fault; }
347
348 ////////////////////////////////////////////////////////////
349 //
350 // INSTRUCTION TYPES - Forward checks to StaticInst object.
351 //
352 ////////////////////////////////////////////////////////////
353 bool isNop() const { return staticInst->isNop(); }
354 bool isMemRef() const { return staticInst->isMemRef(); }
355 bool isLoad() const { return staticInst->isLoad(); }
356 bool isStore() const { return staticInst->isStore(); }
357 bool isStoreConditional() const
358 { return staticInst->isStoreConditional(); }
359 bool isInstPrefetch() const { return staticInst->isInstPrefetch(); }
360 bool isDataPrefetch() const { return staticInst->isDataPrefetch(); }
361 bool isCopy() const { return staticInst->isCopy(); }
362 bool isInteger() const { return staticInst->isInteger(); }
363 bool isFloating() const { return staticInst->isFloating(); }
364 bool isControl() const { return staticInst->isControl(); }
365 bool isCall() const { return staticInst->isCall(); }
366 bool isReturn() const { return staticInst->isReturn(); }
367 bool isDirectCtrl() const { return staticInst->isDirectCtrl(); }
368 bool isIndirectCtrl() const { return staticInst->isIndirectCtrl(); }
369 bool isCondCtrl() const { return staticInst->isCondCtrl(); }
370 bool isUncondCtrl() const { return staticInst->isUncondCtrl(); }
371 bool isCondDelaySlot() const { return staticInst->isCondDelaySlot(); }
372
373 bool isThreadSync() const { return staticInst->isThreadSync(); }
374 bool isSerializing() const { return staticInst->isSerializing(); }
375 bool isSerializeBefore() const
376 { return staticInst->isSerializeBefore() || status[SerializeBefore]; }
377 bool isSerializeAfter() const
378 { return staticInst->isSerializeAfter() || status[SerializeAfter]; }
379 bool isMemBarrier() const { return staticInst->isMemBarrier(); }
380 bool isWriteBarrier() const { return staticInst->isWriteBarrier(); }
381 bool isNonSpeculative() const { return staticInst->isNonSpeculative(); }
382 bool isQuiesce() const { return staticInst->isQuiesce(); }
383 bool isIprAccess() const { return staticInst->isIprAccess(); }
384 bool isUnverifiable() const { return staticInst->isUnverifiable(); }
385
386 /////////////////////////////////////////////
387 //
388 // RESOURCE SCHEDULING
389 //
390 /////////////////////////////////////////////
391
392 void setNextStage(int stage_num) { nextStage = stage_num; }
393 int getNextStage() { return nextStage; }
394
395 ThePipeline::InstStage *addStage();
396 ThePipeline::InstStage *addStage(int stage);
397 ThePipeline::InstStage *currentStage() { return currentInstStage; }
398 void deleteStages();
399
400 /** Add A Entry To Reource Schedule */
401 void addToSched(ThePipeline::ScheduleEntry* sched_entry)
402 { resSched.push(sched_entry); }
403
404
405 /** Print Resource Schedule */
406 void printSched()
407 {
408 using namespace ThePipeline;
409
410 ResSchedule tempSched;
411 std::cerr << "\tInst. Res. Schedule: ";
412 while (!resSched.empty()) {
413 std::cerr << '\t' << resSched.top()->stageNum << "-"
414 << resSched.top()->resNum << ", ";
415
416 tempSched.push(resSched.top());
417 resSched.pop();
418 }
419
420 std::cerr << std::endl;
421 resSched = tempSched;
422 }
423
424 /** Return Next Resource Stage To Be Used */
425 int nextResStage()
426 {
427 if (resSched.empty())
428 return -1;
429 else
430 return resSched.top()->stageNum;
431 }
432
433
434 /** Return Next Resource To Be Used */
435 int nextResource()
436 {
437 if (resSched.empty())
438 return -1;
439 else
440 return resSched.top()->resNum;
441 }
442
443 /** Remove & Deallocate a schedule entry */
444 void popSchedEntry()
445 {
446 if (!resSched.empty()) {
447 ThePipeline::ScheduleEntry* sked = resSched.top();
448 resSched.pop();
449 delete sked;
450 }
451 }
452
453 /** Release a Resource Request (Currently Unused) */
454 void releaseReq(ResourceRequest* req);
455
456 ////////////////////////////////////////////
457 //
458 // INSTRUCTION EXECUTION
459 //
460 ////////////////////////////////////////////
461 /** Returns the opclass of this instruction. */
462 OpClass opClass() const { return staticInst->opClass(); }
463
464 /** Executes the instruction.*/
465 Fault execute();
466
467 unsigned curResSlot;
468
469 unsigned getCurResSlot() { return curResSlot; }
470
471 void setCurResSlot(unsigned slot_num) { curResSlot = slot_num; }
472
473 /** Calls a syscall. */
474 void syscall(int64_t callnum);
475 void prefetch(Addr addr, unsigned flags);
476 void writeHint(Addr addr, int size, unsigned flags);
477 Fault copySrcTranslate(Addr src);
478 Fault copy(Addr dest);
479
480 ////////////////////////////////////////////////////////////
481 //
482 // MULTITHREADING INTERFACE TO CPU MODELS
483 //
484 ////////////////////////////////////////////////////////////
485 virtual void deallocateContext(int thread_num);
486
487 virtual void enableVirtProcElement(unsigned vpe);
488 virtual void disableVirtProcElement(unsigned vpe);
489
490 virtual void enableMultiThreading(unsigned vpe);
491 virtual void disableMultiThreading(unsigned vpe);
492
493 ////////////////////////////////////////////////////////////
494 //
495 // PROGRAM COUNTERS - PC/NPC/NPC
496 //
497 ////////////////////////////////////////////////////////////
498 /** Read the PC of this instruction. */
499 const Addr readPC() const { return PC; }
500
501 /** Sets the PC of this instruction. */
502 void setPC(Addr pc) { PC = pc; }
503
504 /** Returns the next PC. This could be the speculative next PC if it is
505 * called prior to the actual branch target being calculated.
506 */
507 Addr readNextPC() { return nextPC; }
508
509 /** Set the next PC of this instruction (its actual target). */
510 void setNextPC(uint64_t val) { nextPC = val; }
511
512 /** Returns the next NPC. This could be the speculative next NPC if it is
513 * called prior to the actual branch target being calculated.
514 */
515 Addr readNextNPC()
516 {
517 #if ISA_HAS_DELAY_SLOT
518 return nextNPC;
519 #else
520 return nextPC + sizeof(TheISA::MachInst);
521 #endif
522 }
523
524 /** Set the next PC of this instruction (its actual target). */
525 void setNextNPC(uint64_t val) { nextNPC = val; }
526
527 ////////////////////////////////////////////////////////////
528 //
529 // BRANCH PREDICTION
530 //
531 ////////////////////////////////////////////////////////////
532 /** Set the predicted target of this current instruction. */
533 void setPredTarg(Addr predicted_PC) { predPC = predicted_PC; }
534
535 /** Returns the predicted target of the branch. */
536 Addr readPredTarg() { return predPC; }
537
538 /** Returns the predicted PC immediately after the branch. */
539 Addr readPredPC() { return predPC; }
540
541 /** Returns the predicted PC two instructions after the branch */
542 Addr readPredNPC() { return predNPC; }
543
544 /** Returns the predicted micro PC after the branch */
545 Addr readPredMicroPC() { return predMicroPC; }
546
547 /** Returns whether the instruction was predicted taken or not. */
548 bool predTaken() { return predictTaken; }
549
550 /** Returns whether the instruction mispredicted. */
551 bool mispredicted()
552 {
553 #if ISA_HAS_DELAY_SLOT
554 return predPC != nextNPC;
555 #else
556 return predPC != nextPC;
557 #endif
558 }
559
560 /** Returns whether the instruction mispredicted. */
561 bool mistargeted() { return predPC != nextNPC; }
562
563 /** Returns the branch target address. */
564 Addr branchTarget() const { return staticInst->branchTarget(PC); }
565
566 /** Checks whether or not this instruction has had its branch target
567 * calculated yet. For now it is not utilized and is hacked to be
568 * always false.
569 * @todo: Actually use this instruction.
570 */
571 bool doneTargCalc() { return false; }
572
573 void setBranchPred(bool prediction) { predictTaken = prediction; }
574
575 int squashingStage;
576
577 bool predictTaken;
578
579 bool procDelaySlotOnMispred;
580
581 ////////////////////////////////////////////
582 //
583 // MEMORY ACCESS
584 //
585 ////////////////////////////////////////////
586 /**
587 * Does a read to a given address.
588 * @param addr The address to read.
589 * @param data The read's data is written into this parameter.
590 * @param flags The request's flags.
591 * @return Returns any fault due to the read.
592 */
593 template <class T>
594 Fault read(Addr addr, T &data, unsigned flags);
595
596 /**
597 * Does a write to a given address.
598 * @param data The data to be written.
599 * @param addr The address to write to.
600 * @param flags The request's flags.
601 * @param res The result of the write (for load locked/store conditionals).
602 * @return Returns any fault due to the write.
603 */
604 template <class T>
605 Fault write(T data, Addr addr, unsigned flags,
606 uint64_t *res);
607
608 /** Initiates a memory access - Calculate Eff. Addr & Initiate Memory Access
609 * Only valid for memory operations.
610 */
611 Fault initiateAcc();
612
613 /** Completes a memory access - Only valid for memory operations. */
614 Fault completeAcc(Packet *pkt);
615
616 /** Calculates Eff. Addr. part of a memory instruction. */
617 Fault calcEA();
618
619 /** Read Effective Address from instruction & do memory access */
620 Fault memAccess();
621
622 RequestPtr memReq;
623
624 bool memAddrReady;
625
626 bool validMemAddr()
627 { return memAddrReady; }
628
629 void setMemAddr(Addr addr)
630 { memAddr = addr; memAddrReady = true;}
631
632 void unsetMemAddr()
633 { memAddrReady = false;}
634
635 Addr getMemAddr()
636 { return memAddr; }
637
638 int getMemAccSize() { return staticInst->memAccSize(this); }
639
640 int getMemFlags() { return staticInst->memAccFlags(); }
641
642 /** Sets the effective address. */
643 void setEA(Addr &ea) { instEffAddr = ea; eaCalcDone = true; }
644
645 /** Returns the effective address. */
646 const Addr &getEA() const { return instEffAddr; }
647
648 /** Returns whether or not the eff. addr. calculation has been completed. */
649 bool doneEACalc() { return eaCalcDone; }
650
651 /** Returns whether or not the eff. addr. source registers are ready.
652 * Assume that src registers 1..n-1 are the ones that the
653 * EA calc depends on. (i.e. src reg 0 is the source of the data to be
654 * stored)
655 */
656 bool eaSrcsReady()
657 {
658 for (int i = 1; i < numSrcRegs(); ++i) {
659 if (!_readySrcRegIdx[i])
660 return false;
661 }
662
663 return true;
664 }
665
666 //////////////////////////////////////////////////
667 //
668 // SOURCE-DESTINATION REGISTER INDEXING
669 //
670 //////////////////////////////////////////////////
671 /** Returns the number of source registers. */
672 int8_t numSrcRegs() const { return staticInst->numSrcRegs(); }
673
674 /** Returns the number of destination registers. */
675 int8_t numDestRegs() const { return staticInst->numDestRegs(); }
676
677 // the following are used to track physical register usage
678 // for machines with separate int & FP reg files
679 int8_t numFPDestRegs() const { return staticInst->numFPDestRegs(); }
680 int8_t numIntDestRegs() const { return staticInst->numIntDestRegs(); }
681
682 /** Returns the logical register index of the i'th destination register. */
683 RegIndex destRegIdx(int i) const { return staticInst->destRegIdx(i); }
684
685 /** Returns the logical register index of the i'th source register. */
686 RegIndex srcRegIdx(int i) const { return staticInst->srcRegIdx(i); }
687
688 //////////////////////////////////////////////////
689 //
690 // RENAME/PHYSICAL REGISTER FILE SUPPORT
691 //
692 //////////////////////////////////////////////////
693 /** Returns the physical register index of the i'th destination
694 * register.
695 */
696 PhysRegIndex renamedDestRegIdx(int idx) const
697 {
698 return _destRegIdx[idx];
699 }
700
701 /** Returns the physical register index of the i'th source register. */
702 PhysRegIndex renamedSrcRegIdx(int idx) const
703 {
704 return _srcRegIdx[idx];
705 }
706
707 /** Returns the physical register index of the previous physical register
708 * that remapped to the same logical register index.
709 */
710 PhysRegIndex prevDestRegIdx(int idx) const
711 {
712 return _prevDestRegIdx[idx];
713 }
714
715 /** Returns if a source register is ready. */
716 bool isReadySrcRegIdx(int idx) const
717 {
718 return this->_readySrcRegIdx[idx];
719 }
720
721 /** Records that one of the source registers is ready. */
722 void markSrcRegReady()
723 {
724 if (++readyRegs == numSrcRegs()) {
725 status.set(CanIssue);
726 }
727 }
728
729 /** Marks a specific register as ready. */
730 void markSrcRegReady(RegIndex src_idx)
731 {
732 _readySrcRegIdx[src_idx] = true;
733
734 markSrcRegReady();
735 }
736
737 /** Renames a destination register to a physical register. Also records
738 * the previous physical register that the logical register mapped to.
739 */
740 void renameDestReg(int idx,
741 PhysRegIndex renamed_dest,
742 PhysRegIndex previous_rename)
743 {
744 _destRegIdx[idx] = renamed_dest;
745 _prevDestRegIdx[idx] = previous_rename;
746 }
747
748 /** Renames a source logical register to the physical register which
749 * has/will produce that logical register's result.
750 * @todo: add in whether or not the source register is ready.
751 */
752 void renameSrcReg(int idx, PhysRegIndex renamed_src)
753 {
754 _srcRegIdx[idx] = renamed_src;
755 }
756
757
758 PhysRegIndex readDestRegIdx(int idx)
759 {
760 return _destRegIdx[idx];
761 }
762
763 void setDestRegIdx(int idx, PhysRegIndex dest_idx)
764 {
765 _destRegIdx[idx] = dest_idx;
766 }
767
768 int getDestIdxNum(PhysRegIndex dest_idx)
769 {
770 for (int i=0; i < staticInst->numDestRegs(); i++) {
771 if (_destRegIdx[i] == dest_idx)
772 return i;
773 }
774
775 return -1;
776 }
777
778 PhysRegIndex readSrcRegIdx(int idx)
779 {
780 return _srcRegIdx[idx];
781 }
782
783 void setSrcRegIdx(int idx, PhysRegIndex src_idx)
784 {
785 _srcRegIdx[idx] = src_idx;
786 }
787
788 int getSrcIdxNum(PhysRegIndex src_idx)
789 {
790 for (int i=0; i < staticInst->numSrcRegs(); i++) {
791 if (_srcRegIdx[i] == src_idx)
792 return i;
793 }
794
795 return -1;
796 }
797
798 ////////////////////////////////////////////////////
799 //
800 // SOURCE-DESTINATION REGISTER VALUES
801 //
802 ////////////////////////////////////////////////////
803
804 /** Functions that sets an integer or floating point
805 * source register to a value. */
806 void setIntSrc(int idx, uint64_t val);
807 void setFloatSrc(int idx, FloatReg val, int width = 32);
808 void setFloatRegBitsSrc(int idx, uint64_t val);
809
810 uint64_t* getIntSrcPtr(int idx) { return &instSrc[idx].integer; }
811 uint64_t readIntSrc(int idx) { return instSrc[idx].integer; }
812
813 /** These Instructions read a integer/float/misc. source register
814 * value in the instruction. The instruction's execute function will
815 * call these and it is the interface that is used by the ISA descr.
816 * language (which is why the name isnt readIntSrc(...)) Note: That
817 * the source reg. value is set using the setSrcReg() function.
818 */
819 IntReg readIntRegOperand(const StaticInst *si, int idx, unsigned tid=0);
820 FloatReg readFloatRegOperand(const StaticInst *si, int idx,
821 int width = TheISA::SingleWidth);
822 FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx,
823 int width = TheISA::SingleWidth);
824 MiscReg readMiscReg(int misc_reg);
825 MiscReg readMiscRegNoEffect(int misc_reg);
826 MiscReg readMiscRegOperand(const StaticInst *si, int idx);
827 MiscReg readMiscRegOperandNoEffect(const StaticInst *si, int idx);
828
829 /** Returns the result value instruction. */
830 uint64_t readIntResult(int idx) { return instResult[idx].val.integer; }
831 float readFloatResult(int idx) { return instResult[idx].val.fp; }
832 double readDoubleResult(int idx) { return instResult[idx].val.dbl; }
833 Tick readResultTime(int idx) { return instResult[idx].tick; }
834
835 uint64_t* getIntResultPtr(int idx) { return &instResult[idx].val.integer; }
836
837 /** This is the interface that an instruction will use to write
838 * it's destination register.
839 */
840 void setIntRegOperand(const StaticInst *si, int idx, IntReg val);
841 void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val,
842 int width = TheISA::SingleWidth);
843 void setFloatRegOperandBits(const StaticInst *si, int idx, FloatRegBits val,
844 int width = TheISA::SingleWidth);
845 void setMiscReg(int misc_reg, const MiscReg &val);
846 void setMiscRegNoEffect(int misc_reg, const MiscReg &val);
847 void setMiscRegOperand(const StaticInst *si, int idx, const MiscReg &val);
848 void setMiscRegOperandNoEffect(const StaticInst *si, int idx, const MiscReg &val);
849
850 virtual uint64_t readRegOtherThread(unsigned idx, int tid = -1);
851 virtual void setRegOtherThread(unsigned idx, const uint64_t &val, int tid = -1);
852
853 /** Sets the number of consecutive store conditional failures. */
854 void setStCondFailures(unsigned sc_failures)
855 { thread->storeCondFailures = sc_failures; }
856
857 //////////////////////////////////////////////////////////////
858 //
859 // INSTRUCTION STATUS FLAGS (READ/SET)
860 //
861 //////////////////////////////////////////////////////////////
862 /** Sets this instruction as entered on the CPU Reg Dep Map */
863 void setRegDepEntry() { status.set(RegDepMapEntry); }
864
865 /** Returns whether or not the entry is on the CPU Reg Dep Map */
866 bool isRegDepEntry() const { return status[RegDepMapEntry]; }
867
868 /** Sets this instruction as completed. */
869 void setCompleted() { status.set(Completed); }
870
871 /** Returns whether or not this instruction is completed. */
872 bool isCompleted() const { return status[Completed]; }
873
874 /** Marks the result as ready. */
875 void setResultReady() { status.set(ResultReady); }
876
877 /** Returns whether or not the result is ready. */
878 bool isResultReady() const { return status[ResultReady]; }
879
880 /** Sets this instruction as ready to issue. */
881 void setCanIssue() { status.set(CanIssue); }
882
883 /** Returns whether or not this instruction is ready to issue. */
884 bool readyToIssue() const { return status[CanIssue]; }
885
886 /** Sets this instruction as issued from the IQ. */
887 void setIssued() { status.set(Issued); }
888
889 /** Returns whether or not this instruction has issued. */
890 bool isIssued() const { return status[Issued]; }
891
892 /** Sets this instruction as executed. */
893 void setExecuted() { status.set(Executed); }
894
895 /** Returns whether or not this instruction has executed. */
896 bool isExecuted() const { return status[Executed]; }
897
898 /** Sets this instruction as ready to commit. */
899 void setCanCommit() { status.set(CanCommit); }
900
901 /** Clears this instruction as being ready to commit. */
902 void clearCanCommit() { status.reset(CanCommit); }
903
904 /** Returns whether or not this instruction is ready to commit. */
905 bool readyToCommit() const { return status[CanCommit]; }
906
907 void setAtCommit() { status.set(AtCommit); }
908
909 bool isAtCommit() { return status[AtCommit]; }
910
911 /** Sets this instruction as committed. */
912 void setCommitted() { status.set(Committed); }
913
914 /** Returns whether or not this instruction is committed. */
915 bool isCommitted() const { return status[Committed]; }
916
917 /** Sets this instruction as squashed. */
918 void setSquashed() { status.set(Squashed); }
919
920 /** Returns whether or not this instruction is squashed. */
921 bool isSquashed() const { return status[Squashed]; }
922
923 /** Temporarily sets this instruction as a serialize before instruction. */
924 void setSerializeBefore() { status.set(SerializeBefore); }
925
926 /** Clears the serializeBefore part of this instruction. */
927 void clearSerializeBefore() { status.reset(SerializeBefore); }
928
929 /** Checks if this serializeBefore is only temporarily set. */
930 bool isTempSerializeBefore() { return status[SerializeBefore]; }
931
932 /** Temporarily sets this instruction as a serialize after instruction. */
933 void setSerializeAfter() { status.set(SerializeAfter); }
934
935 /** Clears the serializeAfter part of this instruction.*/
936 void clearSerializeAfter() { status.reset(SerializeAfter); }
937
938 /** Checks if this serializeAfter is only temporarily set. */
939 bool isTempSerializeAfter() { return status[SerializeAfter]; }
940
941 /** Sets the serialization part of this instruction as handled. */
942 void setSerializeHandled() { status.set(SerializeHandled); }
943
944 /** Checks if the serialization part of this instruction has been
945 * handled. This does not apply to the temporary serializing
946 * state; it only applies to this instruction's own permanent
947 * serializing state.
948 */
949 bool isSerializeHandled() { return status[SerializeHandled]; }
950
951 private:
952 /** Instruction effective address.
953 * @todo: Consider if this is necessary or not.
954 */
955 Addr instEffAddr;
956
957 /** Whether or not the effective address calculation is completed.
958 * @todo: Consider if this is necessary or not.
959 */
960 bool eaCalcDone;
961
962 public:
963 /** Whether or not the memory operation is done. */
964 bool memOpDone;
965
966 public:
967 /** Load queue index. */
968 int16_t lqIdx;
969
970 /** Store queue index. */
971 int16_t sqIdx;
972
973 /** Iterator pointing to this BaseDynInst in the list of all insts. */
974 ListIt instListIt;
975
976 /** Returns iterator to this instruction in the list of all insts. */
977 ListIt &getInstListIt() { return instListIt; }
978
979 /** Sets iterator for this instruction in the list of all insts. */
980 void setInstListIt(ListIt _instListIt) { instListIt = _instListIt; }
981
982 /** Count of total number of dynamic instructions. */
983 static int instcount;
984
985 /** Dumps out contents of this BaseDynInst. */
986 void dump();
987
988 /** Dumps out contents of this BaseDynInst into given string. */
989 void dump(std::string &outstring);
990
991
992 //inline int curCount() { return curCount(); }
993 };
994
995
996 #endif // __CPU_BASE_DYN_INST_HH__