2 * Copyright (c) 2001-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.
29 #ifndef __CPU_CPU_EXEC_CONTEXT_HH__
30 #define __CPU_CPU_EXEC_CONTEXT_HH__
32 #include "arch/isa_traits.hh"
33 #include "config/full_system.hh"
34 #include "cpu/exec_context.hh"
35 #include "mem/physical.hh"
36 #include "mem/request.hh"
37 #include "sim/byteswap.hh"
38 #include "sim/eventq.hh"
39 #include "sim/host.hh"
40 #include "sim/serialize.hh"
46 #include "sim/system.hh"
47 #include "arch/tlb.hh"
49 class FunctionProfile;
57 #include "sim/process.hh"
58 #include "mem/page_table.hh"
59 class TranslatingPort;
65 // The CPUExecContext object represents a functional context for
66 // instruction execution. It incorporates everything required for
67 // architecture-level functional simulation of a single thread.
73 typedef TheISA::RegFile RegFile;
74 typedef TheISA::MachInst MachInst;
75 typedef TheISA::MiscRegFile MiscRegFile;
76 typedef TheISA::MiscReg MiscReg;
77 typedef TheISA::FloatReg FloatReg;
78 typedef TheISA::FloatRegBits FloatRegBits;
80 typedef ExecContext::Status Status;
86 Status status() const { return _status; }
88 void setStatus(Status newStatus) { _status = newStatus; }
90 /// Set the status to Active. Optional delay indicates number of
91 /// cycles to wait before beginning execution.
92 void activate(int delay = 1);
94 /// Set the status to Suspended.
97 /// Set the status to Unallocated.
100 /// Set the status to Halted.
104 RegFile regs; // correct-path register context
107 // pointer to CPU associated with this context
110 ProxyExecContext<CPUExecContext> *proxy;
112 // Current instruction
115 // Index of hardware thread context on the CPU that this represents.
118 // ID of this context w.r.t. the System or Process object to which
119 // it belongs. For full-system mode, this is the system CPU ID.
132 /** A functional port outgoing only for functional accesses to physical
134 FunctionalPort *physPort;
136 /** A functional port, outgoing only, for functional accesse to virtual
137 * addresses. That doen't require execution context information */
138 VirtualPort *virtPort;
140 FunctionProfile *profile;
141 ProfileNode *profileNode;
143 void dumpFuncProfile();
145 /** Event for timing out quiesce instruction */
146 struct EndQuiesceEvent : public Event
148 /** A pointer to the execution context that is quiesced */
149 CPUExecContext *cpuXC;
151 EndQuiesceEvent(CPUExecContext *_cpuXC);
153 /** Event process to occur at interrupt*/
154 virtual void process();
156 /** Event description */
157 virtual const char *description();
159 EndQuiesceEvent quiesceEvent;
161 Event *getQuiesceEvent() { return &quiesceEvent; }
163 Tick readLastActivate() { return lastActivate; }
165 Tick readLastSuspend() { return lastSuspend; }
169 void profileSample();
172 /// Port that syscalls can use to access memory (provides translation step).
173 TranslatingPort *port;
177 // Address space ID. Note that this is used for TIMING cache
178 // simulation only; all functional memory accesses should use
179 // one of the FunctionalMemory pointers above.
185 * Temporary storage to pass the source address from copy_load to
187 * @todo Remove this temporary when we have a better way to do it.
191 * Temp storage for the physical source address of a copy.
192 * @todo Remove this temporary when we have a better way to do it.
194 Addr copySrcPhysAddr;
198 * number of executed instructions, for matching with syscall trace
199 * points in EIO files.
201 Counter func_exe_inst;
204 // Count failed store conditionals so we can warn of apparent
205 // application deadlock situations.
206 unsigned storeCondFailures;
208 // constructor: initialize context from given process structure
210 CPUExecContext(BaseCPU *_cpu, int _thread_num, System *_system,
211 AlphaITB *_itb, AlphaDTB *_dtb);
213 CPUExecContext(BaseCPU *_cpu, int _thread_num, Process *_process, int _asid,
215 // Constructor to use XC to pass reg file around. Not used for anything
217 CPUExecContext(RegFile *regFile);
219 virtual ~CPUExecContext();
221 virtual void takeOverFrom(ExecContext *oldContext);
223 void regStats(const std::string &name);
225 void serialize(std::ostream &os);
226 void unserialize(Checkpoint *cp, const std::string §ion);
228 BaseCPU *getCpuPtr() { return cpu; }
230 ExecContext *getProxy() { return proxy; }
232 int getThreadNum() { return thread_num; }
235 System *getSystemPtr() { return system; }
237 AlphaITB *getITBPtr() { return itb; }
239 AlphaDTB *getDTBPtr() { return dtb; }
241 int getInstAsid() { return regs.instAsid(); }
242 int getDataAsid() { return regs.dataAsid(); }
244 Fault translateInstReq(RequestPtr &req)
246 return itb->translate(req, proxy);
249 Fault translateDataReadReq(RequestPtr &req)
251 return dtb->translate(req, proxy, false);
254 Fault translateDataWriteReq(RequestPtr &req)
256 return dtb->translate(req, proxy, true);
259 FunctionalPort *getPhysPort() { return physPort; }
261 /** Return a virtual port. If no exec context is specified then a static
262 * port is returned. Otherwise a port is created and returned. It must be
263 * deleted by deleteVirtPort(). */
264 VirtualPort *getVirtPort(ExecContext *xc);
266 void delVirtPort(VirtualPort *vp);
269 TranslatingPort *getMemPort() { return port; }
271 Process *getProcessPtr() { return process; }
273 int getInstAsid() { return asid; }
274 int getDataAsid() { return asid; }
276 Fault translateInstReq(RequestPtr &req)
278 return process->pTable->translate(req);
281 Fault translateDataReadReq(RequestPtr &req)
283 return process->pTable->translate(req);
286 Fault translateDataWriteReq(RequestPtr &req)
288 return process->pTable->translate(req);
295 Fault read(RequestPtr &req, T &data)
297 #if FULL_SYSTEM && THE_ISA == ALPHA_ISA
298 if (req->flags & LOCKED) {
299 req->xc->setMiscReg(TheISA::Lock_Addr_DepTag, req->paddr);
300 req->xc->setMiscReg(TheISA::Lock_Flag_DepTag, true);
305 error = mem->prot_read(req->paddr, data, req->size);
306 data = LittleEndianGuest::gtoh(data);
311 Fault write(RequestPtr &req, T &data)
313 #if FULL_SYSTEM && THE_ISA == ALPHA_ISA
316 // If this is a store conditional, act appropriately
317 if (req->flags & LOCKED) {
320 if (req->flags & UNCACHEABLE) {
321 // Don't update result register (see stq_c in isa_desc)
323 xc->setStCondFailures(0);//Needed? [RGD]
325 bool lock_flag = xc->readMiscReg(TheISA::Lock_Flag_DepTag);
326 Addr lock_addr = xc->readMiscReg(TheISA::Lock_Addr_DepTag);
327 req->result = lock_flag;
329 ((lock_addr & ~0xf) != (req->paddr & ~0xf))) {
330 xc->setMiscReg(TheISA::Lock_Flag_DepTag, false);
331 xc->setStCondFailures(xc->readStCondFailures() + 1);
332 if (((xc->readStCondFailures()) % 100000) == 0) {
333 std::cerr << "Warning: "
334 << xc->readStCondFailures()
335 << " consecutive store conditional failures "
336 << "on cpu " << req->xc->readCpuId()
341 else xc->setStCondFailures(0);
345 // Need to clear any locked flags on other proccessors for
346 // this address. Only do this for succsful Store Conditionals
347 // and all other stores (WH64?). Unsuccessful Store
348 // Conditionals would have returned above, and wouldn't fall
350 for (int i = 0; i < system->execContexts.size(); i++){
351 xc = system->execContexts[i];
352 if ((xc->readMiscReg(TheISA::Lock_Addr_DepTag) & ~0xf) ==
353 (req->paddr & ~0xf)) {
354 xc->setMiscReg(TheISA::Lock_Flag_DepTag, false);
359 return mem->prot_write(req->paddr, (T)htog(data), req->size);
362 virtual bool misspeculating();
365 MachInst getInst() { return inst; }
367 void setInst(MachInst new_inst)
372 Fault instRead(RequestPtr &req)
374 panic("instRead not implemented");
375 // return funcPhysMem->read(req, inst);
379 void setCpuId(int id) { cpu_id = id; }
381 int readCpuId() { return cpu_id; }
383 void copyArchRegs(ExecContext *xc);
386 // New accessors for new decoder.
388 uint64_t readIntReg(int reg_idx)
390 return regs.readIntReg(reg_idx);
393 FloatReg readFloatReg(int reg_idx, int width)
395 return regs.readFloatReg(reg_idx, width);
398 FloatReg readFloatReg(int reg_idx)
400 return regs.readFloatReg(reg_idx);
403 FloatRegBits readFloatRegBits(int reg_idx, int width)
405 return regs.readFloatRegBits(reg_idx, width);
408 FloatRegBits readFloatRegBits(int reg_idx)
410 return regs.readFloatRegBits(reg_idx);
413 void setIntReg(int reg_idx, uint64_t val)
415 regs.setIntReg(reg_idx, val);
418 void setFloatReg(int reg_idx, FloatReg val, int width)
420 regs.setFloatReg(reg_idx, val, width);
423 void setFloatReg(int reg_idx, FloatReg val)
425 regs.setFloatReg(reg_idx, val);
428 void setFloatRegBits(int reg_idx, FloatRegBits val, int width)
430 regs.setFloatRegBits(reg_idx, val, width);
433 void setFloatRegBits(int reg_idx, FloatRegBits val)
435 regs.setFloatRegBits(reg_idx, val);
440 return regs.readPC();
443 void setPC(uint64_t val)
448 uint64_t readNextPC()
450 return regs.readNextPC();
453 void setNextPC(uint64_t val)
458 uint64_t readNextNPC()
460 return regs.readNextNPC();
463 void setNextNPC(uint64_t val)
465 regs.setNextNPC(val);
469 MiscReg readMiscReg(int misc_reg)
471 return regs.readMiscReg(misc_reg);
474 MiscReg readMiscRegWithEffect(int misc_reg, Fault &fault)
476 return regs.readMiscRegWithEffect(misc_reg, fault, proxy);
479 Fault setMiscReg(int misc_reg, const MiscReg &val)
481 return regs.setMiscReg(misc_reg, val);
484 Fault setMiscRegWithEffect(int misc_reg, const MiscReg &val)
486 return regs.setMiscRegWithEffect(misc_reg, val, proxy);
489 unsigned readStCondFailures() { return storeCondFailures; }
491 void setStCondFailures(unsigned sc_failures)
492 { storeCondFailures = sc_failures; }
494 void clearArchRegs() { regs.clear(); }
497 int readIntrFlag() { return regs.intrflag; }
498 void setIntrFlag(int val) { regs.intrflag = val; }
500 bool inPalMode() { return AlphaISA::PcPAL(regs.readPC()); }
501 bool simPalCheck(int palFunc);
505 TheISA::IntReg getSyscallArg(int i)
507 return regs.readIntReg(TheISA::ArgumentReg0 + i);
510 // used to shift args for indirect syscall
511 void setSyscallArg(int i, TheISA::IntReg val)
513 regs.setIntReg(TheISA::ArgumentReg0 + i, val);
516 void setSyscallReturn(SyscallReturn return_value)
518 TheISA::setSyscallReturn(return_value, ®s);
521 void syscall(int64_t callnum)
523 process->syscall(callnum, proxy);
526 Counter readFuncExeInst() { return func_exe_inst; }
528 void setFuncExeInst(Counter new_val) { func_exe_inst = new_val; }
531 void changeRegFileContext(RegFile::ContextParam param,
532 RegFile::ContextVal val)
534 regs.changeContext(param, val);
539 // for non-speculative execution context, spec_mode is always false
541 CPUExecContext::misspeculating()
546 #endif // __CPU_CPU_EXEC_CONTEXT_HH__