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__
36 // forward declaration: see functional_memory.hh
37 class FunctionalMemory;
43 #include "alpha_memory.hh"
44 class MemoryController;
46 #include "kernel_stats.hh"
56 // The ExecContext object represents a functional context for
57 // instruction execution. It incorporates everything required for
58 // architecture-level functional simulation of a single thread.
64 enum Status { Unallocated, Active, Suspended, Halted };
70 Status status() const { return _status; }
71 void setStatus(Status new_status);
75 KernelStats kernelStats;
79 RegFile regs; // correct-path register context
81 // pointer to CPU associated with this context
84 // Index of hardware thread context on the CPU that this represents.
89 FunctionalMemory *mem;
95 // the following two fields are redundant, since we can always
96 // look them up through the system pointer, but we'll leave them
97 // here for now for convenience
98 MemoryController *memCtrl;
99 PhysicalMemory *physmem;
104 FunctionalMemory *mem; // functional storage for process address space
106 // Address space ID. Note that this is used for TIMING cache
107 // simulation only; all functional memory accesses should use
108 // one of the FunctionalMemory pointers above.
115 * number of executed instructions, for matching with syscall trace
116 * points in EIO files.
118 Counter func_exe_insn;
121 // Count failed store conditionals so we can warn of apparent
122 // application deadlock situations.
123 unsigned storeCondFailures;
125 // constructor: initialize context from given process structure
127 ExecContext(BaseCPU *_cpu, int _thread_num, System *_system,
128 AlphaItb *_itb, AlphaDtb *_dtb, FunctionalMemory *_dem,
131 ExecContext(BaseCPU *_cpu, int _thread_num, Process *_process, int _asid);
132 ExecContext(BaseCPU *_cpu, int _thread_num, FunctionalMemory *_mem,
135 virtual ~ExecContext() {}
137 void regStats(const std::string &name);
140 bool validInstAddr(Addr addr) { return true; }
141 bool validDataAddr(Addr addr) { return true; }
142 int getInstAsid() { return ITB_ASN_ASN(regs.ipr[TheISA::IPR_ITB_ASN]); }
143 int getDataAsid() { return DTB_ASN_ASN(regs.ipr[TheISA::IPR_DTB_ASN]); }
145 Fault translateInstReq(MemReqPtr req)
147 return itb->translate(req);
150 Fault translateDataReadReq(MemReqPtr req)
152 return dtb->translate(req, false);
155 Fault translateDataWriteReq(MemReqPtr req)
157 return dtb->translate(req, true);
162 bool validInstAddr(Addr addr)
163 { return process->validInstAddr(addr); }
165 bool validDataAddr(Addr addr)
166 { return process->validDataAddr(addr); }
168 int getInstAsid() { return asid; }
169 int getDataAsid() { return asid; }
171 Fault dummyTranslation(MemReqPtr req)
174 assert((req->vaddr >> 48 & 0xffff) == 0);
177 // put the asid in the upper 16 bits of the paddr
178 req->paddr = req->vaddr & ~((Addr)0xffff << sizeof(Addr) * 8 - 16);
179 req->paddr = req->paddr | (Addr)req->asid << sizeof(Addr) * 8 - 16;
182 Fault translateInstReq(MemReqPtr req)
184 return dummyTranslation(req);
186 Fault translateDataReadReq(MemReqPtr req)
188 return dummyTranslation(req);
190 Fault translateDataWriteReq(MemReqPtr req)
192 return dummyTranslation(req);
198 Fault read(MemReqPtr req, T& data)
200 #if defined(TARGET_ALPHA) && defined(FULL_SYSTEM)
201 if (req->flags & LOCKED) {
202 MiscRegFile *cregs = &req->xc->regs.miscRegs;
203 cregs->lock_addr = req->paddr;
204 cregs->lock_flag = true;
207 return mem->read(req, data);
211 Fault write(MemReqPtr req, T& data)
213 #if defined(TARGET_ALPHA) && defined(FULL_SYSTEM)
217 // If this is a store conditional, act appropriately
218 if (req->flags & LOCKED) {
219 cregs = &req->xc->regs.miscRegs;
221 if (req->flags & UNCACHEABLE) {
222 // Don't update result register (see machine.def)
224 req->xc->storeCondFailures = 0;//Needed? [RGD]
226 req->result = cregs->lock_flag;
227 if (!cregs->lock_flag ||
228 ((cregs->lock_addr & ~0xf) != (req->paddr & ~0xf))) {
229 cregs->lock_flag = false;
230 if (((++req->xc->storeCondFailures) % 100000) == 0) {
231 std::cerr << "Warning: "
232 << req->xc->storeCondFailures
233 << " consecutive store conditional failures "
234 << "on cpu " << req->xc->cpu_id
239 else req->xc->storeCondFailures = 0;
243 // Need to clear any locked flags on other proccessors for this
245 // Only do this for succsful Store Conditionals and all other
247 // Unsuccesful Store Conditionals would have returned above,
248 // and wouldn't fall through
249 for(int i = 0; i < system->num_cpus; i++){
250 cregs = &system->xc_array[i]->regs.miscRegs;
251 if((cregs->lock_addr & ~0xf) == (req->paddr & ~0xf)) {
252 cregs->lock_flag = false;
257 return mem->write(req, data);
260 virtual bool misspeculating();
264 // New accessors for new decoder.
266 uint64_t readIntReg(int reg_idx)
268 return regs.intRegFile[reg_idx];
271 float readFloatRegSingle(int reg_idx)
273 return (float)regs.floatRegFile.d[reg_idx];
276 double readFloatRegDouble(int reg_idx)
278 return regs.floatRegFile.d[reg_idx];
281 uint64_t readFloatRegInt(int reg_idx)
283 return regs.floatRegFile.q[reg_idx];
286 void setIntReg(int reg_idx, uint64_t val)
288 regs.intRegFile[reg_idx] = val;
291 void setFloatRegSingle(int reg_idx, float val)
293 regs.floatRegFile.d[reg_idx] = (double)val;
296 void setFloatRegDouble(int reg_idx, double val)
298 regs.floatRegFile.d[reg_idx] = val;
301 void setFloatRegInt(int reg_idx, uint64_t val)
303 regs.floatRegFile.q[reg_idx] = val;
311 void setNextPC(uint64_t val)
318 return regs.miscRegs.uniq;
321 void setUniq(uint64_t val)
323 regs.miscRegs.uniq = val;
328 return regs.miscRegs.fpcr;
331 void setFpcr(uint64_t val)
333 regs.miscRegs.fpcr = val;
337 uint64_t readIpr(int idx, Fault &fault);
338 Fault setIpr(int idx, uint64_t val);
340 void ev5_trap(Fault fault);
341 bool simPalCheck(int palFunc);
347 process->syscall(this);
353 // for non-speculative execution context, spec_mode is always false
355 ExecContext::misspeculating()
360 #endif // __EXEC_CONTEXT_HH__