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