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