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