2 * Copyright (c) 2003 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 __EXEC_CONTEXT_HH__
30 #define __EXEC_CONTEXT_HH__
32 #include "sim/host.hh"
33 #include "mem/mem_req.hh"
34 #include "mem/functional_mem/functional_memory.hh"
35 #include "sim/serialize.hh"
37 // forward declaration: see functional_memory.hh
38 class FunctionalMemory;
44 #include "targetarch/alpha_memory.hh"
45 class MemoryController;
47 #include "kern/kernel_stats.hh"
48 #include "sim/system.hh"
49 #include "sim/sw_context.hh"
53 #include "sim/process.hh"
58 // The ExecContext object represents a functional context for
59 // instruction execution. It incorporates everything required for
60 // architecture-level functional simulation of a single thread.
68 /// Initialized but not running yet. All CPUs start in
69 /// this state, but most transition to Active on cycle 1.
70 /// In MP or SMT systems, non-primary contexts will stay
71 /// in this state until a thread is assigned to them.
74 /// Running. Instructions should be executed only when
75 /// the context is in this state.
78 /// Temporarily inactive. Entered while waiting for
79 /// synchronization, etc.
82 /// Permanently shut down. Entered when target executes
83 /// m5exit pseudo-instruction. When all contexts enter
84 /// this state, the simulation will terminate.
92 Status status() const { return _status; }
94 /// Set the status to Active. Optional delay indicates number of
95 /// cycles to wait before beginning execution.
96 void activate(int delay = 1);
98 /// Set the status to Suspended.
101 /// Set the status to Unallocated.
104 /// Set the status to Halted.
109 KernelStats kernelStats;
113 RegFile regs; // correct-path register context
115 // pointer to CPU associated with this context
118 // Current instruction
121 // Index of hardware thread context on the CPU that this represents.
124 // ID of this context w.r.t. the System or Process object to which
125 // it belongs. For full-system mode, this is the system CPU ID.
130 FunctionalMemory *mem;
135 // the following two fields are redundant, since we can always
136 // look them up through the system pointer, but we'll leave them
137 // here for now for convenience
138 MemoryController *memCtrl;
139 PhysicalMemory *physmem;
145 FunctionalMemory *mem; // functional storage for process address space
147 // Address space ID. Note that this is used for TIMING cache
148 // simulation only; all functional memory accesses should use
149 // one of the FunctionalMemory pointers above.
155 * Temporary storage to pass the source address from copy_load to
157 * @todo Remove this temporary when we have a better way to do it.
161 * Temp storage for the physical source address of a copy.
162 * @todo Remove this temporary when we have a better way to do it.
164 Addr copySrcPhysAddr;
168 * number of executed instructions, for matching with syscall trace
169 * points in EIO files.
171 Counter func_exe_inst;
174 // Count failed store conditionals so we can warn of apparent
175 // application deadlock situations.
176 unsigned storeCondFailures;
178 // constructor: initialize context from given process structure
180 ExecContext(BaseCPU *_cpu, int _thread_num, System *_system,
181 AlphaITB *_itb, AlphaDTB *_dtb, FunctionalMemory *_dem);
183 ExecContext(BaseCPU *_cpu, int _thread_num, Process *_process, int _asid);
184 ExecContext(BaseCPU *_cpu, int _thread_num, FunctionalMemory *_mem,
187 virtual ~ExecContext() {}
189 virtual void takeOverFrom(ExecContext *oldContext);
191 void regStats(const std::string &name);
193 void serialize(std::ostream &os);
194 void unserialize(Checkpoint *cp, const std::string §ion);
197 bool validInstAddr(Addr addr) { return true; }
198 bool validDataAddr(Addr addr) { return true; }
199 int getInstAsid() { return ITB_ASN_ASN(regs.ipr[TheISA::IPR_ITB_ASN]); }
200 int getDataAsid() { return DTB_ASN_ASN(regs.ipr[TheISA::IPR_DTB_ASN]); }
202 Fault translateInstReq(MemReqPtr &req)
204 return itb->translate(req);
207 Fault translateDataReadReq(MemReqPtr &req)
209 return dtb->translate(req, false);
212 Fault translateDataWriteReq(MemReqPtr &req)
214 return dtb->translate(req, true);
218 bool validInstAddr(Addr addr)
219 { return process->validInstAddr(addr); }
221 bool validDataAddr(Addr addr)
222 { return process->validDataAddr(addr); }
224 int getInstAsid() { return asid; }
225 int getDataAsid() { return asid; }
227 Fault dummyTranslation(MemReqPtr &req)
230 assert((req->vaddr >> 48 & 0xffff) == 0);
233 // put the asid in the upper 16 bits of the paddr
234 req->paddr = req->vaddr & ~((Addr)0xffff << sizeof(Addr) * 8 - 16);
235 req->paddr = req->paddr | (Addr)req->asid << sizeof(Addr) * 8 - 16;
238 Fault translateInstReq(MemReqPtr &req)
240 return dummyTranslation(req);
242 Fault translateDataReadReq(MemReqPtr &req)
244 return dummyTranslation(req);
246 Fault translateDataWriteReq(MemReqPtr &req)
248 return dummyTranslation(req);
254 Fault read(MemReqPtr &req, T &data)
256 #if defined(TARGET_ALPHA) && defined(FULL_SYSTEM)
257 if (req->flags & LOCKED) {
258 MiscRegFile *cregs = &req->xc->regs.miscRegs;
259 cregs->lock_addr = req->paddr;
260 cregs->lock_flag = true;
263 return mem->read(req, data);
267 Fault write(MemReqPtr &req, T &data)
269 #if defined(TARGET_ALPHA) && defined(FULL_SYSTEM)
273 // If this is a store conditional, act appropriately
274 if (req->flags & LOCKED) {
275 cregs = &req->xc->regs.miscRegs;
277 if (req->flags & UNCACHEABLE) {
278 // Don't update result register (see stq_c in isa_desc)
280 req->xc->storeCondFailures = 0;//Needed? [RGD]
282 req->result = cregs->lock_flag;
283 if (!cregs->lock_flag ||
284 ((cregs->lock_addr & ~0xf) != (req->paddr & ~0xf))) {
285 cregs->lock_flag = false;
286 if (((++req->xc->storeCondFailures) % 100000) == 0) {
287 std::cerr << "Warning: "
288 << req->xc->storeCondFailures
289 << " consecutive store conditional failures "
290 << "on cpu " << req->xc->cpu_id
295 else req->xc->storeCondFailures = 0;
299 // Need to clear any locked flags on other proccessors for
300 // this address. Only do this for succsful Store Conditionals
301 // and all other stores (WH64?). Unsuccessful Store
302 // Conditionals would have returned above, and wouldn't fall
304 for (int i = 0; i < system->execContexts.size(); i++){
305 cregs = &system->execContexts[i]->regs.miscRegs;
306 if ((cregs->lock_addr & ~0xf) == (req->paddr & ~0xf)) {
307 cregs->lock_flag = false;
312 return mem->write(req, data);
315 virtual bool misspeculating();
318 MachInst getInst() { return inst; }
320 void setInst(MachInst new_inst)
325 Fault instRead(MemReqPtr &req)
327 return mem->read(req, inst);
331 // New accessors for new decoder.
333 uint64_t readIntReg(int reg_idx)
335 return regs.intRegFile[reg_idx];
338 float readFloatRegSingle(int reg_idx)
340 return (float)regs.floatRegFile.d[reg_idx];
343 double readFloatRegDouble(int reg_idx)
345 return regs.floatRegFile.d[reg_idx];
348 uint64_t readFloatRegInt(int reg_idx)
350 return regs.floatRegFile.q[reg_idx];
353 void setIntReg(int reg_idx, uint64_t val)
355 regs.intRegFile[reg_idx] = val;
358 void setFloatRegSingle(int reg_idx, float val)
360 regs.floatRegFile.d[reg_idx] = (double)val;
363 void setFloatRegDouble(int reg_idx, double val)
365 regs.floatRegFile.d[reg_idx] = val;
368 void setFloatRegInt(int reg_idx, uint64_t val)
370 regs.floatRegFile.q[reg_idx] = val;
378 void setNextPC(uint64_t val)
385 return regs.miscRegs.uniq;
388 void setUniq(uint64_t val)
390 regs.miscRegs.uniq = val;
395 return regs.miscRegs.fpcr;
398 void setFpcr(uint64_t val)
400 regs.miscRegs.fpcr = val;
404 uint64_t readIpr(int idx, Fault &fault);
405 Fault setIpr(int idx, uint64_t val);
406 int readIntrFlag() { return regs.intrflag; }
407 void setIntrFlag(int val) { regs.intrflag = val; }
409 bool inPalMode() { return PC_PAL(regs.pc); }
410 void ev5_trap(Fault fault);
411 bool simPalCheck(int palFunc);
414 /** Meant to be more generic trap function to be
415 * called when an instruction faults.
416 * @param fault The fault generated by executing the instruction.
417 * @todo How to do this properly so it's dependent upon ISA only?
420 void trap(Fault fault);
423 IntReg getSyscallArg(int i)
425 return regs.intRegFile[ArgumentReg0 + i];
428 // used to shift args for indirect syscall
429 void setSyscallArg(int i, IntReg val)
431 regs.intRegFile[ArgumentReg0 + i] = val;
434 void setSyscallReturn(int64_t return_value)
436 // check for error condition. Alpha syscall convention is to
437 // indicate success/failure in reg a3 (r19) and put the
438 // return value itself in the standard return value reg (v0).
439 const int RegA3 = 19; // only place this is used
440 if (return_value >= 0) {
442 regs.intRegFile[RegA3] = 0;
443 regs.intRegFile[ReturnValueReg] = return_value;
445 // got an error, return details
446 regs.intRegFile[RegA3] = (IntReg) -1;
447 regs.intRegFile[ReturnValueReg] = -return_value;
453 process->syscall(this);
459 // for non-speculative execution context, spec_mode is always false
461 ExecContext::misspeculating()
466 #endif // __EXEC_CONTEXT_HH__