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"
34 using namespace TheISA;
39 O3ThreadContext<Impl>::getVirtPort(ThreadContext *src_tc)
42 return thread->getVirtPort();
47 vp = new VirtualPort("tc-vport", src_tc);
48 mem_port = cpu->system->physmem->getPort("functional");
49 mem_port->setPeer(vp);
50 vp->setPeer(mem_port);
56 O3ThreadContext<Impl>::dumpFuncProfile()
58 // Currently not supported
64 O3ThreadContext<Impl>::takeOverFrom(ThreadContext *old_context)
66 // some things should already be set up
68 assert(getSystemPtr() == old_context->getSystemPtr());
70 assert(getProcessPtr() == old_context->getProcessPtr());
73 // copy over functional state
74 setStatus(old_context->status());
75 copyArchRegs(old_context);
76 setCpuId(old_context->readCpuId());
79 thread->funcExeInst = old_context->readFuncExeInst();
81 EndQuiesceEvent *other_quiesce = old_context->getQuiesceEvent();
83 // Point the quiesce event's TC at this TC so that it wakes up
85 other_quiesce->tc = this;
87 if (thread->quiesceEvent) {
88 thread->quiesceEvent->tc = this;
91 // Transfer kernel stats from one CPU to the other.
92 thread->kernelStats = old_context->getKernelStats();
93 // storeCondFailures = 0;
94 cpu->lockFlag = false;
97 old_context->setStatus(ThreadContext::Unallocated);
99 thread->inSyscall = false;
100 thread->trapPending = false;
104 template <class Impl>
106 O3ThreadContext<Impl>::delVirtPort(VirtualPort *vp)
108 delete vp->getPeer();
113 template <class Impl>
115 O3ThreadContext<Impl>::activate(int delay)
117 DPRINTF(O3CPU, "Calling activate on AlphaTC\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 AlphaTC\n");
143 if (thread->status() == ThreadContext::Suspended)
147 thread->lastActivate = curTick;
148 thread->lastSuspend = curTick;
152 // Don't change the status from active if there are pending interrupts
153 if (cpu->check_interrupts()) {
154 assert(status() == ThreadContext::Active);
159 thread->setStatus(ThreadContext::Suspended);
160 cpu->suspendContext(thread->readTid());
163 template <class Impl>
165 O3ThreadContext<Impl>::deallocate()
167 DPRINTF(O3CPU, "Calling deallocate on AlphaTC\n");
169 if (thread->status() == ThreadContext::Unallocated)
172 thread->setStatus(ThreadContext::Unallocated);
173 cpu->deallocateContext(thread->readTid());
176 template <class Impl>
178 O3ThreadContext<Impl>::halt()
180 DPRINTF(O3CPU, "Calling halt on AlphaTC\n");
182 if (thread->status() == ThreadContext::Halted)
185 thread->setStatus(ThreadContext::Halted);
186 cpu->haltContext(thread->readTid());
189 template <class Impl>
191 O3ThreadContext<Impl>::regStats(const std::string &name)
194 thread->kernelStats = new Kernel::Statistics(cpu->system);
195 thread->kernelStats->regStats(name + ".kern");
199 template <class Impl>
201 O3ThreadContext<Impl>::serialize(std::ostream &os)
204 if (thread->kernelStats)
205 thread->kernelStats->serialize(os);
210 template <class Impl>
212 O3ThreadContext<Impl>::unserialize(Checkpoint *cp, const std::string §ion)
215 if (thread->kernelStats)
216 thread->kernelStats->unserialize(cp, section);
222 template <class Impl>
224 O3ThreadContext<Impl>::readLastActivate()
226 return thread->lastActivate;
229 template <class Impl>
231 O3ThreadContext<Impl>::readLastSuspend()
233 return thread->lastSuspend;
236 template <class Impl>
238 O3ThreadContext<Impl>::profileClear()
241 template <class Impl>
243 O3ThreadContext<Impl>::profileSample()
247 template <class Impl>
249 O3ThreadContext<Impl>:: getInst()
251 return thread->getInst();
254 template <class Impl>
256 O3ThreadContext<Impl>::copyArchRegs(ThreadContext *tc)
258 // This function will mess things up unless the ROB is empty and
259 // there are no instructions in the pipeline.
260 unsigned tid = thread->readTid();
261 PhysRegIndex renamed_reg;
263 // First loop through the integer registers.
264 for (int i = 0; i < TheISA::NumIntRegs; ++i) {
265 renamed_reg = cpu->renameMap[tid].lookup(i);
267 DPRINTF(O3CPU, "Copying over register %i, had data %lli, "
268 "now has data %lli.\n",
269 renamed_reg, cpu->readIntReg(renamed_reg),
272 cpu->setIntReg(renamed_reg, tc->readIntReg(i));
275 // Then loop through the floating point registers.
276 for (int i = 0; i < TheISA::NumFloatRegs; ++i) {
277 renamed_reg = cpu->renameMap[tid].lookup(i + TheISA::FP_Base_DepTag);
278 cpu->setFloatRegBits(renamed_reg,
279 tc->readFloatRegBits(i));
282 // Copy the misc regs.
283 copyMiscRegs(tc, this);
285 // Then finally set the PC and the next PC.
286 cpu->setPC(tc->readPC(), tid);
287 cpu->setNextPC(tc->readNextPC(), tid);
289 this->thread->funcExeInst = tc->readFuncExeInst();
293 template <class Impl>
295 O3ThreadContext<Impl>::clearArchRegs()
298 template <class Impl>
300 O3ThreadContext<Impl>::readIntReg(int reg_idx)
302 return cpu->readArchIntReg(reg_idx, thread->readTid());
305 template <class Impl>
307 O3ThreadContext<Impl>::readFloatReg(int reg_idx, int width)
311 return cpu->readArchFloatRegSingle(reg_idx, thread->readTid());
313 return cpu->readArchFloatRegDouble(reg_idx, thread->readTid());
315 panic("Unsupported width!");
320 template <class Impl>
322 O3ThreadContext<Impl>::readFloatReg(int reg_idx)
324 return cpu->readArchFloatRegSingle(reg_idx, thread->readTid());
327 template <class Impl>
329 O3ThreadContext<Impl>::readFloatRegBits(int reg_idx, int width)
331 DPRINTF(Fault, "Reading floatint register through the TC!\n");
332 return cpu->readArchFloatRegInt(reg_idx, thread->readTid());
335 template <class Impl>
337 O3ThreadContext<Impl>::readFloatRegBits(int reg_idx)
339 return cpu->readArchFloatRegInt(reg_idx, thread->readTid());
342 template <class Impl>
344 O3ThreadContext<Impl>::setIntReg(int reg_idx, uint64_t val)
346 cpu->setArchIntReg(reg_idx, val, thread->readTid());
348 // Squash if we're not already in a state update mode.
349 if (!thread->trapPending && !thread->inSyscall) {
350 cpu->squashFromTC(thread->readTid());
354 template <class Impl>
356 O3ThreadContext<Impl>::setFloatReg(int reg_idx, FloatReg val, int width)
360 cpu->setArchFloatRegSingle(reg_idx, val, thread->readTid());
363 cpu->setArchFloatRegDouble(reg_idx, val, thread->readTid());
367 // Squash if we're not already in a state update mode.
368 if (!thread->trapPending && !thread->inSyscall) {
369 cpu->squashFromTC(thread->readTid());
373 template <class Impl>
375 O3ThreadContext<Impl>::setFloatReg(int reg_idx, FloatReg val)
377 cpu->setArchFloatRegSingle(reg_idx, val, thread->readTid());
379 if (!thread->trapPending && !thread->inSyscall) {
380 cpu->squashFromTC(thread->readTid());
384 template <class Impl>
386 O3ThreadContext<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val,
389 DPRINTF(Fault, "Setting floatint register through the TC!\n");
390 cpu->setArchFloatRegInt(reg_idx, val, thread->readTid());
392 // Squash if we're not already in a state update mode.
393 if (!thread->trapPending && !thread->inSyscall) {
394 cpu->squashFromTC(thread->readTid());
398 template <class Impl>
400 O3ThreadContext<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val)
402 cpu->setArchFloatRegInt(reg_idx, val, thread->readTid());
404 // Squash if we're not already in a state update mode.
405 if (!thread->trapPending && !thread->inSyscall) {
406 cpu->squashFromTC(thread->readTid());
410 template <class Impl>
412 O3ThreadContext<Impl>::setPC(uint64_t val)
414 cpu->setPC(val, thread->readTid());
416 // Squash if we're not already in a state update mode.
417 if (!thread->trapPending && !thread->inSyscall) {
418 cpu->squashFromTC(thread->readTid());
422 template <class Impl>
424 O3ThreadContext<Impl>::setNextPC(uint64_t val)
426 cpu->setNextPC(val, thread->readTid());
428 // Squash if we're not already in a state update mode.
429 if (!thread->trapPending && !thread->inSyscall) {
430 cpu->squashFromTC(thread->readTid());
434 template <class Impl>
436 O3ThreadContext<Impl>::setMiscReg(int misc_reg, const MiscReg &val)
438 Fault ret_fault = cpu->setMiscReg(misc_reg, val, thread->readTid());
440 // Squash if we're not already in a state update mode.
441 if (!thread->trapPending && !thread->inSyscall) {
442 cpu->squashFromTC(thread->readTid());
448 template <class Impl>
450 O3ThreadContext<Impl>::setMiscRegWithEffect(int misc_reg,
453 Fault ret_fault = cpu->setMiscRegWithEffect(misc_reg, val,
456 // Squash if we're not already in a state update mode.
457 if (!thread->trapPending && !thread->inSyscall) {
458 cpu->squashFromTC(thread->readTid());
466 template <class Impl>
468 O3ThreadContext<Impl>::getSyscallArg(int i)
470 return cpu->getSyscallArg(i, thread->readTid());
473 template <class Impl>
475 O3ThreadContext<Impl>::setSyscallArg(int i, IntReg val)
477 cpu->setSyscallArg(i, val, thread->readTid());
480 template <class Impl>
482 O3ThreadContext<Impl>::setSyscallReturn(SyscallReturn return_value)
484 cpu->setSyscallReturn(return_value, thread->readTid());
487 #endif // FULL_SYSTEM