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 "sim/serialize.hh"
36 // forward declaration: see functional_memory.hh
37 class FunctionalMemory;
43 #include "targetarch/alpha_memory.hh"
44 class MemoryController;
46 #include "kern/tru64/kernel_stats.hh"
47 #include "sim/system.hh"
50 #include "sim/sw_context.hh"
55 #include "sim/process.hh"
60 // The ExecContext object represents a functional context for
61 // instruction execution. It incorporates everything required for
62 // architecture-level functional simulation of a single thread.
70 /// Initialized but not running yet. All CPUs start in
71 /// this state, but most transition to Active on cycle 1.
72 /// In MP or SMT systems, non-primary contexts will stay
73 /// in this state until a thread is assigned to them.
76 /// Running. Instructions should be executed only when
77 /// the context is in this state.
80 /// Temporarily inactive. Entered while waiting for
81 /// synchronization, etc.
84 /// Permanently shut down. Entered when target executes
85 /// m5exit pseudo-instruction. When all contexts enter
86 /// this state, the simulation will terminate.
94 Status status() const { return _status; }
96 void setStatus(Status new_status);
100 KernelStats kernelStats;
104 RegFile regs; // correct-path register context
106 // pointer to CPU associated with this context
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.
118 FunctionalMemory *mem;
123 // the following two fields are redundant, since we can always
124 // look them up through the system pointer, but we'll leave them
125 // here for now for convenience
126 MemoryController *memCtrl;
127 PhysicalMemory *physmem;
136 FunctionalMemory *mem; // functional storage for process address space
138 // Address space ID. Note that this is used for TIMING cache
139 // simulation only; all functional memory accesses should use
140 // one of the FunctionalMemory pointers above.
147 * number of executed instructions, for matching with syscall trace
148 * points in EIO files.
150 Counter func_exe_insn;
153 // Count failed store conditionals so we can warn of apparent
154 // application deadlock situations.
155 unsigned storeCondFailures;
157 // constructor: initialize context from given process structure
159 ExecContext(BaseCPU *_cpu, int _thread_num, System *_system,
160 AlphaItb *_itb, AlphaDtb *_dtb, FunctionalMemory *_dem);
162 ExecContext(BaseCPU *_cpu, int _thread_num, Process *_process, int _asid);
163 ExecContext(BaseCPU *_cpu, int _thread_num, FunctionalMemory *_mem,
166 virtual ~ExecContext() {}
168 virtual void takeOverFrom(ExecContext *oldContext);
170 void regStats(const std::string &name);
172 void serialize(std::ostream &os);
173 void unserialize(Checkpoint *cp, const std::string §ion);
176 bool validInstAddr(Addr addr) { return true; }
177 bool validDataAddr(Addr addr) { return true; }
178 int getInstAsid() { return ITB_ASN_ASN(regs.ipr[TheISA::IPR_ITB_ASN]); }
179 int getDataAsid() { return DTB_ASN_ASN(regs.ipr[TheISA::IPR_DTB_ASN]); }
181 Fault translateInstReq(MemReqPtr req)
183 return itb->translate(req);
186 Fault translateDataReadReq(MemReqPtr req)
188 return dtb->translate(req, false);
191 Fault translateDataWriteReq(MemReqPtr req)
193 return dtb->translate(req, true);
197 bool validInstAddr(Addr addr)
198 { return process->validInstAddr(addr); }
200 bool validDataAddr(Addr addr)
201 { return process->validDataAddr(addr); }
203 int getInstAsid() { return asid; }
204 int getDataAsid() { return asid; }
206 Fault dummyTranslation(MemReqPtr req)
209 assert((req->vaddr >> 48 & 0xffff) == 0);
212 // put the asid in the upper 16 bits of the paddr
213 req->paddr = req->vaddr & ~((Addr)0xffff << sizeof(Addr) * 8 - 16);
214 req->paddr = req->paddr | (Addr)req->asid << sizeof(Addr) * 8 - 16;
217 Fault translateInstReq(MemReqPtr req)
219 return dummyTranslation(req);
221 Fault translateDataReadReq(MemReqPtr req)
223 return dummyTranslation(req);
225 Fault translateDataWriteReq(MemReqPtr req)
227 return dummyTranslation(req);
233 Fault read(MemReqPtr req, T& data)
235 #if defined(TARGET_ALPHA) && defined(FULL_SYSTEM)
236 if (req->flags & LOCKED) {
237 MiscRegFile *cregs = &req->xc->regs.miscRegs;
238 cregs->lock_addr = req->paddr;
239 cregs->lock_flag = true;
242 return mem->read(req, data);
246 Fault write(MemReqPtr req, T& data)
248 #if defined(TARGET_ALPHA) && defined(FULL_SYSTEM)
252 // If this is a store conditional, act appropriately
253 if (req->flags & LOCKED) {
254 cregs = &req->xc->regs.miscRegs;
256 if (req->flags & UNCACHEABLE) {
257 // Don't update result register (see stq_c in isa_desc)
259 req->xc->storeCondFailures = 0;//Needed? [RGD]
261 req->result = cregs->lock_flag;
262 if (!cregs->lock_flag ||
263 ((cregs->lock_addr & ~0xf) != (req->paddr & ~0xf))) {
264 cregs->lock_flag = false;
265 if (((++req->xc->storeCondFailures) % 100000) == 0) {
266 std::cerr << "Warning: "
267 << req->xc->storeCondFailures
268 << " consecutive store conditional failures "
269 << "on cpu " << req->xc->cpu_id
274 else req->xc->storeCondFailures = 0;
278 // Need to clear any locked flags on other proccessors for
279 // this address. Only do this for succsful Store Conditionals
280 // and all other stores (WH64?). Unsuccessful Store
281 // Conditionals would have returned above, and wouldn't fall
283 for (int i = 0; i < system->execContexts.size(); i++){
284 cregs = &system->execContexts[i]->regs.miscRegs;
285 if ((cregs->lock_addr & ~0xf) == (req->paddr & ~0xf)) {
286 cregs->lock_flag = false;
291 return mem->write(req, data);
294 virtual bool misspeculating();
298 // New accessors for new decoder.
300 uint64_t readIntReg(int reg_idx)
302 return regs.intRegFile[reg_idx];
305 float readFloatRegSingle(int reg_idx)
307 return (float)regs.floatRegFile.d[reg_idx];
310 double readFloatRegDouble(int reg_idx)
312 return regs.floatRegFile.d[reg_idx];
315 uint64_t readFloatRegInt(int reg_idx)
317 return regs.floatRegFile.q[reg_idx];
320 void setIntReg(int reg_idx, uint64_t val)
322 regs.intRegFile[reg_idx] = val;
325 void setFloatRegSingle(int reg_idx, float val)
327 regs.floatRegFile.d[reg_idx] = (double)val;
330 void setFloatRegDouble(int reg_idx, double val)
332 regs.floatRegFile.d[reg_idx] = val;
335 void setFloatRegInt(int reg_idx, uint64_t val)
337 regs.floatRegFile.q[reg_idx] = val;
345 void setNextPC(uint64_t val)
352 return regs.miscRegs.uniq;
355 void setUniq(uint64_t val)
357 regs.miscRegs.uniq = val;
362 return regs.miscRegs.fpcr;
365 void setFpcr(uint64_t val)
367 regs.miscRegs.fpcr = val;
371 uint64_t readIpr(int idx, Fault &fault);
372 Fault setIpr(int idx, uint64_t val);
374 void ev5_trap(Fault fault);
375 bool simPalCheck(int palFunc);
379 IntReg getSyscallArg(int i)
381 return regs.intRegFile[ArgumentReg0 + i];
384 // used to shift args for indirect syscall
385 void setSyscallArg(int i, IntReg val)
387 regs.intRegFile[ArgumentReg0 + i] = val;
390 void setSyscallReturn(int64_t return_value)
392 // check for error condition. Alpha syscall convention is to
393 // indicate success/failure in reg a3 (r19) and put the
394 // return value itself in the standard return value reg (v0).
395 const int RegA3 = 19; // only place this is used
396 if (return_value >= 0) {
398 regs.intRegFile[RegA3] = 0;
399 regs.intRegFile[ReturnValueReg] = return_value;
401 // got an error, return details
402 regs.intRegFile[RegA3] = (IntReg) -1;
403 regs.intRegFile[ReturnValueReg] = -return_value;
409 process->syscall(this);
415 // for non-speculative execution context, spec_mode is always false
417 ExecContext::misspeculating()
422 #endif // __EXEC_CONTEXT_HH__