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