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 "arch/regfile.hh"
33 #include "cpu/o3/thread_context.hh"
34 #include "cpu/quiesce_event.hh"
39 O3ThreadContext<Impl>::getVirtPort(ThreadContext *src_tc)
42 return thread->getVirtPort();
46 vp = new VirtualPort("tc-vport", src_tc);
47 thread->connectToMemFunc(vp);
53 O3ThreadContext<Impl>::dumpFuncProfile()
55 thread->dumpFuncProfile();
61 O3ThreadContext<Impl>::takeOverFrom(ThreadContext *old_context)
63 // some things should already be set up
65 assert(getSystemPtr() == old_context->getSystemPtr());
67 assert(getProcessPtr() == old_context->getProcessPtr());
70 // copy over functional state
71 setStatus(old_context->status());
72 copyArchRegs(old_context);
73 setCpuId(old_context->readCpuId());
76 thread->funcExeInst = old_context->readFuncExeInst();
78 EndQuiesceEvent *other_quiesce = old_context->getQuiesceEvent();
80 // Point the quiesce event's TC at this TC so that it wakes up
82 other_quiesce->tc = this;
84 if (thread->quiesceEvent) {
85 thread->quiesceEvent->tc = this;
88 // Transfer kernel stats from one CPU to the other.
89 thread->kernelStats = old_context->getKernelStats();
90 // storeCondFailures = 0;
91 cpu->lockFlag = false;
94 old_context->setStatus(ThreadContext::Unallocated);
96 thread->inSyscall = false;
97 thread->trapPending = false;
101 template <class Impl>
103 O3ThreadContext<Impl>::delVirtPort(VirtualPort *vp)
105 if (vp != thread->getVirtPort()) {
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 delay %d\n",
169 getThreadNum(), delay);
171 if (thread->status() == ThreadContext::Unallocated)
174 thread->setStatus(ThreadContext::Unallocated);
175 cpu->deallocateContext(thread->readTid(), true, 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 TheISA::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()
243 thread->profileClear();
246 template <class Impl>
248 O3ThreadContext<Impl>::profileSample()
250 thread->profileSample();
254 template <class Impl>
256 O3ThreadContext<Impl>:: getInst()
258 return thread->getInst();
261 template <class Impl>
263 O3ThreadContext<Impl>::copyArchRegs(ThreadContext *tc)
265 // This function will mess things up unless the ROB is empty and
266 // there are no instructions in the pipeline.
267 unsigned tid = thread->readTid();
268 PhysRegIndex renamed_reg;
270 // First loop through the integer registers.
271 for (int i = 0; i < TheISA::NumIntRegs; ++i) {
272 renamed_reg = cpu->renameMap[tid].lookup(i);
274 DPRINTF(O3CPU, "Copying over register %i, had data %lli, "
275 "now has data %lli.\n",
276 renamed_reg, cpu->readIntReg(renamed_reg),
279 cpu->setIntReg(renamed_reg, tc->readIntReg(i));
282 // Then loop through the floating point registers.
283 for (int i = 0; i < TheISA::NumFloatRegs; ++i) {
284 renamed_reg = cpu->renameMap[tid].lookup(i + TheISA::FP_Base_DepTag);
285 cpu->setFloatRegBits(renamed_reg,
286 tc->readFloatRegBits(i));
289 // Copy the misc regs.
290 TheISA::copyMiscRegs(tc, this);
292 // Then finally set the PC and the next PC.
293 cpu->setPC(tc->readPC(), tid);
294 cpu->setNextPC(tc->readNextPC(), tid);
296 this->thread->funcExeInst = tc->readFuncExeInst();
300 template <class Impl>
302 O3ThreadContext<Impl>::clearArchRegs()
305 template <class Impl>
307 O3ThreadContext<Impl>::readIntReg(int reg_idx)
309 reg_idx = TheISA::flattenIntIndex(this, reg_idx);
310 return cpu->readArchIntReg(reg_idx, thread->readTid());
313 template <class Impl>
315 O3ThreadContext<Impl>::readFloatReg(int reg_idx, int width)
319 return cpu->readArchFloatRegSingle(reg_idx, thread->readTid());
321 return cpu->readArchFloatRegDouble(reg_idx, thread->readTid());
323 panic("Unsupported width!");
328 template <class Impl>
330 O3ThreadContext<Impl>::readFloatReg(int reg_idx)
332 return cpu->readArchFloatRegSingle(reg_idx, thread->readTid());
335 template <class Impl>
337 O3ThreadContext<Impl>::readFloatRegBits(int reg_idx, int width)
339 DPRINTF(Fault, "Reading floatint register through the TC!\n");
340 return cpu->readArchFloatRegInt(reg_idx, thread->readTid());
343 template <class Impl>
345 O3ThreadContext<Impl>::readFloatRegBits(int reg_idx)
347 return cpu->readArchFloatRegInt(reg_idx, thread->readTid());
350 template <class Impl>
352 O3ThreadContext<Impl>::setIntReg(int reg_idx, uint64_t val)
354 reg_idx = TheISA::flattenIntIndex(this, reg_idx);
355 cpu->setArchIntReg(reg_idx, val, thread->readTid());
357 // Squash if we're not already in a state update mode.
358 if (!thread->trapPending && !thread->inSyscall) {
359 cpu->squashFromTC(thread->readTid());
363 template <class Impl>
365 O3ThreadContext<Impl>::setFloatReg(int reg_idx, FloatReg val, int width)
369 cpu->setArchFloatRegSingle(reg_idx, val, thread->readTid());
372 cpu->setArchFloatRegDouble(reg_idx, val, thread->readTid());
376 // Squash if we're not already in a state update mode.
377 if (!thread->trapPending && !thread->inSyscall) {
378 cpu->squashFromTC(thread->readTid());
382 template <class Impl>
384 O3ThreadContext<Impl>::setFloatReg(int reg_idx, FloatReg val)
386 cpu->setArchFloatRegSingle(reg_idx, val, thread->readTid());
388 if (!thread->trapPending && !thread->inSyscall) {
389 cpu->squashFromTC(thread->readTid());
393 template <class Impl>
395 O3ThreadContext<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val,
398 DPRINTF(Fault, "Setting floatint register through the TC!\n");
399 cpu->setArchFloatRegInt(reg_idx, val, thread->readTid());
401 // Squash if we're not already in a state update mode.
402 if (!thread->trapPending && !thread->inSyscall) {
403 cpu->squashFromTC(thread->readTid());
407 template <class Impl>
409 O3ThreadContext<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val)
411 cpu->setArchFloatRegInt(reg_idx, val, thread->readTid());
413 // Squash if we're not already in a state update mode.
414 if (!thread->trapPending && !thread->inSyscall) {
415 cpu->squashFromTC(thread->readTid());
419 template <class Impl>
421 O3ThreadContext<Impl>::setPC(uint64_t val)
423 cpu->setPC(val, thread->readTid());
425 // Squash if we're not already in a state update mode.
426 if (!thread->trapPending && !thread->inSyscall) {
427 cpu->squashFromTC(thread->readTid());
431 template <class Impl>
433 O3ThreadContext<Impl>::setNextPC(uint64_t val)
435 cpu->setNextPC(val, thread->readTid());
437 // Squash if we're not already in a state update mode.
438 if (!thread->trapPending && !thread->inSyscall) {
439 cpu->squashFromTC(thread->readTid());
443 template <class Impl>
445 O3ThreadContext<Impl>::setMiscRegNoEffect(int misc_reg, const MiscReg &val)
447 cpu->setMiscRegNoEffect(misc_reg, val, thread->readTid());
449 // Squash if we're not already in a state update mode.
450 if (!thread->trapPending && !thread->inSyscall) {
451 cpu->squashFromTC(thread->readTid());
455 template <class Impl>
457 O3ThreadContext<Impl>::setMiscReg(int misc_reg,
460 cpu->setMiscReg(misc_reg, val, thread->readTid());
462 // Squash if we're not already in a state update mode.
463 if (!thread->trapPending && !thread->inSyscall) {
464 cpu->squashFromTC(thread->readTid());
470 template <class Impl>
472 O3ThreadContext<Impl>::getSyscallArg(int i)
474 return cpu->getSyscallArg(i, thread->readTid());
477 template <class Impl>
479 O3ThreadContext<Impl>::setSyscallArg(int i, IntReg val)
481 cpu->setSyscallArg(i, val, thread->readTid());
484 template <class Impl>
486 O3ThreadContext<Impl>::setSyscallReturn(SyscallReturn return_value)
488 cpu->setSyscallReturn(return_value, thread->readTid());
491 #endif // FULL_SYSTEM