2 * Copyright (c) 2001-2005 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_EXEC_CONTEXT_HH__
30 #define __CPU_EXEC_CONTEXT_HH__
32 #include "config/full_system.hh"
33 #include "mem/functional/functional.hh"
34 #include "mem/mem_req.hh"
35 #include "sim/host.hh"
36 #include "sim/serialize.hh"
37 #include "sim/byteswap.hh"
39 // forward declaration: see functional_memory.hh
40 class FunctionalMemory;
46 #include "sim/system.hh"
47 #include "targetarch/alpha_memory.hh"
49 class FunctionProfile;
51 class MemoryController;
52 namespace Kernel { class Binning; class Statistics; }
56 #include "sim/process.hh"
61 // The ExecContext object represents a functional context for
62 // instruction execution. It incorporates everything required for
63 // architecture-level functional simulation of a single thread.
71 /// Initialized but not running yet. All CPUs start in
72 /// this state, but most transition to Active on cycle 1.
73 /// In MP or SMT systems, non-primary contexts will stay
74 /// in this state until a thread is assigned to them.
77 /// Running. Instructions should be executed only when
78 /// the context is in this state.
81 /// Temporarily inactive. Entered while waiting for
82 /// synchronization, etc.
85 /// Permanently shut down. Entered when target executes
86 /// m5exit pseudo-instruction. When all contexts enter
87 /// this state, the simulation will terminate.
95 Status status() const { return _status; }
97 /// Set the status to Active. Optional delay indicates number of
98 /// cycles to wait before beginning execution.
99 void activate(int delay = 1);
101 /// Set the status to Suspended.
104 /// Set the status to Unallocated.
107 /// Set the status to Halted.
111 RegFile regs; // correct-path register context
113 // pointer to CPU associated with this context
116 // Current instruction
119 // Index of hardware thread context on the CPU that this represents.
122 // ID of this context w.r.t. the System or Process object to which
123 // it belongs. For full-system mode, this is the system CPU ID.
127 FunctionalMemory *mem;
132 // the following two fields are redundant, since we can always
133 // look them up through the system pointer, but we'll leave them
134 // here for now for convenience
135 MemoryController *memctrl;
136 PhysicalMemory *physmem;
138 Kernel::Binning *kernelBinning;
139 Kernel::Statistics *kernelStats;
143 FunctionProfile *profile;
144 ProfileNode *profileNode;
146 void dumpFuncProfile();
151 FunctionalMemory *mem; // functional storage for process address space
153 // Address space ID. Note that this is used for TIMING cache
154 // simulation only; all functional memory accesses should use
155 // one of the FunctionalMemory pointers above.
161 * Temporary storage to pass the source address from copy_load to
163 * @todo Remove this temporary when we have a better way to do it.
167 * Temp storage for the physical source address of a copy.
168 * @todo Remove this temporary when we have a better way to do it.
170 Addr copySrcPhysAddr;
174 * number of executed instructions, for matching with syscall trace
175 * points in EIO files.
177 Counter func_exe_inst;
180 // Count failed store conditionals so we can warn of apparent
181 // application deadlock situations.
182 unsigned storeCondFailures;
184 // constructor: initialize context from given process structure
186 ExecContext(BaseCPU *_cpu, int _thread_num, System *_system,
187 AlphaITB *_itb, AlphaDTB *_dtb, FunctionalMemory *_dem);
189 ExecContext(BaseCPU *_cpu, int _thread_num, Process *_process, int _asid);
190 ExecContext(BaseCPU *_cpu, int _thread_num, FunctionalMemory *_mem,
193 virtual ~ExecContext();
195 virtual void takeOverFrom(ExecContext *oldContext);
197 void regStats(const std::string &name);
199 void serialize(std::ostream &os);
200 void unserialize(Checkpoint *cp, const std::string §ion);
203 bool validInstAddr(Addr addr) { return true; }
204 bool validDataAddr(Addr addr) { return true; }
205 int getInstAsid() { return regs.instAsid(); }
206 int getDataAsid() { return regs.dataAsid(); }
208 Fault translateInstReq(MemReqPtr &req)
210 return itb->translate(req);
213 Fault translateDataReadReq(MemReqPtr &req)
215 return dtb->translate(req, false);
218 Fault translateDataWriteReq(MemReqPtr &req)
220 return dtb->translate(req, true);
224 bool validInstAddr(Addr addr)
225 { return process->validInstAddr(addr); }
227 bool validDataAddr(Addr addr)
228 { return process->validDataAddr(addr); }
230 int getInstAsid() { return asid; }
231 int getDataAsid() { return asid; }
233 Fault dummyTranslation(MemReqPtr &req)
236 assert((req->vaddr >> 48 & 0xffff) == 0);
239 // put the asid in the upper 16 bits of the paddr
240 req->paddr = req->vaddr & ~((Addr)0xffff << sizeof(Addr) * 8 - 16);
241 req->paddr = req->paddr | (Addr)req->asid << sizeof(Addr) * 8 - 16;
244 Fault translateInstReq(MemReqPtr &req)
246 return dummyTranslation(req);
248 Fault translateDataReadReq(MemReqPtr &req)
250 return dummyTranslation(req);
252 Fault translateDataWriteReq(MemReqPtr &req)
254 return dummyTranslation(req);
260 Fault read(MemReqPtr &req, T &data)
262 #if FULL_SYSTEM && defined(TARGET_ALPHA)
263 if (req->flags & LOCKED) {
264 MiscRegFile *cregs = &req->xc->regs.miscRegs;
265 cregs->lock_addr = req->paddr;
266 cregs->lock_flag = true;
271 error = mem->read(req, data);
272 data = LittleEndianGuest::gtoh(data);
277 Fault write(MemReqPtr &req, T &data)
279 #if FULL_SYSTEM && defined(TARGET_ALPHA)
283 // If this is a store conditional, act appropriately
284 if (req->flags & LOCKED) {
285 cregs = &req->xc->regs.miscRegs;
287 if (req->flags & UNCACHEABLE) {
288 // Don't update result register (see stq_c in isa_desc)
290 req->xc->storeCondFailures = 0;//Needed? [RGD]
292 req->result = cregs->lock_flag;
293 if (!cregs->lock_flag ||
294 ((cregs->lock_addr & ~0xf) != (req->paddr & ~0xf))) {
295 cregs->lock_flag = false;
296 if (((++req->xc->storeCondFailures) % 100000) == 0) {
297 std::cerr << "Warning: "
298 << req->xc->storeCondFailures
299 << " consecutive store conditional failures "
300 << "on cpu " << req->xc->cpu_id
305 else req->xc->storeCondFailures = 0;
309 // Need to clear any locked flags on other proccessors for
310 // this address. Only do this for succsful Store Conditionals
311 // and all other stores (WH64?). Unsuccessful Store
312 // Conditionals would have returned above, and wouldn't fall
314 for (int i = 0; i < system->execContexts.size(); i++){
315 cregs = &system->execContexts[i]->regs.miscRegs;
316 if ((cregs->lock_addr & ~0xf) == (req->paddr & ~0xf)) {
317 cregs->lock_flag = false;
322 return mem->write(req, (T)LittleEndianGuest::htog(data));
325 virtual bool misspeculating();
328 MachInst getInst() { return inst; }
330 void setInst(MachInst new_inst)
335 Fault instRead(MemReqPtr &req)
337 return mem->read(req, inst);
341 // New accessors for new decoder.
343 uint64_t readIntReg(int reg_idx)
345 return regs.intRegFile[reg_idx];
348 float readFloatRegSingle(int reg_idx)
350 return (float)regs.floatRegFile.d[reg_idx];
353 double readFloatRegDouble(int reg_idx)
355 return regs.floatRegFile.d[reg_idx];
358 uint64_t readFloatRegInt(int reg_idx)
360 return regs.floatRegFile.q[reg_idx];
363 void setIntReg(int reg_idx, uint64_t val)
365 regs.intRegFile[reg_idx] = val;
368 void setFloatRegSingle(int reg_idx, float val)
370 regs.floatRegFile.d[reg_idx] = (double)val;
373 void setFloatRegDouble(int reg_idx, double val)
375 regs.floatRegFile.d[reg_idx] = val;
378 void setFloatRegInt(int reg_idx, uint64_t val)
380 regs.floatRegFile.q[reg_idx] = val;
388 void setNextPC(uint64_t val)
395 return regs.miscRegs.uniq;
398 void setUniq(uint64_t val)
400 regs.miscRegs.uniq = val;
405 return regs.miscRegs.fpcr;
408 void setFpcr(uint64_t val)
410 regs.miscRegs.fpcr = val;
414 uint64_t readIpr(int idx, Fault &fault);
415 Fault setIpr(int idx, uint64_t val);
416 int readIntrFlag() { return regs.intrflag; }
417 void setIntrFlag(int val) { regs.intrflag = val; }
419 bool inPalMode() { return AlphaISA::PcPAL(regs.pc); }
420 void ev5_trap(Fault fault);
421 bool simPalCheck(int palFunc);
424 /** Meant to be more generic trap function to be
425 * called when an instruction faults.
426 * @param fault The fault generated by executing the instruction.
427 * @todo How to do this properly so it's dependent upon ISA only?
430 void trap(Fault fault);
433 IntReg getSyscallArg(int i)
435 return regs.intRegFile[ArgumentReg0 + i];
438 // used to shift args for indirect syscall
439 void setSyscallArg(int i, IntReg val)
441 regs.intRegFile[ArgumentReg0 + i] = val;
444 void setSyscallReturn(SyscallReturn return_value)
446 // check for error condition. Alpha syscall convention is to
447 // indicate success/failure in reg a3 (r19) and put the
448 // return value itself in the standard return value reg (v0).
449 const int RegA3 = 19; // only place this is used
450 if (return_value.successful()) {
452 regs.intRegFile[RegA3] = 0;
453 regs.intRegFile[ReturnValueReg] = return_value.value();
455 // got an error, return details
456 regs.intRegFile[RegA3] = (IntReg) -1;
457 regs.intRegFile[ReturnValueReg] = -return_value.value();
463 process->syscall(this);
469 // for non-speculative execution context, spec_mode is always false
471 ExecContext::misspeculating()
476 #endif // __CPU_EXEC_CONTEXT_HH__