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;
51 class MemoryController;
55 #include "sim/process.hh"
56 class TranslatingPort;
61 // The CPUExecContext object represents a functional context for
62 // instruction execution. It incorporates everything required for
63 // architecture-level functional simulation of a single thread.
69 typedef TheISA::RegFile RegFile;
70 typedef TheISA::MachInst MachInst;
71 typedef TheISA::MiscRegFile MiscRegFile;
72 typedef TheISA::MiscReg MiscReg;
74 typedef ExecContext::Status Status;
80 Status status() const { return _status; }
82 void setStatus(Status newStatus) { _status = newStatus; }
84 /// Set the status to Active. Optional delay indicates number of
85 /// cycles to wait before beginning execution.
86 void activate(int delay = 1);
88 /// Set the status to Suspended.
91 /// Set the status to Unallocated.
94 /// Set the status to Halted.
98 RegFile regs; // correct-path register context
101 // pointer to CPU associated with this context
104 ProxyExecContext<CPUExecContext> *proxy;
106 // Current instruction
109 // Index of hardware thread context on the CPU that this represents.
112 // ID of this context w.r.t. the System or Process object to which
113 // it belongs. For full-system mode, this is the system CPU ID.
121 /// Port that syscalls can use to access memory (provides translation step).
122 TranslatingPort *port;
129 // the following two fields are redundant, since we can always
130 // look them up through the system pointer, but we'll leave them
131 // here for now for convenience
132 MemoryController *memctrl;
133 // PhysicalMemory *physmem;
135 FunctionProfile *profile;
136 ProfileNode *profileNode;
138 void dumpFuncProfile();
140 /** Event for timing out quiesce instruction */
141 struct EndQuiesceEvent : public Event
143 /** A pointer to the execution context that is quiesced */
144 CPUExecContext *cpuXC;
146 EndQuiesceEvent(CPUExecContext *_cpuXC);
148 /** Event process to occur at interrupt*/
149 virtual void process();
151 /** Event description */
152 virtual const char *description();
154 EndQuiesceEvent quiesceEvent;
156 Event *getQuiesceEvent() { return &quiesceEvent; }
158 Tick readLastActivate() { return lastActivate; }
160 Tick readLastSuspend() { return lastSuspend; }
164 void profileSample();
169 // Address space ID. Note that this is used for TIMING cache
170 // simulation only; all functional memory accesses should use
171 // one of the FunctionalMemory pointers above.
177 * Temporary storage to pass the source address from copy_load to
179 * @todo Remove this temporary when we have a better way to do it.
183 * Temp storage for the physical source address of a copy.
184 * @todo Remove this temporary when we have a better way to do it.
186 Addr copySrcPhysAddr;
190 * number of executed instructions, for matching with syscall trace
191 * points in EIO files.
193 Counter func_exe_inst;
196 // Count failed store conditionals so we can warn of apparent
197 // application deadlock situations.
198 unsigned storeCondFailures;
200 // constructor: initialize context from given process structure
202 CPUExecContext(BaseCPU *_cpu, int _thread_num, System *_system,
203 AlphaITB *_itb, AlphaDTB *_dtb, FunctionalMemory *_dem);
205 CPUExecContext(BaseCPU *_cpu, int _thread_num, Process *_process, int _asid, Port *mem_port);
206 // Constructor to use XC to pass reg file around. Not used for anything
208 CPUExecContext(RegFile *regFile);
210 virtual ~CPUExecContext();
212 virtual void takeOverFrom(ExecContext *oldContext);
214 void regStats(const std::string &name);
216 void serialize(std::ostream &os);
217 void unserialize(Checkpoint *cp, const std::string §ion);
219 BaseCPU *getCpuPtr() { return cpu; }
221 ExecContext *getProxy() { return proxy; }
223 int getThreadNum() { return thread_num; }
226 System *getSystemPtr() { return system; }
228 PhysicalMemory *getPhysMemPtr() { return physmem; }
230 AlphaITB *getITBPtr() { return itb; }
232 AlphaDTB *getDTBPtr() { return dtb; }
234 bool validInstAddr(Addr addr) { return true; }
235 bool validDataAddr(Addr addr) { return true; }
236 int getInstAsid() { return regs.instAsid(); }
237 int getDataAsid() { return regs.dataAsid(); }
239 Fault translateInstReq(CpuRequestPtr &req)
241 return itb->translate(req);
244 Fault translateDataReadReq(CpuRequestPtr &req)
246 return dtb->translate(req, false);
249 Fault translateDataWriteReq(CpuRequestPtr &req)
251 return dtb->translate(req, true);
255 Process *getProcessPtr() { return process; }
257 bool validInstAddr(Addr addr)
258 { return process->validInstAddr(addr); }
260 bool validDataAddr(Addr addr)
261 { return process->validDataAddr(addr); }
263 int getInstAsid() { return asid; }
264 int getDataAsid() { return asid; }
266 Fault translateInstReq(CpuRequestPtr &req)
268 return process->pTable->translate(req);
271 Fault translateDataReadReq(CpuRequestPtr &req)
273 return process->pTable->translate(req);
276 Fault translateDataWriteReq(CpuRequestPtr &req)
278 return process->pTable->translate(req);
285 Fault read(CpuRequestPtr &req, T &data)
287 #if FULL_SYSTEM && defined(TARGET_ALPHA)
288 if (req->flags & LOCKED) {
289 req->xc->setMiscReg(TheISA::Lock_Addr_DepTag, req->paddr);
290 req->xc->setMiscReg(TheISA::Lock_Flag_DepTag, true);
295 error = mem->prot_read(req->paddr, data, req->size);
296 data = LittleEndianGuest::gtoh(data);
301 Fault write(CpuRequestPtr &req, T &data)
303 #if FULL_SYSTEM && defined(TARGET_ALPHA)
306 // If this is a store conditional, act appropriately
307 if (req->flags & LOCKED) {
310 if (req->flags & UNCACHEABLE) {
311 // Don't update result register (see stq_c in isa_desc)
313 xc->setStCondFailures(0);//Needed? [RGD]
315 bool lock_flag = xc->readMiscReg(TheISA::Lock_Flag_DepTag);
316 Addr lock_addr = xc->readMiscReg(TheISA::Lock_Addr_DepTag);
317 req->result = lock_flag;
319 ((lock_addr & ~0xf) != (req->paddr & ~0xf))) {
320 xc->setMiscReg(TheISA::Lock_Flag_DepTag, false);
321 xc->setStCondFailures(xc->readStCondFailures() + 1);
322 if (((xc->readStCondFailures()) % 100000) == 0) {
323 std::cerr << "Warning: "
324 << xc->readStCondFailures()
325 << " consecutive store conditional failures "
326 << "on cpu " << req->xc->readCpuId()
331 else xc->setStCondFailures(0);
335 // Need to clear any locked flags on other proccessors for
336 // this address. Only do this for succsful Store Conditionals
337 // and all other stores (WH64?). Unsuccessful Store
338 // Conditionals would have returned above, and wouldn't fall
340 for (int i = 0; i < system->execContexts.size(); i++){
341 xc = system->execContexts[i];
342 if ((xc->readMiscReg(TheISA::Lock_Addr_DepTag) & ~0xf) ==
343 (req->paddr & ~0xf)) {
344 xc->setMiscReg(TheISA::Lock_Flag_DepTag, false);
349 return mem->prot_write(req->paddr, (T)htog(data), req->size);
352 virtual bool misspeculating();
355 MachInst getInst() { return inst; }
357 void setInst(MachInst new_inst)
362 Fault instRead(CpuRequestPtr &req)
364 panic("instRead not implemented");
365 // return funcPhysMem->read(req, inst);
369 void setCpuId(int id) { cpu_id = id; }
371 int readCpuId() { return cpu_id; }
373 void copyArchRegs(ExecContext *xc);
376 // New accessors for new decoder.
378 uint64_t readIntReg(int reg_idx)
380 return regs.intRegFile[reg_idx];
383 float readFloatRegSingle(int reg_idx)
385 return (float)regs.floatRegFile.d[reg_idx];
388 double readFloatRegDouble(int reg_idx)
390 return regs.floatRegFile.d[reg_idx];
393 uint64_t readFloatRegInt(int reg_idx)
395 return regs.floatRegFile.q[reg_idx];
398 void setIntReg(int reg_idx, uint64_t val)
400 regs.intRegFile[reg_idx] = val;
403 void setFloatRegSingle(int reg_idx, float val)
405 regs.floatRegFile.d[reg_idx] = (double)val;
408 void setFloatRegDouble(int reg_idx, double val)
410 regs.floatRegFile.d[reg_idx] = val;
413 void setFloatRegInt(int reg_idx, uint64_t val)
415 regs.floatRegFile.q[reg_idx] = val;
423 void setPC(uint64_t val)
428 uint64_t readNextPC()
433 void setNextPC(uint64_t val)
438 uint64_t readNextNPC()
443 void setNextNPC(uint64_t val)
449 MiscReg readMiscReg(int misc_reg)
451 return regs.miscRegs.readReg(misc_reg);
454 MiscReg readMiscRegWithEffect(int misc_reg, Fault &fault)
456 return regs.miscRegs.readRegWithEffect(misc_reg, fault, proxy);
459 Fault setMiscReg(int misc_reg, const MiscReg &val)
461 return regs.miscRegs.setReg(misc_reg, val);
464 Fault setMiscRegWithEffect(int misc_reg, const MiscReg &val)
466 return regs.miscRegs.setRegWithEffect(misc_reg, val, proxy);
469 unsigned readStCondFailures() { return storeCondFailures; }
471 void setStCondFailures(unsigned sc_failures)
472 { storeCondFailures = sc_failures; }
474 void clearArchRegs() { memset(®s, 0, sizeof(regs)); }
477 int readIntrFlag() { return regs.intrflag; }
478 void setIntrFlag(int val) { regs.intrflag = val; }
480 bool inPalMode() { return AlphaISA::PcPAL(regs.pc); }
481 bool simPalCheck(int palFunc);
485 TheISA::IntReg getSyscallArg(int i)
487 return regs.intRegFile[TheISA::ArgumentReg0 + i];
490 // used to shift args for indirect syscall
491 void setSyscallArg(int i, TheISA::IntReg val)
493 regs.intRegFile[TheISA::ArgumentReg0 + i] = val;
496 void setSyscallReturn(SyscallReturn return_value)
498 TheISA::setSyscallReturn(return_value, ®s);
503 process->syscall(proxy);
506 Counter readFuncExeInst() { return func_exe_inst; }
508 void setFuncExeInst(Counter new_val) { func_exe_inst = new_val; }
513 // for non-speculative execution context, spec_mode is always false
515 CPUExecContext::misspeculating()
520 #endif // __CPU_CPU_EXEC_CONTEXT_HH__