thread_context_impl.hh revision 8733:64a7bf8fa56c
13914Ssaidi@eecs.umich.edu/* 28332Snate@binkert.org * Copyright (c) 2010-2011 ARM Limited 33914Ssaidi@eecs.umich.edu * All rights reserved 43914Ssaidi@eecs.umich.edu * 53914Ssaidi@eecs.umich.edu * The license below extends only to copyright in the software and shall 63914Ssaidi@eecs.umich.edu * not be construed as granting a license to any other intellectual 73914Ssaidi@eecs.umich.edu * property including but not limited to intellectual property relating 83914Ssaidi@eecs.umich.edu * to a hardware implementation of the functionality of the software 93914Ssaidi@eecs.umich.edu * licensed hereunder. You may use the software subject to the license 103914Ssaidi@eecs.umich.edu * terms below provided that you ensure that this notice is replicated 113914Ssaidi@eecs.umich.edu * unmodified and in its entirety in all distributions of the software, 123914Ssaidi@eecs.umich.edu * modified or unmodified, in source code or in binary form. 133914Ssaidi@eecs.umich.edu * 143914Ssaidi@eecs.umich.edu * Copyright (c) 2004-2006 The Regents of The University of Michigan 153914Ssaidi@eecs.umich.edu * All rights reserved. 163914Ssaidi@eecs.umich.edu * 173914Ssaidi@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 183914Ssaidi@eecs.umich.edu * modification, are permitted provided that the following conditions are 193914Ssaidi@eecs.umich.edu * met: redistributions of source code must retain the above copyright 203914Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 213914Ssaidi@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 223914Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 233914Ssaidi@eecs.umich.edu * documentation and/or other materials provided with the distribution; 243914Ssaidi@eecs.umich.edu * neither the name of the copyright holders nor the names of its 253914Ssaidi@eecs.umich.edu * contributors may be used to endorse or promote products derived from 263914Ssaidi@eecs.umich.edu * this software without specific prior written permission. 273914Ssaidi@eecs.umich.edu * 283914Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 293914Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 303914Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 313914Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 323914Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 333914Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 343914Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 353914Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 363914Ssaidi@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 373914Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 383914Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 393943Sbinkertn@umich.edu * 403943Sbinkertn@umich.edu * Authors: Kevin Lim 413914Ssaidi@eecs.umich.edu * Korey Sewell 424762Snate@binkert.org */ 433914Ssaidi@eecs.umich.edu 443914Ssaidi@eecs.umich.edu#include "arch/registers.hh" 453914Ssaidi@eecs.umich.edu#include "config/the_isa.hh" 463914Ssaidi@eecs.umich.edu#include "config/use_checker.hh" 473914Ssaidi@eecs.umich.edu#include "cpu/o3/thread_context.hh" 483914Ssaidi@eecs.umich.edu#include "cpu/quiesce_event.hh" 493914Ssaidi@eecs.umich.edu#include "debug/O3CPU.hh" 503914Ssaidi@eecs.umich.edu 513914Ssaidi@eecs.umich.edu#if FULL_SYSTEM 523914Ssaidi@eecs.umich.edutemplate <class Impl> 533914Ssaidi@eecs.umich.eduFSTranslatingPortProxy* 544762Snate@binkert.orgO3ThreadContext<Impl>::getVirtProxy() 554762Snate@binkert.org{ 564762Snate@binkert.org return thread->getVirtProxy(); 574762Snate@binkert.org} 584762Snate@binkert.org 593914Ssaidi@eecs.umich.edutemplate <class Impl> 604762Snate@binkert.orgvoid 614762Snate@binkert.orgO3ThreadContext<Impl>::dumpFuncProfile() 623914Ssaidi@eecs.umich.edu{ 6311347Sandreas.hansson@arm.com thread->dumpFuncProfile(); 6411347Sandreas.hansson@arm.com} 653990Ssaidi@eecs.umich.edu#endif 6611168Sandreas.hansson@arm.com 6711168Sandreas.hansson@arm.comtemplate <class Impl> 683914Ssaidi@eecs.umich.eduvoid 693914Ssaidi@eecs.umich.eduO3ThreadContext<Impl>::takeOverFrom(ThreadContext *old_context) 703914Ssaidi@eecs.umich.edu{ 71 // some things should already be set up 72#if FULL_SYSTEM 73 assert(getSystemPtr() == old_context->getSystemPtr()); 74#else 75 assert(getProcessPtr() == old_context->getProcessPtr()); 76#endif 77 78 // copy over functional state 79 setStatus(old_context->status()); 80 copyArchRegs(old_context); 81 setContextId(old_context->contextId()); 82 setThreadId(old_context->threadId()); 83 84#if !FULL_SYSTEM 85 thread->funcExeInst = old_context->readFuncExeInst(); 86#else 87 EndQuiesceEvent *other_quiesce = old_context->getQuiesceEvent(); 88 if (other_quiesce) { 89 // Point the quiesce event's TC at this TC so that it wakes up 90 // the proper CPU. 91 other_quiesce->tc = this; 92 } 93 if (thread->quiesceEvent) { 94 thread->quiesceEvent->tc = this; 95 } 96 97 // Transfer kernel stats from one CPU to the other. 98 thread->kernelStats = old_context->getKernelStats(); 99// storeCondFailures = 0; 100 cpu->lockFlag = false; 101#endif 102 103 old_context->setStatus(ThreadContext::Halted); 104 105 thread->inSyscall = false; 106 thread->trapPending = false; 107} 108 109template <class Impl> 110void 111O3ThreadContext<Impl>::activate(int delay) 112{ 113 DPRINTF(O3CPU, "Calling activate on Thread Context %d\n", 114 threadId()); 115 116 if (thread->status() == ThreadContext::Active) 117 return; 118 119#if FULL_SYSTEM 120 thread->lastActivate = curTick(); 121#endif 122 123 thread->setStatus(ThreadContext::Active); 124 125 // status() == Suspended 126 cpu->activateContext(thread->threadId(), delay); 127} 128 129template <class Impl> 130void 131O3ThreadContext<Impl>::suspend(int delay) 132{ 133 DPRINTF(O3CPU, "Calling suspend on Thread Context %d\n", 134 threadId()); 135 136 if (thread->status() == ThreadContext::Suspended) 137 return; 138 139#if FULL_SYSTEM 140 thread->lastActivate = curTick(); 141 thread->lastSuspend = curTick(); 142#endif 143/* 144#if FULL_SYSTEM 145 // Don't change the status from active if there are pending interrupts 146 if (cpu->checkInterrupts()) { 147 assert(status() == ThreadContext::Active); 148 return; 149 } 150#endif 151*/ 152 thread->setStatus(ThreadContext::Suspended); 153 cpu->suspendContext(thread->threadId()); 154} 155 156template <class Impl> 157void 158O3ThreadContext<Impl>::halt(int delay) 159{ 160 DPRINTF(O3CPU, "Calling halt on Thread Context %d\n", 161 threadId()); 162 163 if (thread->status() == ThreadContext::Halted) 164 return; 165 166 thread->setStatus(ThreadContext::Halted); 167 cpu->haltContext(thread->threadId()); 168} 169 170template <class Impl> 171void 172O3ThreadContext<Impl>::regStats(const std::string &name) 173{ 174#if FULL_SYSTEM 175 thread->kernelStats = new TheISA::Kernel::Statistics(cpu->system); 176 thread->kernelStats->regStats(name + ".kern"); 177#endif 178} 179 180template <class Impl> 181void 182O3ThreadContext<Impl>::serialize(std::ostream &os) 183{ 184#if FULL_SYSTEM 185 if (thread->kernelStats) 186 thread->kernelStats->serialize(os); 187#endif 188 189} 190 191template <class Impl> 192void 193O3ThreadContext<Impl>::unserialize(Checkpoint *cp, const std::string §ion) 194{ 195#if FULL_SYSTEM 196 if (thread->kernelStats) 197 thread->kernelStats->unserialize(cp, section); 198#endif 199 200} 201 202#if FULL_SYSTEM 203template <class Impl> 204Tick 205O3ThreadContext<Impl>::readLastActivate() 206{ 207 return thread->lastActivate; 208} 209 210template <class Impl> 211Tick 212O3ThreadContext<Impl>::readLastSuspend() 213{ 214 return thread->lastSuspend; 215} 216 217template <class Impl> 218void 219O3ThreadContext<Impl>::profileClear() 220{ 221 thread->profileClear(); 222} 223 224template <class Impl> 225void 226O3ThreadContext<Impl>::profileSample() 227{ 228 thread->profileSample(); 229} 230#endif 231 232template <class Impl> 233void 234O3ThreadContext<Impl>::copyArchRegs(ThreadContext *tc) 235{ 236 // Prevent squashing 237 thread->inSyscall = true; 238 TheISA::copyRegs(tc, this); 239 thread->inSyscall = false; 240 241#if !FULL_SYSTEM 242 this->thread->funcExeInst = tc->readFuncExeInst(); 243#endif 244} 245 246template <class Impl> 247void 248O3ThreadContext<Impl>::clearArchRegs() 249{ 250 cpu->isa[thread->threadId()].clear(); 251} 252 253template <class Impl> 254uint64_t 255O3ThreadContext<Impl>::readIntReg(int reg_idx) 256{ 257 reg_idx = cpu->isa[thread->threadId()].flattenIntIndex(reg_idx); 258 return cpu->readArchIntReg(reg_idx, thread->threadId()); 259} 260 261template <class Impl> 262TheISA::FloatReg 263O3ThreadContext<Impl>::readFloatReg(int reg_idx) 264{ 265 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx); 266 return cpu->readArchFloatReg(reg_idx, thread->threadId()); 267} 268 269template <class Impl> 270TheISA::FloatRegBits 271O3ThreadContext<Impl>::readFloatRegBits(int reg_idx) 272{ 273 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx); 274 return cpu->readArchFloatRegInt(reg_idx, thread->threadId()); 275} 276 277template <class Impl> 278void 279O3ThreadContext<Impl>::setIntReg(int reg_idx, uint64_t val) 280{ 281 reg_idx = cpu->isa[thread->threadId()].flattenIntIndex(reg_idx); 282 cpu->setArchIntReg(reg_idx, val, thread->threadId()); 283 284 // Squash if we're not already in a state update mode. 285 if (!thread->trapPending && !thread->inSyscall) { 286 cpu->squashFromTC(thread->threadId()); 287 } 288} 289 290template <class Impl> 291void 292O3ThreadContext<Impl>::setFloatReg(int reg_idx, FloatReg val) 293{ 294 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx); 295 cpu->setArchFloatReg(reg_idx, val, thread->threadId()); 296 297 if (!thread->trapPending && !thread->inSyscall) { 298 cpu->squashFromTC(thread->threadId()); 299 } 300} 301 302template <class Impl> 303void 304O3ThreadContext<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val) 305{ 306 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx); 307 cpu->setArchFloatRegInt(reg_idx, val, thread->threadId()); 308 309 // Squash if we're not already in a state update mode. 310 if (!thread->trapPending && !thread->inSyscall) { 311 cpu->squashFromTC(thread->threadId()); 312 } 313} 314 315template <class Impl> 316void 317O3ThreadContext<Impl>::pcState(const TheISA::PCState &val) 318{ 319 cpu->pcState(val, thread->threadId()); 320 321 // Squash if we're not already in a state update mode. 322 if (!thread->trapPending && !thread->inSyscall) { 323 cpu->squashFromTC(thread->threadId()); 324 } 325} 326 327#if USE_CHECKER 328template <class Impl> 329void 330O3ThreadContext<Impl>::pcStateNoRecord(const TheISA::PCState &val) 331{ 332 cpu->pcState(val, thread->threadId()); 333 334 // Squash if we're not already in a state update mode. 335 if (!thread->trapPending && !thread->inSyscall) { 336 cpu->squashFromTC(thread->threadId()); 337 } 338} 339#endif 340 341template <class Impl> 342int 343O3ThreadContext<Impl>::flattenIntIndex(int reg) 344{ 345 return cpu->isa[thread->threadId()].flattenIntIndex(reg); 346} 347 348template <class Impl> 349int 350O3ThreadContext<Impl>::flattenFloatIndex(int reg) 351{ 352 return cpu->isa[thread->threadId()].flattenFloatIndex(reg); 353} 354 355template <class Impl> 356void 357O3ThreadContext<Impl>::setMiscRegNoEffect(int misc_reg, const MiscReg &val) 358{ 359 cpu->setMiscRegNoEffect(misc_reg, val, thread->threadId()); 360 361 // Squash if we're not already in a state update mode. 362 if (!thread->trapPending && !thread->inSyscall) { 363 cpu->squashFromTC(thread->threadId()); 364 } 365} 366 367template <class Impl> 368void 369O3ThreadContext<Impl>::setMiscReg(int misc_reg, const MiscReg &val) 370{ 371 cpu->setMiscReg(misc_reg, val, thread->threadId()); 372 373 // Squash if we're not already in a state update mode. 374 if (!thread->trapPending && !thread->inSyscall) { 375 cpu->squashFromTC(thread->threadId()); 376 } 377} 378 379