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