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