2 * Copyright (c) 2004-2006 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "cpu/o3/thread_context.hh"
33 #include "cpu/quiesce_event.hh"
38 O3ThreadContext<Impl>::getVirtPort(ThreadContext *src_tc)
41 return thread->getVirtPort();
46 vp = new VirtualPort("tc-vport", src_tc);
47 mem_port = cpu->system->physmem->getPort("functional");
48 mem_port->setPeer(vp);
49 vp->setPeer(mem_port);
55 O3ThreadContext<Impl>::dumpFuncProfile()
57 // Currently not supported
63 O3ThreadContext<Impl>::takeOverFrom(ThreadContext *old_context)
65 // some things should already be set up
67 assert(getSystemPtr() == old_context->getSystemPtr());
69 assert(getProcessPtr() == old_context->getProcessPtr());
72 // copy over functional state
73 setStatus(old_context->status());
74 copyArchRegs(old_context);
75 setCpuId(old_context->readCpuId());
78 thread->funcExeInst = old_context->readFuncExeInst();
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 // storeCondFailures = 0;
93 cpu->lockFlag = false;
96 old_context->setStatus(ThreadContext::Unallocated);
98 thread->inSyscall = false;
99 thread->trapPending = false;
103 template <class Impl>
105 O3ThreadContext<Impl>::delVirtPort(VirtualPort *vp)
107 delete vp->getPeer();
112 template <class Impl>
114 O3ThreadContext<Impl>::activate(int delay)
116 DPRINTF(O3CPU, "Calling activate on Thread Context %d\n",
119 if (thread->status() == ThreadContext::Active)
123 thread->lastActivate = curTick;
126 if (thread->status() == ThreadContext::Unallocated) {
127 cpu->activateWhenReady(thread->readTid());
131 thread->setStatus(ThreadContext::Active);
133 // status() == Suspended
134 cpu->activateContext(thread->readTid(), delay);
137 template <class Impl>
139 O3ThreadContext<Impl>::suspend()
141 DPRINTF(O3CPU, "Calling suspend on Thread Context %d\n",
144 if (thread->status() == ThreadContext::Suspended)
148 thread->lastActivate = curTick;
149 thread->lastSuspend = curTick;
153 // Don't change the status from active if there are pending interrupts
154 if (cpu->check_interrupts()) {
155 assert(status() == ThreadContext::Active);
160 thread->setStatus(ThreadContext::Suspended);
161 cpu->suspendContext(thread->readTid());
164 template <class Impl>
166 O3ThreadContext<Impl>::deallocate(int delay)
168 DPRINTF(O3CPU, "Calling deallocate on Thread Context %d\n",
171 if (thread->status() == ThreadContext::Unallocated)
174 thread->setStatus(ThreadContext::Unallocated);
175 cpu->deallocateContext(thread->readTid(), delay);
178 template <class Impl>
180 O3ThreadContext<Impl>::halt()
182 DPRINTF(O3CPU, "Calling halt on Thread Context %d\n",
185 if (thread->status() == ThreadContext::Halted)
188 thread->setStatus(ThreadContext::Halted);
189 cpu->haltContext(thread->readTid());
192 template <class Impl>
194 O3ThreadContext<Impl>::regStats(const std::string &name)
197 thread->kernelStats = new Kernel::Statistics(cpu->system);
198 thread->kernelStats->regStats(name + ".kern");
202 template <class Impl>
204 O3ThreadContext<Impl>::serialize(std::ostream &os)
207 if (thread->kernelStats)
208 thread->kernelStats->serialize(os);
213 template <class Impl>
215 O3ThreadContext<Impl>::unserialize(Checkpoint *cp, const std::string §ion)
218 if (thread->kernelStats)
219 thread->kernelStats->unserialize(cp, section);
225 template <class Impl>
227 O3ThreadContext<Impl>::readLastActivate()
229 return thread->lastActivate;
232 template <class Impl>
234 O3ThreadContext<Impl>::readLastSuspend()
236 return thread->lastSuspend;
239 template <class Impl>
241 O3ThreadContext<Impl>::profileClear()
244 template <class Impl>
246 O3ThreadContext<Impl>::profileSample()
250 template <class Impl>
252 O3ThreadContext<Impl>:: getInst()
254 return thread->getInst();
257 template <class Impl>
259 O3ThreadContext<Impl>::copyArchRegs(ThreadContext *tc)
261 // This function will mess things up unless the ROB is empty and
262 // there are no instructions in the pipeline.
263 unsigned tid = thread->readTid();
264 PhysRegIndex renamed_reg;
266 // First loop through the integer registers.
267 for (int i = 0; i < TheISA::NumIntRegs; ++i) {
268 renamed_reg = cpu->renameMap[tid].lookup(i);
270 DPRINTF(O3CPU, "Copying over register %i, had data %lli, "
271 "now has data %lli.\n",
272 renamed_reg, cpu->readIntReg(renamed_reg),
275 cpu->setIntReg(renamed_reg, tc->readIntReg(i));
278 // Then loop through the floating point registers.
279 for (int i = 0; i < TheISA::NumFloatRegs; ++i) {
280 renamed_reg = cpu->renameMap[tid].lookup(i + TheISA::FP_Base_DepTag);
281 cpu->setFloatRegBits(renamed_reg,
282 tc->readFloatRegBits(i));
285 // Copy the misc regs.
286 copyMiscRegs(tc, this);
288 // Then finally set the PC and the next PC.
289 cpu->setPC(tc->readPC(), tid);
290 cpu->setNextPC(tc->readNextPC(), tid);
292 this->thread->funcExeInst = tc->readFuncExeInst();
296 template <class Impl>
298 O3ThreadContext<Impl>::clearArchRegs()
301 template <class Impl>
303 O3ThreadContext<Impl>::readIntReg(int reg_idx)
305 return cpu->readArchIntReg(reg_idx, thread->readTid());
308 template <class Impl>
310 O3ThreadContext<Impl>::readFloatReg(int reg_idx, int width)
314 return cpu->readArchFloatRegSingle(reg_idx, thread->readTid());
316 return cpu->readArchFloatRegDouble(reg_idx, thread->readTid());
318 panic("Unsupported width!");
323 template <class Impl>
325 O3ThreadContext<Impl>::readFloatReg(int reg_idx)
327 return cpu->readArchFloatRegSingle(reg_idx, thread->readTid());
330 template <class Impl>
332 O3ThreadContext<Impl>::readFloatRegBits(int reg_idx, int width)
334 DPRINTF(Fault, "Reading floatint register through the TC!\n");
335 return cpu->readArchFloatRegInt(reg_idx, thread->readTid());
338 template <class Impl>
340 O3ThreadContext<Impl>::readFloatRegBits(int reg_idx)
342 return cpu->readArchFloatRegInt(reg_idx, thread->readTid());
345 template <class Impl>
347 O3ThreadContext<Impl>::setIntReg(int reg_idx, uint64_t val)
349 cpu->setArchIntReg(reg_idx, val, thread->readTid());
351 // Squash if we're not already in a state update mode.
352 if (!thread->trapPending && !thread->inSyscall) {
353 cpu->squashFromTC(thread->readTid());
357 template <class Impl>
359 O3ThreadContext<Impl>::setFloatReg(int reg_idx, FloatReg val, int width)
363 cpu->setArchFloatRegSingle(reg_idx, val, thread->readTid());
366 cpu->setArchFloatRegDouble(reg_idx, val, thread->readTid());
370 // Squash if we're not already in a state update mode.
371 if (!thread->trapPending && !thread->inSyscall) {
372 cpu->squashFromTC(thread->readTid());
376 template <class Impl>
378 O3ThreadContext<Impl>::setFloatReg(int reg_idx, FloatReg val)
380 cpu->setArchFloatRegSingle(reg_idx, val, thread->readTid());
382 if (!thread->trapPending && !thread->inSyscall) {
383 cpu->squashFromTC(thread->readTid());
387 template <class Impl>
389 O3ThreadContext<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val,
392 DPRINTF(Fault, "Setting floatint register through the TC!\n");
393 cpu->setArchFloatRegInt(reg_idx, val, thread->readTid());
395 // Squash if we're not already in a state update mode.
396 if (!thread->trapPending && !thread->inSyscall) {
397 cpu->squashFromTC(thread->readTid());
401 template <class Impl>
403 O3ThreadContext<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val)
405 cpu->setArchFloatRegInt(reg_idx, val, thread->readTid());
407 // Squash if we're not already in a state update mode.
408 if (!thread->trapPending && !thread->inSyscall) {
409 cpu->squashFromTC(thread->readTid());
413 template <class Impl>
415 O3ThreadContext<Impl>::setPC(uint64_t val)
417 cpu->setPC(val, thread->readTid());
419 // Squash if we're not already in a state update mode.
420 if (!thread->trapPending && !thread->inSyscall) {
421 cpu->squashFromTC(thread->readTid());
425 template <class Impl>
427 O3ThreadContext<Impl>::setNextPC(uint64_t val)
429 cpu->setNextPC(val, thread->readTid());
431 // Squash if we're not already in a state update mode.
432 if (!thread->trapPending && !thread->inSyscall) {
433 cpu->squashFromTC(thread->readTid());
437 template <class Impl>
439 O3ThreadContext<Impl>::setMiscReg(int misc_reg, const MiscReg &val)
441 Fault ret_fault = cpu->setMiscReg(misc_reg, val, thread->readTid());
443 // Squash if we're not already in a state update mode.
444 if (!thread->trapPending && !thread->inSyscall) {
445 cpu->squashFromTC(thread->readTid());
451 template <class Impl>
453 O3ThreadContext<Impl>::setMiscRegWithEffect(int misc_reg,
456 Fault ret_fault = cpu->setMiscRegWithEffect(misc_reg, val,
459 // Squash if we're not already in a state update mode.
460 if (!thread->trapPending && !thread->inSyscall) {
461 cpu->squashFromTC(thread->readTid());
469 template <class Impl>
471 O3ThreadContext<Impl>::getSyscallArg(int i)
473 return cpu->getSyscallArg(i, thread->readTid());
476 template <class Impl>
478 O3ThreadContext<Impl>::setSyscallArg(int i, IntReg val)
480 cpu->setSyscallArg(i, val, thread->readTid());
483 template <class Impl>
485 O3ThreadContext<Impl>::setSyscallReturn(SyscallReturn return_value)
487 cpu->setSyscallReturn(return_value, thread->readTid());
490 #endif // FULL_SYSTEM