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