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 "arch/isa_traits.hh"
38 #include "sim/byteswap.hh"
40 // forward declaration: see functional_memory.hh
41 class FunctionalMemory;
47 #include "sim/system.hh"
48 #include "targetarch/alpha_memory.hh"
50 class FunctionProfile;
52 class MemoryController;
53 namespace Kernel { class Binning; class Statistics; }
57 #include "sim/process.hh"
62 // The ExecContext object represents a functional context for
63 // instruction execution. It incorporates everything required for
64 // architecture-level functional simulation of a single thread.
72 /// Initialized but not running yet. All CPUs start in
73 /// this state, but most transition to Active on cycle 1.
74 /// In MP or SMT systems, non-primary contexts will stay
75 /// in this state until a thread is assigned to them.
78 /// Running. Instructions should be executed only when
79 /// the context is in this state.
82 /// Temporarily inactive. Entered while waiting for
83 /// initialization,synchronization, etc.
86 /// Permanently shut down. Entered when target executes
87 /// m5exit pseudo-instruction. When all contexts enter
88 /// this state, the simulation will terminate.
96 Status status() const { return _status; }
98 void setStatus(Status newStatus) { _status = newStatus; }
100 /// Set the status to Active. Optional delay indicates number of
101 /// cycles to wait before beginning execution.
102 void activate(int delay = 1);
104 /// Set the status to Suspended.
107 /// Set the status to Unallocated.
110 /// Set the status to Halted.
114 RegFile regs; // correct-path register context
116 // pointer to CPU associated with this context
119 // Current instruction
122 // Index of hardware thread context on the CPU that this represents.
125 // ID of this context w.r.t. the System or Process object to which
126 // 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;
141 Kernel::Binning *kernelBinning;
142 Kernel::Statistics *kernelStats;
146 FunctionProfile *profile;
147 ProfileNode *profileNode;
149 void dumpFuncProfile();
154 FunctionalMemory *mem; // functional storage for process address space
156 // Address space ID. Note that this is used for TIMING cache
157 // simulation only; all functional memory accesses should use
158 // one of the FunctionalMemory pointers above.
164 * Temporary storage to pass the source address from copy_load to
166 * @todo Remove this temporary when we have a better way to do it.
170 * Temp storage for the physical source address of a copy.
171 * @todo Remove this temporary when we have a better way to do it.
173 Addr copySrcPhysAddr;
177 * number of executed instructions, for matching with syscall trace
178 * points in EIO files.
180 Counter func_exe_inst;
183 // Count failed store conditionals so we can warn of apparent
184 // application deadlock situations.
185 unsigned storeCondFailures;
187 // constructor: initialize context from given process structure
189 ExecContext(BaseCPU *_cpu, int _thread_num, System *_system,
190 AlphaITB *_itb, AlphaDTB *_dtb, FunctionalMemory *_dem);
192 ExecContext(BaseCPU *_cpu, int _thread_num, Process *_process, int _asid);
193 ExecContext(BaseCPU *_cpu, int _thread_num, FunctionalMemory *_mem,
196 virtual ~ExecContext();
198 virtual void takeOverFrom(ExecContext *oldContext);
200 void regStats(const std::string &name);
202 void serialize(std::ostream &os);
203 void unserialize(Checkpoint *cp, const std::string §ion);
206 bool validInstAddr(Addr addr) { return true; }
207 bool validDataAddr(Addr addr) { return true; }
208 int getInstAsid() { return regs.instAsid(); }
209 int getDataAsid() { return regs.dataAsid(); }
211 Fault translateInstReq(MemReqPtr &req)
213 return itb->translate(req);
216 Fault translateDataReadReq(MemReqPtr &req)
218 return dtb->translate(req, false);
221 Fault translateDataWriteReq(MemReqPtr &req)
223 return dtb->translate(req, true);
227 bool validInstAddr(Addr addr)
228 { return process->validInstAddr(addr); }
230 bool validDataAddr(Addr addr)
231 { return process->validDataAddr(addr); }
233 int getInstAsid() { return asid; }
234 int getDataAsid() { return asid; }
236 Fault dummyTranslation(MemReqPtr &req)
239 assert((req->vaddr >> 48 & 0xffff) == 0);
242 // put the asid in the upper 16 bits of the paddr
243 req->paddr = req->vaddr & ~((Addr)0xffff << sizeof(Addr) * 8 - 16);
244 req->paddr = req->paddr | (Addr)req->asid << sizeof(Addr) * 8 - 16;
247 Fault translateInstReq(MemReqPtr &req)
249 return dummyTranslation(req);
251 Fault translateDataReadReq(MemReqPtr &req)
253 return dummyTranslation(req);
255 Fault translateDataWriteReq(MemReqPtr &req)
257 return dummyTranslation(req);
263 Fault read(MemReqPtr &req, T &data)
265 #if FULL_SYSTEM && defined(TARGET_ALPHA)
266 if (req->flags & LOCKED) {
267 MiscRegFile *cregs = &req->xc->regs.miscRegs;
268 cregs->lock_addr = req->paddr;
269 cregs->lock_flag = true;
274 error = mem->read(req, data);
275 data = LittleEndianGuest::gtoh(data);
280 Fault write(MemReqPtr &req, T &data)
282 #if FULL_SYSTEM && defined(TARGET_ALPHA)
286 // If this is a store conditional, act appropriately
287 if (req->flags & LOCKED) {
288 cregs = &req->xc->regs.miscRegs;
290 if (req->flags & UNCACHEABLE) {
291 // Don't update result register (see stq_c in isa_desc)
293 req->xc->storeCondFailures = 0;//Needed? [RGD]
295 req->result = cregs->lock_flag;
296 if (!cregs->lock_flag ||
297 ((cregs->lock_addr & ~0xf) != (req->paddr & ~0xf))) {
298 cregs->lock_flag = false;
299 if (((++req->xc->storeCondFailures) % 100000) == 0) {
300 std::cerr << "Warning: "
301 << req->xc->storeCondFailures
302 << " consecutive store conditional failures "
303 << "on cpu " << req->xc->cpu_id
308 else req->xc->storeCondFailures = 0;
312 // Need to clear any locked flags on other proccessors for
313 // this address. Only do this for succsful Store Conditionals
314 // and all other stores (WH64?). Unsuccessful Store
315 // Conditionals would have returned above, and wouldn't fall
317 for (int i = 0; i < system->execContexts.size(); i++){
318 cregs = &system->execContexts[i]->regs.miscRegs;
319 if ((cregs->lock_addr & ~0xf) == (req->paddr & ~0xf)) {
320 cregs->lock_flag = false;
325 return mem->write(req, (T)LittleEndianGuest::htog(data));
328 virtual bool misspeculating();
331 MachInst getInst() { return inst; }
333 void setInst(MachInst new_inst)
338 Fault instRead(MemReqPtr &req)
340 return mem->read(req, inst);
344 // New accessors for new decoder.
346 uint64_t readIntReg(int reg_idx)
348 return regs.intRegFile[reg_idx];
351 float readFloatRegSingle(int reg_idx)
353 return (float)regs.floatRegFile.d[reg_idx];
356 double readFloatRegDouble(int reg_idx)
358 return regs.floatRegFile.d[reg_idx];
361 uint64_t readFloatRegInt(int reg_idx)
363 return regs.floatRegFile.q[reg_idx];
366 void setIntReg(int reg_idx, uint64_t val)
368 regs.intRegFile[reg_idx] = val;
371 void setFloatRegSingle(int reg_idx, float val)
373 regs.floatRegFile.d[reg_idx] = (double)val;
376 void setFloatRegDouble(int reg_idx, double val)
378 regs.floatRegFile.d[reg_idx] = val;
381 void setFloatRegInt(int reg_idx, uint64_t val)
383 regs.floatRegFile.q[reg_idx] = val;
391 void setNextPC(uint64_t val)
398 return regs.miscRegs.uniq;
401 void setUniq(uint64_t val)
403 regs.miscRegs.uniq = val;
408 return regs.miscRegs.fpcr;
411 void setFpcr(uint64_t val)
413 regs.miscRegs.fpcr = val;
417 uint64_t readIpr(int idx, Fault &fault);
418 Fault setIpr(int idx, uint64_t val);
419 int readIntrFlag() { return regs.intrflag; }
420 void setIntrFlag(int val) { regs.intrflag = val; }
422 bool inPalMode() { return AlphaISA::PcPAL(regs.pc); }
423 void ev5_trap(Fault fault);
424 bool simPalCheck(int palFunc);
427 /** Meant to be more generic trap function to be
428 * called when an instruction faults.
429 * @param fault The fault generated by executing the instruction.
430 * @todo How to do this properly so it's dependent upon ISA only?
433 void trap(Fault fault);
436 IntReg getSyscallArg(int i)
438 return regs.intRegFile[ArgumentReg0 + i];
441 // used to shift args for indirect syscall
442 void setSyscallArg(int i, IntReg val)
444 regs.intRegFile[ArgumentReg0 + i] = val;
447 void setSyscallReturn(SyscallReturn return_value)
449 // check for error condition. Alpha syscall convention is to
450 // indicate success/failure in reg a3 (r19) and put the
451 // return value itself in the standard return value reg (v0).
452 const int RegA3 = 19; // only place this is used
453 if (return_value.successful()) {
455 regs.intRegFile[RegA3] = 0;
456 regs.intRegFile[ReturnValueReg] = return_value.value();
458 // got an error, return details
459 regs.intRegFile[RegA3] = (IntReg) -1;
460 regs.intRegFile[ReturnValueReg] = -return_value.value();
466 process->syscall(this);
472 // for non-speculative execution context, spec_mode is always false
474 ExecContext::misspeculating()
479 #endif // __CPU_EXEC_CONTEXT_HH__