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/generic/traits.hh"
49 #include "arch/kernel_stats.hh"
50 #include "arch/registers.hh"
51 #include "config/the_isa.hh"
52 #include "cpu/o3/thread_context.hh"
53 #include "cpu/quiesce_event.hh"
54 #include "debug/O3CPU.hh"
57 FSTranslatingPortProxy&
58 O3ThreadContext<Impl>::getVirtProxy()
60 return thread->getVirtProxy();
65 O3ThreadContext<Impl>::dumpFuncProfile()
67 thread->dumpFuncProfile();
72 O3ThreadContext<Impl>::takeOverFrom(ThreadContext *old_context)
74 ::takeOverFrom(*this, *old_context);
75 TheISA::Decoder *newDecoder = getDecoderPtr();
76 TheISA::Decoder *oldDecoder = old_context->getDecoderPtr();
77 newDecoder->takeOverFrom(oldDecoder);
79 thread->kernelStats = old_context->getKernelStats();
80 thread->funcExeInst = old_context->readFuncExeInst();
82 thread->noSquashFromTC = false;
83 thread->trapPending = false;
88 O3ThreadContext<Impl>::activate()
90 DPRINTF(O3CPU, "Calling activate on Thread Context %d\n",
93 if (thread->status() == ThreadContext::Active)
96 thread->lastActivate = curTick();
97 thread->setStatus(ThreadContext::Active);
99 // status() == Suspended
100 cpu->activateContext(thread->threadId());
103 template <class Impl>
105 O3ThreadContext<Impl>::suspend()
107 DPRINTF(O3CPU, "Calling suspend on Thread Context %d\n",
110 if (thread->status() == ThreadContext::Suspended)
113 if (cpu->isDraining()) {
114 DPRINTF(O3CPU, "Ignoring suspend on TC due to pending drain\n");
118 thread->lastActivate = curTick();
119 thread->lastSuspend = curTick();
121 thread->setStatus(ThreadContext::Suspended);
122 cpu->suspendContext(thread->threadId());
125 template <class Impl>
127 O3ThreadContext<Impl>::halt()
129 DPRINTF(O3CPU, "Calling halt on Thread Context %d\n", threadId());
131 if (thread->status() == ThreadContext::Halting ||
132 thread->status() == ThreadContext::Halted)
135 // the thread is not going to halt/terminate immediately in this cycle.
136 // The thread will be removed after an exit trap is processed
137 // (e.g., after trapLatency cycles). Until then, the thread's status
139 thread->setStatus(ThreadContext::Halting);
141 // add this thread to the exiting list to mark that it is trying to exit.
142 cpu->addThreadToExitingList(thread->threadId());
145 template <class Impl>
147 O3ThreadContext<Impl>::regStats(const std::string &name)
150 thread->kernelStats = new TheISA::Kernel::Statistics();
151 thread->kernelStats->regStats(name + ".kern");
155 template <class Impl>
157 O3ThreadContext<Impl>::readLastActivate()
159 return thread->lastActivate;
162 template <class Impl>
164 O3ThreadContext<Impl>::readLastSuspend()
166 return thread->lastSuspend;
169 template <class Impl>
171 O3ThreadContext<Impl>::profileClear()
173 thread->profileClear();
176 template <class Impl>
178 O3ThreadContext<Impl>::profileSample()
180 thread->profileSample();
183 template <class Impl>
185 O3ThreadContext<Impl>::copyArchRegs(ThreadContext *tc)
187 // Set vector renaming mode before copying registers
188 cpu->vecRenameMode(RenameMode<TheISA::ISA>::mode(tc->pcState()));
191 thread->noSquashFromTC = true;
192 TheISA::copyRegs(tc, this);
193 thread->noSquashFromTC = false;
196 this->thread->funcExeInst = tc->readFuncExeInst();
199 template <class Impl>
201 O3ThreadContext<Impl>::clearArchRegs()
203 cpu->isa[thread->threadId()]->clear();
206 template <class Impl>
208 O3ThreadContext<Impl>::readIntRegFlat(int reg_idx)
210 return cpu->readArchIntReg(reg_idx, thread->threadId());
213 template <class Impl>
215 O3ThreadContext<Impl>::readFloatRegFlat(int reg_idx)
217 return cpu->readArchFloatReg(reg_idx, thread->threadId());
220 template <class Impl>
221 const TheISA::VecRegContainer&
222 O3ThreadContext<Impl>::readVecRegFlat(int reg_id) const
224 return cpu->readArchVecReg(reg_id, thread->threadId());
227 template <class Impl>
228 TheISA::VecRegContainer&
229 O3ThreadContext<Impl>::getWritableVecRegFlat(int reg_id)
231 return cpu->getWritableArchVecReg(reg_id, thread->threadId());
234 template <class Impl>
235 const TheISA::VecElem&
236 O3ThreadContext<Impl>::readVecElemFlat(const RegIndex& idx,
237 const ElemIndex& elemIndex) const
239 return cpu->readArchVecElem(idx, elemIndex, thread->threadId());
242 template <class Impl>
243 const TheISA::VecPredRegContainer&
244 O3ThreadContext<Impl>::readVecPredRegFlat(int reg_id) const
246 return cpu->readArchVecPredReg(reg_id, thread->threadId());
249 template <class Impl>
250 TheISA::VecPredRegContainer&
251 O3ThreadContext<Impl>::getWritableVecPredRegFlat(int reg_id)
253 return cpu->getWritableArchVecPredReg(reg_id, thread->threadId());
256 template <class Impl>
258 O3ThreadContext<Impl>::readCCRegFlat(int reg_idx)
260 return cpu->readArchCCReg(reg_idx, thread->threadId());
263 template <class Impl>
265 O3ThreadContext<Impl>::setIntRegFlat(int reg_idx, RegVal val)
267 cpu->setArchIntReg(reg_idx, val, thread->threadId());
272 template <class Impl>
274 O3ThreadContext<Impl>::setFloatRegFlat(int reg_idx, RegVal val)
276 cpu->setArchFloatReg(reg_idx, val, thread->threadId());
281 template <class Impl>
283 O3ThreadContext<Impl>::setVecRegFlat(int reg_idx, const VecRegContainer& val)
285 cpu->setArchVecReg(reg_idx, val, thread->threadId());
290 template <class Impl>
292 O3ThreadContext<Impl>::setVecElemFlat(const RegIndex& idx,
293 const ElemIndex& elemIndex, const VecElem& val)
295 cpu->setArchVecElem(idx, elemIndex, val, thread->threadId());
299 template <class Impl>
301 O3ThreadContext<Impl>::setVecPredRegFlat(int reg_idx,
302 const VecPredRegContainer& val)
304 cpu->setArchVecPredReg(reg_idx, val, thread->threadId());
309 template <class Impl>
311 O3ThreadContext<Impl>::setCCRegFlat(int reg_idx, RegVal val)
313 cpu->setArchCCReg(reg_idx, val, thread->threadId());
318 template <class Impl>
320 O3ThreadContext<Impl>::pcState(const TheISA::PCState &val)
322 cpu->pcState(val, thread->threadId());
327 template <class Impl>
329 O3ThreadContext<Impl>::pcStateNoRecord(const TheISA::PCState &val)
331 cpu->pcState(val, thread->threadId());
336 template <class Impl>
338 O3ThreadContext<Impl>::flattenRegId(const RegId& regId) const
340 return cpu->isa[thread->threadId()]->flattenRegId(regId);
343 template <class Impl>
345 O3ThreadContext<Impl>::setMiscRegNoEffect(int misc_reg, RegVal val)
347 cpu->setMiscRegNoEffect(misc_reg, val, thread->threadId());
352 #endif//__CPU_O3_THREAD_CONTEXT_IMPL_HH__
353 template <class Impl>
355 O3ThreadContext<Impl>::setMiscReg(int misc_reg, RegVal val)
357 cpu->setMiscReg(misc_reg, val, thread->threadId());