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/registers.hh"
33 #include "config/the_isa.hh"
34 #include "cpu/o3/thread_context.hh"
35 #include "cpu/quiesce_event.hh"
40 O3ThreadContext<Impl>::getVirtPort()
42 return thread->getVirtPort();
47 O3ThreadContext<Impl>::dumpFuncProfile()
49 thread->dumpFuncProfile();
55 O3ThreadContext<Impl>::takeOverFrom(ThreadContext *old_context)
57 // some things should already be set up
58 assert(getSystemPtr() == old_context->getSystemPtr());
60 assert(getProcessPtr() == old_context->getProcessPtr());
63 // copy over functional state
64 setStatus(old_context->status());
65 copyArchRegs(old_context);
66 setContextId(old_context->contextId());
67 setThreadId(old_context->threadId());
70 thread->funcExeInst = old_context->readFuncExeInst();
72 EndQuiesceEvent *other_quiesce = old_context->getQuiesceEvent();
74 // Point the quiesce event's TC at this TC so that it wakes up
76 other_quiesce->tc = this;
78 if (thread->quiesceEvent) {
79 thread->quiesceEvent->tc = this;
82 // Transfer kernel stats from one CPU to the other.
83 thread->kernelStats = old_context->getKernelStats();
84 // storeCondFailures = 0;
85 cpu->lockFlag = false;
88 old_context->setStatus(ThreadContext::Halted);
90 thread->inSyscall = false;
91 thread->trapPending = false;
96 O3ThreadContext<Impl>::activate(int delay)
98 DPRINTF(O3CPU, "Calling activate on Thread Context %d\n",
101 if (thread->status() == ThreadContext::Active)
105 thread->lastActivate = curTick;
108 thread->setStatus(ThreadContext::Active);
110 // status() == Suspended
111 cpu->activateContext(thread->threadId(), delay);
114 template <class Impl>
116 O3ThreadContext<Impl>::suspend(int delay)
118 DPRINTF(O3CPU, "Calling suspend on Thread Context %d\n",
121 if (thread->status() == ThreadContext::Suspended)
125 thread->lastActivate = curTick;
126 thread->lastSuspend = curTick;
130 // Don't change the status from active if there are pending interrupts
131 if (cpu->checkInterrupts()) {
132 assert(status() == ThreadContext::Active);
137 thread->setStatus(ThreadContext::Suspended);
138 cpu->suspendContext(thread->threadId());
141 template <class Impl>
143 O3ThreadContext<Impl>::halt(int delay)
145 DPRINTF(O3CPU, "Calling halt on Thread Context %d\n",
148 if (thread->status() == ThreadContext::Halted)
151 thread->setStatus(ThreadContext::Halted);
152 cpu->haltContext(thread->threadId());
155 template <class Impl>
157 O3ThreadContext<Impl>::regStats(const std::string &name)
160 thread->kernelStats = new TheISA::Kernel::Statistics(cpu->system);
161 thread->kernelStats->regStats(name + ".kern");
165 template <class Impl>
167 O3ThreadContext<Impl>::serialize(std::ostream &os)
170 if (thread->kernelStats)
171 thread->kernelStats->serialize(os);
176 template <class Impl>
178 O3ThreadContext<Impl>::unserialize(Checkpoint *cp, const std::string §ion)
181 if (thread->kernelStats)
182 thread->kernelStats->unserialize(cp, section);
188 template <class Impl>
190 O3ThreadContext<Impl>::readLastActivate()
192 return thread->lastActivate;
195 template <class Impl>
197 O3ThreadContext<Impl>::readLastSuspend()
199 return thread->lastSuspend;
202 template <class Impl>
204 O3ThreadContext<Impl>::profileClear()
206 thread->profileClear();
209 template <class Impl>
211 O3ThreadContext<Impl>::profileSample()
213 thread->profileSample();
217 template <class Impl>
219 O3ThreadContext<Impl>:: getInst()
221 return thread->getInst();
224 template <class Impl>
226 O3ThreadContext<Impl>::copyArchRegs(ThreadContext *tc)
228 // This function will mess things up unless the ROB is empty and
229 // there are no instructions in the pipeline.
230 ThreadID tid = thread->threadId();
231 PhysRegIndex renamed_reg;
233 // First loop through the integer registers.
234 for (int i = 0; i < TheISA::NumIntRegs; ++i) {
235 renamed_reg = cpu->renameMap[tid].lookup(i);
237 DPRINTF(O3CPU, "Copying over register %i, had data %lli, "
238 "now has data %lli.\n",
239 renamed_reg, cpu->readIntReg(renamed_reg),
242 cpu->setIntReg(renamed_reg, tc->readIntReg(i));
245 // Then loop through the floating point registers.
246 for (int i = 0; i < TheISA::NumFloatRegs; ++i) {
247 renamed_reg = cpu->renameMap[tid].lookup(i + TheISA::FP_Base_DepTag);
248 cpu->setFloatRegBits(renamed_reg,
249 tc->readFloatRegBits(i));
252 // Copy the misc regs.
253 TheISA::copyMiscRegs(tc, this);
255 // Then finally set the PC, the next PC, the nextNPC, the micropc, and the
257 cpu->setPC(tc->readPC(), tid);
258 cpu->setNextPC(tc->readNextPC(), tid);
259 cpu->setNextNPC(tc->readNextNPC(), tid);
260 cpu->setMicroPC(tc->readMicroPC(), tid);
261 cpu->setNextMicroPC(tc->readNextMicroPC(), tid);
263 this->thread->funcExeInst = tc->readFuncExeInst();
267 template <class Impl>
269 O3ThreadContext<Impl>::clearArchRegs()
272 template <class Impl>
274 O3ThreadContext<Impl>::readIntReg(int reg_idx)
276 reg_idx = cpu->isa[thread->threadId()].flattenIntIndex(reg_idx);
277 return cpu->readArchIntReg(reg_idx, thread->threadId());
280 template <class Impl>
282 O3ThreadContext<Impl>::readFloatReg(int reg_idx)
284 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx);
285 return cpu->readArchFloatReg(reg_idx, thread->threadId());
288 template <class Impl>
290 O3ThreadContext<Impl>::readFloatRegBits(int reg_idx)
292 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx);
293 return cpu->readArchFloatRegInt(reg_idx, thread->threadId());
296 template <class Impl>
298 O3ThreadContext<Impl>::setIntReg(int reg_idx, uint64_t val)
300 reg_idx = cpu->isa[thread->threadId()].flattenIntIndex(reg_idx);
301 cpu->setArchIntReg(reg_idx, val, thread->threadId());
303 // Squash if we're not already in a state update mode.
304 if (!thread->trapPending && !thread->inSyscall) {
305 cpu->squashFromTC(thread->threadId());
309 template <class Impl>
311 O3ThreadContext<Impl>::setFloatReg(int reg_idx, FloatReg val)
313 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx);
314 cpu->setArchFloatReg(reg_idx, val, thread->threadId());
316 if (!thread->trapPending && !thread->inSyscall) {
317 cpu->squashFromTC(thread->threadId());
321 template <class Impl>
323 O3ThreadContext<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val)
325 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx);
326 cpu->setArchFloatRegInt(reg_idx, val, thread->threadId());
328 // Squash if we're not already in a state update mode.
329 if (!thread->trapPending && !thread->inSyscall) {
330 cpu->squashFromTC(thread->threadId());
334 template <class Impl>
336 O3ThreadContext<Impl>::setPC(uint64_t val)
338 cpu->setPC(val, thread->threadId());
340 // Squash if we're not already in a state update mode.
341 if (!thread->trapPending && !thread->inSyscall) {
342 cpu->squashFromTC(thread->threadId());
346 template <class Impl>
348 O3ThreadContext<Impl>::setNextPC(uint64_t val)
350 cpu->setNextPC(val, thread->threadId());
352 // Squash if we're not already in a state update mode.
353 if (!thread->trapPending && !thread->inSyscall) {
354 cpu->squashFromTC(thread->threadId());
358 template <class Impl>
360 O3ThreadContext<Impl>::setMicroPC(uint64_t val)
362 cpu->setMicroPC(val, thread->threadId());
364 // Squash if we're not already in a state update mode.
365 if (!thread->trapPending && !thread->inSyscall) {
366 cpu->squashFromTC(thread->threadId());
370 template <class Impl>
372 O3ThreadContext<Impl>::setNextMicroPC(uint64_t val)
374 cpu->setNextMicroPC(val, thread->threadId());
376 // Squash if we're not already in a state update mode.
377 if (!thread->trapPending && !thread->inSyscall) {
378 cpu->squashFromTC(thread->threadId());
382 template <class Impl>
384 O3ThreadContext<Impl>::flattenIntIndex(int reg)
386 return cpu->isa[thread->threadId()].flattenIntIndex(reg);
389 template <class Impl>
391 O3ThreadContext<Impl>::flattenFloatIndex(int reg)
393 return cpu->isa[thread->threadId()].flattenFloatIndex(reg);
396 template <class Impl>
398 O3ThreadContext<Impl>::setMiscRegNoEffect(int misc_reg, const MiscReg &val)
400 cpu->setMiscRegNoEffect(misc_reg, val, thread->threadId());
402 // Squash if we're not already in a state update mode.
403 if (!thread->trapPending && !thread->inSyscall) {
404 cpu->squashFromTC(thread->threadId());
408 template <class Impl>
410 O3ThreadContext<Impl>::setMiscReg(int misc_reg,
413 cpu->setMiscReg(misc_reg, val, thread->threadId());
415 // Squash if we're not already in a state update mode.
416 if (!thread->trapPending && !thread->inSyscall) {
417 cpu->squashFromTC(thread->threadId());