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