dyn_inst_impl.hh revision 8471
16700SN/A/*
28257SN/A * Copyright (c) 2010 ARM Limited
36700SN/A * All rights reserved
46700SN/A *
56700SN/A * The license below extends only to copyright in the software and shall
66700SN/A * not be construed as granting a license to any other intellectual
76700SN/A * property including but not limited to intellectual property relating
86700SN/A * to a hardware implementation of the functionality of the software
96700SN/A * licensed hereunder.  You may use the software subject to the license
106700SN/A * terms below provided that you ensure that this notice is replicated
116700SN/A * unmodified and in its entirety in all distributions of the software,
126700SN/A * modified or unmodified, in source code or in binary form.
136700SN/A *
146700SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan
156700SN/A * All rights reserved.
166700SN/A *
176700SN/A * Redistribution and use in source and binary forms, with or without
186700SN/A * modification, are permitted provided that the following conditions are
196700SN/A * met: redistributions of source code must retain the above copyright
206700SN/A * notice, this list of conditions and the following disclaimer;
216700SN/A * redistributions in binary form must reproduce the above copyright
226700SN/A * notice, this list of conditions and the following disclaimer in the
236700SN/A * documentation and/or other materials provided with the distribution;
246700SN/A * neither the name of the copyright holders nor the names of its
256700SN/A * contributors may be used to endorse or promote products derived from
266700SN/A * this software without specific prior written permission.
276700SN/A *
286285SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
298258SBrad.Beckmann@amd.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
306285SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
318258SBrad.Beckmann@amd.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
328258SBrad.Beckmann@amd.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
336285SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
348258SBrad.Beckmann@amd.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3511320Ssteve.reinhardt@amd.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3611320Ssteve.reinhardt@amd.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3711320Ssteve.reinhardt@amd.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
388258SBrad.Beckmann@amd.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
396285SN/A *
406285SN/A * Authors: Kevin Lim
417054SN/A */
428258SBrad.Beckmann@amd.com
436493SN/A#include "base/cp_annotate.hh"
448257SN/A#include "cpu/o3/dyn_inst.hh"
456493SN/A
467054SN/Atemplate <class Impl>
478258SBrad.Beckmann@amd.comBaseO3DynInst<Impl>::BaseO3DynInst(StaticInstPtr staticInst,
488258SBrad.Beckmann@amd.com                                   TheISA::PCState pc, TheISA::PCState predPC,
497054SN/A                                   InstSeqNum seq_num, O3CPU *cpu)
508258SBrad.Beckmann@amd.com    : BaseDynInst<Impl>(staticInst, pc, predPC, seq_num, cpu)
517054SN/A{
528257SN/A    initVars();
538258SBrad.Beckmann@amd.com}
548258SBrad.Beckmann@amd.com
558257SN/Atemplate <class Impl>
568258SBrad.Beckmann@amd.comBaseO3DynInst<Impl>::BaseO3DynInst(ExtMachInst inst,
5711320Ssteve.reinhardt@amd.com                                   TheISA::PCState pc, TheISA::PCState predPC,
5811320Ssteve.reinhardt@amd.com                                   InstSeqNum seq_num, O3CPU *cpu)
5911320Ssteve.reinhardt@amd.com    : BaseDynInst<Impl>(inst, pc, predPC, seq_num, cpu)
608258SBrad.Beckmann@amd.com{
618257SN/A    initVars();
628257SN/A}
638258SBrad.Beckmann@amd.com
648258SBrad.Beckmann@amd.comtemplate <class Impl>
658257SN/ABaseO3DynInst<Impl>::BaseO3DynInst(StaticInstPtr &_staticInst)
668258SBrad.Beckmann@amd.com    : BaseDynInst<Impl>(_staticInst)
678257SN/A{
688257SN/A    initVars();
698258SBrad.Beckmann@amd.com}
708258SBrad.Beckmann@amd.com
718257SN/Atemplate <class Impl>
728258SBrad.Beckmann@amd.comvoid
738257SN/ABaseO3DynInst<Impl>::initVars()
74{
75    // Make sure to have the renamed register entries set to the same
76    // as the normal register entries.  It will allow the IQ to work
77    // without any modifications.
78    for (int i = 0; i < this->staticInst->numDestRegs(); i++) {
79        this->_destRegIdx[i] = this->staticInst->destRegIdx(i);
80    }
81
82    for (int i = 0; i < this->staticInst->numSrcRegs(); i++) {
83        this->_srcRegIdx[i] = this->staticInst->srcRegIdx(i);
84        this->_readySrcRegIdx[i] = 0;
85    }
86
87    _numDestMiscRegs = 0;
88
89#if TRACING_ON
90    fetchTick = 0;
91    decodeTick = 0;
92    renameTick = 0;
93    dispatchTick = 0;
94    issueTick = 0;
95    completeTick = 0;
96#endif
97}
98
99template <class Impl>
100Fault
101BaseO3DynInst<Impl>::execute()
102{
103    // @todo: Pretty convoluted way to avoid squashing from happening
104    // when using the TC during an instruction's execution
105    // (specifically for instructions that have side-effects that use
106    // the TC).  Fix this.
107    bool in_syscall = this->thread->inSyscall;
108    this->thread->inSyscall = true;
109
110    this->fault = this->staticInst->execute(this, this->traceData);
111
112    this->thread->inSyscall = in_syscall;
113
114    return this->fault;
115}
116
117template <class Impl>
118Fault
119BaseO3DynInst<Impl>::initiateAcc()
120{
121    // @todo: Pretty convoluted way to avoid squashing from happening
122    // when using the TC during an instruction's execution
123    // (specifically for instructions that have side-effects that use
124    // the TC).  Fix this.
125    bool in_syscall = this->thread->inSyscall;
126    this->thread->inSyscall = true;
127
128    this->fault = this->staticInst->initiateAcc(this, this->traceData);
129
130    this->thread->inSyscall = in_syscall;
131
132    return this->fault;
133}
134
135template <class Impl>
136Fault
137BaseO3DynInst<Impl>::completeAcc(PacketPtr pkt)
138{
139    // @todo: Pretty convoluted way to avoid squashing from happening
140    // when using the TC during an instruction's execution
141    // (specifically for instructions that have side-effects that use
142    // the TC).  Fix this.
143    bool in_syscall = this->thread->inSyscall;
144    this->thread->inSyscall = true;
145
146    this->fault = this->staticInst->completeAcc(pkt, this, this->traceData);
147
148    this->thread->inSyscall = in_syscall;
149
150    return this->fault;
151}
152
153#if FULL_SYSTEM
154template <class Impl>
155Fault
156BaseO3DynInst<Impl>::hwrei()
157{
158#if THE_ISA == ALPHA_ISA
159    // Can only do a hwrei when in pal mode.
160    if (!(this->instAddr() & 0x3))
161        return new AlphaISA::UnimplementedOpcodeFault;
162
163    // Set the next PC based on the value of the EXC_ADDR IPR.
164    AlphaISA::PCState pc = this->pcState();
165    pc.npc(this->cpu->readMiscRegNoEffect(AlphaISA::IPR_EXC_ADDR,
166                                          this->threadNumber));
167    this->pcState(pc);
168    if (CPA::available()) {
169        ThreadContext *tc = this->cpu->tcBase(this->threadNumber);
170        CPA::cpa()->swAutoBegin(tc, this->nextInstAddr());
171    }
172
173    // Tell CPU to clear any state it needs to if a hwrei is taken.
174    this->cpu->hwrei(this->threadNumber);
175#else
176
177#endif
178    // FIXME: XXX check for interrupts? XXX
179    return NoFault;
180}
181
182template <class Impl>
183void
184BaseO3DynInst<Impl>::trap(Fault fault)
185{
186    this->cpu->trap(fault, this->threadNumber, this->staticInst);
187}
188
189template <class Impl>
190bool
191BaseO3DynInst<Impl>::simPalCheck(int palFunc)
192{
193#if THE_ISA != ALPHA_ISA
194    panic("simPalCheck called, but PAL only exists in Alpha!\n");
195#endif
196    return this->cpu->simPalCheck(palFunc, this->threadNumber);
197}
198#else
199template <class Impl>
200void
201BaseO3DynInst<Impl>::syscall(int64_t callnum)
202{
203    // HACK: check CPU's nextPC before and after syscall. If it
204    // changes, update this instruction's nextPC because the syscall
205    // must have changed the nextPC.
206    TheISA::PCState curPC = this->cpu->pcState(this->threadNumber);
207    this->cpu->syscall(callnum, this->threadNumber);
208    TheISA::PCState newPC = this->cpu->pcState(this->threadNumber);
209    if (!(curPC == newPC)) {
210        this->pcState(newPC);
211    }
212}
213#endif
214
215