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"
51 #include "sim/prog.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; }
72 void setStatus(Status new_status);
76 KernelStats kernelStats;
80 RegFile regs; // correct-path register context
82 // pointer to CPU associated with this context
85 // Index of hardware thread context on the CPU that this represents.
88 // ID of this context w.r.t. the System or Process object to which
89 // it belongs. For full-system mode, this is the system CPU ID.
94 FunctionalMemory *mem;
99 // the following two fields are redundant, since we can always
100 // look them up through the system pointer, but we'll leave them
101 // here for now for convenience
102 MemoryController *memCtrl;
103 PhysicalMemory *physmem;
108 FunctionalMemory *mem; // functional storage for process address space
110 // Address space ID. Note that this is used for TIMING cache
111 // simulation only; all functional memory accesses should use
112 // one of the FunctionalMemory pointers above.
119 * number of executed instructions, for matching with syscall trace
120 * points in EIO files.
122 Counter func_exe_insn;
125 // Count failed store conditionals so we can warn of apparent
126 // application deadlock situations.
127 unsigned storeCondFailures;
129 // constructor: initialize context from given process structure
131 ExecContext(BaseCPU *_cpu, int _thread_num, System *_system,
132 AlphaItb *_itb, AlphaDtb *_dtb, FunctionalMemory *_dem);
134 ExecContext(BaseCPU *_cpu, int _thread_num, Process *_process, int _asid);
135 ExecContext(BaseCPU *_cpu, int _thread_num, FunctionalMemory *_mem,
138 virtual ~ExecContext() {}
140 virtual void takeOverFrom(ExecContext *oldContext);
142 void regStats(const std::string &name);
144 void serialize(std::ostream &os);
145 void unserialize(Checkpoint *cp, const std::string §ion);
148 bool validInstAddr(Addr addr) { return true; }
149 bool validDataAddr(Addr addr) { return true; }
150 int getInstAsid() { return ITB_ASN_ASN(regs.ipr[TheISA::IPR_ITB_ASN]); }
151 int getDataAsid() { return DTB_ASN_ASN(regs.ipr[TheISA::IPR_DTB_ASN]); }
153 Fault translateInstReq(MemReqPtr req)
155 return itb->translate(req);
158 Fault translateDataReadReq(MemReqPtr req)
160 return dtb->translate(req, false);
163 Fault translateDataWriteReq(MemReqPtr req)
165 return dtb->translate(req, true);
169 bool validInstAddr(Addr addr)
170 { return process->validInstAddr(addr); }
172 bool validDataAddr(Addr addr)
173 { return process->validDataAddr(addr); }
175 int getInstAsid() { return asid; }
176 int getDataAsid() { return asid; }
178 Fault dummyTranslation(MemReqPtr req)
181 assert((req->vaddr >> 48 & 0xffff) == 0);
184 // put the asid in the upper 16 bits of the paddr
185 req->paddr = req->vaddr & ~((Addr)0xffff << sizeof(Addr) * 8 - 16);
186 req->paddr = req->paddr | (Addr)req->asid << sizeof(Addr) * 8 - 16;
189 Fault translateInstReq(MemReqPtr req)
191 return dummyTranslation(req);
193 Fault translateDataReadReq(MemReqPtr req)
195 return dummyTranslation(req);
197 Fault translateDataWriteReq(MemReqPtr req)
199 return dummyTranslation(req);
205 Fault read(MemReqPtr req, T& data)
207 #if defined(TARGET_ALPHA) && defined(FULL_SYSTEM)
208 if (req->flags & LOCKED) {
209 MiscRegFile *cregs = &req->xc->regs.miscRegs;
210 cregs->lock_addr = req->paddr;
211 cregs->lock_flag = true;
214 return mem->read(req, data);
218 Fault write(MemReqPtr req, T& data)
220 #if defined(TARGET_ALPHA) && defined(FULL_SYSTEM)
224 // If this is a store conditional, act appropriately
225 if (req->flags & LOCKED) {
226 cregs = &req->xc->regs.miscRegs;
228 if (req->flags & UNCACHEABLE) {
229 // Don't update result register (see stq_c in isa_desc)
231 req->xc->storeCondFailures = 0;//Needed? [RGD]
233 req->result = cregs->lock_flag;
234 if (!cregs->lock_flag ||
235 ((cregs->lock_addr & ~0xf) != (req->paddr & ~0xf))) {
236 cregs->lock_flag = false;
237 if (((++req->xc->storeCondFailures) % 100000) == 0) {
238 std::cerr << "Warning: "
239 << req->xc->storeCondFailures
240 << " consecutive store conditional failures "
241 << "on cpu " << req->xc->cpu_id
246 else req->xc->storeCondFailures = 0;
250 // Need to clear any locked flags on other proccessors for
251 // this address. Only do this for succsful Store Conditionals
252 // and all other stores (WH64?). Unsuccessful Store
253 // Conditionals would have returned above, and wouldn't fall
255 for (int i = 0; i < system->execContexts.size(); i++){
256 cregs = &system->execContexts[i]->regs.miscRegs;
257 if ((cregs->lock_addr & ~0xf) == (req->paddr & ~0xf)) {
258 cregs->lock_flag = false;
263 return mem->write(req, data);
266 virtual bool misspeculating();
270 // New accessors for new decoder.
272 uint64_t readIntReg(int reg_idx)
274 return regs.intRegFile[reg_idx];
277 float readFloatRegSingle(int reg_idx)
279 return (float)regs.floatRegFile.d[reg_idx];
282 double readFloatRegDouble(int reg_idx)
284 return regs.floatRegFile.d[reg_idx];
287 uint64_t readFloatRegInt(int reg_idx)
289 return regs.floatRegFile.q[reg_idx];
292 void setIntReg(int reg_idx, uint64_t val)
294 regs.intRegFile[reg_idx] = val;
297 void setFloatRegSingle(int reg_idx, float val)
299 regs.floatRegFile.d[reg_idx] = (double)val;
302 void setFloatRegDouble(int reg_idx, double val)
304 regs.floatRegFile.d[reg_idx] = val;
307 void setFloatRegInt(int reg_idx, uint64_t val)
309 regs.floatRegFile.q[reg_idx] = val;
317 void setNextPC(uint64_t val)
324 return regs.miscRegs.uniq;
327 void setUniq(uint64_t val)
329 regs.miscRegs.uniq = val;
334 return regs.miscRegs.fpcr;
337 void setFpcr(uint64_t val)
339 regs.miscRegs.fpcr = val;
343 uint64_t readIpr(int idx, Fault &fault);
344 Fault setIpr(int idx, uint64_t val);
346 void ev5_trap(Fault fault);
347 bool simPalCheck(int palFunc);
353 process->syscall(this);
359 // for non-speculative execution context, spec_mode is always false
361 ExecContext::misspeculating()
366 #endif // __EXEC_CONTEXT_HH__