2 * Copyright (c) 2010-2012, 2016-2017 ARM Limited
3 * Copyright (c) 2013 Advanced Micro Devices, Inc.
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
15 * Copyright (c) 2004-2006 The Regents of The University of Michigan
16 * All rights reserved.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 #ifndef __CPU_O3_THREAD_CONTEXT_IMPL_HH__
46 #define __CPU_O3_THREAD_CONTEXT_IMPL_HH__
48 #include "arch/kernel_stats.hh"
49 #include "arch/registers.hh"
50 #include "config/the_isa.hh"
51 #include "cpu/o3/thread_context.hh"
52 #include "cpu/quiesce_event.hh"
53 #include "debug/O3CPU.hh"
56 FSTranslatingPortProxy&
57 O3ThreadContext<Impl>::getVirtProxy()
59 return thread->getVirtProxy();
64 O3ThreadContext<Impl>::dumpFuncProfile()
66 thread->dumpFuncProfile();
71 O3ThreadContext<Impl>::takeOverFrom(ThreadContext *old_context)
73 ::takeOverFrom(*this, *old_context);
74 TheISA::Decoder *newDecoder = getDecoderPtr();
75 TheISA::Decoder *oldDecoder = old_context->getDecoderPtr();
76 newDecoder->takeOverFrom(oldDecoder);
78 thread->kernelStats = old_context->getKernelStats();
79 thread->funcExeInst = old_context->readFuncExeInst();
81 thread->noSquashFromTC = false;
82 thread->trapPending = false;
87 O3ThreadContext<Impl>::activate()
89 DPRINTF(O3CPU, "Calling activate on Thread Context %d\n",
92 if (thread->status() == ThreadContext::Active)
95 thread->lastActivate = curTick();
96 thread->setStatus(ThreadContext::Active);
98 // status() == Suspended
99 cpu->activateContext(thread->threadId());
102 template <class Impl>
104 O3ThreadContext<Impl>::suspend()
106 DPRINTF(O3CPU, "Calling suspend on Thread Context %d\n",
109 if (thread->status() == ThreadContext::Suspended)
112 if (cpu->isDraining()) {
113 DPRINTF(O3CPU, "Ignoring suspend on TC due to pending drain\n");
117 thread->lastActivate = curTick();
118 thread->lastSuspend = curTick();
120 thread->setStatus(ThreadContext::Suspended);
121 cpu->suspendContext(thread->threadId());
124 template <class Impl>
126 O3ThreadContext<Impl>::halt()
128 DPRINTF(O3CPU, "Calling halt on Thread Context %d\n", threadId());
130 if (thread->status() == ThreadContext::Halted)
133 thread->setStatus(ThreadContext::Halted);
134 cpu->haltContext(thread->threadId());
137 template <class Impl>
139 O3ThreadContext<Impl>::regStats(const std::string &name)
142 thread->kernelStats = new TheISA::Kernel::Statistics();
143 thread->kernelStats->regStats(name + ".kern");
147 template <class Impl>
149 O3ThreadContext<Impl>::readLastActivate()
151 return thread->lastActivate;
154 template <class Impl>
156 O3ThreadContext<Impl>::readLastSuspend()
158 return thread->lastSuspend;
161 template <class Impl>
163 O3ThreadContext<Impl>::profileClear()
165 thread->profileClear();
168 template <class Impl>
170 O3ThreadContext<Impl>::profileSample()
172 thread->profileSample();
175 template <class Impl>
177 O3ThreadContext<Impl>::copyArchRegs(ThreadContext *tc)
180 thread->noSquashFromTC = true;
181 TheISA::copyRegs(tc, this);
182 thread->noSquashFromTC = false;
185 this->thread->funcExeInst = tc->readFuncExeInst();
188 template <class Impl>
190 O3ThreadContext<Impl>::clearArchRegs()
192 cpu->isa[thread->threadId()]->clear();
195 template <class Impl>
197 O3ThreadContext<Impl>::readIntRegFlat(int reg_idx)
199 return cpu->readArchIntReg(reg_idx, thread->threadId());
202 template <class Impl>
204 O3ThreadContext<Impl>::readFloatRegFlat(int reg_idx)
206 return cpu->readArchFloatReg(reg_idx, thread->threadId());
209 template <class Impl>
211 O3ThreadContext<Impl>::readFloatRegBitsFlat(int reg_idx)
213 return cpu->readArchFloatRegInt(reg_idx, thread->threadId());
216 template <class Impl>
217 const TheISA::VecRegContainer&
218 O3ThreadContext<Impl>::readVecRegFlat(int reg_id) const
220 return cpu->readArchVecReg(reg_id, thread->threadId());
223 template <class Impl>
224 TheISA::VecRegContainer&
225 O3ThreadContext<Impl>::getWritableVecRegFlat(int reg_id)
227 return cpu->getWritableArchVecReg(reg_id, thread->threadId());
230 template <class Impl>
231 const TheISA::VecElem&
232 O3ThreadContext<Impl>::readVecElemFlat(const RegIndex& idx,
233 const ElemIndex& elemIndex) const
235 return cpu->readArchVecElem(idx, elemIndex, thread->threadId());
238 template <class Impl>
240 O3ThreadContext<Impl>::readCCRegFlat(int reg_idx)
242 return cpu->readArchCCReg(reg_idx, thread->threadId());
245 template <class Impl>
247 O3ThreadContext<Impl>::setIntRegFlat(int reg_idx, uint64_t val)
249 cpu->setArchIntReg(reg_idx, val, thread->threadId());
254 template <class Impl>
256 O3ThreadContext<Impl>::setFloatRegFlat(int reg_idx, FloatReg val)
258 cpu->setArchFloatReg(reg_idx, val, thread->threadId());
263 template <class Impl>
265 O3ThreadContext<Impl>::setFloatRegBitsFlat(int reg_idx, FloatRegBits val)
267 cpu->setArchFloatRegInt(reg_idx, val, thread->threadId());
272 template <class Impl>
274 O3ThreadContext<Impl>::setVecRegFlat(int reg_idx, const VecRegContainer& val)
276 cpu->setArchVecReg(reg_idx, val, thread->threadId());
281 template <class Impl>
283 O3ThreadContext<Impl>::setVecElemFlat(const RegIndex& idx,
284 const ElemIndex& elemIndex, const VecElem& val)
286 cpu->setArchVecElem(idx, elemIndex, val, thread->threadId());
290 template <class Impl>
292 O3ThreadContext<Impl>::setCCRegFlat(int reg_idx, TheISA::CCReg val)
294 cpu->setArchCCReg(reg_idx, val, thread->threadId());
299 template <class Impl>
301 O3ThreadContext<Impl>::pcState(const TheISA::PCState &val)
303 cpu->pcState(val, thread->threadId());
308 template <class Impl>
310 O3ThreadContext<Impl>::pcStateNoRecord(const TheISA::PCState &val)
312 cpu->pcState(val, thread->threadId());
317 template <class Impl>
319 O3ThreadContext<Impl>::flattenRegId(const RegId& regId) const
321 return cpu->isa[thread->threadId()]->flattenRegId(regId);
324 template <class Impl>
326 O3ThreadContext<Impl>::setMiscRegNoEffect(int misc_reg, const MiscReg &val)
328 cpu->setMiscRegNoEffect(misc_reg, val, thread->threadId());
333 #endif//__CPU_O3_THREAD_CONTEXT_IMPL_HH__
334 template <class Impl>
336 O3ThreadContext<Impl>::setMiscReg(int misc_reg, const MiscReg &val)
338 cpu->setMiscReg(misc_reg, val, thread->threadId());