thread_context.hh revision 2315
1/* 2 * Copyright (c) 2006 The Regents of The University of Michigan 3 * All rights reserved. 4 * 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. 15 * 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. 27 */ 28 29#ifndef __CPU_EXEC_CONTEXT_HH__ 30#define __CPU_EXEC_CONTEXT_HH__ 31 32#include "config/full_system.hh" 33#include "mem/mem_req.hh" 34#include "sim/faults.hh" 35#include "sim/host.hh" 36#include "sim/serialize.hh" 37#include "sim/byteswap.hh" 38 39// forward declaration: see functional_memory.hh 40// @todo: Figure out a more architecture independent way to obtain the ITB and 41// DTB pointers. 42class AlphaDTB; 43class AlphaITB; 44class BaseCPU; 45class EndQuiesceEvent; 46class Event; 47class FunctionalMemory; 48class PhysicalMemory; 49class Process; 50class System; 51 52class ExecContext 53{ 54 protected: 55 typedef TheISA::RegFile RegFile; 56 typedef TheISA::MachInst MachInst; 57 typedef TheISA::IntReg IntReg; 58 typedef TheISA::MiscRegFile MiscRegFile; 59 typedef TheISA::MiscReg MiscReg; 60 public: 61 enum Status 62 { 63 /// Initialized but not running yet. All CPUs start in 64 /// this state, but most transition to Active on cycle 1. 65 /// In MP or SMT systems, non-primary contexts will stay 66 /// in this state until a thread is assigned to them. 67 Unallocated, 68 69 /// Running. Instructions should be executed only when 70 /// the context is in this state. 71 Active, 72 73 /// Temporarily inactive. Entered while waiting for 74 /// synchronization, etc. 75 Suspended, 76 77 /// Permanently shut down. Entered when target executes 78 /// m5exit pseudo-instruction. When all contexts enter 79 /// this state, the simulation will terminate. 80 Halted 81 }; 82 83 virtual ~ExecContext() { }; 84 85 virtual BaseCPU *getCpuPtr() = 0; 86 87 virtual void setCpuId(int id) = 0; 88 89 virtual int readCpuId() = 0; 90 91 virtual FunctionalMemory *getMemPtr() = 0; 92 93#if FULL_SYSTEM 94 virtual System *getSystemPtr() = 0; 95 96 virtual PhysicalMemory *getPhysMemPtr() = 0; 97 98 virtual AlphaITB *getITBPtr() = 0; 99 100 virtual AlphaDTB * getDTBPtr() = 0; 101#else 102 virtual Process *getProcessPtr() = 0; 103#endif 104 105 virtual Status status() const = 0; 106 107 virtual void setStatus(Status new_status) = 0; 108 109 /// Set the status to Active. Optional delay indicates number of 110 /// cycles to wait before beginning execution. 111 virtual void activate(int delay = 1) = 0; 112 113 /// Set the status to Suspended. 114 virtual void suspend() = 0; 115 116 /// Set the status to Unallocated. 117 virtual void deallocate() = 0; 118 119 /// Set the status to Halted. 120 virtual void halt() = 0; 121 122#if FULL_SYSTEM 123 virtual void dumpFuncProfile() = 0; 124#endif 125 126 virtual void takeOverFrom(ExecContext *old_context) = 0; 127 128 virtual void regStats(const std::string &name) = 0; 129 130 virtual void serialize(std::ostream &os) = 0; 131 virtual void unserialize(Checkpoint *cp, const std::string §ion) = 0; 132 133#if FULL_SYSTEM 134 virtual EndQuiesceEvent *getQuiesceEvent() = 0; 135 136 // Not necessarily the best location for these... 137 // Having an extra function just to read these is obnoxious 138 virtual Tick readLastActivate() = 0; 139 virtual Tick readLastSuspend() = 0; 140 141 virtual void profileClear() = 0; 142 virtual void profileSample() = 0; 143#endif 144 145 virtual int getThreadNum() = 0; 146 147 // Also somewhat obnoxious. Really only used for the TLB fault. 148 // However, may be quite useful in SPARC. 149 virtual TheISA::MachInst getInst() = 0; 150 151 virtual void copyArchRegs(ExecContext *xc) = 0; 152 153 virtual void clearArchRegs() = 0; 154 155 // 156 // New accessors for new decoder. 157 // 158 virtual uint64_t readIntReg(int reg_idx) = 0; 159 160 virtual float readFloatRegSingle(int reg_idx) = 0; 161 162 virtual double readFloatRegDouble(int reg_idx) = 0; 163 164 virtual uint64_t readFloatRegInt(int reg_idx) = 0; 165 166 virtual void setIntReg(int reg_idx, uint64_t val) = 0; 167 168 virtual void setFloatRegSingle(int reg_idx, float val) = 0; 169 170 virtual void setFloatRegDouble(int reg_idx, double val) = 0; 171 172 virtual void setFloatRegInt(int reg_idx, uint64_t val) = 0; 173 174 virtual uint64_t readPC() = 0; 175 176 virtual void setPC(uint64_t val) = 0; 177 178 virtual uint64_t readNextPC() = 0; 179 180 virtual void setNextPC(uint64_t val) = 0; 181 182 virtual MiscReg readMiscReg(int misc_reg) = 0; 183 184 virtual MiscReg readMiscRegWithEffect(int misc_reg, Fault &fault) = 0; 185 186 virtual Fault setMiscReg(int misc_reg, const MiscReg &val) = 0; 187 188 virtual Fault setMiscRegWithEffect(int misc_reg, const MiscReg &val) = 0; 189 190 // Also not necessarily the best location for these two. Hopefully will go 191 // away once we decide upon where st cond failures goes. 192 virtual unsigned readStCondFailures() = 0; 193 194 virtual void setStCondFailures(unsigned sc_failures) = 0; 195 196#if FULL_SYSTEM 197 virtual bool inPalMode() = 0; 198#endif 199 200 // Only really makes sense for old CPU model. Still could be useful though. 201 virtual bool misspeculating() = 0; 202 203#if !FULL_SYSTEM 204 virtual IntReg getSyscallArg(int i) = 0; 205 206 // used to shift args for indirect syscall 207 virtual void setSyscallArg(int i, IntReg val) = 0; 208 209 virtual void setSyscallReturn(SyscallReturn return_value) = 0; 210 211// virtual void syscall() = 0; 212 213 // Same with st cond failures. 214 virtual Counter readFuncExeInst() = 0; 215#endif 216}; 217 218template <class XC> 219class ProxyExecContext : public ExecContext 220{ 221 public: 222 ProxyExecContext(XC *actual_xc) 223 { actualXC = actual_xc; } 224 225 private: 226 XC *actualXC; 227 228 public: 229 230 BaseCPU *getCpuPtr() { return actualXC->getCpuPtr(); } 231 232 void setCpuId(int id) { actualXC->setCpuId(id); } 233 234 int readCpuId() { return actualXC->readCpuId(); } 235 236 FunctionalMemory *getMemPtr() { return actualXC->getMemPtr(); } 237 238#if FULL_SYSTEM 239 System *getSystemPtr() { return actualXC->getSystemPtr(); } 240 241 PhysicalMemory *getPhysMemPtr() { return actualXC->getPhysMemPtr(); } 242 243 AlphaITB *getITBPtr() { return actualXC->getITBPtr(); } 244 245 AlphaDTB *getDTBPtr() { return actualXC->getDTBPtr(); } 246#else 247 Process *getProcessPtr() { return actualXC->getProcessPtr(); } 248#endif 249 250 Status status() const { return actualXC->status(); } 251 252 void setStatus(Status new_status) { actualXC->setStatus(new_status); } 253 254 /// Set the status to Active. Optional delay indicates number of 255 /// cycles to wait before beginning execution. 256 void activate(int delay = 1) { actualXC->activate(delay); } 257 258 /// Set the status to Suspended. 259 void suspend() { actualXC->suspend(); } 260 261 /// Set the status to Unallocated. 262 void deallocate() { actualXC->deallocate(); } 263 264 /// Set the status to Halted. 265 void halt() { actualXC->halt(); } 266 267#if FULL_SYSTEM 268 void dumpFuncProfile() { actualXC->dumpFuncProfile(); } 269#endif 270 271 void takeOverFrom(ExecContext *oldContext) 272 { actualXC->takeOverFrom(oldContext); } 273 274 void regStats(const std::string &name) { actualXC->regStats(name); } 275 276 void serialize(std::ostream &os) { actualXC->serialize(os); } 277 void unserialize(Checkpoint *cp, const std::string §ion) 278 { actualXC->unserialize(cp, section); } 279 280#if FULL_SYSTEM 281 EndQuiesceEvent *getQuiesceEvent() { return actualXC->getQuiesceEvent(); } 282 283 Tick readLastActivate() { return actualXC->readLastActivate(); } 284 Tick readLastSuspend() { return actualXC->readLastSuspend(); } 285 286 void profileClear() { return actualXC->profileClear(); } 287 void profileSample() { return actualXC->profileSample(); } 288#endif 289 290 int getThreadNum() { return actualXC->getThreadNum(); } 291 292 // @todo: Do I need this? 293 MachInst getInst() { return actualXC->getInst(); } 294 295 // @todo: Do I need this? 296 void copyArchRegs(ExecContext *xc) { actualXC->copyArchRegs(xc); } 297 298 void clearArchRegs() { actualXC->clearArchRegs(); } 299 300 // 301 // New accessors for new decoder. 302 // 303 uint64_t readIntReg(int reg_idx) 304 { return actualXC->readIntReg(reg_idx); } 305 306 float readFloatRegSingle(int reg_idx) 307 { return actualXC->readFloatRegSingle(reg_idx); } 308 309 double readFloatRegDouble(int reg_idx) 310 { return actualXC->readFloatRegDouble(reg_idx); } 311 312 uint64_t readFloatRegInt(int reg_idx) 313 { return actualXC->readFloatRegInt(reg_idx); } 314 315 void setIntReg(int reg_idx, uint64_t val) 316 { actualXC->setIntReg(reg_idx, val); } 317 318 void setFloatRegSingle(int reg_idx, float val) 319 { actualXC->setFloatRegSingle(reg_idx, val); } 320 321 void setFloatRegDouble(int reg_idx, double val) 322 { actualXC->setFloatRegDouble(reg_idx, val); } 323 324 void setFloatRegInt(int reg_idx, uint64_t val) 325 { actualXC->setFloatRegInt(reg_idx, val); } 326 327 uint64_t readPC() { return actualXC->readPC(); } 328 329 void setPC(uint64_t val) { actualXC->setPC(val); } 330 331 uint64_t readNextPC() { return actualXC->readNextPC(); } 332 333 void setNextPC(uint64_t val) { actualXC->setNextPC(val); } 334 335 MiscReg readMiscReg(int misc_reg) 336 { return actualXC->readMiscReg(misc_reg); } 337 338 MiscReg readMiscRegWithEffect(int misc_reg, Fault &fault) 339 { return actualXC->readMiscRegWithEffect(misc_reg, fault); } 340 341 Fault setMiscReg(int misc_reg, const MiscReg &val) 342 { return actualXC->setMiscReg(misc_reg, val); } 343 344 Fault setMiscRegWithEffect(int misc_reg, const MiscReg &val) 345 { return actualXC->setMiscRegWithEffect(misc_reg, val); } 346 347 unsigned readStCondFailures() 348 { return actualXC->readStCondFailures(); } 349 350 void setStCondFailures(unsigned sc_failures) 351 { actualXC->setStCondFailures(sc_failures); } 352#if FULL_SYSTEM 353 bool inPalMode() { return actualXC->inPalMode(); } 354#endif 355 356 // @todo: Fix this! 357 bool misspeculating() { return actualXC->misspeculating(); } 358 359#if !FULL_SYSTEM 360 IntReg getSyscallArg(int i) { return actualXC->getSyscallArg(i); } 361 362 // used to shift args for indirect syscall 363 void setSyscallArg(int i, IntReg val) 364 { actualXC->setSyscallArg(i, val); } 365 366 void setSyscallReturn(SyscallReturn return_value) 367 { actualXC->setSyscallReturn(return_value); } 368 369// void syscall() { actualXC->syscall(); } 370 371 Counter readFuncExeInst() { return actualXC->readFuncExeInst(); } 372#endif 373}; 374 375#endif 376