2 * Copyright (c) 2010 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2004-2006 The Regents of The University of Michigan
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 #include "arch/kernel_stats.hh"
45 #include "arch/registers.hh"
46 #include "config/the_isa.hh"
47 #include "cpu/o3/thread_context.hh"
48 #include "cpu/quiesce_event.hh"
49 #include "debug/O3CPU.hh"
53 O3ThreadContext<Impl>::getVirtPort()
55 return thread->getVirtPort();
60 O3ThreadContext<Impl>::dumpFuncProfile()
62 thread->dumpFuncProfile();
67 O3ThreadContext<Impl>::takeOverFrom(ThreadContext *old_context)
69 // some things should already be set up
70 assert(getSystemPtr() == old_context->getSystemPtr());
71 assert(getProcessPtr() == old_context->getProcessPtr());
73 // copy over functional state
74 setStatus(old_context->status());
75 copyArchRegs(old_context);
76 setContextId(old_context->contextId());
77 setThreadId(old_context->threadId());
80 EndQuiesceEvent *other_quiesce = old_context->getQuiesceEvent();
82 // Point the quiesce event's TC at this TC so that it wakes up
84 other_quiesce->tc = this;
86 if (thread->quiesceEvent) {
87 thread->quiesceEvent->tc = this;
90 // Transfer kernel stats from one CPU to the other.
91 thread->kernelStats = old_context->getKernelStats();
92 cpu->lockFlag = false;
94 thread->funcExeInst = old_context->readFuncExeInst();
97 old_context->setStatus(ThreadContext::Halted);
99 thread->inSyscall = false;
100 thread->trapPending = false;
103 template <class Impl>
105 O3ThreadContext<Impl>::activate(int delay)
107 DPRINTF(O3CPU, "Calling activate on Thread Context %d\n",
110 if (thread->status() == ThreadContext::Active)
113 thread->lastActivate = curTick();
114 thread->setStatus(ThreadContext::Active);
116 // status() == Suspended
117 cpu->activateContext(thread->threadId(), delay);
120 template <class Impl>
122 O3ThreadContext<Impl>::suspend(int delay)
124 DPRINTF(O3CPU, "Calling suspend on Thread Context %d\n",
127 if (thread->status() == ThreadContext::Suspended)
130 thread->lastActivate = curTick();
131 thread->lastSuspend = curTick();
133 thread->setStatus(ThreadContext::Suspended);
134 cpu->suspendContext(thread->threadId());
137 template <class Impl>
139 O3ThreadContext<Impl>::halt(int delay)
141 DPRINTF(O3CPU, "Calling halt on Thread Context %d\n",
144 if (thread->status() == ThreadContext::Halted)
147 thread->setStatus(ThreadContext::Halted);
148 cpu->haltContext(thread->threadId());
151 template <class Impl>
153 O3ThreadContext<Impl>::regStats(const std::string &name)
156 thread->kernelStats = new TheISA::Kernel::Statistics(cpu->system);
157 thread->kernelStats->regStats(name + ".kern");
161 template <class Impl>
163 O3ThreadContext<Impl>::serialize(std::ostream &os)
165 if (FullSystem && thread->kernelStats)
166 thread->kernelStats->serialize(os);
169 template <class Impl>
171 O3ThreadContext<Impl>::unserialize(Checkpoint *cp, const std::string §ion)
173 if (FullSystem && thread->kernelStats)
174 thread->kernelStats->unserialize(cp, section);
177 template <class Impl>
179 O3ThreadContext<Impl>::readLastActivate()
181 return thread->lastActivate;
184 template <class Impl>
186 O3ThreadContext<Impl>::readLastSuspend()
188 return thread->lastSuspend;
191 template <class Impl>
193 O3ThreadContext<Impl>::profileClear()
195 thread->profileClear();
198 template <class Impl>
200 O3ThreadContext<Impl>::profileSample()
202 thread->profileSample();
205 template <class Impl>
207 O3ThreadContext<Impl>::copyArchRegs(ThreadContext *tc)
210 thread->inSyscall = true;
211 TheISA::copyRegs(tc, this);
212 thread->inSyscall = false;
215 this->thread->funcExeInst = tc->readFuncExeInst();
218 template <class Impl>
220 O3ThreadContext<Impl>::clearArchRegs()
222 cpu->isa[thread->threadId()].clear();
225 template <class Impl>
227 O3ThreadContext<Impl>::readIntReg(int reg_idx)
229 reg_idx = cpu->isa[thread->threadId()].flattenIntIndex(reg_idx);
230 return cpu->readArchIntReg(reg_idx, thread->threadId());
233 template <class Impl>
235 O3ThreadContext<Impl>::readFloatReg(int reg_idx)
237 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx);
238 return cpu->readArchFloatReg(reg_idx, thread->threadId());
241 template <class Impl>
243 O3ThreadContext<Impl>::readFloatRegBits(int reg_idx)
245 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx);
246 return cpu->readArchFloatRegInt(reg_idx, thread->threadId());
249 template <class Impl>
251 O3ThreadContext<Impl>::setIntReg(int reg_idx, uint64_t val)
253 reg_idx = cpu->isa[thread->threadId()].flattenIntIndex(reg_idx);
254 cpu->setArchIntReg(reg_idx, val, thread->threadId());
256 // Squash if we're not already in a state update mode.
257 if (!thread->trapPending && !thread->inSyscall) {
258 cpu->squashFromTC(thread->threadId());
262 template <class Impl>
264 O3ThreadContext<Impl>::setFloatReg(int reg_idx, FloatReg val)
266 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx);
267 cpu->setArchFloatReg(reg_idx, val, thread->threadId());
269 if (!thread->trapPending && !thread->inSyscall) {
270 cpu->squashFromTC(thread->threadId());
274 template <class Impl>
276 O3ThreadContext<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val)
278 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx);
279 cpu->setArchFloatRegInt(reg_idx, val, thread->threadId());
281 // Squash if we're not already in a state update mode.
282 if (!thread->trapPending && !thread->inSyscall) {
283 cpu->squashFromTC(thread->threadId());
287 template <class Impl>
289 O3ThreadContext<Impl>::pcState(const TheISA::PCState &val)
291 cpu->pcState(val, thread->threadId());
293 // Squash if we're not already in a state update mode.
294 if (!thread->trapPending && !thread->inSyscall) {
295 cpu->squashFromTC(thread->threadId());
299 template <class Impl>
301 O3ThreadContext<Impl>::flattenIntIndex(int reg)
303 return cpu->isa[thread->threadId()].flattenIntIndex(reg);
306 template <class Impl>
308 O3ThreadContext<Impl>::flattenFloatIndex(int reg)
310 return cpu->isa[thread->threadId()].flattenFloatIndex(reg);
313 template <class Impl>
315 O3ThreadContext<Impl>::setMiscRegNoEffect(int misc_reg, const MiscReg &val)
317 cpu->setMiscRegNoEffect(misc_reg, val, thread->threadId());
319 // Squash if we're not already in a state update mode.
320 if (!thread->trapPending && !thread->inSyscall) {
321 cpu->squashFromTC(thread->threadId());
325 template <class Impl>
327 O3ThreadContext<Impl>::setMiscReg(int misc_reg, const MiscReg &val)
329 cpu->setMiscReg(misc_reg, val, thread->threadId());
331 // Squash if we're not already in a state update mode.
332 if (!thread->trapPending && !thread->inSyscall) {
333 cpu->squashFromTC(thread->threadId());